Skip to content

Shaders: the preparation trusts the driver blobs it checked before - #2951

Draft
throny wants to merge 1 commit into
xcl-dev:nvidia-devfrom
throny:prep-skip-verified
Draft

throny wants to merge 1 commit into
xcl-dev:nvidia-devfrom
throny:prep-skip-verified

Conversation

@throny

@throny throny commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator

At every launch the shader preparation created each used compute pipeline again from its stored driver blob, only to apply its check (the driver makes a pipeline from the blob and returns a blob of the same size), and then dropped the pipeline. That is not free: on an RTX 4080 (driver 621.40) creating a large pipeline from its blob was measured to take as long as compiling it, so the preparation took minutes at every launch, also right after a launch that had completed it. This PR remembers that a blob passed the check and does not create its pipeline again. Part of #2088 (plan and discussion there; the content digest is @ettehn's point).

What is in it

  • crates/xcl/src/hle/d3d12x/real.rs (driver_cache): a marker <blob>.ok beside a blob that passed the check or was just written: the driver's identity (the one the graphics blobs use), the blob's length and an FNV-64 digest of its bytes. verified compares all three with the file as it is now; remove deletes a refused blob together with its marker.
  • crates/xcl/src/shaders.rs (Pipelines::make_one): a record whose blob matches its marker is counted ("pipelines whose blob an earlier pass verified, not created again N") and returns before the worker slot and the driver call. Anything else goes the present way and is marked afterwards. XCL_PREPARE_VERIFY=1 applies the check to every blob again.
  • Tests: a_verified_blob_is_trusted_until_it_changes_or_is_refused (other driver, changed length, same-length overwrite, missing blob, refusal), GPU test a_second_pass_trusts_the_blobs_the_first_verified, and gpu_compute_e2e::offline_compute_pipeline_is_reused_by_a_second_process extended across processes (trusted; a blob overwritten with zeros of the same length is rebuilt and trusted again). Two existing e2e tests list only .pso files and run their reuse assertions with XCL_PREPARE_VERIFY=1, unchanged otherwise.
  • README.md: one bullet for the markers and the switch.

The marker says what the preparation's check said before, no more: it does not prove the driver used the blob (the comment at the check already notes a driver may compile from the DXIL and still succeed). It changes when the check runs, not what it proves.

Tested

  • RTX 4080 16 GB, NVIDIA 621.40, i9-12900K, 64 GB, Windows 11 Pro 26300, Rust 1.100.0, debug for the tests, release for the title.
  • cargo test --workspace --no-fail-fast -- --test-threads=4 on 551bcb90 (this commit before a comment-only amend): 1825 passed, 8 failed, 48 ignored, 27 SKIPPED lines (mostly "no wave64", two "no heap windows"). The 8 failures are 6 tests that fail the same way on the clean base ecc0bb57 on this machine, each rerun alone with and without the change: listed in Nvidia dev #2572 (comment). None is in code this PR touches except gpu_compute_e2e, where the two failing tests fail at the same lines without it.
  • cargo test -p xcl --lib driver_cache: 7 passed; --lib pipeline_cap_tests: 4 passed; --test gpu_compute_e2e: 5 passed, 2 failed (the two above).
  • Retail title, three launches of this build in a row, each ended 5 s after the title started; time from process start to the first game frame: with XCL_PREPARE_VERIFY=1 (the present behaviour) 131 s (compute pipelines 120 s); the two launches after it, with the markers, 11 s and 11 s (compute pipelines 3 s). 4,203 markers were written.

Regression run
On the base commit (nvidia-dev, not main: this PR is against nvidia-dev) and on this PR's head, same title, 120 s:

xcl-smoke v1
commit: ecc0bb57976b1bc94854199ddf4f915fd00e0a59
gpu: NVIDIA GeForce RTX 4080
title: 21222967
seconds: 120
exit: 0x0
frames shown: 3462 (PresentX 3462)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 20430 MB
xcl-smoke v1
commit: 40a14da3716bc28d0c34c86928de987a473192bb
gpu: NVIDIA GeForce RTX 4080
title: 21222967
seconds: 120
exit: 0x0
frames shown: 3449 (PresentX 3449)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 20318 MB

Not tested

  • AMD and Intel GPUs; other NVIDIA drivers (on 621.24 another tester sees blobs load in under a second, where the saving will be smaller).
  • The world: the smoke runs stay in the title's first screens. Whether the title's own first creation of these pipelines gets slower when the preparation no longer creates them (a driver cache kept warm by it) was not measured.
  • A driver update with unchanged version fields, or a D3D12 runtime update: the marker does not cover them; XCL_PREPARE_VERIFY=1 does.
  • The whole suite was not rerun after the comment-only amend (no code token changed between 551bcb90 and the head).

AI use

  • Claude Code with Claude Fable 5.2: plan, measurements, review of the diff, this description. A Claude Sonnet 5.5 sub-agent wrote the code and tests; two independent Claude Opus 5.5 sub-agent reviews, whose findings (three broken e2e tests, wording that overstated the check) are fixed in this commit.

🤖 Generated with Claude Code

At every launch the preparation workers created each used compute pipeline
from its stored driver blob only to run its check (the driver makes a
pipeline from the blob and returns a blob of the same size), and dropped
it. Creating a pipeline from a blob is not free: on an RTX 4080
(driver 621.40) it was measured to cost as much as compiling it, and the
preparation took 7-8 minutes at every launch, also right after a launch
that had completed it (186 of 192 slow creations in two launches were such
hits).

A blob that passed that check, or that was just written, now gets a marker
beside it (`<blob>.ok`: the driver's identity, the blob's length and a
digest of its bytes). A later pass counts a record whose blob still matches
its marker as prepared without creating the pipeline. This is the same
check as before, so it changes when the check runs, not what it proves (it
does not show that the driver used the blob). A blob that changed, also at
the same length, is checked the old way and repaired; a blob the driver
refuses is removed together with its marker. XCL_PREPARE_VERIFY=1 checks
every blob again.

Assisted-by: Claude Code (Claude Fable 5.2; first version written by a Claude Sonnet 5.5 sub-agent, reviewed by a Claude Opus 5.5 sub-agent)
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@andrewDoing

Copy link
Copy Markdown

On 40a14da3716bc28d0c34c86928de987a473192bb, the verified-blob marker and explicit pipeline-size cap behaved consistently across seven fresh Windows CLI processes on an RTX 5070. The test used one synthetic packed compute shader, 4,452 bytes of compiled DXIL, a 2,318-byte driver blob and one isolated cache. No code changes were needed.

Step Observed result
Cold, uncapped Created one pipeline and wrote the blob and .ok marker.
Valid marker, 1 KiB cap Trusted one blob and created zero pipelines.
Same inputs, forced verification Created one pipeline with zero refusals and trusted zero markers.
Overwrote the blob with zeros of identical length, retained the old marker, 1 KiB cap Trusted zero markers, deferred one pipeline, and removed both the rejected blob and its marker. No fresh pipeline was created.
Another capped pass, forced verification Still deferred one pipeline with zero creations.
Uncapped recovery Created one pipeline and wrote a new blob and marker.
Restored 1 KiB cap Trusted the recovered blob and created zero pipelines.

All seven xcl shaders --precompile --pipelines runs exited successfully. This checks the interaction between same-length damage, the size cap and marker cleanup through the public CLI. It does not measure startup or first-dispatch latency in a retail title.

AI use: OpenAI Codex with GPT-6.2 Astra prepared the synthetic checks and compared the CLI counters and cache files; Codex coordinated and prepared this report.

@andrewDoing

Copy link
Copy Markdown

I checked whether marker-bypass savings shifted into the first native consumer PSO creation, using head 40a14da3716bc28d0c34c86928de987a473192bb plus a test-only fixture on RTX 5070 / driver 616.92. Twelve synthetic compute shaders were seeded with driver blobs and markers. Each of 32 fresh processes began with a separate copy; the implicit OS/driver cache remained warm and its contents were not inspected. Eight counterbalanced runs were made per arm.

Preparation Consumer blob Median preparation Median sum of 12 first native creates Median paired subtotal
Trust marker Supplied 23.701 ms 8.752 ms 32.674 ms
Force verification Supplied 42.995 ms 8.292 ms 51.225 ms
Trust marker Omitted 24.120 ms 257.450 ms 281.548 ms
Force verification Omitted 42.629 ms 257.413 ms 300.571 ms

All 384 consumer creates succeeded. One 115.253 ms trust/supplied preparation outlier is retained. The paired subtotal excludes fixture/setup overhead. Consumer blob I/O and root-signature setup were outside the timed native calls; PSOs remained alive. This checks a small synthetic corpus on one device and shows little transfer of the preparation difference to first native creation in this setup. It does not establish which blob path a title uses, cold-driver behavior, GTA VI startup, dispatch correctness or frame time.

AI use: OpenAI Codex with GPT-6.2 Astra built and ran the synthetic measurement and audited the artifacts; Codex coordinated and prepared this report.

@throny

throny commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator Author

@andrewDoing thank you for both checks, in particular the second one: whether the saving just moves into the title's first creation was the open point in Not tested, and your 32 processes on driver 616.92 show little transfer for small programs. The size cap together with a same-length overwrite is a combination I had not run.

