D3D12.X: fix sparse buffer uncommitted holes, sub-tile VRAM reclaim, query delta, and heap/DMA leaks #99

Manually merged
github merged 1 commit from gh-pr/99/head into gh-pr/99/base 2026-11-26 04:10:02 +00:00
Owner

@⁠raylitebull on GitHub · 2026-11-23 11:11 UTC · original
raylitebull:fix/d3d12x-sparse-offsets-and-heaps → main · +678 −81 · 3 files · 1 commits · merged 2026-11-23 11:25 UTC

Summary

Fixes 6 bugs in sparse UMA page tracking, placed-buffer offsets, descriptor heap remapping, and DMA command list cleanup in crates/xcl/src/hle/d3d12x/{sparse.rs, list_x.rs, real.rs}:

  1. sparse::place_buffer uncommitted page hole mask (sparse.rs):

    • place_buffer previously called ensure_mapped with holes = 0 for all 64 KiB tiles covering [start, va + bytes), even when pages in that range were still uncommitted (MEM_RESERVE/PAGE_NOACCESS), causing readback_now/readback_ranges to access-violate on uncommitted pages.
    • Added query_tile_holes(tile) via VirtualQuery over each 64 KiB tile for place_buffer, while committed() initializes newly mapped tiles to 0xFFFF and clears holes for [a, a + n).
  2. sparse::decommitted sub-tile VRAM pool tile reclamation (sparse.rs):

    • Extracted decommit_tiles() so incremental sub-tile decommits (e.g. 2 × 32 KiB or 16 × 4 KiB) reclaim and unmap the 64 KiB pool tile back to s.free as soon as entry.holes == 0xFFFF, pruning stale s.to_zero entries.
  3. ResolveQueryData (#30) applying buffer_delta(dest) (list_x.rs):

    • Added real::buffer_delta(dest) to offset in resolve_query_data_x for both PC ResolveQueryData and nested occlusion WriteBufferImmediate writebacks, fixing misaligned query writes on non-64 KiB-aligned placed buffers.
  4. place_console_buffer coherent fallback state & flags sanitization (real.rs):

    • Added sanitize_coherent_buffer() to mask d.Flags with 0xFF before OR-ing ALLOW_CROSS_ADAPTER and mask state with PC_RESOURCE_STATES on the coherent fallback path (matching the sparse path).
  5. CopyDescriptors / CopyDescriptorsSimple remapping XBOX_EXTRA_CBV_SRV_UAV (real.rs):

    • Added pc_heap_type(ty) mapping XBOX_EXTRA_CBV_SRV_UAV (4) -> CBV_SRV_UAV (0) across dev_create_descriptor_heap_x, dev_increment_size_x, copy_console_slots, dev_copy_descriptors_simple_x, and dev_copy_descriptors_x.
  6. Kind::DmaList Release / Close / Reset overrides (real.rs):

    • Added Kind::DmaList to overrides() so releasing a DMA command list removes its list_x::LISTS entry and decrements fast-path counters instead of leaking permanently.

Testing

  • Added 7 targeted unit and D3D12 integration tests covering all 6 fixes:
    • query_tile_holes_detects_reserved_noaccess_and_committed_pages
    • ensure_mapped_with_query_holes_skips_uncommitted_pages_on_readback
    • decommit_sub_tile_reclaims_pool_tile_when_all_pages_become_holes
    • resolve_query_data_applies_buffer_delta_to_pc_resolve_and_occlusion_writeback
    • coherent_buffer_sanitizes_console_flags_and_state
    • copy_descriptors_remaps_xbox_extra_cbv_srv_uav_to_pc_enum
    • dma_list_release_cleans_up_list_state
  • GPU / Driver: AMD Radeon RX 9070 XT, driver 32.0.32015.2008 (sparse/coherence D3D12 tests verified on AMD only).
  • Verified after rebasing onto origin/main (60599a9): cargo build --workspace and cargo test --workspace -- --test-threads=4 pass (466 passed, 0 failed, 36 ignored, 0 new warnings).
**@⁠raylitebull** on GitHub · 2026-11-23 11:11 UTC · [original](https://github.com/xcl-dev/xcl/pull/99) `raylitebull:fix/d3d12x-sparse-offsets-and-heaps` → `main` · +678 −81 · 3 files · 1 commits · merged 2026-11-23 11:25 UTC ## Summary Fixes 6 bugs in sparse UMA page tracking, placed-buffer offsets, descriptor heap remapping, and DMA command list cleanup in `crates/xcl/src/hle/d3d12x/{sparse.rs, list_x.rs, real.rs}`: 1. **`sparse::place_buffer` uncommitted page hole mask (`sparse.rs`):** - `place_buffer` previously called `ensure_mapped` with `holes = 0` for all 64 KiB tiles covering `[start, va + bytes)`, even when pages in that range were still uncommitted (`MEM_RESERVE`/`PAGE_NOACCESS`), causing `readback_now`/`readback_ranges` to access-violate on uncommitted pages. - Added `query_tile_holes(tile)` via `VirtualQuery` over each 64 KiB tile for `place_buffer`, while `committed()` initializes newly mapped tiles to `0xFFFF` and clears holes for `[a, a + n)`. 2. **`sparse::decommitted` sub-tile VRAM pool tile reclamation (`sparse.rs`):** - Extracted `decommit_tiles()` so incremental sub-tile decommits (e.g. 2 × 32 KiB or 16 × 4 KiB) reclaim and unmap the 64 KiB pool tile back to `s.free` as soon as `entry.holes == 0xFFFF`, pruning stale `s.to_zero` entries. 3. **`ResolveQueryData` (#30) applying `buffer_delta(dest)` (`list_x.rs`):** - Added `real::buffer_delta(dest)` to `offset` in `resolve_query_data_x` for both PC `ResolveQueryData` and nested occlusion `WriteBufferImmediate` writebacks, fixing misaligned query writes on non-64 KiB-aligned placed buffers. 4. **`place_console_buffer` coherent fallback state & flags sanitization (`real.rs`):** - Added `sanitize_coherent_buffer()` to mask `d.Flags` with `0xFF` before OR-ing `ALLOW_CROSS_ADAPTER` and mask `state` with `PC_RESOURCE_STATES` on the coherent fallback path (matching the sparse path). 5. **`CopyDescriptors` / `CopyDescriptorsSimple` remapping `XBOX_EXTRA_CBV_SRV_UAV` (`real.rs`):** - Added `pc_heap_type(ty)` mapping `XBOX_EXTRA_CBV_SRV_UAV` (`4`) -> `CBV_SRV_UAV` (`0`) across `dev_create_descriptor_heap_x`, `dev_increment_size_x`, `copy_console_slots`, `dev_copy_descriptors_simple_x`, and `dev_copy_descriptors_x`. 6. **`Kind::DmaList` `Release` / `Close` / `Reset` overrides (`real.rs`):** - Added `Kind::DmaList` to `overrides()` so releasing a DMA command list removes its `list_x::LISTS` entry and decrements fast-path counters instead of leaking permanently. ## Testing - Added 7 targeted unit and D3D12 integration tests covering all 6 fixes: - `query_tile_holes_detects_reserved_noaccess_and_committed_pages` - `ensure_mapped_with_query_holes_skips_uncommitted_pages_on_readback` - `decommit_sub_tile_reclaims_pool_tile_when_all_pages_become_holes` - `resolve_query_data_applies_buffer_delta_to_pc_resolve_and_occlusion_writeback` - `coherent_buffer_sanitizes_console_flags_and_state` - `copy_descriptors_remaps_xbox_extra_cbv_srv_uav_to_pc_enum` - `dma_list_release_cleans_up_list_state` - **GPU / Driver:** AMD Radeon RX 9070 XT, driver `32.0.32015.2008` (sparse/coherence D3D12 tests verified on AMD only). - Verified after rebasing onto `origin/main` (`60599a9`): `cargo build --workspace` and `cargo test --workspace -- --test-threads=4` pass (466 passed, 0 failed, 36 ignored, 0 new warnings).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:10:01 +00:00
github manually merged commit 3885b86d98 into gh-pr/99/base 2026-11-26 04:10:02 +00:00
Author
Owner

@⁠ivall on GitHub · 2026-11-23 11:25 UTC · original

Merged together with #95–#102 and checked on Windows 11 with an RX 9070: cargo test --workspace green with the retail samples (shader pack, console DLLs, texture archive), lib tests also with XCL_SPLIT_WAVE64=1; XDefiant (title screen, a scripted A reaches its "Xbox network unavailable" dialog), Unicorn Overlord and Minecraft run. Thanks!

**@⁠ivall** on GitHub · 2026-11-23 11:25 UTC · [original](https://github.com/xcl-dev/xcl/pull/99#issuecomment-7099631361) Merged together with #95–#102 and checked on Windows 11 with an RX 9070: `cargo test --workspace` green with the retail samples (shader pack, console DLLs, texture archive), lib tests also with `XCL_SPLIT_WAVE64=1`; XDefiant (title screen, a scripted A reaches its "Xbox network unavailable" dialog), Unicorn Overlord and Minecraft run. Thanks!
This discussion has been locked. Commenting is limited to contributors.
No description provided.