Skip to content

D3D12.X: publish driver cache blobs from private staging files - #714

Merged
ivall merged 1 commit into
xcl-dev:mainfrom
Prime1997:contrib/driver-cache-atomic-publish
Nov 24, 2026
Merged

ivall merged 1 commit into
xcl-dev:mainfrom
Prime1997:contrib/driver-cache-atomic-publish

Conversation

@Prime1997

@Prime1997 Prime1997 commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Two workers saving a driver blob for the same compute pipeline could open the same temporary file. One worker could publish it while the other still held a writable handle. A subsequent write through the older handle changed the bytes readers saw even after the save had succeeded. This affects the disk cache introduced in #634.

What is in it

  • Each save creates its own file in the destination directory before renaming it into place. An occupied temporary name is skipped. An unsuccessful save cleans up the file it created.
  • A Windows regression pauses one writer with its real staging handle open, completes the other save, then resumes the first writer. Another test covers a staging name left behind by an earlier process.

Tested

  • Windows 11 build 26200, Intel Core i5-10400, NVIDIA GeForce RTX 3060 Ti (Windows driver 32.0.16.1714), Rust 1.100.0, debug and release builds. These filesystem regressions run on the CPU.

  • The overlapping-writer test failed on official f4ce27c with the old publication behavior. A successful save of complete second blob was subsequently read back as oldplete second blob.

  • On 2cc79fb, cargo test --locked -p xcl --lib hle::d3d12x::real::driver_cache::tests -- --nocapture passed all 4 tests with 0 failures and 0 ignored.

  • The release workspace built on 2cc79fb. Two full runs of cargo test --locked --workspace --no-fail-fast -- --test-threads=4 --nocapture on the RTX 3060 Ti each reported 700 passed, 3 failed and 41 ignored. Two wave64 cases reported hardware skips within the passing count. The first failure was the shared video-memory total in placed_title_textures_share_vram_and_preserve_pixels. Its panic poisoned the lock used by two later tests. Each of the three passed when run individually in fresh processes. The separate test correction is tracked in #447.

  • An independent run on pristine main at f4ce27c produced the same three failures, with 698 passed and 41 ignored. Both new regression tests account for the two additional passes on this PR.

Regression run

Both 60-second runs used the same local title, adapter and compiler. Each started with a separate empty XCL profile and shader cache. The NVIDIA driver managed its own cache across the two runs. Neither run used menu input.

Main

xcl-smoke v1
commit: f4ce27ceb6d1b0576d0c659b713b674778bf1968
gpu: NVIDIA GeForce RTX 3060 Ti
title: 419239bf
seconds: 60
exit: 0x0
frames shown: 405 (PresentX 405)
presents per 2 s (last 3): 9 12 11
device removals: 0
crashes: 0
peak commit: 15827 MB

PR

xcl-smoke v1
commit: 2cc79fb11140adaccfac198853fb00db6dfda6a8
gpu: NVIDIA GeForce RTX 3060 Ti
title: 419239bf
seconds: 60
exit: 0x0
frames shown: 324 (PresentX 324)
presents per 2 s (last 3): 15 15 15
device removals: 0
crashes: 0
peak commit: 15841 MB

The PR showed 324 frames against 405 on main (80.0%, the project threshold), with 14 MB higher peak commit. Both runs exited cleanly. These short runs created no driver-cache files, so they measure startup only. The overlapping-writer test exercises the corruption directly.

Not tested

The Windows test reproduces file corruption directly. Its effect on retail loading time or stability is unverified.

AI use

  • OpenAI Codex (GPT-6) identified and reviewed the race, implemented the fix and tests, and ran the focused regressions, full workspace tests and paired Windows startup checks.

I use a temporary Discord to coordinate my work. Anyone helping test XCL or compare results is welcome. Test coordination on Discord

The per-process staging pathname was shared by concurrent writes of one key.
A writer paused after opening it could resume after another writer renamed
that file into the cache, changing successfully published bytes through its
older handle.

Create an exclusive sibling file for each invocation using the process ID
and an atomic sequence. Skip occupied names left by an earlier process and
clean up only a staging file this invocation actually created.

A deterministic Windows regression holding the real staging helper's open
handle fails with the old writer and passes with this change. Focused Cargo
writer tests: 4 passed, 0 failed, 0 ignored. Full GPU suite and retail smoke
have not been run for this commit.

Assisted-by: Codex (GPT-6, exact variant not exposed)
@MesshM

MesshM commented Nov 24, 2026

Copy link
Copy Markdown

Test run of 2cc79fb11140adaccfac198853fb00db6dfda6a8 on AMD RDNA4. I merged it onto current main 64b3f35 locally (clean merge) and tested that tree.

Tested

  • AMD Radeon RX 9060 XT 16 GB (RDNA4), driver 32.0.32029.2010; Ryzen 7 5700X, 64 GB RAM, Windows 11 Pro build 26200, Rust 1.100.0 stable-x86_64-pc-windows-msvc, debug
  • cargo build --workspace + cargo test --workspace -- --test-threads=4 on the merge: 703 passed, 0 failed, 41 ignored, exit code 0; xcl lib tests 662 passed, 0 failed, 21 ignored
  • 0 SKIPPED; an_abandoned_staging_file_is_skipped_and_preserved and the other driver_cache tests pass.

Review: Each save opens its own staging file with create_new and a per-process counter in the name, so two workers can no longer hold one writable handle, and a name that already exists is skipped rather than truncated. I found nothing to change.

Not tested: no retail title or regression run (I have no unpacked game), no XCL_SAMPLE_* tests, release build; the PR's head on its old base was not run, only its merge onto main.

Run and review by Claude Code (Claude Opus 5.5) on this machine; the review points were checked against the code.

@raylitebull

Copy link
Copy Markdown
Member

Code/CI review only (not independently runtime-tested by me): clean merge with both checks green (Build and test + PR description). Publishing compute PSO driver cache blobs from private temp staging files cleanly avoids concurrent write races. Recommend merging, @ivall.

@ivall
ivall merged commit 2cc79fb into xcl-dev:main Nov 24, 2026
4 of 6 checks passed
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