GPU: fresh tables are sized by their entries, and a capped heap keeps 2^18 dynamic slots #3870

Open
omarsaifuddin wants to merge 3 commits from upstream-pr/3870 into main
omarsaifuddin commented 2026-11-30 04:01:17 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by omarsaifuddin on 2026-11-30T04:01:17Z.


Stacked on #3518 (base df88467). The change is the last two commits; the rest of the diff is #3518's branch.

What

Two things in #3518's capped path cost it most of the world's draws on an NVIDIA card (measurements in #3518, RTX 3070 Ti):

1. A fresh table is sized by the shader register, not by its entries. UsedResource::lower_bound is the register of the first descriptor the program reads, not a count. #3518 sizes a fresh table with table_offset_dwords / 8 + lower_bound.max(1), and its "reaches past the host heap" check allows lower_bound - 1 extra entries. Over 80,000 fresh tables that took 8,579,260 dynamic slots for 361,283 entries, about 24x too many; the pool was exhausted (used=261,117 of 261,120) and most dropped draws were no dynamic slots for its tables.

This sizes a table by table_offset_dwords / 8 + 1, main's rule, and checks the last used entry. Heap::total_count existed only for the old .min(avail) clamp and goes with it: the clamp mixed the title's descriptor count with a host physical index, and could truncate a valid table.

2. The capped dynamic pool is 64,512. 2^16 ran out seconds into the world and 2^17 in the opening cutscene on capped NVIDIA hosts, where a frame asks for up to 16,000 tables while the previous frame still holds its own. A capped heap now takes DYNAMIC (2^18): 410,176 direct + 327,680 overflow + 261,120 dynamic, which is PORTABLE_VIEWS with NULL_RESERVE kept free. That leaves 737,856 simultaneously usable title slots, above the ~720,000 the title has been seen to use, while keeping #3518's overflow remap for active slots above the direct range.

Credits

The dynamic-budget idea is not new here:

  • #2475 (kais7654, taking over #1349 by wbkepler) reserves 2^18 on main's layout, and trims fresh tables to [first_used, last_used];
  • #3419 (danielibabet, #3518's author) keeps the full DYNAMIC on a capped heap, and #3860 repeats it;
  • #3300 (AdvaitPalve11) scales the same pool.

All are on main's layout, where a capped heap is (737,856 direct, 262,144 dynamic). This is the #3518-specific form: #3518 carves an overflow pool, so its split has three parts, and its fresh-table size is a separate bug (lower_bound), which none of the above touches.

Verified (RTX 3070 Ti, Windows 11)

  • victory-gpu --lib: 233 passed, 0 failed, 1 ignored; with --all-features: 248 passed, 0 failed, 1 ignored.
  • The capped remap test runs on the card and passes; it now also asserts the split sums to PORTABLE_VIEWS.
  • The shader remap GPU test above the 1M limit passes.
  • victory-shader --lib: 299 passed, 3 failed (the #3445 trio, the same on #3518 and on main), 3 ignored.
  • New unit test: a table at offset 8 with lower_bound = 278 sizes 2, not 279.

Not verified in-game from this branch; it reproduces the edits that ran 15-38 minutes on the card in #3518's thread. ROOT_VIEW_RUN = 16 from those experiments is left out (not isolated).

<!-- greyfinch-sync:Marvisak/VIctory:issue:5558736886 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3870). Originally posted by [omarsaifuddin](https://github.com/omarsaifuddin) on 2026-11-30T04:01:17Z. --- Stacked on #3518 (base `df88467`). The change is the **last two commits**; the rest of the diff is #3518's branch. ## What Two things in #3518's capped path cost it most of the world's draws on an NVIDIA card ([measurements in #3518](https://github.com/Marvisak/VIctory/pull/3518#issuecomment-7239421943), RTX 3070 Ti): **1. A fresh table is sized by the shader register, not by its entries.** `UsedResource::lower_bound` is the register of the first descriptor the program reads, not a count. #3518 sizes a fresh table with `table_offset_dwords / 8 + lower_bound.max(1)`, and its "reaches past the host heap" check allows `lower_bound - 1` extra entries. Over 80,000 fresh tables that took 8,579,260 dynamic slots for 361,283 entries, about 24x too many; the pool was exhausted (`used=261,117 of 261,120`) and most dropped draws were `no dynamic slots for its tables`. This sizes a table by `table_offset_dwords / 8 + 1`, main's rule, and checks the last used entry. `Heap::total_count` existed only for the old `.min(avail)` clamp and goes with it: the clamp mixed the title's descriptor count with a host physical index, and could truncate a valid table. **2. The capped dynamic pool is 64,512.** 2^16 ran out seconds into the world and 2^17 in the opening cutscene on capped NVIDIA hosts, where a frame asks for up to 16,000 tables while the previous frame still holds its own. A capped heap now takes `DYNAMIC` (2^18): **410,176 direct + 327,680 overflow + 261,120 dynamic**, which is `PORTABLE_VIEWS` with `NULL_RESERVE` kept free. That leaves 737,856 simultaneously usable title slots, above the ~720,000 the title has been seen to use, while keeping #3518's overflow remap for active slots above the direct range. ## Credits The dynamic-budget idea is not new here: - **#2475** (kais7654, taking over **#1349** by wbkepler) reserves 2^18 on main's layout, and trims fresh tables to `[first_used, last_used]`; - **#3419** (danielibabet, #3518's author) keeps the full `DYNAMIC` on a capped heap, and **#3860** repeats it; - **#3300** (AdvaitPalve11) scales the same pool. All are on main's layout, where a capped heap is `(737,856 direct, 262,144 dynamic)`. This is the #3518-specific form: #3518 carves an overflow pool, so its split has three parts, and its fresh-table size is a separate bug (`lower_bound`), which none of the above touches. ## Verified (RTX 3070 Ti, Windows 11) - `victory-gpu --lib`: 233 passed, 0 failed, 1 ignored; with `--all-features`: 248 passed, 0 failed, 1 ignored. - The capped remap test runs on the card and passes; it now also asserts the split sums to `PORTABLE_VIEWS`. - The shader remap GPU test above the 1M limit passes. - `victory-shader --lib`: 299 passed, 3 failed (the #3445 trio, the same on #3518 and on main), 3 ignored. - New unit test: a table at offset 8 with `lower_bound = 278` sizes 2, not 279. Not verified in-game from this branch; it reproduces the edits that ran 15-38 minutes on the card in #3518's thread. `ROOT_VIEW_RUN = 16` from those experiments is left out (not isolated).
omarsaifuddin commented 2026-11-30 07:37:37 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by omarsaifuddin on 2026-11-30T07:37:37Z.


Run evidence from the RTX 3070 Ti for the capped path, 1440p, full stack (#3330's stack plus the atomic PR):

  • A 20-minute run reached the prologue, no device removal.
  • The overflow pool (327,680) exhausts once per run during world load at virtual title slots 512,976, 771,612, 482,134 and 623,415 (the last on a build without the atomic change, so it is not that PR).
  • The split is 410,176 direct + 327,680 overflow + 261,120 dynamic + 1,024 reserve = 1,000,000; the title's heap is 1,245,184 slots. The pool fills with active high slots, so the title's live views exceed the host's 737,856 title slots — this is the 1M cap, not the split.
  • The alternative 737,856 direct + 0 overflow cannot map a slot at 771,612 at all, so it would not remove the warning either.

No change requested here: the split is the best best-effort the 1M cap allows, and the warning did not remove the device in these runs. A VICTORY_LOG=victory_gpu::descriptor::host=info run would print the live high-slot peak if the review wants the number.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7271942224 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3870#issuecomment-7271942224). Originally posted by [omarsaifuddin](https://github.com/omarsaifuddin) on 2026-11-30T07:37:37Z. --- Run evidence from the RTX 3070 Ti for the capped path, 1440p, full stack (#3330's stack plus the atomic PR): - A 20-minute run reached the prologue, **no device removal**. - The overflow pool (327,680) exhausts once per run during world load at virtual title slots **512,976**, **771,612**, **482,134** and **623,415** (the last on a build without the atomic change, so it is not that PR). - The split is 410,176 direct + 327,680 overflow + 261,120 dynamic + 1,024 reserve = 1,000,000; the title's heap is 1,245,184 slots. The pool fills with *active* high slots, so the title's live views exceed the host's 737,856 title slots — this is the 1M cap, not the split. - The alternative 737,856 direct + 0 overflow cannot map a slot at 771,612 at all, so it would not remove the warning either. No change requested here: the split is the best best-effort the 1M cap allows, and the warning did not remove the device in these runs. A `VICTORY_LOG=victory_gpu::descriptor::host=info` run would print the live high-slot peak if the review wants the number.
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/3870:upstream-pr/3870'
git switch 'upstream-pr/3870'

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