GPU: stop the descriptor view table growing without bound #2099

Open
github-bot wants to merge 3 commits from github-bot/gh-2099 into main AGit
Owner

@⁠0xkn0wh3r3 on GitHub · 2026-11-25 04:59 UTC · original
0xkn0wh3r3:gpu/bounded-view-table → main · +438 −37 · 2 files · 3 commits · open

The problem

The descriptor view table grows for the whole run, by about 1 GB after four minutes of Grand Theft Auto VI.

The table (Views in descriptor.rs) never frees constant buffer views or views of placed memory. They have no resource object, so nothing releases them. Grand Theft Auto VI writes about 14,000 constant buffer views a frame at new addresses, and each is a new entry. Measured on fxceless/victory-fork: about 2.45 million entries (about 1 GB) after four minutes, and 11,000 more every second.

The fix

These two kinds of view are no longer table entries. A descriptor's record already holds two 32-bit words; their top two bits now say what they hold:

  • A table entry, as before (other views).
  • A constant buffer view: its address and size, stored directly (constant_words).
  • A placed view: its address and a shape number (placed_words). A shape is the view's description without the address, kept in a small table of its own (one per kind of texture or buffer, however often the title moves them).

Details:

  • Views too large to fit stay table entries: a constant buffer view past a 47-bit address, or of 16 KiB or more that is not a multiple of 256 bytes or reaches 4 MiB; a placed view past 1 TiB; any placed view once the shape table is full.
  • Readers go through view_at, which decodes all three. The host heap already read records through it; descriptor::view now does too.
  • A table entry's generation now wraps below the two kind bits, so a released view's record never reads as a constant buffer or placed view.

Ported from fxceless/victory-fork (commit 578d459): the view-table change only, not that commit's other descriptor changes.

