Skip to content

GPU: drop unsupported UAV/RT flags on typed host textures and guard RTV creation - #1040

Closed
gabrielcruzg3 wants to merge 3 commits into
Marvisak:mainfrom
gabrielcruzg3:fix/host-texture-uav-support
Closed

gabrielcruzg3 wants to merge 3 commits into
Marvisak:mainfrom
gabrielcruzg3:fix/host-texture-uav-support

Conversation

@gabrielcruzg3

Copy link
Copy Markdown

Addresses #264 (Finding #4) and related D3D12 validation errors on formats that PC GPUs do not support as typed UAVs or render targets (such as B5G5R5A1_UNORM and B4G4R4A4_UNORM).

Changes

  • \crates/victory-gpu/src/resource.rs: Query \D3D12_FEATURE_FORMAT_SUPPORT\ for non-typeless host textures and drop \ALLOW_UNORDERED_ACCESS\ / \ALLOW_RENDER_TARGET\ when unsupported (preserving UAV on typeless formats). Omit \pOptimizedClearValue\ when neither render-target nor depth-stencil flags remain (avoids D3D12 id=815).
  • \crates/victory-gpu/src/host.rs, \draw.rs, \list.rs: Return \Option<D3D12_CPU_DESCRIPTOR_HANDLE>\ from \Host::rtv()\ and skip RTV creation when the host resource lacks \ALLOW_RENDER_TARGET\ (avoids id=36 / id=42 / \DXGI_ERROR_INVALID_CALL).

Verification

  • Added synthetic GPU test \host_texture_drops_unsupported_uav_flag_for_b5g5r5a1\ covering \B5G5R5A1_UNORM, \B4G4R4A4_UNORM\ with clear value, and \R8G8B8A8_TYPELESS.
  • Passed \cargo clippy -- -D warnings, \cargo test -p victory-gpu, and \cargo xtask policy.

@shortselow-byte

Copy link
Copy Markdown

This PR has no CI run yet, so I ran the CI's checks at head 08e4c89: Windows 11, Rust 1.98.1 MSVC, AMD Radeon RX 6900 XT (RDNA2). The new test fails on AMD and on WARP, so it would fail CI too.

  • host_texture_drops_unsupported_uav_flag_for_b5g5r5a1 fails at resource.rs:1904: the B5G5R5A1_UNORM texture keeps ALLOW_UNORDERED_ACCESS. Same failure on WARP (--features diagnostics, VICTORY_D3D12_WARP=1).
  • The code is doing the right thing: a temporary D3D12_FEATURE_FORMAT_SUPPORT query on both devices gives TYPED_UNORDERED_ACCESS_VIEW and RENDER_TARGET for both B5G5R5A1_UNORM (86) and B4G4R4A4_UNORM (115). So nothing is dropped there, as intended. The test hard-codes one driver's answer.
  • Suggestion: have the test query the format support and assert against it, or use a format no device allows as a typed UAV or render target.

Other checks:

  • The branch is based on d2a4bae, and cargo clippy -- -D warnings fails on that base (in victory-hle and victory-gpu code that isn't from this PR). Merged locally onto main ffe310e, both clippy runs (default and --all-features) are clean. The workspace tests still stop at the failing test above.
  • cargo xtask policy: ok.

@NuraadGit

Copy link
Copy Markdown
Contributor

This is the same problem as #55 and #89. Two things from an RTX 2080 (native Windows, driver 616.56) that apply to this version:

1. The continue in set_targets moves later targets into the wrong slots. When host.rtv returns None, the target is left out of rtvs. Every render target after it then binds one slot lower, so the pixel shader's later outputs go to the wrong textures. A null RTV in that slot keeps the order. @EduAzevedo made this point on #55 and posted a patch. Mine does it in Host::rtv: a typed null view (R8G8B8A8_UNORM, TEXTURE2D) when the resource lacks ALLOW_RENDER_TARGET. The early return in clear_rtv is right as it is. (This one is from reading the diff; I haven't run this branch.)

2. The guard is needed, but dropping the use loses the title's writes. In the world the host refuses exactly two textures here: 2560x1440 format 115 (flags RT, loses RT) and 2560x1440 format 86 (flags RT|UAV, loses the UAV). Without a guard, the device was removed with DXGI_ERROR_INVALID_CALL at world entry, 2 of 2 runs. With one, the run stayed up for 8 minutes, but the first texture's draws and the second's compute writes go nowhere.

