GPU: reject non-UAV and structured buffer views in ClearUnorderedAccessView #3171

Open
fuzeofficlal wants to merge 1 commit from upstream-pr/3173 into main
fuzeofficlal commented 2026-11-26 11:00:34 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T11:00:34Z.


Summary

State::clear_unordered forwarded any View recorded at the CPU descriptor handle directly to ClearUnorderedAccessViewUint / ClearUnorderedAccessViewFloat without validating that it is a clearable UAV:

  1. Non-UAV descriptors (View::Shader, View::Constant, View::Sampler, View::ConsoleSampler, View::Placed(false, ..)): make_at / make_view construct SRV descriptors instead of UAVs and pass them to ClearUnorderedAccessView*, crashing WARP with STATUS_ACCESS_VIOLATION (0xc0000005) on a buffer SRV and triggering D3D12 debug layer error 646 (The CPU and GPU descriptor handles refer to unmatched descriptors) on a CBV.
  2. Structured buffer UAVs (StructureByteStride > 0, regular or placed): D3D12 forbids clearing structured buffers with either ClearUnorderedAccessViewUint or ClearUnorderedAccessViewFloat, emitting D3D12 debug layer error 1156 (ClearUnorderedAccessView* methods are not compatible with Structured Buffers).
  3. Invalid calls also allocated dynamic heap slots and deferred unnecessary refresh/writeback work.

Fix

  • Add descriptor::host::is_clearable_uav(view: &View) -> bool in crates/victory-gpu/src/descriptor/host.rs:
    • Accepts only View::Unordered and View::Placed(true, ..).
    • For buffer UAVs (regular and placed), requires a buffer view description with ViewDimension == D3D12_UAV_DIMENSION_BUFFER and StructureByteStride == 0.
    • For texture UAVs (regular and placed), rejects descriptions with D3D12_UAV_DIMENSION_BUFFER.
  • Guard State::clear_unordered in crates/victory-gpu/src/draw.rs with is_clearable_uav(&view) before allocating a dynamic slot or recording GPU work. All valid raw, typed buffer, placed raw buffer, and texture UAV clears continue to run unchanged.

Verification

Added unit and real D3D12 GPU/WARP regression tests:

  • descriptor::host::tests::clearable_uav_rejects_non_uavs_and_structured_buffers: unit-tests all View variants and buffer/texture dimension combinations.
  • draw::tests::clear_unordered_skips_invalid_views_and_clears_valid_ones: verifies that non-UAV views (buffer SRV, texture SRV, CBV, placed buffer SRV) and structured buffer UAVs (regular and placed, both Uint and Float) allocate no dynamic slots, record no GPU work, and emit zero D3D12 debug errors, while valid raw buffer, typed uint/float buffer, placed raw buffer, and texture UAV clears execute on the GPU and write expected values back to title memory. Confirmed the test crashes WARP (0xc0000005) and triggers D3D12 debug errors 646 and 1156 on main, and passes cleanly after the fix.

Ran:

  • cargo test -p victory-gpu --lib --locked -- --test-threads=1 (RTX 5090 default, RTX 5090 --features diagnostics + VICTORY_D3D12_DEBUG=1, and VICTORY_D3D12_WARP=1 + --features diagnostics + VICTORY_D3D12_DEBUG=1)
  • cargo clippy --workspace --all-targets --locked -- -D warnings (default and --all-features)
  • cargo test -p xtask --locked policy::tests::repository_passes_policy
<!-- greyfinch-sync:Marvisak/VIctory:issue:6625190951 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3173). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T11:00:34Z. --- ## Summary `State::clear_unordered` forwarded any `View` recorded at the CPU descriptor handle directly to `ClearUnorderedAccessViewUint` / `ClearUnorderedAccessViewFloat` without validating that it is a clearable UAV: 1. **Non-UAV descriptors (`View::Shader`, `View::Constant`, `View::Sampler`, `View::ConsoleSampler`, `View::Placed(false, ..)`)**: `make_at` / `make_view` construct SRV descriptors instead of UAVs and pass them to `ClearUnorderedAccessView*`, crashing WARP with `STATUS_ACCESS_VIOLATION (0xc0000005)` on a buffer SRV and triggering D3D12 debug layer error 646 (`The CPU and GPU descriptor handles refer to unmatched descriptors`) on a CBV. 2. **Structured buffer UAVs (`StructureByteStride > 0`, regular or placed)**: D3D12 forbids clearing structured buffers with either `ClearUnorderedAccessViewUint` or `ClearUnorderedAccessViewFloat`, emitting D3D12 debug layer error 1156 (`ClearUnorderedAccessView* methods are not compatible with Structured Buffers`). 3. Invalid calls also allocated dynamic heap slots and deferred unnecessary refresh/writeback work. ## Fix - Add `descriptor::host::is_clearable_uav(view: &View) -> bool` in `crates/victory-gpu/src/descriptor/host.rs`: - Accepts only `View::Unordered` and `View::Placed(true, ..)`. - For buffer UAVs (regular and placed), requires a buffer view description with `ViewDimension == D3D12_UAV_DIMENSION_BUFFER` and `StructureByteStride == 0`. - For texture UAVs (regular and placed), rejects descriptions with `D3D12_UAV_DIMENSION_BUFFER`. - Guard `State::clear_unordered` in `crates/victory-gpu/src/draw.rs` with `is_clearable_uav(&view)` before allocating a dynamic slot or recording GPU work. All valid raw, typed buffer, placed raw buffer, and texture UAV clears continue to run unchanged. ## Verification Added unit and real D3D12 GPU/WARP regression tests: - `descriptor::host::tests::clearable_uav_rejects_non_uavs_and_structured_buffers`: unit-tests all `View` variants and buffer/texture dimension combinations. - `draw::tests::clear_unordered_skips_invalid_views_and_clears_valid_ones`: verifies that non-UAV views (buffer SRV, texture SRV, CBV, placed buffer SRV) and structured buffer UAVs (regular and placed, both `Uint` and `Float`) allocate no dynamic slots, record no GPU work, and emit zero D3D12 debug errors, while valid raw buffer, typed uint/float buffer, placed raw buffer, and texture UAV clears execute on the GPU and write expected values back to title memory. Confirmed the test crashes WARP (`0xc0000005`) and triggers D3D12 debug errors 646 and 1156 on `main`, and passes cleanly after the fix. Ran: - `cargo test -p victory-gpu --lib --locked -- --test-threads=1` (RTX 5090 default, RTX 5090 `--features diagnostics` + `VICTORY_D3D12_DEBUG=1`, and `VICTORY_D3D12_WARP=1` + `--features diagnostics` + `VICTORY_D3D12_DEBUG=1`) - `cargo clippy --workspace --all-targets --locked -- -D warnings` (default and `--all-features`) - `cargo test -p xtask --locked policy::tests::repository_passes_policy`
Dukestar69 commented 2026-11-26 12:05:44 +00:00 (Migrated from github.com)

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

