GPU: a buffer view slot follows the title buffer that holds its bytes #2893

Open
0xkn0wh3r3 wants to merge 2 commits from upstream-pr/2895 into main
0xkn0wh3r3 commented 2026-11-25 23:18:54 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by 0xkn0wh3r3 on 2026-11-25T23:18:54Z.


What

A buffer view reads the copy of the innermost title buffer that holds its bytes (shadow::for_view → find). A heap slot made from a view kept the copy it was first made on. Two things change which copy draws refresh for the view (view_copy, from readable):

  • the title places a buffer inside the one the slot shows;
  • the inner buffer the slot shows is released.

The copy the slot showed stayed the same either way. So shaders read a copy that was no longer brought up to date, or a released buffer's copy. The fresh tables a list reuses (fresh_tables) held the same stale views.

This PR adds three things:

  • Owner count: shadow counts title buffers made and released (owners()).
  • HostHeap::mirror: a buffer view slot whose record hasn't changed is checked again only when that count has moved. It's made again when the copy it shows isn't the one its view reads now. Until buffers come or go, the cost is one comparison.
  • Fresh tables: the fresh_tables key includes the count, so a list makes a table again after buffers come or go.

Where it came from

From DexNom's fork, DexNom/VIctory@5f4c3df (buffer_owner_current, BUFFER_GENERATION, and the test placed_buffer_slots_follow_new_and_released_owners). It's reworked for this tree's mirror and compares against view_copy, so views with copies of their own (shadow::exact) are handled too. Credited with Co-authored-by: DexNom.

Tested

  • New test descriptor::host::tests::buffer_view_slots_follow_new_and_released_owners. It places a shader view and an unordered view in a 512-byte title buffer. The slots show its copy, then the copy of a 64-byte buffer placed inside it, then the outer copy again once the inner buffer is released, each time the copy view_copy gives. With the check disabled, it fails at the second step (the slot still shows the outer copy).
  • cargo test -p victory-gpu (Windows 11, RTX 5070 Ti): 230 passed. The 2 known NVIDIA failures are fixed by #2121.
  • cargo clippy -p victory-gpu --all-targets -- -D warnings, with and without --features diagnostics: clean.

Not tested

  • There's no dedicated test of the fresh_tables key change within one list.
  • Not run with the title, so I don't know how often its buffers nest this way.

Changes after review

  • a71de13, race: the owner count now goes up after the buffer map changes, so a mirror that read the old count looks again.
  • a71de13, constant views: constant views in the heap are made raw views of the copy that holds their bytes, and they now follow it too (shown_copy). The test adds a constant view of the same bytes; without the change, slot 2 keeps the outer copy.
  • Slots that shaders reach only through the heap itself (bindless) are still made when their record changes; this PR doesn't change that.
<!-- greyfinch-sync:Marvisak/VIctory:issue:6615760094 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2895). Originally posted by [0xkn0wh3r3](https://github.com/0xkn0wh3r3) on 2026-11-25T23:18:54Z. --- ## What A buffer view reads the copy of the innermost title buffer that holds its bytes (`shadow::for_view` → `find`). A heap slot made from a view kept the copy it was first made on. Two things change which copy draws refresh for the view (`view_copy`, from `readable`): - the title places a buffer inside the one the slot shows; - the inner buffer the slot shows is released. The copy the slot showed stayed the same either way. So shaders read a copy that was no longer brought up to date, or a released buffer's copy. The fresh tables a list reuses (`fresh_tables`) held the same stale views. This PR adds three things: - **Owner count:** `shadow` counts title buffers made and released (`owners()`). - **`HostHeap::mirror`:** a buffer view slot whose record hasn't changed is checked again only when that count has moved. It's made again when the copy it shows isn't the one its view reads now. Until buffers come or go, the cost is one comparison. - **Fresh tables:** the `fresh_tables` key includes the count, so a list makes a table again after buffers come or go. ## Where it came from From DexNom's fork, [DexNom/VIctory@5f4c3df](https://github.com/DexNom/VIctory/commit/5f4c3df44197eb03b82205d2da871ded8d0ccf16) (`buffer_owner_current`, `BUFFER_GENERATION`, and the test `placed_buffer_slots_follow_new_and_released_owners`). It's reworked for this tree's `mirror` and compares against `view_copy`, so views with copies of their own (`shadow::exact`) are handled too. Credited with `Co-authored-by: DexNom`. ## Tested - New test `descriptor::host::tests::buffer_view_slots_follow_new_and_released_owners`. It places a shader view and an unordered view in a 512-byte title buffer. The slots show its copy, then the copy of a 64-byte buffer placed inside it, then the outer copy again once the inner buffer is released, each time the copy `view_copy` gives. With the check disabled, it fails at the second step (the slot still shows the outer copy). - `cargo test -p victory-gpu` (Windows 11, RTX 5070 Ti): 230 passed. The 2 known NVIDIA failures are fixed by #2121. - `cargo clippy -p victory-gpu --all-targets -- -D warnings`, with and without `--features diagnostics`: clean. ## Not tested - There's no dedicated test of the `fresh_tables` key change within one list. - Not run with the title, so I don't know how often its buffers nest this way. ## Changes after review - a71de13, race: the owner count now goes up after the buffer map changes, so a `mirror` that read the old count looks again. - a71de13, constant views: constant views in the heap are made raw views of the copy that holds their bytes, and they now follow it too (`shown_copy`). The test adds a constant view of the same bytes; without the change, slot 2 keeps the outer copy. - Slots that shaders reach only through the heap itself (bindless) are still made when their record changes; this PR doesn't change that.
fuzeofficlal commented 2026-11-26 00:03:05 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T23:32:28Z.

Review: COMMENTED


Verified head b0e51ff3 cleanly on top of origin/main (842b0cb7) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + D3D12 WARP + VICTORY_D3D12_DEBUG=1).

Findings

  1. Concurrency race in crates/victory-gpu/src/shadow.rs:1002-1019 (register / unregister): OWNERS.fetch_add(1) is called before BUFFERS is updated. A concurrent mirror() thread can observe the incremented owners (descriptor/host.rs:792), call view_copy(&view) before the BUFFERS insert/remove completes (still seeing the old owner so held == current), and cache the new owners in owners_seen (descriptor/host.rs:808), permanently missing the owner change. Moving OWNERS.fetch_add(1, Ordering::Release) (paired with Acquire load in shadow::owners()) after updating BUFFERS closes that window.
  2. View::Constant heap slots skipped by owner_moved() (descriptor/host.rs:794): owner_moved() exits early when buffer_range(&view).is_none(), and buffer_range (descriptor/host.rs:1154) returns None for View::Constant. Because make() and readable() both resolve and refresh heap CBV slots via shadow::find, a heap-resident View::Constant whose backing title buffer is created or released won't be refreshed when OWNERS changes.
  3. Pure bindless slots & merge notes:
    • sync_slots only re-checks slots whose dirty-page records changed, so a purely bindless buffer view whose backing buffer changes without a descriptor write won't refresh via sync_slots alone (worth noting if intentional).
    • Semantically orthogonal to #2885 and #2873 (owner_moved() reuses view_copy(&view)), though #2895 and #2873 touch the same area near the top of descriptor/host.rs's mod tests.

Local Verification

  • RTX 5090: shadow::tests 9/9, draw::tests 20/20, descriptor::host::tests 15/16 (buffer_view_slots_follow_new_and_released_owners passes; the single failure is the pre-existing dynamic_slots_are_held_until_released NVIDIA 1M view cap baseline).
  • WARP + VICTORY_D3D12_DEBUG=1: descriptor::host::tests 16/16, shadow::tests 9/9, draw::tests 20/20.
  • cargo clippy --locked -p victory-gpu --tests -- -D warnings & cargo xtask policy (191 files ok): clean.
