shader: support 64-bit source operands in gfx2hlsl (Part of #1723) #2032
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2039"
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-24T23:32:17Z.
Part of #1723
What this unblocks: Run 20 census #10 (
64-bit source N, 62 pairs).gfx2hlslrefusedv_lshlrev_b64,v_lshrrev_b64andv_ashrrev_i64whenever the 64-bit source was a 32-bit hex literal (for example0x80000000) instead of a register pair or an inline constant. These now lower. The literal fills the low word. The high word is zero for the two unsigned shifts and copies bit 31 forv_ashrrev_i64, the same rule the scalar 64-bit operations already use.Known limit: decimal literals outside the inline range (
65,-17), literals wider than 32 bits, float constants,vccandexecas a 64-bit source stay refused. The zero/sign extension of a literal is taken from the existing scalar rule, not measured on a console.Changes:
tools/startup/gfx2hlsl.py:i64_wordsaccepts0xliterals of up to 8 hex digits; the signed shift sign-extends.tests/startup_gfx2hlsl_shift64_literal_check.py(new, registered inCMakeLists.txtasstartup_gfx2hlsl_shift64_literal): checks the emitted line for each shift with literals that have bit 31 clear and set, and that a 33-bit literal and a literal destination stay refused.tests/startup_gfx2hlsl_shift64_check.py:0x41removed from the refusal list, since it is now supported.Verification (head
51842db4f9a5ec1e487771f30070dfab8521e2b3):python3 -B tests/startup_gfx2hlsl_shift64_literal_check.py,startup_gfx2hlsl_shift64_check.py,startup_gfx2hlsl_mad64_check.py,startup_gfx2hlsl_scalar_shift64_bfe_check.py,python3 -m unittest tests.rdna2_tools_check -k shift64: PASS. Withtools/startup/gfx2hlsl.pyfromorigin/mainthe literal check fails (Unsupported: 64-bit source 0x41).ctest --preset devand--preset release-R '^(startup_gfx2hlsl_shift64_literal|startup_gfx2hlsl_shift64_controls|startup_gfx2hlsl_shift64_warp|startup_gfx2hlsl_scalar_shift64_bfe_controls|startup_gfx2hlsl_mad64.*)$': 7/7 passed on dev, 7/7 on release;tests/rdna2_tools_check.pyok.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T23:38:58Z.
Review: COMMENTED
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit:
19a3637896ℹ️ 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 chatgpt-codex-connector[bot] on 2026-11-24T23:32:28Z.
Codex Review Summary: ✅ Completed
This comment shows the latest Codex review activity on this pull request.
19a3637ℹ️ 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 chatgpt-codex-connector[bot] on 2026-11-24T23:38:58Z.
Code review location:
tools/startup/gfx2hlsl.py; line 1429This expands a public translator capability, but the startup-shift description in
docs/experiments.md:6251–6258still lists only register pairs and inline integers and provides no reproduction command for literal sources. Update that section with the accepted 32-bit hex form, the zero/sign-extension assumption, remaining refusals, and the newstartup_gfx2hlsl_shift64_literalcheck. RootAGENTS.mdexplicitly requires updating the public documentation when a capability changes.AGENTS.md reference: AGENTS.md:L210-L211
Useful? React with 👍 / 👎.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T01:28:33Z.
Review: COMMENTED
No description provided.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T01:13:45Z.
Fixed and pushed in
df127ec8(docs updated, tests pass).Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T01:28:33Z.
Code review location:
tools/startup/gfx2hlsl.py; line 1429Fixed in
df127ec8. docs/experiments.md (64-bit VOP3 shift paragraph) now covers the 32-bit hex literal source, the zero/sign-extension assumption, the remaining refusals, and thestartup_gfx2hlsl_shift64_literalctest command. Verification (Linux):python3 tests/startup_gfx2hlsl_shift64_literal_check.pyandstartup_gfx2hlsl_shift64_check.py-> pass. Windows/WARP not run.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by thepatrickworld on 2026-11-25T13:00:38Z.
Run at head
df127ec8, on the AMD adapter, backendhardware, both compilers.12 readbacks per compiler over
v_lshlrev_b64,v_lshrrev_b64andv_ashrrev_i64, all matching, with three mutation runs per compiler that fail as they should. The sign-filling case is in the run above:0x80000000,c0000000read back unchanged through the arithmetic shift.AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T13:45:10Z.
Thanks for the hardware run. It was at head
df127ec8, which is the current head of this PR.All 12 readbacks per compiler match on the AMD hardware backend. The sign-filling case (
80000000,c0000000throughv_ashrrev_i64) is unchanged, and the three mutation runs fail as expected. This confirms the 64-bit shift lowering on real hardware. No code change is needed.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T13:51:00Z.
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.
Imported from R0Y00/Xbox2Windows. Originally posted by NiiRoZz on 2026-11-25T22:29:53Z.
A data point from a local request cache, in case it helps prioritise this (counts only).
64-bit source <literal>. All 170 failing instructions have one shape:v_lshrrev_b64 v[a:a+1], 0, 0x<literal>, a shift by 0 used as a 64-bit constant move into a VGPR pair. No scalar instruction and no EXEC or VCC destination raises it.tests/startup_gfx2hlsl_shift64_literal_check.pypasses there. None of them translates fully yet; they go on to unrelated refusals.0xffffffff,0x80000001), all throughv_lshrrev_b64, so those rely on the zero-extension rule this PR takes for the unsigned shifts. I could not find that rule stated for a 32-bit literal on a 64-bit vector operand in the LLVM sources I read, so for those 23 it stays an assumption on our side as well; the hardware readbacks above cover the lowering, not that rule on the console.Not measured: any effect at run time. The counts come from one local cache and were taken on a tree that is not current
main.🤖 Generated with Claude Code
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T22:34:44Z.
Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit
45a18be54f9a0804ffbfa2b5f20f50e958b35650:--preset dev):ctest --preset dev -R shift64 --no-tests=error --output-on-failure: 7/7 passed (startup_gfx2hlsl_shift64_warp,startup_gfx2hlsl_shift64_hardware,startup_gfx2hlsl_shift64_literal,startup_gfx2hlsl_shift64_controls,startup_gfx2hlsl_scalar_shift64_bfe_controls,pixel_aot_shift64_warp,pixel_aot_shift64_hardware)/O2(--preset release): same command and same 7 tests: 7/7 passedWhat changed since
df127ec8: mergedorigin/main(no conflicts), and fixed one bug found in review: a 32-bit hex literal as the source ofs_ashr_i64is now sign-extended, like the vector form.startup_gfx2hlsl_shift64_literalhas two new checks for it (s_ashr_i64ands_lshr_b64with0xffffffff); thes_ashr_i64check fails without the fix.Not covered here: the hex literal as the 64-bit value has no GPU readback yet (the draws use the literal only as the shift amount), and the one-scalar-or-literal constant-bus rule in the docs is not enforced by the translator (same on main).
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T22:34:45Z.
@MasterDomino #2039 is ready for review/merge.
origin/main(clean), plus a fix so a 32-bit hex literal as the source ofs_ashr_i64is sign-extended (new check instartup_gfx2hlsl_shift64_literal).45a18be5. CI green. Win2025 WARP dev+release receipt above: 7/7 shift64 tests pass on both presets.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-11-26T01:43:39Z.
A second capture, consistent with the data point above (local, counts and instruction shape only), at main
7287979. 55 requests stop at64-bit source <literal>, allv_lshrrev_b64with an inline shift. In 3 the literal has bit 31 set (0xfffffffftwice,0x80000001once).I did not run this branch. With main's translator plus an in-memory wrap of
Stage.i64_wordsthat gives(word, 0)for a hex literal of at most 8 digits (what this PR does forv_lshrrev_b64):s_bfm_b64(#2007);AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T03:17:53Z.
@Leyukaka thank you for the second capture, and @NiiRoZz for the first one.
No code change is needed here. I checked
Stage.i64_wordsat head45a18be5(tools/startup/gfx2hlsl.py): a hex literal of at most 8 digits gives(word, 0)for the unsigned shifts, sov_lshrrev_b64with0xffffffffor0x80000001zero-extends. That is the same mapping as your in-memory wrap. Only the signed form (s_ashr_i64) sign-extends, andstartup_gfx2hlsl_shift64_check.pycovers both.The 25 requests that stop next at
s_bfm_b64belong to #2007, so I left them out of this PR on purpose.Head
45a18be5is unchanged, CI is green and the branch is mergeable. @MasterDomino nothing new to review on #2039.Commands run locally:
gh pr view 2039(head, CI, mergeStateStatus) andgit show 45a18be5:tools/startup/gfx2hlsl.py | sed -n 5602,5626p.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by MasterDomino on 2026-11-26T05:31:14Z.
Review: CHANGES_REQUESTED
Requesting one small change at
45a18be5.The vector lowering looks right. A 32-bit hex literal fills the low word, and the high word is zero for
v_lshlrev_b64/v_lshrrev_b64and copies bit 31 forv_ashrrev_i64. Wider literals and literal destinations stay refused.The problem is in
scalar_wide_op(tools/startup/gfx2hlsl.py:3755). It now passeshelper == 'shr64i'toi64_wordsas the signedness. Buts_bfe_u64ands_bfe_i64both use helperbfe64and differ only insigned(:3804,:3807). Sos_bfe_i64with a hex literal source, refused before this PR, is now accepted with the literal zero-extended.s_bfe_i64 s[20:21], 0x80000000, s9emitsbfe64(2147483648u, 0u, s9, 1u). Under the rule this PR states (sign-extend when the operation is signed), the high word should be4294967295u. Any field that reaches bit 32 or above reads differently.self.i64_words(ops[1], helper == 'shr64i' or signed is True), plus ans_bfe_i64row instartup_gfx2hlsl_shift64_literal_check.py. With that change applied locally, the shift64 and bfe tests still pass.Docs: please also extend the paragraph.
s_lshl_b64,s_lshr_b64,s_ashr_i64,s_bfe_u64ands_bfe_i64, not only of the vector shifts.s_mov_b64zero-extended a hex literal before.Cache revision: no bump needed, since only formerly refused programs change.
Verified locally (Windows 11 build 26300; WARP 10.0.26100.9818 and AMD Radeon RX 9070 XT, driver 32.0.32029.2010; debug layer on):
ctest --preset dev --no-tests=error -j4 -R shift64: 7/7 passed, 0 skipped.ctest --preset dev --no-tests=error -j4 -R startup_gfx2hlsl: 169/170. The one failure,startup_gfx2hlsl_fma_mix_dispatch_hardware, also fails on this adapter without this PR, so this PR didn't cause it.mainbut merges cleanly, and the shift64/bfe Python checks pass on the merged tree.startup_gfx2hlsl_shift64_literal. As already noted, no draw reads a literal 64-bit value back yet.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by MasterDomino on 2026-11-26T06:04:35Z.
Review: APPROVED
Approving
51842db4; the change request is resolved.0c4e94a3passeshelper == 'shr64i' or signed is Truetoi64_words, so a hex literal source ofs_bfe_i64is sign-extended ands_bfe_u64stays zero-extended.startup_gfx2hlsl_shift64_literal_check(bfe64(4294967295u, 4294967295u, s9, 1u)againstbfe64(4294967295u, 0u, s9, 0u)).51842db4tightens the change: a hex literal is now accepted only on the shift and bitfield-extract paths (theliteralflag oni64_words). It stays refused as the 64-bit addend ofv_mad_u64_u32/v_mad_i64_i32, which now has a refusal row, and the scanner pattern and the Linux CI list match.Pure-Python checks at this head, all passing (Windows 11 build 26300):
startup_gfx2hlsl_shift64_literal_checkstartup_gfx2hlsl_scalar_shift64_bfe_check(3498 helper cases)startup_gfx2hlsl_shift64_checkrdna2_tools_check(19 skips, none failed)The WARP and RX 9070 XT runs from my earlier review were at
45a18be5; the only code changes since are the signedness fix and the narrower literal acceptance. CI is green at this head.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by thepatrickworld on 2026-11-26T06:02:13Z.
Checked on
51842db4: both new rows bite — each fails on the head that preceded its fix. Text-level check of the emitted lowering; no GPU involved.Command
add_testatCMakeLists.txt:4267runs the check with${INTAKE_PYTHON} -B, pure Python, no build target:The runs below call the script directly, with the
pe-envPython 3.15 on Windows 11 25H2 build 26200.9974, swapping onlytools/startup/gfx2hlsl.pyand the check out of this branch's own history (git show <ref>:<path>, thengit checkout --):Reading
45a18be5is the head the review was written on: thes_bfe_i64row fails there, and the emitted text says why —bfe64(4294967295u, 0u, s9, 1u)on that head,bfe64(4294967295u, 4294967295u, s9, 1u)onb9208cd7.b9208cd7is the head just before51842db4: the addend row fails there, so the follow-up is pinned by the fixture, not only applied. After the changei64_wordstakesliteralas a third argument (tools/startup/gfx2hlsl.py:7632) and only the two call sites that need it pass it (:5173for the scalar shifts andbfe,:7663); thev_madaddend at:7831keeps the default and stays refused.or signed is Truefrom the call at:5173reproduces the zero-extended word and the sames_bfe_i64assertion onb9208cd7; on51842db4the same edit also dropsliteral=True, so the literal is refused there (Unsupported: 64-bit source 0xffffffff). Both measured: the added rows are what separate these heads in this fixture.0c4e94a3extends thedocs/experiments.mdparagraph to the five scalar forms and the sign rule, so the documentation half of the review is covered as well.Limits
Emitted text of the lowering checked by the branch's own assertions, not an instruction-level measurement: the change only turns formerly refused programs into accepted ones, so there is nothing to draw on a GPU. One translation per form.
AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T07:18:06Z.
@MasterDomino fixed in
51842db4(merged currentmain, no rebase).s_bfe_i64with a hex literal source now sign-extends:s_bfe_i64 s[20:21], 0xffffffff, s9emitsbfe64(4294967295u, 4294967295u, s9, 1u).scalar_wide_oppasseshelper == 'shr64i' or signed is True, as you suggested.startup_gfx2hlsl_shift64_literal_check.pyhas news_bfe_i64ands_bfe_u64rows; thes_bfe_i64row fails without the change and passes with it.s_lshl_b64,s_lshr_b64,s_ashr_i64,s_bfe_u64ands_bfe_i64, that onlys_mov_b64zero-extended a hex literal before, and that the extension rule is an assumption.i64_wordsalso feedsv_mad_u64_u32andv_mad_i64_i32, which would have started accepting a hex addend (zero-extended even when signed). The hex path is now opt-in per caller, so those two stay refused, with a check for it.v_lshlrev_b64 v[2:3], v1, 0x41(therdna2_tools_check.pycase moved to supported; a scalar amount plus a literal value stays refused), and the new pure-Python check runs in the Linux CI job.Verification:
python3 tests/startup_gfx2hlsl_shift64_literal_check.py,startup_gfx2hlsl_shift64_check.py,startup_gfx2hlsl_mad64_check.py,startup_gfx2hlsl_scalar_shift64_bfe_check.py,startup_gfx2hlsl_bit_alu_check.py,python3 -m unittest tests.rdna2_tools_check -k shift64: all pass. CI green on51842db4.51842db4f9a5ec1e487771f30070dfab8521e2b3:ctest --preset devand--preset release-R '^(startup_gfx2hlsl_shift64_literal|startup_gfx2hlsl_shift64_controls|startup_gfx2hlsl_shift64_warp|startup_gfx2hlsl_scalar_shift64_bfe_controls|startup_gfx2hlsl_mad64.*)$': 7/7 passed on dev, 7/7 on release;tests/rdna2_tools_check.pyok.Re-requesting your review.
AI-assisted; commands listed were executed locally.