Skip to content

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

Open
0xkn0wh3r3 wants to merge 1 commit into
Marvisak:mainfrom
0xkn0wh3r3:gpu/bounded-view-table
Open

0xkn0wh3r3 wants to merge 1 commit into
Marvisak:mainfrom
0xkn0wh3r3:gpu/bounded-view-table

Conversation

@0xkn0wh3r3

@0xkn0wh3r3 0xkn0wh3r3 commented Nov 25, 2026 •

Copy link
Copy Markdown

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.
  • VICTORY_VIEW_INLINE=0 restores the old behaviour.

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, with the change on and with VICTORY_VIEW_INLINE=0: all pass except the two tests that already fail on main from the NVIDIA heap cap (NVIDIA D3D12 (70564ae): stride_tests & synthetic_tests fail due to HEAP_VIEWS (2M > 1M NVIDIA limit) and Stride::Structured with rawBufferLoad #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.

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 <36782933+fxceless@users.noreply.github.com>
@0xkn0wh3r3 0xkn0wh3r3 changed the title GPU: constant buffer and placed views are named whole in their records GPU: stop the descriptor view table growing without bound Nov 25, 2026

@catminou4 catminou4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Descriptor view table bounded — stops unbounded growth; check the eviction policy when the cap is hit (LRU vs fail).

@DenRakEiw DenRakEiw left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified locally merged onto origin/main (940d32f, Windows 11 x64, Rust 1.98.1 MSVC):

  • cargo test -p victory-gpu --lib descriptor::tests:: — 8 passed, 0 failed
  • cargo clippy -p victory-gpu --all-targets — 0 warnings
  • cargo xtask policy — ok (183 files ok)

Clean bounded inline/generational representation stopping unbounded growth of the descriptor view table. Looks good.

AI-assisted (Gemini 4 Neon).

@desplmfao

Copy link
Copy Markdown

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.

github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 25, 2026
@0xkn0wh3r3

Copy link
Copy Markdown
Author

@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.

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

The change in descriptor.rs looks sound by reading. constant_words/placed_words encode CBVs and placed views directly in the record. The size and address limits round-trip. view_at decodes all three kinds. In forget, generations now wrap below the kind bits, so host slot keys stay non-zero and distinct. A tester also reports the heap stays flat with it. Before merge, it needs:

  • The new Views doc comment is design rationale with run measurements and a reference to an outside fork (repo docs stay short). Trim it to what the code does, and keep the numbers in the PR.
  • The VICTORY_VIEW_INLINE switch is an extra env knob. Drop it, or justify keeping it.
  • CI has not run on this head.

Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants