GPU: zero 256-byte CBV scratch padding and bind null CBVs for empty/invalid views #1629
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!1629
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1629/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@ESAT586 on GitHub · 2026-11-24 20:01 UTC · original
ESAT586:gpu/cbv-null-and-zero-padding→main· +442 −14 · 3 files · 1 commits · closed without mergingSummary
Fixes two constant-buffer upload/binding bugs in
victory-gpu(reported alongside world-frame testing in #1581, where zeroing CBV scratch padding produced a visible FPS increase on an RTX 4070):Zero
[size..padded)scratch padding for 256-byte-rounded CBVs (host.rs,draw.rs)HostList::scratch()rounds allocations up to 256 bytes and reuses upload chunks acrossHostList::reset().State::tables()(table CBVs) androot_view()(unaligned root CBVs) only filledsize/lenbytes withdefer_fill, leaving[size..padded)holding stale bytes from earlier draws or frames.D3D12_CONSTANT_BUFFER_VIEW_DESC::SizeInBytesup to a 256-byte multiple, shader loads pastsize(within the rounded 256-byte block) read stale scratch data instead of0as on console RDNA2 hardware.HostList::defer_fill_padded()(extendingStep::Fillwithpadded) so[len..padded)is zeroed immediately aftercopy_mappedat submission time, with zero overhead whenlenis already a 256-byte multiple.Bind a proper D3D12 null CBV for zero-address, zero-sized, overflowing, or OOM constant views (
draw.rs,descriptor/host.rs)View::Constant(0, 0)(andView::Constant(addr, 0)/View::Constant(0, size)) inState::tables()allocated 256 bytes of scratch and calledconstant_at(index, gpu, 0), producing an invalid D3D12 CBV with a non-nullBufferLocationandSizeInBytes = 0(and failingReadProcessMemoryonNULLfor(0, size)).list.scratch()failed,State::tables()also fell back tohost.make_null(index)(a 2D texture SRV null view) instead of a null CBV, risking AMD wild-address device removal (#59) and GBV descriptor-type mismatches.HostHeap::make_null_constant(index)(CreateConstantBufferView(None, at)), guardedState::tables()andHostHeap::constant_at()withaddress != 0 && size != 0andsize.checked_next_multiple_of(256)(avoidingu32::next_multiple_ofoverflow panics), and applied the same zero-size / overflow guard indescriptor::host::make().descriptor.rsuntouched (no conflict with #1298 / #1574) and leaves the empty-slotNone =>branch indraw.rsuntouched (no conflict with #581).Changes
crates/victory-gpu/src/host.rs: extendStep::Fillwithpaddedand addHostList::defer_fill_paddedto zero trailing padding bytes at submission time.crates/victory-gpu/src/descriptor/host.rs: addHostHeap::make_null_constant, hardenHostHeap::constant_atandmake()against null-address / zero-sized / overflowing CBVs, and addzero_sized_and_overflowing_cbvs_become_null_views.crates/victory-gpu/src/draw.rs: usedefer_fill_padded+make_null_constantinState::tablesanddefer_fill_paddedin unalignedroot_view, and add end-to-end GPU compute readback teststable_cbv_zeroes_scratch_padding_and_binds_null_cbvs_on_gpuandunaligned_root_cbv_zeroes_scratch_padding_on_gpu.Verification
All tests are synthetic clean-room tests (no game data):
cargo test -p victory-gpu --locked): 53 passed, 0 failed, 1 ignoredcargo test -p victory-gpu --all-features --locked): 56 passed, 0 failed, 1 ignoredVICTORY_D3D12_DEBUG=1 VICTORY_D3D12_GBV=1 cargo test -p victory-gpu --all-features --locked cbv): 3 passed, 0 failedVICTORY_D3D12_WARP=1 cargo test -p victory-gpu --all-features --locked cbv): 3 passed, 0 failedcargo clippy --workspace --all-targets --locked -- -D warnings, default &--all-features): 0 warningscargo xtask policy): 154 files okRefs #1581.
@Marvisak on GitHub · 2026-11-25 01:22 UTC · original
Automated triage for the maintainers. Closing because this change is already in
main, ormainhas since replaced the code it patches.Built on HostHeap::constant_at and per-draw CBV scratch copies in tables, both gone from main (constant buffers are raw views of the title's slots; empty views are nulled by in_buffer). The FPS claim for zeroed padding is not credible.
If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.
@Marvisak on GitHub · 2026-11-25 01:32 UTC · original
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). It will be reviewed once it is rebased onto the currentmain.Generated by Claude Code
Pull request closed