D3D12.X, KernelX: 2 MiB watch-range blocks and call-budgeted coherent-UMA spans #3677

Open
iggyvilla wants to merge 1 commit from upstream-pr/3677 into amd-dev
iggyvilla commented 2026-12-02 07:42:29 +00:00 (Migrated from github.com)

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


TL;DR — Before vs After

Aspect Before (origin/amd-dev 41aa60ce) After (amd-watch-tight-ranges)
Scope & size Split out of #3649 (formerly bundled with hot-gap & hot-retention changes) +232/-27 lines across 3 files (bvh_want.rs, kernelx.rs, title_textures.rs), standalone on amd-dev
Table::coarse & mirrors::shown_blocks granularity 16 MiB blocks (1 << 24), pulling up to 16 MiB of adjacent non-texture memory into GetWriteWatch 2 MiB blocks (1 << 21), matching HOT_BLOCK
Coherent UMA watch ranges Watched by 16 MiB coarse blocks (dragging per-frame coherent buffers into GetWriteWatch) Exact 4 KiB-aligned Table::coh_spans when !u.shadowed() && !bvh_want::watching(), call-budgeted via plan_watch_ranges(..., COH_WATCH_CALLS = 16) so calls never grow unbounded during loading or XCL_WATCH_HOT=0
Test coverage No unit tests for exact_coh split / fallback / committed gating 3 new unit tests covering coh_spans refcounting, watch_blocks / unwatch_blocks committed-window gating, exact_coh split + committed shown_blocks routing, shadowed/bvh_want::watching() fallback, and COH_WATCH_CALLS budget capping
60 s smoke (RX 6650 XT, amd-dev 41aa60ce) 1654 frames (60 61 60, 15902 MB) 1618 frames (60 61 60, 16288 MB, 0 removals, 0 crashes)

What is in it
Split out from #3649 as a standalone, independently measurable PR on amd-dev (41aa60ce), addressing review feedback on call budgeting and test coverage:

  • Shrinks Table::coarse (SRC_COARSE_SHIFT) and kernelx::mirrors::shown_blocks (SHOWN_BLOCK_SHIFT) from 16 MiB (24) to 2 MiB (21), matching HOT_BLOCK and trimming adjacent buffer/padding ranges from cached_watch_ranges and xcl-watch-walk.
  • Tracks refcounted 4 KiB-aligned texture spans (Table::coh_spans) for textures placed in committed UMA windows (watch_blocks_with / unwatch_blocks_with gated on Uma::is_committed).
  • Extracts pure helper build_watch_ranges(...): when unshadowed and no raytracing BVH tiles are watched (!u.shadowed() && !bvh_want::watching()), skips coarse blocks in committed UMA windows and passes coh_spans + committed shown_blocks through existing plan_watch_ranges(&coh_regions, coh_wanted, COH_WATCH_CALLS) (COH_WATCH_CALLS = 16). This keeps exact texture spans disjoint when few exist while capping total GetWriteWatch calls in coherent UMA under load or XCL_WATCH_HOT=0.
  • Adds bvh_want::watching() to watch_key() so WATCH_CACHE invalidates automatically if BVH watching flips.
  • Adds unit tests (coh_spans_refcount_and_watch_blocks_gate_by_committed_window, build_watch_ranges_splits_exact_coh_routes_shown_and_falls_back, build_watch_ranges_caps_coherent_uma_calls_to_budget) and updates a_write_where_a_page_is_kept_is_a_write_to_the_views_showing_it to use SHOWN_BLOCK_SHIFT.

Tested

  • Hardware: AMD Radeon RX 6650 XT (Windows 11, release build).
  • Targeted tests (cargo test -p xcl --lib -- coh_spans_refcount build_watch_ranges a_write_where_a_page_is_kept_is_a_write_to_the_views_showing_it): 4 passed, 0 failed.
  • Whole-workspace GPU suite (cargo test --workspace --no-fail-fast -- --test-threads=4): 2,961 passed, 13 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, 2 e2e tests, 2 two_pass_driver_cache tests).
  • Release build (cargo build --release -p xcl): succeeded cleanly.

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 (bc033a5e):

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

Not tested

  • NVIDIA and Intel GPUs, and Wine.

