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

Open
Pierrot1398 wants to merge 2 commits from upstream-pr/2650 into main
Pierrot1398 commented 2026-11-25 17:32:33 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Pierrot1398 on 2026-11-25T17:32:33Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:issue:6610080231 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2650). Originally posted by [Pierrot1398](https://github.com/Pierrot1398) on 2026-11-25T17:32:33Z. --- *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
Bj0rnis commented 2026-11-25 18:02:47 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Bj0rnis on 2026-11-25T17:38:10Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7169784899 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2650#issuecomment-7169784899). Originally posted by [Bj0rnis](https://github.com/Bj0rnis) on 2026-11-25T17:38:10Z. --- 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.
kotekompotek commented 2026-11-25 18:02:54 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-25T17:54:09Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7170158472 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2650#issuecomment-7170158472). Originally posted by [kotekompotek](https://github.com/kotekompotek) on 2026-11-25T17:54:09Z. --- 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.
fuzeofficlal commented 2026-11-25 19:06:18 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T18:24:53Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7170874749 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2650#issuecomment-7170874749). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-25T18:24:53Z. --- 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.
Marvisak commented 2026-11-25 23:06:02 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T22:15:30Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7176134877 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2650#issuecomment-7176134877). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T22:15:30Z. --- <!-- 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 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/2650:upstream-pr/2650'
git switch 'upstream-pr/2650'

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