d3d12: keep a large guest view heap in smaller CPU heaps #399

Merged
KainanP merged 1 commit from upstream-pr/399 into main 2026-11-28 15:07:14 +00:00
KainanP commented 2026-11-28 14:29:35 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by KainanP on 2026-11-28T14:29:35Z.


lanes-selftest-descriptor-reclaim fails on an Intel UHD (8086:a78b) with create oversized view heap failed: 0x8007000e (it is the failing gate in evidence/windows11-uhd-a78b-native.json).

Cause

A paged guest view heap keeps every slot's native view in a CPU-only heap, made as large as the guest heap in one piece. The scenario's heap has 2,097,152 descriptors. A small probe measured the limits. On this UHD driver, CreateDescriptorHeap for a non-shader-visible CBV/SRV/UAV heap returns E_OUTOFMEMORY at 2,097,152 descriptors and succeeds at 1,048,576. The RTX 4060 Laptop takes up to 4,194,304. No feature query reports the limit.

The guest heap really does need all 2,097,152 slots, so a smaller single heap would not be correct.

Change

  • descriptor_paging/staging.rs:
    • Asks for the whole CPU heap first. While the host refuses for memory, it asks for half, down to 65,536 descriptors, then covers the guest heap with heaps of the size that worked.
    • A slot's CPU handle is found by chunk and offset (Chunks::handle).
    • Arena::copy splits a table copy where chunks end (Chunks::runs).
    • Only E_OUTOFMEMORY shrinks the chunks.
    • A host that takes the whole heap keeps one heap, as before.
    • An arena that isn't shader-visible uses its CPU heap as the visible heap, so it is never split.
  • Each chunk registers its own ranges with the imported, placed, scene and stride maps, so they're cleared when the arena goes.
  • TUXBOX_HOST_PROFILE=cpu-view-heap=N refuses larger CPU view heaps with E_OUTOFMEMORY, the way such a driver does. verify runs descriptor-reclaim a second time, as lanes-selftest-descriptor-reclaim-split, with cpu-view-heap=1048576. That puts any card on the path the UHD takes.
  • Unit tests:
    • halving and chunk sizes, including a count that isn't a power of two;
    • only a memory refusal of a splittable heap is retried;
    • the floor;
    • handle and run math across chunk boundaries;
    • parsing of the new setting.

The path is chosen by what the host refuses, not by vendor.

Tests (Windows 11, native)

The verify runs used --only lanes-selftest --only d3d12-heaps --only d3d12-tables.

Intel UHD 8086:a78b RTX 4060 Laptop 10de:28a0
lanes-selftest-descriptor-reclaim before FAIL 0x8007000e PASS
lanes-selftest-descriptor-reclaim after PASS PASS
lanes-selftest-descriptor-reclaim-split (new) PASS PASS
d3d12-heaps, d3d12-tables PASS PASS
rest of lanes-selftest PASS except ray-tracing-builder (no ray tracing on this card, fails on main too) PASS

Checking the override on the RTX:

  • TUXBOX_HOST_PROFILE=cpu-view-heap=1000 is below the smallest chunk. It reproduces the UHD failure exactly: create oversized view heap failed: 0x8007000e.
  • cpu-view-heap=100000 splits the heap into 32 chunks of 65,536, and the gate passes.

cargo test -p tuxbox-d3d12 --lib: 241 passed. The 4 heap::backing tests that fail also fail on main on this machine.

Still needed: a run on an AMD card. This changes runtime/d3d12, and I have only tested Intel and NVIDIA.

AI use: written with Claude Code (Claude Opus 5.5); the limits were measured and the tests run on the hardware above.

🤖 Generated with Claude Code

