Skip to content

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

Open
ChalanaGimhanaX wants to merge 1 commit into
xcl-dev:mainfrom
ChalanaGimhanaX:d3d12x/title-texture-page-hashes
Open

ChalanaGimhanaX wants to merge 1 commit into
xcl-dev:mainfrom
ChalanaGimhanaX:d3d12x/title-texture-page-hashes

Conversation

@ChalanaGimhanaX

@ChalanaGimhanaX ChalanaGimhanaX commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

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 bmjask left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@ChalanaGimhanaX
ChalanaGimhanaX marked this pull request as draft November 25, 2026 20:20
Track per-page content hashes in LAST_CONTENT (PageHashes) and pass overlapping write-watched dirty pages from refresh_once into upload_all via Upload. When dirty pages are known for a previously uploaded texture at the same (src, size, page_size), changed_pages_with reads and hashes only those deduplicated clamped pages outside the LAST_CONTENT lock instead of re-hashing the full texture. First uploads, pending uploads, size/page_size changes, and xcl-dev#504 GPU-view remaps still perform the full per-page baseline pass, and recheck_gpu_view_sources invalidates LAST_CONTENT after dropping TEXTURES.

Verified with cargo test -p xcl --lib hle::d3d12x::title_textures::tests -- --test-threads=1 (24 passed, 0 failed).
@emirduran707

Copy link
Copy Markdown
Contributor

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
ChalanaGimhanaX marked this pull request as ready for review November 25, 2026 20:25
@ChalanaGimhanaX
ChalanaGimhanaX force-pushed the d3d12x/title-texture-page-hashes branch from b6b5b9c to 1c9e839 Compare November 25, 2026 20:31
@ChalanaGimhanaX

Copy link
Copy Markdown
Contributor Author

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.

raylitebull added a commit that referenced this pull request Nov 25, 2026
Port per-page content hashing (#2484 by ChAlanA) onto the indexed dirty_and_pending + parallel hash_and_detile_all upload pipeline:
- Track per-page hashes (PageHashes) in LAST_CONTENT and propagate overlapping dirty pages from refresh_once into Upload.
- For previously uploaded textures with known dirty pages, upload_all checks changed_pages_since_last_upload first (reading and hashing only those deduplicated clamped 4 KiB pages outside LAST_CONTENT) and skips unchanged textures without reading or detiling the full resource.
- For first/pending uploads, hash_and_detile_all populates PageHashes directly from the single already-read title_bytes buffer, preserving #2470 lazy-mip retry and #2460 invalidations plus invalidating LAST_CONTENT in recheck_gpu_view_sources.

Includes all 5 per-page dirty/unaligned/remap/dedup unit tests.

Assisted-by: Antigravity (Gemini 4 Neon High)
@DavidM1911

Copy link
Copy Markdown
Contributor

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

Thanks!

@KOLESNiii KOLESNiii mentioned this pull request Nov 25, 2026
gustavsi added a commit to gustavsi/xcl that referenced this pull request Nov 26, 2026
…textures)

Reconciles per-page content hashing with xcl-dev#751 safe ReadProcessMemory copy
and xcl-dev#871 Wine coherent-window round-robin hashing (now without holding
TEXTURES/LAST_CONTENT locks during hashing).

Assisted-by: Antigravity (Gemini 4 Neon)
@DavidM1911

Copy link
Copy Markdown
Contributor

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

Kalmarv commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

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 1c9e839), 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.

rootw0rm pushed a commit to rootw0rm/xcl that referenced this pull request Nov 26, 2026
…validation (port upstream xcl-dev#2484 + xcl-dev#2578)

(cherry picked from commit 77ff481152b0573c2df9d11a6dde8012ab13c482)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

D3D12.X: title textures keep per-page hashes and hash only written pages

5 participants