From d396dbbb41d61dbc382393788096ea2e5ee41bdb Mon Sep 17 00:00:00 2001 From: tedin7 Date: Thu, 26 Nov 2026 04:47:40 +0100 Subject: [PATCH 1/5] feat: accept mask-preserving writes of a lane mask in an s_cbranch_execz block phi_mask_ok now also accepts s_andn2 M,M,exec_lo and s_or M,M,T with T exec-masked (any M), a v_cmp into M when M was zeroed, and s_orn2 M,X,exec_lo when M was all ones before the branch. Adds partial-wave dispatch cases P and Q, controls, refusal controls and an exhaustive 4-lane check. --- CMakeLists.txt | 3 +- tests/startup_gfx2hlsl_compute_check.py | 104 ++++++++++++++++++++++++ tools/startup/gfx2hlsl.py | 102 +++++++++++++++++------ 3 files changed, 184 insertions(+), 25 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 237531e302..15619116aa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4126,7 +4126,8 @@ if(EXISTS "${INTAKE_PYTHON}") "$" ${adapter}) set_tests_properties(startup_gfx2hlsl_compute_mbcnt_${adapter} PROPERTIES TIMEOUT 120 SKIP_RETURN_CODE 77) foreach(control IN ITEMS swapped-axes dropped-store b-offset c-unpredicated f-peer f-broadcast g-swapped-offsets g-overlap - j-scalar-dropped h-inner-unpredicated k-block-entered m-else-unswitched n-dropped-broadcast) + j-scalar-dropped h-inner-unpredicated k-block-entered m-else-unswitched n-dropped-broadcast + p-dropped-andn2 p-dropped-or p-block-entered q-block-entered q-not-all-ones) add_test(NAME startup_gfx2hlsl_compute_${control}_${adapter} COMMAND "${INTAKE_PYTHON}" -B "${CMAKE_SOURCE_DIR}/tests/startup_gfx2hlsl_compute_check.py" control ${control} "${DXC_EXECUTABLE}" "$" ${adapter}) diff --git a/tests/startup_gfx2hlsl_compute_check.py b/tests/startup_gfx2hlsl_compute_check.py index 82b5921ec2..04417ceb9b 100644 --- a/tests/startup_gfx2hlsl_compute_check.py +++ b/tests/startup_gfx2hlsl_compute_check.py @@ -46,6 +46,7 @@ and Y group IDs at entry, drop the store, drop case B's immediate offset, drop case C's exec predicate, or drop a scalar statement inside case J's block; each must change the readback. """ +import itertools import struct import subprocess import sys @@ -242,6 +243,49 @@ def tidig(components): SOURCE_K = SOURCE_J.replace('v_cmp_gt_u32 vcc_lo, 3, v0\n', 'v_mov_b32 v6, s7\nv_cmp_eq_u32_e32 vcc_lo, 1, v6\n') WORDS_K = WORDS_J.replace(bytes.fromhex('8300887d'), bytes.fromhex('07020c7e' '810c847d')) +# Case P is the compiler's i1 phi with a per-lane old value (a blend). M (s23) holds lanes tid.x < 4 before the branch; the +# block, entered by lanes tid.x < 3 * group, clears M for the lanes it runs (s_andn2 with exec) and ORs in the odd lanes +# (a compare masked with exec); the lane select after the join reads M per lane. Group 0 skips the block with the whole +# wave, groups 1 and 2 enter with a partial wave (3 and 6 lanes) and group 3 with all of it. Case Q is the same with M set +# to all ones before the branch and `s_orn2 M, C, exec_lo` in the block. +SOURCE_P = """\ +s_mov_b32 s10, s6 +s_mov_b32 s11, 0 +s_load_dwordx8 s[12:19], s[10:11], 0x0 +s_waitcnt lgkmcnt(0) +s_lshl_b32 s20, s7, 3 +v_add_nc_u32 v3, s20, v0 +v_lshlrev_b32 v4, 2, v3 +buffer_load_dword v5, v4, s[12:15], 0 offen +s_waitcnt vmcnt(0) +s_mul_i32 s24, s7, 3 +v_cmp_gt_u32 s23, 4, v0 +s_mov_b32 s21, exec_lo +v_cmp_gt_u32 vcc_lo, s24, v0 +s_mov_b32 exec_lo, vcc_lo +s_cbranch_execz 5 +s_andn2_b32 s23, s23, exec_lo +v_and_b32 v6, 1, v0 +v_cmp_ne_u32 vcc_lo, 0, v6 +s_and_b32 s22, vcc_lo, exec_lo +s_or_b32 s23, s23, s22 +s_mov_b32 exec_lo, s21 +v_not_b32 v6, v5 +v_cndmask_b32 v7, v5, v6, s23 +buffer_store_dword v7, v4, s[16:19], 0 offen +s_endpgm +""" +WORDS_P = bytes.fromhex( + '06038abe' '80038bbe' '05030cf4000000fa' '7fc08cbf' '0783148f' '1400064a' '82060834' '001030e004050380' '703f8cbf' + '07831893' '1700c4d484000200' '7e0395be' '1800887d' '6a03febe' '050088bf' '177e178a' '81000c36' '800c8a7d' + '6a7e1687' '17161788' '1503febe' '056f0c7e' '070001d5050d5e00' '001070e004070480' '000081bf') +SOURCE_Q = (SOURCE_P.replace('v_cmp_gt_u32 s23, 4, v0\n', 's_mov_b32 s23, -1\n').replace('s_cbranch_execz 5', 's_cbranch_execz 3') + .replace('s_andn2_b32 s23, s23, exec_lo\n', '') + .replace('s_and_b32 s22, vcc_lo, exec_lo\ns_or_b32 s23, s23, s22\n', 's_orn2_b32 s23, vcc_lo, exec_lo\n')) +WORDS_Q = (WORDS_P.replace(bytes.fromhex('1700c4d484000200'), bytes.fromhex('c10397be')) + .replace(bytes.fromhex('050088bf'), bytes.fromhex('030088bf')).replace(bytes.fromhex('177e178a'), b'') + .replace(bytes.fromhex('6a7e168717161788'), bytes.fromhex('6a7e178b'))) + # Case M is case H with the nested if as an if/else. Each arm has its own s_cbranch_execz; the then arm stores the # first word, s_andn2_b32 of the saved mask switches to the else arm, which stores the second, and s_mov_b32 # restores the saved mask. @@ -460,6 +504,8 @@ def saveexec_fixture(): 'H': (SOURCE_H, WORDS_H, USER7 | TGID_X | tidig(1), (8, 1, 1), (4, 1, 1)), 'M': (SOURCE_M, WORDS_M, USER7 | TGID_X | tidig(1), (8, 1, 1), (4, 1, 1)), 'K': (SOURCE_K, WORDS_K, USER7 | TGID_X | tidig(1), (8, 1, 1), (4, 1, 1)), + 'P': (SOURCE_P, WORDS_P, USER7 | TGID_X | tidig(1), (8, 1, 1), (4, 1, 1)), + 'Q': (SOURCE_Q, WORDS_Q, USER7 | TGID_X | tidig(1), (8, 1, 1), (4, 1, 1)), 'G': (SOURCE_G, WORDS_G, USER7 | TGID_X | (1 << 15), (64, 1, 1), (2, 1, 1)), **{name: (SOURCE_L, WORDS_L, USER7, (16, 1, 1), (1, 1, 1)) for name in L_WORD3}, 'N': (SOURCE_N, WORDS_N, USER7 | tidig(1), (16, 1, 1), (1, 1, 1)), @@ -710,6 +756,11 @@ def expected(name): i = (gx + 3 * gy + 6 * gz) * 24 + tx + 2 * ty + 6 * tz stride = 0 if name == 'A-ff1' else STRIDE out[i] = ((input_word(i) * 33) & MASK) ^ ((KEY + i * stride) & MASK) + elif name in ('P', 'Q'): + i = gx * 8 + tx + old = 1 if name == 'Q' else int(tx < 4) + mask = (tx & 1) if tx < 3 * gx else old # the block's lanes take the compare, others keep M + out[i] = ~input_word(i) & MASK if mask else input_word(i) elif name == 'K': i = gx * 8 + tx if gx == 1: # only group 1's wave enters the block @@ -1037,6 +1088,24 @@ def lines(*code): refused('buffer store off with data not proven wave-uniform', lambda code=code: lines(*code)) +def check_execz_mask_exact(): + """Exhaustive 4-lane wave: the one-lane model of an s_cbranch_execz block (a lane with exec clear skips it) leaves a + skipped lane's mask bit as M held it; the wave runs the block whenever any lane is active. Which block writes keep + that bit: preserving ones always, a compare / exec-masked move only if M was 0, an s_orn2 with exec only if M was 1s.""" + full = 15 + writes = {'cmp': lambda m, e, c: c & e, 'mov_exec': lambda m, e, c: e, 'andn2': lambda m, e, c: m & ~e & full, + 'blend': lambda m, e, c: (m & ~e & full) | (c & e), 'or_cmp': lambda m, e, c: m | (c & e), + 'orn2': lambda m, e, c: (c | ~e) & full} + for name, write in writes.items(): + bad = set() + for m, e, c in itertools.product(range(16), repeat=3): + wave = write(m, e, c) if e else m + if any(((wave ^ m) >> lane) & 1 for lane in range(4) if not (e >> lane) & 1): + bad.add(m) + want = {'cmp': set(range(1, 16)), 'mov_exec': set(range(1, 16)), 'orn2': set(range(15))}.get(name, set()) + assert bad == want, (name, sorted(bad)) + + def check_controls(): carry = translate('address-carry').hlsl_cs() assert 's21 = (scc ? 1u : 0u);' in carry @@ -1117,6 +1186,7 @@ def check_controls(): raise AssertionError('graphics store accepted') check_hand_words() check_off_stores() + check_execz_mask_exact() for name in ('O-dword', 'O-shift'): hlsl = translate(name).hlsl_cs().splitlines() assert any('u0.Store' in line for line in hlsl), (name, hlsl) @@ -1447,6 +1517,35 @@ def phi(zero, write, read, between=(), inside=()): ['s_cmp_eq_u32 s20, 0'] + cnd_s))) refused(live('s20'), lambda: phi_text(phi(['s_mov_b32 s20, 0'], ['s_mov_b32 s20, exec_lo'], ['s_mov_b32 s7, s20'] + cnd_s))) + # A block that leaves the mask bit of a lane it skips unchanged is exact whatever M held before the branch: + # `s_andn2 M, M, exec_lo` and `s_or M, M, T` with T exec-masked in the block (the compiler's i1 phi with a + # per-lane old value). A compare into M, or an s_orn2 with exec, changes a skipped lane's bit: accepted only + # when M was zeroed (compare) or set to all ones (orn2) before the branch. + SPLICE.update({'s_andn2_b32 s20, s20, exec_lo': '147e148a', 's_andn2_b32 vcc_lo, vcc_lo, exec_lo': '6a7e6a8a', + 's_and_b32 s22, s7, exec_lo': '077e1687', 's_and_b32 s22, s7, s7': '07071687', + 's_or_b32 s20, s20, s22': '14161488', 's_or_b32 vcc_lo, vcc_lo, s22': '6a166a88', + 's_or_b32 s20, s20, s7': '14071488', 's_andn2_b32 s20, s7, exec_lo': '077e148a', + 's_orn2_b32 s20, s7, exec_lo': '077e148b', 'v_cmp_gt_u32 vcc_lo, 3, v0': '8300887d'}) + blend = ['s_andn2_b32 s20, s20, exec_lo', 's_and_b32 s22, s7, exec_lo', 's_or_b32 s20, s20, s22'] + for write, read in ((blend, cnd_s), (blend[:1], cnd_s), + (['s_andn2_b32 vcc_lo, vcc_lo, exec_lo', 's_and_b32 s22, s7, exec_lo', + 's_or_b32 vcc_lo, vcc_lo, s22'], cnd_vcc)): + phi_text(phi([], write, read)) + phi_text(phi(['s_mov_b32 vcc_lo, 0'], ['v_cmp_gt_u32 vcc_lo, 3, v0'], cnd_vcc)) # compare into a zeroed M + phi_text(phi(['s_mov_b32 s20, -1'], ['s_orn2_b32 s20, s7, exec_lo'], cnd_s)) # orn2 into an all-ones M + # controls: the same writes without their set-up, an unmasked term, M not the first source, mixed classes, + # and a whole-mask read after a preserving block + refused(live('vcc'), lambda: phi_text(phi([], ['v_cmp_gt_u32 vcc_lo, 3, v0'], cnd_vcc))) + refused(live('vcc'), lambda: phi_text(phi(['s_mov_b32 vcc_lo, -1'], ['v_cmp_gt_u32 vcc_lo, 3, v0'], cnd_vcc))) + for zero in ([], ['s_mov_b32 s20, 0']): + refused(live('s20'), lambda zero=zero: phi_text(phi(zero, ['s_orn2_b32 s20, s7, exec_lo'], cnd_s))) + refused(live('s20'), lambda: phi_text(phi(['s_mov_b32 s20, -1'], ['s_mov_b32 s20, exec_lo'], cnd_s))) + refused(live('s20'), lambda: phi_text(phi(['s_mov_b32 s20, 0'], ['s_mov_b32 s20, exec_lo', 's_orn2_b32 s20, s7, exec_lo'], cnd_s))) + refused(live('s20'), lambda: phi_text(phi([], [blend[0], 's_or_b32 s20, s20, s7'], cnd_s))) + refused(live('s20'), lambda: phi_text(phi([], [blend[0], 's_and_b32 s22, s7, s7', blend[2]], cnd_s))) + refused(live('s20'), lambda: phi_text(phi([], ['s_andn2_b32 s20, s7, exec_lo'], cnd_s))) + for read in (['s_cmp_eq_u32 s20, 0'] + cnd_s, ['s_mov_b32 s7, s20'] + cnd_s): + refused(live('s20'), lambda read=read: phi_text(phi([], blend, read))) # An implicit-LOD sample has no derivatives in a compute lane; the level-zero form translates. load = ('s_mov_b64 s[20:21], 0', 's_mov_b64 s[22:23], 0', 's_load_dwordx8 s[24:31], s[10:11], 0x40') sample = 'image_sample v[12:15], v[0:1], s[24:31], s[20:23] dmask:0xf dim:SQ_RSRC_IMG_2D' @@ -1501,6 +1600,11 @@ def check_binary(llvm_mc): 'h-inner-unpredicated': ('H', 'if (exec & 1) u0.Store(a, v5);', 'u0.Store(a, v5);'), 'm-else-unswitched': ('M', 'exec = (s0 & ~exec) & 1;', 'exec = (s0) & 1;'), # the then lanes run the else arm 'k-block-entered': ('K', 'pc = ((exec & 1) == 0) ? 2 : 1;', 'pc = 1; exec = 1;'), # skipped waves run it + 'p-dropped-andn2': ('P', 's23 = (s23 & ~exec) & 1;', 's23 = (s23) & 1;'), # an entering lane keeps its old bit + 'p-dropped-or': ('P', 's23 = (s23 | s22) & 1;', 's23 = (s23) & 1;'), # an entering lane loses its compare bit + 'p-block-entered': ('P', 'pc = ((exec & 1) == 0) ? 2 : 1;', 'pc = 1; exec = 1;'), # skipping lanes run the block + 'q-block-entered': ('Q', 'pc = ((exec & 1) == 0) ? 2 : 1;', 'pc = 1; exec = 1;'), + 'q-not-all-ones': ('Q', 's23 = 0xffffffffu;', 's23 = 0u;'), # M not set before the branch: skipped lanes read 0 'g-swapped-offsets': ('G', 'v6 = lds[(a + 20u) >> 2];\n v7 = lds[(a + 144u) >> 2];', 'v6 = lds[(a + 144u) >> 2];\n v7 = lds[(a + 20u) >> 2];'), 'g-overlap': ('G', 'v7 = lds[(a + 144u)', 'v7 = lds[(v6 + 144u)'), diff --git a/tools/startup/gfx2hlsl.py b/tools/startup/gfx2hlsl.py index ab5eed675e..ce0cfa5c1c 100644 --- a/tools/startup/gfx2hlsl.py +++ b/tools/startup/gfx2hlsl.py @@ -2508,7 +2508,12 @@ def execz_refusals(self): whose bit is 0 for any lane whose exec bit is clear there: the clear-mask proof keeps exec clear for that lane, and a copy of exec, or X & exec, has that bit clear. M is 0 at the branch on every path (nothing branches or lands between the zeroing and the branch). So for a lane the model skips, the wave's M has that lane's bit 0 whether the wave ran the block or not, which is the - model's M (0); a lane that runs the block runs it in the model too. This holds only while M is read per + model's M (0); a lane that runs the block runs it in the model too. Writes that leave a skipped lane's bit + as it was are accepted for any M: `s_andn2_b32 M, M, exec_lo` and `s_or_b32 M, M, T` where T is an exec-masked + value computed in the block (`s_and_b32 T, X, exec_lo` or a v_cmp result), the blend the compiler emits for an + i1 phi whose other input is a per-lane value. A v_cmp into M (not v_cmpx) needs M zeroed before the branch + like the moves above, and `s_orn2_b32 M, X, exec_lo` needs M set to all ones (`s_mov_b32 M, -1`). Zeroing + and all-ones writes do not mix. This holds only while M is read per lane. A whole-mask read (s_cbranch_vccz/vccnz, s_cmp, a plain copy, a data operand) sees the other lanes' bits, which the one-lane model does not have, so any such read of M reachable after the join, before M is rewritten, keeps the refusal. The reads accepted are the lane select of v_cndmask, the carry-in of v_addc / @@ -2673,34 +2678,52 @@ def waterfall_refusal(self, head, close, effects, live_in, jumps): return None def phi_mask_ok(self, key, b, t, effects, succ, targets, index): - """True when lane mask `key` ('vcc' for vcc_lo, or 'sN'), live at the join t of the s_cbranch_execz at b, is - the zeroed-then-set-from-exec shape execz_refusals accepts (see its docstring): every write of it in the - block is a 32-bit move of exec_lo or an s_and with exec_lo into it alone, the last write before the branch - is `s_mov_b32 M, 0` with no branch and no branch target after it up to the branch, and after the join it is - only read per lane. The caller has checked that the block is straight-line.""" + """True when lane mask `key` ('vcc' for vcc_lo, or 'sN'), live at the join t of the s_cbranch_execz at b, leaves the + bit of every lane the model skips as the wave has it (see execz_refusals), and after the join it is only read per + lane. A lane the model skips has its exec bit clear for the whole block (the exec proof), and the wave runs the block + iff some lane is active, so the model is exact iff the block never changes that lane's bit of M. Every write of M + in the block is one of (mask_write_class), a 32-bit M written alone: + 'keep' s_andn2 M, M, exec_lo; s_or M, M, T with T written in the block by s_and with exec_lo or a v_cmp + (bit 0 for a lane whose exec bit is clear): the lane's bit is unchanged, whatever M held before. + 'zero' s_mov M, exec_lo; s_and M, X, exec_lo; a v_cmp into M (VOPC writes 0 for an inactive lane): bit 0, + exact only when M was zero before the branch: the last write before it is `s_mov_b32 M, 0`. + 'ones' s_orn2 M, X, exec_lo: bit 1, exact only when M was all ones before it: `s_mov_b32 M, -1`. + Zeroing or setting M before the branch needs no branch and no branch target after it up to the branch; 'zero' and + 'ones' writes do not mix. Any other write (M reused as an offset) is accepted only if a later 'zero' or 'ones' + write overwrites it, since a 'keep' write would carry its bits for a skipped lane. The caller has checked that the block is straight-line.""" name = 'vcc_lo' if key == 'vcc' else key + classes, temps, stale = set(), set(), False for i in range(b + 1, t): - if key not in effects[i][2]: - continue + wrote = effects[i][2] _, ops, _ = parse(self.ins[i][3]) base = re.sub(r'_e(32|64)$', '', self.ins[i][2]) - if not ops or ops[0] != name: - return False - if base == 's_mov_b32' and ops[1:] == ['exec_lo']: - continue - if base == 's_and_b32' and len(ops) == 3 and 'exec_lo' in ops[1:]: - continue - return False - # The zeroing: the last instruction before the branch that may write M. - z = next((k for k in range(b - 1, -1, -1) if key in effects[k][2]), None) - if z is None: - return False - _, ops, _ = parse(self.ins[z][3]) - if self.ins[z][2] != 's_mov_b32' or ops != [name, '0']: - return False - if any(self.ins[k][2].startswith(('s_cbranch', 's_branch', 's_setpc')) for k in range(z + 1, b)) or \ - any(index.get(x) in range(z + 1, b + 1) for x in targets): + if key in wrote: + if not ops or ops[0] != name: + return False + kind = self.mask_write_class(base, ops, name, temps) + if kind is None: + stale = True # data in M (an s_movk used as an offset): only a later full overwrite makes it exact + else: + classes.add(kind) + stale = stale and kind == 'keep' + for w in wrote - {key} - EXEC_KEYS: + if self.exec_masked_def(base, ops, w): + temps.add(w) + else: + temps.discard(w) + if stale or ('zero' in classes and 'ones' in classes): return False + need = {'zero': '0', 'ones': '-1'}.get(next(iter(classes & {'zero', 'ones'}), None)) + if need is not None: + # The setting: the last instruction before the branch that may write M. + z = next((k for k in range(b - 1, -1, -1) if key in effects[k][2]), None) + if z is None: + return False + _, ops, _ = parse(self.ins[z][3]) + if self.ins[z][2] not in ('s_mov_b32', 's_movk_i32') or ops != [name, need]: + return False + if any(self.ins[k][2].startswith(('s_cbranch', 's_branch', 's_setpc')) for k in range(z + 1, b)) or any(index.get(x) in range(z + 1, b + 1) for x in targets): + return False # After the join, until M is rewritten, every read must be per lane. seen, todo = set(), [t] while todo: @@ -2715,6 +2738,37 @@ def phi_mask_ok(self, key, b, t, effects, succ, targets, index): todo.extend(succ[i]) return True + @staticmethod + def exec_masked_def(base, ops, key): + """True when this instruction writes `key` ('sN' or 'vcc') with a value whose bit is 0 for a lane whose exec bit is + clear: s_and with exec_lo into it, or a v_cmp (not v_cmpx) into it.""" + name = 'vcc_lo' if key == 'vcc' else key + if not ops or ops[0] != name: + return False + if base == 's_and_b32': + return len(ops) == 3 and 'exec_lo' in ops[1:] + return base.startswith('v_cmp') and not base.startswith('v_cmpx') + + @staticmethod + def mask_write_class(base, ops, name, temps): + """'keep', 'zero' or 'ones' for a write of mask `name` inside an execz block (see phi_mask_ok), else None.""" + key = 'vcc' if name == 'vcc_lo' else name + if base == 's_mov_b32' and ops[1:] == ['exec_lo']: + return 'zero' + if base == 's_and_b32' and len(ops) == 3 and 'exec_lo' in ops[1:]: + return 'zero' + if base.startswith('v_cmp') and not base.startswith('v_cmpx'): + return 'zero' + if base == 's_orn2_b32' and len(ops) == 3 and ops[2] == 'exec_lo': + return 'ones' + if base == 's_andn2_b32' and ops == [name, name, 'exec_lo']: + return 'keep' + if base == 's_or_b32' and len(ops) == 3 and name in ops[1:]: + other = ops[2] if ops[1] == name else ops[1] + if other != name and ('vcc' if other == 'vcc_lo' else other) in temps: + return 'keep' + return None + def per_lane_read(self, i, key): """True when instruction i reads mask `key` only as a lane select or carry, or into exec (s_and_saveexec, s_and with exec): the lane's own bit is all it uses.""" From c08dae5d24451c6298c5ad2cc5fed77cce29b262 Mon Sep 17 00:00:00 2001 From: tedin7 Date: Thu, 26 Nov 2026 05:50:28 +0100 Subject: [PATCH 2/5] fix: require lane-bit inputs for mask-preserving execz writes; document accepted shapes --- docs/experiments.md | 15 ++++++++-- tests/startup_gfx2hlsl_compute_check.py | 36 ++++++++++++++--------- tools/startup/gfx2hlsl.py | 38 +++++++++++++++++++++---- 3 files changed, 69 insertions(+), 20 deletions(-) diff --git a/docs/experiments.md b/docs/experiments.md index 7c6a5415dc..13339be8f6 100644 --- a/docs/experiments.md +++ b/docs/experiments.md @@ -15359,13 +15359,24 @@ be the lane select of `v_cndmask`, the carry-in of `v_addc`, `v_subb`, `v_add_co `s_and_saveexec_b32` / `s_and_b32` with exec. `s_cbranch_vccz`, `s_cbranch_vccnz`, `s_cmp`, a copy of M and M as a data operand see the other lanes' bits, which the one-lane model does not have, and keep the refusal. +The same lane mask is accepted with three more block writes, each exact only under a condition. All of them need +every mask the write uses to hold lane bits (bit 0 is the lane's own bit: a `v_cmp`, an `s_and` with exec, a copy +of exec, or 0 / -1), not data such as a group id or `s_mov_b32 M, 16`, whose lane bit sits at bit `lane` in the wave: +- preserving: `s_andn2_b32 M, M, exec_lo` and `s_or_b32 M, M, T`, with T written in the block by a `v_cmp` or an + `s_and` of exec and a lane mask. A skipped lane keeps its bit, so M needs no zeroing, but M's last write before the + branch must itself hold lane bits (no branch or branch target after it); +- compare: a `v_cmp` (not `v_cmpx`) into M, only when `s_mov_b32 M, 0` is the last write before the branch; +- all ones: `s_orn2_b32 M, X, exec_lo`, X a lane mask, only when `s_mov_b32 M, -1` is the last write before the branch. +Zeroing and all-ones writes do not mix, and any other write of M that no later zeroing or all-ones write overwrites +keeps the refusal. + The block is still refused in these cases: - a definition that is live at the join, unless the absorbed-read or narrowed-mask rule proves every read of it or it is the lane mask above; a lane mask with a failed condition stays refused (zeroing with a value other than 0 or missing, a branch or a branch target between the zeroing and the branch, a write of M that is not - from exec, a `vcc_hi` or 64-bit write, a whole-mask read after the join); + one of the forms above, a `vcc_hi` or 64-bit write, a whole-mask read after the join); - any other exec write: exec set from a compare alone, restored from a mask saved before the block or on only - some of the paths, written by a form the pass does not follow (`s_orn2`, `s_nand`, `s_nor`, `s_xnor`, `s_not`, + some of the paths, written by a form the pass does not follow (`s_orn2` outside the lane mask above, `s_nand`, `s_nor`, `s_xnor`, `s_not`, the other saveexec and wrexec forms), written in a block that a branch from outside enters (a proven calculated `s_setpc_b64` jump counts), or restored from a copy of the other exec half; - an effect outside scalar registers, such as a scalar store or atomic, a barrier, `s_endpgm` or `v_writelane`; diff --git a/tests/startup_gfx2hlsl_compute_check.py b/tests/startup_gfx2hlsl_compute_check.py index 05d91ffa14..8c3258d878 100644 --- a/tests/startup_gfx2hlsl_compute_check.py +++ b/tests/startup_gfx2hlsl_compute_check.py @@ -1718,26 +1718,36 @@ def phi(zero, write, read, between=(), inside=()): 's_or_b32 s20, s20, s22': '14161488', 's_or_b32 vcc_lo, vcc_lo, s22': '6a166a88', 's_or_b32 s20, s20, s7': '14071488', 's_andn2_b32 s20, s7, exec_lo': '077e148a', 's_orn2_b32 s20, s7, exec_lo': '077e148b', 'v_cmp_gt_u32 vcc_lo, 3, v0': '8300887d'}) - blend = ['s_andn2_b32 s20, s20, exec_lo', 's_and_b32 s22, s7, exec_lo', 's_or_b32 s20, s20, s22'] - for write, read in ((blend, cnd_s), (blend[:1], cnd_s), - (['s_andn2_b32 vcc_lo, vcc_lo, exec_lo', 's_and_b32 s22, s7, exec_lo', - 's_or_b32 vcc_lo, vcc_lo, s22'], cnd_vcc)): - phi_text(phi([], write, read)) + # T and M hold lane bits (bit 0 = the lane's bit, the model's encoding): T from a compare, M zeroed before the branch. + # Group-id data (s7) as T, or `s_mov_b32 M, 16` as M, has the wave's lane bit at bit `lane` and is refused. + cmp_t = ['v_cmp_gt_u32 vcc_lo, 3, v0', 's_and_b32 s22, vcc_lo, exec_lo'] + SPLICE.update({'s_and_b32 s22, vcc_lo, exec_lo': '6a7e1687', 's_mov_b32 s20, 16': '9003 94be'.replace(' ', ''), + 's_orn2_b32 s20, vcc_lo, exec_lo': '6a7e148b'}) + blend = ['s_andn2_b32 s20, s20, exec_lo', *cmp_t, 's_or_b32 s20, s20, s22'] + z20, zv = ['s_mov_b32 s20, 0'], ['s_mov_b32 vcc_lo, 0'] + for zero, write, read in ((z20, blend, cnd_s), (z20, blend[:1], cnd_s), + (zv, ['s_andn2_b32 vcc_lo, vcc_lo, exec_lo', 's_and_b32 s22, vcc_lo, exec_lo', + 's_or_b32 vcc_lo, vcc_lo, s22'], cnd_vcc)): + phi_text(phi(zero, write, read)) phi_text(phi(['s_mov_b32 vcc_lo, 0'], ['v_cmp_gt_u32 vcc_lo, 3, v0'], cnd_vcc)) # compare into a zeroed M - phi_text(phi(['s_mov_b32 s20, -1'], ['s_orn2_b32 s20, s7, exec_lo'], cnd_s)) # orn2 into an all-ones M + phi_text(phi(['s_mov_b32 s20, -1'], ['v_cmp_gt_u32 vcc_lo, 3, v0', 's_orn2_b32 s20, vcc_lo, exec_lo'], cnd_s)) # orn2 # controls: the same writes without their set-up, an unmasked term, M not the first source, mixed classes, - # and a whole-mask read after a preserving block + # M or an operand that is not a lane mask, and a whole-mask read after a preserving block refused(live('vcc'), lambda: phi_text(phi([], ['v_cmp_gt_u32 vcc_lo, 3, v0'], cnd_vcc))) refused(live('vcc'), lambda: phi_text(phi(['s_mov_b32 vcc_lo, -1'], ['v_cmp_gt_u32 vcc_lo, 3, v0'], cnd_vcc))) - for zero in ([], ['s_mov_b32 s20, 0']): + for zero in ([], z20): refused(live('s20'), lambda zero=zero: phi_text(phi(zero, ['s_orn2_b32 s20, s7, exec_lo'], cnd_s))) + refused(live('s20'), lambda: phi_text(phi(['s_mov_b32 s20, -1'], ['s_orn2_b32 s20, s7, exec_lo'], cnd_s))) refused(live('s20'), lambda: phi_text(phi(['s_mov_b32 s20, -1'], ['s_mov_b32 s20, exec_lo'], cnd_s))) - refused(live('s20'), lambda: phi_text(phi(['s_mov_b32 s20, 0'], ['s_mov_b32 s20, exec_lo', 's_orn2_b32 s20, s7, exec_lo'], cnd_s))) - refused(live('s20'), lambda: phi_text(phi([], [blend[0], 's_or_b32 s20, s20, s7'], cnd_s))) - refused(live('s20'), lambda: phi_text(phi([], [blend[0], 's_and_b32 s22, s7, s7', blend[2]], cnd_s))) - refused(live('s20'), lambda: phi_text(phi([], ['s_andn2_b32 s20, s7, exec_lo'], cnd_s))) + refused(live('s20'), lambda: phi_text(phi(z20, ['s_mov_b32 s20, exec_lo', 's_orn2_b32 s20, s7, exec_lo'], cnd_s))) + refused(live('s20'), lambda: phi_text(phi(z20, [blend[0], *cmp_t, 's_or_b32 s20, s20, s7'], cnd_s))) + refused(live('s20'), lambda: phi_text(phi(z20, [blend[0], 's_and_b32 s22, s7, exec_lo', blend[3]], cnd_s))) + refused(live('s20'), lambda: phi_text(phi(z20, [blend[0], 's_and_b32 s22, s7, s7', blend[3]], cnd_s))) + refused(live('s20'), lambda: phi_text(phi(z20, ['s_andn2_b32 s20, s7, exec_lo'], cnd_s))) + refused(live('s20'), lambda: phi_text(phi([], blend, cnd_s))) # M unknown before the block + refused(live('s20'), lambda: phi_text(phi(['s_mov_b32 s20, 16'], blend, cnd_s))) # M holds data, not lane bits for read in (['s_cmp_eq_u32 s20, 0'] + cnd_s, ['s_mov_b32 s7, s20'] + cnd_s): - refused(live('s20'), lambda read=read: phi_text(phi([], blend, read))) + refused(live('s20'), lambda read=read: phi_text(phi(z20, blend, read))) # An implicit-LOD sample has no derivatives in a compute lane; the level-zero form translates. load = ('s_mov_b64 s[20:21], 0', 's_mov_b64 s[22:23], 0', 's_load_dwordx8 s[24:31], s[10:11], 0x40') sample = 'image_sample v[12:15], v[0:1], s[24:31], s[20:23] dmask:0xf dim:SQ_RSRC_IMG_2D' diff --git a/tools/startup/gfx2hlsl.py b/tools/startup/gfx2hlsl.py index 5a484f36ff..e6e2b31f1b 100644 --- a/tools/startup/gfx2hlsl.py +++ b/tools/startup/gfx2hlsl.py @@ -2795,7 +2795,8 @@ def phi_mask_ok(self, key, b, t, effects, succ, targets, index): bit of every lane the model skips as the wave has it (see execz_refusals), and after the join it is only read per lane. A lane the model skips has its exec bit clear for the whole block (the exec proof), and the wave runs the block iff some lane is active, so the model is exact iff the block never changes that lane's bit of M. Every write of M - in the block is one of (mask_write_class), a 32-bit M written alone: + in the block is one of (mask_write_class), a 32-bit M written alone. Every mask it uses must hold lane bits + (lane_bit_keys, or a block temp): the model keeps a lane's bit at bit 0 where the wave has it at bit `lane`: 'keep' s_andn2 M, M, exec_lo; s_or M, M, T with T written in the block by s_and with exec_lo or a v_cmp (bit 0 for a lane whose exec bit is clear): the lane's bit is unchanged, whatever M held before. 'zero' s_mov M, exec_lo; s_and M, X, exec_lo; a v_cmp into M (VOPC writes 0 for an inactive lane): bit 0, @@ -2806,6 +2807,7 @@ def phi_mask_ok(self, key, b, t, effects, succ, targets, index): write overwrites it, since a 'keep' write would carry its bits for a skipped lane. The caller has checked that the block is straight-line.""" name = 'vcc_lo' if key == 'vcc' else key classes, temps, stale = set(), set(), False + enc = self.lane_bit_keys(b, effects, targets, index) for i in range(b + 1, t): wrote = effects[i][2] _, ops, _ = parse(self.ins[i][3]) @@ -2813,19 +2815,25 @@ def phi_mask_ok(self, key, b, t, effects, succ, targets, index): if key in wrote: if not ops or ops[0] != name: return False - kind = self.mask_write_class(base, ops, name, temps) + kind = self.mask_write_class(base, ops, name, temps, enc) if kind is None: stale = True # data in M (an s_movk used as an offset): only a later full overwrite makes it exact else: classes.add(kind) stale = stale and kind == 'keep' for w in wrote - {key} - EXEC_KEYS: - if self.exec_masked_def(base, ops, w): + # T must also hold lane bits: an s_and of exec with a lane mask (not with a group id or other data) + lane_src = base != 's_and_b32' or any( + ('vcc' if x == 'vcc_lo' else x) in temps | enc for x in ops[1:] if x != 'exec_lo') + if self.exec_masked_def(base, ops, w) and lane_src: temps.add(w) else: temps.discard(w) + enc.discard(w) if stale or ('zero' in classes and 'ones' in classes): return False + if 'keep' in classes and key not in self.lane_bit_keys(b, effects, targets, index): + return False # M's bits before the block must already be lane bits (bit 0 = this lane), not data need = {'zero': '0', 'ones': '-1'}.get(next(iter(classes & {'zero', 'ones'}), None)) if need is not None: # The setting: the last instruction before the branch that may write M. @@ -2851,6 +2859,25 @@ def phi_mask_ok(self, key, b, t, effects, succ, targets, index): todo.extend(succ[i]) return True + def lane_bit_keys(self, b, effects, targets, index): + """Keys ('vcc' or 'sN') whose value at the s_cbranch_execz at b holds the lane's own bit as bit 0, the encoding the + one-lane model gives a lane mask: the last write before b is a v_cmp, an s_and with exec_lo, a copy of exec_lo, or + 0 / -1 (every bit alike), with no branch or branch target between it and b. A value from anywhere else (a group id, + an offset, `s_mov_b32 M, 16`) has the wave's lane bit at bit `lane`, which the model reads from bit 0.""" + found, seen = set(), set() + for k in range(b - 1, -1, -1): + if self.ins[k][2].startswith(('s_cbranch', 's_branch', 's_setpc')) or any(index.get(x) == k + 1 for x in targets): + break + _, ops, _ = parse(self.ins[k][3]) + base = re.sub(r'_e(32|64)$', '', self.ins[k][2]) + for w in effects[k][2] - EXEC_KEYS - seen: + seen.add(w) + name = 'vcc_lo' if w == 'vcc' else w + if self.exec_masked_def(base, ops, w) or (base in ('s_mov_b32', 's_movk_i32') and ops == [name, 'exec_lo']) or \ + (base in ('s_mov_b32', 's_movk_i32') and len(ops) == 2 and ops[0] == name and ops[1] in ('0', '-1')): + found.add(w) + return found + @staticmethod def exec_masked_def(base, ops, key): """True when this instruction writes `key` ('sN' or 'vcc') with a value whose bit is 0 for a lane whose exec bit is @@ -2863,16 +2890,17 @@ def exec_masked_def(base, ops, key): return base.startswith('v_cmp') and not base.startswith('v_cmpx') @staticmethod - def mask_write_class(base, ops, name, temps): + def mask_write_class(base, ops, name, temps, enc=frozenset()): """'keep', 'zero' or 'ones' for a write of mask `name` inside an execz block (see phi_mask_ok), else None.""" key = 'vcc' if name == 'vcc_lo' else name if base == 's_mov_b32' and ops[1:] == ['exec_lo']: return 'zero' + lane = lambda x: ('vcc' if x == 'vcc_lo' else x) in temps | enc # a lane mask: bit 0 is this lane's bit if base == 's_and_b32' and len(ops) == 3 and 'exec_lo' in ops[1:]: return 'zero' if base.startswith('v_cmp') and not base.startswith('v_cmpx'): return 'zero' - if base == 's_orn2_b32' and len(ops) == 3 and ops[2] == 'exec_lo': + if base == 's_orn2_b32' and len(ops) == 3 and ops[2] == 'exec_lo' and lane(ops[1]): return 'ones' if base == 's_andn2_b32' and ops == [name, name, 'exec_lo']: return 'keep' From 94c692b4d209249377f955f77805394133591636 Mon Sep 17 00:00:00 2001 From: tedin7 Date: Thu, 26 Nov 2026 05:57:23 +0100 Subject: [PATCH 3/5] fix: require a lane mask as the exec-masked operand of s_and in an execz block --- tests/startup_gfx2hlsl_compute_check.py | 12 +++++++++--- tools/startup/gfx2hlsl.py | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/tests/startup_gfx2hlsl_compute_check.py b/tests/startup_gfx2hlsl_compute_check.py index 8c3258d878..6370988333 100644 --- a/tests/startup_gfx2hlsl_compute_check.py +++ b/tests/startup_gfx2hlsl_compute_check.py @@ -1661,16 +1661,22 @@ def phi(zero, write, read, between=(), inside=()): return splice(*enter, *zero, *between, 's_cbranch_execz %d' % (len(write) + len(inside)), *write, *inside, *leave, *read) phi_text = lambda code: translate('A', code=code).hlsl_cs() + SPLICE.update({'s_and_b32 s20, exec_lo, vcc_lo': '7e6a1487'}) cnd_vcc, cnd_s = ['v_cndmask_b32 v5, v5, v6, vcc_lo'], ['v_cndmask_b32 v5, v5, v6, s20'] for zero, write, read in ((['s_mov_b32 vcc_lo, 0'], ['s_mov_b32 vcc_lo, exec_lo'], cnd_vcc), (['s_mov_b32 s20, 0'], ['s_mov_b32 s20, exec_lo'], cnd_s), - (['s_mov_b32 vcc_lo, 0'], ['s_and_b32 vcc_lo, s7, exec_lo'], cnd_vcc), - (['s_mov_b32 s20, 0'], ['s_and_b32 s20, s7, exec_lo'], cnd_s), - (['s_mov_b32 s20, 0'], ['s_and_b32 s20, exec_lo, s7'], cnd_s)): + (['s_mov_b32 vcc_lo, 0'], ['v_cmp_gt_u32 vcc_lo, 3, v0', 's_and_b32 vcc_lo, vcc_lo, exec_lo'], cnd_vcc), + (['s_mov_b32 s20, 0'], ['v_cmp_gt_u32 vcc_lo, 3, v0', 's_and_b32 s20, vcc_lo, exec_lo'], cnd_s), + (['s_mov_b32 s20, 0'], ['v_cmp_gt_u32 vcc_lo, 3, v0', 's_and_b32 s20, exec_lo, vcc_lo'], cnd_s)): text = phi_text(phi(zero, write, read)) # the lane select reads the mask's lane bit, which the block set from exec (the model runs the block for # every lane it models, and skips it only where exec is clear, leaving the zeroing) assert '& 1) ? ' in text and ('vcc = (exec) & 1;' in text or 's20 = ' in text), text + # an s_and of exec with data (a group id) is not a lane mask: its lane bit is at bit `lane` in the wave + for write in (['s_and_b32 vcc_lo, s7, exec_lo'], ['s_and_b32 s20, s7, exec_lo']): + refused('definition of ' + ('vcc' if 'vcc_lo, s7' in write[0] else 's20') + ', live where the block joins', + lambda write=write: phi_text(phi(['s_mov_b32 %s, 0' % ('vcc_lo' if 'vcc_lo, s7' in write[0] else 's20')], + write, cnd_vcc if 'vcc_lo, s7' in write[0] else cnd_s))) # s_and with exec reads the lane bit only (the result is a lane mask): accepted phi_text(phi(['s_mov_b32 vcc_lo, 0'], ['s_mov_b32 vcc_lo, exec_lo'], ['s_and_b32 s20, vcc_lo, exec_lo'] + cnd_vcc)) # so does s_and_saveexec with the mask as its source (exec &= the lane bit); with the mask as its destination diff --git a/tools/startup/gfx2hlsl.py b/tools/startup/gfx2hlsl.py index e6e2b31f1b..f147f69f32 100644 --- a/tools/startup/gfx2hlsl.py +++ b/tools/startup/gfx2hlsl.py @@ -2896,7 +2896,7 @@ def mask_write_class(base, ops, name, temps, enc=frozenset()): if base == 's_mov_b32' and ops[1:] == ['exec_lo']: return 'zero' lane = lambda x: ('vcc' if x == 'vcc_lo' else x) in temps | enc # a lane mask: bit 0 is this lane's bit - if base == 's_and_b32' and len(ops) == 3 and 'exec_lo' in ops[1:]: + if base == 's_and_b32' and len(ops) == 3 and 'exec_lo' in ops[1:] and lane(ops[2] if ops[1] == 'exec_lo' else ops[1]): return 'zero' if base.startswith('v_cmp') and not base.startswith('v_cmpx'): return 'zero' From 94e7991c8dfba39a77a90454712e73c0733779c8 Mon Sep 17 00:00:00 2001 From: c1 Date: Thu, 26 Nov 2026 07:49:02 +0100 Subject: [PATCH 4/5] fix: bump shader cache revision to 21, add mixed-class and andn2 controls for execz mask writes The change refuses a compute form main translated, so cached compute HLSL must be re-keyed. Adds a zero+ones mix control and an s_andn2 M, M, vcc_lo refusal (both mutants now fail), docs wording and a line continuation fix. --- docs/experiments.md | 6 +++--- src/startup_stubs/d3d12_draw.inl | 4 ++-- tests/startup_compute_request_offline_check.py | 4 ++-- tests/startup_gfx2hlsl_buffer_store_check.py | 2 +- tests/startup_gfx2hlsl_compute_check.py | 10 ++++++++++ tests/startup_gfx2hlsl_const_copy_join_check.py | 2 +- tests/startup_gfx2hlsl_fract_check.py | 4 ++-- tests/startup_indirect_draw_indexed.cpp | 2 +- tests/startup_packed_position_provenance_check.py | 2 +- tests/startup_resource_retire_title.cpp | 2 +- tests/startup_shader_cache_key_check.py | 6 +++--- tools/startup/gfx2hlsl.py | 7 ++++--- 12 files changed, 31 insertions(+), 20 deletions(-) diff --git a/docs/experiments.md b/docs/experiments.md index 0f2c274ec4..17635fc6a8 100644 --- a/docs/experiments.md +++ b/docs/experiments.md @@ -15514,8 +15514,8 @@ of exec, or 0 / -1), not data such as a group id or `s_mov_b32 M, 16`, whose lan - preserving: `s_andn2_b32 M, M, exec_lo` and `s_or_b32 M, M, T`, with T written in the block by a `v_cmp` or an `s_and` of exec and a lane mask. A skipped lane keeps its bit, so M needs no zeroing, but M's last write before the branch must itself hold lane bits (no branch or branch target after it); -- compare: a `v_cmp` (not `v_cmpx`) into M, only when `s_mov_b32 M, 0` is the last write before the branch; -- all ones: `s_orn2_b32 M, X, exec_lo`, X a lane mask, only when `s_mov_b32 M, -1` is the last write before the branch. +- compare: a `v_cmp` (not `v_cmpx`) into M, only when `s_mov_b32 M, 0` (or `s_movk_i32 M, 0`) is the last write before the branch; +- all ones: `s_orn2_b32 M, X, exec_lo`, X a lane mask, only when `s_mov_b32 M, -1` (or `s_movk_i32 M, -1`) is the last write before the branch. Zeroing and all-ones writes do not mix, and any other write of M that no later zeroing or all-ones write overwrites keeps the refusal. @@ -15525,7 +15525,7 @@ The block is still refused in these cases: than 0 or missing, a branch or a branch target between the zeroing and the branch, a write of M that is not one of the forms above, a `vcc_hi` or 64-bit write, a whole-mask read after the join); - any other exec write: exec set from a compare alone, restored from a mask saved before the block or on only - some of the paths, written by a form the pass does not follow (`s_orn2` outside the lane mask above, `s_nand`, `s_nor`, `s_xnor`, `s_not`, + some of the paths, written by a form the pass does not follow (`s_orn2` into exec, `s_nand`, `s_nor`, `s_xnor`, `s_not`, the other saveexec and wrexec forms), written in a block that a branch from outside enters (a proven calculated `s_setpc_b64` jump counts), or restored from a copy of the other exec half; - an effect outside scalar registers, such as a scalar store or atomic, a barrier, `s_endpgm` or `v_writelane`; diff --git a/src/startup_stubs/d3d12_draw.inl b/src/startup_stubs/d3d12_draw.inl index 00a7b5e8a8..04078a452e 100644 --- a/src/startup_stubs/d3d12_draw.inl +++ b/src/startup_stubs/d3d12_draw.inl @@ -353,7 +353,7 @@ Translation* cached_translation(const void* a, std::size_t a_bytes, const void* { // Keep pre-fix desktop bytecode and manifests out of this ABI's cache. // tools/startup/gfx2hlsl.py hashes the same bytes, without a trailing NUL. - constexpr char revision[] = "x2w-startup-shader-20"; + constexpr char revision[] = "x2w-startup-shader-21"; const u64 seed = fnv_bytes(revision, sizeof(revision) - 1); u64 key = fnv_bytes(root_blob.data(), root_blob.size(), fnv_bytes(b, b_bytes, fnv_bytes(a, a_bytes, seed))); // A stream's input layout (stream_input_layout) feeds the vertex fetch, so it is part of the key. @@ -474,7 +474,7 @@ u64 publish_compute_request(const void* desc) std::vector fields(sizeof(words)); words[0] = words[1] = words[3] = words[5] = words[7] = words[9] = words[10] = 0; std::memcpy(fields.data(), words, sizeof(words)); - constexpr char compute_revision[] = "x2w-startup-shader-20cs"; // tools/startup/gfx2hlsl.py compute_key + constexpr char compute_revision[] = "x2w-startup-shader-21cs"; // tools/startup/gfx2hlsl.py compute_key u64 key = fnv_bytes(compute_revision, sizeof(compute_revision) - 1); const std::vector* order[] = {&code, &data, &root_blob, &fields, &state_a, &state_b}; for (const auto* part : order) key = fnv_part(*part, key); diff --git a/tests/startup_compute_request_offline_check.py b/tests/startup_compute_request_offline_check.py index 3b6c7fec31..46042f18ff 100644 --- a/tests/startup_compute_request_offline_check.py +++ b/tests/startup_compute_request_offline_check.py @@ -25,12 +25,12 @@ DESC = struct.pack('<12Q', 0, 0, 24, 0, 20, 0, len(CODE), 0, len(DATA), 0, 0, 11) STATE_A = struct.pack('<3Q', 1, 0x2c, 0xfff0000000000003) STATE_B = struct.pack('<5I', 0x1234abcd, 0xffff0000, 0, 0, 0) -KEY = 0x88e751913fcbf7a8 # framed key at revision 20cs +KEY = 0x90041d02ef75b4e9 # framed key at revision 21cs def framed_key(): h = 1469598103934665603 - for b in b'x2w-startup-shader-20cs': + for b in b'x2w-startup-shader-21cs': h = ((h ^ b) * 1099511628211) & 0xffffffffffffffff for part in (CODE, DATA, ROOT, DESC, STATE_A, STATE_B): for b in struct.pack(' translated_pipeline(ID3D12Device* guest, ID3D12RootSignature* r bool needs_start, bool table_buffer = false, bool indexed = false, bool rect = false) { // The opaque guest programs identify synthetic cache entries. The actual bound shaders are source-built DXBC. - constexpr char revision[] = "x2w-startup-shader-20"; + constexpr char revision[] = "x2w-startup-shader-21"; static std::uint32_t vertex_ids[]{0xe0000101, 0xe0000102, 0xe0000103}; static std::uint32_t pixel_ids[]{0xe0000202, 0xe0000203, 0xe0000204}; auto& vertex_id = vertex_ids[indexed ? 2 : needs_start]; diff --git a/tests/startup_packed_position_provenance_check.py b/tests/startup_packed_position_provenance_check.py index 8620af940c..c701eb64ec 100644 --- a/tests/startup_packed_position_provenance_check.py +++ b/tests/startup_packed_position_provenance_check.py @@ -206,7 +206,7 @@ def refused(label, cache, key, reason): cache = Path(tmp) bare = G.pipeline_key(VS_WORDS, ps_words(4), root_blob()) check('without a description the key is unchanged', - bare == G.fnv(root_blob(), G.fnv(ps_words(4), G.fnv(VS_WORDS, G.fnv(b'x2w-startup-shader-20'))))) + bare == G.fnv(root_blob(), G.fnv(ps_words(4), G.fnv(VS_WORDS, G.fnv(b'x2w-startup-shader-21'))))) keys = [put_request(cache, ps_words(4), masks) for masks in (TARGET, SAME_V4, DECOY)] check('same stages, root and layout with three mask pairs: three request identities', len(set(keys)) == 3 and bare not in keys diff --git a/tests/startup_resource_retire_title.cpp b/tests/startup_resource_retire_title.cpp index b064740771..a9aed728b2 100644 --- a/tests/startup_resource_retire_title.cpp +++ b/tests/startup_resource_retire_title.cpp @@ -371,7 +371,7 @@ constexpr UINT draw_side = 4; // 4x4 R8G8B8A8_UNORM target constexpr UINT draw_covered = 3; // scissor leaves the last row and column untouched as the sentinel constexpr int draw_seed = 77; constexpr UINT draw_clear_pixel = 0xffff00ffu; // ClearRenderTargetView({1, 0, 1, 1}) in R8G8B8A8_UNORM -constexpr char draw_revision[] = "x2w-startup-shader-20"; // d3d12_draw.inl cached_translation +constexpr char draw_revision[] = "x2w-startup-shader-21"; // d3d12_draw.inl cached_translation constexpr char draw_vertex_shader[] = R"( struct Varying { float4 position : SV_Position; }; diff --git a/tests/startup_shader_cache_key_check.py b/tests/startup_shader_cache_key_check.py index fd44bba115..8c6fccb3b9 100644 --- a/tests/startup_shader_cache_key_check.py +++ b/tests/startup_shader_cache_key_check.py @@ -49,10 +49,10 @@ def check_request(blobs, key, diagnostic=None, rtv_request=None, layout=None): def main(): # Independently executed C++ runtime fnv_bytes/cached_translation known-answer vector. - # Revision x2w-startup-shader-20 excludes NUL. Stored order is a, b, root, then optional input layout. + # Revision x2w-startup-shader-21 excludes NUL. Stored order is a, b, root, then optional input layout. vector = (b"\x00VS\xff", b"PS\x00\x80", b"RTS0\x00") - assert gfx2hlsl.pipeline_key(*vector) == 0x4564b4bb15aa0b9b - assert gfx2hlsl.pipeline_key(*vector, b"ia\x00\xfe") == 0x8a4952a88d16d6e3 + assert gfx2hlsl.pipeline_key(*vector) == 0x93a74e652d95daf6 + assert gfx2hlsl.pipeline_key(*vector, b"ia\x00\xfe") == 0x1ff6b039237188d6 blobs = (VERTEX, PIXEL, ROOT) canonical = gfx2hlsl.pipeline_key(*blobs) check_request(blobs, canonical) diff --git a/tools/startup/gfx2hlsl.py b/tools/startup/gfx2hlsl.py index 10a17095b3..6c511a81d2 100644 --- a/tools/startup/gfx2hlsl.py +++ b/tools/startup/gfx2hlsl.py @@ -3070,7 +3070,8 @@ def phi_mask_ok(self, key, b, t, effects, succ, targets, index): _, ops, _ = parse(self.ins[z][3]) if self.ins[z][2] not in ('s_mov_b32', 's_movk_i32') or ops != [name, need]: return False - if any(self.ins[k][2].startswith(('s_cbranch', 's_branch', 's_setpc')) for k in range(z + 1, b)) or any(index.get(x) in range(z + 1, b + 1) for x in targets): + if any(self.ins[k][2].startswith(('s_cbranch', 's_branch', 's_setpc')) for k in range(z + 1, b)) or \ + any(index.get(x) in range(z + 1, b + 1) for x in targets): return False # After the join, until M is rewritten, every read must be per lane. seen, todo = set(), [t] @@ -9891,7 +9892,7 @@ def pipeline_key(vs_code, ps_code, root_blob, layout=b'', ps_inputs=None): SPI_PS_INPUT_ENA and SPI_PS_INPUT_ADDR as little-endian u32. Two pipelines with the same stages, root signature and input layout but different masks are then two requests with their own results. Without a description the key is unchanged.""" - key = fnv(root_blob, fnv(ps_code, fnv(vs_code, fnv(b'x2w-startup-shader-20')))) + key = fnv(root_blob, fnv(ps_code, fnv(vs_code, fnv(b'x2w-startup-shader-21')))) key = fnv(layout, key) if layout else key return key if ps_inputs is None else fnv(b'psin1' + struct.pack(' Date: Thu, 26 Nov 2026 08:11:27 +0100 Subject: [PATCH 5/5] docs: shader cache revision 21 note, drop the unreachable s_movk_i32 -1 wording --- docs/experiments.md | 2 +- docs/startup-runtime.md | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/experiments.md b/docs/experiments.md index 17635fc6a8..b578edf87f 100644 --- a/docs/experiments.md +++ b/docs/experiments.md @@ -15515,7 +15515,7 @@ of exec, or 0 / -1), not data such as a group id or `s_mov_b32 M, 16`, whose lan `s_and` of exec and a lane mask. A skipped lane keeps its bit, so M needs no zeroing, but M's last write before the branch must itself hold lane bits (no branch or branch target after it); - compare: a `v_cmp` (not `v_cmpx`) into M, only when `s_mov_b32 M, 0` (or `s_movk_i32 M, 0`) is the last write before the branch; -- all ones: `s_orn2_b32 M, X, exec_lo`, X a lane mask, only when `s_mov_b32 M, -1` (or `s_movk_i32 M, -1`) is the last write before the branch. +- all ones: `s_orn2_b32 M, X, exec_lo`, X a lane mask, only when `s_mov_b32 M, -1` is the last write before the branch. Zeroing and all-ones writes do not mix, and any other write of M that no later zeroing or all-ones write overwrites keeps the refusal. diff --git a/docs/startup-runtime.md b/docs/startup-runtime.md index d0f03ec519..0a34938c9a 100644 --- a/docs/startup-runtime.md +++ b/docs/startup-runtime.md @@ -208,9 +208,9 @@ The translation is refused when: - either header has another size; - the code reads an attribute the table does not list. -The shader cache revision is `x2w-startup-shader-20`. Revision 20 decodes MTBUF/MUBUF format 50 (`R10G10B10A2_UNORM`) in the run-time FORMAT switch, so cached shaders from revision 19 are not reused. Revision 19 folds `s_mov_b32` from a scalar register that +The shader cache revision is `x2w-startup-shader-21`. Revision 21 refuses a compute lane-mask form that revision 20 translated (`s_and_b32 M, X, exec_lo` with X data, see docs/experiments.md), so its cached compute shaders are not reused. Revision 20 decodes MTBUF/MUBUF format 50 (`R10G10B10A2_UNORM`) in the run-time FORMAT switch, so cached shaders from revision 19 are not reused. Revision 19 folds `s_mov_b32` from a scalar register that holds a plain constant, so later reads of the copy use the constant word. The matching compute -(`x2w-startup-shader-20cs`) key advances because that stage uses the shared lowering. The fixed slot 57 mesh +(`x2w-startup-shader-21cs`) key advances because that stage uses the shared lowering. The fixed slot 57 mesh (`x2w-startup-mesh-57-3`) key stays, because that shader is not translated from guest code. Revisions before 19 read a register copied from a constant as a run-time value. Revision 18 preserves the sign of zero in floating-point min, max, min3, max3 and med3.