<!-- greyfinch-sync:brcly/TuxBox:issue:5541155154 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/399). Originally posted by [KainanP](https://github.com/KainanP) on 2026-11-28T14:29:35Z. --- `lanes-selftest-descriptor-reclaim` fails on an Intel UHD (8086:a78b) with `create oversized view heap failed: 0x8007000e` (it is the failing gate in `evidence/windows11-uhd-a78b-native.json`). ## Cause A paged guest view heap keeps every slot's native view in a CPU-only heap, made as large as the guest heap in one piece. The scenario's heap has 2,097,152 descriptors. A small probe measured the limits. On this UHD driver, `CreateDescriptorHeap` for a non-shader-visible CBV/SRV/UAV heap returns `E_OUTOFMEMORY` at 2,097,152 descriptors and succeeds at 1,048,576. The RTX 4060 Laptop takes up to 4,194,304. No feature query reports the limit. The guest heap really does need all 2,097,152 slots, so a smaller single heap would not be correct. ## Change - `descriptor_paging/staging.rs`: - Asks for the whole CPU heap first. While the host refuses for memory, it asks for half, down to 65,536 descriptors, then covers the guest heap with heaps of the size that worked. - A slot's CPU handle is found by chunk and offset (`Chunks::handle`). - `Arena::copy` splits a table copy where chunks end (`Chunks::runs`). - Only `E_OUTOFMEMORY` shrinks the chunks. - A host that takes the whole heap keeps one heap, as before. - An arena that isn't shader-visible uses its CPU heap as the visible heap, so it is never split. - Each chunk registers its own ranges with the imported, placed, scene and stride maps, so they're cleared when the arena goes. - `TUXBOX_HOST_PROFILE=cpu-view-heap=N` refuses larger CPU view heaps with `E_OUTOFMEMORY`, the way such a driver does. `verify` runs `descriptor-reclaim` a second time, as `lanes-selftest-descriptor-reclaim-split`, with `cpu-view-heap=1048576`. That puts any card on the path the UHD takes. - Unit tests: - halving and chunk sizes, including a count that isn't a power of two; - only a memory refusal of a splittable heap is retried; - the floor; - handle and run math across chunk boundaries; - parsing of the new setting. The path is chosen by what the host refuses, not by vendor. ## Tests (Windows 11, native) The `verify` runs used `--only lanes-selftest --only d3d12-heaps --only d3d12-tables`. | | Intel UHD 8086:a78b | RTX 4060 Laptop 10de:28a0 | | --- | --- | --- | | `lanes-selftest-descriptor-reclaim` before | FAIL `0x8007000e` | PASS | | `lanes-selftest-descriptor-reclaim` after | PASS | PASS | | `lanes-selftest-descriptor-reclaim-split` (new) | PASS | PASS | | `d3d12-heaps`, `d3d12-tables` | PASS | PASS | | rest of `lanes-selftest` | PASS except `ray-tracing-builder` (no ray tracing on this card, fails on main too) | PASS | Checking the override on the RTX: - `TUXBOX_HOST_PROFILE=cpu-view-heap=1000` is below the smallest chunk. It reproduces the UHD failure exactly: `create oversized view heap failed: 0x8007000e`. - `cpu-view-heap=100000` splits the heap into 32 chunks of 65,536, and the gate passes. `cargo test -p tuxbox-d3d12 --lib`: 241 passed. The 4 `heap::backing` tests that fail also fail on main on this machine. **Still needed:** a run on an AMD card. This changes `runtime/d3d12`, and I have only tested Intel and NVIDIA. _AI use: written with Claude Code (Claude Opus 5.5); the limits were measured and the tests run on the hardware above._ 🤖 Generated with [Claude Code](https://claude.com/claude-code)
KainanP commented 2026-11-28 15:12:00 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by KainanP on 2026-11-28T15:12:00Z.


I rebased this onto main (e380da1). The only conflict was in verify.py: main now picks the BVH builder for every ray-tracing-* scenario. I kept that and left the new descriptor-reclaim-split gate where it was.

Rerun after the rebase on Windows 11, native backend. The build includes #400, because build.py all stops at the xcrdapi warning otherwise:

  • RTX 4060 Laptop (10de:28a0) and Intel UHD (8086:a78b): d3d12-heaps, d3d12-tables, lanes-selftest-descriptor-reclaim and lanes-selftest-descriptor-reclaim-split all pass.
  • cargo test -p tuxbox-d3d12 --lib -- --test-threads=1: 280 passed, 5 failed. The 5 failures are the same on main without this PR (275 passed, 5 failed): four in device::heap::backing and one in device::placement::residency (gpu_images_without_room_use_system_memory_and_keep_their_contents). The descriptor-paging and host-profile tests this PR adds all pass.

AI use: Claude Code did the rebase and ran the checks.

<!-- greyfinch-sync:brcly/TuxBox:comment:7241280557 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/399#issuecomment-7241280557). Originally posted by [KainanP](https://github.com/KainanP) on 2026-11-28T15:12:00Z. --- I rebased this onto main (`e380da1`). The only conflict was in `verify.py`: main now picks the BVH builder for every `ray-tracing-*` scenario. I kept that and left the new `descriptor-reclaim-split` gate where it was. Rerun after the rebase on Windows 11, native backend. The build includes #400, because `build.py all` stops at the xcrdapi warning otherwise: - RTX 4060 Laptop (`10de:28a0`) and Intel UHD (`8086:a78b`): `d3d12-heaps`, `d3d12-tables`, `lanes-selftest-descriptor-reclaim` and `lanes-selftest-descriptor-reclaim-split` all pass. - `cargo test -p tuxbox-d3d12 --lib -- --test-threads=1`: 280 passed, 5 failed. The 5 failures are the same on main without this PR (275 passed, 5 failed): four in `device::heap::backing` and one in `device::placement::residency` (`gpu_images_without_room_use_system_memory_and_keep_their_contents`). The descriptor-paging and host-profile tests this PR adds all pass. _AI use: Claude Code did the rebase and ran the checks._
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
brcly/TuxBox!399
No description provided.