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

Merged
raylitebull merged 1 commit from upstream-pr/99 into main 2026-11-23 11:25:27 +00:00
raylitebull commented 2026-11-23 11:11:15 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by raylitebull on 2026-11-23T11:11:15Z.


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).
<!-- greyfinch-sync:ivall/xcl:issue:5451944211 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/99). Originally posted by [raylitebull](https://github.com/raylitebull) on 2026-11-23T11:11:15Z. --- ## 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).
upstream-sync closed this pull request 2026-11-24 06:57:09 +00:00
ivall commented 2026-11-24 07:00:28 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by ivall on 2026-11-23T11:25:44Z.


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!

<!-- greyfinch-sync:ivall/xcl:comment:7099631361 --> Imported from [ivall/xcl](https://github.com/ivall/xcl/pull/99#issuecomment-7099631361). Originally posted by [ivall](https://github.com/ivall) on 2026-11-23T11:25:44Z. --- 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!
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!98
No description provided.