Skip to content

Shaders: record and precompile nonzero compute PSO flags (#2995) - #3001

Open
retrope13 wants to merge 1 commit into
xcl-dev:mainfrom
retrope13:fix/pso-flags-cache-2995
Open

retrope13 wants to merge 1 commit into
xcl-dev:mainfrom
retrope13:fix/pso-flags-cache-2995

Conversation

@retrope13

Copy link
Copy Markdown

Fixes #2995.

What is in it

Offline xcl shaders --precompile --pipelines and startup shader preparation previously built compute driver blobs only with Flags = 0, so runtime translated compute PSOs created with nonzero D3D12_PIPELINE_STATE_FLAGS (such as 4 or 8) missed the offline cache because driver_cache::name_for includes the flags suffix.

  • crates/xcl/src/hle/d3d12x/real.rs:
    • Records driver-accepted nonzero compute PSO flags into <DXIL cache>/compute-pso-flags.txt (<record:016x> <flags:x>, deduplicated, beside used-pipelines.txt) from both whole (compute_container) and split (dispatch_chain::build) success paths in translated_compute_pso_once when XCL_PSO_DISK_CACHE is enabled.
    • Adds unit test driver_cache::tests::compute_flags_recipe_records_dedups_and_parses_nonzero_flags.
  • crates/xcl/src/shaders.rs:
    • Loads compute-pso-flags.txt during precompile (both CLI --precompile --pipelines and startup prepare_for_launch) and prebuilds Flags = 0 plus every recorded nonzero-flag variant under its matching D3D12_COMPUTE_PIPELINE_STATE_DESC.Flags and driver_cache key (whole .pso, split .chain.pso, and startup whole chain fallback).
    • Tracks recorded nonzero-flag refusals separately (flags_refused) so an adapter-specific recorded flag (e.g. from WARP) never aborts startup preparation on another GPU.
    • Adds GPU test shaders::pipeline_cap_tests::nonzero_flags_compute_pipeline_is_cached_and_reused_under_flags_key.
  • crates/xcl/tests/gpu_compute_e2e.rs:
    • Adds offline_compute_pipeline_reuses_recorded_nonzero_flags (runtime records Flags = 4 and 8 → wipe driver/ → offline --precompile --pipelines builds -0.pso, -4.pso, -8.pso → fresh runtime process hits both with driver_cache_stats == (2, 0, 0) and passes all 1,536 readback words).
    • Adds offline_split_compute_pipeline_reuses_recorded_nonzero_flags (same round-trip for split .chain.pso pieces with Flags = 4, verifying driver_cache_stats == (pieces, 0, 0)).
  • README.md:
    • Documents compute-pso-flags.txt and the coverage limit for cold shader-only inputs before any runtime observation.

Tested

  • hardware (GPU + driver, CPU), Rust version, debug / release: Windows 11 26H2, NVIDIA GeForce RTX 4060 Laptop GPU (driver 32.0.16.2140) + Intel(R) UHD Graphics (driver 32.0.101.7092), Intel Core i5-14500HX, rustc 1.100.0 (debug), DXC 1.9.2602.17
  • XCL_ADAPTER=NVIDIA cargo test --workspace --locked --no-fail-fast -- --test-threads=4: 1,462 passed, 0 failed, 47 ignored (29 SKIPPED lines: wave64-only, debug-layer, heap-window opt-ins)
  • cargo test --locked -p xcl --lib driver_cache::tests::: 5 passed, 0 failed
  • XCL_ADAPTER=NVIDIA and XCL_ADAPTER=Intel cargo test --locked -p xcl --lib shaders::pipeline_cap_tests:: -- --test-threads=1: 4 passed, 0 failed on both adapters
  • XCL_ADAPTER=NVIDIA cargo test --locked -p xcl --test gpu_compute_e2e -- --test-threads=1: 9 passed, 0 failed (1 skipped: heap_window_out_of_memory_falls_back_to_the_switch_form without XCL_HEAP_WINDOWS=1)

Regression run

main (623d02e4): offline --precompile --pipelines writes only -0.pso / -0.chain.pso; runtime Flags = 4 and Flags = 8 miss the disk cache (as reproduced in #2995).

PR (894ae3be): runtime records Flags = 4 and Flags = 8 into compute-pso-flags.txt; after clearing driver/, offline --precompile --pipelines writes -0.pso, -4.pso, and -8.pso (and matching -0.chain.pso / -4.chain.pso sets for split programs), and a fresh runtime process gets 100% disk hits (driver_cache_stats() == (2, 0, 0) whole, (pieces, 0, 0) split) with exact GPU readback.

Not tested

  • Retail titles / xcl-smoke or XCL_SAMPLE_RPF packs.
  • AMD / native wave64 hardware GPUs.
  • Cross-adapter refusal of a WARP-only flag (e.g. TOOL_DEBUG = 1) on hardware.

AI use

  • Antigravity (Gemini 4) assisted with tracing the cache paths, writing the patch and regression tests, and drafting this description; all builds and test runs were executed and verified locally on my Windows 11 RTX 4060 / Intel UHD laptop.

rootw0rm pushed a commit to rootw0rm/xcl that referenced this pull request Nov 27, 2026
@JJAutoCompare

JJAutoCompare commented Nov 27, 2026 •

Copy link
Copy Markdown

Tested

Clean 894ae3beebaa32baac2f381fd077ce6897b30bc1 on Windows 11 build 26200.9974, Ryzen 7 3800X, Intel Arc A770 driver 32.0.101.9175 and Rust 1.100.0 MSVC debug. DXC/DXIL 1.9.2602.17. Built the integration test with cargo test --locked -p xcl --test gpu_compute_e2e --no-run -j 2 and ran the pinned executable with --exact --test-threads=1 --nocapture, XCL_ADAPTER=A770 and separate mutex acquisitions.

  • offline_compute_pipeline_reuses_recorded_nonzero_flags: runtime recorded flags 4 and 8. After clearing the driver cache and precompiling, a fresh runtime asserted two matching hits with zero stale blobs or stores. All 1,536 readback words matched per flag.
  • offline_split_compute_pipeline_reuses_recorded_nonzero_flags: offline precompile made six matching flag-0/flag-4 piece pairs. A fresh runtime asserted six flagged hits, zero stale blobs and zero stores.
  • CPU exact filter hle::d3d12x::real::driver_cache::tests::compute_flags_recipe_records_dedups_and_parses_nonzero_flags passed outside the GPU lock.

Three passed, zero failed, ignored, or skipped. The integration test and CLI hashes held before, under, and after both lock acquisitions.

Not tested

Split dispatch readback, startup precompile, live compute-stream path, full suite and retail smoke.

AI use

T3 Code / Codex (gpt-6.2-sol) ran and independently reproduced these fixtures and wrote this report.


Tested — CPU follow-up at fd53bc645a1f49314e06c57eb948f987008ef461

Windows 11 x64 build 26200.9974, Ryzen 7 3800X, Rust 1.100.1 MSVC. I compared the three standalone recipe helpers byte-for-byte with Git blob 0b9c5915100adbea40d29629ed8e622b8358239d and reran the hash-pinned executable in a fresh directory.

recipe.exe --exact recipe::standalone::recipe_rotation_path_isolation --test-threads=1 --nocapture exited 0. 1 passed, 0 failed, 0 ignored, 0 runtime skips.

In one process, two recipe paths tracked flags independently for the same record. After renaming A's recipe file within its directory, observing flag 8 recreated the file with one row. Repeating the observation kept that single row. B retained its own rows and parsed as [2, 4, 8] after adding flag 2. The archived A file remained byte-for-byte unchanged, with flag 8 followed by flag 4.

Not tested

D3D12, GPU execution, real driver blobs, pipeline integration, sharing violations, concurrent writers, cross-process persistence, retail smoke, and the full workspace suite.

AI use

T3 Code through the Codex harness (gpt-6.2-sol) verified source and executable provenance, reran the standalone test, checked the resulting files, and wrote this follow-up.

@ettehn

ettehn commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

A transient sharing violation can make record_compute_flags_in forget a flag for the rest of the process. I compiled the recorder and parser verbatim from 894ae3be in a standalone Windows filesystem test.

  1. Record flag 4, then open the existing compute-pso-flags.txt with FILE_SHARE_READ only.
  2. Observe flag 8 for the same record while append is denied (Win32 error 32). Release the handle and verify the file opens for append.
  3. Observe flag 8 twice more in the same process. The parser still returns [4] in 3/3 runs. A different record written afterward persists, so the file is writable again.

The recorder inserts the tuple into SEEN before opening the file. Keeping the mutex and inserting only after writeln! succeeds gave [4, 8] with one line per tuple in 3/3 runs. This check covers the recording helper; the full CLI and GPU suite were outside this run.

AI-assisted verification with OpenAI Codex (GPT-6).

@LocranKing

Copy link
Copy Markdown

Tested PR #3001 (894ae3be) on Windows 11 (Ryzen 5 5500, 32 GB RAM, NVIDIA GeForce RTX 3060 Ti 8 GB, driver 32.0.16.2140).

Unit & GPU E2E tests

  • cargo test --locked -p xcl --lib -- compute_flags --nocapture:
    • hle::d3d12x::real::driver_cache::tests::compute_flags_recipe_records_dedups_and_parses_nonzero_flags — ok (1 passed, 0 failed)
  • cargo test --locked -p xcl --lib -- nonzero_flags_compute_pipeline --nocapture:
    • shaders::pipeline_cap_tests::nonzero_flags_compute_pipeline_is_cached_and_reused_under_flags_key — ok (1 passed, 0 failed)
  • cargo test --locked -p xcl --test gpu_compute_e2e -- --nocapture:
    • 9 passed, 0 failed (9.79 s, including offline_compute_pipeline_reuses_recorded_nonzero_flags and offline_split_compute_pipeline_reuses_recorded_nonzero_flags on the RTX 3060 Ti).

Smoke check (180 s, lockhart, XCL_PREPARE=0, XCL_DIRECT_DXIL=all)

Against origin/main (06f90c19) on copies of the same warmed main DXIL cache:

  • origin/main (06f90c19): exit: 0x0, 0 crashes, 0 device removals, 1236 frames (PresentX 1236), peak commit 27336 MB, local 14032 MB, non-local 1639 MB.
  • #3001 (894ae3be): exit: 0x0, 0 crashes, 0 device removals, 1250 frames (PresentX 1250), peak commit 27094 MB, local 14025 MB, non-local 1657 MB.
  • Scope caveat: With XCL_PREPARE=0 and default main texture/VRAM settings on this 8 GB card, both runs reached title loading (~60 s active presents, ~14 GB local VRAM, target pages ~7.7 GB) and had 0 presents at 120–180 s without reaching open-world rendering (used-compute-flags-lockhart.txt was not generated in this run).

@cindertheblue

Copy link
Copy Markdown
Contributor

Smoke pair for Regression run, head 894ae3be and main 6089122a, the same title, 60 s each: no device removals or crashes, 99 % of main's frames (1,341 vs 1,353), 100 % of its peak commit (14,199 vs 14,188 MB). With both blocks pasted under Regression run, main's scripts/pr_check.py reports description ok for this head and the current description.

main 6089122a:

xcl-smoke v1
commit: 6089122a1c96dff16e93b6fdf04c8ed20cfb6102
gpu: AMD Radeon RX 7600 XT
title: e7eb0b27
seconds: 60
exit: 0x0
frames shown: 1353 (PresentX 1353)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14188 MB

This PR's head 894ae3be:

xcl-smoke v1
commit: 894ae3beebaa32baac2f381fd077ce6897b30bc1
gpu: AMD Radeon RX 7600 XT
title: e7eb0b27
seconds: 60
exit: 0x0
frames shown: 1341 (PresentX 1341)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14199 MB

Tested

  • AMD Radeon RX 7600 XT 16 GB (RDNA3), driver 32.0.31041.1004, Ryzen 5 9600X, 15.1 GB RAM, Windows 11 Home 26200.9974, rustc 1.99.1, release builds (cargo build --release -p xcl) of both commits from clean worktrees.
  • Each run used its own tree's scripts\smoke.ps1 -Seconds 60 -StartupTimeoutSeconds 1800, with XCL_ADAPTER=7600 and XCL_PREPARE=0 (both logs: Shader preparation left out (XCL_PREPARE=0)).
  • Each run had an empty DXIL cache and data root of its own, and a renamed copy of its xcl.exe, so AMD's per-app driver cache was cold for both.

Not tested

  • The code this PR changes: with XCL_PREPARE=0 there is no startup preparation, and no offline precompile ran, so the recorded compute PSO flags were neither written nor read.
  • A run with the startup preparation (without XCL_PREPARE=0), longer play, the test suite on this head.

AI use

  • Claude Code (Claude Opus 5.5) built both commits, ran the pair on this machine and wrote this comment from the two runs' output.

@DarkPanda69

DarkPanda69 commented Nov 27, 2026 •

Copy link
Copy Markdown

Update for head fd53bc6 (merge of main e429936): same three commands at the head, same PC. gpu_compute_e2e 9 passed, 0 failed, 1 SKIPPED (no heap windows) on both cards. The lib filter now gives 27 passed, 0 failed on both (was 14; the merge brings more tests that match the filter), and stale_blob_cannot_bypass_the_offline_pipeline_cap logs the right adapter on each. shaders_e2e 9 passed, 0 failed in both runs.

Update for head ed49370 (merge of main 2c717a0 + the SEEN fix), tested at the head as is, same PC, XCL_ADAPTER=Radeon and =3060:

  • cargo test -p xcl --test gpu_compute_e2e -- --nocapture --test-threads=1: 9 passed, 0 failed on both cards; 1 SKIPPED (heap_window_out_of_memory_falls_back_to_the_switch_form: no heap windows), as before.
  • cargo test -p xcl --lib -- driver_cache::tests:: pipeline_selection_tests pipeline_cap_tests nonzero_flags compute_flags --test-threads=1 --nocapture: 14 passed, 0 failed on both, including the new compute_flags_recipe_retries_after_transient_sharing_violation. stale_blob_cannot_bypass_the_offline_pipeline_cap logs adapter=AMD Radeon RX 9070 XT / adapter=NVIDIA GeForce RTX 3060.
  • cargo test -p xcl --test shaders_e2e -- --nocapture: 9 passed, 0 failed in both runs.

No xcl-smoke run from me (no retail pack in this test setup).

AMD run (listed as untested), with an RTX 3060 in the same PC: the four new tests pass on both.

Tested: pass, at the PR head 894ae3b against its merge-base with main, 623d02e (the diff no longer applies on today's main; GitHub shows a conflict). Debug, Rust 1.100.0, Windows 11 Pro 26200, Ryzen 7 5800X, cargo build --workspace first, card picked with XCL_ADAPTER (log: backend 'real' – AMD Radeon RX 9070 XT / – NVIDIA GeForce RTX 3060).

  • cargo test -p xcl --test gpu_compute_e2e -- --nocapture --test-threads=1: merge-base 7 passed; PR 9 passed, 0 failed, on both cards. New and ok: offline_compute_pipeline_reuses_recorded_nonzero_flags, offline_split_compute_pipeline_reuses_recorded_nonzero_flags. 1 SKIPPED on both, with and without the PR: heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows).
  • cargo test -p xcl --lib -- nonzero_flags compute_flags --test-threads=4 --nocapture: PR 2 passed, 0 failed on both (compute_flags_recipe_records_dedups_and_parses_nonzero_flags, nonzero_flags_compute_pipeline_is_cached_and_reused_under_flags_key).

Drivers: RX 9070 XT (RDNA4) 32.0.32029.2010, RTX 3060 32.0.16.1088. I didn't check whether the split test builds native or split wave64 on the RX 9070 XT, so this doesn't claim native wave64 coverage.

Not tested: retail packs / XCL_SAMPLE_RPF, cross-adapter refusal of a WARP-only flag, Intel, release.

AI use: Claude Code (Claude Opus 5.5) ran the tests on this machine and wrote this report.

@retrope13

Copy link
Copy Markdown
Author

Huge thanks everyone (@JJAutoCompare, @ettehn, @LocranKing, @cindertheblue, @DarkPanda69) for testing this across Intel Arc A770, NVIDIA RTX 3060 / 3060 Ti, AMD RX 7600 XT, and AMD RX 9070 XT!

Updates pushed

  1. Merged latest main (2c717a04) in ad820512: Resolved the crates/xcl/src/shaders.rs conflict with #1871 / #3043 and wired extra_flags through PipelineJob / make_pipelines, so xcl pso-precompile, xcl shaders --precompile --pipelines, and prepare_for_launch all precompile recorded nonzero compute PSO flags.
  2. Fixed @ettehn's sharing-violation catch in ed49370e: record_compute_flags_in now only inserts (record, flags) into SEEN after writeln! succeeds, so a transient sharing violation on compute-pso-flags.txt won't drop a flag for the rest of the process. Added compute_flags_recipe_retries_after_transient_sharing_violation to cover the exact FILE_SHARE_READ scenario.

Re-verified locally (Windows 11, RTX 4060 Laptop GPU / Intel UHD)

  • cargo check --locked -p xcl --all-targets — clean
  • cargo test --locked -p xcl --lib driver_cache::tests:: — 6 passed, 0 failed (including the new sharing-violation retry test)
  • cargo test --locked -p xcl --lib shaders::pipeline_selection_tests:: — 3 passed, 0 failed
  • cargo test --locked -p xcl --lib shaders::pipeline_cap_tests:: -- --test-threads=1 — 5 passed, 0 failed on both XCL_ADAPTER=NVIDIA and XCL_ADAPTER=Intel
  • cargo test --locked -p xcl --test shaders_e2e — 9 passed, 0 failed
  • XCL_ADAPTER=NVIDIA cargo test --locked -p xcl --test gpu_compute_e2e -- --test-threads=1 — 9 passed, 0 failed (1 skipped: heap_window_out_of_memory_falls_back_to_the_switch_form without XCL_HEAP_WINDOWS=1)

@cindertheblue — thank you so much for running the xcl-smoke pair earlier! Since the head commit updated to ed49370e, I don't have a retail pack locally to refresh the head xcl-smoke block myself, so if anyone happens to re-run it on ed49370e I'll happily paste the updated pair into the PR description.

(AI disclosure: Antigravity (Gemini 4) assisted with resolving the merge conflict, writing the SEEN fix/test, and drafting this reply; all builds and tests were run locally on my machine.)

@retrope13

Copy link
Copy Markdown
Author

Merged latest main (e429936c) into fix/pso-flags-cache-2995 at fd53bc64 to resolve the conflicts in crates/xcl/src/hle/d3d12x/real.rs and crates/xcl/src/shaders.rs (preserving LoadedBlob, dispatch_remap, prewarm_indirect, prepare_compiled_compute, and the earlier record_compute_flags_in SEEN fix).

Re-verified locally on Windows 11 (NVIDIA GeForce RTX 4060 Laptop GPU + Intel(R) UHD Graphics, rustc 1.100.1, DXC 1.9.2602.17):

  • cargo check --locked -p xcl --lib --bins --tests — pass
  • hle::d3d12x::real::driver_cache::tests:: — 19 passed, 0 failed
  • shaders::pipeline_selection_tests:: — 3 passed, 0 failed
  • XCL_ADAPTER=NVIDIA / XCL_ADAPTER=Intel shaders::pipeline_cap_tests:: -- --test-threads=1 — 5 passed each, 0 failed
  • XCL_ADAPTER=NVIDIA --test shaders_e2e — 9 passed, 0 failed
  • XCL_ADAPTER=NVIDIA --test gpu_compute_e2e -- --test-threads=1 — 9 passed, 0 failed (including both recorded nonzero-flag compute tests)

(Conflict resolution and local test commands assisted by Antigravity (Gemini 4). Note: still no retail title available here for an xcl-smoke block.)

@Aniseto

Aniseto commented Nov 28, 2026

Copy link
Copy Markdown

Ran the compute PSO flags cache tests at fd53bc64 on an NVIDIA Blackwell desktop part:

Environment: Windows 11 Pro build 26200 x64, NVIDIA GeForce RTX 5070 Ti (Blackwell, wave32 only, 16 GB) driver 32.0.16.2124, Intel Core i5-12400F, 64 GB RAM, rustc 1.100.0 (0ef1bc386 2026-11-09), MSVC 14.44.35207, DXC 1.9.2609.5, debug build.

XCL_ADAPTER=NVIDIA cargo test -p xcl --lib -- driver_cache::tests:: shaders::pipeline_cap_tests:: --test-threads=1
24 passed; 0 failed; 0 ignored; 0 measured; 2008 filtered out      (exit 0)

XCL_ADAPTER=NVIDIA cargo test -p xcl --test gpu_compute_e2e -- --test-threads=1
9 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out      (exit 0)

The gpu_compute_e2e run reported one SKIPPED (heap_window_out_of_memory_falls_back_to_the_switch_form, needs XCL_HEAP_WINDOWS=1), not counted as coverage. All tests pass here, including the GPU test for a nonzero-flags compute pipeline cached and reused under its flags key. The thread has runs on RTX 4060, RTX 3060 Ti and Intel, but no 5070 Ti.

Not tested: AMD and native wave64 hardware, a paired smoke run, the full workspace suite, release profile, a retail title, game data.

AI-assisted (OpenCode), model: DeepSeek V4.1 Flash Free - checked out the PR's head commit in a detached worktree, built it, ran the tests, wrote this report; the worktree was not modified; no game data was used.

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

The cache-key mismatch is real and the targeted whole/split round-trip tests are strong. I found no concrete defect in recording and replaying nonzero compute PSO flags.

The branch currently conflicts and the required current-head retail smoke is missing. Please rebase, rerun the end-to-end flag round trip on the rebased head, and add exact-head main/PR smoke evidence before merge.

Reviewed at fd53bc6 with Codex (GPT-5).

@retrope13
retrope13 force-pushed the fix/pso-flags-cache-2995 branch from fd53bc6 to a20ec00 Compare November 28, 2026 23:24
@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 area:tests Unit, integration, e2e tests, or testtitle gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks) labels Nov 28, 2026
@retrope13

Copy link
Copy Markdown
Author

@bmjask Thanks for the review! Rebased fix/pso-flags-cache-2995 cleanly onto main (de672a2d) as a single commit at a20ec000:

  • Resolved conflicts in crates/xcl/src/hle/d3d12x/real.rs and crates/xcl/tests/gpu_compute_e2e.rs
  • Kept Pipelines::make non-cfg(test) for the new shaders/milestone.rs
  • Updated XCL_DIRECT_SPLIT_INSTRUCTIONS from 12 to 16 in offline_split_compute_pipeline_reuses_recorded_nonzero_flags to match split_compute_prefers_the_offline_whole_pipeline under main's 4× entry-block split rule

Re-ran the test suites on the rebased head a20ec000 (Windows 11, NVIDIA GeForce RTX 4060 Laptop GPU + Intel(R) UHD Graphics, rustc 1.100.1, DXC 1.9.2602.17):

  • cargo check --locked -p xcl --lib --bins --tests — pass
  • hle::d3d12x::real::driver_cache::tests:: — 21 passed, 0 failed
  • shaders::pipeline_selection_tests:: — 3 passed, 0 failed
  • XCL_ADAPTER=NVIDIA / XCL_ADAPTER=Intel shaders::pipeline_cap_tests:: -- --test-threads=1 — 5 passed each, 0 failed
  • XCL_ADAPTER=NVIDIA --test shaders_e2e — 9 passed, 0 failed
  • XCL_ADAPTER=NVIDIA --test gpu_compute_e2e -- --test-threads=1 — 11 passed, 0 failed (1 skipped: heap_window_out_of_memory_falls_back_to_the_switch_form without XCL_HEAP_WINDOWS=1; both offline_compute_pipeline_reuses_recorded_nonzero_flags and offline_split_compute_pipeline_reuses_recorded_nonzero_flags passed)

Note: I still don't have a retail title set up here to generate the paired xcl-smoke blocks on a20ec000 / main, so that part will need someone with a retail title to attach before merge.

(Rebase and local test verification assisted by Antigravity (Gemini 4).)

@retrope13
retrope13 force-pushed the fix/pso-flags-cache-2995 branch 2 times, most recently from 3eafef1 to 9f02920 Compare November 30, 2026 08:38
@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Triage (#1607) – head 9f02920

No other PR addresses #2995. #2515 keeps the title's flags in the runtime's cache key, but the offline descriptor still uses Flags = 0. It does not record or precompile flag variants.
One cost found in the diff: Pipelines::prepare_compute calls driver_cache::load_compute_flags() for every compute program. That re-reads and re-parses compute-pso-flags.txt once per shader during startup preparation (shaders/milestone.rs, pso_corpus.rs), while precompile loads it once. Loading it once per Pipelines would avoid that. Also, the runtime calls record_compute_flags under a global mutex with a path.exists() check on every nonzero-flag compute PSO creation. That is cheap but not free.
Recommendation: keep open.

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

@retrope13
retrope13 force-pushed the fix/pso-flags-cache-2995 branch from 9f02920 to 4e861ec Compare December 1, 2026 22:56
@retrope13

Copy link
Copy Markdown
Author

@Foniass Thanks for the triage and good catch! Addressed both points and rebased cleanly onto main (1c8b5514) at 4e861ec4:

  • Loaded observed_flags once inside Pipelines::for_adapter and reused it from self.observed_flags in both Pipelines::prepare_compute (milestone.rs, pso_corpus.rs) and precompile, eliminating per-shader reads/parses of compute-pso-flags.txt.
  • Removed the per-call path.exists() check and PathBuf allocation on the SEEN fast path in record_compute_flags_in (checks map.get(path) first and only touches the filesystem on unseen entries, while keeping the retry-on-sharing-violation behavior).

Re-verified locally on 4e861ec4 (Windows 11, NVIDIA GeForce RTX 4060 Laptop GPU + Intel(R) UHD Graphics, rustc 1.100.1, DXC 1.9.2602.17):

  • cargo check --locked -p xcl --lib --bins --tests — pass
  • hle::d3d12x::real::driver_cache::tests:: — 21 passed, 0 failed
  • shaders::pipeline_selection_tests:: — 3 passed, 0 failed
  • XCL_ADAPTER=NVIDIA / XCL_ADAPTER=Intel shaders::pipeline_cap_tests:: -- --test-threads=1 — 8 passed each, 0 failed
  • XCL_ADAPTER=NVIDIA --test shaders_e2e — 9 passed, 0 failed
  • XCL_ADAPTER=NVIDIA --test gpu_compute_e2e -- --test-threads=1 — 11 passed, 0 failed (1 skipped: heap_window_out_of_memory_falls_back_to_the_switch_form without XCL_HEAP_WINDOWS=1; both whole and split nonzero-flag round trips passed)

(Follow-up edits and local verification assisted by Antigravity (Gemini 4).)

@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Follow-up review (head 4e861ec, since 9f02920, diff read, not a merge-check; checks red):

  • load_compute_flags() re-read once per compute program during startup preparation: fixed. The map is loaded once in Pipelines::for_adapter and kept in Pipelines::observed_flags (shaders.rs ~2571), read by prepare_compute (~2650) and precompile (~4237, ~4355).
  • record_compute_flags runs path.exists() under a global mutex on every nonzero-flag compute PSO: fixed. record_compute_flags_in (real.rs ~6674) now looks the path up in its map and touches the file only for a new path or a new (record, flags) pair.

New:

  • The startup preparation path for recorded flags has no test. The extra-flags loop in prepare_compiled_compute (shaders.rs ~2676-2692) runs only when mandatory is set (startup, or XCL_PRECOMPILE_PARENT). The new e2e tests run xcl shaders --precompile --pipelines without XCL_PRECOMPILE_PARENT, so they go through make_pipelines / make_selected, and the GPU unit test calls make_with_flags. Nothing runs the startup flag variants (whole, or chain pieces when the whole is missing), or checks that a refused recorded flag does not abort preparation.
  • No smoke blocks, and Tested is for an earlier commit. The PR changes the runtime (real.rs), but Regression run describes commits 623d02e4 / 894ae3be in prose instead of two scripts/smoke.ps1 blocks for main and 4e861ec4, which is why PR description is red.
  • Reviewed-by: Foniass trailer. The only earlier comment from this account was an automated triage note marked as not checked by a human, not a review; the trailer should go.

Fine: the runtime records flags only after the driver accepts the PSO, with the same d.Flags that compute_container puts in the cache key; flags-0 behaviour of prepare_compiled_compute and make_selected is unchanged; refused nonzero-flag variants go to flags_refused and do not count as failures; the sharing-violation retry has a unit test.

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

Record driver-accepted nonzero D3D12_PIPELINE_STATE_FLAGS for translated
console compute PSOs in a compute-pso-flags.txt sidecar next to the DXIL
cache, and replay those observed flag variants during offline precompile
and startup preparation so cached driver blobs match the runtime key.

- Load observed_flags once per Pipelines instance (reused by precompile,
  milestone.rs, and pso_corpus.rs without per-shader disk re-reads).
- Only mark (record, flags) seen in memory after writeln! succeeds, and
  check SEEN via map.get(path) on the hot path without per-call
  path.exists() syscalls or PathBuf allocations.

Reported-by: ettehn
@retrope13
retrope13 force-pushed the fix/pso-flags-cache-2995 branch from 4e861ec to d78e190 Compare December 1, 2026 23:40
@retrope13

Copy link
Copy Markdown
Author

@Foniass Fair points — updated at d78e190f (still on main 1c8b5514):

  • Removed the Reviewed-by: Foniass trailer from the commit message.
  • Added shaders::pipeline_cap_tests::startup_preparation_warms_nonzero_flags_and_tolerates_refused_flags exercising Pipelines::prepare_compiled_compute directly for recorded nonzero flags on both the whole path and the over-cap split-chain fallback, and asserting that a refused nonzero flag (0x4000_0000) increments flags_refused without incrementing refused or aborting preparation (also gated capped accounting in make_required to flags == 0 for consistency).

Re-verified locally on d78e190f (Windows 11, NVIDIA GeForce RTX 4060 Laptop GPU, Intel(R) UHD Graphics, and WARP, rustc 1.100.1, DXC 1.9.2602.17):

  • cargo check --locked -p xcl --lib --bins --tests — pass
  • hle::d3d12x::real::driver_cache::tests:: — 21 passed, 0 failed
  • shaders::pipeline_selection_tests:: — 3 passed, 0 failed
  • XCL_ADAPTER=NVIDIA / XCL_ADAPTER=Intel / XCL_ADAPTER=warp shaders::pipeline_cap_tests:: -- --test-threads=1 — 9 passed each, 0 failed
  • XCL_ADAPTER=NVIDIA --test shaders_e2e — 9 passed, 0 failed
  • XCL_ADAPTER=NVIDIA --test gpu_compute_e2e -- --test-threads=1 — 11 passed, 0 failed (1 skipped: heap_window_out_of_memory_falls_back_to_the_switch_form without XCL_HEAP_WINDOWS=1)

(Follow-up test, commit-message edit, and local verification assisted by Antigravity (Gemini 4). Still no retail title locally for paired xcl-smoke blocks.)

@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Follow-up review (head d78e190, since 4e861ec, diff read, not a merge-check; checks red):

  • The startup preparation path for recorded flags has no test: fixed. startup_preparation_warms_nonzero_flags_and_tolerates_refused_flags (shaders.rs ~2553-2656) calls prepare_compiled_compute with a valid and an undefined flag, for the whole program and for the over-cap case that uses the chain, and checks that only the 0 and valid-flag outputs are made and that the refused flag only raises flags_refused.
  • Reviewed-by: Foniass trailer: fixed; removed.
  • Per-program load_compute_flags() and the per-PSO exists(): still fixed.
  • No smoke blocks, and Tested is for an earlier commit: still open. Regression run still describes 623d02e4 / 894ae3be in prose instead of xcl-smoke blocks for main and d78e190f (the reason PR description is red), and Tested does not list the new test.

New: none. make_required now adds to capped / capped_bytes only for flags == 0 (~2968, ~3004), so an over-cap program is not counted again per recorded flag.

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 area:tests Unit, integration, e2e tests, or testtitle 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.

Shaders: offline compute precompile misses nonzero PSO flags

9 participants