Skip to content

shader: support 64-bit source operands in gfx2hlsl (Part of #1723) - #2039

Merged
MasterDomino merged 7 commits into
R0Y00:mainfrom
tedin7:x2w-r20-64bit-src
Nov 26, 2026
Merged

MasterDomino merged 7 commits into
R0Y00:mainfrom
tedin7:x2w-r20-64bit-src

Conversation

@tedin7

@tedin7 tedin7 commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

Part of #1723

What this unblocks: Run 20 census #10 (64-bit source N, 62 pairs).

gfx2hlsl refused v_lshlrev_b64, v_lshrrev_b64 and v_ashrrev_i64 whenever the 64-bit source was a 32-bit hex literal (for example 0x80000000) 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 for v_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, vcc and exec as 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_words accepts 0x literals of up to 8 hex digits; the signed shift sign-extends.
  • tests/startup_gfx2hlsl_shift64_literal_check.py (new, registered in CMakeLists.txt as startup_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: 0x41 removed from the refusal list, since it is now supported.

Verification (head 51842db4f9a5ec1e487771f30070dfab8521e2b3):

  • Linux: 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. With tools/startup/gfx2hlsl.py from origin/main the literal check fails (Unsupported: 64-bit source 0x41).
  • Win2025 (D3D12 WARP): ctest --preset dev and --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.py ok.
  • Real GPU (RTX 3090 through vkd3d-proton, Linux): pending.

AI-assisted; commands listed were executed locally.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-24T23:39:01.193250Z 19a3637 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

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 chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

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".

Comment thread tools/startup/gfx2hlsl.py Resolved
@tedin7

tedin7 commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator Author

Fixed and pushed in df127ec (docs updated, tests pass).

@thepatrickworld

Copy link
Copy Markdown
Contributor

Run at head df127ec8, on the AMD adapter, backend hardware, both compilers.

startup_flat_param words=deadbeef,cafebabe,80000000,c0000000
dxc v_ashrrev_i64 draw 3: deadbeef,cafebabe,80000000,c0000000

12 readbacks per compiler over v_lshlrev_b64, v_lshrrev_b64 and v_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,c0000000 read back unchanged through the arithmetic shift.

AI-assisted.

@tedin7

tedin7 commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator Author

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,c0000000 through v_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.

@tedin7

tedin7 commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator Author

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.

@tedin7 tedin7 closed this Nov 25, 2026
@tedin7 tedin7 reopened this Nov 25, 2026
@NiiRoZz

NiiRoZz commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

A data point from a local request cache, in case it helps prioritise this (counts only).

  • 104 requests there refuse first with 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.
  • With this PR's change applied on top of a local tree (the five files of this PR, nothing else), none of the 104 stops at that refusal any more. tests/startup_gfx2hlsl_shift64_literal_check.py passes there. None of them translates fully yet; they go on to unrelated refusals.
  • In 81 of the 104 every literal has bit 31 clear, so zero and sign extension give the same pair. In 23 at least one literal has bit 31 set (for example 0xffffffff, 0x80000001), all through v_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

@tedin7

tedin7 commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator Author

Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit 45a18be54f9a0804ffbfa2b5f20f50e958b35650:

  • Debug (--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)
  • Release /O2 (--preset release): same command and same 7 tests: 7/7 passed

What changed since df127ec8: merged origin/main (no conflicts), and fixed one bug found in review: a 32-bit hex literal as the source of s_ashr_i64 is now sign-extended, like the vector form. startup_gfx2hlsl_shift64_literal has two new checks for it (s_ashr_i64 and s_lshr_b64 with 0xffffffff); the s_ashr_i64 check 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.

@tedin7

tedin7 commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator Author

@MasterDomino #2039 is ready for review/merge.

  • What changed: merged origin/main (clean), plus a fix so a 32-bit hex literal as the source of s_ashr_i64 is sign-extended (new check in startup_gfx2hlsl_shift64_literal).
  • Head: 45a18be5. CI green. Win2025 WARP dev+release receipt above: 7/7 shift64 tests pass on both presets.
  • Known gaps, same as before this merge: no GPU readback for the hex literal as a 64-bit value, and the constant-bus rule is documented but not enforced.

AI-assisted; commands listed were executed locally.

@Leyukaka

Copy link
Copy Markdown
Contributor

A second capture, consistent with the data point above (local, counts and instruction shape only), at main 7287979. 55 requests stop at 64-bit source <literal>, all v_lshrrev_b64 with an inline shift. In 3 the literal has bit 31 set (0xffffffff twice, 0x80000001 once).

I did not run this branch. With main's translator plus an in-memory wrap of Stage.i64_words that gives (word, 0) for a hex literal of at most 8 digits (what this PR does for v_lshrrev_b64):

AI-assisted.

@tedin7

tedin7 commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator Author

@Leyukaka thank you for the second capture, and @NiiRoZz for the first one.

No code change is needed here. I checked Stage.i64_words at head 45a18be5 (tools/startup/gfx2hlsl.py): a hex literal of at most 8 digits gives (word, 0) for the unsigned shifts, so v_lshrrev_b64 with 0xffffffff or 0x80000001 zero-extends. That is the same mapping as your in-memory wrap. Only the signed form (s_ashr_i64) sign-extends, and startup_gfx2hlsl_shift64_check.py covers both.

The 25 requests that stop next at s_bfm_b64 belong to #2007, so I left them out of this PR on purpose.

Head 45a18be5 is 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) and git show 45a18be5:tools/startup/gfx2hlsl.py | sed -n 5602,5626p.

AI-assisted; commands listed were executed locally.

@MasterDomino MasterDomino left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_b64 and copies bit 31 for v_ashrrev_i64. Wider literals and literal destinations stay refused.

The problem is in scalar_wide_op (tools/startup/gfx2hlsl.py:3755). It now passes helper == 'shr64i' to i64_words as the signedness. But s_bfe_u64 and s_bfe_i64 both use helper bfe64 and differ only in signed (:3804, :3807). So s_bfe_i64 with a hex literal source, refused before this PR, is now accepted with the literal zero-extended.

  • Example: s_bfe_i64 s[20:21], 0x80000000, s9 emits bfe64(2147483648u, 0u, s9, 1u). Under the rule this PR states (sign-extend when the operation is signed), the high word should be 4294967295u. Any field that reaches bit 32 or above reads differently.
  • Suggested fix: self.i64_words(ops[1], helper == 'shr64i' or signed is True), plus an s_bfe_i64 row in startup_gfx2hlsl_shift64_literal_check.py. With that change applied locally, the shift64 and bfe tests still pass.

Docs: please also extend the paragraph.

  • The PR newly accepts hex literals as the 64-bit source of s_lshl_b64, s_lshr_b64, s_ashr_i64, s_bfe_u64 and s_bfe_i64, not only of the vector shifts.
  • "the rule the scalar 64-bit operations use" reads as an existing precedent, but scalar shift and bfe literals were refused until this PR. Only s_mov_b64 zero-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.
  • The branch is 168 commits behind main but merges cleanly, and the shift64/bfe Python checks pass on the merged tree.
  • Mutants: five one-line mutants of the new code (no sign fill, 9-digit literals, the scalar signed flag dropped, the vector call always signed, bit 30 in place of bit 31) were all caught, but only by the string-match startup_gfx2hlsl_shift64_literal. As already noted, no draw reads a literal 64-bit value back yet.

AI-assisted; commands listed were executed locally.

@thepatrickworld

Copy link
Copy Markdown
Contributor

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_test at CMakeLists.txt:4267 runs the check with ${INTAKE_PYTHON} -B, pure Python, no build target:

ctest --preset dev --no-tests=error -R '^startup_gfx2hlsl_shift64_literal$' -V

The runs below call the script directly, with the pe-env Python 3.15 on Windows 11 25H2 build 26200.9974, swapping only tools/startup/gfx2hlsl.py and the check out of this branch's own history (git show <ref>:<path>, then git checkout --):

translator 51842db4 + check 51842db4   rc=0
translator b9208cd7 + check 51842db4   rc=1  AssertionError: a hex literal stays refused as the addend of v_mad_u64_u32 and v_mad_i64_i32
translator 45a18be5 + check 51842db4   rc=1  AssertionError: s_bfe_i64 literal 0xffffffff is sign-extended

Reading

  • 45a18be5 is the head the review was written on: the s_bfe_i64 row fails there, and the emitted text says why — bfe64(4294967295u, 0u, s9, 1u) on that head, bfe64(4294967295u, 4294967295u, s9, 1u) on b9208cd7.
  • b9208cd7 is the head just before 51842db4: the addend row fails there, so the follow-up is pinned by the fixture, not only applied. After the change i64_words takes literal as a third argument (tools/startup/gfx2hlsl.py:7632) and only the two call sites that need it pass it (:5173 for the scalar shifts and bfe, :7663); the v_mad addend at :7831 keeps the default and stays refused.
  • Dropping or signed is True from the call at :5173 reproduces the zero-extended word and the same s_bfe_i64 assertion on b9208cd7; on 51842db4 the same edit also drops literal=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.
  • 0c4e94a3 extends the docs/experiments.md paragraph 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.

@MasterDomino MasterDomino left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving 51842db4; the change request is resolved.

  • The fix: 0c4e94a3 passes helper == 'shr64i' or signed is True to i64_words, so a hex literal source of s_bfe_i64 is sign-extended and s_bfe_u64 stays zero-extended.
  • Pinned: both cases now have rows in startup_gfx2hlsl_shift64_literal_check (bfe64(4294967295u, 4294967295u, s9, 1u) against bfe64(4294967295u, 0u, s9, 0u)).
  • Docs: the paragraph now covers the scalar shifts and the bitfield extracts.
  • 51842db4 tightens the change: a hex literal is now accepted only on the shift and bitfield-extract paths (the literal flag on i64_words). It stays refused as the 64-bit addend of v_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_check
  • startup_gfx2hlsl_scalar_shift64_bfe_check (3498 helper cases)
  • startup_gfx2hlsl_shift64_check
  • rdna2_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.

@MasterDomino
MasterDomino merged commit 6fa2281 into R0Y00:main Nov 26, 2026
5 checks passed
@tedin7

tedin7 commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator Author

@MasterDomino fixed in 51842db4 (merged current main, no rebase).

  • s_bfe_i64 with a hex literal source now sign-extends: s_bfe_i64 s[20:21], 0xffffffff, s9 emits bfe64(4294967295u, 4294967295u, s9, 1u). scalar_wide_op passes helper == 'shr64i' or signed is True, as you suggested. startup_gfx2hlsl_shift64_literal_check.py has new s_bfe_i64 and s_bfe_u64 rows; the s_bfe_i64 row fails without the change and passes with it.
  • Docs: the paragraph now says the hex literal is also the 64-bit source of s_lshl_b64, s_lshr_b64, s_ashr_i64, s_bfe_u64 and s_bfe_i64, that only s_mov_b64 zero-extended a hex literal before, and that the extension rule is an assumption.
  • Found while pre-reviewing: i64_words also feeds v_mad_u64_u32 and v_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.
  • Also aligned: the scanner accepts v_lshlrev_b64 v[2:3], v1, 0x41 (the rdna2_tools_check.py case 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:

  • Linux: 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 on 51842db4.
  • Win2025 (WARP) at 51842db4f9a5ec1e487771f30070dfab8521e2b3: ctest --preset dev and --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.py ok.

Re-requesting your review.

AI-assisted; commands listed were executed locally.

@tedin7
tedin7 requested a review from MasterDomino November 26, 2026 07:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants