GPU: a view's own copy that shaders feed reads its buffer's copy on the GPU (stacked on #334 and #1019) #1404

Open
SantannaCarlos wants to merge 9 commits from upstream-pr/1405 into main
SantannaCarlos commented 2026-11-24 17:46:58 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by SantannaCarlos on 2026-11-24T17:46:58Z.


Stacked on #334 (buffer states) and #1019 (views off an element): only the last two commits are new here, e8902a3 and ad2025a (fixes from review). The merge brings #334 as it is (c99e429); the commits before it are #1019's.

What

#1019 gives a view that starts off an element of its buffer's host copy a copy of just its bytes. That copy is brought up to date from title memory when the submission is prepared, so it does not see what the submission's shaders wrote in that range in the buffer's copy before the read; a view on an element of the same bytes does. In the world this is common: in a 10-minute run on an RTX 4070, 1,938 such ranges had bytes written by shaders in the 174 MB buffer's copy within the submission that read them (median 4.5 KB, about ten a frame). This was the known limit noted in #1019.

  • The copy-back of a buffer's copy now marks the copies cut from it whose range holds bytes its shaders changed.
  • A shader view of a marked copy reads what a view on an element reads: the buffer's copy is brought up to date as for such a view, and its bytes are copied into the view's copy on the GPU right before the read, with the states #334 tracks (read for the source, copy destination and then read for the view's copy).
  • The mark stays, since the title produces that data on the GPU every frame; copies never marked keep their own refresh, so the cost is only where it is needed.

Not covered:

  • an unordered view with its own copy still writes it apart, so within a submission other views of those bytes see its writes only after the copy-back;
  • the first submission whose shaders write a copy's range is still read the old way: the mark comes from that submission's copy-back, and lists recorded before it keep the old path for that submission;
  • views read only through directly indexed heaps, which #334 does not track either.

Tested

  • cargo clippy --workspace --all-targets -- -D warnings, with and without --all-features; cargo test --workspace (victory-gpu 61 passed, 1 ignored); cargo xtask policy. New test: shader writes in a view's range, found by the copy-back of the copy it was cut from, mark it; writes next to the range, or in another copy, do not.
  • In the world on an RTX 4070, 10-minute runs, on a tree of main + #493 + #876 + #439 (with #223, #233, #320) + #116 + #984 + #949 + #1020 + #1198 + #1019 + #334 + this, with a local tracing patch:
    • with e8902a3: no stop, 27 own copies marked and read through the GPU copy, no added cost (median 4.4 s a frame, against 5.8 s for the same tree without #334 and this; the tree is slow because of #1198);
    • with ad2025a, two runs: one with no stop (26 copies marked); one where the device was removed at 498 s, with no breadcrumbs in the report and a CS_ClearFeedbackSetup dispatch listed in flight. It did not come back in the repeat, and this stack has other ways to hang on this card, so I can't tie it to this change either way.

What I could not show: a visible difference in the dumped targets. The captures fall on different moments of the scene between runs, so they do not compare.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6587937192 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1405). Originally posted by [SantannaCarlos](https://github.com/SantannaCarlos) on 2026-11-24T17:46:58Z. --- Stacked on #334 (buffer states) and #1019 (views off an element): only the last two commits are new here, e8902a3 and ad2025a (fixes from review). The merge brings #334 as it is (c99e429); the commits before it are #1019's. ## What #1019 gives a view that starts off an element of its buffer's host copy a copy of just its bytes. That copy is brought up to date from title memory when the submission is prepared, so it does not see what the submission's shaders wrote in that range in the buffer's copy before the read; a view on an element of the same bytes does. In the world this is common: in a 10-minute run on an RTX 4070, 1,938 such ranges had bytes written by shaders in the 174 MB buffer's copy within the submission that read them (median 4.5 KB, about ten a frame). This was the known limit noted in #1019. - The copy-back of a buffer's copy now marks the copies cut from it whose range holds bytes its shaders changed. - A shader view of a marked copy reads what a view on an element reads: the buffer's copy is brought up to date as for such a view, and its bytes are copied into the view's copy on the GPU right before the read, with the states #334 tracks (read for the source, copy destination and then read for the view's copy). - The mark stays, since the title produces that data on the GPU every frame; copies never marked keep their own refresh, so the cost is only where it is needed. Not covered: - an unordered view with its own copy still writes it apart, so within a submission other views of those bytes see its writes only after the copy-back; - the first submission whose shaders write a copy's range is still read the old way: the mark comes from that submission's copy-back, and lists recorded before it keep the old path for that submission; - views read only through directly indexed heaps, which #334 does not track either. ## Tested - `cargo clippy --workspace --all-targets -- -D warnings`, with and without `--all-features`; `cargo test --workspace` (`victory-gpu` 61 passed, 1 ignored); `cargo xtask policy`. New test: shader writes in a view's range, found by the copy-back of the copy it was cut from, mark it; writes next to the range, or in another copy, do not. - In the world on an RTX 4070, 10-minute runs, on a tree of `main` + #493 + #876 + #439 (with #223, #233, #320) + #116 + #984 + #949 + #1020 + #1198 + #1019 + #334 + this, with a local tracing patch: - with e8902a3: no stop, 27 own copies marked and read through the GPU copy, no added cost (median 4.4 s a frame, against 5.8 s for the same tree without #334 and this; the tree is slow because of #1198); - with ad2025a, two runs: one with no stop (26 copies marked); one where the device was removed at 498 s, with no breadcrumbs in the report and a `CS_ClearFeedbackSetup` dispatch listed in flight. It did not come back in the repeat, and this stack has other ways to hang on this card, so I can't tie it to this change either way. What I could not show: a visible difference in the dumped targets. The captures fall on different moments of the scene between runs, so they do not compare.
aycow commented 2026-11-24 19:04:07 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by aycow on 2026-11-24T18:13:31Z.


Thanks for following up on #1019. I reviewed exact e8902a3 specifically against f173d36 (#185) and 709647f (#387). The composition has conflicts, and two source-level edge cases stood out. These are review findings pending native reproduction.

  1. The aligned cut cache keys by title address/length, while the cut now permanently owns its source. A minimal check is to request identical aligned spans from two distinct live source generations. Each cut should retain and follow only its own source. The +48/+52 test uses separate keys.
  2. An ordinary parent UAV table can bind before a fresh table containing a fed cut SRV and a CBV. The same-command write precedence can then suppress the source transition before the immediate internal copy. An ordered preparation phase before final dispatch states would also make that copy's native source/destination touches easier to track for #595.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7140337947 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1405#issuecomment-7140337947). Originally posted by [aycow](https://github.com/aycow) on 2026-11-24T18:13:31Z. --- Thanks for following up on #1019. I reviewed exact e8902a3 specifically against f173d36 (#185) and 709647f (#387). The composition has conflicts, and two source-level edge cases stood out. These are review findings pending native reproduction. 1. The [aligned cut cache](https://github.com/SantannaCarlos/VIctory/blob/e8902a3224dc18e3293122205e8e54757025c373/crates/victory-gpu/src/shadow.rs#L541) keys by title address/length, while the cut now permanently owns its source. A minimal check is to request identical aligned spans from two distinct live source generations. Each cut should retain and follow only its own source. The +48/+52 test uses separate keys. 2. An ordinary parent UAV table can bind before a fresh table containing a fed cut SRV and a CBV. [The same-command write precedence](https://github.com/SantannaCarlos/VIctory/blob/e8902a3224dc18e3293122205e8e54757025c373/crates/victory-gpu/src/host.rs#L748) can then suppress the source transition before the [immediate internal copy](https://github.com/SantannaCarlos/VIctory/blob/e8902a3224dc18e3293122205e8e54757025c373/crates/victory-gpu/src/draw.rs#L1150). An ordered preparation phase before final dispatch states would also make that copy's native source/destination touches easier to track for #595.
SantannaCarlos commented 2026-11-24 19:04:12 +00:00 (Migrated from github.com)

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


@aycow both hold; thank you. Fixed in ad2025a on this branch:

  1. A copy of a view's bytes is now found again by start, length and the buffer's copy it was cut from, so the same bytes cut from another copy of that memory (a title buffer released and registered again) get a copy of their own, which follows and is marked by that copy only. New test: the same span cut from two copies gives two copies; shader writes found by one copy's copy-back mark only the copy cut from it.
  2. The GPU copy no longer goes through buffer_state, where the command's own write wins. HostList::copy_buffer moves the source to the copy-source state and the view's copy to copy-destination, records the copy, and moves each back to the state the command has it in (BufferStates::around_copy); a first use records the copy's state for the prelude. New test: after the same command binds the source for writing, a copy from it still transitions it (write, copy source, write), and a read state is left as it is. Keeping the copy and its two transitions in one call should also make it one unit for #595 to track.

cargo test --workspace (victory-gpu 63 passed, 1 ignored), clippy with and without --all-features, and the asset policy pass. On the conflicts with #185 and #387: I haven't resolved those here; this stays on #334 and #1019 as they are.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7140594991 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1405#issuecomment-7140594991). Originally posted by [SantannaCarlos](https://github.com/SantannaCarlos) on 2026-11-24T18:24:11Z. --- @aycow both hold; thank you. Fixed in ad2025a on this branch: 1. A copy of a view's bytes is now found again by start, length and the buffer's copy it was cut from, so the same bytes cut from another copy of that memory (a title buffer released and registered again) get a copy of their own, which follows and is marked by that copy only. New test: the same span cut from two copies gives two copies; shader writes found by one copy's copy-back mark only the copy cut from it. 2. The GPU copy no longer goes through `buffer_state`, where the command's own write wins. `HostList::copy_buffer` moves the source to the copy-source state and the view's copy to copy-destination, records the copy, and moves each back to the state the command has it in (`BufferStates::around_copy`); a first use records the copy's state for the prelude. New test: after the same command binds the source for writing, a copy from it still transitions it (write, copy source, write), and a read state is left as it is. Keeping the copy and its two transitions in one call should also make it one unit for #595 to track. `cargo test --workspace` (`victory-gpu` 63 passed, 1 ignored), clippy with and without `--all-features`, and the asset policy pass. On the conflicts with #185 and #387: I haven't resolved those here; this stays on #334 and #1019 as they are.
aycow commented 2026-11-24 19:04:32 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by aycow on 2026-11-24T18:43:14Z.


Thanks for the fixes in ad2025a. The identical-range, distinct-source regression passed on AMD Radeon Graphics, RTX 5070 Laptop and WARP. An additional native fixture dispatches a UAV producer, copies the alias while the parent is already bound for the next dispatch, then reads the alias while writing the parent again. Both destination-state variants read 43 and wrote 44 on all three with full GBV and no warnings or errors. The previous sequence triggered WARP errors 527 and 538 because the copy source was still UAV.

These results cover the case where the copy path is selected. First-use discovery, already-recorded lists and directly indexed descriptors still need separate controls. #185/#387 and #595 composition have source conflicts. #595 will also need the exact parent and cut read/write touches and native backing ownership through completion.

The author-preserving #1405/#387 composition is now independently tested against current #387 0899b7d. Both inline state variants, all 20 ordering checks, and all five shadow cases passed on AMD, NVIDIA, and WARP with full GBV. Both workspace Clippy configurations and asset policy passed. The test overlay retains the named test-device setup. The first unmarked parent-to-cut read within one native list still needs earlier producer tracking. #185 direct heaps and #595 fence ownership remain separate integration work.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7141054556 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1405#issuecomment-7141054556). Originally posted by [aycow](https://github.com/aycow) on 2026-11-24T18:43:14Z. --- Thanks for the fixes in ad2025a. The identical-range, distinct-source regression passed on AMD Radeon Graphics, RTX 5070 Laptop and WARP. An additional [native fixture](https://github.com/aycow/VIctory/commit/2b69510947061c8e9017ef58a9e8b7a164d39aa1) dispatches a UAV producer, copies the alias while the parent is already bound for the next dispatch, then reads the alias while writing the parent again. Both destination-state variants read 43 and wrote 44 on all three with full GBV and no warnings or errors. The previous sequence triggered WARP errors 527 and 538 because the copy source was still UAV. These results cover the case where the copy path is selected. First-use discovery, already-recorded lists and directly indexed descriptors still need separate controls. #185/#387 and #595 composition have source conflicts. #595 will also need the exact parent and cut read/write touches and native backing ownership through completion. The [author-preserving #1405/#387 composition](https://github.com/aycow/VIctory/commit/f8fa44e47ad908808d734df59bf9990ea1b30267) is now independently tested against current #387 0899b7d. Both inline state variants, all 20 ordering checks, and all five shadow cases passed on AMD, NVIDIA, and WARP with full GBV. Both workspace Clippy configurations and asset policy passed. The [test overlay](https://github.com/aycow/VIctory/commit/fbc9712aa1d127b3d8d7bffbab3517cfa863c358) retains the named test-device setup. The first unmarked parent-to-cut read within one native list still needs earlier producer tracking. #185 direct heaps and #595 fence ownership remain separate integration work.
catminou4 commented 2026-11-24 21:02:24 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T20:49:54Z.

Review: COMMENTED


Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; this is source review of a large diff plus the PR's own Windows tests.

A view's own copy that shaders feed now reads its buffer's copy: make_at/copy_at/mirror per slot, buffer_parts/extent/shader_extent/unordered_extent/view_range_of/view_copy/plan compute the readable extent from the SRV/UAV desc words (14 tests). This is the kind of copy-planning logic that is easy to get subtly wrong (offset/element size/structure stride) — the 14 tests are the evidence; please point to which ones cover structured buffers and byte-address buffers specifically. Windows-only.

<!-- greyfinch-sync:Marvisak/VIctory:review:6047172061 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1405#pullrequestreview-6047172061). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-24T20:49:54Z. **Review:** COMMENTED --- Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; this is source review of a large diff plus the PR's own Windows tests. A view's own copy that shaders feed now reads its buffer's copy: make_at/copy_at/mirror per slot, buffer_parts/extent/shader_extent/unordered_extent/view_range_of/view_copy/plan compute the readable extent from the SRV/UAV desc words (14 tests). This is the kind of copy-planning logic that is easy to get subtly wrong (offset/element size/structure stride) — the 14 tests are the evidence; please point to which ones cover structured buffers and byte-address buffers specifically. Windows-only.
Marvisak commented 2026-11-25 02:06:02 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T01:25:56Z.


Automated triage for the maintainers.

Needs rebase. This pull request conflicts with main (conflicting: crates/victory-gpu/src/descriptor/host.rs, crates/victory-gpu/src/draw.rs, crates/victory-gpu/src/host.rs, crates/victory-gpu/src/indirect.rs, crates/victory-gpu/src/shadow.rs). It will be reviewed once it is rebased onto the current main.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7149539269 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1405#issuecomment-7149539269). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T01:25:56Z. --- <!-- victory-triage v1 head=ad2025a433c985cf41ed227562a9fa98070d081b verdict=needs-rebase at=2026-11-25T01:25:54Z --> Automated triage for the maintainers. **Needs rebase.** This pull request conflicts with `main` (conflicting: `crates/victory-gpu/src/descriptor/host.rs`, `crates/victory-gpu/src/draw.rs`, `crates/victory-gpu/src/host.rs`, `crates/victory-gpu/src/indirect.rs`, `crates/victory-gpu/src/shadow.rs`). It will be reviewed once it is rebased onto the current `main`. --- _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/1405:upstream-pr/1405'
git switch 'upstream-pr/1405'

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