Skip to content

Shaders: a Series S cache starts from the manifests both profiles shared - #3120

Open
Raul-Paiva wants to merge 1 commit into
xcl-dev:mainfrom
Raul-Paiva:shaders/series-s-used-manifest-seed
Open

Raul-Paiva wants to merge 1 commit into
xcl-dev:mainfrom
Raul-Paiva:shaders/series-s-used-manifest-seed

Conversation

@Raul-Paiva

@Raul-Paiva Raul-Paiva commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Follow-up to #2860.

Since #2860, Series S (lockhart) keeps its own used-shaders-lockhart.txt and used-pipelines-lockhart.txt. A Series S cache from before #2860 only has the shared files, so after updating, shader preparation goes from the shaders earlier runs used (2,616 on a retail title) to every record (26,503, about 1.5 h on an i7-11800H). #2860's review noted Series S users get one unfiltered, cold first launch after updating; nothing handled it.

A missing or empty Series S usage manifest now starts as a copy of a non-empty shared one last written before #2860 was merged (2026-11-28 00:36:19 UTC): only such a file has Series S's entries. One written since may hold Series X's alone and is not copied, so #2860's separation holds. From then on each profile keeps its own file. Series X is unchanged. The graphics history (used-graphics-pipelines*.bin) is not seeded.

Changed after Foniass's review of 12-01: the copy is limited to shared files from before the split, and the graphics-history seeding is gone (the shared DXIL cache's file holds other titles' records, and gfx_records.rs is part of the native pipelines' identity, so changing it made every user prepare them again). gfx_records.rs is now as on main.

What is in it

  • crates/xcl/src/hle/d3d12x/pso_async.rs: used_path / seeded_used_path, used by earlier_used_shaders, earlier_used_keys and the run's writers; PROFILES_SPLIT_AT and shared_before_split (only a shared file last written before Shaders: separate Series S and Series X used manifests #2860 is copied); used_shaders_name (no other caller) removed; unit tests a_series_s_manifest_starts_from_the_shared_one and only_a_shared_manifest_from_before_the_split_is_series_s_too.
  • README.md: one clause saying a missing or empty Series S usage manifest starts once as a copy of the shared one when that was last written before the split.

Tested

  • Hardware: RTX 3070 Laptop GPU 8 GB, driver 621.40, i7-11800H, 32 GB, Windows 10 19045, rustc 1.100.0, release build.
  • The head pushed here is this change, with the review fixes of 12-01, rebased onto main b2b1f10 without conflicts; main's newer commits also change README.md, pso_async.rs, which the rebase merged. The full-suite counts below were measured before those fixes and that rebase.
  • At this head 3432ff9 (with the review fixes, on main b2b1f10), the lib tests of hle::d3d12x::pso_async and hle::d3d12x::gfx_records, release, serial, with the 20 skips: 208 passed, 0 failed, 0 ignored, the new test among them.
  • Base for the comparison: main 53e85fb, this PR's base before that rebase (same commands, same machine).
  • cargo test --release --workspace --no-fail-fast -- --test-threads=4: the lib test binary ends early on main too (exit 0x80004005 after sparse upload preparation still failed after bounded retries), so the lib was also run alone, serially (--test-threads=1), with --skip for the 20 tests that end the binary on main (6 list_x, 12 sparse, 1 texture_upload, 1 uma_driver; each passes alone).
  • This PR at 0a7b3a0:
    • integration tests: 139 passed, 0 failed, 20 ignored; main: the same.
    • lib, serial with the 20 skips: 2621 passed, 15 failed, 29 ignored. main 53e85fb: 2617 passed, 16 failed, 29 ignored, with vram::tests::d32s8_targets_take_their_own_size_of_video_memory also skipped because it ended the binary there (about 1 GB of depth targets; it fails or ends the binary late in the long run, and passes alone).
    • Every failure here also fails on main: 12 title_textures, list_x::a_reset_while_the_last_submit_runs_records_on_another_pc_list, standin::concurrent_shell_miss_reuses_winner_and_releases_loser_pipeline, and d32s8_targets_take_their_own_size_of_video_memory above. Two that failed on main passed here (alloc_pool::a_reset_that_puts_the_allocator_aside_keeps_what_the_gpu_still_reads, vram::superseded_texture_waits_for_every_title_queue); both are intermittent in the long run.
    • This PR's tests passed: used_manifests_separate_series_s_from_series_x, a_series_s_manifest_starts_from_the_shared_one and a_header_only_series_s_graphics_manifest_is_seeded (removed since, with the graphics seeding).
  • SKIPPED on this adapter (same on main): the wave64 forms (no wave64), three f16/f32 per-lane forms refused by the recompiler, and the heap-window tests (no heap windows).

Regression run
scripts/smoke.ps1 -Seconds 120 -Title 'retail title A', release builds of clean trees, one after the other on the machine in Tested, with XCL_DEVICE_TYPE=lockhart XCL_DIRECT_DXIL=1 XCL_HEAP_WINDOWS=1 XCL_WATCH_HOT=0 XCL_DRED=1 XCL_GPU_WAIT_TIMEOUT_MS=60000. The title is left on its own, with no input; the shader cache was warmed by two runs of main before.

main:

xcl-smoke v1
commit: b2b1f109d27e746a62ec95b04dd1f9924452e682
gpu: NVIDIA GeForce RTX 3070 Laptop GPU
title: retail title A
seconds: 120
exit: 0x0
frames shown: 3358 (PresentX 3358)
presents per 2 s (last 3): 61 60 60
device removals: 0
crashes: 0
peak commit: 15865 MB

This PR:

xcl-smoke v1
commit: 3432ff93b4b1b2b767c7ef80e0687dd4e8fcb42d
gpu: NVIDIA GeForce RTX 3070 Laptop GPU
title: retail title A
seconds: 120
exit: 0x0
frames shown: 3364 (PresentX 3364)
presents per 2 s (last 3): 61 60 61
device removals: 0
crashes: 0
peak commit: 16417 MB

Not tested

AI use

  • Claude Code (Claude Opus 5.5) wrote the change, the tests and this description, and ran the tests; I read the diff.

🤖 Generated with Claude Code

@Raul-Paiva
Raul-Paiva force-pushed the shaders/series-s-used-manifest-seed branch from 12b7edb to 2ed71d6 Compare November 28, 2026 11:43
@JJAutoCompare

Copy link
Copy Markdown

Tested

At 2ed71d626f4b90082795852e19e4fe1038af1ec5 on Windows 11 x64 build 26200.9974 with a Ryzen 7 3800X. Independently reran a pinned standalone executable built with Rust 1.100.1 (x86_64 MSVC). Verified that both manifest helpers and the stock test match the Git source byte for byte. The harness uses a diagnostic-only logger and a separate temporary directory for each invocation.

manifest-tests.exe --exact fixture::legacy_manifest_seeding_and_profile_isolation --test-threads=1 --nocapture
manifest-tests.exe --exact used_tests::a_series_s_manifest_starts_from_the_shared_one --test-threads=1 --nocapture

Both processes exited 0. Total: 2 passed, 0 failed, 0 ignored, 0 skipped. The fixture seeded all three missing Series S manifests byte for byte from the shared files. An empty Series S graphics manifest reseeded with its original NUL and high bytes. Series X resolved the shared filenames. Later writes to either profile preserved all three files for the other profile. The stock shader-text test passed separately.

Not tested

Graphics record decoding, runtime profile selection or wiring, real shader caches, title launch, GPU, concurrency, performance, and the workspace suite.

AI use

T3 Code through Codex (gpt-6.2-sol, high) prepared the standalone fixture, independently verified its source and executable pins, reran both tests, and drafted this report.

@andrewDoing

Copy link
Copy Markdown
Contributor