<!-- greyfinch-sync:Marvisak/VIctory:review:6066454729 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2895#pullrequestreview-6066454729). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-25T23:32:28Z. **Review:** COMMENTED --- Verified head `b0e51ff3` cleanly on top of `origin/main` (`842b0cb7`) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + D3D12 WARP + `VICTORY_D3D12_DEBUG=1`). ### Findings 1. **Concurrency race in `crates/victory-gpu/src/shadow.rs:1002-1019` (`register` / `unregister`)**: `OWNERS.fetch_add(1)` is called *before* `BUFFERS` is updated. A concurrent `mirror()` thread can observe the incremented `owners` (`descriptor/host.rs:792`), call `view_copy(&view)` before the `BUFFERS` insert/remove completes (still seeing the old owner so `held == current`), and cache the new `owners` in `owners_seen` (`descriptor/host.rs:808`), permanently missing the owner change. Moving `OWNERS.fetch_add(1, Ordering::Release)` (paired with `Acquire` load in `shadow::owners()`) **after** updating `BUFFERS` closes that window. 2. **`View::Constant` heap slots skipped by `owner_moved()` (`descriptor/host.rs:794`)**: `owner_moved()` exits early when `buffer_range(&view).is_none()`, and `buffer_range` (`descriptor/host.rs:1154`) returns `None` for `View::Constant`. Because `make()` and `readable()` both resolve and refresh heap CBV slots via `shadow::find`, a heap-resident `View::Constant` whose backing title buffer is created or released won't be refreshed when `OWNERS` changes. 3. **Pure bindless slots & merge notes**: - `sync_slots` only re-checks slots whose dirty-page records changed, so a purely bindless buffer view whose backing buffer changes without a descriptor write won't refresh via `sync_slots` alone (worth noting if intentional). - Semantically orthogonal to `#2885` and `#2873` (`owner_moved()` reuses `view_copy(&view)`), though `#2895` and `#2873` touch the same area near the top of `descriptor/host.rs`'s `mod tests`. ### Local Verification - **RTX 5090**: `shadow::tests` **9/9**, `draw::tests` **20/20**, `descriptor::host::tests` **15/16** (`buffer_view_slots_follow_new_and_released_owners` passes; the single failure is the pre-existing `dynamic_slots_are_held_until_released` NVIDIA 1M view cap baseline). - **WARP + `VICTORY_D3D12_DEBUG=1`**: `descriptor::host::tests` **16/16**, `shadow::tests` **9/9**, `draw::tests` **20/20**. - `cargo clippy --locked -p victory-gpu --tests -- -D warnings` & `cargo xtask policy` (`191 files ok`): clean.
kotekompotek commented 2026-11-26 00:03:05 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-25T23:37:04Z.

Review: COMMENTED


Correct staleness epoch: owners() counts title-buffer make/release, so a slot whose innermost byte-owner changed since last view gets re-resolved through view_copy — the kept-pointer comparison then catches a shadow that moved. Only re-checked for buffer views and only when the owner count moved, so the per-draw cost stays near zero. LGTM.

<!-- greyfinch-sync:Marvisak/VIctory:review:6066497373 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2895#pullrequestreview-6066497373). Originally posted by [kotekompotek](https://github.com/kotekompotek) on 2026-11-25T23:37:04Z. **Review:** COMMENTED --- Correct staleness epoch: owners() counts title-buffer make/release, so a slot whose innermost byte-owner changed since last view gets re-resolved through view_copy — the kept-pointer comparison then catches a shadow that moved. Only re-checked for buffer views and only when the owner count moved, so the per-draw cost stays near zero. LGTM.
Marvisak commented 2026-11-26 05:04:12 +00:00 (Migrated from github.com)

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


Automated triage for the maintainers.

Thanks, that answers the note. draw::State::cut clears fresh_tables, so an owner change only rebuilds tables within the current segment. A diagnostics counter can be a follow-up. Nothing else has changed (same head). One cross-PR point: #2821's lock-free ready path in HostHeap::mirror would skip owner_moved, so whichever lands second needs to account for it.

CI: passing.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7182653567 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2895#issuecomment-7182653567). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-26T04:30:23Z. --- <!-- victory-triage v1 head=a71de1313c23de8ff1f961011baba273be6ed328 verdict=merge-candidate at=2026-11-26T07:23:28Z --> Automated triage for the maintainers. Thanks, that answers the note. `draw::State::cut` clears `fresh_tables`, so an owner change only rebuilds tables within the current segment. A diagnostics counter can be a follow-up. Nothing else has changed (same head). One cross-PR point: #2821's lock-free `ready` path in `HostHeap::mirror` would skip `owner_moved`, so whichever lands second needs to account for it. CI: passing. --- _Generated by [Claude Code](https://claude.ai/code)_
Dukestar69 commented 2026-11-26 06:02:45 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T05:49:34Z.

Review: APPROVED


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

  • Diff review: Tracking the buffer-owner generation via shadow::owners() and HostHeap::owners_seen and comparing the slot's held host resource against shown_copy(&view) ensures SRV/UAV/CBV buffer view slots rebind whenever an inner placed title buffer is created or released over the same address range.
  • cargo test -p victory-gpu buffer_view_slots_follow_new_and_released_owners -- --test-threads=1 (RTX 5090 & WARP): 1 passed, 0 failed on both.
  • cargo test -p victory-gpu shadow::tests -- --test-threads=1 (RTX 5090): 9 passed, 0 failed.
  • 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:6069154982 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2895#pullrequestreview-6069154982). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T05:49:34Z. **Review:** APPROVED --- Tested locally merged onto `origin/main` (`63bcca4`) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + WARP): - Diff review: Tracking the buffer-owner generation via `shadow::owners()` and `HostHeap::owners_seen` and comparing the slot's held host resource against `shown_copy(&view)` ensures SRV/UAV/CBV buffer view slots rebind whenever an inner placed title buffer is created or released over the same address range. - `cargo test -p victory-gpu buffer_view_slots_follow_new_and_released_owners -- --test-threads=1` (RTX 5090 & WARP): 1 passed, 0 failed on both. - `cargo test -p victory-gpu shadow::tests -- --test-threads=1` (RTX 5090): 9 passed, 0 failed. - `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).
0xkn0wh3r3 commented 2026-11-26 08:03:11 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by 0xkn0wh3r3 on 2026-11-26T07:06:37Z.


On the fresh_tables note: fresh_tables lives in one host list segment (State::cut clears it). So a buffer create or release invalidates the tables already made in that segment only, and each is made again at most once, on its next use. The cost is that rebuild plus its dynamic slots, which stay held until the list is reset.

I haven't added a counter, to keep this PR small. Telling an owner-change rebuild apart from an ordinary miss needs a second key without the count. If you'd like the number before merging, I can add a diagnostics counter here or as a follow-up.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7185105728 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2895#issuecomment-7185105728). Originally posted by [0xkn0wh3r3](https://github.com/0xkn0wh3r3) on 2026-11-26T07:06:37Z. --- On the `fresh_tables` note: `fresh_tables` lives in one host list segment (`State::cut` clears it). So a buffer create or release invalidates the tables already made in that segment only, and each is made again at most once, on its next use. The cost is that rebuild plus its dynamic slots, which stay held until the list is reset. I haven't added a counter, to keep this PR small. Telling an owner-change rebuild apart from an ordinary miss needs a second key without the count. If you'd like the number before merging, I can add a diagnostics counter here or as a follow-up.
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/2895:upstream-pr/2895'
git switch 'upstream-pr/2895'

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