Views: placed views' shapes leave out description padding, so the view table stops leaking #247

Open
SpeezusChrist23 wants to merge 1 commit from upstream-pr/247 into main
SpeezusChrist23 commented 2026-12-01 00:56:40 +00:00 (Migrated from github.com)

Imported from DexNom/VIctory. Originally posted by SpeezusChrist23 on 2026-12-01T00:56:40Z.


Symptom

In a long play session, the CPU time spent preparing each frame grows steadily while GPU time stays flat:

  • prep is ~33 ms at 10 min, ~60 at 30, ~92 at 60 and 120-155 at 80-90;
  • the process's private bytes grow from 24.7 to 38.8 GB;
  • on a 32 GB PC free memory stays under 1 GB from ~20 min on, and the working set is trimmed (paging).

Short test runs (30 min) do not show it.

Cause

descriptor.rs Views names a view of placed memory in its record by a shape (the resource and view descriptions without the address, at most 2^22 = 4,194,304) and the address. The shapes are meant to be as many as the title has kinds of textures and buffers. But a shape kept words 1 and 13 of the resource description, which are the padding of D3D12_RESOURCE_DESC's layout. The title leaves there whatever its stack held.

resource::texture_at already leaves those two words out of its key for that reason. Its "asked for again with other filler words" count reached 563k in the same run.

So almost every placed view written made a new shape:

  • ~600 a second, 1.8 M at 10 min, 3.5 M at 30, full at ~35 min.
  • From then on every placed view at a new address became a table entry. Nothing ever releases those (no resource object): 23.5 M entries and 10 GB after 90 min.
  • Every placed view written looks its shape up in a BTreeMap of millions of 113-byte keys, and then in a 23 M-entry one.
  • New entries take the table's lock, which the recording threads wait behind.
  • The PC runs out of memory, so everything that touches memory slows down.

Evidence

One ~100-min session at 1080p, in 5-min buckets of the memory and frame log lines:

min prep ms GPU ms draws shapes of placed views kept view table entries table MB own allocations MB private MB PC free MB
10 33 9.5 3200 1.8 M 8.3 k 534 2132 24740 1879
30 60 16.9 5400 3.5 M 10.6 k 1132 2874 26700 942
35 70 17.3 6900 4,194,304 (full) 1.0 M 1541 3320 27580 1359
60 92 11.5 8200 full 13.8 M 6030 7898 33680 370
80 155 7.9 8250 full 22.6 M 9909 11782 38300 754
90 122 14.3 5300 full 25.3 M 10436 12315 38820 713
  • Prep per 1000 draws stays at ~10-11 ms up to ~60 min (that part follows the scene). It is 18-29 ms after that.
  • Other per-frame parts slow down together: looking at slots 3.8 -> 26 ms, journal lock waits 5 -> 18-29 ms.
  • The memory line's own blocks show a 4.3 GB block (the table's Vec), and the blocks under 4 KiB grow from 577 MB to 5.75 GB.

With the fix (a live session with the same settings): 71,928 shapes at 16 min (1.8 M at 10 min before), and the view table at 8,741 entries / 30 MB (10 GB before).

  • The remaining growth (~28 shapes a second) is real data. The new log line names the words that differ: buffer widths, first element, element count, stride, format.
  • At that rate the cap is ~40 h away.

The fix (without_filler, on by default)

create_placed_srv / create_placed_uav zero the padding before the view is recorded:

  • words 1 and 13 of the resource description;
  • the shader view's word 3 (between the component mapping and the union);
  • the union's words past the member its dimension uses, for each D3D12 SRV/UAV dimension. A dimension not known there keeps every word.

The host reads these descriptions only as the D3D12 structures (srv_desc / uav_desc) and by their meaningful words, so nothing it builds changes. Views that differed only in padding become one shape and one record, so their slots are also no longer re-made for padding alone.

Switch and logging

  • VICTORY_SHAPE_FILLER=1 keeps the padding, as before. =2 leaves out only resource words 1/13.
  • A new log line at each power of two of shapes from 4,096 (and every 262,144): "shapes of placed views: N kept ... the new ones from 4096 on differ from the one before them in: unordered .., resource words [..], view words 0-9 [..] and 12-15 [..]". It names whatever still makes new shapes.
  • A WARN once when the shapes are full.

Tests

  • descriptor::tests::filler_makes_no_new_shapes: 5,000 placed views with the run's kind of padding (words 1 and 13 changing, the view's word 3 and unused union words changing) make one shape, and the view read back has no padding. Another mip count or height still makes a new shape.
  • descriptor::tests::filler_leaves_what_the_host_reads: every member word of buffer SRV/UAV, 2-D UAV and 2-D array SRV views is kept, and unknown dimensions are kept whole.
  • descriptor::tests::views_at_new_addresses_add_no_entries is updated for views read back without padding.

Checked on this branch: cargo clippy -p victory-gpu --all-targets --locked -- -D warnings, the same with --all-features, and cargo test -p victory-gpu --lib (221 passed, 4 ignored; all 45 descriptor:: tests pass).

Found and verified on an AMD RX 6700 XT.

🤖 Generated with Claude Code

https://claude.ai/code/session_01S4xxcyVsTQvsBVmaF2gBZs

<!-- greyfinch-sync:DexNom/VIctory:issue:5576688030 --> Imported from [DexNom/VIctory](https://github.com/DexNom/VIctory/pull/247). Originally posted by [SpeezusChrist23](https://github.com/SpeezusChrist23) on 2026-12-01T00:56:40Z. --- ## Symptom In a long play session, the CPU time spent preparing each frame grows steadily while GPU time stays flat: - prep is ~33 ms at 10 min, ~60 at 30, ~92 at 60 and 120-155 at 80-90; - the process's private bytes grow from 24.7 to 38.8 GB; - on a 32 GB PC free memory stays under 1 GB from ~20 min on, and the working set is trimmed (paging). Short test runs (30 min) do not show it. ## Cause `descriptor.rs` `Views` names a view of placed memory in its record by a *shape* (the resource and view descriptions without the address, at most 2^22 = 4,194,304) and the address. The shapes are meant to be as many as the title has kinds of textures and buffers. But a shape kept **words 1 and 13 of the resource description**, which are the padding of `D3D12_RESOURCE_DESC`'s layout. The title leaves there whatever its stack held. `resource::texture_at` already leaves those two words out of its key for that reason. Its "asked for again with other filler words" count reached 563k in the same run. So almost every placed view written made a new shape: - ~600 a second, 1.8 M at 10 min, 3.5 M at 30, full at ~35 min. - From then on every placed view at a new address became a table entry. Nothing ever releases those (no resource object): 23.5 M entries and 10 GB after 90 min. - Every placed view written looks its shape up in a BTreeMap of millions of 113-byte keys, and then in a 23 M-entry one. - New entries take the table's lock, which the recording threads wait behind. - The PC runs out of memory, so everything that touches memory slows down. ## Evidence One ~100-min session at 1080p, in 5-min buckets of the memory and frame log lines: | min | prep ms | GPU ms | draws | shapes of placed views kept | view table entries | table MB | own allocations MB | private MB | PC free MB | |---|---|---|---|---|---|---|---|---|---| | 10 | 33 | 9.5 | 3200 | 1.8 M | 8.3 k | 534 | 2132 | 24740 | 1879 | | 30 | 60 | 16.9 | 5400 | 3.5 M | 10.6 k | 1132 | 2874 | 26700 | 942 | | 35 | 70 | 17.3 | 6900 | 4,194,304 (full) | 1.0 M | 1541 | 3320 | 27580 | 1359 | | 60 | 92 | 11.5 | 8200 | full | 13.8 M | 6030 | 7898 | 33680 | 370 | | 80 | 155 | 7.9 | 8250 | full | 22.6 M | 9909 | 11782 | 38300 | 754 | | 90 | 122 | 14.3 | 5300 | full | 25.3 M | 10436 | 12315 | 38820 | 713 | - Prep per 1000 draws stays at ~10-11 ms up to ~60 min (that part follows the scene). It is 18-29 ms after that. - Other per-frame parts slow down together: looking at slots 3.8 -> 26 ms, journal lock waits 5 -> 18-29 ms. - The memory line's own blocks show a 4.3 GB block (the table's Vec), and the blocks under 4 KiB grow from 577 MB to 5.75 GB. **With the fix** (a live session with the same settings): 71,928 shapes at 16 min (1.8 M at 10 min before), and the view table at 8,741 entries / 30 MB (10 GB before). - The remaining growth (~28 shapes a second) is real data. The new log line names the words that differ: buffer widths, first element, element count, stride, format. - At that rate the cap is ~40 h away. ## The fix (`without_filler`, on by default) `create_placed_srv` / `create_placed_uav` zero the padding before the view is recorded: - words 1 and 13 of the resource description; - the shader view's word 3 (between the component mapping and the union); - the union's words past the member its dimension uses, for each D3D12 SRV/UAV dimension. A dimension not known there keeps every word. The host reads these descriptions only as the D3D12 structures (`srv_desc` / `uav_desc`) and by their meaningful words, so nothing it builds changes. Views that differed only in padding become one shape and one record, so their slots are also no longer re-made for padding alone. ## Switch and logging - `VICTORY_SHAPE_FILLER=1` keeps the padding, as before. `=2` leaves out only resource words 1/13. - A new log line at each power of two of shapes from 4,096 (and every 262,144): "shapes of placed views: N kept ... the new ones from 4096 on differ from the one before them in: unordered .., resource words [..], view words 0-9 [..] and 12-15 [..]". It names whatever still makes new shapes. - A WARN once when the shapes are full. ## Tests - `descriptor::tests::filler_makes_no_new_shapes`: 5,000 placed views with the run's kind of padding (words 1 and 13 changing, the view's word 3 and unused union words changing) make one shape, and the view read back has no padding. Another mip count or height still makes a new shape. - `descriptor::tests::filler_leaves_what_the_host_reads`: every member word of buffer SRV/UAV, 2-D UAV and 2-D array SRV views is kept, and unknown dimensions are kept whole. - `descriptor::tests::views_at_new_addresses_add_no_entries` is updated for views read back without padding. Checked on this branch: `cargo clippy -p victory-gpu --all-targets --locked -- -D warnings`, the same with `--all-features`, and `cargo test -p victory-gpu --lib` (221 passed, 4 ignored; all 45 `descriptor::` tests pass). Found and verified on an AMD RX 6700 XT. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01S4xxcyVsTQvsBVmaF2gBZs
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/247:upstream-pr/247'
git switch 'upstream-pr/247'

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