shader: lower 64-bit scalar compares, quadmask and wqm in gfx2hlsl (Part of #1723) #2076
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!2076
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/2076/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-25 00:03 UTC · original
tedin7:x2w-b3-cmp64-wqm→main· +253 −1 · 4 files · 4 commits · closed without mergingPart of #1723
What this unblocks: gfx2hlsl can translate shaders that compare 64-bit scalar pairs, test a bit of a 64-bit pair, or build quad masks (
s_quadmask,s_wqm) on ordinary scalar registers, instead of refusing them or silently skippings_wqm.Lowers
s_cmp_eq_u64,s_cmp_lg_u64,s_bitcmp0_b64,s_bitcmp1_b64,s_quadmask_b32/b64ands_wqm_b32/b64intools/startup/gfx2hlsl.py. 64-bit operands are even-aligned SGPR pairs or immediates (inline constants sign-extended, 32-bit literals zero-extended). Lane-mask operands (exec, vcc, projected masks) and misaligned pairs are refused;s_wqmof a lane mask keeps its previous no-op behaviour.Verification:
python3 -B tests/startup_gfx2hlsl_s_cmp64_wqm_check.pyon this branch:s_cmp64_wqm: ok. The same test againstorigin/main'sgfx2hlsl.py: 631 failures.python3 -Bon everytests/*gfx2hlsl*_check.py, plustests/pixel_aot_check.py: all pass.startup_gfx2hlsl_s_cmp64_wqminCMakeLists.txt.tests/form_coverage_check.py(needs theiced_x86module, not installed here). Win2025 run not executed; checks ran locally on Linux.AI-assisted; commands listed were executed locally.
@chatgpt-codex-connector[bot] on GitHub · 2026-11-25 00:03 UTC · original · edited 2026-11-25 00:08 UTC
Codex Review Summary: ✅ Completed
This comment shows the latest Codex review activity on this pull request.
7af0c09ℹ️ 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.
@ -4305,0 +4312,4 @@raise Unsupported('%s operand %s' % (base, tok))if reg[1] in self.masks or reg[2] in self.masks:raise Unsupported("%s on a projected lane mask in %s" % (base, tok))return self.S(reg[1]), self.S(reg[2])@chatgpt-codex-connector[bot] on GitHub · 2026-11-25 00:08 UTC · original
When the high SGPR contains a projected lane mask,
is_lane_mask(tok)checks only the pair's low register, so this return exposes the high register as an ordinary numeric word. For example, afters_mov_b32 s4, 0; s_mov_b32 s5, exec_lo, the newly supporteds_bitcmp1_b64 s[4:5], 33is accepted. With guest EXEC equal to0xf, SCC should be true, but evaluating the emitted code produces false becauses5contains the current-lane projection1, not the full mask. The parent commit refused this instruction instead of silently miscompiling it. Check both member registers for projected masks before returning their numeric expressions.Useful? React with 👍 / 👎.
@ -2795,1 +2795,4 @@"${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_gfx2hlsl_handler_arity_check.py")# gfx2hlsl lowers s_cmp_eq_u64, s_cmp_lg_u64, s_bitcmp0/1_b64, s_quadmask_b32/b64 and s_wqm_b32/b64 on scalar registers.add_test(NAME startup_gfx2hlsl_s_cmp64_wqm COMMAND "${INTAKE_PYTHON}" -B"${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_gfx2hlsl_s_cmp64_wqm_check.py")@chatgpt-codex-connector[bot] on GitHub · 2026-11-25 00:08 UTC · original
This commit adds publicly usable instruction support and registers a new reproduction check, but changes neither the README nor
docs/experiments.md.AGENTS.mdexplicitly requires updating one of those documents when a public capability or reproduction command changes. Add the supported scalar forms, lane-mask limitations, and exact verification command/result so contributors can reproduce this capability and distinguish it from the existing pixel-AOT implementation.AGENTS.md reference: AGENTS.md:L211-L212
Useful? React with 👍 / 👎.
@tedin7 on GitHub · 2026-11-25 01:13 UTC · original
Fixed and pushed in ff79222a (pair-word mask check + docs, tests pass).
@ -4305,0 +4312,4 @@raise Unsupported('%s operand %s' % (base, tok))if reg[1] in self.masks or reg[2] in self.masks:raise Unsupported("%s on a projected lane mask in %s" % (base, tok))return self.S(reg[1]), self.S(reg[2])@tedin7 on GitHub · 2026-11-25 01:30 UTC · original
Fixed in b8833999:
_word_pairnow refuses a projected lane mask in either member register, sos_mov_b32 s5, exec_lo; s_bitcmp1_b64 s[4:5], 33is refused again.tests/startup_gfx2hlsl_s_cmp64_wqm_check.pyplants a mask in the low and the high word for five forms.Verification:
python -B tools/run_checks_parallel.py <the 83 Linux checks from ci.yml>-> all 83 checks passed;python -B tests/startup_gfx2hlsl_s_cmp64_wqm_check.py->s_cmp64_wqm: ok.AI-assisted; commands listed were executed locally.
@ -2795,1 +2795,4 @@"${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_gfx2hlsl_handler_arity_check.py")# gfx2hlsl lowers s_cmp_eq_u64, s_cmp_lg_u64, s_bitcmp0/1_b64, s_quadmask_b32/b64 and s_wqm_b32/b64 on scalar registers.add_test(NAME startup_gfx2hlsl_s_cmp64_wqm COMMAND "${INTAKE_PYTHON}" -B"${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_gfx2hlsl_s_cmp64_wqm_check.py")@tedin7 on GitHub · 2026-11-25 01:30 UTC · original
Fixed in ff79222a:
docs/experiments.mdnow has a "Scalar 64-bit compares, quad masks and WQM" section with the supported forms, the lane-mask and EXEC/VCC/M0 refusals, and the exactctest --preset dev --no-tests=error -R '^startup_gfx2hlsl_s_cmp64_wqm$' -Vcommand.Verification: Linux Python checks (83) all passed locally; targeted test prints
s_cmp64_wqm: ok.AI-assisted; commands listed were executed locally.
@thepatrickworld on GitHub · 2026-11-25 02:05 UTC · original
Differential sweep of the emitted expressions against the guide's loops
This PR has no draw stage, and the property worth keeping is that its check does not reimplement the intent: it translates a line and evaluates the assignments the translator emitted. So I ran that same evaluation against the guide's own loops, on far more inputs than the ten hand-picked qwords.
S_QUADMASK(D[i] = (S0[i*4+3:i*4] != 0)) andS_WQM(every bit of a quad takes the quad's OR,SCC = (D != 0)), both widths: 4008 32-bit patterns and 4006 qwords, edge patterns included. No divergence.S_BITCMP0/1_B64on 6000 index cases, including 63, 64, 65, 0x7f, 0xff and 0xffffffff. The guide masks withS1.u[5:0], and the emitted(index >> 5) & 1withindex & 31reproduces that, including the wrap at 64. No divergence.S_CMP_EQ_U64andS_CMP_LG_U64on 600 random pairs plus the inline-constant cases: the sign extension of-16..-1to 64 bits and the zero extension of a 32-bit literal are what the guide describes, and the emitted comparisons agree.No defect found, and I would rather say that than invent one. What is missing is not correctness but reach: the scalar-to-SCC path has no adapter stage anywhere, so evaluating the emitted text in Python is the only channel available for these operations, and this check is doing it properly. One line saying so would keep a reader from assuming the draw coverage of the neighbouring PRs applies here too.
Limit. The loops above are written from the guide text by me, not taken from this PR, so agreement means the emitted expressions match the architecture as I read it.
AI-assisted.
@tedin7 on GitHub · 2026-11-25 10:52 UTC · original
Thank you @thepatrickworld for the differential sweep against the guide's loops. Agreed that this PR has no adapter stage, so the evaluation of the emitted text is its only channel; the neighbouring PRs' draw coverage does not apply here.
AI-assisted; commands listed were executed locally.
@tedin7 on GitHub · 2026-11-25 13:52 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-25 00:08 UTC · original · reviewed
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit:
7af0c09a65ℹ️ 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