diff --git a/packages/cultmath/tools/glsl/build-glsl.sh b/packages/cultmath/tools/glsl/build-glsl.sh index 270199d6..659ea930 100644 --- a/packages/cultmath/tools/glsl/build-glsl.sh +++ b/packages/cultmath/tools/glsl/build-glsl.sh @@ -131,6 +131,8 @@ SENTINEL=$(cut -f2 "$W/shw/capacity.tsv") expect_refused macro-in-expression 'int cultmath_zz_probe(int n) { return n + CULTMATH_MAX_SITES; }' 'outside its guard' # the sentinel spelled in hex: wrappers.py's scan reads decimal tokens, so only the length check can see it expect_refused length-in-expression "uint cultmath_zz_probe(uint n) { return n + $(printf '0x%xu' "$SENTINEL"); }" 'also used by opcode' +# the sentinel as another element type's array length: not a capacity parameter type +expect_refused other-element-same-length "float3 cultmath_zz_probe(float3 x[$(printf '0x%x' "$SENTINEL")], int n) { return x[n]; }" 'not a capacity parameter type' variant array-128 'float4 cultmath_zz_probe(float4 x[128], int n) { return x[n]; }' || { echo "array-128 failed: a library array of length 128 broke the build"; tail -5 "$VD/log"; exit 1; } grep -Eq 'cultmath_zz_probe\(.*\[128\]' "$VD/out/core.glsl" || { echo "array-128 failed: the 128 array is not literal in core.glsl"; exit 1; } PROBE='vec4 x[128]; c = cultmath_zz_probe(x, 1);' diff --git a/packages/cultmath/tools/glsl/spvedit.py b/packages/cultmath/tools/glsl/spvedit.py index 5d882b13..a5707518 100644 --- a/packages/cultmath/tools/glsl/spvedit.py +++ b/packages/cultmath/tools/glsl/spvedit.py @@ -179,7 +179,7 @@ def by_value(h, ins): return out, len(newtype), len(newid) -def capacity_edit(h, ins, rows, callee_of, default, sentinel): +def capacity_edit(h, ins, rows, callee_of, default): """Each capacity parameter (wrappers.tsv column 5) of each callee has an OpTypeArray type. Exactly one length id may serve all of them, and nothing but OpTypeArray, OpName and decorations may use it. That OpConstant becomes an OpSpecConstant with SpecId SPEC_ID named cultmath_max_sites, defaulting to the HLSL guard value. The constant is the @@ -204,9 +204,6 @@ def capacity_edit(h, ins, rows, callee_of, default, sentinel): if len(lengths) != 1: sys.exit('refuse: %d array length ids serve the capacity parameters, expected exactly one' % len(lengths)) cap = lengths.pop() - value = next(x[3] for x in ins if op(x) == OP_CONSTANT and x[2] == cap) - if value != sentinel: - sys.exit('refuse: the capacity length constant is %d, expected the sentinel %d' % (value, sentinel)) site_types = {params[fid][int(c)] for row, fid in zip(rows, callee_of) for c in row[4].split(',') if c} if {t for t, a in arrays.items() if a[3] == cap} != site_types: sys.exit('refuse: an array type of the capacity length is not a capacity parameter type') @@ -233,8 +230,8 @@ def main(src, dst, tsv, capacity): rows = [l.split('\t') for l in open(tsv).read().splitlines() if l] ins, callee_of = export_edit(h, ins, rows) ins, changed, params = by_value(h, ins) - default, sentinel = [int(v) for v in open(capacity).read().split()] - ins, spec = capacity_edit(h, ins, rows, callee_of, default, sentinel) + default = int(open(capacity).read().split()[0]) + ins, spec = capacity_edit(h, ins, rows, callee_of, default) words = h + [v for x in ins for v in x] open(dst, 'wb').write(struct.pack('<%dI' % len(words), *words)) print('spvedit: %d wrappers dropped; by-value: %d functions changed, %d parameters; capacity spec constant id %d' % (len(rows), changed, params, spec))