GPU: Graceful degradation and dynamic recycling for descriptor heaps exceeding 1,000,000 slots #2187

Open
Xvania7 wants to merge 6 commits from upstream-pr/2189 into main
Xvania7 commented 2026-11-25 07:21:22 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Xvania7 on 2026-11-25T07:21:22Z.


Fixes #887 (supersedes tracking issue #902; related to #871, #876, #562).

Summary

  • Multi-tiered Heap Fallback (crates/victory-gpu/src/descriptor/host.rs): When requested views + dynamic headroom exceed PORTABLE_VIEWS (1,000,000) or heap creation fails, gracefully steps down through [PORTABLE_VIEWS, 500_000, 250_000, MIN_DYNAMIC] with 131_072 dynamic slots on capped 1M heaps.
  • Cursor Wraparound & Lifetime-Safe Allocation (descriptor/host.rs, draw.rs): Fixes free-span search across the ring cursor and keeps occupied dynamic slots strictly reserved until owning command lists release them (incorporating @andrewpozdnakov7-jpg's lifetime fix 280d033 + @MichaelSmithAI's review feedback).
  • Safe Out-of-Bounds Mirroring (HostHeap::mirror): Recovers and returns the underlying title View when index >= self.count so resource transitions and barriers continue cleanly.

Verification

  • Synthetic tests: heap_request_over_one_million_caps_gracefully, exhausted_heap_keeps_existing_descriptor_tables_reserved, dynamic_cursor_wraparound_finds_contiguous_span
  • Independently verified on RTX 5060 / Win10 and WARP (see #902 comments).
<!-- greyfinch-sync:Marvisak/VIctory:issue:5486988119 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2189). Originally posted by [Xvania7](https://github.com/Xvania7) on 2026-11-25T07:21:22Z. --- Fixes #887 (supersedes tracking issue #902; related to #871, #876, #562). ### Summary - **Multi-tiered Heap Fallback (crates/victory-gpu/src/descriptor/host.rs):** When requested views + dynamic headroom exceed PORTABLE_VIEWS (1,000,000) or heap creation fails, gracefully steps down through [PORTABLE_VIEWS, 500_000, 250_000, MIN_DYNAMIC] with 131_072 dynamic slots on capped 1M heaps. - **Cursor Wraparound & Lifetime-Safe Allocation (descriptor/host.rs, draw.rs):** Fixes free-span search across the ring cursor and keeps occupied dynamic slots strictly reserved until owning command lists release them (incorporating @andrewpozdnakov7-jpg's lifetime fix 280d033 + @MichaelSmithAI's review feedback). - **Safe Out-of-Bounds Mirroring (HostHeap::mirror):** Recovers and returns the underlying title View when index >= self.count so resource transitions and barriers continue cleanly. ### Verification - Synthetic tests: heap_request_over_one_million_caps_gracefully, exhausted_heap_keeps_existing_descriptor_tables_reserved, dynamic_cursor_wraparound_finds_contiguous_span - Independently verified on RTX 5060 / Win10 and WARP (see #902 comments).
catminou4 commented 2026-11-25 08:02:59 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T08:02:59Z.

Review: COMMENTED


Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; source review of the diff.

Graceful degradation + dynamic recycling for descriptors — resource-exhaustion handling; relates to #2099's bounded view table.

<!-- greyfinch-sync:Marvisak/VIctory:review:6053835598 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2189#pullrequestreview-6053835598). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-25T08:02:59Z. **Review:** COMMENTED --- Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; source review of the diff. Graceful degradation + dynamic recycling for descriptors — resource-exhaustion handling; relates to #2099's bounded view table.
MamaLeVrai commented 2026-11-25 09:06:22 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by MamaLeVrai on 2026-11-25T08:52:12Z.


Test report on real hardware: AMD RX 6950 XT (RDNA2), Windows 11, Rust 1.98.1, with a GPU present, so the hardware-only shader checks run. I merged this PR's head 7e1292d6 into main 940d32f in a throwaway tree (no conflict). cargo clippy --workspace --all-targets --locked -- -D warnings: clean; the same with --all-features: clean. cargo test --workspace --locked: 704 passed, 0 failed, 10 ignored, two runs (main alone on the same machine: 701 passed, 0 failed, 10 ignored). The title was not run, so this says nothing about in-game effect. No game data.

AI-assisted (Claude Code); no game data.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7157573989 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2189#issuecomment-7157573989). Originally posted by [MamaLeVrai](https://github.com/MamaLeVrai) on 2026-11-25T08:52:12Z. --- Test report on real hardware: AMD RX 6950 XT (RDNA2), Windows 11, Rust 1.98.1, with a GPU present, so the hardware-only shader checks run. I merged this PR's head `7e1292d6` into `main` `940d32f` in a throwaway tree (no conflict). `cargo clippy --workspace --all-targets --locked -- -D warnings`: clean; the same with `--all-features`: clean. `cargo test --workspace --locked`: 704 passed, 0 failed, 10 ignored, two runs (`main` alone on the same machine: 701 passed, 0 failed, 10 ignored). The title was not run, so this says nothing about in-game effect. No game data. AI-assisted (Claude Code); no game data.
Marvisak commented 2026-11-25 14:07:19 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T13:28:28Z.


Automated triage for the maintainers.

This pull request no longer merges cleanly into main (conflicts in crates/victory-gpu/src/descriptor/host.rs). It will be reviewed once it is rebased onto the current main. The earlier verdict (needs-work) was for an older state of main.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7163829369 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2189#issuecomment-7163829369). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T13:28:28Z. --- <!-- victory-triage v1 head=364c6757c9c4efe799bb66c801ba46331151b4dd verdict=needs-rebase at=2026-11-25T16:11:30Z --> Automated triage for the maintainers. This pull request no longer merges cleanly into `main` (conflicts in `crates/victory-gpu/src/descriptor/host.rs`). It will be reviewed once it is rebased onto the current `main`. The earlier verdict (needs-work) was for an older state of `main`. --- _Generated by [Claude Code](https://claude.ai/code)_
Xvania7 commented 2026-11-25 15:04:16 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Xvania7 on 2026-11-25T14:16:01Z.


Addressed the triage points in (364c675):

  1. Hardware Tier 1 Anchor & Removal of Arbitrary Steps:
    Removed the 500k/250k loops. The cap is anchored directly to D3D12 Tier 1 limits (D3D12_MAX_SHADER_VISIBLE_DESCRIPTOR_HEAP_SIZE_TIER_1 = 1_000_000) enforced by NVIDIA drivers (Ampere, Ada, Blackwell). Keeping PORTABLE_VIEWS = 1_000_000 preserves the invariant that translated shaders can safely clamp below HEAP_VIEWS.
  2. Order & Error Branch:
    Restored return None on plain allocation failure (Err(e) when count + MIN_DYNAMIC <= PORTABLE_VIEWS), avoiding retrying larger heaps when the device ran out of memory.
  3. Mirror Path Test Coverage:
    Updated heap_request_over_one_million_caps_gracefully to assert both the zero-tag fallback and the VIEW_TAG branch without host heap indexing.

All checks pass cleanly: unit tests 148 passed, Clippy 0 warnings, asset policy ok.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7165012296 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2189#issuecomment-7165012296). Originally posted by [Xvania7](https://github.com/Xvania7) on 2026-11-25T14:16:01Z. --- Addressed the triage points in (364c675): 1. **Hardware Tier 1 Anchor & Removal of Arbitrary Steps:** Removed the 500k/250k loops. The cap is anchored directly to D3D12 Tier 1 limits (`D3D12_MAX_SHADER_VISIBLE_DESCRIPTOR_HEAP_SIZE_TIER_1 = 1_000_000`) enforced by NVIDIA drivers (Ampere, Ada, Blackwell). Keeping `PORTABLE_VIEWS = 1_000_000` preserves the invariant that translated shaders can safely clamp below `HEAP_VIEWS`. 2. **Order & Error Branch:** Restored `return None` on plain allocation failure (`Err(e)` when `count + MIN_DYNAMIC <= PORTABLE_VIEWS`), avoiding retrying larger heaps when the device ran out of memory. 3. **Mirror Path Test Coverage:** Updated `heap_request_over_one_million_caps_gracefully` to assert both the zero-tag fallback and the `VIEW_TAG` branch without host heap indexing. All checks pass cleanly: unit tests 148 passed, Clippy 0 warnings, asset policy ok.
Xvania7 commented 2026-11-26 19:54:47 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Xvania7 on 2026-11-26T19:54:47Z.


Rebased cleanly onto latest main (63bcca4):

  • Resolved conflicts in crates/victory-gpu/src/descriptor/host.rs and crates/victory-gpu/src/draw.rs (integrated with placed texture view tests).
  • Accommodated hardware Tier 1 capped heaps in dynamic_slots_are_held_until_released (num >= HEAP_VIEWS || num >= MIN_DYNAMIC).
  • Verified all descriptor heap tests pass (cargo test -p victory-gpu --lib -- dynamic_, heap_request_over_one_million_caps_gracefully, and exhausted_heap_keeps_existing_descriptor_tables_reserved).
  • Both standard and diagnostics Clippy clean (-D warnings), cargo xtask policy 191 files clean.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7202092603 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2189#issuecomment-7202092603). Originally posted by [Xvania7](https://github.com/Xvania7) on 2026-11-26T19:54:47Z. --- Rebased cleanly onto latest `main` (`63bcca4`): - Resolved conflicts in `crates/victory-gpu/src/descriptor/host.rs` and `crates/victory-gpu/src/draw.rs` (integrated with placed texture view tests). - Accommodated hardware Tier 1 capped heaps in `dynamic_slots_are_held_until_released` (`num >= HEAP_VIEWS || num >= MIN_DYNAMIC`). - Verified all descriptor heap tests pass (`cargo test -p victory-gpu --lib -- dynamic_`, `heap_request_over_one_million_caps_gracefully`, and `exhausted_heap_keeps_existing_descriptor_tables_reserved`). - Both standard and diagnostics Clippy clean (`-D warnings`), `cargo xtask policy` 191 files clean.
kalberts0089-hash commented 2026-11-27 10:46:52 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kalberts0089-hash on 2026-11-27T10:46:52Z.


Test report on NVIDIA Ada hardware: RTX 4070 Ti, driver 621.01, Windows 11.

Tested: head 0ff9d5f (base 63bcca4, which is current main, so nothing was merged locally). Compared with main 63bcca4 on the same machine.

Confirmed

cargo test -p victory-gpu --lib -- --test-threads=1

passed failed ignored
main 63bcca4 229 2 1
this PR 0ff9d5f 233 1 1
  • The three new tests pass here, in the suite and alone with --exact --nocapture: heap_request_over_one_million_caps_gracefully, dynamic_cursor_wraparound_finds_contiguous_span, exhausted_heap_keeps_existing_descriptor_tables_reserved.
  • The capped path is the one that runs on this card: a request for 1,245,184 views gives a host heap of 1,000,000 descriptors (count 934,464 + dynamic 65,536), so exhausted_heap_keeps_existing_descriptor_tables_reserved does not take its early return.
  • dynamic_slots_are_held_until_released: fails on main, passes on this head.
  • lists_share_a_table_and_copies_keep_their_views: fails on main and on this head, same assertion (memory.rs:1030, "past the dynamic slots"). Unchanged by this PR.

cargo test -p victory-shader --lib --no-fail-fast -- --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index: 298 passed, 3 failed, 3 ignored on both main and this head. The three are the known NVIDIA failures and are unrelated to this PR (it does not touch victory-shader): a_heap_buffer_read_by_element_takes_the_views_stride, a_heap_buffer_read_where_no_buffer_view_is_reads_zeros, gathers_at_a_level_match_the_hardware. heap_direct_texture_reads_mark_their_heap_index was skipped because it crashes the test process on this card (#2571).

Why dynamic_slots_are_held_until_released now passes

As a fact about the diff: the heap code that test exercises is unchanged; its first assertion changed from NumDescriptors >= HEAP_VIEWS to num >= HEAP_VIEWS || num >= MIN_DYNAMIC. On this card the values are num = 65,540, HEAP_VIEWS = 2,097,152, MIN_DYNAMIC = 65,536.

Local check (uncommitted edit, discarded afterwards): with only that assertion put back to the main form on this head, the test fails exactly as on main.

Local check of the new tests against the mirror change

The diff against main has one behavioural change outside tests, as far as I can read it: HostHeap::mirror returns the title's view for index >= self.count instead of None. The cap branch in HostHeap::new is the same expression split over two lines, and the draw.rs change outside tests is a comment.

Local check (uncommitted edit, discarded afterwards): with that mirror hunk put back to return None;, all three new tests still pass on this card.

Questions

  1. A view heap always has at least MIN_DYNAMIC dynamic slots, so can num >= MIN_DYNAMIC ever be false? If not, is it intended that the test no longer checks anything about heap size on a capped host, given the comment above it still says every index a translated shader can reach exists?
  2. Is there a test meant to cover the new Some(view) return from mirror past the cap? The VIEW_TAG case in heap_request_over_one_million_caps_gracefully uses generation 0, which gives None before and after the change.
  3. Is the description still current for this head? It mentions 500,000/250,000 steps, 131,072 dynamic slots on capped heaps, and a fix to the free-span search, while the diff against 63bcca4 does not change dynamic or release, and the capped heap measured here has 65,536 dynamic slots.

Not tested

  • No title was run, so nothing here says whether returning the view from mirror past the cap helps or harms a real frame.
  • The Some(view) path of mirror for index >= count was not exercised by any test I ran.
  • The uncapped path (a host that accepts the full 1,245,184 request) cannot be reached on this card.
  • Clippy, cargo xtask policy and the other crates were not run.

Synthetic tests only, no game files. AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7216296548 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2189#issuecomment-7216296548). Originally posted by [kalberts0089-hash](https://github.com/kalberts0089-hash) on 2026-11-27T10:46:52Z. --- Test report on NVIDIA Ada hardware: RTX 4070 Ti, driver 621.01, Windows 11. **Tested:** head `0ff9d5f` (base `63bcca4`, which is current `main`, so nothing was merged locally). Compared with `main` `63bcca4` on the same machine. ### Confirmed `cargo test -p victory-gpu --lib -- --test-threads=1` | | passed | failed | ignored | |---|---|---|---| | `main` `63bcca4` | 229 | 2 | 1 | | this PR `0ff9d5f` | 233 | 1 | 1 | - The three new tests pass here, in the suite and alone with `--exact --nocapture`: `heap_request_over_one_million_caps_gracefully`, `dynamic_cursor_wraparound_finds_contiguous_span`, `exhausted_heap_keeps_existing_descriptor_tables_reserved`. - The capped path is the one that runs on this card: a request for 1,245,184 views gives a host heap of 1,000,000 descriptors (`count` 934,464 + `dynamic` 65,536), so `exhausted_heap_keeps_existing_descriptor_tables_reserved` does not take its early return. - `dynamic_slots_are_held_until_released`: fails on `main`, passes on this head. - `lists_share_a_table_and_copies_keep_their_views`: fails on `main` and on this head, same assertion (`memory.rs:1030`, "past the dynamic slots"). Unchanged by this PR. `cargo test -p victory-shader --lib --no-fail-fast -- --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index`: 298 passed, 3 failed, 3 ignored on both `main` and this head. The three are the known NVIDIA failures and are unrelated to this PR (it does not touch `victory-shader`): `a_heap_buffer_read_by_element_takes_the_views_stride`, `a_heap_buffer_read_where_no_buffer_view_is_reads_zeros`, `gathers_at_a_level_match_the_hardware`. `heap_direct_texture_reads_mark_their_heap_index` was skipped because it crashes the test process on this card (#2571). ### Why `dynamic_slots_are_held_until_released` now passes As a fact about the diff: the heap code that test exercises is unchanged; its first assertion changed from `NumDescriptors >= HEAP_VIEWS` to `num >= HEAP_VIEWS || num >= MIN_DYNAMIC`. On this card the values are `num` = 65,540, `HEAP_VIEWS` = 2,097,152, `MIN_DYNAMIC` = 65,536. Local check (uncommitted edit, discarded afterwards): with only that assertion put back to the `main` form on this head, the test fails exactly as on `main`. ### Local check of the new tests against the `mirror` change The diff against `main` has one behavioural change outside tests, as far as I can read it: `HostHeap::mirror` returns the title's view for `index >= self.count` instead of `None`. The cap branch in `HostHeap::new` is the same expression split over two lines, and the `draw.rs` change outside tests is a comment. Local check (uncommitted edit, discarded afterwards): with that `mirror` hunk put back to `return None;`, all three new tests still pass on this card. ### Questions 1. A view heap always has at least `MIN_DYNAMIC` dynamic slots, so can `num >= MIN_DYNAMIC` ever be false? If not, is it intended that the test no longer checks anything about heap size on a capped host, given the comment above it still says every index a translated shader can reach exists? 2. Is there a test meant to cover the new `Some(view)` return from `mirror` past the cap? The `VIEW_TAG` case in `heap_request_over_one_million_caps_gracefully` uses generation 0, which gives `None` before and after the change. 3. Is the description still current for this head? It mentions 500,000/250,000 steps, 131,072 dynamic slots on capped heaps, and a fix to the free-span search, while the diff against `63bcca4` does not change `dynamic` or `release`, and the capped heap measured here has 65,536 dynamic slots. ### Not tested - No title was run, so nothing here says whether returning the view from `mirror` past the cap helps or harms a real frame. - The `Some(view)` path of `mirror` for `index >= count` was not exercised by any test I ran. - The uncapped path (a host that accepts the full 1,245,184 request) cannot be reached on this card. - Clippy, `cargo xtask policy` and the other crates were not run. Synthetic tests only, no game files. AI-assisted (Claude Code).
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/2189:upstream-pr/2189'
git switch 'upstream-pr/2189'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/2189'
git switch 'upstream-pr/2189'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2189'
git switch 'upstream-pr/2189'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2189'
git switch 'main'
git merge --squash 'upstream-pr/2189'
git switch 'main'
git merge --ff-only 'upstream-pr/2189'
git switch 'main'
git merge 'upstream-pr/2189'
git push origin 'main'
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
Marvisak/VIctory!2187
No description provided.