Skip to content

GPU: a texture is made in the uses its format takes - #2773

Open
kais7654 wants to merge 2 commits into
Marvisak:mainfrom
kais7654:gpu/formats-keep-the-uses-the-device-refuses
Open

kais7654 wants to merge 2 commits into
Marvisak:mainfrom
kais7654:gpu/formats-keep-the-uses-the-device-refuses

Conversation

@kais7654

Copy link
Copy Markdown

Fixes #2725 (group A — 14 of the 20 crashes; may also help #2719's group A).

What

The console makes any texture a render target or unordered storage. The host (D3D12) refuses resources with uses their format cannot take — on NVIDIA the 16-bit packed ones: B4G4R4A4 has no render-target support and neither B4G4R4A4 nor B5G5R5A1 supports typed UAVs. Until now the creation itself (and even a plain GetResourceAllocationInfo of such a description) was an invalid call, which removed the device: the verbose log of #2725 reproduces one of these crashes 13 s after launch.

Now a format's uses come from a cached CheckFeatureSupport(D3D12_FEATURE_FORMAT_SUPPORT) query, and host_desc leaves the refused uses away before anything reaches the device. The texture is created without them (its shader reads keep working). Host::rtv/Host::dsv report None for a resource its view would not be valid on, and set_targets, ClearRenderTargetView and ClearDepthStencilView leave such a target out, as they already do for a target without a recorded view — a dropped clear instead of a device removal.

On formats that do take their uses (everything else), nothing changes.

Verified on hardware (RTX 5070, driver 616.87)

  • CheckFeatureSupport there: B4G4R4A4 (115) — no RT, no UAV; B5G5R5A1 (86) — RT yes, UAV no — matching the report's debug-layer output.
  • New test a_target_of_a_format_the_device_refuses_the_uses_of_is_made_without_them: the sanitized description agrees with the device's own answer for 86/115/87.
  • cargo clippy --workspace --all-targets --locked -- -D warnings clean (standard and --all-features).
  • cargo test -p victory-gpu --features diagnostics: 200 passed; the 2 failures are the heap-cap pair pre-existing on main on this machine (NVIDIA heap cap, Shaders: the null-buffer reads of the heap skip a host that caps its heaps #1943 family), unrelated to this diff.

Not covered: the report's group B (DEVICE_HUNG in a mesh draw) and group C (feature level) are separate causes, and the 1M descriptor-heap cap of #2725's section 2 is its own fix; this PR takes the group that was 14/20 crashes.

AI-assisted: implemented with Mistral Vibe.

@fuzeofficlal

Copy link
Copy Markdown
Contributor

Reviewed and tested 05d444c4 (merged cleanly onto main 13f91ca) on Windows 11 (RTX 5090 + WARP).

Blocking bug confirmed on both RTX 5090 and WARP: format_uses strips RT and UAV flags from all TYPELESS and sRGB + UNORDERED textures

In crates/victory-gpu/src/resource.rs:1131-1150, host_desc first promotes sRGB + UNORDERED formats (29/91/93) to TYPELESS (27/90/92) and then queries format_uses(d.format) via CheckFeatureSupport(D3D12_FEATURE_FORMAT_SUPPORT).

In D3D12, D3D12_FEATURE_FORMAT_SUPPORT reports RENDER_TARGET = false and TYPED_UNORDERED_ACCESS_VIEW = false for every TYPELESS format (views on a typeless resource supply the typed format, not the resource format itself). Probed directly on this branch on both RTX 5090 and WARP:

  • format_uses(27 / R8G8B8A8_TYPELESS) -> rt = false, uav = false
  • format_uses(90 / B8G8R8A8_TYPELESS) -> rt = false, uav = false
  • format_uses(92 / B8G8R8X8_TYPELESS) -> rt = false, uav = false
  • Consequently, host_desc returns fmt = 27, flags = 0x0 for both R8G8B8A8_UNORM_SRGB (29) + RENDER_TARGET | UNORDERED and title-created R8G8B8A8_TYPELESS (27) + RENDER_TARGET | UNORDERED, stripping both ALLOW_RENDER_TARGET and ALLOW_UNORDERED_ACCESS.
  • Similarly, for B8G8R8X8_UNORM (88) + RENDER_TARGET | UNORDERED, format_uses(88) strips ALLOW_UNORDERED_ACCESS even when a castable R32_UINT (42) UAV is valid on the resource.

Skipping TYPELESS formats in format_uses (or probing a representative typed format in the family) and preserving UNORDERED for formats castable to UAV-capable formats would avoid stripping legitimate RT/UAV flags.

Verification & merge compatibility

  • RTX 5090 (--features diagnostics): resource::tests 18/18 passed; full --test-threads=1 197 passed, 2 failed (only the 2 pre-existing RTX 5090 >1M heap-cap baselines).
  • WARP (VICTORY_D3D12_WARP=1, --features diagnostics --test-threads=1): 199 passed, 0 failed, 1 ignored.
  • cargo clippy (default & diagnostics): 0 warnings; cargo xtask policy: 184 files ok.
  • Merge-tree: clean vs 13f91ca, #2187, #2767 (semantically mutually exclusive with #2767); conflicts with #2679 in resource.rs.

@oni-swr

oni-swr commented Nov 25, 2026

Copy link
Copy Markdown

Independent verification of head 05d444c4 (WARP/CPU): code looks right, but its test cannot catch the bug here.

  • Diff: host_desc drops the render target / unordered use when CheckFeatureSupport says the format cannot take it. Host::rtv and Host::dsv return None for a resource without the flag, and the draw and clear paths skip such targets. This matches the described intent and is in scope. Tests: victory-gpu --lib 196 pass, 0 fail (baseline 195). Clippy -D warnings is clean.
  • Negative control is inconclusive on WARP: with the flag-clearing block in host_desc disabled, a_target_of_a_format_the_device_refuses_the_uses_of_is_made_without_them still passes. The test compares host_desc against the device's own report, and WARP takes all three formats, so it cannot fail there. It only catches the bug on a host that refuses a use, such as the NVIDIA case from Host GPU device removed (D3D12) on NVIDIA: B4G4R4A4/B5G5R5A1 resources cause DXGI_ERROR_INVALID_CALL; shader-visible descriptor heap capped at 1M; wave64 compute shaders refused #2725. The rtv/dsv None paths have no test at all. A device-free unit test of the None path, or a stubbed support table, would make this verifiable without that GPU.
  • Minor: format_uses caches true, true permanently if host() is not yet available on its first call (!reported), so a later query is not redone.

Method: WARP/CPU only (no physical GPU; VICTORY_WARP=1, VICTORY_D3D12_WARP=1, Windows SDK dxil.dll on PATH, so DXIL validation ran), cargo test -p <crate> --lib --locked and cargo clippy -p <crate> --all-targets --locked -- -D warnings, compared with origin/main 13f91ca. Nothing from the game was used.

AI-assisted review (Claude Code / Claude Sonnet 5.5).

kais7654 added a commit to kais7654/VIctory that referenced this pull request Nov 25, 2026
…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,
Marvisak#2725): an unordered access use stays, the creation refusing cleanly
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>
@kotekompotek

Copy link
Copy Markdown

Tightens the right seam: fits() now refuses any unordered view naming a format the device can't store - including the default view case (view==0 on a typed unstorable resource), which the old cast-only guard missed. Complements the creation-side work (making RTV/DSV fallible and skipping untaken uses keeps a dropped view from silently becoming device removal). Layers well with #2442's flag-drop: even where the flag survives, a bad view reads null instead of removing the device.

@kais7654

Copy link
Copy Markdown
Author

Reviewed and tested 05d444c4 (merged cleanly onto main 13f91ca) on Windows 11 (RTX 5090 + WARP).

Blocking bug confirmed on both RTX 5090 and WARP: format_uses strips RT and UAV flags from all TYPELESS and sRGB + UNORDERED textures

In crates/victory-gpu/src/resource.rs:1131-1150, host_desc first promotes sRGB + UNORDERED formats (29/91/93) to TYPELESS (27/90/92) and then queries format_uses(d.format) via CheckFeatureSupport(D3D12_FEATURE_FORMAT_SUPPORT).

In D3D12, D3D12_FEATURE_FORMAT_SUPPORT reports RENDER_TARGET = false and TYPED_UNORDERED_ACCESS_VIEW = false for every TYPELESS format (views on a typeless resource supply the typed format, not the resource format itself). Probed directly on this branch on both RTX 5090 and WARP:

  • format_uses(27 / R8G8B8A8_TYPELESS) -> rt = false, uav = false
  • format_uses(90 / B8G8R8A8_TYPELESS) -> rt = false, uav = false
  • format_uses(92 / B8G8R8X8_TYPELESS) -> rt = false, uav = false
  • Consequently, host_desc returns fmt = 27, flags = 0x0 for both R8G8B8A8_UNORM_SRGB (29) + RENDER_TARGET | UNORDERED and title-created R8G8B8A8_TYPELESS (27) + RENDER_TARGET | UNORDERED, stripping both ALLOW_RENDER_TARGET and ALLOW_UNORDERED_ACCESS.
  • Similarly, for B8G8R8X8_UNORM (88) + RENDER_TARGET | UNORDERED, format_uses(88) strips ALLOW_UNORDERED_ACCESS even when a castable R32_UINT (42) UAV is valid on the resource.

Skipping TYPELESS formats in format_uses (or probing a representative typed format in the family) and preserving UNORDERED for formats castable to UAV-capable formats would avoid stripping legitimate RT/UAV flags.

Verification & merge compatibility

  • RTX 5090 (--features diagnostics): resource::tests 18/18 passed; full --test-threads=1 197 passed, 2 failed (only the 2 pre-existing RTX 5090 >1M heap-cap baselines).
  • WARP (VICTORY_D3D12_WARP=1, --features diagnostics --test-threads=1): 199 passed, 0 failed, 1 ignored.
  • cargo clippy (default & diagnostics): 0 warnings; cargo xtask policy: 184 files ok.
  • Merge-tree: clean vs 13f91ca, #2187, #2767 (semantically mutually exclusive with #2767); conflicts with #2679 in resource.rs.

@fuzeofficlal Fixed in c1fcd74, on both points:

  1. TYPELESS formats take their description's uses instead of the support report's (a typeless format names no view format itself, so the report is false-negative by construction) — the sRGB de-promoted targets keep theirs, and only the render target use is stripped at creation now, for a typed format the device refuses it on (the B4G4R4A4 of Host GPU device removed (D3D12) on NVIDIA: B4G4R4A4/B5G5R5A1 resources cause DXGI_ERROR_INVALID_CALL; shader-visible descriptor heap capped at 1M; wave64 compute shaders refused #2725). The unordered access use is no longer stripped at all: a creation the device refuses comes back a clean E_INVALIDARG (probed on hardware), and what actually removed the device in Host GPU device removed (D3D12) on NVIDIA: B4G4R4A4/B5G5R5A1 resources cause DXGI_ERROR_INVALID_CALL; shader-visible descriptor heap capped at 1M; wave64 compute shaders refused #2725 was the view.

  2. So the removal's real spot is guarded where it happens: fits now requires every typed unordered access view to name a format the device stores — own format and formats without a description included, which the old typed_store guard only covered for cross-family casts. A UAV over B5G5R5A1/B4G4R4A4 reads null and drops its writes; a cast to a UAV-capable format (your R32_UINT case over B8G8R8X8) keeps working.

New tests: the sanitized 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 all uses; typed_store agrees with the device's report. Probed your exact sequences on hardware (RTX 5070, driver 616.87): typeless formats report rt=false/uav=false as you measured, and plain CreateCommittedResource with ALLOW_UNORDERED_ACCESS + B8G8R8X8 returns E_INVALIDARG without device removal. Clippy clean (default and diagnostics), the 2 remaining failures are the pre-existing heap-cap baselines on this machine. Thanks again for the catch.

AI-assisted (Mistral Vibe).

@kais7654

Copy link
Copy Markdown
Author

Tightens the right seam: fits() now refuses any unordered view naming a format the device can't store - including the default view case (view==0 on a typed unstorable resource), which the old cast-only guard missed. Complements the creation-side work (making RTV/DSV fallible and skipping untaken uses keeps a dropped view from silently becoming device removal). Layers well with #2442's flag-drop: even where the flag survives, a bad view reads null instead of removing the device.

@kotekompotek Thanks — the seam mattered: the creation side alone would have left a hole either way (keep the flag and the description's own view removes the device; drop the flag and every cast view dies with it), so the guard had to sit on the view. The default-view case (view==0 on a typed unstorable resource) was exactly the one that stayed open until this pass. Layering with #2442's flag-drop is the story of the whole fix: whatever survives the creation ends readable or bounded, never a removal.

AI-assisted (Mistral Vibe).

@fuzeofficlal

Copy link
Copy Markdown
Contributor

Re-verified updated c1fcd742 on Windows 11 (RTX 5090 + WARP, --features diagnostics):

  • The previous TYPELESS (27/90/92) and sRGB + UNORDERED flag-stripping issue is completely resolved: host_desc no longer strips UNORDERED at resource creation, format_takes_render_target preserves all typeless families, and descriptor::host::fits() now blocks unsupported typed-store UAVs on both default (view == 0) and explicit same-/cross-family views without device removal.
  • cargo xtask policy: 184 files ok; cargo clippy --locked -p victory-gpu --all-targets -- -D warnings (default & --features diagnostics): 0 warnings.
  • RTX 5090 (--features diagnostics, --test-threads=1): 198 passed, 2 failed (only the 2 pre-existing RTX 5090 >1M heap-limit tests dynamic_slots_are_held_until_released and lists_share_a_table_and_copies_keep_their_views), 1 ignored; both new tests pass.
  • WARP (VICTORY_D3D12_WARP=1, --features diagnostics, --test-threads=1): 200 passed, 0 failed, 1 ignored.
  • Clean git merge-tree against origin/main 13f91ca (note: overlaps GPU: make shared sRGB textures typeless for unordered access #2679 in resource.rs and descriptor/host.rs).

Non-blocking observations:

  • If format_takes_render_target is first called before host() is available (!reported), true is cached permanently in KNOWN.
  • The Host::rtv/Host::dsv None skip paths do not yet have dedicated unit tests.

Looks solid and ready from my side!

kais7654 added a commit to kais7654/VIctory that referenced this pull request Nov 25, 2026
…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>
@artor410

Copy link
Copy Markdown
Contributor

Tested on RTX 3070 Ti, driver 610.88, Windows 11 26300, rustc 1.98.1. main 13f91ca. Merged into main cleanly (725d6f4).

  • cargo test -p victory-gpu (main: 193 passed, 2 failed: the known heap-cap pair dynamic_slots_are_held_until_released, lists_share_a_table_and_copies_keep_their_views). With this PR: 195 passed, same 2 failed. New an_unordered_view_names_a_format_the_device_stores and a_target_of_a_format_the_device_refuses_the_use_of_is_made_without_it pass.
  • Probe (temporary test, not committed): 256x256 texture via create_placed with the UAV and/or RT flag, then descriptor::host::make_view(View::Unordered(..)) and Host::rtv(texture, None), then GetDeviceRemovedReason, one process per case. On main: UAV view of 86 or 115 crashes the test process (0xc0000005 inside the driver); RTV of 115 removes the device (0x887A0001); 115 with RT|UAV gets no host texture. CheckFeatureSupport here: 86 RT yes, typed UAV no; 115 RT no, typed UAV no.
  • With this PR: every case safe. 115 loses the RT flag (RTV call no longer removes the device); UAV flag kept on 86/115 but make_view returns no view; 115 with RT|UAV now gets a texture.

Covers both formats and both uses, but by dropping them: draws to a 115 target and UAV writes to 86/115 are lost. #2767 makes the same cases work as R8G8B8A8.

(Claude Code, Claude Opus 5.5.)

kais7654 and others added 2 commits November 25, 2026 22:56
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>

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

The current head strips the render-target flag in resource::host_desc (via a new format_takes_render_target) for formats the device refuses it on, and makes Host::rtv/Host::dsv return None so draw.rs set_targets and list.rs clear_rtv/clear_dsv skip such targets. A few things before this is mergeable:

  • CI (check) is failing on this head; please look at the job log and fix it.
  • The fits/typed_store guard for unordered views described in the thread is already in main (descriptor/host.rs fits, from GPU: no typed unordered view in a format the host cannot store to #2462); this PR only adds a test for it, so the description should be updated to match what the diff does.
  • format_takes_render_target caches true permanently when host() is not yet available on its first call; it should not record an answer it did not get.
  • This drops draws and clears to a B4G4R4A4 target, while gpu: widen unsupported 16-bit render targets and UAVs to R8G8B8A8_UNORM #2767 makes the same cases work by widening to R8G8B8A8_UNORM. Please say how the two relate (complementary or one instead of the other) so a maintainer can choose; the rtv/dsv None paths also have no test.

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 (233 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

7 participants