Skip to content

D3D12.X: stage upload arguments for indirect mesh draws - #3105

Draft
Prime1997 wants to merge 1 commit into
xcl-dev:mainfrom
Prime1997:codex/nvidia-upload-indirect-mesh
Draft

Prime1997 wants to merge 1 commit into
xcl-dev:mainfrom
Prime1997:codex/nvidia-upload-indirect-mesh

Conversation

@Prime1997

@Prime1997 Prime1997 commented Nov 28, 2026 •

Copy link
Copy Markdown
Collaborator

Enable standalone UPLOAD-heap arguments/counts for two-pass indirect mesh draws on nvidia-dev. The existing path only accepts console UMA inputs.

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 a54edd3735b9268fcc70dd537239b4c9983fd2aa (was 95ff502bb2badc516b71836ed9c9c3578b36c567). The one conflict was in execute_indirect_classified (bind.rs): this PR's checked offsets are kept, on main's dispatches, args_off_title and draw_pipeline(pso, bound_unbuilt), and the new test's FakeAdoptedList gained main's last_pso field. That port needs a review. The wider indirect test filter is not counted: on this PC it ends in an access violation on plain main 765b2c5b too (3 of 3 runs), where dispatch_chain::tests::failed_binding_keeps_indirect_commands_until_allocator_reset also fails alone with adopted class. 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 gpu_upload_indirect_preparation_uses_its_recording_arena_and_sources gpu_upload_indirect_staging_keeps_inputs_counts_and_canaries indirect_known_console_ranges_never_fall_back_to_the_pc_buffer indirect_upload_layout_bounds_both_inputs_and_outputs indirect_upload_source_classification_and_failed_submit_retention invalid_indirect_count_records_no_gpu_work gave 6 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

  • Windows 11 Pro 26200; Intel i5-10400; RTX 3060 Ti, driver 32.0.16.1714; Rust 1.100.0. Debug/test profile, debug symbols disabled, two build jobs, isolated outputs.
  • cargo test --locked -p xcl --lib --target-dir <isolated-target> --no-run: passed.
  • Thirteen individual invocations of cargo test --locked -p xcl --lib --target-dir <isolated-target> hle::d3d12x::bind::tests::<test> -- --exact --nocapture --test-threads=1: 13 passed, 0 failed, 0 ignored; no SKIPPED messages (1,811 filtered per invocation).
  • New tests: indirect_upload_layout_bounds_both_inputs_and_outputs, indirect_known_console_ranges_never_fall_back_to_the_pc_buffer, indirect_upload_source_classification_and_failed_submit_retention, invalid_indirect_count_records_no_gpu_work, gpu_upload_indirect_staging_keeps_inputs_counts_and_canaries, gpu_upload_indirect_preparation_uses_its_recording_arena_and_sources.
  • The classification/failed-submit test uses WARP and modeled completion values. The two new GPU fixtures exercised staging/scaling, full readback canaries, and the production preparation core with a private imported 8 MiB UMA aperture.
  • Existing regressions cover scaler group/count bounds, capped scratch, completion/reset/replay retention, removal-sentinel rejection, and the mesh-record oracle.
  • Executions preceded committing the unchanged source tree; exact commands, hashes and logs are retained locally.

Regression run
Pending paired clean-head main/PR title runs; no smoke block claimed. Draft until required validation is complete.

Not tested

  • Full workspace on this head; positive full ExecuteIndirect mesh rendering with the new UPLOAD path; retail texture recovery; AMD/Intel.
  • DEFAULT-heap GPU-produced arguments remain unsupported.
  • Reduced game RAM usage: scratch is capped, but retained external upload-source sizes are not included in that cap. Missing-completion quarantine is intentionally conservative.
  • The independent clean NVIDIA full-suite diagnostic thread-slot failure remains a separate repair.

AI use
Codex (GPT-6) reviewed the related work and actual main source, implemented the bounded NVIDIA adaptation, ran the targeted tests and prepared this PR.

Optional temporary Discord for coordinating contributor work, testing and comparing results: https://discord.gg/6B4TykyC4W

@thehollowedone

Copy link
Copy Markdown
Contributor

