D3D12.X: restore coexisting committed aliases and re-queue uncovered CPU-backed textures in title_textures::Table::remove #3426

Closed
Kalmarv wants to merge 1 commit from upstream-pr/3426 into main
Kalmarv commented 2026-11-29 15:30:26 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Kalmarv on 2026-11-29T15:30:26Z.


What changed

  • Added Table::has_blocking_active_overlap in crates/xcl/src/hle/d3d12x/title_textures.rs mirroring Table::insert's coexistence rule: two committed (!placed) textures covering the exact same [va, end) range coexist as format aliases, while any placed or different-range active overlap blocks reactivation.
  • Updated Table::remove to check has_blocking_active_overlap when restoring shadowed entries instead of has_active_overlap, so all coexisting committed exact-range format aliases reactivate together when a covering texture is released.
  • Updated Table::remove to set e.pending = true whenever an uncovered entry is e.cpu_backed && !e.gpu_written (not only when e.unmapped was true), so exact same-range placed aliases whose shared vram::Pages tiles were overwritten and committed textures whose CPU writes were missed while unlinked from src_pieces re-upload on the next submit.
  • Added unit test table_remove_restores_committed_aliases_and_marks_uncovered_cpu_backed_pending covering coexisting committed aliases, exact-range placed aliases with unmapped == false, and committed/placed layering order.

Why

  1. Table::insert allows multiple committed (!placed) textures with the exact same [va, end) range to coexist as format aliases. When a covering texture shadowed those aliases and was later released, Table::remove restored the newest alias first and then rejected every older coexisting alias via has_active_overlap, leaving them trapped in shadowed and unlinked from src_pieces until the newest alias was also released.
  2. Table::remove calls texture_upload::forget(&e.known) on every uncovered texture because the covering texture may have overwritten shared video memory, yet only marked e.pending = true when e.unmapped was true. Exact same-range placed aliases stay mapped (unmapped == false) while sharing vram::Pages tiles, and committed textures never set unmapped, so uncovered CPU-backed textures stayed pending == false with stale or overwritten texels.

Tested

  • cargo check --workspace --all-targets (0 errors, 0 new warnings).
  • cargo build --workspace and cargo build --release -p xcl.
  • Targeted unit tests: table_remove_restores_committed_aliases_and_marks_uncovered_cpu_backed_pending (failed before the fix on origin/main 24d21a41, passes after), overlapping_placements_retire_superseded_entries, and gpu_owned_alias_generations_restore_the_previous_address_owner.
  • Full workspace GPU test suite on NVIDIA GeForce RTX 5070 Ti (cargo test --workspace -- --test-threads=4, exit 0, 0 failures across all crates).
  • 150 s xcl-smoke on PR head (b243d81c) and main-ancestor baseline (f0e8fdd5):
xcl-smoke v1
commit: b243d81ceebef6e784e086e2981ad975d53725af
gpu: NVIDIA GeForce RTX 5070 Ti
title: ea3b5e4d
seconds: 150
exit: 0x0
frames shown: 1510 (PresentX 1510)
presents per 2 s (last 3): 0 0 0
device removals: 0
crashes: 0
peak commit: 33278 MB
xcl-smoke v1
commit: f0e8fdd5c3942ddd399d5ee11384c8595c5aacff
gpu: NVIDIA GeForce RTX 5070 Ti
title: ea3b5e4d
seconds: 150
exit: 0x0
frames shown: 1695 (PresentX 1695)
presents per 2 s (last 3): 0 0 0
device removals: 0
crashes: 0
peak commit: 31546 MB

Not tested

  • AMD or Intel GPUs (tested on NVIDIA GeForce RTX 5070 Ti only).
  • Longer-than-150 s title sessions or titles beyond ea3b5e4d.
  • Shadowed entry PENDING accounting in recheck_source / mapping_changed (left out of scope to avoid overlapping open PRs #1294/#1733).

AI use

  • Authored and verified with an AI coding assistant; all code, tests, builds, GPU test runs, and 150 s smoke verification were executed locally against clean-room tests and real hardware.
<!-- greyfinch-sync:ivall/xcl:issue:5552205783 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3426). Originally posted by [Kalmarv](https://github.com/Kalmarv) on 2026-11-29T15:30:26Z. --- **What changed** - Added `Table::has_blocking_active_overlap` in `crates/xcl/src/hle/d3d12x/title_textures.rs` mirroring `Table::insert`'s coexistence rule: two committed (`!placed`) textures covering the exact same `[va, end)` range coexist as format aliases, while any placed or different-range active overlap blocks reactivation. - Updated `Table::remove` to check `has_blocking_active_overlap` when restoring shadowed entries instead of `has_active_overlap`, so all coexisting committed exact-range format aliases reactivate together when a covering texture is released. - Updated `Table::remove` to set `e.pending = true` whenever an uncovered entry is `e.cpu_backed && !e.gpu_written` (not only when `e.unmapped` was true), so exact same-range placed aliases whose shared `vram::Pages` tiles were overwritten and committed textures whose CPU writes were missed while unlinked from `src_pieces` re-upload on the next submit. - Added unit test `table_remove_restores_committed_aliases_and_marks_uncovered_cpu_backed_pending` covering coexisting committed aliases, exact-range placed aliases with `unmapped == false`, and committed/placed layering order. **Why** 1. `Table::insert` allows multiple committed (`!placed`) textures with the exact same `[va, end)` range to coexist as format aliases. When a covering texture shadowed those aliases and was later released, `Table::remove` restored the newest alias first and then rejected every older coexisting alias via `has_active_overlap`, leaving them trapped in `shadowed` and unlinked from `src_pieces` until the newest alias was also released. 2. `Table::remove` calls `texture_upload::forget(&e.known)` on every uncovered texture because the covering texture may have overwritten shared video memory, yet only marked `e.pending = true` when `e.unmapped` was true. Exact same-range placed aliases stay mapped (`unmapped == false`) while sharing `vram::Pages` tiles, and committed textures never set `unmapped`, so uncovered CPU-backed textures stayed `pending == false` with stale or overwritten texels. **Tested** - `cargo check --workspace --all-targets` (0 errors, 0 new warnings). - `cargo build --workspace` and `cargo build --release -p xcl`. - Targeted unit tests: `table_remove_restores_committed_aliases_and_marks_uncovered_cpu_backed_pending` (failed before the fix on `origin/main` `24d21a41`, passes after), `overlapping_placements_retire_superseded_entries`, and `gpu_owned_alias_generations_restore_the_previous_address_owner`. - Full workspace GPU test suite on NVIDIA GeForce RTX 5070 Ti (`cargo test --workspace -- --test-threads=4`, exit 0, 0 failures across all crates). - 150 s `xcl-smoke` on PR head (`b243d81c`) and `main`-ancestor baseline (`f0e8fdd5`): ``` xcl-smoke v1 commit: b243d81ceebef6e784e086e2981ad975d53725af gpu: NVIDIA GeForce RTX 5070 Ti title: ea3b5e4d seconds: 150 exit: 0x0 frames shown: 1510 (PresentX 1510) presents per 2 s (last 3): 0 0 0 device removals: 0 crashes: 0 peak commit: 33278 MB ``` ``` xcl-smoke v1 commit: f0e8fdd5c3942ddd399d5ee11384c8595c5aacff gpu: NVIDIA GeForce RTX 5070 Ti title: ea3b5e4d seconds: 150 exit: 0x0 frames shown: 1695 (PresentX 1695) presents per 2 s (last 3): 0 0 0 device removals: 0 crashes: 0 peak commit: 31546 MB ``` **Not tested** - AMD or Intel GPUs (tested on NVIDIA GeForce RTX 5070 Ti only). - Longer-than-150 s title sessions or titles beyond `ea3b5e4d`. - Shadowed entry `PENDING` accounting in `recheck_source` / `mapping_changed` (left out of scope to avoid overlapping open PRs `#1294`/`#1733`). **AI use** - Authored and verified with an AI coding assistant; all code, tests, builds, GPU test runs, and 150 s smoke verification were executed locally against clean-room tests and real hardware.
andrewDoing commented 2026-11-29 15:41:34 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by andrewDoing on 2026-11-29T15:41:34Z.


I ran the restoration through actual upload and fenced GPU readback on an RTX 5070 (616.92), using b243d81c and the same snapshot with this PR diff reversed.

Two committed 64×64 textures (R8_UNORM and R8_UINT) covered the same CPU source bytes. Both initially read 0x31 in all 4,096 texels. A larger texture shadowed both. I changed the CPU bytes to 0x97, refreshed while the covering texture was still registered, then removed it and refreshed again.

Tree Active aliases after removal Texels reading 0x97
PR diff reversed Older no, newer yes 0/4,096, 0/4,096
PR applied Both yes 4,096/4,096, 4,096/4,096

cargo test --locked --offline -p xcl --lib -- --test-threads=1 --nocapture gpu_uncovered_committed_format_aliases_refresh_together table_remove_restores_committed_aliases_and_marks_uncovered_cpu_backed_pending passed both tests on the PR without skips. The GPU assertion failed in the matched reversed control. The fixture used the production registration, refresh and forget helpers with synthetic CPU-backed committed resources. Guest release hooks, GPU-written aliases and retail behavior remain untested here.

Apply-checked native fixture

--- a/crates/xcl/src/hle/d3d12x/title_textures.rs
+++ b/crates/xcl/src/hle/d3d12x/title_textures.rs
@@ -6130,6 +6130,77 @@
         assert!(tbl.by_res.contains_key(&10) && tbl.by_res.contains_key(&11));
         assert_eq!(tbl.insert(12, entry(0x20_0000, &tex_64k, true, false)), (-1, vec![]));
         assert!(!tbl.by_res.contains_key(&10) && !tbl.by_res.contains_key(&11) && tbl.by_res.contains_key(&12));
+    }
+
+    #[test]
+    fn gpu_uncovered_committed_format_aliases_refresh_together() {
+        use windows::Win32::Graphics::Dxgi::Common::{DXGI_FORMAT, DXGI_FORMAT_R8_UINT, DXGI_FORMAT_R8_UNORM, DXGI_SAMPLE_DESC};
+
+        let _vram_guard = super::super::vram::VRAM_TEST_LOCK.lock().unwrap_or_else(|e| e.into_inner());
+        let _guard = TEST_LOCK.lock().unwrap_or_else(|e| e.into_inner());
+        if super::super::backend() != super::super::Backend::Real {
+            return crate::gpu::recomp::runner::skip_test("no GPU");
+        }
+        struct Registered(usize);
+        impl Drop for Registered {
+            fn drop(&mut self) { forget(self.0); }
+        }
+        unsafe {
+            let raw_device = super::super::real::device_raw();
+            let device = ID3D12Device::from_raw_borrowed(&raw_device).unwrap();
+            let queue: ID3D12CommandQueue = device.CreateCommandQueue(&D3D12_COMMAND_QUEUE_DESC::default()).unwrap();
+            let _uploads = DirectQueueUploads::new(&queue);
+            let make = |width, height, format: DXGI_FORMAT| {
+                let mut resource = None;
+                device.CreateCommittedResource(
+                    &D3D12_HEAP_PROPERTIES { Type: D3D12_HEAP_TYPE_DEFAULT, ..Default::default() },
+                    D3D12_HEAP_FLAG_NONE,
+                    &D3D12_RESOURCE_DESC { Dimension: D3D12_RESOURCE_DIMENSION_TEXTURE2D, Width: width, Height: height, DepthOrArraySize: 1, MipLevels: 1, Format: format, SampleDesc: DXGI_SAMPLE_DESC { Count: 1, Quality: 0 }, ..Default::default() },
+                    D3D12_RESOURCE_STATE_COMMON, None, &mut resource,
+                ).unwrap();
+                let resource: ID3D12Resource = resource.unwrap();
+                (resource, console_desc(3, width, height, 1, 1, format.0 as u32, 1))
+            };
+            let (first, first_desc) = make(64, 64, DXGI_FORMAT_R8_UNORM);
+            let (second, second_desc) = make(64, 64, DXGI_FORMAT_R8_UINT);
+            let (cover, cover_desc) = make(512, 256, DXGI_FORMAT_R8_UNORM);
+            let size = |desc| xg::Texture::new(desc).unwrap().size() as usize;
+            assert_eq!(size(&first_desc), size(&second_desc));
+            assert!(size(&cover_desc) > size(&first_desc));
+            let mut source = vec![0x31u8; size(&cover_desc)];
+            let va = source.as_ptr() as usize;
+            let register_texture = |resource: &ID3D12Resource, desc| {
+                register(raw_device, resource.as_raw(), va, desc, D3D12_RESOURCE_STATE_COMMON).unwrap();
+                Registered(resource.as_raw() as usize)
+            };
+            let first_key = register_texture(&first, &first_desc);
+            let second_key = register_texture(&second, &second_desc);
+            refresh(queue.as_raw());
+            for texture in [&first, &second] {
+                assert_eq!(read_r8(device, &queue, texture), vec![0x31; 4096]);
+            }
+
+            let cover_key = register_texture(&cover, &cover_desc);
+            {
+                let table = TEXTURES.lock().unwrap();
+                assert!(table.shadowed.contains_key(&first_key.0));
+                assert!(table.shadowed.contains_key(&second_key.0));
+            }
+            source.fill(0x97);
+            mark_hot(va, source.len());
+            refresh(queue.as_raw());
+            drop(cover_key);
+            refresh(queue.as_raw());
+            let active = {
+                let table = TEXTURES.lock().unwrap();
+                [table.by_res.contains_key(&first_key.0), table.by_res.contains_key(&second_key.0)]
+            };
+            let pixels = [&first, &second].map(|texture| read_r8(device, &queue, texture));
+            let updated = pixels.map(|pixels| pixels.iter().filter(|&&byte| byte == 0x97).count());
+            println!("committed aliases active={active:?}, updated texels={updated:?}");
+            assert_eq!(active, [true, true]);
+            assert_eq!(updated, [4096, 4096]);
+        }
     }
 
     #[test]

AI disclosure: OpenAI Codex (GPT-6.2 Sol) implemented and ran the fixture and drafted the report.

<!-- greyfinch-sync:ivall/xcl:comment:7258290358 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3426#issuecomment-7258290358). Originally posted by [andrewDoing](https://github.com/andrewDoing) on 2026-11-29T15:41:34Z. --- I ran the restoration through actual upload and fenced GPU readback on an RTX 5070 (616.92), using `b243d81c` and the same snapshot with this PR diff reversed. Two committed 64×64 textures (`R8_UNORM` and `R8_UINT`) covered the same CPU source bytes. Both initially read `0x31` in all 4,096 texels. A larger texture shadowed both. I changed the CPU bytes to `0x97`, refreshed while the covering texture was still registered, then removed it and refreshed again. | Tree | Active aliases after removal | Texels reading `0x97` | |---|---|---| | PR diff reversed | Older no, newer yes | `0/4,096`, `0/4,096` | | PR applied | Both yes | `4,096/4,096`, `4,096/4,096` | `cargo test --locked --offline -p xcl --lib -- --test-threads=1 --nocapture gpu_uncovered_committed_format_aliases_refresh_together table_remove_restores_committed_aliases_and_marks_uncovered_cpu_backed_pending` passed both tests on the PR without skips. The GPU assertion failed in the matched reversed control. The fixture used the production registration, refresh and forget helpers with synthetic CPU-backed committed resources. Guest release hooks, GPU-written aliases and retail behavior remain untested here. <details><summary>Apply-checked native fixture</summary> ```diff --- a/crates/xcl/src/hle/d3d12x/title_textures.rs +++ b/crates/xcl/src/hle/d3d12x/title_textures.rs @@ -6130,6 +6130,77 @@ assert!(tbl.by_res.contains_key(&10) && tbl.by_res.contains_key(&11)); assert_eq!(tbl.insert(12, entry(0x20_0000, &tex_64k, true, false)), (-1, vec![])); assert!(!tbl.by_res.contains_key(&10) && !tbl.by_res.contains_key(&11) && tbl.by_res.contains_key(&12)); + } + + #[test] + fn gpu_uncovered_committed_format_aliases_refresh_together() { + use windows::Win32::Graphics::Dxgi::Common::{DXGI_FORMAT, DXGI_FORMAT_R8_UINT, DXGI_FORMAT_R8_UNORM, DXGI_SAMPLE_DESC}; + + let _vram_guard = super::super::vram::VRAM_TEST_LOCK.lock().unwrap_or_else(|e| e.into_inner()); + let _guard = TEST_LOCK.lock().unwrap_or_else(|e| e.into_inner()); + if super::super::backend() != super::super::Backend::Real { + return crate::gpu::recomp::runner::skip_test("no GPU"); + } + struct Registered(usize); + impl Drop for Registered { + fn drop(&mut self) { forget(self.0); } + } + unsafe { + let raw_device = super::super::real::device_raw(); + let device = ID3D12Device::from_raw_borrowed(&raw_device).unwrap(); + let queue: ID3D12CommandQueue = device.CreateCommandQueue(&D3D12_COMMAND_QUEUE_DESC::default()).unwrap(); + let _uploads = DirectQueueUploads::new(&queue); + let make = |width, height, format: DXGI_FORMAT| { + let mut resource = None; + device.CreateCommittedResource( + &D3D12_HEAP_PROPERTIES { Type: D3D12_HEAP_TYPE_DEFAULT, ..Default::default() }, + D3D12_HEAP_FLAG_NONE, + &D3D12_RESOURCE_DESC { Dimension: D3D12_RESOURCE_DIMENSION_TEXTURE2D, Width: width, Height: height, DepthOrArraySize: 1, MipLevels: 1, Format: format, SampleDesc: DXGI_SAMPLE_DESC { Count: 1, Quality: 0 }, ..Default::default() }, + D3D12_RESOURCE_STATE_COMMON, None, &mut resource, + ).unwrap(); + let resource: ID3D12Resource = resource.unwrap(); + (resource, console_desc(3, width, height, 1, 1, format.0 as u32, 1)) + }; + let (first, first_desc) = make(64, 64, DXGI_FORMAT_R8_UNORM); + let (second, second_desc) = make(64, 64, DXGI_FORMAT_R8_UINT); + let (cover, cover_desc) = make(512, 256, DXGI_FORMAT_R8_UNORM); + let size = |desc| xg::Texture::new(desc).unwrap().size() as usize; + assert_eq!(size(&first_desc), size(&second_desc)); + assert!(size(&cover_desc) > size(&first_desc)); + let mut source = vec![0x31u8; size(&cover_desc)]; + let va = source.as_ptr() as usize; + let register_texture = |resource: &ID3D12Resource, desc| { + register(raw_device, resource.as_raw(), va, desc, D3D12_RESOURCE_STATE_COMMON).unwrap(); + Registered(resource.as_raw() as usize) + }; + let first_key = register_texture(&first, &first_desc); + let second_key = register_texture(&second, &second_desc); + refresh(queue.as_raw()); + for texture in [&first, &second] { + assert_eq!(read_r8(device, &queue, texture), vec![0x31; 4096]); + } + + let cover_key = register_texture(&cover, &cover_desc); + { + let table = TEXTURES.lock().unwrap(); + assert!(table.shadowed.contains_key(&first_key.0)); + assert!(table.shadowed.contains_key(&second_key.0)); + } + source.fill(0x97); + mark_hot(va, source.len()); + refresh(queue.as_raw()); + drop(cover_key); + refresh(queue.as_raw()); + let active = { + let table = TEXTURES.lock().unwrap(); + [table.by_res.contains_key(&first_key.0), table.by_res.contains_key(&second_key.0)] + }; + let pixels = [&first, &second].map(|texture| read_r8(device, &queue, texture)); + let updated = pixels.map(|pixels| pixels.iter().filter(|&&byte| byte == 0x97).count()); + println!("committed aliases active={active:?}, updated texels={updated:?}"); + assert_eq!(active, [true, true]); + assert_eq!(updated, [4096, 4096]); + } } #[test] ``` </details> AI disclosure: OpenAI Codex (GPT-6.2 Sol) implemented and ran the fixture and drafted the report.
Foniass commented 2026-12-01 03:55:48 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T03:55:48Z.


merge-check
base: d0832e614f
head: b243d81cee
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2891 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 (title_textures.rs, +85/-8). It changes the default path: when a covering texture is released, every uncovered texture that is CPU-backed and not GPU-written is now marked pending and uploaded again in full, not only one whose tiles had been unmapped. Findings: (1) possible overwrite of rendered texels (from reading, not seen on a title). A GPU-owned render target registered with register_gpu_owned (placed, not CPU-backed) can shadow a placed CPU-backed sampled texture at the exact same range with shared tiles. On main, releasing the target leaves the sampled texture holding what was rendered, as aliasing does on the console. With this PR the texture is re-uploaded from CPU memory over it, unless a download already wrote those texels back. Limiting the re-queue to entries whose tiles were unmapped or that saw CPU writes while shadowed would avoid it. (2) The extra full uploads per uncover aren't measured; the PR's own smoke runs are 89 % of main's frames and +1.7 GB peak commit, one run each. (3) Unmapped, non-CPU-backed, not GPU-written entries are no longer marked pending (on main they were never uploaded, so the pending count leaked). Looks like an improvement but has no test. (4) AI use names no tool or model. Fine: has_blocking_active_overlap follows insert's rule for same-range committed aliases, newest-first restore is consistent for mixed placed and committed entries, no new lock is taken under TEXTURES, pending_res and the pending count move together, and the new test fails on main for both claimed bugs.
performance: 60 s smoke of a retail title, main d0832e61 vs this merge (f1635dfe): 1516 -> 1671 frames shown (110 %; last presents per 2 s: 60 60 60), peak commit 18133 -> 17255 MB, 0 device removals, 0 crashes. This run doesn't show whether the title releases a GPU-owned target over a CPU-backed alias.
verdict: not yet: rule out finding (1) (a re-upload from CPU memory over texels a GPU-owned target rendered into a shared-tile alias), e.g. by limiting the re-queue to unmapped or CPU-written entries
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.

<!-- greyfinch-sync:ivall/xcl:comment:7300205739 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3426#issuecomment-7300205739). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T03:55:48Z. --- merge-check base: d0832e614fa7d6ae027bb4feb27ccb9121f54a8f head: b243d81ceebef6e784e086e2981ad975d53725af merge: clean build: cargo build --workspace -> ok tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2891 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 (title_textures.rs, +85/-8). It changes the default path: when a covering texture is released, every uncovered texture that is CPU-backed and not GPU-written is now marked pending and uploaded again in full, not only one whose tiles had been unmapped. Findings: (1) possible overwrite of rendered texels (from reading, not seen on a title). A GPU-owned render target registered with `register_gpu_owned` (placed, not CPU-backed) can shadow a placed CPU-backed sampled texture at the exact same range with shared tiles. On main, releasing the target leaves the sampled texture holding what was rendered, as aliasing does on the console. With this PR the texture is re-uploaded from CPU memory over it, unless a download already wrote those texels back. Limiting the re-queue to entries whose tiles were unmapped or that saw CPU writes while shadowed would avoid it. (2) The extra full uploads per uncover aren't measured; the PR's own smoke runs are 89 % of main's frames and +1.7 GB peak commit, one run each. (3) Unmapped, non-CPU-backed, not GPU-written entries are no longer marked pending (on main they were never uploaded, so the pending count leaked). Looks like an improvement but has no test. (4) AI use names no tool or model. Fine: `has_blocking_active_overlap` follows `insert`'s rule for same-range committed aliases, newest-first restore is consistent for mixed placed and committed entries, no new lock is taken under `TEXTURES`, `pending_res` and the pending count move together, and the new test fails on main for both claimed bugs. performance: 60 s smoke of a retail title, main d0832e61 vs this merge (f1635dfe): 1516 -> 1671 frames shown (110 %; last presents per 2 s: 60 60 60), peak commit 18133 -> 17255 MB, 0 device removals, 0 crashes. This run doesn't show whether the title releases a GPU-owned target over a CPU-backed alias. verdict: not yet: rule out finding (1) (a re-upload from CPU memory over texels a GPU-owned target rendered into a shared-tile alias), e.g. by limiting the re-queue to unmapped or CPU-written entries 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.
bmjask commented 2026-12-02 05:44:23 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T05:44:23Z.

Code review location: crates/xcl/src/hle/d3d12x/title_textures.rs; line 439

