D3D12.X: pipelines not built yet share the copies of equal shaders #3505
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3505"
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 ArtuArtaza on 2026-11-30T03:54:54Z.
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 (7e242379);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 #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 #3455, #3302 and #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
Imported from ivall/xcl. Originally posted by ettehn on 2026-11-30T06:12:54Z.
Independent Windows check of
c635d342merged cleanly intod52ff48c. Release build, Rust 1.97.1 MSVC, RTX 5070 Ti Laptop system (621.24). The device-hook, owned-description and malformed-stream tests passed 25/25, with both D3D12 GPU cases running and no skips.One lifetime detail is worth carrying over from #3091. The new
own_shader/own_streamcallers share live copies, but the pool storesWeak<[u8]>. Those weak entries still retain the entire inline slice allocation after the last owner drops it. On an insertion the pool sweeps only after the count threshold, initially 8,192 entries.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
Weak<Vec<u8>>approach would let the payload go at the last strong drop. These are synthetic allocation counts. I did not measure retail process commit or run the full workspace suite.OpenAI Codex (GPT-6.2 Sol) assisted with source review and Windows verification.
Imported from ivall/xcl. Originally posted by thehollowedone on 2026-11-30T07:21:11Z.
Follow-up to ettehn’s retention report: one integration detail matters for the fix.
ComputeBuildKeyalso owns anArc<[u8]>for a compute shader. If the pool andOwnedDescmove toArc<Vec<u8>>but the build key converts back toArc<[u8]>, each pending compute recipe can still keep a second payload copy.Please carry one shared
Arc<Vec<u8>>throughBase,OwnedDesc, andComputeBuildKey. Keep the current hash/length lookup, full-byte collision check, and locked second lookup; pass slices explicitly to hashing. This follows the weak-Vecownership pattern already in #3091.Candidate shape
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;
Weak::upgrade() == Nonealone passes for both representations.Imported from ivall/xcl. Originally posted by Aniseto on 2026-11-30T12:05:43Z.
Ran the shared shader-copy tests at
12713ec6on an NVIDIA Blackwell desktop part.System
Results
XCL_ADAPTER=NVIDIA cargo test -p xcl --lib owned_descriptions_share_the_copies_of_equal_shaders -- --test-threads=1: 1 passed, 0 failed, 0 ignored.XCL_ADAPTER=NVIDIA cargo test -p xcl --lib the_pool_keeps_no_bytes_of_a_shader_without_owners -- --test-threads=1: 1 passed, 0 failed, 0 ignored.What this adds
Both tests pass on the current head: equal shader bytes are shared by the descriptions and the copy outlives its owners without keeping pool bytes. The thread already has an RTX 5070 Ti Laptop report on the first commit; this adds a desktop 5070 Ti run on driver 32.0.16.2140 at the final head. Synthetic tests only; no title memory measurement was made here.
Not tested
A retail title, a paired smoke run, the full workspace suite here, AMD and Intel GPUs, native wave64 hosts, Wine, release profile, game data.
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.
Imported from ivall/xcl. Originally posted by ArtuArtaza on 2026-11-30T12:38:42Z.
Thanks, you are both right. I reproduced it before changing anything: 128 blobs of 256 KB without owners still held 32,776 KB behind
Weak<[u8]>, and 9 KB behindWeak<Vec<u8>>.12713ec6carries oneArc<Vec<u8>>throughBase,OwnedDescandComputeBuildKey. The lookup, the full compare and the second lookup under the lock are the same, andOwnedDesc::shaders_keyhashes the slices withshader_set_key.The new test
the_pool_keeps_no_bytes_of_a_shader_without_ownersdrops the last owner of a 4 MiB blob, checks that the pool's entry is still there, and asksVirtualQuerywhether the pages are free. It fails onc635d342and passes on the head. The suite, the merge check on main9dfbe3eaand the 60 s runs are in the description. The long title runs there are of the first commit; I did not repeat them with this one.(Change and reply written by Claude Code with Claude Opus 5.5, sent from my account.)
Imported from ivall/xcl. Originally posted by saintwolf on 2026-11-30T12:57:32Z.
merge-check claim
head:
12713ec6a4Imported from ivall/xcl. Originally posted by saintwolf on 2026-11-30T13:02:56Z.
merge-check
base:
9dfbe3ea66head:
12713ec6a4merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2886 passed, 3 failed, 51 ignored; SKIPPED: 27 (22 no wave64, 2 no heap windows, 2 no xgameruntime.dll, 1 cannot disable the driver cache 0x887A002D); failing: gpu::dxil::msaa_tests::gpu_direct_image_get_resinfo_d16 (also fails on base
9dfbe3eaalone) and two_pass_driver_cache_reuses_both_passes_and_recovers_corrupt_blobs in gpu_two_pass_cache_e2e (unrelated); targeted tests passed (the_pool_keeps_no_bytes_of_a_shader_without_owners, owned_descriptions_share_the_copies_of_equal_shaders, build_key_shares_the_owned_shader_allocation)review: none (read the full +95/-32 diff across device_x.rs, pso_async.rs, real.rs, and compute_build_key.rs: moves ShaderPool from Weak<[u8]> to Weak<Vec> so dropped blobs release their heap buffers immediately rather than waiting for the 8192-entry sweep, and carries one shared Arc<Vec> through Base, OwnedDesc (own_shader / own_stream), and ComputeBuildKey with fnv64+len lookup and full-byte equality checks; not tested: live retail title with ~83k pipelines)
performance: memory win for unbuilt/lazy pipelines sharing equal shaders, and immediate Vec buffer release when owners drop; adds an intern_shader_blob lookup/lock per shader in own_shader/own_stream
verdict: safe to merge
hardware / tool and model: NVIDIA GeForce RTX 4070 SUPER (32.0.16.2140), AMD Ryzen 7 7800X3D, Windows 11 Pro 26300, rustc 1.100.0, debug / Antigravity (Gemini 4 Hydrogen)
Imported from ivall/xcl. Originally posted by tiagonleal on 2026-11-30T13:46:38Z.
merge-check
base:
9dfbe3ea66head:
12713ec6a4merge: clean
build: cargo build --workspace -> ok (also
cargo build --release -p xcl)tests: cargo test --workspace --no-fail-fast -j 8 -- --test-threads=4 -> 2887 passed, 1 failed, 51 ignored; SKIPPED: 24 lines, the same as on the base; failing:
gpu::dxil::msaa_tests::gpu_direct_image_get_resinfo_d16, which fails the same way on the base alone (2885 passed, 1 failed, 51 ignored; #3513 fixes it). The two-pass cache e2e test that failed in the other check passed here. The new teststhe_pool_keeps_no_bytes_of_a_shader_without_ownersandowned_descriptions_share_the_copies_of_equal_shadersran and passed. Withown_shaderput back to a private copy per description (Arc::new(bytes.to_vec())atreal.rs:8402),owned_descriptions_share_the_copies_of_equal_shadersfails atreal.rs:8519("one copy of equal shaders"); file restored after.review: whole diff read (+95/-32, 4 files). Sharing is decided by a full byte compare:
intern_shader_blob(device_x.rs:389) looks up by(fnv64, len)and returns an existing copy only whenexisting.as_slice() == bytes(device_x.rs:396outside the lock,device_x.rs:404again under it), so two different shaders are never given one copy. On a key collision with both alive, the newer copy replaces the map entry (device_x.rs:412); the older one stays valid for its owners and only stops being shared. Locking is one global mutex,BASE_SHADERS(device_x.rs:374). The hash is taken outside it, the second compare and the insert under it, so two threads interning the same bytes end with one copy, and the extrato_vec(device_x.rs:400) is dropped. Lifetime: eachOwnedDescholds anArc<Vec<u8>>per stage and points the descriptor at theVecbuffer (real.rs:8402-8404, stream atreal.rs:8481). I found nomake_mut,get_mutor write through those pointers inhle/d3d12x, so a shared buffer never moves or changes while a description points at it. A failed or cancelled build only drops itsOwnedDesc; the bytes go with the lastArc, and the pool keeps a dead weak entry (theArcandVecheader, no shader bytes) until the sweep atdevice_x.rs:408-411. Cost: onefnv64over each shader at pipeline creation plus the global lock, and a full compare under the lock on a hit; not measured on its own. Overlap: #827 and #3091 changeown_shaderthe same way (the PR says so), and #2297 changes the signature ofown_shader; whichever lands second needs a rebase.performance:
scripts/smoke.ps1, 60 s of a retail title, release, after one warm-up run of the base: 1673 frames and 17222 MB peak commit against 1659 frames and 17322 MB on the base (warm-up: 1689, 17197 MB). No device removal, no crash. Pipelines at the end of the run, from the log: 60753 made (58011 graphics) on both, 2336 built against 2295; the built count rose run after run today as caches warmed, so I do not read that difference as this PR. The 100 MB commit difference is inside today's run-to-run spread, and 60 s in the menus does not show the copy savings the PR measures over 240 s. Not verified here: the title past its first world load, and the memory effect over a long run.verdict: safe to merge
hardware / tool and model: RTX 5070 Ti 16 GB (617.42, wave32), Ryzen 7 9800X3D, 32 GB, Windows 11 26300, rustc 1.100.0 / Claude Code (Claude Opus 5.5 ran the build, suite, tests and smoke, reviewed the diff against the merged source and wrote this)
Imported from ivall/xcl. Originally posted by Kalmarv on 2026-11-30T15:16:57Z.
Independent verification on RTX 5070 Ti (Windows 11, Ryzen 9 9950X, NVIDIA
nvgpucomp64.dll32.0.16.1074, DXC 1.9.2609), local merge of12713ec6a4f0f87320f7ee7206d64796ec69421fontomain9dfbe3ea6653a9c76ef3ea0d66187a4b5407483b:+95/-32across 4 files),cargo build --release -p xclsucceeded.--test-threads=1): 28 passed, 0 failed (hle::d3d12x::device_x::tests: 22/22 includingthe_pool_keeps_no_bytes_of_a_shader_without_owners;hle::d3d12x::real::compute_build_key::tests: 5/5 includingbuild_key_shares_the_owned_shader_allocation;owned_descriptions_share_the_copies_of_equal_shaders: 1/1).device_x.rs,pso_async.rs,real.rs, andcompute_build_key.rs. SwitchingShaderPoolfromWeak<[u8]>toWeak<Vec<u8>>ensures shader byte buffers are freed immediately when the last strongArcdrops instead of waiting for the 8192-entry sweep, andown_shader/own_stream/ComputeBuildKeycleanly share the sameArc<Vec<u8>>with full-byte equality verification.scripts/smoke.ps1, release):(0 device removals, 0 crashes.)
Not tested here: Full
cargo test --workspacelocally and multi-minute in-world peak-commit delta past the opening menus.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.
Imported from ivall/xcl. Originally posted by ClosetPie107 on 2026-11-30T16:03:11Z.
Test report for #3505 at
12713ec6a4f0f87320f7ee7206d64796ec69421f, against its merge-base withmain,cfb9753a, under Wine on AMD.Tested
experimental-11.0-20261112, stock vkd3d-protonmaster71cae091. Debug build,x86_64-pc-windows-gnu, under Wine. It wasn't run on Windows.cargo test --locked -p xcl --lib --target x86_64-pc-windows-gnu -- <filter>.--test-threads=1 <name>): both pass:owned_descriptions_share_the_copies_of_equal_shaders,the_pool_keeps_no_bytes_of_a_shader_without_owners. 2 passed, 0 failed.--test-threads=2, with--skip gpu::and these six:failed_restore_stops_before_importing_an_unbacked_window,grooming_leaves_a_window_under_1_gib_only_its_hole(both run out of memory here),write_buffer_immediate_on_open_existing_heap_visible_to_cpu,coherent_buffer_sanitizes_console_flags_and_state,serialize_root_signature_strips_console_flags_and_preserves_pc_flagsandexecute_indirect_reads_the_arguments_written_before_it. Under Wine each of the last four ends the process or makes RADV reject later submissions (#3067), so without them the suite reaches its summary:12713ec6: 1604 passed, 116 failed, 5 ignoredcfb9753a: 1602 passed, 116 failed, 5 ignoredlist_x::tests::timestamps_outside_unified_memory_land_after_the_queue, withE_INVALIDARGfrom a list creation (the cascade above). It passes 3 of 3 alone on #3505 and on the base. Most of the base's failures under Wine aremain's known ones on stock vkd3d-proton: list creation refused (E_INVALIDARG, #175 / #1701) and the tests after it (#3067).Not tested
gpu::tests in the suite runs-p xcl --lib)AI use: Claude Code (Claude Opus 5.5) ran the tests and wrote this report.
Imported from ivall/xcl. Originally posted by andresd-cerebras on 2026-11-30T21:49:33Z.
Code review location:
crates/xcl/src/hle/d3d12x/real.rs; line 8369Interning here into the global pool couples
own_stream_rejects_null_truncated_and_unreadable_streams(same 8 bytes44 58 42 43 01 02 03 04) withbase_pso_retains_shader_bytecode_after_title_buffer_changes, whose finalweak_vs.upgrade().is_none()assert can then fail when the two run in parallel. Distinct test bytes would fix it.Imported from ivall/xcl. Originally posted by andresd-cerebras on 2026-11-30T21:49:33Z.
Review: COMMENTED
Withdrawn.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T09:00:46Z.
merge-check
base:
7d86c5d2b7head:
12713ec6a4merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2898 passed, 0 failed, 51 ignored; SKIPPED: 28 (20 no wave64, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 1 no heap windows, 1 cannot disable the driver cache, 3 others; the same set as on main); failing: none
review: read the whole diff (device_x.rs, real.rs, real/compute_build_key.rs, pso_async.rs tests). Every background or lazy pipeline description now copies its shaders through
intern_shader_blob, with the pool,Baseand the compute build key holdingArc<Vec<u8>>. Findings: (1) it repeats the pending-recipe part of open #3091 (Arc<Vec<u8>>,own_shader/own_streamthrough a shared pool, theComputeBuildKeytype change), as the description says; a maintainer needs to pick one, and #3091 would then keep only its derived and base parts. (2)own_shader/own_stream(real.rs ~8288, ~8369) now runfnv64over every shader on the creation thread, plus a full byte compare on a hit under the globalBASE_SHADERSlock, andOwnedDesc::shaders_key(~8250-8253) hashes the same bytes twice more; reusing the interned hash would drop a pass. Not measured, as the description says. (3)the_pool_keeps_no_bytes_of_a_shader_without_owners(device_x.rs ~2112) depends on the process heap releasing a 4 MiB block's pages (it retries 8 times). Fine: descriptions, bases and build keys hold strong references until after the driver call returns and the pool holds only weak ones; nothing mutates the shared bytes and a hash hit is confirmed by comparing all bytes; theArc<Vec<u8>>change fixes bytes being kept alive through weak entries.performance: 60 s smoke of a retail title, main
7d86c5d2vs this merge (05778095): 1663 -> 1662 frames shown (99 %; last presents per 2 s: 60 60 60), peak commit 17153 -> 17289 MB, 0 device removals, 0 crashes.verdict: not yet: it duplicates the pending-recipe part of open #3091, and a maintainer has to pick one. Otherwise nothing blocks it: the suite passes, the smoke run is flat, and I found no bug in the diff
hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5
AI-written and posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T10:04:56Z.
Triage (#1607) – head
12713ecSame idea as #827:
own_shader/own_streamshare one copy of equal shader bytes. #827 adds its own weak pool inreal.rsand conflicts with main. This PR reuses main'sdevice_x::intern_shader_bloband also fixes the pool keepingArc<[u8]>bytes alive through its weak entries (nowArc<Vec<u8>>). #3091 does the same as part of a larger change.No problems found in the diff.
Recommendation: keep open.
AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T14:12:41Z.
@Prime1997 could you take a look at this one for review and merge? My automated review notes are above, if any.
Imported from ivall/xcl. Originally posted by stijn-boer on 2026-12-02T18:47:29Z.
merge-check
base:
c53e969602head:
12713ec6a4verdict: not yet: the focused checks passed, but the workspace and retail smoke ended early, and #3091 overlaps this implementation.
Windows / AMD RDNA4 (native D3D12) — shader blob ownership and compute build-key checks on
12713ecClean merge onto
mainatc53e969(merge commit5be27dac1344c30d84bc97bed4900a61aa7ef36d).git diff --checkwas clean.Setup
d3d12SDKLayers.dll, DXC 1.9.2609.5Tested
cargo build --workspacepassed.cargo test --workspace --no-fail-fast -- --test-threads=4 --show-outputexited 101 on both builds. The baseline table row is from a prior run of the same commit, machine, SDK, and command.SKIPPEDnoticesmainCounts are partial because two test processes aborted on each build.
main— none observed in comparable results.--test-threads=1 --show-output --nocapture. They cover graphics and stream sharing, release of the final byte owner, and compute build-key allocation sharing, equality, digest collision handling, and padding independence.uploads_start_from_each_subresources_statepassed.Shared failures and process aborts
fuzz_validate_and_gpu_1,fuzz_validate_and_gpu_3, andtwo_pass_driver_cache_reuses_both_passes_and_recovers_corrupt_blobsreported failures on both builds.gpu_compute_e2etest processes exited with0xc0000409on both builds.Retail smoke
Ran
scripts/smoke.ps1 -Game <local folder> -Seconds 60 -Xcl <debug binary>withXCL_UMA_DRIVER=mixedfor title hash2c508222.main0xc00004090xc00004090xc0000409The higher initial startup commit did not reproduce. These exits leave steady-state pool memory behavior unverified.
Diff review
The pool retains a weak reference to the vector owner, while strong owners retain the bytes. The added tests verified identical graphics and stream shader pointers and release after the last owner. Duplicate tracker #1607 identifies overlapping pending-recipe work in #3091.
Not tested
Remaining workspace tests after the aborts, retail performance, and long-running shader-pool memory under load.
AI use
Codex (GPT-6) merged and built the PR, ran the tests, compared the results with
main, reviewed the diff, and drafted this report.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.