Skip to content

Recompiler: count split shader pieces in the cache budget - #2475

Open
Creaa wants to merge 1 commit into
xcl-dev:mainfrom
Creaa:recompiler/split-cache-bytes-2454
Open

Creaa wants to merge 1 commit into
xcl-dev:mainfrom
Creaa:recompiler/split-cache-bytes-2454

Conversation

@Creaa

@Creaa Creaa commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

The in-memory shader cache omitted the allocations for split compute pieces when it admitted an entry, then subtracted those allocations when it evicted the entry. The difference could exceed the remaining byte count. Fixes #2454.

What is in it

Insertion and eviction use the same size calculation. The cache checks the full size before copying the shader blob. A unit test checks admission at a tight limit and that eviction returns the byte count to zero.

Tested

  • NVIDIA GeForce RTX 4070 12 GB, driver 617.14, i7-13700F, Windows 11 build 26300, Rust 1.100.0. Debug tests and release smoke runs.
  • On the original code the split-entry regression check observed 94 bytes charged for a 190-byte entry. On 398cefb, cargo test -p xcl --lib shader_cache_counts_split_pieces_against_its_budget passed.
  • cargo build --workspace succeeded. cargo test --workspace --no-fail-fast -- --test-threads=4 reported 1414 passed, 0 failed, 46 ignored. The harness includes skipped GPU cases in its pass count. There were 29 SKIPPED messages for wave64 support, unsupported direct-DXIL cases, heap windows, D3D12 debug layers, and the driver cache setting that requires Developer Mode.

Regression run

main:

xcl-smoke v1
commit: 06055a7a0fb43c5f83f55e7a2ce201417de171e9
gpu: NVIDIA GeForce RTX 4070
title: RetailTitle
seconds: 60
exit: 0x0
frames shown: 1564 (PresentX 1564)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 16956 MB

this PR:

xcl-smoke v1
commit: 398cefbcd74ab303442a2df2ca1dae13f884fab7
gpu: NVIDIA GeForce RTX 4070
title: RetailTitle
seconds: 60
exit: 0x0
frames shown: 1580 (PresentX 1580)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 16877 MB

Not tested

The retail smoke run did not measure shader-cache pressure or establish whether the title evicted a split shader. The unit test exercises that path directly.

AI use

OpenAI Codex (GPT-6) verified the accounting discrepancy, wrote the patch and test, ran the checks and drafted this description.

Insertion and eviction now use the same entry size. A split shader can exceed the cache limit through its piece allocations even when the primary DXIL is small. The regression test checks admission and eviction with those allocations.

Assisted-by: OpenAI Codex (GPT-6)
gustavsi added a commit to gustavsi/xcl that referenced this pull request Nov 25, 2026
…#2127, xcl-dev#2476, xcl-dev#2479, xcl-dev#2467, xcl-dev#2444, xcl-dev#2447, xcl-dev#2448

Integrates compositor RT tracking fix (xcl-dev#2480), split shader cache budget
(xcl-dev#2475), foreign-thread deferred release (xcl-dev#2474), Wine 4-thread DXC cap
(xcl-dev#2127), DXIL feature/reload fixes (xcl-dev#2476, xcl-dev#2479), DXC loader cleanup
(xcl-dev#2467), console xcl-dev#14 null ppv guard (xcl-dev#2444), root-sig flag stripping
(xcl-dev#2447), and two-pass stream canonicalization (xcl-dev#2448).

Assisted-by: Antigravity (Gemini 4 Neon)
@DavidM1911

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

Thanks!

@bmjask bmjask left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No concrete correctness or accounting defect found. ShaderEntry::size centralizes piece-capacity accounting on insertion and eviction, restoring the cache.bytes invariant; exact-accounting/rejection tests and current Windows CI are green. The intentional exclusion of Vec/Arc/map metadata predates this patch and matches the existing model. I found no blocker.

@SlopTart

Copy link
Copy Markdown

gpu_ suite (cold cache): 164 passed / 3 failed, no crashes. The three are the known baseline on this lane (seed-1003 fuzz, mad/mac contraction, and the promoted-UAV-clear driver gap, PR #2490); none caused by this PR. Note gpu_depth_buffer_created_for_unordered_access_is_placed is green on main now, #2466 did its job on this lane.
Targeted run of shader_cache_counts_split_pieces_against_its_budget: passed.

@xpatfussy69x

Copy link
Copy Markdown

Test run on exact head 398cefb (398cefbcd74ab303442a2df2ca1dae13f884fab7, on its base 06055a7), clean tree.

Tested

  • NVIDIA GeForce RTX 3060 12 GB (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: 1414 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)
  • cargo test -p xcl --lib shader_cache: 26 passed, 0 failed, including shader_cache_counts_split_pieces_against_its_budget
  • I hit the same bug independently (closed duplicate Recompiler: the shader cache counts a dispatch chain when it goes in (#2454) #2516): on main, an entry with a 300- and a 200-byte dispatch-chain piece is counted as 94 bytes on insert and 594 on eviction

Regression run (60 s, default settings)

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

this PR:

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

No crash or device removal; frames 101 % of main's, peak commit 100 %.

Not tested

  • The PR merged into current main (tested on its own base 06055a7; it merges into 6d12f58 without conflicts)
  • Whether the title evicts a cached shader with a dispatch chain in 60 s: a regression check only
  • AMD / native wave64

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and both smoke runs on the machine above and wrote this report.

@thehollowedone

Copy link
Copy Markdown

Independent Windows check of #2475 head 398cefb, on its original base 06055a7, with a clean checkout.

Tested

  • RTX 3080 Ti / NVIDIA 621.35, Ryzen 7 9800X3D, Windows 11 build 26300, rustc 1.99.1 MSVC; debug build and tests.
  • cargo build --offline --locked --workspace: passed.
  • cargo test --offline --locked -p xcl --lib shader_cache_tests --jobs 6 -- --test-threads=1: 24 passed, 0 failed, 0 ignored.
  • cargo test --offline --locked --workspace --no-fail-fast -- --test-threads=4: 1,414 passed, 0 failed, 46 ignored. The output included 25 GPU SKIPPED notices for unsupported features; these were not counted as GPU coverage.

I read the one-file diff. Cache admission and eviction now use the same size calculation, including split-piece vector capacities; the new test checks accounting, eviction to zero, and rejection at one byte below the entry cost. I found no concrete issue in that change.

Not tested: an AMD GPU, native wave64/per-lane features skipped on this adapter, or a retail title on this PR head. I did not run paired smoke; the earlier independent RTX 3060 report contains that separate evidence. This branch predates current main, so the counts above describe the exact PR head, not a rebased merge result.

AI-assisted: Codex (GPT-6, exact variant unavailable) reviewed the diff, ran the tests, and drafted this report.

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

6 participants