Skip to content

D3D12.X: a superseded target the title binds, clears or moves is mapped again - #3192

Open
Kalmarv wants to merge 1 commit into
xcl-dev:mainfrom
Kalmarv:standby/retire-use-nv
Open

Kalmarv wants to merge 1 commit into
xcl-dev:mainfrom
Kalmarv:standby/retire-use-nv

Conversation

@Kalmarv

@Kalmarv Kalmarv commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

A placed render target or depth buffer that a newer placement supersedes (placements.rs, XCL_PLACE_RETIRE, on by default) has its tiles unmapped once the queues have passed, and placements::note_use maps them again when the title uses it again. A use was only seen in a legacy ResourceBarrier and in the copies. A title that moves its textures with the barrier groups of list slot #146 and then binds and clears such a target was never seen: the target stayed without tiles, every write to it was dropped and every read of it returned 0.

A use is now also a texture barrier in list #146's groups, OMSetRenderTargets with its RTVs or DSV, ClearRenderTargetView and ClearDepthStencilView. All of them record into a list, so the mapping is queued before that list's submit waits for the tile mappings (vram::before_execute). An RTV or DSV the title copies (CopyDescriptorsSimple, CopyDescriptors) names what its source names, as one made at that handle does: otherwise a bind or clear through a copied view looks up what the destination handle named earlier (@andrewDoing's controls below). The handles of both kinds are kept in placements, not looked up in present's table of RTVs, which holds nothing with present = "off" (@thehollowedone's reproduction below).

Related: #3179 does the same for textures bound through descriptor tables. This PR is the other side, the calls that write a target; neither covers the other's calls. Both add placements::any_superseded(), so whichever is merged second needs a rebase that keeps one copy; I will do that for this one.

What is in it

  • hle/d3d12x/placements.rs: any_superseded() (one atomic load: the calls below do nothing more while no target is superseded) and the RTV and DSV handles of placed textures (note_view, note_view_use, views_copied: one table of addresses, no references held). Unit test a_view_handle_names_the_placed_texture_it_was_last_made_of (made at a handle, copied to it, copied from a handle that names nothing).
  • hle/d3d12x/list_x.rs: uav_barrier_x (list Compute dispatches: a shader takes no more arguments from user SGPRs than it has (XboxBvhBuilder builds empty BLAS / TLAS) #146) notes the textures of its texture barrier groups (barrier_group_textures: read only while a target is superseded, every group of the call and every barrier of a group, groups that are not readable memory are passed over); clear_depth_stencil_x notes its DSV. Unit test the_texture_barriers_of_barrier_groups_name_their_textures (a 257th group and a 4,097th barrier among them).
  • hle/d3d12x/real.rs: cl_om_set_render_targets notes the RTVs the list now holds and its DSV, cl_clear_rtv its RTV, dev_create_rtv and dev_create_dsv_x feed the handle table; the two descriptor copy hooks pass RTV and DSV copies to it (target_views_copied, ranges walked by depth_uav::pieces, which is pub(super) for it). GPU tests superseded_target_tests::gpu_a_superseded_render_target_the_title_binds_clears_or_moves_is_mapped_again (R32_FLOAT) and gpu_a_superseded_depth_buffer_the_title_binds_or_clears_is_mapped_again (D16): they place a target on title pages, place a smaller one over its last page so that it is superseded and loses its tiles, call each hook on an adopted list (one bind through an RTV copied with CopyDescriptorsSimple, one clear through a DSV copied with CopyDescriptors), and require the target to have tiles again after each call and to read back the value it was then cleared to. The render-target test first drops present's entries of its RTVs, which is what present = "off" leaves. They print SKIPPED without tiled resources.

Tested

  • The head is ee8bb3d since 2026-11-28 21:25Z (review changes). The suite, GPU-test and regression-run lines below name 2d632bd, the head before it, and are being rerun. On ee8bb3d so far (debug, RTX 5070 Ti and WARP): cargo test -p xcl --lib -- superseded_target a_view_handle the_texture_barriers copy_descriptors_remaps --test-threads=1: 6 passed, 0 failed on each; the same tests on the runtime code of 2d632bd (superseded_target the_texture_barriers): 2 passed, 2 failed on each.
  • NVIDIA GeForce RTX 5070 Ti 16 GB (driver 610.74), Ryzen 9 9950X, Windows 11 Pro 26200, Rust 1.99.0 MSVC, debug tests (CARGO_PROFILE_DEV_DEBUG=0), release smoke; DXC 1.9.2609 via XCL_DXC_DIR.
  • cargo build --workspace && cargo test --workspace --no-fail-fast -- --test-threads=4 --skip a_refused_gpu_upload_segment_becomes_custom --skip mixed_window_keeps_its_bytes_and_the_gpu_sees_every_segment --skip failed_restore_stops_before_importing_an_unbacked_window on 2d632bd: 2594 passed, 1 failed, 49 ignored. The same command on main 765b2c5b: 2590 passed, 1 failed, 49 ignored. The three skipped uma_driver tests ended the lib test process on NVIDIA on nvidia-dev 54225f5, which main now contains (reported on [OFFICIAL] Merge queue: which PRs can be merged next, and how to claim a merge check #3041; Tests: the mixed-window remake tests run in a child process #3187).
  • Failed here and on 765b2c5b as well: a_preparation_worker_also_builds_a_split_programs_whole_form.
  • 26 SKIPPED: 8 no wave64; 1 const_mask, wave64: no wave64; 1 f32 arithmetic, wave64: no wave64; 1 f16 arithmetic, wave32, per-lane form: refused (unsupported V_MUL_F16 (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's)); 1 f16 arithmetic, wave64: no wave64; 1 f16 packed, wave32, per-lane form: refused (unsupported V_PK_MUL_F16: VOP3 modifiers (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's)); 1 f16 packed, wave64: no wave64; 1 f32 compares, wave64: no wave64; 1 integer arithmetic, wave64: no wave64; 1 f64, wave64: no wave64; 1 mask_ff0_flbit, wave64: no wave64; 1 f32 conversions, wave32, per-lane form: refused (unsupported V_CVT_F16_F32 (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's)); 1 f32 conversions, wave64: no wave64; 1 integer carries, wave64: no wave64; 1 f32 rounding, wave64: no wave64; 1 f32 transcendentals, wave64: no wave64; 1 f32 three-source, wave64: no wave64; 1 no heap windows (opt-in: XCL_HEAP_WINDOWS=1); 1 no heap windows.
  • The two GPU tests and placements::tests::a_superseded_target_used_again_is_mapped_again, release (cargo test --release -p xcl --lib superseded_target -- --test-threads=1) on 2d632bd: 3 passed, 0 failed on the RTX 5070 Ti (3 runs, 0 skipped) and 3 passed, 0 failed on WARP (XCL_ADAPTER=warp, 0 skipped).
  • On the earlier head 843d868, the same command with the new note calls taken out (WARP): 1 passed, 2 failed, with still without tiles after ["OMSetRenderTargets", "ClearDepthStencilView", "ClearDepthStencilView with a copied DSV"] and still without tiles after ["OMSetRenderTargets", "OMSetRenderTargets with a copied RTV", "ClearRenderTargetView", "a texture barrier in list #146's groups"].
  • On 843d868, the same command with the copies not followed (target_views_copied returning at once, WARP): 1 passed, 2 failed, with still without tiles after ["ClearDepthStencilView with a copied DSV"] and still without tiles after ["OMSetRenderTargets with a copied RTV"].

Regression run
150 s runs after the startup shader preparation, same title, same env (XCL_UMA_WINDOWS=16 XCL_HEAP_WINDOWS=1 XCL_DIRECT_DXIL=all XCL_DIRECT_SPLIT_INSTRUCTIONS=0 XCL_PSO_JOURNAL=0 XCL_DRED=1 XCL_GPU_WAIT_TIMEOUT_MS=120000, DXC 1.9), the same graphics pipeline history at the start. main's run uses a DXIL cache precompiled for it (xcl shaders --precompile --pipelines --used-only --windows 16), the head's a hard-link copy of that folder taken after main's run.

The two runs below are not of the same scene, so their frame and commit lines do not compare. The harness presses the gamepad at times counted from the process start (the last at 197 s). main's run prepared shaders for 459 s, so no press reached the title and ended with 1440 textures and 6186 MB of video memory on the first screen; the head's run prepared for 166 s (the driver blobs were on disk by then), got the presses and ended with 57719 textures and 14045 MB of video memory in the loaded world. A main run that gets the presses as well is pending; the PR description check stays red on the frame and commit comparison until it replaces the first block.

main (daae0330, the parent of merge 765b2c5 that has its tree):

xcl-smoke v1
commit: daae0330b95c43b868f8957c29dc4ccae90ac8ef
gpu: NVIDIA GeForce RTX 5070 Ti
title: ea3b5e4d
seconds: 150
exit: 0x0
frames shown: 4377 (PresentX 4377)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15676 MB

This PR's head:

xcl-smoke v1
commit: 2d632bd2ac4f3492f886a92424189c9b51530538
gpu: NVIDIA GeForce RTX 5070 Ti
title: ea3b5e4d
seconds: 150
exit: 0x0
frames shown: 1868 (PresentX 1868)
presents per 2 s (last 3): 34 4 1
device removals: 0
crashes: 0
peak commit: 28646 MB

The head's run does not show the change being reached: its log has no a superseded texture is used again line (main's: 0). The run of this PR's earlier head fe9039d on nvidia-dev 54225f5 (4 UMA windows, no startup preparation) had 64 such lines (the log prints at most 64), 16-bit depth targets and R32_UINT targets with unordered access; why this run has none was not looked into.

Not tested

  • What this changes in the title's picture: no frames were compared.
  • Frame rate: the runs above are single runs, not timing runs.
  • The head against main in the same scene, and the change being reached in a title run on main (see Regression run).
  • An RTV copied with CopyDescriptors and a DSV copied with CopyDescriptorsSimple in this PR's tests: they take the other pairing, and both hooks go through the same target_views_copied (@andrewDoing ran both pairings on 2d632bd, the head before this one). Whether the title copies RTVs or DSVs at all was not counted.
  • A run with present = "off" set in a title's config: the GPU test only empties present's table (@thehollowedone's child-process test with the setting was not taken).
  • A descriptor heap released while its handles are in the table, and a placed texture made at a released one's address: entries are addresses, and go when their handle is written again.
  • AMD, Intel, Wine; titles other than ea3b5e4d.

AI use

  • Claude Code (Claude Fable 5) wrote the change and its tests, ran the suite and the regression runs on the hardware above, and wrote this description.

🤖 Generated with Claude Code

@andrewDoing

Copy link
Copy Markdown
Contributor

Copied DSVs can remap the previous destination resource. At fe9039deefe2cc15c2916380367202294b1705c7 on RTX 5070 12 GB / 616.92, I created D16 depth targets A and B in separate address ranges, superseded each with its own placement, and confirmed both were unmapped. The destination DSV initially named A and the source DSV named B.

How the destination was changed to B Mapped after binding the destination with OMSetRenderTargets
CreateDepthStencilView for B directly at the destination B only
CopyDescriptorsSimple from the source A only
CopyDescriptors, one source and one destination range of size 1 A only

I then explicitly remapped both resources using direct descriptors before any GPU write. A clear of A to 0.25 followed by a clear of the replaced destination to 0.75 gave fenced D16 readbacks of 0x4000 for every texel of A and 0xbfff for every texel of B (262,144 texels per target). This confirms the native copied handle names B even when the placement bookkeeping remaps A. Six fresh processes, zero skips; no write to an unmapped resource.

Both copy hooks already forward DSV changes to depth_uav; keeping the placement DSV association in sync there as well would address this case. No retail workload tested.

AI use: OpenAI Codex (GPT-6) prepared and ran the test-only fixture and wrote the report.

@andrewDoing

Copy link
Copy Markdown
Contributor

RTVs are affected too at fe9039deefe2cc15c2916380367202294b1705c7 on RTX 5070 / 616.92. RTVs use the existing present::rtv_resource association, separate from the new DSV table.

I repeated the DSV replacement control with two independent R32_FLOAT targets. After both were superseded and unmapped, recreating B's RTV at A's former handle and binding it through OMSetRenderTargets remapped B only. Replacing that same handle via CopyDescriptorsSimple or CopyDescriptors (one range, one descriptor) instead remapped A only; B remained unmapped.

Before each GPU write I restored both targets through direct handles. A clear of A to 0.25 followed by a clear of the replaced destination to 0.75 gave 0.25 on A and 0.75 on B across all 262,144 texels of each, for all three replacement methods. Six fresh processes, zero skips. The copied native RTV thus points at B while the bind's resource lookup still selects A. Both RTV and DSV copy bookkeeping merit coverage when fixing the destination association. No title run or unmapped write.

AI use: OpenAI Codex (GPT-6) prepared and ran the native controls and wrote this follow-up.

@Aniseto

Aniseto commented Nov 28, 2026

Copy link
Copy Markdown

Ran the superseded-target remapping tests at fe9039de on an NVIDIA Blackwell desktop part; both GPU tests ran here, with no SKIPPED line.

System

  • GPU: NVIDIA GeForce RTX 5070 Ti (Blackwell, 32-lane waves only, mesh shaders), driver 32.0.16.2124
  • CPU: Intel Core i5-12400F, 64 GB RAM
  • OS: Windows 11 Pro build 26200 x64
  • Toolchain: rustc 1.100.0 (0ef1bc386 2026-11-09), MSVC 14.44.35207, DXC 1.9.2609.5
  • Build: debug

Results

  • XCL_ADAPTER=NVIDIA cargo test -p xcl --lib gpu_a_superseded_render_target_the_title_binds_clears_or_moves_is_mapped_again -- --test-threads=1: 1 passed, 0 failed, 0 ignored.
  • XCL_ADAPTER=NVIDIA cargo test -p xcl --lib gpu_a_superseded_depth_buffer_the_title_binds_or_clears_is_mapped_again -- --test-threads=1: 1 passed, 0 failed, 0 ignored.

What this adds
Both device-backed tests pass on tiled resources: a superseded render target and depth buffer get their tiles mapped again after the title binds, clears or moves them. The thread has no comments yet, so this is the first datapoint in it and the first from an RTX 5070 Ti. These are synthetic device tests, not a title run.

Not tested
A retail title, a paired smoke run, the full workspace suite, AMD and Intel GPUs, native wave64 hosts, Wine, release profile, game data.

AI-assisted (OpenCode), model: DeepSeek V4.1 Flash Free - ran the commands above on this machine and wrote this report; no game data was used.

@andrewDoing

Copy link
Copy Markdown
Contributor

A candidate fix for the copied-RTV/DSV remapping findings is included below. It applies to fe9039deefe2cc15c2916380367202294b1705c7 with git apply. Both native copy hooks propagate the source association to the destination and clear a stale destination when the source has no association. Ranged copies follow the existing range walker with the device's increment for that heap type. The RTV table takes its own COM reference and releases displaced resources after unlocking.

On Windows with an RTX 5070 12 GB, direct recreation, CopyDescriptorsSimple, and CopyDescriptors now remap B only when the destination changes from A to B. All 12 fresh-process RTV/DSV bind and fenced readback controls passed. With a valid source view absent from XCL's lookup table, the stock head wrongly remapped A in all four view/API combinations. The patch leaves A unmapped in all four. Every clear reached the live native source resource (16,384/16,384 pixels per case).

The 13 placement tests passed, including the added CPU regression with different source/destination range boundaries, two untracked sources and an untouched gap. The existing depth-twin descriptor-copy control also passed. Native ranged controls used a single range; the multi-range result is from the CPU test. Scope was synthetic descriptor copying and remapping. Full workspace and title runs were outside this check.

Applyable four-file patch including regression test
--- a/crates/xcl/src/hle/d3d12x/real.rs
+++ b/crates/xcl/src/hle/d3d12x/real.rs
@@ -2373,6 +2373,20 @@
     }
 }
 
+/// Native RTV/DSV copies change the resource named at the destination just like recreating the view.
+unsafe fn copy_target_views(ty: u32, n: u32, dst: u64, src: u64, inc: u64) {
+    if ty == D3D12_DESCRIPTOR_HEAP_TYPE_RTV.0 as u32 {
+        super::present::copy_rtvs(n, dst, src, inc);
+    } else {
+        super::placements::copy_dsvs(n, dst, src, inc);
+        super::depth_uav::copy_dsvs(n, dst, src, inc);
+    }
+}
+
+fn is_target_heap(ty: u32) -> bool {
+    ty == D3D12_DESCRIPTOR_HEAP_TYPE_RTV.0 as u32 || ty == D3D12_DESCRIPTOR_HEAP_TYPE_DSV.0 as u32
+}
+
 /// #24 CopyDescriptorsSimple(n, dst, src, type)
 unsafe extern "system" fn dev_copy_descriptors_simple_x(this: *mut c_void, n: u32, dst: u64, src: u64, ty: u32) {
     let _t = crate::hle::api_cost::time_if(super::look_stats::deep(), crate::hle::api_cost::Call::ViewDescriptor);
@@ -2385,8 +2399,9 @@
         note_mixed_copy();
         return;
     }
-    if ty == D3D12_DESCRIPTOR_HEAP_TYPE_DSV.0 as u32 {
-        super::depth_uav::dsvs_copied(this, n, dst, src);
+    if is_target_heap(ty) {
+        let inc = dev_increment_size_x(this, ty) as u64;
+        copy_target_views(ty, n, dst, src, inc);
     }
     let f: unsafe extern "system" fn(*mut c_void, u32, u64, u64, u32) = std::mem::transmute(orig_fn(this, 24));
     f(this, n, dst, src, ty);
@@ -2405,8 +2420,14 @@
             note_mixed_copy();
             return;
         }
-        if ty == D3D12_DESCRIPTOR_HEAP_TYPE_DSV.0 as u32 {
-            super::depth_uav::dsv_ranges_copied(this, nd, dsts, dsizes, ns, srcs, ssizes);
+        if is_target_heap(ty) && !dsts.is_null() && !srcs.is_null() {
+            let inc = dev_increment_size_x(this, ty) as u64;
+            let ranges = |starts: *const u64, sizes: *const u32, n: u32| -> Vec<(u64, u32)> {
+                (0..n as usize).map(|i| (*starts.add(i), if sizes.is_null() { 1 } else { *sizes.add(i) })).collect()
+            };
+            for (dst, src, n) in super::depth_uav::pieces(&ranges(dsts, dsizes, nd), &ranges(srcs, ssizes, ns), inc) {
+                copy_target_views(ty, n, dst, src, inc);
+            }
         }
         type F = unsafe extern "system" fn(*mut c_void, u32, *const u64, *const u32, u32, *const u64, *const u32, u32);
         let f: F = std::mem::transmute(orig_fn(this, 23));
--- a/crates/xcl/src/hle/d3d12x/depth_uav.rs
+++ b/crates/xcl/src/hle/d3d12x/depth_uav.rs
@@ -851,45 +851,8 @@
     }
 }
 
-/// The DSV handle increment of `dev`, read once.
-unsafe fn dsv_increment(dev: *mut c_void) -> u64 {
-    static INC: AtomicU32 = AtomicU32::new(0);
-    let mut inc = INC.load(Ordering::Relaxed);
-    if inc == 0 {
-        let Some(d) = ID3D12Device::from_raw_borrowed(&dev) else { return 0 };
-        inc = d.GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_DSV);
-        INC.store(inc, Ordering::Relaxed);
-    }
-    inc as u64
-}
-
-/// CopyDescriptorsSimple of `n` DSVs from `src` to `dst`: each destination names what its source
-/// names, or nothing.
-pub(super) unsafe fn dsvs_copied(dev: *mut c_void, n: u32, dst: u64, src: u64) {
-    if DSV_ENTRIES.load(Ordering::Relaxed) == 0 {
-        return;
-    }
-    copy_dsvs(n, dst, src, dsv_increment(dev));
-}
-
-/// CopyDescriptors of DSVs: destination and source ranges (start, length; no lengths: 1 each)
-/// walked in step.
-#[allow(clippy::too_many_arguments)]
-pub(super) unsafe fn dsv_ranges_copied(dev: *mut c_void, nd: u32, dsts: *const u64, dsizes: *const u32, ns: u32, srcs: *const u64, ssizes: *const u32) {
-    if DSV_ENTRIES.load(Ordering::Relaxed) == 0 || dsts.is_null() || srcs.is_null() {
-        return;
-    }
-    let ranges = |starts: *const u64, sizes: *const u32, n: u32| -> Vec<(u64, u32)> {
-        (0..n as usize).map(|r| (*starts.add(r), if sizes.is_null() { 1 } else { *sizes.add(r) })).collect()
-    };
-    let inc = dsv_increment(dev);
-    for (dst, src, n) in pieces(&ranges(dsts, dsizes, nd), &ranges(srcs, ssizes, ns), inc) {
-        copy_dsvs(n, dst, src, inc);
-    }
-}
-
 /// Destination and source ranges cut where either one ends: (dst, src, n) runs.
