shader: lower 64-bit scalar shifts and s_bfe in gfx2hlsl (Part of #1723) #2088
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!2088
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/2088/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:06 UTC · original
tedin7:x2w-b3-s-shift64-bfe→main· +439 −0 · 4 files · 3 commits · merged 2026-11-25 12:54 UTCPart of #1723
What this unblocks: scalar 64-bit shifts and bitfield extracts (s_lshl_b64, s_lshr_b64, s_ashr_i64, s_bfe_i32, s_bfe_u64, s_bfe_i64) no longer stop gfx2hlsl translation of titles that build 64-bit addresses and packed fields in SGPRs.
Verification:
Run on Linux (Python only, no GPU, no dxc/fxc available there). Not run on Win2025.
python3 -I -B tests/startup_gfx2hlsl_scalar_shift64_bfe_check.py->startup scalar 64-bit shift and bitfield extract controls passed (3498 helper cases)origin/maincheckout -> fails (AssertionError: bfe32 helper missing).python3 -B tests/startup_gfx2hlsl_*_check.py,tests/startup_translator_check.py,tests/startup_flat_param_check.py(no arguments) -> all pass, including shift64, scalar_m0, bit_alu, cvt_alu, mad.What changed:
tools/startup/gfx2hlsl.py: six handlers sharing onescalar_wide_op. Constant operands fold to exact words; otherwise one block reads all sources before writing either destination register (an overlapping destination is safe). SCC = (result != 0). m0, vcc, odd register pairs, lane masks and vector sources are refused. New HLSL helpersbfe32andbfe64reuseshl64,shr64u,shr64i.tests/startup_gfx2hlsl_scalar_shift64_bfe_check.py(new, in CMakeLists.txt and the Windows Python check list): hand-written constant cases, the emitted helper text run on a grid against an independent bit-string reference (no 32-bit shift ever gets a count of 32 or more), overlap, uniformity and refusal checks.Notes:
s_ashr_i64, so that is the handler name.s_bfe_u64/s_bfe_i64is treated as the whole field (hardware behaviour for that corner is not confirmed here).AI-assisted; commands listed were executed locally.
@chatgpt-codex-connector[bot] on GitHub · 2026-11-25 00:06 UTC · original · edited 2026-11-25 00:13 UTC
Codex Review Summary: ✅ Completed
This comment shows the latest Codex review activity on this pull request.
4c7111aℹ️ 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.
@chatgpt-codex-connector[bot] on GitHub · 2026-11-25 00:13 UTC · original
When a signed field extends past bit 31/63 and the source's most-significant bit is set, the result must retain that sign. This logic instead zero-fills the missing bits before testing bit
width - 1. For example,s_bfe_i32of0x80000000with control0x0002001fmust produce0xffffffff, but bothscalar_wide_foldand the emittedbfe32helper produce1; the analogous 64-bit case also fails. Clamp the effective width to the remaining source bits or use an arithmetic shift for this case, and correct the test reference, which currently zero-pads the same way.Useful? React with 👍 / 👎.
@ -2529,0 +2586,4 @@self.emit('{ uint t = %s(%s, %s%s); s%d = t; scc = t != 0u; }' % (helper, low, amount, sg, d))for r in range(d, d + width):self.sym.pop(r, None)self.used_s.add(r)@chatgpt-codex-connector[bot] on GitHub · 2026-11-25 00:13 UTC · original
When these handlers reuse an SGPR that previously held a lane mask, neither the folded path nor this runtime path removes it from
self.masks. The decoded sequences_mov_b32 s20, vcc_lo; s_lshl_b64 s[20:21], 8, 1; s_mov_b32 s22, s20therefore emitss22 = (0x00000010u) & 1, producing zero instead of 16 becauseStage.scalarstill treats the overwritten register as a mask. Clear the mask tag for every destination word in both write paths.Useful? React with 👍 / 👎.
@chatgpt-codex-connector[bot] on GitHub · 2026-11-25 00:13 UTC · original
When the high word of a source pair holds a lane mask, this guard misses it because
is_lane_mask('s[6:7]')only inspectss6. For example,s_mov_b32 s7, vcc_lofollowed bys_lshr_b64 s[20:21], s[6:7], 32is accepted. For a whole-wave VCC mask of 2, the guest result iss20 = 2in every lane, but the generated HLSL instead returns each lane's projected zero/one value and computes SCC from it. Reject masks in either member of a wide source pair before lowering the operation.Useful? React with 👍 / 👎.
@tedin7 on GitHub · 2026-11-25 01:04 UTC · original
Fixed in
bea78121: the bfe field width is clamped to the bits left above the offset, so the sign comes from the source MSB; the test reference no longer zero-pads. Verified: python3 tests/startup_gfx2hlsl_scalar_shift64_bfe_check.py (pass). AI-assisted; commands listed were executed locally.@ -2529,0 +2586,4 @@self.emit('{ uint t = %s(%s, %s%s); s%d = t; scc = t != 0u; }' % (helper, low, amount, sg, d))for r in range(d, d + width):self.sym.pop(r, None)self.used_s.add(r)@tedin7 on GitHub · 2026-11-25 01:04 UTC · original
Fixed in
bea78121: both the folded and the runtime path now drop the mask tag of every destination word; new overwritten_mask test covers all six ops. Verified: python3 tests/startup_gfx2hlsl_scalar_shift64_bfe_check.py (pass). AI-assisted; commands listed were executed locally.@tedin7 on GitHub · 2026-11-25 01:04 UTC · original
Fixed in
bea78121: every register of a wide source pair is checked against the mask set, so s_mov_b32 s7, vcc_lo then a pair read is refused; new refusal test added. Verified: python3 tests/startup_gfx2hlsl_scalar_shift64_bfe_check.py (pass). AI-assisted; commands listed were executed locally.@R0Y00 on GitHub · 2026-11-25 12:50 UTC · original
The dynamic bitfield helpers at the previous head raised FXC X4000 under
/WX. I fast-forwarded the branch toeca7576fwith masked shift counts and one result expression. The same dynamic helper sample now compiles with both FXCps_5_1 /WXand DXCps_6_0 -WX. The 3,498 independent helper cases still pass. This update also records the emitted runtime SCC write and pins the documented refusal of m0 operands. Hosted checks are running on the new head.@chatgpt-codex-connector[bot] on GitHub · 2026-11-25 00:13 UTC · original · reviewed
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit:
4c7111a02fℹ️ 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".