D3D12.X: plain physical page homes, residency trim, lazy level pages, async texture upload #3747

Open
Kalmarv wants to merge 4 commits from upstream-pr/3747 into main
Kalmarv commented 2026-12-03 00:35:28 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Kalmarv on 2026-12-03T00:35:28Z.


Coordinates four VRAM residency and texture-upload improvements into one coherent change: plain write-watched physical page homes, watermarked residency trimming with lazy shared depth UAV twins, opt-in mip-class demotion and mip-scoped overlap unmapping for lazy level pages, and an opt-in bounded background texture-upload preparation worker. Shipping these four commits together keeps the sparse-window budget, residency trimming, lazy tile-page mapping, and async upload synchronization aligned (for example, residency.rs reclaims completed async upload jobs before trimming pools, and async_texture_upload.rs respects vram::has_unmapped_levels and kernelx free/unmap paths). Part of #2697 (and keeps XCL_TEXTURE_LEVEL_PAGES opt-in while the #3188 render-target aliasing gap remains open).

In the paired 60 s smoke on origin/main e99b0bdfc (title: ea3b5e4d, default settings where XCL_TEXTURE_LEVEL_PAGES, XCL_MIP_DEMOTE, and XCL_ASYNC_TEX_UPLOAD are all opt-in): local VRAM drops by 153 MB (6,567 -> 6,414 MB), depth UAV twins drop to 0 MB (lazy shared reserved), frames shown are 1,638 vs 1,342 (1.22x main, 60 60 60 presents/2 s), texel residency stays at 97% (307.8M / 316.9M, matching main), async textures queue 0 (zero overhead when off), and peak process commit is 17,592 MB vs 15,850 MB (1.11x main, settling at 16,828 MB) with 0 device removals and 0 crashes. Passed cross-model Opus adversarial review (all blockers and follow-ups resolved and verified LGTM).

What is in it

  • Write-watched plain physical page homes (XCL_PHYS_HOME_PLAIN, default ON): AllocateTitlePhysicalPages reserves write-watched plain memory instead of sparse UMA windows (=0 restores UMA homes and > uma::WINDOW MEM_64K_PAGES placement), unregistering plain homes from GRAPHICS_RESERVATIONS on FreeTitlePhysicalPages. When MapTitlePhysicalPages receives a NULL destination address for pages whose home is outside UMA, it maps them into a GPU-visible sparse UMA slot (reusing only dedicated null_maps slots — never a title-owned MEM_GRAPHICS mapping — kept alive while any other live page is mapped in the slot, and released once empty on FreeTitlePhysicalPages or VirtualFree). Under default XCL_PHYS_HOME_PLAIN=1, multi-window MEM_64K_PAGES reservations larger than uma::WINDOW (4 GiB) overflow to write-watched plain memory (gpu_visible_fallback) instead of capturing sparse windows 1–2 freed by plain homes.
  • Watermarked residency trimming and pool hygiene (XCL_RESIDENCY_TRIM, default ON): residency.rs wakes a dedicated xcl-residency background worker from the presentation WM_TIMER (never blocking the window message pump on GPU queries, pool locks, or COM releases) to sample OS commit headroom and DXGI local VRAM usage and trim idle staging pools, readback buffers, compute-split scratch (XCL_SCRATCH_POOL_TRIM), shared lazy reserved depth UAV twins (XCL_DEPTH_UAV_SHARE), and reset-count retired command allocators (XCL_ALLOC_RETIRE_RESETS) under Elevated/Critical pressure. Depth UAV twin trimming takes vram::unmap_completion_snapshot() before locking Cell::inner and executes deferred queue signals/releases after dropping Cell::inner, caps shared twin tiles to each buffer's console byte size (xg::Texture::size, with least_texture_bytes fallback) so PC overflow tiles stay private, tracks active UAV use across both DIRECT and compute lists, stamps last_used_ms and clears entered on UAV leave, and never trims barrierless COMMON / UNORDERED_ACCESS-initial twins.
  • Opt-in mip-class demotion and mip-scoped overlap unmap for level pages (XCL_TEXTURE_LEVEL_PAGES=1 and XCL_MIP_DEMOTE=1, both default OFF): Keeps XCL_TEXTURE_LEVEL_PAGES opt-in (matching main, while #3188 remains open). When enabled, segregates large texture tile heaps by mip class (Mip0/Mip1/Tail) with heap-aware quarantine and opt-in cold top-mip demotion under pressure, scopes overlapping Table::insert unmapping to overlapping mip levels only (falling back to whole-resource unmap when level pages are off), and adds rate-limited residency logging.
  • Opt-in bounded async texture upload preparation (XCL_ASYNC_TEX_UPLOAD=1, default OFF; XCL_ASYNC_TEX_DEFER_FULL, default ON when async is enabled): async_texture_upload.rs hashes and detiles sampled textures (> 64 KiB, up to 16 MiB) on a bounded background worker (64 snapshots, 64 MiB staging cap each) and drains prepared copies on their originating DIRECT queue. When off (default), partition, drain, requeue_deferred_for, forget_queue, wait_if_reading_resource, guard_source_free, and allocation_len all fast-path out, and synchronous texture_upload::submit() does not retain Job::resources (preserving main's exact texture lifetimes and sync upload semantics). When enabled (=1), unmapped lazy levels stay synchronous, saturated queues defer per-queue with a 16 ms same-device DIRECT queue strand-rescue timeout, SourceGuardState serializes worker reads of contiguous and paged (PageMap) title memory against free/protect/unmap paths, and Job::resources retains destination resources until GPU copy completion.
  • Overlap check across open PRs: Related/overlapping open PRs checked: #2905 (physical page homes / alloc_physical_home), #3742 (sparse physical-page heaps through L0 budget), #3098 and #2385 (dropping top mips under VRAM budget, similar area to opt-in XCL_MIP_DEMOTE), #3740 (residency/VRAM overlap), #3651 (GPU compute detiling), #3653/#3696 (UMA view/heap windows), #3648 (dispatch-chain mutex drop), #3612 (allocator size trim vs reset-count retirement), #3587/#3682 (adapter VRAM budget / opt-in two-tier texture budget), and #3678/#3679/#3691/#3718 (separate upload/overlap/SRV-mip changes).

Tested

  • Hardware & toolchain: NVIDIA GeForce RTX 5070 Ti (16 GB VRAM, driver 610.74), AMD Ryzen 9 9950X, Windows 11 x64, rustc 1.99.0 (b940084d7 2026-09-28), DXC 1.9.2609.
  • cargo build --release -p xcl: succeeded on 4b00e738b with 39 warnings in xcl lib (0 new warnings vs origin/main e99b0bdfc, which also has 39 warnings).
  • cargo test -p xcl --lib -- --test-threads=4 on 4b00e738b: 2,898 passed, 1 failed, 37 ignored (0 error 487 aborts — fixed by rebasing onto origin/main e99b0bdfc with #3743 and isolating global-state tests in child processes). The sole failure is pre-existing and unrelated to this PR (gpu::dxil::idioms::tests::gpu_split_wave64_uniform_first_lanes_read_what_the_exchange_reads; crates/xcl/src/gpu/dxil/ has 0 diff vs origin/main).
  • cargo bench -p xcl --bench '*' -- --test and cargo test --workspace --test '*' -- --test-threads=4: 0 failed across all benchmark targets and workspace integration test binaries, including testtitle e2e with tests/testtitle/ unmodified vs origin/main (strict single read_back).
  • New and updated unit/GPU tests all pass with 0 skips on RTX 5070 Ti:
    • Plain physical homes, MapTitlePhysicalPages(NULL) sparse UMA reuse restricted to null_maps (asserting it never returns a title-owned MEM_GRAPHICS reservation), child-process XCL_PHYS_HOME_PLAIN=0 opt-out (physical_home_plain_opt_out_returns_uma_home_on_null_map), FreeTitlePhysicalPages unregistration, and multi-window MEM_64K_PAGES overflow.
    • Child-process forced-pressure GPU residency test (residency::tests::forced_pressure_passes_exercise_all_trim_paths, verifying both Elevated retention below ELEVATED_POOL_CAP and Critical drain to 0) and depth_uav::tests::reserved_depth_twin_lazy_maps_shares_and_trims (shared lazy reserved twin mapping, console-size tile cap, UAV protection, and idle trim).
    • Child-process title_textures::tests::a_cold_first_level_gives_back_its_heap_and_comes_back_when_used, mip-scoped overlap unmapping, allocator retirement, scratch pool trimming, and async upload eligibility / 16 ms strand rescue / SourceGuardState serialization (with all existing sync title_textures tests unmodified — no refresh_and_drain_async or reclaim_completed_uploads workarounds).
  • Cross-model adversarial review: re-reviewed and approved (LGTM) by Claude Opus 5.5 after fixing all findings from @Foniass's merge-check and Opus's review.

Regression run

main:

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

PR:

xcl-smoke v1
commit: 4b00e738bb52caa60243acf5b990613b7e1c1b30
gpu: NVIDIA GeForce RTX 5070 Ti
title: ea3b5e4d
seconds: 60
exit: 0x0
frames shown: 1638 (PresentX 1638)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 17592 MB

Notes on the paired 60 s run (title: ea3b5e4d, default settings):

  • Local VRAM settled at 6,414 MB vs 6,567 MB on main (-153 MB); depth UAV twins used 0 MB (lazy shared reserved); target pools dropped from 3,648 MB to 3,584 MB (-64 MB).
  • Texel residency stayed identical to main at 97% (307.8M / 316.9M) because XCL_TEXTURE_LEVEL_PAGES=1 is opt-in; async textures logged 0 queued, 0 uploaded because XCL_ASYNC_TEX_UPLOAD=1 is opt-in.
  • Process commit peaked at 17,592 MB (1.11x main, settling at 16,828 MB; sparse pools 1,704 MB / 1,544 MB mapped vs 840 MB / 838 MB mapped on main, because > 4 GiB MEM_64K_PAGES pools overflow to plain write-watched memory while a 3.3 GiB MEM_64K_PAGES reservation fits inside sparse window 1).

Not tested

  • Elevated and Critical residency pressure trims, depth-twin idle unmapping, smaller compute-split scratch budgets, and opt-in XCL_MIP_DEMOTE=1 on a title under real VRAM/commit pressure (the 60 s smoke on a 16 GB RTX 5070 Ti stays at Normal pressure; these paths are exercised by GPU unit tests only).
  • Reset-count allocator retirement (XCL_ALLOC_RETIRE_RESETS, default 256 resets) re-creation cost under sustained gameplay load.
  • Opt-in XCL_ASYNC_TEX_UPLOAD=1 live title runs (including the one-submit-late reactivation edge case when Job::resources retains COM refs on the opt-in async path) and opt-in XCL_TEXTURE_LEVEL_PAGES=1 live title runs after flipping both to opt-in.
  • Multi-window > 4 GiB MEM_64K_PAGES plain-memory overflow beyond the 60 s smoke on one title (XCL_PHYS_HOME_PLAIN=0 restores main placement).
  • Wave64 GPU recompiler tests (skipped on NVIDIA RTX 5070 Ti) and opt-in XCL_HEAP_WINDOWS=1 tests.
  • AMD/Intel GPUs and Wine/Linux.
  • XCL_SAMPLE_* game-data tests (unset).

AI use

  • Claude Code, Claude Opus 5.5: authored the original residency, mip-demotion, plain physical-home, and async texture-upload implementations, and performed adversarial pre-PR code reviews (4 rounds total, final LGTM).
  • Antigravity, Gemini 4 Neon: rebased onto origin/main e99b0bdfc, addressed all merge-check and Opus adversarial review findings (flipped XCL_ASYNC_TEX_UPLOAD and XCL_TEXTURE_LEVEL_PAGES to opt-in, reverted all test loosenings in tests/testtitle and title_textures.rs, isolated global-state GPU tests in child processes with "1 passed" checks, removed the global allocator from main.rs, tightened MapTitlePhysicalPages(NULL) to null_maps only, tied > 4 GiB 64K overflow to phys_home_plain(), restored origin/main coherent-UMA VirtualFree order, capped shared depth-twin tiles to console byte size, moved unmap_completion_snapshot and signals outside Cell::inner, and ensured default sync uploads never retain Job::resources), and ran the release builds, test suite, and paired 60 s smokes.
<!-- greyfinch-sync:ivall/xcl:issue:5617352241 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3747). Originally posted by [Kalmarv](https://github.com/Kalmarv) on 2026-12-03T00:35:28Z. --- Coordinates four VRAM residency and texture-upload improvements into one coherent change: plain write-watched physical page homes, watermarked residency trimming with lazy shared depth UAV twins, opt-in mip-class demotion and mip-scoped overlap unmapping for lazy level pages, and an opt-in bounded background texture-upload preparation worker. Shipping these four commits together keeps the sparse-window budget, residency trimming, lazy tile-page mapping, and async upload synchronization aligned (for example, `residency.rs` reclaims completed async upload jobs before trimming pools, and `async_texture_upload.rs` respects `vram::has_unmapped_levels` and `kernelx` free/unmap paths). Part of #2697 (and keeps `XCL_TEXTURE_LEVEL_PAGES` opt-in while the #3188 render-target aliasing gap remains open). In the paired 60 s smoke on `origin/main` `e99b0bdfc` (`title: ea3b5e4d`, default settings where `XCL_TEXTURE_LEVEL_PAGES`, `XCL_MIP_DEMOTE`, and `XCL_ASYNC_TEX_UPLOAD` are all opt-in): local VRAM drops by 153 MB (`6,567 -> 6,414 MB`), depth UAV twins drop to `0 MB` (lazy shared reserved), frames shown are `1,638` vs `1,342` (`1.22x` `main`, `60 60 60` presents/2 s), texel residency stays at `97%` (`307.8M / 316.9M`, matching `main`), async textures queue `0` (zero overhead when off), and peak process commit is `17,592 MB` vs `15,850 MB` (`1.11x` `main`, settling at `16,828 MB`) with 0 device removals and 0 crashes. Passed cross-model Opus adversarial review (all blockers and follow-ups resolved and verified LGTM). **What is in it** - **Write-watched plain physical page homes (`XCL_PHYS_HOME_PLAIN`, default ON):** `AllocateTitlePhysicalPages` reserves write-watched plain memory instead of sparse UMA windows (`=0` restores UMA homes and `> uma::WINDOW` `MEM_64K_PAGES` placement), unregistering plain homes from `GRAPHICS_RESERVATIONS` on `FreeTitlePhysicalPages`. When `MapTitlePhysicalPages` receives a `NULL` destination address for pages whose home is outside UMA, it maps them into a GPU-visible sparse UMA slot (reusing only dedicated `null_maps` slots — never a title-owned `MEM_GRAPHICS` mapping — kept alive while any other live page is mapped in the slot, and released once empty on `FreeTitlePhysicalPages` or `VirtualFree`). Under default `XCL_PHYS_HOME_PLAIN=1`, multi-window `MEM_64K_PAGES` reservations larger than `uma::WINDOW` (4 GiB) overflow to write-watched plain memory (`gpu_visible_fallback`) instead of capturing sparse windows 1–2 freed by plain homes. - **Watermarked residency trimming and pool hygiene (`XCL_RESIDENCY_TRIM`, default ON):** `residency.rs` wakes a dedicated `xcl-residency` background worker from the presentation `WM_TIMER` (never blocking the window message pump on GPU queries, pool locks, or COM releases) to sample OS commit headroom and DXGI local VRAM usage and trim idle staging pools, readback buffers, compute-split scratch (`XCL_SCRATCH_POOL_TRIM`), shared lazy reserved depth UAV twins (`XCL_DEPTH_UAV_SHARE`), and reset-count retired command allocators (`XCL_ALLOC_RETIRE_RESETS`) under Elevated/Critical pressure. Depth UAV twin trimming takes `vram::unmap_completion_snapshot()` before locking `Cell::inner` and executes deferred queue signals/releases after dropping `Cell::inner`, caps shared twin tiles to each buffer's console byte size (`xg::Texture::size`, with `least_texture_bytes` fallback) so PC overflow tiles stay private, tracks active UAV use across both DIRECT and compute lists, stamps `last_used_ms` and clears `entered` on UAV leave, and never trims barrierless `COMMON` / `UNORDERED_ACCESS`-initial twins. - **Opt-in mip-class demotion and mip-scoped overlap unmap for level pages (`XCL_TEXTURE_LEVEL_PAGES=1` and `XCL_MIP_DEMOTE=1`, both default OFF):** Keeps `XCL_TEXTURE_LEVEL_PAGES` opt-in (matching `main`, while #3188 remains open). When enabled, segregates large texture tile heaps by mip class (`Mip0`/`Mip1`/`Tail`) with heap-aware quarantine and opt-in cold top-mip demotion under pressure, scopes overlapping `Table::insert` unmapping to overlapping mip levels only (falling back to whole-resource unmap when level pages are off), and adds rate-limited residency logging. - **Opt-in bounded async texture upload preparation (`XCL_ASYNC_TEX_UPLOAD=1`, default OFF; `XCL_ASYNC_TEX_DEFER_FULL`, default ON when async is enabled):** `async_texture_upload.rs` hashes and detiles sampled textures (`> 64 KiB`, up to `16 MiB`) on a bounded background worker (64 snapshots, 64 MiB staging cap each) and drains prepared copies on their originating DIRECT queue. When off (default), `partition`, `drain`, `requeue_deferred_for`, `forget_queue`, `wait_if_reading_resource`, `guard_source_free`, and `allocation_len` all fast-path out, and synchronous `texture_upload::submit()` does not retain `Job::resources` (preserving `main`'s exact texture lifetimes and sync upload semantics). When enabled (`=1`), unmapped lazy levels stay synchronous, saturated queues defer per-queue with a 16 ms same-device DIRECT queue strand-rescue timeout, `SourceGuardState` serializes worker reads of contiguous and paged (`PageMap`) title memory against free/protect/unmap paths, and `Job::resources` retains destination resources until GPU copy completion. - **Overlap check across open PRs:** Related/overlapping open PRs checked: `#2905` (physical page homes / `alloc_physical_home`), `#3742` (sparse physical-page heaps through L0 budget), `#3098` and `#2385` (dropping top mips under VRAM budget, similar area to opt-in `XCL_MIP_DEMOTE`), `#3740` (residency/VRAM overlap), `#3651` (GPU compute detiling), `#3653`/`#3696` (UMA view/heap windows), `#3648` (dispatch-chain mutex drop), `#3612` (allocator size trim vs reset-count retirement), `#3587`/`#3682` (adapter VRAM budget / opt-in two-tier texture budget), and `#3678`/`#3679`/`#3691`/`#3718` (separate upload/overlap/SRV-mip changes). **Tested** - Hardware & toolchain: NVIDIA GeForce RTX 5070 Ti (16 GB VRAM, driver 610.74), AMD Ryzen 9 9950X, Windows 11 x64, `rustc 1.99.0 (b940084d7 2026-09-28)`, DXC 1.9.2609. - `cargo build --release -p xcl`: succeeded on `4b00e738b` with 39 warnings in `xcl` lib (0 new warnings vs `origin/main` `e99b0bdfc`, which also has 39 warnings). - `cargo test -p xcl --lib -- --test-threads=4` on `4b00e738b`: **2,898 passed, 1 failed, 37 ignored** (`0` `error 487` aborts — fixed by rebasing onto `origin/main` `e99b0bdfc` with `#3743` and isolating global-state tests in child processes). The sole failure is pre-existing and unrelated to this PR (`gpu::dxil::idioms::tests::gpu_split_wave64_uniform_first_lanes_read_what_the_exchange_reads`; `crates/xcl/src/gpu/dxil/` has 0 diff vs `origin/main`). - `cargo bench -p xcl --bench '*' -- --test` and `cargo test --workspace --test '*' -- --test-threads=4`: **0 failed** across all benchmark targets and workspace integration test binaries, including `testtitle` e2e with `tests/testtitle/` unmodified vs `origin/main` (strict single `read_back`). - New and updated unit/GPU tests all pass with 0 skips on RTX 5070 Ti: - Plain physical homes, `MapTitlePhysicalPages(NULL)` sparse UMA reuse restricted to `null_maps` (asserting it never returns a title-owned `MEM_GRAPHICS` reservation), child-process `XCL_PHYS_HOME_PLAIN=0` opt-out (`physical_home_plain_opt_out_returns_uma_home_on_null_map`), `FreeTitlePhysicalPages` unregistration, and multi-window `MEM_64K_PAGES` overflow. - Child-process forced-pressure GPU residency test (`residency::tests::forced_pressure_passes_exercise_all_trim_paths`, verifying both `Elevated` retention below `ELEVATED_POOL_CAP` and `Critical` drain to 0) and `depth_uav::tests::reserved_depth_twin_lazy_maps_shares_and_trims` (shared lazy reserved twin mapping, console-size tile cap, UAV protection, and idle trim). - Child-process `title_textures::tests::a_cold_first_level_gives_back_its_heap_and_comes_back_when_used`, mip-scoped overlap unmapping, allocator retirement, scratch pool trimming, and async upload eligibility / 16 ms strand rescue / `SourceGuardState` serialization (with all existing sync `title_textures` tests unmodified — no `refresh_and_drain_async` or `reclaim_completed_uploads` workarounds). - Cross-model adversarial review: re-reviewed and approved (`LGTM`) by Claude Opus 5.5 after fixing all findings from `@Foniass`'s merge-check and Opus's review. **Regression run** main: ``` xcl-smoke v1 commit: e99b0bdfcfa9a172c66a5be3b31f53a2940ed041 gpu: NVIDIA GeForce RTX 5070 Ti title: ea3b5e4d seconds: 60 exit: 0x0 frames shown: 1342 (PresentX 1342) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 15850 MB ``` PR: ``` xcl-smoke v1 commit: 4b00e738bb52caa60243acf5b990613b7e1c1b30 gpu: NVIDIA GeForce RTX 5070 Ti title: ea3b5e4d seconds: 60 exit: 0x0 frames shown: 1638 (PresentX 1638) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 17592 MB ``` Notes on the paired 60 s run (`title: ea3b5e4d`, default settings): - Local VRAM settled at `6,414 MB` vs `6,567 MB` on `main` (`-153 MB`); depth UAV twins used `0 MB` (lazy shared reserved); target pools dropped from `3,648 MB` to `3,584 MB` (`-64 MB`). - Texel residency stayed identical to `main` at `97%` (`307.8M / 316.9M`) because `XCL_TEXTURE_LEVEL_PAGES=1` is opt-in; `async textures` logged `0 queued, 0 uploaded` because `XCL_ASYNC_TEX_UPLOAD=1` is opt-in. - Process commit peaked at `17,592 MB` (`1.11x` `main`, settling at `16,828 MB`; sparse pools `1,704 MB` / `1,544 MB` mapped vs `840 MB` / `838 MB` mapped on `main`, because `> 4 GiB` `MEM_64K_PAGES` pools overflow to plain write-watched memory while a `3.3 GiB` `MEM_64K_PAGES` reservation fits inside sparse window 1). **Not tested** - Elevated and Critical residency pressure trims, depth-twin idle unmapping, smaller compute-split scratch budgets, and opt-in `XCL_MIP_DEMOTE=1` on a title under real VRAM/commit pressure (the 60 s smoke on a 16 GB RTX 5070 Ti stays at Normal pressure; these paths are exercised by GPU unit tests only). - Reset-count allocator retirement (`XCL_ALLOC_RETIRE_RESETS`, default 256 resets) re-creation cost under sustained gameplay load. - Opt-in `XCL_ASYNC_TEX_UPLOAD=1` live title runs (including the one-submit-late reactivation edge case when `Job::resources` retains COM refs on the opt-in async path) and opt-in `XCL_TEXTURE_LEVEL_PAGES=1` live title runs after flipping both to opt-in. - Multi-window `> 4 GiB` `MEM_64K_PAGES` plain-memory overflow beyond the 60 s smoke on one title (`XCL_PHYS_HOME_PLAIN=0` restores `main` placement). - Wave64 GPU recompiler tests (skipped on NVIDIA RTX 5070 Ti) and opt-in `XCL_HEAP_WINDOWS=1` tests. - AMD/Intel GPUs and Wine/Linux. - `XCL_SAMPLE_*` game-data tests (unset). **AI use** - Claude Code, Claude Opus 5.5: authored the original residency, mip-demotion, plain physical-home, and async texture-upload implementations, and performed adversarial pre-PR code reviews (4 rounds total, final LGTM). - Antigravity, Gemini 4 Neon: rebased onto `origin/main` `e99b0bdfc`, addressed all merge-check and Opus adversarial review findings (flipped `XCL_ASYNC_TEX_UPLOAD` and `XCL_TEXTURE_LEVEL_PAGES` to opt-in, reverted all test loosenings in `tests/testtitle` and `title_textures.rs`, isolated global-state GPU tests in child processes with `"1 passed"` checks, removed the global allocator from `main.rs`, tightened `MapTitlePhysicalPages(NULL)` to `null_maps` only, tied `> 4 GiB` 64K overflow to `phys_home_plain()`, restored `origin/main` coherent-UMA `VirtualFree` order, capped shared depth-twin tiles to console byte size, moved `unmap_completion_snapshot` and signals outside `Cell::inner`, and ensured default sync uploads never retain `Job::resources`), and ran the release builds, test suite, and paired 60 s smokes.
Foniass commented 2026-12-03 08:07:27 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-03T08:07:27Z.


merge-check
base: 078358a058
head: f2d9073715
merge: clean
build: ok
tests: did not finish: the -p xcl --lib binary aborted after 152 tests in both of two runs (finding 1); the other test binaries passed
review: 2 critical, 3 high, 7 medium, 3 nits (below)
performance: 60 s smoke run: 1669 → 1602 frames (95 % of main), peak commit 17577 → 19789 MB, no device removal, no crash
title run: retail title on the RTX 5070 Ti (driver 621.14), into the world by scripted presses: 234 s there, 0 device removals, 0 crashes, 2.2 presents/s; run with XCL_SKIP_CS=95cc13288a27a96e (the NVIDIA hang at the end of loading, #3541) and NVIDIA's 2048 MB shader heap (#2590)
verdict: not yet: 2 critical findings (the library test binary aborts at the same point in both runs on this merge, and async texture uploads let the next submit sample old texels) and 3 high (below)
hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5


In short: Six default-on VRAM and upload changes in one PR (plain physical-page homes; residency trimming with allocator retirement, shared depth twins and scratch trimming; lazy level pages turned on by default with mip-class heaps; async texture preparation), plus a Rust heap counting allocator: about 5,900 lines added. Reading the code: the async worker takes eligible textures out of the submit that follows the CPU write, so that submit's GPU work samples old texels, and the e2e and unit tests were changed to retry until the upload lands; level pages go on by default with the aliasing gap #3188 found still open. The async latency, the loosened tests, the aliasing gap and the size block it.

Critical

  1. The library test binary aborts at the same point in both runs. On this merge the -p xcl --lib test binary stopped after 152 tests in two separate runs on an RTX 5070 Ti, both times right after the vram tests, with "coherent window could not be restored at 0x... (268435456 bytes, got 0x0, Windows error 487) after segment 2 (64 MB CUSTOM): Map gave 0x..., wanted 0x...; stopping before guest memory is used". Every other PR tonight passed the whole library suite on the same base (one hit a different, known early crash once). This PR changes where large MEM_64K_PAGES reservations and physical-page homes go (kernelx.rs VirtualAlloc ~957/~991, map_pages ~2645), which is likely what now takes the address the coherent-window restore needs. Run cargo test -p xcl --lib -- --test-threads=4 on the merge and fix the reservation that lands in the window before anything else.
  2. Async upload makes the next submit sample old texels. upload_all (title_textures.rs ~3081) now calls async_upload::partition (async_texture_upload.rs ~522), which takes every non-target, fully mapped texture of 64 KiB to 16 MiB out of the current submit's uploads and hands it to xcl-texture-prepare. drain (~594) records it only at the start of a later refresh_once on that DIRECT queue, or later still when the queue is full (defer_on_full). The command lists of the submit right after the CPU write run with the texture's previous contents (zeros on first use); on the console, and on main, they see the write. The worker also reads title memory while the title goes on writing it, so a snapshot can mix two frames. The README now says "Streamed textures may appear on a later submit". Have the submit wait for the textures it needs (or prepare them inline), or keep XCL_ASYNC_TEX_UPLOAD opt-in.

High

  1. E2E and unit tests loosened to wait for the late upload. tests/testtitle/src/gpu.rs ~888 replaces the single read_back after the first submit with read_back_settled, which retries for up to 2 s; the title_textures.rs tests replace refresh() with refresh_and_drain_async (~8059), which calls refresh until has_pending clears, for up to 5 s. The e2e check that the GPU sees new texels on the submit after the write can no longer fail for the change above. The repo forbids weakening an assertion to make a test pass: keep the single read_back.
  2. Level pages on by default with the #3188 aliasing gap open. vram.rs ~1639 turns XCL_TEXTURE_LEVEL_PAGES on by default. place_pages (~4024) still makes every sampled single-slice 2D texture with no flags lazy, and its levels get pages only from non-zero CPU texels (map_levels_with_texels_in, title_textures.rs ~3160). A sampled texture placed over a live render target, depth buffer or UAV (the case #3188 described; closed 2026-12-02 without a fix) has zero CPU texels, gets no pages and reads zeros instead of what the GPU rendered. Handle that case before turning it on, or keep the default off.
  3. Six default-on changes in 6,200 lines with no reason it cannot be split. Four commits, each its own feature with its own switch (XCL_PHYS_HOME_PLAIN; XCL_RESIDENCY_TRIM with XCL_ALLOC_RETIRE_RESETS, XCL_DEPTH_UAV_SHARE and XCL_SCRATCH_POOL_TRIM; the XCL_TEXTURE_LEVEL_PAGES default and XCL_MIP_DEMOTE; XCL_ASYNC_TEX_UPLOAD), plus a global allocator and new memory-report parts. The description says shipping them together "keeps ... aligned"; CONTRIBUTING asks a PR over ~800 lines to say why it cannot be split, and these commits already stand alone. Open them as stacked PRs (plain homes and residency trim first), with the diagnostics separate.

Medium

  1. MapTitlePhysicalPages(NULL) can return the title's own mapping. kernelx.rs map_pages ~2645: with a plain home, a NULL map of pages that are already mapped contiguously anywhere in UMA returns that address (away.page), which can be an address the title chose itself, e.g. inside its MEM_GRAPHICS reservation. When the title later maps other pages there, the pointer it got from the NULL map shows those pages. Limit the shortcut to null_maps slots.
  2. The NULL-map home tests now pass the home address. kernelx.rs check_home (~4490) and the tests at ~4663 and ~5224 now pass the home address instead of NULL, because NULL no longer returns the home with plain homes. Nothing tests NULL returning the home with XCL_PHYS_HOME_PLAIN=0 (the opt-out), and the new plain-home NULL test does nothing without UMA and does not call skip_test. Add a test for the =0 path.
  3. The opt-out does not restore main for >4 GiB 64K reservations. kernelx.rs VirtualAlloc ~957 and ~991: every MEM_64K_PAGES reservation bigger than uma::WINDOW now goes to write-watched plain memory, also with XCL_PHYS_HOME_PLAIN=0 (the condition does not check the switch), so =0 does not bring back main's placement. Measured on one title for 60 s. Tie it to the switch, or say so in the README.
  4. The pressure-trim test changes process-wide state in the shared lib binary. residency.rs ~423 forced_pressure_passes_exercise_all_trim_paths runs a Critical pass. It empties the global bind, texture_upload, readback and scratch pools, trims depth twins and allocators, and sets dispatch_chain pressure 2 and the spare-pool limit 0 for every test running at the same time with --test-threads=4 (the cross-test interference #3743 works around). It returns without skip_test when no device can be made and checks nothing after the Elevated pass. Run it in a child process or under a lock, and call skip_test.
  5. The pressure paths never ran on a title. The 60 s smoke stays at Normal pressure (6.3 GB local VRAM on a 16 GB card), so the Elevated and Critical trims, twin unmapping, the smaller compute-split budgets (dispatch_chain.rs ~514 effective_budgets) and demotion never ran on a title. Allocator retirement every 256 resets is on by default and its re-creation cost is not reported. Say so under Not tested, or measure on a card near its budget.
  6. Rust heap counter is a global allocator outside the four changes. main.rs ~1-80 adds a #[global_allocator] wrapper to xcl.exe for a memory-report line. It belongs to none of the four changes in the title, reads XCL_ACTIVITY once at the process's first allocation, and no test runs it (the lib tests do not use main.rs). Diagnostics go in their own PR.
  7. No issue link, and open overlapping PRs not named. There is no Fixes/Part of #N. The overlap list leaves out #2905 (physical page homes; it changes alloc_physical_home too), #3742 (sparse physical-page heaps through the L0 budget), #3098 and #2385 (dropping top mips under the VRAM budget, as XCL_MIP_DEMOTE does) and #3740.

Nit

  1. The first commit drops the sparse release notice until the last. 21bded11f replaces source_going(a, n, true, || ()) in VirtualFree's UMA branch with a bare u.free(a); f2d90737 restores it as source_going(.., || u.free(a)). The first three commits on their own release a paired view without telling sparse, so they do not each stand for bisect. Fold the fix into 21bded11f.
  2. Out-of-date doc comment for level pages. vram.rs ~1625 still says "XCL_TEXTURE_LEVEL_PAGES=1 (off by default)", and the log line names =1, though it is now on unless =0.
  3. allocation_len walks every region on a whole release. kernelx.rs ~1205: every VirtualFree(addr, 0, MEM_RELEASE) of plain memory now sizes the allocation with one VirtualQuery per region, which is many calls for a large pool with many commit/reserve runs. It is only needed while the async worker is reading.
Checked and fine
  • Merges cleanly into origin/main 078358a0; smoke blocks name 078358a0 and f2d90737: 1636 vs 1711 frames (96 %), peak commit 18670 vs 16563 MB (113 %), no removals or crashes
  • GPU-written lazy textures get all their levels mapped before the write (capture_gpu_write, title_textures.rs ~1091) and on remap (~1243)
  • SourceGuardState: the worker checks TEXTURES before begin_read, the free guard blocks overlapping reads and cancels stale snapshots, and its test covers overlapping, disjoint and zero-length frees
  • Depth-twin trimming decides and unmaps under Cell::inner and skips planes in UAV, planes entered, and twins of buffers made in COMMON or UNORDERED_ACCESS
  • Table::insert/remove and TilePool test edits adapt to the new UnmapScope and HeapClass types and keep their checks; the only changed assertions are the NULL-map ones above
  • AI use names Claude Code with Claude Opus 5.5 and Antigravity with Gemini 4 Neon; neither is a model the rules refuse
How this was tested
  • Merged onto main 078358a0, then cargo build --workspace and cargo test --workspace --no-fail-fast -- --test-threads=4.
  • The skipped GPU tests are those this card can't run (no wave64 on NVIDIA, no D3D12 debug layer, and similar).
  • scripts/smoke.ps1: 60 s of a retail title on main 078358a0 and on this merge; presents per 2 s at the end: 61 60 60.
  • Title run: the release build of this merge launched the retail title with XCL_RUN_SECONDS=300 and scripted A presses counted from the first frame (XCL_PRESS_BASE=frame, #3712) into the world from an existing save; time in the world is counted from the first in-world draw call to the end of the run.

Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.

<!-- greyfinch-sync:ivall/xcl:comment:7371851879 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3747#issuecomment-7371851879). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-03T08:07:27Z. --- merge-check base: 078358a058f7ba5d16690dba8dc4e55d2c88ae0a head: f2d907371549ce726463e67224d1967f1d536461 merge: clean build: ok tests: did not finish: the `-p xcl --lib` binary aborted after 152 tests in both of two runs (finding 1); the other test binaries passed review: 2 critical, 3 high, 7 medium, 3 nits (below) performance: 60 s smoke run: 1669 → 1602 frames (95 % of main), peak commit 17577 → 19789 MB, no device removal, no crash title run: retail title on the RTX 5070 Ti (driver 621.14), into the world by scripted presses: 234 s there, 0 device removals, 0 crashes, 2.2 presents/s; run with `XCL_SKIP_CS=95cc13288a27a96e` (the NVIDIA hang at the end of loading, #3541) and NVIDIA's 2048 MB shader heap (#2590) verdict: not yet: 2 critical findings (the library test binary aborts at the same point in both runs on this merge, and async texture uploads let the next submit sample old texels) and 3 high (below) hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5 --- **In short:** Six default-on VRAM and upload changes in one PR (plain physical-page homes; residency trimming with allocator retirement, shared depth twins and scratch trimming; lazy level pages turned on by default with mip-class heaps; async texture preparation), plus a Rust heap counting allocator: about 5,900 lines added. Reading the code: the async worker takes eligible textures out of the submit that follows the CPU write, so that submit's GPU work samples old texels, and the e2e and unit tests were changed to retry until the upload lands; level pages go on by default with the aliasing gap #3188 found still open. The async latency, the loosened tests, the aliasing gap and the size block it. #### Critical 1. **The library test binary aborts at the same point in both runs.** On this merge the `-p xcl --lib` test binary stopped after 152 tests in two separate runs on an RTX 5070 Ti, both times right after the vram tests, with "coherent window could not be restored at 0x... (268435456 bytes, got 0x0, Windows error 487) after segment 2 (64 MB CUSTOM): Map gave 0x..., wanted 0x...; stopping before guest memory is used". Every other PR tonight passed the whole library suite on the same base (one hit a different, known early crash once). This PR changes where large MEM_64K_PAGES reservations and physical-page homes go (kernelx.rs VirtualAlloc ~957/~991, map_pages ~2645), which is likely what now takes the address the coherent-window restore needs. Run `cargo test -p xcl --lib -- --test-threads=4` on the merge and fix the reservation that lands in the window before anything else. 2. **Async upload makes the next submit sample old texels.** upload_all (title_textures.rs ~3081) now calls async_upload::partition (async_texture_upload.rs ~522), which takes every non-target, fully mapped texture of 64 KiB to 16 MiB out of the current submit's uploads and hands it to xcl-texture-prepare. drain (~594) records it only at the start of a later refresh_once on that DIRECT queue, or later still when the queue is full (defer_on_full). The command lists of the submit right after the CPU write run with the texture's previous contents (zeros on first use); on the console, and on main, they see the write. The worker also reads title memory while the title goes on writing it, so a snapshot can mix two frames. The README now says "Streamed textures may appear on a later submit". Have the submit wait for the textures it needs (or prepare them inline), or keep XCL_ASYNC_TEX_UPLOAD opt-in. #### High 3. **E2E and unit tests loosened to wait for the late upload.** tests/testtitle/src/gpu.rs ~888 replaces the single read_back after the first submit with read_back_settled, which retries for up to 2 s; the title_textures.rs tests replace refresh() with refresh_and_drain_async (~8059), which calls refresh until has_pending clears, for up to 5 s. The e2e check that the GPU sees new texels on the submit after the write can no longer fail for the change above. The repo forbids weakening an assertion to make a test pass: keep the single read_back. 4. **Level pages on by default with the #3188 aliasing gap open.** vram.rs ~1639 turns XCL_TEXTURE_LEVEL_PAGES on by default. place_pages (~4024) still makes every sampled single-slice 2D texture with no flags lazy, and its levels get pages only from non-zero CPU texels (map_levels_with_texels_in, title_textures.rs ~3160). A sampled texture placed over a live render target, depth buffer or UAV (the case #3188 described; closed 2026-12-02 without a fix) has zero CPU texels, gets no pages and reads zeros instead of what the GPU rendered. Handle that case before turning it on, or keep the default off. 5. **Six default-on changes in 6,200 lines with no reason it cannot be split.** Four commits, each its own feature with its own switch (XCL_PHYS_HOME_PLAIN; XCL_RESIDENCY_TRIM with XCL_ALLOC_RETIRE_RESETS, XCL_DEPTH_UAV_SHARE and XCL_SCRATCH_POOL_TRIM; the XCL_TEXTURE_LEVEL_PAGES default and XCL_MIP_DEMOTE; XCL_ASYNC_TEX_UPLOAD), plus a global allocator and new memory-report parts. The description says shipping them together "keeps ... aligned"; CONTRIBUTING asks a PR over ~800 lines to say why it cannot be split, and these commits already stand alone. Open them as stacked PRs (plain homes and residency trim first), with the diagnostics separate. #### Medium 6. **MapTitlePhysicalPages(NULL) can return the title's own mapping.** kernelx.rs map_pages ~2645: with a plain home, a NULL map of pages that are already mapped contiguously anywhere in UMA returns that address (away.page), which can be an address the title chose itself, e.g. inside its MEM_GRAPHICS reservation. When the title later maps other pages there, the pointer it got from the NULL map shows those pages. Limit the shortcut to null_maps slots. 7. **The NULL-map home tests now pass the home address.** kernelx.rs check_home (~4490) and the tests at ~4663 and ~5224 now pass the home address instead of NULL, because NULL no longer returns the home with plain homes. Nothing tests NULL returning the home with XCL_PHYS_HOME_PLAIN=0 (the opt-out), and the new plain-home NULL test does nothing without UMA and does not call skip_test. Add a test for the =0 path. 8. **The opt-out does not restore main for >4 GiB 64K reservations.** kernelx.rs VirtualAlloc ~957 and ~991: every MEM_64K_PAGES reservation bigger than uma::WINDOW now goes to write-watched plain memory, also with XCL_PHYS_HOME_PLAIN=0 (the condition does not check the switch), so =0 does not bring back main's placement. Measured on one title for 60 s. Tie it to the switch, or say so in the README. 9. **The pressure-trim test changes process-wide state in the shared lib binary.** residency.rs ~423 forced_pressure_passes_exercise_all_trim_paths runs a Critical pass. It empties the global bind, texture_upload, readback and scratch pools, trims depth twins and allocators, and sets dispatch_chain pressure 2 and the spare-pool limit 0 for every test running at the same time with --test-threads=4 (the cross-test interference #3743 works around). It returns without skip_test when no device can be made and checks nothing after the Elevated pass. Run it in a child process or under a lock, and call skip_test. 10. **The pressure paths never ran on a title.** The 60 s smoke stays at Normal pressure (6.3 GB local VRAM on a 16 GB card), so the Elevated and Critical trims, twin unmapping, the smaller compute-split budgets (dispatch_chain.rs ~514 effective_budgets) and demotion never ran on a title. Allocator retirement every 256 resets is on by default and its re-creation cost is not reported. Say so under Not tested, or measure on a card near its budget. 11. **Rust heap counter is a global allocator outside the four changes.** main.rs ~1-80 adds a #[global_allocator] wrapper to xcl.exe for a memory-report line. It belongs to none of the four changes in the title, reads XCL_ACTIVITY once at the process's first allocation, and no test runs it (the lib tests do not use main.rs). Diagnostics go in their own PR. 12. **No issue link, and open overlapping PRs not named.** There is no Fixes/Part of #N. The overlap list leaves out #2905 (physical page homes; it changes alloc_physical_home too), #3742 (sparse physical-page heaps through the L0 budget), #3098 and #2385 (dropping top mips under the VRAM budget, as XCL_MIP_DEMOTE does) and #3740. #### Nit 13. **The first commit drops the sparse release notice until the last.** 21bded11f replaces source_going(a, n, true, || ()) in VirtualFree's UMA branch with a bare u.free(a); f2d90737 restores it as source_going(.., || u.free(a)). The first three commits on their own release a paired view without telling sparse, so they do not each stand for bisect. Fold the fix into 21bded11f. 14. **Out-of-date doc comment for level pages.** vram.rs ~1625 still says "XCL_TEXTURE_LEVEL_PAGES=1 (off by default)", and the log line names =1, though it is now on unless =0. 15. **allocation_len walks every region on a whole release.** kernelx.rs ~1205: every VirtualFree(addr, 0, MEM_RELEASE) of plain memory now sizes the allocation with one VirtualQuery per region, which is many calls for a large pool with many commit/reserve runs. It is only needed while the async worker is reading. <details><summary>Checked and fine</summary> - Merges cleanly into origin/main 078358a0; smoke blocks name 078358a0 and f2d90737: 1636 vs 1711 frames (96 %), peak commit 18670 vs 16563 MB (113 %), no removals or crashes - GPU-written lazy textures get all their levels mapped before the write (capture_gpu_write, title_textures.rs ~1091) and on remap (~1243) - SourceGuardState: the worker checks TEXTURES before begin_read, the free guard blocks overlapping reads and cancels stale snapshots, and its test covers overlapping, disjoint and zero-length frees - Depth-twin trimming decides and unmaps under Cell::inner and skips planes in UAV, planes entered, and twins of buffers made in COMMON or UNORDERED_ACCESS - Table::insert/remove and TilePool test edits adapt to the new UnmapScope and HeapClass types and keep their checks; the only changed assertions are the NULL-map ones above - AI use names Claude Code with Claude Opus 5.5 and Antigravity with Gemini 4 Neon; neither is a model the rules refuse </details> <details><summary>How this was tested</summary> - Merged onto main `078358a0`, then `cargo build --workspace` and `cargo test --workspace --no-fail-fast -- --test-threads=4`. - The skipped GPU tests are those this card can't run (no wave64 on NVIDIA, no D3D12 debug layer, and similar). - `scripts/smoke.ps1`: 60 s of a retail title on main `078358a0` and on this merge; presents per 2 s at the end: 61 60 60. - Title run: the release build of this merge launched the retail title with `XCL_RUN_SECONDS=300` and scripted A presses counted from the first frame (`XCL_PRESS_BASE=frame`, #3712) into the world from an existing save; time in the world is counted from the first in-world draw call to the end of the run. </details> <sub>Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.</sub>
Kalmarv commented 2026-12-03 17:35:25 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Kalmarv on 2026-12-03T17:35:25Z.


Thanks for the thorough merge-check, @Foniass! Rebased onto origin/main e99b0bdfc and pushed 4b00e738b addressing every critical, high, medium, and nit finding (keeping the 4 bisect-clean commits together in this PR):

Critical

  1. Lib test binary abort (error 487): Rebased onto origin/main e99b0bdfc (pulling in #3743 / 864628216, which isolates the mixed-window remake tests in child processes) and isolated our global-state GPU tests (residency::tests::forced_pressure_passes_exercise_all_trim_paths and title_textures::tests::a_cold_first_level_gives_back_its_heap_and_comes_back_when_used) in child processes as well. cargo test -p xcl --lib -- --test-threads=4 now runs all tests to completion with 0 error 487 aborts (2,898 passed; only 1 unrelated pre-existing failure in gpu::dxil::idioms::tests::gpu_split_wave64_uniform_first_lanes_read_what_the_exchange_reads, with 0 diff under crates/xcl/src/gpu/dxil/).
  2. Async upload sampling old texels: Flipped XCL_ASYNC_TEX_UPLOAD to opt-in (=1, default OFF). When off, partition, drain, requeue_deferred_for, forget_queue, wait_if_reading_resource, guard_source_free, and allocation_len all fast-path out, and synchronous texture_upload::submit() passes retain_resources = false so Job::resources never extends destination COM lifetimes on the default path.

High

  1. Loosened tests: Reverted tests/testtitle/src/gpu.rs completely (0 diff vs origin/main, restoring the strict single read_back) and removed refresh_and_drain_async and all reclaim_completed_uploads() test additions from title_textures.rs. All workspace integration tests (including testtitle e2e) pass unmodified.
  2. Level pages default with #3188 open: Flipped XCL_TEXTURE_LEVEL_PAGES back to opt-in (=1, default OFF, matching main), with XCL_MIP_DEMOTE also opt-in (=1).
  3. Keeping the 4 commits in one PR: Kept as a single 4-commit PR rather than splitting (each commit stands cleanly on its own for bisect, with the two opt-in features XCL_TEXTURE_LEVEL_PAGES=1 / XCL_MIP_DEMOTE=1 and XCL_ASYNC_TEX_UPLOAD=1 off by default so the default-on footprint is strictly plain physical homes + residency trimming/shared depth twins).

Medium

  1. MapTitlePhysicalPages(NULL) returning a title-owned mapping: Removed the away.page shortcut in kernelx.rs so NULL maps only reuse dedicated away.null_maps slots, and added a regression assertion verifying MapTitlePhysicalPages(NULL) never returns a title-owned MEM_GRAPHICS reservation.
  2. XCL_PHYS_HOME_PLAIN=0 NULL-map test & skip_test: Added skip_test("no UMA") to the plain-home tests and added child-process test physical_home_plain_opt_out_returns_uma_home_on_null_map (XCL_PHYS_HOME_PLAIN=0, asserting output.status.success() and "1 passed").
  3. > 4 GiB MEM_64K_PAGES overflow tied to opt-out: Both VirtualAlloc overflow checks in kernelx.rs now check phys_home_plain(), so XCL_PHYS_HOME_PLAIN=0 restores main's placement completely; documented in README and Not tested.
  4. Pressure-trim test mutating global state: Isolated forced_pressure_passes_exercise_all_trim_paths in a child process (forwarding SKIPPED lines to stderr and asserting "1 passed"), added skip_test("no D3D12 device"), and asserted that Elevated retains 4 MiB under ELEVATED_POOL_CAP (elev_trimmed == 0) while Critical drains to 0.
  5. Pressure paths / allocator retirement not exercised on title: Explicitly documented under Not tested in the PR description (along with opt-in async/level-page runs).
  6. Global allocator in main.rs: Removed CountingAlloc from crates/xcl/src/main.rs (0 diff vs origin/main) and removed "Rust heap" from memory_report.rs.
  7. Issue link & overlapping PR list: Added Part of #2697 / #3188 context and listed #2905, #3742, #3098, #2385, #3740 alongside the other overlapping PRs in the PR description.

Nits & additional follow-ups from Opus re-review

  1. Commit 1 VirtualFree sparse notice & ordering: Restored origin/main's exact coherent-UMA VirtualFree sequence (source_going -> mirrors::released -> sparse::remapped -> u.free) in commit 1 (68c7466bf), preserving bisect cleanliness and preventing any reuse race before mirrors::released.
  2. Level-pages doc comment & log: Now accurate again with XCL_TEXTURE_LEVEL_PAGES=1 opt-in.
  3. allocation_len overhead: Gated behind async_source_guard_enabled() (XCL_ASYNC_TEX_UPLOAD=1) so VirtualFree/VirtualFreeEx incur zero VirtualQuery walks under default settings.
  • Also fixed two low-severity items caught in Opus re-review: capped shared depth_uav reserved twin tiles to each buffer's console byte size (xg::Texture::size, with least_texture_bytes fallback) so PC overflow tiles stay private, and moved vram::unmap_completion_snapshot() + deferred queue signals/releases outside Cell::inner in depth_uav::trim_idle_twins.

Fresh paired 60 s smoke (e99b0bdfc vs 4b00e738b, RTX 5070 Ti, title: ea3b5e4d)

  • main (e99b0bdfc): 1,342 frames (60 60 60), 15,850 MB peak commit, 6,567 MB local VRAM, 97% texel residency, 0 removals, 0 crashes.
  • PR (4b00e738b): 1,638 frames (60 60 60, 1.22x), 17,592 MB peak commit (1.11x), 6,414 MB local VRAM (-153 MB, 0 MB depth UAV twins), 97% texel residency, 0 async uploads queued (default off), 0 removals, 0 crashes.
<!-- greyfinch-sync:ivall/xcl:comment:7386753250 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/3747#issuecomment-7386753250). Originally posted by [Kalmarv](https://github.com/Kalmarv) on 2026-12-03T17:35:25Z. --- Thanks for the thorough merge-check, @Foniass! Rebased onto `origin/main` `e99b0bdfc` and pushed `4b00e738b` addressing every critical, high, medium, and nit finding (keeping the 4 bisect-clean commits together in this PR): ### Critical 1. **Lib test binary abort (`error 487`):** Rebased onto `origin/main` `e99b0bdfc` (pulling in `#3743` / `864628216`, which isolates the mixed-window remake tests in child processes) and isolated our global-state GPU tests (`residency::tests::forced_pressure_passes_exercise_all_trim_paths` and `title_textures::tests::a_cold_first_level_gives_back_its_heap_and_comes_back_when_used`) in child processes as well. `cargo test -p xcl --lib -- --test-threads=4` now runs all tests to completion with **0 `error 487` aborts** (`2,898` passed; only 1 unrelated pre-existing failure in `gpu::dxil::idioms::tests::gpu_split_wave64_uniform_first_lanes_read_what_the_exchange_reads`, with 0 diff under `crates/xcl/src/gpu/dxil/`). 2. **Async upload sampling old texels:** Flipped `XCL_ASYNC_TEX_UPLOAD` to **opt-in** (`=1`, default OFF). When off, `partition`, `drain`, `requeue_deferred_for`, `forget_queue`, `wait_if_reading_resource`, `guard_source_free`, and `allocation_len` all fast-path out, and synchronous `texture_upload::submit()` passes `retain_resources = false` so `Job::resources` never extends destination COM lifetimes on the default path. ### High 3. **Loosened tests:** Reverted `tests/testtitle/src/gpu.rs` completely (0 diff vs `origin/main`, restoring the strict single `read_back`) and removed `refresh_and_drain_async` and all `reclaim_completed_uploads()` test additions from `title_textures.rs`. All workspace integration tests (including `testtitle` e2e) pass unmodified. 4. **Level pages default with `#3188` open:** Flipped `XCL_TEXTURE_LEVEL_PAGES` back to **opt-in** (`=1`, default OFF, matching `main`), with `XCL_MIP_DEMOTE` also opt-in (`=1`). 5. **Keeping the 4 commits in one PR:** Kept as a single 4-commit PR rather than splitting (each commit stands cleanly on its own for bisect, with the two opt-in features `XCL_TEXTURE_LEVEL_PAGES=1` / `XCL_MIP_DEMOTE=1` and `XCL_ASYNC_TEX_UPLOAD=1` off by default so the default-on footprint is strictly plain physical homes + residency trimming/shared depth twins). ### Medium 6. **`MapTitlePhysicalPages(NULL)` returning a title-owned mapping:** Removed the `away.page` shortcut in `kernelx.rs` so `NULL` maps only reuse dedicated `away.null_maps` slots, and added a regression assertion verifying `MapTitlePhysicalPages(NULL)` never returns a title-owned `MEM_GRAPHICS` reservation. 7. **`XCL_PHYS_HOME_PLAIN=0` NULL-map test & `skip_test`:** Added `skip_test("no UMA")` to the plain-home tests and added child-process test `physical_home_plain_opt_out_returns_uma_home_on_null_map` (`XCL_PHYS_HOME_PLAIN=0`, asserting `output.status.success()` and `"1 passed"`). 8. **`> 4 GiB` `MEM_64K_PAGES` overflow tied to opt-out:** Both `VirtualAlloc` overflow checks in `kernelx.rs` now check `phys_home_plain()`, so `XCL_PHYS_HOME_PLAIN=0` restores `main`'s placement completely; documented in README and **Not tested**. 9. **Pressure-trim test mutating global state:** Isolated `forced_pressure_passes_exercise_all_trim_paths` in a child process (forwarding `SKIPPED` lines to stderr and asserting `"1 passed"`), added `skip_test("no D3D12 device")`, and asserted that `Elevated` retains 4 MiB under `ELEVATED_POOL_CAP` (`elev_trimmed == 0`) while `Critical` drains to `0`. 10. **Pressure paths / allocator retirement not exercised on title:** Explicitly documented under **Not tested** in the PR description (along with opt-in async/level-page runs). 11. **Global allocator in `main.rs`:** Removed `CountingAlloc` from `crates/xcl/src/main.rs` (0 diff vs `origin/main`) and removed `"Rust heap"` from `memory_report.rs`. 12. **Issue link & overlapping PR list:** Added `Part of #2697` / `#3188` context and listed `#2905`, `#3742`, `#3098`, `#2385`, `#3740` alongside the other overlapping PRs in the PR description. ### Nits & additional follow-ups from Opus re-review 13. **Commit 1 `VirtualFree` sparse notice & ordering:** Restored `origin/main`'s exact coherent-UMA `VirtualFree` sequence (`source_going` -> `mirrors::released` -> `sparse::remapped` -> `u.free`) in commit 1 (`68c7466bf`), preserving bisect cleanliness and preventing any reuse race before `mirrors::released`. 14. **Level-pages doc comment & log:** Now accurate again with `XCL_TEXTURE_LEVEL_PAGES=1` opt-in. 15. **`allocation_len` overhead:** Gated behind `async_source_guard_enabled()` (`XCL_ASYNC_TEX_UPLOAD=1`) so `VirtualFree`/`VirtualFreeEx` incur zero `VirtualQuery` walks under default settings. - Also fixed two low-severity items caught in Opus re-review: capped shared `depth_uav` reserved twin tiles to each buffer's console byte size (`xg::Texture::size`, with `least_texture_bytes` fallback) so PC overflow tiles stay private, and moved `vram::unmap_completion_snapshot()` + deferred queue signals/releases outside `Cell::inner` in `depth_uav::trim_idle_twins`. ### Fresh paired 60 s smoke (`e99b0bdfc` vs `4b00e738b`, RTX 5070 Ti, `title: ea3b5e4d`) - `main` (`e99b0bdfc`): `1,342` frames (`60 60 60`), `15,850 MB` peak commit, `6,567 MB` local VRAM, `97%` texel residency, `0` removals, `0` crashes. - PR (`4b00e738b`): `1,638` frames (`60 60 60`, `1.22x`), `17,592 MB` peak commit (`1.11x`), `6,414 MB` local VRAM (`-153 MB`, `0 MB` depth UAV twins), `97%` texel residency, `0` async uploads queued (default off), `0` removals, `0` crashes.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3747:upstream-pr/3747'
git switch 'upstream-pr/3747'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/3747'
git switch 'upstream-pr/3747'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3747'
git switch 'upstream-pr/3747'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3747'
git switch 'main'
git merge --squash 'upstream-pr/3747'
git switch 'main'
git merge --ff-only 'upstream-pr/3747'
git switch 'main'
git merge 'upstream-pr/3747'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
xcl-dev/xcl!3747
No description provided.