Skip to content

Recompiler: compact block-PC table reads one word, and words() counts it - #3475

Open
Foniass wants to merge 2 commits into
xcl-dev:mainfrom
Foniass:dxil-compact-hardening
Open

Foniass wants to merge 2 commits into
xcl-dev:mainfrom
Foniass:dxil-compact-hardening

Conversation

@Foniass

@Foniass Foniass commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #3473; only the top commit (70ed9c60) belongs here.

Follow-ups to KOLESNiii's review of the compact form on #3263 (merged):

  • Plan::words(), which the table limit (MAX_TABLE_WORDS) is checked against, left out the block-PC table and the literal index and pool tables. A program could take the form with more table words than the limit. It now counts them. A plan with a PC table and no block literal no longer emits empty literal tables.
  • The block-PC table (xcl_pc) gets Recompiler: compact literal indices are read from one table word on AMD #3473's change: entries of a power-of-two width, read from one word (entry_bits). AMD's driver got the two-word read wrong for the literal index. In the new GPU test the PC values read right on AMD with the old read too, so this one is for consistency, not a failure I saw.
  • The comments said repeated memory ops split out at >= 4 occurrences; the code does it at >= 2.
  • Tests for code that had none (KOLESNiii's third point):
    • the PC-parameterized classes;
    • the far-jump veneer strip, in a compute program and in the kernel form;
    • words() against the table sizes in the DXIL.

On the 4th point, MAX_TABLE_WORDS 12288 → 32768 on every GPU: I kept 32768.

  • On the retail title, one compute program has a 16121-word plan (19840 blocks). It takes the compact form with 32768, and would go back to the plain form with 12288.
  • amd-dev runs 32768 on its RDNA4 machine by default.
  • I could not measure that program's build memory on AMD. The RX 9070 XT 24 GB report (e964ad2) was of the older compact form, before micro-blocks.

What is in it

  • crates/xcl/src/gpu/dxil/compact.rs: Plan::words, Plan::pc_width, Plan::lit_pool, entry_bits, the one-word PC read, the comments
  • crates/xcl/src/gpu/dxil/compact_tests.rs:
    • gpu_compact_form_with_a_block_pc_table_runs_as_the_plain_form
    • dead_far_jump_veneers_are_left_out: all of them in a compute program, all but the last in the kernel form
    • gpu_compact_form_without_dead_veneers_runs_as_the_plain_form
    • the_word_count_includes_the_pc_and_literal_tables: fails without the words() change; it found the empty literal tables too

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, 19 passed, 0 failed, on:
    • the 5070 Ti
    • the iGPU, native wave64 (XCL_SPLIT_WAVE64=0) and split (=1)
  • cargo test --workspace --no-fail-fast -- --test-threads=4 on 70ed9c6, rebased on main 86e86fc (5070 Ti): 2894 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: all compute programs translated (xcl shaders shaders.rpf --direct --only cs --sample 0 --max-bytes 0). 768 reach the compact plan. None has a literal or PC table, so on this title the program choice is unchanged; their table sizes are the numbers above.
  • 60 s smoke run below.

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: 70ed9c603b013e6726461378c6c1123e00db61f8
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: 16091 MB

Not tested

  • RDNA3 / RDNA4, and the 16121-word program's build memory on AMD
  • A retail program with a PC or literal table (none in this title)

AI use

  • Claude Code with Claude Opus 5.5: wrote the changes and tests, measured the title's table sizes, ran the tests on both GPUs 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:amd Code is specific to AMD / RDNA / wave64 GPUs (scope tag; see needs:amd-test) labels Nov 29, 2026
Foniass and others added 2 commits November 30, 2026 22:43
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>
Follow-ups to the compact form's review on xcl-dev#3263 (KOLESNiii):
- Plan::words(), which the table limit is checked against, now counts
  the block-PC table and the literal index and pool tables, so a
  program can no longer take the form with more table words than
  MAX_TABLE_WORDS. A plan with a PC table and no block literal no
  longer emits empty literal tables.
- The block-PC table gets the literal index table's fix: entries of a
  power-of-two width, read from one word (entry_bits). The two-word
  read is what AMD's driver got wrong for the literal index; the PC
  values themselves read right on AMD in the new test, so this one is
  for consistency, not a seen failure.
- The comments said repeated memory ops split out at >= 4 occurrences;
  the code does it at >= 2.
- Tests for code that had none: a GPU run of blocks that share a class
  through the PC table, dead far-jump veneers left out (all of them in
  a compute program, all but the last in the kernel form) and a GPU
  run of that kernel form against the plain one, and words() against
  the table sizes in the DXIL.

On the retail title nothing changes: none of its 768 compute programs
that reach the compact plan has a literal or PC table. One of them has
a 16121-word plan (19840 blocks), over main's former 12288-word limit
and under the 32768 one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@fromthemoonx

fromthemoonx commented Dec 1, 2026 •

Copy link
Copy Markdown

merge-check
base: 1c8b551
head: 70ed9c6
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> lib binary run on its own 2765 passed, 1 failed, 31 ignored, plus the other binaries 148 passed, 0 failed, 20 ignored (base: 2909 passed); SKIPPED: 25 (22 no wave64, 2 no heap windows, 1 no GPU_UPLOAD heaps), the same set as base; failing: hle::xaudio2::tests::xma2_source_voice_decodes_and_manages_lifetime, the race #3551 fixes, not this PR. The whole-suite run, and one run of the lib binary on its own, ended with 0xc0000005 during eh::tests::thread_dumps_while_threads_run_and_exit (#3586, on main too).
review: read this PR's commit 70ed9c60 on top of #3473 (4afd8a55, which BBareth checked on NVIDIA). One problem, then notes.

  • A PC table of 17 bits or more now overflows its mask. pc_width now goes through entry_bits, which rounds to a power of two, so a program whose largest block PC is at or past dword 65536 (256 KB of code) gets pc_w = 32. The lookup then masks with (1u32 << pc_w) - 1 (compact.rs, the xcl_pc read in emit_with_nest):
    • in a debug build that is a "shift left with overflow" panic during translation;
    • in release the shift count wraps to 0, the mask is 0, and every block reads PC 0.
      On main the width is bits(max_pc_dw + 1).min(32), which only reaches 32 near 2^31 dwords. The literal index (Recompiler: compact literal indices are read from one table word on AMD #3473, lit_w) has the same mask, but needs more than 65536 distinct literals.
      This is from reading the code; I did not build a 256 KB program to show it. u32::MAX >> (32 - w) (or skipping the mask at 32) would cover both.
  • words() now counts the PC table and the literal index and pool, so the MAX_TABLE_WORDS check sees them. A plan with a PC table and no block literal no longer emits literal tables.
  • The one-word PC read matches the packing now that entries are a power of two.
  • gpu::dxil::compact (21 tests, including the new ones on this wave32 GPU): 3 of 3 runs passed.
  • No retail title on this machine.
    performance: tables of power-of-two entries are up to twice as wide; words() counts them against the limit.
    verdict: not yet: block PCs at or past dword 65536 make pc_w 32, and (1u32 << 32) - 1 panics in debug and reads every PC as 0 in release
    hardware / tool and model: RTX 3060 12 GB (610.88), Ryzen 7 5700X, Windows 11 Pro 26300 / Claude Code (Claude Opus 5.5)

@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 labels Dec 1, 2026
@fromthemoonx

Copy link
Copy Markdown

@Foniass merge-check above: with entry_bits, a block PC at or past dword 65536 gives pc_w = 32, and the xcl_pc mask (1u32 << pc_w) - 1 then panics in debug and reads every PC as 0 in release (main capped the width at the plain bit count). Found by reading, not reproduced: #3475 (comment)

@github-actions github-actions Bot removed 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 labels Dec 1, 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:amd Code is specific to AMD / RDNA / wave64 GPUs (scope tag; see needs:amd-test)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants