D3D12.X: CopyIntoSubresource makes the blocks it wrote hot at once #3437

Open
tiagonleal wants to merge 1 commit from upstream-pr/3437 into main
tiagonleal commented 2026-11-29 17:04:30 +00:00 (Migrated from github.com)

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 ExecuteCommandLists asks 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.

CopyIntoSubresource is 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 with title_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 writes fail now and then in whole-suite runs and on CI: it rewrites a subresource with CopyIntoSubresource and submits at once.

What is in it

  • xg.rs: copy_into calls mark_hot on the bytes it wrote, for a 2D level and for a volume level
  • title_textures.rs: mark_hot is pub(crate); a #[cfg(test)] reader hot_block for the test
  • test hle::xg::tests::a_subresource_copy_makes_its_blocks_hot: a copy across a block boundary leaves both blocks hot
  • +47/-4, two files

Tested

  • Windows 11 Pro 10.0.26300, NVIDIA GeForce RTX 5070 Ti 16 GB (driver 617.42), AMD Ryzen 7 9800X3D, 32 GB RAM, rustc 1.100.0, debug
  • Forced timing, on the commit before the rebase onto main 0fe06eb0 (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_dred run 5 times. Without the two mark_hot calls: 5 of 5 fail the check with subresource 2 row 0 differs from the title memory. With them: 5 of 5 pass.
  • a_subresource_copy_makes_its_blocks_hot fails 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=4 on head f4f2bff7: 2738 passed, 0 failed, 49 ignored (27 SKIPPED lines). main 0fe06eb0 on this machine: 2737 passed, 0 failed, 49 ignored. This is the second run on this head: in the first the lib test binary ended inside uma_driver::tests with coherent 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, main 0fe06eb0 first, one run each, XCL_PREPARE=0, same DXIL cache. A warm-up run of main came before them and is not shown; a second run of main after them showed 1697 frames and a peak commit of 15302 MB.

main (0fe06eb0):

xcl-smoke v1
commit: 0fe06eb0f05459007ebfffc67bb9983acb3a832d
gpu: NVIDIA GeForce RTX 5070 Ti
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1686 (PresentX 1686)
presents per 2 s (last 3): 60 61 60
device removals: 0
crashes: 0
peak commit: 14882 MB

This PR (f4f2bff7):

xcl-smoke v1
commit: f4f2bff7e828e486f45ec2eb4823a342d3b2ac08
gpu: NVIDIA GeForce RTX 5070 Ti
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1692 (PresentX 1692)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15228 MB

Not tested

  • Raw stores by the title's own code into a block idle for more than 1.5 s still wait for the walk, as before. This PR does not close #3382 for them.
  • CopyFromSubresource is not touched: its destination is the title's linear buffer.
  • Command-list memory writes (fills, immediate writes, copies into title memory) were not audited for the same gap. DirectStorage, file reads and the kernelx page writes already tell the looks what they wrote through note_known_write.
  • No retail title was checked for a visible difference.
  • Not tested on AMD or Intel.

AI use

  • Claude Code with Claude Fable 5.2 and Anthropic subagents (Claude Opus 5.5, Claude Sonnet 5.5) helped developing.

🤖 Generated with Claude Code

<!-- greyfinch-sync:ivall/xcl:issue:5553028010 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3437). Originally posted by [tiagonleal](https://github.com/tiagonleal) on 2026-11-29T17:04:30Z. --- Part of #3382. With the hot write-watch looks (the default), a look before `ExecuteCommandLists` asks 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. `CopyIntoSubresource` is 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 with `title_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 writes` fail now and then in whole-suite runs and on CI: it rewrites a subresource with `CopyIntoSubresource` and submits at once. **What is in it** - `xg.rs`: `copy_into` calls `mark_hot` on the bytes it wrote, for a 2D level and for a volume level - `title_textures.rs`: `mark_hot` is `pub(crate)`; a `#[cfg(test)]` reader `hot_block` for the test - test `hle::xg::tests::a_subresource_copy_makes_its_blocks_hot`: a copy across a block boundary leaves both blocks hot - +47/-4, two files **Tested** - Windows 11 Pro 10.0.26300, NVIDIA GeForce RTX 5070 Ti 16 GB (driver 617.42), AMD Ryzen 7 9800X3D, 32 GB RAM, rustc 1.100.0, debug - Forced timing, on the commit before the rebase onto `main` `0fe06eb0` (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_dred` run 5 times. Without the two `mark_hot` calls: 5 of 5 fail the check with `subresource 2 row 0 differs from the title memory`. With them: 5 of 5 pass. - `a_subresource_copy_makes_its_blocks_hot` fails 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=4` on head `f4f2bff7`: 2738 passed, 0 failed, 49 ignored (27 `SKIPPED` lines). `main` `0fe06eb0` on this machine: 2737 passed, 0 failed, 49 ignored. This is the second run on this head: in the first the lib test binary ended inside `uma_driver::tests` with `coherent 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, `main` `0fe06eb0` first, one run each, `XCL_PREPARE=0`, same DXIL cache. A warm-up run of `main` came before them and is not shown; a second run of `main` after them showed 1697 frames and a peak commit of 15302 MB. `main` (`0fe06eb0`): ``` xcl-smoke v1 commit: 0fe06eb0f05459007ebfffc67bb9983acb3a832d gpu: NVIDIA GeForce RTX 5070 Ti title: 9cc6a39e seconds: 60 exit: 0x0 frames shown: 1686 (PresentX 1686) presents per 2 s (last 3): 60 61 60 device removals: 0 crashes: 0 peak commit: 14882 MB ``` This PR (`f4f2bff7`): ``` xcl-smoke v1 commit: f4f2bff7e828e486f45ec2eb4823a342d3b2ac08 gpu: NVIDIA GeForce RTX 5070 Ti title: 9cc6a39e seconds: 60 exit: 0x0 frames shown: 1692 (PresentX 1692) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 15228 MB ``` **Not tested** - Raw stores by the title's own code into a block idle for more than 1.5 s still wait for the walk, as before. This PR does not close #3382 for them. - `CopyFromSubresource` is not touched: its destination is the title's linear buffer. - Command-list memory writes (fills, immediate writes, copies into title memory) were not audited for the same gap. DirectStorage, file reads and the `kernelx` page writes already tell the looks what they wrote through `note_known_write`. - No retail title was checked for a visible difference. - Not tested on AMD or Intel. **AI use** - Claude Code with Claude Fable 5.2 and Anthropic subagents (Claude Opus 5.5, Claude Sonnet 5.5) helped developing. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
andrewDoing commented 2026-11-29 17:15:00 +00:00 (Migrated from github.com)

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 actual CopyIntoSubresource vtable call against Windows MEM_WRITE_WATCH allocations 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.

Tail mip Hot blocks selected Range scanned Current median One-block control median
2D 3 5.375 MiB 6.5–8.1 µs 3.6–4.5 µs
3D volume 11 21.344 MiB 20.2 µs 4.1 µs

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::tests and hle::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.

<!-- greyfinch-sync:ivall/xcl:comment:7259541275 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3437#issuecomment-7259541275). Originally posted by [andrewDoing](https://github.com/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 actual `CopyIntoSubresource` vtable call against Windows `MEM_WRITE_WATCH` allocations 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. | Tail mip | Hot blocks selected | Range scanned | Current median | One-block control median | | --- | ---: | ---: | ---: | ---: | | 2D | 3 | 5.375 MiB | 6.5–8.1 µs | 3.6–4.5 µs | | 3D volume | 11 | 21.344 MiB | 20.2 µs | 4.1 µs | 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::tests` and `hle::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.
Foniass commented 2026-12-01 09:33:28 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T09:33:28Z.


merge-check
base: 7d86c5d2b7
head: f4f2bff7e8
merge: 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 level i. 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), and all_hot() turns true for the texture. Nothing is missed, but the upload reads more than the copy wrote. MipLevel.offset would 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 when ptr sits at least size / 2 below a 2 MiB boundary. The Windows heap makes that true in practice, but nothing checks it. Fine: mark_hot runs after the stores and nothing resets the write watch, so no page is lost or uploaded twice. copy_into holds no lock and HOT is a leaf lock taken the way register and sparse.rs already take it. A destination that isn't a registered texture is harmless (hot_runs only uses blocks in watched ranges, stale entries expire). Before the first look and with XCL_WATCH_HOT=0 it does nothing, and the test skips. The test fails without the two calls.
performance: 60 s smoke of a retail title, main 7d86c5d2 vs 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.

<!-- greyfinch-sync:ivall/xcl:comment:7306872905 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3437#issuecomment-7306872905). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T09:33:28Z. --- merge-check base: 7d86c5d2b7845695031eeea1327aa81b6c439323 head: f4f2bff7e828e486f45ec2eb4823a342d3b2ac08 merge: 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 level `i`. 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`), and `all_hot()` turns true for the texture. Nothing is missed, but the upload reads more than the copy wrote. `MipLevel.offset` would 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 when `ptr` sits at least `size / 2` below a 2 MiB boundary. The Windows heap makes that true in practice, but nothing checks it. Fine: `mark_hot` runs after the stores and nothing resets the write watch, so no page is lost or uploaded twice. `copy_into` holds no lock and `HOT` is a leaf lock taken the way `register` and `sparse.rs` already take it. A destination that isn't a registered texture is harmless (`hot_runs` only uses blocks in watched ranges, stale entries expire). Before the first look and with `XCL_WATCH_HOT=0` it does nothing, and the test skips. The test fails without the two calls. performance: 60 s smoke of a retail title, main 7d86c5d2 vs 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.
Foniass commented 2026-12-01 09:55:03 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T09:55:03Z.


Triage (#1607) – head f4f2bff

No other open or merged PR addresses #3382. mark_hot already exists on main for commits and sparse mappings; this adds it to xg.rs copy_into for both the 2D and the volume path, and makes it pub(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.

<!-- greyfinch-sync:ivall/xcl:comment:7307396041 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3437#issuecomment-7307396041). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T09:55:03Z. --- **Triage (#1607)** – head f4f2bff No other open or merged PR addresses #3382. `mark_hot` already exists on main for commits and sparse mappings; this adds it to `xg.rs` `copy_into` for both the 2D and the volume path, and makes it `pub(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.
vasanex commented 2026-12-02 01:09:22 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by vasanex on 2026-12-02T01:09:22Z.


merge-check claim
head: f4f2bff7e8

<!-- greyfinch-sync:ivall/xcl:comment:7331377319 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3437#issuecomment-7331377319). Originally posted by [vasanex](https://github.com/vasanex) on 2026-12-02T01:09:22Z. --- merge-check claim head: f4f2bff7e828e486f45ec2eb4823a342d3b2ac08
vasanex commented 2026-12-02 01:22:44 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by vasanex on 2026-12-02T01:22:44Z.


merge-check
base: 1c8b551475
head: f4f2bff7e8
merge: clean (merged tree d92a7152, git diff --check clean)
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_hot passes.
review: whole diff read (xg.rs, title_textures.rs, +47/-4). No finding. Both exits of copy_into that write the destination (the volume path and the level path) now call title_textures::mark_hot on the bytes they tiled; mark_hot is the function main already uses for memory just committed, made pub(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 helper hot_block is #[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 short HOT lock 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.

<!-- greyfinch-sync:ivall/xcl:comment:7331634564 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3437#issuecomment-7331634564). Originally posted by [vasanex](https://github.com/vasanex) on 2026-12-02T01:22:44Z. --- merge-check base: 1c8b551475e1e7bfe48f94448492a4c3544a2e0f head: f4f2bff7e828e486f45ec2eb4823a342d3b2ac08 merge: clean (merged tree d92a7152, `git diff --check` clean) 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_hot` passes. review: whole diff read (xg.rs, title_textures.rs, +47/-4). No finding. Both exits of `copy_into` that write the destination (the volume path and the level path) now call `title_textures::mark_hot` on the bytes they tiled; `mark_hot` is the function main already uses for memory just committed, made `pub(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 helper `hot_block` is `#[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 short `HOT` lock 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.
bmjask commented 2026-12-02 06:12:31 +00:00 (Migrated from github.com)

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.

<!-- greyfinch-sync:ivall/xcl:review:6145657084 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3437#pullrequestreview-6145657084). Originally posted by [bmjask](https://github.com/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._
bmjask commented 2026-12-02 06:12:32 +00:00 (Migrated from github.com)

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 1852

@@ -1836,10 +1836,20 @@ fn take_known(dirty: &mut Vec<usize>) {
     }
 }
 
-/// Memory the title just committed or placed something in: the looks take its blocks for a
-/// while, as they do a block new to the ranges (a write made right after the commit is there
-/// for the next submit).
-pub(super) fn mark_hot(at: usize, len: usize) {
+/// Whether the block of `at` is hot now; with `forget`, it is not any more.
+#[cfg(test)]
+pub(crate) fn hot_block(at: usize, forget: bool) -> bool {
+    let mut g = HOT.lock().unwrap_or_else(|e| e.into_inner());
+    let h = g.get_or_insert_with(HotBlocks::default);
+    let b = at & !(HOT_BLOCK - 1);
+    if forget { h.hot.remove(&b).is_some() } else { h.hot.contains_key(&b) }
+}
+
+/// Memory the title just committed or placed something in, or XCL just wrote for it (an XG
+/// copy): the looks take its blocks for a while, as they do a block new to the ranges (a write
+/// made right after it is there for the next submit). The write watch is left as it is: the
+/// next look takes the written pages from it.
+pub(crate) fn mark_hot(at: usize, len: usize) {

mark_hot makes a block hot without bumping WALK_FOUND, but the XCL_LOOK_SKIP check (closed_before_last_look_in) uses WALK_FOUND to 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 in mark_hot would close it.

<!-- greyfinch-sync:ivall/xcl:review-comment:4765497296 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3437#discussion_r4765497296). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T06:12:32Z. **Code review location:** `crates/xcl/src/hle/d3d12x/title_textures.rs`; line 1852 ~~~~diff @@ -1836,10 +1836,20 @@ fn take_known(dirty: &mut Vec<usize>) { } } -/// Memory the title just committed or placed something in: the looks take its blocks for a -/// while, as they do a block new to the ranges (a write made right after the commit is there -/// for the next submit). -pub(super) fn mark_hot(at: usize, len: usize) { +/// Whether the block of `at` is hot now; with `forget`, it is not any more. +#[cfg(test)] +pub(crate) fn hot_block(at: usize, forget: bool) -> bool { + let mut g = HOT.lock().unwrap_or_else(|e| e.into_inner()); + let h = g.get_or_insert_with(HotBlocks::default); + let b = at & !(HOT_BLOCK - 1); + if forget { h.hot.remove(&b).is_some() } else { h.hot.contains_key(&b) } +} + +/// Memory the title just committed or placed something in, or XCL just wrote for it (an XG +/// copy): the looks take its blocks for a while, as they do a block new to the ranges (a write +/// made right after it is there for the next submit). The write watch is left as it is: the +/// next look takes the written pages from it. +pub(crate) fn mark_hot(at: usize, len: usize) { ~~~~ --- `mark_hot` makes a block hot without bumping `WALK_FOUND`, but the `XCL_LOOK_SKIP` check (`closed_before_last_look_in`) uses `WALK_FOUND` to 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 in `mark_hot` would close it.
bmjask commented 2026-12-02 06:12:32 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T06:12:32Z.

Code review location: crates/xcl/src/hle/xg.rs; line 733

@@ -727,6 +728,9 @@ unsafe extern "system" fn copy_into(p: *mut c_void, dst: *mut u8, plane: u32, su
     }
     let slice = std::slice::from_raw_parts_mut(dst.add(at as usize + k * t.chain.slice_bytes), t.chain.slice_bytes);
     t.chain.tile_level(slice, i, k, &linear);
+    // (a title submits right after this: the looks take these blocks now, not once the walk
+    // finds them, which can be after that submit for a block idle longer than `hot_for`)
+    crate::hle::d3d12x::title_textures::mark_hot(slice.as_ptr() as usize, slice.len());

Not certain about this one: mark_hot gets 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 mark home/kept, not the view address. Relatedly, title_textures::note_known_write already 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.

<!-- greyfinch-sync:ivall/xcl:review-comment:4765497301 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3437#discussion_r4765497301). Originally posted by [bmjask](https://github.com/bmjask) on 2026-12-02T06:12:32Z. **Code review location:** `crates/xcl/src/hle/xg.rs`; line 733 ~~~~diff @@ -727,6 +728,9 @@ unsafe extern "system" fn copy_into(p: *mut c_void, dst: *mut u8, plane: u32, su } let slice = std::slice::from_raw_parts_mut(dst.add(at as usize + k * t.chain.slice_bytes), t.chain.slice_bytes); t.chain.tile_level(slice, i, k, &linear); + // (a title submits right after this: the looks take these blocks now, not once the walk + // finds them, which can be after that submit for a block idle longer than `hot_for`) + crate::hle::d3d12x::title_textures::mark_hot(slice.as_ptr() as usize, slice.len()); ~~~~ --- Not certain about this one: `mark_hot` gets 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 mark `home`/`kept`, not the view address. Relatedly, `title_textures::note_known_write` already 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.
tiagonleal commented 2026-12-02 09:42:27 +00:00 (Migrated from github.com)

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 1852

@@ -1836,10 +1836,20 @@ fn take_known(dirty: &mut Vec<usize>) {
     }
 }
 
-/// Memory the title just committed or placed something in: the looks take its blocks for a
-/// while, as they do a block new to the ranges (a write made right after the commit is there
-/// for the next submit).
-pub(super) fn mark_hot(at: usize, len: usize) {
+/// Whether the block of `at` is hot now; with `forget`, it is not any more.
+#[cfg(test)]
+pub(crate) fn hot_block(at: usize, forget: bool) -> bool {
+    let mut g = HOT.lock().unwrap_or_else(|e| e.into_inner());
+    let h = g.get_or_insert_with(HotBlocks::default);
+    let b = at & !(HOT_BLOCK - 1);
+    if forget { h.hot.remove(&b).is_some() } else { h.hot.contains_key(&b) }
+}
+
+/// Memory the title just committed or placed something in, or XCL just wrote for it (an XG
+/// copy): the looks take its blocks for a while, as they do a block new to the ranges (a write
+/// made right after it is there for the next submit). The write watch is left as it is: the
+/// next look takes the written pages from it.
+pub(crate) fn mark_hot(at: usize, len: usize) {

Right, mark_hot never moves WALK_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 the mark_hot call already on main has the same gap. The fix is one line (fetch_max on WALK_FOUND in mark_hot) plus a test on closed_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.

  • Tiago
<!-- greyfinch-sync:ivall/xcl:review-comment:4767575938 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3437#discussion_r4767575938). Originally posted by [tiagonleal](https://github.com/tiagonleal) on 2026-12-02T09:42:27Z. **Code review location:** `crates/xcl/src/hle/d3d12x/title_textures.rs`; line 1852 ~~~~diff @@ -1836,10 +1836,20 @@ fn take_known(dirty: &mut Vec<usize>) { } } -/// Memory the title just committed or placed something in: the looks take its blocks for a -/// while, as they do a block new to the ranges (a write made right after the commit is there -/// for the next submit). -pub(super) fn mark_hot(at: usize, len: usize) { +/// Whether the block of `at` is hot now; with `forget`, it is not any more. +#[cfg(test)] +pub(crate) fn hot_block(at: usize, forget: bool) -> bool { + let mut g = HOT.lock().unwrap_or_else(|e| e.into_inner()); + let h = g.get_or_insert_with(HotBlocks::default); + let b = at & !(HOT_BLOCK - 1); + if forget { h.hot.remove(&b).is_some() } else { h.hot.contains_key(&b) } +} + +/// Memory the title just committed or placed something in, or XCL just wrote for it (an XG +/// copy): the looks take its blocks for a while, as they do a block new to the ranges (a write +/// made right after it is there for the next submit). The write watch is left as it is: the +/// next look takes the written pages from it. +pub(crate) fn mark_hot(at: usize, len: usize) { ~~~~ --- Right, `mark_hot` never moves `WALK_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 the `mark_hot` call already on main has the same gap. The fix is one line (`fetch_max` on `WALK_FOUND` in `mark_hot`) plus a test on `closed_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. - Tiago
tiagonleal commented 2026-12-02 09:42:29 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by tiagonleal on 2026-12-02T09:42:29Z.

Code review location: crates/xcl/src/hle/xg.rs; line 733

@@ -727,6 +728,9 @@ unsafe extern "system" fn copy_into(p: *mut c_void, dst: *mut u8, plane: u32, su
     }
     let slice = std::slice::from_raw_parts_mut(dst.add(at as usize + k * t.chain.slice_bytes), t.chain.slice_bytes);
     t.chain.tile_level(slice, i, k, &linear);
+    // (a title submits right after this: the looks take these blocks now, not once the walk
+    // finds them, which can be after that submit for a block idle longer than `hot_for`)
+    crate::hle::d3d12x::title_textures::mark_hot(slice.as_ptr() as usize, slice.len());

I 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_write fits 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.

  • Tiago
<!-- greyfinch-sync:ivall/xcl:review-comment:4767576505 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3437#discussion_r4767576505). Originally posted by [tiagonleal](https://github.com/tiagonleal) on 2026-12-02T09:42:29Z. **Code review location:** `crates/xcl/src/hle/xg.rs`; line 733 ~~~~diff @@ -727,6 +728,9 @@ unsafe extern "system" fn copy_into(p: *mut c_void, dst: *mut u8, plane: u32, su } let slice = std::slice::from_raw_parts_mut(dst.add(at as usize + k * t.chain.slice_bytes), t.chain.slice_bytes); t.chain.tile_level(slice, i, k, &linear); + // (a title submits right after this: the looks take these blocks now, not once the walk + // finds them, which can be after that submit for a block idle longer than `hot_for`) + crate::hle::d3d12x::title_textures::mark_hot(slice.as_ptr() as usize, slice.len()); ~~~~ --- I 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_write` fits 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. - Tiago
bmjask commented 2026-12-02 14:13:45 +00:00 (Migrated from github.com)

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.

<!-- greyfinch-sync:ivall/xcl:comment:7348198123 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3437#issuecomment-7348198123). Originally posted by [bmjask](https://github.com/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.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3437:upstream-pr/3437'
git switch 'upstream-pr/3437'

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.

git switch 'main'
git merge --no-ff 'upstream-pr/3437'
git switch 'upstream-pr/3437'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3437'
git switch 'upstream-pr/3437'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3437'
git switch 'main'
git merge --squash 'upstream-pr/3437'
git switch 'main'
git merge --ff-only 'upstream-pr/3437'
git switch 'main'
git merge 'upstream-pr/3437'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
xcl-dev/xcl!3437
No description provided.