GPU: a capped view heap keeps room for its page table's view pairs #3120

Open
Indy2l wants to merge 2 commits from upstream-pr/3122 into main
Indy2l commented 2026-11-26 09:05:12 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Indy2l on 2026-11-26T09:05:12Z.


What

On hosts that cap shader-visible view heaps below HEAP_VIEWS (NVIDIA: 1,000,000), HostHeap::new made the heap exactly count + MIN_DYNAMIC slots. HostHeap::pair then had no range of its own (pairs_end == count + dynamic), so every page-table view pair fell back to self.dynamic(2) and drained the per-draw dynamic pool. When that pool runs out, tables are refused and draws are dropped.

lists_share_a_table_and_copies_keep_their_views already guards against this ("none takes a per-draw dynamic slot"). On an RTX 3060 its pairs came back as slots 2 and 4, which are dynamic slots.

Change

  • A capped heap reserves CAPPED_PAIRS slots past its dynamic range, as an uncapped heap has between count + DYNAMIC and HEAP_VIEWS. The overflow branch (title count past PORTABLE_VIEWS) takes that reservation from the title's kept-in-place slots.
  • Size: 2^14 (16,384). A pair per shadow copy: the world's roughly 4,700 copies take about 9,400 slots, so 2^14 leaves about 1.7 times that. In the overflow branch, each reserved slot is a title descriptor no longer kept in place, so it stays no larger than that. Pairs past the reservation still fall back to dynamic slots, as before.
  • Tests:
    • dynamic_slots_are_held_until_released accepts the capped layout and checks that the pair room exists.
    • The page-table test compares pairs against address_slots() instead of a hard-coded 1 << 18.

VICTORY_DYNAMIC_SLOTS (from the first revision) is split out, per review, to come back in its own PR with measurements from this repo.

Testing

  • RTX 3060, driver 32.0.16.2140, Windows 11.
  • cargo test -p victory-gpu --lib --locked: 231 passed. On main, 2 victory-gpu tests fail on this card.
  • cargo clippy --workspace --all-targets [--all-features] --locked -- -D warnings: clean.
  • cargo xtask policy: clean.
  • Not yet measured in the world.

Refs #1744.