AI use

  • Antigravity (Gemini) split this PR out of #3649, replaced unbounded gap = 0 coherent-UMA ranges with plan_watch_ranges(..., COH_WATCH_CALLS) call budgeting, added unit tests for the range builder and committed-window gating, ran workspace tests and 60 s smoke on local AMD hardware, and wrote this description.
<!-- greyfinch-sync:ivall/xcl:issue:5602071535 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3677). Originally posted by [iggyvilla](https://github.com/iggyvilla) on 2026-12-02T07:42:29Z. --- ### TL;DR — Before vs After | Aspect | Before (`origin/amd-dev` `41aa60ce`) | After (`amd-watch-tight-ranges`) | | --- | --- | --- | | Scope & size | Split out of `#3649` (formerly bundled with hot-gap & hot-retention changes) | **+232/-27 lines across 3 files** (`bvh_want.rs`, `kernelx.rs`, `title_textures.rs`), standalone on `amd-dev` | | `Table::coarse` & `mirrors::shown_blocks` granularity | `16 MiB` blocks (`1 << 24`), pulling up to 16 MiB of adjacent non-texture memory into `GetWriteWatch` | `2 MiB` blocks (`1 << 21`), matching `HOT_BLOCK` | | Coherent UMA watch ranges | Watched by 16 MiB coarse blocks (dragging per-frame coherent buffers into `GetWriteWatch`) | Exact 4 KiB-aligned `Table::coh_spans` when `!u.shadowed() && !bvh_want::watching()`, **call-budgeted via `plan_watch_ranges(..., COH_WATCH_CALLS = 16)`** so calls never grow unbounded during loading or `XCL_WATCH_HOT=0` | | Test coverage | No unit tests for `exact_coh` split / fallback / committed gating | 3 new unit tests covering `coh_spans` refcounting, `watch_blocks` / `unwatch_blocks` committed-window gating, `exact_coh` split + committed `shown_blocks` routing, `shadowed`/`bvh_want::watching()` fallback, and `COH_WATCH_CALLS` budget capping | | 60 s smoke (`RX 6650 XT`, `amd-dev` `41aa60ce`) | `1654` frames (`60 61 60`, `15902 MB`) | `1618` frames (`60 61 60`, `16288 MB`, 0 removals, 0 crashes) | **What is in it** Split out from #3649 as a standalone, independently measurable PR on `amd-dev` (`41aa60ce`), addressing review feedback on call budgeting and test coverage: - Shrinks `Table::coarse` (`SRC_COARSE_SHIFT`) and `kernelx::mirrors::shown_blocks` (`SHOWN_BLOCK_SHIFT`) from `16 MiB` (`24`) to `2 MiB` (`21`), matching `HOT_BLOCK` and trimming adjacent buffer/padding ranges from `cached_watch_ranges` and `xcl-watch-walk`. - Tracks refcounted 4 KiB-aligned texture spans (`Table::coh_spans`) for textures placed in committed UMA windows (`watch_blocks_with` / `unwatch_blocks_with` gated on `Uma::is_committed`). - Extracts pure helper `build_watch_ranges(...)`: when unshadowed and no raytracing BVH tiles are watched (`!u.shadowed() && !bvh_want::watching()`), skips coarse blocks in committed UMA windows and passes `coh_spans` + committed `shown_blocks` through existing `plan_watch_ranges(&coh_regions, coh_wanted, COH_WATCH_CALLS)` (`COH_WATCH_CALLS = 16`). This keeps exact texture spans disjoint when few exist while capping total `GetWriteWatch` calls in coherent UMA under load or `XCL_WATCH_HOT=0`. - Adds `bvh_want::watching()` to `watch_key()` so `WATCH_CACHE` invalidates automatically if BVH watching flips. - Adds unit tests (`coh_spans_refcount_and_watch_blocks_gate_by_committed_window`, `build_watch_ranges_splits_exact_coh_routes_shown_and_falls_back`, `build_watch_ranges_caps_coherent_uma_calls_to_budget`) and updates `a_write_where_a_page_is_kept_is_a_write_to_the_views_showing_it` to use `SHOWN_BLOCK_SHIFT`. **Tested** - Hardware: AMD Radeon RX 6650 XT (Windows 11, release build). - Targeted tests (`cargo test -p xcl --lib -- coh_spans_refcount build_watch_ranges a_write_where_a_page_is_kept_is_a_write_to_the_views_showing_it`): **4 passed, 0 failed**. - Whole-workspace GPU suite (`cargo test --workspace --no-fail-fast -- --test-threads=4`): **2,961 passed, 13 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, 2 `e2e` tests, 2 `two_pass_driver_cache` tests). - Release build (`cargo build --release -p xcl`): succeeded cleanly. **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 (`bc033a5e`): ``` xcl-smoke v1 commit: bc033a5eb4f7183691665bdaeb7e3c628f594515 gpu: AMD Radeon RX 6650 XT title: 1778c2d9 seconds: 60 exit: 0x0 frames shown: 1618 (PresentX 1618) presents per 2 s (last 3): 60 61 60 device removals: 0 crashes: 0 peak commit: 16288 MB ``` **Not tested** - NVIDIA and Intel GPUs, and Wine. **AI use** - Antigravity (Gemini) split this PR out of #3649, replaced unbounded `gap = 0` coherent-UMA ranges with `plan_watch_ranges(..., COH_WATCH_CALLS)` call budgeting, added unit tests for the range builder and committed-window gating, ran workspace tests and 60 s smoke on local AMD hardware, and wrote this description.
Foniass commented 2026-12-02 07:47:31 +00:00 (Migrated from github.com)

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


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

  • Every new texture span still rebuilds the watch ranges. watch_blocks_with (title_textures.rs ~332-336) bumps COARSE_GEN whenever a committed-UMA texture gets a new span, even when exact_coh is off (shadowed UMA, or BVH tiles watched) and cached_watch_ranges (~1922-1927) never reads coh_spans. Each bump invalidates WATCH_CACHE, so the next submit's refresh_parts (~2727) copies every coarse key and every span under the TEXTURES lock, sorts them and plans again: the per-texture rebuild the base's blocks avoided ("by 16 MiB blocks, not by texture: a title has tens of thousands, and their sources change every submit while it loads", a comment this PR removes). There are no numbers for rebuild frequency or cost while a title loads.
  • The 2 MiB granularity is a separate, global change. SRC_COARSE_SHIFT (~193) and SHOWN_BLOCK_SHIFT (kernelx.rs ~397) drop from 16 MiB to 2 MiB on every path, not only unshadowed coherent UMA; outside it watch_ranges still merges only across the 4 MiB WATCH_GAP with no call budget, so blocks 6-14 MiB apart that one range used to cover now each need their own GetWriteWatch call, and blocks change state (and bump COARSE_GEN) up to 8× as often. It does not depend on coh_spans and could be its own commit; the only measurement is one 60 s smoke of both together (1618 vs 1654 frames).
  • COH_WATCH_CALLS = 16 is not measured. plan_watch_ranges' doc (~4071) still says production keeps watch_ranges "until a Windows measurement establishes a target", and this PR uses it (~1902) with a target of 16 and no call count, look time or WATCH_PLAN bytes. Under many textures it bridges all but the 15 largest gaps (e.g. 128 textures 8 MiB apart over 1 GiB become 16 calls covering about 900 MiB), pulling in the coherent buffers the description says this keeps out.
  • Conflicts with #3649 in the title_textures.rs test module (both add a test after the same one, ~6786); textual only. #3676 merges cleanly.

Fine: coh_spans refcounts stay balanced since every link / unlink / GPU-written path goes through watch_blocks / unwatch_blocks with the same (src, size); committed windows are 4 GiB-aligned, so a skipped 2 MiB block never covers memory outside the window; bvh_want::watching() in watch_key invalidates the cache when it flips; build_watch_ranges_splits_exact_coh_routes_shown_and_falls_back and the budget test check the new helper.

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

<!-- greyfinch-sync:ivall/xcl:comment:7338613289 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3677#issuecomment-7338613289). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-02T07:47:31Z. --- Review (head bc033a5e, diff read, not a merge-check): - **Every new texture span still rebuilds the watch ranges.** `watch_blocks_with` (`title_textures.rs` ~332-336) bumps `COARSE_GEN` whenever a committed-UMA texture gets a new span, even when `exact_coh` is off (shadowed UMA, or BVH tiles watched) and `cached_watch_ranges` (~1922-1927) never reads `coh_spans`. Each bump invalidates `WATCH_CACHE`, so the next submit's `refresh_parts` (~2727) copies every `coarse` key and every span under the `TEXTURES` lock, sorts them and plans again: the per-texture rebuild the base's blocks avoided ("by 16 MiB blocks, not by texture: a title has tens of thousands, and their sources change every submit while it loads", a comment this PR removes). There are no numbers for rebuild frequency or cost while a title loads. - **The 2 MiB granularity is a separate, global change.** `SRC_COARSE_SHIFT` (~193) and `SHOWN_BLOCK_SHIFT` (`kernelx.rs` ~397) drop from 16 MiB to 2 MiB on every path, not only unshadowed coherent UMA; outside it `watch_ranges` still merges only across the 4 MiB `WATCH_GAP` with no call budget, so blocks 6-14 MiB apart that one range used to cover now each need their own `GetWriteWatch` call, and blocks change state (and bump `COARSE_GEN`) up to 8× as often. It does not depend on `coh_spans` and could be its own commit; the only measurement is one 60 s smoke of both together (1618 vs 1654 frames). - **`COH_WATCH_CALLS = 16` is not measured.** `plan_watch_ranges`' doc (~4071) still says production keeps `watch_ranges` "until a Windows measurement establishes a target", and this PR uses it (~1902) with a target of 16 and no call count, look time or `WATCH_PLAN` bytes. Under many textures it bridges all but the 15 largest gaps (e.g. 128 textures 8 MiB apart over 1 GiB become 16 calls covering about 900 MiB), pulling in the coherent buffers the description says this keeps out. - **Conflicts with #3649** in the `title_textures.rs` test module (both add a test after the same one, ~6786); textual only. #3676 merges cleanly. Fine: `coh_spans` refcounts stay balanced since every link / unlink / GPU-written path goes through `watch_blocks` / `unwatch_blocks` with the same `(src, size)`; committed windows are 4 GiB-aligned, so a skipped 2 MiB block never covers memory outside the window; `bvh_want::watching()` in `watch_key` invalidates the cache when it flips; `build_watch_ranges_splits_exact_coh_routes_shown_and_falls_back` and the budget test check the new helper. AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
Foniass commented 2026-12-02 12:41:27 +00:00 (Migrated from github.com)

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


merge-check
base: 41aa60ce84
head: bc033a5eb4
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2964 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/3677#issuecomment-7338613289 and its findings stand. Most serious: watch_blocks_with (~322-336) bumps COARSE_GEN for every new committed-UMA span even with exact_coh off, so watch ranges are rebuilt per texture, and the global 2 MiB SRC_COARSE_SHIFT (~193) is on the default path unmeasured.
performance: 60 s smoke of a retail title, amd-dev 41aa60ce vs this merge (bc033a5e): 1671 -> 1687 frames shown (100 %; last presents per 2 s: 60 60 60), peak commit 16722 -> 16707 MB, 0 device removals, 0 crashes.
verdict: not yet: watch_blocks_with (~322-336) bumps COARSE_GEN for every new committed-UMA span even with exact_coh off, so watch ranges are rebuilt per texture, and the global 2 MiB SRC_COARSE_SHIFT (~193) is on the default path unmeasured (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:7345724722 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3677#issuecomment-7345724722). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-02T12:41:27Z. --- merge-check base: 41aa60ce842060a597b7e8724896f7bf6a031af5 head: bc033a5eb4f7183691665bdaeb7e3c628f594515 merge: clean build: cargo build --workspace -> ok tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2964 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/3677#issuecomment-7338613289 and its findings stand. Most serious: `watch_blocks_with` (~322-336) bumps `COARSE_GEN` for every new committed-UMA span even with `exact_coh` off, so watch ranges are rebuilt per texture, and the global 2 MiB `SRC_COARSE_SHIFT` (~193) is on the default path unmeasured. performance: 60 s smoke of a retail title, amd-dev 41aa60ce vs this merge (bc033a5e): 1671 -> 1687 frames shown (100 %; last presents per 2 s: 60 60 60), peak commit 16722 -> 16707 MB, 0 device removals, 0 crashes. verdict: not yet: `watch_blocks_with` (~322-336) bumps `COARSE_GEN` for every new committed-UMA span even with `exact_coh` off, so watch ranges are rebuilt per texture, and the global 2 MiB `SRC_COARSE_SHIFT` (~193) is on the default path unmeasured (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/3677:upstream-pr/3677'
git switch 'upstream-pr/3677'

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