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
ivall:mainfrom
Grimkaaah:fix/504-title-textures-content-hash
Open

Grimkaaah wants to merge 1 commit into
ivall: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

…vall#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.

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)

5 participants