Skip to content

D3D12.X: the depth plane of an R24G8 buffer has a twin, drawn into the plane before its DSV is bound - #3089

Open
imnicho wants to merge 3 commits into
xcl-dev:mainfrom
imnicho:depth-plane-twin-r24g8
Open

imnicho wants to merge 3 commits into
xcl-dev:mainfrom
imnicho:depth-plane-twin-r24g8

Conversation

@imnicho

@imnicho imnicho commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

With XCL_DEPTH_UAV_TWIN_R24=1, the depth twins reach the depth target a retail title's lighting draws test (#970): the depth plane of an R24G8 buffer gets a twin the title's compute program can write, and the twin is drawn into the plane before the buffer's DSV is bound. The default is unchanged (off).

Rebased onto main and merged with #3290 there, with what the reviews asked for. Three commits on main 493dbd3dd: the merge, and what two reviews of it (as 8de5808d8 and e228ed5da) asked for; the head is a9aa32db5. The old head 3b12e0b25 (on nvidia-dev) is what the reports below from before 1 December tested.

This is not a second twin implementation. main has depth UAV twins (hle/d3d12x/depth_uav.rs, on by default since #3290). This PR adds, inside that module, the one case it still turns away: the depth plane of an R24G8 buffer, which is the buffer the title's lighting uses. Nothing of the existing twins is replaced, and this one has a switch of its own because the others are on by default now.

Plan comment: #970 (comment)

What is in it

On main a UAV of the depth plane of an R24G8 buffer is still a null view ("its depth plane has no twin yet"), and the twins the module makes are copied around the title's transitions into and out of UNORDERED_ACCESS. The title's target is a console D16_UNORM_S8_UINT (console format 118), R24G8 on the PC, and the title keeps it in a depth state while its compute program writes it (@CharlyRien measured that on main with #3287's transitions: the planes are in DEPTH_WRITE or in read states at the bind, never in UNORDERED_ACCESS). So there is no transition to hang a copy on, and a D3D12 copy cannot put a colour texture into a 24-bit plane anyway.

In that module, behind XCL_DEPTH_UAV_TWIN_R24=1:

  1. A twin for the depth plane of an R24G8 buffer. R16 for the console's 16-bit depth formats (118 to 120), R32 for a console D24S8. resolve_uav makes the UAV a view of it.
  2. The step from the twin to the plane where the buffer is used. before_dsv_bind, called from cl_om_set_render_targets, records a pass of XCL's own that writes SV_Depth from the twin into every level and slice of the plane, before the title's bind of a DSV of the buffer. It is left out when this recording of the list already drew the twin into the plane of the same object and no dispatch was recorded and no clear of the twin made since (bind::activity): then nothing wrote the twin.
  3. 16-bit steps, bit for bit. A 16-bit twin is read as a count (R16_UINT) and written as count * (1.0f / 65535), the float 0x37800080. That is the product the title's vertex shader makes for the draw that tests the plane with EQUAL. Read as R16_UNORM the same texel can come out one unit in the last place off, which in 24 bits is another value for some counts.
  4. The title's list state stays the title's. The pass is recorded past XCL's hooks (list_x::depth_only_pass); view heaps, topology, viewports, scissors, blend factor, stencil reference, vertex buffers, render targets and the pipeline the title had set are set again after it.
  5. States. The planes' states are followed as the PC gets the title's transitions in plan_with, with D3D12.X: depth UAV twins on by default, stencil twins copied with the plane #3290's PARK where the title has the buffer in UNORDERED_ACCESS. The pass moves the depth plane to DEPTH_WRITE and back where the title has it elsewhere, and is left out (a line says so) after a transition of part of that plane. It does not move the stencil plane: its DSV names that plane read only where the title has it in DEPTH_READ.

After the reviews:

  1. A clear of the twin makes the next bind draw it again: ClearUnorderedAccessView* writes the twin and bind::activity does not count it (@thehollowedone's first point, with the candidate from that comment).

  2. The pass's views live as long as a recorded list can name them. They are kept one set an object of the buffer, not one a buffer, and the object itself keeps their two descriptor heaps (private data of the PC's object, past XCL's hook) until the PC destroys it. XCL puts that off until the queues are past the work in flight, so a bind of another object of the buffer, or the title's release, no longer frees a heap a recorded pass names (@thehollowedone's second point; the candidate from that comment without the twin, whose own release is put off the same way).

  3. The pass's pipelines are made on a thread of their own, where the twin is made (a title makes that UAV at load), not on the recording thread at the first bind. A bind that comes before they are ready is left out with a line, before the buffer is marked drawn, so the next one draws (@CharlyRien, who saw that first bind wait over 30 s in the driver on a PC short of memory, until the title's watchdog ended it).

  4. What spares a pass is the recording's own. The note that a twin was drawn was the buffer's, set while recording, so a recording that was reset and never submitted spared the next one its pass, and a pass for one object of a buffer spared another's. It is now kept with the list's live recording and the object (list_x::plane_drawn), next to depth_in_step and cleared where that is: at a Reset and at a KickoffX (@thehollowedone, on 8de5808d8).

  5. The pass runs with the title's predicate off. Its draws were recorded while a predicate the title set with SetPredicationBufferX was on, so a failing predicate left the pass undrawn while the recording noted the plane as drawn. depth_only_pass takes the predicate off for its draws and sets it again after them from the list's own copy of the value the title's call latched (pred_buf), not from the title's memory (@thehollowedone, on e228ed5da).

The SV_Depth pass and the 16-bit steps are @raylitebull's, from #1989 and its follow-up on amd-dev (3cda5bea).

Size: 3 files, 575 lines of code and 463 of tests. That is more than a PR should be; about 140 lines of it are points 6 to 10.

Not in it (the module's header says so too):

  • Plane to twin: what a draw or a clear writes into such a plane does not reach the twin. D3D12.X: add depth+UAV color twins, format-aliased placed texture copies, and dual-twin UAV barriers #1989 has that as a compute copy.
  • A shader that samples the plane before the next DSV bind reads what the plane held.
  • Order is the order of recording. A dispatch recorded later on another list and submitted earlier is not seen by the check in 2.
  • A predicate the title sets by the PC's own SetPredication (console slot 31), which XCL passes on without following it, still decides the pass's draws.

Tested

On this head (debug, RTX 5080 16 GB, driver 610.47, Windows 10 22H2):

  • cargo test -p xcl --lib -- --test-threads=1 depth_uav r24g8 twin: 22 passed, 0 failed, no SKIPPED line (17 of the module, 5 on WARP in child processes; the crate's outputs cleaned first: see the note under "Not tested"). cargo test -p xcl --lib -- --test-threads=1 list_x::tests predication: 105 passed, 0 failed.
  • cargo test -p xcl --lib -- --test-threads=4 gives no count on this PC: plain main (d0832e614) ends the test process partway here. After 1,376 tests alloc_pool::tests::a_reset_that_puts_the_allocator_aside_keeps_what_the_gpu_still_reads fails and the process stops with sparse upload preparation still failed after bounded retries – the title is stopped before its GPU submission (exit 0x80004005); one test at a time (--test-threads=1 hle::d3d12x) plain main stops the same way in sparse::tests::a_buffer_over_a_remapped_tile_reads_the_new_page after 739 tests. This PR's first main-based head stopped the same way at four threads. CI has the whole suite. (Correction: this line said before that the head was run one test at a time too. Those two runs were of plain main's binary, not the head's: see the note under "Not tested".)

New and changed tests (WARP, synthetic shaders):

  • gpu_a_depth_twin_is_drawn_into_the_r24g8_plane_before_its_dsv_is_bound: an R32 twin with 256 different values; after the bind hook the plane, read back, holds each within one 24-bit step. A second bind with no dispatch between records no second pass; after a clear of the twin the next bind records one again, and the one after that none; the buffer holds the pass's two heaps, and still holds them after XCL has forgotten it. Then the list is reset: the new recording's first bind draws again, with no dispatch and no clear in between.
  • gpu_an_equal_test_at_a_counts_depth_passes_where_the_16_bit_twin_holds_the_count: a console format 118 buffer, an R16 twin holding a count for each texel, then 18 draws with the depth test EQUAL at count * (1.0 / 65535.0) that count the stencil up. The stencil plane, read back, is 1 on exactly the texels that hold a drawn count and 0 on the others. Twelve of the counts are ones where the product and the correctly rounded count / 65535 are different floats. With the pass changed to read the twin as R16_UNORM (not in the PR) this test fails on WARP at four of them: 385, 898, 1412 and 1924.
  • the_states_of_an_r24g8_buffers_planes_follow_the_titles_transitions, and the format cases in a_depth_view_is_a_view_of_a_twin_of_the_planes_size.
  • Both GPU tests wait for the pass's pipelines first, as a title's load does in effect (27 ms on WARP here).

In the title, on this head: not run by me (see "Not tested"). What there is:

  • @CharlyRien (RTX 3090, main 7a649b0 with D3D12.X: depth UAV twins on by default, stencil twins copied with the plane #3290's stencil half and other changes, the first version ported, Series X size): the class buffer's depth plane (2560x1440) goes from one value to 38 distinct ones, among them exactly the 24-bit values of the title's permutations; the bright 128-px cells of the tiled lighting go from 3 to 0 at two times in two runs; at least 512 passes on that one buffer, 0 binds left without one, no device loss in 320 s of world. (The clean window of that report was withdrawn by its author: it came from that run's set-up.)
  • On the first version (nvidia-dev), mine (RTX 5080, Series S profile, the tree of my #1989 report): without it the room after the opening cutscene stays unlit in 3 of 3 runs; with it the room is lit in 3 of 3, one of them 600 s with 679 frames after the world's set-up and 1,024 passes logged, about two a frame. A version of the pass that moved both planes to DEPTH_WRITE lost the device in 4 of 4 runs, which is why the stencil plane is not moved.
  • Tests of the first version on other hardware, in the comments: RTX 5070 and RTX 3080 Ti (@andrewDoing, @thehollowedone), RTX 3070 (@upipibi), RX 7900 XT / RADV and GTX 1070 under Wine (@SlopTart).

Regression run

scripts/smoke.ps1, 60 s, XCL_PREPARE=0, each built in release from a clean worktree. The switch is off in these runs, as it is by default.

main (d0832e614):

xcl-smoke v1
commit: d0832e614fa7d6ae027bb4feb27ccb9121f54a8f
gpu: NVIDIA GeForce RTX 5080
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1560 (PresentX 1560)
presents per 2 s (last 3): 62 62 62
device removals: 0
crashes: 0
peak commit: 12450 MB

This PR (a9aa32db5):

xcl-smoke v1
commit: a9aa32db588abd94983482346bc2d06b44d46acf
gpu: NVIDIA GeForce RTX 5080
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1551 (PresentX 1551)
presents per 2 s (last 3): 61 60 60
device removals: 0
crashes: 0
peak commit: 12833 MB

Three kept runs of this binary gave 1,110, 1,551 and 1,533 frames; the block is the second. The first came straight after an hour of long title runs on this PC, the other two a few minutes later. (A new binary's very first run fills its caches and is not kept, as for main.)

Not tested

  • The title's world on this head. This PC's caches are of the nvidia-dev tree, and main builds every pipeline anew; the 60 s runs above do not reach the buffer. A run of mine on main with this head will follow as a comment.
  • Points 6 to 9 in a title: they have the WARP test's checks only. Point 10 has no test of its own: no GPU case here binds the DSV under a failing predicate (@thehollowedone's suggested regression); the list and predication tests of main pass with it. A bind left out while the pipelines are being made has no test (the test waits for them).
  • The D3D12 debug layer on this head: Windows refuses it here without its Graphics Tools feature. @thehollowedone (WARP and RTX 3080 Ti) and @andrewDoing (WARP, two levels, three initial states) ran the first version's GPU cases under it with zero errors.
  • AMD and Intel GPUs and Linux / Wine on this head.
  • A buffer of several slices on a GPU, and on this head one of several levels or one whose stencil plane the title has in DEPTH_READ (the read-only DSV): this PR's unit tests cover the states and the arithmetic only. On the first version @andrewDoing's fixture had two levels and a stencil plane in DEPTH_READ on WARP, and @CharlyRien's run had the planes in read states (0x8e0) at binds.
  • The integration test binaries of crates/xcl/tests (each d3d12_* one takes about 9 minutes here).
  • A note on my own numbers: I build several worktrees into one target folder, and today cargo twice called a test binary of another worktree up to date. That is how the wrong line above came about, and the regression block of 8de5808d8 that stood here was from a build I cannot vouch for either. Every count on this page now is from a build whose log names this worktree as compiled, with the crate's outputs cleaned first.
  • The cost of the pass by itself (one full-screen draw and two barrier calls a bind).

AI use

Claude Code with Claude Fable 5.2 wrote the code and the tests, ran the suite and the regression runs, and wrote this description.

🤖 Generated with Claude Code

@andrewDoing

Copy link
Copy Markdown
Contributor

I checked two previously untested boundaries at head aca8939c6bafe53492a8dd4ee21e6d3c8789b795 with test-only fixtures.

Native precision, RTX 5070 / NVIDIA 616.92. The same instrumented binary ran the 18-draw EQUAL/stencil oracle on a 16×16 console D16S8 target in four fresh processes: the PR's R16_UINT conversion and a test-only R16_UNORM/float alternative, each on the RTX and on WARP. All 256 stencil bytes matched for both conversions on the RTX. On WARP, the PR conversion matched all 256, while the alternative had four mismatches (counts 385, 898, 1412, 1924). This independently reproduces the WARP distinction; on this RTX and sampled count set, both conversions matched. It does not establish equivalence for all counts.

Two mips, WARP + D3D12 debug layer. Distinct patterns in two mips of an R32 twin produced the expected D24 depth values, within one quantization step, for all 256 base-mip and 64 second-mip texels under each initial state: both planes DEPTH_WRITE, the whole resource DEPTH_READ, and only stencil mip 0 DEPTH_READ. All three fresh-process runs had zero debug errors.

The two-mip check covers one array slice and depth-plane readback; it does not verify stencil contents or physical GPU behavior for that case. Neither fixture is a retail title or performance test.

AI use: OpenAI Codex with GPT-6.2 Astra built and ran the fixtures; Codex reviewed and prepared this report.

@imnicho

imnicho commented Nov 28, 2026

Copy link
Copy Markdown
Contributor Author

CI: the "Build and test" job's 2 failures are the base's, not this PR's. The run shows 1771 passed, 2 failed, 28 ignored. The two are texture_upload::tests::gpu_parts_of_a_texture_go_up_and_the_rest_stays and pieces_hold_the_texels_of_their_levels ("attempt to multiply with overflow" in the tests' generator), which fail the same way on nvidia-dev ba9d1f947 without this change (run locally, in the description) and which #2771 fixes. This PR's 11 tests pass in that run.

AI use: Claude Code with Claude Fable 5.2 read the CI log and wrote this.

@SlopTart

Copy link
Copy Markdown

Real-GPU counts for this PR from both Linux/Wine lanes. Heads-up first: we ran head aca8939c (sha checked inside the run); the head has since moved to 3b12e0b2, which we have not run.

Hardware

  • rig1: Ryzen 9 9900X, 96 GB DDR5, RX 7900 XT (Navi 31), Mesa 26.2.5 RADV, wine 11.0 (proton build)
  • rig2: i5-10600K, 16 GB DDR4, GTX 1070, nvidia 550.163.01, wine 10.0 under xvfb

Filters depth_uav, depth_twin, r24g8, each twice per lane: default (switch off) and with XCL_DEPTH_UAV_TWIN=1:

filter rig1 off rig1 on rig2 off rig2 on
depth_uav 21 passed 21 passed 21 passed 21 passed
depth_twin 1 passed 1 passed 1 passed 1 passed
r24g8 2 passed 2 passed 2 passed 2 passed

That set includes the five real::depth_uav_twin_tests::gpu_* tests, which ran against real GPUs on both lanes (GTX 1070 and Navi 31), not a software rasterizer. Zero failures anywhere, with the twin switch on or off. Nothing overlaps the three failures the author logged on lavapipe (the two texture_upload overflows from #2771 and the Kickoff flake).

Tested: the 24 matching tests per lane per switch setting at aca8939c.
Not tested: the new 3b12e0b2 head, full suite on this head, native Windows, retail titles.
AI use: Hermes agent (local Qwen-class) ran the tests and drafted this; I checked it before posting.

@thehollowedone

Copy link
Copy Markdown
Contributor

Independent Windows check of #3089 head 3b12e0b: I ran the two new depth-plane GPU readback cases on both WARP and an RTX 3080 Ti (driver 621.35). Each case passed on each adapter: 4/4 focused runs, zero skips. The 16-bit case exercised the depth EQUAL/stencil readback; the other checked all 256 depth texels.

For this check I made a local test-only fixture change: enable the D3D12 debug layer before creating the device, require an ID3D12InfoQueue, select the high-performance NVIDIA adapter for the native runs, and inspect the queue after each GPU fence/readback. All four runs had zero ERROR or CORRUPTION messages, and the device stayed healthy. The published PR fixture otherwise selects WARP, so an environment switch alone would not establish native-GPU coverage. I removed the local fixture change after testing.

Command for each case: cargo test --offline --locked -j 4 -p xcl --lib <test name> -- --nocapture --test-threads=1, repeated with XCL_TEST_NATIVE_GPU=1 in the temporary fixture for the RTX runs. Windows build 26300, rustc 1.99.1. I did not run the full workspace suite or a title with this switch enabled; this is focused synthetic coverage.

AI use: Codex (GPT-6.2 Sol) prepared the fixture and ran these tests.

@SlopTart

Copy link
Copy Markdown

Follow-up to my earlier row on this PR: we re-ran at the new head 3b12e0b2 (sha checked inside the run) on both Linux/Wine lanes with real GPUs - rig1 (RX 7900 XT, Mesa 26.2.5 RADV, wine 11.0) and rig2 (GTX 1070, nvidia 550.163.01, wine 10.0/xvfb).

Same as aca8939c: filters depth_uav (21 tests), depth_twin (1), r24g8 (2), each with XCL_DEPTH_UAV_TWIN unset and set to 1 - 24/24 green on both lanes, both switch positions, zero failures. The five real::depth_uav_twin_tests::gpu_* ran against actual NVIDIA and AMD hardware again.

Tested: the 24 matching tests per lane per switch setting at 3b12e0b2.
Not tested: full suite at this head, native Windows, retail titles.
AI use: Hermes agent (local Qwen-class) ran the tests and drafted this; I checked it before posting.

@thehollowedone

thehollowedone commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

merge-check
base: 54225f5 (nvidia-dev)
head: 3b12e0b (3b12e0b)
merge: clean, three files, +858/-33

Windows results. cargo build --offline --locked -j 4 --workspace passed on the merged tree. With XCL_DEPTH_UAV_TWIN=1, cargo test --offline --locked -j 4 -p xcl --lib depth_uav -- --test-threads=1 passed 21/21, zero skips. The unmodified merged tree's cargo test --offline --locked -j 4 --workspace --no-fail-fast -- --test-threads=4 finished 1,909 passed / 4 failed / 48 ignored, with 26 explicit SKIPPED notices included in Cargo's passing counts. Failures were console_mesh_caches_hlsl_compute_pass_in_memory_and_on_disk, a_held_submit_goes_on_when_the_hold_ends_and_at_once_inside_a_timed_call, a_thread_in_the_driver_is_seen_until_it_returns (all also failed in my earlier full run on this exact base), and an_address_keeps_the_page_the_title_mapped_there_last (passed a subsequent isolated 1/1 rerun). CI is green at this head; my local full suite is not.

verdict: not yet

Review verdict: not yet. I found two boundaries outside the existing GPU fixtures:

  1. A clear can leave the depth plane stale. A successful ClearUnorderedAccessViewFloat of the R24 depth twin changes its contents without advancing bind::activity().1. On the same direct list, the second DSV bind therefore skips the draw. I extended the existing WARP readback fixture locally: first bind, clear the twin to 0.25, second bind, fence, read back the depth plane. The unchanged head failed 0/1 in the child process (0x0 at texel 0, expected 0x400000); the candidate below passed 1/1 in the child and 1/1 in the parent, with no skips. This local test-only overlay should become a separate regression so the original 256-distinct-texel fixture remains intact.
  2. A second alias can release a heap still used by a recorded draw. before_dsv_bind replaces the one PassViews when a DSV of another resource at the same cell is bound. I added a synthetic WARP ownership diagnostic: record A's pass, advance dispatch activity, record B's pass before submission, then inspect A's descriptor-heap COM reference count. On the unchanged merged head it failed 0/1 in both child and parent: 2 → 1 while A's pass was still recorded. The test holds the final reference so the measurement itself remains safe. This establishes a lifetime violation; it is not a GPU readback or a title result. D3D12 command lists do not retain referenced objects.

Locally tested candidate for point 2. Keep immutable views per native destination in the cell, and attach the SRV heap, DSV heap and twin to that destination under distinct private GUIDs with SetPrivateDataInterface. Check each result, reuse an existing destination's views, and clone the pass owner across recording. res_release calls forget before delayed native release, so the destination attachment must outlive removal from XCL's cell map. On this candidate the same diagnostic passed 1/1 in child and parent; a further assertion after explicit forget(A) also passed while the native destination remained alive. With XCL_DEPTH_UAV_TWIN=1, cargo test --offline --locked -j 4 -p xcl --lib depth_uav -- --test-threads=4 passed 22/22, zero failures, zero ignored, zero skips. The added diagnostic uses a synthetic activity increment, not an actual dispatch. A fenced two-alias GPU readback and debug-layer check, the full suite, and paired title smoke remain to test on a production change.

Local candidate diff for the alias lifetime (including test hook)
diff --git a/crates/xcl/src/hle/d3d12x/depth_uav.rs b/crates/xcl/src/hle/d3d12x/depth_uav.rs
index fe7e9eb5..014f27d0 100644
--- a/crates/xcl/src/hle/d3d12x/depth_uav.rs
+++ b/crates/xcl/src/hle/d3d12x/depth_uav.rs
@@ -104,7 +104,7 @@ struct Inner {
     /// [depth, stencil]
     twins: [Option<Twin>; 2],
     /// an R24G8 buffer's depth twin: the views `before_dsv_bind` draws it into the plane with
-    pass: Option<PassViews>,
+    passes: HashMap<usize, PassViews>,
     /// `bind::activity`'s count of dispatches when the twin was last drawn into the plane
     drawn_at: Option<u64>,
 }
@@ -265,7 +265,7 @@ fn register(res: usize, x: &[u8; 0x38], at: Option<usize>, pc_state: u32) -> boo
             Default::default()
         }
         // (an object XCL did not see released: its membership goes back)
-        Some(old) => leave(cells, &old.cell),
+        Some(old) => leave(cells, &old.cell, res),
     };
     drop(g);
     drop(gone);
@@ -289,13 +289,14 @@ pub(super) fn by_address<R>(f: impl FnOnce() -> R) -> R {
 /// One object of `cell` is gone; the last one takes the Cell with it, and its twins, which the
 /// caller drops outside every lock (their Release goes through `real::res_release`).
 #[must_use]
-fn leave(cells: &mut HashMap<Key, Arc<Cell>>, cell: &Arc<Cell>) -> [Option<Twin>; 2] {
+fn leave(cells: &mut HashMap<Key, Arc<Cell>>, cell: &Arc<Cell>, res: usize) -> [Option<Twin>; 2] {
     let mut inner = cell.inner.lock().unwrap();
+    inner.passes.remove(&res);
     inner.members = inner.members.saturating_sub(1);
     if inner.members == 0 && cells.get(&cell.key).is_some_and(|c| Arc::ptr_eq(c, cell)) {
         cells.remove(&cell.key);
         // (views and heaps of the PC's own, not adopted: their release calls nothing of XCL's)
-        (inner.pass, inner.drawn_at) = (None, None);
+        (inner.passes, inner.drawn_at) = (HashMap::new(), None);
         return std::mem::take(&mut inner.twins);
     }
     Default::default()
@@ -308,7 +309,7 @@ pub(super) fn forget(res: usize) {
     }
     let Some(o) = OBJECTS.remove(res) else { return };
     REGISTERED.fetch_sub(1, Ordering::Relaxed);
-    let gone = CELLS.lock().unwrap().as_mut().map(|cells| leave(cells, &o.cell));
+    let gone = CELLS.lock().unwrap().as_mut().map(|cells| leave(cells, &o.cell, res));
     drop(gone);
 }
 
@@ -644,13 +645,20 @@ fn note_plane_state(o: &Object, b: &[u32; 8]) {
 /// its own, and a DSV of each level and slice of the depth plane of the object `of` (level `m`,
 /// slice `a` at `m * array + a`), then each once more with the stencil plane read only. Heaps
 /// of the PC's own, not adopted.
+#[derive(Clone)]
 struct PassViews {
-    of: usize,
     srv_heap: ID3D12DescriptorHeap,
     dsv_heap: ID3D12DescriptorHeap,
     dsv_inc: usize,
 }
 
+#[cfg(test)]
+pub(super) fn pass_heap_for_test(res: usize) -> Option<ID3D12DescriptorHeap> {
+    let o = OBJECTS.get(res)?;
+    let inner = o.cell.inner.lock().unwrap();
+    inner.passes.get(&res).map(|p| p.srv_heap.clone())
+}
+
 // D3D12 objects are free-threaded
 unsafe impl Send for PassViews {}
 unsafe impl Sync for PassViews {}
@@ -814,7 +822,20 @@ unsafe fn make_pass_views(dev: *mut c_void, of: usize, twin: &ID3D12Resource, ke
             }
         }
     }
-    Some(PassViews { of, srv_heap, dsv_heap, dsv_inc })
+    Some(PassViews { srv_heap, dsv_heap, dsv_inc })
+}
+
+/// A recorded command list borrows descriptors and resources. Keep each pass's dependencies
+/// until its destination is actually destroyed, including when XCL defers that destruction.
+unsafe fn retain_pass_views(of: usize, pass: &PassViews, twin: &ID3D12Resource) -> bool {
+    let raw = of as *mut c_void;
+    let Some(dest) = ID3D12Resource::from_raw_borrowed(&raw) else { return false };
+    let srv = windows::core::GUID::from_u128(0x913c5c24e9c34f0a8c7ae2e36c3caeaf);
+    let dsv = windows::core::GUID::from_u128(0xf0a0bb4d165848bcaa00708b334aaee7);
+    let tex = windows::core::GUID::from_u128(0x6c51e87a5ead4deb89e3755c69fad178);
+    dest.SetPrivateDataInterface(&srv, &pass.srv_heap).is_ok()
+        && dest.SetPrivateDataInterface(&dsv, &pass.dsv_heap).is_ok()
+        && dest.SetPrivateDataInterface(&tex, twin).is_ok()
 }
 
 /// Before OMSetRenderTargets binds the DSV at `dsv` on `list` (`real::cl_om_set_render_targets`).
@@ -851,7 +872,7 @@ pub(super) unsafe fn before_dsv_bind(list: *mut c_void, dsv: usize) {
     if state[0] == STATE_UNKNOWN {
         return left("the title moved a part of the depth plane to a state of its own");
     }
-    let (twin, n, dev, srv_heap, table, dsv_base, dsv_inc) = {
+    let (twin, n, dev, srv_heap, table, dsv_base, dsv_inc, _pass) = {
         let mut inner = cell.inner.lock().unwrap();
         let Some(t) = inner.twins[0].as_ref() else { return };
         if inner.drawn_at == Some(now) {
@@ -859,16 +880,21 @@ pub(super) unsafe fn before_dsv_bind(list: *mut c_void, dsv: usize) {
             return;
         }
         let (twin, n, dev) = (t.res.clone(), t.n, t.dev as *mut c_void);
-        if inner.pass.as_ref().map(|p| p.of) != Some(d.res) {
-            inner.pass = make_pass_views(dev, d.res, &twin, &key, r16);
+        if !inner.passes.contains_key(&d.res) {
+            let Some(pass) = make_pass_views(dev, d.res, &twin, &key, r16) else {
+                drop(inner);
+                return left("its views could not be made");
+            };
+            if !retain_pass_views(d.res, &pass, &twin) {
+                drop(inner);
+                return left("its views could not be retained");
+            }
+            inner.passes.insert(d.res, pass);
         }
-        let Some(p) = inner.pass.as_ref() else {
-            drop(inner);
-            return left("its views could not be made");
-        };
+        let p = inner.passes.get(&d.res).unwrap().clone();
         let views = (p.srv_heap.as_raw() as usize, p.srv_heap.GetGPUDescriptorHandleForHeapStart().ptr, p.dsv_heap.GetCPUDescriptorHandleForHeapStart().ptr, p.dsv_inc);
         inner.drawn_at = Some(now);
-        (twin, n, dev, views.0, views.1, views.2, views.3)
+        (twin, n, dev, views.0, views.1, views.2, views.3, p)
     };
     let Some(pl) = pass_pipelines(dev) else { return left("the pass could not be made") };
     let (mips, array) = (key.mips.max(1) as u32, key.array.max(1) as u32);
Locally verified candidate for the clear path
@@ clear_target(res, named) in depth_uav.rs
-    let twins = o.cell.inner.lock().unwrap().twins.each_ref().map(|t| t.as_ref().map(|t| t.res.as_raw() as usize));
+    let mut inner = o.cell.inner.lock().unwrap();
+    let twins = inner.twins.each_ref().map(|t| t.as_ref().map(|t| t.res.as_raw() as usize));
     let c = clear_choice(twins, named);
+    if let Clear::Twin(t) = &c {
+        if o.cell.key.format == 44 && twins[0] == Some(*t) {
+            inner.drawn_at = None;
+        }
+    }

No paired title smoke or performance run in this check. Host: Windows 11 build 26300, Ryzen 7 9800X3D, RTX 3080 Ti (621.35), rustc 1.99.1; the focused depth fixture used WARP. AI use: Codex (GPT-6.2 Sol) inspected the paths, wrote and ran the local regression and candidate; Codex (GPT-6.2 Astra) independently reviewed the lifetime and state boundaries.

@upipibi

upipibi commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

Test report for #3089 on NVIDIA: the whole workspace suite on this PR merged onto today's nvidia-dev and on nvidia-dev alone, and the PR's own tests 3 times by name.

Tested

  • Base: nvidia-dev 54225f5884a94cd23b7aab3f703a7c975070aa77. Head: 3b12e0b2593c0a22ac1d787987686f68e54a2863. git merge --no-ff of the head onto the base: clean, no conflicts (list_x.rs auto-merged); the merge (7112ec86, local) differs from the base by 3 files, +858/-33.

  • RTX 3070 8 GB (Ampere, 32-lane waves), driver 616.56, Windows 11 Pro 10.0.26100, Rust 1.100.0 MSVC, debug. Each tree in its own worktree and target dir; XCL_DEPTH_UAV_TWIN not set.

  • cargo build --workspace and cargo build --workspace --tests: both exit 0 on both trees, 9 and 10 warnings, the same count as the base.

  • cargo test --workspace --no-fail-fast -- --test-threads=4, once on each tree. On both trees the xcl library binary stopped partway through, before printing its result. It exited with code 130088963 (0x7C10003) after D3D12.X: coherent window could not be restored at ... (268435456 bytes, got 0x0, Windows error 487) after CreateCommandQueue: ... (0x8007000E); stopping before guest memory is used, which a uma_driver mixed-window test prints. The other 39 result lines:

    • merge: 132 passed, 0 failed, 20 ignored, 26 SKIPPED lines;
    • base: 132 passed, 0 failed, 20 ignored, 26 SKIPPED lines; the same per-binary results as the merge.
    • Before the stop, the library binary printed 4 FAILED lines on the merge and 5 on the base: the 4 title_textures tests below on both, plus hle::d3d12x::list_x::tests::mid_list_write64_wait64_split_avoids_cycle_and_reuses_spares on the base only. That test passed in the base's 3 library re-runs and 3 of 3 times alone, and it passed in the merge's run.
  • Because of that stop, the library binary was run again on each tree with the two mixed-window tests skipped: cargo test -p xcl --lib -- --test-threads=4 --skip hle::d3d12x::uma_driver::tests::a_refused_gpu_upload_segment_becomes_custom --skip hle::d3d12x::uma_driver::tests::mixed_window_keeps_its_bytes_and_the_gpu_sees_every_segment:

    • merge: 1773 passed, 6 failed, 28 ignored (2 filtered out), 26 SKIPPED lines;
    • base: 1770 passed, 6 failed, 28 ignored (2 filtered out), 26 SKIPPED lines, the same in 3 runs.
    • The 6 failures have the same names on both trees: hle::d3d12x::title_textures::tests::placed_title_textures_share_vram_and_preserve_pixels, …stream_recheck_keeps_the_whole_upload_baseline_over_partial_uploads, …stream_recheck_partial_upload_without_an_entry_queues_a_whole_upload, …stream_recheck_schedule_catches_late_writes_and_resets_milestones, hle::d3d12x::vram::tests::d32s8_targets_take_their_own_size_of_video_memory and …gpu_retire_queue_holds_heap_until_blocked_queue_passes_mark. Three panic on 0x8007000E (E_OUTOFMEMORY) from a D3D12 call, and the other three stream_recheck_* ones on a PoisonError after those panics. All 6 pass alone, one at a time, 3 of 3 times on the base.
    • The two skipped mixed-window tests pass alone on both trees: 2 passed, 0 failed, 3 of 3 times each (--exact --test-threads=1).
    • Together with the other 39 result lines of the workspace run: merge 1905 passed, 6 failed, 48 ignored, base 1902 passed, 6 failed, 48 ignored. The difference of 3 is the PR's added tests: the merge lists 1809 library tests, the base 1806.
  • The 26 SKIPPED lines are the same on both trees: 21 "no wave64", 3 f16/f32 per-lane forms refused after gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426, 1 "no heap windows", 1 "cannot disable the driver cache".

  • None of the 9 tests in main e429936 on NVIDIA: 3 e2e title tests and 6 split-wave64 GPU tests fail since #2959 #3093 fail here. The 5 split-wave64 tests present on nvidia-dev and the 3 e2e title tests pass on both trees; gpu_heap_flat_reads_match_guarded_and_root_output is not in nvidia-dev's test list.

  • The PR's own tests, by exact name, 3 runs: cargo test -p xcl --lib -- <the 7 names> --exact --test-threads=1 --nocapture. 7 passed, 0 failed, 0 ignored in each of the 3 runs, 0 SKIPPED lines:

    • hle::d3d12x::depth_uav::tests::a_depth_uav_of_a_kept_buffer_asks_for_a_twin
    • hle::d3d12x::depth_uav::tests::the_states_of_an_r24g8_buffers_planes_follow_the_titles_transitions
    • hle::d3d12x::depth_uav::tests::a_depth_view_is_a_view_of_a_twin_of_the_planes_size
    • hle::d3d12x::real::depth_uav_twin_tests::gpu_a_depth_twin_is_drawn_into_the_r24g8_plane_before_its_dsv_is_bound
    • hle::d3d12x::real::depth_uav_twin_tests::gpu_an_equal_test_at_a_counts_depth_passes_where_the_16_bit_twin_holds_the_count
    • hle::d3d12x::real::depth_uav_twin_tests::gpu_a_stencil_uav_of_a_console_depth_buffer_is_a_view_of_its_twin
    • hle::d3d12x::real::depth_uav_twin_tests::gpu_clear_uav_of_a_stencil_uav_clears_the_twin

    The four real::depth_uav_twin_tests::gpu_* tests each ran in their own child process, which printed its own 1 passed, and their fixture makes its device on WARP. So these runs do not test the twins on the RTX 3070 itself.

Not tested

  • No xcl-smoke block: no title was run.
  • XCL_DEPTH_UAV_TWIN=1: every run here had the switch unset.
  • The PR's GPU tests on the RTX 3070 rather than WARP.
  • A release build, AMD or Intel GPUs, Linux / Wine.

AI use: Claude Code (Claude Opus 5.5) ran the tests above on the hardware named and wrote this report.

@CharlyRien

Copy link
Copy Markdown
Contributor

Tested on the retail title, RTX 3090, Windows 11, with XCL_DEPTH_UAV_TWIN=1. Result: it fixes the 128-px light squares in
that title's tiled lighting, and a half-black window view that came from the same lighting pass.

Stack (exact)

  • Base: main at 7a649b0 (the merge of D3D12.X: register x64 .pdata unwind info for stub and guard thunks #936), plus 28 local commits.
  • On top:
    • 3b12e0b of this PR, cherry-picked, with two adaptations for that base:
    • A change to when the pass's pipelines are made (see the second comment).
    • An env-gated texture dump at a present, used for the readings below.
  • Run env, the same in both runs except the last three items:
    • XCL_ALIAS_COPY=1 XCL_HEAP_WINDOWS=1 XCL_UMA_WINDOWS=16 XCL_PLACE_RETIRE=0 XCL_VIEW_REACH_MB=36 XCL_PREPARE=0
    • XCL_TWO_PASS_MB=2048 XCL_HUGE_PSO_CONCURRENCY=8 XCL_HUGE_PSO_WANTED_CONCURRENCY=8 XCL_PSO_WAIT_MS=5000
    • the dump switches
    • baseline: without this PR and without XCL_DEPTH_UAV_TWIN.

Read

The title's tiled lighting draws each material permutation as a separate full-tile pass, with an EQUAL depth test and no
depth write. The test runs against a class buffer: console D16S8, R24G8 on the PC. A compute program writes that buffer's
depth plane as z = permutation / 65535, through a UAV of the depth buffer.

The title keeps the buffer in DEPTH_WRITE while the compute program writes it. There is no transition into or out of
UNORDERED_ACCESS. So the copies at transitions (#1989, and #3290's stencil copies) never move anything for this plane, and
the switch alone changed nothing. Your pass at the DSV bind is what reaches it.

Measured

  • The class depth plane (2560x1440), dumped at a present in the world, about 390 s into the run:
    • baseline: 1 distinct value, 0. The stencil plane is also all 0.
    • with the PR: 38 distinct values, 22.2 % of texels non-zero. The most common:
      • 0 (2.87 M texels);
      • 0xffffff (295 k);
      • 0x000700 (252 k) and 0x000500 (189 k), exactly the 24-bit values of permutations 7 and 5;
      • 0x001a00, 0x000400, 0x001e00, … (permutations 26, 4, 30, …).
    • The stencil plane now has 10 values.
  • The pass ran at least 512 times, all on that one buffer. 0 binds were left without a pass. At the bind, the title had
    the depth plane either in read states (0x8e0) or in DEPTH_WRITE (0x10).
  • The picture (bright 128-px cells in the right third of the frame, at 360 s and 400 s):
    • baseline: 3 at both times, in two runs;
    • with the PR: 0 at both times.
    • The pose is the same: phase correlation on the edges of that area gives a (0, 0) px shift against both baseline runs.
    • Outside the cells and outside a window view, the mean |difference| is 4–13. A same-pose witness pair gives 10–14.
  • What else changed in the picture:
    • the wall around the old cells is a bit darker (luma ×0.79–0.84). Deduced: tiles of those materials are now lit as
      themselves, not as permutation 0;
    • a window view that showed a large black diagonal triangle is now drawn in full. Share of frames at that pose where
      more than 20 % of the window box is black:
      • with this PR and XCL_DEPTH_UAV_TWIN=1: 1 of 27 (4 %);
      • the same stack with XCL_DEPTH_UAV_TWIN=1 but without this PR: 72 of 72;
      • baseline without both: 18 of 18.
        So the switch alone does not do it; this PR's pass does. Read: the frame's only R24G8 buffer is this class buffer, and
        the window's own draws test against a different depth buffer (D32S8). Deduced: the black triangle is the tiled
        lighting's output over that area, not the glass draws.
  • Stability: 0 device-removed lines, 0 Close E_INVALIDARG. It ran to the end of the measure (320 s after the world).

Deduced

Without the plane, only permutation 0 (z = 0) passed EQUAL. A tile of one other material alone was then never shaded, and
kept whatever its lighting targets held before: the bright or black squares.

Not covered

  • Other titles, and AMD hardware.
  • What a draw or a clear writes into such a plane does not reach the twin. Your "Not in it" already says so; this title
    never does it.

Found and written with Claude Code (Claude Opus 5.5), checked and posted by me.

🤖 Generated with Claude Code

@CharlyRien

Copy link
Copy Markdown
Contributor

Review note: the pass pipelines are made at the first DSV bind, on the recording thread

pass_pipelines compiles the three programs and makes the root signature and both pipelines at the first bind of an R24G8
DSV. That runs on the title's thread that records the list, under the PASS_PIPELINES mutex.

On the retail title (same stack and env, RTX 3090) that call stayed in the driver for more than 30 s:

  • the thread dump at the end shows the recording thread inside the driver's shader-cache code;
  • there were no presents after the world was reached;
  • the title's own watchdog ended the process about 32 s after the last present.

None of 13 runs of the same stack and env without this PR stopped that way.

When the pipelines were made off that thread, the same build step took 36,958 ms. That was on RTX 3090, with the system at
high memory use; it is not a property of the shaders.

The change we ran (on top of 3b12e0b):

  • the first R24G8 depth twin, which a title makes when it creates the UAV (at load here), starts pass_pipelines on a
    thread of its own, once per device;
  • before_dsv_bind only does try_lock. While the pipelines are not made, it leaves that bind with a reason ("its
    pipelines are still being made") before it sets drawn_at, so a later bind draws;
  • a log line gives the time the pipelines took;
  • the two WARP tests wait for the pipelines first (a test-only pass_made).

In that run the pipelines were ready about 74 s before the first bind that needed them, and 0 binds were left waiting. I
can share it as a patch here, or open it as a follow-up PR on top of yours, whichever you prefer.

Found and written with Claude Code (Claude Opus 5.5), checked and posted by me.

🤖 Generated with Claude Code

@CharlyRien

Copy link
Copy Markdown
Contributor

Correction to my test report above: the window part was wrong. Same binary and env as that run, minus two diagnostic dump switches (XCL_RT_DUMP, XCL_RT_DUMP_ONLY, which only record tables before their capture time): the half-black window is back, 65 % of the window box black from 250 s on, the same as without this PR. A run with this PR plus the skinned characters fixed shows it too (64 %). So the clean window came from that one run's setup, not from this PR; I don't know yet what made it clean there.

The light squares result stands: 0 bright cells again in this run (3 without the PR).

AI use: found and written with Claude Code (Claude Opus 5.5), checked and posted by me.

@CharlyRien

Copy link
Copy Markdown
Contributor

This now conflicts with main (after #3290 was merged). The R24G8 depth-plane pass is still needed for the light squares on the retail title: #3290 alone turns the twins on but does not fill the class plane at the DSV bind. Our stack, rebased onto main d52ff48, carries a port of 3b12e0b on top of #3290 (stencil_twinnable replaced by #3290's parked), RTX 3090; the first-bind pipeline note from my earlier comment still applies.

Would you rebase it onto current main? I can then post a test report on the new head.

AI use: found and written with Claude Code (Claude Opus 5.5), checked and posted by me.

@imnicho
imnicho force-pushed the depth-plane-twin-r24g8 branch from 3b12e0b to 8de5808 Compare November 30, 2026 23:54
@github-actions github-actions Bot added area:d3d12 D3D12.X runtime, command lists, resources, sparse memory gpu:nvidia Code is specific to NVIDIA / wave32 GPUs (scope tag; see needs:nvidia-test) labels Nov 30, 2026
@imnicho

imnicho commented Nov 30, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto main and merged with #3290: new head 8de5808d8 (one commit; the old head on nvidia-dev was 3b12e0b25). @CharlyRien, thank you for the port notes and the measurements; it builds on main d0832e614 now, and a report on the new head would be very welcome.

  • A switch of its own. The other twins are on by default since D3D12.X: depth UAV twins on by default, stencil twins copied with the plane #3290, so this one is behind XCL_DEPTH_UAV_TWIN_R24=1. Without it an R24G8 buffer's depth UAV is the null view it is on main, and nothing of this PR runs.
  • @thehollowedone, point 1 (a clear leaves the plane stale): in, as in your candidate. The WARP test clears the twin and checks that the next bind draws again.
  • @thehollowedone, point 2 (a second alias releases a heap a recorded draw names): in, after your candidate: the views are kept one set an object, and the object keeps the two heaps as private data, set by the PC's own call past XCL's hook (which takes a title's call for a reason not to recycle the object). I left the twin out of what is attached: its own release already goes through late_release. The test checks that the buffer holds both heaps, also after forget.
  • @CharlyRien (the first bind waited over 30 s in the driver): the pipelines are made on a thread of their own where the twin is made, and a bind that comes before they are ready is left out before drawn_at is set, so the next one draws. I wrote it from your description, not from your patch, so please check it against what you ran. On WARP here the pipelines take 27 ms.
  • States: note_plane_state records what the PC gets in plan_with, PARK included, as in your port.

Tested on the new head: 22 depth-twin tests passed (5 of them on WARP in child processes), and the regression runs in the description (1,465 frames against main's 1,560 in 60 s, switch off). The whole library suite gives no count on this PC: plain main ends the test process partway here (details in the description), so CI is the suite's word on this head.

Not run by me: the title's world on this head, for the same reason as on #3094 (my caches are of the nvidia-dev tree). That run is next, and I will post it here.

AI use: Claude Code with Claude Fable 5.2 did the merge and the changes and wrote this comment.

🤖 Generated with Claude Code

@thehollowedone

Copy link
Copy Markdown
Contributor

Source follow-up on current head 8de5808d: the earlier clear invalidation and descriptor-heap lifetime points are addressed in the new code. I found one recording-lifetime case that the new tests do not cover.

drawn_at belongs to the shared buffer cell, and before_dsv_bind sets it while recording. Once the pass pipelines are ready, record a DSV bind on a direct list, close the list, then reset it without submitting that recording. Bind the same DSV in the new recording without another dispatch or clear. The first recording left drawn_at == Some(now), so the new bind skips the pass, although no pass from the discarded recording can execute. Submitting the second recording can leave the depth plane stale. A second destination object sharing the cell has the same problem because drawn_at is not keyed by destination.

Please elide a pass only when a pass for that destination was recorded earlier in the same live command-list recording, with no intervening twin write. Reset or discard must clear that proof; the existing clear path must still invalidate it. A focused regression can close and reset an unsubmitted list, bind the same DSV, submit, and compare a fenced depth readback with the twin's known values. The current WARP fixture covers sequential binds, clear routing and heap retention, but not a discarded recording.

This is a source trace on the exact head; I did not run a GPU or title test of it. AI use: OpenAI Codex (GPT-6.2 Sol) checked the current source and discussion; OpenAI Codex (GPT-6.2 Astra) independently traced the reset and resource lifetimes.

KDenKC added a commit to KDenKC/xcl that referenced this pull request Dec 1, 2026
…t drawn into the plane), not for a PR

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
imnicho and others added 2 commits December 1, 2026 08:39
…e plane before its DSV is bound

A retail title's tiled lighting tests a console D16_UNORM_S8_UINT buffer
(R24G8 on the PC) with EQUAL, after a compute program wrote a count for
each pixel into its depth plane through a UAV. The title keeps the buffer
in a depth state all the while, so no transition says when the plane was
written, and a D3D12 copy cannot put a colour texture into a 24-bit plane.

With XCL_DEPTH_UAV_TWIN_R24=1 (off by default; the other depth twins stay
as they are) the depth plane of an R24G8 buffer gets a twin in depth_uav:
R16 for the console's 16-bit depth formats, else R32. resolve_uav makes
the title's UAV a view of it, and before_dsv_bind draws it into the plane,
by a pass of XCL's own that writes SV_Depth, before the title's bind of a
DSV of the buffer, when a dispatch was recorded since the buffer's last
pass. A 16-bit twin is read as a count and written as count * (1.0f /
65535), the product the title's vertex shader makes. The planes' states
are followed as the PC gets the title's transitions (PARK where the title
has the buffer in UNORDERED_ACCESS); the pass moves the depth plane to
DEPTH_WRITE and back and does not move the stencil plane.

After review of the first version on nvidia-dev:
- a clear of the twin makes the next bind draw it again (thehollowedone);
- the pass's views are kept one set an object of the buffer, and the
  object itself keeps their two heaps until the PC destroys it, so a
  recorded list never names a heap that is gone (thehollowedone);
- the pass's pipelines are made on a thread of their own where the twin
  is made, not on the recording thread at the first bind; a bind that
  comes before they are ready is left out and the next one draws
  (CharlyRien).

The SV_Depth pass and the 16-bit steps are raylitebull's, from xcl-dev#1989 and
its follow-up on amd-dev (3cda5be).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…t drew it

After the review of 8de5808 (thehollowedone): the note that a buffer's
twin was drawn into its plane was the buffer's, set while recording. A
recording that was reset and never submitted then spared the next
recording its pass, and a pass for one object of a buffer spared another
object's.

The proof is now the list's live recording's and the object's
(list_x::plane_drawn): which object's plane was drawn, at which count of
dispatches and of clears of the twin. A Reset and a KickoffX clear it, as
they clear depth_in_step. The WARP test resets its list and binds again:
the new recording draws.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@imnicho
imnicho force-pushed the depth-plane-twin-r24g8 branch from 8de5808 to e228ed5 Compare December 1, 2026 07:54
@imnicho

imnicho commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

New head e228ed5da (rebased onto main 493dbd3dd; the second commit is this round).

@thehollowedone, the recording-lifetime case on 8de5808d8 is right, and it is in: what spares a pass is no longer a note on the buffer's Cell. It is kept with the list's live recording and the object whose plane was drawn (list_x::plane_drawn: the object, the count of dispatches recorded, the count of clears of the twin), next to depth_in_step and cleared where that is cleared, at a Reset and at a KickoffX. So a recording that is reset and never submitted spares nothing, and a pass for one object of a buffer does not spare another's. The clear path now counts clears instead of resetting the note, so it still invalidates.

The WARP test follows your regression as far as the bind: after its first recording it resets the list and binds the same DSV with no dispatch and no clear in between, and the new recording draws. It does not submit that second recording and read the plane back; the first recording's readback is what it had.

Tested on the new head: 22 depth-twin tests passed (5 on WARP in child processes), and the regression run in the description (1,321 frames against main's 1,560 in 60 s, switch off).

A correction to the description of 8de5808d8. It said the head was also run one test at a time with the same stop as plain main. Those two runs were of plain main's test binary: I build several worktrees into one target folder, and cargo called the other worktree's binary up to date. The regression block that stood there came from a build I cannot vouch for either. Both are replaced; every count on the page now is from a build whose log names the worktree as compiled, with the crate's outputs cleaned first. The four-thread result (the suite ends the test process on this PC, on plain main and on the head alike) was from the right binaries.

Still not run by me: the title's world on main with this head, for the reason on #3094 (two tries today stopped drawing about 30 s after the world's set-up behind first-time driver compiles; I am warming the caches).

AI use: Claude Code with Claude Fable 5.2 wrote the changes and this comment.

🤖 Generated with Claude Code

@thehollowedone

Copy link
Copy Markdown
Contributor

Follow-up on current head e228ed5d. The reset fix addresses the earlier recording-lifetime finding; this is a separate predication case.

depth_only_pass issues DrawInstanced while the title's predicate may still be active, then before_dsv_bind records the plane as drawn. A false predicate can suppress the helper draw. If the title then disables predication and binds the same DSV again in that recording, the cached plane_drawn state can skip the still-needed pass. Microsoft lists DrawInstanced among predicable commands and documents that SetPredication snapshots the 64-bit value when executed (predication contract).

The helper needs to run with predication disabled, then restore the title's already-latched value. Console slot 85 already snapshots its predicate into a private buffer (snapshot path); console slot 31 maps directly to PC SetPredication (slot mapping). Any fix needs to preserve the snapshot for both entry paths; rebinding the guest source can sample a changed value.

Suggested regression: bind the DSV under a suppressing predicate, change the predicate buffer afterward, and verify the internal depth copy executes while a subsequent title draw remains suppressed. Submit and read back the depth plane. This is a source review; I did not run the GPU test.

AI use: OpenAI Codex (GPT-6.2 Sol) traced the current source; OpenAI Codex (GPT-6.2 Astra) checked the D3D12 contract and both predicate entry paths.

@Foniass

Foniass commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Triage (#1607) – head a9aa32d

Main's depth_uav module (#3290) still returns a null view for the depth plane of an R24G8 buffer. This PR adds that case behind XCL_DEPTH_UAV_TWIN_R24=1, with a plane-only pass before the DSV bind (list_x::depth_only_pass) and per-recording plane_drawn state. Nothing like it is on main.
#1989 also gives the R24G8 depth plane a twin with an SV_Depth pass (this PR takes its pass from there), but #1989 is a separate 4.3k-line twin system written before #3290 and now conflicts. These are different approaches, not duplicates. #3480 and #1063 do not touch the R24G8 plane.
No problems found in the diff. It is over the size target (575 lines of code plus tests), and the description says so.
Recommendation: keep open.

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

After the review of e228ed5 (thehollowedone): the pass's draws were
recorded while a predicate the title set with SetPredicationBufferX was
on, so a failing predicate left the pass undrawn while the recording
noted the plane as drawn. depth_only_pass takes the predicate off for its
draws and sets it again after them from the list's own copy of the value
the title's call latched (pred_buf), not from the title's memory.

A predicate the title sets by the PC's own SetPredication, which XCL
does not follow, still decides the pass's draws.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@imnicho

imnicho commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor Author

New head a9aa32db5 (one more commit on the same base).

@thehollowedone, the predication case on e228ed5da is right: the pass's draws were recorded with the title's predicate still on, and a failing one left the plane undrawn while the recording noted it as drawn. depth_only_pass now takes a predicate set with SetPredicationBufferX off for its draws and sets it again after them from the list's own copy of the latched value (pred_buf), so the title's later draws see what its call latched, whatever its memory holds by then.

Two things it does not do, both in the description:

  • A predicate set by the PC's own SetPredication (console slot 31) is passed on without XCL following it, so it still decides the pass's draws. Following that path means snapshotting it as slot 85 is, which is a change to how main treats slot 31 for every title, and I would rather not make it inside this PR.
  • No GPU case of mine binds the DSV under a failing predicate; your suggested regression is not written. What ran: the 22 depth-twin tests (5 on WARP) and main's 105 list and predication tests, all passing on a clean build.

Regression run in the description: 1,551 frames against main's 1,560 in 60 s (three runs of the binary gave 1,110, 1,551 and 1,533; the first came straight after an hour of long title runs here).

A word on scope, said with thanks for the findings on this PR and on #3094, every one of them real: this PR has grown from 437 to 575 lines of code by taking them. Where a further case is a defect in what the PR does today I will keep fixing it here; where it is a wider model (submission order, slot 31's predicate), I think it belongs in a follow-up, and I am glad to review or write one.

AI use: Claude Code with Claude Fable 5.2 wrote the change and this comment.

🤖 Generated with Claude Code

@Foniass

Foniass commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

merge-check
base: 493dbd3
head: a9aa32d
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2903 passed, 0 failed, 51 ignored; SKIPPED: 28 (20 no wave64, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 1 no heap windows, 1 cannot disable the driver cache, 3 others; the same set as on main); failing: none
review: read the whole diff (+1038/-38). The twin is an R16 / R32 texture the title's compute program writes through its UAV, drawn into the depth plane by an SV_Depth pass at each DSV bind. Off by default (XCL_DEPTH_UAV_TWIN_R24); the default path gains an atomic check per OMSetRenderTargets with a DSV, note_plane_state stores on depth-buffer transitions, and one Arc per depth object. The run below has a second smoke with the switch on, which in 60 s doesn't reach the world's lighting. Findings, switch on: (1) The pass can overwrite the plane. It redraws after any dispatch recorded anywhere (depth_uav.rs ~1043, a global count), and nothing copies the plane to the twin, so depth the title drew or cleared since the last pass is lost. The retail title survives because its compute program rewrites the twin each time; another title with such a buffer would have its depth corrupted. #1989 and #3480 both copy plane to twin; worth taking. (2) Stencil plane state (~1101): the pass binds a DSV with writable stencil unless the stencil plane's state includes DEPTH_READ. In PARK (0x800), SRV-only or unknown states that breaks D3D12's state rules; the debug layer wasn't run on this head, and moving the stencil plane lost the device in 4 of 4 runs. (3) The R32 path reads the twin as float (~971) while a title's R32_UINT UAV is kept as uint (no title reaches it). (4) The 16-bit step constant 0x37800080 (~845) is fitted to one title's vertex shader. (5) Tests: the switch defaults to on under cfg!(test) (~59-62), and the existing default-path check (depth UAV stays a null view) was rewritten to expect a twin (real.rs ~14965), so the off path now has no test. The predication fix has none either, and the hook at real.rs ~11403 is called by no test. (6) Cost when on: one full-screen draw per level and slice per bind plus a descriptor-heap switch, unmeasured; one twin per buffer (7-15 MB at 1440p). (7) 1,038 lines with no reason given for not splitting: plane-state tracking first, then depth_only_pass and predication with a test, then the R24 twin and switch. Fine: heaps live as long as a recorded list can name them, what spares a pass is per recording and cleared at Reset / KickoffX, pipelines are built on their own thread, the predicate is restored from the list's latched copy, and the switch-off resolve_uav path is unchanged.
performance: 60 s smoke of a retail title, main 493dbd3 vs this merge (a9aa32d): 1670 -> 1682 frames shown (100 %; last presents per 2 s: 60 60 60), peak commit 17083 -> 17343 MB, 0 device removals, 0 crashes. A second 60 s run of the same merge with XCL_DEPTH_UAV_TWIN_R24=1: 1694 frames shown (last presents per 2 s: 61 60 60), peak commit 17325 MB, 0 device removals, 0 crashes. Its log shows only the existing R16 twins of 768x768x6 D16 buffers and no R24 twin, so the new pass isn't used in 60 s; its pipeline is still built at 16 s, taking 7.6 s on its own thread.
verdict: not yet: with the switch on, the pass can overwrite depth the title drew or cleared since the last pass (no plane-to-twin copy, finding 1), and the stencil-plane state can break D3D12's rules (finding 2); the switch-off path also lost its test (finding 5). Split as suggested
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.

@imnicho

imnicho commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

@Foniass thank you for the read and the second regression run.

On the findings, on a9aa32db5:

  1. Nothing takes the plane to the twin: right. The pass goes one way only. As you say, it is enough for the title it was written on only because that title's compute program writes the twin again each time; a title that draws or clears the plane and then reads the twin would read what the twin held before. The way back cannot be a copy for D24S8 (no unordered access on R24_UNORM_X8), so it is a second small pass, as in D3D12.X: add depth+UAV color twins, format-aliased placed texture copies, and dual-twin UAV barriers #1989 and D3D12.X: draws that test a depth buffer left in UAV get its twin first #3480.
  2. The stencil plane's state: right that the rule is only "writable unless DEPTH_READ is among its states"; a plane parked in COPY_SOURCE or in a state XCL does not know gets a DSV that says it may be written. The debug layer was not run on this head (it is not installed here).
  3. Right, and unreached: no title I have gives an R32_UINT view of such a plane.
  4. Right: it is the step that title's vertex shader makes of a 16-bit depth, and the description should say so in those words.
  5. Tests: right. The switch is on under cfg!(test), so the null-view case of the default path lost its test when I rewrote that one, and the predicate's move around the pass has only the predication tests of list_x that were there before.
  6. No measure from me of the pass's cost.
  7. The split you lay out is the right one.

What I will do, and one thing I would like settled first. The draft #3547 brings amd-dev's depth work, which has its own SV_Depth pass for an R24G8 plane that compute programs write (execute_r24g8_copy in its depth_uav.rs). I would rather not put this PR in front of reviewers again, as three new PRs, if main is about to get that. So I am holding the fixes for findings 1, 2 and 5 and the split until it is clear whether #3547 goes in; if it does not, I will push them as (a) the plane's state, (b) the pass and the predicate with a test of their own, (c) the R24 twin and its switch, with the default path's test back. Meanwhile this machine (RTX 5080) is running #3547's branch, where results on NVIDIA were asked for.

Nothing was built or run for this comment.

AI use: Claude Code with Claude Fable 5.2 read the review against the code and wrote this comment.

🤖 Generated with Claude Code

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 gpu:nvidia Code is specific to NVIDIA / wave32 GPUs (scope tag; see needs:nvidia-test)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants