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

Closed
github-bot wants to merge 1 commit from gh-pr/800/head into gh-pr/800/base
Owner

@⁠wayward-tail on GitHub · 2026-11-24 05:36 UTC · original
wayward-tail:pr/release-empty-vram-pools → main · +90 −7 · 2 files · 1 commits · closed without merging

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.
**@⁠wayward-tail** on GitHub · 2026-11-24 05:36 UTC · [original](https://github.com/xcl-dev/xcl/pull/800) `wayward-tail:pr/release-empty-vram-pools` → `main` · +90 −7 · 2 files · 1 commits · closed without merging 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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:33:05 +00:00
github-bot closed this pull request 2026-11-26 04:33:05 +00:00
Author
Owner

@⁠futurepro62 on GitHub · 2026-11-24 07:06 UTC · original

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.
**@⁠futurepro62** on GitHub · 2026-11-24 07:06 UTC · [original](https://github.com/xcl-dev/xcl/pull/800#issuecomment-7124616723) 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.
Author
Owner

@⁠iggyvilla on GitHub · 2026-11-24 07:34 UTC · original

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.

**@⁠iggyvilla** on GitHub · 2026-11-24 07:34 UTC · [original](https://github.com/xcl-dev/xcl/pull/800#issuecomment-7125140416) 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 ```rust 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.
Author
Owner

@⁠Jefter5549 on GitHub · 2026-11-24 15:46 UTC · original · edited 2026-11-24 20:28 UTC

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 #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 #1017 (closed): PR #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 #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 #640) reading pools.len() should check pools.iter().flatten().count().
  3. Combination with continuous streaming: While PR #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 #800 forms the necessary foundation for heap release, which pairs effectively with PR #640's LRU eviction on 8 GB cards.

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

**@⁠Jefter5549** on GitHub · 2026-11-24 15:46 UTC · [original](https://github.com/xcl-dev/xcl/pull/800#issuecomment-7136593504) · edited 2026-11-24 20:28 UTC **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 #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 #1017 (closed):** PR #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 #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 #640) reading `pools.len()` should check `pools.iter().flatten().count()`. 3. **Combination with continuous streaming:** While PR #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 #800 forms the necessary foundation for heap release, which pairs effectively with PR #640's LRU eviction on 8 GB cards. **AI use:** Gemini 4 Neon assisted with test orchestration, telemetry analysis, and report preparation.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-25 10:58 UTC · original

Verification on RTX 3060 Ti (Windows 11): merge conflict with current main — needs a rebase before it can be tested.

**@⁠DavidM1911** on GitHub · 2026-11-25 10:58 UTC · [original](https://github.com/xcl-dev/xcl/pull/800#issuecomment-7160423385) Verification on RTX 3060 Ti (Windows 11): **merge conflict with current `main`** — needs a rebase before it can be tested.
Author
Owner

@⁠Prime1997 on GitHub · 2026-11-26 00:32 UTC · original

Closing because main already has this behaviour, from 5a515f03 ("reclaim empty 64 MiB VRAM pool heaps"). In crates/xcl/src/hle/d3d12x/vram.rs, PoolHeaps reuses vacated slots (free_slots) and counts only live heaps. reclaim_empty_heaps() drops completely free, cooled pool heaps and keeps one spare warm by default (XCL_VRAM_KEEP_SPARE_POOLS). This branch also conflicts with main in vram.rs. #1142 (texture-only heap flags) is a separate change and is not affected.

Compared at head e712b74e against main 08db802. Reviewed with Claude Code (Claude Opus 5.5); I checked the comparison before closing.

**@⁠Prime1997** on GitHub · 2026-11-26 00:32 UTC · [original](https://github.com/xcl-dev/xcl/pull/800#issuecomment-7178865857) Closing because main already has this behaviour, from 5a515f03 ("reclaim empty 64 MiB VRAM pool heaps"). In `crates/xcl/src/hle/d3d12x/vram.rs`, `PoolHeaps` reuses vacated slots (`free_slots`) and counts only live heaps. `reclaim_empty_heaps()` drops completely free, cooled pool heaps and keeps one spare warm by default (`XCL_VRAM_KEEP_SPARE_POOLS`). This branch also conflicts with main in vram.rs. #1142 (texture-only heap flags) is a separate change and is not affected. Compared at head e712b74e against main 08db802. Reviewed with Claude Code (Claude Opus 5.5); I checked the comparison before closing.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.