At 2ed71d62, a valid 12-byte, zero-record Series S graphics manifest prevents migration. The byte-length check in seeded_used_path treats it as populated, but gfx_records::read returns zero entries. The production writer can produce this layout: it writes the header on open, then leaves it alone if the first record exceeds the configured cap (for example, XCL_GFX_RECORDS_MB=0). This also matters on a later run after the cap is raised.

I exercised the exact path selection, graphics writer and record reader on isolated Windows files, with one valid shared shader record. A missing or zero-byte Series S file each yielded one migrated record. A header-only file created by the writer yielded zero. A Series S file with its own valid record preserved that record without importing the shared one.

Could the binary path recognize an exact current-format header with no payload as empty, while preserving populated profile files? The text-manifest paths can keep their existing test. This was CPU/disk verification with synthetic records; I did not measure title preparation time.

AI use: OpenAI Codex extracted and ran the production helpers, checked the results and prepared this report.

@andrewDoing

Copy link
Copy Markdown
Contributor

I tested a small fix for the zero-record graphics manifest reported above. A Series S file that consists of exactly the current graphics-record header now seeds from the shared file. The same check prevents copying a header-only shared file back on each lookup. Only a 12-byte graphics file gets opened for the additional check. The header comes from the production writer.

On Windows, using the production manifest selector, writer and reader in a standalone Rust test, the previous head and candidate gave these results with one valid shared shader record:

Series S file before selection 2ed71d62 Candidate
Missing Shared record Shared record
Zero bytes Shared record Shared record
Header written with cap zero Zero records Shared record
Own valid record Own record Own record

Two additional candidate assertions passed: an empty shared header left a missing profile file absent, and a 12-byte profile file with different bytes stayed intact. This exercised serial disk migration with synthetic records. Concurrent writers, title startup, preparation time and the workspace suite remain untested.

Patch and regression test, apply-checked against 2ed71d6
--- a/crates/xcl/src/hle/d3d12x/pso_async.rs
+++ b/crates/xcl/src/hle/d3d12x/pso_async.rs
@@ -916,9 +916,15 @@
 /// starts as a copy of a shared one that has entries; from then on each profile keeps its own.
 fn seeded_used_path(dir: &std::path::Path, stem: &str, ext: &str, series_s: bool) -> std::path::PathBuf {
     let path = dir.join(used_file_name(stem, ext, series_s));
-    if series_s && std::fs::metadata(&path).map_or(true, |m| m.len() == 0) {
+    let populated = |p: &std::path::Path| {
+        std::fs::metadata(p).is_ok_and(|m| {
+            m.len() != 0 && !(stem == "used-graphics-pipelines" && ext == "bin"
+                && super::gfx_records::header_only(p, m.len()))
+        })
+    };
+    if series_s && !populated(&path) {
         let shared = dir.join(used_file_name(stem, ext, false));
-        if std::fs::metadata(&shared).is_ok_and(|m| m.len() > 0) && std::fs::copy(&shared, &path).is_ok() {
+        if populated(&shared) && std::fs::copy(&shared, &path).is_ok() {
             crate::xlog_info!("D3D12.X: {} starts as a copy of {}, which both profiles shared before", path.display(), shared.display());
         }
     }
@@ -2463,6 +2469,40 @@
         assert!(!profile_is_series_s_from(None, None));
     }
 
+    #[test]
+    fn a_header_only_series_s_graphics_manifest_can_still_be_seeded() {
+        use super::super::gfx_records::{read, shader_entry, Added, Writer};
+        let dir = std::env::temp_dir().join(format!("xcl-gfx-seed-{}", std::process::id()));
+        std::fs::create_dir_all(&dir).unwrap();
+        let stem = "used-graphics-pipelines";
+        let local = dir.join(used_file_name(stem, "bin", true));
+        let shared = dir.join(used_file_name(stem, "bin", false));
+        let old = shader_entry(1, &[11, 22]);
+        let own = shader_entry(2, &[33]);
+        let seed = || seeded_used_path(&dir, stem, "bin", true);
+        let add = |p: &std::path::Path, cap, item: &[u8]| Writer::open(p, cap).unwrap().add(item).unwrap();
+
+        assert_eq!(add(&shared, 0, &old), Added::Full);
+        seed();
+        assert!(!local.exists());
+        assert_eq!(add(&shared, 1024, &old), Added::New);
+        assert_eq!(read(&seed()), vec![old.clone()]);
+        std::fs::write(&local, []).unwrap();
+        assert_eq!(read(&seed()), vec![old.clone()]);
+        std::fs::remove_file(&local).unwrap();
+        assert_eq!(add(&local, 0, &own), Added::Full);
+        assert_eq!(read(&seed()), vec![old]);
+        std::fs::remove_file(&local).unwrap();
+        assert_eq!(add(&local, 1024, &own), Added::New);
+        assert_eq!(read(&seed()), vec![own]);
+        std::fs::write(&local, [0xaa; 12]).unwrap();
+        seed();
+        assert_eq!(std::fs::read(&local).unwrap(), [0xaa; 12]);
+        std::fs::remove_file(local).unwrap();
+        std::fs::remove_file(shared).unwrap();
+        std::fs::remove_dir(dir).unwrap();
+    }
+
     /// A Series S cache from before the profiles had files of their own: its `-lockhart` file
     /// starts as a copy of the shared one when it is missing or empty, never when it has entries
     /// of its own; Series X reads the shared file, and nothing is copied when that is empty.
--- a/crates/xcl/src/hle/d3d12x/gfx_records.rs
+++ b/crates/xcl/src/hle/d3d12x/gfx_records.rs
@@ -306,6 +306,18 @@
     h[..8].copy_from_slice(MAGIC);
     h[8..].copy_from_slice(&VERSION.to_le_bytes());
     h
+}
+
+/// A writer may leave just the current header when its first record exceeds the cap.
+pub(super) fn header_only(path: &Path, len: u64) -> bool {
+    use std::io::Read;
+    if len != HEADER as u64 { return false; }
+    let mut bytes = [0; HEADER + 1];
+    std::fs::File::open(path).is_ok_and(|mut file| {
+        file.read_exact(&mut bytes[..HEADER]).is_ok()
+            && bytes[..HEADER] == header()
+            && matches!(file.read(&mut bytes[HEADER..]), Ok(0))
+    })
 }
 
 fn check(payload: &[u8]) -> u32 {

AI assistance: OpenAI Codex (GPT-6) prepared and tested the candidate and drafted this follow-up.

@Prime1997
Prime1997 changed the base branch from nvidia-dev to main November 28, 2026 20:13
@Raul-Paiva
Raul-Paiva force-pushed the shaders/series-s-used-manifest-seed branch from 2ed71d6 to 0a7b3a0 Compare November 30, 2026 01:15
@Raul-Paiva

Copy link
Copy Markdown
Contributor Author

Thanks @andrewDoing, confirmed: Writer::open writes the 12-byte header and leaves it alone when the first record is over the cap (e.g. XCL_GFX_RECORDS_MB=0), and the length check in seeded_used_path took that file as populated, so it never migrated.

The fix and a regression test are folded into the PR's single commit; the PR is rebased onto main and its head is now 0a7b3a0f. It follows your approach in a smaller form: gfx_records::header_only reads a file only when it is exactly the header's length and compares it with the current header, and seeded_used_path uses it for both the Series S file (a header-only one is seeded) and the shared one (a header-only one is not copied). a_header_only_series_s_graphics_manifest_is_seeded covers a header-only shared file, a header-only Series S file, and a Series S file with its own entry; it fails without the fix.

The full suite against main 53e85fb is in the description (no new failure); the smoke runs are still to come.

Written with Claude Code (Claude Opus 5.5).

@github-actions github-actions Bot added area:d3d12 D3D12.X runtime, command lists, resources, sparse memory area:docs-ci Documentation, scripts, workflows, repo governance area:shaders Shader cache, PSO compilation, pipeline libraries, precompilation gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks) labels Nov 30, 2026
@Raul-Paiva
Raul-Paiva force-pushed the shaders/series-s-used-manifest-seed branch from 0a7b3a0 to 33866d5 Compare November 30, 2026 07:19
@Raul-Paiva
Raul-Paiva marked this pull request as ready for review November 30, 2026 08:13
@Raul-Paiva
Raul-Paiva force-pushed the shaders/series-s-used-manifest-seed branch from 33866d5 to ad3c470 Compare November 30, 2026 17:28
@Foniass

Foniass commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Triage (#1607) – head 3432ff9

No open or merged PR makes the same change (a follow-up to #2860). No problems found in the diff. seeded_used_path copies a non-empty shared usage manifest only when the Series S file is missing or empty and the shared one was last written before the split (PROFILES_SPLIT_AT, 2026-11-28). The graphics history (.bin) is no longer seeded and gfx_records.rs is unchanged. Both new tests cover those cases.
Minor: used_path now stats the file on every call.
Recommendation: keep open.

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Review (head ad3c470, diff read, not a merge-check; PR description red: the smoke block names 33866d5 and the counts 0a7b3a0):

  • The seeding isn't limited to caches from before Shaders: separate Series S and Series X used manifests #2860. Any Series S cache without -lockhart files copies the shared file, including entries written only by Series X runs since Shaders: separate Series S and Series X used manifests #2860. The log line "which both profiles shared before" is then wrong (pso_async.rs ~4666), and a first Series S run prepares Series X's pipelines too. Copying only when the shared file predates the split (a version or timestamp check) would keep Shaders: separate Series S and Series X used manifests #2860's separation.
  • shared_history_path now also seeds from the old file in the shared DXIL cache, which holds other titles' records (gfx_records.rs ~66). It can copy up to 64 MB, and graphics_in_workers then reads it under Series S, where main read nothing. Low impact.
  • Touching gfx_records.rs (hashed by build.rs) makes every user re-prepare the driver's graphics pipelines once.

Fine: this can't produce wrong pipelines. Translation doesn't depend on the profile (nothing under gpu/recomp reads it), and the manifests are keys and descriptions the runtime matches exactly, so the worst case is preparing pipelines Series S never uses. The parent process seeds before the workers start (shaders.rs ~3513), and the two tests cover missing, empty, header-only and own-entry files.

AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.

@Raul-Paiva
Raul-Paiva force-pushed the shaders/series-s-used-manifest-seed branch from ad3c470 to e5fac00 Compare December 1, 2026 12:21
Since xcl-dev#2860, Series S (`lockhart`) reads and writes its own
used-shaders-lockhart.txt and used-pipelines-lockhart.txt instead of the
shared files. A Series S cache from before xcl-dev#2860 only has the shared
files, so after updating, shader preparation goes from the shaders
earlier runs used (2,616 on a retail title) to every record (26,503,
about 1.5 h on an i7-11800H). xcl-dev#2860's review noted this cold first
launch; nothing handled it.

A missing or empty Series S usage manifest now starts as a copy of a
non-empty shared one last written before xcl-dev#2860 was merged
(2026-11-28 00:36:19 UTC, `PROFILES_SPLIT_AT`): only such a file has
Series S's entries. One written since may hold Series X's alone, and is
not copied, so xcl-dev#2860's separation holds (`seeded_used_path`,
`shared_before_split`). From then on each profile keeps its own. The
readers (`earlier_used_shaders`, `earlier_used_keys`) and the run's
writers go through `used_path`. `used_shaders_name` had no other caller
and is removed. README mentions the copy.

The graphics history (used-graphics-pipelines*.bin) is not seeded: the
shared DXIL cache's file holds other titles' records, and
gfx_records.rs is part of the native pipelines' identity (build.rs), so
changing it would make every user prepare them again once.

Review: andrewDoing (an empty or header-only Series S file); Foniass
(seed only files from before the split, no graphics seeding from the
shared cache, gfx_records.rs in the pipeline identity).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Raul-Paiva
Raul-Paiva force-pushed the shaders/series-s-used-manifest-seed branch from e5fac00 to 3432ff9 Compare December 1, 2026 14:46
@Raul-Paiva

Copy link
Copy Markdown
Contributor Author

Thanks for the review. Head is now 3432ff9 (rebased onto main b2b1f10), squashed into the one commit:

  1. Seeding only from caches from before Shaders: separate Series S and Series X used manifests #2860. A shared usage manifest is copied only when it was last written before Shaders: separate Series S and Series X used manifests #2860 was merged (2026-11-28 00:36:19 UTC, PROFILES_SPLIT_AT). A file written since may hold Series X's entries alone, so it is left alone and the separation holds. With that, "which both profiles shared before" is true whenever it is logged. Tests: a_series_s_manifest_starts_from_the_shared_one now also checks that a recent shared file is not copied and an older one is; only_a_shared_manifest_from_before_the_split_is_series_s_too checks the cut-off.
  2. Graphics history from the shared DXIL cache, and point 3. I dropped the graphics-history seeding, so gfx_records.rs is now as on main. That fixes both points: nothing copies other titles' records, and the native pipeline identity does not change, so nobody has to prepare again. The usage manifests (used-shaders, used-pipelines), which caused the 1.5 h first preparation, are still seeded. The header-only test went with it.

On the per-call stat: it is a metadata call when the manifests are read at preparation and run start, not on a hot path, so I left it.

Tested on an RTX 3070 Laptop (driver 621.40): pso_async and gfx_records, release, serially, gave 208 passed, 0 failed.

Claude Code (Claude Opus 5.5) helped with the fixes and this reply; I checked each point.

@Foniass

Foniass commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Follow-up review (head 3432ff9, since ad3c470, diff read, not a merge-check):

  • Seeding not limited to caches from before Shaders: separate Series S and Series X used manifests #2860: fixed. seeded_used_path copies the shared file only when shared_before_split says it was last written before PROFILES_SPLIT_AT (Shaders: separate Series S and Series X used manifests #2860's merge time) (pso_async.rs ~4653-4680).
  • Graphics history seeded from the shared DXIL cache's file: fixed. gfx_records.rs is no longer touched; only the two .txt usage manifests go through used_path.
  • Touching gfx_records.rs forces a re-prepare: fixed. Only pso_async.rs and README.md change, and build.rs hashes neither.

New:

  • "Not tested" contradicts the code. It says a shared file written only by Series X runs after Shaders: separate Series S and Series X used manifests #2860 "is seeded from those entries too (once)", but shared_before_split (pso_async.rs ~4672, and the test at ~10764) refuses to copy such a file. That bullet is left from the earlier head.
  • Workers can seed used-pipelines-lockhart.txt at the same time (low impact). The parent seeds it before starting the workers only when progress.only is set (shaders.rs ~3513, the && short-circuits). With XCL_PREPARE_ALL=1, or with no used-shaders list, each compute worker calls earlier_used_keys() (~4099) and they can all fs::copy onto the same file at once, so one can read a partial list. It only sets build order (PipelineJob::used), so nothing wrong is built.

Fine: the cutoff matches #2860's merge time; the own file is checked and seeded before the run's writer opens it (pso_async.rs ~4763-4771); Series X paths are unchanged; the tests cover missing, empty, before-split and after-split shared files, own files with and without entries, and the cutoff boundary.

AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:d3d12 D3D12.X runtime, command lists, resources, sparse memory area:docs-ci Documentation, scripts, workflows, repo governance area:shaders Shader cache, PSO compilation, pipeline libraries, precompilation gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants