startup: refuse a lane mask read as numeric data by the remaining ALU forms in gfx2hlsl (Part of #1723) #2694
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2702"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T02:39:36Z.
Part of #1723
What this unblocks: stops silently wrong shader output when a wave lane mask is read as a number (the
llvm.amdgcn.ballotword and anything derived from it).What changed
gfx2hlsl.pykeeps one lane's bit of every wave mask (vcc,exec, SGPRs that hold a compare or ballot result). On RDNA 2 a mask register is the whole wave's bit set, so any instruction that reads it as a number sees the other lanes' bits too. The one-lane model has only its own bit, so the lowered word was wrong and nothing refused it. #2623 coversv_mov_b32andv_cndmask_b32data sources; this PR covers the rest:vcc,exec, or an SGPR tracked as a mask, including results of bitwise ops on a mask) is refused:<op> reads lane mask <reg> as numeric data. A vector compare's sources count as data, its destination does not.mov/and/or/xor/andn2/orn2/nand/nor/xnor/not/cselect/wqm, the*saveexecforms, branches,ff1,bitset) that reads a mask is refused the same way (this commit is the scalar half).s_xor_b64 s[0:1], vcc, s[0:1]thenv_mov_b32 v0, s1) is modelled as 0 but is the other lanes' bits on hardware: av_mov_b32of it is refused.v_shift64withvcc_loorexec_loas the shift count is no longer accepted (a mask as a count).Why it is correct
The hardware rule: a mask SGPR/
vcc/execholds one bit per lane of the wave (64 in wave64). A numeric read returns that word; the model returns 0 or 1. So the only reads the model can honour are the per-lane ones: the select ofv_cndmask, the carry ofv_addc/v_subb/*_co,v_readlane/v_writelane, bitwise mask algebra andsaveexec. Those stay allowed.What stays refused / translating
Mask-only uses (select, carry, bitwise mask algebra,
saveexec, branches onvcc/scc) translate as before.v_mov_b32of a non-mask SGPR translates as before.Tests
tests/startup_gfx2hlsl_compute_check.py:check_lane_mask_data(vector ALU readingvcc_lo; select still translates),check_lane_mask_high_word(move of the high word refused; move of a non-mask SGPR translates),check_lane_mask_derived_word(s_and_b32 s6, vcc_lo, 0xffthen a vector compare or add readings6is refused). Each fails on main without the lowering change and passes with it. Existing suites updated for the earlier, more specific refusal message:readfirstlane_uniform,readfirstlane_recompute,shift64.Verification
python3 -B tests/startup_gfx2hlsl_compute_check.py: PASS (fails before the change, see above)python3 -B tests/startup_gfx2hlsl_readfirstlane_uniform_check.py,..._readfirstlane_recompute_check.py,..._shift64_check.py,..._sdwa_check.py,..._sdwa_cndmask_check.py,..._mask_data_check.py,..._float_alu_check.py: PASStests/startup_gfx2hlsl_*_check.pyrun with no arguments on this branch and onorigin/main: identical result per script (105 PASS;export_null_drawandmul24_align_drawneed a compiler and renderer and exit 1 on both).bf138972a56b7ec0c40036206cbc30ec432592ad:x2w_pipe.py win2025 2702 --host aws-1 --no-skip-build --py-checks tests/startup_gfx2hlsl_compute_check.py --targets offscreen_check --regex 'startup_gfx2hlsl_(compute|mask|lane|vcc|cndmask|join|readfirstlane|cmp)': dev 56/56 passed, release 56/56 passed (includesstartup_gfx2hlsl_compute_warpand_hardware). Build and run:cmake --build --preset dev --target offscreen_checkthenctest --preset dev --no-tests=error -R '^startup_gfx2hlsl_(compute|mask|lane|vcc|cndmask|join|readfirstlane|cmp)' -V.tests/startup_gfx2hlsl_*scripts give the same result on the merge of this branch with currentmainas onmain(onlyexport_null_drawandmul24_align_draw, which need a compiler and renderer, exit 1 on both). Every case ofCASESinstartup_gfx2hlsl_compute_check.pytranslates (23 of 23). The one-thread boundary was probed both ways: group (1,1,1) translates; (2,1,1), (1,2,1), (1,1,2), (3,1,1), (4,1,1), (32,1,1), (64,1,1) are refused. Three mutations oflane_mask_exact(always false, always true, at most two threads) and of the tag propagation each makestartup_gfx2hlsl_compute_check.pyfail.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-26T03:26:53Z.
Review: COMMENTED
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit:
d7eb2e3118ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T03:46:20Z.
Review: COMMENTED
No description provided.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T03:46:22Z.
Review: COMMENTED
No description provided.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T03:46:24Z.
Review: COMMENTED
No description provided.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T03:16:51Z.
@MasterDomino this is ready for review at head
d7eb2e311.Independent gate review plus Windows run, four rounds. What it caught and the author fixed, so you know what was checked:
v_mov_b32; now every single-register read and every copy or combination of a mask pair carries the tag (one place,propagate_mask_tags), with a refusal test per kind;mainmadestartup_gfx2hlsl_readfirstlane_uniform_checkfail on a case whose expected message changed; updated;startup_gfx2hlsl_compute_check(a saveexec result read as a number in a one-thread group, where the one-lane model is exact), visible only on Windows (compute_warp/compute_hardware); now a numeric mask read stays lowered in a compute group of one thread and is refused in every other group size.Verification is in the PR body (commands, dev 36/36 and release 36/36 on WARP on this exact head, 111 Linux scripts identical to
main, boundary probed both ways, mutations fail the tests).AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-26T03:16:52Z.
Codex Review Summary: ✅ Completed
This comment shows the latest Codex review activity on this pull request.
bf13897ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T03:48:49Z.
Independent re-check of the fix pushed after Ready (
f837dc298: high-word tag stays a high word, ends on overwrite, resets per pass), head07003864c.s_mov_b64 s[20:21], execfirst): copy of the low word then a numeric use is refused in a 2-thread group and translates in a 1-thread group; copy of the high word is refused in a 2-thread group; a wide write (s_mov_b64 s[20:21], 0) ends the tag, so the next read of s21 is not falsely refused.tests/startup_gfx2hlsl_compute_check.pyfails on the parent of the fix and passes with it.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-26T03:26:54Z.
Code review location:
tools/startup/gfx2hlsl.py; line 3558For a one-thread compute group,
s_mov_b64 s[20:21], exec; s_mov_b32 s22, s21; s_or_b32 s23, s22, 2should produce numerics23 == 2, since the high EXEC word is zero. Here the high-word tag causes the scalar copy to adds22toself.masks, so the next OR is emitted as(s22 | 2) & 1. A following conversion and buffer store remain accepted because oflane_mask_exact(), causing the generated shader to store0.0frather than2.0f; the parent emits the correct full-word OR. Preserve the high-word classification instead of treating this numeric copy as a low-word lane bit.Useful? React with 👍 / 👎.
Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-26T03:26:54Z.
Code review location:
tools/startup/gfx2hlsl.py; line 2437When a tagged pair is overwritten by a runtime
scalar_wide_op(), that handler clearsself.masksand writes both HLSL words directly, but never clearsmask_high. Consequently,s_mov_b64 s[20:21], exec; s_lshl_b64 s[20:21], s[4:5], s7; v_mov_b32 v5, s21now fails as a numeric mask read in a multi-thread compute group even thoughs21holds an ordinary shift result. Symbol-only scalar moves also retain stale high tags because they bypass this cleanup. Invalidate high-word tags on those overwrite paths as well as inset_s()so ordinary register reuse does not cause false refusals.Useful? React with 👍 / 👎.
Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-26T03:26:54Z.
Code review location:
tools/startup/gfx2hlsl.py; line 3560When
translate()repeats its uniformity proof, it restoresself.masksfrom the entry snapshot but retains thismask_highset from the end of the previous pass; the outer retry inStage.__init__()retains it as well. A multi-thread compute shader that first converts entry group-IDs9and later savesexecintos[8:9]in a loop succeeds on the first pass, but the second pass refuses the earlier conversion as a numeric mask read. Reset or snapshotmask_highalongside the other per-pass register state so later writes cannot poison entry operands on retranslations.Useful? React with 👍 / 👎.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T03:46:20Z.
Code review location:
tools/startup/gfx2hlsl.py; line 3558Confirmed and fixed in
07003864c. A one-thread group that copied the high word of a savedexec(s_mov_b64 s[20:21], exec; s_mov_b32 s22, s21; s_or_b32 s23, s22, 2) emitteds23 = (s22 | 0x2u) & 1;. A copy of a high word now carries only the high-word tag (propagate_mask_tags), so the numeric use stayss23 = s22 | 0x00000002u;.Test:
check_lane_mask_high_word_copy_and_overwriteintests/startup_gfx2hlsl_compute_check.py(fails on the previous head, passes now; the same program with a 2-thread group is still refused).Commands run:
python3 tests/startup_gfx2hlsl_compute_check.pytests/startup_gfx2hlsl_*scripts (same exit codes as before; the two*_draw_checkscripts need a renderer argument)07003864c:ctest --preset dev|release -R 'startup_gfx2hlsl_(compute|readfirstlane_uniform|readfirstlane_recompute|shift64)'36/36 on both presetsAI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T03:46:22Z.
Code review location:
tools/startup/gfx2hlsl.py; line 2437Confirmed and fixed in
07003864c.s_mov_b64 s[20:21], exec; s_lshl_b64 s[20:21], s[4:5], s7; v_mov_b32 v5, s21in a 4-thread group was refused as "reads lane mask s21 as numeric data" because the wide write left the high-word tag on s21.lower()now drops the high-word tag of every SGPR the instruction wrote, before the tags of its sources are propagated.Test:
check_lane_mask_high_word_copy_and_overwrite(the shifted pair now translates; fails on the previous head).Commands run: same as the first thread on this PR (compute check, all
startup_gfx2hlsl_*scripts, Windows dev+release 36/36 on07003864c).AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T03:46:24Z.
Code review location:
tools/startup/gfx2hlsl.py; line 3560Real by code reading, fixed in
07003864c:self.mask_highwas not reset whereself.masks = set(init_masks)starts each translation pass, so a tag set in a first pass leaked into the retry. The two sets are now reset together.I could not build a program that shows it through the public translate path: every loop I tried hit an unrelated refusal first, or the tags were rebuilt before the read. So there is no separate failing test for this one; the reset is covered by the existing retry fixtures staying green (compute check and all
startup_gfx2hlsl_*scripts, Windows dev+release 36/36 on07003864c).AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T04:13:34Z.
Moving this back to Draft for now: an extra round of generated test shapes found a few more ways a wave64 mask high word can still be read as a number (for example a copy to another register pair, then a scalar add). Fixing them with tests; it goes back to Ready once they pass.
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-26T05:16:19Z.
Review: COMMENTED
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit:
ee0deadadcℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T05:36:44Z.
Review: COMMENTED
No description provided.
Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-26T05:44:25Z.
Review: COMMENTED
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit:
bf138972a5ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T05:11:08Z.
@MasterDomino Ready for review on head
bf138972a(re-gate after the CI fix and a review-thread fix).History: marked Ready on
ee0deadad, put back to Draft because the Linux CI check startup_gfx2hlsl_bfm_b64 failed there; c7 fixed that test. While re-gating I also confirmed the open review thread (a 64-bit copy of plain data cleared the mask tag, so its truncated low word could be read as a number) and fixed it in745d2c34cwith a check that fails on the previous head; thread replied and resolved.Re-gate on
bf138972a: fresh_gate GO (CI green, no open threads). Break-it sweep of 141 generated variants plus 173 corpus shapes: no FAIL, no unproven gain. The oracle result of the earlier run (32 translated, 32 MATCH, 0 MISMATCH, 346 refused) is unchanged for the translated HLSL. Sweep of alltests/startup_gfx2hlsl_*_check.pywith no arguments: only the two draw-only checks that need adapter arguments exit 1.Win2025 (dev + release) on the exact head:
x2w_pipe.py win2025 2702 --host aws-1 --no-skip-build --py-checks tests/startup_gfx2hlsl_compute_check.py --targets offscreen_check --regex "startup_gfx2hlsl_(compute|mask|lane|vcc|cndmask|join|readfirstlane|cmp)": 56/56 dev, 56/56 release.Open note, not new in this PR: a mask copy on one branch arm with a plain overwrite on the other, read as a number after the join, is not refused (the tag follows program order); llc does not emit it for an i1 value.
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-26T05:16:19Z.
Code review location:
tools/startup/gfx2hlsl.py; line 3707In a multi-thread compute shader,
s_mov_b64 s[20:21], s[4:5]; v_mov_b32 v5, s20is now accepted even thoughscalar()still treats the runtimes_mov_b64as a mask copy and emitss20 = (ud0) & 1. Clearingself.maskshere makesv_mov_b32accept that truncated value, so a subsequent store writes1rather than the original root constant, such as case A's0x01234567; the parent refuses this read. Preserve the mask tag until a full-word numeric copy is actually emitted, or update the b64 lowering before clearing it.Useful? React with 👍 / 👎.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T05:36:44Z.
Code review location:
tools/startup/gfx2hlsl.py; line 3707Confirmed and fixed in
745d2c34c(merged onbf138972a).scalar()lowers every b64 move as a mask copy (lane bit only), so clearing the tag on a pair copy of plain data let the truncated low word be read as a number. Now only a 32-bit copy of plain data clears the tag; a 64-bit pair copy keeps it. New checkcheck_lane_mask_pair_copy_of_data_stays_refusedintests/startup_gfx2hlsl_compute_check.py(s_mov_b64 s[20:21], s[4:5]; v_mov_b32 v5, s20in a 2-thread group is refused; the 32-bit copy of the same word still translates); it fails on the previous head. Win2025 on aws-1, dev + release: 56/56 each.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-26T05:44:25Z.
Code review location:
tools/startup/gfx2hlsl.py; line 3753In a four-thread compute group, inserting
v_cmp_gt_i32_e64 s20, 17, v0; s_wqm_b32 s20, 0; v_mov_b32 v5, s20before case A's store now translates, whereas the parent refuses the final move.MASK_COPY_SALU_REincludes WQM, but_lower()treatss_wqm_b32as a no-op, so this cleanup removes the mask tag without replacing the old per-lane compare value. The generated shader consequently stores1for these lanes instead of the WQM result0. Preserve the tag for this no-op lowering, or implement the actual register write before clearing it.Useful? React with 👍 / 👎.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T06:23:37Z.
Review: COMMENTED
No description provided.
Imported from R0Y00/Xbox2Windows. Originally posted by MasterDomino on 2026-11-26T06:50:13Z.
Review: CHANGES_REQUESTED
Reviewed
7d3472d8. It fixes the WQM thread, and its merge with currentmain(e3cf6a91) passes the gfx2hlsl group here: 287/289 on WARP and an AMD Radeon RX 9070 XT (driver 32.0.32029.2010, Windows 11 build 26300). The two failures are already onmain:fma_mix_dispatch_hardware(#2746);f16_alu_draw_hardware, where -0 products read back as +0.Seven one-line mutations of the new tag and refusal logic each fail
startup_gfx2hlsl_compute_check.py: the vector and scalar numeric checks off, no derived-word tag, no compare-pair high tag, the high tag not cleared on overwrite, the WQM fix reverted, and "exact" widened to 64 threads. Legitimate mask uses emit identical HLSL before and after:v_cndmaskwith VCC or an SGPR,s_and/s_or/s_andn2on masks, saveexec, and carry-in.One change is needed: a cache revision bump.
maintranslates programs that this PR now refuses.v_cmp_lt_i32 vcc_lo, 5, v0followed by any ofv_cvt_f32_u32 v5, vcc_lo,s_add_u32 s6, vcc_lo, 1, ors_and_b32 s6, vcc_lo, 0xff; v_add_nc_u32 v5, s6, v5translates onmainand is refused here. About 15 more stage-level forms flip the same way.x2w-startup-shader-19/19csto20/20cs, or one past whatever lands first; #2006 just took20, so checkmain. That'spipeline_key/compute_key,d3d12_draw.inl, and the tests and docs that spell the revision.Non-blocking, and also wrong on
main:s_not_b32 s7, s6; s_add_i32 s1, s7, 1is lowered as(~s6) & 1, while hardware holds 0xFFFFFFFE or 0xFFFFFFFF. The high word ofs_not_b64 s[6:7], execis modelled as 0 but is 0xFFFFFFFF. So the exactness argument holds only for masks that aren't complemented._co_form (v_add_co_u32_e64 v1, s8, s6, v2) is still accepted.s_cselect_b32: a mask through it doesn't carry the tag; only the b64 form does.Commands:
ctest --preset dev --no-tests=error -j 8 -R '^(startup_gfx2hlsl|startup_compute_readfirstlane)'on the PR head and on its merge withmain;python -B tests/startup_gfx2hlsl_{compute,mask_overwrite,readfirstlane_uniform,readfirstlane_recompute,shift64,bfm_b64,vcc_hi}_check.py.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T06:23:37Z.
Code review location:
tools/startup/gfx2hlsl.py; line 3753Confirmed (repro:
v_cmp_gt_i32_e64 s20, 17, v0; s_wqm_b32 s20, 0; v_mov_b32 v5, s20translated in a 4-thread group) and fixed in7d3472d8d:s_wqmis a no-op in the lowering, so it is excluded from the plain-data tag cleanup and a mask it nominally rewrites keeps its tag. New checkcheck_lane_mask_wqm_keeps_tagintests/startup_gfx2hlsl_compute_check.py(fails on the previous head). Win2025 on aws-1, dev + release: 59/59 each.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T07:56:06Z.
Thanks for the review and the mutation runs.
Cache revision: done. The startup shader cache revision advances from 22 / 22cs to 23 / 23cs:
pipeline_keyandcompute_keyintools/startup/gfx2hlsl.py,revision/compute_revisioninsrc/startup_stubs/d3d12_draw.inl, the two runtime tests that spell it (startup_indirect_draw_indexed.cpp,startup_resource_retire_title.cpp),docs/startup-runtime.md, and the Python checks that pin it. The two known-answer keys (startup_shader_cache_key_check.py,startup_compute_request_offline_check.py) are recomputed with the independent hash loops those tests already carry. Main moved to revision 22 while this was open, so this is one past it.Also in this push: main merged again, and two controls that main added (#2769) now meet the lane-mask rule before the uniformity rule (
predicate as OR sourceaccepts either refusal).Your non-blocking notes, left for a follow-up (all three are wrong on
maintoday and none is made worse here; they widen the rule rather than fix this PR's):s_not_b32/s_not_b64 s[6:7], exec): the tag survives a complement, but the value modelled for it is not the hardware's;_co_carry form (v_add_co_u32_e64 v1, s8, s6, v2);s_cselect_b32carrying the mask tag like the b64 form.I can take them as a separate PR with their own WARP readback if you want them.
Commands run on the new head: the full Linux Python check list from the workflow (same 15 environment failures as
origin/main, nothing new);python -B tests/startup_gfx2hlsl_{compute,mask_overwrite,readfirstlane_uniform,readfirstlane_recompute,shift64,bfm_b64}_check.py,startup_shader_cache_key_check.py,startup_compute_request_offline_check.py; the mask-tag fuzz variants over four llc seeds: 0 holes.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by MasterDomino on 2026-11-26T08:01:48Z.
Review: APPROVED
Approving
fcfd9f1c. The cache revision moves tox2w-startup-shader-23/23cs, one past currentmain(22).Since
7d3472d8, which I reviewed with mutants:gfx2hlsl.pydiff is identical.predicate as OR sourcealso accepts the mask-rule refusal (v_and_or_b32 reads lane mask s2 as numeric data), so the case stays refused under either rule.main624f5927, and CI is green at the head.Commands, on Windows 11 build 26300, at
fcfd9f1c; all exit 0:python -B tests/startup_gfx2hlsl_{compute,mask_overwrite,readfirstlane_uniform,readfirstlane_recompute,readfirstlane_load_recompute,shift64,bfm_b64,vcc_hi,mask_data}_check.py;startup_shader_cache_rekey_check.py,startup_shader_cache_key_check.py,startup_compute_request_offline_check.py;startup_gfx2hlsl_compute_check.py binary <llvm-mc 15>: "fixture words match llvm-mc".@tedin7, yes please: a separate PR for the three follow-ups (complemented masks,
_co_carry data sources,s_cselect_b32), each with its readback, would be welcome.AI-assisted; commands listed were executed locally.