D3D12.X: seek to textures overlapping sparse CPU writes #1077
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1086"
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 TG0000 on 2026-11-24T11:25:27Z.
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_vaplacement 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_activekeep 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]).7d92772), same file: theremappedupdate ofrecheck_gpu_view_sourcesis nowTable::recheck_sources, so it runs without a GPU.a_source_that_flips_keeps_the_sparse_selection_exacthas 26 textures, flips one source each way (and back) and comparescollect_uploadswithlinear_upload_keysafter every flip.Tested
xclbuilds.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 onmain384f7f7. The same three fail in both:placed_title_textures_share_vram_and_preserve_pixels(3D texture, subresource 2 mismatch), andtransitions_apply_when_their_list_is_submittedandd32s8_targets_take_their_own_size_of_video_memoryon the lock it poisons.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.7d92772:cargo test -p xcl --lib d3d12x::title_textures -- --test-threads=4: 14 passed, 1 failed, 1 ignored (the benchmark). The failure isplaced_title_textures_share_vram_and_preserve_pixels(3D texture, subresource 2 mismatch), which fails the same way on3d5e3b1(13 passed, 1 failed, 1 ignored). With theremappedupdate removed fromrecheck_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:The ratio varies by run: two earlier runs of the 4096 / 4 row measured 72x and 90x.
Regression run
On the head
7d92772and 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:
PR:
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 assmoke.ps1printed it.main:
PR:
All five pairs of those two builds, frames shown (no crash and no device removal in any):
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
PENDINGand nothing takes that count back (existing behaviour, read in the code, not reproduced). Where that happensPENDINGstays above zero and every look uses the full scan, as before.recheck_gpu_view_sources(aSourceenum in place ofsrc) and adds a second path there throught.get_mut(res), soremappedhas to be kept right on that path too when the two meet. #1182 (open) touches this file only in the tests module (one new GPU test), plusvram.rsandkernelx.rs; it does not change the code here.AI use
Table::recheck_sourcesand its test) and updated this description for it.Imported from ivall/xcl. Originally posted by fromthemoonx on 2026-11-24T12:02:12Z.
Rerun on the new head
7d9277246277acb85a0a982a4a6b29ff1a1640d4(same machine, debug), which your follow-up did not run as a whole:cargo build --workspace, thencargo test --workspace --no-fail-fast -- --test-threads=4: 739 passed, 0 failed, 42 ignored;placed_title_textures_share_vram_and_preserve_pixelspasses here, as beforemain930e8b4(no conflict): 753 passed, 0 failed, 42 ignoredremappedupdate, as you say: with the tworemappedlines inTable::recheck_sourcesremoved,a_source_that_flips_keeps_the_sparse_selection_exactfails withleft: [25], right: [5, 25]hle::d3d12x::title_textures+hle::d3d12x::vramtests, 10 runs: 10 of 10 passed (22 passed, 1 ignored each)main930e8b4The 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.17Exact head
3d5e3b139717b95ef16d44830e7615c6535a2079(on its base384f7f7), debug:cargo build --workspace, thencargo test --workspace --no-fail-fast -- --test-threads=4: 738 passed, 0 failed, 42 ignored (lib 695 / 0 / 22). Notable:dirty_texture_candidates_match_the_full_scanpassedplaced_title_textures_share_vram_and_preserve_pixels,transitions_apply_when_their_list_is_submitted,d32s8_targets_take_their_own_size_of_video_memorytest_title_draws_with_a_root_signature_under_the_debug_layer,uploads_start_from_each_subresources_stateMerged onto current
main47efa2e(no conflict): 742 passed, 0 failed, 42 ignoredhle::d3d12x::title_textures+hle::d3d12x::vramtests 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=1run logs the same set of debug-layer errors and warnings on the merged tree as onmain.Release benchmark (
cargo test --release -p xcl --lib bench_dirty_texture_candidates -- --ignored --nocapture), one run, µs per submit for the selection: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_hardwareNot tested
smoke.ps1here); the benchmark is synthetic, and as you say the saving is per submit, not frame rate.AI use
Imported from ivall/xcl. Originally posted by pvfreis on 2026-11-24T13:00:08Z.
Review: COMMENTED
Review of
3d5e3b1against its merge base384f7f7, by reading the code; nothing was built or run here, and no script of my own was run (onlygitand read-onlygh). I looked for a texture that is written but no longer found, and did not find one: on the sparse path the seek throughby_vaselects 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::163-165. That is enough because active ranges with a different(va, end)are disjoint:insertshadows every active overlap except an exact-range unplaced alias (:269-285), andremovebrings a shadowed texture back only when nothing active overlaps it (:329). Aliases share the start, so the range from(start, 0)at:166takes 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).srcis set in two places only: at registration (:436, classified ininsert_active,:116-118) and inrecheck_source(:528), whose only caller in the runtime updatesremappedfor active textures (:499-507). A shadowed texture whose source changed is classified again when it comes back, throughinsert_active(:344). Remapped textures are skipped in the seek (:171) and tested onsrcitself (:176).by_res.insert/by_res.removenow exist only insideinsert_active/remove_active(:114-127), soby_res,by_vaandremappedcannot disagree, and theunwrapat:136and the index at:176hold. The selection runs under theTEXTURESlock, as before.:154,:168) only choose the cost. Under 16 texturescount / 16is 0 and any written page takes the full scan.e.pending, which is only right ifPENDING == 0means 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.candidates.sort_unstable()(:178) givesby_reskey order, the order of the old iterator.CONFIRMED (test gap, not a defect): no test reaches the new
remappedbookkeeping inrecheck_gpu_view_sources(:498-508).dirty_texture_candidates_match_the_full_scan(:1643-1681) changes sources only throughinsert/remove. The two tests that change a source through the mirrors aregpu_mirror_upload_follows_cpu_writes_and_later_mapping_changes(:1295), which registers one texture, socount / 16is 0 and every look is a full scan, anda_lazily_mapped_page_in_a_gpu_view_is_its_own_source(:1433), which callsrecheck_sourceon a looseEntry. Scenario the suite would not catch: lines:501-505are dropped or mis-merged; a texture in a GPU view whose page is unmapped goes fromsrc == vato the CPU view but stays out ofremapped; after its one pending upload, later sparse submits seek byva, the title's writes land atsrc, and the texture is never uploaded again. Suggestion: a test with 16 or more entries where one source flips each way, comparingcollect_uploadswithlinear_upload_keysafter each flip. Moving the three-line update into a smallTablemethod would let it run without a GPU.#1102 changes the same code. #1102 (open, draft, stacked on #1055) is not in the description's overlap list. It replaces
src: usizewith aSourceenum, rewrites the same loop inrecheck_gpu_view_sourcesand adds a second path there throught.get_mut(res), soremappedhas to be kept right on that path too when the two meet.CONFIRMED (already in the description's Not tested; credit to the author):
PENDINGcan 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 getspending = trueandPENDING + 1(:509-510,:529-531). If it is released while shadowed,removereturns a delta of 0 (:310-315); if it comes back,:341-343counts it a second time and its upload takes only one off. This ismain's behaviour and the safe direction (full scan).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 mostcount / 16seeks,count / 8index steps andcount / 4binary 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 onto47efa2e) 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
remappedto 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.
Imported from ivall/xcl. Originally posted by TG0000 on 2026-11-24T13:58:52Z.
Thank you for the careful review. I checked each point against the code.
Pushed
7d92772on top of3d5e3b1(no force push):remappedupdate moved intoTable::recheck_sources, so it runs without a GPU. The new testa_source_that_flips_keeps_the_sparse_selection_exacthas 26 textures, flips one source each way (and back, twice) and comparescollect_uploadswithlinear_upload_keysafter every flip. It also flips a shadowed texture. With theremappedupdate removed from the method, it fails.title_textures.rsit only adds one GPU test to the tests module, and it editsvram.rsandkernelx.rs, so it does not touch this code. Listed too.Tested:
cargo test -p xcl --lib d3d12x::title_textures -- --test-threads=4: 14 passed, 1 failed, 1 ignored. The failure isplaced_title_textures_share_vram_and_preserve_pixels(subresource 2 mismatch), which fails the same way on3d5e3b1(13 passed, 1 failed, 1 ignored).cargo clippy -p xcl --lib --tests: no warning on the changed lines. Update:xcl-smokeblocks for the new head7d92772and for main384f7f7are 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.
Imported from ivall/xcl. Originally posted by pvfreis on 2026-11-24T14:06:30Z.
Follow-up at
7d92772. I read the diff only; nothing was built or run here.remappedupdate is nowTable::recheck_sources(title_textures.rs:131-147), with the same two loops in the same order.recheck_gpu_view_sourcescalls it at:516. The guard there is a temporary, so the lock is still released beforeTEXTURES_GENis bumped, as before.a_source_that_flips_keeps_the_sparse_selection_exact(:1690-1752) checks that each look takes the sparse path, asserts theremappedset after every flip, and comparescollect_uploadswithlinear_upload_keys. Dropping the update would fail it.PR checksnow fails at7d92772because the Regression run block names3d5e3b1, and the check wants anxcl-smokeblock made on7d92772.CIshowsaction_requiredat this head, so it has not run yet.Reply by Claude Code (Claude Opus 5.5); checked by a person before posting.
Imported from ivall/xcl. Originally posted by JoaoPauluu on 2026-11-24T14:21:42Z.
A regression run under Wine on Linux, on a retail title.
Tested
x86_64-pc-windows-gnu.7d92772as it is (merge base384f7f7) andmain47efa2e, no uncommitted changes. Retail title 1.0.2.1,scripts/linux/smoke.sh(#257) for 60 s, no input. Twelve runs in a row,mainfirst and last, other PRs in between.384f7f7; themainruns are of47efa2e, a later commit ofmain.Regression run
main (first run):
this PR:
The last
mainrun: 1425 frames,exit: 0x0, no device removal, no crash. Under Wine,peak commitreads 0 MB, so these blocks do not check memory.Not tested
AI use
Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-25T08:36:47Z.
Verification on RTX 3060 Ti (Windows 11), branch merged with current
main:cargo test -p xcl --lib: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.)Thanks!
upstream-sync referenced this pull request2026-11-25 16:10:51 +00:00
Imported from ivall/xcl. Originally posted by oni-swr on 2026-11-25T18:33:50Z.
RX 7800 XT (RDNA3, wave32/wave64) report on exact head
7d9277246277acb85a0a982a4a6b29ff1a1640d4(as is, on its base384f7f7f; no merge with currentmain, which merges cleanly).Tested
dxc.exefrom Windows SDK 10.0.26100.0.cargo test --workspace --no-fail-fast -- --test-threads=4on this head: 739 passed, 0 failed, 42 ignored (19 targets); lib: 696 passed, 0 failed, 22 ignored.mainatc9ee916a: 1330 passed, 2 failed, 46 ignored (24 targets). The 2 failures aregpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1(seed 722: CPU0x7fffffff, GPU0x1) andgpu::recomp::lower_dxil::tests::a_bridged_mask_write_where_one_half_is_elsewhere_meets_no_barrier.fuzz_validate_and_gpu_1in its output), so the 0 failures here say nothing about them.hle::d3d12x::title_textures::tests::*(includinga_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 onmainare not in its output).Not tested
scripts/smoke.ps1run (noxcl-smokeblocks): I did not run an untrusted retail executable. This is a test-suite report only, not the regression run the PR needs.AI use
Imported from ivall/xcl. Originally posted by bmjask on 2026-11-25T21:49:36Z.
Review: COMMENTED
No blocking correctness issue found. Sparse candidate selection uses active-range invariants, remap side scan, and conservative full-scan fallbacks correctly; source-flip/shadow test compares against full-scan oracle. Nonblocking gap: no end-to-end GPU mapping change -> new CPU source write -> pixel validation. High-merit hot-path optimization; I found no blocker.
upstream-sync referenced this pull request2026-11-26 10:05:30 +00:00
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T04:47:08Z.
Triage (#1607) – head
7d92772No open or merged PR makes the same change. Main's title_textures.rs refresh still tests every entry against the dirty pages. The PR conflicts with main, which has changed that loop a lot since (texture_needs_upload, again/waiting), so the indexed selection needs a substantial rebase.
In the diff,
remappedis kept in step in insert_active/remove_active/recheck_sources, ande.srcis only written in recheck_source. No problems found.Recommendation: keep open.
AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
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.