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

Open
github-bot wants to merge 1 commit from github-bot/gh-144 into main AGit
Owner

@⁠MartinIndra02 on GitHub · 2026-11-24 21:50 UTC · original
MartinIndra02:perf/fxceless-table-cbv-shadow → main · +24 −6 · 1 files · 1 commits · open

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\ → \
**@⁠MartinIndra02** on GitHub · 2026-11-24 21:50 UTC · [original](https://github.com/fxceless/victory-fork/pull/144) `MartinIndra02:perf/fxceless-table-cbv-shadow` → `main` · +24 −6 · 1 files · 1 commits · open ### 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\ → \
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:36:54 +00:00
Author
Owner

@⁠ericomeehan on GitHub · 2026-11-24 22:01 UTC · original

#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).

**@⁠ericomeehan** on GitHub · 2026-11-24 22:01 UTC · [original](https://github.com/fxceless/victory-fork/pull/144#issuecomment-7145700553) #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).
Author
Owner

@⁠Revens2 on GitHub · 2026-11-25 05:13 UTC · original

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.

**@⁠Revens2** on GitHub · 2026-11-25 05:13 UTC · [original](https://github.com/fxceless/victory-fork/pull/144#issuecomment-7153564889) 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.
Author
Owner

@⁠ryotdev on GitHub · 2026-11-25 14:28 UTC · original

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.

**@⁠ryotdev** on GitHub · 2026-11-25 14:28 UTC · [original](https://github.com/fxceless/victory-fork/pull/144#issuecomment-7165346078) 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 has changes conflicting with the target branch.
  • crates/victory-gpu/src/draw.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

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

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-144'
git switch 'github-bot/gh-144'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-144'
git switch 'github-bot/gh-144'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-144'
git switch 'main'
git merge --squash 'github-bot/gh-144'
git switch 'main'
git merge --ff-only 'github-bot/gh-144'
git switch 'main'
git merge 'github-bot/gh-144'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.