Recompiler: compact literal indices are read from one table word on AMD #3473
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3473"
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 ivall/xcl. Originally posted by Foniass on 2026-11-29T23:17:28Z.
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: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 readcrates/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)Tested
XCL_ADAPTER=radeon), AMD Ryzen 7 7800X3D, Windows 11 build 26300, Rust 1.100.0 (stable-x86_64-pc-windows-msvc), debug tests, release smokecargo test -p xcl --lib gpu::dxil::compact_tests -- --test-threads=1, 15 passed, 0 failed, on:XCL_SPLIT_WAVE64=0) and split (=1)cargo test --workspace --no-fail-fast -- --test-threads=4on4afd8a55, rebased on main86e86fcb(5070 Ti): 2890 passed, 0 failed, 51 ignored. SKIPPED: 28 notices, almost allno 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.Regression run
main:
this PR:
Not tested
AI use
🤖 Generated with Claude Code
Imported from ivall/xcl. Originally posted by bobosneefdev on 2026-11-30T00:36:48Z.
Test report on RDNA2 discrete (RX 6800).
Tested
origin/main53e85fb1:gpu_compact_form_with_micro_blocks_and_literal_table_runs_as_the_plain_formfails (left: (50, 0, 1, 5),right: (50, 10045, 1, 5)): same failure as on the 7800 XT and the iGPU12d4f354,cargo test --release -p xcl --lib gpu::dxil::compact_tests -- --test-threads=1:XCL_SPLIT_WAVE64=0: 15 passed, 0 failed, 0 ignoredXCL_SPLIT_WAVE64=1: 15 passed, 0 failed, 0 ignored8d1bc67b, same command: 19 passed, 0 failed, 0 ignored, with bothXCL_SPLIT_WAVE64=0and=1Not tested
Report written with Claude Code (Claude Opus 5.5) from runs on this machine.
Imported from ivall/xcl. Originally posted by ClosetPie107 on 2026-11-30T16:03:10Z.
Test report for #3473 at
12d4f354011282d684b9346cecaead13fec955ce, against its merge-base withmain,53e85fb1, under Wine on AMD.Tested
experimental-11.0-20261112, stock vkd3d-protonmaster71cae091. Debug build,x86_64-pc-windows-gnu, under Wine. It wasn't run on Windows.cargo test --locked -p xcl --lib --target x86_64-pc-windows-gnu -- <filter>.--test-threads=1 <name>): passes:a_literal_index_is_read_from_one_word. 1 passed, 0 failed.--test-threads=2, with--skip gpu::and these six:failed_restore_stops_before_importing_an_unbacked_window,grooming_leaves_a_window_under_1_gib_only_its_hole(both run out of memory here),write_buffer_immediate_on_open_existing_heap_visible_to_cpu,coherent_buffer_sanitizes_console_flags_and_state,serialize_root_signature_strips_console_flags_and_preserves_pc_flagsandexecute_indirect_reads_the_arguments_written_before_it. Under Wine each of the last four ends the process or makes RADV reject later submissions (#3067), so without them the suite reaches its summary:12d4f354: 1581 passed, 117 failed, 5 ignored53e85fb1: 1581 passed, 117 failed, 5 ignoredmain's known ones on stock vkd3d-proton: list creation refused (E_INVALIDARG, #175 / #1701) and the tests after it (#3067).gpu::tests in the suite, so it doesn't run translated programs on the RX 9070; only the new compact-form test.Not tested
gpu::tests in the suite runs-p xcl --lib)AI use: Claude Code (Claude Opus 5.5) ran the tests and wrote this report.
Imported from ivall/xcl. Originally posted by thehollowedone on 2026-12-01T04:48:05Z.
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, butsgpr[4] = 50exits 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)
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.
Imported from ivall/xcl. Originally posted by BBareth on 2026-12-01T07:30:25Z.
merge-check claim
head:
4afd8a55bdImported from ivall/xcl. Originally posted by BBareth on 2026-12-01T07:47:07Z.
merge-check
base:
493dbd3dd0head:
4afd8a55bdmerge: 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_wordran and passed, andgpu_compact_form_with_micro_blocks_and_literal_table_runs_as_the_plain_formran 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_nestis rounded up to a power of two (at most 32), so an index never crosses a 32-bit word ofxcl_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 the1 << lit_wmask 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.
Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T07:14:03Z.
Review: COMMENTED
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 itsfieldis used as an index intoxcl_steps/xcl_targets(~874, ~885), the same "extracted value used as the next table's index" pattern. A plan whosecb+pbwidth 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. Thexcl_pctable (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.
Imported from ivall/xcl. Originally posted by fromthemoonx on 2026-12-02T14:07:36Z.
merge-check
base:
5eaadb54c1head:
4afd8a55bdmerge: 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.
andc(le, 0xff)), all 17gpu::dxil::compacttests still pass.sgpr[4] = 1500) on this wave32 GPU, through the split form: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.
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)
Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T14:13:21Z.
@Prime1997 could you take a look at this one for review and merge? My automated review notes are above, if any.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.