GPU: bind 256-byte-aligned table CBVs directly from shadow buffers #144

Open
MartinIndra02 wants to merge 1 commit from upstream-pr/144 into main
MartinIndra02 commented 2026-11-24 21:50:17 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by MartinIndra02 on 2026-11-24T21:50:17Z.


Summary

Mirrors
oot_view\ (\draw.rs:391) for \View::Constant(address, size)\ entries inside descriptor tables (\draw.rs:2008):

  • Previously, every \View::Constant\ in a descriptor table unconditionally allocated upload scratch memory (\list.scratch) and pushed a \Step::Fill\ copy from title memory.
  • When a table CBV resides in a \Shadow\ buffer at a 256-byte-aligned host GPU address with \ligned_size\ in \1..=65536\ and fits within \shadow.left(address), this PR now binds \shadow.gpu(address)\ directly via \shadow.refresh(list, address, aligned_size)\ + \host.constant_at(index, shadow.gpu(address), size), falling back to the existing \list.scratch\ + \defer_fill\ path for unaligned or out-of-shadow views.
  • This avoids unnecessary per-draw upload-scratch allocations and CPU memcpys, and prevents 256-byte-aligned table CBVs that read GPU-written shadow buffers from triggering \WHY_READ\ (\ fill of upload memory) submission stalls.

RTX 3080 A/B Measurement (Windows 11, 10 GB)

On our local RTX 3080 run (paired with #71 + #25, same switches):

  • \ itle memory read\ caused by \ fill of upload memory\ dropped from **\1.0\ → \
<!-- greyfinch-sync:fxceless/victory-fork:issue:6592109670 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/144). Originally posted by [MartinIndra02](https://github.com/MartinIndra02) on 2026-11-24T21:50:17Z. --- ### Summary Mirrors \ oot_view\ (\draw.rs:391\) for \View::Constant(address, size)\ entries inside descriptor tables (\draw.rs:2008\): - Previously, every \View::Constant\ in a descriptor table unconditionally allocated upload scratch memory (\list.scratch\) and pushed a \Step::Fill\ copy from title memory. - When a table CBV resides in a \Shadow\ buffer at a 256-byte-aligned host GPU address with \ligned_size\ in \1..=65536\ and fits within \shadow.left(address)\, this PR now binds \shadow.gpu(address)\ directly via \shadow.refresh(list, address, aligned_size)\ + \host.constant_at(index, shadow.gpu(address), size)\, falling back to the existing \list.scratch\ + \defer_fill\ path for unaligned or out-of-shadow views. - This avoids unnecessary per-draw upload-scratch allocations and CPU memcpys, and prevents 256-byte-aligned table CBVs that read GPU-written shadow buffers from triggering \WHY_READ\ (\ fill of upload memory\) submission stalls. ### RTX 3080 A/B Measurement (Windows 11, 10 GB) On our local RTX 3080 run (paired with #71 + #25, same switches): - \ itle memory read\ caused by \ fill of upload memory\ dropped from **\1.0\ → \
ericomeehan commented 2026-11-24 22:07:40 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by ericomeehan on 2026-11-24T22:01:30Z.


#104 and this PR change the same lines (the View::Constant arm of table binding in crates/victory-gpu/src/draw.rs, around line 2008), so whichever merges second needs a rebase. They also fit together:

  • On main, the table path makes a CBV of the guest's full size (constant_at rounds to 256 but does not cap). D3D12 allows at most 65536 bytes per CBV, and root_view already caps constant buffers at 1 << 16. #104 adds that cap to the table path.
  • Here, a constant buffer over 64 KiB takes the fallback, which is main's code unchanged, so it still gets the oversized view. With #104's cap the fallback is fine, and the direct path could clamp to 64 KiB, as root_view does, instead of refusing.
  • One difference from the scratch path: defer_fill copies into upload memory private to this list, while the shadow is shared with other lists. Both are brought up to date when the list is submitted. root_view already binds shadows this way, so this is consistent with it; the only new exposure is if another list refreshes the same range while this one is still in flight, which depends on the shadow's in-flight tracking.

Suggestion: merge #104 first, then rebase this onto it with aligned_size.min(65536).

I only read the code. I didn't build or run it.

Written with an AI assistant (Claude).

<!-- greyfinch-sync:fxceless/victory-fork:comment:7145700553 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/144#issuecomment-7145700553). Originally posted by [ericomeehan](https://github.com/ericomeehan) on 2026-11-24T22:01:30Z. --- #104 and this PR change the same lines (the `View::Constant` arm of table binding in `crates/victory-gpu/src/draw.rs`, around line 2008), so whichever merges second needs a rebase. They also fit together: - On `main`, the table path makes a CBV of the guest's full size (`constant_at` rounds to 256 but does not cap). D3D12 allows at most 65536 bytes per CBV, and `root_view` already caps constant buffers at `1 << 16`. #104 adds that cap to the table path. - Here, a constant buffer over 64 KiB takes the fallback, which is `main`'s code unchanged, so it still gets the oversized view. With #104's cap the fallback is fine, and the direct path could clamp to 64 KiB, as `root_view` does, instead of refusing. - One difference from the scratch path: `defer_fill` copies into upload memory private to this list, while the shadow is shared with other lists. Both are brought up to date when the list is submitted. `root_view` already binds shadows this way, so this is consistent with it; the only new exposure is if another list refreshes the same range while this one is still in flight, which depends on the shadow's in-flight tracking. Suggestion: merge #104 first, then rebase this onto it with `aligned_size.min(65536)`. I only read the code. I didn't build or run it. Written with an AI assistant (Claude).
Revens2 commented 2026-11-25 06:06:36 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by Revens2 on 2026-11-25T05:13:29Z.


Build check only: this PR merges cleanly on main c96b4f2 and the integration build of eight PRs (#115 #66 #36 #144 #147 #141 #139 #130) compiles (diagnostics profile). In the game, that combo was run alone 3 times (900 s, VICTORY_RELAY=2, scripted input): one run to the end (median 4.95 fps, about 4.9k draws per frame, against 4.84-5.04 fps on main), one title breakpoint 0x80000003 at about 157 s after a failed dstorage request (the pattern is explained on #115), one device removed (0x887A0005) at about 160 s that did not repeat in the two other runs. Nothing is proven for this PR alone: it was not run on its own, cargo test was not run on the combo, and nothing was checked on the title side of its change. Not verified.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7153564889 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/144#issuecomment-7153564889). Originally posted by [Revens2](https://github.com/Revens2) on 2026-11-25T05:13:29Z. --- Build check only: this PR merges cleanly on main c96b4f2 and the integration build of eight PRs (#115 #66 #36 #144 #147 #141 #139 #130) compiles (diagnostics profile). In the game, that combo was run alone 3 times (900 s, `VICTORY_RELAY=2`, scripted input): one run to the end (median 4.95 fps, about 4.9k draws per frame, against 4.84-5.04 fps on main), one title breakpoint `0x80000003` at about 157 s after a failed dstorage request (the pattern is explained on #115), one device removed (`0x887A0005`) at about 160 s that did not repeat in the two other runs. Nothing is proven for this PR alone: it was not run on its own, `cargo test` was not run on the combo, and nothing was checked on the title side of its change. Not verified.
ryotdev commented 2026-11-25 15:08:32 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by ryotdev on 2026-11-25T14:28:57Z.


I reviewed the direct CBV path at 1ac9b30. There is a dependency missing when a command list is cut. The first physical list records shadow.refresh(...) for the table CBV. After the cut, State::replay preserves the table cache, and a cache hit skips CBVs. The second physical list can therefore bind the cached GPU address without recording that shadow or its byte range among its own refresh dependencies. A title write to the constants between the two parts can go unseen by this binding. #742 discusses the related scratch-buffer lifetime case.

Could you retain the shadow and exact byte range for each directly bound CBV and request its refresh on cache hits, or evict CBV-bearing tables at the cut and rebuild them? A focused regression would bind the same table on both sides of a cut, change its constant bytes before the second submission, and check that the second draw sees the update.

One performance detail worth counting in the A/B is the number of new shadows created by the eligibility check. shadow::find can allocate on a miss, including a loose window for an unregistered range. The alignment check follows the lookup, so a binding can pay for that allocation and still fall back to scratch.

AI-assisted source review. I traced the paths on this PR head. My RTX 5070 timing runs used a separate diagnostics build, so I have no FPS claim for this PR.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7165346078 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/144#issuecomment-7165346078). Originally posted by [ryotdev](https://github.com/ryotdev) on 2026-11-25T14:28:57Z. --- I reviewed the direct CBV path at `1ac9b30`. There is a dependency missing when a command list is cut. The first physical list records `shadow.refresh(...)` for the table CBV. After the cut, `State::replay` preserves the table cache, and a cache hit skips CBVs. The second physical list can therefore bind the cached GPU address without recording that shadow or its byte range among its own refresh dependencies. A title write to the constants between the two parts can go unseen by this binding. #742 discusses the related scratch-buffer lifetime case. Could you retain the shadow and exact byte range for each directly bound CBV and request its refresh on cache hits, or evict CBV-bearing tables at the cut and rebuild them? A focused regression would bind the same table on both sides of a cut, change its constant bytes before the second submission, and check that the second draw sees the update. One performance detail worth counting in the A/B is the number of new shadows created by the eligibility check. `shadow::find` can allocate on a miss, including a loose window for an unregistered range. The alignment check follows the lookup, so a binding can pay for that allocation and still fall back to scratch. AI-assisted source review. I traced the paths on this PR head. My RTX 5070 timing runs used a separate diagnostics build, so I have no FPS claim for this PR.
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/144:upstream-pr/144'
git switch 'upstream-pr/144'

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