-fn pieces(dsts: &[(u64, u32)], srcs: &[(u64, u32)], inc: u64) -> Vec<(u64, u64, u32)> {
+pub(super) fn pieces(dsts: &[(u64, u32)], srcs: &[(u64, u32)], inc: u64) -> Vec<(u64, u64, u32)> {
     let (mut out, mut d, mut s, mut dk, mut sk) = (Vec::new(), 0, 0, 0u32, 0u32);
     while d < dsts.len() && s < srcs.len() {
         let n = (dsts[d].1 - dk).min(srcs[s].1 - sk);
@@ -908,7 +871,8 @@
     out
 }
 
-fn copy_dsvs(n: u32, dst: u64, src: u64, inc: u64) {
+pub(super) fn copy_dsvs(n: u32, dst: u64, src: u64, inc: u64) {
+    if DSV_ENTRIES.load(Ordering::Relaxed) == 0 { return; }
     for k in 0..n as u64 {
         let (to, from) = ((dst + k * inc) as usize, (src + k * inc) as usize);
         match DSVS.get(from) {
--- a/crates/xcl/src/hle/d3d12x/placements.rs
+++ b/crates/xcl/src/hle/d3d12x/placements.rs
@@ -587,6 +587,18 @@
     }
 }
 
+pub(super) fn copy_dsvs(n: u32, dst: u64, src: u64, inc: u64) {
+    let mut g = DSVS.lock().unwrap();
+    let Some(views) = g.as_mut() else { return };
+    for i in 0..u64::from(n) {
+        let to = (dst + i * inc) as usize;
+        match views.get(&((src + i * inc) as usize)).copied() {
+            Some(res) => { views.insert(to, res); }
+            None => { views.remove(&to); }
+        }
+    }
+}
+
 /// The placed texture the DSV at `handle` names.
 fn dsv_texture(handle: usize) -> Option<usize> {
     DSVS.lock().unwrap().as_ref()?.get(&handle).copied()
@@ -632,6 +644,30 @@
         r.remove(a);
         r.remove(b);
     }
+    #[test]
+    fn copied_dsv_ranges_replace_and_clear_only_their_destinations() {
+        let handles = [0u8; 16];
+        let src = handles.as_ptr() as usize;
+        let dst = src + 8;
+        {
+            let mut guard = DSVS.lock().unwrap();
+            let views = guard.get_or_insert_with(HashMap::new);
+            views.insert(src, 21);
+            views.insert(src + 4, 22);
+            for i in 0..5 { views.insert(dst + i, 19); }
+        }
+        let dsts = [(dst as u64, 2), ((dst + 3) as u64, 2)];
+        let srcs = [(src as u64, 1), ((src + 3) as u64, 3)];
+        for (to, from, n) in super::super::depth_uav::pieces(&dsts, &srcs, 1) {
+            copy_dsvs(n, to, from, 1);
+        }
+        let actual = (0..5).map(|i| dsv_texture(dst + i)).collect::<Vec<_>>();
+        let mut guard = DSVS.lock().unwrap();
+        let views = guard.as_mut().unwrap();
+        for i in 0..16 { views.remove(&(src + i)); }
+        assert_eq!(actual, [Some(21), None, Some(19), Some(22), None]);
+    }
+
     const MIB: usize = 1 << 20;
 
     /// A placement looked at, not retiring: (its sequence number, its cases).
--- a/crates/xcl/src/hle/d3d12x/present.rs
+++ b/crates/xcl/src/hle/d3d12x/present.rs
@@ -226,6 +226,27 @@
     if let Some(o) = old {
         release(o);
     }
+}
+
+pub(super) unsafe fn copy_rtvs(n: u32, dst: u64, src: u64, inc: u64) {
+    let mut replaced = Vec::new();
+    {
+        let mut g = RTVS.lock().unwrap();
+        let Some(views) = g.as_mut() else { return };
+        for i in 0..u64::from(n) {
+            let to = (dst + i * inc) as usize;
+            let old = match views.get(&((src + i * inc) as usize)).copied() {
+                Some(res) => {
+                    add_ref(res);
+                    views.insert(to, res)
+                }
+                None => views.remove(&to),
+            };
+            if let Some(res) = old { replaced.push(res); }
+        }
+    }
+    // Release can call back into descriptor bookkeeping.
+    for res in replaced { release(res); }
 }
 
 /// `XCL_TRACE_FRAME=1`: what console code does with each resource it later presents –

AI assistance: OpenAI Codex (GPT-6) prepared the candidate, ran the controls and drafted this report.

@Kalmarv

Kalmarv commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor Author

@andrewDoing thanks, both findings are right: an RTV or DSV written by CopyDescriptorsSimple / CopyDescriptors kept whatever its handle named before, so a bind or clear through it mapped the wrong target again (or none). For DSVs that was the case listed under Not tested; for RTVs I had not seen it (present's table has never followed copies).

Fixed in 2d632bd (squashed into the PR's commit, which is now on main): the two copy hooks pass RTV and DSV copies to both tables (present::rtvs_copied, placements::dsvs_copied), each destination naming what its source names, or nothing. I wrote it against the tables as they are here and did not take your patch, which also moves depth_uav's copy functions: that module keeps its own path. The two GPU tests now also bind through an RTV copied with CopyDescriptorsSimple and clear through a DSV copied with CopyDescriptors; on 2d632bd (release, RTX 5070 Ti, cargo test --release -p xcl --lib superseded_target -- --test-threads=1) 3 passed, 0 failed; with the copies not followed (WARP) 1 passed, 2 failed, with still without tiles after ["OMSetRenderTargets with a copied RTV"] and still without tiles after ["ClearDepthStencilView with a copied DSV"].

Edit: the first push of this, 843d868, crashed an existing test (copy_descriptors_remaps_xbox_extra_cbv_srv_uav_to_pc_enum copies an RTV on a fake device with two slots, and the new code asked it for the handle step); 2d632bd asks the device for the step only when a range holds more than one view. The description now has the suite on 2d632bd and on main, and its regression run; the main side of that pair is still to be rerun (see there).

Not covered: the other pairing on a GPU (an RTV through CopyDescriptors, a DSV through CopyDescriptorsSimple); both hooks share one function.

Written with Claude Code (Claude Fable 5).

@KDenKC

KDenKC commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

@Kalmarv we ran the whole suite of your head on an RTX 3090 against its base on the same machine: no failure the base doesn't have. All 4 new tests pass:

  • list_x::tests::the_texture_barriers_of_barrier_groups_name_their_textures
  • placements::tests::a_dsv_handle_names_the_placed_texture_it_was_last_made_of
  • real::superseded_target_tests::gpu_a_superseded_render_target_the_title_binds_clears_or_moves_is_mapped_again
  • real::superseded_target_tests::gpu_a_superseded_depth_buffer_the_title_binds_or_clears_is_mapped_again

Tested: fe9039de and its base nvidia-dev 54225f58.

  • RTX 3090 24 GB, NVIDIA 621.24, i7-10700T x8 (a VM with the GPU passed through), Windows 11 26H2 (26300.9974), Rust 1.99.1 (stable-x86_64-pc-windows-msvc), debug, no XCL_* set.
  • cargo test --workspace --no-fail-fast -- --test-threads=4 --skip uma_driver::tests::a_refused_gpu_upload_segment_becomes_custom --skip uma_driver::tests::mixed_window_keeps_its_bytes_and_the_gpu_sees_every_segment --skip uma_driver::tests::failed_restore_stops_before_importing_an_unbacked_window
    • Those three end the lib test binary on 621.24, at the base too.
  • base: 1,900 passed, 7 failed, 48 ignored; head: 1,904 passed, 7 failed, 48 ignored.
  • The 7 failures are the same tests on both, and they come from this VM:
    • 4 title_textures: one 0x8007000E in the full run, which passes alone, and three PoisonError from it;
    • 2 vram 0x8007000E;
    • e2e test_title_runs_and_game_folder_is_untouched.
  • SKIPPED: 30, the same on both.

Also on a tree with #3179: cherry-picked onto nvidia-dev + #3179, the two PRs merge in text, but both add placements::any_superseded() (identical bodies), so that tree needs one of the two removed to build. With that, cargo test -p xcl --lib -- placements gives 17 passed, 0 failed (both PRs' placement tests).

Not tested: a title run; a release build; AMD / Intel.

Your loyal testing minion, as ever.

AI use: an agent swarm: Claude Fable 5.2, Claude Opus 5.5, GPT-6.2-Sol and Gemini 4 Neon.

@Kalmarv
Kalmarv force-pushed the standby/retire-use-nv branch from 843d868 to 2d632bd Compare November 28, 2026 20:24
@andrewDoing

Copy link
Copy Markdown
Contributor

Verified the two outstanding GPU pairings on the author’s current implementation, 2d632bd2ac4f3492f886a92424189c9b51530538, RTX 5070 / NVIDIA 616.92. Only test fixtures were added.

The destination initially named superseded target A, and the source named superseded target B. Both started unmapped. Binding the copied destination remapped B only in both cases:

Descriptor copy Mapping after bind A readback B readback
RTV via single-range CopyDescriptors A unmapped, B mapped R32_FLOAT 0.25 R32_FLOAT 0.75
DSV via CopyDescriptorsSimple A unmapped, B mapped D16 0x4000 D16 0xbfff

Each A/B readback independently checked all 262,144 texels. Direct recreation and the converse API pairings gave the same results. The original head fe9039de had remapped A only through both copy APIs. After checking the initial mapping, the fixture explicitly remapped both resources through direct handles before issuing clears.

Four further cases copied a valid native descriptor whose source association was intentionally absent from XCL’s table. For both copy APIs and both view types, binding left stale A unmapped and all 16,384 pixels of the actually named live target received the clear. 16 fresh-process cases passed, zero skips. This covers normal single-descriptor replacement, including a single range; multi-range copies and retail rendering were outside this run.

AI use: OpenAI Codex adapted the prior native fixture to the head’s four-slot test heap, ran the controls and prepared the report.

@thehollowedone

thehollowedone commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Independent check of #3192 head 2d632bd2 on Windows 11 build 26300, RTX 3080 Ti / 621.35, Ryzen 7 9800X3D, rustc 1.99.1 MSVC.

cargo test --offline --locked -j 4 -p xcl --lib superseded_target -- --test-threads=1 --nocapture: 3 passed, 0 failed, 0 ignored, zero skips on the unchanged head. The GPU render-target and depth-buffer cases both ran.

I found two remaining paths that can leave a superseded target unmapped:

  1. List #146's group reader silently truncates valid input to 256 groups and 4,096 barriers per group. If the only barrier naming the superseded target is later, note_use never runs while the global UAV barrier still does. I added 257-group and 4,097-barrier controls to the existing unit test. On the unchanged head, the first control failed 0/1 ([] versus [0x4000]). With the small candidate below, both controls and the existing assertions passed 1/1. The candidate also avoids quadratic Vec::contains work for distinct resources. This is synthetic coverage; I did not measure a title batch of that size.
  2. present::note_rtv records no RTV association when present = "off", a supported per-title setting. The new clear and bind remapping reads only that association, so it cannot restore tiles for an RTV in that mode. A placement-owned RTV lookup independent of presentation capture, with a fresh-process present = "off" bind/clear regression, would cover direct and copied views. This second point is source-traced, not runtime-tested.
Tested candidate for the list #146 boundary
diff --git a/crates/xcl/src/hle/d3d12x/list_x.rs b/crates/xcl/src/hle/d3d12x/list_x.rs
index fe7a11fc..d256eeec 100644
--- a/crates/xcl/src/hle/d3d12x/list_x.rs
+++ b/crates/xcl/src/hle/d3d12x/list_x.rs
@@ -4932,19 +4932,20 @@ pub(super) unsafe extern "system" fn dispatch_x(this: *mut c_void, x: u32, y: u3
 /// their order; groups and barrier arrays that are not readable memory are passed over.
 unsafe fn barrier_group_textures(n: u32, groups: *const c_void) -> Vec<usize> {
     let mut out = Vec::new();
-    let count = (n as usize).min(256);
+    let mut seen = HashSet::new();
+    let count = n as usize;
     if count == 0 || groups.is_null() || !crate::gpu::shader::readable(groups as usize, count * std::mem::size_of::<D3D12_BARRIER_GROUP>()) {
         return out;
     }
     for g in std::slice::from_raw_parts(groups as *const D3D12_BARRIER_GROUP, count) {
-        let m = (g.NumBarriers as usize).min(4096);
+        let m = g.NumBarriers as usize;
         let p = g.Anonymous.pTextureBarriers;
         if g.Type != D3D12_BARRIER_TYPE_TEXTURE || m == 0 || p.is_null() || !crate::gpu::shader::readable(p as usize, m * std::mem::size_of::<D3D12_TEXTURE_BARRIER>()) {
             continue;
         }
         for b in std::slice::from_raw_parts(p, m) {
             let r: usize = transmute_copy(&b.pResource);
-            if r != 0 && !out.contains(&r) {
+            if r != 0 && seen.insert(r) {
                 out.push(r);
             }
         }
@@ -11789,6 +11790,29 @@ mod tests {
             assert_eq!(barrier_group_textures(3, at), vec![0x1000, 0x2000], "the groups past the count are not read");
             assert!(barrier_group_textures(0, at).is_empty());
             assert!(barrier_group_textures(5, std::ptr::null()).is_empty());
+
+            // A valid group or barrier beyond the old scan caps still names its texture.
+            let one = [tex(0x4000)];
+            let mut many_groups = vec![D3D12_BARRIER_GROUP {
+                Type: D3D12_BARRIER_TYPE_GLOBAL,
+                NumBarriers: 0,
+                Anonymous: D3D12_BARRIER_GROUP_0 { pGlobalBarriers: std::ptr::null() },
+            }; 257];
+            many_groups[256] = D3D12_BARRIER_GROUP {
+                Type: D3D12_BARRIER_TYPE_TEXTURE,
+                NumBarriers: 1,
+                Anonymous: D3D12_BARRIER_GROUP_0 { pTextureBarriers: one.as_ptr() },
+            };
+            assert_eq!(barrier_group_textures(257, many_groups.as_ptr().cast()), vec![0x4000]);
+
+            let mut many_barriers = vec![tex(0); 4097];
+            many_barriers[4096] = tex(0x5000);
+            let group = [D3D12_BARRIER_GROUP {
+                Type: D3D12_BARRIER_TYPE_TEXTURE,
+                NumBarriers: 4097,
+                Anonymous: D3D12_BARRIER_GROUP_0 { pTextureBarriers: many_barriers.as_ptr() },
+            }];
+            assert_eq!(barrier_group_textures(1, group.as_ptr().cast()), vec![0x5000]);
         }
     }
 }

Update — GPU reproduction of point 2. I ran the existing superseded-render-target fixture in an isolated child test process with the documented present = "off" setting. On unchanged head 2d632bd2, the new focused test failed 0/1 with the direct RTV bind, copied RTV bind, and RTV clear all still unmapped; the texture-barrier control remapped. Recording RTV associations despite presentation being off made that same test pass 1/1, and cargo test --offline --locked -j 4 -p xcl --lib superseded_target -- --test-threads=1 then passed 4/4, zero skips. Same Windows 11 / RTX 3080 Ti setup as above. The child process keeps the altered global config out of other workspace tests.

Tested presentation-off reproduction and minimal functional candidate
diff --git a/crates/xcl/src/hle/d3d12x/present.rs b/crates/xcl/src/hle/d3d12x/present.rs
index 9e915e39..d81857e1 100644
--- a/crates/xcl/src/hle/d3d12x/present.rs
+++ b/crates/xcl/src/hle/d3d12x/present.rs
@@ -214,9 +214,6 @@ unsafe fn release(p: usize) {
 }
 
 pub unsafe fn note_rtv(handle: usize, res: *mut c_void) {
-    if !enabled() {
-        return;
-    }
     let mut g = RTVS.lock().unwrap();
     let m = g.get_or_insert_with(HashMap::new);
     if !res.is_null() {
diff --git a/crates/xcl/src/hle/d3d12x/real.rs b/crates/xcl/src/hle/d3d12x/real.rs
index a174d526..836aabcb 100644
--- a/crates/xcl/src/hle/d3d12x/real.rs
+++ b/crates/xcl/src/hle/d3d12x/real.rs
@@ -14868,6 +14868,38 @@ mod superseded_target_tests {
     /// (ClearRenderTargetView) or names it in a texture barrier of list #146's groups, and the
     /// clear is in it. Before, only a legacy barrier or a copy gave them back: the target stayed
     /// without tiles, what was drawn to it was dropped.
+    #[test]
+    fn gpu_a_superseded_rtv_remaps_when_presentation_is_off() {
+        const CHILD: &str = "XCL_TEST_PRESENT_OFF_CHILD";
+        if std::env::var_os(CHILD).is_none() {
+            let output = std::process::Command::new(std::env::current_exe().expect("test binary"))
+                .arg("--exact")
+                .arg("hle::d3d12x::real::superseded_target_tests::gpu_a_superseded_rtv_remaps_when_presentation_is_off")
+                .arg("--test-threads=1")
+                .env(CHILD, "1")
+                .output()
+                .expect("isolated presentation-off test");
+            let stdout = String::from_utf8_lossy(&output.stdout);
+            let stderr = String::from_utf8_lossy(&output.stderr);
+            if stdout.contains("SKIPPED") {
+                crate::gpu::recomp::runner::skip_test("isolated presentation-off GPU fixture skipped");
+            }
+            assert!(output.status.success(), "isolated presentation-off fixture failed:\n{stdout}\n{stderr}");
+            return;
+        }
+        let mut config = crate::config::Config::default();
+        config.present = "off".into();
+        crate::state::set_boot(crate::config::Boot {
+            title: "synthetic".into(),
+            exe_path: std::path::PathBuf::new(),
+            game_root: std::path::PathBuf::new(),
+            data_dir: std::env::temp_dir(),
+            config,
+        });
+        assert_eq!(crate::state::config().present, "off");
+        gpu_a_superseded_render_target_the_title_binds_clears_or_moves_is_mapped_again();
+    }
+
     #[test]
     fn gpu_a_superseded_render_target_the_title_binds_clears_or_moves_is_mapped_again() {
         let _vram = vram::VRAM_TEST_LOCK.lock().unwrap_or_else(|e| e.into_inner());

The three-line present::note_rtv change proves the cause but would retain a COM reference for every RTV in presentation-off mode. For a memory-conscious production fix, keep the placement lookup independent of presentation and retire its handle associations with descriptor-heap/resource lifetime; preserve the copy hooks' source-to-destination updates. Production ownership detail (source review). Keep an RTV slot’s weak (resource address, placement sequence) in the placement registry, populated at view creation and by both descriptor-copy APIs even before the resource is superseded. A null or untracked source clears the destination. Validate the sequence and !released while holding the same registry lock used for use_again, so an old view cannot remap a different resource later allocated at that address. Register each RTV heap with a generation and retire only that generation’s slots after its final native Release; a delayed release must not erase entries of a new heap reusing its address. This keeps the lookup independent of presentation and bounds its metadata to live heap slots. The present-off GPU reproduction above covers the remap symptom; heap and address reuse still need a targeted regression on a candidate implementation.\n\nI did not run the full workspace or paired title smokes on either local candidate. AI use: Codex (GPT-6.2 Astra) independently traced the original paths; Codex (GPT-6.2 Sol) checked them, wrote and ran the RTX regressions/candidates, and drafted this report.

@throny

throny commented Nov 28, 2026

Copy link
Copy Markdown
Collaborator

merge-check claim
head: 2d632bd

@Kalmarv

Kalmarv commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor Author

@thehollowedone thanks, both hold: barrier_group_textures stopped at 256 groups and at 4,096 barriers a group, and the RTV binds and clears found their target through present's table, which holds nothing with present = "off".

Changed in ee8bb3d (squashed into the PR's commit):

  • The two caps are gone: every group of the call and every barrier of a group is read (still only while a target is superseded, and only memory that is readable); HashSet instead of Vec::contains, as in your candidate. The unit test has a 257th group and a 4,097th barrier.
  • The RTV handles of placed textures are now kept where the DSV handles already were, in one table of addresses in placements (note_view, fed by CreateRenderTargetView, CreateDepthStencilView and both descriptor copies). The binds and clears look only there, so they no longer depend on presentation, and present.rs is not touched by this PR any more (its table follows no copies, as on main). The GPU render-target test now drops present's entries of its RTVs before the title's calls, which is what present = "off" leaves; I did not take the child-process test.
  • The table keeps no reference and no sequence. An entry whose texture is released names no live placement and does nothing; one whose address a later placed texture reuses can only be reached through a view the title has not written again since its resource went, which D3D12 does not allow it to use, and the worst it does is map a superseded target again that a barrier would also map. Entries go when their handle is written again, not with their heap. If you see a path where that is wrong, I will add the sequence.

Run on ee8bb3d so far (RTX 5070 Ti and WARP, debug): cargo test -p xcl --lib -- superseded_target a_view_handle the_texture_barriers copy_descriptors_remaps --test-threads=1: 6 passed, 0 failed on each. The new tests on the previous head's runtime code (2d632bd with only the test changes): 2 passed, 2 failed on each, with left: [], right: [8192, 12288] at the 257-group assertion and still without tiles after ["OMSetRenderTargets", "OMSetRenderTargets with a copied RTV", "ClearRenderTargetView"].

Not run yet on ee8bb3d: the whole suite and the regression run; the description gets both when they are done, and until then its numbers are of 2d632bd.

@throny the head is now ee8bb3d.

Written with Claude Code (Claude Fable 5).

@Kalmarv
Kalmarv force-pushed the standby/retire-use-nv branch from 2d632bd to ee8bb3d Compare November 28, 2026 21:25
@github-actions github-actions Bot added area:d3d12 D3D12.X runtime, command lists, resources, sparse memory gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks) labels Nov 28, 2026
@throny

throny commented Nov 28, 2026

Copy link
Copy Markdown
Collaborator

merge-check claim
head: ee8bb3d

The head moved while my suite ran on 2d632bd (clean there: 2598 passed, 0 failed, 49 ignored on main beeb81b); rerunning on this head.

@github-actions github-actions Bot added the needs-pr-check Failing the PR description check (CONTRIBUTING.md) label Nov 28, 2026
@KDenKC

KDenKC commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

merge-check
base: 7db2f39
head: ee8bb3d
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2590 passed, 5 failed, 49 ignored (base 7db2f39 on the same machine: 2586 passed, the same 5 failed, 49 ignored); SKIPPED: 30 lines, identical to the base: 21 "no wave64", 3 f16/f32 per-lane forms refused (#1426 semantics), 2 "no heap windows", 1 driver cache cannot be disabled (no Developer Mode), 3 no D3D12 debug layer; failing: title_textures::tests::placed_title_textures_share_vram_and_preserve_pixels (subtract overflow, title_textures.rs:6198) and the 3 stream_recheck_* tests it poisons, e2e test_title_runs_and_game_folder_is_untouched ("Invalid bitcode signature" on this VM): all 5 fail on the base too. This PR's 4 new tests ran and pass (the two GPU ones are not skipped). The run skips the 3 coherent-window remake tests (uma_driver::tests) that kill the lib binary on 621.x, on base and merge alike.
review: whole diff of the merge result read. (1) #3179 adds its own placements::any_superseded(): whichever of #3179 / #3192 merges second fails to build (a duplicate definition, not a git conflict); one copy must go. (2) note_view takes the placements registry lock and the view table lock on every CreateRenderTargetView / CreateDepthStencilView, even with nothing superseded; view creation is not per draw, so small (not measured). The table holds addresses only, no references. (3) The list #146 barrier-group walk has no count limit now; readable() checks the group array and each barrier array before they are read, and the walk is skipped while nothing is superseded. Not covered here: a title that takes the barrier-group path (no title on this machine).
performance: on by default (XCL_PLACE_RETIRE); the new work runs only while a superseded target exists, apart from the two locks per RTV/DSV creation. Not measured: this machine has no title, so there is no smoke from us.
verdict: not yet: Tier 2 needs the 60 s smoke (base vs merged) on a title, and this machine has none; no new failures, no blocking finding in the diff
hardware / tool and model: NVIDIA GeForce RTX 3090 24 GB (VM), driver 32.0.16.2124, Intel i7-10700T x8, Windows 11 build 26300.9974, Rust 1.99.1, debug / Claude Code: Claude Opus 5.5 ran the merge, build and suite and read the diff; Claude Fable 5.2 checked the report

(This replaces our claim above. The smoke we mentioned there is not coming from us: the RTX 5090 is taken up by other work, so this check is the suite on an RTX 3090 only.)

@throny

throny commented Nov 28, 2026

Copy link
Copy Markdown
Collaborator

merge-check
base: 7db2f39
head: ee8bb3d
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2598 passed, 0 failed, 49 ignored on the merge result with main 7db2f39 (27 SKIPPED lines); the same counts on the previous head 2d632bd with main beeb81b, whose base alone gave 2594 passed, 0 failed, 49 ignored. I did not run 7db2f39 alone.
review: the full read was of the previous head 2d632bd; of this head I read the difference to it. That difference answers the two open points of the earlier review: one table now holds render-target and depth views alike and no longer depends on the present path keeping the view (so it works with present = "off"), and the limits on barrier groups and barriers per group are gone, with a test for the 257th group and the 4097th barrier. What the PR covers beyond #3179 (descriptor tables only): binding render targets and the depth view, the two clears, texture barriers in the list's barrier groups, and copies of view descriptors, which now carry the target's name over. Not covered by either: resolves and unordered-access clears. No ping-pong: using a superseded target maps it again without unmapping the newer one; only a new placement supersedes again. Not fixed and not new: a list that bound a target before the newer placement but is submitted after the unmap still draws to an unmapped target. Two things block today. (1) #3179 and this PR each add the function any_superseded to placements.rs; a merge of both has it twice and does not build (git reports no conflict), so the second to land must drop its copy. (2) The regression run in the description does not meet the rule and did not reach the change: its log has no "used again" line, the frames are 1868 against main's 4377, and the description check is red.
performance: one atomic load per call while nothing is superseded, a table update per view-descriptor copy. No translator source. A world run on this card (RTX 4080, where XCL_PLACE_RETIRE=0 makes much more of the frame lit and #3179 alone did not) is what I do next and post here.
verdict: not yet: a regression run that reaches the change and meets the rule, and the duplicate function settled with #3179; the code reads as sound.
hardware / tool and model: RTX 4080 16 GB (621.40), i9-12900K, Windows 11 26300, Rust 1.100.0, debug. Claude Code; merge, build and suite run by Claude Fable 5.2, diff review by Claude Opus 5.5 (every hunk read; nothing run on the GPU beyond the suite).

@throny

throny commented Nov 29, 2026 •

Copy link
Copy Markdown
Collaborator

World runs for this PR on an RTX 4080 16 GB (621.40), as announced (edited: now 10 runs). With this PR the open world came out lit in 3 of 5 runs (31 to 41 % of the frame); with XCL_PLACE_RETIRE=0 in 2 of 3 (45 and 49 %); the base in 0 of 2 (4 and 14 %). The dark runs with the PR look like the base. Same place and camera view in all runs; the lit runs show walls and a building front that are black in the dark ones.

Tested

  • RTX 4080 16 GB, NVIDIA 621.40, i9-12900K, 64 GB RAM, Windows 11 Pro 26300, Rust 1.100.0, release.
  • Tree: main 7db2f391 + D3D12.X: fail lazy texture placement when mappings are unfinished #3124 (hang at world entry) + one local input-timing patch; the runs marked PR add this PR's diff (ee8bb3d3). All shaders translated beforehand, the driver's pipeline cache warm.
  • Setup: 16 view windows, XCL_UMA_DRIVER=mixed:1536:1792, XCL_TEXTURE_LEVEL_PAGES=1, 600 s after the first frame, automatic input into the open world. Lit share = pixels with a channel above 16 (above 64) of 255, over the last 40 dumped frames of each run (every 15th presented frame, about the last four minutes). Runs in the order made.
run tree lit share (above 16): median, min–max above 64: median presents/s device removed
227 base 4.3 %, 1.1–8.2 0.7 % 2.19 no
228 PR 41.3 %, 37.0–45.7 7.9 % 2.16 no
229 base, XCL_PLACE_RETIRE=0 48.9 %, 44.7–52.7 10.5 % 2.17 no
230 PR 4.6 %, 0.7–14.1 0.8 % 2.06 no
231 PR 34.8 %, 30.6–39.4 3.5 % 2.04 no
232 base, XCL_PLACE_RETIRE=0 3.7 %, 0.3–7.6 0.5 % 2.12 no
233 PR 31.0 %, 27.8–36.3 3.3 % 2.19 no
234 base 13.7 %, 5.7–18.4 3.4 % 2.06 no
235 PR 14.7 %, 6.5–17.5 3.8 % 2.26 no
236 base, XCL_PLACE_RETIRE=0 44.5 %, 28.8–48.6 8.7 % 2.19 no
  • The change is reached in every run with the PR (64 a superseded texture is used again lines each, the log's cap), costs no frame rate, and no run lost the device.
  • The PR and the switch behave alike here: lit in about 3 of 5, dark like the base otherwise. So retiring superseded targets is one cause of the dark picture on this card, this PR removes that cause about as well as the switch does, and a second cause that varies from run to run remains (even XCL_PLACE_RETIRE=0 was dark once). Yesterday's nvidia-dev runs showed the same split with the switch (38 % and 16 %, numbers); the base was dark in all 8 of its runs on both trees.
  • What the frames show (looked at locally, not posted): the same place and view in every run. Dark runs: one small lit structure, the rest black. Lit runs: in addition block walls on both sides and a building front; still no sky and a dark middle, so not a complete scene either.
  • This answers the regression-run point of my merge check for this card: the change is reached in the open world and does no harm.

Not tested

AI use: Claude Code (Claude Fable 5.2) built the trees, made the runs and wrote this; Claude Haiku 5.5 compared the frames.

@Aniseto

Aniseto commented Nov 29, 2026

Copy link
Copy Markdown

Re-ran the superseded-target remapping tests at ee8bb3d after the head moved from fe9039de; this is a new response in the same thread, not an edit of my earlier report: #3192 (comment)

System

  • GPU: NVIDIA GeForce RTX 5070 Ti (Blackwell, 32-lane waves only, mesh shaders), driver 32.0.16.2140 (621.40)
  • CPU: Intel Core i5-12400F, 64 GB RAM
  • OS: Windows 11 Pro build 26200 x64
  • Toolchain: rustc 1.100.0 (0ef1bc386 2026-11-09), MSVC 14.44.35207, DXC 1.9.2609.5
  • Build: debug

Results

  • XCL_ADAPTER=NVIDIA cargo test -p xcl --lib gpu_a_superseded_render_target_the_title_binds_clears_or_moves_is_mapped_again -- --test-threads=1: 1 passed, 0 failed, 0 ignored.
  • XCL_ADAPTER=NVIDIA cargo test -p xcl --lib gpu_a_superseded_depth_buffer_the_title_binds_or_clears_is_mapped_again -- --test-threads=1: 1 passed, 0 failed, 0 ignored.

What this adds
Both device-backed tests still pass at the new head, with no SKIPPED line here: a superseded render target and depth buffer get their tiles mapped again after the title binds, clears or moves them. This adds the new head and the updated driver as dimensions; I did not run a title.

Not tested
A retail title, a paired smoke run, the full workspace suite, AMD and Intel GPUs, native wave64 hosts, Wine, release profile, game data.

AI-assisted (OpenCode), model: DeepSeek V4.1 Flash Free - ran the commands above on this machine and wrote this report; no game data was used.

@ettehn

ettehn commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

I checked this head against newer main after #3179 and #3287 landed. On d52ff48c + ee8bb3d3, the only textual conflict was the comment above uav_barrier_x. Keeping main’s comment left both code paths intact. The build then hit the duplicate any_superseded definition noted above (E0428). Keeping main’s helper fixed the build. Local integration tree cfb2ad75502edae2f75e09251de767100bc31c49.

Windows Release, RTX 5070 Ti Laptop system (NVIDIA 621.24), Rust 1.97.1 MSVC. Placement, barrier-group and superseded-target tests passed 25/25 with no skips. The R32_FLOAT and D16 GPU readback cases also passed 2/2 in a fresh process with XCL_BARRIER_GROUPS=0. The remaps in those fixtures still happen with #3287’s optional texture transition conversion disabled. This run covered synthetic tests only.

OpenAI Codex (GPT-6.2 Sol) assisted with source review and Windows verification.

…ed again

A render target or depth buffer placed on title pages loses its tiles when a
newer placement covers other pages of it (placements: superseded), and gets
them back when the title uses it again. A use was only seen in a legacy
ResourceBarrier or a copy. A title that moves its textures with the barrier
groups of list xcl-dev#146 and then clears and draws into such a target was never
seen: the target stayed without tiles, every write to it was dropped and
every read of it returned 0.

A use is now also:
- a texture barrier in the groups of list xcl-dev#146 (the groups are read only
  while the title holds a superseded target, then all groups of the call and
  all barriers of a group),
- OMSetRenderTargets with its RTVs (the handles the list keeps, so a single
  range is stepped by the device's increment) or its DSV,
- ClearRenderTargetView and ClearDepthStencilView of it.

The RTV and DSV handles of placed textures are kept for this in one table of
addresses (placements::note_view). present's table of RTVs is not used: it
holds a reference for each view and is empty with present = "off". A view the
title copies (CopyDescriptorsSimple, CopyDescriptors) names what its source
names: a bind or clear through a copied view would otherwise look up what its
handle named earlier. All of these are calls that record into a list, so the
mapping is queued before the list's submit waits for the tile mappings
(vram::before_execute).

Tests: the textures named by barrier groups, a 257th group and a 4097th
barrier among them; the handle table; on a GPU with tiled resources, a
superseded R32_FLOAT target and a superseded D16 depth buffer are mapped
again by each of the calls above and hold the value they are then cleared to,
one bind through a copied RTV and one clear through a copied DSV among them,
the RTVs with nothing in present's table.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@Kalmarv
Kalmarv force-pushed the standby/retire-use-nv branch from ee8bb3d to 7c60a35 Compare December 1, 2026 00:51
@github-actions github-actions Bot removed the needs-pr-check Failing the PR description check (CONTRIBUTING.md) label Dec 1, 2026
@thehollowedone

Copy link
Copy Markdown
Contributor

CI follow-up for head 7c60a35a: the Windows job fails the unchanged a_placed_texture_gets_the_pages_of_a_level_with_its_texels assertion. It expects 28 new 64 KiB pages but sees 4. The earlier new depth test logged three disjoint 512×512 D16 targets, 8 pages each, and finished 2.017 s before that assertion. page_bytes_for counts the whole device, while bind_range sweeps idle pages before allocating after a 2 s idle interval. Removing 24 unrelated pages while adding 28 gives exactly the observed net 4. That is a strong explanation for this assertion, though the log does not identify the swept pages or explain the subsequent access violation. The same test passed on current main CI.

The test can check its own mapped mip groups instead of a device-wide delta, then compare the two fully mapped resources' tile identities to retain the sharing check. This follows the earlier #718 correction. Candidate against this head, not run locally:

Candidate test-only diff
diff --git a/crates/xcl/src/hle/d3d12x/title_textures.rs b/crates/xcl/src/hle/d3d12x/title_textures.rs
--- a/crates/xcl/src/hle/d3d12x/title_textures.rs
+++ b/crates/xcl/src/hle/d3d12x/title_textures.rs
@@ -6956,9 +6956,8 @@
 
             super::super::vram::LEVEL_PAGES_FOR_TEST.store(true, Ordering::Relaxed);
             let dev_key = dev.as_raw() as usize;
-            let dev_pages = || super::super::vram::page_bytes_for(dev_key).0;
-            let p0 = dev_pages();
             let small = place_tex(at);
+            let small_key = small.as_raw() as usize;
             super::super::vram::LEVEL_PAGES_FOR_TEST.store(false, Ordering::Relaxed);
             if !super::super::vram::has_lazy_levels(small.as_raw() as usize) {
                 // (not reserved, or a tiling that does not add up: it has its pages as before)
@@ -6967,14 +6966,14 @@
                 return println!("SKIPPED {NAME}: this adapter's texture was not placed with lazy levels");
             }
             super::super::vram::LEVEL_PAGES_FOR_TEST.store(true, Ordering::Relaxed);
-            assert_eq!(dev_pages(), p0, "no pages before the first upload");
+            assert_eq!(super::super::vram::mapped_level_tiles(small_key), Some(0), "no pages before the first upload");
             // the tiles of mip 0 and of all of it, as this driver lays them out
             let (mut all, mut n, mut mip0) = (0u32, 1u32, D3D12_SUBRESOURCE_TILING::default());
             dev.GetResourceTiling(&small, Some(&mut all), None, None, Some(&mut n), 0, &mut mip0);
             let top_tiles = mip0.WidthInTiles * mip0.HeightInTiles as u32 * mip0.DepthInTiles as u32;
             assert!(n == 1 && top_tiles > 0 && top_tiles < all, "mip 0 has tiles of its own: {top_tiles} of {all}");
             refresh(queue.as_raw());
-            assert_eq!(dev_pages() - p0, ((all - top_tiles) as usize) << 16, "pages for the levels with texels, none for mip 0");
+            assert_eq!(super::super::vram::mapped_level_tiles(small_key), Some((all - top_tiles) as u64), "pages for the levels with texels, none for mip 0");
             for sub in 1..11u32 {
                 assert!(read_sub(&small, sub) == want[sub as usize].data, "level {sub} after the first upload");
             }
@@ -6986,7 +6985,7 @@
             std::ptr::copy_nonoverlapping(whole.as_ptr().add(top), (at + top) as *mut u8, size - top);
             let full = place_tex(at);
             refresh(queue.as_raw());
-            assert_eq!(dev_pages() - p0, (all as usize) << 16, "mip 0's pages come with its texels; the other levels' are shared");
+            assert_eq!(super::super::vram::mapped_level_tiles(full.as_raw() as usize), Some(all as u64), "mip 0's pages come with its texels");
             assert!(!super::super::vram::has_unmapped_levels(full.as_raw() as usize));
             for sub in 0..11u32 {
                 assert!(read_sub(&full, sub) == want[sub as usize].data, "level {sub} once all of it is there");
@@ -6995,7 +6994,10 @@
             // the pages of its address, which hold what the second one's upload put there
             let write = capture_gpu_write(small.as_raw() as usize, ALL).unwrap();
             publish_gpu_writes(WriterQueueId { raw: queue.as_raw() as usize, generation: 1 }, &[write]);
-            assert_eq!(dev_pages() - p0, (all as usize) << 16, "the same pages");
+            assert_eq!(super::super::vram::mapped_level_tiles(small_key), Some(all as u64), "the GPU-written texture has every level mapped");
+            let small_tiles = super::super::vram::mapped_tiles_for(dev_key, small_key).expect("small texture is fully mapped");
+            let full_tiles = super::super::vram::mapped_tiles_for(dev_key, full.as_raw() as usize).expect("full texture is fully mapped");
+            assert_eq!(small_tiles, full_tiles, "the textures share the same physical tiles");
             assert!(read_sub(&small, 0) == want[0].data, "a GPU-written texture has pages under all its levels");
             // the title takes the memory from under mip 0 again (a streamed level it let go): the
             // second texture's next upload finds mip 0 all zeros, and mip 0 gives back its pages;

Separately, the description check requires a newly generated clean xcl-smoke block for this head; its current PR block is for 2d632bd2. I did not run that smoke or a new test here.

AI use: Codex (GPT-6.2 Sol) traced the CI and source; Codex (GPT-6.2 Astra) independently checked the idle-page sweep and candidate direction.

@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Review (head 7c60a35, diff read, not a merge-check: Build and test and PR description both fail, so not built or run here yet):

  • The new GPU tests likely break another test. In CI, title_textures::a_placed_texture_gets_the_pages_of_a_level_with_its_texels came up short by 1,572,864 B and the test process then crashed (STATUS_ACCESS_VIOLATION). That's exactly the pages of the three 512x512 D16 targets in gpu_a_superseded_depth_buffer... (real.rs ~15370; also ~15327), so their placements probably stay on the shared device and get freed after VRAM_TEST_LOCK is released. Main's recent CI runs are green.
  • The smoke block is on 2d632bd, not the head 7c60a35 (why PR description fails), in different scenes, and the PR's own log shows the change wasn't reached. The description still refers to heads ee8bb3d / 2d632bd.
  • The barrier claim is overstated: on main, list Compute dispatches: a shader takes no more arguments from user SGPRs than it has (XboxBvhBuilder builds empty BLAS / TLAS) #146 texture transitions already reach note_use through resource_barrier_x (list_x.rs ~6474-6477). Only barriers with no state change are new here (the test's COMMON -> COMMON is one), and the groups get parsed twice. The "both add any_superseded()" note is stale; main has it since D3D12.X: remap superseded targets bound through descriptor tables #3179.
  • Cost is unmeasured: while any target stays superseded, each OMSetRenderTargets takes up to three kinds of global lock (real.rs ~11397-11402), and every CreateRenderTargetView / CreateDepthStencilView now takes two.
  • Minor: the handle table never shrinks for released heaps (placements.rs ~589).

Fine: no nested locks, the same queue wait as the existing note_use, no interaction with #3416 (separate hunks), the tests fail without the change, and the GPU tests use skip_test.

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

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

Labels

area:d3d12 D3D12.X runtime, command lists, resources, sparse memory gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants