Skip to content

Shaders: share owned bytecode across derived and pending pipelines - #3091

Open
Prime1997 wants to merge 2 commits into
xcl-dev:mainfrom
Prime1997:codex/gdkx-base-shader-ownership
Open

Prime1997 wants to merge 2 commits into
xcl-dev:mainfrom
Prime1997:codex/gdkx-base-shader-ownership

Conversation

@Prime1997

@Prime1997 Prime1997 commented Nov 28, 2026 •

Copy link
Copy Markdown
Collaborator

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-dev was merged into main by #3203, so this PR now targets main and its branch was rebased onto main 765b2c5bfff6754e8c9886a73e188a86aca3c64c: head 1dad60ed99b343428faff147592de955ae273dfa (was 299c93f113c59eec315933c09432130569288f88). main already kept each recipe's shader bytes in an Arc<[u8]> shared with its compute build key (cfbe016), which the second commit collided with. It is ported onto that code by hand: recipes and compute build keys now both hold this PR's Arc<Vec<u8>> from the weak index, so compute_build_key.rs, its tests and one test helper in pso_async.rs change 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-targets exited 0, and cargo 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_bias gave 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

  • Retain owned Base shader bytes across creation, derivation and depth-bias fallback.
  • Share live payloads between Base and asynchronous compute, graphics and stream descriptions, preserving shader keys and stream validation.
  • Ownership/lifetime, collision, index-bound, concurrency and synthetic backlog fixtures, plus README behavior notes.

Tested

  • Before the requested pause in further validation, 11 exact CPU-only tests passed, 0 failed, 0 ignored and 0 explicit skips on Windows x64. This was the combined 5d0833553c68d2afa327c913cd9a22f17ec6f45e source plus patch SHA256 1ea04e88f32675f0c5a4a64eb368479567ae9c1c79d4e7ab7da44ddc3a7c6ac5, not an individual-head full suite.
  • Tests covered async recipe ownership, stable shader keys, unreadable streams, Base lifetimes, collision/bound checks and concurrent sharing. Command: cargo test --locked -p xcl --lib --target-dir <isolated target> -- --exact --test-threads=4 --nocapture followed by the 11 exact test names in those groups; the exact command and outputs are retained locally.
  • The 1,024-recipe fixture retained 2 unique shader payloads totaling 81,920 bytes; copying both payloads into each recipe would require 83,886,080 bytes. This measures unique payload storage only, excluding descriptors, index/Arc overhead, process commit and VRAM.

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

  • Refreshed individual-head build/full suite and paired current-main/title regression.
  • Actual game memory savings, frame-time impact, hardware GPU regressions and AMD.

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

@Prime1997
Prime1997 force-pushed the codex/gdkx-base-shader-ownership branch from dcb2004 to 64aa28f Compare November 28, 2026 03:38
@Prime1997
Prime1997 marked this pull request as ready for review November 28, 2026 03:40
@thehollowedone

Copy link
Copy Markdown
Contributor

Independent Windows/NVIDIA check of #3091 head 64aa28f0, based on nvidia-dev e48e74ca.

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_shader and GPU fixtures with cargo 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 explicit SKIPPED notices. The sole failure was console_mesh_caches_hlsl_compute_pass_in_memory_and_on_disk (DXIL not compiled yet). I reran that exact test on the unchanged e48e74ca parent; 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 existing Arc owners 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
@@
+    #[test]
+    fn saturated_base_shader_index_shares_repeated_new_stage() {
+        let index: BaseShaderIndex = Mutex::new(None);
+        let a = share_base_shader(&index, 1, &[1], 2);
+        let b = share_base_shader(&index, 2, &[2], 2);
+        let c = share_base_shader(&index, 3, &[3], 2);
+        let again = share_base_shader(&index, 3, &[3], 2);
+        assert_eq!(a.as_slice(), &[1]);
+        assert_eq!(b.as_slice(), &[2]);
+        assert!(Arc::ptr_eq(&c, &again), "an overflow stage should share a live payload");
+    }

AI use: Codex (GPT-6.2 Sol) ran the tests and checked the finding; Codex (GPT-6.2 Astra) independently traced the index path.

@andrewDoing

