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

Open
github-bot wants to merge 8 commits from github-bot/gh-1855 into main AGit
Owner

@⁠mgunes1311-lab on GitHub · 2026-11-24 23:29 UTC · original
mgunes1311-lab:gpu-constant-view-copies → main · +367 −31 · 4 files · 8 commits · open

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
**@⁠mgunes1311-lab** on GitHub · 2026-11-24 23:29 UTC · [original](https://github.com/Marvisak/VIctory/pull/1855) `mgunes1311-lab:gpu-constant-view-copies` → `main` · +367 −31 · 4 files · 8 commits · open ## 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`
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:46:39 +00:00
Author
Owner

@⁠andrewpozdnakov7-jpg on GitHub · 2026-11-24 23:39 UTC · original

Independent WARP check at base 70564ae08c and head dca80ab6e0.

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

**@⁠andrewpozdnakov7-jpg** on GitHub · 2026-11-24 23:39 UTC · [original](https://github.com/Marvisak/VIctory/pull/1855#issuecomment-7147641773) Independent WARP check at base 70564ae08c82d43df5fad97b08d34628b07b1d9d and head dca80ab6e028c84cf61e9f0f83cd4121259272d3. 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).
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 07:25 UTC · original · edited 2026-11-25 22:22 UTC

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** on GitHub · 2026-11-25 07:25 UTC · [original](https://github.com/Marvisak/VIctory/pull/1855#issuecomment-7155851131) · edited 2026-11-25 22:22 UTC <!-- victory-triage v1 head=20811d920d9916b11b902bf4b7fc3b35a9b2eadf verdict=needs-rebase at=2026-11-25T22:23:00Z --> 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](https://claude.ai/code)_
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 22:02 UTC · original

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.

**@⁠Marvisak** on GitHub · 2026-11-25 22:02 UTC · [original](https://github.com/Marvisak/VIctory/pull/1855#issuecomment-7175858968) 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.
Author
Owner

@⁠catminou4 on GitHub · 2026-11-24 23:47 UTC · original · reviewed

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.

**@⁠catminou4** on GitHub · 2026-11-24 23:47 UTC · [original](https://github.com/Marvisak/VIctory/pull/1855#pullrequestreview-6049282684) · **reviewed** 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.
Author
Owner

@⁠mgunes1311-lab on GitHub · 2026-11-26 17:13 UTC · original

Merged main (63bcca4) following the rebase notes above:

  • draw.rs: preserved len > 0 and page_range(address, len as usize) with descriptor::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: updated constant_views_clamp_to_their_buffer_and_record_their_address for 16-byte heap-keyed view-address entries and 5-tuple Viewed::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, and xtask policy on Windows 11 (x86_64-pc-windows-msvc).

**@⁠mgunes1311-lab** on GitHub · 2026-11-26 17:13 UTC · [original](https://github.com/Marvisak/VIctory/pull/1855#issuecomment-7198687267) Merged `main` (`63bcca4`) following the rebase notes above: - `draw.rs`: preserved `len > 0` and `page_range(address, len as usize)` with `descriptor::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`: updated `constant_views_clamp_to_their_buffer_and_record_their_address` for 16-byte heap-keyed view-address entries and 5-tuple `Viewed::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`, and `xtask policy` on Windows 11 (`x86_64-pc-windows-msvc`).
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

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

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1855'
git switch 'github-bot/gh-1855'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1855'
git switch 'github-bot/gh-1855'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1855'
git switch 'main'
git merge --squash 'github-bot/gh-1855'
git switch 'main'
git merge --ff-only 'github-bot/gh-1855'
git switch 'main'
git merge 'github-bot/gh-1855'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!1855
No description provided.