D3D12.X: bound target-page pools by title and adapter VRAM budgets #2357

Open
github-bot wants to merge 1 commit from github-bot/gh-2357 into main AGit
Owner

@⁠safesearch77 on GitHub · 2026-11-25 16:29 UTC · original
safesearch77:fix/vram-target-pages-budget → main · +766 −84 · 1 files · 1 commits · open

Bound vram::Pages 64 MiB pool-heap growth by Config::title_memory_budget_mb() and DXGI local VRAM budget, and keep Tier-2 reserved resources alive with explicit D3D12_TILE_RANGE_FLAG_NULL partial tile mappings when capped or out of VRAM instead of destroying them and failing CreatePlacedResourceX with 0x8007000E.

Part of #1833
Part of #646
Part of #333
Part of #1337
Part of #1773

What is in it

  • crates/xcl/src/hle/d3d12x/vram.rs:
    • compute_max_pools / target_pages_max_pools: cap 64 MiB PoolHeaps at min(title_memory_budget_mb(), 75% of DXGI local VRAM budget) on discrete GPUs (5,056 MiB / 79 pools on 8 GB GPUs; 4,096 MiB / 64 pools on #646 Run 2), use title_memory_budget_mb() on UMA adapters so small BIOS carve-outs are ignored, and support XCL_TARGET_PAGES_MB (0 = uncapped).
    • alloc_budgeted_pool & RetireQueue pool accounting (RetiringBatch::pool_heaps, note_queued_pools, reap_completed, poll_retiring_pool_heaps, page_bytes): count in-flight retiring 64 MiB pool heaps separately from variable-sized Arenas heaps sharing RetireQueue (active + retiring < max_pools), and poll/reap fence-completed retirements before refusing pool allocation at cap.
    • TilePool::take_up_to, Pages::bind_tiles, Pages::rebind & Target::is_complete: reuse 100% of already-resident shared pages at cap, retain packed mip tails (D3D12_PACKED_MIP_INFO) and coarsest standard mips across every array/cubemap slice (DepthOrArraySize) when fresh.len() < missing, back off CreateHeap retries for 1s on driver OOM until a pool is reclaimed or retired, and treat partially backed (used + used_extra < total) or 0-tile eager targets as incomplete in remap_if_unmapped so missing tiles backfill in place once budget frees up (under XCL_TEXTURE_LEVEL_PAGES=1, bind_range returns None at cap so unbacked level groups retry later).
    • TileRange::Null, heap_ranges & Pages::map: explicitly bind unbacked (None) tile spans with D3D12_TILE_RANGE_FLAG_NULL on the first heap pass (preserving trailing Null spans) and emit a pHeap = None D3D12_TILE_RANGE_FLAG_NULL mapping + pages.fence Signal when 0 tiles are backed, ensuring vkd3d-proton emits VK_NULL_HANDLE sparse binds instead of leaving newly created reserved tiles uninitialized on Linux/NVIDIA copy queues.
    • Pure-CPU and GPU tests (target_pages_budget_respects_env_title_memory_uma_and_adapter_vram, budgeted_bind_shares_pages_retains_cubemap_coarse_mips_and_recovers_after_free, retire_queue_pool_cap_counts_retiring_pools_ignores_arenas_and_polls_completion, capped_pages_keep_over_budget_placements_alive, extended tile_ranges_per_heap).

The diff is 850 changed lines (+766 / -84 in vram.rs), of which ~250 lines are the pure-CPU and GPU tests; the runtime budget formula, FLAG_NULL sparse binding, incomplete-target backfill, and retiring-pool cap accounting stay in one commit because they enforce one pool-cap invariant without regressions on capped placements.

Tested

  • Cross-typechecked rebased head c6213b24fc993a4df783f7713342beaf19e60c9d (on origin/main b49be183) on Linux x86_64 with cargo check --offline --target x86_64-pc-windows-gnu --workspace --tests (0 errors, 0 warnings in vram.rs; only b49be183's 2 pre-existing fetch_update deprecation warnings in d3d12x/real.rs:3804 and xgameruntime/mod.rs:547), and ran the 10 pure-CPU vram::tests natively via rustc --edition 2021 --test (10 passed; 0 failed: budget matrix, FLAG_NULL tile ranges, partial/0-tile bind_tiles backfill, 6-tail and single-tail cubemaps, and RetireQueue pool-cap vs Arenas accounting).
  • Windows GPU & retail title verification on v1 head 889008fd342ac779a601d7f93c8a54430360b306 vs base 65fc114a140d9043f8e3d70ffb863f7987816d8f:
    • @Haxodius (#2357 (comment)): AMD Radeon RX 6700 XT 12 GB (RDNA2, driver 32.0.21025.1024), Ryzen 5 5600X, 16 GB RAM, Windows 10 19045.6466, rustc 1.98.1 MSVC — cargo test --workspace --no-fail-fast -- --test-threads=4 (debug): 1283 passed, 1 failed (gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1 seed 540, same on 65fc114), 46 ignored; SKIPPED (8): six per-lane f16/f32 lower_dxil::tests, pso_measurement_compiles_an_exact_synthetic_record (Developer Mode off), heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows).
    • Community retail runs on 889008fd: RTX 3080 10 GB world-load 0/6 -> 6/6 surviving (@Berserker64), RTX 3060 12 GB -1.46 GB local VRAM (9.52 GB -> 8.06 GB, @jennydeth, plus 298.9 s at XCL_TARGET_PAGES_MB=4096 vs 4/4 device losses without #2357, @Anon64), RX 6600 XT 8 GB capped at 5,056 MiB / 79 pools with 0 crashes (@SlopTart), RX 9070 XT 16 GB Linux/RADV 25 min crash-free (@DavidM1911).

Regression run

Note: the 60 s scripts/smoke.ps1 pair below was recorded on v1 head 889008fd (@Haxodius, #2357 (comment)); a fresh scripts/smoke.ps1 pair on b49be183 and rebased head c6213b24 is still needed on Windows after force-pushing c6213b24.

main:

xcl-smoke v1
commit: 65fc114a140d9043f8e3d70ffb863f7987816d8f
gpu: AMD Radeon RX 6700 XT
title: f651e787
seconds: 60
exit: 0x0
frames shown: 1554 (PresentX 1554)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 13829 MB

PR (v1 889008fd — rerun pending for c6213b24):

xcl-smoke v1
commit: 889008fd342ac779a601d7f93c8a54430360b306
gpu: AMD Radeon RX 6700 XT
title: f651e787
seconds: 60
exit: 0x0
frames shown: 1562 (PresentX 1562)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 13834 MB

Not tested

  • Re-running the Windows GPU test suite (cargo test --workspace -- --test-threads=4, including the expanded capped_pages_keep_over_budget_placements_alive blocked-retire-fence and remap_if_unmapped recovery assertions) and a fresh scripts/smoke.ps1 pair on rebased head c6213b24 (authored on Linux without a Windows GPU host).
  • Re-testing Linux / Wine + vkd3d-proton on NVIDIA (lockhart / 8 GB cap) on c6213b24 to confirm explicit D3D12_TILE_RANGE_FLAG_NULL binding + #2275 multi-queue retirement resolve the Xid 31 copy-engine fault reported on 889008fd + 68a284a.
  • On 12 GB discrete GPUs where non-Pages allocations (sparse heaps, coherent window, PSOs) consume ~5 GB, the default 75% adapter cap (~8.3 GiB) prevents unbounded growth (#646) while XCL_TARGET_PAGES_MB=4096 (or title_memory_mb = 4096) bounds Pages more tightly; XCL_TARGET_PAGES_MB=0 restores uncapped behavior.

AI use

  • Antigravity (Gemini 4 Carbon): traced #646/#333/#1337 pool growth, vkd3d-proton D3D12_TILE_RANGE_FLAG_NULL sparse-init behavior, retiring-pool cap accounting, and partial-target remap_if_unmapped backfill; implemented the vram.rs changes, rebase onto b49be183, unit/GPU tests, and PR description; reviewed with Claude Opus 5.5. Windows v1 GPU test and smoke runs reported by @Haxodius using Claude Code (Claude Opus 5.5).
**@⁠safesearch77** on GitHub · 2026-11-25 16:29 UTC · [original](https://github.com/xcl-dev/xcl/pull/2357) `safesearch77:fix/vram-target-pages-budget` → `main` · +766 −84 · 1 files · 1 commits · open Bound `vram::Pages` 64 MiB pool-heap growth by `Config::title_memory_budget_mb()` and DXGI local VRAM budget, and keep Tier-2 reserved resources alive with explicit `D3D12_TILE_RANGE_FLAG_NULL` partial tile mappings when capped or out of VRAM instead of destroying them and failing `CreatePlacedResourceX` with `0x8007000E`. Part of #1833 Part of #646 Part of #333 Part of #1337 Part of #1773 **What is in it** - `crates/xcl/src/hle/d3d12x/vram.rs`: - `compute_max_pools` / `target_pages_max_pools`: cap 64 MiB `PoolHeaps` at `min(title_memory_budget_mb(), 75% of DXGI local VRAM budget)` on discrete GPUs (`5,056 MiB` / 79 pools on 8 GB GPUs; `4,096 MiB` / 64 pools on `#646` Run 2), use `title_memory_budget_mb()` on `UMA` adapters so small BIOS carve-outs are ignored, and support `XCL_TARGET_PAGES_MB` (`0` = uncapped). - `alloc_budgeted_pool` & `RetireQueue` pool accounting (`RetiringBatch::pool_heaps`, `note_queued_pools`, `reap_completed`, `poll_retiring_pool_heaps`, `page_bytes`): count in-flight retiring 64 MiB pool heaps separately from variable-sized `Arenas` heaps sharing `RetireQueue` (`active + retiring < max_pools`), and poll/reap fence-completed retirements before refusing pool allocation at cap. - `TilePool::take_up_to`, `Pages::bind_tiles`, `Pages::rebind` & `Target::is_complete`: reuse 100% of already-resident shared pages at cap, retain packed mip tails (`D3D12_PACKED_MIP_INFO`) and coarsest standard mips across every array/cubemap slice (`DepthOrArraySize`) when `fresh.len() < missing`, back off `CreateHeap` retries for `1s` on driver OOM until a pool is reclaimed or retired, and treat partially backed (`used + used_extra < total`) or `0`-tile eager targets as incomplete in `remap_if_unmapped` so missing tiles backfill in place once budget frees up (under `XCL_TEXTURE_LEVEL_PAGES=1`, `bind_range` returns `None` at cap so unbacked level groups retry later). - `TileRange::Null`, `heap_ranges` & `Pages::map`: explicitly bind unbacked (`None`) tile spans with `D3D12_TILE_RANGE_FLAG_NULL` on the first heap pass (preserving trailing `Null` spans) and emit a `pHeap = None` `D3D12_TILE_RANGE_FLAG_NULL` mapping + `pages.fence` `Signal` when `0` tiles are backed, ensuring `vkd3d-proton` emits `VK_NULL_HANDLE` sparse binds instead of leaving newly created reserved tiles uninitialized on Linux/NVIDIA copy queues. - Pure-CPU and GPU tests (`target_pages_budget_respects_env_title_memory_uma_and_adapter_vram`, `budgeted_bind_shares_pages_retains_cubemap_coarse_mips_and_recovers_after_free`, `retire_queue_pool_cap_counts_retiring_pools_ignores_arenas_and_polls_completion`, `capped_pages_keep_over_budget_placements_alive`, extended `tile_ranges_per_heap`). The diff is 850 changed lines (`+766 / -84` in `vram.rs`), of which ~250 lines are the pure-CPU and GPU tests; the runtime budget formula, `FLAG_NULL` sparse binding, incomplete-target backfill, and retiring-pool cap accounting stay in one commit because they enforce one pool-cap invariant without regressions on capped placements. **Tested** - Cross-typechecked rebased head `c6213b24fc993a4df783f7713342beaf19e60c9d` (on `origin/main` `b49be183`) on Linux `x86_64` with `cargo check --offline --target x86_64-pc-windows-gnu --workspace --tests` (`0` errors, `0` warnings in `vram.rs`; only `b49be183`'s 2 pre-existing `fetch_update` deprecation warnings in `d3d12x/real.rs:3804` and `xgameruntime/mod.rs:547`), and ran the 10 pure-CPU `vram::tests` natively via `rustc --edition 2021 --test` (`10 passed; 0 failed`: budget matrix, `FLAG_NULL` tile ranges, partial/0-tile `bind_tiles` backfill, 6-tail and single-tail cubemaps, and `RetireQueue` pool-cap vs `Arenas` accounting). - Windows GPU & retail title verification on v1 head `889008fd342ac779a601d7f93c8a54430360b306` vs base `65fc114a140d9043f8e3d70ffb863f7987816d8f`: - `@Haxodius` ([#2357 (comment)](https://git.gtahub.st/github/xcl-dev--xcl/pulls/2357)): AMD Radeon RX 6700 XT 12 GB (RDNA2, driver 32.0.21025.1024), Ryzen 5 5600X, 16 GB RAM, Windows 10 19045.6466, `rustc 1.98.1` MSVC — `cargo test --workspace --no-fail-fast -- --test-threads=4` (debug): `1283 passed`, `1 failed` (`gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1` seed 540, same on `65fc114`), `46 ignored`; `SKIPPED` (8): six per-lane `f16`/`f32` `lower_dxil::tests`, `pso_measurement_compiles_an_exact_synthetic_record` (Developer Mode off), `heap_window_out_of_memory_falls_back_to_the_switch_form` (no heap windows). - Community retail runs on `889008fd`: RTX 3080 10 GB world-load `0/6` -> `6/6` surviving (`@Berserker64`), RTX 3060 12 GB `-1.46 GB` local VRAM (`9.52 GB` -> `8.06 GB`, `@jennydeth`, plus `298.9 s` at `XCL_TARGET_PAGES_MB=4096` vs `4/4` device losses without `#2357`, `@Anon64`), RX 6600 XT 8 GB capped at `5,056 MiB` / 79 pools with `0` crashes (`@SlopTart`), RX 9070 XT 16 GB Linux/RADV 25 min crash-free (`@DavidM1911`). **Regression run** > Note: the 60 s `scripts/smoke.ps1` pair below was recorded on v1 head `889008fd` (`@Haxodius`, [#2357 (comment)](https://git.gtahub.st/github/xcl-dev--xcl/pulls/2357)); a fresh `scripts/smoke.ps1` pair on `b49be183` and rebased head `c6213b24` is still needed on Windows after force-pushing `c6213b24`. main: ``` xcl-smoke v1 commit: 65fc114a140d9043f8e3d70ffb863f7987816d8f gpu: AMD Radeon RX 6700 XT title: f651e787 seconds: 60 exit: 0x0 frames shown: 1554 (PresentX 1554) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 13829 MB ``` PR (v1 `889008fd` — rerun pending for `c6213b24`): ``` xcl-smoke v1 commit: 889008fd342ac779a601d7f93c8a54430360b306 gpu: AMD Radeon RX 6700 XT title: f651e787 seconds: 60 exit: 0x0 frames shown: 1562 (PresentX 1562) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 13834 MB ``` **Not tested** - Re-running the Windows GPU test suite (`cargo test --workspace -- --test-threads=4`, including the expanded `capped_pages_keep_over_budget_placements_alive` blocked-retire-fence and `remap_if_unmapped` recovery assertions) and a fresh `scripts/smoke.ps1` pair on rebased head `c6213b24` (authored on Linux without a Windows GPU host). - Re-testing Linux / Wine + `vkd3d-proton` on NVIDIA (`lockhart` / 8 GB cap) on `c6213b24` to confirm explicit `D3D12_TILE_RANGE_FLAG_NULL` binding + `#2275` multi-queue retirement resolve the `Xid 31` copy-engine fault reported on `889008fd` + `68a284a`. - On 12 GB discrete GPUs where non-`Pages` allocations (sparse heaps, coherent window, PSOs) consume ~5 GB, the default 75% adapter cap (~8.3 GiB) prevents unbounded growth (`#646`) while `XCL_TARGET_PAGES_MB=4096` (or `title_memory_mb = 4096`) bounds `Pages` more tightly; `XCL_TARGET_PAGES_MB=0` restores uncapped behavior. **AI use** - Antigravity (Gemini 4 Carbon): traced `#646`/`#333`/`#1337` pool growth, `vkd3d-proton` `D3D12_TILE_RANGE_FLAG_NULL` sparse-init behavior, retiring-pool cap accounting, and partial-target `remap_if_unmapped` backfill; implemented the `vram.rs` changes, rebase onto `b49be183`, unit/GPU tests, and PR description; reviewed with Claude Opus 5.5. Windows v1 GPU test and smoke runs reported by `@Haxodius` using Claude Code (Claude Opus 5.5).
`vram::Pages` backed GPU-owned targets (`vram::place`) and placed sampled
textures (`vram::place_pages`) with 64 MiB `D3D12_HEAP_TYPE_DEFAULT` pool
heaps without checking `Config::title_memory_budget_mb()` or DXGI's local
video-memory budget (`DXGI_MEMORY_SEGMENT_GROUP_LOCAL`). As a result:

1. `target pages` climbed past 9,521 MB even with `title_memory_mb = 4096`
   (#646), pushing WDDM into local-VRAM overcommit / PCIe thrash TDRs
   (`0x887a0007`) and multi-30 GB system commit on 8 GB and 12 GB GPUs
   (#1337, #1773).
2. When `alloc_pool_heap` eventually returned `None` on `CreateHeap` OOM,
   `place_on_pages` destroyed the already-created Tier-2 reserved
   `ID3D12Resource` and returned `None`, spilling into unbudgeted arenas
   or `CreateCommittedResource(DEFAULT)` until `CreatePlacedResourceX`
   returned `E_OUTOFMEMORY` (`0x8007000E`) and tripped the retail title's
   infallible-placement assert at `+0x193e00f` (#333, #1337).

Bound `Pages` pool creation to `min(title_memory_mb, 75% of DXGI local
budget)` on discrete adapters and `title_memory_mb` on UMA adapters by
default (overridable via `XCL_TARGET_PAGES_MB`, `0` = uncapped), back off
failed `CreateHeap` calls for 1s until a pool heap is reclaimed, and keep
over-budget Tier-2 reserved placements alive with unbacked tiles left
`D3D12_TILE_RANGE_FLAG_NULL` (retaining the coarsest mips across every
array/cubemap slice when `MipLevels > 1` while sharing all already-backed
pages).

Part of #1833 (#333, #646, #1337, #1773).

Assisted-by: Antigravity (Gemini 4 Carbon)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:28:47 +00:00
Author
Owner

@⁠Haxodius on GitHub · 2026-11-25 17:14 UTC · original

Windows / AMD RDNA2, 12 GB card + 16 GB RAM: exact head 889008f, suite + smoke pair + a cap-on / cap-off title A/B. No regression; on this machine host RAM runs out long before the target-page cap is reached, so the cap never engaged.

Tested

  • AMD Radeon RX 6700 XT 12 GB (RDNA2, native wave64), driver 32.0.21025.1024; Ryzen 5 5600X (6C/12T); 16 GB RAM, commit limit 35.9 GB; Windows 10 Home 19045.6466; rustc 1.98.1 MSVC; DXC / DXIL 1.9.2609.5; Agility D3D12Core 1.620.2.
  • Exact head 889008fd342ac779a601d7f93c8a54430360b306 and its base main 65fc114a140d9043f8e3d70ffb863f7987816d8f, each in a clean worktree.
  • cargo test --workspace --no-fail-fast -- --test-threads=4 (debug) on 889008f: 1283 passed, 1 failed, 46 ignored.
    • The failure is gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1 (seed 540: res[833] = 0x7, CPU 0x6). It fails the same way on the base 65fc114, so it is not this PR.
    • In a first run without --no-fail-fast, hle::d3d12x::list_x::tests::a_reset_while_the_last_submit_runs_records_on_another_pc_list also failed once; alone it passed 3 / 3 on the head. Reads as the parallel flake of #1978.
    • SKIPPED (8 lines): six per-lane f16 / f32 cases of lower_dxil::tests (refused: V_MUL_F16, V_PK_MUL_F16, V_CVT_F16_F32), pso_measurement_compiles_an_exact_synthetic_record (Developer Mode off), heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows).
    • The new vram::tests all pass on this card, including budgeted_bind_shares_pages_retains_cubemap_coarse_mips_and_survives_cap, capped_pages_keep_over_budget_placements_alive and target_pages_budget_respects_env_title_memory_uma_and_adapter_vram.
  • Budget the head picks on this card (default anaconda, 13 824 MiB): pool budget 8576 MiB, 134 pools from 75% of DXGI local budget.
  • Title runs: the retail title 1.0.2.1, my own copy, unpacked, on an NVMe drive; release builds.

Regression run

scripts/smoke.ps1, 60 s, default settings, same binaries. The first base run was on a cold shader cache (870 frames); this is the warm pair, base run again after it:

main:

xcl-smoke v1
commit: 65fc114a140d9043f8e3d70ffb863f7987816d8f
gpu: AMD Radeon RX 6700 XT
title: f651e787
seconds: 60
exit: 0x0
frames shown: 1554 (PresentX 1554)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 13829 MB

PR:

xcl-smoke v1
commit: 889008fd342ac779a601d7f93c8a54430360b306
gpu: AMD Radeon RX 6700 XT
title: f651e787
seconds: 60
exit: 0x0
frames shown: 1562 (PresentX 1562)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 13834 MB

Title A/B on the head, cap on (default) vs XCL_TARGET_PAGES_MB=0

  • Same binary, one run each, back to back, warm caches. XCL_NETWORK=0 XCL_DIRECT_DXIL=1 XCL_HEAP_WINDOWS=1 XCL_PSO_PRELOAD=0 XCL_DXC_THREADS=4 XCL_SPLIT_MIDLIST_WAIT=0 XCL_TEXTURE_LEVEL_PAGES=1 XCL_ACTIVITY=1, XCL_PRESS_AT=16:A, XCL_PRESS_A_AT=20,24,…,80,90,100. A local watchdog stops the title when free physical RAM stays under 500 MB for 3 s (16 GB host).
  • Both reached the loading of the world and were stopped by that watchdog before it presented:
cap on cap off
stopped at 83 s 87 s
process commit (last memory: line) 18 397 MB 18 767 MB
target pages (pools) 4 348 MB (4 544 MB) 4 309 MB (4 544 MB)
video memory local / non-local 7 898 / 4 554 MB 7 897 / 4 556 MB
level pages at ~60 s 2 418 MB placed, 940 MB backed 2 412 MB placed, 932 MB backed
frames by 63 s 1 500 1 500
  • So on a 12 GB card with 16 GB of host RAM, the pools stay at about half of the 8 576 MiB cap when host RAM runs out; the cap does not engage and the two arms match. No device removal, no crash, no failed placement in either.

Not tested

  • A run that reaches the cap: this host runs out of RAM at ~4.5 GB of pools. An 8 GB card, or this card with more host RAM, would be needed to see the capped path in the title.
  • The world itself, and whether textures under the cap look right.
  • NVIDIA / Intel, Linux / Wine, other titles.

AI use

  • Claude Code (Claude Opus 5.5) built the trees, ran the suite, the smoke pair and the title runs on the machine above, and wrote this report; I checked it before posting.
**@⁠Haxodius** on GitHub · 2026-11-25 17:14 UTC · [original](https://github.com/xcl-dev/xcl/pull/2357#issuecomment-7169207046) **Windows / AMD RDNA2, 12 GB card + 16 GB RAM: exact head `889008f`, suite + smoke pair + a cap-on / cap-off title A/B. No regression; on this machine host RAM runs out long before the target-page cap is reached, so the cap never engaged.** **Tested** - AMD Radeon RX 6700 XT 12 GB (RDNA2, native wave64), driver 32.0.21025.1024; Ryzen 5 5600X (6C/12T); 16 GB RAM, commit limit 35.9 GB; Windows 10 Home 19045.6466; rustc 1.98.1 MSVC; DXC / DXIL 1.9.2609.5; Agility D3D12Core 1.620.2. - Exact head `889008fd342ac779a601d7f93c8a54430360b306` and its base `main` `65fc114a140d9043f8e3d70ffb863f7987816d8f`, each in a clean worktree. - `cargo test --workspace --no-fail-fast -- --test-threads=4` (debug) on `889008f`: **1283 passed, 1 failed, 46 ignored**. - The failure is `gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1` (seed 540: `res[833] = 0x7, CPU 0x6`). It fails the same way on the base `65fc114`, so it is not this PR. - In a first run without `--no-fail-fast`, `hle::d3d12x::list_x::tests::a_reset_while_the_last_submit_runs_records_on_another_pc_list` also failed once; alone it passed 3 / 3 on the head. Reads as the parallel flake of #1978. - SKIPPED (8 lines): six per-lane `f16` / `f32` cases of `lower_dxil::tests` (refused: `V_MUL_F16`, `V_PK_MUL_F16`, `V_CVT_F16_F32`), `pso_measurement_compiles_an_exact_synthetic_record` (Developer Mode off), `heap_window_out_of_memory_falls_back_to_the_switch_form` (no heap windows). - The new `vram::tests` all pass on this card, including `budgeted_bind_shares_pages_retains_cubemap_coarse_mips_and_survives_cap`, `capped_pages_keep_over_budget_placements_alive` and `target_pages_budget_respects_env_title_memory_uma_and_adapter_vram`. - Budget the head picks on this card (default `anaconda`, 13 824 MiB): `pool budget 8576 MiB, 134 pools from 75% of DXGI local budget`. - Title runs: the retail title 1.0.2.1, my own copy, unpacked, on an NVMe drive; release builds. **Regression run** `scripts/smoke.ps1`, 60 s, default settings, same binaries. The first base run was on a cold shader cache (870 frames); this is the warm pair, base run again after it: main: ``` xcl-smoke v1 commit: 65fc114a140d9043f8e3d70ffb863f7987816d8f gpu: AMD Radeon RX 6700 XT title: f651e787 seconds: 60 exit: 0x0 frames shown: 1554 (PresentX 1554) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 13829 MB ``` PR: ``` xcl-smoke v1 commit: 889008fd342ac779a601d7f93c8a54430360b306 gpu: AMD Radeon RX 6700 XT title: f651e787 seconds: 60 exit: 0x0 frames shown: 1562 (PresentX 1562) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 13834 MB ``` **Title A/B on the head, cap on (default) vs `XCL_TARGET_PAGES_MB=0`** - Same binary, one run each, back to back, warm caches. `XCL_NETWORK=0 XCL_DIRECT_DXIL=1 XCL_HEAP_WINDOWS=1 XCL_PSO_PRELOAD=0 XCL_DXC_THREADS=4 XCL_SPLIT_MIDLIST_WAIT=0 XCL_TEXTURE_LEVEL_PAGES=1 XCL_ACTIVITY=1`, `XCL_PRESS_AT=16:A`, `XCL_PRESS_A_AT=20,24,…,80,90,100`. A local watchdog stops the title when free physical RAM stays under 500 MB for 3 s (16 GB host). - Both reached the loading of the world and were stopped by that watchdog before it presented: | | cap on | cap off | |---|---|---| | stopped at | 83 s | 87 s | | process commit (last `memory:` line) | 18 397 MB | 18 767 MB | | target pages (pools) | 4 348 MB (4 544 MB) | 4 309 MB (4 544 MB) | | video memory local / non-local | 7 898 / 4 554 MB | 7 897 / 4 556 MB | | `level pages` at ~60 s | 2 418 MB placed, 940 MB backed | 2 412 MB placed, 932 MB backed | | frames by 63 s | 1 500 | 1 500 | - So on a 12 GB card with 16 GB of host RAM, the pools stay at about half of the 8 576 MiB cap when host RAM runs out; the cap does not engage and the two arms match. No device removal, no crash, no failed placement in either. **Not tested** - A run that reaches the cap: this host runs out of RAM at ~4.5 GB of pools. An 8 GB card, or this card with more host RAM, would be needed to see the capped path in the title. - The world itself, and whether textures under the cap look right. - NVIDIA / Intel, Linux / Wine, other titles. **AI use** - Claude Code (Claude Opus 5.5) built the trees, ran the suite, the smoke pair and the title runs on the machine above, and wrote this report; I checked it before posting.
Author
Owner

@⁠pane33 on GitHub · 2026-11-25 17:22 UTC · original

I tested 889008fd342ac779a601d7f93c8a54430360b306 on Windows 11 with a native RTX 4060 (tiled resources Tier 4). The VRAM filter returned 21 passed, 0 failed, 1 ignored and no skips, including two local test-only probes. The probes used one- and two-heap caps.

  • Eager remap: At a one-heap cap, four-tile RGBA8 resources read back the uploaded pattern on 4/4, 2/4 and 0/4 tiles, respectively. Unmapped bytes read as zero as intended. After 1,018 tiles became free, remap_if_unmapped returned true for the partial and empty resources, which remained at 2/4 and 0/4. Explicitly unmapping the empty resource let it remap to 4/4 and read back a fresh upload in full. The target starts mapped = true at vram.rs:1338 and remap returns early at :1398. Is incomplete eager backing expected to persist until explicit unmap or replacement?
  • Cap accounting: With a two-heap cap and a blocked retire fence (0/1), a replacement allocation left two active heaps plus one held for retirement (192 MiB of heap capacity). The pool counter reported 128 MiB. The retiring count returned to zero after the fence completed. At vram.rs:967 the cap checks the active count. Is the intended bound active heap capacity, or should it also cover heaps held for retirement?

No retail run. AI use — Codex added the two local test probes, ran the tests, analyzed the results, and assisted in drafting this report.

**@⁠pane33** on GitHub · 2026-11-25 17:22 UTC · [original](https://github.com/xcl-dev/xcl/pull/2357#issuecomment-7169400649) I tested `889008fd342ac779a601d7f93c8a54430360b306` on Windows 11 with a native RTX 4060 (tiled resources Tier 4). The VRAM filter returned 21 passed, 0 failed, 1 ignored and no skips, including two local test-only probes. The probes used one- and two-heap caps. - **Eager remap:** At a one-heap cap, four-tile RGBA8 resources read back the uploaded pattern on 4/4, 2/4 and 0/4 tiles, respectively. Unmapped bytes read as zero as intended. After 1,018 tiles became free, `remap_if_unmapped` returned `true` for the partial and empty resources, which remained at 2/4 and 0/4. Explicitly unmapping the empty resource let it remap to 4/4 and read back a fresh upload in full. The target starts `mapped = true` at `vram.rs:1338` and remap returns early at `:1398`. Is incomplete eager backing expected to persist until explicit unmap or replacement? - **Cap accounting:** With a two-heap cap and a blocked retire fence (0/1), a replacement allocation left two active heaps plus one held for retirement (192 MiB of heap capacity). The pool counter reported 128 MiB. The retiring count returned to zero after the fence completed. At `vram.rs:967` the cap checks the active count. Is the intended bound active heap capacity, or should it also cover heaps held for retirement? No retail run. **AI use** — Codex added the two local test probes, ran the tests, analyzed the results, and assisted in drafting this report.
Author
Owner

@⁠ozimchuk on GitHub · 2026-11-25 17:57 UTC · original

A test where the cap engages on the retail title: on NVIDIA under Linux, one of the two runs with this PR ended in a GPU page fault from the copy engine, and the other had fewer frames and about half the draws of the two runs without it.

Tested

  • NVIDIA (32-lane waves), 16 GB; Linux, Wine 11.21 + vkd3d-proton (dxil-spirv 694cc67); release build for x86_64-pc-windows-gnu.
  • Not main alone: this PR's 889008f merged without conflicts into my working tree (main 68a284a + other open PRs + local changes); the same tree without it as the comparison.
  • The retail title in Series S mode (XCL_DEVICE_TYPE=lockhart: title memory budget 8 192 MB, so the cap here is 8 192 MB), XCL_PSO_WAIT_MS=50, 300 s each, the same data folder, runs alternated (with, without, without, with).
run this PR texture pools (end) ended
1 yes 8 192 MB (capped), 8 190 used 300 s, no crash
2 no 8 832 MB, 8 670 used 300 s, no crash
3 no 8 832 MB, 8 689 used 300 s, no crash
4 yes 8 192 MB (capped), 7 366 used Xid 31 at ~154 s, then D3D12 device removed: 0x887a0005

Run 4's kernel line: NVRM: Xid (PCI:0000:01:00): 31, … MMU Fault: ENGINE CE7 HUBCLIENT_CE1 faulted @ 0x2_8fcec000. Fault is of type FAULT_PTE ACCESS_TYPE_VIRT_READ – a copy-engine read of an unmapped page. That fits tiles this PR leaves NULL at the cap being read by a copy; on this driver path a NULL tile does not seem to read as zero. It is one fault in two runs, so not proven.

After the world load (runs 1–3): 1.45 presents/s, 234 draws/s with the cap; 1.65–1.73 presents/s, 561–574 draws/s without. Peak GPU memory 15.3 GB with the cap against 15.8 GB (full) without; system memory and swap about the same. The frames I dumped are loading screens in all four runs and look the same.

Not tested: Windows; Series X mode (there the cap would be ~12 GB here, above the ~10.5 GB the pools reach, so it would not engage); the test suite on this tree with the PR; whether the copy that faulted is an upload, a readback or a title copy.

AI-assisted. Claude Code, Claude Opus 5.5 made the runs and wrote this comment.

**@⁠ozimchuk** on GitHub · 2026-11-25 17:57 UTC · [original](https://github.com/xcl-dev/xcl/pull/2357#issuecomment-7170231115) A test where the cap engages on the retail title: on NVIDIA under Linux, one of the two runs with this PR ended in a GPU page fault from the copy engine, and the other had fewer frames and about half the draws of the two runs without it. **Tested** - NVIDIA (32-lane waves), 16 GB; Linux, Wine 11.21 + vkd3d-proton (dxil-spirv `694cc67`); release build for `x86_64-pc-windows-gnu`. - Not `main` alone: this PR's `889008f` merged without conflicts into my working tree (`main` `68a284a` + other open PRs + local changes); the same tree without it as the comparison. - The retail title in Series S mode (`XCL_DEVICE_TYPE=lockhart`: title memory budget 8 192 MB, so the cap here is 8 192 MB), `XCL_PSO_WAIT_MS=50`, 300 s each, the same data folder, runs alternated (with, without, without, with). | run | this PR | texture pools (end) | ended | |---|---|---|---| | 1 | yes | 8 192 MB (capped), 8 190 used | 300 s, no crash | | 2 | no | 8 832 MB, 8 670 used | 300 s, no crash | | 3 | no | 8 832 MB, 8 689 used | 300 s, no crash | | 4 | yes | 8 192 MB (capped), 7 366 used | **Xid 31 at ~154 s, then `D3D12 device removed: 0x887a0005`** | Run 4's kernel line: `NVRM: Xid (PCI:0000:01:00): 31, … MMU Fault: ENGINE CE7 HUBCLIENT_CE1 faulted @ 0x2_8fcec000. Fault is of type FAULT_PTE ACCESS_TYPE_VIRT_READ` – a copy-engine read of an unmapped page. That fits tiles this PR leaves `NULL` at the cap being read by a copy; on this driver path a NULL tile does not seem to read as zero. It is one fault in two runs, so not proven. After the world load (runs 1–3): 1.45 presents/s, 234 draws/s with the cap; 1.65–1.73 presents/s, 561–574 draws/s without. Peak GPU memory 15.3 GB with the cap against 15.8 GB (full) without; system memory and swap about the same. The frames I dumped are loading screens in all four runs and look the same. **Not tested**: Windows; Series X mode (there the cap would be ~12 GB here, above the ~10.5 GB the pools reach, so it would not engage); the test suite on this tree with the PR; whether the copy that faulted is an upload, a readback or a title copy. AI-assisted. Claude Code, Claude Opus 5.5 made the runs and wrote this comment.
Author
Owner

@⁠raylitebull on GitHub · 2026-11-25 18:28 UTC · original

Diff review on 889008f (crates/xcl/src/hle/d3d12x/vram.rs): clean budget computation (compute_max_pools) and unit coverage (bind_tiles, capped_pages_keep_over_budget_placements_alive).

Remaining before merge:

  1. Rebase onto origin/main (currently DIRTY).
  2. Address @pane33's questions (mapped = true preventing remap_if_unmapped on partially backed eager resources, and whether active-only vs retiring heap counts should bound the cap) and check @ozimchuk's Wine/NVIDIA CE Xid 31 fault report on NULL tiles under the cap.
**@⁠raylitebull** on GitHub · 2026-11-25 18:28 UTC · [original](https://github.com/xcl-dev/xcl/pull/2357#issuecomment-7170963742) Diff review on `889008f` (`crates/xcl/src/hle/d3d12x/vram.rs`): clean budget computation (`compute_max_pools`) and unit coverage (`bind_tiles`, `capped_pages_keep_over_budget_placements_alive`). **Remaining before merge:** 1. Rebase onto `origin/main` (currently `DIRTY`). 2. Address `@pane33`'s questions (`mapped = true` preventing `remap_if_unmapped` on partially backed eager resources, and whether active-only vs retiring heap counts should bound the cap) and check `@ozimchuk`'s Wine/NVIDIA CE `Xid 31` fault report on NULL tiles under the cap.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-25 18:37 UTC · original

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.)

Thanks!

**@⁠DavidM1911** on GitHub · 2026-11-25 18:37 UTC · [original](https://github.com/xcl-dev/xcl/pull/2357#issuecomment-7171167720) Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.) Thanks!
Author
Owner

@⁠jennydeth on GitHub · 2026-11-25 19:00 UTC · original

NVIDIA RTX 3060 12 GB (the #646 card), retail title 1.0.2.1 into its story load: the cap holds – pools stop at 8 448 MB and target pages at 8 404 MB, against 9 984 / 9 644 MB on the base, and local video memory ends 1.46 GB lower. No 0x8007000E, no crash, no device removal. Neither arm reaches the world in 600 s: both stop presenting during the load and spend the rest of the run compiling pipelines, as on main in #846. The lower peak commit (31.7 vs 34.8 GB) is not evidence for the cap: see below. One run per arm.

Setup: NVIDIA GeForce RTX 3060 12 GB, driver 32.0.16.2101 (wave32), Ryzen 5 5600X, 32 GB RAM, Windows 11 Pro 10.0.26300.9974, Rust 1.100.0, release builds, DXC 1.9.2609.5. Head 889008f against its base 65fc114, both as they are. Default settings (no XCL_TARGET_PAGES_MB), XCL_NETWORK=0, XCL_FRAME_DUMP=300, scripts/smoke.ps1 -Seconds 600 (from main, the same script for both), profile already past the first-run flow, A presses on the schedule from my #846 comment. Base first, then head, back to back; driver-blob cache warm from earlier runs.

Head's startup line: textures in title memory: tiled resources on 64 KiB pages of video memory, one per page of the title's (pool budget 8448 MiB, 132 pools from 75% of DXGI local budget) – so the DXGI local budget here is ~11.3 GB.

Regression run

Base 65fc114:

xcl-smoke v1
commit: 65fc114a140d9043f8e3d70ffb863f7987816d8f
gpu: NVIDIA GeForce RTX 3060
title: 4a4b54dc
seconds: 600
exit: 0x0
frames shown: 2110 (PresentX 2110)
presents per 2 s (last 3): 0 0 0
device removals: 0
crashes: 0
peak commit: 34846 MB

Head 889008f:

xcl-smoke v1
commit: 889008fd342ac779a601d7f93c8a54430360b306
gpu: NVIDIA GeForce RTX 3060
title: 4a4b54dc
seconds: 600
exit: 0x0
frames shown: 2271 (PresentX 2271)
presents per 2 s (last 3): 0 0 0
device removals: 0
crashes: 0
peak commit: 31725 MB

Head 108 % of base frames, 91 % of its peak commit.

base 65fc114 head 889008f
target pages (pools) at 60 s, menus 4 551 (4 608) MB 4 549 (4 608) MB
target pages (pools) at 90 s 8 303 (8 832) MB 8 217 (8 448) MB
target pages (pools), final 9 644 (9 984) MB from 120 s 8 404 (8 448) MB from 105 s; pools at 8 448 from 86.7 s
local / non-local video memory, final 13 977 / 4 728 MB 12 516 / 4 720 MB
sparse pools, final 2 048 MB 2 112 MB
commit, menus (44–70 s average) 16 655 MB 19 704 MB
peak commit 34 846 MB (at 504 s; 29 251 MB at 543 s) 31 725 MB (at 439 s)
target-page pool cap reached – #1 at 87.0 s, #8192 at 100.2 s (#512 within 0.1 s of #1); no #16384 line
0x8007000E / out of memory 0 0
last present-bearing 2 s window 120 s 105 s
whole run: submits / draws / dispatches 10 476 / 19 027 / 11 057 11 303 / 19 924 / 11 068
driver compiles started / finished 62 / 60 100 / 98
AS slot – refused / would close a GPU cycle / wanted at once 40 / 0 / 0 40 / 0 / 0
DirectStorage failed requests (activity lines; request failed warnings) 387 (2) 99 (1)
world reached no no
  • The cap holds: the pools reach 8 448 MB (132 × 64 MiB) at 86.7 s and never grow or shrink after that (no reclaimed lines in either log). Target pages fill the free tiles inside them up to 8 404 MB by 104.7 s and stay there; the base goes on to 9 644 MB in 9 984 MB of pools. Local video memory ends 1.46 GB lower (12.5 vs 14.0 GB), matching the 1.5 GB fewer pools, but that is still ~1.2 GB over the ~11.3 GB DXGI local budget the cap is computed from: ~4.1 GB of local video memory outside the pool heaps keeps it oversubscribed.
  • Commit is not evidence either way: the head's commit is ~3 GB above the base's in the menus with identical target pages (19.7 vs 16.7 GB) and still higher at 120 s (29.2 vs 28.5 GB). The whole peak gap comes from a late, transient climb in the base (34.8 GB at 504 s, back to 29.3 GB at 543 s) while both arms' target pages are flat. Commit swings by ~3 GB within either run, so with one run per arm I can't credit any of the 3.1 GB to the cap.
  • What happens past the cap: reading the head's vram.rs, a bind past the cap gets whatever free tiles remain – for mipmapped textures the coarsest mips of each slice first – and the rest stay NULL (reads zero, writes dropped). In the default mode they are not retried for that placement; only XCL_TEXTURE_LEVEL_PAGES=1 retries level groups. The warning counts bind calls that came up short (new placements and re-binds of superseded textures) and logs at #1–4 and powers of two: it reached #8192 at 100.2 s and never #16384, so 8 192–16 383 such calls in the run; after 100.2 s the log can't say whether they continued. Whether that changes the picture I can't tell: neither arm shows the world.
  • GPU work is about the same: over the whole run the arms issue nearly the same work (11 057 vs 11 068 dispatches). The head's load just ends ~15 s earlier – last present at 105 vs 120 s, and its ~7.5k-dispatch burst at 105 s matches the base's ~6.8k burst at 154 s. After their last presents both are close to idle while driver compiles go on. Nothing here ties the NULL tiles to a stall.

Tested

  • The runs above. I did not run the unit / GPU suite on this branch.

Not tested

  • A second run per arm; the world itself (neither arm reaches it here), so the picture with the cap; XCL_TARGET_PAGES_MB overrides; XCL_TEXTURE_LEVEL_PAGES=1; the branch rebased onto current main; AMD.

AI use

  • Claude Code (Claude Opus 5.5) built both commits, ran the title on my machine, read the logs and the PR's code, and wrote this comment; two further Claude Opus 5.5 agents fact-checked the numbers and the reading of the code against the logs before posting.
**@⁠jennydeth** on GitHub · 2026-11-25 19:00 UTC · [original](https://github.com/xcl-dev/xcl/pull/2357#issuecomment-7171704280) **NVIDIA RTX 3060 12 GB (the #646 card), retail title 1.0.2.1 into its story load: the cap holds – pools stop at 8 448 MB and target pages at 8 404 MB, against 9 984 / 9 644 MB on the base, and local video memory ends 1.46 GB lower. No `0x8007000E`, no crash, no device removal. Neither arm reaches the world in 600 s: both stop presenting during the load and spend the rest of the run compiling pipelines, as on `main` in #846. The lower peak commit (31.7 vs 34.8 GB) is not evidence for the cap: see below.** One run per arm. **Setup:** NVIDIA GeForce RTX 3060 12 GB, driver 32.0.16.2101 (wave32), Ryzen 5 5600X, 32 GB RAM, Windows 11 Pro 10.0.26300.9974, Rust 1.100.0, release builds, DXC 1.9.2609.5. Head `889008f` against its base `65fc114`, both as they are. Default settings (no `XCL_TARGET_PAGES_MB`), `XCL_NETWORK=0`, `XCL_FRAME_DUMP=300`, `scripts/smoke.ps1 -Seconds 600` (from `main`, the same script for both), profile already past the first-run flow, A presses on the schedule from my #846 comment. Base first, then head, back to back; driver-blob cache warm from earlier runs. Head's startup line: `textures in title memory: tiled resources on 64 KiB pages of video memory, one per page of the title's (pool budget 8448 MiB, 132 pools from 75% of DXGI local budget)` – so the DXGI local budget here is ~11.3 GB. **Regression run** Base `65fc114`: ``` xcl-smoke v1 commit: 65fc114a140d9043f8e3d70ffb863f7987816d8f gpu: NVIDIA GeForce RTX 3060 title: 4a4b54dc seconds: 600 exit: 0x0 frames shown: 2110 (PresentX 2110) presents per 2 s (last 3): 0 0 0 device removals: 0 crashes: 0 peak commit: 34846 MB ``` Head `889008f`: ``` xcl-smoke v1 commit: 889008fd342ac779a601d7f93c8a54430360b306 gpu: NVIDIA GeForce RTX 3060 title: 4a4b54dc seconds: 600 exit: 0x0 frames shown: 2271 (PresentX 2271) presents per 2 s (last 3): 0 0 0 device removals: 0 crashes: 0 peak commit: 31725 MB ``` Head 108 % of base frames, 91 % of its peak commit. | | base `65fc114` | head `889008f` | |---|---|---| | target pages (pools) at 60 s, menus | 4 551 (4 608) MB | 4 549 (4 608) MB | | target pages (pools) at 90 s | 8 303 (8 832) MB | 8 217 (8 448) MB | | target pages (pools), final | 9 644 (9 984) MB from 120 s | **8 404 (8 448) MB** from 105 s; pools at 8 448 from 86.7 s | | local / non-local video memory, final | 13 977 / 4 728 MB | 12 516 / 4 720 MB | | sparse pools, final | 2 048 MB | 2 112 MB | | commit, menus (44–70 s average) | 16 655 MB | 19 704 MB | | peak commit | 34 846 MB (at 504 s; 29 251 MB at 543 s) | 31 725 MB (at 439 s) | | `target-page pool cap reached` | – | #1 at 87.0 s, #8192 at 100.2 s (#512 within 0.1 s of #1); no #16384 line | | `0x8007000E` / out of memory | 0 | 0 | | last present-bearing 2 s window | 120 s | 105 s | | whole run: submits / draws / dispatches | 10 476 / 19 027 / 11 057 | 11 303 / 19 924 / 11 068 | | driver compiles started / finished | 62 / 60 | 100 / 98 | | `AS slot – refused` / `would close a GPU cycle` / `wanted at once` | 40 / 0 / 0 | 40 / 0 / 0 | | DirectStorage failed requests (activity lines; `request failed` warnings) | 387 (2) | 99 (1) | | world reached | no | no | - **The cap holds:** the pools reach 8 448 MB (132 × 64 MiB) at 86.7 s and never grow or shrink after that (no `reclaimed` lines in either log). Target pages fill the free tiles inside them up to 8 404 MB by 104.7 s and stay there; the base goes on to 9 644 MB in 9 984 MB of pools. Local video memory ends 1.46 GB lower (12.5 vs 14.0 GB), matching the 1.5 GB fewer pools, but that is still ~1.2 GB over the ~11.3 GB DXGI local budget the cap is computed from: ~4.1 GB of local video memory outside the pool heaps keeps it oversubscribed. - **Commit is not evidence either way:** the head's commit is ~3 GB *above* the base's in the menus with identical target pages (19.7 vs 16.7 GB) and still higher at 120 s (29.2 vs 28.5 GB). The whole peak gap comes from a late, transient climb in the base (34.8 GB at 504 s, back to 29.3 GB at 543 s) while both arms' target pages are flat. Commit swings by ~3 GB within either run, so with one run per arm I can't credit any of the 3.1 GB to the cap. - **What happens past the cap:** reading the head's `vram.rs`, a bind past the cap gets whatever free tiles remain – for mipmapped textures the coarsest mips of each slice first – and the rest stay `NULL` (reads zero, writes dropped). In the default mode they are not retried for that placement; only `XCL_TEXTURE_LEVEL_PAGES=1` retries level groups. The warning counts bind calls that came up short (new placements and re-binds of superseded textures) and logs at #1–4 and powers of two: it reached #8192 at 100.2 s and never #16384, so 8 192–16 383 such calls in the run; after 100.2 s the log can't say whether they continued. Whether that changes the picture I can't tell: neither arm shows the world. - **GPU work is about the same:** over the whole run the arms issue nearly the same work (11 057 vs 11 068 dispatches). The head's load just ends ~15 s earlier – last present at 105 vs 120 s, and its ~7.5k-dispatch burst at 105 s matches the base's ~6.8k burst at 154 s. After their last presents both are close to idle while driver compiles go on. Nothing here ties the `NULL` tiles to a stall. **Tested** - The runs above. I did not run the unit / GPU suite on this branch. **Not tested** - A second run per arm; the world itself (neither arm reaches it here), so the picture with the cap; `XCL_TARGET_PAGES_MB` overrides; `XCL_TEXTURE_LEVEL_PAGES=1`; the branch rebased onto current `main`; AMD. **AI use** - Claude Code (Claude Opus 5.5) built both commits, ran the title on my machine, read the logs and the PR's code, and wrote this comment; two further Claude Opus 5.5 agents fact-checked the numbers and the reading of the code against the logs before posting.
Author
Owner

@⁠SlopTart on GitHub · 2026-11-25 19:06 UTC · original

Tested: current PR head merged onto current origin/main (clean), Linux (Arch, kernel 7.2.15), Mesa 26.2.5 RADV, Radeon RX 7900 XT (NAVI31), cargo target x86_64-pc-windows-gnu run under wine-11.0 (Proton), rustc 1.94.0, vkd3d-proton 3.1 with the XCL patch, official MS DXC (binaries 2026-09-29).
suite: 145/3 = the three known baseline failures on this lane (fuzz_validate_and_gpu_2 seed 1003, gpu_nonfused_mad_and_mac_prevent_fma_contraction, gpu_depth_buffer_created_for_unordered_access_is_placed). Targeted run of the four new tile-budget tests: 4 passed.

Not tested: retail titles (no title data on this lane, counts only).

AI use: Hermes agent (local Qwen-class) ran both machines and drafted this; I checked it before posting.

**@⁠SlopTart** on GitHub · 2026-11-25 19:06 UTC · [original](https://github.com/xcl-dev/xcl/pull/2357#issuecomment-7171818602) **Tested**: current PR head merged onto current `origin/main` (clean), Linux (Arch, kernel 7.2.15), Mesa 26.2.5 RADV, Radeon RX 7900 XT (NAVI31), cargo target `x86_64-pc-windows-gnu` run under wine-11.0 (Proton), rustc 1.94.0, vkd3d-proton 3.1 with the XCL patch, official MS DXC (binaries 2026-09-29). suite: 145/3 = the three known baseline failures on this lane (`fuzz_validate_and_gpu_2` seed 1003, `gpu_nonfused_mad_and_mac_prevent_fma_contraction`, `gpu_depth_buffer_created_for_unordered_access_is_placed`). Targeted run of the four new tile-budget tests: 4 passed. **Not tested**: retail titles (no title data on this lane, counts only). **AI use**: Hermes agent (local Qwen-class) ran both machines and drafted this; I checked it before posting.
Author
Owner

@⁠Berserker64 on GitHub · 2026-11-25 21:57 UTC · original

RTX 3080 10 GB: with this PR the retail title no longer loses its device at world load. 6 of 6 runs reached 100 s against 0 of 6 without it.

Setup

  • NVIDIA GeForce RTX 3080 10 GB, driver 621.24 (32.0.16.2124), AMD Ryzen 9 5950X, 32 GB RAM, Windows 10 Pro 19045, release build.
  • Base: 65fc114 + #684. Head: 889008f + #684. #684 (e56dbc3) applied cleanly to both, so this PR is the only difference.
  • Retail title 1.0.2.1, Series X mode, warm caches. Each run: xcl run, XCL_RUN_SECONDS=100 XCL_ACTIVITY=1 XCL_DRED=1 XCL_FRAME_DUMP=200 XCL_PRESS_A_AT=21,62,66,70,75,90,105,120,140,180,240. Base and head alternate run by run.

Results

runs ended peak local video memory
base + #684 6 all at 58–70 s: 5 × 0x887a0007, 1 × 0x887a0006 10.3–12.8 GB
head + #684 6 all 6 at the 100 s limit (about 1,540 frames each) 10.8 GB, flat

One longer run of head + #684 with no XCL_RUN_SECONDS (stopped at 900 s): no removal and no crash in 15 minutes, local video memory steady at 10.8 GB. It presented for the first 78 s (loading art) and then waited on cold NVIDIA compute-pipeline compiles for the rest of the run (100 of 103 finished, up to 280 s each), so it did not reach the world.

Without #684, head got past the removal but every run (7 of 7) then crashed at 74–80 s in VCRUNTIME140.dll+0x122b3 (memcpy from game_scarlett_master.exe+0x979f5b, a write into title memory), the crash in #646. The two base runs that weren't removed first crashed the same way. So on this card the two PRs go together.

Why the removal is out of memory
The 0x887a0007 removals on this card are the kernel refusing a submission: D3D12Core's NDXGI::CDevice::RemoveDevice is entered from SubmitCommandCB (called from list_x::execute_with_waits_on), with D3DKMTGetDeviceState reporting D3DKMT_DEVICEEXECUTION_ERROR_OUTOFMEMORY (5). D3D12Core reports state 5 as 0x887a0007 and writes no DRED data for it, which is why DRED was always empty. A read-only Frida probe saw state 5 in all 6 removals it caught, on an older tree (c4d37be plus open PRs); no runtime configuration change removed the device. There's no TDR event in the System log at these removals.

Not tested

  • The world itself: the long run stalled on compiles before it, so nothing past world load is covered.
  • cargo test; other cards; AMD.

AI use: Claude Code (Claude Opus 5.5) made the builds, ran the runs and the probe on the hardware above, and wrote this.

**@⁠Berserker64** on GitHub · 2026-11-25 21:57 UTC · [original](https://github.com/xcl-dev/xcl/pull/2357#issuecomment-7175752244) **RTX 3080 10 GB: with this PR the retail title no longer loses its device at world load. 6 of 6 runs reached 100 s against 0 of 6 without it.** **Setup** - NVIDIA GeForce RTX 3080 10 GB, driver 621.24 (32.0.16.2124), AMD Ryzen 9 5950X, 32 GB RAM, Windows 10 Pro 19045, release build. - Base: `65fc114` + #684. Head: `889008f` + #684. #684 (`e56dbc3`) applied cleanly to both, so this PR is the only difference. - Retail title 1.0.2.1, Series X mode, warm caches. Each run: `xcl run`, `XCL_RUN_SECONDS=100 XCL_ACTIVITY=1 XCL_DRED=1 XCL_FRAME_DUMP=200 XCL_PRESS_A_AT=21,62,66,70,75,90,105,120,140,180,240`. Base and head alternate run by run. **Results** | | runs | ended | peak local video memory | |---|---|---|---| | base + #684 | 6 | all at 58–70 s: 5 × `0x887a0007`, 1 × `0x887a0006` | 10.3–12.8 GB | | head + #684 | 6 | all 6 at the 100 s limit (about 1,540 frames each) | 10.8 GB, flat | One longer run of head + #684 with no `XCL_RUN_SECONDS` (stopped at 900 s): no removal and no crash in 15 minutes, local video memory steady at 10.8 GB. It presented for the first 78 s (loading art) and then waited on cold NVIDIA compute-pipeline compiles for the rest of the run (100 of 103 finished, up to 280 s each), so it did not reach the world. Without #684, head got past the removal but every run (7 of 7) then crashed at 74–80 s in `VCRUNTIME140.dll+0x122b3` (`memcpy` from `game_scarlett_master.exe+0x979f5b`, a write into title memory), the crash in #646. The two base runs that weren't removed first crashed the same way. So on this card the two PRs go together. **Why the removal is out of memory** The `0x887a0007` removals on this card are the kernel refusing a submission: D3D12Core's `NDXGI::CDevice::RemoveDevice` is entered from `SubmitCommandCB` (called from `list_x::execute_with_waits_on`), with `D3DKMTGetDeviceState` reporting `D3DKMT_DEVICEEXECUTION_ERROR_OUTOFMEMORY` (5). D3D12Core reports state 5 as `0x887a0007` and writes no DRED data for it, which is why DRED was always empty. A read-only Frida probe saw state 5 in all 6 removals it caught, on an older tree (`c4d37be` plus open PRs); no runtime configuration change removed the device. There's no TDR event in the System log at these removals. **Not tested** - The world itself: the long run stalled on compiles before it, so nothing past world load is covered. - `cargo test`; other cards; AMD. AI use: Claude Code (Claude Opus 5.5) made the builds, ran the runs and the probe on the hardware above, and wrote this.
Author
Owner

@⁠bmjask on GitHub · 2026-11-25 20:23 UTC · original · reviewed

P2: VRAM cap accounting excludes fence-retiring heaps. The cap checks active pools.len() (vram.rs:967/bind allocation), but sweep_and_reclaim removes empty pools from active state before queuing their heaps in retiring until both fences complete. New allocations then see a free cap slot; repeated reclaim/allocate while fences lag can exceed the configured cap by all retired heaps. Count active plus retiring residency, or retain cap capacity until retirement completes, with a blocked-retire-fence test. P2: eager partial binds still set Target.mapped=true when cap pressure leaves some tiles NULL. remap_if_unmapped then returns immediately, so later freed tiles never fill those eager missing pages. Track missing tiles/retry them, or leave partial targets unmapped; add a recovery-after-budget-frees test.

**@⁠bmjask** on GitHub · 2026-11-25 20:23 UTC · [original](https://github.com/xcl-dev/xcl/pull/2357#pullrequestreview-6064422819) · **reviewed** P2: VRAM cap accounting excludes fence-retiring heaps. The cap checks active pools.len() (vram.rs:967/bind allocation), but sweep_and_reclaim removes empty pools from active state before queuing their heaps in retiring until both fences complete. New allocations then see a free cap slot; repeated reclaim/allocate while fences lag can exceed the configured cap by all retired heaps. Count active plus retiring residency, or retain cap capacity until retirement completes, with a blocked-retire-fence test. P2: eager partial binds still set Target.mapped=true when cap pressure leaves some tiles NULL. remap_if_unmapped then returns immediately, so later freed tiles never fill those eager missing pages. Track missing tiles/retry them, or leave partial targets unmapped; add a recovery-after-budget-frees test.
Author
Owner

@⁠Anon64 on GitHub · 2026-11-26 08:53 UTC · original

Tested on an RTX 3060 12 GB with 32 GB of RAM in a retail world load (the case "Not tested" asks for): the cap holds, but on a 12 GB card 75 % of the budget still leaves the process about 3 GB over it.

Setup: RTX 3060 12 GB, NVIDIA 581.80, i9-14900KF, 32 GB RAM, Windows 11 26200, release build. The PR's head 889008f merged locally onto nvidia-dev af2cecc4, not onto main. One conflict in vram.rs: I kept nvidia-dev's comment on pools and the PR's max_pools / oom_until, and left out the PR's retire_fence, which nvidia-dev no longer has. So this is not the exact head. All runs: XCL_ADAPTER=3060 XCL_GFX_PSO_WAIT_MS=200 XCL_PREPARE=0 XCL_ACTIVITY=1, compute pipelines warmed first, one run each, same title and start.

Video memory from the 2 s memory: line (MB):

build pool budget line pools at most local at most DXGI budget then over the budget warnings
nvidia-dev af2cecc4 (none) 10,368 15,031 10,931 27, from 60 s on
+ #2357, defaults pool budget 8448 MiB, 132 pools from 75% of DXGI local budget 8,448 13,797 10,844 23, from 64 s on
+ #2357, XCL_TARGET_PAGES_MB=4096 pool budget 4096 MiB, 64 pools from XCL_TARGET_PAGES_MB 4,096 9,732 10,860 0
  • The cap works as described: pools stop at exactly 8,448 MB with the defaults and 4,096 MB with the switch, and CreatePlacedResourceX kept succeeding (no 0x8007000E, no device removal in any of the three).
  • The rest of local video memory besides the target pages is about 5.4 GB here (coherent window, sparse pools, two-pass buffers, pipelines). On a 12 GB card a cap of 75 % of the DXGI budget (8.4 GB) plus that is about 13.8 GB against a 10.8 GB budget. A cap that counts what the process already holds outside the pools, or a lower share, would keep it under. 4 GB did.
  • Without the cap (and on nvidia-dev c044dc6 before it) the same world load lost the device (0x887a0005) in 4 of 4 runs at 120–254 s with 14–17 GB local against a 10.9 GB budget (#2688).

How far each got. None of the three lost the device; all ended on the title's own watchdog when its submits stopped while pipelines were still being built, which is not this PR's code. The first XCL_TARGET_PAGES_MB=4096 run stopped at 106 s on a compute pipeline the warm-up had missed. After warming it, a second 4096 run went on to 298.9 s, the longest of any run on this card, and played the cutscene. Its submits stopped at 270 s, while graphics pipelines for a part of the world no run had reached were waiting 24–109 s each at the compile gate.

What the cap costs and what it does not cover, from that 298.9 s run:

  • The picture was mostly black, with lights and the horizon drawn. Tiles past the cap are left NULL and read as 0, so part of that is this PR's cap; the rest is graphics pipelines not built yet (81,530 queued, XCL_GFX_PSO_WAIT_MS=200). I have not separated the two.
  • Target pages stayed at 4,088–4,095 MB throughout, but local video memory still went from 7,540 MB at 60 s to 12,694 MB at 278 s, 1.95 GB over the budget at the end. The growth was in the sparse pools (1,792 MB at 60 s, 3,648 MB at 200 s, 4,352 MB at 298 s), which this PR does not bound.

Not tested: the PR's exact head or main; how the textures look with NULL tiles at the cap (no screenshots taken); more than one run per row; XCL_TEXTURE_LEVEL_PAGES=1; the suite on this merge.

AI use: Claude Code (Claude Opus 5.5) merged the branch locally, ran the runs on this machine and wrote this report.

**@⁠Anon64** on GitHub · 2026-11-26 08:53 UTC · [original](https://github.com/xcl-dev/xcl/pull/2357#issuecomment-7187140709) **Tested on an RTX 3060 12 GB with 32 GB of RAM in a retail world load (the case "Not tested" asks for): the cap holds, but on a 12 GB card 75 % of the budget still leaves the process about 3 GB over it.** **Setup:** RTX 3060 12 GB, NVIDIA 581.80, i9-14900KF, 32 GB RAM, Windows 11 26200, release build. The PR's head `889008f` merged locally onto `nvidia-dev` `af2cecc4`, not onto `main`. One conflict in `vram.rs`: I kept `nvidia-dev`'s comment on `pools` and the PR's `max_pools` / `oom_until`, and left out the PR's `retire_fence`, which `nvidia-dev` no longer has. So this is not the exact head. All runs: `XCL_ADAPTER=3060 XCL_GFX_PSO_WAIT_MS=200 XCL_PREPARE=0 XCL_ACTIVITY=1`, compute pipelines warmed first, one run each, same title and start. **Video memory from the 2 s `memory:` line (MB):** | build | pool budget line | pools at most | local at most | DXGI budget then | `over the budget` warnings | |---|---|---|---|---|---| | `nvidia-dev` `af2cecc4` | (none) | 10,368 | 15,031 | 10,931 | 27, from 60 s on | | + #2357, defaults | `pool budget 8448 MiB, 132 pools from 75% of DXGI local budget` | 8,448 | 13,797 | 10,844 | 23, from 64 s on | | + #2357, `XCL_TARGET_PAGES_MB=4096` | `pool budget 4096 MiB, 64 pools from XCL_TARGET_PAGES_MB` | 4,096 | 9,732 | 10,860 | 0 | - The cap works as described: pools stop at exactly 8,448 MB with the defaults and 4,096 MB with the switch, and `CreatePlacedResourceX` kept succeeding (no `0x8007000E`, no device removal in any of the three). - The rest of local video memory besides the target pages is about 5.4 GB here (coherent window, sparse pools, two-pass buffers, pipelines). On a 12 GB card a cap of 75 % of the DXGI budget (8.4 GB) plus that is about 13.8 GB against a 10.8 GB budget. A cap that counts what the process already holds outside the pools, or a lower share, would keep it under. 4 GB did. - Without the cap (and on `nvidia-dev` `c044dc6` before it) the same world load lost the device (`0x887a0005`) in 4 of 4 runs at 120–254 s with 14–17 GB local against a 10.9 GB budget (#2688). **How far each got.** None of the three lost the device; all ended on the title's own watchdog when its submits stopped while pipelines were still being built, which is not this PR's code. The first `XCL_TARGET_PAGES_MB=4096` run stopped at 106 s on a compute pipeline the warm-up had missed. After warming it, a second 4096 run went on to **298.9 s**, the longest of any run on this card, and played the cutscene. Its submits stopped at 270 s, while graphics pipelines for a part of the world no run had reached were waiting 24–109 s each at the compile gate. **What the cap costs and what it does not cover**, from that 298.9 s run: - The picture was mostly black, with lights and the horizon drawn. Tiles past the cap are left `NULL` and read as 0, so part of that is this PR's cap; the rest is graphics pipelines not built yet (81,530 queued, `XCL_GFX_PSO_WAIT_MS=200`). I have not separated the two. - Target pages stayed at 4,088–4,095 MB throughout, but local video memory still went from 7,540 MB at 60 s to 12,694 MB at 278 s, 1.95 GB over the budget at the end. The growth was in the sparse pools (1,792 MB at 60 s, 3,648 MB at 200 s, 4,352 MB at 298 s), which this PR does not bound. **Not tested:** the PR's exact head or `main`; how the textures look with `NULL` tiles at the cap (no screenshots taken); more than one run per row; `XCL_TEXTURE_LEVEL_PAGES=1`; the suite on this merge. AI use: Claude Code (Claude Opus 5.5) merged the branch locally, ran the runs on this machine and wrote this report.
github-bot force-pushed github-bot/gh-2357 from 889008fd34 to c6213b24fc 2026-11-26 14:05:25 +00:00 Compare
Author
Owner

@⁠safesearch77 on GitHub · 2026-11-26 14:06 UTC · original

Rebased onto b49be183 (#2275 integrated) as one squashed commit (c6213b24), addressing all review and hardware test findings:

  1. Active + retiring 64 MiB pool-heap cap accounting (@bmjask P2 #1, @pane33):

    • RetiringBatch now tracks pool_heaps: usize and RetireQueue maintains retiring_pools: usize (note_queued_pools / reap_completed), keeping 64 MiB Pages pool heaps separate from variable-sized Arenas heaps that share RetireQueue (before_execute passes reclaimed_pools; place passes 0 for Arenas).
    • alloc_budgeted_pool calls poll_retiring_pool_heaps(dev_key) first to reap fence-completed batches (dropping finished ID3D12Heaps outside RETIRE.lock()) and enforces pools.len().saturating_add(retiring) < max_pools. page_bytes() also includes retiring pool heaps.
    • Covered by retire_queue_pool_cap_counts_retiring_pools_ignores_arenas_and_polls_completion (CPU) and a blocked-gate-fence phase in capped_pages_keep_over_budget_placements_alive (GPU).
  2. Incomplete eager target tracking & backfill (@bmjask P2 #2, @pane33) + packed mip tails:

    • Target::is_complete() checks self.mapped && (self.levels.is_some() || self.used.len() + self.used_extra.len() >= self.total as usize) (Target.mapped stays true so unmap_superseded and forget_pages never leak Page::users refcounts on partial binds).
    • When !complete, remap_if_unmapped runs Pages::rebind, which sweeps idle pages first, preserves already-held tiles in place (users == 1), backfills missing slots once budget frees, and re-emits map only when backed > prev_backed. place_on_pages also reads D3D12_PACKED_MIP_INFO so bind_tiles backs packed mip tails (NumTilesForPackedMips, e.g. 6-tail or SINGLE_MIPTAIL_BIT cubemaps) before per-slice standard mips.
    • Covered by budgeted_bind_shares_pages_retains_cubemap_coarse_mips_and_recovers_after_free (CPU) and capped_pages_keep_over_budget_placements_alive (GPU).
  3. Linux / Wine + vkd3d-proton NVIDIA copy-engine Xid 31 fault (@ozimchuk):

    • In vkd3d-proton (libs/vkd3d/resource.c, d3d12_device_requires_explicit_sparse_init == false), CreateReservedResource does not emit an initial vkQueueBindSparse(..., memory = VK_NULL_HANDLE) over the resource's tiles; vkd3d-proton only binds VK_NULL_HANDLE when UpdateTileMappings explicitly passes D3D12_TILE_RANGE_FLAG_NULL. In 889008fd, Pages::map returned early on 0-tile binds and used FLAG_SKIP (plus trimmed trailing None spans) on partial binds. Pages::map and heap_ranges_trimmed now explicitly bind every unbacked span with D3D12_TILE_RANGE_FLAG_NULL on pass 0 (and issue UpdateTileMappings(..., pHeap = None, D3D12_TILE_RANGE_FLAG_NULL) + pages.fence Signal on 0-tile binds), alongside #2275 multi-queue retirement across copy/upload queues (which 68a284a lacked when Run 4 reclaimed ~826 MB of pools).
  4. nvidia-dev struct conflict & 12 GB budget note (@Anon64):

    • Placed max_pools and oom_until below pool: TilePool to avoid the Pages::pools hunk conflict on nvidia-dev. On 12 GB cards where non-Pages allocations take ~5 GB in heavy scenes, XCL_TARGET_PAGES_MB=4096 (or title_memory_mb = 4096) tightens the Pages cap while XCL_TARGET_PAGES_MB=0 leaves it uncapped.

Huge thanks to @Berserker64, @jennydeth, @Haxodius, @DavidM1911, @SlopTart, @pane33, @ozimchuk, @Anon64, and @raylitebull for the testing and reviews! Since c6213b24 is a new head SHA (authored on Linux), a fresh Windows cargo test --workspace -- --test-threads=4 + 60 s scripts/smoke.ps1 pair on c6213b24 is needed to turn PR description green.

AI use: Antigravity (Gemini 4 Carbon)

**@⁠safesearch77** on GitHub · 2026-11-26 14:06 UTC · [original](https://github.com/xcl-dev/xcl/pull/2357#issuecomment-7194294918) Rebased onto `b49be183` (`#2275` integrated) as one squashed commit (`c6213b24`), addressing all review and hardware test findings: 1. **Active + retiring 64 MiB pool-heap cap accounting (`@bmjask` P2 #1, `@pane33`):** - `RetiringBatch` now tracks `pool_heaps: usize` and `RetireQueue` maintains `retiring_pools: usize` (`note_queued_pools` / `reap_completed`), keeping 64 MiB `Pages` pool heaps separate from variable-sized `Arenas` heaps that share `RetireQueue` (`before_execute` passes `reclaimed_pools`; `place` passes `0` for `Arenas`). - `alloc_budgeted_pool` calls `poll_retiring_pool_heaps(dev_key)` first to reap fence-completed batches (dropping finished `ID3D12Heap`s outside `RETIRE.lock()`) and enforces `pools.len().saturating_add(retiring) < max_pools`. `page_bytes()` also includes retiring pool heaps. - Covered by `retire_queue_pool_cap_counts_retiring_pools_ignores_arenas_and_polls_completion` (CPU) and a blocked-`gate`-fence phase in `capped_pages_keep_over_budget_placements_alive` (GPU). 2. **Incomplete eager target tracking & backfill (`@bmjask` P2 #2, `@pane33`) + packed mip tails:** - `Target::is_complete()` checks `self.mapped && (self.levels.is_some() || self.used.len() + self.used_extra.len() >= self.total as usize)` (`Target.mapped` stays `true` so `unmap_superseded` and `forget_pages` never leak `Page::users` refcounts on partial binds). - When `!complete`, `remap_if_unmapped` runs `Pages::rebind`, which sweeps idle pages first, preserves already-held tiles in place (`users == 1`), backfills missing slots once budget frees, and re-emits `map` only when `backed > prev_backed`. `place_on_pages` also reads `D3D12_PACKED_MIP_INFO` so `bind_tiles` backs packed mip tails (`NumTilesForPackedMips`, e.g. 6-tail or `SINGLE_MIPTAIL_BIT` cubemaps) before per-slice standard mips. - Covered by `budgeted_bind_shares_pages_retains_cubemap_coarse_mips_and_recovers_after_free` (CPU) and `capped_pages_keep_over_budget_placements_alive` (GPU). 3. **Linux / Wine + `vkd3d-proton` NVIDIA copy-engine `Xid 31` fault (`@ozimchuk`):** - In `vkd3d-proton` (`libs/vkd3d/resource.c`, `d3d12_device_requires_explicit_sparse_init == false`), `CreateReservedResource` does not emit an initial `vkQueueBindSparse(..., memory = VK_NULL_HANDLE)` over the resource's tiles; `vkd3d-proton` only binds `VK_NULL_HANDLE` when `UpdateTileMappings` explicitly passes `D3D12_TILE_RANGE_FLAG_NULL`. In `889008fd`, `Pages::map` returned early on `0`-tile binds and used `FLAG_SKIP` (plus trimmed trailing `None` spans) on partial binds. `Pages::map` and `heap_ranges_trimmed` now explicitly bind every unbacked span with `D3D12_TILE_RANGE_FLAG_NULL` on pass 0 (and issue `UpdateTileMappings(..., pHeap = None, D3D12_TILE_RANGE_FLAG_NULL)` + `pages.fence` `Signal` on `0`-tile binds), alongside `#2275` multi-queue retirement across copy/upload queues (which `68a284a` lacked when Run 4 reclaimed ~826 MB of pools). 4. **`nvidia-dev` struct conflict & 12 GB budget note (`@Anon64`):** - Placed `max_pools` and `oom_until` below `pool: TilePool` to avoid the `Pages::pools` hunk conflict on `nvidia-dev`. On 12 GB cards where non-`Pages` allocations take ~5 GB in heavy scenes, `XCL_TARGET_PAGES_MB=4096` (or `title_memory_mb = 4096`) tightens the `Pages` cap while `XCL_TARGET_PAGES_MB=0` leaves it uncapped. Huge thanks to `@Berserker64`, `@jennydeth`, `@Haxodius`, `@DavidM1911`, `@SlopTart`, `@pane33`, `@ozimchuk`, `@Anon64`, and `@raylitebull` for the testing and reviews! Since `c6213b24` is a new head SHA (authored on Linux), a fresh Windows `cargo test --workspace -- --test-threads=4` + 60 s `scripts/smoke.ps1` pair on `c6213b24` is needed to turn `PR description` green. AI use: Antigravity (Gemini 4 Carbon)
Author
Owner

@⁠thehollowedone on GitHub · 2026-11-26 14:18 UTC · original

Windows/NVIDIA check of current head c6213b24, based on b49be18: cargo build --offline --locked --workspace passed; cargo test --offline --locked --workspace --no-fail-fast -- --test-threads=4 passed with 1,439 passed, 0 failed, 47 ignored across 37 test targets. There were 25 GPU SKIPPED notices (21 wave64, 3 refused per-lane forms, 1 heap-window case); I do not count those as coverage. Hardware: Windows 11 build 26300, RTX 3080 Ti / driver 621.35, Ryzen 7 9800X3D, rustc 1.99.1 MSVC, DXC 1.8.2502.11. This was a clean tracked tree at the exact head. I did not run the paired retail-title smoke, so this report does not establish merge readiness.

One remaining cap-accounting interleaving in the new revision: before_execute removes empty pool heaps from Pages::pools under PAGES.lock(), then releases that lock before retire_heaps_and_sweep() records them in RetireQueue::retiring_pools. A concurrent placement can enter alloc_budgeted_pool during that gap: the heap is in neither count, so it can allocate a replacement while the old heap is still live behind GPU fences. I traced this lock/order path in the source; I have not reproduced the scheduling window in a runtime test. A bounded fix is to reserve cap capacity for reclaimed pools before releasing PAGES.lock(), then transfer that reservation to the retirement batch (or release it if retirement is immediate). A concurrent reclaim/placement test with a blocked retirement fence would cover the gap.

AI use: Codex (GPT-6.2 Sol) inspected the revision, ran the tests, and drafted this report; I checked the review point against the code.

**@⁠thehollowedone** on GitHub · 2026-11-26 14:18 UTC · [original](https://github.com/xcl-dev/xcl/pull/2357#issuecomment-7194617610) Windows/NVIDIA check of current head [`c6213b24`](https://github.com/xcl-dev/xcl/commit/c6213b24fc993a4df783f7713342beaf19e60c9d), based on `b49be18`: `cargo build --offline --locked --workspace` passed; `cargo test --offline --locked --workspace --no-fail-fast -- --test-threads=4` passed with **1,439 passed, 0 failed, 47 ignored** across 37 test targets. There were 25 GPU `SKIPPED` notices (21 wave64, 3 refused per-lane forms, 1 heap-window case); I do not count those as coverage. Hardware: Windows 11 build 26300, RTX 3080 Ti / driver 621.35, Ryzen 7 9800X3D, rustc 1.99.1 MSVC, DXC 1.8.2502.11. This was a clean tracked tree at the exact head. I did not run the paired retail-title smoke, so this report does not establish merge readiness. One remaining cap-accounting interleaving in the new revision: [`before_execute`](https://github.com/xcl-dev/xcl/blob/c6213b24fc993a4df783f7713342beaf19e60c9d/crates/xcl/src/hle/d3d12x/vram.rs#L1640-L1663) removes empty pool heaps from `Pages::pools` under `PAGES.lock()`, then releases that lock before `retire_heaps_and_sweep()` records them in `RetireQueue::retiring_pools`. A concurrent placement can enter [`alloc_budgeted_pool`](https://github.com/xcl-dev/xcl/blob/c6213b24fc993a4df783f7713342beaf19e60c9d/crates/xcl/src/hle/d3d12x/vram.rs#L694-L707) during that gap: the heap is in neither count, so it can allocate a replacement while the old heap is still live behind GPU fences. I traced this lock/order path in the source; I have not reproduced the scheduling window in a runtime test. A bounded fix is to reserve cap capacity for reclaimed pools *before* releasing `PAGES.lock()`, then transfer that reservation to the retirement batch (or release it if retirement is immediate). A concurrent reclaim/placement test with a blocked retirement fence would cover the gap. AI use: Codex (GPT-6.2 Sol) inspected the revision, ran the tests, and drafted this report; I checked the review point against the code.
Author
Owner

@⁠thehollowedone on GitHub · 2026-11-26 14:35 UTC · original

Follow-up to my exact-head report: I reproduced the narrow cap handoff race on an RTX 3080 Ti using a gated GPU regression. The test pauses before_execute after it removes one empty 64 MiB heap from Pages::pools and before it queues retirement. On unmodified c6213b24, alloc_budgeted_pool admits a replacement during that pause: the test fails, 0 passed / 1 failed. With the candidate diff below, it passes, 1 passed / 0 failed. The test also asserts the old heap appears in the cap count during the handoff, so an unrelated allocation failure cannot make it pass.

The candidate reserves reclaimed pool capacity while PAGES.lock() is still held, then transfers that count to RetireQueue's fence-backed batch under RETIRE.lock(). It counts pending plus retiring heaps in allocation and memory accounting. The existing PAGES → RETIRE lock order is preserved. The test uses a five-second rendezvous and restores per-device state; it skips when no GPU is available. This is an uncommitted suggestion against the exact head, with no retail-title smoke run. It does not establish merge readiness.

Tested: Windows 11 build 26300, RTX 3080 Ti / 621.35, Ryzen 7 9800X3D, rustc 1.99.1 MSVC, DXC 1.8.2502.11. cargo build --offline --locked --workspace passed. Focused command on stock and candidate: cargo test --offline --locked -p xcl --lib reclaimed_pool_still_counts_before_retirement_is_queued -- --nocapture --test-threads=1. Full candidate suite: cargo test --offline --locked --workspace --no-fail-fast -- --test-threads=4, 1,440 passed / 0 failed / 47 ignored across 37 targets, with 25 GPU SKIPPED notices (21 no wave64, 3 refused per-lane cases, 1 no heap windows); skips are not coverage.

Not tested: paired retail-title smoke, AMD and Intel GPUs.

AI use: Codex (GPT-6.2 Sol) wrote and ran the regression and candidate; Codex (GPT-6.2 Astra) reviewed the lock and test-lifecycle paths. I checked each point against the code and test output.

Candidate diff against c6213b24
diff --git a/crates/xcl/src/hle/d3d12x/vram.rs b/crates/xcl/src/hle/d3d12x/vram.rs
index 892e4557..1ab348f6 100644
--- a/crates/xcl/src/hle/d3d12x/vram.rs
+++ b/crates/xcl/src/hle/d3d12x/vram.rs
@@ -1479,11 +1479,12 @@ struct RetireQueue<H, F> {
     fences: std::collections::HashMap<usize, (F, u64)>,
     batches: Vec<RetiringBatch<H, F>>,
     retiring_pools: usize,
+    pending_pools: usize,
 }
 
 impl<H, F: Clone> RetireQueue<H, F> {
     fn new() -> Self {
-        Self { fences: std::collections::HashMap::new(), batches: Vec::new(), retiring_pools: 0 }
+        Self { fences: std::collections::HashMap::new(), batches: Vec::new(), retiring_pools: 0, pending_pools: 0 }
     }
 
     /// Seal `heaps` behind `unmap_mark` and one fence signal per queue (signaled BEFORE queueing).
@@ -1513,6 +1514,8 @@ impl<H, F: Clone> RetireQueue<H, F> {
 
     fn retiring_pools(&self) -> usize { self.retiring_pools }
 
+    fn counted_pools(&self) -> usize { self.retiring_pools.saturating_add(self.pending_pools) }
+
     fn note_queued_pools(&mut self, pool_heaps: usize) {
         if let Some(b) = self.batches.last_mut().filter(|_| pool_heaps > 0) {
             debug_assert!(b.pool_heaps + pool_heaps <= b.heaps.len());
@@ -1543,15 +1546,15 @@ unsafe impl Send for RetireQueue<ID3D12Heap, ID3D12Fence> {}
 
 static RETIRE: Mutex<Option<std::collections::HashMap<usize, RetireQueue<ID3D12Heap, ID3D12Fence>>>> = Mutex::new(None);
 static RETIRING_BATCHES: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0);
+#[cfg(test)]
+static RECLAIM_GAP: Mutex<Option<(usize, std::sync::mpsc::Sender<()>, std::sync::mpsc::Receiver<()>)>> = Mutex::new(None);
 
 fn retiring_pool_heaps_count(dev_key: usize) -> usize {
-    if RETIRING_BATCHES.load(std::sync::atomic::Ordering::Acquire) == 0 { return 0; }
     let g = RETIRE.lock().unwrap();
-    g.as_ref().and_then(|m| m.get(&dev_key)).map_or(0, RetireQueue::retiring_pools)
+    g.as_ref().and_then(|m| m.get(&dev_key)).map_or(0, RetireQueue::counted_pools)
 }
 
 unsafe fn poll_retiring_pool_heaps(dev_key: usize) -> (usize, bool) {
-    if RETIRING_BATCHES.load(std::sync::atomic::Ordering::Acquire) == 0 { return (0, false); }
     let (done, remaining) = {
         let mut guard = RETIRE.lock().unwrap();
         let Some(rq) = guard.as_mut().and_then(|m| m.get_mut(&dev_key)) else { return (0, false) };
@@ -1559,7 +1562,7 @@ unsafe fn poll_retiring_pool_heaps(dev_key: usize) -> (usize, bool) {
         let done = rq.reap_completed(|f| f.GetCompletedValue());
         let delta = before - rq.batches.len();
         if delta > 0 { RETIRING_BATCHES.fetch_sub(delta, std::sync::atomic::Ordering::AcqRel); }
-        (done, rq.retiring_pools())
+        (done, rq.counted_pools())
     };
     let freed_pool = done.iter().any(|b| !b.heaps.is_empty() && b.pool_heaps > 0);
     drop(done);
@@ -1606,6 +1609,8 @@ unsafe fn retire_heaps_and_sweep(
         let rq = map.entry(dev_key).or_insert_with(RetireQueue::new);
         let before = rq.batches.len();
         let immediate = rq.retire_with(newly_reclaimed, unmap_mark, &queues, || dev.CreateFence::<ID3D12Fence>(0, D3D12_FENCE_FLAG_NONE).ok(), |q, f, v| q.Signal(f, v).is_ok());
+        debug_assert!(rq.pending_pools >= pool_heaps);
+        rq.pending_pools -= pool_heaps;
         if immediate.is_empty() {
             rq.note_queued_pools(pool_heaps);
         }
@@ -1644,12 +1649,29 @@ pub(super) unsafe fn before_execute(queue: &ID3D12CommandQueue) {
                 do_reclaim = true;
                 newly_reclaimed = pages.sweep_and_reclaim(now);
                 if !newly_reclaimed.is_empty() {
+                    let mut retire = RETIRE.lock().unwrap();
+                    let rq = retire.get_or_insert_with(std::collections::HashMap::new)
+                        .entry(dev_key).or_insert_with(RetireQueue::new);
+                    rq.pending_pools += newly_reclaimed.len();
                     unmap_mark = Some((pages.fence.clone(), pages.value));
                 }
             }
         }
     }
     let reclaimed_pools = newly_reclaimed.len();
+    #[cfg(test)]
+    if reclaimed_pools > 0 {
+        let gate = {
+            let mut hook = RECLAIM_GAP.lock().unwrap();
+            if hook.as_ref().is_some_and(|(key, _, _)| *key == dev_key) { hook.take() } else { None }
+        };
+        if let Some((_, reached, resume)) = gate {
+            if reached.send(()).is_ok() {
+                resume.recv_timeout(std::time::Duration::from_secs(5))
+                    .expect("reclaim test hook was not resumed");
+            }
+        }
+    }
     if do_reclaim {
         newly_reclaimed.extend(ARENAS.lock().unwrap().sweep_dropped_for(dev_key, now));
     }
@@ -2075,6 +2097,79 @@ mod tests {
         );
     }
 
+    #[test]
+    fn reclaimed_pool_still_counts_before_retirement_is_queued() {
+        let _vram_guard = VRAM_TEST_LOCK.lock().unwrap_or_else(|e| e.into_inner());
+        use windows::Win32::Graphics::Direct3D::D3D_FEATURE_LEVEL_11_0;
+        unsafe {
+            let Ok(dev) = crate::gpu::agility::create_device(None, D3D_FEATURE_LEVEL_11_0) else {
+                return crate::gpu::recomp::runner::skip_test("no GPU");
+            };
+            let Some(mut pages) = Pages::new(&dev) else {
+                return crate::gpu::recomp::runner::skip_test("no GPU");
+            };
+            let spare = keep_spare_pools();
+            if spare > 2 { return crate::gpu::recomp::runner::skip_test("spare pool override > 2"); }
+            let cap = spare + 1;
+            for _ in 0..cap {
+                let heap = alloc_pool_heap(&dev).unwrap();
+                let slot = pages.pools.push_heap(heap);
+                pages.pool.add_heap_at(slot, POOL_PAGES);
+            }
+            pages.max_pools = cap;
+            pages.last_reclaim = Instant::now() - Duration::from_secs(2);
+            let queue = pages.queue.clone();
+            let dev_k = dev.as_raw() as usize;
+            let previous_retire = RETIRE.lock().unwrap().as_mut()
+                .and_then(|map| map.remove(&dev_k));
+            let previous = PAGES.lock().unwrap().insert(dev_k, Some(pages));
+            let (reached_tx, reached_rx) = std::sync::mpsc::channel();
+            let (resume_tx, resume_rx) = std::sync::mpsc::channel();
+            *RECLAIM_GAP.lock().unwrap() = Some((dev_k, reached_tx, resume_rx));
+            let worker = std::thread::spawn(move || before_execute(&queue));
+            let reached = reached_rx.recv_timeout(Duration::from_secs(5)).is_ok();
+            let (active, counted, replacement) = if reached {
+                let mut g = PAGES.lock().unwrap();
+                let p = g.get_mut(&dev_k).unwrap().as_mut().unwrap();
+                let active = p.pools.len();
+                let counted = retiring_pool_heaps_count(dev_k);
+                let replacement = alloc_budgeted_pool(
+                    &dev, dev_k, cap, &mut p.oom_until, &mut p.pools, Instant::now(),
+                );
+                (active, counted, replacement)
+            } else { (0, 0, None) };
+            let _ = resume_tx.send(());
+            worker.join().unwrap();
+            *RECLAIM_GAP.lock().unwrap() = None;
+            let pages = PAGES.lock().unwrap().remove(&dev_k).flatten();
+            if let Some(previous) = previous { PAGES.lock().unwrap().insert(dev_k, previous); }
+            drop(pages);
+            let marks = {
+                let g = RETIRE.lock().unwrap();
+                g.as_ref().and_then(|m| m.get(&dev_k)).map(|rq| {
+                    rq.batches.iter().flat_map(|b| b.marks.iter().chain(b.unmap_mark.iter()).cloned())
+                        .collect::<Vec<_>>()
+                }).unwrap_or_default()
+            };
+            for (f, v) in marks { crate::gpu::fence::wait(&f, v, &dev, None, 5_000).unwrap(); }
+            let _ = poll_retiring_pool_heaps(dev_k);
+            let remaining_batches = {
+                let mut guard = RETIRE.lock().unwrap();
+                if let Some(m) = guard.as_mut() {
+                    let ours = m.remove(&dev_k);
+                    let remaining = ours.as_ref().map_or(0, |rq| rq.batches.len());
+                    if let Some(old) = previous_retire { m.insert(dev_k, old); }
+                    remaining
+                } else { 0 }
+            };
+            assert_eq!(remaining_batches, 0);
+            assert!(reached, "before_execute did not reclaim the empty pool");
+            assert_eq!(active, cap - 1);
+            assert_eq!(counted, 1, "the reclaimed pool must remain reserved during handoff");
+            assert!(replacement.is_none(), "a pool still live behind retirement fences cannot free cap capacity");
+        }
+    }
+
     #[test]
     fn capped_pages_keep_over_budget_placements_alive() {
         let _vram_guard = VRAM_TEST_LOCK.lock().unwrap_or_else(|e| e.into_inner());
**@⁠thehollowedone** on GitHub · 2026-11-26 14:35 UTC · [original](https://github.com/xcl-dev/xcl/pull/2357#issuecomment-7195029453) Follow-up to [my exact-head report](https://git.gtahub.st/github/xcl-dev--xcl/pulls/2357): I reproduced the narrow cap handoff race on an RTX 3080 Ti using a gated GPU regression. The test pauses `before_execute` after it removes one empty 64 MiB heap from `Pages::pools` and before it queues retirement. On unmodified [`c6213b24`](https://github.com/xcl-dev/xcl/commit/c6213b24fc993a4df783f7713342beaf19e60c9d), `alloc_budgeted_pool` admits a replacement during that pause: the test **fails, 0 passed / 1 failed**. With the candidate diff below, it **passes, 1 passed / 0 failed**. The test also asserts the old heap appears in the cap count during the handoff, so an unrelated allocation failure cannot make it pass. The candidate reserves reclaimed pool capacity while `PAGES.lock()` is still held, then transfers that count to `RetireQueue`'s fence-backed batch under `RETIRE.lock()`. It counts pending plus retiring heaps in allocation and memory accounting. The existing `PAGES` → `RETIRE` lock order is preserved. The test uses a five-second rendezvous and restores per-device state; it skips when no GPU is available. This is an uncommitted suggestion against the exact head, with no retail-title smoke run. It does not establish merge readiness. **Tested:** Windows 11 build 26300, RTX 3080 Ti / 621.35, Ryzen 7 9800X3D, rustc 1.99.1 MSVC, DXC 1.8.2502.11. `cargo build --offline --locked --workspace` passed. Focused command on stock and candidate: `cargo test --offline --locked -p xcl --lib reclaimed_pool_still_counts_before_retirement_is_queued -- --nocapture --test-threads=1`. Full candidate suite: `cargo test --offline --locked --workspace --no-fail-fast -- --test-threads=4`, **1,440 passed / 0 failed / 47 ignored** across 37 targets, with 25 GPU `SKIPPED` notices (21 no wave64, 3 refused per-lane cases, 1 no heap windows); skips are not coverage. **Not tested:** paired retail-title smoke, AMD and Intel GPUs. AI use: Codex (GPT-6.2 Sol) wrote and ran the regression and candidate; Codex (GPT-6.2 Astra) reviewed the lock and test-lifecycle paths. I checked each point against the code and test output. <details> <summary>Candidate diff against c6213b24</summary> ```diff diff --git a/crates/xcl/src/hle/d3d12x/vram.rs b/crates/xcl/src/hle/d3d12x/vram.rs index 892e4557..1ab348f6 100644 --- a/crates/xcl/src/hle/d3d12x/vram.rs +++ b/crates/xcl/src/hle/d3d12x/vram.rs @@ -1479,11 +1479,12 @@ struct RetireQueue<H, F> { fences: std::collections::HashMap<usize, (F, u64)>, batches: Vec<RetiringBatch<H, F>>, retiring_pools: usize, + pending_pools: usize, } impl<H, F: Clone> RetireQueue<H, F> { fn new() -> Self { - Self { fences: std::collections::HashMap::new(), batches: Vec::new(), retiring_pools: 0 } + Self { fences: std::collections::HashMap::new(), batches: Vec::new(), retiring_pools: 0, pending_pools: 0 } } /// Seal `heaps` behind `unmap_mark` and one fence signal per queue (signaled BEFORE queueing). @@ -1513,6 +1514,8 @@ impl<H, F: Clone> RetireQueue<H, F> { fn retiring_pools(&self) -> usize { self.retiring_pools } + fn counted_pools(&self) -> usize { self.retiring_pools.saturating_add(self.pending_pools) } + fn note_queued_pools(&mut self, pool_heaps: usize) { if let Some(b) = self.batches.last_mut().filter(|_| pool_heaps > 0) { debug_assert!(b.pool_heaps + pool_heaps <= b.heaps.len()); @@ -1543,15 +1546,15 @@ unsafe impl Send for RetireQueue<ID3D12Heap, ID3D12Fence> {} static RETIRE: Mutex<Option<std::collections::HashMap<usize, RetireQueue<ID3D12Heap, ID3D12Fence>>>> = Mutex::new(None); static RETIRING_BATCHES: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0); +#[cfg(test)] +static RECLAIM_GAP: Mutex<Option<(usize, std::sync::mpsc::Sender<()>, std::sync::mpsc::Receiver<()>)>> = Mutex::new(None); fn retiring_pool_heaps_count(dev_key: usize) -> usize { - if RETIRING_BATCHES.load(std::sync::atomic::Ordering::Acquire) == 0 { return 0; } let g = RETIRE.lock().unwrap(); - g.as_ref().and_then(|m| m.get(&dev_key)).map_or(0, RetireQueue::retiring_pools) + g.as_ref().and_then(|m| m.get(&dev_key)).map_or(0, RetireQueue::counted_pools) } unsafe fn poll_retiring_pool_heaps(dev_key: usize) -> (usize, bool) { - if RETIRING_BATCHES.load(std::sync::atomic::Ordering::Acquire) == 0 { return (0, false); } let (done, remaining) = { let mut guard = RETIRE.lock().unwrap(); let Some(rq) = guard.as_mut().and_then(|m| m.get_mut(&dev_key)) else { return (0, false) }; @@ -1559,7 +1562,7 @@ unsafe fn poll_retiring_pool_heaps(dev_key: usize) -> (usize, bool) { let done = rq.reap_completed(|f| f.GetCompletedValue()); let delta = before - rq.batches.len(); if delta > 0 { RETIRING_BATCHES.fetch_sub(delta, std::sync::atomic::Ordering::AcqRel); } - (done, rq.retiring_pools()) + (done, rq.counted_pools()) }; let freed_pool = done.iter().any(|b| !b.heaps.is_empty() && b.pool_heaps > 0); drop(done); @@ -1606,6 +1609,8 @@ unsafe fn retire_heaps_and_sweep( let rq = map.entry(dev_key).or_insert_with(RetireQueue::new); let before = rq.batches.len(); let immediate = rq.retire_with(newly_reclaimed, unmap_mark, &queues, || dev.CreateFence::<ID3D12Fence>(0, D3D12_FENCE_FLAG_NONE).ok(), |q, f, v| q.Signal(f, v).is_ok()); + debug_assert!(rq.pending_pools >= pool_heaps); + rq.pending_pools -= pool_heaps; if immediate.is_empty() { rq.note_queued_pools(pool_heaps); } @@ -1644,12 +1649,29 @@ pub(super) unsafe fn before_execute(queue: &ID3D12CommandQueue) { do_reclaim = true; newly_reclaimed = pages.sweep_and_reclaim(now); if !newly_reclaimed.is_empty() { + let mut retire = RETIRE.lock().unwrap(); + let rq = retire.get_or_insert_with(std::collections::HashMap::new) + .entry(dev_key).or_insert_with(RetireQueue::new); + rq.pending_pools += newly_reclaimed.len(); unmap_mark = Some((pages.fence.clone(), pages.value)); } } } } let reclaimed_pools = newly_reclaimed.len(); + #[cfg(test)] + if reclaimed_pools > 0 { + let gate = { + let mut hook = RECLAIM_GAP.lock().unwrap(); + if hook.as_ref().is_some_and(|(key, _, _)| *key == dev_key) { hook.take() } else { None } + }; + if let Some((_, reached, resume)) = gate { + if reached.send(()).is_ok() { + resume.recv_timeout(std::time::Duration::from_secs(5)) + .expect("reclaim test hook was not resumed"); + } + } + } if do_reclaim { newly_reclaimed.extend(ARENAS.lock().unwrap().sweep_dropped_for(dev_key, now)); } @@ -2075,6 +2097,79 @@ mod tests { ); } + #[test] + fn reclaimed_pool_still_counts_before_retirement_is_queued() { + let _vram_guard = VRAM_TEST_LOCK.lock().unwrap_or_else(|e| e.into_inner()); + use windows::Win32::Graphics::Direct3D::D3D_FEATURE_LEVEL_11_0; + unsafe { + let Ok(dev) = crate::gpu::agility::create_device(None, D3D_FEATURE_LEVEL_11_0) else { + return crate::gpu::recomp::runner::skip_test("no GPU"); + }; + let Some(mut pages) = Pages::new(&dev) else { + return crate::gpu::recomp::runner::skip_test("no GPU"); + }; + let spare = keep_spare_pools(); + if spare > 2 { return crate::gpu::recomp::runner::skip_test("spare pool override > 2"); } + let cap = spare + 1; + for _ in 0..cap { + let heap = alloc_pool_heap(&dev).unwrap(); + let slot = pages.pools.push_heap(heap); + pages.pool.add_heap_at(slot, POOL_PAGES); + } + pages.max_pools = cap; + pages.last_reclaim = Instant::now() - Duration::from_secs(2); + let queue = pages.queue.clone(); + let dev_k = dev.as_raw() as usize; + let previous_retire = RETIRE.lock().unwrap().as_mut() + .and_then(|map| map.remove(&dev_k)); + let previous = PAGES.lock().unwrap().insert(dev_k, Some(pages)); + let (reached_tx, reached_rx) = std::sync::mpsc::channel(); + let (resume_tx, resume_rx) = std::sync::mpsc::channel(); + *RECLAIM_GAP.lock().unwrap() = Some((dev_k, reached_tx, resume_rx)); + let worker = std::thread::spawn(move || before_execute(&queue)); + let reached = reached_rx.recv_timeout(Duration::from_secs(5)).is_ok(); + let (active, counted, replacement) = if reached { + let mut g = PAGES.lock().unwrap(); + let p = g.get_mut(&dev_k).unwrap().as_mut().unwrap(); + let active = p.pools.len(); + let counted = retiring_pool_heaps_count(dev_k); + let replacement = alloc_budgeted_pool( + &dev, dev_k, cap, &mut p.oom_until, &mut p.pools, Instant::now(), + ); + (active, counted, replacement) + } else { (0, 0, None) }; + let _ = resume_tx.send(()); + worker.join().unwrap(); + *RECLAIM_GAP.lock().unwrap() = None; + let pages = PAGES.lock().unwrap().remove(&dev_k).flatten(); + if let Some(previous) = previous { PAGES.lock().unwrap().insert(dev_k, previous); } + drop(pages); + let marks = { + let g = RETIRE.lock().unwrap(); + g.as_ref().and_then(|m| m.get(&dev_k)).map(|rq| { + rq.batches.iter().flat_map(|b| b.marks.iter().chain(b.unmap_mark.iter()).cloned()) + .collect::<Vec<_>>() + }).unwrap_or_default() + }; + for (f, v) in marks { crate::gpu::fence::wait(&f, v, &dev, None, 5_000).unwrap(); } + let _ = poll_retiring_pool_heaps(dev_k); + let remaining_batches = { + let mut guard = RETIRE.lock().unwrap(); + if let Some(m) = guard.as_mut() { + let ours = m.remove(&dev_k); + let remaining = ours.as_ref().map_or(0, |rq| rq.batches.len()); + if let Some(old) = previous_retire { m.insert(dev_k, old); } + remaining + } else { 0 } + }; + assert_eq!(remaining_batches, 0); + assert!(reached, "before_execute did not reclaim the empty pool"); + assert_eq!(active, cap - 1); + assert_eq!(counted, 1, "the reclaimed pool must remain reserved during handoff"); + assert!(replacement.is_none(), "a pool still live behind retirement fences cannot free cap capacity"); + } + } + #[test] fn capped_pages_keep_over_budget_placements_alive() { let _vram_guard = VRAM_TEST_LOCK.lock().unwrap_or_else(|e| e.into_inner()); ``` </details>
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2357/head:github-bot/gh-2357'
git switch 'github-bot/gh-2357'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2357'
git switch 'github-bot/gh-2357'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2357'
git switch 'github-bot/gh-2357'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2357'
git switch 'main'
git merge --squash 'github-bot/gh-2357'
git switch 'main'
git merge --ff-only 'github-bot/gh-2357'
git switch 'main'
git merge 'github-bot/gh-2357'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.