fix(gpu): add CBV guards and typed buffer view validation #3339

Open
legayclightning22 wants to merge 1 commit from upstream-pr/3339 into main
legayclightning22 commented 2026-11-26 19:03:50 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by legayclightning22 on 2026-11-26T19:03:50Z.


Summary

Adds CBV guards and typed buffer view validation in victory-gpu (414d469), along with unit tests covering buffer view validation.

Changes

  • Add CBV guard checks and typed buffer view validation in the descriptor/buffer view path.
  • Add unit tests verifying view validation and guard behavior.

Verification

  • cargo test -p victory-gpu --lib descriptor
  • cargo clippy --locked -p victory-gpu --all-targets -- -D warnings
  • cargo xtask policy
<!-- greyfinch-sync:Marvisak/VIctory:issue:5515706539 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3339). Originally posted by [legayclightning22](https://github.com/legayclightning22) on 2026-11-26T19:03:50Z. --- ## Summary Adds CBV guards and typed buffer view validation in `victory-gpu` (`414d469`), along with unit tests covering buffer view validation. ## Changes - Add CBV guard checks and typed buffer view validation in the descriptor/buffer view path. - Add unit tests verifying view validation and guard behavior. ## Verification - `cargo test -p victory-gpu --lib descriptor` - `cargo clippy --locked -p victory-gpu --all-targets -- -D warnings` - `cargo xtask policy` ```[cite: 20]
Dukestar69 commented 2026-11-26 19:08:06 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T19:08:06Z.

Review: APPROVED


LGTM — verified on RTX 5090 (Windows / D3D12) against origin/main (63bcca4).

  • Capping CBV sizes, clearing stale views on null CBVs, validating buffer view ranges before creation, and using bit-exact host formats for typed buffer views are cleanly scoped and well-tested.
  • cargo test -p victory-gpu --lib descriptor:: -- --skip dynamic_slots_are_held_until_released --test-threads=1: 24 passed, 0 failed (including cbv_sizes_are_capped_and_zero_sizes_use_the_zero_view, null_cbv_clears_a_stale_view, buffer_view_ranges_are_validated_before_creation, and typed_buffer_views_use_bit_exact_host_formats).
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6079329766 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3339#pullrequestreview-6079329766). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T19:08:06Z. **Review:** APPROVED --- LGTM — verified on RTX 5090 (Windows / D3D12) against `origin/main` (`63bcca4`). - Capping CBV sizes, clearing stale views on null CBVs, validating buffer view ranges before creation, and using bit-exact host formats for typed buffer views are cleanly scoped and well-tested. - `cargo test -p victory-gpu --lib descriptor:: -- --skip dynamic_slots_are_held_until_released --test-threads=1`: 24 passed, 0 failed (including `cbv_sizes_are_capped_and_zero_sizes_use_the_zero_view`, `null_cbv_clears_a_stale_view`, `buffer_view_ranges_are_validated_before_creation`, and `typed_buffer_views_use_bit_exact_host_formats`). - `cargo clippy -p victory-gpu --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
fuzeofficlal commented 2026-11-26 22:24:25 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T22:24:25Z.

Review: APPROVED


Looks good. The CBV size clamping and zero-CBV handling (crates/victory-gpu/src/descriptor.rs:575-595, crates/victory-gpu/src/descriptor/host.rs:1516-1538, 1792-1821), overflow-checked buffer_view_range (descriptor/host.rs:1293-1305), cached CPU-heap null buffer descriptor copies (descriptor/host.rs:1823-1886), and make_view null fallback (descriptor/host.rs:1502-1508) are all clean and well-structured.

Verified merged onto origin/main (63bcca43):

  • cargo xtask policy (191 files ok) and cargo clippy --locked -p victory-gpu --all-targets -- -D warnings (default and --features diagnostics) pass cleanly.
  • Under --features diagnostics with VICTORY_D3D12_DEBUG=1: descriptor:: passes 25/25 on WARP and 24/24 on RTX 5090 (skipping the 1M-heap-cap dynamic_slots_are_held_until_released); bindless:: (3/3) and draw:: (20/20) also pass on both RTX 5090 and WARP.
  • Tested buffer_view_format's 32-bit integer-to-float remapping live across three adapters — RTX 5090, AMD Radeon gfx1036 iGPU, and WARP — with D3D12 Debug Layer + GPU-Based Validation (VICTORY_D3D12_GBV=1):
    • Buffer<float4> -> RWBuffer<float4> preserves subnormal integer bit patterns (0x0000_0001, 0x0000_002A, 0x007F_FFFF), -0.0 (0x8000_0000), signaling NaN (0x7F80_0001), and 0xFFFF_FFFF bit-for-bit across all three adapters with 0 Debug Layer / GBV messages.
    • ClearUnorderedAccessViewUint, RWBuffer<uint> InterlockedAdd, and RWByteAddressBuffer InterlockedAdd on remapped R32_FLOAT / R32G32B32A32_FLOAT UAVs all produce exact results with 0 Debug Layer / GBV messages.
    • zero_constant, cached_null_buffer, and u64::MAX range overflow paths execute cleanly with 0 Debug Layer / GBV messages.

A few minor non-blocking follow-up notes:

  • buffer_view_format (descriptor/host.rs:1065) maps 7 | 8 (R32G32B32_UINT/SINT) to 6 (R32G32B32_FLOAT) for both SRVs and UAVs. While valid for SRVs, 96-bit formats cannot be used with typed UAVs (D3D12 reports an error and removes the device for both R32G32B32_UINT on main and R32G32B32_FLOAT here). Checking typed_store for typed buffer UAVs in buffer_uav — as fits already does for textures — would be a nice follow-up.
  • In buffer_view_range (descriptor/host.rs:1300), offset.is_multiple_of(element) && bytes.is_multiple_of(element) is always true after checked_mul and can be simplified.
  • Returning Some(Some((buffer.clone(), None))) from zero_constant (descriptor/host.rs:1820) causes describe_slot (diagnostics builds) to format zero CBVs as "Constant(0, 0)" rather than "null".
<!-- greyfinch-sync:Marvisak/VIctory:review:6081102067 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3339#pullrequestreview-6081102067). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T22:24:25Z. **Review:** APPROVED --- Looks good. The CBV size clamping and zero-CBV handling (`crates/victory-gpu/src/descriptor.rs:575-595`, `crates/victory-gpu/src/descriptor/host.rs:1516-1538`, `1792-1821`), overflow-checked `buffer_view_range` (`descriptor/host.rs:1293-1305`), cached CPU-heap null buffer descriptor copies (`descriptor/host.rs:1823-1886`), and `make_view` null fallback (`descriptor/host.rs:1502-1508`) are all clean and well-structured. Verified merged onto `origin/main` (`63bcca43`): - `cargo xtask policy` (191 files ok) and `cargo clippy --locked -p victory-gpu --all-targets -- -D warnings` (default and `--features diagnostics`) pass cleanly. - Under `--features diagnostics` with `VICTORY_D3D12_DEBUG=1`: `descriptor::` passes 25/25 on WARP and 24/24 on RTX 5090 (skipping the 1M-heap-cap `dynamic_slots_are_held_until_released`); `bindless::` (3/3) and `draw::` (20/20) also pass on both RTX 5090 and WARP. - Tested `buffer_view_format`'s 32-bit integer-to-float remapping live across three adapters — RTX 5090, AMD Radeon `gfx1036` iGPU, and WARP — with D3D12 Debug Layer + GPU-Based Validation (`VICTORY_D3D12_GBV=1`): - `Buffer<float4>` -> `RWBuffer<float4>` preserves subnormal integer bit patterns (`0x0000_0001`, `0x0000_002A`, `0x007F_FFFF`), `-0.0` (`0x8000_0000`), signaling NaN (`0x7F80_0001`), and `0xFFFF_FFFF` bit-for-bit across all three adapters with 0 Debug Layer / GBV messages. - `ClearUnorderedAccessViewUint`, `RWBuffer<uint>` `InterlockedAdd`, and `RWByteAddressBuffer` `InterlockedAdd` on remapped `R32_FLOAT` / `R32G32B32A32_FLOAT` UAVs all produce exact results with 0 Debug Layer / GBV messages. - `zero_constant`, `cached_null_buffer`, and `u64::MAX` range overflow paths execute cleanly with 0 Debug Layer / GBV messages. A few minor non-blocking follow-up notes: - `buffer_view_format` (`descriptor/host.rs:1065`) maps `7 | 8` (`R32G32B32_UINT/SINT`) to `6` (`R32G32B32_FLOAT`) for both SRVs and UAVs. While valid for SRVs, 96-bit formats cannot be used with typed UAVs (D3D12 reports an error and removes the device for both `R32G32B32_UINT` on `main` and `R32G32B32_FLOAT` here). Checking `typed_store` for typed buffer UAVs in `buffer_uav` — as `fits` already does for textures — would be a nice follow-up. - In `buffer_view_range` (`descriptor/host.rs:1300`), `offset.is_multiple_of(element) && bytes.is_multiple_of(element)` is always true after `checked_mul` and can be simplified. - Returning `Some(Some((buffer.clone(), None)))` from `zero_constant` (`descriptor/host.rs:1820`) causes `describe_slot` (diagnostics builds) to format zero CBVs as `"Constant(0, 0)"` rather than `"null"`.
Jackster commented 2026-11-26 22:48:36 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Jackster on 2026-11-26T22:48:36Z.


Windows 11, 63bcca4 + this PR, Radeon RX 7900 XTX:

  • cargo test -p victory-gpu --lib: 234 passed / 0 failed / 1 ignored (unpatched 63bcca4 here: 231; three new tests).
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.

The three new tests are cbv_sizes_are_capped_and_zero_sizes_use_the_zero_view, typed_buffer_views_use_bit_exact_host_formats and buffer_view_ranges_are_validated_before_creation, and all three pass on this card. Synthetic only. AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7205003831 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3339#issuecomment-7205003831). Originally posted by [Jackster](https://github.com/Jackster) on 2026-11-26T22:48:36Z. --- Windows 11, `63bcca4` + this PR, Radeon RX 7900 XTX: - `cargo test -p victory-gpu --lib`: **234 passed / 0 failed / 1 ignored** (unpatched `63bcca4` here: 231; three new tests). - `cargo clippy -p victory-gpu --all-targets -- -D warnings`: clean. The three new tests are `cbv_sizes_are_capped_and_zero_sizes_use_the_zero_view`, `typed_buffer_views_use_bit_exact_host_formats` and `buffer_view_ranges_are_validated_before_creation`, and all three pass on this card. Synthetic only. AI-assisted.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3339:upstream-pr/3339'
git switch 'upstream-pr/3339'

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.

git switch 'main'
git merge --no-ff 'upstream-pr/3339'
git switch 'upstream-pr/3339'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3339'
git switch 'upstream-pr/3339'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3339'
git switch 'main'
git merge --squash 'upstream-pr/3339'
git switch 'main'
git merge --ff-only 'upstream-pr/3339'
git switch 'main'
git merge 'upstream-pr/3339'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
Marvisak/VIctory!3339
No description provided.