D3D12.X: compare the pages a mapping changed under a texture before upload #3482
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3482"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from ivall/xcl. Originally posted by Foniass on 2026-11-30T00:10:08Z.
Stacked on #3477 (same file); only the top commit (
2b0ef63e) belongs here.Port of raylitebull's amd-dev commit
02ceae64. WhenCopyPageMappingsBatchXchanges the pages under a texture read through its pages, those 64 KiB pages went up again without comparison, because no write watch fires for a clean pool page newly mapped. In a retail title's open world on amd-dev (RX 9070 XT), about 4,400 textures per 1,024 submits went up again that way, next to 2 GB of uploads.The changed pages are now compared with the hashes of what the PC texture got at its last upload, the same comparison CPU-written pages get, and only those that differ go up. A page whose hash is unknown counts as different. Render targets, UAVs and textures whose GPU write gives way to the mapping still go up without comparison.
XCL_TEXTURE_REMAP_COMPARE=0restores the old behaviour.A main bug this fixes on the way. Main clears
gpu_writtenonce the GPU's bytes are copied back (publish_download), but it kept the page hashes from the upload before the GPU write. A page that later held those old bytes again would look "the same", and the PC texture would keep the GPU's texels. That applies to remapped pages, and already on main to CPU-written ones. A published GPU write now makes the texture's page hashes unknown (texture_upload::unknown). The cost: after a copy-back, the next CPU write to that texture sends it whole instead of only its changed pages. That cost is not measured.What is in it
crates/xcl/src/hle/d3d12x/title_textures.rs: the comparison inmapping_changed/ the upload selection (texture_needs_upload),unknownon a published GPU write, testsremapped_pages_are_compared_with_what_they_heldanda_remapped_page_of_a_texture_the_gpu_wrote_is_not_taken_for_what_it_heldcrates/xcl/src/hle/d3d12x/texture_upload.rs: the hashes used by the comparisonXCL_GPU_WRITE_STAYS(c06cf419) is not ported (main has its own GPU-write copy-back), so its early return is left out; the upload breakdown line is the stacked follow-up.Tested
cargo test -p xcl --lib -- title_textures texture_upload: 77 passed, 0 failed, 1 ignored. Each new test fails without its change: without the comparison, and without theunknown()call.cargo test --workspace --no-fail-fast -- --test-threads=4on2b0ef63e, rebased on main86e86fcb(5070 Ti): 2892 passed, 0 failed, 51 ignored. SKIPPED: 28 notices, almost allno wave64(the others: no D3D12 debug layer, heap windows off, driver cache needs Developer Mode). The narrower runs listed here are from before the rebase.CopyPageMappingsBatchXline says 0 textures read again for a changed mapping.Regression run
main:
this PR:
Not tested
changed(), not an upload on a deviceAI use
XCL_GPU_WRITE_STAYSdependency, found and fixed the stale hashes after a copy-back, wrote the extra test, ran the tests and the smoke runs, wrote this description.02ceae64.🤖 Generated with Claude Code
Imported from ivall/xcl. Originally posted by fromthemoonx on 2026-12-02T02:00:33Z.
merge-check
base:
1c8b551475head:
2b0ef63e52merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2912 passed, 0 failed, 51 ignored (base: 2909 passed, 0 failed, 51 ignored); SKIPPED: 25 (22 no wave64, 2 no heap windows, 1 no GPU_UPLOAD heaps), the same set as base; failing: none
review: read this PR's commit
2b0ef63eon top of #3477 (d8c75c5c, which my merge-check on #3477 covers). No correctness problem found.texture_upload::recheck, and its next upload compares those pages with the hashes of what the PC texture last got. Before, they went up whole. A render or UAV target, a texture the GPU wrote, andXCL_TEXTURE_REMAP_COMPARE=0keep the old whole upload.texture_upload::unknown), so old bytes mapped again are not taken for what the PC texture holds.title_textures::tests::remapped_pages_are_compared_with_what_they_heldanda_remapped_page_of_a_texture_the_gpu_wrote_is_not_taken_for_what_it_held.hle::d3d12x::title_textures::tests::at--test-threads=8: 20 of 20 ok.texture_upload::unknowncall after a published GPU write removed failsa_remapped_page_of_a_texture_the_gpu_wrote_is_not_taken_for_what_it_held. Good.performance: on by default.
verdict: safe to merge
hardware / tool and model: RTX 3060 12 GB (610.88), Ryzen 7 5700X, Windows 11 Pro 26300 / Claude Code (Claude Opus 5.5)
Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T08:15:19Z.
Review: COMMENTED
Review of
2b0ef63e: 3 finding(s). 3 are inline.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.
Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T08:15:20Z.
Code review location:
crates/xcl/src/hle/d3d12x/title_textures.rs; line 2168take_recheckonly runs when the texture is inwaitingand!e.gpu_written. A GPU-written texture is still removed from AGAIN and not put back inlater, so its remapped pages are stranded inknown.recheckand never compared or uploaded. The title remaps a pool page under mip 3 of a non-target texture (recheck, AGAIN). Before the next submit, a list that writes only subresource 0 is published, so the whole entry becomesgpu_written. refresh_parts takes AGAIN, skipstake_recheck, and drops the texture.publish_downloadthen writes back only the pages that differ (subresource 0), so mip 3 never goes dirty, nothing re-queues it, and the PC texture keeps the old mip-3 texels. The oldstalepath had the same gap. Re-queuing the texture when recheck is non-empty would close it.Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T08:15:20Z.
Code review location:
crates/xcl/src/hle/d3d12x/title_textures.rs; line 980texture_upload::unknown()now runs on every published GPU write, so after each copy-back the next look finds the texture's hashes empty and uploads the whole texture instead of the changed pages. For a non-target texture written by GPU copies and copied back every frame,publish_downloadwrites into title memory, the write watch flags those pages, andchanged()seesh.len() != pages_ofand returns Change::All, a full upload every frame where only differing pages went up before.publish_downloadalready holds the exactconsolebytes the PC texture now has, so storing those pages' hashes there (viaall_sent) would fix the stale-hash problem without throwing the hashes away.Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T08:15:20Z.
Code review location:
crates/xcl/src/hle/d3d12x/title_textures.rs; line 888Not certain about this one:
forget()andunknown()clearagainbut not the newPages::recheck, so leftover recheck parts from before a forget surface in a later, unrelated upload and are compared against hashes they no longer belong to. Every place that clears or consumesagainneeds to handlerechecktoo, or the two should be one pending-change record with a compare flag.Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T14:12:57Z.
@Prime1997 could you take a look at this one for review and merge? My automated review notes are above, if any.
Imported from ivall/xcl. Originally posted by stijn-boer on 2026-12-02T18:12:05Z.
merge-check
base:
817eb1fc9fhead:
2b0ef63e52verdict: not yet: the focused remap tests passed and the workspace and retail smoke runs ended early on both builds. Retail upload counts remain unverified.
Windows / AMD RDNA4 (native D3D12) — texture page remapping checks on
2b0ef63Clean merge onto
mainat817eb1f(merge commitf6c15bb86396d979bc9f67aa2f0b73f750594706).git diff --checkwas clean.Setup
d3d12SDKLayers.dll, DXC 1.9.2609.5Tested
cargo build --workspacepassed.cargo test --workspace --no-fail-fast -- --test-threads=4 --show-outputexited 101 on both builds. The baseline table row is from a prior run of the same commit, machine, SDK, and command.SKIPPEDnoticesmainCounts are partial because two test processes aborted on each build.
main— none observed in the comparable results.--test-threads=1 --show-output --nocapture. They cover equal and changed bytes after page remaps, invalidation after GPU writes, and newly covered blocks.uploads_start_from_each_subresources_statepassed.Shared failures and process aborts
fuzz_validate_and_gpu_1,fuzz_validate_and_gpu_3, andtwo_pass_driver_cache_reuses_both_passes_and_recovers_corrupt_blobsreported failures on both builds.gpu_compute_e2etest processes exited with0xc0000409on both builds.Retail smoke
Ran
scripts/smoke.ps1 -Game <local folder> -Seconds 60 -Xcl <debug binary>withXCL_UMA_DRIVER=mixedfor title hash2c508222.main0xc00004090xc0000409XCL_TEXTURE_REMAP_COMPARE=00xc00004090xc0000409The higher initial startup commit did not reproduce. These exits leave retail upload counts and frame behavior unverified.
Diff review
The remap comparison path schedules affected pages for comparison while GPU-written textures invalidate cached page fingerprints. The focused tests exercised both choices as well as comparison-disabled behavior.
Not tested
Remaining workspace tests after the aborts, retail frame performance, and a retail upload-count comparison with remap comparison off and on.
AI use
Codex (GPT-6) merged and built the PR, ran the tests, compared the results with
main, reviewed the diff, and drafted this report.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.