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

Open
github-bot wants to merge 1 commit from github-bot/gh-3173 into main AGit
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 11:00 UTC · original
fuzeofficlal:fix/gpu-clear-uav-validation → main · +319 −0 · 2 files · 1 commits · open

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
**@⁠fuzeofficlal** on GitHub · 2026-11-26 11:00 UTC · [original](https://github.com/Marvisak/VIctory/pull/3173) `fuzeofficlal:fix/gpu-clear-uav-validation` → `main` · +319 −0 · 2 files · 1 commits · open ## 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`
State::clear_unordered forwarded any recorded View to host ClearUnorderedAccessViewUint and ClearUnorderedAccessViewFloat without checking that it is a clearable UAV. Passing an SRV/CBV descriptor caused a STATUS_ACCESS_VIOLATION crash on WARP and D3D12 debug error 646 (unmatched descriptors), and passing a structured buffer UAV (StructureByteStride > 0) triggered D3D12 debug error 1156 (ClearUnorderedAccessView* methods are not compatible with Structured Buffers).

Validate the recorded view via descriptor::host::is_clearable_uav before allocating a dynamic slot or recording GPU work, skipping non-UAV views, mismatched buffer/texture UAV dimensions, and structured buffer UAVs (both regular and placed). Valid raw, typed buffer, placed raw buffer, and texture UAV clears are unchanged.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 11:09:29 +00:00
Author
Owner

@⁠Dukestar69 on GitHub · 2026-11-26 11:06 UTC · original · approved these changes

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

**@⁠Dukestar69** on GitHub · 2026-11-26 11:06 UTC · [original](https://github.com/Marvisak/VIctory/pull/3173#pullrequestreview-6073045624) · **approved these changes** 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).
Author
Owner

@⁠oni-swr on GitHub · 2026-11-26 14:43 UTC · original

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

**@⁠oni-swr** on GitHub · 2026-11-26 14:43 UTC · [original](https://github.com/Marvisak/VIctory/pull/3173#issuecomment-7195238404) **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 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/3173/head:github-bot/gh-3173'
git switch 'github-bot/gh-3173'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-3173'
git switch 'github-bot/gh-3173'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-3173'
git switch 'github-bot/gh-3173'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-3173'
git switch 'main'
git merge --squash 'github-bot/gh-3173'
git switch 'main'
git merge --ff-only 'github-bot/gh-3173'
git switch 'main'
git merge 'github-bot/gh-3173'
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!3173
No description provided.