D3D12.X: CopyIntoSubresource makes the blocks it wrote hot at once #3437
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3437"
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 tiagonleal on 2026-11-29T17:04:30Z.
Part of #3382. With the hot write-watch looks (the default), a look before
ExecuteCommandListsasks the write watch only about the 2 MiB blocks written in the last 1.5 s (hot_for); the walk thread makes any other block hot when it finds a written page there, a walk pass later. A write into a block that was idle for longer, followed at once by a submit, reached the GPU one submit late.CopyIntoSubresourceis one such write, and it is XCL's own code, so it knows what it wrote. It now marks the blocks of the bytes it tiled hot withtitle_textures::mark_hot, which already did this for memory the title had just committed. The next look then takes those pages from the write watch, whose bits the copy's own stores set. Nothing is reset, so no page goes up twice and none is lost. The cost is one short lock and one map insert per 2 MiB block written.This is what makes the test title's check
a texture in title memory (XG layout, #44) follows CPU writesfail now and then in whole-suite runs and on CI: it rewrites a subresource withCopyIntoSubresourceand submits at once.What is in it
xg.rs:copy_intocallsmark_hoton the bytes it wrote, for a 2D level and for a volume leveltitle_textures.rs:mark_hotispub(crate); a#[cfg(test)]readerhot_blockfor the testhle::xg::tests::a_subresource_copy_makes_its_blocks_hot: a copy across a block boundary leaves both blocks hotTested
main0fe06eb0(same diff): with a 2000 ms pause added in the test title before the rewrite (a local change, not in this PR),test_title_runs_under_the_debug_layer_with_dredrun 5 times. Without the twomark_hotcalls: 5 of 5 fail the check withsubresource 2 row 0 differs from the title memory. With them: 5 of 5 pass.a_subresource_copy_makes_its_blocks_hotfails without the two calls (xg.rs, the assert on both blocks) and passes with them.cargo test -p xcl --lib hle::xg: 80 passed, 0 failed.cargo test -p xcl --lib title_textures -- --test-threads=4: 65 passed, 0 failed, 1 ignored.cargo test --workspace --no-fail-fast -j 8 -- --test-threads=4on headf4f2bff7: 2738 passed, 0 failed, 49 ignored (27SKIPPEDlines).main0fe06eb0on this machine: 2737 passed, 0 failed, 49 ignored. This is the second run on this head: in the first the lib test binary ended insideuma_driver::testswithcoherent window could not be restored(the abort #3187 is open for), before this PR's test had run.Regression run
scripts/smoke.ps1 -Seconds 60 -Title 9cc6a39e(Newer Retail Game), release builds of both commits in clean trees,main0fe06eb0first, one run each,XCL_PREPARE=0, same DXIL cache. A warm-up run ofmaincame before them and is not shown; a second run ofmainafter them showed 1697 frames and a peak commit of 15302 MB.main(0fe06eb0):This PR (
f4f2bff7):Not tested
CopyFromSubresourceis not touched: its destination is the title's linear buffer.kernelxpage writes already tell the looks what they wrote throughnote_known_write.AI use
🤖 Generated with Claude Code
Imported from ivall/xcl. Originally posted by andrewDoing on 2026-11-29T17:15:00Z.
On current head
f4f2bff7, I checked the one-texel tail mip of a 1024×1024 RGBA8 texture and a 256×256×64 RGBA8 volume on a Ryzen 7 5700X3D, Windows 11 build 26300.10075, Rust 1.100.0, debug. The test used the actualCopyIntoSubresourcevtable call against WindowsMEM_WRITE_WATCHallocations after clearing their hot-block markers. Both cases round-tripped the four bytes. The first foreground look collected the exact page that Windows reported dirty, and the next native query found zero remaining dirty pages. No walk thread was needed.Each copy touched one 4 KiB page. The current code marked the whole slice or volume hot. After touching all the allocation’s pages to make them resident, I alternated the stock range with a diagnostic control that retained only the actually written 2 MiB block. Both found the same page. The table gives per-process median scan times across four fresh processes, 96 samples per lane per process. Timing starts after the copy and includes choosing the hot ranges and taking the dirty pages.
The one-block control only narrows this fixture’s known footprint. A footprint-aware implementation would need to preserve all touched blocks for larger and noncontiguous mips. The two existing test modules (
hle::xg::testsandhle::d3d12x::title_textures::tests) also passed on the RTX 5070 (616.92), with 70 passed, zero failures, one ignored manual benchmark, and zero explicit skips. The timing probe measured CPU work only. Retail behavior and frame time remain unmeasured. Codex with GPT-6.2 Sol ran the test-only overlay and prepared the report.Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T09:33:28Z.
merge-check
base:
7d86c5d2b7head:
f4f2bff7e8merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2897 passed, 0 failed, 51 ignored; SKIPPED: 28 (20 no wave64, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 1 no heap windows, 1 cannot disable the driver cache, 3 others; the same set as on main); failing: none
review: read the whole diff (+47/-4). After an XG CopyIntoSubresource has tiled its bytes, the range it wrote is marked hot (
mark_hot). The retail title in the run below calls XG CopyInto/FromSubresource (6-argument form), so the smoke reaches the change. Findings: (1) It marks more than the copy wrote. A 2D copy marks the whole array slice with every mip (xg.rs~733,slice_bytes), and a volume copy marks the whole surface (~722,t.size()), but the copy writes only leveli. So a title that streams one small mip of a large texture keeps every 2 MiB block of that slice hot for 1.5 s (hot_for), andall_hot()turns true for the texture. Nothing is missed, but the upload reads more than the copy wrote.MipLevel.offsetwould narrow it (the tail levels need care). (2) The test's destination (xg.rs~831,align_up(ptr + 1, 2 MiB) - size / 2) is only inside the allocation whenptrsits at leastsize / 2below a 2 MiB boundary. The Windows heap makes that true in practice, but nothing checks it. Fine:mark_hotruns after the stores and nothing resets the write watch, so no page is lost or uploaded twice.copy_intoholds no lock andHOTis a leaf lock taken the wayregisterandsparse.rsalready take it. A destination that isn't a registered texture is harmless (hot_runsonly uses blocks in watched ranges, stale entries expire). Before the first look and withXCL_WATCH_HOT=0it does nothing, and the test skips. The test fails without the two calls.performance: 60 s smoke of a retail title, main
7d86c5d2vs this merge (32e188b8): 1663 -> 1672 frames shown (100 %; last presents per 2 s: 60 60 61), peak commit 17153 -> 17779 MB, 0 device removals, 0 crashes. The title calls XG CopyInto/FromSubresource in this run, so the changed path runs.verdict: safe to merge (finding 1 is a follow-up worth doing: marking only the written level would keep the upload smaller)
hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5
AI-written and posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T09:55:03Z.
Triage (#1607) – head
f4f2bffNo other open or merged PR addresses #3382.
mark_hotalready exists on main for commits and sparse mappings; this adds it toxg.rscopy_intofor both the 2D and the volume path, and makes itpub(crate)with a test-only reader. No problems found in the diff.Recommendation: keep open.
AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
Imported from ivall/xcl. Originally posted by vasanex on 2026-12-02T01:09:22Z.
merge-check claim
head:
f4f2bff7e8Imported from ivall/xcl. Originally posted by vasanex on 2026-12-02T01:22:44Z.
merge-check
base:
1c8b551475head:
f4f2bff7e8merge: clean (merged tree d92a7152,
git diff --checkclean)build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2910 passed, 0 failed, 51 ignored; SKIPPED: 25 (22 no wave64, 2 no heap windows, 1 cannot disable the driver cache), the same set as on the base; failing: none. Base alone, same machine: 2909 passed, 0 failed, 51 ignored. The new test
hle::xg::tests::a_subresource_copy_makes_its_blocks_hotpasses.review: whole diff read (xg.rs, title_textures.rs, +47/-4). No finding. Both exits of
copy_intothat write the destination (the volume path and the level path) now calltitle_textures::mark_hoton the bytes they tiled;mark_hotis the function main already uses for memory just committed, madepub(crate), and it returns at once when the hot looks are off. Nothing is reset in the write watch, so the pages are taken from it by the next look as usual. The test helperhot_blockis#[cfg(test)]only. Not checked here: that the late upload this is for (#3382) is gone in a title.performance: 60 s smoke of the same title, release, default settings, same machine, one run each. Base
1c8b5514: 1608 frames shown, presents per 2 s (last 3) 60 60 61, 0 device removals, 0 crashes, peak commit 19911 MB. Merge result (local merge commit): 1496 frames shown, 60 60 60, 0 device removals, 0 crashes, peak commit 20052 MB. 93 % of the base's frames with the same rate at the end; four other merges on this base gave 1539 to 1624 in the same hour, so I read it as start-up spread of one run, not as an effect. Cost by default, reasoned: one shortHOTlock and one map insert per 2 MiB block per CopyIntoSubresource call.verdict: safe to merge
hardware / tool and model: NVIDIA GeForce RTX 3080 10 GB (driver 621.40), AMD Ryzen 9 7950X, Windows 11 Pro 26200, rustc 1.100.0, debug suite and release smoke / Claude Code with Claude Fable 5.2. Run and posted without a human check of each point.
Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T06:12:31Z.
Review: COMMENTED
Review of
f4f2bff7: 2 finding(s). 2 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-02T06:12:32Z.
Code review location:
crates/xcl/src/hle/d3d12x/title_textures.rs; line 1852mark_hotmakes a block hot without bumpingWALK_FOUND, but theXCL_LOOK_SKIPcheck (closed_before_last_look_in) usesWALK_FOUNDto know a block became hot after the last look began. With XCL_LOOK_SKIP=1, a look begins, the title runs CopyIntoSubresource during or right after it, then submits lists closed before that look in the same frame.walk_found < began, so the look is skipped and the copied texels miss the submit, the delay this PR fixes, even though the block was just made hot. Bumping WALK_FOUND inmark_hotwould close it.Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T06:12:32Z.
Code review location:
crates/xcl/src/hle/xg.rs; line 733Not certain about this one:
mark_hotgets the CopyIntoSubresource destination address, but for a texture read through its pages (Entry::paged/Due::pages) the written pages are watched where they're kept, not at the view's own address. A title that calls CopyIntoSubresource into the GPU-view VA of a paged texture and submits right away gets the view VA's blocks marked hot but not the blocks where the pages live, so the copy still reaches the GPU one submit late. The existing tests at title_textures.rs:4780-4808 markhome/kept, not the view address. Relatedly,title_textures::note_known_writealready exists for "XCL wrote these bytes itself" and hands the exact pages to the next look without keeping whole blocks hot for 1.5 s.Imported from ivall/xcl. Originally posted by tiagonleal on 2026-12-02T09:42:27Z.
Code review location:
crates/xcl/src/hle/d3d12x/title_textures.rs; line 1852Right,
mark_hotnever movesWALK_FOUND, so with XCL_LOOK_SKIP=1 a copy right after a look can still be left out of a submit in the same frame. The switch is off unless set, and themark_hotcall already on main has the same gap. The fix is one line (fetch_maxonWALK_FOUNDinmark_hot) plus a test onclosed_before_last_look_in. I would like to send it as a follow-up once this lands, so the two merge-checks here stay valid.Imported from ivall/xcl. Originally posted by tiagonleal on 2026-12-02T09:42:29Z.
Code review location:
crates/xcl/src/hle/xg.rs; line 733I think you are right. The pages of a paged texture are watched where they are kept, so marking the view address hot does nothing for them. That gap is older than this PR and the PR leaves it open.
note_known_writefits better, as you say: resolve the written range to where the pages are kept and hand those to the next look. I have not checked whether any title copies into the view address of a paged texture. I will send it as a separate change with a test next to the paged ones at title_textures.rs:4780.Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T14:13:45Z.
@Prime1997 could you take a look at this one for review and merge? My automated review notes are above, if any.
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.