GPU: #1779 (view heaps on hosts capped below 2^21) on current main, with lazy placed-texture views #2650

Open
github-bot wants to merge 2 commits from github-bot/gh-2650 into main AGit
Owner

@⁠Pierrot1398 on GitHub · 2026-11-25 17:32 UTC · original
Pierrot1398:gpu/1779-on-main → main · +923 −131 · 11 files · 2 commits · open

From a tester working with Claude (AI-assisted); measured on my own machine.

#1779 on current main (13f91ca), for whichever the maintainers prefer: this branch, or its resolution taken into #1779. wrothgaril's commits (#1779 head 9323a74) are kept unchanged under one merge commit. Only the conflict resolution is new.

Why

#1779 no longer merges into main. Today's main makes placed textures' views lazily (mirror, make_read, evict in descriptor/host.rs and descriptor.rs), and moved the view-address table to 16 bytes a slot. Both meet #1779's change of the same code: on a capped heap a title slot and a host slot are no longer the same number.

Resolution

  • mirror(): main's flow (a placed texture's view left null until a draw reads it; preparation outside the slot lock; the record read again and the slot remade if the title wrote it meanwhile) with #1779's mapping. The host's arrays are indexed by host slot: made, kept, strides, addresses, marks and CPU handles. The title's bookkeeping is indexed by title slot: viewed, vacate. A title slot without a host slot gives #1779's warning and None.
  • Read marks: shaders mark the heap index they read, which under blocks is the host slot. make_read called mirror(i, …) with that index as the title's. A new HostHeap::title_of(slot) (the reverse of slot) maps it back; stamp_read and unmade_placed keep the host slot.
  • evict: the same mapping for viewed and forget_read. The title slots are looked up before made is locked, because mirror takes the blocks' map first and the reverse order would invite a deadlock.
  • View addresses: main's 16-byte entries, sized for every host slot under blocks (as #1779 sizes them) and for the title's slots otherwise.
  • draw.rs, lower.rs, emit/mod.rs, shader.rs, stride_tests.rs: both sides' items.

Measured

RTX 5060 Ti 8 GB (driver 621.24, MaxViewDescriptorHeapSize 1,000,000), Windows 11 26300.

  • cargo test -p victory-gpu --lib: 198 passed, 0 failed, including dynamic_slots_are_held_until_released and lists_share_a_table_and_copies_keep_their_views, which fail on main on this card.
  • cargo test -p victory-shader --lib stride: 8 of 9. The one left, a_heap_buffer_read_by_element_takes_the_views_stride, is the structured-view read on NVIDIA (#2178), which fails on main too.
  • cargo xtask policy and cargo clippy -p victory-gpu -p victory-shader -- -D warnings are clean.
  • Live, on a tree that also carries #1832, #1763, #2332, #1906, #1922, #233 and #2178: the 310,720 × title slot past the host heap of main are gone, the black wait before the first boot screen goes from 91 s to 2 s, and the title reaches the world on this card.

🤖 Generated with Claude Code

https://claude.ai/code/session_011f6R3kMoarujHzzA1AvSBb

**@⁠Pierrot1398** on GitHub · 2026-11-25 17:32 UTC · [original](https://github.com/Marvisak/VIctory/pull/2650) `Pierrot1398:gpu/1779-on-main` → `main` · +923 −131 · 11 files · 2 commits · open *From a tester working with Claude (AI-assisted); measured on my own machine.* **#1779 on current `main` (`13f91ca`), for whichever the maintainers prefer: this branch, or its resolution taken into #1779.** wrothgaril's commits (#1779 head `9323a74`) are kept unchanged under one merge commit. Only the conflict resolution is new. ## Why #1779 no longer merges into `main`. Today's `main` makes placed textures' views lazily (`mirror`, `make_read`, `evict` in `descriptor/host.rs` and `descriptor.rs`), and moved the view-address table to 16 bytes a slot. Both meet #1779's change of the same code: on a capped heap a title slot and a host slot are no longer the same number. ## Resolution - **`mirror()`**: `main`'s flow (a placed texture's view left null until a draw reads it; preparation outside the slot lock; the record read again and the slot remade if the title wrote it meanwhile) with #1779's mapping. The host's arrays are indexed by **host slot**: `made`, `kept`, strides, addresses, marks and CPU handles. The title's bookkeeping is indexed by **title slot**: `viewed`, `vacate`. A title slot without a host slot gives #1779's warning and `None`. - **Read marks**: shaders mark the heap index they read, which under blocks is the host slot. `make_read` called `mirror(i, …)` with that index as the title's. A new `HostHeap::title_of(slot)` (the reverse of `slot`) maps it back; `stamp_read` and `unmade_placed` keep the host slot. - **`evict`**: the same mapping for `viewed` and `forget_read`. The title slots are looked up **before** `made` is locked, because `mirror` takes the blocks' map first and the reverse order would invite a deadlock. - **View addresses**: `main`'s 16-byte entries, sized for every host slot under blocks (as #1779 sizes them) and for the title's slots otherwise. - `draw.rs`, `lower.rs`, `emit/mod.rs`, `shader.rs`, `stride_tests.rs`: both sides' items. ## Measured RTX 5060 Ti 8 GB (driver 621.24, `MaxViewDescriptorHeapSize` 1,000,000), Windows 11 26300. - `cargo test -p victory-gpu --lib`: **198 passed, 0 failed**, including `dynamic_slots_are_held_until_released` and `lists_share_a_table_and_copies_keep_their_views`, which fail on `main` on this card. - `cargo test -p victory-shader --lib stride`: 8 of 9. The one left, `a_heap_buffer_read_by_element_takes_the_views_stride`, is the structured-view read on NVIDIA (#2178), which fails on `main` too. - `cargo xtask policy` and `cargo clippy -p victory-gpu -p victory-shader -- -D warnings` are clean. - Live, on a tree that also carries #1832, #1763, #2332, #1906, #1922, #233 and #2178: the 310,720 × `title slot past the host heap` of `main` are gone, the black wait before the first boot screen goes from 91 s to 2 s, and the title reaches the world on this card. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_011f6R3kMoarujHzzA1AvSBb
A host that makes no shader-visible view heap of HEAP_VIEWS slots (NVIDIA:
1,000,000) had shaders index past its heaps, a small dynamic range, and no
room for a title heap larger than its own.

- The host says how large its view heaps may be (Host::view_heap_limit,
  emit::set_view_heap): view heap indices are clamped below that and the
  null buffer views lie two below the end. A host that takes 2^21 slots
  is told nothing and translates as before (same DXIL). The shader cache
  and the pre-build tag key on the values where they differ.
- A capped heap holds the title's slots by blocks of 1,024: a block gets
  a host block when the title first writes a view into it and gives it
  back with its last view, so a sparse title heap of any size fits in
  the slots the host has (703 blocks beside 2^18 dynamic slots, 2^14 for
  view pairs and the null views). Shaders taking descriptors from the
  resource heap itself turn the title's index into the host's through
  the view-block table (root SRV VIEW_BLOCKS: one load, a shift, a mask
  and an add; emitted only for such hosts). Tables are told where their
  first used entry lies on the host; one whose slots are not in one run
  there is made afresh in dynamic slots, as before.
- Tables made afresh take slots from their first used entry on.

Tests: the capped layout and its dynamic slots, pairs and null views; a
capped heap holding a larger title heap by blocks (a view far past the
host's slots found through the block table and through a table, blocks
given back, a full heap); a translated shader reading through the block
table; the shader cache key.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
#1779's head 9323a74 on main 13f91ca. Conflicts with today's main resolved:

- descriptor/host.rs mirror(): main's flow (placed textures made lazily
  when a draw reads them, prepared outside the slot lock, the record
  re-read and the slot remade if the title wrote it meanwhile) with
  #1779's mapping: host arrays (made, kept, strides, addresses, marks, CPU
  handles) by host slot, the title's bookkeeping (viewed, vacate) by title
  slot.
- Shaders mark their reads by heap index, the host slot: make_read and
  evict map it back with the new HostHeap::title_of. evict looks the title
  slots up before locking made, since mirror takes the blocks' map first.
- The view-address buffer: main's 16-byte entries, for every host slot
  under blocks (#1779), else the title's.
- draw.rs, lower.rs, mod.rs, shader.rs, stride_tests.rs: both sides' items.

Co-Authored-By: wrothgaril <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_011f6R3kMoarujHzzA1AvSBb
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:11:14 +00:00
Author
Owner

@⁠Bj0rnis on GitHub · 2026-11-25 17:38 UTC · original

Independent Windows 11 + NVIDIA GeForce RTX 5070 Ti + WARP verification of #2650 at 3e606d27 (clean git merge-tree with origin/main 13f91cae, Rust 1.98.1 MSVC):

  • NVIDIA GeForce RTX 5070 Ti (victory-gpu): cargo test -p victory-gpu --features diagnostics --lib --locked -- --test-threads=1 -> 201 passed, 0 failed, 1 ignored (3.25s). Fixes both pre-existing #1744 NVIDIA 1M view-heap baseline failures (descriptor::host::tests::dynamic_slots_are_held_until_released and memory::tests::lists_share_a_table_and_copies_keep_their_views) that fail on main 13f91cae (196 passed, 2 failed).
  • WARP (VICTORY_D3D12_WARP=1): 201 passed, 0 failed, 1 ignored (1.72s).
  • Clippy (victory-gpu): cargo clippy -p victory-gpu --all-targets --all-features --locked -- -D warnings -> 0 warnings.
  • Note on victory-shader: emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index exited with 0xc0000005 (STATUS_ACCESS_VIOLATION) on RTX 5070 Ti; confirmed this reproduces identically on clean main 13f91cae (not a regression from #2650).

Not tested: live game workload / victory-shader full suite past the pre-existing access violation.

AI-assisted test run and summary.

**@⁠Bj0rnis** on GitHub · 2026-11-25 17:38 UTC · [original](https://github.com/Marvisak/VIctory/pull/2650#issuecomment-7169784899) Independent Windows 11 + NVIDIA GeForce RTX 5070 Ti + WARP verification of #2650 at `3e606d27` (clean `git merge-tree` with `origin/main` `13f91cae`, Rust 1.98.1 MSVC): - **NVIDIA GeForce RTX 5070 Ti (`victory-gpu`):** `cargo test -p victory-gpu --features diagnostics --lib --locked -- --test-threads=1` -> **201 passed, 0 failed, 1 ignored** (3.25s). **Fixes both pre-existing #1744 NVIDIA 1M view-heap baseline failures** (`descriptor::host::tests::dynamic_slots_are_held_until_released` and `memory::tests::lists_share_a_table_and_copies_keep_their_views`) that fail on `main` `13f91cae` (196 passed, 2 failed). - **WARP (`VICTORY_D3D12_WARP=1`):** **201 passed, 0 failed, 1 ignored** (1.72s). - **Clippy (`victory-gpu`):** `cargo clippy -p victory-gpu --all-targets --all-features --locked -- -D warnings` -> **0 warnings**. - **Note on `victory-shader`:** `emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index` exited with `0xc0000005` (`STATUS_ACCESS_VIOLATION`) on RTX 5070 Ti; confirmed this reproduces identically on clean `main` `13f91cae` (not a regression from #2650). Not tested: live game workload / `victory-shader` full suite past the pre-existing access violation. AI-assisted test run and summary.
Author
Owner

@⁠kotekompotek on GitHub · 2026-11-25 17:54 UTC · original

Reviewed the slot-mapping piece: on capped hosts the host heap holds the title's slots by blocks, so every shader-reported index must go through title_of() — both make_read sites now translate before comparing against desc.count, and stamp_read is keyed on the host slot consistently. This closes the same capped-heap family as #2475's trim work but at the mapping layer, which is the more fundamental fix; check for overlap with #2628's clamp-side change when ordering merges. CI pending at review time.

**@⁠kotekompotek** on GitHub · 2026-11-25 17:54 UTC · [original](https://github.com/Marvisak/VIctory/pull/2650#issuecomment-7170158472) Reviewed the slot-mapping piece: on capped hosts the host heap holds the title's slots by blocks, so every shader-reported index must go through `title_of()` — both `make_read` sites now translate before comparing against `desc.count`, and `stamp_read` is keyed on the *host* slot consistently. This closes the same capped-heap family as #2475's trim work but at the mapping layer, which is the more fundamental fix; check for overlap with #2628's clamp-side change when ordering merges. CI pending at review time.
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-25 18:24 UTC · original

Independent Windows 11 + NVIDIA GeForce RTX 5090 + WARP verification and code review of 3e606d27 (on 13f91ca):

Hardware Verification (rustc 1.98.1 MSVC)

  • NVIDIA GeForce RTX 5090 (victory-gpu): cargo test --locked -p victory-gpu --features diagnostics --lib -- --test-threads=1 -> 201 passed, 0 failed, 1 ignored (2.59s). Fixes both pre-existing 1M-cap failures on 13f91ca (dynamic_slots_are_held_until_released and lists_share_a_table_and_copies_keep_their_views).
  • WARP (VICTORY_D3D12_WARP=1): 201 passed, 0 failed, 1 ignored (1.89s).
  • Clippy (victory-gpu): cargo clippy --locked -p victory-gpu --all-targets --all-features -- -D warnings -> 0 warnings.

Bugs found in code review (crates/victory-gpu/src/descriptor/host.rs)

  1. HostHeap::sync_slots still indexes self.made by title slot i instead of host slot (untouched in this PR):
    On 13f91ca, sync_slots (lines 636–657) does made.get(i as usize) directly with the title slot i. Under blocks.sparse == true (1M-capped hosts like RTX 5090/3080/Arc A770), self.made is indexed by host slot (map.host[i / BLOCK] * BLOCK + i % BLOCK), not title slot i:

    • Permanent resource & sparse-block leaks: when title slot i < self.count lives in a remapped host block and is cleared (!current), if the unrelated host slot i happens to have made[i] == 0, sync_slots skips self.mirror(i, ...). The real host slot is never nulled, its kept ID3D12Resource is not released, and self.vacate(i) never runs to decrement map.views[block] and return the host block.
    • Stale descriptors: when title slot i < self.count changes from view A to view B (current == true) and unrelated made[i] already matches view B's key (e.g., identical view copied into another slot), sync_slots skips mirror(i) and leaves the host slot stuck on view A.
    • Fast-path defeat above self.count: for every title slot i >= self.count, made.get(i as usize) returns None => true, forcing a per-slot mirror(i) call on every heap sync even when the slot is empty or unchanged.
    • Suggested fix: matching the blocks.map -> made lock order already noted in evict, resolve the host slot (Option<u32>) for each i in first..last under one blocks.map lock before locking self.made; then for Some(slot) compare against made[slot as usize], and for None (unmapped block) mark stale only if current is true.
  2. Concurrency window between self.place(...) and self.made lock in HostHeap::mirror:
    mirror calls self.place(index, view.is_some()) (which releases blocks.map) before acquiring self.made. If thread A resolves slot for a view (particularly on the later == true path, which does not re-read handle) and pauses before locking made, thread B can concurrently observe index cleared, null made[slot], drop made, and call self.vacate(index) — freeing host block slot / BLOCK (which thread C can then reassign to a different title block). When thread A then acquires made, it writes made[slot], strides[slot], addresses[slot], and a descriptor into a vacated or reassigned host block. Holding the block mapping check / re-verifying slot against self.slot(index) or serializing vacate with made (e.g. under blocks.map -> made order) would close this window.

**@⁠fuzeofficlal** on GitHub · 2026-11-25 18:24 UTC · [original](https://github.com/Marvisak/VIctory/pull/2650#issuecomment-7170874749) Independent Windows 11 + NVIDIA GeForce RTX 5090 + WARP verification and code review of `3e606d27` (on `13f91ca`): ### Hardware Verification (`rustc 1.98.1` MSVC) - **NVIDIA GeForce RTX 5090 (`victory-gpu`):** `cargo test --locked -p victory-gpu --features diagnostics --lib -- --test-threads=1` -> **201 passed, 0 failed, 1 ignored** (2.59s). Fixes both pre-existing 1M-cap failures on `13f91ca` (`dynamic_slots_are_held_until_released` and `lists_share_a_table_and_copies_keep_their_views`). - **WARP (`VICTORY_D3D12_WARP=1`):** **201 passed, 0 failed, 1 ignored** (1.89s). - **Clippy (`victory-gpu`):** `cargo clippy --locked -p victory-gpu --all-targets --all-features -- -D warnings` -> **0 warnings**. ### Bugs found in code review (`crates/victory-gpu/src/descriptor/host.rs`) 1. **`HostHeap::sync_slots` still indexes `self.made` by title slot `i` instead of host slot (untouched in this PR):** On `13f91ca`, `sync_slots` (lines 636–657) does `made.get(i as usize)` directly with the title slot `i`. Under `blocks.sparse == true` (1M-capped hosts like RTX 5090/3080/Arc A770), `self.made` is indexed by **host slot** (`map.host[i / BLOCK] * BLOCK + i % BLOCK`), not title slot `i`: - **Permanent resource & sparse-block leaks:** when title slot `i < self.count` lives in a remapped host block and is cleared (`!current`), if the unrelated host slot `i` happens to have `made[i] == 0`, `sync_slots` skips `self.mirror(i, ...)`. The real host slot is never nulled, its `kept` `ID3D12Resource` is not released, and `self.vacate(i)` never runs to decrement `map.views[block]` and return the host block. - **Stale descriptors:** when title slot `i < self.count` changes from view A to view B (`current == true`) and unrelated `made[i]` already matches view B's key (e.g., identical view copied into another slot), `sync_slots` skips `mirror(i)` and leaves the host slot stuck on view A. - **Fast-path defeat above `self.count`:** for every title slot `i >= self.count`, `made.get(i as usize)` returns `None => true`, forcing a per-slot `mirror(i)` call on every heap sync even when the slot is empty or unchanged. - **Suggested fix:** matching the `blocks.map -> made` lock order already noted in `evict`, resolve the host slot (`Option<u32>`) for each `i` in `first..last` under one `blocks.map` lock before locking `self.made`; then for `Some(slot)` compare against `made[slot as usize]`, and for `None` (unmapped block) mark stale only if `current` is true. 2. **Concurrency window between `self.place(...)` and `self.made` lock in `HostHeap::mirror`:** `mirror` calls `self.place(index, view.is_some())` (which releases `blocks.map`) before acquiring `self.made`. If thread A resolves `slot` for a view (particularly on the `later == true` path, which does not re-read `handle`) and pauses before locking `made`, thread B can concurrently observe `index` cleared, null `made[slot]`, drop `made`, and call `self.vacate(index)` — freeing host block `slot / BLOCK` (which thread C can then reassign to a different title block). When thread A then acquires `made`, it writes `made[slot]`, `strides[slot]`, `addresses[slot]`, and a descriptor into a vacated or reassigned host block. Holding the block mapping check / re-verifying `slot` against `self.slot(index)` or serializing `vacate` with `made` (e.g. under `blocks.map` -> `made` order) would close this window.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 22:15 UTC · original

Automated triage for the maintainers.

This PR no longer merges cleanly into main (f3578e3): crates/victory-gpu/src/descriptor/host.rs, crates/victory-gpu/src/draw.rs and crates/victory-gpu/src/host.rs conflict with changes that landed on main. It will be reviewed once it is rebased.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 22:15 UTC · [original](https://github.com/Marvisak/VIctory/pull/2650#issuecomment-7176134877) <!-- victory-triage v1 head=3e606d2786a96cd0a7e88c970ffbd794c09bd9f2 verdict=needs-rebase at=2026-11-25T22:15:11Z --> Automated triage for the maintainers. This PR no longer merges cleanly into `main` (f3578e3): `crates/victory-gpu/src/descriptor/host.rs`, `crates/victory-gpu/src/draw.rs` and `crates/victory-gpu/src/host.rs` conflict with changes that landed on `main`. It will be reviewed once it is rebased. --- _Generated by [Claude Code](https://claude.ai/code)_
This pull request has changes conflicting with the target branch.
  • crates/victory-gpu/src/descriptor/host.rs
  • crates/victory-gpu/src/draw.rs
  • crates/victory-gpu/src/host.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

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

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2650'
git switch 'github-bot/gh-2650'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2650'
git switch 'github-bot/gh-2650'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2650'
git switch 'main'
git merge --squash 'github-bot/gh-2650'
git switch 'main'
git merge --ff-only 'github-bot/gh-2650'
git switch 'main'
git merge 'github-bot/gh-2650'
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!2650
No description provided.