D3D12.X: pipelines that share a shader share one copy of its bytes #827
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl!827
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-827"
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?
@Cattn on GitHub · 2026-11-24 06:12 UTC · original
Cattn:intern-shader-blobs→main· +40 −11 · 1 files · 1 commits · openAn async pipeline keeps its description, with copies of its shader bytecode, until it is built. A title that creates tens of thousands of pipelines from a few thousand shaders holds one copy per pipeline. A retail title had about 84,000 pending pipelines; with the copies shared, its commit at 80 s was about 1 GB lower (27,016 MB against 27,972 MB, in a longer run on a branch with other changes).
What is in it
crates/xcl/src/hle/d3d12x/real.rs:intern_shader_blobkeeps a weak map from (hash, length) toArc<[u8]>, compares the bytes in full, andown_shader/own_streamstore the sharedArcinstead of aVec<u8>copy.shaders_keytakes any byte slices. A unit test checks that equal shaders share one copy, different ones do not, and that a copy is made again once every pipeline released it.Tested
cargo test --workspace --no-fail-fast -- --test-threads=4on44d6921: 702 passed, 0 failed, 41 ignoredgpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardware(no wave64)Regression run
The first smoke run of this commit came right after two others with a warm shader cache, got further into loading in its 60 s and peaked at 22,423 MB. I ran main and this PR again back to back; these are the second pair.
main:
this PR:
Not tested
AI use
🤖 Generated with Claude Code
@crosettiremi on GitHub · 2026-11-24 06:18 UTC · original
Checked
44d6921on Windows with an RX 7900 XT. The title run adds this PR to the #782 residency comparison and uses the same saved Series X profile, 28 GiB job cap, 6 GiB texture budget, and A press at 75 seconds. The disk cache directories started from the same snapshot. The AMD driver cache persisted.At 150.26 s, queued or active descriptors referenced 588 MiB of shader bytes counting duplicates. The interner held 185 MiB of live payload and 2 MiB of payload behind expired weak entries, about 401 MiB less than retaining each reference separately. The process committed 28,231 MB at that sample, versus 28,117 MB without #827 at 150.07 s. Texture and driver allocation patterns varied. The run had an explicit native compute creation E_OUTOFMEMORY (0x8007000e) at 151.450 s, peaked at 28,440 MB sampled process commit, and exited with 0xc0000409. No device removal was logged.
The weak-cache entry has a lifetime detail. Arc<[u8]> allocates the bytes inline, so Weak<[u8]> retains the backing allocation after strong_count reaches zero. An 8 MiB standalone allocator probe on the installed MSVC Rust toolchain measured 8,388,624 bytes retained after the final owner dropped, versus 40 bytes for Arc<Vec> with Weak<Vec>. A local change to Arc<Vec> preserves pointer sharing between descriptors and releases the payload with the last strong owner. Both shader-key and sharing tests pass with that representation. The retail sample retained only 2 MiB in expired entries, so this specific issue does not account for the memory peak.
@MesshM on GitHub · 2026-11-24 06:21 UTC · original
Test run of
44d69219872ae75420b953a8c9853aa6b57a29a3on AMD RDNA4. I merged it onto currentmainbeaa245locally (clean merge) and tested that tree.Tested
stable-x86_64-pc-windows-msvc, debugcargo build --workspace+cargo test --workspace -- --test-threads=4on the merge: 714 passed, 0 failed, 41 ignored, exit code 0;xcllib tests 673 passed; 0SKIPPED.Review: Sharing the shader bytes of pending pipelines as
Arc<[u8]>keeps one copy per shader instead of one per pipeline; the build path reads the same bytes. I found nothing to change.Not tested: no retail title or regression run (I have no unpacked game), release build.
Run and review by Claude Code (Claude Opus 5.5) on this machine.
@dcastell1 on GitHub · 2026-11-24 06:50 UTC · original
Verified on Windows 11 10.0.26300, NVIDIA GeForce RTX 5090 (driver 621.24), Rust 1.100.0 MSVC 14.44.35207, debug build, applied on
main@beaa245:That is one more passing test than
mainon the same box (737), so shader blobs shared between pipelines runs green here and nothing else in the workspace changes verdict. No game data, hardware adapter, no Wine.AI-assisted (opencode): applied the patch to a built tree, ran the suite, restored the two files.
@ryosen0 on GitHub · 2026-11-24 06:51 UTC · original
Paired 150 s runs of
44d6921vs currentmain(beaa245) on RTX 3060 Ti 8 GB (Ryzen 7 9800X3D, driver 32.0.16.1742, Windows 11, release), same title, same scripted presses (25/35/45/55/65/80/95/110/125/140 s), same session — reaching the loading screens where the pending-pipeline population is large:beaa24544d6921So the interning saving is real and measurable on a second host in a plain 150 s window: ~120 MB here, consistent in both the 80 s sample and the peak. Smaller than the 1 GB figure from your longer stacked run, as expected — this window creates far fewer pending pipelines than a full world load, and the saving should scale with the pending population. Frame pacing identical (60 presents / 2 s throughout both).
The
thehollowedonelifetime point above stands independent of this measurement.AI use: GPT-6.2 Astra (API model selector) in DSH built both commits, ran the paired runs, and drafted this comment; the human contributor reviewed the numbers before posting.
@SlopTart on GitHub · 2026-11-24 07:17 UTC · original
Linux / AMD RDNA3 datapoint.
Merged state: head
44d6921onto maina1672ef, clean merge.Full suite,
cargo test --workspace --release --no-fail-fast --target x86_64-pc-windows-gnu -- --test-threads=4: 706 passed, 10 failed, 41 ignored. Failures are the known Wine-lane set from my #42 rows plus #718 trio members; nothing here fails because of your change. Shared shader byte tests green; no new failures.Not tested: retail titles (none here), Windows, RDNA4.
Counts only, no game data.
Machine: RX 7900 XT (RADV NAVI31), Mesa 26.2.5, kernel 7.2 (Arch), Proton Experimental (wine-11.0), patched vkd3d-proton v3.1, Rust cross
x86_64-pc-windows-gnu,XCL_NETWORK=0, release profile,--test-threads=4. Linux rows: #42 / #718.AI use: Hermes agent (local Qwen-class) ran the suite and drafted this; I checked it before posting.
@raylitebull on GitHub · 2026-11-24 10:39 UTC · original
Code/CI review only (not independently runtime-tested by me): clean merge with both checks green (
Build and test+PR description). Small, clean+40/-11change deduplicating shader bytes across pending PSOs. Recommend merging, @ivall.@DavidM1911 on GitHub · 2026-11-25 10:38 UTC · original
Verification on RTX 3060 Ti (Windows 11): merge conflict with current
main— needs a rebase before it can be tested.@thehollowedone on GitHub · 2026-11-24 06:20 UTC · original · edited 2026-11-25 14:21 UTC
Shader allocation lifetime on
44d6921. A synthetic fixture calledintern_shader_blobwith 32 distinct 2 MiB buffers and confirmed identical inputs shared a live allocation. On Windows 11 build 26300, Ryzen 7 9800X3D, Rust 1.99.1 MSVC, private commit rose 64.26 MiB and stayed there after the last strong owners were dropped.A separate
Arc<Box<[u8]>>control rose 64.25 MiB and returned to its starting commit after the strong owners dropped, with all weak entries still present. This matches Rust’sWeakallocation lifetime. WithWeak<[u8]>, the shader bytes are in the allocation the map still retains.cargo test --offline --locked -p xcl --lib scratch_shader_blob_commit_lifetime -- --nocapture --test-threads=1passed 1/1 in two fresh debug processes with identical measurements and zero skips. Synthetic CPU memory only. AI-assisted. Codex (GPT-6, exact variant unavailable) wrote and ran the fixture and drafted the report.Current-main integration recheck. 44d6921 still conflicts with 06c9f55. I resolved the two conflicts locally, preserving the public shader key and main’s empty shader stream handling, and tried the separate byte allocation in the actual pipeline ownership code.
A second synthetic probe counted live allocator bytes after both owners of each of 24 distinct 2 MiB buffers were dropped. The PR interner retained 50,333,104 bytes. The local version retained 1,584 bytes of cache metadata. Both shared the live allocation for equal inputs.
The local integration passed
cargo build --offline --locked --workspace -j 6andcargo test --offline --locked --workspace --no-fail-fast -j 6 -- --test-threads=4 --nocapture. Results were 1,266 passed, 0 failed, 46 ignored, including 26 runtime skips. Shader-key, shader-sharing and stream tests passed. The full suite used an RTX 3080 Ti / 621.35 and DXC 1.8.2502.11. Synthetic evidence only. Codex (GPT-6, exact variant unavailable) resolved the local integration, wrote the allocator probe, ran the tests and drafted this update.@S1m0ne1997 on GitHub · 2026-11-25 14:03 UTC · original · edited 2026-11-25 14:23 UTC
Test report for
44d69219872ae75420b953a8c9853aa6b57a29a3(this PR's head), for #1607.Tested
rustc 1.100.0 (0ef1bc386 2026-11-09)x86_64-pc-windows-msvc, debug.cargo build --workspace, thencargo test --workspace -- --test-threads=4at the head: 702 passed, 0 failed, 41 ignored.gpu_geometry_wave32_prefix_count_over_a_mask(no wave64),gpu_wave32_program_in_wave64_hardware(no wave64).Regression run (retail title,
scripts/smoke.ps1 -Seconds 60, release;mainbuilt from the commit in its block, this PR from its head, no uncommitted changes)main:
this PR:
Not tested
AI use: Claude Code with Claude Opus 5.5 ran the build, the suite and the regression run and wrote this report at my request.
@crastinator on GitHub · 2026-11-25 21:22 UTC · original
Linux / AMD RDNA2 test report for
44d6921, merged onto currentmain6d12f58: no new test failures, a clean smoke pair, and on a retail title the shared copies take 106,496 shader copies (210 MB) down to 3,493 distinct shaders (58 MB) by 14 s.Merge with
main: two conflicts, both inreal.rs:shaders_keyispub(crate)onmainnow (shaders.rscalls it). I kept that, with your generic signature.own_stream's shader branch was restructured onmain(a null shader is zeroed, an unreadable one refuses the stream). I keptmain's structure withintern_shader_blobin place of theto_vec().main's newer testown_stream_rejects_null_truncated_and_unreadable_streamsneedsassert_eq!(&*blobs[0], &shader[..]), becauseblobs[0]is anArc<[u8]>now.Tested
53aac418); cross-built forx86_64-pc-windows-msvc.cargo test -p xcl --lib -- hle::d3d12x::real::: 60 passed, 0 failed (with your new test).--lib --test-threads=1and every integration test), compared per test withmain6d12f58: 1411 passed, 13 failed, 46 ignored (main: 1410 / 13 / 46). The same 13 fail onmain.intern_shader_blob, retail title, 14 s in: 106,496 shader copies requested, 210 MB (whatmaincopies); 3,493 distinct shaders kept, 58 MB; 59 MB allocated in all. Plain process RSS was too noisy between runs to show the ~150 MB on its own.scripts/linux/smoke.sh, thesmoke.ps1block under Wine,XCL_COHERENT_MB=512; "this PR" is the local merge commit):main:
#827 merged onto it:
A small note on the code: a
Weak<[u8]>keeps theArc's allocation alive, bytes included. So a shader whose pipelines were all released stays allocated until the same shader is interned again (I checked this with a counting allocator). Here that is about 1 MB (59 MB allocated against 58 MB live), so it does not matter for this title. Removing dead entries now and then would close it.Not tested
mainand with this PR alike (it hit 2 of 3 runs of each). It is not from this PR, but it makes long RSS comparisons unreliable.AI use: Claude Code (Claude Opus 5.5) merged, built and ran this, wrote the counter and this report; I checked the results.
View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.