[Ready to merge] GPU: Graceful degradation and dynamic recycling for descriptor heaps exceeding 1,000,000 slots #902
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory#902
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@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).
@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_dynamiccan 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
mirrorallows 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.
@andrewpozdnakov7-jpg on GitHub · 2026-11-24 13:59 UTC · original
I reproduced the occupied-range issue above through
State::tableson Windows D3D12 WARP. With all dynamic slots reserved,0ae1f58still 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.
@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(from5e3c9e2) and the 86/115pc_formatmap on top of it.The heap part works
no dynamic slots for its tablesrecycle_dynamictriggeredVICE CITY, TWO YEARS AGOwith 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 heapnever appears, and TDR (raised to 180 s here) is never hit.What still stops it
The title's own fault, unchanged:
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
Happy to run any follow-up variant. This box reaches the world deterministically in about 3 minutes now.
@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: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.exhausted_heap_keeps_existing_descriptor_tables_reservedto verify that requests while held are declined and cleanly succeed once released.77d9f68): Adjustedheap_request_over_one_million_caps_gracefullyso 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.@Marvisak on GitHub · 2026-11-25 06:59 UTC · original
Automated triage for the maintainers.
Part of this is on
main: the cursor wraparound inHostHeap::dynamicwas fixed by #974. The heap-size fallback is unchanged:HostHeap::newincrates/victory-gpu/src/descriptor/host.rsstill caps an oversized request at 1,000,000 withMIN_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