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

Closed
Sakura-Byte wants to merge 2 commits from upstream-pr/948 into main
Sakura-Byte commented 2026-11-24 14:25:44 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Sakura-Byte on 2026-11-24T14:25:44Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6584002132 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/948). Originally posted by [Sakura-Byte](https://github.com/Sakura-Byte) on 2026-11-24T14:25:44Z. --- ### 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.*
MartinIndra02 commented 2026-11-24 15:04:05 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by MartinIndra02 on 2026-11-24T14:30:18Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7134482872 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/948#issuecomment-7134482872). Originally posted by [MartinIndra02](https://github.com/MartinIndra02) on 2026-11-24T14:30:18Z. --- 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.*
MichaelSmithAI commented 2026-11-24 15:04:09 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by MichaelSmithAI on 2026-11-24T14:40:08Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7134752156 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/948#issuecomment-7134752156). Originally posted by [MichaelSmithAI](https://github.com/MichaelSmithAI) on 2026-11-24T14:40:08Z. --- 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.
Sakura-Byte commented 2026-11-24 16:05:03 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Sakura-Byte on 2026-11-24T15:09:23Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7135549570 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/948#issuecomment-7135549570). Originally posted by [Sakura-Byte](https://github.com/Sakura-Byte) on 2026-11-24T15:09:23Z. --- 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).
shortselow-byte commented 2026-11-24 16:05:11 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by shortselow-byte on 2026-11-24T15:24:45Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7135981749 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/948#issuecomment-7135981749). Originally posted by [shortselow-byte](https://github.com/shortselow-byte) on 2026-11-24T15:24:45Z. --- 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.
Zipettte commented 2026-11-24 16:05:18 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Zipettte on 2026-11-24T15:40:39Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7136427298 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/948#issuecomment-7136427298). Originally posted by [Zipettte](https://github.com/Zipettte) on 2026-11-24T15:40:39Z. --- 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)._
upstream-sync closed this pull request 2026-11-25 01:04:59 +00:00
Marvisak commented 2026-11-25 01:07:52 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T00:28:29Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7148546711 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/948#issuecomment-7148546711). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T00:28:29Z. --- 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

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