Review: APPROVED


Verified on RTX 5090 & WARP against origin/main (63bcca4):

  • cargo test -p victory-gpu --lib draw:: -- --test-threads=1: 21/21 passed on RTX 5090 and WARP (including clear_unordered_skips_invalid_views_and_clears_valid_ones).
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Cleanly rejects non-UAV and structured buffer views in ClearUnorderedAccessView while clearing valid views normally.

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

<!-- greyfinch-sync:Marvisak/VIctory:review:6073045624 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3173#pullrequestreview-6073045624). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T11:06:58Z. **Review:** APPROVED --- Verified on RTX 5090 & WARP against `origin/main` (`63bcca4`): - `cargo test -p victory-gpu --lib draw:: -- --test-threads=1`: 21/21 passed on RTX 5090 and WARP (including `clear_unordered_skips_invalid_views_and_clears_valid_ones`). - `cargo clippy -p victory-gpu --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Cleanly rejects non-UAV and structured buffer views in `ClearUnorderedAccessView` while clearing valid views normally. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
oni-swr commented 2026-11-26 15:02:34 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by oni-swr on 2026-11-26T14:43:49Z.


WARP verification of head a9aa5353 (base = current main 63bcca4).

Setup: Windows 11, VICTORY_WARP=1 + VICTORY_D3D12_WARP=1, --features diagnostics (software adapter only, no physical GPU), Windows SDK dxil.dll, synthetic tests only.

  • cargo test -p victory-gpu --lib: 248 passed, 0 failed, 1 ignored
  • New tests descriptor::host::tests::clearable_uav_rejects_non_uavs_and_structured_buffers and draw::tests::clear_unordered_skips_invalid_views_and_clears_valid_ones: both pass
  • Control (main + only the draw.rs test, no fix): clear_unordered_skips_invalid_views_and_clears_valid_ones fails. The descriptor/host.rs test calls the new is_clearable_uav, so it cannot be built on main without the fix.

Verified with Claude Code (Claude Sonnet 5.5).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7195238404 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3173#issuecomment-7195238404). Originally posted by [oni-swr](https://github.com/oni-swr) on 2026-11-26T14:43:49Z. --- **WARP verification** of head `a9aa5353` (base = current main `63bcca4`). Setup: Windows 11, `VICTORY_WARP=1` + `VICTORY_D3D12_WARP=1`, `--features diagnostics` (software adapter only, no physical GPU), Windows SDK `dxil.dll`, synthetic tests only. - `cargo test -p victory-gpu --lib`: **248 passed, 0 failed, 1 ignored** - New tests `descriptor::host::tests::clearable_uav_rejects_non_uavs_and_structured_buffers` and `draw::tests::clear_unordered_skips_invalid_views_and_clears_valid_ones`: **both pass** - Control (main + only the `draw.rs` test, no fix): `clear_unordered_skips_invalid_views_and_clears_valid_ones` **fails**. The `descriptor/host.rs` test calls the new `is_clearable_uav`, so it cannot be built on main without the fix. Verified with Claude Code (Claude Sonnet 5.5).
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/3173:upstream-pr/3173'
git switch 'upstream-pr/3173'

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/3173'
git switch 'upstream-pr/3173'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3173'
git switch 'upstream-pr/3173'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3173'
git switch 'main'
git merge --squash 'upstream-pr/3173'
git switch 'main'
git merge --ff-only 'upstream-pr/3173'
git switch 'main'
git merge 'upstream-pr/3173'
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!3171
No description provided.