Skip to content

victory-gpu: clamp constant buffer views to their registered buffer - #1855

Open
mgunes1311-lab wants to merge 5 commits into
Marvisak:mainfrom
mgunes1311-lab:gpu-constant-view-copies
Open

mgunes1311-lab wants to merge 5 commits into
Marvisak:mainfrom
mgunes1311-lab:gpu-constant-view-copies

Conversation

@mgunes1311-lab

Copy link
Copy Markdown
Contributor

Summary

Since descriptor-table and heap View::Constant(address, size) slots are backed in place by raw ByteAddressBuffer SRVs over Shadow copies, suballocated constant buffer descriptors that declare a 64 KiB SizeInBytes near the end of a registered title buffer exposed four mismatches across victory-gpu:

  1. Split host copies on overlong constant views (descriptor::host::make): make called shadow::find(address, size) before clamping size to the registered buffer's remaining bytes. Whenever address + size exceeded the buffer's end, shadow::find rejected the registered buffer and allocated a separate 4 MiB loose window for the host SRV while draw::readable (shadow::find(address, 1)) refreshed the registered buffer's Shadow copy — 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 to 0.
  2. Heap-indexed refresh mismatch (bindless::seen): bindless::seen likewise looked up shadow::find(address, size) unclamped instead of resolving through view_copy.
  3. Zeroed view_addresses entries (descriptor::host::buffer_range): buffer_range returned None for View::Constant, so write_address (HostHeap::view_addresses / note_address) wrote [0, 0] instead of the 48-bit title GPU address for constant buffer slots (and describe_slot omitted their address range).
  4. Null-address constant views (View::Constant(0, size)): Previously allocated a 4 MiB loose window at virtual address 0x0 instead of falling back to null_buffer_view.

Changes

  • crates/victory-gpu/src/shadow.rs: Add registered_left(address) returning the remaining bytes in the innermost registered title buffer containing address (None for loose memory).
  • crates/victory-gpu/src/descriptor/host.rs: Handle View::Constant in buffer_range (returning None at address 0, clamping to registered_left(address) when inside a registered buffer while leaving loose-memory constant views unclamped, and rounding down to whole dwords), resolve View::Constant in view_copy via shadow::for_view(..., 4), and build the raw SRV in make from buffer_range (falling back to null_buffer_view when null or empty).
  • crates/victory-gpu/src/bindless.rs & crates/victory-gpu/src/draw.rs: Route constant buffer view tracking and refreshes through buffer_range and view_copy directly.
  • Tests:
    • descriptor::host::tests::constant_views_clamp_to_their_buffer_and_record_their_address
    • bindless::tests::overlong_constant_views_read_their_buffers_copy (multi-round D3D12 compute dispatch test covering defer_heap, view_copy refresh, hardware out-of-bounds 0 reads 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 --locked
  • VICTORY_D3D12_DEBUG=1 cargo test -p victory-gpu --all-features --target x86_64-pc-windows-msvc --locked
  • cargo run -p xtask --target x86_64-pc-windows-msvc --locked -- policy --staged & cargo test -p xtask --target x86_64-pc-windows-msvc --locked

@andrewpozdnakov7-jpg

Copy link
Copy Markdown
Contributor

Independent WARP check at base 70564ae and head dca80ab.

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

@catminou4 catminou4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Marvisak commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Needs rebase. main has moved since the last triage, and this PR no longer merges cleanly into it (conflicts in crates/victory-gpu/src/descriptor/host.rs and crates/victory-gpu/src/draw.rs). It will be reviewed again once it is rebased onto current main. The second-look comment above names the two test updates the rebase needs (the ranges() tuple and the 16-byte view-address slots).

Previous verdict for this head: merge candidate.


Generated by Claude Code

@Marvisak

Copy link
Copy Markdown
Owner

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. In crates/victory-gpu/src/bindless.rs, overlong_constant_views_read_their_buffers_copy should destructure the items of heap_host.viewed.ranges() as (s, a, len, uav, _). In crates/victory-gpu/src/descriptor/host.rs, constant_views_clamp_to_their_buffer_and_record_their_address should read the view-address entry at data + 16 * slot (main writes 16 bytes per slot now). With those two changes the tests pass. It also conflicts with main in descriptor/host.rs and draw.rs after today's merges, so it needs a rebase.

Push the change and it will be reviewed again. Thank you for the contribution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants