Shaders: share owned bytecode across derived and pending pipelines #3091
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3091"
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 Prime1997 on 2026-11-28T03:35:21Z.
Derived pipelines and pending asynchronous pipeline recipes retain shared immutable copies of shader bytes. The title can reuse its input memory without corrupting derived pipelines, and large pending queues avoid retaining one copy of the same shader per recipe. The weak sharing index is bounded, compares full bytes on hash collisions, and releases the payload at the last strong owner.
This extends the existing #3091. The pending-recipe sharing behavior overlaps the proposal in #827 (credit: Cattn); this NVIDIA implementation reuses the bounded
Weak<Vec<u8>>index already present here. No separate duplicate shader-sharing PR is opened.Rebased onto main (2026-11-28).
nvidia-devwas merged intomainby #3203, so this PR now targetsmainand its branch was rebased ontomain765b2c5bfff6754e8c9886a73e188a86aca3c64c: head1dad60ed99b343428faff147592de955ae273dfa(was299c93f113c59eec315933c09432130569288f88).mainalready kept each recipe's shader bytes in anArc<[u8]>shared with its compute build key (cfbe0164a), which the second commit collided with. It is ported onto that code by hand: recipes and compute build keys now both hold this PR'sArc<Vec<u8>>from the weak index, socompute_build_key.rs, its tests and one test helper inpso_async.rschange type with it. That port needs a review. On the rebased head, on the same RTX 3060 Ti PC, debug profile:cargo check -p xcl --all-targetsexited 0, andcargo test -p xcl --lib -- --test-threads=4 a_thousand_pending_graphics_recipes_keep_two_unique_shader_payloads async_recipes_share_shader_bytes_and_keep_them_until_the_last_owner base_shader_bytes_survive_title_memory_reuse base_shader_copy_rejects_unreadable_nonempty_stages base_shader_sharing_checks_collisions_and_bounds_weak_entries build_key_shares_the_owned_shader_allocation concurrent_bases_publish_one_shader_copy derived_base_owns_shader_bytes_after_parent_is_forgotten derived_pipeline_patches_land_on_the_desc_parts gpu_derived_pipeline_survives_original_shader_reuse many_bases_share_shader_payload compute_build_key shaders_key owned_desc owned_shader in_flight base_shader mesh_stream derived depth_biasgave 40 passed, 0 failed, 0 ignored, no SKIPPED. The whole suite and the paired title runs have not been rerun on this head; every other result below is from the earlier head. The rebase and its conflict resolution were done with Claude Code.What is in it
Tested
5d0833553c68d2afa327c913cd9a22f17ec6f45esource plus patch SHA2561ea04e88f32675f0c5a4a64eb368479567ae9c1c79d4e7ab7da44ddc3a7c6ac5, not an individual-head full suite.cargo test --locked -p xcl --lib --target-dir <isolated target> -- --exact --test-threads=4 --nocapturefollowed by the 11 exact test names in those groups; the exact command and outputs are retained locally.Regression run
Not run for refreshed head
299c93f113c59eec315933c09432130569288f88. Previous-head results remain historical. The user requested a release candidate and interactive log monitoring, explicitly waiving further local shader/memory validation. This is not a passing GPU or gameplay result.Not tested
AI use
Codex (GPT-6) implemented the ownership repair, adapted #827's sharing concept to the existing bounded index, reviewed source and ran the CPU-only checks described above.
Optional temporary contributor/testing coordination: https://discord.gg/6B4TykyC4W
Imported from ivall/xcl. Originally posted by thehollowedone on 2026-11-28T03:54:05Z.
Independent Windows/NVIDIA check of #3091 head
64aa28f0, based onnvidia-deve48e74ca.The nine named shader-ownership fixtures pass on the RTX 3080 Ti (driver 621.35), including the native derived-pipeline check: 9 passed, 0 failed, 0 ignored, no reported skips. I ran the
base_shaderand GPU fixtures withcargo test --offline --locked -j 4 -p xcl --lib <filter> -- --test-threads=1, and the remaining named fixtures individually from the resulting lib test binary. Windows 11 build 26300, Ryzen 7 9800X3D, rustc 1.99.1 MSVC, DXC 1.8.2502.11.The current-head full workspace run,
cargo test --offline --locked -j 4 --workspace --no-fail-fast -- --test-threads=4, finished 1,908 passed, 1 failed, 48 ignored across 40 targets, with 26 explicitSKIPPEDnotices. The sole failure wasconsole_mesh_caches_hlsl_compute_pass_in_memory_and_on_disk(DXIL not compiled yet). I reran that exact test on the unchangede48e74caparent; it failed there too, 0/1/0, with the same error. I did not run a retail smoke pair.One bounded performance issue remains in
share_base_shader: once 65,536 distinct shader keys remain live, every new key scans the entire weak index under its mutex, is not admitted, and cannot share a second request for the same bytes. This is a source-level scaling concern, not a measured retail bottleneck. A small test-only regression failed on the unchanged head, 0/1/0, because two requests for the same overflow stage returned distinct allocations. Admitting the new weak entry with bounded FIFO/clock eviction would keep the index capped and preserve existingArcowners without a full scan on each saturated miss. Please cover repeated overflow keys and concurrent insertion when changing the admission policy.Failing test-only regression
AI use: Codex (GPT-6.2 Sol) ran the tests and checked the finding; Codex (GPT-6.2 Astra) independently traced the index path.
Imported from ivall/xcl. Originally posted by andrewDoing on 2026-11-28T03:56:32Z.
I tested the proposed bounded FIFO approach independently against head
64aa28f0in a standalone Rust harness using the upstream interning function and a local candidate.With all 65,536 index entries live, 16 threads requested four new payloads. The stock implementation returned distinct allocations for equal requests; the candidate shared one allocation per new payload, kept the index at its cap, and preserved the bytes held by every original owner. The candidate passed the existing collision and concurrency controls and the saturated case in 20/20 fresh processes.
The bound is on index entries, not total live shader memory: after a key is evicted, a later request can create a second copy while an older owner still retains the first. This is a synthetic candidate test; retail memory and timing were not measured.
AI use: OpenAI Codex with GPT-6.2 Astra built and ran the checks; Codex reviewed and prepared this report.
Imported from ivall/xcl. Originally posted by DarkPanda69 on 2026-11-28T04:04:00Z.
Update for head
299c93f(rebased onnvidia-dev54225f5, plus "share pending pipeline shader payloads"): samedevice_x::tests::command against the new merge-base54225f5, 18 → 25 passed, 0 failed, no SKIPPED on both cards, the same seven changes as before. The GPU test again loggedS6 native adapter=AMD Radeon RX 9070 XT …/… NVIDIA GeForce RTX 3060 …. The commit's two new tests,a_thousand_pending_graphics_recipes_keep_two_unique_shader_payloadsandasync_recipes_share_shader_bytes_and_keep_them_until_the_last_owner, pass too, run once withXCL_ADAPTER=Radeon(cargo test -p xcl --lib -- async_recipes_share_shader_bytes a_thousand_pending_graphics_recipes, 2 passed).AMD run (listed as untested), with an RTX 3060 in the same PC: the seven new tests pass on both, and nothing else in
device_xchanges.Tested: at the PR head
64aa28fagainst its merge-base withnvidia-dev,e48e74c(the diff doesn't apply as a patch on today'snvidia-dev01b94f5). Debug, Rust 1.100.0, Windows 11 Pro 26200, Ryzen 7 5800X, card picked withXCL_ADAPTER; RX 9070 XT (RDNA4) driver 32.0.32029.2010, RTX 3060 driver 32.0.16.1088.cargo test -p xcl --lib -- hle::d3d12x::device_x::tests:: --test-threads=1 --nocapture: merge-base 18 passed, 0 failed; PR 25 passed, 0 failed, 0 ignored, no SKIPPED, on both cards.gpu_derived_pipeline_survives_original_shader_reuseloggedS6 native adapter=AMD Radeon RX 9070 XT (16253 MiB VRAM); validation=PSO creation; dispatches=0, and the same withNVIDIA GeForce RTX 3060.Not tested: the whole suite, a title, Intel.
AI use: Claude Code (Claude Opus 5.5) ran the tests on this machine and wrote this report.
Imported from ivall/xcl. Originally posted by andrewDoing on 2026-11-28T04:12:01Z.
I extended the existing pipeline-chain fixture with a native GPU draw on RTX 5070 / NVIDIA 616.92 at head
64aa28f0(test-only overlay). After overwriting the original VS/PS bytecode, releasing the base, creating the grandchild, and releasing the child, I bound the grandchild for a scissored draw.After a bounded completion fence, readback showed exactly eight expected red pixels in the left two columns and eight untouched blue-clear pixels in the right two. The device remained healthy and the focused test passed with no skips. The existing fallback counters were checked at base, child, and grandchild creation. The fixture intentionally kept the root signature alive.
This extends the creation-only coverage to one graphics draw after those shader-bytecode and ancestor lifetimes. It does not establish general resource lifetime, retail rendering, or memory savings.
AI use: OpenAI Codex with GPT-6.2 Astra built and ran the fixture; Codex reviewed and prepared this report.
Imported from ivall/xcl. Originally posted by thehollowedone on 2026-11-28T04:26:45Z.
Follow-up to my saturated-index regression on head
64aa28f0. I implemented a local candidate that keeps a bounded FIFO of weak index keys. A new key evicts one indexed key at capacity instead of scanning all 65,536 entries; existingArcowners keep their payloads. Same-key hash collisions retain their queue position and replace only the weak index entry. This complements andrewDoing's independent saturation check.The previously posted repeated-overflow fixture failed on the unchanged head (0/1/0). With this candidate,
cargo test --offline --locked -j 4 -p xcl --lib hle::d3d12x::device_x::tests -- --test-threads=1passed 27/0/0, including the native RTX 3080 Ti fixture, existing collision/concurrency tests, repeated overflow and a new eight-thread saturated insertion.git diff --checkpassed. Windows 11 build 26300, RTX 3080 Ti / 621.35, Ryzen 7 9800X3D, rustc 1.99.1 MSVC. This candidate has not had a full workspace suite or paired smoke; the exact head's earlier full-suite result is in my linked report.Apply-ready candidate diff
AI use: Codex (GPT-6.2 Sol) wrote the candidate, reviewed the bounded index and ownership path, and ran the stated tests.
Imported from ivall/xcl. Originally posted by thehollowedone on 2026-11-28T19:25:49Z.
Independent Windows/NVIDIA check of #3091 head
299c93f1, based onnvidia-dev54225f58. Windows 11 build 26300, RTX 3080 Ti / 621.35, Ryzen 7 9800X3D, rustc 1.99.1 MSVC.cargo test --offline --locked -j 4 -p xcl --lib hle::d3d12x::device_x::tests -- --test-threads=1 --nocapture: 25 passed, 0 failed, 0 ignored, no reported skips. The native derived-pipeline fixture identified the RTX 3080 Ti; it validates PSO creation, not a draw.The full
cargo test --offline --locked -j 4 --workspace --no-fail-fast -- --test-threads=4did not pass: Cargo reported-p xcl --libas the failed target. A separate run of that library target ended abnormally with0x07C10003before its test summary. Its last diagnostic was that a mixed driver-heap window could not be restored afterCreateHeapreturnedE_OUTOFMEMORY, followed by the intentional fail-stop. The same failure on plainnvidia-devand the test-isolation follow-up are already documented. This run cannot supply a complete library count or establish that the whole PR suite passes. The library rerun also logged the pre-existingconsole_mesh_caches_hlsl_compute_pass_in_memory_and_on_diskfailure (DXIL not compiled yet), which I have reproduced on an unchanged base in earlier checks.I did not run a paired title smoke, measure retail memory savings, or test AMD/Intel on this head. AI use: Codex (GPT-6.2 Sol) built and ran these checks and reviewed the results.
Imported from ivall/xcl. Originally posted by andrewDoing on 2026-11-28T19:34:46Z.
At
299c93f1on RTX 5070 / NVIDIA 616.92, I checked whether the new graphics recipe could create a working native PSO after it became the last owner of both shader payloads.A hook in the test captured a valid native DXIL descriptor with production
own_graphics. The recipe's vertex and pixel shader byte pointers both matched the corresponding owned payloads in the base. I overwrote the title's original bytecode, derived the child and grandchild, dropped the title buffers, and released all three native pipelines. Immediately before creating the delayed pipeline, each shader payload had exactly one strong owner, the recipe. The root signature stayed alive.The recipe preserved a red-only write mask, distinct from the grandchild's all-channel mask. Both drew a red triangle over a blue-cleared 4×4 target, scissored to the left two columns:
All 16 pixels matched after a completion fence in each fresh process, and the device remained healthy. This verifies native use of the stored graphics descriptor and the shared shader lifetime. The fixture invoked deferred creation directly, so it does not exercise asynchronous worker scheduling or measure memory savings.
AI use: OpenAI Codex adapted the fixture, ran the controls and prepared the report.
Imported from ivall/xcl. Originally posted by bmjask on 2026-11-28T22:04:22Z.
Review: COMMENTED
Critical-review result: I found no concrete ownership or deduplication defect. Keeping weak entries in the index does not affect correctness because byte equality is checked and live users retain their own
Arc; replacement affects reuse only.Please update the failing PR-description gate and preserve the measured memory/startup evidence when this is promoted from
nvidia-dev.Reviewed at
1dad60ed99with Codex (GPT-5).Imported from ivall/xcl. Originally posted by thehollowedone on 2026-11-28T22:58:27Z.
CI follow-up for #3091 head
1dad60ed: the Windows job first fails inbuilder_deduplicates_names_and_atomically_replaces_outputwith 4 entries instead of 2. Three later pipeline-library/warm-library failures arePoisonErrorafter that test poisons their shared lock.pipeline_library.rshas the same Git blob (470de7f) on this head and itsmainbase.PR #3183 addresses the shared-test-state race: its bounded WARP overlap check reproduced 4/2 before the lock and 2/2 after it. Its Windows build/test and description checks pass. That existing test-isolation PR is the relevant CI unblocker; #3091 should be rerun after it lands.
The separate PR-description job rejects the historical smoke results: Regression run needs generated
xcl-smokeblocks from a clean commit ofmainand this PR's exact current head, using the same title and duration. Put both blocks in the PR description, and rerun the head block after every push. If #3091 is rebased after #3183 lands, use that final head for the paired run. This is a CI/source review, not a new local title run.AI use: Codex (GPT-6.2 Sol) inspected both exact CI failures, compared the source blobs, and drafted this note.
Imported from ivall/xcl. Originally posted by vasanex on 2026-11-29T04:23:17Z.
How this was run: the suite ran once on the 11 of your PRs that build on this base, merged together (#3047 #3048 #3049 #3091 #3092 #3103 #3104 #3105 #3107 #3123 #3125; a local tree, only #3125 needed a resolution in README and the
sparse.rstest module); the base alone gave 2608 passed, 0 failed, 49 ignored with the same 27SKIPPEDlines (21 no wave64, 3 refused per-lane f16/f32 forms, 2 heap windows opt-in, 1 driver cache needs Developer Mode). This PR alone was merged onto the base, built (cargo build --workspace, then release), its modules' lib tests run (debug), and smoke-run once for 60 s (scripts/smoke.ps1, retail title, front end,XCL_PREPARE=0). The smoke numbers are for my local merged tree, not a clean-head block for the description. Load runs: 150 s, the save loaded with A presses,XCL_PREPARE=0, after one warm-up, one run per arm; on this 10 GB card main is over the video memory budget while loading, and presents stop after 94-125 s in every arm.AI use: Claude Code (Claude Opus 5.5 and Claude Fable 5.2) ran the builds, tests and title runs, reviewed the diff and wrote this; the code points cited were checked against the merged tree.
Imported from ivall/xcl. Originally posted by Prime1997 on 2026-11-29T11:18:26Z.
merge-check
base:
d8bd9a3820head:
1dad60ed99merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2624 passed, 0 failed, 49 ignored, with three uma_driver tests skipped (on this PC's driver they can end the library test process; run alone on the merged tree: 3 passed, 0 failed); SKIPPED: 28 lines (21 no wave64 on this wave32 card, 3 wave32 per-lane forms refused, 2 heap windows opt-in, 1 no dxc.exe, 1 driver cache needs Developer Mode); failing: none
review: the whole diff was read (device_x.rs, real.rs, pso_async.rs, compute_build_key.rs, README). (1) Unchanged at this head: once the weak index holds 65,536 live entries, every miss in share_base_shader runs m.retain over the whole map under the global INDEX mutex, and the new key is not admitted, so equal bytes stop being shared (thehollowedone's saturated-overflow test from 2026-11-28 still applies). This PR sends every asynchronous compute, graphics and stream recipe through shared_shader_bytes (real.rs own_shader / own_stream), as well as every graphics base (note_base), so the index sits on the title's pipeline-creation path for every pipeline. This retail title makes about 84,000 lazy pipelines by 400 s on main (420 s runs on this PC today); how many distinct shader payloads that is was not counted, so whether the cap is reached here is open. (2) note_base now keeps a copy of each graphics PSO's shader bytes for the PSO's life (shared when identical); not measured in a world. (3) Ownership and lifetimes read correctly: descriptors point at the owned bytes, the index holds only weak references, and hash collisions are compared byte for byte. No lifetime defect found.
performance: 60 s scripts/smoke.ps1 (retail title, front end, no input), two runs each: merged tree 272cecb3 1092 and 1454 frames, peak commit 14905 and 15287 MB; base
d8bd9a381424 and 1392 frames, 15285 and 15364 MB; 0 device removals and 0 crashes in all four. The first merged run's low count did not repeat. The title's world is not reached on main on this 8 GB card (it stops on the loading screen), so the retained shader bytes and the saturated scan were not measured where they would matter.verdict: not yet: the saturated-index full scan under the global lock is still unanswered, and with this PR it is on every pipeline creation; the retained memory is unmeasured in a world
hardware / tool and model: RTX 3060 Ti 8 GB (driver 32.0.16.1714), Intel Core i5-10400, Windows 11 Pro 26200 / Claude Code (model not named: this session cannot tell which model served each turn)
This check was run from the PR author's account (Prime1997), so it does not count as one of #3041's two independent checks. Suite in debug; smokes on release builds of the exact merged and base commits, with a copied profile and shader cache.
Generated by Claude Code
Imported from ivall/xcl. Originally posted by bmjask on 2026-11-29T22:44:25Z.
Review: COMMENTED
Critical review of current head
1dad60ed. I found no concrete ownership defect in the shared immutable shader bytes: live pipelines retain strongArcs and weak-index replacement affects reuse, not correctness. The current branch is nevertheless conflicted with main, so the hand-ported recipe and compute-build-key paths need a fresh rebase plus targeted tests of title memory reuse during pending builds and derived PSO creation. Please also retain the measured memory/startup evidence after rebasing. This updates my prior code review; no local Windows run.Imported from ivall/xcl. Originally posted by thehollowedone on 2026-12-01T05:17:59Z.
Source overlap check for #3091 head
1dad60edand #3505 head12713ec6: main commit7e242379already makes tracked base graphics pipelines own and share their shader bytes for derived/depth-bias use. #3505 then reuses that pool for pending compute, graphics and stream descriptions, and carriesArc<Vec<u8>>throughComputeBuildKey. Those production ownership and sharing changes substantially overlap #3091; landing both unchanged would require reconciling two pool implementations and the sameOwnedDesctype change.#3091 still has distinct work worth preserving: its test exercises a 1,024-recipe backlog and sharing across compute, graphics and stream forms; its derived-pipeline chain tests go further than #3505's new tests. It also rejects a nonempty shader stage with a null pointer while capturing a base, whereas current main's
stage_blobstreats that case as absent. Please keep any of those cases that are not already covered after rebasing, with their focused regressions. The previous saturation report also remains relevant to #3091's own bounded index if that index survives the rebase.If #3505 lands first, a smaller follow-up from #3091's distinct validation and tests would avoid duplicating its production pool. This is a diff comparison, not a build, runtime measurement or merge check. AI use: OpenAI Codex (GPT-6.2 Sol) compared both current PR diffs and the existing main ownership path.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T05:39:46Z.
Review (head
1dad60ed, diff read, not a merge-check; it conflicts with main andPR descriptionfails, so not built or run):7e242379("D3D12.X: base pipelines keep their own copy of their shaders, shared by content", #3292) already makes base pipelines own their shader bytes, shared by content (intern_shader_blob,device_x.rs~386); that's the conflict in device_x.rs and README.md. The first commit should be dropped, keeping only the sharing between pending recipes.Arc<Vec<u8>>point is valid on main: main'sWeak<[u8]>index (~366) keeps a dead shader's bytes allocated until a sweep that only runs at 8192+ entries (~405-407). Freeing at the last owner is worth its own PR on main's pool.share_base_shader, once all 65,536 entries are live, every new shader runs a fullretainunder the global lock, and every recipe now hashes each shader stage in full (fnv64) on the title's creation thread. That CPU cost isn't measured, and the memory saving is only measured on a synthetic set of 1,024 identical recipes.PR descriptionfails), only 40 targeted tests ran on this head, and AI use doesn't name the model used for the Claude Code rebase. The fourpipeline_library/warm_libraryCI failures also appear on unrelated PRs (the test race since fixed on main).Fine: the bytes handed to the driver stay valid while the descriptor and build key hold the
Arc, hash collisions are compared byte for byte, and the GPU test usesskip_test.AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
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.