Skip to content

Memory: cover overflow MEM_GRAPHICS reservations in trailing view windows - #3653

Open
Kalmarv wants to merge 2 commits into
xcl-dev:mainfrom
Kalmarv:pr/overflow-graphics-views
Open

Kalmarv wants to merge 2 commits into
xcl-dev:mainfrom
Kalmarv:pr/overflow-graphics-views

Conversation

@Kalmarv

@Kalmarv Kalmarv commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #3517 (carries @CharlyRien's 4-sparse-window 16-window layout commit from #3517, rebased onto origin/main 5eaadb54c; will rebase onto main once #3517 merges).

In the 16-window UMA layout (4 sparse + 1..2 coherent + 6 primary GPU-view = 11..12 windows), the trailing 4..5 windows (windows 12..16 = 16 GiB with 2 coherent windows, or windows 11..16 = 20 GiB with 1 coherent window) remained unused WindowKind::None while overflow MEM_GRAPHICS and GPU-visible fallback reservations fell out to plain Windows memory outside UMA. Translated shaders drop reads and writes past xcl_w >= 16, leaving GPU-side buffers in those overflow reservations unreadable.

Notes on scope and trade-offs:

What is in it

  • crates/xcl/src/gpu/uma.rs: Reserve the trailing 16-window view windows past the 6 primary GPU-view windows as MEM_RESERVE | MEM_WRITE_WATCH (PAGE_READWRITE) and add Uma::view_reserve_graphics and Uma::graphics_view_windows. Keep the 6 primary GPU-view windows (VIEW_WINDOWS) isolated for 24 GiB GPU views and reject 24 GiB CPU views from the trailing windows.
  • crates/xcl/src/hle/kernelx.rs: Route overflow MEM_GRAPHICS and non-GPU-view gpu_visible_fallback reservations into the trailing write-watched view windows via reserve_in_view_graphics without registering MEM_GRAPHICS reservations as unpaired CPU views in mirrors; bound view-window VirtualAlloc(MEM_COMMIT) ranges against u.view_reservation(a) (failing out-of-bounds or released ranges with ERROR_INVALID_ADDRESS); notify sparse::source_committed on self-backed graphics commits (commit_in_view_graphics); and on VirtualFree(MEM_RELEASE) of a self-backed graphics reservation (free_in_view), run sparse::source_release (removing GRAPHICS_RESERVATIONS and unpairing mirrors inside its freeing span before forget_mirrors) and clean up title mappings before u.view_release(a).
  • crates/xcl/src/hle/d3d12x/sparse.rs, title_textures.rs, bind.rs, real.rs: Keep self-backed graphics reservations in trailing view windows in title_textures write-watch tracking (recording Table::coarse membership per resource at link_src time so unlink_src stays balanced if the reservation is released first); resolve tile_shows to the tile's own CPU address when in_graphics_reservation is true; allow State::fill_later to map uncommitted/lazy GPU-only tiles (h == 0xFFFF when self-backed) while charging full PAGES_PER_TILE against the per-submit page budget; forget asks on self-backed tile decommit (source_decommitted_in); and re-queue linked unmapped self-backed tiles on re-ask (take_asks) or VirtualAlloc(MEM_COMMIT) (source_committed_in).
  • Unit tests (CPU and WARP-only): 4-sparse 16-window layout and trailing graphics view windows (VirtualAlloc commit + GetWriteWatch), kernelx reserve_in_view_graphics (including non-registration of MEM_GRAPHICS | MEM_64K_PAGES in mirrors) and view_graphics_free_decommit_release_and_reuse (bounds/post-release ERROR_INVALID_ADDRESS, MEM_DECOMMIT / re-commit / MEM_RELEASE / AWAY.title cleanup / address reuse), title_textures coarse_refcount_stays_balanced_after_graphics_reservation_release, and WARP self_backed_graphics_reservation_maps_committed_and_uncommitted_tiles_on_warp covering committed/uncommitted mapping, post-decommit remapping, and PAGES_PER_TILE fill_later budget charging.

Tested

  • Hardware / toolchain: AMD Ryzen 9 9950X 16-Core, Windows 11 10.0.26200.0, NVIDIA GeForce RTX 5070 Ti (driver 610.74 / 32.0.16.1074), rustc 1.99.0 (b940084d7 2026-09-28), DXC 1.9.2609.5.
  • cargo build --release -p xcl: succeeded with 39 warnings (0 new vs origin/main 5eaadb54c).
  • Targeted unit tests (reserve_in_view_graphics_places_and_tracks_fallback_reservations, view_graphics_free_decommit_release_and_reuse, coarse_refcount_stays_balanced_after_graphics_reservation_release, self_backed_graphics_reservation_maps_committed_and_uncommitted_tiles_on_warp, graphics_view_windows_cover_reservations_and_support_commit_and_write_watch): 5 passed, 0 failed, 0 ignored, 0 skipped.
  • .\scripts\test.ps1 (workspace build, bench --test, and cargo test --workspace -- --test-threads=4 with DXC 1.9): 2982 passed, 0 failed, 52 ignored, 24 SKIPPED GPU tests (22 no wave64 on RTX 5070 Ti, 2 no heap windows).