Copy link
Copy Markdown
Contributor

I tested the proposed bounded FIFO approach independently against head 64aa28f0 in 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.

@DarkPanda69

DarkPanda69 commented Nov 28, 2026 •

Copy link
Copy Markdown

Update for head 299c93f (rebased on nvidia-dev 54225f5, plus "share pending pipeline shader payloads"): same device_x::tests:: command against the new merge-base 54225f5, 18 → 25 passed, 0 failed, no SKIPPED on both cards, the same seven changes as before. The GPU test again logged S6 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_payloads and async_recipes_share_shader_bytes_and_keep_them_until_the_last_owner, pass too, run once with XCL_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_x changes.

Tested: at the PR head 64aa28f against its merge-base with nvidia-dev, e48e74c (the diff doesn't apply as a patch on today's nvidia-dev 01b94f5). Debug, Rust 1.100.0, Windows 11 Pro 26200, Ryzen 7 5800X, card picked with XCL_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.
  • The only changes are the seven new tests, all ok. gpu_derived_pipeline_survives_original_shader_reuse logged S6 native adapter=AMD Radeon RX 9070 XT (16253 MiB VRAM); validation=PSO creation; dispatches=0, and the same with NVIDIA 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.

@andrewDoing

Copy link
Copy Markdown
Contributor

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.

Royalflamejlh added a commit to Royalflamejlh/xcl that referenced this pull request Nov 28, 2026
…#3092

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@thehollowedone

Copy link
Copy Markdown
Contributor

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; existing Arc owners 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=1 passed 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 --check passed. 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
diff --git a/crates/xcl/src/hle/d3d12x/device_x.rs b/crates/xcl/src/hle/d3d12x/device_x.rs
index be8051bb..ec952ada 100644
--- a/crates/xcl/src/hle/d3d12x/device_x.rs
+++ b/crates/xcl/src/hle/d3d12x/device_x.rs
@@ -344,29 +344,40 @@ fn rd64(d: &[u8], o: usize) -> u64 {
     u64::from_le_bytes(d[o..o + 8].try_into().unwrap())
 }
 
