Skip to content

D3D12.X: release empty tiled-texture VRAM pools - #800

Draft
wayward-tail wants to merge 1 commit into
xcl-dev:mainfrom
wayward-tail:pr/release-empty-vram-pools
Draft

wayward-tail wants to merge 1 commit into
xcl-dev:mainfrom
wayward-tail:pr/release-empty-vram-pools

Conversation

@wayward-tail

@wayward-tail wayward-tail commented Nov 24, 2026 •

Copy link
Copy Markdown

Tiled-texture pool heaps remain allocated after all their tiles become free. Release excess completely free heaps after cooling, keep one warm pool, and reuse vacated pool slots. This preserves the upstream idle-page sweep.

What is in it

  • vram.rs: reclaim free pool heaps, count only live heaps in memory reporting, and test cooling, live tiles, the warm pool and slot reuse.
  • README note describing the behavior.

Tested

  • Commit e712b74e0157f9bfc3a4870d9683e048bcc54a95; Windows 11 Home build 26200, AMD Ryzen 7 8845HS, NVIDIA RTX 4060 Laptop GPU (driver 32.0.15.9282), Rust 1.100.0 MSVC, DXC 1.9.2609.5. Tests debug; title smoke release with symbols. XCL_ADAPTER=rtx 4060.
  • cargo build --workspace and cargo build --release -p xcl: succeeded.
  • cargo test --workspace --no-fail-fast -- --test-threads=4: 701 passed, 1 failed, 41 ignored. The two wave64 skips below are included in Cargo's passed count.
  • Baseline 64b3f35: 700 passed, 1 failed, 41 ignored. gpu_clamp_and_omod_per_instruction fails at v_pk_add_i16 clamp on unmodified main on this GPU.
  • Branch failures: gpu::recomp::tests::gpu_clamp_and_omod_per_instruction.
  • GPU skips: SKIPPED gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask: no wave64; SKIPPED gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware: no wave64.

Regression run
Main:

xcl-smoke v1
commit: 64b3f35599bb7102f55d640e1a791e7d6dd3b175
gpu: NVIDIA GeForce RTX 4060 Laptop GPU
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 989 (PresentX 990)
presents per 2 s (last 3): 50 49 53
device removals: 0
crashes: 0
peak commit: 15068 MB

This branch:

xcl-smoke v1
commit: e712b74e0157f9bfc3a4870d9683e048bcc54a95
gpu: NVIDIA GeForce RTX 4060 Laptop GPU
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1115 (PresentX 1116)
presents per 2 s (last 3): 60 58 60
device removals: 0
crashes: 0
peak commit: 14658 MB

Not tested

  • Earlier title runs were inconsistent: one smoke wrapper timed out without a usable report; a diagnostic rerun exited normally at 60 s with 611 frames and no submits in its final 16 s. The recorded repeat below reached 1115 frames with no crash/device removal. The cause of the earlier stalls is not established; retain this as a draft pending stability checks.
  • AMD / Intel GPU behavior, wave64, gameplay and sustained streaming. The smoke runs exercise startup without menu input.
  • Tests requiring XCL_SAMPLE_* game-data variables: unset, so those bodies were not exercised.
  • Not merge-ready while the full suite has failures; retained as a draft with the upstream baseline failure disclosed.

AI use

  • OpenAI Codex (GPT-6) reconciled the existing local fix with upstream, adjusted the regression test where needed, ran validation, and prepared this description. The existing local commit's original model provenance is unknown.

Pages previously appended 64 MiB DEFAULT pool heaps monotonically and never released them back to VRAM even after idle and cooling tiles returned to free.

Track pool heaps as Vec<Option<ID3D12Heap>>, drain expired cooling tiles in sweep(), drop excess pools whose all POOL_PAGES tiles are free (keeping at least one pool warm), and reuse vacated pool indices on future allocations.
@futurepro62

Copy link
Copy Markdown

Full-suite run, since this PR has no test report yet. Tested exact head e712b74 (on its base 64b3f35).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 616.64, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.100.0 MSVC, debug, D3D12 debug layer installed.
  • cargo build --workspace, then XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4: 702 passed, 0 failed, 41 ignored. SKIPPED (no wave64): gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware.
  • The new tests ran and passed: empty_tile_pools_are_released_after_cooling_and_slots_reused.

Not tested

  • AMD, a release build, a game (test run only).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.

@iggyvilla

Copy link
Copy Markdown
Contributor

Code read of head e712b74 (static read only; nothing built or run). Two points.

1. pools.len() is no longer the number of live heaps, and #640 / #782 read it as one.
After this PR a released heap stays as a None slot (vram.rs:463 release_empty_pools, slot reused by insert_pool, vram.rs:448), so pools.len() only ever grows to the high-water mark. The page budget in #640 (vram.rs:329) and #782 (vram.rs:319) is

