D3D12.X, KernelX: wire watch_cold into texture looks and memory guards #3676

Open
iggyvilla wants to merge 3 commits from upstream-pr/3676 into amd-dev
iggyvilla commented 2026-12-02 07:21:56 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by iggyvilla on 2026-12-02T07:21:56Z.


Stacked on #3639; only the top commit belongs here.

TL;DR — Before vs After

Aspect Before (#3639 core only) After (amd-watch-cold-wire)
Scope & size watch_cold.rs core module (#[allow(dead_code)], not yet called) +134/-11 lines across 6 files wiring watch_cold into title_textures, kernelx, lazy, and sparse
mark_hot / all_hot / sibling warming Disabled when watch_cold::on() because hot_looks() was false Fixed via tracks_hot_blocks() = hot_looks() || watch_cold::on(), plus look_cold warms opened_ranges
Background walk thread Spawned redundantly in watch_cold mode Only spawned for hot_looks() (watch_cold::look_with already scans all non-cold pieces)
60 s smoke (default flags, RX 6650 XT) 1654 frames (60 61 60, 15902 MB) on amd-dev 1652 frames (60 60 60, 16000 MB, 0 removals, 0 crashes)
60 s smoke (XCL_GUEST_WRITE_GUARD=1 XCL_WATCH_COLD=1) Not wired 1653 frames (60 61 60, 16324 MB, 0 removals, 0 crashes)

What is in it
Wires the opt-in watch_cold core module from #3639 into D3D12.X texture write-watch looks and KernelX/sparse memory transitions (still off by default; requires XCL_GUEST_WRITE_GUARD=1 XCL_WATCH_COLD=1):

  • title_textures.rs: routes refresh_parts through look_cold when watch_cold::on(), keeps start_walk off in watch_cold mode, and introduces tracks_hot_blocks() = hot_looks() || watch_cold::on() so mark_hot (newly created textures, sparse commits, and multi-block opened_ranges sibling warming) and all_hot (upload_all cross-block safety check) stay active when watch_cold is enabled (addressing the review finding on #3639).
  • kernelx.rs, kernelx/lazy.rs, sparse.rs: guards VirtualAlloc / VirtualFree / VirtualProtect / home commit & decommit / lazy page commits / sparse commit & decommit paths against concurrent read-only freezing.
  • Adds cross-look regression test watch_cold_tracks_hot_blocks_and_warms_opened_siblings_across_looks verifying that mark_hot, all_hot, and 4 MiB fault-window sibling warming work across consecutive looks.

Tested

  • Hardware: AMD Radeon RX 6650 XT (Windows 11, release build).
  • Targeted tests (cargo test -p xcl --lib -- watch_cold --test-threads=1): 5 passed, 0 failed (4 watch_cold::tests + title_textures::tests::watch_cold_tracks_hot_blocks_and_warms_opened_siblings_across_looks).
  • Whole-workspace GPU suite (cargo test --workspace --no-fail-fast -- --test-threads=4): 2,967 passed, 16 pre-existing failed, 49 ignored (same pre-existing failures as clean origin/amd-dev 41aa60ce: 3 RDNA2 f32/NaN tests, 6 parallel sparse/title_textures contention tests, 5 e2e debug-layer/title tests, 2 two_pass_driver_cache tests).
  • Release build (cargo build --release -p xcl): succeeded cleanly.
  • Opt-in live 60 s smoke (XCL_GUEST_WRITE_GUARD=1 XCL_WATCH_COLD=1): 1653 frames (60 61 60), 0 device removals, 0 crashes, 16324 MB peak commit.

Regression run
Baseline (origin/main d8bd9a38):

xcl-smoke v1
commit: d8bd9a38204667f3ca7dd9eeffcc2f1c937b07b0
gpu: AMD Radeon RX 6650 XT
title: 1778c2d9
seconds: 60
exit: 0x0
frames shown: 1618 (PresentX 1618)
presents per 2 s (last 3): 61 60 60
device removals: 0
crashes: 0
peak commit: 15479 MB

Baseline (origin/amd-dev 41aa60ce):

xcl-smoke v1
commit: 41aa60ce842060a597b7e8724896f7bf6a031af5
gpu: AMD Radeon RX 6650 XT
title: 1778c2d9
seconds: 60
exit: 0x0
frames shown: 1654 (PresentX 1654)
presents per 2 s (last 3): 60 61 60
device removals: 0
crashes: 0
peak commit: 15902 MB

PR head (0362c226, default flags):

xcl-smoke v1
commit: 0362c226d6ce61e0660b9fc207e7ce13d8896a9b
gpu: AMD Radeon RX 6650 XT
title: 1778c2d9
seconds: 60
exit: 0x0
frames shown: 1652 (PresentX 1652)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 16000 MB

Not tested

  • NVIDIA and Intel GPUs, and Wine.

AI use

  • Antigravity (Gemini) split the watch_cold wiring out of #3639, added the tracks_hot_blocks() fix and cross-look regression test, ran unit/workspace tests and both default and XCL_WATCH_COLD=1 60 s smoke runs on local AMD hardware, and wrote this description.
<!-- greyfinch-sync:ivall/xcl:issue:5601807759 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3676). Originally posted by [iggyvilla](https://github.com/iggyvilla) on 2026-12-02T07:21:56Z. --- Stacked on #3639; only the top commit belongs here. ### TL;DR — Before vs After | Aspect | Before (`#3639` core only) | After (`amd-watch-cold-wire`) | | --- | --- | --- | | Scope & size | `watch_cold.rs` core module (`#[allow(dead_code)]`, not yet called) | **+134/-11 lines across 6 files** wiring `watch_cold` into `title_textures`, `kernelx`, `lazy`, and `sparse` | | `mark_hot` / `all_hot` / sibling warming | Disabled when `watch_cold::on()` because `hot_looks()` was `false` | Fixed via `tracks_hot_blocks() = hot_looks() \|\| watch_cold::on()`, plus `look_cold` warms `opened_ranges` | | Background walk thread | Spawned redundantly in `watch_cold` mode | Only spawned for `hot_looks()` (`watch_cold::look_with` already scans all non-cold pieces) | | 60 s smoke (`default flags`, RX 6650 XT) | `1654` frames (`60 61 60`, `15902 MB`) on `amd-dev` | `1652` frames (`60 60 60`, `16000 MB`, 0 removals, 0 crashes) | | 60 s smoke (`XCL_GUEST_WRITE_GUARD=1 XCL_WATCH_COLD=1`) | Not wired | `1653` frames (`60 61 60`, `16324 MB`, 0 removals, 0 crashes) | **What is in it** Wires the opt-in `watch_cold` core module from #3639 into D3D12.X texture write-watch looks and KernelX/sparse memory transitions (still off by default; requires `XCL_GUEST_WRITE_GUARD=1 XCL_WATCH_COLD=1`): - `title_textures.rs`: routes `refresh_parts` through `look_cold` when `watch_cold::on()`, keeps `start_walk` off in `watch_cold` mode, and introduces `tracks_hot_blocks() = hot_looks() || watch_cold::on()` so `mark_hot` (newly created textures, sparse commits, and multi-block `opened_ranges` sibling warming) and `all_hot` (`upload_all` cross-block safety check) stay active when `watch_cold` is enabled (addressing the review finding on #3639). - `kernelx.rs`, `kernelx/lazy.rs`, `sparse.rs`: guards `VirtualAlloc` / `VirtualFree` / `VirtualProtect` / home commit & decommit / lazy page commits / sparse commit & decommit paths against concurrent read-only freezing. - Adds cross-look regression test `watch_cold_tracks_hot_blocks_and_warms_opened_siblings_across_looks` verifying that `mark_hot`, `all_hot`, and 4 MiB fault-window sibling warming work across consecutive looks. **Tested** - Hardware: AMD Radeon RX 6650 XT (Windows 11, release build). - Targeted tests (`cargo test -p xcl --lib -- watch_cold --test-threads=1`): **5 passed, 0 failed** (4 `watch_cold::tests` + `title_textures::tests::watch_cold_tracks_hot_blocks_and_warms_opened_siblings_across_looks`). - Whole-workspace GPU suite (`cargo test --workspace --no-fail-fast -- --test-threads=4`): **2,967 passed, 16 pre-existing failed, 49 ignored** (same pre-existing failures as clean `origin/amd-dev` `41aa60ce`: 3 RDNA2 f32/NaN tests, 6 parallel `sparse`/`title_textures` contention tests, 5 `e2e` debug-layer/title tests, 2 `two_pass_driver_cache` tests). - Release build (`cargo build --release -p xcl`): succeeded cleanly. - Opt-in live 60 s smoke (`XCL_GUEST_WRITE_GUARD=1 XCL_WATCH_COLD=1`): `1653` frames (`60 61 60`), `0` device removals, `0` crashes, `16324 MB` peak commit. **Regression run** Baseline (`origin/main` `d8bd9a38`): ``` xcl-smoke v1 commit: d8bd9a38204667f3ca7dd9eeffcc2f1c937b07b0 gpu: AMD Radeon RX 6650 XT title: 1778c2d9 seconds: 60 exit: 0x0 frames shown: 1618 (PresentX 1618) presents per 2 s (last 3): 61 60 60 device removals: 0 crashes: 0 peak commit: 15479 MB ``` Baseline (`origin/amd-dev` `41aa60ce`): ``` xcl-smoke v1 commit: 41aa60ce842060a597b7e8724896f7bf6a031af5 gpu: AMD Radeon RX 6650 XT title: 1778c2d9 seconds: 60 exit: 0x0 frames shown: 1654 (PresentX 1654) presents per 2 s (last 3): 60 61 60 device removals: 0 crashes: 0 peak commit: 15902 MB ``` PR head (`0362c226`, default flags): ``` xcl-smoke v1 commit: 0362c226d6ce61e0660b9fc207e7ce13d8896a9b gpu: AMD Radeon RX 6650 XT title: 1778c2d9 seconds: 60 exit: 0x0 frames shown: 1652 (PresentX 1652) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 16000 MB ``` **Not tested** - NVIDIA and Intel GPUs, and Wine. **AI use** - Antigravity (Gemini) split the `watch_cold` wiring out of #3639, added the `tracks_hot_blocks()` fix and cross-look regression test, ran unit/workspace tests and both default and `XCL_WATCH_COLD=1` 60 s smoke runs on local AMD hardware, and wrote this description.
Foniass commented 2026-12-02 07:26:41 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T07:26:41Z.


Review (head 0362c226, diff read, not a merge-check):

  • VirtualFree(addr, 0, MEM_RELEASE) clears only part of the cold map. The hook at kernelx.rs ~1245 calls guard_free(addr, 0), and guard_free (watch_cold.rs ~430-440) takes the length from VirtualQuery's RegionSize, which is only the first run of pages with the same protection. In a partly frozen watched reservation, the COLD spans after that run stay behind after the release; if reserve_watched hands the address out again (VirtualAlloc(NULL, …), ~1160, whose hook at ~934 calls guard(0, size) and never covers the returned range), the new read-write memory is still listed as cold, so hot_pieces leaves it out of every GetWriteWatch and freeze refuses it (~487): CPU writes to those textures are never uploaded. The release path already knows the full length (whole, ~1327).
  • The regression test does not cover the fix. watch_cold_tracks_hot_blocks_and_warms_opened_siblings_across_looks (title_textures.rs ~8563-8587) passes enabled = true to all_hot_if / mark_hot_at directly and never goes through tracks_hot_blocks(), which is the actual fix for the mark_hot / all_hot problem raised on #3639; it would pass with the old hot_looks() gate too.
  • The new test races with watch_cold::tests. It holds title_textures' TEST_LOCK, while the watch_cold tests hold their own SERIAL, and both use the same statics (OPENED, OPENED_RANGES, FAULTED, LOOKS, COLD); look_cold → look_with drains OPENED_RANGES, so under the parallel runner either test can lose its window to the other.

Fine: own commit only (+134/-11); with XCL_WATCH_COLD unset, or without XCL_GUEST_WRITE_GUARD=1, hot_looks(), mark_hot, all_hot and the refresh_parts dispatch behave as before and every guard / guard_free / changed hook returns early; with it on, look_with is reached only through look_cold, start_walk and look-ahead stay off, and tracks_hot_blocks() turns mark_hot / all_hot back on, which fixes the point raised on #3639.

AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.

<!-- greyfinch-sync:ivall/xcl:comment:7338190206 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3676#issuecomment-7338190206). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-02T07:26:41Z. --- Review (head 0362c226, diff read, not a merge-check): - **`VirtualFree(addr, 0, MEM_RELEASE)` clears only part of the cold map.** The hook at `kernelx.rs` ~1245 calls `guard_free(addr, 0)`, and `guard_free` (`watch_cold.rs` ~430-440) takes the length from `VirtualQuery`'s `RegionSize`, which is only the first run of pages with the same protection. In a partly frozen watched reservation, the `COLD` spans after that run stay behind after the release; if `reserve_watched` hands the address out again (`VirtualAlloc(NULL, …)`, ~1160, whose hook at ~934 calls `guard(0, size)` and never covers the returned range), the new read-write memory is still listed as cold, so `hot_pieces` leaves it out of every `GetWriteWatch` and `freeze` refuses it (~487): CPU writes to those textures are never uploaded. The release path already knows the full length (`whole`, ~1327). - **The regression test does not cover the fix.** `watch_cold_tracks_hot_blocks_and_warms_opened_siblings_across_looks` (`title_textures.rs` ~8563-8587) passes `enabled = true` to `all_hot_if` / `mark_hot_at` directly and never goes through `tracks_hot_blocks()`, which is the actual fix for the `mark_hot` / `all_hot` problem raised on #3639; it would pass with the old `hot_looks()` gate too. - **The new test races with `watch_cold::tests`.** It holds `title_textures`' `TEST_LOCK`, while the `watch_cold` tests hold their own `SERIAL`, and both use the same statics (`OPENED`, `OPENED_RANGES`, `FAULTED`, `LOOKS`, `COLD`); `look_cold` → `look_with` drains `OPENED_RANGES`, so under the parallel runner either test can lose its window to the other. Fine: own commit only (+134/-11); with `XCL_WATCH_COLD` unset, or without `XCL_GUEST_WRITE_GUARD=1`, `hot_looks()`, `mark_hot`, `all_hot` and the `refresh_parts` dispatch behave as before and every `guard` / `guard_free` / `changed` hook returns early; with it on, `look_with` is reached only through `look_cold`, `start_walk` and look-ahead stay off, and `tracks_hot_blocks()` turns `mark_hot` / `all_hot` back on, which fixes the point raised on #3639. AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
Foniass commented 2026-12-02 13:29:19 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T13:29:19Z.


merge-check
base: 41aa60ce84
head: 0362c226d6
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2973 passed, 9 failed, 49 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 amd-dev); failing: gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu, gpu::recomp::tests::gpu_fract_f32_edges, hle::d3d12x::sparse::tests::private_physical_pages_reach_the_gpu_on_mapping, hle::d3d12x::title_textures::tests::placed_title_textures_share_vram_and_preserve_pixels, hle::d3d12x::title_textures::tests::remapped_pages_are_compared_with_what_they_held, hle::d3d12x::title_textures::tests::stream_recheck_keeps_the_whole_upload_baseline_over_partial_uploads, hle::d3d12x::title_textures::tests::stream_recheck_partial_upload_without_an_entry_queues_a_whole_upload, hle::d3d12x::title_textures::tests::stream_recheck_schedule_catches_late_writes_and_resets_milestones (the same tests fail on amd-dev 41aa60ce alone on this card, so none is from this PR)
review: read by one reviewer at this same head; the review is at https://github.com/xcl-dev/xcl/pull/3676#issuecomment-7338190206 and its findings stand. Most serious: VirtualFree(addr, 0, MEM_RELEASE) -> guard_free(addr, 0) takes its length from VirtualQuery's RegionSize (watch_cold.rs ~430-440), so cold spans after the first protection run outlive the release, and VirtualAlloc(NULL, …) guards [0, size) instead of the returned address.
performance: 60 s smoke of a retail title, amd-dev 41aa60ce vs this merge (0362c226): 1671 -> 1674 frames shown (100 %; last presents per 2 s: 60 60 61), peak commit 16722 -> 16842 MB, 0 device removals, 0 crashes.
verdict: not yet: VirtualFree(addr, 0, MEM_RELEASE) -> guard_free(addr, 0) takes its length from VirtualQuery's RegionSize (watch_cold.rs ~430-440), so cold spans after the first protection run outlive the release, and VirtualAlloc(NULL, …) guards [0, size) instead of the returned address (see the review)
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:7346959641 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3676#issuecomment-7346959641). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-02T13:29:19Z. --- merge-check base: 41aa60ce842060a597b7e8724896f7bf6a031af5 head: 0362c226d6ce61e0660b9fc207e7ce13d8896a9b merge: clean build: cargo build --workspace -> ok tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2973 passed, 9 failed, 49 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 amd-dev); failing: gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu, gpu::recomp::tests::gpu_fract_f32_edges, hle::d3d12x::sparse::tests::private_physical_pages_reach_the_gpu_on_mapping, hle::d3d12x::title_textures::tests::placed_title_textures_share_vram_and_preserve_pixels, hle::d3d12x::title_textures::tests::remapped_pages_are_compared_with_what_they_held, hle::d3d12x::title_textures::tests::stream_recheck_keeps_the_whole_upload_baseline_over_partial_uploads, hle::d3d12x::title_textures::tests::stream_recheck_partial_upload_without_an_entry_queues_a_whole_upload, hle::d3d12x::title_textures::tests::stream_recheck_schedule_catches_late_writes_and_resets_milestones (the same tests fail on amd-dev 41aa60ce alone on this card, so none is from this PR) review: read by one reviewer at this same head; the review is at https://github.com/xcl-dev/xcl/pull/3676#issuecomment-7338190206 and its findings stand. Most serious: `VirtualFree(addr, 0, MEM_RELEASE)` -> `guard_free(addr, 0)` takes its length from `VirtualQuery`'s `RegionSize` (`watch_cold.rs` ~430-440), so cold spans after the first protection run outlive the release, and `VirtualAlloc(NULL, …)` guards `[0, size)` instead of the returned address. performance: 60 s smoke of a retail title, amd-dev 41aa60ce vs this merge (0362c226): 1671 -> 1674 frames shown (100 %; last presents per 2 s: 60 60 61), peak commit 16722 -> 16842 MB, 0 device removals, 0 crashes. verdict: not yet: `VirtualFree(addr, 0, MEM_RELEASE)` -> `guard_free(addr, 0)` takes its length from `VirtualQuery`'s `RegionSize` (`watch_cold.rs` ~430-440), so cold spans after the first protection run outlive the release, and `VirtualAlloc(NULL, …)` guards `[0, size)` instead of the returned address (see the review) 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.
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/3676:upstream-pr/3676'
git switch 'upstream-pr/3676'

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 'amd-dev'
git merge --no-ff 'upstream-pr/3676'
git switch 'upstream-pr/3676'
git rebase 'amd-dev'
git switch 'amd-dev'
git merge --ff-only 'upstream-pr/3676'
git switch 'upstream-pr/3676'
git rebase 'amd-dev'
git switch 'amd-dev'
git merge --no-ff 'upstream-pr/3676'
git switch 'amd-dev'
git merge --squash 'upstream-pr/3676'
git switch 'amd-dev'
git merge --ff-only 'upstream-pr/3676'
git switch 'amd-dev'
git merge 'upstream-pr/3676'
git push origin 'amd-dev'
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!3676
No description provided.