Skip to content

D3D12.X: seek to textures overlapping sparse CPU writes - #1086

Open
TG0000 wants to merge 2 commits into
xcl-dev:mainfrom
TG0000:perf/dirty-texture-candidates
Open

TG0000 wants to merge 2 commits into
xcl-dev:mainfrom
TG0000:perf/dirty-texture-candidates

Conversation

@TG0000

@TG0000 TG0000 commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Each submit that finds written pages checked every tracked title texture against the list of written pages, even when only a few pages were written. A sparse submit now seeks the overlapping textures through the existing by_va placement index. Textures whose CPU source differs from their placement are kept in a small set and checked separately. Pending first uploads and dense writes keep the full scan, and the resulting upload order is unchanged.

Related to #582, but it does not change GetWriteWatch, which that issue measured as 99.7 % of a look. This is a saving of microseconds per submit in the selection step, not an expected frame-rate gain.

What is in it

  • crates/xcl/src/hle/d3d12x/title_textures.rs: indexed selection of upload candidates; insert_active / remove_active keep the remapped set in step with the placement index; a test against the full scan (aliases, remapped sources, shadowed and restored placements, GPU-written and pending textures, dense writes); a manual release benchmark (#[ignore]).
  • Review follow-up (7d92772), same file: the remapped update of recheck_gpu_view_sources is now Table::recheck_sources, so it runs without a GPU. a_source_that_flips_keeps_the_sparse_selection_exact has 26 textures, flips one source each way (and back) and compares collect_uploads with linear_upload_keys after every flip.

Tested

  • Ryzen 9 5900X, Radeon RX 6800 (driver 32.0.21045.29003), Windows build 26300, Rust 1.100.0 MSVC. Debug workspace and release xcl builds.
  • cargo test --workspace --no-fail-fast -- --test-threads=4 --show-output: 735 passed, 3 failed, 42 ignored on this head; 734 passed, 3 failed, 41 ignored on main 384f7f7. The same three fail in both: placed_title_textures_share_vram_and_preserve_pixels (3D texture, subresource 2 mismatch), and transitions_apply_when_their_list_is_submitted and d32s8_targets_take_their_own_size_of_video_memory on the lock it poisons.
  • SKIPPED in both, no D3D12 debug layer: test_title_draws_with_a_root_signature_under_the_debug_layer, uploads_start_from_each_subresources_state.
  • cargo clippy -p xcl --lib --tests (before the rebase, same patch): no warnings on the changed lines.
  • Follow-up commit 7d92772: cargo test -p xcl --lib d3d12x::title_textures -- --test-threads=4: 14 passed, 1 failed, 1 ignored (the benchmark). The failure is placed_title_textures_share_vram_and_preserve_pixels (3D texture, subresource 2 mismatch), which fails the same way on 3d5e3b1 (13 passed, 1 failed, 1 ignored). With the remapped update removed from recheck_sources, the new test fails. cargo clippy -p xcl --lib --tests: no warning on the changed lines. Same machine as above; the whole workspace was not run again for this commit.
  • cargo test --release -p xcl --lib bench_dirty_texture_candidates -- --ignored --nocapture, median of seven rounds, synthetic textures, µs per submit for the selection alone:
textures pages written full scan this PR
512 4 4.029 0.307 13.1x
512 16 6.199 1.897 3.3x
4096 4 40.353 0.368 109.5x
4096 16 53.251 2.173 24.5x
8192 4 99.095 0.406 244.2x

The ratio varies by run: two earlier runs of the 4096 / 4 row measured 72x and 90x.

Regression run

On the head 7d92772 and on its merge base with main, 384f7f7: one release build and one run each, from clean trees at those commits, the same title and 45 s. Other builds and tests ran on the PC during both runs, so the frame counts are not a timing comparison. Head: 1048 frames, main: 962; peak commit 15136 MB against 15133 MB; no device removal and no crash.

main:

xcl-smoke v1
commit: 384f7f7f8c79fa4d4dee59336d650a4021af4c7e
gpu: AMD Radeon RX 6800
title: retail-title-1.0.2.1
seconds: 45
exit: 0x0
frames shown: 962 (PresentX 962)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15133 MB

PR:

xcl-smoke v1
commit: 7d9277246277acb85a0a982a4a6b29ff1a1640d4
gpu: AMD Radeon RX 6800
title: retail-title-1.0.2.1
seconds: 45
exit: 0x0
frames shown: 1048 (PresentX 1048)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15136 MB

Earlier runs, on 3d5e3b1 (before the review follow-up). The first pair, main then PR. The title line is the folder name, replaced with a neutral label; everything else is as smoke.ps1 printed it.

main:

xcl-smoke v1
commit: 384f7f7f8c79fa4d4dee59336d650a4021af4c7e
gpu: AMD Radeon RX 6800
title: retail-title-1.0.2.1
seconds: 45
exit: 0x0
frames shown: 1036 (PresentX 1037)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15113 MB

PR:

xcl-smoke v1
commit: 3d5e3b139717b95ef16d44830e7615c6535a2079
gpu: AMD Radeon RX 6800
title: retail-title-1.0.2.1
seconds: 45
exit: 0x0
frames shown: 977 (PresentX 977)
presents per 2 s (last 3): 60 60 46
device removals: 0
crashes: 0
peak commit: 15513 MB

All five pairs of those two builds, frames shown (no crash and no device removal in any):

pair run first main PR
1 main 1036 977
2 main 1039 991
3 PR 986 787
4 PR 1045 1011
5 PR 1017 1034

Other builds ran on the PC during several of these, and I found no mechanism for a slowdown, but the PR's median is 4 % lower and its third run is below 80 % of main's, so a small cost is not ruled out. Runs 1 and 2 of the PR and run 3 of main peaked at about 15.5 GB, the others at about 15.1 GB. A run on a quiet PC is welcome.

Not tested

AI use

  • Codex in T3 Code with GPT 6.2 Sol wrote the change, the test and the benchmark. Claude Code with Claude Opus 5.5 reviewed the diff, ran the tests, benchmark and smoke runs, and wrote this description. Claude Code with Claude Sonnet 5.5 wrote the review follow-up commit (Table::recheck_sources and its test) and updated this description for it.

Use the placement index to select uploads when a submit dirties a few pages. Check remapped CPU sources separately and preserve resource order. First uploads and dense writes still use the full scan.

Co-Authored-By: GPT 6.2 Sol <noreply@openai.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@fromthemoonx

fromthemoonx commented Nov 24, 2026 •

Copy link
Copy Markdown

Rerun on the new head 7d9277246277acb85a0a982a4a6b29ff1a1640d4 (same machine, debug), which your follow-up did not run as a whole:

  • cargo build --workspace, then cargo test --workspace --no-fail-fast -- --test-threads=4: 739 passed, 0 failed, 42 ignored; placed_title_textures_share_vram_and_preserve_pixels passes here, as before
  • Merged onto current main 930e8b4 (no conflict): 753 passed, 0 failed, 42 ignored
  • The new test fails without the remapped update, as you say: with the two remapped lines in Table::recheck_sources removed, a_source_that_flips_keeps_the_sparse_selection_exact fails with left: [25], right: [5, 25]
  • hle::d3d12x::title_textures + hle::d3d12x::vram tests, 10 runs: 10 of 10 passed (22 passed, 1 ignored each)
  • D3D12 debug layer: the e2e test title's run on the merged tree logs the same debug-layer error and warning ids as on main 930e8b4

The first run, on 3d5e3b1, follows unchanged.


NVIDIA run, since Not tested lists NVIDIA. This machine has the D3D12 debug layer installed, so the two tests that were SKIPPED in your run ran here.

Tested

  • NVIDIA GeForce RTX 3060 12 GB (32-lane waves), driver 32.0.16.1088; AMD Ryzen 7 5700X; native Windows 11 Pro 26H2 (build 26300.9974), Graphics Tools (D3D12 debug layer) installed; rustc 1.100.0 stable-x86_64-pc-windows-msvc; DXC 1.9.2602.17

  • Exact head 3d5e3b139717b95ef16d44830e7615c6535a2079 (on its base 384f7f7), debug: cargo build --workspace, then cargo test --workspace --no-fail-fast -- --test-threads=4: 738 passed, 0 failed, 42 ignored (lib 695 / 0 / 22). Notable:

    • the new dirty_texture_candidates_match_the_full_scan passed
    • the three that fail in your RX 6800 run pass here: placed_title_textures_share_vram_and_preserve_pixels, transitions_apply_when_their_list_is_submitted, d32s8_targets_take_their_own_size_of_video_memory
    • the two you had SKIPPED ran and passed: test_title_draws_with_a_root_signature_under_the_debug_layer, uploads_start_from_each_subresources_state
  • Merged onto current main 47efa2e (no conflict): 742 passed, 0 failed, 42 ignored

  • hle::d3d12x::title_textures + hle::d3d12x::vram tests on the merged tree, 10 runs: 10 of 10 passed (23 passed, 1 ignored each)

  • D3D12 debug layer: the e2e test title's XCL_D3D12_DEBUG=1 run logs the same set of debug-layer errors and warnings on the merged tree as on main.

  • Release benchmark (cargo test --release -p xcl --lib bench_dirty_texture_candidates -- --ignored --nocapture), one run, µs per submit for the selection:

    textures pages full scan this PR
    512 1 / 4 / 16 2.29 / 3.66 / 4.95 0.13 / 0.32 / 1.67 18× / 11× / 3.0×
    4096 1 / 4 / 16 22.9 / 28.8 / 35.9 0.15 / 0.34 / 2.07 154× / 86× / 17×
    8192 1 / 4 / 16 44.8 / 62.1 / 83.7 0.14 / 0.39 / 2.59 320× / 158× / 32×

    Same shape as yours: the full scan is faster on this CPU, so the ratios differ, but the PR's times are close to yours.

  • SKIPPED (no wave64 on this adapter): gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware

Not tested

  • A retail title (no smoke.ps1 here); the benchmark is synthetic, and as you say the saving is per submit, not frame rate.

AI use

  • Claude Code (Claude Opus 5.5) ran the builds, tests and benchmark on the machine above and wrote this report from the output.

@pvfreis pvfreis 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.

Review of 3d5e3b1 against its merge base 384f7f7, by reading the code; nothing was built or run here, and no script of my own was run (only git and read-only gh). I looked for a texture that is written but no longer found, and did not find one: on the sparse path the seek through by_va selects the same textures, in the same order, as the full scan. The points below are a test gap, a note on #1102 and two notes on what the description already says.

What I traced for the "no missed upload" conclusion, all in crates/xcl/src/hle/d3d12x/title_textures.rs:

  • Textures spanning pages. A texture that starts before a dirty run and reaches into it is found by the look-back at :163-165. That is enough because active ranges with a different (va, end) are disjoint: insert shadows every active overlap except an exact-range unplaced alias (:269-285), and remove brings a shadowed texture back only when nothing active overlaps it (:329). Aliases share the start, so the range from (start, 0) at :166 takes all of them. A texture starting inside a run has its first page in the run (runs are contiguous, :158). One crossing two runs is found twice and deduplicated (:178-179).
  • Sources that differ from the placement. src is set in two places only: at registration (:436, classified in insert_active, :116-118) and in recheck_source (:528), whose only caller in the runtime updates remapped for active textures (:499-507). A shadowed texture whose source changed is classified again when it comes back, through insert_active (:344). Remapped textures are skipped in the seek (:171) and tested on src itself (:176).
  • Added, removed, moved between submits. by_res.insert / by_res.remove now exist only inside insert_active / remove_active (:114-127), so by_res, by_va and remapped cannot disagree, and the unwrap at :136 and the index at :176 hold. The selection runs under the TEXTURES lock, as before.
  • Sparse / dense threshold. Both paths give the same set, so the thresholds (:154, :168) only choose the cost. Under 16 textures count / 16 is 0 and any written page takes the full scan.
  • Pending uploads. The sparse path ignores e.pending, which is only right if PENDING == 0 means no active texture is pending. I followed every change of the counter (insert, remove, retire_range, recheck_source, the upload closure at :841-844): it can end up too high (point 3), never too low, and it is read under the lock at :840.
  • Upload order. candidates.sort_unstable() (:178) gives by_res key order, the order of the old iterator.
  1. CONFIRMED (test gap, not a defect): no test reaches the new remapped bookkeeping in recheck_gpu_view_sources (:498-508). dirty_texture_candidates_match_the_full_scan (:1643-1681) changes sources only through insert / remove. The two tests that change a source through the mirrors are gpu_mirror_upload_follows_cpu_writes_and_later_mapping_changes (:1295), which registers one texture, so count / 16 is 0 and every look is a full scan, and a_lazily_mapped_page_in_a_gpu_view_is_its_own_source (:1433), which calls recheck_source on a loose Entry. Scenario the suite would not catch: lines :501-505 are dropped or mis-merged; a texture in a GPU view whose page is unmapped goes from src == va to the CPU view but stays out of remapped; after its one pending upload, later sparse submits seek by va, the title's writes land at src, and the texture is never uploaded again. Suggestion: a test with 16 or more entries where one source flips each way, comparing collect_uploads with linear_upload_keys after each flip. Moving the three-line update into a small Table method would let it run without a GPU.

  2. #1102 changes the same code. #1102 (open, draft, stacked on #1055) is not in the description's overlap list. It replaces src: usize with a Source enum, rewrites the same loop in recheck_gpu_view_sources and adds a second path there through t.get_mut(res), so remapped has to be kept right on that path too when the two meet.

  3. CONFIRMED (already in the description's Not tested; credit to the author): PENDING can stay above zero for the rest of the run, and then this PR never takes the sparse path again. A shadowed texture whose source changes gets pending = true and PENDING + 1 (:509-510, :529-531). If it is released while shadowed, remove returns a delta of 0 (:310-315); if it comes back, :341-343 counts it a second time and its upload takes only one off. This is main's behaviour and the safe direction (full scan).

  4. Note on the numbers (as the author says; figures here are arithmetic on the description's tables, not measurements of mine). The pasted pair meets the rule: 977 / 1036 frames is 94.3 %, 15513 / 15113 MB is 102.6 %. Pair 3 (787 / 986) is 79.8 %, and the PR's median over the five pairs (991) is 4.3 % under main's (1036). I found nothing in the code that would cost frames: the sparse path does at most count / 16 seeks, count / 8 index steps and count / 4 binary searches under a lock that was already held. fromthemoonx's report on this head (738 passed, 0 failed on an RTX 3060, and 742 / 0 merged onto 47efa2e) covers NVIDIA and the two tests skipped on the author's machine.

Against CONTRIBUTING: the sections are all there (Tested with counts, Regression run with both blocks, Not tested, AI use with exact models), one commit, one file, 224 + 37 lines. The description's claims ("pending first uploads and dense writes keep the full scan", "upload order is unchanged") match the code.

Verdict: no defect found; correct as far as reading can tell. Before merging I would ask for the test of point 1, and for remapped to be kept right where #1102 meets this.

Review by Claude Code (written by Claude Fable 5.2, checked with Claude Opus 5.5); each point checked by a person before posting.

Review of xcl-dev#1086: nothing reached the `remapped` update in
recheck_gpu_view_sources, which needs a GPU. The update moves into
Table::recheck_sources (same loop, same order, shadowed textures too), and
a test with 26 textures flips one source each way (and one back) and
compares collect_uploads with linear_upload_keys after every flip. Without
the update the test fails.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@TG0000

TG0000 commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor Author

Thank you for the careful review. I checked each point against the code.

Pushed 7d92772 on top of 3d5e3b1 (no force push):

  • Point 1: the remapped update moved into Table::recheck_sources, so it runs without a GPU. The new test a_source_that_flips_keeps_the_sparse_selection_exact has 26 textures, flips one source each way (and back, twice) and compares collect_uploads with linear_upload_keys after every flip. It also flips a shadowed texture. With the remapped update removed from the method, it fails.
  • Point 2: D3D12.X: a texture in a GPU view reads the pages the page-mapping method put under it #1102 added to the overlap list in the description. I also checked D3D12.X: render targets on one physical page share its video memory #1182 (open): in title_textures.rs it only adds one GPU test to the tests module, and it edits vram.rs and kernelx.rs, so it does not touch this code. Listed too.
  • Point 3 and 4 need no change (existing behaviour, already in Not tested).

Tested: cargo test -p xcl --lib d3d12x::title_textures -- --test-threads=4: 14 passed, 1 failed, 1 ignored. The failure is placed_title_textures_share_vram_and_preserve_pixels (subresource 2 mismatch), which fails the same way on 3d5e3b1 (13 passed, 1 failed, 1 ignored). cargo clippy -p xcl --lib --tests: no warning on the changed lines. Update: xcl-smoke blocks for the new head 7d92772 and for main 384f7f7 are now in the description (1048 and 962 frames, no device removal or crash; other work ran on the PC, so not a timing comparison). The whole workspace was not run again for this commit.

AI-assisted: this follow-up was written and tested by Claude Code with Claude Sonnet 5.5.

@pvfreis

pvfreis commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Follow-up at 7d92772. I read the diff only; nothing was built or run here.

  • Point 1 is fixed. The remapped update is now Table::recheck_sources (title_textures.rs:131-147), with the same two loops in the same order. recheck_gpu_view_sources calls it at :516. The guard there is a temporary, so the lock is still released before TEXTURES_GEN is bumped, as before. a_source_that_flips_keeps_the_sparse_selection_exact (:1690-1752) checks that each look takes the sparse path, asserts the remapped set after every flip, and compares collect_uploads with linear_upload_keys. Dropping the update would fail it.
  • Point 2 is fixed: D3D12.X: a texture in a GPU view reads the pages the page-mapping method put under it #1102 is in the overlap list. Points 3 and 4 needed no change.
  • Still open before merging: PR checks now fails at 7d92772 because the Regression run block names 3d5e3b1, and the check wants an xcl-smoke block made on 7d92772. CI shows action_required at this head, so it has not run yet.

Reply by Claude Code (Claude Opus 5.5); checked by a person before posting.

@JoaoPauluu

Copy link
Copy Markdown

A regression run under Wine on Linux, on a retail title.

Tested

Regression run

main (first run):

xcl-smoke v1
commit: 47efa2ecea0a12934719ae69b81930cf02a4b1c3
gpu: NVIDIA GeForce RTX 3060
title: GTA6.Xbox.v1.0.2.1
seconds: 60
exit: 0x0
frames shown: 1384 (PresentX 1384)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 0 MB

this PR:

xcl-smoke v1
commit: 7d9277246277acb85a0a982a4a6b29ff1a1640d4
gpu: NVIDIA GeForce RTX 3060
title: GTA6.Xbox.v1.0.2.1
seconds: 60
exit: 0x0
frames shown: 1424 (PresentX 1424)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 0 MB

The last main run: 1425 frames, exit: 0x0, no device removal, no crash. Under Wine, peak commit reads 0 MB, so these blocks do not check memory.

Not tested

  • the test suite on this head; native Windows; AMD.

AI use

  • Claude Code (Claude Opus 5.5) built both commits, ran the runs and wrote this report. The account owner asked for test reports to be posted and has not reviewed this one.

@DavidM1911

Copy link
Copy Markdown
Contributor

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

Thanks!

@throny throny added the goal:world-load Bears on the retail title getting past world loading label Nov 25, 2026
@oni-swr

oni-swr commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

RX 7800 XT (RDNA3, wave32/wave64) report on exact head 7d9277246277acb85a0a982a4a6b29ff1a1640d4 (as is, on its base 384f7f7f; no merge with current main, which merges cleanly).

Tested

  • AMD Radeon RX 7800 XT, driver 32.0.31035.1003; Ryzen 7 5700X3D; Windows 11 build 26200; Rust 1.100.0 MSVC; debug profile; dxc.exe from Windows SDK 10.0.26100.0.
  • cargo test --workspace --no-fail-fast -- --test-threads=4 on this head: 739 passed, 0 failed, 42 ignored (19 targets); lib: 696 passed, 0 failed, 22 ignored.
  • Baseline, same machine and command, unmodified main at c9ee916a: 1330 passed, 2 failed, 46 ignored (24 targets). The 2 failures are gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1 (seed 722: CPU 0x7fffffff, GPU 0x1) and gpu::recomp::lower_dxil::tests::a_bridged_mask_write_where_one_half_is_elsewhere_meets_no_barrier.
  • Note: this older head does not contain either of the two baseline-failing tests (grep finds no fuzz_validate_and_gpu_1 in its output), so the 0 failures here say nothing about them.
  • Relevant tests, all passing: hle::d3d12x::title_textures::tests::* (including a_lazily_mapped_page_in_a_gpu_view_is_its_own_source, a_source_that_flips_keeps_the_sparse_selection_exact)
  • SKIPPED: none printed on this older head (the f16 and heap-window tests that skip on main are not in its output).

Not tested

  • No title and no scripts/smoke.ps1 run (no xcl-smoke blocks): I did not run an untrusted retail executable. This is a test-suite report only, not the regression run the PR needs.
  • Release profile, NVIDIA, Intel, Wine, RDNA2/RDNA4.

AI use

  • This run and report were done by Claude Code (Claude Sonnet 5.5): it fetched the head, ran the commands above and wrote this comment. Nothing was reviewed line by line for correctness here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

goal:world-load Bears on the retail title getting past world loading

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants