shader: lower s_bitset0_b32 and s_ff0_i32_b32 in gfx2hlsl (Part of #1723) #2040
No reviewers
Labels
No labels
accessibility
awaiting author
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
priority: P0
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/R0Y00--Xbox2Windows!2040
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/2040/head"
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?
@tedin7 on GitHub · 2026-11-24 23:32 UTC · original
tedin7:x2w-r21-scalar-twins-a→main· +160 −1 · 3 files · 5 commits · closed without mergingPart of #1723
What this unblocks: startup shaders that use the RDNA2 scalar address/bit helpers
s_lshl2_add_u32,s_lshl3_add_u32,s_bitset0_b32ands_ff0_i32_b32now translate instead of stopping at "Unsupported".Change
tools/startup/gfx2hlsl.py: lowering for the four scalar ops.s_lshl2_add_u32/s_lshl3_add_u32:D = (S0 << n) + S1; SCC is the carry out of the 64-bit sum (bits shifted out of S0 or a wrapped add). SCC is computed before the destination write, so a destination aliasing a source is correct.s_bitset0_b32: clears bitS0[4:0]of the destination (read-modify-write); SCC unchanged.s_ff0_i32_b32:uint(firstbitlow(~S0)), which is0xffffffff(-1) when no bit is zero; SCC unchanged.tests/startup_gfx2hlsl_scalar_twins_check.py, registered inCMakeLists.txtasstartup_gfx2hlsl_scalar_twins: builds instruction words from the decoder layouts, translates, runs the emitted lines on an integer evaluator over edge values and compares with an integer reference (including destination aliasing and SCC).Verification
Run on the Linux worker (Python only, no GPU):
python3 -B tests/startup_gfx2hlsl_scalar_twins_check.pyonorigin/main: fails (Unsupported: s_lshl2_add_u32).startup_gfx2hlsl_scalar_twins_check: ok.python3 -B tests/startup_gfx2hlsl_sop2_complement_check.py: PASS.python3 -B tests/startup_gfx2hlsl_scalar_m0_check.py: controls passed.python3 -B tests/startup_gfx2hlsl_bit_alu_check.py: ok.Win2025 commands: not run (no Windows host in this worker).
AI-assisted; commands listed were executed locally.
@chatgpt-codex-connector[bot] on GitHub · 2026-11-24 23:32 UTC · original · edited 2026-11-24 23:36 UTC
Codex Review Summary: ✅ Completed
This comment shows the latest Codex review activity on this pull request.
e9e35fcℹ️ 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.
@ -4255,2 +4294,4 @@'s_sext_i32_i8': ('uint(int({0} << 24) >> 24)', None),'s_sext_i32_i16': ('uint(int({0} << 16) >> 16)', None),# s_ff0_i32_b32: index of the lowest zero bit, -1 when every bit is set; SCC unchanged.'s_ff0_i32_b32': ('uint(firstbitlow(~{0}))', None),@chatgpt-codex-connector[bot] on GitHub · 2026-11-24 23:36 UTC · original
When this instruction reads
exec_lo,vcc_lo, or an SGPR tracked inself.masks, dispatch throughSCAbypasses the whole-word guards used by the other new lowerings. These masks contain only the current lane's bit in the translated shader. For example, when the guest'sEXEC_LOis0xffffffff, the emitteduint(firstbitlow(~exec))evaluates to1because translatedexecis1, rather than the required0xffffffff. This silently mistranslates valid shaders; reject lane-mask sources, including copied masks, unless a full-wave representation is available.Useful? React with 👍 / 👎.
@chatgpt-codex-connector[bot] on GitHub · 2026-11-24 23:36 UTC · original
When an operand is a root constant or a value read by a literal-offset
s_buffer_load_dword*, its symbolic tag isudorfixed_buffer_word; both already represent complete numeric values supported byStage.S(). This check incorrectly classifies them as descriptor data. For example,s_lshl2_add_u32 s4, s8, s3raisesUnsupportedwhens8holds a root constant, ands_bitset0_b32similarly rejects a numeric root-constant destination. The new operations therefore reject ordinary scalar inputs even though moving the same value through a temporary makes them work. Allow these numeric tags while retaining the descriptor and pointer refusals.Useful? React with 👍 / 👎.
@R0Y00 on GitHub · 2026-11-25 00:15 UTC · original
#2027 is now on main and supplies the
s_lshl2_add_u32ands_lshl3_add_u32handlers, including the SCC proof and discard-destination control. Please keep those definitions from main when updating this branch and limit its remaining diff tos_bitset0_b32ands_ff0_i32_b32. That leaves the two operations independently reviewable and keeps the existing lane-mask and numeric-symbol findings applicable to this smaller slice.@tedin7 on GitHub · 2026-11-25 00:38 UTC · original
Updated in 90959dc6: removed the duplicate s_lshl2_add_u32 / s_lshl3_add_u32 handlers and kept main's SCC uniformity and discard-destination control; this PR now covers s_bitset0_b32 and s_ff0_i32_b32 only.
@ -4255,2 +4294,4 @@'s_sext_i32_i8': ('uint(int({0} << 24) >> 24)', None),'s_sext_i32_i16': ('uint(int({0} << 16) >> 16)', None),# s_ff0_i32_b32: index of the lowest zero bit, -1 when every bit is set; SCC unchanged.'s_ff0_i32_b32': ('uint(firstbitlow(~{0}))', None),@tedin7 on GitHub · 2026-11-25 00:57 UTC · original
Fixed in 10ec331e (rebased on main, push pending): s_ff0_i32_b32 now refuses lane-mask sources (exec/vcc/copied masks); test added.
@tedin7 on GitHub · 2026-11-25 00:57 UTC · original
Fixed in 10ec331e (rebased on main, push pending): ud and fixed_buffer_word symbols are now accepted as numeric sources; test added.
@tedin7 on GitHub · 2026-11-25 13:51 UTC · original
Closing this PR for now to keep the Windows test queue short. Nothing is wrong with it and the branch stays as it is.
We will reopen it once the queue is clear, re-run the Win2025 WARP checks at its head, and post the result here.
AI-assisted; commands listed were executed locally.
@chatgpt-codex-connector[bot] on GitHub · 2026-11-24 23:36 UTC · original · reviewed
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit:
e9e35fc438ℹ️ 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".
Pull request closed