-type BaseShaderIndex = Mutex<Option<HashMap<(u64, usize), std::sync::Weak<Vec<u8>>>>>;
+#[derive(Default)]
+struct BaseShaderEntries {
+    blobs: HashMap<(u64, usize), std::sync::Weak<Vec<u8>>>,
+    order: std::collections::VecDeque<(u64, usize)>,
+}
+
+type BaseShaderIndex = Mutex<Option<BaseShaderEntries>>;
 
 /// A weak index shares live Base shader copies, without keeping their byte buffers alive.
 /// Unlike Arc<[u8]>, the Vec payload is released at the last strong reference, even while
 /// this index keeps a weak reference. The index itself is bounded too.
 fn share_base_shader(index: &BaseShaderIndex, hash: u64, bytes: &[u8], limit: usize) -> Arc<Vec<u8>> {
     let key = (hash, bytes.len());
-    let cached = index.lock().unwrap().as_ref().and_then(|m| m.get(&key)).and_then(std::sync::Weak::upgrade);
+    let cached = index.lock().unwrap().as_ref().and_then(|m| m.blobs.get(&key)).and_then(std::sync::Weak::upgrade);
     if let Some(cached) = cached.filter(|v| v.as_slice() == bytes) {
         return cached;
     }
     // Copy outside the lock; another creation may have published the same bytes meanwhile.
     let owned = Arc::new(bytes.to_vec());
     let mut g = index.lock().unwrap();
-    let m = g.get_or_insert_with(HashMap::new);
-    if let Some(cached) = m.get(&key).and_then(std::sync::Weak::upgrade).filter(|v| v.as_slice() == bytes) {
+    let m = g.get_or_insert_with(BaseShaderEntries::default);
+    if let Some(cached) = m.blobs.get(&key).and_then(std::sync::Weak::upgrade).filter(|v| v.as_slice() == bytes) {
         return cached;
     }
-    if m.len() >= limit {
-        m.retain(|_, v| v.strong_count() != 0);
-    }
-    if m.len() < limit || m.contains_key(&key) {
-        m.insert(key, Arc::downgrade(&owned));
+    if limit != 0 {
+        if !m.blobs.contains_key(&key) {
+            if m.blobs.len() >= limit {
+                if let Some(oldest) = m.order.pop_front() {
+                    m.blobs.remove(&oldest);
+                }
+            }
+            m.order.push_back(key);
+        }
+        m.blobs.insert(key, Arc::downgrade(&owned));
     }
     owned
 }
@@ -1706,19 +1717,52 @@ mod tests {
         let b = share_base_shader(&index, 7, &[5], 2);
         let uncached = share_base_shader(&index, 9, &[6], 2);
         assert_eq!(uncached.as_slice(), &[6], "full index still returns owned bytes");
-        assert_eq!(index.lock().unwrap().as_ref().unwrap().len(), 2);
+        assert_eq!(index.lock().unwrap().as_ref().unwrap().blobs.len(), 2);
         let weak = Arc::downgrade(&collision);
         drop(collision);
         assert!(weak.upgrade().is_none(), "the index does not keep the Vec or its payload live");
         let c = share_base_shader(&index, 9, &[6], 2);
         let keys = index.lock().unwrap();
         let keys = keys.as_ref().unwrap();
-        assert_eq!(keys.len(), 2);
-        assert!(!keys.contains_key(&(7, 3)), "dead entry pruned at capacity");
-        assert!(keys.contains_key(&(7, 1)) && keys.contains_key(&(9, 1)), "length is part of identity");
+        assert_eq!(keys.blobs.len(), 2);
+        assert!(!keys.blobs.contains_key(&(7, 3)), "oldest entry evicted at capacity");
+        assert!(keys.blobs.contains_key(&(7, 1)) && keys.blobs.contains_key(&(9, 1)), "length is part of identity");
         drop((a, same, b, c, uncached));
     }
 
+    #[test]
+    fn saturated_base_shader_index_shares_repeated_new_stage() {
+        let index: BaseShaderIndex = Mutex::new(None);
+        let a = share_base_shader(&index, 1, &[1], 2);
+        let b = share_base_shader(&index, 2, &[2], 2);
+        let c = share_base_shader(&index, 3, &[3], 2);
+        let again = share_base_shader(&index, 3, &[3], 2);
+        assert_eq!(a.as_slice(), &[1]);
+        assert_eq!(b.as_slice(), &[2]);
+        assert!(Arc::ptr_eq(&c, &again), "an overflow stage should share a live payload");
+        let entries = index.lock().unwrap();
+        let entries = entries.as_ref().unwrap();
+        assert_eq!((entries.blobs.len(), entries.order.len()), (2, 2));
+    }
+
+    #[test]
+    fn concurrent_overflow_shares_one_shader_copy() {
+        let index = Arc::new(Mutex::new(None));
+        let held = [share_base_shader(&index, 1, &[1], 2), share_base_shader(&index, 2, &[2], 2)];
+        let gate = Arc::new(std::sync::Barrier::new(8));
+        let threads: Vec<_> = (0..8).map(|_| {
+            let (index, gate) = (index.clone(), gate.clone());
+            std::thread::spawn(move || {
+                gate.wait();
+                share_base_shader(&index, 3, &[3; 1024], 2)
+            })
+        }).collect();
+        let copies: Vec<_> = threads.into_iter().map(|t| t.join().unwrap()).collect();
+        assert!(copies.iter().all(|v| Arc::ptr_eq(&copies[0], v)));
+        assert_eq!(index.lock().unwrap().as_ref().unwrap().blobs.len(), 2);
+        drop(held);
+    }
+
     #[test]
     fn concurrent_bases_publish_one_shader_copy() {
         let index = Arc::new(Mutex::new(None));
@@ -1732,7 +1776,7 @@ mod tests {
         }).collect();
         let copies: Vec<_> = threads.into_iter().map(|t| t.join().unwrap()).collect();
         assert!(copies.iter().all(|v| Arc::ptr_eq(&copies[0], v)));
-        assert_eq!(index.lock().unwrap().as_ref().unwrap().len(), 1);
+        assert_eq!(index.lock().unwrap().as_ref().unwrap().blobs.len(), 1);
     }
 
     #[test]

AI use: Codex (GPT-6.2 Sol) wrote the candidate, reviewed the bounded index and ownership path, and ran the stated tests.

Prime1997 added a commit to Prime1997/xcl that referenced this pull request Nov 28, 2026
Adapt the shader interning proposal in PR xcl-dev#827 using the bounded weak Vec ownership index from xcl-dev#3091. Pending compute, graphics and stream recipes share live immutable copies while preserving title-memory lifetime and cache keys. Source patch passed 11 focused CPU tests before integration; full GPU/gameplay validation is waived for this user test build.

Concept credit: Cattn / PR xcl-dev#827. Implementation and focused checks: Codex (GPT-6).
@Prime1997 Prime1997 changed the title Shaders: retain shared bytecode for derived pipelines Shaders: share owned bytecode across derived and pending pipelines Nov 28, 2026
@Prime1997
Prime1997 force-pushed the codex/gdkx-base-shader-ownership branch from 64aa28f to 299c93f Compare November 28, 2026 08:40
@thehollowedone

Copy link
Copy Markdown
Contributor

Independent Windows/NVIDIA check of #3091 head 299c93f1, based on nvidia-dev 54225f58. 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=4 did not pass: Cargo reported -p xcl --lib as the failed target. A separate run of that library target ended abnormally with 0x07C10003 before its test summary. Its last diagnostic was that a mixed driver-heap window could not be restored after CreateHeap returned E_OUTOFMEMORY, followed by the intentional fail-stop. The same failure on plain nvidia-dev and 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-existing console_mesh_caches_hlsl_compute_pass_in_memory_and_on_disk failure (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.

@andrewDoing

Copy link
Copy Markdown
Contributor

At 299c93f1 on 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:

Native graphics pipeline Left 8 pixels Right 8 pixels
Grandchild control after ancestor release Red Blue
Pipeline created from the surviving recipe Magenta (red written, blue preserved) Blue

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.

Own shader bytes for each retained graphics base and share equal live bytecode through a bounded weak index. Native derivation survives original-buffer reuse and parent release. The 1024-pipeline fixture retains 81920 payload bytes instead of 83886080 with separate copies; this is payload accounting, not process RAM. Full-suite and retail merge checks remain pending.

Assisted-by: Codex (GPT-6)
Adapt the shader interning proposal in PR xcl-dev#827 using the bounded weak Vec ownership index from xcl-dev#3091. Pending compute, graphics and stream recipes share live immutable copies while preserving title-memory lifetime and cache keys. Source patch passed 11 focused CPU tests before integration; full GPU/gameplay validation is waived for this user test build.

Concept credit: Cattn / PR xcl-dev#827. Implementation and focused checks: Codex (GPT-6).
@Prime1997
Prime1997 force-pushed the codex/gdkx-base-shader-ownership branch from 299c93f to 1dad60e Compare November 28, 2026 21:57
@github-actions github-actions Bot added area:d3d12 D3D12.X runtime, command lists, resources, sparse memory area:docs-ci Documentation, scripts, workflows, repo governance area:shaders Shader cache, PSO compilation, pipeline libraries, precompilation gpu:nvidia Code is specific to NVIDIA / wave32 GPUs (scope tag; see needs:nvidia-test) labels Nov 28, 2026

@bmjask bmjask left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 1dad60e with Codex (GPT-5).

@thehollowedone

thehollowedone commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

CI follow-up for #3091 head 1dad60ed: the Windows job first fails in builder_deduplicates_names_and_atomically_replaces_output with 4 entries instead of 2. Three later pipeline-library/warm-library failures are PoisonError after that test poisons their shared lock. pipeline_library.rs has the same Git blob (470de7f) on this head and its main base.

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-smoke blocks from a clean commit of main and 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.

@vasanex

vasanex commented Nov 29, 2026

Copy link
Copy Markdown
merge-check
base: fa204595a488c60c6c5f905244f0172072c9c2a9
head: 1dad60ed99b343428faff147592de955ae273dfa
merge: clean
build: cargo build --workspace -> ok
tests: not run alone; in a stack of 11 of your PRs on this base: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2650 passed, 1 failed, 49 ignored; SKIPPED: 27 lines; failing: #3123's private_physical_pages_reach_the_gpu_on_mapping only. Alone: hle::d3d12x::device_x:: hle::d3d12x::pso_async:: hle::d3d12x::real:: 385 passed, 0 failed (1 SKIPPED line).
review: no ownership or lifetime defect found. Two open points: (1) on by default, note_base runs for every graphics PSO (device_x.rs:233 in the merged tree) and keeps a CPU copy of its shader bytes for the PSO's life - not measured in a world; (2) once the weak index holds 65,536 live entries (device_x.rs:388), every miss runs a full retain under the global lock (:377) and the new key is not shared - reported on the PR with a failing test, unchanged at this head. Overlaps open #827.
performance: 60 s smoke of the merged tree (925aa89e): 1687 frames, peak commit 17845 MB, 0 removals, 0 crashes (base 1629-1689 frames, 16065-16596 MB; commit is noisy in this series). Load run with #3049's counters (XCL_HEAP_COUNT=2), base + #3049 vs base + #3049 + this PR, one run each, about 6,400-6,500 pipelines alive: XCL's own heap 993 / 1230 / 1404 / 1626 / 1893 MB without against 1056 / 1096 / 1266 / 1520 / 1708 MB with it at 20 / 40 / 60 / 80 / 100 s - no increase beyond the run-to-run spread (the arm with the PR is lower at four of five points). So the retained shader bytes are not visible at this pipeline count; a loaded world (not reachable on main on this 10 GB card) was not measured. No removal or crash (2277 frames in 150 s, base 2014).
verdict: not yet: the saturated-index scan is unanswered; the memory retention does not show in a 150 s load on this title (world not measured); CI red is the unrelated pipeline_library test
hardware / tool and model: RTX 3080 10 GB 621.40, Ryzen 9 7950X, Windows 11 26200 / Claude Code (Claude Opus 5.5, Claude Fable 5.2)

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.rs test module); the base alone gave 2608 passed, 0 failed, 49 ignored with the same 27 SKIPPED lines (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.

@Prime1997

Copy link
Copy Markdown
Collaborator Author

merge-check
base: d8bd9a3
head: 1dad60e
merge: 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 d8bd9a3 1424 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

@github-actions github-actions Bot added the needs-pr-check Failing the PR description check (CONTRIBUTING.md) label Nov 29, 2026
Royalflamejlh added a commit to Royalflamejlh/xcl that referenced this pull request Nov 29, 2026
main has merged nvidia-dev (xcl-dev#3203): its two-pass mesh, sparse and upload
paths now submit through real::native_queue_execute / _signal / _wait.
Those already carry xcl-dev#867's UnadoptGuard and unwrap_fence; the conflicts
and the main-only submit paths were resolved as follows.

Taken from main, the stack's version dropped (main does the same):
- recomp/dxc.rs (3): xcl-dev#688's private DXC heaps; main's form (3842807)
  falls back on any failure and never destroys a heap.
- device_x.rs (10): xcl-dev#3091 (cherry-pick 511a297); main's 7e24237 keeps
  interned shader copies for base pipelines. xcl-dev#3091's tests and its
  real.rs test counter (GRAPHICS_FALLBACK_ATTEMPTS) and README line go;
  xcl-dev#2753's console_bytes is re-applied on main's file.
- bind.rs (16): the stack's only change there was xcl-dev#1803, merged in main.
  main's file, plus the xcl-dev#2816 feedback-copy UnadoptGuard in
  poll_two_pass_feedback (ed887d2, from linux/stack-nvidia-dev).
- pso.rs: main has daae033 (multidimensional groups take direct DXIL,
  xcl-dev#3189's change), so the stack-only commit is in main; translate calls
  take main's translate_compute_rodata / translate_entry_rodata_rt32.
- list_x.rs tests: xcl-dev#3090's barrier tests were in twice (cherry-pick and
  main's merge); the cherry-picked copy goes.
- runner.rs device(), xbox.rs Fssm::rodata: added on both sides; one copy.
- README.md: the precompile-wrapper paragraph was added on both sides;
  one copy.

Both kept:
- build.rs (2): TRANSLATION_GLUE_REVISION "pso-glue-v5-linux-multidimensional-
  direct" (main's v5 + the stack suffix); translator sources keep xcl-dev#2229's
  cfg.rs and code_loads.rs, drop dxc.rs as main does.
- dxil/kernel.rs (6): TRANSLATOR_VERSION 13 (main 12; the stack's xcl-dev#2229
  head output differs, as on linux/stack-nvidia-dev); main's rt32 entry
  points with xcl-dev#2229's code_loads.
- dxil/lower.rs (4), lower_mem.rs (3), lower_window.rs (1), recomp/emit.rs
  (11), recomp/mod.rs (3), recomp/tests.rs (1), core_tests.rs: main has
  an earlier copy of xcl-dev#2229 (41f1a85); xcl-dev#2229's head (code_loads, xcl_cload
  / xcl_gload(hi, a)) is kept over it, as on linux/stack-nvidia-dev;
  main's loop_ids, IO slots, ps_mask_live_scc and rt32 mask kept beside
  it, and main's duplicate core_tests copy of the rodata test goes.
  lower_mem.rs keeps the stack's scratch_ptr insert-before-terminator line.
- real.rs (6): the class scan keeps `own` with main's
  release_through_its_own_vtable; xcl-dev#2477's in-place patch after main's
  two-pass defer hooks; q_signal_pc / q_wait_pc beside main's page
  mappings; the title ExecuteCommandLists keeps xcl-dev#867's list guards inside
  main's watch::in_driver scope; test modules of both.
- list_x.rs (1): xcl-dev#867's allocator / PSO guards with main's `on = pc_alloc`.
- sparse.rs (1): main's new_state, with xcl-dev#867's raw fences for the sparse
  and readback fences and the async readback fence pairs (as on
  linux/stack-nvidia-dev); pc_execute (main's texture_upload submit path)
  unadopts its list for the submit.
- title_textures.rs (1): main's early fence creation, as a raw fence.
- dstorage.rs (4): xcl-dev#2864's unpack cache on main's Cow source and stage
  buffers.
- xg.rs (2): main's copy_args (adccb7d) covers xcl-dev#684's argument fix;
  xcl-dev#684's destination guard kept.
- present.rs (1), gpu_compute_e2e.rs (1), README.md (2): tests and text
  of both.

linux/README.md: main line updated; xcl-dev#1599, xcl-dev#2082, xcl-dev#1803, xcl-dev#3090, xcl-dev#688,
xcl-dev#3091 and the stack-only multidimensional row leave the table.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@bmjask bmjask left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Critical review of current head 1dad60ed. I found no concrete ownership defect in the shared immutable shader bytes: live pipelines retain strong Arcs 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.

ArtuArtaza added a commit to ArtuArtaza/xcl that referenced this pull request Nov 30, 2026
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>
@thehollowedone

Copy link
Copy Markdown
Contributor

Source overlap check for #3091 head 1dad60ed and #3505 head 12713ec6: main commit 7e242379 already 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 carries Arc<Vec<u8>> through ComputeBuildKey. Those production ownership and sharing changes substantially overlap #3091; landing both unchanged would require reconciling two pool implementations and the same OwnedDesc type 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_blobs treats 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.

@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Review (head 1dad60e, diff read, not a merge-check; it conflicts with main and PR description fails, so not built or run):

  • Partly superseded. Main's 7e24237 ("D3D12.X: base pipelines keep their own copy of their shaders, shared by content", 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.
  • The Arc<Vec<u8>> point is valid on main: main's Weak<[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.
  • Cost: in share_base_shader, once all 65,536 entries are live, every new shader runs a full retain under 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.
  • No xcl-smoke pair (why PR description fails), only 40 targeted tests ran on this head, and AI use doesn't name the model used for the Claude Code rebase. The four pipeline_library / warm_library CI 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 uses skip_test.

AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:d3d12 D3D12.X runtime, command lists, resources, sparse memory area:docs-ci Documentation, scripts, workflows, repo governance area:shaders Shader cache, PSO compilation, pipeline libraries, precompilation gpu:nvidia Code is specific to NVIDIA / wave32 GPUs (scope tag; see needs:nvidia-test) needs-pr-check Failing the PR description check (CONTRIBUTING.md)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants