Skip to content

GPU: a texture loses the unordered use its format cannot take, as its render target's - #2834

Open
kais7654 wants to merge 3 commits into
Marvisak:mainfrom
kais7654:gpu/formats-give-up-the-uses-the-device-refuses
Open

kais7654 wants to merge 3 commits into
Marvisak:mainfrom
kais7654:gpu/formats-give-up-the-uses-the-device-refuses

Conversation

@kais7654

Copy link
Copy Markdown

Stacked on #2773. Fixes the resource side of #2725's steps 1/3 (and #2563):

host_desc left the unordered access use in even when the device refuses a
resource of the format for it — the 16-bit packed ones on NVIDIA, B5G5R5A1
typed UAV and B4G4R4A4 alike (the comment said the creation refuses
cleanly and only the views remove the device). A probe on an NVIDIA host
proves that wrong: CreateCommittedResource of such a description fails
E_INVALIDARG without any debug layer (GetResourceAllocationInfo reports
SizeInBytes = UINT64_MAX) — the log's no host texture … (0x80070057) —
and under the debug layer GetResourceAllocationInfo (id=599) is an error
of its own, so the device is removed before any view is made
(#2725's step 3, #2563's B5G5R5A1 typed UAV removal).

The use is now left away like the render target's: format_takes_unordered
asks CheckFeatureSupport for TYPED_UNORDERED_ACCESS_VIEW (a typeless
format names no format itself and takes any use, its views do); the query
is shared with format_takes_render_target's cache, keyed by the use.
Where the use goes, the texture is made and its shader reads work; its
own-format unordered views are held back in descriptor::host::fits as
before, and a view of a castable format the device does store reads null
(#2442's flag-drop) instead of the creation killing the device.

Tests (RTX 5090):

  • a_target_of_a_format_the_device_refuses_the_use_of_is_made_without_it:
    the description agrees with the device on both uses now — each stays when
    CheckFeatureSupport reports the use, and goes when it does not, for
    86/115/87, with the typeless and sRGB promotions unchanged.
  • New an_unordered_use_the_device_refuses_is_made_without_it: a texture
    of 86 and of 115 with RENDER_TARGET | UNORDERED is placed, made on
    first use (where today the whole creation fails), and its host flags
    follow the device's; R8G8B8A8 keeps its use.
  • cargo test -p victory-gpu --lib --test-threads=1: 196 passed, 0
    failed
    but the 2 pre-existing >1M heap-cap baselines.
  • cargo clippy --workspace --all-targets --locked, and with
    --all-features: 0 warnings, both.

Generated with Mistral Vibe.

kais7654 and others added 3 commits November 25, 2026 22:43
The console makes any texture a target or unordered storage; the host
refuses resources with uses their format cannot take -- the 16-bit packed
ones on NVIDIA: B4G4R4A4 has no render target support and its and
B5G5R5A1's unordered access is refused too (Marvisak#2725) -- and both the
creation and a plain query of such a description removed the device: 14
of the 20 crashes in the report, one of them 13 s after launch.

A format's uses now come from CheckFeatureSupport (cached), and a host
description leaves the refused ones away: the texture is made without
them (its shader reads work; on NVIDIA the render target clears of a
B4G4R4A4 skip, on the formats that do take a use nothing changes). A
render target or depth view of a texture made without its use is dropped
(the view reads null) instead of made on a resource that does not allow
it -- Host::rtv and Host::dsv say None, and set_targets, the clear of a
render target and of depth leave such a target out, as they do one
without a view.

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
…ce does not store is held back

found in review on Marvisak#2773 by fuzeofficial (verified on RTX 5090 and WARP):

`CheckFeatureSupport` reports no uses for a TYPELESS format (and every
sRGB de-promoted one, 27/90/92): the format names no format itself, its
views do. Stripping by that report left such a texture without the
render target use of the game's own sRGB targets.

A typeless format now takes its description's uses instead of the
report's, and only the render target use is stripped at creation -- the
one whose resource the device refuses wholesale (B4G4R4A4 on NVIDIA,
where it does (an E_INVALIDARG, no device removal), and what removes the
device is a view of it: every typed unordered access view now names a
format the device stores (own format and casts alike, the description's
own format included), and one it does not (B5G5R5A1, B4G4R4A4) is held
back -- reads null, writes dropped.

Tests: the description of 86/115/87 agrees with the device on the render
target use and keeps the unordered one; typeless 27/90/92 and a sRGB
promotion keep theirs; `typed_store` agrees with the device for 86, 115
and 28.

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
… render target's

The unordered access the device refuses a resource of (the 16-bit packed
formats on NVIDIA: B5G5R5A1's typed UAV, Marvisak#2725's CreateUnorderedAccessView
step; Marvisak#2563) is left away in the hosted description, as the render target
use's already was: the creation of such a resource fails
(`E_INVALIDARG`, the log's `no host texture`, and under the debug layer a
device removal), where without the use the texture is made and its
shader reads work, its own-format unordered views held back in
`descriptor::host::fits` as before. The device's answer to both usages
is the same `CheckFeatureSupport` query, cached once for both.

Generated by Mistral Vibe.

Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
@kais7654
kais7654 force-pushed the gpu/formats-give-up-the-uses-the-device-refuses branch from 733ab02 to 208080e Compare November 25, 2026 21:44
@kais7654

Copy link
Copy Markdown
Author

Rebased onto main (61bfc77). The conflict was descriptor/host.rs: main's
"mirror placed unordered texture views" already guards the view side —
fits keeps an unordered view only in a format the device stores (named,
cast, and the view-less default alike). Those hunks are taken from main
now, this branch's iteration-2 view guards are subsumed by them, and the
test they brought (an_unordered_view_names_a_format_the_device_stores)
is kept. What remains of this branch is the creation side: host_desc
leaves the render target and unordered access uses a format cannot take
(B4G4R4A4's, B5G5R5A1's on NVIDIA — #2725, #2563) — the probed creation
fails E_INVALIDARG even without a debug layer, where with the strip it
is made and reads work.

cargo test -p victory-gpu --lib (RTX 5090): 199 passed, 2 failed (the
pre-existing >1M heap-cap baselines); cargo clippy --workspace --all-targets --locked and --all-features: 0 warnings, both.

@kotekompotek kotekompotek left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Heads-up on overlap: this is the same host_desc change as #2442 (mine, stacked differently — #2442 is on main, CI-green, and has already been through two maintainer-review rounds on exactly this logic). Worth a look at that history before this lands:

format_takes_unordered(format) here checks only the bare format. A title texture created typeless can still get a legal UAV view — the castable-formats list passed at CreateCommittedResource3 includes family members that DO store typed. On fyernald's Win10/RTX 3080 (no ID3D12Device10), checking only the bare format strips ALLOW_UNORDERED_ACCESS from the sRGB formats (29, 91) even though family member 28 stores typed and the texture's UAV view is legal — the exact regression #2442's first revision had. #2442's current version keeps the flag when a typeless family member can store typed, and drops it for standalone formats like 85/86 (no typeless base, so no legal cast path even where Device10 exists).

Also note GetResourceAllocationInfo sees only the bare desc — the cast list isn't visible there — so for a standalone UAV-flagged format the flag is still lethal regardless of Device10, which is what makes the typeless gate necessary rather than merely a probe.

The RTV/DSV Option guard on top is complementary and good — it's the view-side counterpart #2773 started.

@fuzeofficlal

Copy link
Copy Markdown
Contributor

Reviewed and tested 208080e5 on Windows 11 (RTX 5090 + WARP) against main (f3578e3):

  • Verification: cargo xtask policy (186 files ok), cargo clippy --locked -p victory-gpu --all-targets (default & --features diagnostics, 0 warnings); RTX 5090 (resource::tests 19/19, descriptor::host::tests 14/14, draw::tests 13/13, host::tests 27/27, list::tests 4/4) and WARP (19/19, 15/15, 13/13, 27/27, 4/4) all passed.
  • Overall a much cleaner direction than silent cross-family format promotion (complements #2462's view-side fits() by stripping unsupported UNORDERED at creation time), but two edge cases need fixes:
    1. Stale clear_value in make_texture: when host_desc strips RENDER_TARGET for an unsupported format (and DEPTH == 0), make_texture still forwards a non-null clear_value to CreateCommittedResource/CreateCommittedResource3, which D3D12 rejects with E_INVALIDARG when neither ALLOW_RENDER_TARGET nor ALLOW_DEPTH_STENCIL is set.
    2. shared_texture re-adds stripped UNORDERED from siblings (resource.rs:1309-1317): shared_texture runs host_desc first and then merges d.flags |= host_desc(&r.desc).map_or(0, |h| h.flags & USES) across same-MemoryKey siblings. If the first texture is an unsupported-UAV format (e.g. B5G5R5A1_UNORM 86, 2 B/px) and a sibling at the same memory has a same-bpp UAV-capable format (e.g. R8G8_UNORM 61 + UNORDERED), UNORDERED gets OR'd back onto format 86 and passed to make_texture -> E_INVALIDARG. Re-checking UAV support (while still allowing castable-list aliasing like format 67 + castable R32_UINT 42) closes this gap.

@futurepro62

Copy link
Copy Markdown

Full-suite run on NVIDIA, since this PR has no test report yet. Tested exact head 208080e (on its base 61bfc77).

Tested

Not tested

  • AMD (the tests take the default adapter), a release build, the title (test run only).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Verdict: needs work. This PR is stacked on #2773, so it carries that PR's commits. On top of them, resource::host_desc drops UNORDERED (and the render target) when CheckFeatureSupport does not report the use (format_takes_unordered). CI passes, and the RTX 5070 Ti and 5090 runs are useful. Before it can be a merge candidate:

  • Clear value. make_texture still passes the title's clear value when host_desc has removed the render-target use from a colour texture. D3D12 refuses an optimized clear value without ALLOW_RENDER_TARGET/ALLOW_DEPTH_STENCIL, so creation still fails (point 1 from @fuzeofficlal).
  • Shared textures. shared_texture ORs host_desc(&r.desc).flags & USES from same-memory siblings back into d.flags after the strip, which can put UNORDERED back on format 86 or 115. The format check needs to run again after that merge.
  • Cache. format_takes still caches true when host() is not available yet (!reported). The GPU: a texture is made in the uses its format takes #2773 review asked for this to change; an answer the query did not give should not be recorded.

The larger question is direction. #2626 (merge candidate) makes these same textures R8G8B8A8_UNORM so draws and clears to them still work, while this PR drops the uses. Please say whether this is meant as a fallback alongside #2626 or instead of it. Landing #2773 first would also shrink this diff to its own change.

CI: passing (check).


Generated by Claude Code

@zed6000

zed6000 commented Nov 26, 2026

Copy link
Copy Markdown

Merged onto current main 63bcca4 (git merges it without a conflict), victory-gpu's tests don't compile: E0308 mismatched types. This PR makes Host::dsv and Host::rtv return Option<D3D12_CPU_DESCRIPTOR_HANDLE>, and two tests that landed on main since use the old form:

  • crates/victory-gpu/src/pipeline/depth_bounds_test.rs (from GPU: the depth bounds test reaches the host #158): let dsv = host.dsv(&depth, None);
  • crates/victory-gpu/src/queue.rs, a test's ClearRenderTargetView(host.rtv(&primary.texture, None), …)

With .expect("a depth buffer takes a depth view") and .expect("a render target takes a target view") on those two calls, it compiles, and cargo test -p victory-gpu --lib --locked -- --test-threads=1 passes on an RX 7900 XTX (234 passed, 0 failed). Tested as part of a run of the GPU tests of open PRs on AMD hardware.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants