Skip to content

D3D12.X: compare the pages a mapping changed under a texture before upload - #3482

Open
Foniass wants to merge 2 commits into
xcl-dev:mainfrom
Foniass:d3d12x-remap-compare
Open

Foniass wants to merge 2 commits into
xcl-dev:mainfrom
Foniass:d3d12x-remap-compare

Conversation

@Foniass

@Foniass Foniass commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #3477 (same file); only the top commit (2b0ef63e) belongs here.

Port of raylitebull's amd-dev commit 02ceae64. When CopyPageMappingsBatchX changes 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=0 restores the old behaviour.

A main bug this fixes on the way. Main clears gpu_written once 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 in mapping_changed / the upload selection (texture_needs_upload), unknown on a published GPU write, tests remapped_pages_are_compared_with_what_they_held and a_remapped_page_of_a_texture_the_gpu_wrote_is_not_taken_for_what_it_held
  • crates/xcl/src/hle/d3d12x/texture_upload.rs: the hashes used by the comparison
  • Port: amd-dev's XCL_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

  • NVIDIA GeForce RTX 5070 Ti (driver 32.0.16.2114), AMD Ryzen 7 7800X3D, Windows 11 build 26300, Rust 1.100.0 (stable-x86_64-pc-windows-msvc), debug tests, release smoke
  • 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 the unknown() call.
  • cargo test --workspace --no-fail-fast -- --test-threads=4 on 2b0ef63, rebased on main 86e86fc (5070 Ti): 2892 passed, 0 failed, 51 ignored. SKIPPED: 28 notices, almost all no 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.
  • Retail title: 60 s smoke run below. The run doesn't reach this code: the log's CopyPageMappingsBatchX line says 0 textures read again for a changed mapping.

Regression run

main:

xcl-smoke v1
commit: 86e86fcb33f94fa5d0c809d9b50af7b84bf49cce
gpu: NVIDIA GeForce RTX 5070 Ti
title: 3cb1d8e0
seconds: 60
exit: 0x0
frames shown: 1608 (PresentX 1608)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15766 MB

this PR:

xcl-smoke v1
commit: 2b0ef63e5286e1b3f519940456cc096d36ff636c
gpu: NVIDIA GeForce RTX 5070 Ti
title: 3cb1d8e0
seconds: 60
exit: 0x0
frames shown: 1607 (PresentX 1607)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 16972 MB

Not tested

  • The open world, where the remaps happen; the 2 GB figure is amd-dev's
  • AMD GPUs
  • The tests check the bookkeeping and changed(), not an upload on a device

AI use

  • Claude Code with Claude Opus 5.5: ported the commit to main without its XCL_GPU_WRITE_STAYS dependency, found and fixed the stale hashes after a copy-back, wrote the extra test, ran the tests and the smoke runs, wrote this description.
  • Original code: raylitebull's amd-dev 02ceae64.

🤖 Generated with Claude Code

@github-actions github-actions Bot added area:d3d12 D3D12.X runtime, command lists, resources, sparse memory gpu:amd Code is specific to AMD / RDNA / wave64 GPUs (scope tag; see needs:amd-test) labels Nov 30, 2026
raylitebull and others added 2 commits November 30, 2026 22:43
…hange

`hot_runs` makes a block new to the watched ranges hot. To find those it
kept a set of all blocks (2 MiB) of the ranges of the last look and, each
time the ranges changed, made the set again over every block of every
range while holding `HOT` (the walk thread takes it too). The ranges are
made again whenever a tile is mapped, a texture is placed, a GPU-view page
is shown: in a retail title's world that is ~3.5 GB in 16 ranges, ~1,800
blocks, and the ranges change between many of the submits.

Now `new_blocks` compares the ranges with the last look's (both sorted and
apart, as `watch_ranges` makes them): a range found among the old ones as
it is has no new block, and a block of a changed range is new when no old
range meets it, which is what the set said. 16 ranges with one changed:
4 µs against 1.4 ms for a set of all their blocks (debug build, the test's
own timing; not measured in a release build or a game).

Test: new_blocks_are_those_no_old_range_meets (against a set of all the
old blocks: ranges grown, shifted, merged, new, gone, in part of a block).

Ported from amd-dev without its reasons for a hot block (`HOT_NEW`,
`look_stats::HOT_WHY`), which main does not have: a new block is put in
with its time only, as before.

(cherry picked from commit 5b660277a9460246eca668b144872fe4c66c1594)
(cherry picked from commit 5ff2b66)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…pload

