Skip to content

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

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

0xkn0wh3r3 wants to merge 3 commits into
Marvisak:mainfrom
0xkn0wh3r3:gpu/bounded-view-table

Conversation

@0xkn0wh3r3

@0xkn0wh3r3 0xkn0wh3r3 commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

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

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 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
Contributor

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

Marvisak commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

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

desplmfao added a commit to desplmfao/VIctory that referenced this pull request Nov 25, 2026
desplmfao added a commit to desplmfao/VIctory that referenced this pull request Nov 25, 2026
The previous main (old upstream base) is the first parent; the second is
upstream main with the current heads of our pull requests merged in:
Marvisak#2143, Marvisak#1849 (carried onto main's per-region runtime_pages), Marvisak#259, Marvisak#491,
Marvisak#2153, Marvisak#2099, Marvisak#2071 (main covers it), Marvisak#2162, Marvisak#2218, Marvisak#2088, Marvisak#2389, Marvisak#177's
element-type key on main's three handle maps, and the README. Marvisak#2112
(opt-in, in place) stays in the renderer branch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@0xkn0wh3r3

Copy link
Copy Markdown
Contributor Author

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.

@pickles976

Copy link
Copy Markdown

Independent Wine/NVIDIA check of 82d5d11, 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.

0xkn0wh3r3 added a commit to 0xkn0wh3r3/VIctory that referenced this pull request Nov 25, 2026
0xkn0wh3r3 and others added 3 commits November 25, 2026 17:06
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>
… records

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.
@0xkn0wh3r3
0xkn0wh3r3 force-pushed the gpu/bounded-view-table branch from 82d5d11 to 2cad160 Compare November 25, 2026 22:09
0xkn0wh3r3 added a commit to 0xkn0wh3r3/VIctory that referenced this pull request Nov 26, 2026
desplmfao added a commit to desplmfao/VIctory that referenced this pull request Nov 26, 2026
…e in their records

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

# Conflicts:
#	crates/victory-gpu/src/descriptor.rs
desplmfao added a commit to desplmfao/VIctory that referenced this pull request Nov 26, 2026
…nd views held whole)

descriptor.rs is fork/main's but for Marvisak#688's lease module.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
desplmfao added a commit to desplmfao/VIctory that referenced this pull request Nov 26, 2026
The previous renderer (old upstream base 940d32f) is the first parent and
is also kept as the branch renderer-2026-11-25-oldbase; the second parent
is the rebuild: fork main (upstream main 63bcca4 + our pull requests) with
the renderer stack merged on it: Marvisak#439 (on main: update/439-main's
resolution), Marvisak#2309, Marvisak#2167, Marvisak#2118, Marvisak#2311, Marvisak#1722, Marvisak#1751, Marvisak#688, Marvisak#1872, Marvisak#2292,
Marvisak#2310, Marvisak#2112 (opt-in), Marvisak#2230 (latch on by default), Marvisak#2389, Marvisak#2088 (small
windows opt-in), Marvisak#2099's new head, and tonight's Marvisak#491 journal fixes.
Merged upstream since: Marvisak#2143, Marvisak#2162, Marvisak#158, Marvisak#1906, Marvisak#1152; superseded by
main: Marvisak#1769, Marvisak#1763, Marvisak#2366.

The picture on this base still shows the overlay that plain upstream main
shows too; that is being looked into.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

6 participants