I checked head 95ff502 on an RTX 3080 Ti. All six new bind::tests cases passed in four focused invocations (6 passed, 0 failed, 0 ignored, no skips). The two GPU fixtures executed on the adapter. The full workspace and title smoke were not run.

One lifetime case needs a regression before this leaves draft. alloc_pool::executed calls two_pass_submitted(..., None, ...) if fence creation or Signal fails after submission. It then leaves no completion mark on the PC allocator backing. Retirement quarantines only blocks with upload sources (the argument scratch). The two-pass draw also reads its separate record buffer and scaler constants in the recording's UMA arena. On reset, an unmarked backing can appear idle to done_with, allowing those other dependencies to be reused before the submitted GPU work is known complete. The existing failed-submit test checks only the scratch and its upload reference.

Suggested recovery and regression

Keep the complete recording dependency set held when a submitted queue has no completion proof: scratch and upload sources, record buffer, allocator backing, and UMA constants. A replacement fence signal on that same queue, issued after the failed marking attempt, can establish a new ordered completion point; release only after it and every other queue mark for the recording complete. If a replacement mark cannot be established, retain the complete set without recycling it. A later proved mark should drain the retained set; the current process-global UNFENCED_UPLOADS has no drain even after a transient failure.

A regression can block a queue behind an unsignaled gate, inject a failed completion mark after submission, reset the recording, and assert that none of the three allocations is reusable. Include two queues: completion on only one must not release the recording; completion on both may release it once.

The focused commands were cargo test --offline --locked -j 4 -p xcl --lib <filter> -- --nocapture --test-threads=1, with filters indirect_upload_ (2 passed), gpu_upload_indirect_ (2), invalid_indirect_count_records_no_gpu_work (1), and indirect_known_console_ranges_never_fall_back_to_the_pc_buffer (1). Windows 11 build 26300, Ryzen 7 9800X3D, RTX 3080 Ti driver 621.35, DXC 1.8.2502.11. This finding is source-traced; I did not inject a real fence failure. AI use: Codex (GPT-6.2 Sol) reviewed the path and ran the tests; Codex (GPT-6.2 Astra) independently audited the lifetime path.

Copy proven UPLOAD inputs into recording-owned scratch and retain sources through submission completion. Bound both inputs before recording and quarantine unmarked staged resources. Thirteen targeted tests passed without skips; full workspace and paired clean-head title runs remain pending.

Assisted-by: Codex (GPT-6)
@Prime1997
Prime1997 force-pushed the codex/nvidia-upload-indirect-mesh branch from 95ff502 to a54edd3 Compare November 28, 2026 20:42
@andrewDoing

Copy link
Copy Markdown
Contributor

I tested the rebased indirect caller at a54edd3735b9268fcc70dd537239b4c9983fd2aa on RTX 5070, driver 616.92. Standalone UPLOAD arguments and counts at nonzero byte offsets produced the expected mesh geometry through execute_indirect → execute_indirect_classified on a tracked direct list.

The fixture registered a real native compute/mesh PSO pair as a two-pass pipeline and used the production signature-creation hook to create the DispatchMesh signature and its companion Dispatch signature. The UPLOAD argument buffer held two records starting at byte 16 (16-byte stride, one group then two). A separate UPLOAD count buffer supplied the count at byte 8. The preceding words were zero. The native compute pass wrote each group's ID to the record buffer; the mesh pass read it to distinguish the left and right halves of a 4×4 target.

Count input (maximum 2) Left eight pixels Right eight pixels
0 Blue clear Blue clear
1 Red Blue clear
2 Red Green
No count buffer Red Green

All four fresh processes logged the production two-pass ExecuteIndirect path. Every pixel matched after a completion fence; zero skips. This exercises the rebased exact/native pipeline route, both checked nonzero offsets, GPU argument rewriting and real indirect command consumption. The PSO pair was synthetic, batching was disabled, and the inputs stayed alive through submission. The test does not cover pending asynchronous PSO resolution, retention after early release, or retail rendering.

AI use: OpenAI Codex adapted the native geometry fixture, ran the four controls, and wrote this report.

@vasanex

vasanex commented Nov 29, 2026

Copy link
Copy Markdown
merge-check
base: fa204595a488c60c6c5f905244f0172072c9c2a9
head: a54edd3735b9268fcc70dd537239b4c9983fd2aa
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::bind:: hle::d3d12x::real:: 286 passed, 0 failed (28 SKIPPED lines, the wave64 and heap-window ones).
review: no defect found in the staging code (layout, bounds and barrier order read through). Open: UNFENCED_UPLOADS (bind.rs:93, filled at :621) is never drained - only reached when a submit has no completion fence; `expect("scratch belongs to this recording")` (bind.rs:3371) sits on the hook path of every two-pass indirect draw, an Err would be safer; the lifetime point raised on the earlier head (other buffers still reused on allocator reset, as on main) is unanswered; about 655 changed lines; possible overlap with #3079.
performance: 60 s smoke of the merged tree (e43f582a): 1689 frames, peak commit 18520 MB, 0 removals, 0 crashes (base 1629-1689 frames, 16065-16596 MB; commit is noisy in this series). The front end does not reach UPLOAD-heap indirect mesh draws, so the new path was NOT exercised by a title here.
verdict: not yet: on by default and it turns skipped draws on (tier 3) - needs a title run that reaches such draws; the points above are for the author
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.

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.

@thehollowedone

thehollowedone commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Follow-up to my earlier lifetime review on head a54edd3: I no longer find premature allocator/UMA reuse for a tracked recording. begin_submit pins the exact backing before ExecuteCommandLists; a failed fence creation or Signal keeps that pin, and BackingProbe::free refuses reuse. My earlier warning about apparently idle scratch, record storage, and scaler UMA applied to the older head.

The remaining memory failure mode is retention after a transient fence error. I made an uncommitted candidate that retries completion marking once in the same ordered queue turn and on the same PendingSubmit. Failed Signal values are burned; the retry reserves a fresh value. It checks marker identity before retrying or releasing pins. A second failure leaves the submit pinned. The normal successful path adds no driver call or state-lock acquisition. The best-effort timing receipt also shares this retry budget, so its failed sample may make one extra driver attempt.

On the untouched PR head, the new transient-Signal regression failed (0 passed, 1 failed). With the candidate, cargo test --offline --locked -j 4 -p xcl --lib hle::d3d12x::alloc_pool::tests:: -- --test-threads=4 passed 30/30, and cargo test --offline --locked -j 4 -p xcl --lib gpu_upload_indirect_ -- --test-threads=1 --nocapture passed 2/2 on Windows 11 build 26300, RTX 3080 Ti / 621.35, Ryzen 7 9800X3D. No GPU skip was printed in that focused run. cargo build --offline --locked --workspace passed.

The full cargo test --offline --locked -j 4 --workspace --no-fail-fast -- --test-threads=4 run recorded 2,601 passed, 4 failed attempts, 49 ignored, 26 GPU skip notices. The failures were the mesh HLSL cache test, the two-pass driver-cache test (failed twice through its own retry), and a_preparation_worker_also_builds_a_split_programs_whole_form. The first two had already failed on untouched main in a prior paired check. I reran the compute test on the untouched a54edd3 PR head; it failed there with the same “no split program” result (0 passed, 1 failed). These failures are not attributed to the candidate. I have not run clean-commit paired title smoke or an AMD/Intel adapter check, so this is a candidate for the author to adapt and verify, not a merge-readiness claim.