Testing

  • Three new CPU-only tests:
    • constant_views_fit_their_records: records round-trip addresses and sizes, and views that do not fit say so.
    • views_at_new_addresses_add_no_entries: 20,000 views at new addresses add no table entries, and one shape stands for all the placed views.
    • released_entries_keep_their_generations_below_the_kind_bits: a table generation wraps without colliding with the new record kinds.
  • cargo test -p victory-gpu --lib on an RTX 5070 Ti: all pass except the two tests that already fail on main from the NVIDIA heap cap (#1835).
  • cargo clippy -p victory-gpu --all-targets, with and without --features diagnostics: clean.

Not covered

Not run with a game (no game data here); the growth figures are from the fork's run.

Rebased onto 13f91ca

Upstream's heap sync (f809521) checks a page's records under one lock with views_current, which read the table directly instead of going through view_at. Records holding a constant buffer or placed view were never current, so a sync never made their slots (heap_syncs_make_the_slots_whose_records_changed failed). views_current now decodes records as view_at does. Two new tests cover it: views_held_whole_are_current_for_heap_syncs (CPU-only) and heap_syncs_make_the_slots_whose_records_hold_their_views_whole. Test, clippy and policy results are unchanged from above.

Rebased onto f3578e3

Only the tests conflicted (beside #2449's null_cbv_clears_a_stale_view). #2449's null CBV is Constant(0, 0), which a record holds whole like any other constant buffer view. No upstream change since 13f91ca reads record words apart from view_at/views_current (#1906's view addresses, #2234, #2262 and #2462 work on decoded views). cargo test -p victory-gpu --lib: all pass but the three that fail on main here (two NVIDIA heap-cap tests and the flaky views_bound_while_another_slot_gets_its_texture_do_not_wait). Clippy clean with and without --features diagnostics; cargo xtask policy passes.

**@⁠0xkn0wh3r3** on GitHub · 2026-11-25 04:59 UTC · [original](https://github.com/Marvisak/VIctory/pull/2099) `0xkn0wh3r3:gpu/bounded-view-table` → `main` · +438 −37 · 2 files · 3 commits · open ## The problem The descriptor view table grows for the whole run, by about 1 GB after four minutes of Grand Theft Auto VI. The table (`Views` in `descriptor.rs`) never frees constant buffer views or views of placed memory. They have no resource object, so nothing releases them. Grand Theft Auto VI writes about 14,000 constant buffer views a frame at new addresses, and each is a new entry. Measured on fxceless/victory-fork: about 2.45 million entries (about 1 GB) after four minutes, and 11,000 more every second. ## The fix These two kinds of view are no longer table entries. A descriptor's record already holds two 32-bit words; their top two bits now say what they hold: - **A table entry**, as before (other views). - **A constant buffer view**: its address and size, stored directly (`constant_words`). - **A placed view**: its address and a shape number (`placed_words`). A shape is the view's description without the address, kept in a small table of its own (one per kind of texture or buffer, however often the title moves them). Details: - Views too large to fit stay table entries: a constant buffer view past a 47-bit address, or of 16 KiB or more that is not a multiple of 256 bytes or reaches 4 MiB; a placed view past 1 TiB; any placed view once the shape table is full. - Readers go through `view_at`, which decodes all three. The host heap already read records through it; `descriptor::view` now does too. - A table entry's generation now wraps below the two kind bits, so a released view's record never reads as a constant buffer or placed view. Ported from fxceless/victory-fork (commit 578d459): the view-table change only, not that commit's other descriptor changes. ## Testing - Three new CPU-only tests: - `constant_views_fit_their_records`: records round-trip addresses and sizes, and views that do not fit say so. - `views_at_new_addresses_add_no_entries`: 20,000 views at new addresses add no table entries, and one shape stands for all the placed views. - `released_entries_keep_their_generations_below_the_kind_bits`: a table generation wraps without colliding with the new record kinds. - `cargo test -p victory-gpu --lib` on an RTX 5070 Ti: all pass except the two tests that already fail on `main` from the NVIDIA heap cap (#1835). - `cargo clippy -p victory-gpu --all-targets`, with and without `--features diagnostics`: clean. ## Not covered Not run with a game (no game data here); the growth figures are from the fork's run. ### Rebased onto 13f91ca Upstream's heap sync (f809521) checks a page's records under one lock with `views_current`, which read the table directly instead of going through `view_at`. Records holding a constant buffer or placed view were never current, so a sync never made their slots (`heap_syncs_make_the_slots_whose_records_changed` failed). `views_current` now decodes records as `view_at` does. Two new tests cover it: `views_held_whole_are_current_for_heap_syncs` (CPU-only) and `heap_syncs_make_the_slots_whose_records_hold_their_views_whole`. Test, clippy and policy results are unchanged from above. ### Rebased onto f3578e3 Only the tests conflicted (beside #2449's `null_cbv_clears_a_stale_view`). #2449's null CBV is `Constant(0, 0)`, which a record holds whole like any other constant buffer view. No upstream change since 13f91ca reads record words apart from `view_at`/`views_current` (#1906's view addresses, #2234, #2262 and #2462 work on decoded views). `cargo test -p victory-gpu --lib`: all pass but the three that fail on `main` here (two NVIDIA heap-cap tests and the flaky `views_bound_while_another_slot_gets_its_texture_do_not_wait`). Clippy clean with and without `--features diagnostics`; `cargo xtask policy` passes.
Every view a title writes is kept in one table, and a descriptor's
record (the tag and two words) names its entry and generation, which
survives titles copying descriptors as bytes. Views of resource objects
are freed with their resource, but views without one (constant buffers,
views of placed memory) have nothing that releases them, so their
entries were kept for the run. Grand Theft Auto VI writes some 14,000
constant buffer views a frame, each at the address its constants have
that frame: on fxceless/victory-fork, 2,450,139 entries after four
minutes of play, about 1 GB with the index, growing by 11,000 a second.

The record's two words now say what they hold in the generation's top
two bits: 0, a table entry as before (generations stay below those
bits); a constant buffer view whole (a 47-bit address and a 15-bit
size: bytes below 16 KiB, else 256-byte units below 4 MiB); or a view of
placed memory whole (a 40-bit title address and the number of its
"shape", the view's description without its address, kept in a table
of their own: as many as the title has kinds of textures and buffers).
Views that do not fit (larger addresses or sizes, shapes past 2^22)
stay table entries. Every reader goes through `view_at`, which decodes
all three; the host heap keys its slots by the same two words, which
stay equal for equal views and differ for different ones.
`VICTORY_VIEW_INLINE=0` keeps every view a table entry.

Ported from fxceless/victory-fork (commit 578d459), the view-table part
only (not that commit's other descriptor changes).

Tests (no GPU needed):
- `constant_views_fit_their_records`: addresses and sizes round-trip,
  and those that do not fit say so.
- `views_at_new_addresses_add_no_entries`: 20,000 constant buffer and
  placed views at new addresses add no entries and one shape.
- `released_entries_keep_their_generations_below_the_kind_bits`: a
  generation bumped past the top wraps to 1, and the released view's
  record goes stale.

Co-authored-by: fxceless <[email protected]>
The VICTORY_VIEW_INLINE switch is gone, and the view table's doc comment
says only what the code does; the measurements stay in the pull request.
`views_current`, which a heap sync uses to look at a page's records under
one lock, compared every record with the table entry it names, so a
record holding a constant buffer view or a view of placed memory whole
was never current and its slot was never made: a title copying such
records as bytes left the copies null. It now decodes records as
`view_at` does: a table entry at its own generation, a constant buffer
view, or a placed view whose shape is numbered.

Tests:
- `views_held_whole_are_current_for_heap_syncs` (no GPU needed):
  `views_current` agrees with `view_at` on constant and placed views held
  whole, live and released table entries, unknown shapes and kinds, and
  records without the tag.
- `heap_syncs_make_the_slots_whose_records_hold_their_views_whole`: a
  heap sync makes slots given byte copies of a constant buffer view's and
  a placed view's records, and leaves a cleared one null.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:54:45 +00:00
Author
Owner

@⁠desplmfao on GitHub · 2026-11-25 06:21 UTC · original

Tested this in Grand Theft Auto VI's world: RTX 5080, Linux, proton-cachyos 11.0, on main plus a few other open PRs (#2153, #2151). I measured VIctory's Rust heap with a counting global allocator and tracked allocations of 1 MiB or more by call site.

  • Without this PR, VIctory's heap grew about 200 MB every 30 s in the world. The top growing site was the Vec in descriptor::record (68, then 136, then 272 MB), and blocks under 4 KB grew alongside it, which fits the BTreeMap index.
  • With this PR, the heap stayed flat at about 1.4 GB over several minutes in the world. descriptor::record was no longer among the top sites.
  • Frame time didn't change: 428–452 ms per frame, against 442–451 ms without it.
  • It merged into that stack without conflicts.
**@⁠desplmfao** on GitHub · 2026-11-25 06:21 UTC · [original](https://github.com/Marvisak/VIctory/pull/2099#issuecomment-7154707953) Tested this in Grand Theft Auto VI's world: RTX 5080, Linux, proton-cachyos 11.0, on `main` plus a few other open PRs (#2153, #2151). I measured VIctory's Rust heap with a counting global allocator and tracked allocations of 1 MiB or more by call site. - Without this PR, VIctory's heap grew about 200 MB every 30 s in the world. The top growing site was the `Vec` in `descriptor::record` (68, then 136, then 272 MB), and blocks under 4 KB grew alongside it, which fits the `BTreeMap` index. - With this PR, the heap stayed flat at about 1.4 GB over several minutes in the world. `descriptor::record` was no longer among the top sites. - Frame time didn't change: 428–452 ms per frame, against 442–451 ms without it. - It merged into that stack without conflicts.
Author
Owner

@⁠0xkn0wh3r3 on GitHub · 2026-11-25 06:35 UTC · original

@⁠catminou4: there's no eviction. When something doesn't fit the new compact form, it stays an ordinary table entry, exactly as before this change. That covers a constant-buffer view past a 47-bit address, or one of 16 KiB or more that isn't a multiple of 256 bytes or reaches 4 MiB, a placed view past 1 TiB, and any placed view once the shape table is full. So hitting the cap only means those views grow the table as they do on main; nothing is dropped or reused. The shape table holds one entry per kind of texture or buffer description, without the address, so it stays small however often the game moves its views.

**@⁠0xkn0wh3r3** on GitHub · 2026-11-25 06:35 UTC · [original](https://github.com/Marvisak/VIctory/pull/2099#issuecomment-7154951478) @⁠catminou4: there's no eviction. When something doesn't fit the new compact form, it stays an ordinary table entry, exactly as before this change. That covers a constant-buffer view past a 47-bit address, or one of 16 KiB or more that isn't a multiple of 256 bytes or reaches 4 MiB, a placed view past 1 TiB, and any placed view once the shape table is full. So hitting the cap only means those views grow the table as they do on `main`; nothing is dropped or reused. The shape table holds one entry per kind of texture or buffer description, without the address, so it stays small however often the game moves its views.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 10:37 UTC · original · edited 2026-11-26 01:21 UTC

Automated triage for the maintainers.

Merge candidate (re-checked on 2cad160). This push is a rebase onto main. A range-diff against the previously reviewed head 82d5d11 shows the three commits unchanged. The only difference is one context line in an existing descriptor.rs test, taken from main.

The change itself is unchanged. Constant buffer and placed views are encoded whole in their descriptor records (constant_words, placed_words plus the small shapes table), so they no longer add a Views table entry each time. view_at and views_current decode all three record kinds, and table generations wrap below the kind bits. An independent NVIDIA/Wine check of the previous head passed the five focused tests, including the host heap-sync test.

CI: passing (check).


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 10:37 UTC · [original](https://github.com/Marvisak/VIctory/pull/2099#issuecomment-7159952855) · edited 2026-11-26 01:21 UTC <!-- victory-triage v1 head=2cad1608b26f2c83679d762f23b1653cb10da61f verdict=merge-candidate at=2026-11-26T01:21:13Z --> Automated triage for the maintainers. **Merge candidate (re-checked on `2cad160`).** This push is a rebase onto `main`. A range-diff against the previously reviewed head `82d5d11` shows the three commits unchanged. The only difference is one context line in an existing `descriptor.rs` test, taken from `main`. The change itself is unchanged. Constant buffer and placed views are encoded whole in their descriptor records (`constant_words`, `placed_words` plus the small `shapes` table), so they no longer add a `Views` table entry each time. `view_at` and `views_current` decode all three record kinds, and table generations wrap below the kind bits. An independent NVIDIA/Wine check of the previous head passed the five focused tests, including the host heap-sync test. CI: passing (`check`). --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠0xkn0wh3r3 on GitHub · 2026-11-25 18:37 UTC · original

Thanks, both done in b0af626:

  • The Views doc comment now says only what the code does: constant buffer and placed views are named whole in their records, and the table keeps only placed-view shapes and the views that don't fit. The run figures and the fork reference are now only in the description. The same trim applies to views_at_new_addresses_add_no_entries's doc comment.
  • VICTORY_VIEW_INLINE is gone. Nothing depended on it, and the test that skipped when it was off now always runs.
**@⁠0xkn0wh3r3** on GitHub · 2026-11-25 18:37 UTC · [original](https://github.com/Marvisak/VIctory/pull/2099#issuecomment-7171159276) Thanks, both done in b0af626: - The `Views` doc comment now says only what the code does: constant buffer and placed views are named whole in their records, and the table keeps only placed-view shapes and the views that don't fit. The run figures and the fork reference are now only in the description. The same trim applies to `views_at_new_addresses_add_no_entries`'s doc comment. - `VICTORY_VIEW_INLINE` is gone. Nothing depended on it, and the test that skipped when it was off now always runs.
Author
Owner

@⁠pickles976 on GitHub · 2026-11-25 20:25 UTC · original

Independent Wine/NVIDIA check of 82d5d117b71808d2cd82fc7e367371c320cf9eb4, including the views_current / heap-sync follow-up. This used a separate checkout of the exact PR head, not our older title-integration tree.

Environment: RTX 4060 Laptop 8 GiB, 16 GiB system RAM; Linux 6.17.0-40-generic; Wine 11.0; NVIDIA 590.48.01; DXVK 3.1.1-209-g1039f682058fa71; stock vkd3d-proton 3.2.0 (2576c0b4adfae4a). Rust 1.98.1 Windows-MSVC cross-build, Wine Cargo runner, VICTORY_ADAPTER=nvidia, DXVK_CONFIG='dxgi.hideNvidiaGpu = False'. No Microsoft D3D12 debug-layer validation.

After configuring the Windows SDK/linker and runner environment:

cargo +1.98.1 test --locked --target x86_64-pc-windows-msvc \
  -p victory-gpu --lib -- --nocapture --test-threads=1 \
  constant_views_fit_their_records \
  views_at_new_addresses_add_no_entries \
  released_entries_keep_their_generations_below_the_kind_bits \
  views_held_whole_are_current_for_heap_syncs \
  heap_syncs_make_the_slots_whose_records_hold_their_views_whole

5 passed, 0 failed, 0 ignored. This covers compact CBV round-trips/boundaries, 20,000 changing addresses without table growth, generation wrapping/stale views, current-record classification, and the host-heap synchronization path for byte-copied compact records.

To rule out the GPU fixture's silent host().is_none() return, I temporarily replaced only that return with assert!(host().is_some(), ...) and reran heap_syncs_make_the_slots_whose_records_hold_their_views_whole: 1 passed. The real NVIDIA device and host descriptor heap were used. That test-only change was then reverted; no runtime code was altered.

Limits: the host test checks descriptor creation/synchronization, not shader execution or pixel readback. No full-suite result, in-title memory-growth measurement, VRAM saving, world-entry pass, or 15-minute stability claim follows from these checks. Those remain separate from the focused compatibility result above.

AI-assisted: omp with openai-codex/gpt-6-astra inspected the PR, ran the checks and temporary no-skip probe, and prepared this report from the observed output.

**@⁠pickles976** on GitHub · 2026-11-25 20:25 UTC · [original](https://github.com/Marvisak/VIctory/pull/2099#issuecomment-7173643380) Independent Wine/NVIDIA check of **82d5d117b71808d2cd82fc7e367371c320cf9eb4**, including the `views_current` / heap-sync follow-up. This used a separate checkout of the exact PR head, not our older title-integration tree. **Environment:** RTX 4060 Laptop 8 GiB, 16 GiB system RAM; Linux 6.17.0-40-generic; Wine 11.0; NVIDIA 590.48.01; DXVK 3.1.1-209-g1039f682058fa71; stock vkd3d-proton 3.2.0 (`2576c0b4adfae4a`). Rust 1.98.1 Windows-MSVC cross-build, Wine Cargo runner, `VICTORY_ADAPTER=nvidia`, `DXVK_CONFIG='dxgi.hideNvidiaGpu = False'`. No Microsoft D3D12 debug-layer validation. After configuring the Windows SDK/linker and runner environment: ```sh cargo +1.98.1 test --locked --target x86_64-pc-windows-msvc \ -p victory-gpu --lib -- --nocapture --test-threads=1 \ constant_views_fit_their_records \ views_at_new_addresses_add_no_entries \ released_entries_keep_their_generations_below_the_kind_bits \ views_held_whole_are_current_for_heap_syncs \ heap_syncs_make_the_slots_whose_records_hold_their_views_whole ``` **5 passed, 0 failed, 0 ignored.** This covers compact CBV round-trips/boundaries, 20,000 changing addresses without table growth, generation wrapping/stale views, current-record classification, and the host-heap synchronization path for byte-copied compact records. To rule out the GPU fixture's silent `host().is_none()` return, I temporarily replaced only that return with `assert!(host().is_some(), ...)` and reran `heap_syncs_make_the_slots_whose_records_hold_their_views_whole`: **1 passed**. The real NVIDIA device and host descriptor heap were used. That test-only change was then reverted; no runtime code was altered. **Limits:** the host test checks descriptor creation/synchronization, not shader execution or pixel readback. No full-suite result, in-title memory-growth measurement, VRAM saving, world-entry pass, or 15-minute stability claim follows from these checks. Those remain separate from the focused compatibility result above. AI-assisted: omp with `openai-codex/gpt-6-astra` inspected the PR, ran the checks and temporary no-skip probe, and prepared this report from the observed output.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2099/head:github-bot/gh-2099'
git switch 'github-bot/gh-2099'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2099'
git switch 'github-bot/gh-2099'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2099'
git switch 'github-bot/gh-2099'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2099'
git switch 'main'
git merge --squash 'github-bot/gh-2099'
git switch 'main'
git merge --ff-only 'github-bot/gh-2099'
git switch 'main'
git merge 'github-bot/gh-2099'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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!2099
No description provided.