Merging the efforts: the RTV guard and the null clear value (which #55 doesn't have) are useful on their own, for any format. For 86 and 115, #89 keeps the writes by making them R8G8B8A8_UNORM. With a substitution like it on this card, no use is dropped, and the world ran 12 minutes at ~2,810 draws per frame. So I'd combine: the guard with a null RTV from here, the substitution from #89, and the use-dropping as the last resort for other formats.

AI-assisted (Claude Code): the runs and log analysis were automated. The hardware, title copy and runs are the user's.

@Zipettte

Copy link
Copy Markdown

Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at 08e4c89: the new test resource::tests::host_texture_drops_unsupported_uav_flag_for_b5g5r5a1 fails every time (3/3):

panicked at crates\victory-gpu\src\resource.rs:1904:9:
assertion `left == right` failed
  left: 4
 right: 0

4 is D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS, so the UAV flag is kept on this machine. Maybe this RDNA3 driver reports typed UAV support for B5G5R5A1 and the flag is (correctly) not dropped. If so, the test may need to check the format support first instead of always expecting the flag to be removed. The other 43 victory-gpu tests pass.

Tested with AI assistance (Claude).

@fuzeofficlal

Copy link
Copy Markdown
Contributor

Tested across NVIDIA GeForce RTX 5090, AMD Radeon(TM) Graphics (1002:13c0), and D3D12 WARP with VICTORY_D3D12_DEBUG=1, and put together a rebased branch fixing the two issues noted above:

  1. Adapter-aware capability assertions in resource.rs: Queries CheckFeatureSupport(D3D12_FEATURE_FORMAT_SUPPORT) dynamically for B5G5R5A1_UNORM / B4G4R4A4_UNORM (stripping on NVIDIA while preserving supported flags on AMD and WARP), and tests unconditional RT+UAV flag stripping + pOptimizedClearValue omission on BC1_UNORM (71, flags = 5) and UAV stripping on B8G8R8X8_UNORM (88).
  2. Preserve MRT output slot indices when ALLOW_RENDER_TARGET was stripped (host.rs + draw.rs): Instead of continue shifting subsequent targets down by one slot, pushes a typed null RTV (Host::null_rtv, falling back to R8G8B8A8_UNORM TEXTURE2D when the texture's own format cannot back a host RTV) while keeping the non-RT texture out of self.targets so no invalid RENDER_TARGET barrier is emitted. Verified with a synthetic MRT draw (SV_Target0 bound to BC1_UNORM, SV_Target1 bound to R8G8B8A8_UNORM reading back [0, 255, 0, 255]) with zero D3D12 debug errors on all three adapters.

Branch ready to cherry-pick from (author attribution preserved): https://github.com/fuzeofficlal/VIctory/tree/fix/host-texture-uav-support-1040 (1bdeeb4c)

@BaggyALPHA BaggyALPHA left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I independently reproduced the optimized-clear issue from item 22 of #1242 on Windows WARP. For a synthetic RGBA8 texture, upstream allocates it with a null clear pointer and refuses it with a clear hint when neither render-target nor depth-stencil is set. With this PR integrated into current main, both the plain texture and the UAV-only variant allocate even when the caller supplies a clear hint.

The full GPU suite on that integration had 54 passes, one ignored test, and one failure. The failure was the previously reported B5G5R5A1 UAV capability assertion. The final-flags clear guard is independently useful. The plain and UAV-only cases can test that guard without assuming support for a particular packed format.

AI-assisted (Codex).

justr4mzi added a commit to justr4mzi/VIctory that referenced this pull request Nov 24, 2026
@MamaLeVrai

Copy link
Copy Markdown

Heads-up on this PR's test host_texture_drops_unsupported_uav_flag_for_b5g5r5a1: on main plus this PR alone it fails on an RX 6950 XT (left: 4, right: 0 at the first assert). host_texture only drops what the adapter refuses, via CheckFeatureSupport, and that adapter accepts a typed UAV on B5G5R5A1_UNORM, so the flag stays; the test assumes every adapter refuses it. The CI runner has no GPU there (host() is None, the test returns early), so CI would not show it. The code is right; the test can ask the adapter the same way and expect the flag kept or dropped accordingly. That is what the commit 9b2e665 of #1632 does (for B5G5R5A1 UAV and render target and for B4G4R4A4 render target). AI-assisted (Claude Code); no game data.

MamaLeVrai added a commit to MamaLeVrai/VIctory that referenced this pull request Nov 24, 2026
…#1040

Marvisak#1523's new head no longer declares it (its 16-bit widening is gone); Marvisak#1040's flag-dropping code
uses it.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@Marvisak

Copy link
Copy Markdown
Owner

Automated triage for the maintainers. Closing because another open pull request covers the same change.

See #55. same change as before (drop UAV/RT flags by a format-support query, skip UAV barriers by a hard-coded flag test, guard RTVs) and still conflicts; #55 fixes the same NVIDIA packed 16-bit refusals in 47 lines by retrying creation. Also carried by bundles #1632/#1638.

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 Marvisak closed this Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants