D3D12.X: hash only written pages of title textures (#2395) #2474

Closed
ChalanaGimhanaX wants to merge 1 commit from upstream-pr/2484 into main
ChalanaGimhanaX commented 2026-11-25 20:01:27 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by ChalanaGimhanaX on 2026-11-25T20:01:27Z.


Track per-page content hashes for write-watched title textures instead of hashing the entire texture on every dirty hit. When refresh_once collects overlapping dirty pages for a previously uploaded texture with matching (src, size, page_size), upload_all reads and hashes only those deduplicated dirty pages (outside LAST_CONTENT), returns the changed page indices (ready for #2396), and still forces a full baseline upload on first upload, pending uploads, or #504 GPU-view remaps.

Fixes #2395. Part of #2390, #582, and #1833.

What is in it

  • crates/xcl/src/hle/d3d12x/title_textures.rs: replaced LAST_CONTENT's whole-texture hash with per-page PageHashes, passed dirty pages from refresh_once through Upload, invalidated LAST_CONTENT outside TEXTURES on recheck_gpu_view_sources remaps, implemented changed_pages_with / changed_pages_since_last_upload (documenting the ExecuteCommandLists / GetWriteWatch(WRITE_WATCH_FLAG_RESET) synchronization contract), and added 6 unit tests (including a GetWriteWatch(RESET) post-reset interleaving test) alongside updating the existing unchanged-upload test.

Tested

  • Hardware / toolchain: NVIDIA GeForce RTX 3060 12 GB (driver 32.0.16.1714), Intel Core i5-10400F, Windows 11 Pro Build 26200, rustc 1.100.0 (0ef1bc386 2026-11-09), release build.
  • cargo test --release -p xcl --lib hle::d3d12x::title_textures::tests -- --test-threads=1 (1c9e839): 25 passed, 0 failed.
  • cargo build --release --workspace + cargo test --release --workspace --no-fail-fast -- --test-threads=4 --nocapture (1c9e839): 1423 passed, 0 failed, 46 ignored.
  • SKIPPED GPU/adapter tests (26): 21 no wave64, 3 refused f16 forms (#1426), 1 no heap windows, 1 pso_measurement_compiles_an_exact_synthetic_record (Windows Developer Mode required for driver cache disable).
  • cargo test --release -p xcl --test e2e -- --test-threads=1 (1c9e839): 4 passed, 0 failed.

Regression run

main (6d051da):

xcl-smoke v1
commit: 6d051da51ba3fe7ba7d4ef542da71f544646e3ba
gpu: NVIDIA GeForce RTX 3060
title: 37fe04ab
seconds: 60
exit: 0x0
frames shown: 1473 (PresentX 1473)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14348 MB

this PR (1c9e839):

xcl-smoke v1
commit: 1c9e8396cd80b45d21329327daa9c604b5856bfc
gpu: NVIDIA GeForce RTX 3060
title: 37fe04ab
seconds: 60
exit: 0x0
frames shown: 1409 (PresentX 1409)
presents per 2 s (last 3): 59 48 23
device removals: 0
crashes: 0
peak commit: 14086 MB

Not tested

  • AMD / Intel GPUs, Linux / Wine, wave64-native hardware, and retail gameplay beyond the 60-second menu smoke run.

AI use

  • Antigravity (Gemini 4 Neon) implemented the per-page hashing change and tests, ran the test suite and regression smoke runs, and drafted this description.
<!-- greyfinch-sync:ivall/xcl:issue:5498253517 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2484). Originally posted by [ChalanaGimhanaX](https://github.com/ChalanaGimhanaX) on 2026-11-25T20:01:27Z. --- Track per-page content hashes for write-watched title textures instead of hashing the entire texture on every dirty hit. When `refresh_once` collects overlapping dirty pages for a previously uploaded texture with matching `(src, size, page_size)`, `upload_all` reads and hashes only those deduplicated dirty pages (outside `LAST_CONTENT`), returns the changed page indices (ready for #2396), and still forces a full baseline upload on first upload, pending uploads, or #504 GPU-view remaps. Fixes #2395. Part of #2390, #582, and #1833. **What is in it** - `crates/xcl/src/hle/d3d12x/title_textures.rs`: replaced `LAST_CONTENT`'s whole-texture hash with per-page `PageHashes`, passed dirty pages from `refresh_once` through `Upload`, invalidated `LAST_CONTENT` outside `TEXTURES` on `recheck_gpu_view_sources` remaps, implemented `changed_pages_with` / `changed_pages_since_last_upload` (documenting the `ExecuteCommandLists` / `GetWriteWatch(WRITE_WATCH_FLAG_RESET)` synchronization contract), and added 6 unit tests (including a `GetWriteWatch(RESET)` post-reset interleaving test) alongside updating the existing unchanged-upload test. **Tested** - Hardware / toolchain: NVIDIA GeForce RTX 3060 12 GB (driver 32.0.16.1714), Intel Core i5-10400F, Windows 11 Pro Build 26200, `rustc 1.100.0 (0ef1bc386 2026-11-09)`, release build. - `cargo test --release -p xcl --lib hle::d3d12x::title_textures::tests -- --test-threads=1` (`1c9e839`): 25 passed, 0 failed. - `cargo build --release --workspace` + `cargo test --release --workspace --no-fail-fast -- --test-threads=4 --nocapture` (`1c9e839`): 1423 passed, 0 failed, 46 ignored. - `SKIPPED` GPU/adapter tests (26): 21 no wave64, 3 refused f16 forms (`#1426`), 1 `no heap windows`, 1 `pso_measurement_compiles_an_exact_synthetic_record` (Windows Developer Mode required for driver cache disable). - `cargo test --release -p xcl --test e2e -- --test-threads=1` (`1c9e839`): 4 passed, 0 failed. **Regression run** main (`6d051da`): ``` xcl-smoke v1 commit: 6d051da51ba3fe7ba7d4ef542da71f544646e3ba gpu: NVIDIA GeForce RTX 3060 title: 37fe04ab seconds: 60 exit: 0x0 frames shown: 1473 (PresentX 1473) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14348 MB ``` this PR (`1c9e839`): ``` xcl-smoke v1 commit: 1c9e8396cd80b45d21329327daa9c604b5856bfc gpu: NVIDIA GeForce RTX 3060 title: 37fe04ab seconds: 60 exit: 0x0 frames shown: 1409 (PresentX 1409) presents per 2 s (last 3): 59 48 23 device removals: 0 crashes: 0 peak commit: 14086 MB ``` **Not tested** - AMD / Intel GPUs, Linux / Wine, wave64-native hardware, and retail gameplay beyond the 60-second menu smoke run. **AI use** - Antigravity (Gemini 4 Neon) implemented the per-page hashing change and tests, ran the test suite and regression smoke runs, and drafted this description.
bmjask commented 2026-11-25 20:16:30 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-11-25T20:16:30Z.

Review: COMMENTED


Nonblocking validation gap: GetWriteWatch(RESET) captures/reset dirty pages at title_textures.rs:751-767, and the new fast path hashes only those captured pages at :905-946. A CPU write to another texture page after reset but before upload_all can miss this submission and be caught only on the next refresh, adding a frame/submission of staleness. Please either document the synchronization guarantee that excludes this or add an interleaving regression test.

<!-- greyfinch-sync:ivall/xcl:review:6064333867 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2484#pullrequestreview-6064333867). Originally posted by [bmjask](https://github.com/bmjask) on 2026-11-25T20:16:30Z. **Review:** COMMENTED --- Nonblocking validation gap: GetWriteWatch(RESET) captures/reset dirty pages at title_textures.rs:751-767, and the new fast path hashes only those captured pages at :905-946. A CPU write to another texture page after reset but before upload_all can miss this submission and be caught only on the next refresh, adding a frame/submission of staleness. Please either document the synchronization guarantee that excludes this or add an interleaving regression test.
emirduran707 commented 2026-11-25 21:05:15 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by emirduran707 on 2026-11-25T20:24:13Z.


Independent AMD RDNA4 (native wave64) test report on exact head b6b5b9c85ffe47aec7b701de1f938f664c3229d7 (clean detached checkout, no local changes).

Tested

  • AMD Radeon RX 9060 XT 16 GB (RDNA4, native wave64, driver 32.0.31044.16), Ryzen 5 5600, 32 GB RAM, Windows 11 Pro 26300, Rust 1.100.0 (stable-x86_64-pc-windows-msvc), DXC 1.9.2602.17; tests debug, smoke release.
  • cargo build --workspace && cargo test --workspace --no-fail-fast -- --test-threads=4: 1420 passed, 2 failed, 46 ignored; 8 SKIPPED (6 in lower_dxil::tests::{f16,f32}_programs_on_the_gpu refused by per-lane form; heap_window_out_of_memory_falls_back_to_the_switch_form; pso_measurement_compiles_an_exact_synthetic_record). All native wave64 GPU tests and all 5 new title_textures dirty-page hashing tests ran and passed.
    • The 2 failures (gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1 seed 722 and fuzz_validate_and_gpu_3 seed 1599) are pre-existing on unmodified main on this GPU.

Regression run (60 s retail-title smoke, XCL_NETWORK=0, release)

xcl-smoke v1
commit: b6b5b9c85ffe47aec7b701de1f938f664c3229d7
gpu: AMD Radeon RX 9060 XT
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1610 (PresentX 1610)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 16243 MB

(Matched main 68a284a baseline on the same machine today: 1573 frames, 14420 MB peak, 0 device removals, 0 crashes.)

Not tested

  • D3D12 debug layer; Intel GPUs.

AI use

  • Antigravity with Gemini 4 Neon ran the build, test suite, and smoke run and drafted this report.
<!-- greyfinch-sync:ivall/xcl:comment:7173619293 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2484#issuecomment-7173619293). Originally posted by [emirduran707](https://github.com/emirduran707) on 2026-11-25T20:24:13Z. --- Independent AMD RDNA4 (native wave64) test report on exact head `b6b5b9c85ffe47aec7b701de1f938f664c3229d7` (clean detached checkout, no local changes). **Tested** - AMD Radeon RX 9060 XT 16 GB (RDNA4, native wave64, driver 32.0.31044.16), Ryzen 5 5600, 32 GB RAM, Windows 11 Pro 26300, Rust 1.100.0 (`stable-x86_64-pc-windows-msvc`), DXC 1.9.2602.17; tests debug, smoke release. - `cargo build --workspace && cargo test --workspace --no-fail-fast -- --test-threads=4`: **1420 passed, 2 failed, 46 ignored; 8 SKIPPED** (6 in `lower_dxil::tests::{f16,f32}_programs_on_the_gpu` refused by per-lane form; `heap_window_out_of_memory_falls_back_to_the_switch_form`; `pso_measurement_compiles_an_exact_synthetic_record`). All native wave64 GPU tests and all 5 new `title_textures` dirty-page hashing tests ran and passed. - The 2 failures (`gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1` seed 722 and `fuzz_validate_and_gpu_3` seed 1599) are pre-existing on unmodified `main` on this GPU. **Regression run** (60 s retail-title smoke, `XCL_NETWORK=0`, release) ``` xcl-smoke v1 commit: b6b5b9c85ffe47aec7b701de1f938f664c3229d7 gpu: AMD Radeon RX 9060 XT title: 21222967 seconds: 60 exit: 0x0 frames shown: 1610 (PresentX 1610) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 16243 MB ``` (Matched `main` `68a284a` baseline on the same machine today: 1573 frames, 14420 MB peak, 0 device removals, 0 crashes.) **Not tested** - D3D12 debug layer; Intel GPUs. **AI use** - Antigravity with Gemini 4 Neon ran the build, test suite, and smoke run and drafted this report.
ChalanaGimhanaX commented 2026-11-25 21:05:17 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by ChalanaGimhanaX on 2026-11-25T20:31:41Z.


Thanks for the review, @bmjask — addressed in 1c9e839:

  1. Synchronization guarantee (now documented on changed_pages_with): refresh_once runs inside ExecuteCommandLists, so any CPU write ordered before that GPU submission is already captured before GetWriteWatch(WRITE_WATCH_FLAG_RESET) runs. A concurrent write to another page after WRITE_WATCH_FLAG_RESET is not ordered before the current submission (and on main already waited for the next refresh whenever no other page of that texture was dirty); because it happens after the reset, the OS write watch keeps that page dirty and the fast path leaves its stored hash untouched, so the next refresh_once is guaranteed to detect and upload it.
  2. Interleaving regression test: added post_reset_write_to_unchecked_page_is_caught_on_next_refresh using a real MEM_WRITE_WATCH allocation and take_written (GetWriteWatch(WRITE_WATCH_FLAG_RESET)), verifying that a write to page 4 landing after reset while pass 1 checks unchanged page 1 stays dirty and is detected on pass 2 (Some(vec![4])).

Re-ran the full release suite (1423 passed, 0 failed, 46 ignored, title_textures::tests 25/25, e2e 4/4) and a fresh 60s smoke run on 1c9e839 (1409 frames, 0 crashes/removals).

AI use: Antigravity (Gemini 4 Neon) added the doc comment and interleaving test, ran the tests and smoke check, and drafted this reply.

<!-- greyfinch-sync:ivall/xcl:comment:7173804456 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2484#issuecomment-7173804456). Originally posted by [ChalanaGimhanaX](https://github.com/ChalanaGimhanaX) on 2026-11-25T20:31:41Z. --- Thanks for the review, @bmjask — addressed in `1c9e839`: 1. **Synchronization guarantee (now documented on `changed_pages_with`):** `refresh_once` runs inside `ExecuteCommandLists`, so any CPU write ordered before that GPU submission is already captured before `GetWriteWatch(WRITE_WATCH_FLAG_RESET)` runs. A concurrent write to another page *after* `WRITE_WATCH_FLAG_RESET` is not ordered before the current submission (and on `main` already waited for the next refresh whenever no other page of that texture was dirty); because it happens after the reset, the OS write watch keeps that page dirty and the fast path leaves its stored hash untouched, so the next `refresh_once` is guaranteed to detect and upload it. 2. **Interleaving regression test:** added `post_reset_write_to_unchecked_page_is_caught_on_next_refresh` using a real `MEM_WRITE_WATCH` allocation and `take_written` (`GetWriteWatch(WRITE_WATCH_FLAG_RESET)`), verifying that a write to page 4 landing after reset while pass 1 checks unchanged page 1 stays dirty and is detected on pass 2 (`Some(vec![4])`). Re-ran the full release suite (`1423 passed, 0 failed, 46 ignored`, `title_textures::tests` `25/25`, `e2e` `4/4`) and a fresh 60s smoke run on `1c9e839` (`1409` frames, `0` crashes/removals). **AI use:** Antigravity (Gemini 4 Neon) added the doc comment and interleaving test, ran the tests and smoke check, and drafted this reply.
DavidM1911 commented 2026-11-25 21:05:18 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-25T20:34:29Z.


Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.)

Thanks!

<!-- greyfinch-sync:ivall/xcl:comment:7173872222 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2484#issuecomment-7173872222). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-25T20:34:29Z. --- Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.) Thanks!
DavidM1911 commented 2026-11-26 02:08:24 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-26T01:49:59Z.


Re-verification on RTX 3060 Ti (Windows 11), new head merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, 27 ignored. The earlier merge conflict is resolved.

Thanks!

— Devin

<!-- greyfinch-sync:ivall/xcl:comment:7180181981 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2484#issuecomment-7180181981). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-26T01:49:59Z. --- Re-verification on RTX 3060 Ti (Windows 11), new head merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, 27 ignored. The earlier merge conflict is resolved. Thanks! — Devin
Kalmarv commented 2026-11-26 06:06:43 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Kalmarv on 2026-11-26T05:32:41Z.


Found while building on this PR, one case where the skip leaves out an upload it needs (no benchmarks): a placed texture superseded by a placement over a different range is unmapped (title_textures.rs:407, :544 on 1c9e8396), and when that placement is released it is uncovered, remapped and made pending again (:271, :564). The remap gives it other tiles for the pages it had given back, but its LAST_CONTENT entry survives (it is dropped only in register, :342, and forget, :553), so its next upload compares the full hash with the old one (:957-:979), finds the memory unchanged and is left out (:1253): the texture then reads whatever the new tiles hold.

Steps that show it on this PR's head with an RTX 5070 Ti (test an_uncovered_texture_on_other_tiles_is_uploaded_again, a harness modelled on placed_title_textures_share_vram_and_preserve_pixels): place a 256 KiB texture A at va, write it, refresh (uploaded); place a 256 KiB texture at va - 192 KiB (A is unmapped, its last three pages go back); wait 2.1 s and place a texture elsewhere; release the second one (A is remapped: 3 of its 4 tiles are new); refresh: A is left out as unchanged (UNCHANGED +1, no upload of it); A's subresource 0 then reads 0 in 195,840 of its 262,144 bytes, the three new tiles.

Suggested fix: drop the hashes where the tiles go, one line LAST_CONTENT.lock().unwrap().remove(&(r.as_raw() as usize)); next to super::vram::unmap_superseded(r) in each of the two loops (:407, :544), so the first upload after the remap is a full one. With it, the same test passes on the same card (same remap, uploaded 2, left out as unchanged 0, A reads its bytes); the rest of the suite was not run on it.

AI use: Claude Code (Claude Opus 5.5) found this, wrote and ran the test, and drafted this comment.

<!-- greyfinch-sync:ivall/xcl:comment:7183582759 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2484#issuecomment-7183582759). Originally posted by [Kalmarv](https://github.com/Kalmarv) on 2026-11-26T05:32:41Z. --- Found while building on this PR, one case where the skip leaves out an upload it needs (no benchmarks): a placed texture superseded by a placement over a different range is unmapped (`title_textures.rs:407`, `:544` on 1c9e8396), and when that placement is released it is uncovered, remapped and made pending again (`:271`, `:564`). The remap gives it other tiles for the pages it had given back, but its `LAST_CONTENT` entry survives (it is dropped only in `register`, `:342`, and `forget`, `:553`), so its next upload compares the full hash with the old one (`:957`-`:979`), finds the memory unchanged and is left out (`:1253`): the texture then reads whatever the new tiles hold. Steps that show it on this PR's head with an RTX 5070 Ti (test `an_uncovered_texture_on_other_tiles_is_uploaded_again`, a harness modelled on `placed_title_textures_share_vram_and_preserve_pixels`): place a 256 KiB texture A at `va`, write it, refresh (uploaded); place a 256 KiB texture at `va - 192 KiB` (A is unmapped, its last three pages go back); wait 2.1 s and place a texture elsewhere; release the second one (A is remapped: 3 of its 4 tiles are new); refresh: A is left out as unchanged (`UNCHANGED` +1, no upload of it); A's subresource 0 then reads 0 in 195,840 of its 262,144 bytes, the three new tiles. Suggested fix: drop the hashes where the tiles go, one line `LAST_CONTENT.lock().unwrap().remove(&(r.as_raw() as usize));` next to `super::vram::unmap_superseded(r)` in each of the two loops (`:407`, `:544`), so the first upload after the remap is a full one. With it, the same test passes on the same card (same remap, `uploaded 2, left out as unchanged 0`, A reads its bytes); the rest of the suite was not run on it. AI use: Claude Code (Claude Opus 5.5) found this, wrote and ran the test, and drafted this comment.
thehollowedone commented 2026-11-26 16:06:15 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by thehollowedone on 2026-11-26T15:18:14Z.


Independent RTX 3080 Ti follow-up on PR head 1c9e839, building on Kalmarv's remap report. I reproduced the different-range case in the existing placed-texture GPU test: after restoring the original CPU bytes and uncovering the old texture, its readback differed in 1,045,504 of 1,048,576 bytes. Adding the two suggested hash invalidations at unmap_superseded made that assertion pass.

There is a related exact-range path those two lines do not cover. Exact-range siblings share tiles and are shadowed without unmap_superseded. After the newer sibling overwrites the tiles, releasing it and restoring the older sibling's original CPU bytes left 262,144 of 262,144 bytes wrong on this GPU. The older entry was reactivated with pending=false; clearing its hash only in the unmap loops could not schedule an upload. A local candidate that also marks each reactivated CPU-owned texture pending and clears its old hash before remapping passed both GPU readback assertions. This forces a fresh upload even if no write-watch page was captured after reactivation.

Windows 11 build 26300; RTX 3080 Ti (driver 621.35); Ryzen 7 9800X3D; rustc 1.99.1 MSVC; DXC 1.8.2502.11. cargo test --offline --locked -p xcl --lib placed_title_textures_share_vram_and_preserve_pixels -- --nocapture --test-threads=1: stock assertion 0 passed, 1 failed; different-range check with the two unmap invalidations 1 passed before adding the exact-range assertion; with both assertions and the candidate below 1 passed, 0 failed, 0 ignored, no GPU skip. cargo test --offline --locked --workspace --no-fail-fast -- --test-threads=4 on the final local candidate: 1,422 passed, 1 failed, 46 ignored across 37 targets, including 25 explicit GPU skip notices (21 no wave64, 3 refused per-lane forms, 1 no heap windows). The sole failure was console_mesh_caches_hlsl_compute_pass_in_memory_and_on_disk (DXIL not compiled yet); I reproduced it with the same focused command on untouched PR head. No retail title run or AMD/Intel test was performed.

Exact local candidate diff (not committed)
diff --git a/crates/xcl/src/hle/d3d12x/title_textures.rs b/crates/xcl/src/hle/d3d12x/title_textures.rs
index 1e0a2bef..a185abed 100644
--- a/crates/xcl/src/hle/d3d12x/title_textures.rs
+++ b/crates/xcl/src/hle/d3d12x/title_textures.rs
@@ -237,16 +237,16 @@ impl Table {
     }
 
     /// Remove `res` on COM release, reactivating any shadowed older textures it uncovered (newest
-    /// first). Returns `(was_present, pending_delta, unmapped_res_to_remap)`.
-    fn remove(&mut self, res: usize) -> (bool, isize, Vec<usize>) {
+    /// first). Returns `(was_present, pending_delta, unmapped_res_to_remap, reactivated)`.
+    fn remove(&mut self, res: usize) -> (bool, isize, Vec<usize>, Vec<usize>) {
         if let Some(old) = self.shadowed.remove(&res) {
             self.shadowed_by_va.remove(&(old.va, res));
             if self.shadowed.is_empty() {
                 self.max_shadowed_size = 0;
             }
-            return (true, 0, Vec::new());
+            return (true, 0, Vec::new(), Vec::new());
         }
-        let Some(old) = self.by_res.remove(&res) else { return (false, 0, Vec::new()) };
+        let Some(old) = self.by_res.remove(&res) else { return (false, 0, Vec::new(), Vec::new()) };
         self.by_va.remove(&(old.va, res));
         let mut pending_delta = if old.pending { -1 } else { 0 };
         let va = old.va;
@@ -258,18 +258,20 @@ impl Table {
             .collect();
         cands.sort_unstable_by(|a, b| b.0.cmp(&a.0));
         let mut to_remap = Vec::new();
+        let mut reactivated = Vec::new();
         for (_, sres, sva, send) in cands {
             if self.has_active_overlap(sva, send) {
                 continue;
             }
             self.shadowed_by_va.remove(&(sva, sres));
             if let Some(mut e) = self.shadowed.remove(&sres) {
+                reactivated.push(sres);
                 if e.unmapped {
                     e.unmapped = false;
                     to_remap.push(sres);
-                    if !e.gpu_written {
-                        e.pending = true;
-                    }
+                }
+                if !e.gpu_written {
+                    e.pending = true;
                 }
                 if e.pending {
                     pending_delta += 1;
@@ -281,7 +283,7 @@ impl Table {
         if self.shadowed.is_empty() {
             self.max_shadowed_size = 0;
         }
-        (true, pending_delta, to_remap)
+        (true, pending_delta, to_remap, reactivated)
     }
 
     fn get_mut(&mut self, res: usize) -> Option<&mut Entry> {
@@ -404,6 +406,7 @@ pub(super) unsafe fn register(device: *mut c_void, res: *mut c_void, va: usize,
         clone_resources(&unmap_ptrs)
     };
     for r in &to_unmap {
+        LAST_CONTENT.lock().unwrap().remove(&(r.as_raw() as usize));
         super::vram::unmap_superseded(r);
     }
     TEXTURES_GEN.fetch_add(1, Ordering::Release);
@@ -541,6 +544,7 @@ pub(super) unsafe fn retire_overlapping(va: usize, len: usize) {
         (retired, clone_resources(&unmap_ptrs))
     };
     for r in &to_unmap {
+        LAST_CONTENT.lock().unwrap().remove(&(r.as_raw() as usize));
         super::vram::unmap_superseded(r);
     }
     if retired > 0 {
@@ -552,13 +556,16 @@ pub(super) unsafe fn retire_overlapping(va: usize, len: usize) {
 pub fn forget(res: usize) {
     LAST_CONTENT.lock().unwrap().remove(&res);
     STREAM_RECHECK.lock().unwrap().remove(&res);
-    let (removed, to_remap) = {
+    let (removed, to_remap, reactivated) = {
         let mut t = TEXTURES.lock().unwrap();
-        let (removed, delta, remap_ptrs) = t.remove(res);
+        let (removed, delta, remap_ptrs, reactivated) = t.remove(res);
         adjust_pending(delta);
         TEXTURES_LEN.store(t.by_res.len(), Ordering::Relaxed);
-        (removed, unsafe { clone_resources(&remap_ptrs) })
+        (removed, unsafe { clone_resources(&remap_ptrs) }, reactivated)
     };
+    for res in reactivated {
+        LAST_CONTENT.lock().unwrap().remove(&res);
+    }
     for r in &to_remap {
         unsafe {
             super::vram::remap_if_unmapped(r);
@@ -2337,12 +2344,12 @@ mod tests {
         assert_eq!((delta, unmap), (0, vec![1, 2, 20]));
         assert!(tbl.by_res.contains_key(&3) && tbl.by_res.contains_key(&4));
         // Releasing 4 uncovers newest non-overlapping shadowed entries (1 and 20) and requests remap.
-        let (removed, delta, mut remap) = tbl.remove(4);
+        let (removed, delta, mut remap, _) = tbl.remove(4);
         remap.sort_unstable();
         assert_eq!((removed, delta, remap), (true, 1, vec![1, 20]));
         assert!(tbl.by_res.contains_key(&1) && tbl.by_res.contains_key(&20) && tbl.shadowed.contains_key(&2));
         // Releasing 20 uncovers 2; releasing middle of a 3-chain still uncovers oldest when top goes.
-        let (removed, _, remap) = tbl.remove(20);
+        let (removed, _, remap, _) = tbl.remove(20);
         assert_eq!((removed, remap), (true, vec![2]));
         assert!(tbl.by_res.contains_key(&2));
         assert_eq!(tbl.insert(5, entry(0x10_8000, &tex_64k, true, true)).0, 1);
@@ -2529,6 +2536,12 @@ mod tests {
             assert_eq!(read_sub(&same_b, 0), want_2b, "row 3: new placement readback");
             assert_eq!(read_sub(&same_a, 0), want_2b, "row 4: older exact-range alias shares tiles");
             drop(same_b);
+            write_tiled(base + 0x1000, &same_desc, 0x1A);
+            refresh(queue.as_raw());
+            let want_1a = subresources(base + 0x1000, &xg::Texture::new(&same_desc).unwrap()).swap_remove(0).data;
+            let got_1a = read_sub(&same_a, 0);
+            let wrong = got_1a.iter().zip(&want_1a).filter(|(got, want)| got != want).count();
+            assert_eq!(wrong, 0, "uncovered exact-range sibling must upload restored CPU bytes");
             write_tiled(base + 0x1000, &same_desc, 0x3C);
             refresh(queue.as_raw());
             assert_eq!(read_sub(&same_a, 0), subresources(base + 0x1000, &xg::Texture::new(&same_desc).unwrap())[0].data, "row 6: releasing newer placement reactivates older one");
@@ -2553,6 +2566,12 @@ mod tests {
             assert_eq!(read_sub(&new_res, 0), want_b, "row 5: stale shadowed texture corrupted B");
             // Releasing B remaps previously-unmapped old_res cleanly and restores its pixels.
             drop(new_res);
+            write_tiled(base, &old_desc, 0xAA);
+            refresh(queue.as_raw());
+            let want_a = subresources(base, &xg::Texture::new(&old_desc).unwrap()).swap_remove(0).data;
+            let got_a = read_sub(&old_res, 0);
+            let wrong = got_a.iter().zip(&want_a).filter(|(got, want)| got != want).count();
+            assert_eq!(wrong, 0, "reactivated placement must upload when CPU bytes match its pre-unmap upload");
             write_tiled(base, &old_desc, 0xD4);
             refresh(queue.as_raw());
             assert_eq!(read_sub(&old_res, 0), subresources(base, &xg::Texture::new(&old_desc).unwrap())[0].data, "reactivated unmapped texture remapped cleanly");

AI use: Codex (GPT-6.2 Sol) traced the lifecycle, wrote and ran the local candidate and regression assertions, and drafted this report.

<!-- greyfinch-sync:ivall/xcl:comment:7196075082 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2484#issuecomment-7196075082). Originally posted by [thehollowedone](https://github.com/thehollowedone) on 2026-11-26T15:18:14Z. --- Independent RTX 3080 Ti follow-up on [PR head `1c9e839`](https://github.com/xcl-dev/xcl/commit/1c9e8396cd80b45d21329327daa9c604b5856bfc), building on [Kalmarv's remap report](https://github.com/xcl-dev/xcl/pull/2484#issuecomment-7183582759). I reproduced the different-range case in the existing placed-texture GPU test: after restoring the original CPU bytes and uncovering the old texture, its readback differed in **1,045,504 of 1,048,576 bytes**. Adding the two suggested hash invalidations at `unmap_superseded` made that assertion pass. There is a related exact-range path those two lines do not cover. Exact-range siblings share tiles and are shadowed without `unmap_superseded`. After the newer sibling overwrites the tiles, releasing it and restoring the older sibling's original CPU bytes left **262,144 of 262,144 bytes** wrong on this GPU. The older entry was reactivated with `pending=false`; clearing its hash only in the unmap loops could not schedule an upload. A local candidate that also marks each reactivated CPU-owned texture pending and clears its old hash before remapping passed both GPU readback assertions. This forces a fresh upload even if no write-watch page was captured after reactivation. Windows 11 build 26300; RTX 3080 Ti (driver 621.35); Ryzen 7 9800X3D; rustc 1.99.1 MSVC; DXC 1.8.2502.11. `cargo test --offline --locked -p xcl --lib placed_title_textures_share_vram_and_preserve_pixels -- --nocapture --test-threads=1`: stock assertion **0 passed, 1 failed**; different-range check with the two unmap invalidations **1 passed** before adding the exact-range assertion; with both assertions and the candidate below **1 passed, 0 failed, 0 ignored**, no GPU skip. `cargo test --offline --locked --workspace --no-fail-fast -- --test-threads=4` on the final local candidate: **1,422 passed, 1 failed, 46 ignored** across 37 targets, including 25 explicit GPU skip notices (21 no wave64, 3 refused per-lane forms, 1 no heap windows). The sole failure was `console_mesh_caches_hlsl_compute_pass_in_memory_and_on_disk` (`DXIL not compiled yet`); I reproduced it with the same focused command on untouched PR head. No retail title run or AMD/Intel test was performed. <details><summary>Exact local candidate diff (not committed)</summary> ```diff diff --git a/crates/xcl/src/hle/d3d12x/title_textures.rs b/crates/xcl/src/hle/d3d12x/title_textures.rs index 1e0a2bef..a185abed 100644 --- a/crates/xcl/src/hle/d3d12x/title_textures.rs +++ b/crates/xcl/src/hle/d3d12x/title_textures.rs @@ -237,16 +237,16 @@ impl Table { } /// Remove `res` on COM release, reactivating any shadowed older textures it uncovered (newest - /// first). Returns `(was_present, pending_delta, unmapped_res_to_remap)`. - fn remove(&mut self, res: usize) -> (bool, isize, Vec<usize>) { + /// first). Returns `(was_present, pending_delta, unmapped_res_to_remap, reactivated)`. + fn remove(&mut self, res: usize) -> (bool, isize, Vec<usize>, Vec<usize>) { if let Some(old) = self.shadowed.remove(&res) { self.shadowed_by_va.remove(&(old.va, res)); if self.shadowed.is_empty() { self.max_shadowed_size = 0; } - return (true, 0, Vec::new()); + return (true, 0, Vec::new(), Vec::new()); } - let Some(old) = self.by_res.remove(&res) else { return (false, 0, Vec::new()) }; + let Some(old) = self.by_res.remove(&res) else { return (false, 0, Vec::new(), Vec::new()) }; self.by_va.remove(&(old.va, res)); let mut pending_delta = if old.pending { -1 } else { 0 }; let va = old.va; @@ -258,18 +258,20 @@ impl Table { .collect(); cands.sort_unstable_by(|a, b| b.0.cmp(&a.0)); let mut to_remap = Vec::new(); + let mut reactivated = Vec::new(); for (_, sres, sva, send) in cands { if self.has_active_overlap(sva, send) { continue; } self.shadowed_by_va.remove(&(sva, sres)); if let Some(mut e) = self.shadowed.remove(&sres) { + reactivated.push(sres); if e.unmapped { e.unmapped = false; to_remap.push(sres); - if !e.gpu_written { - e.pending = true; - } + } + if !e.gpu_written { + e.pending = true; } if e.pending { pending_delta += 1; @@ -281,7 +283,7 @@ impl Table { if self.shadowed.is_empty() { self.max_shadowed_size = 0; } - (true, pending_delta, to_remap) + (true, pending_delta, to_remap, reactivated) } fn get_mut(&mut self, res: usize) -> Option<&mut Entry> { @@ -404,6 +406,7 @@ pub(super) unsafe fn register(device: *mut c_void, res: *mut c_void, va: usize, clone_resources(&unmap_ptrs) }; for r in &to_unmap { + LAST_CONTENT.lock().unwrap().remove(&(r.as_raw() as usize)); super::vram::unmap_superseded(r); } TEXTURES_GEN.fetch_add(1, Ordering::Release); @@ -541,6 +544,7 @@ pub(super) unsafe fn retire_overlapping(va: usize, len: usize) { (retired, clone_resources(&unmap_ptrs)) }; for r in &to_unmap { + LAST_CONTENT.lock().unwrap().remove(&(r.as_raw() as usize)); super::vram::unmap_superseded(r); } if retired > 0 { @@ -552,13 +556,16 @@ pub(super) unsafe fn retire_overlapping(va: usize, len: usize) { pub fn forget(res: usize) { LAST_CONTENT.lock().unwrap().remove(&res); STREAM_RECHECK.lock().unwrap().remove(&res); - let (removed, to_remap) = { + let (removed, to_remap, reactivated) = { let mut t = TEXTURES.lock().unwrap(); - let (removed, delta, remap_ptrs) = t.remove(res); + let (removed, delta, remap_ptrs, reactivated) = t.remove(res); adjust_pending(delta); TEXTURES_LEN.store(t.by_res.len(), Ordering::Relaxed); - (removed, unsafe { clone_resources(&remap_ptrs) }) + (removed, unsafe { clone_resources(&remap_ptrs) }, reactivated) }; + for res in reactivated { + LAST_CONTENT.lock().unwrap().remove(&res); + } for r in &to_remap { unsafe { super::vram::remap_if_unmapped(r); @@ -2337,12 +2344,12 @@ mod tests { assert_eq!((delta, unmap), (0, vec![1, 2, 20])); assert!(tbl.by_res.contains_key(&3) && tbl.by_res.contains_key(&4)); // Releasing 4 uncovers newest non-overlapping shadowed entries (1 and 20) and requests remap. - let (removed, delta, mut remap) = tbl.remove(4); + let (removed, delta, mut remap, _) = tbl.remove(4); remap.sort_unstable(); assert_eq!((removed, delta, remap), (true, 1, vec![1, 20])); assert!(tbl.by_res.contains_key(&1) && tbl.by_res.contains_key(&20) && tbl.shadowed.contains_key(&2)); // Releasing 20 uncovers 2; releasing middle of a 3-chain still uncovers oldest when top goes. - let (removed, _, remap) = tbl.remove(20); + let (removed, _, remap, _) = tbl.remove(20); assert_eq!((removed, remap), (true, vec![2])); assert!(tbl.by_res.contains_key(&2)); assert_eq!(tbl.insert(5, entry(0x10_8000, &tex_64k, true, true)).0, 1); @@ -2529,6 +2536,12 @@ mod tests { assert_eq!(read_sub(&same_b, 0), want_2b, "row 3: new placement readback"); assert_eq!(read_sub(&same_a, 0), want_2b, "row 4: older exact-range alias shares tiles"); drop(same_b); + write_tiled(base + 0x1000, &same_desc, 0x1A); + refresh(queue.as_raw()); + let want_1a = subresources(base + 0x1000, &xg::Texture::new(&same_desc).unwrap()).swap_remove(0).data; + let got_1a = read_sub(&same_a, 0); + let wrong = got_1a.iter().zip(&want_1a).filter(|(got, want)| got != want).count(); + assert_eq!(wrong, 0, "uncovered exact-range sibling must upload restored CPU bytes"); write_tiled(base + 0x1000, &same_desc, 0x3C); refresh(queue.as_raw()); assert_eq!(read_sub(&same_a, 0), subresources(base + 0x1000, &xg::Texture::new(&same_desc).unwrap())[0].data, "row 6: releasing newer placement reactivates older one"); @@ -2553,6 +2566,12 @@ mod tests { assert_eq!(read_sub(&new_res, 0), want_b, "row 5: stale shadowed texture corrupted B"); // Releasing B remaps previously-unmapped old_res cleanly and restores its pixels. drop(new_res); + write_tiled(base, &old_desc, 0xAA); + refresh(queue.as_raw()); + let want_a = subresources(base, &xg::Texture::new(&old_desc).unwrap()).swap_remove(0).data; + let got_a = read_sub(&old_res, 0); + let wrong = got_a.iter().zip(&want_a).filter(|(got, want)| got != want).count(); + assert_eq!(wrong, 0, "reactivated placement must upload when CPU bytes match its pre-unmap upload"); write_tiled(base, &old_desc, 0xD4); refresh(queue.as_raw()); assert_eq!(read_sub(&old_res, 0), subresources(base, &xg::Texture::new(&old_desc).unwrap())[0].data, "reactivated unmapped texture remapped cleanly"); ``` </details> AI use: Codex (GPT-6.2 Sol) traced the lifecycle, wrote and ran the local candidate and regression assertions, and drafted this report.
brainhay5 commented 2026-11-30 17:27:21 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by brainhay5 on 2026-11-30T17:27:21Z.


Triage note: this no longer merges with current main (mergeable=false, DIRTY), so it can't be built or tested as it stands.

If it's still wanted, a rebase would make it testable again. It's directly relevant to something we're measuring on an RTX 5070 Ti: the title-texture write-watch scan is the present-path cost we see (about 2.1 M dirty pages and up to ~6 s of scan time across a run), so "hash only written pages" is the right shape of fix.

If it has been superseded by other work, saying so is enough and it can be closed.

AI use: an agent posted this triage note.

<!-- greyfinch-sync:ivall/xcl:comment:7286319082 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2484#issuecomment-7286319082). Originally posted by [brainhay5](https://github.com/brainhay5) on 2026-11-30T17:27:21Z. --- Triage note: this no longer merges with current `main` (`mergeable=false`, `DIRTY`), so it can't be built or tested as it stands. If it's still wanted, a rebase would make it testable again. It's directly relevant to something we're measuring on an RTX 5070 Ti: the title-texture write-watch scan is the present-path cost we see (about 2.1 M dirty pages and up to ~6 s of scan time across a run), so "hash only written pages" is the right shape of fix. If it has been superseded by other work, saying so is enough and it can be closed. *AI use: an agent posted this triage note.*
Foniass commented 2026-12-01 08:09:44 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T08:09:44Z.


Triage (#1607) – head 1c9e839

Main now does what this PR adds: commit 73fc616f (D3D12.X: what changed of a texture goes up, through lists and buffers that are kept) moved uploads to texture_upload.rs, where Pages.hashes holds a hash per 4 KiB page and only the dirty pages are read and compared (changed). It goes further than this PR: it uploads only the changed parts, while this PR still uploads the whole texture. LAST_CONTENT/same_as_last_upload, which this diff replaces, are no longer on main, so the PR also conflicts.
Recommendation: close (superseded by main commit 73fc616f).

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

<!-- greyfinch-sync:ivall/xcl:comment:7304954118 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2484#issuecomment-7304954118). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T08:09:44Z. --- **Triage (#1607)** – head 1c9e839 Main now does what this PR adds: commit 73fc616f (`D3D12.X: what changed of a texture goes up, through lists and buffers that are kept`) moved uploads to `texture_upload.rs`, where `Pages.hashes` holds a hash per 4 KiB page and only the dirty pages are read and compared (`changed`). It goes further than this PR: it uploads only the changed parts, while this PR still uploads the whole texture. `LAST_CONTENT`/`same_as_last_upload`, which this diff replaces, are no longer on main, so the PR also conflicts. Recommendation: close (superseded by main commit 73fc616f). AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
throny commented 2026-12-01 12:53:23 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by throny on 2026-12-01T12:53:23Z.


Closing as superseded: this change is already on main (73fc616f). 73fc616f texture_upload.rs keeps per-page hashes (Known/changed, only the write-watched pages are compared); PR's PageHashes/changed_pages_since_last_upload is the same proposal

Two independent checks found this: Foniass's close list on #1607 and ours against current main. If something here is still missing on main, say so and reopen it, or ask and I will.

AI use: Claude Code (Claude Opus 5.5); the per-PR comparison was done by Claude Sonnet 5.5 sub-agents.

<!-- greyfinch-sync:ivall/xcl:comment:7311795185 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2484#issuecomment-7311795185). Originally posted by [throny](https://github.com/throny) on 2026-12-01T12:53:23Z. --- Closing as superseded: this change is already on `main` (73fc616f). 73fc616f texture_upload.rs keeps per-page hashes (Known/changed, only the write-watched pages are compared); PR's PageHashes/changed_pages_since_last_upload is the same proposal Two independent checks found this: Foniass's close list on #1607 and ours against current `main`. If something here is still missing on `main`, say so and reopen it, or ask and I will. AI use: Claude Code (Claude Opus 5.5); the per-PR comparison was done by Claude Sonnet 5.5 sub-agents.

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!2474
No description provided.