Repository navigation
D3D12.X: pipelines not built yet share the copies of equal shaders - #3505
ArtuArtaza wants to merge 2 commits into
Conversation
A pipeline made in the background keeps its description, with a copy of each shader's bytes, until a worker builds it (`OwnedDesc`). A lazy one keeps it until its first use, often the whole run. A retail title makes about 83,000 pipelines at its start, 81,500 of them graphics, and about 2,000 are built in a run, so the copies of the rest stay. `device_x::intern_shader_blob` already keeps one copy of each distinct shader for the tracked base pipelines (7e24237). `own_shader` and `own_stream` take their copies from that pool now. Measured with a counter in both builds (not in this commit), Series S profile, 240 s in the title's opening area: 155,648 shader copies asked for, 527 MB of them made before, 143 MB (18,112) with the change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Independent Windows check of One lifetime detail is worth carrying over from #3091. The new I compiled the current pool and hash function in an isolated Rust probe and counted live 256 KiB slice allocations. Holding 128 equal blobs used 32 MiB with standalone copies and 0.25 MiB with the pool. After dropping those owners and then making and dropping 128 distinct blobs one at a time, standalone copies held 0 MiB and the pool still held 32.25 MiB. All 129 weak entries failed to upgrade. Clearing those entries released all the counted allocations. #3091's OpenAI Codex (GPT-6.2 Sol) assisted with source review and Windows verification. |
|
Follow-up to ettehn’s retention report: one integration detail matters for the fix. Please carry one shared Candidate shape- Weak<[u8]> / Arc<[u8]>
+ Weak<Vec<u8>> / Arc<Vec<u8>>
- Arc::from(bytes)
+ Arc::new(bytes.to_vec())
- shaders_key(blobs)
+ shader_set_key(blobs.iter().map(|blob| blob.as_slice()))Apply the shared type to the shader owners and the compute build key together. Add a regression that observes the backing buffer being released after the last strong owner drops while the weak index entry remains; |
The pool's entries are weak, but an `Arc<[u8]>` holds its bytes in the allocation its weak references keep: the bytes of a shader whose last owner went stayed until the pool's next sweep (8,192 entries or more). The copies are `Arc<Vec<u8>>` now, so they go with their last owner, as in xcl-dev#3091. The bases, the descriptions of pipelines not built yet and the compute build keys hold the same one. Found by ettehn; the shape of the fix and the need to change the build key with it are thehollowedone's (review of xcl-dev#3505). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Ran the shared shader-copy tests at System
Results
What this adds Not tested AI-assisted (OpenCode), model: DeepSeek V4.1 Flash Free - ran the commands above on this machine and wrote this report; no game data was used. |
|
Thanks, you are both right. I reproduced it before changing anything: 128 blobs of 256 KB without owners still held 32,776 KB behind 12713ec carries one The new test (Change and reply written by Claude Code with Claude Opus 5.5, sent from my account.) |
|
merge-check claim |
|
merge-check |
|
merge-check
|
|
Independent verification on RTX 5070 Ti (Windows 11, Ryzen 9 9950X, NVIDIA
(0 device removals, 0 crashes.) Not tested here: Full Verdict: Safe to merge. AI use: Antigravity assisted with merging locally, inspecting the diff, running the targeted tests and 60 s smoke, and drafting this report. |
|
Test report for #3505 at Tested
Not tested
AI use: Claude Code (Claude Opus 5.5) ran the tests and wrote this report. |
|
merge-check AI-written and posted by Foniass without a human check of each point. |
|
Same idea as #827: AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human. |
A pipeline made in the background keeps its description, with a copy of each shader's bytes, until a worker builds it (
OwnedDesc); a lazy one keeps it until its first use, often the whole run. A retail title makes about 83,000 pipelines at its start (81,500 of them graphics) and about 2,000 of them are built in a run, so the copies of the rest stay for the whole session.device_x::intern_shader_blobalready keeps one copy of each distinct shader for the tracked base pipelines (7e24237);own_shaderandown_streamnow take their copies from that pool.The second commit makes the pool's copies
Arc<Vec<u8>>: its weak entries kept the bytes of anArc<[u8]>after their last owner went, until the next sweep (8,192 entries or more). That was there before this PR, which gives the pool more callers. Found by ettehn; that the compute build key has to change with it, and the shape, are thehollowedone's (comments below).This is the idea of #827 (Cattn, open, conflicts with main) and part of #3091 (Prime1997, open, conflicts with main; its weak
Vecentries too), written again on today's main because the pool it needs is there now.What is in it
crates/xcl/src/hle/d3d12x/real.rs:own_shaderandown_streamtake their copies throughdevice_x::intern_shader_blob. Testowned_descriptions_share_the_copies_of_equal_shaders(graphics and stream descriptions of equal bytes at other addresses hold one copy; other bytes hold their own; a copy outlives the descriptions that shared it).crates/xcl/src/hle/d3d12x/device_x.rs:intern_shader_blobispub(super); the pool,Baseand the descriptions holdArc<Vec<u8>>(same lookup, full compare and second lookup as before). Testthe_pool_keeps_no_bytes_of_a_shader_without_owners: after the last owner goes the pool's entry is still there, and Windows says the pages of the bytes are free (VirtualQuery).crates/xcl/src/hle/d3d12x/real/compute_build_key.rs,pso_async.rs(its tests): the build key holds the sameArc<Vec<u8>>as the description, so no second copy.Tested
cargo build --workspace && cargo test --workspace --no-fail-fast -- --test-threads=4on12713ec6: 2834 passed, 3 failed, 51 ignored (43 test binaries). The 3 are 2 tests, and both fail the same way on unmodified maincfb9753aon this card (ran them there alone):gpu_compact_form_with_micro_blocks_and_literal_table_runs_as_the_plain_form((50, 0, 1, 5)against(50, 10045, 1, 5): what Recompiler: compact literal indices are read from one table word on AMD #3473 fixes) andgpu_two_pass_cache_e2e::two_pass_driver_cache_reuses_both_passes_and_recovers_corrupt_blobs(parent and child run,gpu_two_pass_cache_e2e.rs:472and:584). 4SKIPPEDnotices (no GPU_UPLOAD heaps, no heap windows, no Developer Mode).one copy of equal shaders), the second fails on the first commitc635d342(the bytes go with their last owner); both pass on the head.9dfbe3ea: no conflicts,cargo check -p xcl --all-targetspasses.XCL_DEVICE_TYPE=lockhart), its opening area,XCL_PREPARE=0 XCL_PSO_AHEAD=0, first commit only, 240 s, four runs by turns on main53e85fb1with Recompiler: a pixel shader's carry ballot reads its quad lane by lane, not through quadOp #3455, xcl run: XCL_RT_LEAVE_OUT leaves out a title's ray-tracing programs #3302 and Recompiler: compact literal indices are read from one table word on AMD #3473 (earlier main did not get that far on this card without them) plus a counter of the copies made, and the same with the change (two runs each; the counter is not in this PR):9dfbe3ea, first commit only, one run each of 150 s with cold caches: 155,648 copies (527 MB) made without, 17,705 (142 MB) with. The whole process' commit at the end shows no difference there (25,439 and 25,493 MB: the cold compiles and the heaps move it more than this does).cfb9753aand on this PR's head, blocks below: peak commit 13,672 MB and 13,504 MB.Regression run
main
cfb9753a, then this PR's head:Not tested
intern_shader_blobadds at pipeline creation (onefnv64of the shader and a lock) was not measured on its own.AI use
🤖 Generated with Claude Code