Skip to content

D3D12.X: reclaim empty 64 MiB VRAM pool heaps, alias GPU mirror pages, and sync 2048x128 glyph atlases - #1985

Merged
raylitebull merged 1 commit into
xcl-dev:mainfrom
raylitebull:feat/vram-local-reclaim-and-bind
Nov 25, 2026
Merged

raylitebull merged 1 commit into
xcl-dev:mainfrom
raylitebull:feat/vram-local-reclaim-and-bind

Conversation

@raylitebull

@raylitebull raylitebull commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

Reclaims idle 64 MiB VRAM tile-pool heaps (keeping a configurable warm spare count via XCL_VRAM_KEEP_SPARE_POOLS, default 1), defers reclaimed heap destruction safely behind GPU fence completion (retire_fence), canonicalizes GPU mirror virtual addresses (canonical_va) only when uncommitted/aliasing a mapped GPU view (physical_page_at + VirtualQuery MEM_COMMIT guard), and widens is_small_cpu_filled_target up to 2048 on an axis (<= 1M pixels) so 2048x128 CPU-filled glyph atlases stay in sync.

Part of #1833.

What is in it

  • crates/xcl/src/hle/d3d12x/vram.rs:
    • Arenas::sweep_dropped: zero-alloc fast-path + order-preserving drain (arenas_sweep_dropped_preserves_newest_fitting_order).
    • TilePool::reclaim_empty_heaps, per-device last_reclaim, and retire_fence (queue.Signal + fence.GetCompletedValue() verification) so reclaimed pool/arena ID3D12Heap objects are never dropped while in-flight GPU work references them (compatible with #1983's note_internal_wait).
    • canonical_va: checks kernelx::physical_page_at(va) + VirtualQuery MEM_COMMIT before aliasing a GPU mirror view (canonical_va_aliases_unmapped_gpu_view_but_preserves_committed_override).
  • crates/xcl/src/hle/kernelx.rs & crates/xcl/src/hle/d3d12x/title_textures.rs:
    • kernelx::mirrors::gpu_views_of + symmetric title_textures::retire_overlapping retirement in both directions (gpu_va -> cpu_va and cpu_va -> paired gpu_va).
    • is_small_cpu_filled_target up to 2048x128 (<= 1M pixels, small_cpu_filled_target_accepts_wide_glyph_atlas_and_rejects_large_or_depth).

Tested

  • Toolchain: Windows 11 x64, rustc 1.99.1 (58cf8f9c3 2026-10-13), rebased cleanly onto 3da2abb (5a515f0).
  • Release compilation verified locally (cargo build --release, 0 errors) on 5a515f0; GitHub Actions Build and test is running on this pushed head (5a515f0).
  • Exact-head 60 s scripts/smoke.ps1 regression pair on AMD Radeon RX 9070 (@Toons29): passed (0 device removals, 0 crashes).

Regression run
60 s scripts/smoke.ps1 pair on exact head 5a515f0 vs main (AMD Radeon RX 9070, driver 32.0.32029.2010, Windows 11 26300, release, XCL_NETWORK=0 on a retail title), contributed by @Toons29:

main:

xcl-smoke v1
commit: cbc296ab65a2661a61e3e2da109134bcd5319f60
gpu: AMD Radeon RX 9070
title: 34df7c50
seconds: 60
exit: 0x0
frames shown: 1623 (PresentX 1623)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14648 MB

this PR:

xcl-smoke v1
commit: 5a515f0398b664975306794ac6498c436d81aa28
gpu: AMD Radeon RX 9070
title: 34df7c50
seconds: 60
exit: 0x0
frames shown: 1630 (PresentX 1631)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14688 MB

Not tested

  • cargo test suite and 60 s scripts/smoke.ps1 pair on 5a515f0, full cargo test --workspace suite, runtime GPU execution across AMD / NVIDIA / Intel hardware, and Linux/Wine/vkd3d-proton.

AI use

  • Antigravity assisted with implementation and unit tests; the author reviewed the diff and test output.

@Filip722

Copy link
Copy Markdown

On 363a451, expiring an unrelated arena made the next texture placement select an older overlapping heap. The reproducer creates a one-page arena and then a two-page arena at the same address. After cleanup, the one-page placement chose arena 2 instead of the newest fitting arena, 3. The PR parent’s allocator passes the same isolated fixture. Preserving insertion order during extraction fixes the Windows regression test. Fix and test for cherry-pick

On the RTX 5060 Laptop GPU (8 GiB), an asset-free D3D12 probe allocated three 64 MiB heaps. With one warm spare, DXGI local usage went from 208 to 144 MiB after reclaim, then back to 208 MiB when the slot was reused. Ten focused checks passed with zero failures, ignores or hardware skips, including that local probe. Bazzite 44, NVIDIA 615.78.08, Proton Experimental 11.0-20261112, vkd3d-proton 3.1.0 (4522cc1a8b1347f+), Windows MSVC target, Rust 1.98.1.

In matched offline Series X startup checks (parent 8c4a46a and fixed PR e9f2d68), both reached 512 MiB in target-page pools and 896 MiB in sparse pools. The fixed build logged no heap reclaim during that interval. All window captures were black. The parent hit the test’s swap cutoff at 24 seconds and the fixed build reached the 25-second deadline. Gameplay savings remain unmeasured.

OpenAI Codex (GPT-6.2-Sol) assisted with diagnosis, implementation, tests and reporting.

@eizispark

Copy link
Copy Markdown

Hardware test report — commit 363a451

Verified 363a45140d3ce9593f48ce963ca8420ddd7a4bd7 (based on 8c4a46a3c2d50498691cbda79cbbf4fadb45fbe8; clean merge with current main 6567c5f): pass (0 new failures vs main; all vram and title_textures unit/GPU tests pass).

Tested

  • Hardware: Windows 11 x64, AMD Ryzen 7 9800X3D, AMD Radeon RX 9070 XT (16 GB VRAM, RDNA4, Tiled Resources Tier 4, driver 32.0.32015.16001), 32 GB RAM, rustc 1.100.0 (0ef1bc386 2026-11-09) (stable-x86_64-pc-windows-msvc), debug tests + release smoke
  • Unfiltered cargo test --workspace --no-fail-fast -- --test-threads=4: 996 passed, 2 failed, 45 ignored (8 skipped) — 0 new failures:
    • hle::d3d12x::title_textures::tests (14/14 passed, 0 skips: including small_cpu_filled_target_accepts_wide_glyph_atlas_and_rejects_large_or_depth, placed_title_textures_share_vram_and_preserve_pixels, gpu_mirror_upload_follows_cpu_writes_and_later_mapping_changes, transitions_apply_when_their_list_is_submitted)
    • hle::d3d12x::vram::tests (12/12 passed, 0 skips: including tile_pool_reclaims_empty_heaps_keeping_warm_spare_and_reuses_slots, arenas_sweep_dropped_returns_expired_heaps, d32s8_targets_take_their_own_size_of_video_memory, streamed_targets_stay_bounded)
    • Native RDNA4 wave64 GPU tests (gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware, console_wave64_compute_through_the_pso_hook_dispatch_and_read_back) all passed
    • The 2 failures (gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1 seed 722 and fuzz_validate_and_gpu_3 seed 1599) are pre-existing on main (#1679); 8 skipped = 6 lower_dxil f16/f32 #1426-semantics sub-cases, pso_measurement_compiles_an_exact_synthetic_record (0x887A002D), and heap_window_out_of_memory_falls_back_to_the_switch_form: no heap windows
  • 60 s retail xcl.log check: logged 64 CPU-filled glyph-cache render targets kept in step with title memory and 8192 skipped unchanged uploads; empty 64 MiB VRAM pool-heap reclamation did not trigger during the 60 s menu window

Regression run
main (8e87fc7b62a87ea589ccb9ea6182f514016cf7db):

xcl-smoke v1
commit: 8e87fc7b62a87ea589ccb9ea6182f514016cf7db
gpu: AMD Radeon RX 9070 XT
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1675 (PresentX 1675)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14861 MB

PR (363a45140d3ce9593f48ce963ca8420ddd7a4bd7):

xcl-smoke v1
commit: 363a45140d3ce9593f48ce963ca8420ddd7a4bd7
gpu: AMD Radeon RX 9070 XT
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1678 (PresentX 1678)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14824 MB

Not tested

  • sustained 3D world streaming past 60 s exercising live 64 MiB VRAM pool-heap reclamation under tile churn, < 16 GB VRAM GPUs, NVIDIA/Intel GPUs, Wine/vkd3d-proton

AI use

  • Antigravity (Google DeepMind, Gemini 4 Carbon) ran the workspace test suite and 60-second retail smoke check and formatted this report.

@gsucristo

Copy link
Copy Markdown
Contributor

Technical review findings:

Blocking

  1. Arenas::sweep_dropped breaks insertion order via swap_remove (vram.rs, Arenas::sweep_dropped): Arenas::take uses self.list.iter().rposition(fits) assuming self.list stays ordered oldest-to-newest so it picks the newest fitting arena. Using swap_remove moves the newest arena to the front when an older arena expires, causing overlapping placements to pick an older arena. Needs an order-preserving removal.

Major

  1. canonical_va unconditionally aliases GPU mirror views (vram.rs, canonical_va, place_on_pages, place): Calls kernelx::mirrors::source(va).unwrap_or(va) without checking kernelx::physical_page_at(va) or va_committed(va). If a title maps distinct physical pages directly at a GPU mirror address va, this falsely aliases unrelated textures onto the same VRAM pages/arena.
  2. Asymmetric mirror retirement (title_textures.rs, retire_overlapping): by_va/shadowed_by_va are keyed by entry.va, not entry.src. Retiring a GPU-owned target at cpu_va sees mirror_source(cpu_va) == cpu_va and misses any texture registered at the paired gpu_va, allowing stale CPU uploads to overwrite the render target.
  3. Destroying ID3D12Heaps on wall-clock COOL (2 s) without GPU fence verification (vram.rs, sweep_and_reclaim, before_execute): If any title queue is stalled >2 s (e.g. heavy PSO compile or Wine/vkd3d-proton stall) with in-flight work referencing a resource mapped to that heap, dropping the ID3D12Heap causes GPU UAF / device removal. Also should_reclaim uses a process-global LAST_MS static across devices.

@Anon64

Anon64 commented Nov 25, 2026

Copy link
Copy Markdown

Regression run for this PR: head 363a451, based on main 80f4819. RTX 3060 12 GB (581.80, wave32), Windows 11 26200, release, XCL_NETWORK=0, A pressed every 4 s from 20 s, scripts/smoke.ps1 on a retail title for 60 s, in one batch with the main run.

main 80f4819:

xcl-smoke v1
commit: 80f4819098e921f2e1ab371144d4832f68ffedd6
gpu: NVIDIA GeForce RTX 3060
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1588 (PresentX 1589)
presents per 2 s (last 3): 47 56 27
device removals: 0
crashes: 0
peak commit: 25184 MB

this PR:

xcl-smoke v1
commit: 363a45140d3ce9593f48ce963ca8420ddd7a4bd7
gpu: NVIDIA GeForce RTX 3060
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1626 (PresentX 1626)
presents per 2 s (last 3): 60 44 54
device removals: 0
crashes: 0
peak commit: 24036 MB

No device removals or crashes; 102 % of main's frames, 95 % of its peak commit.

Not tested: the whole suite; world loading; whether the title reaches all of the changed code in these 60 s (default settings: XCL_DIRECT_DXIL and XCL_HEAP_WINDOWS unset).

Written with Claude Code (Claude Opus 5.5) from runs on this machine.

@raylitebull
raylitebull force-pushed the feat/vram-local-reclaim-and-bind branch from 363a451 to 5a515f0 Compare November 25, 2026 01:53
@raylitebull

Copy link
Copy Markdown
Member Author

Thanks for the detailed catches, @Filip722 and @gsucristo!

Updated #1985 cleanly onto 3da2abb (5a515f0), addressing the Blocking + Major findings:

  1. Arenas::sweep_dropped order & fast-path (vram.rs): switched to a zero-alloc fast-path and order-preserving drain (arenas_sweep_dropped_preserves_newest_fitting_order).
  2. canonical_va committed-page guard (vram.rs): checks kernelx::physical_page_at(va) and VirtualQuery MEM_COMMIT before aliasing a GPU mirror view (canonical_va_aliases_unmapped_gpu_view_but_preserves_committed_override).
  3. Symmetric overlap retirement (kernelx.rs, title_textures.rs): added kernelx::mirrors::gpu_views_of so retire_overlapping retires both gpu_va -> cpu_va and cpu_va -> paired gpu_va.
  4. Per-device reclaim & fence-guarded heap drop (vram.rs): replaced the global LAST_MS throttle with per-device last_reclaim, and deferred reclaimed pool/arena ID3D12Heap destruction behind retire_fence (queue.Signal + fence.GetCompletedValue() verification) so in-flight GPU work never observes premature drops (preserving #1983's note_internal_wait).

Compiled cleanly in release (0 errors) and pushed 5a515f0 for GitHub Actions Build and test + reviewer verification.

@DavidM1911

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11): merge conflict with current main (crates/xcl/src/hle/d3d12x/vram.rs) — needs a rebase before it can be tested.

@thehollowedone

Copy link
Copy Markdown
Contributor

Independent NVIDIA check of 5a515f0 against the requested 3da2abb baseline. Windows 11 build 26300, RTX 3080 Ti / 621.35, Rust 1.99.1 MSVC, debug build.

Built with cargo test --offline --locked -j 4 -p xcl --lib --no-run. Ran both test binaries with XCL_ADAPTER=3080 Ti, XCL_HEAP_WINDOWS=1, and --nocapture --test-threads=1 hle::d3d12x::vram hle::d3d12x::title_textures. The PR had 29 passing tests and the baseline had 24. Both had zero failures, one ignored test, and zero reported skips.

The PR's empty-pool bookkeeping test passed. The shared-VRAM GPU test passed on both revisions. Its 512 unreleased 1 MiB texture placements over a 16 MiB working set had zero additional page growth after fill. Coverage was the stock synthetic tests with default driver validation.

AI-assisted. Codex (GPT-6, exact variant unavailable) ran the tests and drafted this report.

@thehollowedone

Copy link
Copy Markdown
Contributor

Follow-up on 5a515f0. A separate synthetic GPU fixture on the RTX 3080 Ti (621.35, Windows 11 build 26300) created one pool with a live RGBA8 texture and two empty 64 MiB heaps. With one warm spare configured, before_execute moved one heap to retirement, and the next call after the queue fence drained that entry. Readback matched all 65,536 bytes of the surviving texture.

One exact test passed with zero failures or skips. The fixture seeded already-empty heaps and exercised native D3D12 retirement on one queue. AI-assisted. Codex (GPT-6, exact variant unavailable) wrote and ran the fixture and drafted this report.

@Toons29

Toons29 commented Nov 25, 2026

Copy link
Copy Markdown

Regression run of 5a515f03 on the retail title, for this PR's Regression run section. Both blocks are from scripts/smoke.ps1 as printed, not edited: main on cbc296ab, this PR on its head commit with no uncommitted changes, same title and time.

xcl-smoke v1
commit: cbc296ab65a2661a61e3e2da109134bcd5319f60
gpu: AMD Radeon RX 9070
title: 34df7c50
seconds: 60
exit: 0x0
frames shown: 1623 (PresentX 1623)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14648 MB
xcl-smoke v1
commit: 5a515f0398b664975306794ac6498c436d81aa28
gpu: AMD Radeon RX 9070
title: 34df7c50
seconds: 60
exit: 0x0
frames shown: 1630 (PresentX 1631)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14688 MB

Against the limits in CONTRIBUTING.md: 100 % of main's frames, 100 % of its peak commit, no crash, no device removal.

AMD Radeon RX 9070 (RDNA4, driver 32.0.32029.2010), Ryzen 7 7800X3D, 32 GB, Windows 11 build 26300, Rust 1.100.0, cargo build --release -p xcl, 60 s, XCL_NETWORK=0. This is a regression check only: it does not show whether the run reaches the code this PR changes.

AI use: Claude Code (Claude Opus 5.5) built both trees and ran scripts/smoke.ps1; a script posted this right after the run, with both blocks exactly as printed.

IvyNotFound added a commit to IvyNotFound/xcl that referenced this pull request Nov 25, 2026
IvyNotFound added a commit to IvyNotFound/xcl that referenced this pull request Nov 25, 2026
xcl-dev#1182 keys owned pages by their physical page, but the count of tiles to take (from the
xcl-dev#1985/xcl-dev#1663 batch code) still looked pages up by address: a page already shared through its
physical page was counted as missing, and a new one not, so fresh_iter ran dry and the
title aborted at vram.rs:789 in the first XCLM run (49 s, menus).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@raylitebull

Copy link
Copy Markdown
Member Author

Thanks @Toons29 for running and sharing the exact-head 60 s scripts/smoke.ps1 pair on 5a515f0 (0 device removals, 0 crashes) — added to the PR description!

@raylitebull
raylitebull merged commit b7130dc into xcl-dev:main Nov 25, 2026
2 of 4 checks passed
anoyarou added a commit to anoyarou/xcl that referenced this pull request Nov 25, 2026
Brings main to full parity with upstream/main (cdb0891), including:
- World rendering & gameplay: xcl-dev#1991, xcl-dev#1988, xcl-dev#1984, xcl-dev#2028, xcl-dev#2078
- Memory / VRAM / PSO: xcl-dev#1985, xcl-dev#2157, xcl-dev#2178, xcl-dev#2195, xcl-dev#2176, xcl-dev#1996, xcl-dev#1914
- Direct DXIL & shaders: xcl-dev#2120, xcl-dev#2174, xcl-dev#2194, xcl-dev#2207, xcl-dev#1951, xcl-dev#1973, xcl-dev#2156, xcl-dev#2064
- Preserves local Linux/Wine customizations: docs/linux.md, scripts/linux/*,
  in-process Wine XAsync (xgameruntime/api.rs), loader watchdog bypass, and
  Wine MEM_WRITE_WATCH bypass on coherent UMA windows (gpu/uma.rs).

Assisted-by: Antigravity (Gemini 4)
rrrarrra9 added a commit to rrrarrra9/xcl that referenced this pull request Nov 25, 2026
Pass per-device heap properties when the batched allocator grows. Keep xcl-dev#1747 batching and xcl-dev#1985 heap slot reuse and fence-delayed retirement for both heap types. Verify the selected backing with a two-tile GPU copy/readback.

Assisted-by: OpenAI Codex (GPT-6)
@DavidM1911

Copy link
Copy Markdown
Contributor

Re-verification on RTX 3060 Ti (Windows 11), new head merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, 27 ignored. The earlier merge conflict is resolved.

Thanks!

— Devin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants