GPU: fresh tables past a capped heap's title slots copy views made once per slot #3066

Open
r4tedx wants to merge 3 commits from upstream-pr/3068 into main
r4tedx commented 2026-11-26 06:13:57 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by r4tedx on 2026-11-26T06:13:57Z.


What changes

On a host that caps its shader-visible view heap (NVIDIA: 1,000,000 descriptors), main keeps 934,464 title slots and 65,536 dynamic ones. A title table that reaches past the title slots is made afresh at every use (State::tables): make_at creates each of its views into dynamic slots, every time. In our title run that came to about 30,000 views created a frame on the recording threads.

This PR keeps a view for each title slot past the cap, and fresh tables copy those views instead of creating them again.

  • An overflow heap. A capped view heap gets a second, CPU-only CBV/SRV/UAV heap (HostHeap::overflow), with one slot per title slot past the host's. That's 310,720 slots for our title, 32 B each on NVIDIA, about 10 MB of CPU memory. It is not shader-visible, so the host's cap doesn't apply to it. Its size is logged once, when it's made.
  • One view per slot, made at its first use. When a fresh table is used (HostHeap::copy_overflow), each of its slots is compared with the record (view entry, generation) its overflow slot was made from. A view is created only where the record changed. This is the same rule the title slots follow in HostHeap::mirror. The cache is per slot, not per record: the same record in two slots is made twice.
  • Then one CopyDescriptorsSimple of the whole table into its dynamic slots. Each dynamic slot keeps the host resource, stride, write mark and view address that make_at would have given it. Its own readable calls (transitions, copy refreshes) are unchanged.
  • Placed textures and failed views.
    • An overflow slot viewing a texture the title placed itself is made again when the host texture behind it has changed. This is the same check mirror makes for title slots (needs_remake).
    • A view the host couldn't make is tried again at the next use.
  • Locks. Each table takes one look-up in the views' registry for all its records. It locks the overflow shards it spans (1,024 slots each, in order, so lists recording at once rarely meet) and takes the kept-resources lock once. What an overflow slot kept before it's replaced is retired as for a title slot (crate::host::retire).
  • Switch. VICTORY_OVERFLOW_VIEWS=0 restores main's path, with every view made per use. A heap that isn't capped has no overflow heap, so nothing changes there.

Files: descriptor/host.rs (Overflow, copy_overflow, keep_run, the heap's creation); descriptor.rs (views_of: the views of several records under one lock); draw.rs (State::tables copies where the heap has an overflow heap, else makes views as before; tests).

This doesn't depend on any other open PR.

Tests

The title was not used in these tests.

New:

  • draw::tests::a_table_past_the_title_slots_reads_the_same_views_copied_or_made (WARP). It makes a view heap that keeps 4 of its 16 title slots (a test-only, thread-local override of the title slots kept, as a capped heap would) and runs three checks on a table at title slot 8:
    • copied at its first use (1 view made), a dispatch writes through it into the buffer the title's record names;
    • after the title writes another record there, it is made again (1 view) and writes into the new buffer;
    • copied again unchanged (0 views made), it still writes the new buffer, as a table made one by one with make_at does.
  • descriptor::host::tests::overflow_views_are_on_unless_switched_off.
  • draw::tests::fresh_tables_made_or_copied_per_1000: a microbench, ignored by default. It times 1,000 fresh tables of 8 three ways: made one by one, copied at first use, and copied with the records unchanged.

Results on main 63bcca43 (this machine, WARP):

  • cargo clippy -p victory-gpu --all-targets --locked -- -D warnings, and the same with --features diagnostics: both clean.
  • VICTORY_D3D12_WARP=1 cargo test -p victory-gpu --features diagnostics --lib --locked: 248 passed, 0 failed, 2 ignored (the existing benchmark and the new one). On main itself: 246 passed, 0 failed, 1 ignored.
  • The two new tests by name: 2 passed.
  • The microbench (--ignored --nocapture, WARP, one run), 1,000 tables of 8:
    • views made one by one: 7.6 ms;
    • copied, first use (views made in the overflow heap): 9.1 ms;
    • copied, records unchanged: 3.5 ms.

In game

Local title data was used for these runs; only counts and timings from the logs are given here.

This was on an RTX 5070, in the title's first open-world area, 10 minutes a run with 0 device removals in either run. OV0 has the overflow heap switched off (VICTORY_OVERFLOW_VIEWS=0) and OV1 has it on, with everything else the same exe and switches.

The play build carries other unmerged changes: our dynamic-slot reclaim (see #688), host copies in video memory, and others. So the absolute numbers aren't main's. The difference between the two runs is this change.

OV0 (off) OV1 (on)
frame ms, mean / p50 / p95 816 / 778 / 1,021 699 / 682 / 791
preparing ms (mean) 270 221
GPU ms (mean) 125 119
fresh tables' views made / frame 28,908 24,602
copied from the overflow heap / frame 0 2,778
  • Median frame time: −73 to −118 ms (95 % bootstrap interval over the 5-second meter windows).
  • Most of the gain is in preparing (−49 ms).
  • Only about 10 % of the fresh tables' views came from the overflow heap. Most slots had a different record at their next use, so their views were made again. Whether the title cycles the same records through different slots (which a cache keyed per record would serve) or writes new ones is a follow-up; we have a diagnostics build for it but no run yet.
  • That run was of the play build's version of this change, which kept placed textures by record only. This PR also checks their host texture, as mirror does, so it may make a few more views than OV1 did.
  • #2121 (page view heaps) gives the title's slots past the cap a place in the shader-visible heap, through a page table that translated shaders index. Where it pages a heap, no table is fresh and this change has nothing to do. It's a larger change that also touches the shader translator. This one is smaller and leaves the shader translator alone: only the host side of fresh tables changes, and shaders and the heap layout are as on main. The two don't conflict: with #2121 paging a heap, the overflow heap is simply unused.
  • #562 shares whole immutable texture tables across lists. This PR's cache is per slot and within the views a heap makes, so it applies to tables that change in part. In our title's census, no fresh table was the same as one another list made that frame, so sharing across lists would have found little there. The two could be combined.
  • #1548, #2628 and others give the capped heap more dynamic slots, which leaves fewer title slots and so more slots past them. The overflow heap is sized from the heap's own split, so it follows either.

AI-assisted

🤖 Generated with Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:issue:5505021623 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3068). Originally posted by [r4tedx](https://github.com/r4tedx) on 2026-11-26T06:13:57Z. --- ### What changes On a host that caps its shader-visible view heap (NVIDIA: 1,000,000 descriptors), main keeps 934,464 title slots and 65,536 dynamic ones. A title table that reaches past the title slots is made afresh at every use (`State::tables`): `make_at` creates each of its views into dynamic slots, every time. In our title run that came to about 30,000 views created a frame on the recording threads. This PR keeps a view for each title slot past the cap, and fresh tables copy those views instead of creating them again. - **An overflow heap.** A capped view heap gets a second, CPU-only CBV/SRV/UAV heap (`HostHeap::overflow`), with one slot per title slot past the host's. That's 310,720 slots for our title, 32 B each on NVIDIA, about 10 MB of CPU memory. It is not shader-visible, so the host's cap doesn't apply to it. Its size is logged once, when it's made. - **One view per slot, made at its first use.** When a fresh table is used (`HostHeap::copy_overflow`), each of its slots is compared with the record (view entry, generation) its overflow slot was made from. A view is created only where the record changed. This is the same rule the title slots follow in `HostHeap::mirror`. The cache is per **slot**, not per record: the same record in two slots is made twice. - **Then one `CopyDescriptorsSimple`** of the whole table into its dynamic slots. Each dynamic slot keeps the host resource, stride, write mark and view address that `make_at` would have given it. Its own `readable` calls (transitions, copy refreshes) are unchanged. - **Placed textures and failed views.** - An overflow slot viewing a texture the title placed itself is made again when the host texture behind it has changed. This is the same check `mirror` makes for title slots (`needs_remake`). - A view the host couldn't make is tried again at the next use. - **Locks.** Each table takes one look-up in the views' registry for all its records. It locks the overflow shards it spans (1,024 slots each, in order, so lists recording at once rarely meet) and takes the kept-resources lock once. What an overflow slot kept before it's replaced is retired as for a title slot (`crate::host::retire`). - **Switch.** `VICTORY_OVERFLOW_VIEWS=0` restores main's path, with every view made per use. A heap that isn't capped has no overflow heap, so nothing changes there. Files: `descriptor/host.rs` (`Overflow`, `copy_overflow`, `keep_run`, the heap's creation); `descriptor.rs` (`views_of`: the views of several records under one lock); `draw.rs` (`State::tables` copies where the heap has an overflow heap, else makes views as before; tests). This doesn't depend on any other open PR. ### Tests The title was not used in these tests. New: - `draw::tests::a_table_past_the_title_slots_reads_the_same_views_copied_or_made` (WARP). It makes a view heap that keeps 4 of its 16 title slots (a test-only, thread-local override of the title slots kept, as a capped heap would) and runs three checks on a table at title slot 8: - copied at its first use (1 view made), a dispatch writes through it into the buffer the title's record names; - after the title writes another record there, it is made again (1 view) and writes into the new buffer; - copied again unchanged (0 views made), it still writes the new buffer, as a table made one by one with `make_at` does. - `descriptor::host::tests::overflow_views_are_on_unless_switched_off`. - `draw::tests::fresh_tables_made_or_copied_per_1000`: a microbench, ignored by default. It times 1,000 fresh tables of 8 three ways: made one by one, copied at first use, and copied with the records unchanged. Results on `main` 63bcca43 (this machine, WARP): - `cargo clippy -p victory-gpu --all-targets --locked -- -D warnings`, and the same with `--features diagnostics`: both clean. - `VICTORY_D3D12_WARP=1 cargo test -p victory-gpu --features diagnostics --lib --locked`: 248 passed, 0 failed, 2 ignored (the existing benchmark and the new one). On `main` itself: 246 passed, 0 failed, 1 ignored. - The two new tests by name: 2 passed. - The microbench (`--ignored --nocapture`, WARP, one run), 1,000 tables of 8: - views made one by one: 7.6 ms; - copied, first use (views made in the overflow heap): 9.1 ms; - copied, records unchanged: 3.5 ms. ### In game Local title data was used for these runs; only counts and timings from the logs are given here. This was on an RTX 5070, in the title's first open-world area, 10 minutes a run with 0 device removals in either run. OV0 has the overflow heap switched off (`VICTORY_OVERFLOW_VIEWS=0`) and OV1 has it on, with everything else the same exe and switches. **The play build carries other unmerged changes**: our dynamic-slot reclaim (see #688), host copies in video memory, and others. So the absolute numbers aren't main's. The difference between the two runs is this change. | | OV0 (off) | OV1 (on) | |---|---:|---:| | frame ms, mean / p50 / p95 | 816 / 778 / 1,021 | 699 / 682 / 791 | | preparing ms (mean) | 270 | 221 | | GPU ms (mean) | 125 | 119 | | fresh tables' views made / frame | 28,908 | 24,602 | | copied from the overflow heap / frame | 0 | 2,778 | - Median frame time: −73 to −118 ms (95 % bootstrap interval over the 5-second meter windows). - Most of the gain is in preparing (−49 ms). - Only about 10 % of the fresh tables' views came from the overflow heap. Most slots had a different record at their next use, so their views were made again. Whether the title cycles the same records through different slots (which a cache keyed per record would serve) or writes new ones is a follow-up; we have a diagnostics build for it but no run yet. - That run was of the play build's version of this change, which kept placed textures by record only. This PR also checks their host texture, as `mirror` does, so it may make a few more views than OV1 did. ### Related - #2121 (page view heaps) gives the title's slots past the cap a place in the shader-visible heap, through a page table that translated shaders index. Where it pages a heap, no table is fresh and this change has nothing to do. It's a larger change that also touches the shader translator. This one is smaller and leaves the shader translator alone: only the host side of fresh tables changes, and shaders and the heap layout are as on main. The two don't conflict: with #2121 paging a heap, the overflow heap is simply unused. - #562 shares whole immutable texture tables across lists. This PR's cache is per slot and within the views a heap makes, so it applies to tables that change in part. In our title's census, no fresh table was the same as one another list made that frame, so sharing across lists would have found little there. The two could be combined. - #1548, #2628 and others give the capped heap more dynamic slots, which leaves fewer title slots and so more slots past them. The overflow heap is sized from the heap's own split, so it follows either. AI-assisted 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Dukestar69 commented 2026-11-26 06:29:05 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T06:29:05Z.

Review: APPROVED


Tested locally merged onto origin/main (63bcca4) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + WARP):

  • cargo test -p victory-gpu descriptor::host::tests -- --test-threads=1 --skip dynamic_slots_are_held_until_released (RTX 5090 & WARP): 15 passed, 0 failed on both (including overflow_views_are_on_unless_switched_off). (Pre-existing dynamic_slots_are_held_until_released fails on NVIDIA's 1M view-heap cap #1744.)
  • cargo test -p victory-gpu draw::tests -- --test-threads=1 (RTX 5090): 21 passed, 0 failed (including a_table_past_the_title_slots_reads_the_same_views_copied_or_made).
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6069507748 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3068#pullrequestreview-6069507748). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T06:29:05Z. **Review:** APPROVED --- Tested locally merged onto `origin/main` (`63bcca4`) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + WARP): - `cargo test -p victory-gpu descriptor::host::tests -- --test-threads=1 --skip dynamic_slots_are_held_until_released` (RTX 5090 & WARP): 15 passed, 0 failed on both (including `overflow_views_are_on_unless_switched_off`). *(Pre-existing `dynamic_slots_are_held_until_released` fails on NVIDIA's 1M view-heap cap #1744.)* - `cargo test -p victory-gpu draw::tests -- --test-threads=1` (RTX 5090): 21 passed, 0 failed (including `a_table_past_the_title_slots_reads_the_same_views_copied_or_made`). - `cargo clippy -p victory-gpu --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
kotekompotek commented 2026-11-26 06:36:11 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-26T06:36:11Z.

Review: APPROVED


Verified the whole path: Overflow CPU heap keyed by generation<<32|index (NULL=no view, 0=unmakeable->retried), placed_texture_moved factored correctly out of mirror, shards locked in index order, CopyDescriptorsSimple under the shard locks, retired kept go through host::retire post-unlock, keep_run/set_stride/set_mark/note_address mirror make_at's bookkeeping, graceful None fallback to one-by-one. views_of batches the VIEWS lock with the same tag+generation check. End-to-end test discriminates made=1/copied=0 and verifies actual dispatch writes.

<!-- greyfinch-sync:Marvisak/VIctory:review:6069566612 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3068#pullrequestreview-6069566612). Originally posted by [kotekompotek](https://github.com/kotekompotek) on 2026-11-26T06:36:11Z. **Review:** APPROVED --- Verified the whole path: Overflow CPU heap keyed by generation<<32|index (NULL=no view, 0=unmakeable->retried), placed_texture_moved factored correctly out of mirror, shards locked in index order, CopyDescriptorsSimple under the shard locks, retired kept go through host::retire post-unlock, keep_run/set_stride/set_mark/note_address mirror make_at's bookkeeping, graceful None fallback to one-by-one. views_of batches the VIEWS lock with the same tag+generation check. End-to-end test discriminates made=1/copied=0 and verifies actual dispatch writes.
r4tedx commented 2026-11-26 07:01:53 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by r4tedx on 2026-11-26T06:44:16Z.


Head update 67a8692 → b40e60b: adds @passerbyyhx's regression test an_overflow_srv_follows_a_replaced_texture_without_a_new_record (draw.rs only, plus Slots::new split into Slots::from_heap; no change to the fix). The title's record and generation stay the same while the placed texture's backing resource is replaced; the overflow copy must remake once and read the new contents.

Verified here on WARP: clippy clean; draw:: tests 22 passed, 0 failed, 1 ignored. With the resource-change check disabled, the new test fails (0 remakes, stale texel), so it guards that check. The author also reports RTX 4090 Laptop and full WARP diagnostics results in r4tedx/VIctory#20; those were not re-run here. Synthetic tests only, no title data.

AI-assisted

<!-- greyfinch-sync:Marvisak/VIctory:comment:7184730998 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3068#issuecomment-7184730998). Originally posted by [r4tedx](https://github.com/r4tedx) on 2026-11-26T06:44:16Z. --- Head update `67a8692` → `b40e60b`: adds @passerbyyhx's regression test `an_overflow_srv_follows_a_replaced_texture_without_a_new_record` (draw.rs only, plus `Slots::new` split into `Slots::from_heap`; no change to the fix). The title's record and generation stay the same while the placed texture's backing resource is replaced; the overflow copy must remake once and read the new contents. Verified here on WARP: clippy clean; `draw::` tests 22 passed, 0 failed, 1 ignored. With the resource-change check disabled, the new test fails (0 remakes, stale texel), so it guards that check. The author also reports RTX 4090 Laptop and full WARP diagnostics results in r4tedx/VIctory#20; those were not re-run here. Synthetic tests only, no title data. AI-assisted
fuzeofficlal commented 2026-11-26 08:12:22 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T08:12:22Z.

Review: CHANGES_REQUESTED


Tested locally on Windows 11 x64 (rustc 1.98.1, NVIDIA GeForce RTX 5090 + WARP):

  • cargo clippy -p victory-gpu --all-targets --locked -- -D warnings (default and --all-features): clean.
  • RTX 5090: descriptor::host::tests (15 passed, skipping pre-existing NVIDIA cap test dynamic_slots_are_held_until_released), draw::tests (22 passed, 1 ignored). Microbench (fresh_tables_made_or_copied_per_1000): 8.5 ms one-by-one vs 7.0 ms first copy vs 2.8 ms unchanged copy.
  • WARP (--features diagnostics, VICTORY_D3D12_WARP=1): descriptor::host::tests (16 passed), draw::tests (22 passed, 1 ignored). Microbench: 10.0 ms one-by-one vs 10.6 ms first copy vs 3.6 ms unchanged copy.
  • cargo xtask policy: 191 files ok.

One real bug in texture eviction handling should be fixed before merge:

HostHeap::evict does not evict self.overflow (crates/victory-gpu/src/descriptor/host.rs)
When crate::resource::give_up evicts a host texture (resource.rs:1687-1709), it calls HostHeap::evict(&raws) and clears resource(r).host = None. Because HostHeap::evict only walks self.kept and never touches self.overflow:

  1. VRAM leak: Overflow's Over.kept retains a strong ID3D12Resource COM reference to every evicted texture viewed through an overflow slot until a different title record overwrites that slot, keeping its VRAM pinned.
  2. Stale descriptor for evicted regular (non-placed) textures: For title slots (< self.count), HostHeap::evict clears self.kept[index] = None, which causes HostHeap::mirror's needs_remake() (let Some(held) = held else { return true; }) to remake the view on the next draw. In copy_overflow, however, slot.kept is still Some(old_evicted_tex) and moved() only checks is_placed_texture(v). On the next draw of an evicted regular texture (View::Shader(r, ..) / View::Unordered(r, ..)), slot.key == key matches and moved() returns false, so copy_overflow copies the stale descriptor pointing to the old evicted ID3D12Resource (made == 0), while draw.rs's readable() recreates a fresh HostTexture and uploads the title bytes into the new resource. The shader then keeps sampling the stale evicted texture.

Fix: in HostHeap::evict, also walk self.overflow shards—when slot.kept matches textures (with k.1.is_none()), clear slot.kept = None, reset slot.key = 0 (so the next copy_overflow remakes it), and crate::host::retire the replaced ID3D12Resource after dropping the shard lock. Lock ordering stays clean (HostHeap::evict runs under SHADER_HEAPS, and copy_overflow never acquires SHADER_HEAPS). Adding a regression test mirroring a_texture_given_up_is_made_again_with_its_bytes_and_recorded_lists_keep_it through an overflow slot (evict with resource::give_up_now, mutate title bytes, re-copy and assert made == 1 + updated texel readback) will cover this directly.

Minor non-blocking notes:

  • keep_run omits the #[cfg(feature = "diagnostics")] crate::resource::life::note(...) tracking present in HostHeap::keep.
  • In copy_overflow, first.checked_add(n).is_none_or(|end| end > self.count + self.dynamic) avoids relying on caller-guaranteed non-overflow for first + n.
<!-- greyfinch-sync:Marvisak/VIctory:review:6070504775 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3068#pullrequestreview-6070504775). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T08:12:22Z. **Review:** CHANGES_REQUESTED --- Tested locally on Windows 11 x64 (`rustc 1.98.1`, NVIDIA GeForce RTX 5090 + WARP): - `cargo clippy -p victory-gpu --all-targets --locked -- -D warnings` (default and `--all-features`): clean. - RTX 5090: `descriptor::host::tests` (15 passed, skipping pre-existing NVIDIA cap test `dynamic_slots_are_held_until_released`), `draw::tests` (22 passed, 1 ignored). Microbench (`fresh_tables_made_or_copied_per_1000`): 8.5 ms one-by-one vs 7.0 ms first copy vs 2.8 ms unchanged copy. - WARP (`--features diagnostics`, `VICTORY_D3D12_WARP=1`): `descriptor::host::tests` (16 passed), `draw::tests` (22 passed, 1 ignored). Microbench: 10.0 ms one-by-one vs 10.6 ms first copy vs 3.6 ms unchanged copy. - `cargo xtask policy`: 191 files ok. One real bug in texture eviction handling should be fixed before merge: **`HostHeap::evict` does not evict `self.overflow` (`crates/victory-gpu/src/descriptor/host.rs`)** When `crate::resource::give_up` evicts a host texture (`resource.rs:1687-1709`), it calls `HostHeap::evict(&raws)` and clears `resource(r).host = None`. Because `HostHeap::evict` only walks `self.kept` and never touches `self.overflow`: 1. **VRAM leak:** `Overflow`'s `Over.kept` retains a strong `ID3D12Resource` COM reference to every evicted texture viewed through an overflow slot until a different title record overwrites that slot, keeping its VRAM pinned. 2. **Stale descriptor for evicted regular (non-placed) textures:** For title slots (`< self.count`), `HostHeap::evict` clears `self.kept[index] = None`, which causes `HostHeap::mirror`'s `needs_remake()` (`let Some(held) = held else { return true; }`) to remake the view on the next draw. In `copy_overflow`, however, `slot.kept` is still `Some(old_evicted_tex)` and `moved()` only checks `is_placed_texture(v)`. On the next draw of an evicted regular texture (`View::Shader(r, ..)` / `View::Unordered(r, ..)`), `slot.key == key` matches and `moved()` returns `false`, so `copy_overflow` copies the stale descriptor pointing to the old evicted `ID3D12Resource` (`made == 0`), while `draw.rs`'s `readable()` recreates a fresh `HostTexture` and uploads the title bytes into the new resource. The shader then keeps sampling the stale evicted texture. Fix: in `HostHeap::evict`, also walk `self.overflow` shards—when `slot.kept` matches `textures` (with `k.1.is_none()`), clear `slot.kept = None`, reset `slot.key = 0` (so the next `copy_overflow` remakes it), and `crate::host::retire` the replaced `ID3D12Resource` after dropping the shard lock. Lock ordering stays clean (`HostHeap::evict` runs under `SHADER_HEAPS`, and `copy_overflow` never acquires `SHADER_HEAPS`). Adding a regression test mirroring `a_texture_given_up_is_made_again_with_its_bytes_and_recorded_lists_keep_it` through an overflow slot (evict with `resource::give_up_now`, mutate title bytes, re-copy and assert `made == 1` + updated texel readback) will cover this directly. Minor non-blocking notes: - `keep_run` omits the `#[cfg(feature = "diagnostics")] crate::resource::life::note(...)` tracking present in `HostHeap::keep`. - In `copy_overflow`, `first.checked_add(n).is_none_or(|end| end > self.count + self.dynamic)` avoids relying on caller-guaranteed non-overflow for `first + n`.
fuzeofficlal commented 2026-11-26 08:51:52 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T08:51:52Z.

Review: APPROVED


All three points from the earlier review are cleanly addressed in 6b42656a:

  • HostHeap::evict now calls evict_overflow after dropping made, clearing (slot.key, slot.mark) and retiring evicted ID3D12Resource handles outside the shard locks. Lock ordering (SHADER_HEAPS -> individual shards in evict_overflow, ascending shards without SHADER_HEAPS held across CopyDescriptorsSimple in copy_overflow, and retire/keep_run after dropping shards) is deadlock- and race-free, and since Over::NULL == u64::MAX and valid generations start at 1, key = 0 guarantees the CPU descriptor is rebuilt before the next copy.
  • keep_run logs resource::life::note under diagnostics, matching HostHeap::keep, and copy_overflow uses checked_add for the dynamic-slot bound check.
  • draw::tests::an_overflow_table_reads_a_texture_given_up_as_made_again directly exercises the eviction -> rewrite -> remake -> readback path.

Verified locally on Windows 11 (RTX 5090 + WARP + D3D12 Debug Layer):

  • cargo clippy -p victory-gpu --all-targets -- -D warnings (default and --all-features): clean
  • RTX 5090: descriptor:: 22/22 passed (skipping the pre-existing NVIDIA dynamic_slots_are_held_until_released cap failure), draw:: 23/23 passed (1 ignored bench)
  • RTX 5090 + VICTORY_D3D12_DEBUG=1 (--features diagnostics): overflow 9/9 passed (including an_overflow_table_reads_a_texture_given_up_as_made_again)
  • WARP + VICTORY_D3D12_DEBUG=1 (--features diagnostics, VICTORY_D3D12_WARP=1): descriptor:: 23/23 passed, draw:: 23/23 passed (1 ignored bench)
  • cargo xtask policy: 191 files ok

LGTM.

<!-- greyfinch-sync:Marvisak/VIctory:review:6070997352 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3068#pullrequestreview-6070997352). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T08:51:52Z. **Review:** APPROVED --- All three points from the earlier review are cleanly addressed in `6b42656a`: - `HostHeap::evict` now calls `evict_overflow` after dropping `made`, clearing `(slot.key, slot.mark)` and retiring evicted `ID3D12Resource` handles outside the shard locks. Lock ordering (`SHADER_HEAPS` -> individual shards in `evict_overflow`, ascending shards without `SHADER_HEAPS` held across `CopyDescriptorsSimple` in `copy_overflow`, and `retire`/`keep_run` after dropping shards) is deadlock- and race-free, and since `Over::NULL == u64::MAX` and valid generations start at 1, `key = 0` guarantees the CPU descriptor is rebuilt before the next copy. - `keep_run` logs `resource::life::note` under `diagnostics`, matching `HostHeap::keep`, and `copy_overflow` uses `checked_add` for the dynamic-slot bound check. - `draw::tests::an_overflow_table_reads_a_texture_given_up_as_made_again` directly exercises the eviction -> rewrite -> remake -> readback path. Verified locally on Windows 11 (RTX 5090 + WARP + D3D12 Debug Layer): - `cargo clippy -p victory-gpu --all-targets -- -D warnings` (default and `--all-features`): clean - RTX 5090: `descriptor::` 22/22 passed (skipping the pre-existing NVIDIA `dynamic_slots_are_held_until_released` cap failure), `draw::` 23/23 passed (1 ignored bench) - RTX 5090 + `VICTORY_D3D12_DEBUG=1` (`--features diagnostics`): `overflow` 9/9 passed (including `an_overflow_table_reads_a_texture_given_up_as_made_again`) - WARP + `VICTORY_D3D12_DEBUG=1` (`--features diagnostics`, `VICTORY_D3D12_WARP=1`): `descriptor::` 23/23 passed, `draw::` 23/23 passed (1 ignored bench) - `cargo xtask policy`: 191 files ok LGTM.
r4tedx commented 2026-11-26 09:06:06 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by r4tedx on 2026-11-26T08:23:05Z.


Thanks @fuzeofficlal for the careful review and the RTX 5090 numbers.

You were right. I checked it in the code before changing anything.

  • HostHeap::evict walked only self.kept (title and dynamic slots), never self.overflow.
  • After resource::give_up gave up a regular (non-placed) texture, the overflow slot still held the old ID3D12Resource, so its video memory stayed pinned.
  • On the next use the slot's key was unchanged, and moved() only looks at placed textures. So copy_overflow copied the stale view (made == 0), while readable made the texture again from title memory, and the shader read the one given up.

The regression test you suggested shows it: without the fix it fails at "made again: its texture was given up" (left 0, right 1).

The fix (6b42656a, on top of b40e60b3):

  • HostHeap::evict now also walks the overflow shards. A slot holding a given-up texture (k.1.is_none() and in the set) drops it and clears its key, so the next copy_overflow makes the view again, of the texture made again.
    • What the slot held is retired after the shard's lock is dropped.
    • The overflow descriptor itself is left as it is: it's in a CPU-only heap the GPU never reads, and it is made again before it's next copied.
  • Lock order: descriptor::evict takes SHADER_HEAPS, then each shard. copy_overflow takes shards and never SHADER_HEAPS, and nothing it calls while holding them (make_marked) reaches SHADER_HEAPS. Eviction runs on the submitting thread before a submission (resource::evict_unused), not from view creation.
  • Your two minor notes, both taken:
    • keep_run now has the same #[cfg(feature = "diagnostics")] crate::resource::life::note(...) as keep.
    • copy_overflow bounds its dynamic slots with first.checked_add(n).is_none_or(|end| end > self.count + self.dynamic).

The test. draw::tests::an_overflow_table_reads_a_texture_given_up_as_made_again, modelled on a_texture_given_up_is_made_again_with_its_bytes_and_recorded_lists_keep_it:

  1. Reads a texture fed from title memory through an overflow table (title slot 8 of a heap keeping 4).
  2. Gives it up with resource::give_up_now.
  3. Changes the title bytes from 0x40 to 0x80.
  4. Copies again and asserts one view made and the new texel (128/255) read back.

It fails without the fix and passes with it.

Testing (WARP, Windows 11):

  • cargo clippy -p victory-gpu --all-targets -- -D warnings, with and without --features diagnostics: clean.
  • VICTORY_D3D12_WARP=1 cargo test -p victory-gpu --features diagnostics --lib -- --test-threads=1: 250 passed, 0 failed, 2 ignored. That includes the new test, an_overflow_srv_follows_a_replaced_texture_without_a_new_record and a_table_past_the_title_slots_reads_the_same_views_copied_or_made.

The title was not used in these tests.

AI-assisted

<!-- greyfinch-sync:Marvisak/VIctory:comment:7186528710 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3068#issuecomment-7186528710). Originally posted by [r4tedx](https://github.com/r4tedx) on 2026-11-26T08:23:05Z. --- Thanks @fuzeofficlal for the careful review and the RTX 5090 numbers. **You were right.** I checked it in the code before changing anything. - `HostHeap::evict` walked only `self.kept` (title and dynamic slots), never `self.overflow`. - After `resource::give_up` gave up a regular (non-placed) texture, the overflow slot still held the old `ID3D12Resource`, so its video memory stayed pinned. - On the next use the slot's key was unchanged, and `moved()` only looks at placed textures. So `copy_overflow` copied the stale view (made == 0), while `readable` made the texture again from title memory, and the shader read the one given up. The regression test you suggested shows it: without the fix it fails at "made again: its texture was given up" (left 0, right 1). **The fix (6b42656a, on top of b40e60b3):** - `HostHeap::evict` now also walks the overflow shards. A slot holding a given-up texture (`k.1.is_none()` and in the set) drops it and clears its key, so the next `copy_overflow` makes the view again, of the texture made again. - What the slot held is retired after the shard's lock is dropped. - The overflow descriptor itself is left as it is: it's in a CPU-only heap the GPU never reads, and it is made again before it's next copied. - **Lock order:** `descriptor::evict` takes `SHADER_HEAPS`, then each shard. `copy_overflow` takes shards and never `SHADER_HEAPS`, and nothing it calls while holding them (`make_marked`) reaches `SHADER_HEAPS`. Eviction runs on the submitting thread before a submission (`resource::evict_unused`), not from view creation. - **Your two minor notes, both taken:** - `keep_run` now has the same `#[cfg(feature = "diagnostics")] crate::resource::life::note(...)` as `keep`. - `copy_overflow` bounds its dynamic slots with `first.checked_add(n).is_none_or(|end| end > self.count + self.dynamic)`. **The test.** `draw::tests::an_overflow_table_reads_a_texture_given_up_as_made_again`, modelled on `a_texture_given_up_is_made_again_with_its_bytes_and_recorded_lists_keep_it`: 1. Reads a texture fed from title memory through an overflow table (title slot 8 of a heap keeping 4). 2. Gives it up with `resource::give_up_now`. 3. Changes the title bytes from 0x40 to 0x80. 4. Copies again and asserts one view made and the new texel (128/255) read back. It fails without the fix and passes with it. **Testing** (WARP, Windows 11): - `cargo clippy -p victory-gpu --all-targets -- -D warnings`, with and without `--features diagnostics`: clean. - `VICTORY_D3D12_WARP=1 cargo test -p victory-gpu --features diagnostics --lib -- --test-threads=1`: 250 passed, 0 failed, 2 ignored. That includes the new test, `an_overflow_srv_follows_a_replaced_texture_without_a_new_record` and `a_table_past_the_title_slots_reads_the_same_views_copied_or_made`. The title was not used in these tests. AI-assisted
Marvisak commented 2026-11-26 09:06:06 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-26T08:23:16Z.


Automated triage for the maintainers.

Verdict: needs work. The overflow heap is a reasonable approach and the record-key and placed-texture checks match HostHeap::mirror. One interaction with texture eviction is missing, though.

  • Eviction does not reach overflow slots. crate::resource::give_up → descriptor::evict → HostHeap::evict (descriptor/host.rs) nulls every slot whose kept holds a given-up host texture, so the texture can be freed and is made again on the next read. The new Overflow slots keep their own Over.kept, which HostHeap::evict never walks. So any overflow slot that last viewed a given-up texture keeps it alive until that slot is used again, which may be never. Under the card's budget (BUDGET_HIGH), that memory doesn't come back. The overflow slot's key also stays the same, so on its next use it is copied without being made again. placed_texture_moved catches that case for placed textures only; a non-placed evictable texture would be viewed stale.
  • What would change the verdict: have HostHeap::evict also clear overflow slots that hold one of the textures (null view, key = 0, kept retired). Add a test that gives up a texture viewed through an overflow slot and checks that it is released and made again at the next copy_overflow.

CI: check passing on b40e60b. The default-on switch (VICTORY_OVERFLOW_VIEWS) and the measured gain are noted; this is not a judgement on the approach.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7186532354 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3068#issuecomment-7186532354). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-26T08:23:16Z. --- <!-- victory-triage v1 head=b40e60b3545b589453e065f61ee97136e2a4323e verdict=needs-work at=2026-11-26T08:18:50Z --> Automated triage for the maintainers. **Verdict: needs work.** The overflow heap is a reasonable approach and the record-key and placed-texture checks match `HostHeap::mirror`. One interaction with texture eviction is missing, though. - **Eviction does not reach overflow slots.** `crate::resource::give_up` → `descriptor::evict` → `HostHeap::evict` (`descriptor/host.rs`) nulls every slot whose `kept` holds a given-up host texture, so the texture can be freed and is made again on the next read. The new `Overflow` slots keep their own `Over.kept`, which `HostHeap::evict` never walks. So any overflow slot that last viewed a given-up texture keeps it alive until that slot is used again, which may be never. Under the card's budget (`BUDGET_HIGH`), that memory doesn't come back. The overflow slot's key also stays the same, so on its next use it is copied without being made again. `placed_texture_moved` catches that case for placed textures only; a non-placed evictable texture would be viewed stale. - **What would change the verdict:** have `HostHeap::evict` also clear overflow slots that hold one of the textures (null view, `key = 0`, kept retired). Add a test that gives up a texture viewed through an overflow slot and checks that it is released and made again at the next `copy_overflow`. CI: `check` passing on b40e60b. The default-on switch (`VICTORY_OVERFLOW_VIEWS`) and the measured gain are noted; this is not a judgement on the approach. --- _Generated by [Claude Code](https://claude.ai/code)_
r4tedx commented 2026-11-26 09:06:07 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by r4tedx on 2026-11-26T08:24:05Z.


For triage's point (written at b40e60b3): it's addressed in 6b42656a, as described in the reply above.

  • HostHeap::evict now walks the overflow shards too. A slot holding a given-up texture has its key cleared and what it kept retired, after the shard's lock is dropped.
  • The test is draw::tests::an_overflow_table_reads_a_texture_given_up_as_made_again. It gives up a texture viewed through an overflow slot (resource::give_up_now), changes its title bytes, copies the table again, and checks that the view is made again (one view made) and that the new texel is read back. Without the fix it fails ("made again: its texture was given up", left 0, right 1).
  • One difference from the suggestion: the overflow descriptor itself isn't nulled. It sits in a CPU-only heap the GPU never reads, and with its key cleared it's always made again before it's next copied into a shader-visible slot. So nulling it would add a write without changing what any shader can see. Happy to add it if you'd rather have the slot null in between.

The title was not used in these tests.

AI-assisted

<!-- greyfinch-sync:Marvisak/VIctory:comment:7186548552 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3068#issuecomment-7186548552). Originally posted by [r4tedx](https://github.com/r4tedx) on 2026-11-26T08:24:05Z. --- For triage's point (written at b40e60b3): it's addressed in 6b42656a, as described in the reply above. - `HostHeap::evict` now walks the overflow shards too. A slot holding a given-up texture has its key cleared and what it kept retired, after the shard's lock is dropped. - The test is `draw::tests::an_overflow_table_reads_a_texture_given_up_as_made_again`. It gives up a texture viewed through an overflow slot (`resource::give_up_now`), changes its title bytes, copies the table again, and checks that the view is made again (one view made) and that the new texel is read back. Without the fix it fails ("made again: its texture was given up", left 0, right 1). - One difference from the suggestion: the overflow descriptor itself isn't nulled. It sits in a CPU-only heap the GPU never reads, and with its key cleared it's always made again before it's next copied into a shader-visible slot. So nulling it would add a write without changing what any shader can see. Happy to add it if you'd rather have the slot null in between. The title was not used in these tests. AI-assisted
GustawMatuszewski commented 2026-11-26 21:34:07 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by GustawMatuszewski on 2026-11-26T21:34:07Z.


An independent verification on a capped host, and the first Linux/RADV data point — a different driver from the NVIDIA numbers above, which may matter for the merge.

Machine: Radeon RX 9060 XT 16 GB, RADV (Mesa), GE-Proton 11.14 (Wine 11.0 + vkd3d-proton), Linux, 45 GB RAM, Series X profile, diagnostics build of main @ 63bcca4, VICTORY_HAIR=1 only.

The wall, on a capped view heap (1,000,000):

WARN victory_gpu::descriptor::host: host view heap capped at 1000000
     error=Invalid parameter. (0x80070057) count=1245184
INFO victory_gpu::descriptor::host: title slot past the host heap index=934464 count=934464
     ... 278,340 such lines in a 4-minute run ...
  • 278,340 title slot past the host heap lines in ~4 minutes (this is #1800/#2634's per-slot logging, seen at full volume);
  • not one fps, ... ms/frame line in the whole run — the title never reaches a presentable world frame;
  • no crash, no device removal, no translation failure: the run simply never gets there.

What this PR does for that, measured on a fork that already carries it (a port of this patch to a tree based on the same code; RX 9060 XT as above):

before with the overflow heap
textures picked by index, the queue: … waiting for their memory 11,679 slots (mean 81 s, 90 % over 32 s) 0 – 1
world draws/frame 134–429 (with 544 dropped) 2,737, none dropped by the clamp
what the screen shows black the world, lit, with its interface

I did not post a screenshot of the title's content, but the run was watched on the display and the difference was unambiguous.

So the memory a capped host keeps for the title's slots past the cap is not a micro-optimisation here: without it a capped host has a run that never presents, and with it the same run does. Happy to run any test build you want on this card (RADV) if a second driver's numbers help get this in.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7203850466 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3068#issuecomment-7203850466). Originally posted by [GustawMatuszewski](https://github.com/GustawMatuszewski) on 2026-11-26T21:34:07Z. --- An independent verification on a **capped** host, and the first Linux/RADV data point — a different driver from the NVIDIA numbers above, which may matter for the merge. **Machine:** Radeon RX 9060 XT 16 GB, RADV (Mesa), GE-Proton 11.14 (Wine 11.0 + vkd3d-proton), Linux, 45 GB RAM, Series X profile, diagnostics build of `main` @ `63bcca4`, `VICTORY_HAIR=1` only. **The wall, on a capped view heap (`1,000,000`):** ``` WARN victory_gpu::descriptor::host: host view heap capped at 1000000 error=Invalid parameter. (0x80070057) count=1245184 INFO victory_gpu::descriptor::host: title slot past the host heap index=934464 count=934464 ... 278,340 such lines in a 4-minute run ... ``` - **278,340** `title slot past the host heap` lines in ~4 minutes (this is #1800/#2634's per-slot logging, seen at full volume); - **not one `fps, ... ms/frame` line in the whole run** — the title never reaches a presentable world frame; - no crash, no device removal, no translation failure: the run simply never gets there. **What this PR does for that**, measured on a fork that already carries it (a port of this patch to a tree based on the same code; RX 9060 XT as above): | | before | with the overflow heap | |---|---|---| | `textures picked by index, the queue: … waiting for their memory` | 11,679 slots (mean 81 s, 90 % over 32 s) | **0 – 1** | | world draws/frame | 134–429 (with 544 dropped) | 2,737, none dropped by the clamp | | what the screen shows | black | the world, lit, with its interface | I did not post a screenshot of the title's content, but the run was watched on the display and the difference was unambiguous. So the memory a capped host keeps for the title's slots past the cap is not a micro-optimisation here: without it a capped host has a run that never presents, and with it the same run does. Happy to run any test build you want on this card (RADV) if a second driver's numbers help get this in.
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/3068:upstream-pr/3068'
git switch 'upstream-pr/3068'

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