Regression run

Base (origin/main):

xcl-smoke v1
commit: 5eaadb54c14e0fc29597b2a1689d7dbd83491303
gpu: NVIDIA GeForce RTX 5070 Ti
title: ea3b5e4d
seconds: 60
exit: 0x0
frames shown: 1688 (PresentX 1688)
presents per 2 s (last 3): 60 60 61
device removals: 0
crashes: 0
peak commit: 16676 MB

PR (5c963d8fe94168b1e5ff1855ce09978300c6c9b5):

xcl-smoke v1
commit: 5c963d8fe94168b1e5ff1855ce09978300c6c9b5
gpu: NVIDIA GeForce RTX 5070 Ti
title: ea3b5e4d
seconds: 60
exit: 0x0
frames shown: 1663 (PresentX 1663)
presents per 2 s (last 3): 61 60 60
device removals: 0
crashes: 0
peak commit: 17392 MB

Not tested

  • Default 4-window smoke does not run the 16-window branches: scripts/smoke.ps1 runs with default XCL_UMA_WINDOWS=4 (XCL_HEAP_WINDOWS unset), so the regression run above verifies no regression on the default layout and does not execute the 16-window trailing view-window paths. No live 16-window title run was re-run on 5c963d8fe; coverage of the updated commit comes from the CPU and WARP unit tests.
  • Wave64-native GPU adapters / AMD hardware (22 wave64 GPU tests skipped on RTX 5070 Ti).
  • Default scripts/test.ps1 runs without XCL_HEAP_WINDOWS=1 (2 heap-window GPU tests skipped in the full suite).
  • Multi-minute 16-window gameplay under heavy XCL_MIRROR_MB pressure or concurrent decommit/release churn on trailing graphics view reservations.

AI use

@github-actions github-actions Bot added area:d3d12 D3D12.X runtime, command lists, resources, sparse memory area:docs-ci Documentation, scripts, workflows, repo governance area:hle kernelx, XGameRuntime, XAudio2, VFS, PE loader, TLS, EH area:memory Virtual/physical memory, arenas, VRAM budget, UMA area:recompiler RDNA2 decoder, HLSL/direct-DXIL recompiler, wave64/wave32 area:tests Unit, integration, e2e tests, or testtitle gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks) labels Dec 2, 2026
@Decodere

