GPU: zero 256-byte CBV scratch padding and bind null CBVs for empty/invalid views #1628
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1629"
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?
Imported from Marvisak/VIctory. Originally posted by ESAT586 on 2026-11-24T20:01:39Z.
Summary
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.
Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T20:06:17Z.
Review: COMMENTED
Static review only: victory-gpu/victory-hle/apps are Windows-only (D3D12/windows_sys), so nothing here compiles or runs on macOS — please rely on the Windows CI leg.
CBV creation is hardened:
constant_atand the descriptormakepath now usechecked_next_multiple_of(256)(u32::MAX-sized CBVs no longer wrap to a small SizeInBytes), null/zero-sized buffers become real null CBVs (CreateConstantBufferView(None, ...)) that read zeros, and scratch padding is zeroed. The new test covers gpu+size=0, address=0 and the overflow case. This matches the D3D12 requirement that CBV SizeInBytes be a multiple of 256 and > 0 — the previoussize.next_multiple_of(256)could panic in debug or wrap in release on overflow. Windows-only; looks correct statically.Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T01:22:01Z.
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.
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T01:32:41Z.
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