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

Open
github-bot wants to merge 1 commit from github-bot/gh-2594 into main AGit
Owner

@⁠storrmzz on GitHub · 2026-11-26 01:01 UTC · original
storrmzz:shaders/reuse-cache-read-buffer → main · +77 −2 · 2 files · 1 commits · draft

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).

**@⁠storrmzz** on GitHub · 2026-11-26 01:01 UTC · [original](https://github.com/xcl-dev/xcl/pull/2594) `storrmzz:shaders/reuse-cache-read-buffer` → `main` · +77 −2 · 2 files · 1 commits · draft 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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:34:36 +00:00
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-26 01:13 UTC · original

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

**@⁠DavidM1911** on GitHub · 2026-11-26 01:13 UTC · [original](https://github.com/xcl-dev/xcl/pull/2594#issuecomment-7179556439) 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
Author
Owner

@⁠mokkamokacaffe on GitHub · 2026-11-26 13:25 UTC · original

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.
**@⁠mokkamokacaffe** on GitHub · 2026-11-26 13:25 UTC · [original](https://github.com/xcl-dev/xcl/pull/2594#issuecomment-7193326931) 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.
Author
Owner

@⁠mokkamokacaffe on GitHub · 2026-11-26 14:00 UTC · original

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.
**@⁠mokkamokacaffe** on GitHub · 2026-11-26 14:00 UTC · [original](https://github.com/xcl-dev/xcl/pull/2594#issuecomment-7194145696) **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.
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2594/head:github-bot/gh-2594'
git switch 'github-bot/gh-2594'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2594'
git switch 'github-bot/gh-2594'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2594'
git switch 'github-bot/gh-2594'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2594'
git switch 'main'
git merge --squash 'github-bot/gh-2594'
git switch 'main'
git merge --ff-only 'github-bot/gh-2594'
git switch 'main'
git merge 'github-bot/gh-2594'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.