Decodere commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Diff review (head a74a58b98, read-only code review — not a #3041 merge-check):

Nice design on the trailing MEM_WRITE_WATCH view windows for overflow MEM_GRAPHICS reservations (and good attention to excluding in_graphics_reservation(src) in title_textures.rs:175-176 so write-watch tracking stays active). Two concrete issues turned up in the full diff:

  1. [HIGH] Inherits #3517's with_switch_fallback window-4 cutoff (crates/xcl/src/gpu/uma.rs:48, :59, :1562, :1611):
    Moving 16-window coherent UMA memory from window 3 to window 4 (SIXTEEN_WINDOW_SPARSE_WINDOWS = 4) leaves #156 with_switch_fallback (real.rs:5178 -> pso::in_switch_form -> windows_for_mode) capped at MAX_WINDOWS = 4 (root UAVs 0..3 only in bind.rs:3108, :5317). Any shader taking switch fallback on the 16-window layout can no longer address coherent memory in window 4. Either keeping coherent memory reachable by switch-form shaders or ensuring switch fallback binds/switches across window 4 resolves this.

  2. [MEDIUM] Unrelated dead code leaked into crates/xcl/src/hle/d3d12x/title_list.rs:292-298, :1135-1161:
    The diff adds pub fn active_backing(list: *mut c_void) -> Option<*mut c_void> and its unit test (+36 lines) that are unrelated to UMA/sparse memory and never called anywhere in this PR or main. Dropping that hunk keeps the PR cleanly scoped.

Testing note: the default 4-window scripts/smoke.ps1 configuration does not execute the 16-window runtime paths; verifying this PR end-to-end requires running with XCL_HEAP_WINDOWS=1 XCL_UMA_WINDOWS=16.

AI use: Antigravity (Gemini 4 Neon) audited the full diff against main and drafted this review.

@Foniass

Foniass commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator

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

  • GPU-only tiles now come out of the GPU view's video-memory budget. sparse.rs ~6734 (h == 0xFFFF && w != c) gives video memory to a self-backed tile with no committed page. That memory comes from mirror_cap (XCL_MIRROR_MB, 4096 MB by default, sparse.rs ~2708), which the 24 GiB GPU view's tiles also use. If a 6 GiB overflow reservation is asked for whole (BVH scratch, or D3D12.X: hook XboxBvhBuilder builds and ask for every range whole in GPU views #3662's whole-range asks), it can use up the cap. After that, GPU-view tiles are refused and read zeros (sparse.rs ~6638). The 30 s run in the description does not report mirror counts or refusals.
  • A GPU-only tile does not get its memory back after a decommit. A decommit over a self-backed tile parks its video memory (source_decommitted_in, called from kernelx.rs ~1303). When the title commits the range again, the commit goes to plain VirtualAlloc, and nothing tells sparse. mirror_writes remaps a tile only after a CPU write. The tile also stays in MIRROR_ASKED, so map_mirror does not queue it again. Scratch that only the GPU writes stays unmapped (zeros, writes dropped). The w == c exception exists only in fill_later.
  • The new free and allocation paths have no tests. The view-window branch of VirtualFree (kernelx.rs ~1296-1325: source_decommit, the GRAPHICS_RESERVATIONS removal, forget_mirrors/remapped, view_release) is never called. The kernelx test cleans up by hand "without relying on global uma::get()" (~5613), and the sparse test calls source_decommitted_in directly. The routing inside VirtualAlloc (~1012, ~1076) is tested only through reserve_in_view_graphics. A test that decommits, releases and reuses the address through the hooks would cover the release path this PR adds.
  • Address given back before the title's mappings are forgotten. In the view branch, u.view_release(a) (kernelx.rs ~1321) runs before forget_title_mappings(a, n) (~1322). Another thread can reserve that range and map pages there in between, and those mappings are then dropped. The sparse branch does it the other way round (~1281 before ~1283). Main had the same order for GPU views, but this PR now expects map_pages to be used in these reservations (~2568).
  • Unrelated code. title_list::active_backing (title_list.rs ~293) and its test (+36 lines) are not called in this PR, on main, or in D3D12.X: hook XboxBvhBuilder builds and ask for every range whole in GPU views #3662. They belong in a separate PR.
  • Stack and regression run. The PR carries Memory: the 16-window layout keeps 4 runtime sparse windows #3517's commit unchanged, and Memory: the 16-window layout keeps 4 runtime sparse windows #3517 is still open. D3D12.X: hook XboxBvhBuilder builds and ask for every range whole in GPU views #3662 carries both commits. scripts/smoke.ps1 does not set XCL_UMA_WINDOWS and the blocks do not record the layout. With the default 4 windows the new branches never run, and the only run of the 16-window layout (30 s) has no comparison with main. Not tested should say this.

Fine: on the default 4-window layout this is a no-op by reading. There are no View windows, so view_reserve_graphics returns None, and every other new check sits behind is_view or w == c. The only cost is one extra GRAPHICS_RESERVATIONS lookup per NoView tile in tile_shows. The window arithmetic is correct: primary views limited to lo..lo+VIEW_WINDOWS, trailing windows as lo+VIEW_WINDOWS..hi, take_sparse_in bounds and alignment, the 24 GiB rejection, and nothing to place when 8 sparse + 2 coherent windows leave no trailing window. The trailing reservation is MEM_WRITE_WATCH, which src_runs scanning needs. tile_shows takes GRAPHICS_RESERVATIONS under STATE, and no lock-order inversion was found. No overlap with #3651 (committed windows only) or #3665 (placements/vram only).

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

@Foniass

Foniass commented Dec 2, 2026 •

Copy link
Copy Markdown
Collaborator

merge-check
base: 1c8b551
head: a74a58b
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2916 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 by one reviewer at this same head; the review is at #3653 (comment) and its findings stand. Most serious: GPU-only tiles in the trailing windows use the same 4 GiB budget as the GPU view, and the new free path is untested.
performance: 60 s smoke of a retail title, main 1c8b551 vs this merge (a74a58b): 1652 -> 1688 frames shown (102 %; last presents per 2 s: 61 60 60), peak commit 18228 -> 17424 MB, 0 device removals, 0 crashes.
verdict: safe to merge (it carries open #3517's commits, which land with it): no blocking finding in the review (the points there are minor), the suite passes and the smoke run is clean
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.

@github-actions github-actions Bot added needs-2nd-check Has 1 safe merge-check; needs second independent check (#3041) needs:amd-test Needs a test report or merge-check on an AMD GPU labels Dec 2, 2026
The 16-window layout (XCL_UMA_WINDOWS=16) now reserves 4 sparse VRAM
windows instead of 3: 4 sparse + 1 coherent + 6 view windows still fit in
16, and the 4th window was one of the 5 it left empty, so it costs no
address space. The 4- and 8-window layouts keep 3.

A retail title's BVH builder works in a 3.39 GB MEM_RESERVE | MEM_64K_PAGES
reservation made once windows 1..2 are taken. With 3 sparse windows it
found no room and became plain write-watched memory, which shaders read as
zeros, so every acceleration structure stayed empty (xcl-dev#505). With
4 it lands in window 3, where the GPU sees it.

XCL_SPARSE_WINDOWS=<n> (1..=8) overrides the count for any layout
(README). A coherent plan in the 16-window layout now gets at most 6
windows instead of 7.

Tests: the setting's parse, clamp and per-layout default and the layout
accounting for 1..=8 sparse windows; the 16-window layout's windows; the
3.39 GB reservation landing in window 3 (fails on main, where it gets no
room). Existing layout tests follow the new window indices; the GPU test
of the 4-root-UAV program skips when the coherent window is not window 3.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Kalmarv
Kalmarv force-pushed the pr/overflow-graphics-views branch from a74a58b to 1de2334 Compare December 2, 2026 14:59
@github-actions github-actions Bot removed needs-2nd-check Has 1 safe merge-check; needs second independent check (#3041) needs:amd-test Needs a test report or merge-check on an AMD GPU labels Dec 2, 2026
@Kalmarv

Kalmarv commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @Decodere and @Foniass for the thorough reviews — rebased onto origin/main (5eaadb54c, keeping @CharlyRien's still-open #3517 commit intact) and updated head to 1de2334d6:

  • Dropped unrelated title_list.rs hunk (@Decodere, @Foniass): removed title_list::active_backing and its unit test (-36 lines).
  • Fixed VirtualFree address-reuse ordering in kernelx.rs (@Foniass): factored the view-window branch into free_in_view and moved forget_title_mappings(a, n) (along with GRAPHICS_RESERVATIONS removal, mirrors::released, mirrors::place_gone, and sparse::forget_mirrors / remapped) before u.view_release(a), matching the sparse branch order so another thread cannot reuse the VA before old mappings are cleared.
  • Fixed post-decommit remapping of self-backed GPU-only tiles in sparse.rs + kernelx.rs (@Foniass):
    • State::source_decommitted_in now calls forget_ask(w) when a self-backed tile (w == t) is unmapped (clearing MIRROR_ASKED and bumping MIRROR_FORGOTTEN for view_want).
    • State::take_asks re-queues linked unmapped self-backed tiles (g == c && !self.mapped.contains_key(&g)) into self.later so a subsequent GPU ask (map_mirror) remaps them even with h == 0xFFFF.
    • VirtualAlloc(MEM_COMMIT) inside a view graphics reservation (commit_in_view_graphics) calls sparse::source_committed -> State::source_committed_in so re-committing a decommitted self-backed tile also regains video memory without needing a CPU write or fresh ask.
  • Added unit tests covering the new free/release/reuse and post-decommit remapping paths (@Foniass):
    • kernelx::tests::view_graphics_free_decommit_release_and_reuse: exercises reserve_in_view_graphics, commit_in_view_graphics, partial MEM_DECOMMIT, re-commit zeroing, MEM_RELEASE clearing GRAPHICS_RESERVATIONS and AWAY.title, double-release rejection, and immediate address reuse.
    • sparse::tests::self_backed_graphics_reservation_maps_committed_and_uncommitted_tiles_on_warp: now asks through map_mirror, verifies source_decommitted_in clears MIRROR_ASKED and increments MIRROR_FORGOTTEN, and checks all three post-decommit recovery paths (map_mirror GPU-only re-ask, source_committed_in re-commit, and mirror_writes CPU write) on WARP.
  • Updated PR description (@Decodere, @Foniass): noted @KDenKC's RTX 5090 finding (that Memory: the 16-window layout keeps 4 runtime sparse windows #3517 alone fixes the glass characters), documented the shared XCL_MIRROR_MB (4096 MiB) pool budget and the #3517 with_switch_fallback window-4 cutoff (unchanged here since Memory: the 16-window layout keeps 4 runtime sparse windows #3517 owns the 4-sparse-window layout), and explicitly disclosed in Not tested that the default 4-window smoke does not exercise the 16-window branches.

Verified on 1de2334d6: cargo build --release -p xcl (39 warnings, matching 5eaadb54c), .\scripts\test.ps1 with DXC 1.9 (2981 passed, 0 failed, 52 ignored, 24 SKIPPED), fresh 60 s smoke pair (5eaadb54c 1688 frames / 16676 MB vs 1de2334d6 1683 frames / 16728 MB, 0 device removals, 0 crashes), and scripts/pr_check.py --local (description ok).

AI use: Antigravity (Gemini 4 Neon) implemented these fixes, ran the checks, and drafted this reply.

@github-actions github-actions Bot added gpu:nvidia Code is specific to NVIDIA / wave32 GPUs (scope tag; see needs:nvidia-test) and removed gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks) labels Dec 2, 2026
@pvfreis

pvfreis commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

One integration note for whichever of this PR and #3696 lands second. Both use the slots immediately after the six primary GPU views. When dedicated heaps occupy some of that tail, the overflow allocator’s free list and graphics_view_windows() need to cover only the slots actually reserved as write-watched views. See #3696 for the proposed layout check.

AI use: OpenAI Codex (GPT-6.2 Sol) reviewed the source and drafted this note. Claude Code (Claude Fable 5.2) independently checked it.

@Kalmarv

Kalmarv commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks @pvfreis — good catch, noted. Right now reserve_runtime takes all slots after views_at + VIEW_WINDOWS as write-watched WindowKind::View since they are WindowKind::None on main. If #3696 lands first, we will narrow total_view_wins, views.0, and graphics_view_windows() during the rebase so they cover only the trailing slots actually reserved as write-watched views (leaving dedicated heap windows untouched).

AI use: Antigravity (Gemini 4 Neon) checked gpu/uma.rs against #3696 and drafted this reply.

@ClosetPie107

Copy link
Copy Markdown

Linux / AMD RDNA4 (RADV, Wine + vkd3d-proton): full test suite on 1de2334

Merged onto main 5eaadb54 (clean merge) and compared with main run twice on the same machine.

Setup

  • AMD Radeon RX 9070 16 GB (RDNA4, RADV GFX1201, Mesa 26.3.1), Ryzen 5 9600X, 30 GiB RAM, CachyOS (kernel 7.3.7)
  • Wine 11.23 (system), stock vkd3d-proton v3.1-83-gcae8353ed and DXVK dxgi.dll from GE-Proton11-16, DXC 1.9.2609.5
  • Debug build, cross-compiled for x86_64-pc-windows-msvc with cargo-xwin; test binaries run under Wine

Tested: cargo xwin test --workspace --target x86_64-pc-windows-msvc --no-fail-fast -- --test-threads=4 --skip <31 tests>

passed failed ignored
main 5eaadb54 2769 177 52
this PR merged 2775 178 52
  • Tests that fail with this PR and pass on main: none.
  • Tests this PR adds: 6 of 7 pass (sparse_windows_setting_parses_clamps_and_fits_the_layout, sixteen_windows_keep_four_sparse_windows, a_bvh_scratch_reservation_lands_in_the_fourth_sparse_window, graphics_view_windows_cover_reservations_and_support_commit_and_write_watch, reserve_in_view_graphics_places_and_tracks_fallback_reservations, view_graphics_free_decommit_release_and_reuse).
About the failures on main and the 31 skipped tests (same for every PR in this batch)
  • Most of main's 177 failures under Wine come from Linux (Wine + vkd3d-proton): a retail game reaches what main reaches on Windows; the obstacle is replaced vtables — proposal: proxies #175: once a test has set up the real device, vkd3d-proton refuses the command allocators XCL adopts (d3d12_command_list_Reset: Invalid command allocator), and later tests get E_INVALIDARG (0x80070057). Running vkd3d-proton master with its vtable check taken out, hle::d3d12x::sparse::tests goes from 106 passed / 38 failed to 144 / 0.
  • The 31 skipped tests make vkd3d-proton's dxil-spirv call std::terminate() (Cannot reliably convert LLVM pointer type, we cannot differentiate between Function and Private), which kills the whole test binary. They are the split-wave64, dispatch-chain and bridged-mask GPU tests, gpu_compute_mode_dispatch_abi, gpu_compute_thread_limits_leave_the_lanes_past_them_out, the two gpu_mesh_mode_* tests, and console_wave64_compute_through_the_pso_hook_dispatch_and_read_back, plus serialize_root_signature_strips_console_flags_and_preserves_pc_flags, whose null descriptor vkd3d-proton dereferences. The dxil-spirv ones crash the same way with vkd3d-proton master (f8c1cae8, dxil-spirv 93ab44c5).
  • main was run twice: same counts, same failure set. SKIPPED lines (same as main): no heap windows (2), no D3D12 debug layer (2-3), driver cache control not implemented in vkd3d-proton (1).

Not tested: Windows, NVIDIA, a retail title / scripts/smoke.ps1, a review of the diff. This is a test report, not a merge-check.

AI use: omp (Claude Opus 5.5) merged, built and ran the suites on this machine, compared the results with main, and drafted this report. The user asked for it to be posted.

@Foniass

Foniass commented Dec 2, 2026 •

Copy link
Copy Markdown
Collaborator

merge-check
base: 5eaadb5
head: 1de2334
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2981 passed, 0 failed, 52 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: follow-up on 1de2334 (reworked and rebased from a74a58b, my last review's head). Rebased onto main 5eaadb5; the carried commit 0de9878 has the same patch as #3517's current head 0b4283d (still open). The top commit is now +553/-73, about 330 lines of tests: it drops title_list::active_backing, moves the view-window VirtualFree branch into free_in_view (kernelx.rs ~1279) and adds commit_in_view_graphics (~1266), which the VirtualAlloc commit branch (~944) uses to call the new sparse::source_committed / source_committed_in (sparse.rs ~6475, ~7046); a decommit of a self-backed tile now calls forget_ask (~7033), and a re-ask of a linked, unmapped self-backed tile goes back into later (~6786). Earlier findings: (1) GPU-only tiles drawing on XCL_MIRROR_MB: still open; fill_later ~6756 only charges at least one page per tile now, and the description states the trade-off but gives no mirror or refusal counts from a 16-window run. (2) no video memory after decommit and re-commit: fixed; a decommit drops the ask, and the WARP test's path 1 would fail without forget_ask. (3) untested free and allocation paths: partly fixed; free_in_view and commit_in_view_graphics are called directly by view_graphics_free_decommit_release_and_reuse (~5654) but only with no sparse state, the WARP test calls source_committed_in directly, and the routing inside VirtualAlloc (~944, ~1019, ~1085) and the VirtualFree dispatch are still never reached through the hooks. (4) order of address release and forgetting the title's mappings: fixed (forget_title_mappings, forget_mirrors and remapped now run before u.view_release(a), ~1300-1306), though no test would catch the old order. (5) active_backing: removed. (6) disclosure: a 60 s smoke pair on the default layout, and Not tested says the 16-window branches didn't run. New, all minor: on MEM_RELEASE of a graphics reservation, free_in_view decommits before forget_mirrors, so the new re-queue in take_asks can give a tile of the reservation being released video memory in between (wasted work only); graphics_alloc_align (~1148) copies the alignment block at ~982 instead of replacing it; the kernelx test fills the global AWAY when it's empty and leaves it filled. Fine: the default 4-window layout is still a no-op (view_reserve_graphics returns None with no View windows, and the checks all require is_view); the sparse changes apply only to self-backed tiles; the partial decommit, re-commit, release and address-reuse sequence in free_in_view checks out.
performance: 60 s smoke of a retail title, main 5eaadb5 vs this merge (1de2334): 1422 -> 1666 frames shown (117 %; last presents per 2 s: 60 60 61), peak commit 17184 -> 17780 MB, 0 device removals, 0 crashes.
verdict: safe to merge (it carries open #3517's commit, which lands with it): no blocking finding in the review (the points there are minor), the suite passes and the smoke run is clean
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.

@github-actions github-actions Bot added the needs-2nd-check Has 1 safe merge-check; needs second independent check (#3041) label Dec 2, 2026

@bmjask bmjask left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review of 1de2334d: 6 finding(s) (1 high, 5 medium), most severe first.

  1. High crates/xcl/src/gpu/uma.rs:48: With 16 windows, SIXTEEN_WINDOW_SPARSE_WINDOWS = 4 moves the coherent window (the title's GPU heaps) from window 3 to window 4, which a pipeline rebuilt in switch form by with_switch_fallback (MAX_WINDOWS = 4, root UAVs 0..3) can't r.... (inline)
  2. Medium crates/xcl/src/hle/kernelx.rs:945: A commit in a trailing view window only checks that its start address is in a graphics reservation and never bounds the range, and all trailing windows are one OS MEM_RESERVE, so a commit past the reservation's end silently succeeds in f.... (inline)
  3. Medium crates/xcl/src/hle/kernelx.rs:1020: MEM_GRAPHICS overflow reservations now go through reserve_in_view_graphics, which calls mirrors::reserved with MEM_COMMIT stripped, so a MEM_GRAPHICS reservation of 64 KiB pages is recorded as an unpaired CPU view (the old plain fall.... (inline)
  4. Medium crates/xcl/src/hle/d3d12x/title_textures.rs:176: in_view_window now depends on the changing GRAPHICS_RESERVATIONS map, so link_src and unlink_src can get different answers for the same texture source and the coarse refcount goes wrong. (inline)
  5. Medium crates/xcl/src/hle/kernelx.rs:1285: On MEM_RELEASE of a self-backed graphics reservation, free_in_view uses sparse::source_decommit and calls forget_mirrors only afterwards, outside the freeing span, which is the gap sparse::source_release exists to close. (inline)
  6. Medium crates/xcl/src/hle/d3d12x/sparse.rs:6759: Self-backed tiles with no committed page (h == 0xFFFF) now get video memory but are charged 1 page against the per-submit fill_pages budget, while each takes a full 64 KiB tile plus a zero-fill. (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.

Comment thread crates/xcl/src/gpu/uma.rs
/// space. A retail title's BVH builder works in a 3.5 GB `MEM_RESERVE | MEM_64K_PAGES` reservation
/// made once windows 1..2 are taken: with 3 it found no room and became plain write-watched
/// memory, which shaders read as zeros (every acceleration structure stayed empty).
const SIXTEEN_WINDOW_SPARSE_WINDOWS: usize = 4;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

High: With 16 windows, SIXTEEN_WINDOW_SPARSE_WINDOWS = 4 moves the coherent window (the title's GPU heaps) from window 3 to window 4, which a pipeline rebuilt in switch form by with_switch_fallback (MAX_WINDOWS = 4, root UAVs 0..3) can't reach. The PR makes gpu_sparse_vram_descriptors_buffers_and_xmem skip on the 16-window layout instead of fixing it. With XCL_UMA_WINDOWS=16 and XCL_HEAP_WINDOWS=1, when the driver refuses a heap-window PSO and it's rebuilt in switch form, that shader's reads and writes to GPU heaps (xcl_w == 4) fall outside its windows and are dropped, so heaps read as zero or writes are lost. The only test that covered the coherent window now skips, so nothing catches it. This comes from the stacked #3517 commit but is in this diff.

Comment thread crates/xcl/src/hle/kernelx.rs Outdated
// sparse so any previously decommitted self-backed tiles regain video memory without needing a
// CPU write.
if !addr.is_null() && t & mem::MEM_COMMIT != 0 && uma.is_some_and(|u| u.is_view(addr as usize)) {
if in_graphics_reservation(addr as usize) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Medium: A commit in a trailing view window only checks that its start address is in a graphics reservation and never bounds the range, and all trailing windows are one OS MEM_RESERVE, so a commit past the reservation's end silently succeeds in free or neighbouring address space. If the title reserves 4 MiB at r (placed in window 11) and then calls VirtualAlloc(r + 3 MiB, 2 MiB, MEM_COMMIT), the call failed with ERROR_INVALID_ADDRESS before (as a separate plain reservation). Now commit_in_view_graphics commits 1 MiB past the reservation, possibly inside another title reservation placed right after it, and calls sparse::source_committed over that foreign range. A commit at a trailing address that was already released also falls through to the plain-pages path and succeeds. Checking a + n <= reservation end would restore the old failure.

return q as *mut c_void;
}
let align = graphics_alloc_align(t);
if let Some(q) = reserve_in_view_graphics(uma, size, align, t & !mem::MEM_COMMIT, p) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Medium: MEM_GRAPHICS overflow reservations now go through reserve_in_view_graphics, which calls mirrors::reserved with MEM_COMMIT stripped, so a MEM_GRAPHICS reservation of 64 KiB pages is recorded as an unpaired CPU view (the old plain fallback never called mirrors::reserved). If such a reservation of size X lands in a trailing window, a later GPU-view reservation (PAGE_NOACCESS|PAGE_GRAPHICS_NOACCESS) of the same size calls unpaired_cpu, which picks the most recent CPU view of size X: the graphics reservation, not the title's real CPU view. The GPU view's tiles then show the wrong memory. Not registering graphics reservations as CPU views would avoid it.

/// (`kernelx::in_graphics_reservation`) are write-watched and remain tracked.
fn in_view_window(src: usize) -> bool {
crate::gpu::uma::get().is_some_and(|u| u.is_view(src))
crate::gpu::uma::get().is_some_and(|u| u.is_view(src)) && !crate::hle::kernelx::in_graphics_reservation(src)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Medium: in_view_window now depends on the changing GRAPHICS_RESERVATIONS map, so link_src and unlink_src can get different answers for the same texture source and the coarse refcount goes wrong. A texture placed in a graphics reservation in a trailing view window is linked with in_view_window false, so coarse is incremented. If the title then calls VirtualFree(MEM_RELEASE) before destroying the texture, free_in_view removes the GRAPHICS_RESERVATIONS entry, unlink_src sees in_view_window true and returns early, and the 16 MiB coarse block is never decremented. It stays in cached_watch_ranges forever, or is miscounted when the address is reused. Recording the answer at link time would keep the two in step.

let graphics = in_graphics_reservation(a);
if n > 0 {
let ok = if graphics {
crate::hle::d3d12x::sparse::source_decommit(a, n, || mem::VirtualFree(addr, n, mem::MEM_DECOMMIT))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Medium: On MEM_RELEASE of a self-backed graphics reservation, free_in_view uses sparse::source_decommit and calls forget_mirrors only afterwards, outside the freeing span, which is the gap sparse::source_release exists to close. A submit on another thread in that gap can run fill_later on tiles re-queued by take_asks or source_committed_in, and with the new h == 0xFFFF && w == c rule map video memory again over the released tiles, burning XCL_MIRROR_MB and racing forget_mirrors. Using source_release(a, n, ..) for the release case would fix it.

Comment thread crates/xcl/src/hle/d3d12x/sparse.rs Outdated
self.refused.remove(&w);
} else if self.new_mirror(w, c, h, false) {
*budget = budget.saturating_sub(PAGES_PER_TILE - h.count_ones() as usize);
*budget = budget.saturating_sub((PAGES_PER_TILE - h.count_ones() as usize).max(1));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Medium: Self-backed tiles with no committed page (h == 0xFFFF) now get video memory but are charged 1 page against the per-submit fill_pages budget, while each takes a full 64 KiB tile plus a zero-fill. So one submit can map up to 16x more tiles than intended and drain the shared XCL_MIRROR_MB pool. When a BVH or scratch view in a multi-GiB uncommitted trailing reservation is asked for whole, the pool fills with GPU-only scratch, and later GPU-view tiles hit mirror_cap and are refused, so the GPU reads zeros there. Charging the tile's full size would keep the budget meaningful.

@bmjask

bmjask commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

@Prime1997 could you take a look at this one for review and merge? My automated review notes are above, if any.

…dows

In the 16-window UMA layout (4 sparse + 1..2 coherent + 6 primary GPU-view = 11..12 windows), the trailing 4..5 windows (16..20 GiB) stayed unused WindowKind::None while overflow MEM_GRAPHICS and GPU-visible fallback reservations fell out to plain Windows memory outside UMA. Shaders drop reads and writes past xcl_w >= 16, leaving GPU-side buffers in those overflow reservations unreadable.

- Reserve trailing 16-window view windows past the 6 primary GPU-view windows as MEM_RESERVE | MEM_WRITE_WATCH (PAGE_READWRITE) via Uma::view_reserve_graphics, keeping the 6 primary GPU-view windows isolated for 24 GiB GPU views.
- Route overflow MEM_GRAPHICS and non-GPU-view fallback reservations in kernelx into those trailing view windows, tracking them in GRAPHICS_RESERVATIONS and keeping them write-watched in title_textures.
- Clean up GRAPHICS_RESERVATIONS, mirror pairings, title physical-page mappings (forget_title_mappings), and sparse mirrors before calling u.view_release(a) on VirtualFree(MEM_RELEASE) so a recycled address cannot race with cleanup.
- Let sparse map both committed CPU tiles and uncommitted/lazy GPU-only tiles (h == 0xFFFF when self-backed) for self-backed graphics reservations, forget asks on self-backed tile decommit (and re-queue linked unmapped self-backed tiles on re-ask or VirtualAlloc MEM_COMMIT) so GPU-only tiles regain video memory after decommit.
- Add CPU and WARP-only unit tests covering trailing graphics view windows (commit + GetWriteWatch), kernelx reserve/commit/decommit/release/reuse lifecycle, and self-backed committed/uncommitted tile mapping and post-decommit remapping.

Assisted-by: Antigravity (Gemini 4 Neon)
@Kalmarv
Kalmarv force-pushed the pr/overflow-graphics-views branch from 1de2334 to 5c963d8 Compare December 2, 2026 21:04
@Kalmarv

Kalmarv commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @bmjask for the thorough review (and @Prime1997 for taking a look). Fixed all five medium findings from 1de2334d in 5c963d8fe:

  1. gpu/uma.rs:48 (High — inherited from stacked Memory: the 16-window layout keeps 4 runtime sparse windows #3517): Left unchanged here since it belongs to @CharlyRien's carried Memory: the 16-window layout keeps 4 runtime sparse windows #3517 commit (SIXTEEN_WINDOW_SPARSE_WINDOWS = 4 and with_switch_fallback's 4-window limit), already noted in the PR description.
  2. kernelx.rs:945 (view-window VirtualAlloc(MEM_COMMIT) bounds): Both VirtualAlloc (view-window branch) and commit_in_view_graphics now verify u.view_reservation(a) covers [a, a + size) and fail out-of-bounds or already-released addresses with ERROR_INVALID_ADDRESS.
  3. kernelx.rs:1020 (MEM_GRAPHICS overflow registered as unpaired CPU view): Removed mirrors::reserved from reserve_in_view_graphics so MEM_GRAPHICS overflow reservations are never recorded as unpaired CPU views (non-MEM_GRAPHICS gpu_visible_fallback reservations still call mirrors::reserved).
  4. title_textures.rs:176 (Table::coarse refcount drift when reservation is released before texture unlink): Recorded link-time coarse membership in Table::coarse_res so unlink_src decrements the exact resources link_src added regardless of subsequent GRAPHICS_RESERVATIONS changes.
  5. kernelx.rs:1285 (free_in_view release gap): On MEM_RELEASE of a self-backed graphics reservation, free_in_view now uses sparse::source_release(a, n, ...) and removes GRAPHICS_RESERVATIONS / calls mirrors::released(a) inside its freeing span before forget_mirrors runs.
  6. sparse.rs:6759 (fill_later budget for uncommitted self-backed tiles): Uncommitted self-backed tiles (h == 0xFFFF) now charge the full PAGES_PER_TILE (16) against fill_later's per-submit page budget instead of 1 page.

Also addressed @Foniass's minor cleanup notes (graphics_alloc_align reuse at line 982 and restoring AWAY in the kernelx test) and added unit-test coverage for each fix (reserve_in_view_graphics_places_and_tracks_fallback_reservations, view_graphics_free_decommit_release_and_reuse, coarse_refcount_stays_balanced_after_graphics_reservation_release, and self_backed_graphics_reservation_maps_committed_and_uncommitted_tiles_on_warp).

Verified on 5c963d8fe (RTX 5070 Ti, Windows 11, DXC 1.9.2609.5): cargo build --release -p xcl (39 warnings, 0 new), .\scripts\test.ps1 (2982 passed, 0 failed, 52 ignored, 24 SKIPPED), and fresh 60 s smoke (1663 frames, 17392 MB peak commit, 0 device removals, 0 crashes; PR description updated).

AI use: Antigravity (Gemini 4 Neon) implemented the fixes and tests, ran the build/test/smoke checks, and drafted this reply.

@github-actions github-actions Bot added needs-1st-check Passes gates; needs first independent merge-check (#3041) and removed needs-2nd-check Has 1 safe merge-check; needs second independent check (#3041) labels Dec 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:d3d12 D3D12.X runtime, command lists, resources, sparse memory area:docs-ci Documentation, scripts, workflows, repo governance area:hle kernelx, XGameRuntime, XAudio2, VFS, PE loader, TLS, EH area:memory Virtual/physical memory, arenas, VRAM budget, UMA area:recompiler RDNA2 decoder, HLSL/direct-DXIL recompiler, wave64/wave32 area:tests Unit, integration, e2e tests, or testtitle gpu:nvidia Code is specific to NVIDIA / wave32 GPUs (scope tag; see needs:nvidia-test) needs-1st-check Passes gates; needs first independent merge-check (#3041)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants