Skip to content

Recompiler: the shader cache counts a dispatch chain when it goes in (#2454) - #2516

Closed
xpatfussy69x wants to merge 1 commit into
xcl-dev:mainfrom
xpatfussy69x:recompiler/shader-cache-bytes
Closed

xpatfussy69x wants to merge 1 commit into
xcl-dev:mainfrom
xpatfussy69x:recompiler/shader-cache-bytes

Conversation

@xpatfussy69x

Copy link
Copy Markdown

Fixes #2454. ShaderCache::insert added the blob, cache dir, DXIL and samplers to its byte count, but evict_one subtracts ShaderEntry::bytes(), which also counts a split compute shader's dispatch_chain pieces. Evicting such an entry subtracted more than was added: a subtract-with-overflow panic in debug builds (which poisons the global shader_cache() mutex), and in release a count near usize::MAX, after which every insert evicts the whole cache. insert now builds the entry first and counts it with ShaderEntry::bytes(), so both sides use one definition.

What is in it

  • crates/xcl/src/gpu/recomp/pso.rs: ShaderCache::insert counts the entry with ShaderEntry::bytes(); no other behaviour change
  • crates/xcl/src/gpu/recomp/pso.rs: shader_cache_counts_a_dispatch_chain_on_insert_and_evict: an entry with a 300- and a 200-byte piece. Without the fix insert counts 94 bytes where the entry holds 594; with it the count matches and goes back to 0 on eviction

Tested

  • NVIDIA GeForce RTX 3060 (driver 32.0.16.2124, 32-lane waves only), AMD Ryzen 5 7500F, Windows 11, Rust 1.100.0, debug build for the tests, release for the smoke runs
  • cargo test --workspace -- --test-threads=4: 1424 passed, 0 failed, 46 ignored
  • SKIPPED (25): 21 × no wave64; 1 × no heap windows; 3 × per-lane form refused V_MUL_F16 / V_PK_MUL_F16 / V_CVT_F16_F32 (on main too; Recompiler: the per-lane form takes f16 converts and products from #1426 #2182 removes them)
  • cargo test -p xcl --lib shader_cache: 26 passed, 0 failed

Regression run

main:

xcl-smoke v1
commit: 6d12f58a229bc73889878a448c64dc3af25eeba0
gpu: NVIDIA GeForce RTX 3060
title: c3f791f3
seconds: 60
exit: 0x0
frames shown: 1130 (PresentX 1130)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14808 MB

PR:

xcl-smoke v1
commit: bcd375c367dc0fadb5366c013cb73ec1318131ec
gpu: NVIDIA GeForce RTX 3060
title: c3f791f3
seconds: 60
exit: 0x0
frames shown: 1148 (PresentX 1148)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14812 MB

Not tested

  • Whether the title evicts a cached shader with a dispatch chain in this run (the cache's 64 MiB limit may not be reached in 60 s): the smoke run is a regression check only
  • AMD / native wave64 GPUs

AI use

  • Claude Code, Claude Opus 5.5: wrote the fix, the test and this description, ran the tests and both smoke runs on the hardware above

…cl-dev#2454)

ShaderCache::insert added the blob, cache dir, DXIL and samplers to its
byte count, but evict_one subtracts ShaderEntry::bytes(), which also
counts a split compute shader's dispatch_chain pieces. Evicting such an
entry subtracted more than was added: a subtract-with-overflow panic in
debug builds (poisoning the global shader_cache() mutex), and in release
a count near usize::MAX, after which every insert evicts the whole cache.

insert now builds the entry first and counts it with ShaderEntry::bytes(),
so the two sides use one definition.

Test: an entry with a 300- and a 200-byte piece. Without the fix insert
counts 94 bytes where the entry holds 594; with it the count goes back
to 0 on eviction.

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

Copy link
Copy Markdown
Author

Closing as a duplicate of #2475, which makes the same insert/evict byte-count fix for #2454 and was opened first. I'll post this branch's test and smoke results there instead.

@SlopTart

Copy link
Copy Markdown

Tested: current PR head merged onto current origin/main (clean), Linux (Arch, kernel 7.2.15), Mesa 26.2.5 RADV, Radeon RX 7900 XT (NAVI31), cargo target x86_64-pc-windows-gnu run under wine-11.0 (Proton), rustc 1.94.0, vkd3d-proton 3.1 with the XCL patch, official MS DXC (binaries 2026-09-29).

First cold-cache gpu_ suite run: 158 passed / 9 failed. Beyond the baseline trio: gpu_console_textures_upload_every_mip_and_slice, gpu_large_mixed_upload_keeps_tight_staging_and_exact_pixels, copy_scratch_budget_counts_resources_until_gpu_completion, cpu_watchdog_signal_with_inflight_gpu_signal_completes_cleanly, gpu_mirror_upload_follows_cpu_writes_and_later_mapping_changes, gpu_retire_queue_holds_heap_until_blocked_queue_passes_mark. Second run, same head: 164 passed / 3 failed (baseline trio only). Targeted run of shader_cache_counts_a_dispatch_chain_on_insert_and_evict: passed.
Same upload/scratch/lifetime family as the burst I logged on #2486 (that one also showed 6 extras, non-reproducible). Two PRs in unrelated areas now show the identical burst pattern on cold first runs; the tests involved are timing-sensitive, this looks like lane flakiness rather than anything this PR does. Worth watching if CI starts showing the same cluster.

Not tested: retail titles (no title data on this lane, counts only).

AI use: Hermes agent (local Qwen-class) ran both machines and drafted this; I checked it before posting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Recompiler: ShaderCache::bytes integer underflow / usize::MAX wraparound when evicting split compute (dispatch_chain) entries

2 participants