Skip to content

D3D12.X: fix title texture skip hash on remap, one read, no poison (#504) - #508

Open
Grimkaaah wants to merge 1 commit into
xcl-dev:mainfrom
Grimkaaah:fix/504-title-textures-content-hash
Open

Grimkaaah wants to merge 1 commit into
xcl-dev:mainfrom
Grimkaaah:fix/504-title-textures-content-hash

Conversation

@Grimkaaah

Copy link
Copy Markdown

Summary

Fixes #504

Test plan

  • cargo test -p xcl --lib hle::d3d12x::title_textures::tests::last_content
  • cargo test -p xcl --lib hle::d3d12x::title_textures::tests::a_texture_with_unchanged_memory

…cl-dev#504)

Clear LAST_CONTENT on unmap/remap; hash and detile from one read_committed snapshot; remember hashes only after a successful upload_batch entry.

Co-authored-by: Cursor <cursoragent@cursor.com>
@thehollowedone

Copy link
Copy Markdown

The upload path now reads title memory once. There’s one more full copy of the detiled bytes on each cache miss: subs.clone() duplicates every subresource’s owned Vec<u8> while the original batch is still live. Could upload_all push (r, subs, states) directly into the upload list and append (res_key, h) to a parallel list at the same point? That keeps the failure indices aligned and moves the bytes into the batch once. Batch construction at 61ee2a2 · Subresource definition

Tested

On the same commit, cargo test --offline --locked -p xcl --lib hle::d3d12x::title_textures::tests -- --test-threads=1 --nocapture passed 9 tests, with 0 failures, 0 ignored and no reported skips. XCL selected the RTX 3080 Ti (621.35). Ryzen 7 9800X3D, Windows 11 build 26300, Rust 1.99.1 MSVC, debug.

Not tested

Full workspace, retail titles, and the performance impact of removing the copy.

AI use

Codex with GPT-6.2 Astra reviewed the upload path, ran the tests and drafted this report.

@Abdellah-Khanani

Copy link
Copy Markdown

Tested on AMD RDNA1: no new failures.

  • AMD Radeon RX 5700 XT (RDNA1), driver 32.0.21045.29003; Ryzen 5 2600; Windows 11 Pro 22631; Rust 1.100.0 MSVC, debug.
  • cargo test --workspace --no-fail-fast -- --test-threads=4 on this PR's head 61ee2a2 (on top of current main 7ebf1b8): 677 passed, 1 failed, 41 ignored. On main 7ebf1b8 alone: 676 passed, 1 failed, 41 ignored.
  • The one failure is gpu::recomp::tests::gpu_nonfused_mad_and_mac_prevent_fma_contraction. It fails on main on this adapter too and is unrelated (Recompiler: v_fma_f32 is not fused on AMD's RDNA1 driver (mad() left unfused) #472).
  • last_content_is_not_poisoned_by_a_hash_check_alone, a_texture_with_unchanged_memory_is_left_out_until_it_is_forgotten and the other 7 title_textures tests pass. On this adapter placed_title_textures_share_vram_and_preserve_pixels is SKIPPED on main (the driver refuses the reserved cube; see D3D12.X: map a one-slice title texture's packed mips where D3D12 addresses them #470), so it does not cover this change here.
  • SKIPPED: gpu_geometry_mode_es_gs_strip, gpu_mesh_mode_two_passes (no mesh shaders).
  • Diff read in full before building. Upload failures are reported by batch index (upload_batch pushes (k, e)), so the failed_idx mapping to keys is right.
  • No retail title run.

Tested with Claude Code (Claude Opus 5.5); the run was on my machine.

@gta5all

gta5all commented Nov 24, 2026

Copy link
Copy Markdown

Review of 8d09824's diff against main (69f0635). The three fixes match #504, and reading the memory once and slicing it gives the same bytes as the old per-slice read_committed calls (size() covers array × slice_bytes, and bytes past the end read as 0 in detile_level / detile_volume). Two things I'd change before it is merged:

1. Every batch's detiled data is copied once more. upload_items clones each item's Vec<Subresource> (up to BATCH_BYTES, 256 MiB, per batch) only to drop the two extra tuple fields. That gives back much of what reading once saves. Keeping batch as the tuple upload_batch takes, with the keys in a separate vec, avoids the copy:

-            batch.push((r, subs, states, res_key, h));
+            batch.push((r, subs, states));
+            keys.push((res_key, h));
-        let upload_items: Vec<_> = batch.iter().map(|(r, subs, states, _, _)| (r.clone(), subs.clone(), states.clone())).collect();
-        let keys: Vec<_> = batch.iter().map(|(_, _, _, res, h)| (*res, *h)).collect();
         match own_work(|| {
             super::vram::before_execute(&queue);
-            texture::upload_batch(dev, &queue, &upload_items)
+            texture::upload_batch(dev, &queue, &batch)
         }) {

(with let mut keys = Vec::new(); next to let mut batch = Vec::new();). Smaller point: with XCL_TEXTURE_SKIP_UNCHANGED=0 the hash is still computed for every upload. let h = if unchanged_skip() { content_hash(&mem) } else { 0 }; only remembers a dummy hash that is never compared.

2. No test fails without the fix for #504.1. last_content_is_not_poisoned_by_a_hash_check_alone checks the helpers only. The placement test misses the remap case because it writes a new pattern (0xD4) before the refresh that follows drop(new_res). Restoring the old texture's memory to what it held at its last upload shows the bug: B's 0x55 write lies inside old_res, so rewriting 0xAA gives the bytes of old_res's last upload while its remapped tiles hold B's data. Without the LAST_CONTENT removal in forget, this upload is skipped and the assert fails:

             drop(new_res);
+            write_tiled(base, &old_desc, 0xAA); // the bytes of old_res's last upload, before B
+            refresh(queue.as_raw());
+            assert_eq!(read_sub(&old_res, 0), subresources(base, &xg::Texture::new(&old_desc).unwrap())[0].data, "#504.1: remapped texture with unchanged memory is uploaded again");
             write_tiled(base, &old_desc, 0xD4);

Also: the multi-line reformatting of the two Subresource { .. } expressions in subresources_from is churn CONTRIBUTING asks to leave out. And the PR description check fails because the description has no Tested (full GPU suite counts), Regression run (the two xcl-smoke blocks), Not tested or AI use sections.

Static review only: I did not build or run this (no Windows machine here). The diffs above are suggestions to check, not tested code.

Written with Claude Code (Claude Opus 5.5), under human review.

@Alpha325

Copy link
Copy Markdown

I ran the unchanged-source remap regression suggested in review. I applied the same local test-only edits to base 7ebf1b8 and PR head 61ee2a2.

The fixture uploads a 512×512 RGBA8 texture, then places and uploads a smaller texture over part of its address range. While the old texture is still shadowed, the fixture restores the exact CPU bytes from its first upload. It then releases the overlapping texture, calls refresh, and compares the old texture’s GPU readback byte for byte.

Build Uploads after remap Hash skips Wrong readback bytes
Base, cache enabled 0 1 1,045,504 / 1,048,576
Base, cache disabled 1 0 0 / 1,048,576
PR, cache enabled 1 0 0 / 1,048,576

The cache-disabled control isolates the cause: identical CPU bytes do not mean the remapped GPU tiles still contain the old texture. The PR forces the upload and restores the full readback. I’d add this case to placed_title_textures_share_vram_and_preserve_pixels, since the existing fixture writes a different pattern after remapping.

Tested: Radeon RX 9060 XT, driver 32.0.32029.2010, Windows 11, Rust 1.100.0 MSVC x64, release. The PR’s texture test module passed 9/9 with the fixture and no skips. This check covers remap invalidation, not upload-failure handling or snapshot performance.

AI use: OpenAI Codex (GPT-6.2 Sol) wrote the local fixture, ran the tests, and drafted this report.

@ryosen0

ryosen0 commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Test report on NVIDIA (the review thread so far has RDNA1 and code audits): PR head 61ee2a2 merged onto main 508a0c7 (clean merge), release build, RTX 3060 Ti 8 GB (wave32), Ryzen 7 9800X3D, driver 32.0.16.1742, Windows 11.

Tested

  • cargo test -p xcl --lib -- --test-threads=1 title_textures xaudio2 acphal on the merge with acphal: audio frame deadlines are exact 1/375 s per frame index #468 and XAudio2: a voice at a reused address drops the stale decoder's state #456 also applied (all three touch adjacent paths): 27 passed, 0 failed - including the three new LAST_CONTENT tests (last_content_is_not_poisoned_by_a_hash_check_alone, the unchanged-remap regression, the one-read snapshot).
  • The title_textures GPU tests (gpu_mirror_upload_follows_cpu_writes_and_later_mapping_changes, placed_title_textures_share_vram_and_preserve_pixels, transitions_apply_when_their_list_is_submitted) pass serially on this adapter. Under --test-threads=4 the same set fails on a poisoned lock on unmodified main too (documented in D3D12.X: show live FPS in the game window title #516's report) - worth running GPU tests serially when reporting counts.
  • Retail run (GTA VI 1.0.2.1, XCL_NETWORK=0 XCL_ACTIVITY=1): the game exited cleanly on its own at t≈34 s during shader warm-up (exit 0x0, no crash, no device removal) - the early-exit behaviour varies run to run on this title; nothing in the log points at the skip path. Not counted as a regression signal either way.

Not tested

  • A long retail run on this PR alone; no visual comparison of remapped textures.

AI use: GPT-6.2 Astra (API model selector) in DSH ran the builds/tests and wrote this comment; the human contributor reviewed it.

@jacksonslab

Copy link
Copy Markdown

Tested on a retail title (Windows 11, RTX 4070 SUPER 12 GB, i7-14700K). We hit #504.3 independently: with #486's skip-unchanged on, a failed upload_queue/upload_batch left the content hash recorded, so the texture was never uploaded again. We had a local fix that only forgot the hash on failure; this PR's version is strictly better (also covers remaps with unchanged bytes and the double read). We've replaced our fix with this PR in our test build; title_textures tests pass.

@Toons29

Toons29 commented Nov 25, 2026

Copy link
Copy Markdown

Regression run of 61ee2a28 on the retail title, for this PR's Regression run section. Both blocks are from scripts/smoke.ps1 as printed, not edited: main on 4178e888, this PR on its head commit with no uncommitted changes, same title and time.

xcl-smoke v1
commit: 4178e888c0b5be50a2887eda45cdb832763b68a4
gpu: AMD Radeon RX 9070
title: game.exe
seconds: 60
exit: 0x0
frames shown: 1618 (PresentX 1618)
presents per 2 s (last 3): 61 60 60
device removals: 0
crashes: 0
peak commit: 14831 MB
xcl-smoke v1
commit: 61ee2a280184ba22995ef306609dc18aa975e981
gpu: AMD Radeon RX 9070
title: game.exe
seconds: 60
exit: 0x0
frames shown: 1488 (PresentX 1488)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14799 MB

Against the limits in CONTRIBUTING.md: 92 % of main's frames, 100 % of its peak commit, no crash, no device removal.

AMD Radeon RX 9070 (RDNA4, driver 32.0.32029.2010), Ryzen 7 7800X3D, 32 GB, Windows 11 build 26300, Rust 1.100.0, cargo build --release -p xcl, 60 s, XCL_NETWORK=0. This is a regression check only: it does not show whether the run reaches the code this PR changes.

AI use: Claude Code (Claude Opus 5.5) built both trees and ran scripts/smoke.ps1; I checked the blocks before posting.

@DavidM1911

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11): merge conflict with current main — needs a rebase before it can be tested.

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 content hash skips remapped textures, double-reads changed textures, and caches failed uploads (#486)

9 participants