From 219d99573435f48211e38145e1ef246266e06085 Mon Sep 17 00:00:00 2001 From: tedin7 Date: Wed, 25 Nov 2026 00:25:31 +0100 Subject: [PATCH 1/5] startup: lower s_nor_b32 and s_nand_b32 on a lane mask in gfx2hlsl Part of #1723 --- CMakeLists.txt | 3 + tests/startup_gfx2hlsl_s_nor_nand_check.py | 78 +++++++++++++++++++ .../startup_gfx2hlsl_sop2_complement_check.py | 6 +- tools/startup/gfx2hlsl.py | 8 +- 4 files changed, 89 insertions(+), 6 deletions(-) create mode 100644 tests/startup_gfx2hlsl_s_nor_nand_check.py diff --git a/CMakeLists.txt b/CMakeLists.txt index 36aa44a2b7..febf79263e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2486,6 +2486,9 @@ if(EXISTS "${INTAKE_PYTHON}") # Scalar SOPK accumulate: s_addk_i32 signed-overflow SCC and s_mulk_i32 against an integer reference. add_test(NAME startup_gfx2hlsl_sopk_accum COMMAND "${INTAKE_PYTHON}" -B "${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_gfx2hlsl_sopk_accum_check.py") + # s_nand_b32 and s_nor_b32 on a lane mask (exec, vcc, compare-result SGPRs), per-lane bit against a reference (#1723). + add_test(NAME startup_gfx2hlsl_s_nor_nand COMMAND "${INTAKE_PYTHON}" -B + "${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_gfx2hlsl_s_nor_nand_check.py") # gfx2hlsl run-time sampler heap indexing (#1143): translation controls, then a desktop draw with # DXC ps_6_0 and, when the Windows SDK's FXC is found, the ps_5_1 the startup tools compile with. find_program(STARTUP_FXC fxc HINTS "${DXC_BIN_DIR}") diff --git a/tests/startup_gfx2hlsl_s_nor_nand_check.py b/tests/startup_gfx2hlsl_s_nor_nand_check.py new file mode 100644 index 0000000000..0a97631d5d --- /dev/null +++ b/tests/startup_gfx2hlsl_s_nor_nand_check.py @@ -0,0 +1,78 @@ +"""s_nor_b32 and s_nand_b32 on a lane mask in tools/startup/gfx2hlsl.py (Part of #1723). + +Pure Python, no arguments. A lane mask is the per-lane bit the translator keeps for exec, vcc and the SGPRs that +hold a compare result. Each form is decoded and translated, and the emitted lines are run on the CPU with the integer +evaluator of startup_gfx2hlsl_bit_alu_check.py over every pair of lane bits. The reference is the ISA meaning on one +lane: D = ~(S0 op S1), kept to that lane's bit. The destination must also be recorded as a mask (or be exec/vcc), so +that a later mask operation reads it as one. + +s_xnor_b32 on a lane mask stays refused: it is outside this change. +""" +import sys +from pathlib import Path + +HERE = Path(__file__).resolve().parent +sys.path.insert(0, str(HERE)) +import startup_gfx2hlsl_sop2_complement_check as C # noqa: E402 + +G = C.G +REFERENCE = { + 's_nand_b32': lambda a, b: ~(a & b) & 1, + 's_nor_b32': lambda a, b: ~(a | b) & 1, +} +# (form, destination variable, source variables): vcc_lo/exec_lo name themselves in the emitted lines. +FORMS = [ + ((3, C.VCC_LO, 2, None), 's3', ['vcc', 's2']), + ((3, 1, C.EXEC_LO, None), 's3', ['s1', 'exec']), + ((C.VCC_LO, 1, 2, None), 'vcc', ['s1', 's2']), + ((C.EXEC_LO, 1, 2, None), 'exec', ['s1', 's2']), +] + + +def lane_value(stage, name, form, dest, srcs, a, b): + env = {srcs[0]: a, srcs[1]: b, 'scc': C.SCC_UNSET} + for source in ('s1', 's2', 'vcc', 'exec'): + env.setdefault(source, 0) + return C.run_lines(stage.lines, env)[dest] + + +def main(): + for name, reference in REFERENCE.items(): + wrong, refused = [], [] + for form, dest, srcs in FORMS: + asm, stage = C.attempt(C.code(name, form)) + if stage.lines and stage.lines[0].startswith('refused: '): + refused.append((asm, stage.lines[0])) + continue + for a in (0, 1): + for b in (0, 1): + got = lane_value(stage, name, form, dest, srcs, a, b) + if got != reference(a, b): + wrong.append((asm, a, b, got, reference(a, b))) + C.check('%s: vcc_lo/exec_lo forms are lowered' % name, not refused, str(refused[:2])) + C.check('%s: lane-bit results equal the reference' % name, not wrong, str(wrong[:2])) + + stage = C.Probe() + stage.masks.add(1) # s1 holds a compare result + try: + stage.one(name, '%s s3, s1, s2' % name) + except G.Unsupported as error: + C.check('%s: an SGPR mask source is lowered' % name, False, str(error)) + else: + C.check('%s: an SGPR mask source marks the destination as a mask' % name, 3 in stage.masks, + str(stage.masks)) + + refused = C.attempt(C.code('s_xnor_b32', FORMS[0][0]))[1].lines + C.check('s_xnor_b32 on a lane mask is still refused', refused == ['refused: s_xnor_b32 on a lane mask'], + str(refused)) + + if C.failures: + print('FAIL') + for text in C.failures: + print(' ' + text) + sys.exit(1) + print('PASS') + + +if __name__ == '__main__': + main() diff --git a/tests/startup_gfx2hlsl_sop2_complement_check.py b/tests/startup_gfx2hlsl_sop2_complement_check.py index 2655ba1342..d9e61fee1b 100644 --- a/tests/startup_gfx2hlsl_sop2_complement_check.py +++ b/tests/startup_gfx2hlsl_sop2_complement_check.py @@ -16,7 +16,7 @@ The lowering text and SCC rule equal pixel_aot's SCALAR entries for the same operations (#561). Every numeric form (SGPR, inline, literal or m0 operands) emits the lines of its non-complement sibling (s_and_b32, s_or_b32, s_xor_b32) -with the operation wrapped in ~( ). Lane-mask forms are refused: a vcc_lo or exec_lo operand or destination, or an +with the operation wrapped in ~( ). s_xnor_b32 on a lane mask is refused: a vcc_lo or exec_lo operand or destination, or an SGPR holding a compare mask, is the whole wave's mask, and SCC is set when any bit of the complemented 32-bit result is; the translator's per-lane projection cannot show that, so no mask lowering is claimed. @@ -501,8 +501,8 @@ def controls(): check('%s: %d numeric forms emit the %s lines complemented, same mask and EXEC bookkeeping' % (name, len(VALUE_FORMS), sibling), not wrong, str(wrong[:2])) - # 5b. Lane-mask forms are refused: vcc_lo/exec_lo operands and destinations, and an SGPR holding a compare mask. - for name in OPS: + # 5b. s_xnor_b32 lane-mask forms are refused (s_nand_b32 and s_nor_b32 are lowered, see startup_gfx2hlsl_s_nor_nand_check.py). + for name in ('s_xnor_b32',): accepted = [] for form in MASK_FORMS: asm, stage = attempt(code(name, form)) diff --git a/tools/startup/gfx2hlsl.py b/tools/startup/gfx2hlsl.py index 18688048c3..b6fe4db306 100644 --- a/tools/startup/gfx2hlsl.py +++ b/tools/startup/gfx2hlsl.py @@ -1078,9 +1078,11 @@ def low(tok): word_complement = base in ('s_nand_b32', 's_nor_b32', 's_xnor_b32') # s_mul_hi_u32 needs the whole 32-bit word of each source, like the halfword pack. word_pack = base in ('s_pack_hh_b32_b16', 's_sext_i32_i8', 's_sext_i32_i16', 's_mul_hi_u32') - if shift_add or word_complement or word_pack: - # The per-lane mask cannot supply the full word needed by these operations. s_mul_hi_u32 into an - # SGPR that held a mask replaces it with a plain word (set_s drops the mark), so only vcc/exec count. + if shift_add or base == 's_xnor_b32' or word_pack: + # The per-lane mask cannot supply the full word needed by these operations. s_nand_b32 and + # s_nor_b32 on a lane mask act on each lane's own bit, like s_and_b32 and s_or_b32. + # s_mul_hi_u32 into an SGPR that held a mask replaces it with a plain word (set_s drops the + # mark), so only vcc/exec count as a mask destination there. mask_dest = (dname in ('exec', 'exec_lo', 'exec_hi', 'vcc', 'vcc_lo', 'vcc_hi') if base == 's_mul_hi_u32' else self.is_lane_mask(dname)) if mask_dest or any(self.is_lane_mask(t) for t in srcs): From 2ebf8dd18d6e133568c56e5d6fc789ca28ce3728 Mon Sep 17 00:00:00 2001 From: tedin7 Date: Wed, 25 Nov 2026 01:50:31 +0100 Subject: [PATCH 2/5] shader: refuse unprojected scalar words and high-half masks in s_nor_b32/s_nand_b32 lane-mask lowering, document scope --- docs/experiments.md | 11 +++ tests/startup_gfx2hlsl_s_nor_nand_check.py | 85 +++++++++++++++------- tools/startup/gfx2hlsl.py | 7 ++ 3 files changed, 75 insertions(+), 28 deletions(-) diff --git a/docs/experiments.md b/docs/experiments.md index c441b2ca8b..cf975deb20 100644 --- a/docs/experiments.md +++ b/docs/experiments.md @@ -6605,6 +6605,17 @@ refused by name. Run `ctest --preset dev --no-tests=error -R '^startup_gfx2hlsl_ LLVM 15, `tests/startup_gfx2hlsl_sop2_complement_check.py binary ` and `decode ` round-trip the same words. +**`s_nand_b32` and `s_nor_b32` on a lane mask (#1723).** When every source is a lane mask (`exec_lo`, `vcc_lo` or an +SGPR holding a compare result) and the destination is a mask, `exec_lo`, `vcc_lo` or an SGPR, the pair lowers to +`~(a & b) & 1` and `~(a | b) & 1` on each lane's own bit, like `s_and_b32` and `s_or_b32`, and the destination is +recorded as a mask. Limits: SCC is the per-lane bit, not the whole-wave 32-bit result, so a later SCC read on a lane +mask result is not claimed to match the ISA; `s_xnor_b32` on a lane mask stays refused; `exec_hi` and `vcc_hi` +operands are refused with `Unsupported`; a raw scalar word (inline constant or plain SGPR) mixed with a mask is +refused, because `s_nor_b32 vcc_lo, 1, 0` is `0xfffffffe` in the ISA and one bit per lane cannot say that. The check +runs the emitted lines on the CPU over every pair of lane bits and lists the refused forms; no GPU or WARP result is +claimed. Run `ctest --preset dev --no-tests=error -R '^startup_gfx2hlsl_s_nor_nand$' -V` or +`python3 -B tests/startup_gfx2hlsl_s_nor_nand_check.py`. + **Scalar high-halfword packing.** The same check covers `s_pack_hh_b32_b16` for startup pixel translation. It combines the high halves of two numeric scalar sources, with source 0 in the low result half and source 1 in the high result diff --git a/tests/startup_gfx2hlsl_s_nor_nand_check.py b/tests/startup_gfx2hlsl_s_nor_nand_check.py index 0a97631d5d..fb6111023d 100644 --- a/tests/startup_gfx2hlsl_s_nor_nand_check.py +++ b/tests/startup_gfx2hlsl_s_nor_nand_check.py @@ -1,12 +1,16 @@ """s_nor_b32 and s_nand_b32 on a lane mask in tools/startup/gfx2hlsl.py (Part of #1723). Pure Python, no arguments. A lane mask is the per-lane bit the translator keeps for exec, vcc and the SGPRs that -hold a compare result. Each form is decoded and translated, and the emitted lines are run on the CPU with the integer +hold a compare result. Each form is translated, and the emitted lines are run on the CPU with the integer evaluator of startup_gfx2hlsl_bit_alu_check.py over every pair of lane bits. The reference is the ISA meaning on one lane: D = ~(S0 op S1), kept to that lane's bit. The destination must also be recorded as a mask (or be exec/vcc), so that a later mask operation reads it as one. -s_xnor_b32 on a lane mask stays refused: it is outside this change. +Refused, as before: s_xnor_b32 on a lane mask; the high halves exec_hi/vcc_hi (not modelled); and any form that mixes a +lane mask with a raw scalar word (inline constant or plain SGPR), because such a word has no per-lane bit. +`s_nor_b32 vcc_lo, 1, 0` is ~(1|0) = 0xfffffffe in the ISA, so lane 1 and up must read 1, which one bit cannot say. + +Reproduce: python3 -B tests/startup_gfx2hlsl_s_nor_nand_check.py (CPU only; no GPU or WARP result is claimed). """ import sys from pathlib import Path @@ -20,51 +24,76 @@ 's_nand_b32': lambda a, b: ~(a & b) & 1, 's_nor_b32': lambda a, b: ~(a | b) & 1, } -# (form, destination variable, source variables): vcc_lo/exec_lo name themselves in the emitted lines. +# (destination operand, source operands, mask SGPRs, destination variable, source variables) FORMS = [ - ((3, C.VCC_LO, 2, None), 's3', ['vcc', 's2']), - ((3, 1, C.EXEC_LO, None), 's3', ['s1', 'exec']), - ((C.VCC_LO, 1, 2, None), 'vcc', ['s1', 's2']), - ((C.EXEC_LO, 1, 2, None), 'exec', ['s1', 's2']), + ('s3', ['vcc_lo', 's2'], {2}, 's3', ['vcc', 's2']), + ('s3', ['s1', 'exec_lo'], {1}, 's3', ['s1', 'exec']), + ('vcc_lo', ['s1', 's2'], {1, 2}, 'vcc', ['s1', 's2']), + ('exec_lo', ['s1', 's2'], {1, 2}, 'exec', ['s1', 's2']), +] +# Each must raise Unsupported: unprojected scalar words and the unmodelled high halves. +REFUSED = [ + ('vcc_lo', ['1', '0'], set()), + ('vcc_lo', ['1', '-1'], set()), + ('exec_lo', ['s1', 's2'], set()), + ('s3', ['vcc_lo', '0'], set()), + ('s3', ['s1', '-1'], {1}), + ('vcc_hi', ['0', '0'], set()), + ('exec_hi', ['0', '0'], set()), + ('vcc_hi', ['vcc_lo', 'exec_lo'], set()), + ('s3', ['vcc_hi', 's2'], set()), ] -def lane_value(stage, name, form, dest, srcs, a, b): - env = {srcs[0]: a, srcs[1]: b, 'scc': C.SCC_UNSET} +def translate(name, dest, srcs, masks): + stage = C.Probe() + stage.masks.update(masks) + stage.one(name, '%s %s, %s, %s' % (name, dest, srcs[0], srcs[1])) + return stage + + +def lane_value(stage, dest_var, src_vars, a, b): + env = {src_vars[0]: a, src_vars[1]: b, 'scc': C.SCC_UNSET} for source in ('s1', 's2', 'vcc', 'exec'): env.setdefault(source, 0) - return C.run_lines(stage.lines, env)[dest] + return C.run_lines(stage.lines, env)[dest_var] def main(): for name, reference in REFERENCE.items(): wrong, refused = [], [] - for form, dest, srcs in FORMS: - asm, stage = C.attempt(C.code(name, form)) - if stage.lines and stage.lines[0].startswith('refused: '): - refused.append((asm, stage.lines[0])) + for dest, srcs, masks, dest_var, src_vars in FORMS: + try: + stage = translate(name, dest, srcs, masks) + except G.Unsupported as error: + refused.append((dest, srcs, str(error))) continue + if dest.startswith('s') and int(dest[1:]) not in stage.masks: + wrong.append((dest, 'destination not recorded as a mask', stage.masks)) for a in (0, 1): for b in (0, 1): - got = lane_value(stage, name, form, dest, srcs, a, b) + got = lane_value(stage, dest_var, src_vars, a, b) if got != reference(a, b): - wrong.append((asm, a, b, got, reference(a, b))) - C.check('%s: vcc_lo/exec_lo forms are lowered' % name, not refused, str(refused[:2])) + wrong.append((dest, srcs, a, b, got, reference(a, b))) + C.check('%s: mask forms are lowered' % name, not refused, str(refused[:2])) C.check('%s: lane-bit results equal the reference' % name, not wrong, str(wrong[:2])) - stage = C.Probe() - stage.masks.add(1) # s1 holds a compare result + accepted = [] + for dest, srcs, masks in REFUSED: + try: + translate(name, dest, srcs, masks) + accepted.append((dest, srcs)) + except G.Unsupported: + pass + C.check('%s: raw scalar words and high halves stay refused (%d forms)' % (name, len(REFUSED)), + not accepted, str(accepted[:2])) + + for dest, srcs, masks, _, _ in FORMS[:1]: try: - stage.one(name, '%s s3, s1, s2' % name) + translate('s_xnor_b32', dest, srcs, masks) + C.check('s_xnor_b32 on a lane mask is still refused', False, 'accepted') except G.Unsupported as error: - C.check('%s: an SGPR mask source is lowered' % name, False, str(error)) - else: - C.check('%s: an SGPR mask source marks the destination as a mask' % name, 3 in stage.masks, - str(stage.masks)) - - refused = C.attempt(C.code('s_xnor_b32', FORMS[0][0]))[1].lines - C.check('s_xnor_b32 on a lane mask is still refused', refused == ['refused: s_xnor_b32 on a lane mask'], - str(refused)) + C.check('s_xnor_b32 on a lane mask is still refused', str(error) == 's_xnor_b32 on a lane mask', str(error)) if C.failures: print('FAIL') diff --git a/tools/startup/gfx2hlsl.py b/tools/startup/gfx2hlsl.py index b6fe4db306..73fd5f01da 100644 --- a/tools/startup/gfx2hlsl.py +++ b/tools/startup/gfx2hlsl.py @@ -1087,6 +1087,13 @@ def low(tok): else self.is_lane_mask(dname)) if mask_dest or any(self.is_lane_mask(t) for t in srcs): raise Unsupported('%s on a lane mask' % base) + elif word_complement: + operands = [dname] + srcs + if any(t in ('exec_hi', 'vcc_hi') for t in operands): + raise Unsupported('%s on the high half of a lane mask' % base) + # A raw scalar word (inline constant, plain SGPR) has no per-lane bit: keep it refused. + if any(self.is_lane_mask(t) for t in operands) and not all(self.is_lane_mask(t) for t in srcs): + raise Unsupported('%s mixes a lane mask with an unprojected scalar word' % base) if shift_add and dname != 'm0' and (not dst or dst[0] != 's' or dst[1] != dst[2] or dst[1] > 105): raise Unsupported('%s destination %s' % (base, dname)) if word_pack: From 392a40de0685e69fc27c2d78950d95ff9984aa35 Mon Sep 17 00:00:00 2001 From: tedin7 Date: Thu, 26 Nov 2026 01:16:37 +0100 Subject: [PATCH 3/5] docs: list the s_nor_b32 and s_nand_b32 check in the pure-Python checks --- AGENTS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/AGENTS.md b/AGENTS.md index cd477f2040..0a47b4a9df 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -197,6 +197,7 @@ python3 -m venv out/pe-env ./out/pe-env/bin/python -B tests/startup_gfx2hlsl_join_symbols_check.py ./out/pe-env/bin/python -B tests/startup_gfx2hlsl_readfirstlane_recompute_check.py ./out/pe-env/bin/python -B tests/startup_gfx2hlsl_sop2_complement_check.py +./out/pe-env/bin/python -B tests/startup_gfx2hlsl_s_nor_nand_check.py ./out/pe-env/bin/python -B tests/startup_gfx2hlsl_pack_absdiff_check.py ./out/pe-env/bin/python -B tests/startup_gfx2hlsl_sdwa_cvt_check.py ./out/pe-env/bin/python -B tests/startup_gfx2hlsl_sopk_accum_check.py From f80220655cb7dfa63cd257ec208c4b5d0018c2ff Mon Sep 17 00:00:00 2001 From: c1 Date: Thu, 26 Nov 2026 07:45:24 +0100 Subject: [PATCH 4/5] fix: treat a bare probe as a pixel stage in the exec_lo wave32 gate --- tests/startup_gfx2hlsl_sop2_complement_check.py | 1 - tools/startup/gfx2hlsl.py | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/startup_gfx2hlsl_sop2_complement_check.py b/tests/startup_gfx2hlsl_sop2_complement_check.py index a66ff7ad80..4d52d9f3c4 100644 --- a/tests/startup_gfx2hlsl_sop2_complement_check.py +++ b/tests/startup_gfx2hlsl_sop2_complement_check.py @@ -121,7 +121,6 @@ def code(name, form): class Probe(G.Stage): """A Stage with no pipeline: enough state for decoded instructions to be translated. It is a pixel stage (wave32) unless a test sets `kind` and `pipe.group`.""" - kind = 'ps' def __init__(self): self.lines, self.sym = [], {} diff --git a/tools/startup/gfx2hlsl.py b/tools/startup/gfx2hlsl.py index c56ce83b2c..a9a42025a5 100644 --- a/tools/startup/gfx2hlsl.py +++ b/tools/startup/gfx2hlsl.py @@ -4695,9 +4695,9 @@ def mask_source(tok): # A write to exec_lo leaves lanes 32..63 alone, so it is exact only where the wave is proven wave32: # a pixel stage, or compute with at most 32 threads per group (as the b32 waterfall close requires). # Other stages (the slot 57 mesh stage is wave64) keep refusing it. + kind = getattr(self, 'kind', 'ps') # a bare test probe has no pipeline and stands for a pixel stage group = getattr(getattr(self, 'pipe', None), 'group', None) - wave32_stage = self.kind == 'ps' or ( - self.kind == 'cs' and group is not None and group[0] * group[1] * group[2] <= 32) + wave32_stage = kind == 'ps' or (kind == 'cs' and group is not None and group[0] * group[1] * group[2] <= 32) exec_dest = (dname == 'exec_lo' and base in ('s_nand_b32', 's_nor_b32') and wave32_stage) lane_complement = (word_complement and (sgpr_dest or exec_dest) and all(mask_source(t) for t in (ops[1:] if exec_dest else srcs))) From ef54c20a638f7d0ff72dc3747c6a82158273207a Mon Sep 17 00:00:00 2001 From: c1 Date: Thu, 26 Nov 2026 08:31:29 +0100 Subject: [PATCH 5/5] fix: accept the exec_lo destination only for compute of at most 32 threads The wave size of a pixel or vertex stage is unknown to the translator, so only compute with at most 32 threads per group is proven wave32. --- docs/experiments.md | 2 +- tests/startup_gfx2hlsl_s_nor_nand_check.py | 6 +++--- tests/startup_gfx2hlsl_sop2_complement_check.py | 7 +++++-- tools/startup/gfx2hlsl.py | 11 ++++++----- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/docs/experiments.md b/docs/experiments.md index d747089af8..76276958b8 100644 --- a/docs/experiments.md +++ b/docs/experiments.md @@ -8287,7 +8287,7 @@ when every source is a mask, because bit i of the complement depends only on bit lowers to `(~(a op b)) & 1` into an SGPR, checked on all 32 lanes of the edge words. Guest SCC reads the whole 32-bit result, which the per-lane projection cannot show, so SCC is not emitted and a program that can read it before the next SCC write is refused, through joins and back edges. A mask mixed with a plain word or a constant -and a vcc_lo destination (or an exec_lo destination of s_xnor_b32) stay refused. s_nand_b32 and s_nor_b32 also accept exec_lo as the destination when every source is a mask and the stage is proven wave32 (a pixel stage, or compute with at most 32 threads per group; the slot 57 mesh stage and any wave64 compute group keep refusing it, because a write to exec_lo leaves lanes 32..63 unchanged): the lane's new EXEC bit is the same per-lane value, including for a lane that was inactive. `startup_gfx2hlsl_s_nor_nand` and its `_dispatch_warp`/`_dispatch_hardware` variants check those forms by D3D12 UAV readback against an integer reference. A mask source is also refused whose last write does not dominate a +and a vcc_lo destination (or an exec_lo destination of s_xnor_b32) stay refused. s_nand_b32 and s_nor_b32 also accept exec_lo as the destination when every source is a mask and the stage is proven wave32 (compute with at most 32 threads per group; pixel and vertex stages, whose wave size is unknown, the slot 57 mesh stage and any wave64 compute group keep refusing it, because a write to exec_lo leaves lanes 32..63 unchanged): the lane's new EXEC bit is the same per-lane value, including for a lane that was inactive. `startup_gfx2hlsl_s_nor_nand` and its `_dispatch_warp`/`_dispatch_hardware` variants check those forms by D3D12 UAV readback against an integer reference. A mask source is also refused whose last write does not dominate a branch target crossed since, or which a block on a path to that target writes again. Run `ctest --preset dev --no-tests=error -R '^startup_gfx2hlsl_sop2_complement$' -V`; with LLVM 15, `tests/startup_gfx2hlsl_sop2_complement_check.py binary ` and `decode ` round-trip the same words. diff --git a/tests/startup_gfx2hlsl_s_nor_nand_check.py b/tests/startup_gfx2hlsl_s_nor_nand_check.py index 7111fc0306..c5ad04c475 100644 --- a/tests/startup_gfx2hlsl_s_nor_nand_check.py +++ b/tests/startup_gfx2hlsl_s_nor_nand_check.py @@ -59,10 +59,10 @@ def accepts(name, dest, kind, group): def stage_checks(): """exec_lo leaves lanes 32..63 alone, so a wave64 stage must keep refusing it (a wave64 wave would keep stale - upper lanes active while the low lanes are rewritten). Only a pixel stage or compute with at most 32 threads - per group is proven wave32. An SGPR destination is exact per lane in every stage.""" + upper lanes active while the low lanes are rewritten). Only compute with at most 32 threads per group is proven + wave32; the wave size of a pixel or vertex stage is unknown. An SGPR destination is exact per lane in every stage.""" for name in REFERENCES: - for kind, group, want in (('ps', None, True), ('cs', (32, 1, 1), True), ('cs', (8, 4, 1), True), + for kind, group, want in (('ps', None, False), ('cs', (32, 1, 1), True), ('cs', (8, 4, 1), True), ('cs', (64, 1, 1), False), ('cs', (8, 8, 1), False), ('ms', None, False), ('vs', None, False)): C.check('%s into exec_lo in a %s stage%s is %s' % (name, kind, ' of %s threads' % (group,) if group else '', diff --git a/tests/startup_gfx2hlsl_sop2_complement_check.py b/tests/startup_gfx2hlsl_sop2_complement_check.py index 4d52d9f3c4..bf7755e104 100644 --- a/tests/startup_gfx2hlsl_sop2_complement_check.py +++ b/tests/startup_gfx2hlsl_sop2_complement_check.py @@ -53,6 +53,7 @@ import struct import sys from pathlib import Path +from types import SimpleNamespace HERE = Path(__file__).resolve().parent sys.path.insert(0, str(HERE.parent / 'tools')) @@ -119,8 +120,10 @@ def code(name, form): class Probe(G.Stage): - """A Stage with no pipeline: enough state for decoded instructions to be translated. It is a pixel stage (wave32) - unless a test sets `kind` and `pipe.group`.""" + """A Stage with no pipeline: enough state for decoded instructions to be translated. It is a compute stage of + one 32-lane group (proven wave32) unless a test sets `kind` and `pipe.group`.""" + kind = 'cs' + pipe = SimpleNamespace(group=(32, 1, 1)) def __init__(self): self.lines, self.sym = [], {} diff --git a/tools/startup/gfx2hlsl.py b/tools/startup/gfx2hlsl.py index a9a42025a5..e09d4212dd 100644 --- a/tools/startup/gfx2hlsl.py +++ b/tools/startup/gfx2hlsl.py @@ -4693,12 +4693,13 @@ def mask_source(tok): r and r[0] == 's' and r[1] == r[2] and r[1] in self.masks) sgpr_dest = bool(dst) and dst[0] == 's' and dst[1] == dst[2] and dst[1] <= 105 # A write to exec_lo leaves lanes 32..63 alone, so it is exact only where the wave is proven wave32: - # a pixel stage, or compute with at most 32 threads per group (as the b32 waterfall close requires). - # Other stages (the slot 57 mesh stage is wave64) keep refusing it. - kind = getattr(self, 'kind', 'ps') # a bare test probe has no pipeline and stands for a pixel stage + # compute with at most 32 threads per group (as the b32 waterfall close requires). The wave size of a + # pixel or vertex stage is unknown here (see require_spill_lanes_apart) and the slot 57 mesh stage is + # wave64, so those keep refusing it. group = getattr(getattr(self, 'pipe', None), 'group', None) - wave32_stage = kind == 'ps' or (kind == 'cs' and group is not None and group[0] * group[1] * group[2] <= 32) - exec_dest = (dname == 'exec_lo' and base in ('s_nand_b32', 's_nor_b32') and wave32_stage) + wave32_stage = (getattr(self, 'kind', None) == 'cs' and group is not None + and group[0] * group[1] * group[2] <= 32) + exec_dest = dname == 'exec_lo' and base in ('s_nand_b32', 's_nor_b32') and wave32_stage lane_complement = (word_complement and (sgpr_dest or exec_dest) and all(mask_source(t) for t in (ops[1:] if exec_dest else srcs))) if not lane_complement and (mask_dest or any(self.is_lane_mask(t) for t in srcs)):