victory-gpu: implement ClearUnorderedAccessViewUint/Float and DiscardResource #948

Closed
github-bot wants to merge 2 commits from gh-pr/948/head into gh-pr/948/base
Owner

@⁠Sakura-Byte on GitHub · 2026-11-24 14:25 UTC · original
Sakura-Byte:pr/clear-uav-discard → main · +1362 −48 · 6 files · 2 commits · closed without merging

Summary

  • Implement ClearUnorderedAccessViewUint, ClearUnorderedAccessViewFloat, and DiscardResource across crates/victory-gpu/src/{descriptor.rs, descriptor/host.rs, draw.rs, host.rs, list.rs, texture.rs}.
  • Ensure proper host view resolution (including typed DXGI_FORMAT_R32_UINT / FLAG_NONE for 4-byte-aligned ClearUnorderedAccessViewUint, rejecting float clears on raw/structured views) and deferred texture::host_written tracking on submission.
  • Include synthetic GPU unit tests.

Verification

  • cargo xtask policy and cargo clippy --workspace --all-targets (--all-features) --locked -- -D warnings: clean
  • Verified on Windows 11 (NVIDIA GeForce RTX 5090 D & WARP)

AI-assisted; synthetic tests only, zero game assets.

**@⁠Sakura-Byte** on GitHub · 2026-11-24 14:25 UTC · [original](https://github.com/Marvisak/VIctory/pull/948) `Sakura-Byte:pr/clear-uav-discard` → `main` · +1362 −48 · 6 files · 2 commits · closed without merging ### Summary - Implement `ClearUnorderedAccessViewUint`, `ClearUnorderedAccessViewFloat`, and `DiscardResource` across `crates/victory-gpu/src/{descriptor.rs, descriptor/host.rs, draw.rs, host.rs, list.rs, texture.rs}`. - Ensure proper host view resolution (including typed `DXGI_FORMAT_R32_UINT` / `FLAG_NONE` for 4-byte-aligned `ClearUnorderedAccessViewUint`, rejecting float clears on raw/structured views) and deferred `texture::host_written` tracking on submission. - Include synthetic GPU unit tests. ### Verification - `cargo xtask policy` and `cargo clippy --workspace --all-targets (--all-features) --locked -- -D warnings`: clean - Verified on Windows 11 (NVIDIA GeForce RTX 5090 D & WARP) *AI-assisted; synthetic tests only, zero game assets.*
- Translate 4-byte-aligned raw and structured buffer views to typed DXGI_FORMAT_R32_UINT (D3D12_BUFFER_UAV_FLAG_NONE) for ClearKind::Uint so non-16-byte-aligned offsets clear cleanly.
- Reject ClearKind::Float on raw and structured buffer views.
- Defer texture::host_written via list.defer_host until submission so unsubmitted resets do not mark textures host-written.
- Add synthetic WARP unit tests for non-16B-aligned Uint clears, Float refusal on raw/structured views, and deferred host_written.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:14:43 +00:00
github-bot closed this pull request 2026-11-26 04:14:43 +00:00
Author
Owner

@⁠MartinIndra02 on GitHub · 2026-11-24 14:30 UTC · original

Nice clean implementation (and good addition of DiscardResource). Two D3D12 edge cases we hit under VICTORY_D3D12_DEBUG=1 on RTX 3080 when testing raw/structured buffer UAV clears:

  1. 16-byte alignment for D3D12_BUFFER_UAV_FLAG_RAW (R32_TYPELESS): resolve_buffer_uav checks byte_offset.is_multiple_of(4) and creates an R32_TYPELESS | D3D12_BUFFER_UAV_FLAG_RAW UAV with FirstElement = byte_offset / 4. In D3D12, FLAG_RAW requires FirstElement to be a multiple of 4 (16-byte aligned) — passing a 4-byte-aligned non-16-byte-aligned offset (e.g. FirstElement = 2, byte offset 8) triggers a D3D12 Debug Layer error and device removal. Reinterpreting raw/converted buffer views as typed DXGI_FORMAT_R32_UINT with D3D12_BUFFER_UAV_FLAG_NONE for ClearUnorderedAccessViewUint clears every dword identically at any 4-byte FirstElement with zero Debug Layer errors.
  2. ClearUnorderedAccessViewFloat on R32_TYPELESS | RAW: D3D12 forbids ClearUnorderedAccessViewFloat on R32_TYPELESS (raw) views; refusing float clears on raw/structured views (or reinterpreting as R32_FLOAT only if intended) avoids an invalid command.

Code review note; no game data. AI-assisted.

**@⁠MartinIndra02** on GitHub · 2026-11-24 14:30 UTC · [original](https://github.com/Marvisak/VIctory/pull/948#issuecomment-7134482872) Nice clean implementation (and good addition of `DiscardResource`). Two D3D12 edge cases we hit under `VICTORY_D3D12_DEBUG=1` on RTX 3080 when testing raw/structured buffer UAV clears: 1. **16-byte alignment for `D3D12_BUFFER_UAV_FLAG_RAW` (`R32_TYPELESS`):** `resolve_buffer_uav` checks `byte_offset.is_multiple_of(4)` and creates an `R32_TYPELESS | D3D12_BUFFER_UAV_FLAG_RAW` UAV with `FirstElement = byte_offset / 4`. In D3D12, `FLAG_RAW` requires `FirstElement` to be a multiple of 4 (16-byte aligned) — passing a 4-byte-aligned non-16-byte-aligned offset (e.g. `FirstElement = 2`, byte offset `8`) triggers a D3D12 Debug Layer error and device removal. Reinterpreting raw/converted buffer views as typed **`DXGI_FORMAT_R32_UINT`** with **`D3D12_BUFFER_UAV_FLAG_NONE`** for `ClearUnorderedAccessViewUint` clears every dword identically at any 4-byte `FirstElement` with zero Debug Layer errors. 2. **`ClearUnorderedAccessViewFloat` on `R32_TYPELESS | RAW`:** D3D12 forbids `ClearUnorderedAccessViewFloat` on `R32_TYPELESS` (raw) views; refusing float clears on raw/structured views (or reinterpreting as `R32_FLOAT` only if intended) avoids an invalid command. *Code review note; no game data. AI-assisted.*
Author
Owner

@⁠MichaelSmithAI on GitHub · 2026-11-24 14:40 UTC · original

The resource-backed texture path passed an isolated readback on 78f74a6 under Wine/vkd3d-proton 3.2 on an RTX 4090. Using the PR’s float-clear sequence on a 4×4 RGBA8 texture, we cleared the full texture red, then the center 2×2 green. After submission, all four inner texels were green and all twelve outer texels remained red.

Two integration details remain outside that test. In clear_uav, the texture branch calls host_written during recording. A list reset before submission therefore needs separate coverage for subsequent texture reads (see #758). The buffer branch requests refresh and writeback, but has no explicit transition of the shadow to UAV state before the clear. #785 also has same-list producer tracking for a later placed upload. This run exercised only the submitted texture clears.

**@⁠MichaelSmithAI** on GitHub · 2026-11-24 14:40 UTC · [original](https://github.com/Marvisak/VIctory/pull/948#issuecomment-7134752156) The resource-backed texture path passed an isolated readback on `78f74a6` under Wine/vkd3d-proton 3.2 on an RTX 4090. Using the PR’s float-clear sequence on a 4×4 RGBA8 texture, we cleared the full texture red, then the center 2×2 green. After submission, all four inner texels were green and all twelve outer texels remained red. Two integration details remain outside that test. In `clear_uav`, the texture branch calls `host_written` during recording. A list reset before submission therefore needs separate coverage for subsequent texture reads (see #758). The buffer branch requests refresh and writeback, but has no explicit transition of the shadow to UAV state before the clear. #785 also has same-list producer tracking for a later placed upload. This run exercised only the submitted texture clears.
Author
Owner

@⁠Sakura-Byte on GitHub · 2026-11-24 15:09 UTC · original

Thank you @⁠MartinIndra02 and @⁠MichaelSmithAI for the detailed review and hardware/Wine verification!

Addressed in commit 35802af69d54797159e785ecfa2e60817107d647 (35802af):

  1. 4-byte-aligned ClearUnorderedAccessViewUint via typed R32_UINT (FLAG_NONE) (crates/victory-gpu/src/descriptor/host.rs): resolve_buffer_uav now translates both raw (R32_TYPELESS / D3D12_BUFFER_UAV_FLAG_RAW) and structured buffer UAVs to DXGI_FORMAT_R32_UINT with D3D12_BUFFER_UAV_FLAG_NONE for ClearKind::Uint, avoiding the 16-byte FirstElement alignment requirement on raw UAVs.
  2. Refuse ClearUnorderedAccessViewFloat on raw/structured buffer views (crates/victory-gpu/src/descriptor/host.rs, crates/victory-gpu/src/list.rs): ClearKind::Float now returns None on raw or structured views instead of emitting an invalid clear.
  3. Defer texture::host_written until submission (crates/victory-gpu/src/list.rs): the texture branch now uses list.defer_host to call crate::texture::host_written, so resetting an unsubmitted command list does not mark the texture host-written.
  4. New synthetic WARP unit tests:
    • descriptor::host::tests::structured_uav_converts_to_raw_for_clear_when_4_byte_aligned (checks R32_UINT + D3D12_BUFFER_UAV_FLAG_NONE at non-16B-aligned offsets and ClearKind::Float refusal)
    • list::tests::uav_tests::clear_uav_uint_handles_non_16b_aligned_offsets_and_refuses_float_raw (end-to-end WARP clear/readback at non-16B-aligned raw and structured offsets, plus ignored float clears)
    • list::tests::uav_tests::clear_uav_defers_texture_host_written_until_submit (checks reset-without-submit leaves is_host_written false, and submit marks it true with expected texels)

Note on buffer UAV state tracking: Shadow buffer state tracking (buffer_state) is not on main yet (matching draw.rs, which calls shadow.refresh and shadow.gpu_writes), so clear_uav matches draw.rs on main.

Verified on WARP (VICTORY_D3D12_WARP=1, VICTORY_WARP=1): cargo xtask policy, cargo clippy --workspace --all-targets --locked -- -D warnings, cargo clippy --workspace --all-targets --all-features --locked -- -D warnings, and cargo test -p victory-gpu --features diagnostics --locked -- --test-threads=1 (58 passed, 0 failed, 1 benchmark ignored).

**@⁠Sakura-Byte** on GitHub · 2026-11-24 15:09 UTC · [original](https://github.com/Marvisak/VIctory/pull/948#issuecomment-7135549570) Thank you @⁠MartinIndra02 and @⁠MichaelSmithAI for the detailed review and hardware/Wine verification! Addressed in commit `35802af69d54797159e785ecfa2e60817107d647` (`35802af`): 1. **4-byte-aligned `ClearUnorderedAccessViewUint` via typed `R32_UINT` (`FLAG_NONE`)** (`crates/victory-gpu/src/descriptor/host.rs`): `resolve_buffer_uav` now translates both raw (`R32_TYPELESS` / `D3D12_BUFFER_UAV_FLAG_RAW`) and structured buffer UAVs to `DXGI_FORMAT_R32_UINT` with `D3D12_BUFFER_UAV_FLAG_NONE` for `ClearKind::Uint`, avoiding the 16-byte `FirstElement` alignment requirement on raw UAVs. 2. **Refuse `ClearUnorderedAccessViewFloat` on raw/structured buffer views** (`crates/victory-gpu/src/descriptor/host.rs`, `crates/victory-gpu/src/list.rs`): `ClearKind::Float` now returns `None` on raw or structured views instead of emitting an invalid clear. 3. **Defer `texture::host_written` until submission** (`crates/victory-gpu/src/list.rs`): the texture branch now uses `list.defer_host` to call `crate::texture::host_written`, so resetting an unsubmitted command list does not mark the texture host-written. 4. **New synthetic WARP unit tests**: - `descriptor::host::tests::structured_uav_converts_to_raw_for_clear_when_4_byte_aligned` (checks `R32_UINT` + `D3D12_BUFFER_UAV_FLAG_NONE` at non-16B-aligned offsets and `ClearKind::Float` refusal) - `list::tests::uav_tests::clear_uav_uint_handles_non_16b_aligned_offsets_and_refuses_float_raw` (end-to-end WARP clear/readback at non-16B-aligned raw and structured offsets, plus ignored float clears) - `list::tests::uav_tests::clear_uav_defers_texture_host_written_until_submit` (checks reset-without-submit leaves `is_host_written` false, and submit marks it true with expected texels) Note on buffer UAV state tracking: `Shadow` buffer state tracking (`buffer_state`) is not on `main` yet (matching `draw.rs`, which calls `shadow.refresh` and `shadow.gpu_writes`), so `clear_uav` matches `draw.rs` on `main`. Verified on WARP (`VICTORY_D3D12_WARP=1`, `VICTORY_WARP=1`): `cargo xtask policy`, `cargo clippy --workspace --all-targets --locked -- -D warnings`, `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`, and `cargo test -p victory-gpu --features diagnostics --locked -- --test-threads=1` (58 passed, 0 failed, 1 benchmark ignored).
Author
Owner

@⁠shortselow-byte on GitHub · 2026-11-24 15:24 UTC · original

Tested at head 35802af, merged locally onto current main (ffe310e, the branch is based on 8e79c80), on AMD, since the runs above are NVIDIA (native and vkd3d-proton): Windows 11, Rust 1.98.1 MSVC, AMD Radeon RX 6900 XT (RDNA2, driver 32.0.21045.16010).

  • All four clear_uav* tests pass on the AMD device (default adapter) and on WARP (--features diagnostics, VICTORY_D3D12_WARP=1), including the new clear_uav_uint_handles_non_16b_aligned_offsets_and_refuses_float_raw. A temporary print confirmed that test reached its last assertion on both, so the FirstElement = 2 / 3 raw-buffer clears through R32_UINT hit exactly their dwords and the device was not removed.
  • cargo test --locked -p victory-gpu --lib -- --test-threads=1: 55 passed on AMD, 58 on WARP with diagnostics. Whole workspace on the merged tree: 347 passed, 0 failed.
  • cargo clippy --workspace --all-targets --locked -- -D warnings, and with --all-features: clean.

Not covered: no D3D12 debug layer on this machine, and no in-title run.

**@⁠shortselow-byte** on GitHub · 2026-11-24 15:24 UTC · [original](https://github.com/Marvisak/VIctory/pull/948#issuecomment-7135981749) Tested at head `35802af`, merged locally onto current `main` (`ffe310e`, the branch is based on `8e79c80`), on AMD, since the runs above are NVIDIA (native and vkd3d-proton): Windows 11, Rust 1.98.1 MSVC, **AMD Radeon RX 6900 XT** (RDNA2, driver 32.0.21045.16010). - All four `clear_uav*` tests pass on the AMD device (default adapter) and on WARP (`--features diagnostics`, `VICTORY_D3D12_WARP=1`), including the new `clear_uav_uint_handles_non_16b_aligned_offsets_and_refuses_float_raw`. A temporary print confirmed that test reached its last assertion on both, so the `FirstElement = 2` / `3` raw-buffer clears through `R32_UINT` hit exactly their dwords and the device was not removed. - `cargo test --locked -p victory-gpu --lib -- --test-threads=1`: 55 passed on AMD, 58 on WARP with `diagnostics`. Whole workspace on the merged tree: 347 passed, 0 failed. - `cargo clippy --workspace --all-targets --locked -- -D warnings`, and with `--all-features`: clean. Not covered: no D3D12 debug layer on this machine, and no in-title run.
Author
Owner

@⁠Zipettte on GitHub · 2026-11-24 15:40 UTC · original

Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at 35802af: cargo test -p victory-gpu passes, 55 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed).

Tested with AI assistance (Claude).

**@⁠Zipettte** on GitHub · 2026-11-24 15:40 UTC · [original](https://github.com/Marvisak/VIctory/pull/948#issuecomment-7136427298) Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at 35802af: `cargo test -p victory-gpu` passes, 55 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed). _Tested with AI assistance (Claude)._
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 00:28 UTC · original

Automated triage for the maintainers. Closing because this change is already in main, or main has since replaced the code it patches.

ClearUnorderedAccessViewUint/Float is already served in main (list.rs slots 0x1a8/0x1b0 -> draw.rs State::clear_unordered); main ignores DiscardResource (0x1b8) on purpose. 1,362 lines against code that no longer exists.

If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

**@⁠Marvisak** on GitHub · 2026-11-25 00:28 UTC · [original](https://github.com/Marvisak/VIctory/pull/948#issuecomment-7148546711) Automated triage for the maintainers. Closing because this change is already in `main`, or `main` has since replaced the code it patches. ClearUnorderedAccessViewUint/Float is already served in main (list.rs slots 0x1a8/0x1b0 -> draw.rs State::clear_unordered); main ignores DiscardResource (0x1b8) on purpose. 1,362 lines against code that no longer exists. If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

Pull request closed

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!948
No description provided.