GPU: a buffer view off its copy's elements gets a copy of its own instead of a null slot #362

Open
RenzoWit35 wants to merge 2 commits from upstream-pr/362 into main
RenzoWit35 commented 2026-11-24 23:56:26 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by RenzoWit35 on 2026-11-24T23:56:26Z.


Refs #62 (the refused typed views reported in its comments). It does not close #62: see the note below.

What

A typed shader view of buffer memory names its first element in its own elements, so on the host copy of the memory it is in it can only begin where offset % element == 0. The console lets a view begin anywhere. buffer_srv refused the rest ("buffer view not on an element of its host copy") and left the slot null, so shaders read zeros. The report in #62 counted 100–121 such views per run, all R32G32B32_FLOAT (12-byte elements), 264–792 bytes, 4 or 16 bytes off.

  • shadow::exact(start, len): a host copy of exactly the title memory one view reads, so the view begins at element 0. Kept in its own map, handed out under its lock, and let go with the idle windows in let_go_idle (same criteria: no list, no slot, idle).
  • descriptor::host::off_element: the one decision. A view that is no raw window, has a known element size, and does not begin on an element of its copy. buffer_srv makes such a view on its own copy at element 0. buffer_copy names the same copy for the view, so the heap pass and readable() bring it up to date, and the slot shows the copy that gets refreshed.
  • Structured views that cannot be raw windows and are off their stride are covered by the same path.
  • Unordered views keep the refusal: a second copy that shaders write would diverge from the first.

shortcut: within one submission, what shaders write to the other copy of the same memory reaches the view's copy only through title memory, after the submission (the same as any other copy). Before, these views read zeros.

Note on #62

A commenter on #62 ported the same idea locally on 4e17478: the refusals went to 0, but the missing cell walls were still missing in that run. So this is a correctness fix for what those views read, not a fix for the walls.

Tests

  • views_off_their_copys_elements_are_told_apart (pure): typed 12-byte elements 4 and 16 bytes in need their own copy; 0 and 24 do not; a structured view that is a raw window does not; one that is not and is off its stride does; an unknown format does not.
  • a_typed_view_off_its_copys_elements_gets_its_own_copy (needs a host device, skips without one): 22 R32G32B32_FLOAT elements (264 bytes) from element 1, 4 bytes into a registered buffer, get a slot on a copy of exactly that range, and buffer_copy names that copy. A view of the same memory on an element keeps the buffer's own copy. With the fix switched off it fails: the view is left null.
  • a_views_own_copy_holds_exactly_its_bytes (needs a host device): after update, the copy holds the title's bytes for the range, and the same range asked for again is the same copy.

On Windows 11, MSVC Rust 1.98.1, on top of main (2119b0e): cargo clippy --workspace --all-targets --locked -- -D warnings, the same with --all-features, cargo test --workspace --locked, and cargo xtask policy all pass. Not run in the title.

🤖 Generated with Claude Code

<!-- greyfinch-sync:fxceless/victory-fork:issue:6593891974 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/362). Originally posted by [RenzoWit35](https://github.com/RenzoWit35) on 2026-11-24T23:56:26Z. --- Refs #62 (the refused typed views reported in its comments). It does not close #62: see the note below. ## What A typed shader view of buffer memory names its first element in its own elements, so on the host copy of the memory it is in it can only begin where `offset % element == 0`. The console lets a view begin anywhere. `buffer_srv` refused the rest (`"buffer view not on an element of its host copy"`) and left the slot null, so shaders read zeros. The report in #62 counted 100–121 such views per run, all `R32G32B32_FLOAT` (12-byte elements), 264–792 bytes, 4 or 16 bytes off. - **`shadow::exact(start, len)`**: a host copy of exactly the title memory one view reads, so the view begins at element 0. Kept in its own map, handed out under its lock, and let go with the idle windows in `let_go_idle` (same criteria: no list, no slot, idle). - **`descriptor::host::off_element`**: the one decision. A view that is no raw window, has a known element size, and does not begin on an element of its copy. `buffer_srv` makes such a view on its own copy at element 0. `buffer_copy` names the same copy for the view, so the heap pass and `readable()` bring it up to date, and the slot shows the copy that gets refreshed. - Structured views that cannot be raw windows and are off their stride are covered by the same path. - **Unordered views keep the refusal**: a second copy that shaders write would diverge from the first. `shortcut:` within one submission, what shaders write to the other copy of the same memory reaches the view's copy only through title memory, after the submission (the same as any other copy). Before, these views read zeros. ## Note on #62 A commenter on #62 ported the same idea locally on 4e17478: the refusals went to 0, but the missing cell walls were still missing in that run. So this is a correctness fix for what those views read, not a fix for the walls. ## Tests - `views_off_their_copys_elements_are_told_apart` (pure): typed 12-byte elements 4 and 16 bytes in need their own copy; 0 and 24 do not; a structured view that is a raw window does not; one that is not and is off its stride does; an unknown format does not. - `a_typed_view_off_its_copys_elements_gets_its_own_copy` (needs a host device, skips without one): 22 `R32G32B32_FLOAT` elements (264 bytes) from element 1, 4 bytes into a registered buffer, get a slot on a copy of exactly that range, and `buffer_copy` names that copy. A view of the same memory on an element keeps the buffer's own copy. With the fix switched off it fails: the view is left null. - `a_views_own_copy_holds_exactly_its_bytes` (needs a host device): after `update`, the copy holds the title's bytes for the range, and the same range asked for again is the same copy. On Windows 11, MSVC Rust 1.98.1, on top of `main` (2119b0e): `cargo clippy --workspace --all-targets --locked -- -D warnings`, the same with `--all-features`, `cargo test --workspace --locked`, and `cargo xtask policy` all pass. Not run in the title. 🤖 Generated with [Claude Code](https://claude.com/claude-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/362:upstream-pr/362'
git switch 'upstream-pr/362'

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