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

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

@⁠0xkn0wh3r3 on GitHub · 2026-11-25 23:18 UTC · original
0xkn0wh3r3:gpu/buffer-slots-follow-new-and-released-owners → main · +118 −3 · 3 files · 2 commits · open

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.
**@⁠0xkn0wh3r3** on GitHub · 2026-11-25 23:18 UTC · [original](https://github.com/Marvisak/VIctory/pull/2895) `0xkn0wh3r3:gpu/buffer-slots-follow-new-and-released-owners` → `main` · +118 −3 · 3 files · 2 commits · open ## 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.
A buffer view reads the copy of the innermost title buffer holding its
bytes (shadow::for_view). A heap slot made from a view kept the copy it
was first made on: a buffer the title then placed inside that one, or
the release of the inner buffer it had shown, changed the copy draws
refresh for the view (view_copy) but not the one the slot showed, so
shaders read a copy no longer brought up to date (or a released
buffer's). The fresh tables a list reuses held the same stale views.

shadow counts title buffers made and released (owners); a buffer view
slot found unchanged is looked at again only when that count moved, and
made again when the copy it shows is not the one its view reads now.
The fresh-table key takes the count, so a list makes a table again after
buffers came or went.

Test: buffer_view_slots_follow_new_and_released_owners (placed shader
and unordered views in a 512-byte buffer: the slot shows its copy, then
the copy of a 64-byte buffer placed inside it, then the outer one again
once that is released; fails without the change).

From DexNom/VIctory@5f4c3df441
(buffer_owner_current, BUFFER_GENERATION and its test), reworked for
this tree's mirror.

Co-authored-by: DexNom <[email protected]>
Review of the buffer view slots following their owners:

- The count of buffers made and released went up before the buffer map
  changed, so a mirror reading the new count could still find the old
  owner and keep a stale slot until the next change. It now goes up
  after the map changed: a mirror that read the old count looks again.
- Constant views in the heap (made raw views of the copy holding their
  bytes) were not looked at (buffer_range has none for them). shown_copy
  gives the copy a slot made from any buffer or constant view would
  show now, and constant view slots follow it as the others do.

The test now also holds a constant view of the same bytes (fails without
the change: slot 2 keeps the outer copy).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:16:56 +00:00
Author
Owner

@⁠Marvisak on GitHub · 2026-11-26 04:30 UTC · original · edited 2026-11-26 07:23 UTC

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

**@⁠Marvisak** on GitHub · 2026-11-26 04:30 UTC · [original](https://github.com/Marvisak/VIctory/pull/2895#issuecomment-7182653567) · edited 2026-11-26 07:23 UTC <!-- 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)_
Author
Owner

@⁠0xkn0wh3r3 on GitHub · 2026-11-26 07:06 UTC · original

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.

**@⁠0xkn0wh3r3** on GitHub · 2026-11-26 07:06 UTC · [original](https://github.com/Marvisak/VIctory/pull/2895#issuecomment-7185105728) 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 can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

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

Merge

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