Uncommitted candidate diff and focused regressions
diff --git a/crates/xcl/src/hle/d3d12x/alloc_pool.rs b/crates/xcl/src/hle/d3d12x/alloc_pool.rs
index b1159583..afbd0583 100644
--- a/crates/xcl/src/hle/d3d12x/alloc_pool.rs
+++ b/crates/xcl/src/hle/d3d12x/alloc_pool.rs
@@ -687,8 +687,8 @@ impl PendingSubmit {
     fn finish_with_queue_ops(
         self,
         key: usize,
-        create: impl FnOnce() -> Option<ID3D12Fence>,
-        signal: impl FnOnce(&ID3D12Fence, u64) -> bool,
+        create: impl FnMut() -> Option<ID3D12Fence>,
+        signal: impl FnMut(&ID3D12Fence, u64) -> bool,
     ) -> bool {
         self.finish_with_queue_ops_marked(key, create, signal).is_ok()
     }
@@ -696,8 +696,8 @@ impl PendingSubmit {
     fn finish_with_queue_ops_marked(
         self,
         key: usize,
-        create: impl FnOnce() -> Option<ID3D12Fence>,
-        signal: impl FnOnce(&ID3D12Fence, u64) -> bool,
+        create: impl FnMut() -> Option<ID3D12Fence>,
+        signal: impl FnMut(&ID3D12Fence, u64) -> bool,
     ) -> Result<Option<SubmissionReceipt>, ()> {
         if self.entries.is_empty() {
             return Ok(None);
@@ -709,8 +709,8 @@ impl PendingSubmit {
     fn finish_with_queue_ops_receipted(
         self,
         key: usize,
-        create: impl FnOnce() -> Option<ID3D12Fence>,
-        signal: impl FnOnce(&ID3D12Fence, u64) -> bool,
+        create: impl FnMut() -> Option<ID3D12Fence>,
+        signal: impl FnMut(&ID3D12Fence, u64) -> bool,
     ) -> Option<SubmissionReceipt> {
         // `begin_submit` intentionally does not initialize allocator state when swapping is off;
         // a requested receipt still needs the shared queue-generation marker namespace.
@@ -723,46 +723,73 @@ impl PendingSubmit {
     fn finish_with_queue_ops_inner(
         mut self,
         key: usize,
-        create: impl FnOnce() -> Option<ID3D12Fence>,
-        signal: impl FnOnce(&ID3D12Fence, u64) -> bool,
+        mut create: impl FnMut() -> Option<ID3D12Fence>,
+        mut signal: impl FnMut(&ID3D12Fence, u64) -> bool,
     ) -> Option<SubmissionReceipt> {
         let marker = {
             let g = lock_for_submit();
             let s = g.as_ref()?;
             s.fences.get(&key).cloned()
         };
+        let mut recovered = false;
         let marker = match marker {
             Some(marker) => marker,
             None => {
-                let fence = create()?;
-                let made = Arc::new(QueueFence::new(fence));
-                let mut g = lock_for_submit();
-                let s = g.as_mut()?;
-                let (marker, unused) = match s.fences.entry(key) {
-                    Entry::Occupied(entry) => (Arc::clone(entry.get()), Some(made)),
-                    Entry::Vacant(entry) => {
-                        let marker = Arc::clone(&made);
-                        entry.insert(made);
-                        (marker, None)
+                let mut created = create();
+                let mut nested = None;
+                if created.is_none() {
+                    recovered = true;
+                    nested = {
+                        let g = lock_for_submit();
+                        g.as_ref()?.fences.get(&key).cloned()
+                    };
+                    if nested.is_none() {
+                        created = create();
                     }
-                };
-                drop(g);
-                drop(unused);
-                marker
+                }
+                if let Some(marker) = nested {
+                    marker
+                } else {
+                    let made = Arc::new(QueueFence::new(created?));
+                    let mut g = lock_for_submit();
+                    let s = g.as_mut()?;
+                    let (marker, unused) = match s.fences.entry(key) {
+                        Entry::Occupied(entry) => (Arc::clone(entry.get()), Some(made)),
+                        Entry::Vacant(entry) => {
+                            let marker = Arc::clone(&made);
+                            entry.insert(made);
+                            (marker, None)
+                        }
+                    };
+                    drop(g);
+                    drop(unused);
+                    marker
+                }
             }
         };
         // Reserve before entering the driver. The queue lease excludes another thread, while an
         // atomic reservation lets intentional same-thread re-entry take a distinct later value.
-        // A failed Signal burns its value; its submit remains pinned and a gap is harmless.
-        let Ok(value) = marker.next_value.fetch_update(Ordering::Relaxed, Ordering::Relaxed, |v| v.checked_add(1)) else {
-            return None;
-        };
-        let value = value + 1;
-        SUBMIT.signal_attempts.fetch_add(1, Ordering::Relaxed);
-        if !signal(&marker.fence, value) {
+        // A failed Signal burns its value; a second failure leaves the submit pinned.
+        let value = loop {
+            let Ok(value) = marker.next_value.fetch_update(Ordering::Relaxed, Ordering::Relaxed, |v| v.checked_add(1)) else {
+                return None;
+            };
+            let value = value + 1;
+            SUBMIT.signal_attempts.fetch_add(1, Ordering::Relaxed);
+            if signal(&marker.fence, value) {
+                break value;
+            }
             SUBMIT.signal_failures.fetch_add(1, Ordering::Relaxed);
-            return None;
-        }
+            if recovered {
+                return None;
+            }
+            recovered = true;
+            let g = lock_for_submit();
+            let s = g.as_ref()?;
+            if s.fences.get(&key).is_none_or(|current| !Arc::ptr_eq(current, &marker)) {
+                return None;
+            }
+        };
         let fence = marker.fence.clone();
         let mut g = lock_for_submit();
         let s = g.as_mut()?;
@@ -1818,6 +1845,156 @@ mod tests {
         assert_eq!(object.refs.get(), 0);
     }
 
+    fn assert_submit_pin_during_driver_callback(alloc: usize) {
+        let started = std::time::Instant::now();
+        let state = loop {
+            if let Ok(state) = STATE.try_lock() { break state; }
+            assert!(started.elapsed() < std::time::Duration::from_secs(1), "driver callback could not reenter allocator state");
+            std::thread::yield_now();
+        };
+        assert_eq!(state.as_ref().unwrap().backings[&alloc].submit_pins, 1);
+    }
+
+    #[test]
+    fn a_transient_signal_failure_marks_the_original_submit() {
+        let (alloc, list, queue) = (0x7ffe_6b90usize, 0x7ffe_6b91usize, 0x7ffe_6b92usize);
+        created_on(list, alloc, D3D12_COMMAND_LIST_TYPE_DIRECT.0);
+        let (mock, completed) = submission_receipt_for_test(0, 0);
+        let fence = mock.marker.fence.clone();
+        let pending = begin_submit(&[list as *mut c_void]).unwrap().execution_possible();
+        let mut attempts = Vec::new();
+        let marked = pending.finish_with_queue_ops_marked(queue, || Some(fence.clone()), |_, value| {
+            assert_submit_pin_during_driver_callback(alloc);
+            attempts.push(value);
+            attempts.len() == 2
+        });
+        assert_eq!(attempts, [1, 2], "retry must reserve a distinct ordered value");
+        let receipt = marked.expect("a transient failure should be recovered").unwrap();
+        assert_eq!(receipt.value, 2);
+        assert_eq!(STATE.lock().unwrap().as_ref().unwrap().backings[&alloc].submit_pins, 0);
+        assert!(!receipt.is_complete());
+        completed.store(2, Ordering::Release);
+        assert!(receipt.is_complete());
+
+        let removed = {
+            let mut g = STATE.lock().unwrap();
+            let s = g.as_mut().unwrap();
+            s.of_list.remove(&list);
+            s.list_lifetimes.remove(&list);
+            s.recordings.remove(&list);
+            s.last_submit.remove(&list);
+            s.cur.remove(&alloc);
+            s.types.remove(&alloc);
+            (s.backings.remove(&alloc), s.fences.remove(&queue))
+        };
+        drop(removed);
+    }
+
+    #[test]
+    fn a_transient_fence_creation_failure_marks_the_original_submit() {
+        let (alloc, list, queue) = (0x7ffe_6ba0usize, 0x7ffe_6ba1usize, 0x7ffe_6ba2usize);
+        created_on(list, alloc, D3D12_COMMAND_LIST_TYPE_DIRECT.0);
+        let (mock, _) = submission_receipt_for_test(0, 0);
+        let fence = mock.marker.fence.clone();
+        let pending = begin_submit(&[list as *mut c_void]).unwrap().execution_possible();
+        let mut creates = 0;
+        let marked = pending.finish_with_queue_ops_marked(queue, || {
+            assert_submit_pin_during_driver_callback(alloc);
+            creates += 1;
+            (creates == 2).then(|| fence.clone())
+        }, |_, value| value == 1);
+        assert_eq!(creates, 2);
+        assert_eq!(marked.unwrap().unwrap().value, 1);
+        assert_eq!(STATE.lock().unwrap().as_ref().unwrap().backings[&alloc].submit_pins, 0);
+
+        let removed = {
+            let mut g = STATE.lock().unwrap();
+            let s = g.as_mut().unwrap();
+            s.of_list.remove(&list);
+            s.list_lifetimes.remove(&list);
+            s.recordings.remove(&list);
+            s.last_submit.remove(&list);
+            s.cur.remove(&alloc);
+            s.types.remove(&alloc);
+            (s.backings.remove(&alloc), s.fences.remove(&queue))
+        };
+        drop(removed);
+    }
+
+    #[test]
+    fn a_nested_marker_after_failed_creation_marks_without_another_create() {
+        let (alloc, list, queue) = (0x7ffe_6bc0usize, 0x7ffe_6bc1usize, 0x7ffe_6bc2usize);
+        created_on(list, alloc, D3D12_COMMAND_LIST_TYPE_DIRECT.0);
+        let (mock, _) = submission_receipt_for_test(0, 0);
+        let fence = mock.marker.fence.clone();
+        let pending = begin_submit(&[list as *mut c_void]).unwrap().execution_possible();
+        let mut creates = 0;
+        let marked = pending.finish_with_queue_ops_marked(queue, || {
+            assert_submit_pin_during_driver_callback(alloc);
+            creates += 1;
+            assert_eq!(creates, 1, "reuse the marker installed during the first CreateFence");
+            STATE.lock().unwrap().as_mut().unwrap().fences.insert(
+                queue, Arc::new(QueueFence::new(fence.clone())),
+            );
+            None
+        }, |actual, value| {
+            assert_eq!(actual.as_raw(), fence.as_raw());
+            value == 1
+        });
+        assert_eq!(creates, 1);
+        assert_eq!(marked.unwrap().unwrap().value, 1);
+        assert_eq!(STATE.lock().unwrap().as_ref().unwrap().backings[&alloc].submit_pins, 0);
+
+        let removed = {
+            let mut g = STATE.lock().unwrap();
+            let s = g.as_mut().unwrap();
+            s.of_list.remove(&list);
+            s.list_lifetimes.remove(&list);
+            s.recordings.remove(&list);
+            s.last_submit.remove(&list);
+            s.cur.remove(&alloc);
+            s.types.remove(&alloc);
+            (s.backings.remove(&alloc), s.fences.remove(&queue))
+        };
+        drop(removed);
+    }
+
+    #[test]
+    fn a_replaced_fence_marker_cannot_recover_a_failed_signal() {
+        let (alloc, list, queue) = (0x7ffe_6bb0usize, 0x7ffe_6bb1usize, 0x7ffe_6bb2usize);
+        created_on(list, alloc, D3D12_COMMAND_LIST_TYPE_DIRECT.0);
+        let (old, _) = submission_receipt_for_test(0, 0);
+        let (new, _) = submission_receipt_for_test(0, 0);
+        let old_fence = old.marker.fence.clone();
+        let new_fence = new.marker.fence.clone();
+        let pending = begin_submit(&[list as *mut c_void]).unwrap().execution_possible();
+        let mut signals = 0;
+        let marked = pending.finish_with_queue_ops_marked(queue, || Some(old_fence.clone()), |_, value| {
+            signals += 1;
+            assert_eq!(value, 1);
+            STATE.lock().unwrap().as_mut().unwrap().fences.insert(
+                queue, Arc::new(QueueFence::new(new_fence.clone())),
+            );
+            false
+        });
+        assert!(marked.is_err());
+        assert_eq!(signals, 1, "a changed queue generation must prevent a retry");
+        assert_eq!(STATE.lock().unwrap().as_ref().unwrap().backings[&alloc].submit_pins, 1);
+
+        let removed = {
+            let mut g = STATE.lock().unwrap();
+            let s = g.as_mut().unwrap();
+            s.of_list.remove(&list);
+            s.list_lifetimes.remove(&list);
+            s.recordings.remove(&list);
+            s.submit_pins.retain(|&(p, _), _| p != list);
+            s.cur.remove(&alloc);
+            s.types.remove(&alloc);
+            (s.backings.remove(&alloc), s.fences.remove(&queue))
+        };
+        drop(removed);
+    }
+
     #[test]
     fn submit_marking_calls_out_unlocked_and_revalidates_the_queue_marker() {
         use std::cell::Cell;
@@ -1874,13 +2051,15 @@ mod tests {
 
         let failed_list = 0x7ffe_6b05usize;
         let failed = begin_submit(&[failed_list as *mut c_void]).unwrap().execution_possible();
+        let mut failed_values = Vec::new();
         assert!(!failed.finish_with_queue_ops(first_queue, || unreachable!(), |_, value| {
-            assert_eq!(value, 2);
+            failed_values.push(value);
             false
         }));
+        assert_eq!(failed_values, [2, 3], "both failed Signals burn distinct values");
         let retried = begin_submit(&[failed_list as *mut c_void]).unwrap().execution_possible();
         assert!(retried.finish_with_queue_ops(first_queue, || unreachable!(), |_, value| {
-            assert_eq!(value, 3, "a failed Signal leaves a gap instead of colliding with a retry");
+            assert_eq!(value, 4, "failed Signals leave a gap instead of colliding with a later submit");
             true
         }));
         {
@@ -1888,18 +2067,18 @@ mod tests {
             let s = g.as_ref().unwrap();
             let lifetime = s.list_lifetimes[&failed_list];
             assert_eq!(s.submit_pins.get(&(failed_list, lifetime)), Some(&1), "the failed submit stays pinned");
-            assert_eq!(s.last_submit[&failed_list].value, 3);
+            assert_eq!(s.last_submit[&failed_list].value, 4);
         }
 
         let (outer_list, inner_list) = (0x7ffe_6b06usize, 0x7ffe_6b07usize);
         let outer = begin_submit(&[outer_list as *mut c_void]).unwrap().execution_possible();
-        let inner = begin_submit(&[inner_list as *mut c_void]).unwrap().execution_possible();
+        let mut inner = Some(begin_submit(&[inner_list as *mut c_void]).unwrap().execution_possible());
         assert!(super::super::queue_submit::with(first_queue, || {
             outer.finish_with_queue_ops(first_queue, || unreachable!(), |_, outer_value| {
-                assert_eq!(outer_value, 4);
+                assert_eq!(outer_value, 5);
                 assert!(super::super::queue_submit::with(first_queue, || {
-                    inner.finish_with_queue_ops(first_queue, || unreachable!(), |_, inner_value| {
-                        assert_eq!(inner_value, 5, "same-thread re-entry reserves a distinct value");
+                    inner.take().unwrap().finish_with_queue_ops(first_queue, || unreachable!(), |_, inner_value| {
+                        assert_eq!(inner_value, 6, "same-thread re-entry reserves a distinct value");
                         true
                     })
                 }));
@@ -1909,7 +2088,7 @@ mod tests {
         {
             let g = STATE.lock().unwrap();
             let s = g.as_ref().unwrap();
-            assert_eq!((s.last_submit[&outer_list].value, s.last_submit[&inner_list].value), (4, 5));
+            assert_eq!((s.last_submit[&outer_list].value, s.last_submit[&inner_list].value), (5, 6));
         }
 
         let (reused_list, reused_queue) = (0x7ffe_6b03usize, 0x7ffe_6b04usize);
@@ -2026,12 +2205,14 @@ mod tests {
         assert!(second_receipt.is_complete());
 
         let failed = begin_submit(&[failed_list as *mut c_void]).unwrap().execution_possible();
+        let mut failed_values = Vec::new();
         assert!(failed
             .finish_with_queue_ops_receipted(queue, || unreachable!(), |_, value| {
-                assert_eq!(value, 1);
+                failed_values.push(value);
                 false
             })
             .is_none());
+        assert_eq!(failed_values, [1, 2]);
         let (marker, submit, second_submit) = {
             let mut g = STATE.lock().unwrap();
             let s = g.as_mut().unwrap();

AI use: Codex (GPT-6.2 Sol) investigated, wrote the candidate and regressions, and ran the checks; Codex (GPT-6.2 Astra) independently reviewed the low-level lifetime and retry paths.

@Kalmarv

Kalmarv commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

merge-check
base: beeb81b (mergeable cleanly on current main)
head: a54edd3
merge: clean
build: cargo check -p xcl --all-targets -> ok
tests: non-GPU lib tests of touched module (bind 17 passed). Full workspace suite and device/GPU tests not run.
review: none blocking. UPLOAD-heap indirect arguments are staged into scratch only on tracked DIRECT recordings, offsets/sizes are overflow-checked, and blocks without a completion fence are quarantined. Note minor behaviour change: ExecuteIndirect with a null argument buffer now counts as skipped mesh work and warns instead of returning silently.
performance: one copy per staged indirect mesh draw; no regression seen in combined run. Tested in a combined 600 s retail run on main beeb81b + 13 PRs (warm cache, defaults) vs baseline: presents/2 s 3.27 vs 3.29, peak commit 35,016 vs 35,767 MB, local video memory 14.19-14.76 vs 14.32-14.95 GB, 0 pipeline waits >= 1 s vs 5, 0 device removals, 0 crashes. Combined result across all 13 PRs, not isolated to this PR.
verdict: not yet: full workspace suite, device tests, and per-PR visual check not run.
hardware / tool and model: NVIDIA GeForce RTX 5070 Ti, driver 32.0.16.1074, AMD Ryzen 9 9950X, Windows 11 Pro 26200 / Claude Code (claude-opus-5-5)

@github-actions github-actions Bot added area:d3d12 D3D12.X runtime, command lists, resources, sparse memory area:docs-ci Documentation, scripts, workflows, repo governance 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) labels Nov 29, 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 of current head a54edd37. The current begin_submit/backing pin corrects the earlier premature allocator-reuse concern for tracked direct recordings; the follow-up review confirms that correction. I found no new source-level blocker in that ownership route. The critical unverified cases are an ExecuteIndirect count/argument buffer rewritten during recording, failed fence creation or Signal, and allocator reset before submission. Please keep exact-head GPU fixtures for those paths and report retained bytes after a transient failure, since deliberate retention is the remaining memory cost. No local Windows run.

@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Review (head a54edd3, diff read, not a merge-check; draft, so not built or run):

  • Too big and mixed: 655 lines (about 360 tests) combining checked offsets for every ExecuteIndirect, validation moved before recording, and the upload staging itself; worth splitting. The overflow skip (bind.rs ~3692) runs before draw_pipeline, so an overflowing dispatch or PC ExecuteIndirect is logged as "two-pass ExecuteIndirect skipped" and counted in DRAWS_SKIPPED.
  • The new default path was never run end to end. It's on by default (the allocator pool is on unless XCL_ALLOC_SWAP=0), but the GPU tests only cover record_scaled_sources / prepare_scaled_sources_in in isolation; nothing drives execute_indirect_snapshot through records_for and run_two_pass_plan with upload sources, and no title was run.
  • if max == 0 { return; } (~3729) drops the draw count, the render-target note and the flush of deferred draws that main does, and args == 0 is now counted as skipped (bookkeeping only).
  • UNFENCED_UPLOADS (~93, ~621) is never emptied; it only fills when a submit gets no fence, so rare.
  • Overlaps open D3D12.X: copy out-of-window two-pass indirect arguments into the window #3079. AI use names no Claude model; no full suite or smoke runs at this head.

Fine: the copy is recorded on the GPU, so it reads the upload buffer at execution time as native ExecuteIndirect does; an upload buffer's GENERIC_READ already allows copying from it; the source buffers are held until the fence completes or the allocator is reset; the copies and the doubled rewritten arguments use separate scratch spans.

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

@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Test report (not a merge-check: draft, PR description red)
base: b2b1f10
head: a54edd3
merge: clean (no textual conflict)
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> the lib test target doesn't compile on the merge: error[E0428], set_test_console_buffer is defined twice in crates/xcl/src/hle/d3d12x/real.rs (main's at ~505, (res, range: Option<(usize, usize)>); this PR's at ~2315, (res, entry: Option<(usize, usize)>)). Main added the same test helper after this PR's base, so the rebase should keep one (and the callers' meaning of the tuple: range vs entry). No tests ran.
review: not repeated here; my review of this same head is at #3105 (comment), and its findings stand. This run adds what reading couldn't: whether the change merges, builds and passes the whole suite on current main.
performance: not measured.
assessment: needs a rebase onto current main that keeps one set_test_console_buffer; the findings in my review stand
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.

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 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