D3D12.X: base pipelines keep their own copy of their shaders, shared by content #3292
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3292"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from ivall/xcl. Originally posted by Foniass on 2026-11-29T06:18:48Z.
RSSetDepthBiasX's patched-pipeline fallback and CreateDerivedPipelineStateX
derive a pipeline from a base one recorded at its creation. The base kept
the title's shader pointers and checked the bytecode by hash when deriving:
once the title freed or reused its shader buffers (common after pipeline
creation), deriving failed ("the shaders of base pipeline ... are gone").
The base now owns its stage bytecode. Tens of thousands of pipelines share
a few thousand shaders, so the copies are interned in a pool keyed by
(fnv64, length) and compared byte for byte (Arc<[u8]>, weak entries swept
as the pool grows): one copy per distinct shader, freed with the last
pipeline that holds it.
Ported from amd-dev
48cf7139(its device_x part) and60345c97(the sharedpool), raylitebull. The other parts of
48cf7139are separate PRs.What is in it
crates/xcl/src/hle/d3d12x/device_x.rs:Base::shader_blobs(Arc<[u8]>per stage), the interning poolBASE_SHADERS,desc_with_owned_shadersfor RSSetDepthBiasX and CreateDerivedPipelineStateX; testbase_pso_retains_shader_bytecode_after_title_buffer_changes(bytecode survives the title freeing its buffers, identical shaders share one copy, the copy goes with the last pipeline)Tested
cargo test --workspace --no-fail-fast -- --test-threads=4on7e242379: 2605 passed, 4 failed, 49 ignored. The 4 failures aregpu::dxil::fuzz_tests::fuzz_validate_and_gpu_0..3(E_OUTOFMEMORYfromCreateComputePipelineState, seeds 70 / 545 / 1019 / 1507), the same as on main on this machine; they pass on another RTX 5070 Ti. SKIPPED GPU tests: 44 notices, almost allno wave64.Regression run
main:
this PR:
Not tested
AI use
🤖 Generated with Claude Code
Imported from ivall/xcl. Originally posted by andrewDoing on 2026-11-29T06:36:09Z.
Overlap with #3091 matters for the stated last-owner guarantee. Weak<[u8]> keeps the Arc allocation, including its inline bytes, allocated after the final strong owner drops. Weak::upgrade returning None proves the shader is no longer accessible through the index; it does not prove its allocation was freed.
I compiled the exact interning helpers from this head (
7e242379) and #3091 (1dad60ed) in a Windows allocator-instrumented CPU harness. Eight synchronized threads retained 512 references to 16 distinct immutable 256 KiB shader payloads. Both helpers shared identical bytes by pointer across all threads and preserved all contents. After joining, I dropped every strong reference, leaving each production weak index intact. Net live allocations of the payload sizes (input buffers excluded) were:The 256-byte difference while live is the inline Arc headers on this toolchain; the material difference is the 4 MiB of outstanding payload after release. If no later insertion triggers the sweep, that allocation remains. Both implementations copy on a cold miss outside the lock and recheck before publishing, so concurrent cold misses can transiently allocate duplicates. This measures allocator requests and releases, not RSS or peak commit.
I suggest coordinating the derived-base path with #3091, whose bounded weak index also covers pending async recipes. If taking this PR alone, splitting payload storage from the weakly retained allocation and asserting deallocation rather than failed upgrade would match its stated guarantee. OpenAI Codex prepared and ran the CPU controls and drafted this comment.
Imported from ivall/xcl. Originally posted by Kalmarv on 2026-11-29T07:54:01Z.
merge-check
base:
fa204595head:
7e242379verdict: safe to merge
Merged cleanly onto
origin/main(fa204595) in a 5-PR batch (#3288,#3290,#3292,#3294,#3300) and verified on NVIDIA GeForce RTX 5070 Ti with DXC 1.9.2609.5:hle::d3d12x::ande2edebug-layer runs.gpu::: 853 passed, 0 failed, 24 ignored (10.45 s, includingfuzz_validate_and_gpu_0..3).hle::d3d12x::(--test-threads=1, skipping 2 knownmain#3187uma_drivermixed-window tests): 1144 passed, 0 failed, 3 ignored (30.21 s).xcl --lib(--test-threads=1): 0 failed.-p xcl --test e2e(after rebuildingxcl-testtitle): 5 passed, 0 failed (including D3D12 debug layer + DRED).Build and test (Windows, no GPU)andPR description): green.Imported from ivall/xcl. Originally posted by Aniseto on 2026-11-29T08:42:09Z.
Ran the base-pipeline shader retention test at
7e242379on an NVIDIA Blackwell desktop part with an updated driver:Environment: Windows 11 Pro build 26200 x64, NVIDIA GeForce RTX 5070 Ti (Blackwell, wave32 only, 16 GB) driver 32.0.16.2140 (621.40), 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.
The test passes: base pipelines keep their shader bytecode after the title frees its buffers and identical shaders share one copy. The thread already has an RTX 5070 Ti report on driver 32.0.16.2114; this adds the newer driver 32.0.16.2140. It is a synthetic retention test, not the title path that derives pipelines after freeing buffers.
Not tested: a retail title, a paired smoke run, the full workspace suite, AMD and Intel GPUs, native wave64 hosts, Wine, release profile, 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.
Imported from ivall/xcl. Originally posted by throny on 2026-11-29T09:21:19Z.
merge-check claim
head:
7e24237984Imported from ivall/xcl. Originally posted by throny on 2026-11-29T09:36:10Z.
merge-check
base:
d8bd9a38head:
7e24237984merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2619 passed, 0 failed, 49 ignored (27 SKIPPED lines). Base alone at
d8bd9a38: 2618 passed, 0 failed, 49 ignored.review: no finding. A base pipeline now holds its own copies of its shaders (shared between pipelines through a pool of weak references) instead of hashes, the stored description no longer holds the title's shader pointers, and they are pointed at the copies when a pipeline is derived. Lifetimes are sound from reading: the base owns the bytes, the description with the copies is used only while the base is alive, and the background build path copies the shaders itself. Deriving a pipeline after the title freed its shaders now works where main returned E_FAIL, which is the intent. Cost: one copy of each distinct shader stays in memory as long as a graphics pipeline using it lives. The test checks the sharing, the bytes and the release after the last pipeline; it does not drive the two derive functions themselves.
performance: not measured (memory: see the cost above).
verdict: safe to merge
hardware / tool and model: RTX 4080 16 GB (621.40), i9-12900K, Windows 11 26300, Rust 1.100.0, debug. Claude Code; merge, build and suite run by Claude Fable 5.2, diff review by Claude Opus 5.5 (every hunk read; nothing run on the GPU beyond the suite).
Imported from ivall/xcl. Originally posted by crosettiremi on 2026-11-29T19:02:56Z.
A negative data point: the error this targets ("shaders of base pipeline ... are gone") does not occur in any of our 19 retail-title logs on a Radeon RX 7900 XT 20 GB (driver 32.0.32029.2010), bases
fa204595andd8bd9a38, 4 and 16 UMA windows, cold and warm caches, runs that reach the first world frame. So this card and title give no before/after for it. I have not run this PR's head. Since our runs end at a job commit limit, I would be interested in what the kept copies cost in commit on a full retail load if anyone measured it.AI use: Claude Code (Claude Fable 5.2) searched the logs and wrote this.