Repository navigation
D3D12.X: base pipelines keep their own copy of their shaders, shared by content - #3292
Conversation
…by content
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 48cf713 (its device_x part) and 60345c9 (the shared
pool), raylitebull. The other parts of 48cf713 are separate PRs.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
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 (7e24237) and #3091 (1dad60e) 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. |
|
merge-check Merged cleanly onto
|
|
Ran the base-pipeline shader retention test at 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. |
|
merge-check claim |
|
merge-check |
|
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 AI use: Claude Code (Claude Fable 5.2) searched the logs and wrote this. |
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 48cf713 (its device_x part) and 60345c9 (the shared
pool), raylitebull. The other parts of 48cf713 are 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=4on 7e24237: 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