Status of the checks: Build and test (Windows, no GPU) fails in hle::d3d12x::sparse::tests::a_gpu_write_into_a_gpu_view_lands_in_its_cpu_view, which this PR does not touch; the same check is red on the other open PRs against nvidia-dev I looked at (#2935, #2927, #2923), so it comes from the base. PR description asks for a smoke block made on a commit of main; that run is in progress and I will add the block to the description.

AI use: Claude Code (Claude Fable 5.2).

@throny throny mentioned this pull request Nov 27, 2026
@LocranKing

Copy link
Copy Markdown

Independent back-to-back verification on RTX 3060 Ti (8 GB) + Ryzen 5 5500 (6C/12T) (40a14da3 merged with nvidia-dev ecc0bb57, Series S / lockhart profile).

Setup

  • Machine: Windows 11 Home build 26300, AMD Ryzen 5 5500, 31.8 GB RAM, RTX 3060 Ti (8 GB, driver 621.40), DXC 1.9.2602.17.
  • Env: XCL_DEVICE_TYPE=lockhart XCL_DIRECT_DXIL=1 XCL_HEAP_WINDOWS=1 XCL_TEXTURE_LEVEL_PAGES=1 XCL_PSO_WAIT_MS=50 XCL_GFX_PSO_WAIT_MS=200 XCL_CS_PSO_WAIT_MS=50 XCL_PREPARE_GRAPHICS=0 XCL_DRED=1 + XCL_PRESS_AT (18:A..74:A).

Two consecutive 90 s runs on the same cache folder

  • Run 1 started from a warm lockhart snapshot (1,572 used shaders, 3,206 driver blobs, no .ok markers yet).
  • Run 2 relaunched immediately on the same folder (now with .ok markers written by Run 1).
run compute pipeline prep total pre-launch time frames shown (90 s) first_2pass_mesh_t peak commit
nvidia-dev (ecc0bb57, 2 runs) 22–24 s 31.1–32.8 s – 98.8–112.9 s –
PR #2951 Run 1 (creates .ok) 35 s (43.3 s wall) 43.3 s 1,699 (1 5 11) 128.5 s 19,902 MB
PR #2951 Run 2 (trusts .ok) 6 s (5.8× faster) 11.4 s (3.8× faster) 1,680 (44 31 9) 80.6 s 20,914 MB
xcl-smoke v1
commit: 40a14da3716bc28d0c34c86928de987a473192bb
gpu: NVIDIA GeForce RTX 3060 Ti
title: 9cc6a39e
seconds: 90
exit: 0x0
frames shown: 1699 (PresentX 1699)
presents per 2 s (last 3): 1 5 11
device removals: 0
crashes: 0
peak commit: 19902 MB
xcl-smoke v1
commit: 40a14da3716bc28d0c34c86928de987a473192bb
gpu: NVIDIA GeForce RTX 3060 Ti
title: 9cc6a39e
seconds: 90
exit: 0x0
frames shown: 1680 (PresentX 1681)
presents per 2 s (last 3): 44 31 9
device removals: 0
crashes: 0
peak commit: 20914 MB

Not tested: driver update invalidation / tampered-blob fallback test on this machine, AMD/Intel adapters.

@luckyteagirl luckyteagirl 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.

On 40a14da3716bc28d0c34c86928de987a473192bb, the cold creation path marks a freshly exported blob verified as soon as driver_cache::write succeeds. That path cleared desc.CachedPSO and built the pipeline from DXIL, so the newly written bytes have not passed the check described for this marker: importing them through CreateComputePipelineState, then receiving a cached blob of the same size. On the next normal launch driver_cache::verified returns early and may never perform that check. Could the first pass round-trip the exported blob before marking it, or defer the marker until from_cache succeeds on a later pass? The new test currently expects a marker immediately after cold creation and would need to cover the intended cold → checked → trusted sequence. This is exact-head source review; I did not demonstrate a driver that rejects its own exported blob.

AI use: OpenAI Codex (GPT-6.2 Sol) traced the cold and trusted paths and checked the discussion; OpenAI Codex (GPT-6.2 Astra) independently read the exact source and wrote this review.

@oni-swr

oni-swr commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

amd-win check of 40a14da3 (base nvidia-dev ecc0bb57), RX 7800 XT (RDNA3), driver 32.0.31035.1003, Windows 11 build 26200, Ryzen 7 5700X3D, 64 GB, release builds, DXC 1.8.2502.11.

  • Tests on the head: a_verified_blob_is_trusted_until_it_changes_or_is_refused and a_second_pass_trusts_the_blobs_the_first_verified: 2 passed, 0 failed, 0 skipped. gpu_compute_e2e::offline_compute_pipeline_is_reused_by_a_second_process: 1 passed, 0 failed.
  • Warm second launch, used-only preparation, each exe on its own fresh copy of one warm shader cache: xcl shaders <pack> --precompile --only cs --pipelines --used-only (331 used pipelines, 238 compute programs compiled), XCL_PSO_DISK_CACHE=1 XCL_PIPELINE_THREADS=4, run twice in a row per exe (first pass fills, second is the warm one):
pass 1 pass 2 (second launch) pipelines made / loaded from the driver cache / not created again (pass 2)
base ecc0bb57 159 s 3.4 s 238 made, 238 loaded from the driver cache, -
head 40a14da3 160 s 3.3 s 0 made, 0 loaded, 238 not created again

What this says for AMD: creating the pipelines from the stored blobs costs almost nothing here. The whole second pass of the base, translation included, takes 3.4 s for 238 pipelines (at most about 57 ms each on average with 4 threads), against 159 s for the first pass. So on this driver the marker saves about 0.1 s per launch and is neutral, in contrast to the 19.7 s per create reported on the RTX 4080. It also did no harm: 0 refused, 0 errors, identical pass 1 time.

Not tested: a title run, graphics pipelines, a driver or adapter change between passes, other AMD parts, NVIDIA. The AMD driver's own cache was warm from earlier runs (blobs here are names of entries in it), so this says nothing about a cold driver cache.

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

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.

5 participants