[Ready to merge] GPU: Graceful degradation and dynamic recycling for descriptor heaps exceeding 1,000,000 slots #902

Open
opened 2026-11-26 04:14:08 +00:00 by github-bot · 5 comments
Owner

@⁠Xvania7 on GitHub · 2026-11-24 13:50 UTC · original

Fixes #887 (related to #871, #876, #562).

Problem

After #876 resolved the black screen cutscenes, titles requesting large descriptor heaps (e.g. 1,245,184 views on GTA VI world load) run into the D3D12 Tier 1/2 hardware limit of 1,000,000 shader-visible descriptors:

HostHeap::new() attempts to allocate count + DYNAMIC and count + MIN_DYNAMIC, both of which fail with E_INVALIDARG (0x80070057) because the size exceeds 1,000,000.
The cap fallback previously gave only MIN_DYNAMIC (65,536) slots to dynamic tables and 934,464 to title views.
Under heavy world frames (3,300–5,500 draws/dispatches), 65,536 dynamic slots were rapidly exhausted. HostHeap::dynamic() returned None, causing draw.rs to drop passes (a draw or dispatch dropped: no dynamic slots for its tables reaching dropped=65536). Dropped compute dispatches and render passes ultimately led to null-pointer crashes (0xc0000005 write 0x0).
Any allocation failure at exactly 1,000,000 slots caused HostHeap::new() to return None, abandoning the host view heap entirely.
Solution

Multi-tiered Heap Fallback (crates/victory-gpu/src/descriptor/host.rs):

When requested views + dynamic headroom exceed PORTABLE_VIEWS (1,000,000), or if heap creation fails, we gracefully try a decreasing fallback ladder: [PORTABLE_VIEWS, 500_000, 250_000, MIN_DYNAMIC].
On a capped 1M heap, dynamic headroom is doubled to 131_072 (1 << 17 slots), providing sufficient breathing room for thousands of simultaneous draws.

Cursor Wraparound Fix in dynamic():

Extended the second search pass to (cursor..end).chain(0..cursor.saturating_add(n - 1).min(end)) so free contiguous blocks crossing the allocator search cursor are not falsely rejected.

Ring-Buffer Dynamic Recycling (crates/victory-gpu/src/descriptor/host.rs, draw.rs):

Implemented HostHeap::recycle_dynamic(n).
In State::tables(), table allocation now uses host.dynamic(n).or_else(|| host.recycle_dynamic(n)). When dynamic capacity is fully saturated, slots are recycled in a ring-buffer fashion instead of dropping draws or dispatches.

Safe Out-of-Bounds Mirroring:

In HostHeap::mirror(), requests for index >= self.count now recover and return the underlying title View from guest memory so resource transitions and barriers continue to run cleanly.
Verification
Added synthetic unit test heap_request_over_one_million_caps_gracefully emulating a 1,245,184 descriptor allocation request.
Added synthetic unit test dynamic_descriptor_recycling_survives_pool_exhaustion verifying safe slot recycling when the pool is completely saturated.
Added synthetic unit test dynamic_cursor_wraparound_finds_contiguous_span validating cursor-boundary allocation.
cargo test -p victory-gpu passed (53 passed, 0 failed, 1 ignored).
cargo clippy -p victory-gpu --all-targets -- -D warnings and cargo xtask policy (154 files ok) pass cleanly.

Branch: fix/issue-887-descriptor-heap-limit (commit 0ae1f58).

**@⁠Xvania7** on GitHub · 2026-11-24 13:50 UTC · [original](https://github.com/Marvisak/VIctory/issues/902) Fixes #887 (related to #871, #876, #562). Problem After #876 resolved the black screen cutscenes, titles requesting large descriptor heaps (e.g. 1,245,184 views on GTA VI world load) run into the D3D12 Tier 1/2 hardware limit of 1,000,000 shader-visible descriptors: HostHeap::new() attempts to allocate count + DYNAMIC and count + MIN_DYNAMIC, both of which fail with E_INVALIDARG (0x80070057) because the size exceeds 1,000,000. The cap fallback previously gave only MIN_DYNAMIC (65,536) slots to dynamic tables and 934,464 to title views. Under heavy world frames (3,300–5,500 draws/dispatches), 65,536 dynamic slots were rapidly exhausted. HostHeap::dynamic() returned None, causing draw.rs to drop passes (a draw or dispatch dropped: no dynamic slots for its tables reaching dropped=65536). Dropped compute dispatches and render passes ultimately led to null-pointer crashes (0xc0000005 write 0x0). Any allocation failure at exactly 1,000,000 slots caused HostHeap::new() to return None, abandoning the host view heap entirely. Solution Multi-tiered Heap Fallback (crates/victory-gpu/src/descriptor/host.rs): When requested views + dynamic headroom exceed PORTABLE_VIEWS (1,000,000), or if heap creation fails, we gracefully try a decreasing fallback ladder: [PORTABLE_VIEWS, 500_000, 250_000, MIN_DYNAMIC]. On a capped 1M heap, dynamic headroom is doubled to 131_072 (1 << 17 slots), providing sufficient breathing room for thousands of simultaneous draws. Cursor Wraparound Fix in dynamic(): Extended the second search pass to (cursor..end).chain(0..cursor.saturating_add(n - 1).min(end)) so free contiguous blocks crossing the allocator search cursor are not falsely rejected. Ring-Buffer Dynamic Recycling (crates/victory-gpu/src/descriptor/host.rs, draw.rs): Implemented HostHeap::recycle_dynamic(n). In State::tables(), table allocation now uses host.dynamic(n).or_else(|| host.recycle_dynamic(n)). When dynamic capacity is fully saturated, slots are recycled in a ring-buffer fashion instead of dropping draws or dispatches. Safe Out-of-Bounds Mirroring: In HostHeap::mirror(), requests for index >= self.count now recover and return the underlying title View from guest memory so resource transitions and barriers continue to run cleanly. Verification Added synthetic unit test heap_request_over_one_million_caps_gracefully emulating a 1,245,184 descriptor allocation request. Added synthetic unit test dynamic_descriptor_recycling_survives_pool_exhaustion verifying safe slot recycling when the pool is completely saturated. Added synthetic unit test dynamic_cursor_wraparound_finds_contiguous_span validating cursor-boundary allocation. cargo test -p victory-gpu passed (53 passed, 0 failed, 1 ignored). cargo clippy -p victory-gpu --all-targets -- -D warnings and cargo xtask policy (154 files ok) pass cleanly. Branch: [fix/issue-887-descriptor-heap-limit](https://github.com/Xvania7/VIctory/tree/fix/issue-887-descriptor-heap-limit) (commit 0ae1f58).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:14:08 +00:00
Author
Owner

@⁠MichaelSmithAI on GitHub · 2026-11-24 13:54 UTC · original

There is a descriptor lifetime problem in the ring fallback at 0ae1f58. A recorded list owns its fresh descriptor range until release. After the free-range search fails, recycle_dynamic can return slots that still belong to that list. Writing the replacement table changes the descriptors visible to previously recorded work. The earlier owner also retains its release record, so its eventual release can mark the replacement range free.

I’d keep the normal allocation-failure path until a range is available for exclusive use. That ownership has to cover both lists waiting to be submitted and submissions still using the descriptors. The free-range cursor fix can be taken independently from #871. The heap-size fallback can also be evaluated separately by recording the capacity actually created and how much remains for mirrored title slots.

This finding is from source review. The allocation-count test establishes that recycling returns an index under pressure. It doesn't establish lifetime correctness for recorded tables or the cause of the reported title crash.

For the oversized-request path at the 1,000,000-slot fallback, the dynamic reserve grows from 65,536 to 131,072. That leaves 868,928 directly mirrored title slots, down from 934,464. Tables in the displaced range can now consume the extra dynamic space themselves. Returning a guest view from mirror allows resource preparation, but the shader still needs a materialized descriptor in the bound heap. Logging the selected total, mirrored count, and dynamic count would distinguish the outcomes, including when a smaller allocation succeeds.

The >1M test also assumes the fallback was taken. The constructor deliberately tries the full request first, and that can succeed on a capable adapter. A deterministic ladder test could control which allocation attempts succeed, with separate cases for full-size success and each fallback.

**@⁠MichaelSmithAI** on GitHub · 2026-11-24 13:54 UTC · [original](https://github.com/Marvisak/VIctory/issues/902#issuecomment-7133528657) There is a descriptor lifetime problem in the ring fallback at 0ae1f58. A recorded list owns its fresh descriptor range until release. After the free-range search fails, `recycle_dynamic` can return slots that still belong to that list. Writing the replacement table changes the descriptors visible to previously recorded work. The earlier owner also retains its release record, so its eventual release can mark the replacement range free. I’d keep the normal allocation-failure path until a range is available for exclusive use. That ownership has to cover both lists waiting to be submitted and submissions still using the descriptors. The free-range cursor fix can be taken independently from [#871](https://git.gtahub.st/github/Marvisak--VIctory/issues/871). The heap-size fallback can also be evaluated separately by recording the capacity actually created and how much remains for mirrored title slots. This finding is from source review. The allocation-count test establishes that recycling returns an index under pressure. It doesn't establish lifetime correctness for recorded tables or the cause of the reported title crash. For the oversized-request path at the 1,000,000-slot fallback, the dynamic reserve grows from 65,536 to 131,072. That leaves 868,928 directly mirrored title slots, down from 934,464. Tables in the displaced range can now consume the extra dynamic space themselves. Returning a guest view from `mirror` allows resource preparation, but the shader still needs a materialized descriptor in the bound heap. Logging the selected total, mirrored count, and dynamic count would distinguish the outcomes, including when a smaller allocation succeeds. The >1M test also assumes the fallback was taken. The constructor deliberately tries the full request first, and that can succeed on a capable adapter. A deterministic ladder test could control which allocation attempts succeed, with separate cases for full-size success and each fallback.
Author
Owner

@⁠andrewpozdnakov7-jpg on GitHub · 2026-11-24 13:59 UTC · original

I reproduced the occupied-range issue above through State::tables on Windows D3D12 WARP. With all dynamic slots reserved, 0ae1f58 still returns the occupied slot at byte offset 32 for a fresh CBV table. With the fix, that request is declined and the slot becomes available after release.

Fix and regression test, one commit directly on 0ae1f58. The focused test fails before the fix and passes after it. GPU diagnostics: 55 passed, 1 ignored with the existing >1M test filtered. That test fails on both revisions because this WARP device accepts a heap larger than 1M. Clippy with diagnostics and the asset policy check passed.

The fixture builds tables without submitting GPU work. AI-assisted.

**@⁠andrewpozdnakov7-jpg** on GitHub · 2026-11-24 13:59 UTC · [original](https://github.com/Marvisak/VIctory/issues/902#issuecomment-7133668153) I reproduced the occupied-range issue above through `State::tables` on Windows D3D12 WARP. With all dynamic slots reserved, `0ae1f58` still returns the occupied slot at byte offset 32 for a fresh CBV table. With the fix, that request is declined and the slot becomes available after release. [Fix and regression test](https://github.com/andrewpozdnakov7-jpg/VIctory/commit/b8dcf762c5f4eb3e48b618531c6a94e5918410b5), one commit directly on `0ae1f58`. The focused test fails before the fix and passes after it. GPU diagnostics: 55 passed, 1 ignored with the existing >1M test filtered. That test fails on both revisions because this WARP device accepts a heap larger than 1M. Clippy with diagnostics and the asset policy check passed. The fixture builds tables without submitting GPU work. AI-assisted.
Author
Owner

@⁠bailu12300 on GitHub · 2026-11-24 14:03 UTC · original

Tested on the RTX 5060 / Windows 10 19045 host from #887. Normal boot flow, real key presses, no test-only injection.

Caveat first: this branch does not contain #876's typeless remap, so applied alone the black screen comes back. I hand-merged adapt_view_format + is_typeless/first_concrete (from 5e3c9e2) and the 86/115 pc_format map on top of it.

The heap part works

before #902 (934,464 + 65,536) with #902
no dynamic slots for its tables up to 65,536, then every world draw 0
recycle_dynamic triggered n/a 1
GPU device removed yes, 0x887A0006 after 11 and 27 lists 0
time in the world before exit ~40 s ~3.5 min
draws/frame 5,500 and dropping 7,396, then 1,502 stable
screen flat clear colour prologue title card renders (VICE CITY, TWO YEARS AGO with the Chinese subtitle 【两年前,罪恶城】)

So the fallback ladder, the wraparound fix and the ring recycling do exactly what they say: the process degrades gracefully instead of hanging the GPU, which is the failure from #887. no host descriptor heap never appears, and TDR (raised to 180 s here) is never hit.

What still stops it

The title's own fault, unchanged:

first-chance exception 0xc0000005 at victory-image-b99f876b74d4a77f.dll+0x23cf683 (write 0x0)
  #0 +0x23cf683  #1 +0x2215c35  #2 +0x2215eca

with 1,000,000 views held against 1,245,184 requested. No dump, no device removal — it reads as the view side of the same budget (the 245,184 views without a host slot leave a null resource that the title later writes through), not a heap allocation failure.

Two notes

  1. Landing #876 first (or folding the typeless remap into this branch) would make this branch testable on its own.
  2. Frame time in the world here is 0.7–14.7 s (4K, ~7,400 draws, 8 GB card), so even with the heap fixed the world is a slideshow on this class of hardware — playable is still a separate problem from "does not hang".

Happy to run any follow-up variant. This box reaches the world deterministically in about 3 minutes now.

**@⁠bailu12300** on GitHub · 2026-11-24 14:03 UTC · [original](https://github.com/Marvisak/VIctory/issues/902#issuecomment-7133780162) Tested on the RTX 5060 / Windows 10 19045 host from #887. Normal boot flow, real key presses, no test-only injection. Caveat first: this branch does **not** contain #876's typeless remap, so applied alone the black screen comes back. I hand-merged `adapt_view_format` + `is_typeless`/`first_concrete` (from `5e3c9e2`) and the 86/115 `pc_format` map on top of it. ## The heap part works | | before #902 (934,464 + 65,536) | with #902 | |---|---|---| | `no dynamic slots for its tables` | up to 65,536, then every world draw | **0** | | `recycle_dynamic` triggered | n/a | **1** | | GPU device removed | yes, 0x887A0006 after 11 and 27 lists | **0** | | time in the world before exit | ~40 s | **~3.5 min** | | draws/frame | 5,500 and dropping | 7,396, then 1,502 stable | | screen | flat clear colour | **prologue title card renders** (`VICE CITY, TWO YEARS AGO` with the Chinese subtitle 【两年前,罪恶城】) | So the fallback ladder, the wraparound fix and the ring recycling do exactly what they say: the process degrades gracefully instead of hanging the GPU, which is the failure from #887. `no host descriptor heap` never appears, and TDR (raised to 180 s here) is never hit. ## What still stops it The title's own fault, unchanged: ``` first-chance exception 0xc0000005 at victory-image-b99f876b74d4a77f.dll+0x23cf683 (write 0x0) #0 +0x23cf683 #1 +0x2215c35 #2 +0x2215eca ``` with 1,000,000 views held against 1,245,184 requested. No dump, no device removal — it reads as the view side of the same budget (the 245,184 views without a host slot leave a null resource that the title later writes through), not a heap allocation failure. ## Two notes 1. Landing #876 first (or folding the typeless remap into this branch) would make this branch testable on its own. 2. Frame time in the world here is 0.7–14.7 s (4K, ~7,400 draws, 8 GB card), so even with the heap fixed the world is a slideshow on this class of hardware — playable is still a separate problem from "does not hang". Happy to run any follow-up variant. This box reaches the world deterministically in about 3 minutes now.
Author
Owner

@⁠Xvania7 on GitHub · 2026-11-24 14:48 UTC · original

Thanks @⁠MichaelSmithAI for catching the lifetime hazard with unsubmitted command lists, and huge thanks to @⁠andrewpozdnakov7-jpg for the reproduction and patch!

I have updated fix/issue-887-descriptor-heap-limit:

  1. Descriptor Lifetime Safety: Integrated @⁠andrewpozdnakov7-jpg's commit (280d033). Removed the eager ring overwriting; occupied dynamic slots remain strictly reserved until their owning command lists release them, preventing in-flight descriptor table corruption.
  2. Regression Test: Added exhausted_heap_keeps_existing_descriptor_tables_reserved to verify that requests while held are declined and cleanly succeed once released.
  3. Tier 3 / WARP Test Compatibility (77d9f68): Adjusted heap_request_over_one_million_caps_gracefully so it accommodates Tier 3 hardware/WARP allocating the full request as well as Tier 1/2 adapters taking the portable cap ladder.

@⁠bailu12300: If testing on your host, remember to test together with #876 (or cherry-pick commit b7a0a8c) so that the typeless view remap prevents the black frame.

**@⁠Xvania7** on GitHub · 2026-11-24 14:48 UTC · [original](https://github.com/Marvisak/VIctory/issues/902#issuecomment-7134993044) Thanks @⁠MichaelSmithAI for catching the lifetime hazard with unsubmitted command lists, and huge thanks to @⁠andrewpozdnakov7-jpg for the reproduction and patch! I have updated [`fix/issue-887-descriptor-heap-limit`](https://github.com/Xvania7/VIctory/tree/fix/issue-887-descriptor-heap-limit): 1. **Descriptor Lifetime Safety**: Integrated @⁠andrewpozdnakov7-jpg's commit (`280d033`). Removed the eager ring overwriting; occupied dynamic slots remain strictly reserved until their owning command lists release them, preventing in-flight descriptor table corruption. 2. **Regression Test**: Added `exhausted_heap_keeps_existing_descriptor_tables_reserved` to verify that requests while held are declined and cleanly succeed once released. 3. **Tier 3 / WARP Test Compatibility** (`77d9f68`): Adjusted `heap_request_over_one_million_caps_gracefully` so it accommodates Tier 3 hardware/WARP allocating the full request as well as Tier 1/2 adapters taking the portable cap ladder. @⁠bailu12300: If testing on your host, remember to test together with #876 (or cherry-pick commit `b7a0a8c`) so that the typeless view remap prevents the black frame.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 06:59 UTC · original

Automated triage for the maintainers.

Part of this is on main: the cursor wraparound in HostHeap::dynamic was fixed by #974. The heap-size fallback is unchanged: HostHeap::new in crates/victory-gpu/src/descriptor/host.rs still caps an oversized request at 1,000,000 with MIN_DYNAMIC (65,536) dynamic slots. The comments found a lifetime problem in the first ring fallback (slots a recorded list still owned could be handed out); the branch has since dropped that and keeps occupied slots reserved until release. Pull requests are open to everyone, so please open one from the updated branch. The report it addresses is #887.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 06:59 UTC · [original](https://github.com/Marvisak/VIctory/issues/902#issuecomment-7155365961) <!-- victory-issue-triage v1 verdict=tracked seen=2026-11-24T14:48:57Z at=2026-11-25T06:59:15Z --> Automated triage for the maintainers. Part of this is on `main`: the cursor wraparound in `HostHeap::dynamic` was fixed by #974. The heap-size fallback is unchanged: `HostHeap::new` in `crates/victory-gpu/src/descriptor/host.rs` still caps an oversized request at 1,000,000 with `MIN_DYNAMIC` (65,536) dynamic slots. The comments found a lifetime problem in the first ring fallback (slots a recorded list still owned could be handed out); the branch has since dropped that and keeps occupied slots reserved until release. Pull requests are open to everyone, so please open one from the updated branch. The report it addresses is #887. --- _Generated by [Claude Code](https://claude.ai/code)_
This discussion has been locked. Commenting is limited to contributors.
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory#902
No description provided.