Skip to content

Shaders: a stale-blob probe the driver takes is not created a second time - #2940

Draft
KOLESNiii wants to merge 1 commit into
xcl-dev:mainfrom
KOLESNiii:shaders-stale-probe-one-create
Draft

KOLESNiii wants to merge 1 commit into
xcl-dev:mainfrom
KOLESNiii:shaders-stale-probe-one-create

Conversation

@KOLESNiii

Copy link
Copy Markdown

--pipelines and startup shader preparation create a compute pipeline with the driver's blob of an earlier run. When the driver cannot use the blob but compiles from the DXIL and still succeeds (#1774), the size check on the returned blob dropped that pipeline and created it a second time without the blob, in the same XCL_PIPELINE_THREADS slot. Now the pipeline from a successful probe is kept: one native create. Whether it counts as reused is unchanged (the returned blob has the size handed over). When it doesn't, its own blob replaces the stale one on disk. A refused blob is still compiled again without it, and over the cap it is still capped and removed.

Fixes #2939

What is in it

  • crates/xcl/src/shaders.rs: the create-with-blob decision moves out of Pipelines::make_one into build_with_blob, which takes the native create and GetCachedBlob as closures (the same pattern as create_graphics_pso_cached in real.rs). make_one keeps the slot, counters and file handling.
  • One behaviour change beyond the issue: over the cap, a stale blob that the driver takes is now made and replaced instead of capped and deleted. The expensive compile has already happened inside that create, so throwing the result away gained nothing.
  • Tests: build_with_blob_tests (no GPU) drive the helper with a fake driver: stale blob taken (ettehn's 1,418 → 1,402 bytes), same over the cap, akimfomin's same-size/different-bytes control (asserts one create only, leaving the hit rule open for discussion in Shaders: avoid a second compute PSO create after a successful stale-cache probe #2939), the blob handed back, a pipeline without a blob, refused blob under and over the cap, no blob. pipeline_cap_tests::a_stale_blob_the_driver_takes_is_made_with_one_create_and_replaced (GPU) repeats ettehn's reproducer on real D3D12: the stock pipeline's blob with 16 zero bytes appended, which must be made with one native create (test-only counter on Pipelines) and replaced on disk. It reports SKIPPED when the driver refuses the padded blob.

Tested

  • RTX 2070 SUPER, Windows 11 26300, stable-x86_64-pc-windows-msvc, debug
  • cargo test -p xcl --lib build_with_blob_tests: 8 passed, 0 failed, 0 ignored
  • GPU: pipeline_cap_tests on this head, and the new GPU test on main + the counter (to show it fails without the fix): pending, queued
  • cargo test --workspace -- --test-threads=4: pending, queued

Regression run

  • pending: scripts/smoke.ps1 on a retail game, main 8b957be and this head, both from the same DXIL cache with no driver blobs, so both go through startup pipeline preparation

Not tested

AI use

🤖 Generated with Claude Code

…time

`--pipelines` (and startup shader preparation) creates a compute pipeline
with the driver's blob of an earlier run. A driver that cannot use the
blob may compile from the DXIL and still succeed (xcl-dev#1774); the size check
on the returned blob then dropped that pipeline and called
CreateComputePipelineState again without the blob, in the same
XCL_PIPELINE_THREADS slot (xcl-dev#2939).

The create-with-blob decision moves into build_with_blob, which takes
the native create as a closure: a successful probe is the pipeline
(made, with one create). It counts as reused when its blob has the size
handed over, as before; otherwise its own blob replaces the stale one on
disk. A refused blob is still compiled again without it, and over the
cap is still capped and removed. Over the cap, a stale blob the driver
takes is now made and replaced instead of capped: its compile has
already happened.

Tests: unit tests drive build_with_blob with a fake driver (stale blob
taken, same-size blob with other bytes, refused blob under and over the
cap, no blob), and a GPU test repeats ettehn's reproducer: the stock
pipeline's blob with 16 bytes appended is taken by the driver, made with
one native create, and replaced by the driver's own blob.

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

Copy link
Copy Markdown

I ran the eight exact build_with_blob_tests from ee919a6407afdaefeb295fa0bc3feb0d1868581c in an isolated Rust test binary: 8 passed. I also added a one-case callback counter: uncached success invokes blob_of once. At the calling site, XCL_PSO_DISK_CACHE=0 gives no path, but that callback still calls GetCachedBlob and copies its bytes. The old path skipped both operations when the path was absent.

Returning None from the callback when path is absent preserves that behavior. A regression can count zero exports/copies in that control. The separate warm-cache case also copies each blob into a Rust Vec before deciding by length and dropping it. A retained blob handle plus length would preserve the old no-copy path for equal-sized results. Performance impact is unmeasured. The one-create, fallback and cap controls passed in isolation. AI-assisted source review and isolated compilation with OpenAI Codex.

@andrewDoing

Copy link
Copy Markdown

I compared the native compute PSO path on parent 8b957bec6f82495aec940944c6bf47faa02db590 and draft head ee919a6407afdaefeb295fa0bc3feb0d1868581c, using trace-only instrumentation around the existing calls. All six synthetic runs made exactly one PSO and reported zero refusals.

  • With the disk cache disabled, the parent did not call GetCachedBlob; the draft retrieved and copied a 3,070-byte blob that had no disk destination.
  • On a cold disk-enabled build, the parent borrowed native blob bytes for the write; the draft copied the same number of bytes before writing.
  • On an accepted warm hit, the parent checked GetBufferSize without reading the returned buffer; the draft copied the 3,070 bytes and discarded them after the size check.

The draft's one-create result is preserved in all three cases. Keeping the returned blob handle through the size check and borrowing its contents only when a replacement must be written could avoid these copies; a no-destination cold build could skip retrieval. I did not measure latency, retail hit frequency, or GTA VI startup time. Trace printing itself occurred inside the limited pipeline slot, so these runs should not be used for timing.

AI use: OpenAI Codex with GPT-6.2 Astra instrumented and ran the checks and independently reviewed the source; Codex coordinated and prepared this report.

@ettehn

ettehn commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

Independent native D3D12 run on exact ee919a64: RTX 5070 Ti Laptop, NVIDIA 621.24, Windows 11, SDK DXC 1.8.2502.11. cargo test --offline --locked -p xcl --lib -- build_with_blob_tests pipeline_cap_tests --test-threads=1 --nocapture: 12 passed, 0 failed, 0 skipped. On the real padded-blob fixture, the 1,418-byte input took one native create and was replaced by a 1,402-byte blob (reused=0). The existing over-cap refusal test still reported capped=1, made=0.

I also tried a local overlay for the review above: retain the ID3DBlob and its length through the decision, borrow its bytes only when writing a replacement, and skip GetCachedBlob when there is no cache path. The 12 tests passed with that overlay. I extended the native fixture to set the cap one byte below the synthetic DXIL length after seeding. The successful padded probe still used one native create and wrote the replacement, with no capped increment. No retail run or timing measurement in this check.

OpenAI Codex (6.2sol) assisted with verification.

@ettehn

ettehn commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

Thanks for turning the padded-blob reproducer I posted in #2939 into a GPU regression. Since that test is included in #2940, would you consider adding this co-author trailer for the reproducer and Windows verification?

Co-authored-by: ettehn <141814824+ettehn@users.noreply.github.com>

@oni-swr

oni-swr commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

amd-win check of ee919a6407afdaefeb295fa0bc3feb0d1868581c (parent 8b957bec), native Windows, AMD.

  • RX 7800 XT (RDNA3), driver 32.0.31035.1003, Windows 11 build 26200, AMD Ryzen 7 5700X3D 8-Core Processor , 64 GB, rustc 1.100.0 (0ef1bc386 2026-11-09), debug test profile, DXC 1.8.2502.11 (SDK 10.0.26100.0).
  • cargo test --locked -p xcl --lib -- build_with_blob_tests pipeline_cap_tests --test-threads=1 --nocapture on the head: 12 passed, 0 failed, 0 ignored, 0 skipped.
  • ... -- shaders:: on the head: 19 passed, 0 failed. On the parent binary (run separately, built from its own checkout): 10 passed, 0 failed (the 9 new tests do not exist there).
  • The real padded-blob fixture on this adapter: good blob 954 B, padded blob 970 B, creates=1, made=2, refused=0, reused=0, kept blob 954 B. So the AMD driver also takes a padded blob and returns a smaller one, the same case as on NVIDIA, and the head makes one native create.
  • stale_blob_cannot_bypass_the_offline_pipeline_cap: capped=1, made=0, refused=0.

Not tested: the parent's two-create count on AMD (the fixture is part of this PR, so I did not run it on the parent); a title run or a precompile; cargo test -p xcl in full; correctness on AMD of a driver-returned blob across runs (XCL does not keep AMD blobs on disk by default); no timing of the second create.

AI use: Claude Code (Claude Sonnet 5.5) ran the tests and wrote this.

@akimfomin

Copy link
Copy Markdown

The Radeon and NVIDIA runs both exercised the accepted padded-blob path. Intel’s behavior is still open. I put the exact ee919a64 fixture and return fields in Test Lab #114 and offered the run to a contributor who volunteered native D3D12 testing on Arc B580. If the Intel driver refuses the padded blob, we’ll record the refusal/skip separately from a successful one-create replacement. I’ll bring the credited result here if the run happens.

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.

Shaders: avoid a second compute PSO create after a successful stale-cache probe

5 participants