When CopyPageMappingsBatchX changed the pages under a texture read
through its pages, those 64 KiB pages went up again with no comparison:
no write watch fires for a clean pool page newly mapped. In a retail
title's open world (RX 9070 XT) about 4400 textures per
1024 submits were read again that way ("25294 read again for a mapping
changed under them" by 127 s), next to 7903 uploads of 2082 MB that took
1890 ms of the 1024 submits.

The changed parts are now compared, page by page, with the hashes of
what the PC texture got at its last upload (the same comparison CPU-
written pages get; a page whose hash is not known differs), and only
pages that differ go up. A page mapped again with the bytes the texture
has (the same page after an unmap, a page moved in its pool) costs a
hash instead of an upload. A render target or UAV texture, and one the
GPU wrote that gives way, still sends its pages with no comparison.
VIctory-Neo does the same: a remapped slot is digested again and only
uploaded when its bytes differ. XCL_TEXTURE_REMAP_COMPARE=0 restores the
old behaviour; on by default.

A line every 1024 submits that upload says what went up and for what:
whole textures, CPU-written pages, remapped pages, parts sent again
behind another queue (count and MB each), how many remapped textures
were compared and left out, and the GPU writes kept by
XCL_GPU_WRITE_STAYS. It gives the breakdown the 2 GB could only be
estimated from before.

Tests: new title_textures::tests::remapped_pages_are_compared_with_what_
they_held. cargo test -p xcl --lib -- title_textures texture_upload:
53 passed, 0 failed (RX 9070 XT). Not measured on the title.

Port onto main: amd-dev's XCL_GPU_WRITE_STAYS (c06cf41) is not on
main, so its early return in mapping_changed and its test are left
out; main's own GPU-write tracking decides instead: a texture whose
gpu_written mark gives way to the mapping still sends its pages with no
comparison. main clears gpu_written once the GPU's bytes are copied
back (publish_download) but kept the hashes of the upload before the
GPU's write, so a page mapped again with those old bytes would have
looked the same and the PC texture kept the GPU's texels: a published
GPU write now makes what the texture's pages held unknown
(texture_upload::unknown), and the next comparison sends all of it. As
a side effect a CPU write to such a texture after the copy-back sends
it whole instead of in parts. The selection follows main's
texture_needs_upload (pages to compare count like parts to send again)
and main's Due (no displaced textures). The upload breakdown line
described above is not in this commit: it is the next one, on its own.
New test title_textures::tests::a_remapped_page_of_a_texture_the_gpu_
wrote_is_not_taken_for_what_it_held (fails without the unknown() call;
remapped_pages_are_compared_with_what_they_held fails without the
comparison). cargo +stable-x86_64-pc-windows-msvc test -p xcl --lib --
title_textures texture_upload: 77 passed, 0 failed, 1 ignored, no
SKIPPED (Windows 11, Ryzen 7 7800X3D with Radeon iGPU, RTX 5070 Ti).
Not measured on a title.

(cherry picked from commit 01ec624f32b33c2f4115f677781432b498471111)
(cherry picked from commit 02ceae6)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Foniass
Foniass force-pushed the d3d12x-remap-compare branch from 041e39e to 2b0ef63 Compare November 30, 2026 23:07
@github-actions github-actions Bot added needs-pr-check Failing the PR description check (CONTRIBUTING.md) and removed needs-pr-check Failing the PR description check (CONTRIBUTING.md) labels Nov 30, 2026
@fromthemoonx

fromthemoonx commented Dec 2, 2026 •

Copy link
Copy Markdown

merge-check
base: 1c8b551
head: 2b0ef63
merge: 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 2b0ef63e on top of #3477 (d8c75c5c, which my merge-check on #3477 covers). No correctness problem found.

  • A mapping change under a texture read through its pages now goes to 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, and XCL_TEXTURE_REMAP_COMPARE=0 keep the old whole upload.
  • A published GPU write now makes the texture's page hashes unknown (texture_upload::unknown), so old bytes mapped again are not taken for what the PC texture holds.
  • Each 30 of 30 alone, not skipped: title_textures::tests::remapped_pages_are_compared_with_what_they_held and a_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.
  • Mutation: the comparison branch off (every remapped page goes up whole, as on main) fails both new tests. Good.
  • Mutation: the texture_upload::unknown call after a published GPU write removed fails a_remapped_page_of_a_texture_the_gpu_wrote_is_not_taken_for_what_it_held. Good.
  • No retail title on this machine.
    performance: on by default.
  • Remapped pages are hashed before they go up, instead of going up whole: fewer uploads in the author's amd-dev count (about 4,400 textures per 1,024 submits), not measured here.
  • After a copied-back GPU write, the next CPU write sends the whole texture. The description says this is not measured.
    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)

@github-actions github-actions Bot added needs-1st-check Passes gates; needs first independent merge-check (#3041) needs:amd-test Needs a test report or merge-check on an AMD GPU needs-2nd-check Has 1 safe merge-check; needs second independent check (#3041) and removed needs-1st-check Passes gates; needs first independent merge-check (#3041) labels Dec 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:d3d12 D3D12.X runtime, command lists, resources, sparse memory gpu:amd Code is specific to AMD / RDNA / wave64 GPUs (scope tag; see needs:amd-test) needs:amd-test Needs a test report or merge-check on an AMD GPU needs-2nd-check Has 1 safe merge-check; needs second independent check (#3041)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants