Skip to content

Recompiler: compact literal indices are read from one table word on AMD - #3473

Open
Foniass wants to merge 1 commit into
xcl-dev:mainfrom
Foniass:dxil-compact-literal-index-one-word
Open

Foniass wants to merge 1 commit into
xcl-dev:mainfrom
Foniass:dxil-compact-literal-index-one-word

Conversation

@Foniass

@Foniass Foniass commented Nov 29, 2026 •

Copy link
Copy Markdown
Collaborator

Follow-up to #3261 (merged): on AMD the compact form read every parameterized literal as 0. moombathepilot's merge-check on #3261 found it on an RX 7800 XT (gpu_compact_form_with_micro_blocks_and_literal_table_runs_as_the_plain_form: s1 = 0 instead of 10045, native and split wave64). I reproduced it on this PC's RDNA2 iGPU (Ryzen 7 7800X3D, driver 32.0.21030), where the plain form gives 10045 and the same DXIL is right on NVIDIA.

Cause: a block's literal comes through two tables, a bit-packed pool index per block (xcl_lit_idx) and the pool (xcl_lit_pool). An index could straddle two words and was read with a two-word funnel extraction. On AMD:

  • the index as a value is right (the sum of the indices came out right);
  • the pool read with that index gives 0, and with a clamp it gives the last entry, so the driver sees a too-large index;
  • the same read with a one-word extraction gives the right literals;
  • the result is the same with every one of our optimizer passes off.

So this looks like an AMD driver miscompile of that pattern. The index width is now a power of two, so no index straddles two words and the lookup reads one word. The table grows at most 2x (8-bit indices stay 8 bits, 9 bits take 16).

What is in it

  • crates/xcl/src/gpu/dxil/compact.rs: power-of-two literal index width, one-word read
  • crates/xcl/src/gpu/dxil/compact_tests.rs:
    • a_literal_index_is_read_from_one_word (new, runs without a GPU, fails without the fix: 2 reads of the table)
    • the GPU test also runs a 300-copy program (9-bit indices)

Tested

  • NVIDIA GeForce RTX 5070 Ti (driver 32.0.16.2114) and AMD Radeon RDNA2 iGPU (driver 32.0.21030, XCL_ADAPTER=radeon), AMD Ryzen 7 7800X3D, Windows 11 build 26300, Rust 1.100.0 (stable-x86_64-pc-windows-msvc), debug tests, release smoke
  • cargo test -p xcl --lib gpu::dxil::compact_tests -- --test-threads=1, 15 passed, 0 failed, on:
    • the iGPU, native wave64 (XCL_SPLIT_WAVE64=0) and split (=1)
    • the 5070 Ti
    • Without the fix the iGPU fails the GPU test as above.
  • cargo test --workspace --no-fail-fast -- --test-threads=4 on 4afd8a5, rebased on main 86e86fc (5070 Ti): 2890 passed, 0 failed, 51 ignored. SKIPPED: 28 notices, almost all no wave64 (the others: no D3D12 debug layer, heap windows off, driver cache needs Developer Mode). The narrower runs listed here are from before the rebase.
  • Retail title: 60 s smoke run below (the title has no compact program with a literal table, so it doesn't reach this code).

Regression run

main:

xcl-smoke v1
commit: 86e86fcb33f94fa5d0c809d9b50af7b84bf49cce
gpu: NVIDIA GeForce RTX 5070 Ti
title: 3cb1d8e0
seconds: 60
exit: 0x0
frames shown: 1608 (PresentX 1608)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15766 MB

this PR:

xcl-smoke v1
commit: 4afd8a55bd63e82cee8ac1d33a1941d78d50e456
gpu: NVIDIA GeForce RTX 5070 Ti
title: 3cb1d8e0
seconds: 60
exit: 0x0
frames shown: 1449 (PresentX 1449)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15737 MB

Not tested

  • RDNA3 / RDNA4 with this fix (moombathepilot's RX 7800 XT showed the bug; a rerun there would confirm the fix)
  • A retail program that takes the literal table (none in this title)

AI use

  • Claude Code with Claude Opus 5.5: reproduced the failure on the iGPU, narrowed it down to the two-word extraction, wrote the fix and the tests, ran the tests and the smoke runs, wrote this description.

🤖 Generated with Claude Code

@github-actions github-actions Bot added area:recompiler RDNA2 decoder, HLSL/direct-DXIL recompiler, wave64/wave32 area:tests Unit, integration, e2e tests, or testtitle gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks) labels Nov 29, 2026
@bobosneefdev

Copy link
Copy Markdown

Test report on RDNA2 discrete (RX 6800).

Tested

  • AMD Radeon RX 6800 16 GB (driver 32.0.21045.29003), Ryzen 5 5600X3D, Windows 11 Pro 26200, Rust 1.98.1 MSVC, release tests
  • origin/main 53e85fb: gpu_compact_form_with_micro_blocks_and_literal_table_runs_as_the_plain_form fails (left: (50, 0, 1, 5), right: (50, 10045, 1, 5)): same failure as on the 7800 XT and the iGPU
  • this PR at 12d4f35, cargo test --release -p xcl --lib gpu::dxil::compact_tests -- --test-threads=1:
    • XCL_SPLIT_WAVE64=0: 15 passed, 0 failed, 0 ignored
    • XCL_SPLIT_WAVE64=1: 15 passed, 0 failed, 0 ignored
  • Recompiler: compact block-PC table reads one word, and words() counts it #3475 at 8d1bc67, same command: 19 passed, 0 failed, 0 ignored, with both XCL_SPLIT_WAVE64=0 and =1
  • No SKIPPED tests in these runs.

Not tested

  • the whole suite at either head
  • a smoke run of a retail title at either head

Report written with Claude Code (Claude Opus 5.5) from runs on this machine.

@ClosetPie107

Copy link
Copy Markdown

Test report for #3473 at 12d4f354011282d684b9346cecaead13fec955ce, against its merge-base with main, 53e85fb1, under Wine on AMD.

Tested

Not tested

  • native Windows
  • NVIDIA
  • the gpu:: tests in the suite runs
  • the workspace's other crates and integration tests (only -p xcl --lib)
  • a game run (no regression block)

AI use: Claude Code (Claude Opus 5.5) ran the tests and wrote this report.

The compact form (xcl-dev#3261) gives each block of a parameterized class its
literal through two tables: a bit-packed index per block (xcl_lit_idx)
and the pool of distinct literals (xcl_lit_pool). An index could
straddle two words of xcl_lit_idx and was read with a two-word funnel
extraction. AMD's driver (an RX 7800 XT, 32.0.32029, and a Ryzen
7800X3D's RDNA2 iGPU, 32.0.21030) gets the pool index wrong from that
extraction: gpu_compact_form_with_micro_blocks_and_literal_table_runs_
as_the_plain_form read 0 for every literal (s1 = 0 instead of 10045),
in native and split wave64. The same DXIL runs correctly on NVIDIA, and
the index is right when used as a value; only its use as the next
table's index goes wrong (with a clamp, it read the last pool entry).

The index width is now a power of two, so an index never straddles two
words and the lookup reads one word. The table grows at most 2x (an
8-bit index stays 8 bits; 9 bits take 16).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Foniass
Foniass force-pushed the dxil-compact-literal-index-one-word branch from 12d4f35 to 4afd8a5 Compare November 30, 2026 23:07
@github-actions github-actions Bot added needs-pr-check Failing the PR description check (CONTRIBUTING.md) and removed needs-pr-check Failing the PR description check (CONTRIBUTING.md) labels Nov 30, 2026
@Foniass Foniass closed this Nov 30, 2026
@Foniass Foniass reopened this Nov 30, 2026
@thehollowedone

Copy link
Copy Markdown
Contributor

Source review on head 4afd8a55: I found no defect in the new literal-index writer/reader. One regression boundary is still unexercised. The 300-copy GPU case makes the index table 16 bits wide, but sgpr[4] = 50 exits after ten 5-unit copies. Its numeric comparison never reads a pool index above 255, so a high-bit error could still pass. The single-read disassembly assertion checks the instruction shape, not that value.

Keep the fast 200-copy case and let the 300-copy case execute its full chain. That checks the widened index against the plain form and the expected literal sum. This test is also present in stacked #3475, so the change should carry forward there.

Candidate test-only diff (not run here)
diff --git a/crates/xcl/src/gpu/dxil/compact_tests.rs b/crates/xcl/src/gpu/dxil/compact_tests.rs
@@
-    st.sgpr[4] = 50;
     let o = KernelOptions { wave64: true, split: runner::split_wave64(), mem_windows: 1, sampler_base: 0 };
     for copies in [200, 300] {
+        st.sgpr[4] = if copies == 300 { 1500 } else { 50 };
         let code = loads_and_literals(copies);
@@
-        assert_eq!((c.sgpr[0], c.sgpr[1], c.sgpr[5], c.sgpr[8]), (50, (1000..1010).sum::<u32>(), 1, 5), "{copies} copies");
+        let end = if copies == 300 { 1300 } else { 1010 };
+        assert_eq!((c.sgpr[0], c.sgpr[1], c.sgpr[5], c.sgpr[8]), (st.sgpr[4], (1000..end).sum::<u32>(), 1, 5), "{copies} copies");

I did not run this candidate or a GPU test. AI use: OpenAI Codex (GPT-6.2 Sol) checked the test path; OpenAI Codex (GPT-6.2 Astra) independently reviewed the index encoding and decoding.

@BBareth

BBareth commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

merge-check claim
head: 4afd8a5

@github-actions github-actions Bot added needs-1st-check Passes gates; needs first independent merge-check (#3041) needs:amd-test Needs a test report or merge-check on an AMD GPU needs:nvidia-test Needs a test report or merge-check on an NVIDIA GPU labels Dec 1, 2026
@BBareth

BBareth commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

merge-check
base: 493dbd3
head: 4afd8a5
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2901 passed, 0 failed, 51 ignored; 28 SKIPPED lines, as on the base; failing: none. The base alone, same machine, same commit: 2900 passed, 0 failed, 51 ignored, 28 SKIPPED lines (22 no wave64, 2 no heap windows, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 1 cannot disable the driver cache). The new test a_literal_index_is_read_from_one_word ran and passed, and gpu_compact_form_with_micro_blocks_and_literal_table_runs_as_the_plain_form ran on the GPU with 200 and 300 copies and passed (this adapter is wave32, so through the split form).
review: no blocking finding; two files (+29/-16), every line read. The literal index width in emit_with_nest is rounded up to a power of two (at most 32), so an index never crosses a 32-bit word of xcl_lit_idx, and the lookup reads one word and shifts instead of joining two; the packing loop and the table size already work for any width, and the 32-bit case keeps its own branch, so the 1 << lit_w mask is never reached with 32. Cost: the index table grows (9 bits are stored in 16, 17 in 32). Not tested here: an AMD GPU, where the wrong index was read; on NVIDIA the old and the new form both pass.
performance: none measurable: one table read less per literal lookup, a larger constant table.
verdict: safe to merge
hardware / tool and model: RTX 5070 Ti 16 GB, driver 621.24 (32.0.16.2124); i7-12700K; Windows 11 26200. Claude Code, Claude Fable 5.2 read the diff, ran the build and the suite and wrote this check.

@github-actions github-actions Bot added needs-2nd-check Has 1 safe merge-check; needs second independent check (#3041) and removed needs-1st-check Passes gates; needs first independent merge-check (#3041) needs:nvidia-test Needs a test report or merge-check on an NVIDIA GPU labels Dec 1, 2026

@bmjask bmjask left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review of 4afd8a55: 1 finding(s). These are on lines outside the diff:

crates/xcl/src/gpu/dxil/compact.rs:828: Not certain about this one, because it rests on the PR's AMD diagnosis, which hasn't been confirmed: if the two-word read (shift and OR across two words) is what the AMD driver miscompiles, it's still used for two other tables. xcl_blocks (~828) is read that way, and its field is used as an index into xcl_steps / xcl_targets (~874, ~885), the same "extracted value used as the next table's index" pattern. A plan whose cb+pb width isn't a power of two (e.g. 11 or 13 bits) has entries that straddle words, so on RDNA2/3 the loop could jump to the wrong block. The xcl_pc table (pc_w = bits(max_pc_dw+1), ~848) is read the same way, where a wrong value would give S_GETPC bad addresses. Fixing the read pattern itself, or applying power-of-two widths to every packed table, would cover all three.


These findings come from an AI-assisted review (Claude Code) and focus on correctness. Each is a candidate; please check it before acting on it.

@fromthemoonx

fromthemoonx commented Dec 2, 2026 •

Copy link
Copy Markdown

merge-check
base: 5eaadb5
head: 4afd8a5
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2975 passed, 0 failed, 52 ignored (base: 2974 passed, 0 failed, 52 ignored); SKIPPED: 25 (22 no wave64, 2 no heap windows, 1 no GPU_UPLOAD heaps), the same set as base; failing: none
review: read the whole diff (2 files, +29 -16). No problem in the code; one gap in the tests, not a blocker.

  • The index width is a power of two, so an index never crosses a word and the one-word read is enough. At width 32 the word is read directly, so the mask is never built for 32.
  • thehollowedone's point about the 300-copy GPU case is right. With the mask cut to 8 bits (andc(le, 0xff)), all 17 gpu::dxil::compact tests still pass.
  • I ran their proposed change (300 copies run to the end, sgpr[4] = 1500) on this wave32 GPU, through the split form:
    • this PR passes (17 of 17);
    • the 8-bit mask fails (sum 332331, expected 344850);
    • the width without next_power_of_two, still read from one word, fails (315785).
      So the PR reads indices above 255 correctly here, and the change is worth adding.
  • Not run here: AMD, where the bug was. bobosneefdev's RX 6800 report (on 12d4f354, before the rebase) shows it failing on main and passing with the PR. No title was run here.
    performance: one table read less per literal lookup; the index table is up to twice as wide. Not measured here. In the author's smoke pair the PR has 1449 frames against 1608 (90 %, within the limit), and the description says the title does not reach this code.
    verdict: safe to merge
    hardware / tool and model: RTX 3060 12 GB (610.88), Ryzen 7 5700X, Windows 11 Pro 26300 / Claude Code (Claude Opus 5.5)

@bmjask

bmjask commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

@Prime1997 could you take a look at this one for review and merge? My automated review notes are above, if any.

@github-actions github-actions Bot added ready-to-merge Has 2 independent safe merge-checks on current head (#3041) and removed needs-2nd-check Has 1 safe merge-check; needs second independent check (#3041) needs:amd-test Needs a test report or merge-check on an AMD GPU labels Dec 2, 2026
@throny throny added needs:amd-test Needs a test report or merge-check on an AMD GPU needs:title-run Runtime change: needs a merge-check with a real title run into the world (#3041) and removed ready-to-merge Has 2 independent safe merge-checks on current head (#3041) labels Dec 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:recompiler RDNA2 decoder, HLSL/direct-DXIL recompiler, wave64/wave32 area:tests Unit, integration, e2e tests, or testtitle gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks) needs:amd-test Needs a test report or merge-check on an AMD GPU needs:title-run Runtime change: needs a merge-check with a real title run into the world (#3041)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants