victory-gpu: clamp constant buffer views to their registered buffer #1853
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1855"
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 mgunes1311-lab on 2026-11-24T23:29:38Z.
Summary
Since descriptor-table and heap
View::Constant(address, size)slots are backed in place by rawByteAddressBufferSRVs overShadowcopies, suballocated constant buffer descriptors that declare a 64 KiBSizeInBytesnear the end of a registered title buffer exposed four mismatches acrossvictory-gpu:descriptor::host::make):makecalledshadow::find(address, size)before clampingsizeto the registered buffer's remaining bytes. Wheneveraddress + sizeexceeded the buffer's end,shadow::findrejected the registered buffer and allocated a separate 4 MiBloosewindow for the host SRV whiledraw::readable(shadow::find(address, 1)) refreshed the registered buffer'sShadowcopy — leaving the SRV reading stale/zero bytes (missing both CPU writes and GPU UAV writes into the buffer's copy) and reading past the buffer's end instead of hardware bounds-checking to0.bindless::seen):bindless::seenlikewise looked upshadow::find(address, size)unclamped instead of resolving throughview_copy.view_addressesentries (descriptor::host::buffer_range):buffer_rangereturnedNoneforView::Constant, sowrite_address(HostHeap::view_addresses/note_address) wrote[0, 0]instead of the 48-bit title GPU address for constant buffer slots (anddescribe_slotomitted their address range).View::Constant(0, size)): Previously allocated a 4 MiBloosewindow at virtual address0x0instead of falling back tonull_buffer_view.Changes
crates/victory-gpu/src/shadow.rs: Addregistered_left(address)returning the remaining bytes in the innermost registered title buffer containingaddress(Nonefor loose memory).crates/victory-gpu/src/descriptor/host.rs: HandleView::Constantinbuffer_range(returningNoneat address0, clamping toregistered_left(address)when inside a registered buffer while leaving loose-memory constant views unclamped, and rounding down to whole dwords), resolveView::Constantinview_copyviashadow::for_view(..., 4), and build the raw SRV inmakefrombuffer_range(falling back tonull_buffer_viewwhen null or empty).crates/victory-gpu/src/bindless.rs&crates/victory-gpu/src/draw.rs: Route constant buffer view tracking and refreshes throughbuffer_rangeandview_copydirectly.descriptor::host::tests::constant_views_clamp_to_their_buffer_and_record_their_addressbindless::tests::overlong_constant_views_read_their_buffers_copy(multi-round D3D12 compute dispatch test coveringdefer_heap,view_copyrefresh, hardware out-of-bounds0reads past the clamped buffer end, and GPU UAV writes into the buffer's copy).Verification
cargo clippy --workspace --all-targets --target x86_64-pc-windows-msvc --locked -- -D warnings(default and--all-features)RUSTDOCFLAGS="-D warnings -A rustdoc::private-intra-doc-links" cargo doc --workspace --no-deps --target x86_64-pc-windows-msvc --lockedVICTORY_D3D12_DEBUG=1 cargo test -p victory-gpu --all-features --target x86_64-pc-windows-msvc --lockedcargo run -p xtask --target x86_64-pc-windows-msvc --locked -- policy --staged&cargo test -p xtask --target x86_64-pc-windows-msvc --lockedImported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T23:47:42Z.
Review: COMMENTED
Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; source review of the diff.
Constant buffer views clamped to their registered buffer range: bounds fix in CBV creation — pairs with #1629's padding work; check overlap.
Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-24T23:39:03Z.
Independent WARP check at base
70564ae08cand headdca80ab6e0.I ran the GPU-write portion of the same fixture on both revisions, skipping the earlier host-side range assertions so the baseline reached the dispatch. With a 64 KiB CBV at offset 0xfc00, the base read the stale CPU value 0x00004000 at dword 0 after a UAV write of 0xdead0000. The head read back the expected 63 in-range words from that GPU write and zero out of range.
The unmodified PR head also passed both of its CBV regressions and the full victory-gpu suite on WARP (83 passed, 1 ignored).
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T07:25:51Z.
Automated triage for the maintainers.
Needs rebase.
mainhas moved since the last triage, and this PR no longer merges cleanly into it (conflicts incrates/victory-gpu/src/descriptor/host.rsandcrates/victory-gpu/src/draw.rs). It will be reviewed again once it is rebased onto currentmain. The second-look comment above names the two test updates the rebase needs (theranges()tuple and the 16-byte view-address slots).Previous verdict for this head: merge candidate.
Generated by Claude Code
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T22:02:27Z.
Automated triage for the maintainers, second look (a review against
main, with the PR built and tested).The mismatch is real (an overlong constant buffer view is made over one copy and read as another) and the fix is consistent. This can be merged once its tests are brought up to
main, where they no longer compile. Incrates/victory-gpu/src/bindless.rs,overlong_constant_views_read_their_buffers_copyshould destructure the items ofheap_host.viewed.ranges()as(s, a, len, uav, _). Incrates/victory-gpu/src/descriptor/host.rs,constant_views_clamp_to_their_buffer_and_record_their_addressshould read the view-address entry atdata + 16 * slot(mainwrites 16 bytes per slot now). With those two changes the tests pass. It also conflicts withmainindescriptor/host.rsanddraw.rsafter today's merges, so it needs a rebase.Push the change and it will be reviewed again. Thank you for the contribution.
Imported from Marvisak/VIctory. Originally posted by mgunes1311-lab on 2026-11-26T17:13:54Z.
Merged
main(63bcca4) following the rebase notes above:draw.rs: preservedlen > 0andpage_range(address, len as usize)withdescriptor::view_copy(view)so zero-length clamped constant views skip page-range updates while valid clamped views reuse their registered buffer copy.descriptor/host.rs&bindless.rs: updatedconstant_views_clamp_to_their_buffer_and_record_their_addressfor 16-byte heap-keyed view-address entries and 5-tupleViewed::ranges().Verified
constant_views_clamp_to_their_buffer_and_record_their_address,overlong_constant_views_read_their_buffers_copy,view_addresses_cover_tables_made_afresh,clippy, andxtask policyon Windows 11 (x86_64-pc-windows-msvc).View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.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.