@@ -404,27 +416,28 @@ impl Table {
         let mut pending_delta = if old.pending { -1 } else { 0 };
         let va = old.va;
         let end = va.saturating_add(old.tex.size() as usize);
-        let mut cands: Vec<(u64, usize, usize, usize)> = self
+        let mut cands: Vec<(u64, usize, usize, usize, bool)> = self
             .shadowed_overlaps(va, end)
             .into_iter()
-            .filter_map(|(sva, sres, send)| self.shadowed.get(&sres).map(|e| (e.generation, sres, sva, send)))
+            .filter_map(|(sva, sres, send)| self.shadowed.get(&sres).map(|e| (e.generation, sres, sva, send, e.placed)))
             .collect();
         cands.sort_unstable_by(|a, b| b.0.cmp(&a.0));
         let mut to_remap = Vec::new();
-        for (_, sres, sva, send) in cands {
-            if self.has_active_overlap(sva, send) {
+        for (_, sres, sva, send, placed) in cands {
+            if self.has_blocking_active_overlap(sva, send, placed) {
                 continue;
             }
             self.shadowed_by_va.remove(&(sva, sres));
             if let Some(mut e) = self.shadowed.remove(&sres) {
-                // (the one that lay over it may have been uploaded over the same video memory)
+                // (the one that lay over it may have been uploaded over the same video memory,
+                // and CPU writes while shadowed were missed while unlinked from `src_pieces`)
                 texture_upload::forget(&e.known);
                 if e.unmapped {
                     e.unmapped = false;
                     to_remap.push(sres);
-                    if !e.gpu_written {
-                        e.pending = true;
-                    }
+                }
+                if e.cpu_backed && !e.gpu_written {

When a GPU-owned placed render target or UAV is released, the exact-range placed sampled texture under it is now marked pending, and its whole upload from stale CPU memory overwrites the shared tiles the GPU rendered into. Sampled placed 20 and GPU-owned RT 21 (register_gpu_owned: placed=true, cpu_backed=false) share [va,end), and they share tiles the way the console aliases memory. The title renders into 21 and releases it. remove(21) uncovers 20 (unmapped=false), cpu_backed && !gpu_written sets pending, and the next ExecuteCommandLists uploads 20 whole from title memory, which GPU writes never reach. The rendered texels are replaced with stale bytes. Test case 2 asserts exactly this upload.

<!-- greyfinch-sync:ivall/xcl:review-comment:4765280337 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3426#discussion_r4765280337). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T05:44:23Z. **Code review location:** `crates/xcl/src/hle/d3d12x/title_textures.rs`; line 439 ~~~~diff @@ -404,27 +416,28 @@ impl Table { let mut pending_delta = if old.pending { -1 } else { 0 }; let va = old.va; let end = va.saturating_add(old.tex.size() as usize); - let mut cands: Vec<(u64, usize, usize, usize)> = self + let mut cands: Vec<(u64, usize, usize, usize, bool)> = self .shadowed_overlaps(va, end) .into_iter() - .filter_map(|(sva, sres, send)| self.shadowed.get(&sres).map(|e| (e.generation, sres, sva, send))) + .filter_map(|(sva, sres, send)| self.shadowed.get(&sres).map(|e| (e.generation, sres, sva, send, e.placed))) .collect(); cands.sort_unstable_by(|a, b| b.0.cmp(&a.0)); let mut to_remap = Vec::new(); - for (_, sres, sva, send) in cands { - if self.has_active_overlap(sva, send) { + for (_, sres, sva, send, placed) in cands { + if self.has_blocking_active_overlap(sva, send, placed) { continue; } self.shadowed_by_va.remove(&(sva, sres)); if let Some(mut e) = self.shadowed.remove(&sres) { - // (the one that lay over it may have been uploaded over the same video memory) + // (the one that lay over it may have been uploaded over the same video memory, + // and CPU writes while shadowed were missed while unlinked from `src_pieces`) texture_upload::forget(&e.known); if e.unmapped { e.unmapped = false; to_remap.push(sres); - if !e.gpu_written { - e.pending = true; - } + } + if e.cpu_backed && !e.gpu_written { ~~~~ --- When a GPU-owned placed render target or UAV is released, the exact-range placed sampled texture under it is now marked pending, and its whole upload from stale CPU memory overwrites the shared tiles the GPU rendered into. Sampled placed 20 and GPU-owned RT 21 (`register_gpu_owned`: placed=true, cpu_backed=false) share [va,end), and they share tiles the way the console aliases memory. The title renders into 21 and releases it. `remove(21)` uncovers 20 (unmapped=false), `cpu_backed && !gpu_written` sets pending, and the next ExecuteCommandLists uploads 20 whole from title memory, which GPU writes never reach. The rendered texels are replaced with stale bytes. Test case 2 asserts exactly this upload.
bmjask commented 2026-12-02 05:44:23 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T05:44:23Z.

Code review location: crates/xcl/src/hle/d3d12x/title_textures.rs; line 440

@@ -404,27 +416,28 @@ impl Table {
         let mut pending_delta = if old.pending { -1 } else { 0 };
         let va = old.va;
         let end = va.saturating_add(old.tex.size() as usize);
-        let mut cands: Vec<(u64, usize, usize, usize)> = self
+        let mut cands: Vec<(u64, usize, usize, usize, bool)> = self
             .shadowed_overlaps(va, end)
             .into_iter()
-            .filter_map(|(sva, sres, send)| self.shadowed.get(&sres).map(|e| (e.generation, sres, sva, send)))
+            .filter_map(|(sva, sres, send)| self.shadowed.get(&sres).map(|e| (e.generation, sres, sva, send, e.placed)))
             .collect();
         cands.sort_unstable_by(|a, b| b.0.cmp(&a.0));
         let mut to_remap = Vec::new();
-        for (_, sres, sva, send) in cands {
-            if self.has_active_overlap(sva, send) {
+        for (_, sres, sva, send, placed) in cands {
+            if self.has_blocking_active_overlap(sva, send, placed) {
                 continue;
             }
             self.shadowed_by_va.remove(&(sva, sres));
             if let Some(mut e) = self.shadowed.remove(&sres) {
-                // (the one that lay over it may have been uploaded over the same video memory)
+                // (the one that lay over it may have been uploaded over the same video memory,
+                // and CPU writes while shadowed were missed while unlinked from `src_pieces`)
                 texture_upload::forget(&e.known);
                 if e.unmapped {
                     e.unmapped = false;
                     to_remap.push(sres);
-                    if !e.gpu_written {
-                        e.pending = true;
-                    }
+                }
+                if e.cpu_backed && !e.gpu_written {
+                    e.pending = true;

The same happens for render-target/UAV entries (target) in general. Entry::target says the GPU can write them other than by copies and XCL doesn't see all of that, so gpu_written can stay false after GPU writes. A committed or placed target A that the title renders into, shadowed by cover C, is forced pending with known forgotten when C is released, and its GPU content is replaced from CPU memory. Before, it was only re-uploaded if the CPU actually wrote its pages. For committed entries (own memory the cover never touched), comparing known against current CPU bytes and uploading only the changed pages would avoid both this and the extra upload cost (the smoke run shows 1510 vs 1695 frames, +1.7 GB peak commit).

<!-- greyfinch-sync:ivall/xcl:review-comment:4765280347 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3426#discussion_r4765280347). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T05:44:23Z. **Code review location:** `crates/xcl/src/hle/d3d12x/title_textures.rs`; line 440 ~~~~diff @@ -404,27 +416,28 @@ impl Table { let mut pending_delta = if old.pending { -1 } else { 0 }; let va = old.va; let end = va.saturating_add(old.tex.size() as usize); - let mut cands: Vec<(u64, usize, usize, usize)> = self + let mut cands: Vec<(u64, usize, usize, usize, bool)> = self .shadowed_overlaps(va, end) .into_iter() - .filter_map(|(sva, sres, send)| self.shadowed.get(&sres).map(|e| (e.generation, sres, sva, send))) + .filter_map(|(sva, sres, send)| self.shadowed.get(&sres).map(|e| (e.generation, sres, sva, send, e.placed))) .collect(); cands.sort_unstable_by(|a, b| b.0.cmp(&a.0)); let mut to_remap = Vec::new(); - for (_, sres, sva, send) in cands { - if self.has_active_overlap(sva, send) { + for (_, sres, sva, send, placed) in cands { + if self.has_blocking_active_overlap(sva, send, placed) { continue; } self.shadowed_by_va.remove(&(sva, sres)); if let Some(mut e) = self.shadowed.remove(&sres) { - // (the one that lay over it may have been uploaded over the same video memory) + // (the one that lay over it may have been uploaded over the same video memory, + // and CPU writes while shadowed were missed while unlinked from `src_pieces`) texture_upload::forget(&e.known); if e.unmapped { e.unmapped = false; to_remap.push(sres); - if !e.gpu_written { - e.pending = true; - } + } + if e.cpu_backed && !e.gpu_written { + e.pending = true; ~~~~ --- The same happens for render-target/UAV entries (`target`) in general. Entry::target says the GPU can write them other than by copies and XCL doesn't see all of that, so `gpu_written` can stay false after GPU writes. A committed or placed target A that the title renders into, shadowed by cover C, is forced pending with `known` forgotten when C is released, and its GPU content is replaced from CPU memory. Before, it was only re-uploaded if the CPU actually wrote its pages. For committed entries (own memory the cover never touched), comparing `known` against current CPU bytes and uploading only the changed pages would avoid both this and the extra upload cost (the smoke run shows 1510 vs 1695 frames, +1.7 GB peak commit).
bmjask commented 2026-12-02 05:44:23 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T05:44:23Z.

Code review location: crates/xcl/src/hle/d3d12x/title_textures.rs; line 443

@@ -404,27 +416,28 @@ impl Table {
         let mut pending_delta = if old.pending { -1 } else { 0 };
         let va = old.va;
         let end = va.saturating_add(old.tex.size() as usize);
-        let mut cands: Vec<(u64, usize, usize, usize)> = self
+        let mut cands: Vec<(u64, usize, usize, usize, bool)> = self
             .shadowed_overlaps(va, end)
             .into_iter()
-            .filter_map(|(sva, sres, send)| self.shadowed.get(&sres).map(|e| (e.generation, sres, sva, send)))
+            .filter_map(|(sva, sres, send)| self.shadowed.get(&sres).map(|e| (e.generation, sres, sva, send, e.placed)))
             .collect();
         cands.sort_unstable_by(|a, b| b.0.cmp(&a.0));
         let mut to_remap = Vec::new();
-        for (_, sres, sva, send) in cands {
-            if self.has_active_overlap(sva, send) {
+        for (_, sres, sva, send, placed) in cands {
+            if self.has_blocking_active_overlap(sva, send, placed) {
                 continue;
             }
             self.shadowed_by_va.remove(&(sva, sres));
             if let Some(mut e) = self.shadowed.remove(&sres) {
-                // (the one that lay over it may have been uploaded over the same video memory)
+                // (the one that lay over it may have been uploaded over the same video memory,
+                // and CPU writes while shadowed were missed while unlinked from `src_pieces`)
                 texture_upload::forget(&e.known);
                 if e.unmapped {
                     e.unmapped = false;
                     to_remap.push(sres);
-                    if !e.gpu_written {
-                        e.pending = true;
-                    }
+                }
+                if e.cpu_backed && !e.gpu_written {
+                    e.pending = true;
                 }
                 if e.pending {
                     pending_delta += 1;

PENDING can be counted twice: mapping_changed() and recheck_source() already do PENDING.fetch_add(1) on a shadowed entry, and remove() adds +1 again via pending_delta when it uncovers that pending entry. The submit decrements only once, so PENDING stays one too high for good, the PENDING == 0 fast path is never taken again, and every submit takes the slow selection path. The PR widens this branch without fixing that.

<!-- greyfinch-sync:ivall/xcl:review-comment:4765280352 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3426#discussion_r4765280352). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T05:44:23Z. **Code review location:** `crates/xcl/src/hle/d3d12x/title_textures.rs`; line 443 ~~~~diff @@ -404,27 +416,28 @@ impl Table { let mut pending_delta = if old.pending { -1 } else { 0 }; let va = old.va; let end = va.saturating_add(old.tex.size() as usize); - let mut cands: Vec<(u64, usize, usize, usize)> = self + let mut cands: Vec<(u64, usize, usize, usize, bool)> = self .shadowed_overlaps(va, end) .into_iter() - .filter_map(|(sva, sres, send)| self.shadowed.get(&sres).map(|e| (e.generation, sres, sva, send))) + .filter_map(|(sva, sres, send)| self.shadowed.get(&sres).map(|e| (e.generation, sres, sva, send, e.placed))) .collect(); cands.sort_unstable_by(|a, b| b.0.cmp(&a.0)); let mut to_remap = Vec::new(); - for (_, sres, sva, send) in cands { - if self.has_active_overlap(sva, send) { + for (_, sres, sva, send, placed) in cands { + if self.has_blocking_active_overlap(sva, send, placed) { continue; } self.shadowed_by_va.remove(&(sva, sres)); if let Some(mut e) = self.shadowed.remove(&sres) { - // (the one that lay over it may have been uploaded over the same video memory) + // (the one that lay over it may have been uploaded over the same video memory, + // and CPU writes while shadowed were missed while unlinked from `src_pieces`) texture_upload::forget(&e.known); if e.unmapped { e.unmapped = false; to_remap.push(sres); - if !e.gpu_written { - e.pending = true; - } + } + if e.cpu_backed && !e.gpu_written { + e.pending = true; } if e.pending { pending_delta += 1; ~~~~ --- PENDING can be counted twice: `mapping_changed()` and `recheck_source()` already do `PENDING.fetch_add(1)` on a shadowed entry, and `remove()` adds +1 again via `pending_delta` when it uncovers that pending entry. The submit decrements only once, so PENDING stays one too high for good, the `PENDING == 0` fast path is never taken again, and every submit takes the slow selection path. The PR widens this branch without fixing that.
bmjask commented 2026-12-02 05:44:23 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T05:44:23Z.

Code review location: crates/xcl/src/hle/d3d12x/title_textures.rs; line 431

@@ -404,27 +416,28 @@ impl Table {
         let mut pending_delta = if old.pending { -1 } else { 0 };
         let va = old.va;
         let end = va.saturating_add(old.tex.size() as usize);
-        let mut cands: Vec<(u64, usize, usize, usize)> = self
+        let mut cands: Vec<(u64, usize, usize, usize, bool)> = self
             .shadowed_overlaps(va, end)
             .into_iter()
-            .filter_map(|(sva, sres, send)| self.shadowed.get(&sres).map(|e| (e.generation, sres, sva, send)))
+            .filter_map(|(sva, sres, send)| self.shadowed.get(&sres).map(|e| (e.generation, sres, sva, send, e.placed)))
             .collect();
         cands.sort_unstable_by(|a, b| b.0.cmp(&a.0));
         let mut to_remap = Vec::new();
-        for (_, sres, sva, send) in cands {
-            if self.has_active_overlap(sva, send) {
+        for (_, sres, sva, send, placed) in cands {
+            if self.has_blocking_active_overlap(sva, send, placed) {
                 continue;
             }
             self.shadowed_by_va.remove(&(sva, sres));
             if let Some(mut e) = self.shadowed.remove(&sres) {

Not certain about this one: the uncovered texture now uploads at the next submit, but remove() doesn't run texture_upload::inherit from the released cover's unfinished sends the way insert() does for a placed-over-placed cover. If cover 21 still has an upload queued on another device's XCL queue to the same Pages tiles, 20's known.last doesn't include it, and 21's late copy can land after 20's upload and corrupt it.

<!-- greyfinch-sync:ivall/xcl:review-comment:4765280360 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3426#discussion_r4765280360). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T05:44:23Z. **Code review location:** `crates/xcl/src/hle/d3d12x/title_textures.rs`; line 431 ~~~~diff @@ -404,27 +416,28 @@ impl Table { let mut pending_delta = if old.pending { -1 } else { 0 }; let va = old.va; let end = va.saturating_add(old.tex.size() as usize); - let mut cands: Vec<(u64, usize, usize, usize)> = self + let mut cands: Vec<(u64, usize, usize, usize, bool)> = self .shadowed_overlaps(va, end) .into_iter() - .filter_map(|(sva, sres, send)| self.shadowed.get(&sres).map(|e| (e.generation, sres, sva, send))) + .filter_map(|(sva, sres, send)| self.shadowed.get(&sres).map(|e| (e.generation, sres, sva, send, e.placed))) .collect(); cands.sort_unstable_by(|a, b| b.0.cmp(&a.0)); let mut to_remap = Vec::new(); - for (_, sres, sva, send) in cands { - if self.has_active_overlap(sva, send) { + for (_, sres, sva, send, placed) in cands { + if self.has_blocking_active_overlap(sva, send, placed) { continue; } self.shadowed_by_va.remove(&(sva, sres)); if let Some(mut e) = self.shadowed.remove(&sres) { ~~~~ --- Not certain about this one: the uncovered texture now uploads at the next submit, but `remove()` doesn't run `texture_upload::inherit` from the released cover's unfinished sends the way `insert()` does for a placed-over-placed cover. If cover 21 still has an upload queued on another device's XCL queue to the same Pages tiles, 20's `known.last` doesn't include it, and 21's late copy can land after 20's upload and corrupt it.
bmjask commented 2026-12-02 05:44:23 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T05:44:23Z.

Review: COMMENTED


Review of b243d81c: 5 finding(s). 4 are inline. These are on lines outside the diff:

crates/xcl/src/hle/d3d12x/title_textures.rs:404: Shadowed entries are only reconsidered when an active cover is released, so the case the PR fixes still happens. With committed A at [0,X), placed P at [0,X) shadowing A, then committed B at [0,X) shadowing P: releasing P (shadowed) returns early here and never reconsiders A. A is a format alias that may coexist with active B, but it stays shadowed, unlinked from src_pieces, and misses CPU writes until B is released. insert() doesn't apply the coexistence rule either.


These findings come from an AI-assisted review (Claude Code) and focus on correctness. Each is a candidate; please check it before acting on it.

<!-- greyfinch-sync:ivall/xcl:review:6145395619 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3426#pullrequestreview-6145395619). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T05:44:23Z. **Review:** COMMENTED --- Review of `b243d81c`: 5 finding(s). 4 are inline. These are on lines outside the diff: **`crates/xcl/src/hle/d3d12x/title_textures.rs:404`**: Shadowed entries are only reconsidered when an active cover is released, so the case the PR fixes still happens. With committed A at [0,X), placed P at [0,X) shadowing A, then committed B at [0,X) shadowing P: releasing P (shadowed) returns early here and never reconsiders A. A is a format alias that may coexist with active B, but it stays shadowed, unlinked from src_pieces, and misses CPU writes until B is released. `insert()` doesn't apply the coexistence rule either. --- _These findings come from an AI-assisted review (Claude Code) and focus on correctness. Each is a candidate; please check it before acting on it._
bmjask commented 2026-12-02 14:14:00 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T14:14:00Z.


@Prime1997 could you take a look at this one for review and merge? My automated review notes are above, if any.

<!-- greyfinch-sync:ivall/xcl:comment:7348204952 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3426#issuecomment-7348204952). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T14:14:00Z. --- @Prime1997 could you take a look at this one for review and merge? My automated review notes are above, if any.
Kalmarv commented 2026-12-02 19:39:56 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Kalmarv on 2026-12-02T19:39:56Z.


Closing: review flagged stale CPU re-uploads overwriting GPU-rendered shared tiles and double-counted PENDING entries.

<!-- greyfinch-sync:ivall/xcl:comment:7356530360 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3426#issuecomment-7356530360). Originally posted by [Kalmarv](https://github.com/Kalmarv) on 2026-12-02T19:39:56Z. --- Closing: review flagged stale CPU re-uploads overwriting GPU-rendered shared tiles and double-counted `PENDING` entries.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

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