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

Open
Foniass wants to merge 1 commit from upstream-pr/3473 into main
Foniass commented 2026-11-29 23:17:28 +00:00 (Migrated from github.com)

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:

  • 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 4afd8a55, rebased on main 86e86fcb (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

<!-- greyfinch-sync:ivall/xcl:issue:5556224534 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3473). Originally posted by [Foniass](https://github.com/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: - 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 4afd8a55, rebased on main 86e86fcb (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](https://claude.com/claude-code)
bobosneefdev commented 2026-11-30 00:36:48 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bobosneefdev on 2026-11-30T00:36:48Z.


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 53e85fb1: 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 12d4f354, 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
  • #3475 at 8d1bc67b, 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.

<!-- greyfinch-sync:ivall/xcl:comment:7265424747 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3473#issuecomment-7265424747). Originally posted by [bobosneefdev](https://github.com/bobosneefdev) on 2026-11-30T00:36:48Z. --- 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` 53e85fb1: `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 12d4f354, `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 - #3475 at 8d1bc67b, 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 commented 2026-11-30 16:03:10 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by ClosetPie107 on 2026-11-30T16:03:10Z.


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

Tested

  • RX 9070 16 GB (RDNA4), Mesa 26.3.1 RADV, Ryzen 5 9600X, CachyOS; Proton Experimental experimental-11.0-20261112, stock vkd3d-proton master 71cae091. Debug build, x86_64-pc-windows-gnu, under Wine. It wasn't run on Windows.
  • Command: cargo test --locked -p xcl --lib --target x86_64-pc-windows-gnu -- <filter>.
  • The PR's new tests, each alone (--test-threads=1 <name>): passes: a_literal_index_is_read_from_one_word. 1 passed, 0 failed.
  • The lib suite at --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_flags and execute_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:
    • #3473 12d4f354: 1581 passed, 117 failed, 5 ignored
    • base 53e85fb1: 1581 passed, 117 failed, 5 ignored
  • The same tests fail on both. Most of the base's failures under Wine are main's known ones on stock vkd3d-proton: list creation refused (E_INVALIDARG, #175 / #1701) and the tests after it (#3067).
  • This run has no gpu:: tests in the suite, so it doesn't run translated programs on the RX 9070; only the new compact-form test.

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.

<!-- greyfinch-sync:ivall/xcl:comment:7284036487 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3473#issuecomment-7284036487). Originally posted by [ClosetPie107](https://github.com/ClosetPie107) on 2026-11-30T16:03:10Z. --- Test report for #3473 at `12d4f354011282d684b9346cecaead13fec955ce`, against its merge-base with `main`, `53e85fb1`, under Wine on AMD. **Tested** - RX 9070 16 GB (RDNA4), Mesa 26.3.1 RADV, Ryzen 5 9600X, CachyOS; Proton Experimental `experimental-11.0-20261112`, stock vkd3d-proton `master` `71cae091`. Debug build, `x86_64-pc-windows-gnu`, under Wine. It wasn't run on Windows. - Command: `cargo test --locked -p xcl --lib --target x86_64-pc-windows-gnu -- <filter>`. - The PR's new tests, each alone (`--test-threads=1 <name>`): passes: `a_literal_index_is_read_from_one_word`. **1 passed, 0 failed.** - The lib suite at `--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_flags` and `execute_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: - #3473 `12d4f354`: 1581 passed, 117 failed, 5 ignored - base `53e85fb1`: 1581 passed, 117 failed, 5 ignored - The same tests fail on both. Most of the base's failures under Wine are `main`'s known ones on stock vkd3d-proton: list creation refused (`E_INVALIDARG`, #175 / #1701) and the tests after it (#3067). - This run has no `gpu::` tests in the suite, so it doesn't run translated programs on the RX 9070; only the new compact-form test. **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.
thehollowedone commented 2026-12-01 04:48:05 +00:00 (Migrated from github.com)

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

<!-- greyfinch-sync:ivall/xcl:comment:7301114610 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3473#issuecomment-7301114610). Originally posted by [thehollowedone](https://github.com/thehollowedone) on 2026-12-01T04:48:05Z. --- Source review on [head `4afd8a55`](https://github.com/xcl-dev/xcl/commit/4afd8a55bd63e82cee8ac1d33a1941d78d50e456): I found no defect in the new literal-index writer/reader. One regression boundary is still unexercised. The [300-copy GPU case](https://github.com/xcl-dev/xcl/blob/4afd8a55bd63e82cee8ac1d33a1941d78d50e456/crates/xcl/src/gpu/dxil/compact_tests.rs#L187-L202) 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. <details> <summary>Candidate test-only diff (not run here)</summary> ```diff 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"); ``` </details> 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 commented 2026-12-01 07:30:25 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by BBareth on 2026-12-01T07:30:25Z.


merge-check claim
head: 4afd8a55bd

<!-- greyfinch-sync:ivall/xcl:comment:7304137903 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3473#issuecomment-7304137903). Originally posted by [BBareth](https://github.com/BBareth) on 2026-12-01T07:30:25Z. --- merge-check claim head: 4afd8a55bd63e82cee8ac1d33a1941d78d50e456
BBareth commented 2026-12-01 07:47:07 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by BBareth on 2026-12-01T07:47:07Z.


merge-check
base: 493dbd3dd0
head: 4afd8a55bd
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.

<!-- greyfinch-sync:ivall/xcl:comment:7304475912 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3473#issuecomment-7304475912). Originally posted by [BBareth](https://github.com/BBareth) on 2026-12-01T07:47:07Z. --- merge-check base: 493dbd3dd0cd50b4c3e8d28f73ab9b504fcd8158 head: 4afd8a55bd63e82cee8ac1d33a1941d78d50e456 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.
bmjask commented 2026-12-02 07:14:03 +00:00 (Migrated from github.com)

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

<!-- greyfinch-sync:ivall/xcl:review:6146260050 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3473#pullrequestreview-6146260050). Originally posted by [bmjask](https://github.com/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 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 commented 2026-12-02 14:07:36 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by fromthemoonx on 2026-12-02T14:07:36Z.


merge-check
base: 5eaadb54c1
head: 4afd8a55bd
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)
<!-- greyfinch-sync:ivall/xcl:comment:7348030923 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3473#issuecomment-7348030923). Originally posted by [fromthemoonx](https://github.com/fromthemoonx) on 2026-12-02T14:07:36Z. --- merge-check base: 5eaadb54c14e0fc29597b2a1689d7dbd83491303 head: 4afd8a55bd63e82cee8ac1d33a1941d78d50e456 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 commented 2026-12-02 14:13:21 +00:00 (Migrated from github.com)

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.

<!-- greyfinch-sync:ivall/xcl:comment:7348187349 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3473#issuecomment-7348187349). Originally posted by [bmjask](https://github.com/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.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3473:upstream-pr/3473'
git switch 'upstream-pr/3473'

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.

git switch 'main'
git merge --no-ff 'upstream-pr/3473'
git switch 'upstream-pr/3473'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3473'
git switch 'upstream-pr/3473'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3473'
git switch 'main'
git merge --squash 'upstream-pr/3473'
git switch 'main'
git merge --ff-only 'upstream-pr/3473'
git switch 'main'
git merge 'upstream-pr/3473'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
xcl-dev/xcl!3473
No description provided.