🤖 Generated with Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:issue:5507076797 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3122). Originally posted by [Indy2l](https://github.com/Indy2l) on 2026-11-26T09:05:12Z. --- ## What On hosts that cap shader-visible view heaps below `HEAP_VIEWS` (NVIDIA: 1,000,000), `HostHeap::new` made the heap exactly `count + MIN_DYNAMIC` slots. `HostHeap::pair` then had no range of its own (`pairs_end == count + dynamic`), so every page-table view pair fell back to `self.dynamic(2)` and drained the per-draw dynamic pool. When that pool runs out, tables are refused and draws are dropped. `lists_share_a_table_and_copies_keep_their_views` already guards against this ("none takes a per-draw dynamic slot"). On an RTX 3060 its pairs came back as slots 2 and 4, which are dynamic slots. ## Change - A capped heap reserves `CAPPED_PAIRS` slots past its dynamic range, as an uncapped heap has between `count + DYNAMIC` and `HEAP_VIEWS`. The overflow branch (title count past `PORTABLE_VIEWS`) takes that reservation from the title's kept-in-place slots. - **Size: 2^14 (16,384).** A pair per shadow copy: the world's roughly 4,700 copies take about 9,400 slots, so 2^14 leaves about 1.7 times that. In the overflow branch, each reserved slot is a title descriptor no longer kept in place, so it stays no larger than that. Pairs past the reservation still fall back to dynamic slots, as before. - Tests: - `dynamic_slots_are_held_until_released` accepts the capped layout and checks that the pair room exists. - The page-table test compares pairs against `address_slots()` instead of a hard-coded `1 << 18`. `VICTORY_DYNAMIC_SLOTS` (from the first revision) is split out, per review, to come back in its own PR with measurements from this repo. ## Testing - RTX 3060, driver 32.0.16.2140, Windows 11. - `cargo test -p victory-gpu --lib --locked`: 231 passed. On main, 2 victory-gpu tests fail on this card. - `cargo clippy --workspace --all-targets [--all-features] --locked -- -D warnings`: clean. - `cargo xtask policy`: clean. - Not yet measured in the world. Refs #1744. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Dukestar69 commented 2026-11-26 09:07:56 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T09:07:56Z.

Review: APPROVED


Verified on RTX 5090 (1M view-heap cap) & WARP against origin/main (63bcca4):

  • cargo test -p victory-gpu --lib descriptor::host:: -- --test-threads=1: 15/15 passed on RTX 5090 (including dynamic_slots_are_held_until_released, which fails on clean origin/main under #1744).
  • cargo test -p victory-gpu --lib memory:: -- --test-threads=1: 8/8 passed on RTX 5090 and WARP (including lists_share_a_table_and_copies_keep_their_views, also previously failing on RTX 5090 under #1744).
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Cleanly reserves room for the page table's view pairs on capped 1M view heaps (NVIDIA).

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6071219514 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3122#pullrequestreview-6071219514). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T09:07:56Z. **Review:** APPROVED --- Verified on RTX 5090 (1M view-heap cap) & WARP against `origin/main` (`63bcca4`): - `cargo test -p victory-gpu --lib descriptor::host:: -- --test-threads=1`: **15/15 passed** on RTX 5090 (including `dynamic_slots_are_held_until_released`, which fails on clean `origin/main` under `#1744`). - `cargo test -p victory-gpu --lib memory:: -- --test-threads=1`: **8/8 passed** on RTX 5090 and WARP (including `lists_share_a_table_and_copies_keep_their_views`, also previously failing on RTX 5090 under `#1744`). - `cargo clippy -p victory-gpu --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Cleanly reserves room for the page table's view pairs on capped 1M view heaps (NVIDIA). Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
fuzeofficlal commented 2026-11-26 09:27:35 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T09:27:35Z.

Review: APPROVED


Clean, well-scoped fix for NVIDIA's 1,000,000-descriptor view-heap cap.

Reviewed crates/victory-gpu/src/descriptor/host.rs and crates/victory-gpu/src/memory.rs:

  • Non-overflow capped heaps (count + MIN_DYNAMIC + CAPPED_PAIRS <= PORTABLE_VIEWS) allocate CAPPED_PAIRS (65,536) slots past [count, count + MIN_DYNAMIC), so HostHeap::pair stops falling back to self.dynamic(2) and draining per-draw dynamic slots.
  • Overflow capped heaps clamp VICTORY_DYNAMIC_SLOTS to [MIN_DYNAMIC, PORTABLE_VIEWS / 2 - CAPPED_PAIRS] ([65_536, 434_464]), preserving at least 500,000 in-place title slots plus 65,536 pair slots with no underflow.
  • Uncapped heaps / WARP stay on the existing (count + DYNAMIC).max(HEAP_VIEWS) path unchanged.
  • Updating memory.rs to assert >= views.address_slots() validates the real invariant (pairs live past dynamic slots) across both capped and uncapped layouts.

Verified locally on Windows 11 with a 1M-capped RTX 5090 and WARP:

  • cargo clippy --workspace --all-targets [--all-features] -- -D warnings: clean
  • cargo xtask policy: 191 files ok
  • RTX 5090: descriptor::host::tests:: 15/15 passed (dynamic_slots_are_held_until_released now passes) and memory::tests:: 8/8 passed (lists_share_a_table_and_copies_keep_their_views now passes)
  • RTX 5090 + VICTORY_D3D12_DEBUG=1: both previously failing tests pass with zero debug layer errors
  • RTX 5090 with VICTORY_DYNAMIC_SLOTS=0, 524288, 999999999: dynamic_slots_are_held_until_released passes in all cases
  • WARP (--features diagnostics, VICTORY_D3D12_WARP=1) + VICTORY_D3D12_DEBUG=1: descriptor::host::tests:: 15/15 passed, memory::tests:: 8/8 passed

Two minor non-blocking notes:

  • count + MIN_DYNAMIC + CAPPED_PAIRS at descriptor/host.rs:180,182 (like the existing count + DYNAMIC at line 175) uses unchecked u32 addition; using saturating_add would guard against a wild title descriptor count.
  • VICTORY_DYNAMIC_SLOTS could be documented alongside the other VICTORY_* environment variables if desired.

LGTM.

<!-- greyfinch-sync:Marvisak/VIctory:review:6071538677 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3122#pullrequestreview-6071538677). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T09:27:35Z. **Review:** APPROVED --- Clean, well-scoped fix for NVIDIA's 1,000,000-descriptor view-heap cap. Reviewed `crates/victory-gpu/src/descriptor/host.rs` and `crates/victory-gpu/src/memory.rs`: - Non-overflow capped heaps (`count + MIN_DYNAMIC + CAPPED_PAIRS <= PORTABLE_VIEWS`) allocate `CAPPED_PAIRS` (65,536) slots past `[count, count + MIN_DYNAMIC)`, so `HostHeap::pair` stops falling back to `self.dynamic(2)` and draining per-draw dynamic slots. - Overflow capped heaps clamp `VICTORY_DYNAMIC_SLOTS` to `[MIN_DYNAMIC, PORTABLE_VIEWS / 2 - CAPPED_PAIRS]` (`[65_536, 434_464]`), preserving at least 500,000 in-place title slots plus 65,536 pair slots with no underflow. - Uncapped heaps / WARP stay on the existing `(count + DYNAMIC).max(HEAP_VIEWS)` path unchanged. - Updating `memory.rs` to assert `>= views.address_slots()` validates the real invariant (pairs live past dynamic slots) across both capped and uncapped layouts. Verified locally on Windows 11 with a 1M-capped RTX 5090 and WARP: - `cargo clippy --workspace --all-targets [--all-features] -- -D warnings`: clean - `cargo xtask policy`: `191 files ok` - RTX 5090: `descriptor::host::tests::` 15/15 passed (`dynamic_slots_are_held_until_released` now passes) and `memory::tests::` 8/8 passed (`lists_share_a_table_and_copies_keep_their_views` now passes) - RTX 5090 + `VICTORY_D3D12_DEBUG=1`: both previously failing tests pass with zero debug layer errors - RTX 5090 with `VICTORY_DYNAMIC_SLOTS=0`, `524288`, `999999999`: `dynamic_slots_are_held_until_released` passes in all cases - WARP (`--features diagnostics`, `VICTORY_D3D12_WARP=1`) + `VICTORY_D3D12_DEBUG=1`: `descriptor::host::tests::` 15/15 passed, `memory::tests::` 8/8 passed Two minor non-blocking notes: - `count + MIN_DYNAMIC + CAPPED_PAIRS` at `descriptor/host.rs:180,182` (like the existing `count + DYNAMIC` at line 175) uses unchecked `u32` addition; using `saturating_add` would guard against a wild title descriptor count. - `VICTORY_DYNAMIC_SLOTS` could be documented alongside the other `VICTORY_*` environment variables if desired. LGTM.
Indy2l commented 2026-11-26 10:05:03 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Indy2l on 2026-11-26T09:14:00Z.


Refs #1744. This should cover the failures there that come from the 1,000,000 view heap cap: dynamic_slots_are_held_until_released and lists_share_a_table_and_copies_keep_their_views pass on an RTX 3060 here and on an RTX 5090 per the review above. I haven't confirmed the other two failures in that report; if the reporter can re-run cargo test -p victory-gpu --lib on this branch, that would settle it.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7187632265 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3122#issuecomment-7187632265). Originally posted by [Indy2l](https://github.com/Indy2l) on 2026-11-26T09:14:00Z. --- Refs #1744. This should cover the failures there that come from the 1,000,000 view heap cap: `dynamic_slots_are_held_until_released` and `lists_share_a_table_and_copies_keep_their_views` pass on an RTX 3060 here and on an RTX 5090 per the review above. I haven't confirmed the other two failures in that report; if the reporter can re-run `cargo test -p victory-gpu --lib` on this branch, that would settle it.
Marvisak commented 2026-11-26 10:05:05 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-26T09:20:41Z.


Automated triage for the maintainers.

Needs work: please split it. The core fix is right. On a capped heap pairs_end == count + dynamic, so HostHeap::pair always fell back to self.dynamic(2). Reserving CAPPED_PAIRS past the dynamic range in HostHeap::new (crates/victory-gpu/src/descriptor/host.rs) fixes that, and the updated address_slots() assertion in memory.rs is good. Before merge:

  1. Move capped_dynamic/VICTORY_DYNAMIC_SLOTS to their own PR. It is a separate behaviour change with no test. It can take up to about half the heap from the title's kept-in-place slots, and its comment cites numbers from another fork. It can come back with measurements from this repo.
  2. Justify the 2^16 reservation. In the overflow branch, each of those slots is a title descriptor that can no longer be kept in place. The world's roughly 4,700 copies need about 9,400 slots per table, so 2^14 may be enough.
  3. Wrap the long let asked = ... line.

A PR with only the pair reservation, sized with a stated reason, would be a merge candidate. This does not overlap #3119.

CI: check passing.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7187821229 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3122#issuecomment-7187821229). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-26T09:20:41Z. --- <!-- victory-triage v1 head=d2b946aa7876b8f94225400dc08b2f6cb783c1aa verdict=needs-work at=2026-11-26T09:22:00Z --> Automated triage for the maintainers. **Needs work: please split it.** The core fix is right. On a capped heap `pairs_end == count + dynamic`, so `HostHeap::pair` always fell back to `self.dynamic(2)`. Reserving `CAPPED_PAIRS` past the dynamic range in `HostHeap::new` (`crates/victory-gpu/src/descriptor/host.rs`) fixes that, and the updated `address_slots()` assertion in `memory.rs` is good. Before merge: 1. Move `capped_dynamic`/`VICTORY_DYNAMIC_SLOTS` to their own PR. It is a separate behaviour change with no test. It can take up to about half the heap from the title's kept-in-place slots, and its comment cites numbers from another fork. It can come back with measurements from this repo. 2. Justify the 2^16 reservation. In the overflow branch, each of those slots is a title descriptor that can no longer be kept in place. The world's roughly 4,700 copies need about 9,400 slots per table, so 2^14 may be enough. 3. Wrap the long `let asked = ...` line. A PR with only the pair reservation, sized with a stated reason, would be a merge candidate. This does not overlap #3119. CI: `check` passing. --- _Generated by [Claude Code](https://claude.ai/code)_
Indy2l commented 2026-11-26 10:05:06 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Indy2l on 2026-11-26T09:32:50Z.


Thanks for the review. Addressed in 69618cf:

  1. capped_dynamic / VICTORY_DYNAMIC_SLOTS removed from this PR. I'll bring it back separately with in-world measurements from this repo.
  2. CAPPED_PAIRS is now 2^14, with the reason beside the constant: about 4,700 world copies take about 9,400 pair slots, so 2^14 gives about 1.7x headroom while taking fewer title slots in the overflow branch. Pairs past it still fall back to dynamic slots.
  3. The long line went with (1).

cargo test -p victory-gpu --lib (231 passed), both clippy configurations and cargo xtask policy are clean on an RTX 3060. The PR description is updated to match.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7188135848 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3122#issuecomment-7188135848). Originally posted by [Indy2l](https://github.com/Indy2l) on 2026-11-26T09:32:50Z. --- Thanks for the review. Addressed in 69618cf: 1. `capped_dynamic` / `VICTORY_DYNAMIC_SLOTS` removed from this PR. I'll bring it back separately with in-world measurements from this repo. 2. `CAPPED_PAIRS` is now 2^14, with the reason beside the constant: about 4,700 world copies take about 9,400 pair slots, so 2^14 gives about 1.7x headroom while taking fewer title slots in the overflow branch. Pairs past it still fall back to dynamic slots. 3. The long line went with (1). `cargo test -p victory-gpu --lib` (231 passed), both clippy configurations and `cargo xtask policy` are clean on an RTX 3060. The PR description is updated to match.
Indy2l commented 2026-11-27 11:52:55 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Indy2l on 2026-11-27T11:52:55Z.


Could this get a re-review when someone has time? The triage points are addressed in 69618cf: the VICTORY_DYNAMIC_SLOTS knob is split out, CAPPED_PAIRS is 2^14 with the reason beside the constant, and the long line went with the knob. CI passes, it merges cleanly, and it has been confirmed on RTX 3060 and RTX 5090 since.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7217583003 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3122#issuecomment-7217583003). Originally posted by [Indy2l](https://github.com/Indy2l) on 2026-11-27T11:52:55Z. --- Could this get a re-review when someone has time? The triage points are addressed in 69618cf: the `VICTORY_DYNAMIC_SLOTS` knob is split out, `CAPPED_PAIRS` is 2^14 with the reason beside the constant, and the long line went with the knob. CI passes, it merges cleanly, and it has been confirmed on RTX 3060 and RTX 5090 since.
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/3122:upstream-pr/3122'
git switch 'upstream-pr/3122'

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/3122'
git switch 'upstream-pr/3122'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3122'
git switch 'upstream-pr/3122'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3122'
git switch 'main'
git merge --squash 'upstream-pr/3122'
git switch 'main'
git merge --ff-only 'upstream-pr/3122'
git switch 'main'
git merge 'upstream-pr/3122'
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!3120
No description provided.