Recompiler: compact block-PC table reads one word, and words() counts it #3475
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3475"
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:25:47Z.
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.xcl_pc) gets #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.>= 4occurrences; the code does it at>= 2.words()against the table sizes in the DXIL.On the 4th point,
MAX_TABLE_WORDS12288 → 32768 on every GPU: I kept 32768.e964ad22) 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 commentscrates/xcl/src/gpu/dxil/compact_tests.rs:gpu_compact_form_with_a_block_pc_table_runs_as_the_plain_formdead_far_jump_veneers_are_left_out: all of them in a compute program, all but the last in the kernel formgpu_compact_form_without_dead_veneers_runs_as_the_plain_formthe_word_count_includes_the_pc_and_literal_tables: fails without thewords()change; it found the empty literal tables tooTested
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, 19 passed, 0 failed, on:XCL_SPLIT_WAVE64=0) and split (=1)cargo test --workspace --no-fail-fast -- --test-threads=4on70ed9c60, rebased on main86e86fcb(5070 Ti): 2894 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.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.Regression run
main:
this PR:
Not tested
AI use
🤖 Generated with Claude Code
Imported from ivall/xcl. Originally posted by fromthemoonx on 2026-12-01T23:15:53Z.
merge-check
base:
38ad22daa6head:
70ed9c603bmerge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2967 passed, 0 failed, 52 ignored; SKIPPED: 25 (22 no wave64, 2 no heap windows, 1 no GPU_UPLOAD heaps); failing: none
review: correction: the problem I reported here on 2026-12-01 does not exist. I said a block PC at or past dword 65536 overflows the
xcl_pcmask. Foniass pointed out thatemit_with_nestreads the word directly whenpc_w == 32, so(1u32 << pc_w) - 1is only built for widths of 16 or less. I checked the code at this head and that is right. The literal index has the same guard.70ed9c60. It is stacked on #3473 (4afd8a55, still open), which is in the merge tested here but which I did not review. #3473 has to go first or with it.words()now counts the PC table and the literal index and pool, so theMAX_TABLE_WORDScheck sees them. A plan with a PC table and no block literal no longer emits literal tables.gpu::dxil::compacttests pass in this run, on a wave32 GPU. Wave64 was not run here.performance: power-of-two entries can make these tables up to twice as wide;
words()counts them against the limit. Not measured here. The author's smoke pair has the same frame count (1608) and a peak commit of 16091 MB against 15766 MB.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)
This replaces my
not yeton the same head.Imported from ivall/xcl. Originally posted by fromthemoonx on 2026-12-01T23:22:15Z.
@Foniass merge-check above: with
entry_bits, a block PC at or past dword 65536 givespc_w = 32, and thexcl_pcmask(1u32 << pc_w) - 1then 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: https://github.com/xcl-dev/xcl/pull/3475#issuecomment-7329124464Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T07:14:04Z.
Review: COMMENTED
Review of
70ed9c60: 1 finding(s). 1 are inline.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 bmjask on 2026-12-02T07:14:05Z.
Code review location:
crates/xcl/src/gpu/dxil/compact.rs; line 262pc_widthnow rounds PC entries up to a power of two (17 bits becomes 32), andwords()now counts the PC table against MAX_TABLE_WORDS, so large programs can lose the compact form for a change that fixes no failure anyone has seen. Take a program like the retail one: 19840 blocks, a 16121-word base plan, and code past 256 KB so the largest PC needs 17 bits. The PC table goes from about 10541 to 19841 words, the total of about 35962 exceeds 32768, andautomatic_planreturns None. The program falls back to the plain form, the case that causes driver memory spikes. At 17 bits the total would be about 26662, under the limit. Theuse_pcheuristic (~633) also still prices the table at ~2 B/block, where it's now 4 B/block above 64K code dwords, so it can enable PC parameterization that pushes the plan over the limit. (Thexcl_blockstwo-word read is noted on #3473.)Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T08:06:33Z.
Reply to the merge-check above (https://github.com/xcl-dev/xcl/pull/3475#issuecomment-7329124464), on the "PC table of 17 bits or more overflows its mask" point: that case is guarded. At
70ed9c60, thexcl_pcread inemit_with_nest(compact.rs~864-876) isso with
pc_w == 32the word is read directly and the(1u32 << pc_w) - 1mask is never built; it only exists for widths of 16 or less. The literal index has the same guard (lit_w == 32, ~879-888). The table itself is packed throughu64(v << (at % 32)on au64, ~823-826), which is also fine at 32 bits. So a block PC at or past dword 65536 reads its PC whole rather than panicking or reading 0. The rest of that check (the xaudio2 failure is the race #3551 fixes; the 0xc0000005 is #3586 on main too) matches what I see.AI-assisted: Claude Code (Claude Opus 5.5), posted by Foniass.
Imported from ivall/xcl. Originally posted by fromthemoonx on 2026-12-02T13:42:27Z.
@Foniass you are right, and I was wrong: with
pc_w == 32the word is read directly and the mask is never built. I have withdrawn the finding and rerun the PR on current main: 2967 passed, 0 failed, nowsafe to merge. Sorry for the false alarm. https://github.com/xcl-dev/xcl/pull/3475#issuecomment-7329124464AI use: Claude Code (Claude Opus 5.5) checked the code, ran the tests and wrote this.
Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T14:13:17Z.
@Prime1997 could you take a look at this one for review and merge? My automated review notes are above, if any.
Imported from ivall/xcl. Originally posted by stijn-boer on 2026-12-02T18:15:33Z.
merge-check
base:
817eb1fc9fhead:
70ed9c603bverdict: not yet: the targeted AMD tests passed and the workspace and retail smoke runs ended early on both builds. The large retail shader workload was not verified.
Windows / AMD RDNA4 (native D3D12) — compact DXIL table checks on
70ed9c6Clean merge onto
mainat817eb1f(merge commit05d91c71df84eed58a78e030157dd6a84d318116).git diff --checkwas clean.Setup
d3d12SDKLayers.dll, DXC 1.9.2609.5Tested
cargo build --workspacepassed.cargo test --workspace --no-fail-fast -- --test-threads=4 --show-outputexited 101 on both builds. The baseline table row is from a prior run of the same commit, machine, SDK, and command.SKIPPEDnoticesmainCounts are partial because two test processes aborted on each build.
main— none observed in the comparable results.--test-threads=1 --show-output --nocapture. The two GPU tests compared compact and plain output on AMD. The other checks covered the PC/literal word count, one-word literal index, and dead far-jump veneers.uploads_start_from_each_subresources_statepassed.Shared failures and process aborts
fuzz_validate_and_gpu_1,fuzz_validate_and_gpu_3, andtwo_pass_driver_cache_reuses_both_passes_and_recovers_corrupt_blobsreported failures on both builds.gpu_compute_e2etest processes exited with0xc0000409on both builds.Retail smoke
Ran
scripts/smoke.ps1 -Game <local folder> -Seconds 60 -Xcl <debug binary>withXCL_UMA_DRIVER=mixedfor title hash2c508222.main0xc00004090xc00004090xc0000409The first run's higher startup commit did not reproduce. These exits leave frame and steady-state memory behavior unverified.
Diff review
The table count now includes packed PC and literal data. Power-of-two entry widths keep indices within one word, with a separate direct load for 32-bit entries.
Not tested
Remaining workspace tests after the aborts, retail performance, the referenced 16,121-word shader workload, and RDNA2/RDNA3 hardware.
AI use
Codex (GPT-6) merged and built the PR, ran the tests, compared the results with
main, reviewed the diff, and drafted this report.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.