Skip to content

Shaders: reuse the file buffer when loading unsplit cache entries - #2594

Draft
storrmzz wants to merge 1 commit into
xcl-dev:mainfrom
storrmzz:shaders/reuse-cache-read-buffer
Draft

storrmzz wants to merge 1 commit into
xcl-dev:mainfrom
storrmzz:shaders/reuse-cache-read-buffer

Conversation

@storrmzz

Copy link
Copy Markdown

Loading a translated shader cache entry currently allocates a second payload-sized buffer after reading the file. Reuse the validated file buffer for entries without split pieces; split entries retain their existing allocation and validation behavior.

What is in it

  • Reuse the unsplit payload buffer in pso.rs, with ownership/round-trip and malformed-entry tests; document it in README.

Tested

  • Ryzen 7 8840HS, Radeon 780M (32.0.31033.3), Windows 11 Pro 26300, Rust 1.100.0; debug workspace, optimized standalone benchmark.
  • cargo build --workspace --jobs 2: passed.
  • cargo test --workspace --no-fail-fast --jobs 2 -- --test-threads=4 --nocapture: 1436 passed, 1 failed, 47 ignored; 11 SKIPPED subcases (six unsupported f16/conversion cases, one driver-cache test requiring Developer Mode, three missing-debug-layer cases, one unavailable heap-window case).
  • The sole failure is gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1, seed 722; reproduced before this optimization on base 08db802. No test was disabled to conceal it. The final branch is based on b49be18.
  • Buffer-ownership test fails before the optimization and passes after it. The standalone old/new loader comparison agrees on 2,664 valid/malformed inputs.
  • Two warm-file-cache runs of the extracted production loader (including validation), synthetic structurally valid containers, rustc -O, alternating order, nine-round medians: 4-16 MiB entries loaded 27-35% faster, with approximately half the incremental heap peak. This does not measure game loading or FPS.

Regression run
Not run: no unpacked retail title available. The required main/head smoke pair is still missing; this is draft material and cannot pass the runtime PR description gate yet.

Not tested

  • Retail games, overall loading time/FPS, cold physical-disk reads, NVIDIA/Intel GPUs. Optional XCL_SAMPLE_* inputs were unset. The full suite is not green because of the pre-existing GPU failure above.

AI use
This PR was created with AI assistance from OpenAI Codex (gpt-6-astra).

Move a validated unsplit payload to the start of its read buffer and retain that allocation. Keep split entries on the existing copy path so the whole shader does not retain the combined file allocation. Cover allocation ownership, sampler offsets, malformed files and split round trips.
@DavidM1911

Copy link
Copy Markdown
Contributor

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

  • cargo test -p xcl --lib: all passed, 0 failed, 26 ignored.

Thanks!

— Devin

rootw0rm pushed a commit to rootw0rm/xcl that referenced this pull request Nov 26, 2026
bmjask pushed a commit to bmjask/xcl that referenced this pull request Nov 26, 2026
After validating an unsplit translated-shader cache entry, move its payload to the front of the file buffer and retain that allocation instead of making a second payload-sized copy. Split entries keep the existing copy path so they do not retain all piece bytes.

Preserve cache-I/O stall attribution and add ownership, sampler-offset, malformed-entry, and split round-trip coverage. The upstream extracted-loader benchmark reported 27-35% faster 4-16 MiB warm-cache loads with roughly half the incremental heap peak.

GNU Windows-target cargo check passed. Windows/MSVC, GPU tests, and retail smoke were not run on this host.

Adapted from PR xcl-dev#2594.
Assisted-by: OpenAI Codex (gpt-6-astra)
Assisted-by: Codex (GPT-5.6-sol)
@mokkamokacaffe

Copy link
Copy Markdown

Reviewed exact head ae921b40fc1f4253ef186aeab389247bbf4302c3 against main b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7. I found no logic issue requiring a code change.

  • The owned file buffer is validated before it is modified.
  • For an unsplit entry, rest.is_empty() proves the validated DXIL payload reaches the end of the file buffer; b.len() - len therefore identifies its start.
  • copy_within and truncate do not reallocate, which is pinned by the pointer/capacity regression.
  • Split entries retain the prior copying behavior, avoiding retention of all encoded pieces.
  • The regressions cover sampler offsets, malformed/truncated inputs, trailing data and split round trips.
  • git diff --check origin/main...ae921b40 passed.

The same change appears in mega-PR #2778 as 355826c5, whose commit message says it was adapted from #2594. #2594 should remain the focused source of truth rather than being duplicated through #2787.

Not tested

  • I did not produce a Windows/GPU test or retail smoke result. A Linux-hosted Windows-target compile-only attempt did not reach XCL because the environment ran out of disk space while compiling dependencies, so it is not evidence for or against this PR.

AI use

  • OpenAI Codex (GPT-6.2 Astra Ultra) performed the source/provenance review and drafted this comment.

@Prime1997 Prime1997 mentioned this pull request Nov 26, 2026
@mokkamokacaffe

Copy link
Copy Markdown

Tested

  • PR head ae921b40fc1f4253ef186aeab389247bbf4302c3 and upstream main b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7.
  • Windows 10 Pro 22H2 (19045.7846), GTX 1060 6GB (driver 582.66), Core i7-6700, Rust 1.100.0 (MSVC). Debug workspace and optimized release builds passed on both commits.
  • PR cargo test --workspace -- --test-threads=4 stopped after the library suite with 1,308 passed, 3 failed, 27 ignored, and 349 explicit SKIPPED messages.
  • With --no-fail-fast and four test threads, the PR finished with 1,434 passed, 3 failed, and 47 ignored. main finished with 1,432 passed, 3 failed, and 47 ignored. Both logged 359 explicit SKIPPED messages. All three PR failures reproduced on main with matching errors.

Regression run

Both release builds completed from clean worktrees. The smoke runs were blocked because no locally owned unpacked title was available. No xcl-smoke blocks were generated.

Not tested

  • Retail-title runtime behavior.

AI use

  • OpenAI Codex ran the builds and tests and drafted this report. The exact serving model was unavailable in the session.

@tiagonleal

Copy link
Copy Markdown
Contributor

Paired 60 s smoke on RTX 5070 Ti (Windows 11): ae921b40 and main b49be183 both reach 60 presents per 2 s, 0 removals, 0 crashes; the PR's cache tests pass

Tested

  • PR head ae921b40fc1f4253ef186aeab389247bbf4302c3 (still the head, PR open, no smoke posted before this one). Base b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7 = current main and the merge-base. Both built as is, release, in clean detached worktrees; no earlier build was reused.
  • RTX 5070 Ti 16 GB (driver 32.0.16.1742), Ryzen 7 9800X3D, 32 GB RAM, Windows 11 Pro 26300, rustc 1.100.0 (0ef1bc386 2026-11-09). NVIDIA profile for xcl.exe: shader heap 1024 MB.
  • scripts/smoke.ps1 -Seconds 60 -Title 9cc6a39e, default settings, one run each, base first. Neither tree has the shader preparation step that xcl run: prepare shaders in the game window before title execution #2555 added later.
xcl-smoke v1
commit: b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7
gpu: NVIDIA GeForce RTX 5070 Ti
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1516 (PresentX 1516)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15236 MB
xcl-smoke v1
commit: ae921b40fc1f4253ef186aeab389247bbf4302c3
gpu: NVIDIA GeForce RTX 5070 Ti
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1618 (PresentX 1618)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15188 MB
  • cargo test -p xcl --lib translated_cache -- --nocapture --test-threads=1: 6 passed, 0 failed, 0 ignored, including translated_cache_reuses_unsplit_read_buffer and translated_cache_buffer_decode_preserves_validation_and_split_entries.
  • cargo test -p xcl --lib gpu::recomp::pso -- --nocapture --test-threads=4 (the module the PR touches): 29 passed, 0 failed, 1 ignored (compile_time_bench::repeated_pso_shader_compile), no SKIPPED lines.

Not tested

  • Anything past 60 s (no world load), the full workspace suite, a second smoke pair, AMD or Intel. The frame counts differ by 102 between the two runs; with one run each I do not read that as a speed change.

AI use

  • Claude Code with Claude Fable 5.2 and Anthropic subagents (Claude Sonnet 5.5) ran the builds and tests and wrote this; I checked it.

bmjask pushed a commit to bmjask/xcl that referenced this pull request Nov 26, 2026
After validating an unsplit translated-shader cache entry, move its payload to the front of the file buffer and retain that allocation instead of making a second payload-sized copy. Split entries keep the existing copy path so they do not retain all piece bytes.

Preserve cache-I/O stall attribution and add ownership, sampler-offset, malformed-entry, and split round-trip coverage. The upstream extracted-loader benchmark reported 27-35% faster 4-16 MiB warm-cache loads with roughly half the incremental heap peak.

GNU Windows-target cargo check passed. Windows/MSVC, GPU tests, and retail smoke were not run on this host.

Adapted from PR xcl-dev#2594.
Assisted-by: OpenAI Codex (gpt-6-astra)
Assisted-by: Codex (GPT-5.6-sol)
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.

4 participants