D3D12.X: base pipelines keep their own copy of their shaders, shared by content #3292

Merged
Foniass merged 1 commit from upstream-pr/3292 into main 2026-11-29 12:21:04 +00:00
Foniass commented 2026-11-29 06:18:48 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-11-29T06:18:48Z.


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 48cf7139 (its device_x part) and 60345c97 (the shared
pool), raylitebull. The other parts of 48cf7139 are separate PRs.

What is in it

  • crates/xcl/src/hle/d3d12x/device_x.rs: Base::shader_blobs (Arc<[u8]> per stage), the interning pool BASE_SHADERS, desc_with_owned_shaders for RSSetDepthBiasX and CreateDerivedPipelineStateX; test base_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

  • NVIDIA GeForce RTX 5070 Ti (driver 32.0.16.2114), AMD Ryzen 7 7800X3D, Windows 11 build 26300, Rust 1.100.0 (stable-x86_64-pc-windows-msvc), debug tests, release smoke
  • cargo test --workspace --no-fail-fast -- --test-threads=4 on 7e242379: 2605 passed, 4 failed, 49 ignored. The 4 failures are gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_0..3 (E_OUTOFMEMORY from CreateComputePipelineState, 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 all no wave64.
  • Retail title: 60 s smoke run below (no device removal or crash, frames and peak commit within the limits).

Regression run

main:

xcl-smoke v1
commit: b10cc4c6766adc947c2054ada4a2af98be15108d
gpu: NVIDIA GeForce RTX 5070 Ti
title: 3cb1d8e0
seconds: 60
exit: 0x0
frames shown: 1565 (PresentX 1565)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 16026 MB

this PR:

xcl-smoke v1
commit: 7e2423798475fb4bbd01f5ab382c463eaeb550b0
gpu: NVIDIA GeForce RTX 5070 Ti
title: 3cb1d8e0
seconds: 60
exit: 0x0
frames shown: 1667 (PresentX 1667)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 16768 MB

Not tested

  • a title that derives pipelines after freeing its shader buffers: the smoke title's runs never logged the old "shaders ... are gone" warning, so this path is covered by the unit test only
  • memory of the pool on a title with many pipelines (not measured)
  • AMD GPUs

AI use

  • Claude Code with Claude Opus 5.5: ported this part of the amd-dev commit named above to main, wrote the commit message and this description, ran the tests and the smoke run.

🤖 Generated with Claude Code

<!-- greyfinch-sync:ivall/xcl:issue:5548210614 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3292). Originally posted by [Foniass](https://github.com/Foniass) on 2026-11-29T06:18:48Z. --- 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 48cf7139 (its device_x part) and 60345c97 (the shared pool), raylitebull. The other parts of 48cf7139 are separate PRs. **What is in it** - `crates/xcl/src/hle/d3d12x/device_x.rs`: `Base::shader_blobs` (`Arc<[u8]>` per stage), the interning pool `BASE_SHADERS`, `desc_with_owned_shaders` for RSSetDepthBiasX and CreateDerivedPipelineStateX; test `base_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** - NVIDIA GeForce RTX 5070 Ti (driver 32.0.16.2114), AMD Ryzen 7 7800X3D, Windows 11 build 26300, Rust 1.100.0 (stable-x86_64-pc-windows-msvc), debug tests, release smoke - `cargo test --workspace --no-fail-fast -- --test-threads=4` on 7e242379: 2605 passed, 4 failed, 49 ignored. The 4 failures are `gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_0..3` (`E_OUTOFMEMORY` from `CreateComputePipelineState`, 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 all `no wave64`. - Retail title: 60 s smoke run below (no device removal or crash, frames and peak commit within the limits). **Regression run** main: ``` xcl-smoke v1 commit: b10cc4c6766adc947c2054ada4a2af98be15108d gpu: NVIDIA GeForce RTX 5070 Ti title: 3cb1d8e0 seconds: 60 exit: 0x0 frames shown: 1565 (PresentX 1565) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 16026 MB ``` this PR: ``` xcl-smoke v1 commit: 7e2423798475fb4bbd01f5ab382c463eaeb550b0 gpu: NVIDIA GeForce RTX 5070 Ti title: 3cb1d8e0 seconds: 60 exit: 0x0 frames shown: 1667 (PresentX 1667) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 16768 MB ``` **Not tested** - a title that derives pipelines after freeing its shader buffers: the smoke title's runs never logged the old "shaders ... are gone" warning, so this path is covered by the unit test only - memory of the pool on a title with many pipelines (not measured) - AMD GPUs **AI use** - Claude Code with Claude Opus 5.5: ported this part of the amd-dev commit named above to main, wrote the commit message and this description, ran the tests and the smoke run. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
andrewDoing commented 2026-11-29 06:36:09 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by andrewDoing on 2026-11-29T06:36:09Z.


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 (7e242379) and #3091 (1dad60ed) 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:

Helper With strong owners After last owner After forcing the next sweep
This PR, Arc<[u8]> 4,194,560 B 4,194,560 B 0 B
#3091, Arc<Vec> 4,194,304 B 0 B already released

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.

<!-- greyfinch-sync:ivall/xcl:comment:7251954945 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3292#issuecomment-7251954945). Originally posted by [andrewDoing](https://github.com/andrewDoing) on 2026-11-29T06:36:09Z. --- 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 (7e242379) and #3091 (1dad60ed) 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: | Helper | With strong owners | After last owner | After forcing the next sweep | |---|---:|---:|---:| | This PR, Arc<[u8]> | 4,194,560 B | 4,194,560 B | 0 B | | #3091, Arc<Vec<u8>> | 4,194,304 B | 0 B | already released | 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.
Kalmarv commented 2026-11-29 07:54:01 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Kalmarv on 2026-11-29T07:54:01Z.


merge-check
base: fa204595
head: 7e242379
verdict: safe to merge

Merged cleanly onto origin/main (fa204595) in a 5-PR batch (#3288, #3290, #3292, #3294, #3300) and verified on NVIDIA GeForce RTX 5070 Ti with DXC 1.9.2609.5:

  • Base pipeline shader retention + Arc sharing verified across hle::d3d12x:: and e2e debug-layer runs.
  • gpu::: 853 passed, 0 failed, 24 ignored (10.45 s, including fuzz_validate_and_gpu_0..3).
  • hle::d3d12x:: (--test-threads=1, skipping 2 known main #3187 uma_driver mixed-window tests): 1144 passed, 0 failed, 3 ignored (30.21 s).
  • Remaining xcl --lib (--test-threads=1): 0 failed.
  • -p xcl --test e2e (after rebuilding xcl-testtitle): 5 passed, 0 failed (including D3D12 debug layer + DRED).
  • GitHub CI (Build and test (Windows, no GPU) and PR description): green.
<!-- greyfinch-sync:ivall/xcl:comment:7252759827 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3292#issuecomment-7252759827). Originally posted by [Kalmarv](https://github.com/Kalmarv) on 2026-11-29T07:54:01Z. --- merge-check base: fa204595 head: 7e242379 verdict: safe to merge Merged cleanly onto `origin/main` (`fa204595`) in a 5-PR batch (`#3288`, `#3290`, `#3292`, `#3294`, `#3300`) and verified on NVIDIA GeForce RTX 5070 Ti with DXC 1.9.2609.5: - Base pipeline shader retention + Arc sharing verified across `hle::d3d12x::` and `e2e` debug-layer runs. - `gpu::`: 853 passed, 0 failed, 24 ignored (10.45 s, including `fuzz_validate_and_gpu_0..3`). - `hle::d3d12x::` (`--test-threads=1`, skipping 2 known `main` `#3187` `uma_driver` mixed-window tests): 1144 passed, 0 failed, 3 ignored (30.21 s). - Remaining `xcl --lib` (`--test-threads=1`): 0 failed. - `-p xcl --test e2e` (after rebuilding `xcl-testtitle`): 5 passed, 0 failed (including D3D12 debug layer + DRED). - GitHub CI (`Build and test (Windows, no GPU)` and `PR description`): green.
Aniseto commented 2026-11-29 08:42:09 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Aniseto on 2026-11-29T08:42:09Z.


Ran the base-pipeline shader retention test at 7e242379 on an NVIDIA Blackwell desktop part with an updated driver:

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.

XCL_ADAPTER=NVIDIA cargo test -p xcl --lib base_pso_retains_shader_bytecode_after_title_buffer_changes -- --test-threads=1
1 passed; 0 failed; 0 ignored; 0 measured; 2498 filtered out      (exit 0)

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.

<!-- greyfinch-sync:ivall/xcl:comment:7253275912 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3292#issuecomment-7253275912). Originally posted by [Aniseto](https://github.com/Aniseto) on 2026-11-29T08:42:09Z. --- Ran the base-pipeline shader retention test at `7e242379` on an NVIDIA Blackwell desktop part with an updated driver: 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. ``` XCL_ADAPTER=NVIDIA cargo test -p xcl --lib base_pso_retains_shader_bytecode_after_title_buffer_changes -- --test-threads=1 1 passed; 0 failed; 0 ignored; 0 measured; 2498 filtered out (exit 0) ``` 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.
throny commented 2026-11-29 09:21:19 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by throny on 2026-11-29T09:21:19Z.


merge-check claim
head: 7e24237984

<!-- greyfinch-sync:ivall/xcl:comment:7253707024 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3292#issuecomment-7253707024). Originally posted by [throny](https://github.com/throny) on 2026-11-29T09:21:19Z. --- merge-check claim head: 7e2423798475fb4bbd01f5ab382c463eaeb550b0
throny commented 2026-11-29 09:36:10 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by throny on 2026-11-29T09:36:10Z.


merge-check
base: d8bd9a38
head: 7e24237984
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2619 passed, 0 failed, 49 ignored (27 SKIPPED lines). Base alone at d8bd9a38: 2618 passed, 0 failed, 49 ignored.
review: no finding. A base pipeline now holds its own copies of its shaders (shared between pipelines through a pool of weak references) instead of hashes, the stored description no longer holds the title's shader pointers, and they are pointed at the copies when a pipeline is derived. Lifetimes are sound from reading: the base owns the bytes, the description with the copies is used only while the base is alive, and the background build path copies the shaders itself. Deriving a pipeline after the title freed its shaders now works where main returned E_FAIL, which is the intent. Cost: one copy of each distinct shader stays in memory as long as a graphics pipeline using it lives. The test checks the sharing, the bytes and the release after the last pipeline; it does not drive the two derive functions themselves.
performance: not measured (memory: see the cost above).
verdict: safe to merge
hardware / tool and model: RTX 4080 16 GB (621.40), i9-12900K, Windows 11 26300, Rust 1.100.0, debug. Claude Code; merge, build and suite run by Claude Fable 5.2, diff review by Claude Opus 5.5 (every hunk read; nothing run on the GPU beyond the suite).

<!-- greyfinch-sync:ivall/xcl:comment:7253872487 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3292#issuecomment-7253872487). Originally posted by [throny](https://github.com/throny) on 2026-11-29T09:36:10Z. --- merge-check base: d8bd9a38 head: 7e2423798475fb4bbd01f5ab382c463eaeb550b0 merge: clean build: cargo build --workspace -> ok tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2619 passed, 0 failed, 49 ignored (27 SKIPPED lines). Base alone at d8bd9a38: 2618 passed, 0 failed, 49 ignored. review: no finding. A base pipeline now holds its own copies of its shaders (shared between pipelines through a pool of weak references) instead of hashes, the stored description no longer holds the title's shader pointers, and they are pointed at the copies when a pipeline is derived. Lifetimes are sound from reading: the base owns the bytes, the description with the copies is used only while the base is alive, and the background build path copies the shaders itself. Deriving a pipeline after the title freed its shaders now works where main returned E_FAIL, which is the intent. Cost: one copy of each distinct shader stays in memory as long as a graphics pipeline using it lives. The test checks the sharing, the bytes and the release after the last pipeline; it does not drive the two derive functions themselves. performance: not measured (memory: see the cost above). verdict: safe to merge hardware / tool and model: RTX 4080 16 GB (621.40), i9-12900K, Windows 11 26300, Rust 1.100.0, debug. Claude Code; merge, build and suite run by Claude Fable 5.2, diff review by Claude Opus 5.5 (every hunk read; nothing run on the GPU beyond the suite).
crosettiremi commented 2026-11-29 19:02:56 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by crosettiremi on 2026-11-29T19:02:56Z.


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 fa204595 and d8bd9a38, 4 and 16 UMA windows, cold and warm caches, runs that reach the first world frame. So this card and title give no before/after for it. I have not run this PR's head. Since our runs end at a job commit limit, I would be interested in what the kept copies cost in commit on a full retail load if anyone measured it.

AI use: Claude Code (Claude Fable 5.2) searched the logs and wrote this.

<!-- greyfinch-sync:ivall/xcl:comment:7260964902 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3292#issuecomment-7260964902). Originally posted by [crosettiremi](https://github.com/crosettiremi) on 2026-11-29T19:02:56Z. --- 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 `fa204595` and `d8bd9a38`, 4 and 16 UMA windows, cold and warm caches, runs that reach the first world frame. So this card and title give no before/after for it. I have not run this PR's head. Since our runs end at a job commit limit, I would be interested in what the kept copies cost in commit on a full retail load if anyone measured it. AI use: Claude Code (Claude Fable 5.2) searched the logs and wrote this.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
xcl-dev/xcl!3292
No description provided.