if cap > 0 && self.pools.len() >= cap {
    self.evict_lru(EVICT_BATCH);

git merge-tree of #782 with this PR is clean, so nothing flags it, but once a heap has been released and len() has reached cap, take_tile runs evict_lru (unmaps and later re-uploads live textures) every time the free list and cooling are empty, even if the live heap count is well under the budget. The count to use there is self.pools.iter().flatten().count() (or a small live_pools() helper next to insert_pool). Whichever of these lands second should carry that change; worth a line in the description so it is not missed.

2. sweep now does O(free tiles) work and allocates on every placement.
bind calls self.sweep(now) for every placement (vram.rs:397). release_empty_pools returns early only when free.len() < POOL_PAGES or one heap is live; otherwise it allocates vec![0u32; pools.len()] and walks all of free (vram.rs:473 on). With several live heaps and a few thousand free tiles that is a walk plus an allocation per CreatePlacedResourceX. sweep_idle right above it was changed in #490 specifically so that a placement does not look at every page. Per-heap free counters kept in take_tile / release_tiles, or running the release pass at most once per COOL, would keep the placement path flat.

Smaller: the heap is dropped once its tiles have sat in cooling for COOL (2 s); please say in the description that the 2 s wall-clock COOL is accepted as the guard for destroying the ID3D12Heap too, as it already is for reusing a tile.

AI use: Claude Code, Claude Sonnet 5.5, read the diff and the code of #640 / #782 at the heads named above and drafted this comment; I checked each line reference.

gustavsi added a commit to gustavsi/xcl that referenced this pull request Nov 24, 2026
…ps (ivall#594)

Re-apply XCL_PAGE_BUDGET_MB LRU texture eviction (ivall#640) and fenced unmaps (ivall#594) on top of upstream/main (930e8b4) + ivall#1182/ivall#1142/ivall#800, using real::create_raw_fence for vram queue fences under Wine.

Assisted-by: Antigravity (Google DeepMind)
@Jefter5549

Jefter5549 commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Hardware verification on NVIDIA GeForce RTX 2060 SUPER (Turing 8 GB) at 6142deb (PR #800 merged with latest main + PR #1017; note: #1017 was later closed as invalid)

Environment:

  • OS: Windows 11 Pro 24H2 (x64)
  • CPU: Intel Xeon E5-2666 v3 (10C/20T, Haswell-EP)
  • GPU: NVIDIA GeForce RTX 2060 SUPER 8 GB (driver 32.0.15.6614), 32-lane wave32 architecture
  • RAM: 32 GB DDR4 2133 Quad-Channel
  • Toolchain: rustc 1.100.0 MSVC / DXC 1.9.2602.17 (Windows SDK 10.0.26100.0)
  • Profile: Release build (--release -p xcl)

1. Invariants & Unit Verification:

  • cargo test -p xcl --lib empty_tile_pools: PASSED (empty_tile_pools_are_released_after_cooling_and_slots_reused).
  • cargo test -p xcl --lib vram -- --test-threads=1: 12/12 PASSED (all arena, isolation, page boundary, and pool lifecycle tests pass cleanly).
  • Invariant checks confirmed:
    1. Warm Pool Floor (live >= 1): Kept at least one warm pool active under complete drain; no heap thrashing observed.
    2. Cooling Quarantine (COOL = 2s): Tiles in cooling are preserved until wall-clock expiry and GPU fence completion.
    3. Zero Dangling Free Tiles: Verified free.retain purges indices corresponding to dropped heaps.
    4. Slot Reuse: Verified insert_pool reuses None slots first, preventing unbounded vector growth.

2. Retail Title Smoke & Sustained Streaming Run:

Tested on a heavy retail title package with XCL_NETWORK=0 and XCL_ACTIVITY=1:

  • Presents: 8,333 frames presented at 4K (3840x2160, format 28) at solid 30.0 FPS (60 presents / 2 s), 0 frame-event timeouts.
  • Audio: 24,825 Opus packets (23,769,600 audio samples) decoded through XAudio2 with 0 errors.
  • DirectStorage: Streamed over 2.5 GB of world assets with zero transfer errors.
  • VRAM Behavior & Impact:
    • On baseline main without this PR, switching from loading screens to video streams repeatedly triggered CreateHeap(0x4000000) refused (0x887A0005) as abandoned loading heaps exhausted 8 GB VRAM.
    • With PR D3D12.X: release empty tiled-texture VRAM pools #800, CreateHeap failures were 100% eliminated (0 heap refusals). Local video memory stayed stabilized at 7,295 MB across 3,000+ frames during steady-state loading screens.

3. Edge Cases, Cross-PR Combinations & Downstream Interactions:

  1. Note on PR D3D12.X: use NON_PIXEL_SHADER_RESOURCE state for predication on compute command lists #1017 (closed): PR D3D12.X: use NON_PIXEL_SHADER_RESOURCE state for predication on compute command lists #1017 was included in this test build, but was later closed after D3D12 debug layer testing confirmed D3D12_RESOURCE_STATE_PREDICATION is the valid state on compute command lists (whereas NON_PIXEL_SHADER_RESOURCE triggers debug layer error 538). Subsequent clean main runs confirmed compute command list splits pass without D3D12.X: use NON_PIXEL_SHADER_RESOURCE state for predication on compute command lists #1017.
  2. Compatibility with @iggyvilla's review: Concur that pools.len() reflects the high-water mark rather than live count; downstream page-budget mechanisms (such as PR D3D12.X: an optional page budget evicts CPU-filled title textures LRU #640) reading pools.len() should check pools.iter().flatten().count().
  3. Combination with continuous streaming: While PR D3D12.X: release empty tiled-texture VRAM pools #800 successfully reclaims completely empty heaps after cooling, titles that stream continuously without unmapping old resources eventually expand target pages (reached 9.6 GB during intro transition). PR D3D12.X: release empty tiled-texture VRAM pools #800 forms the necessary foundation for heap release, which pairs effectively with PR D3D12.X: an optional page budget evicts CPU-filled title textures LRU #640's LRU eviction on 8 GB cards.

AI use: Gemini 4 Neon assisted with test orchestration, telemetry analysis, and report preparation.

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.

5 participants