Skip to content

GPU: castable formats the host has - #2101

Open
Deilach wants to merge 1 commit into
Marvisak:mainfrom
Deilach:linux-castable-formats
Open

Deilach wants to merge 1 commit into
Marvisak:mainfrom
Deilach:linux-castable-formats

Conversation

@Deilach

@Deilach Deilach commented Nov 25, 2026

Copy link
Copy Markdown

What

Under Wine and Proton, which run D3D12 on Vulkan through vkd3d-proton, the first castable colour texture logs:

WARN victory_gpu::resource: the host refuses castable formats: textures of one memory in other formats get their own host texture error=Invalid parameter. (0x80070057) desc=ResourceDesc { … width: 3840, height: 2160, … format: 28, … flags: 5 }

With VKD3D_DEBUG=warn, vkd3d-proton gives the reason: d3d12_resource_validate_usage: Unrecognized format #59. The number is hex, so this is format 89, R10G10B10_XR_BIAS_A2_UNORM. vkd3d-proton has no mapping for it; it's the only one of the 21 formats castable(28) lists that's missing from its format table. One unknown format refuses the whole list. Every colour texture of that element is then made without castable formats, and title textures of one memory in other formats get their own host textures, bridged by copies.

Change

make_texture keeps only the castable formats the host reports support for: CheckFeatureSupport(D3D12_FEATURE_FORMAT_SUPPORT) with a non-zero Support1, asked once per format and cached. A host that has every format, as Windows drivers do, keeps exactly the lists it has today. A host missing one loses only that format, not every list.

Tests

  • New: resource::tests::a_colour_target_is_castable_to_the_formats_the_host_has. A 256×256 R8G8B8A8_UNORM render target with unordered access is made castable to the formats of its element that the host has. Under vkd3d-proton it fails on main, with the warning above, and passes with this change.
  • An existing test that failed under vkd3d-proton now passes: draw::tests::a_texture_written_in_one_format_reads_in_another_through_a_placed_view. That is the case castable formats exist for.

In the title, from VIctory's own texture counters in the log, comparing a world run before and after on the same Linux setup:

main this change
"refuses castable formats" warning yes none
copies between textures of one memory 59–166 per frame 0
host textures replaced 49 0
saved by title textures sharing one host texture ~130 MB ~308 MB
host texture memory ~9.2 GB ~8.7 GB

victory-gpu tests on Linux, Wine 11.22 + vkd3d-proton master on RADV, RX 9070 XT: main 130 ok / 12 failed, this branch 131 ok / 12 failed. The differences are the two tests above, plus draw::tests::a_depth_texture_written_through_unordered_views_reads_as_depth, which fails on main here too when run alone (5 of 5). cargo clippy --workspace --all-targets [--all-features] -- -D warnings is clean.

🤖 Generated with Claude Code

A castable list naming a format the host does not have is refused whole,
and the texture is then made without castable formats. vkd3d-proton
(D3D12 on Vulkan, under Wine and Proton) has no
`R10G10B10_XR_BIAS_A2_UNORM`, one of the 4-byte formats `castable` lists,
so there every colour texture of that element lost its list, and title
textures of one memory in other formats got their own host textures,
bridged by copies.

`make_texture` now keeps the formats the host reports support for
(`CheckFeatureSupport`, asked once per format). A host that has every
format, as Windows drivers do, keeps the same lists.

New test: a render target with unordered views is castable to the formats
of its element the host has. Under vkd3d-proton it fails before this
change, and `draw::tests::a_texture_written_in_one_format_reads_in_another_through_a_placed_view`
passes after it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
zhaibingye added a commit to zhaibingye/VIctory that referenced this pull request Nov 25, 2026
Do not let one unsupported DXGI format discard the rest of a texture's castable list. Source native vkd3d-proton tests cover the failure. Verified 59 portable GPU tests and the Windows workspace test build cross-check on the merged tree.

@catminou4 catminou4 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.

Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; source review of the diff.

Castable formats the host has — format-cast gating by host caps; pairs with the capability-gating cluster (#1775/#1787/#1801/#1832/#1843).

@upipibi

upipibi commented Nov 25, 2026

Copy link
Copy Markdown

Ran on Windows 11 with an RTX 3070 (Ampere, driver 616.56), debug build, at 4d8c89a. victory-gpu: 142 passed, 2 failed, 2 ignored. The new a_colour_target_is_castable_to_the_formats_the_host_has passes. The 2 failures are #1744's heap-cap failures on main. Same as main on this hardware (native D3D12, so not the vkd3d-proton case this PR is about).

AI-assisted (Claude Code).

@fiestorra

Copy link
Copy Markdown
Contributor

Reviewed the Support1 != 0 choice by measuring it: it is the right one, and here is the trap it walks past

I checked the two things a review of this change can check on hardware rather than by reading: whether the filter leaves the Windows lists exactly as they are, and whether the stricter test would have.

On this machine (RTX 4090, driver 32.0.16.2124), for the 21 formats castable(28) lists:

test formats kept
Support1 != D3D12_FORMAT_SUPPORT1_NONE (what this PR uses) 21 of 21
Support1 & CAST_WITHIN_BIT_LAYOUT (0x8000) 13 of 21

So the claim in the description holds here — a host that has every format keeps exactly today's lists — and it holds because the test is the loose one. The eight that the cast bit would have dropped are

25, 30, 32, 36, 38, 42, 43, 89   (s1 = 0x27051f3, 0x27051f3, 0x27051f3,
                                  0x27051f3, 0x27051f3, 0x27051ff,
                                  0x27051fb, 0x31180020)

which is exactly the trap: CAST_WITHIN_BIT_LAYOUT is the bit that says "this format may be cast to within its bit layout", and on this driver eight formats of the very list that is being filtered do not carry it while the host does make them castable in practice. Tightening the predicate later — and it reads like the tidier choice — would silently take 21 formats down to 13 on Windows, which is the opposite of what this change is for.

Suggestion, and it is only documentation: say that in host_has's comment, in the terms above. Something like "asked whether the host knows the format at all, not whether it can be cast: on Windows drivers 8 of the 21 formats of castable(28) do not carry CAST_WITHIN_BIT_LAYOUT and are still castable in practice, so the strict bit would halve the list". The code is right; the next person to "improve" it needs the number, not the principle.

Two smaller things, both checked:

  • the 128-entry table is safe: castable() iterates 1..=115, so the HAS.get(format as usize) fallback to false cannot be reached by a format from this path. (I looked, because a fixed table with a silent false outside its range is the kind of thing that bites later.)
  • it does not collide with the other change in this file: merging this onto my GPU: drop the unordered-access permission a format cannot carry, before any call names it #1832 (which also asks CheckFeatureSupport for a format, for typed UAVs) is clean and builds — I tried it, in that order. Both ask the device once per format and cache; if the two caches are ever unified, that is a tidy-up for later and not a reason to hold either.

What I did not check: the Wine/Proton path, because this machine has no vkd3d-proton. The bug report and the fix are consistent with what vkd3d does (an unknown format refuses the whole EnhancedBarriersSupportedFormats list), and I have no way to reproduce it here — so on that half I am reading, not measuring, and saying so.

No game data is involved: format numbers and support masks.

Written with an AI assistant.

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

In resource.rs, make_texture now passes only the castable formats the host reports. host_has asks CheckFeatureSupport(FORMAT_SUPPORT) with Support1 != NONE and caches the answer per format. Before, one unknown format (89 on vkd3d-proton) made the host refuse the whole list. takes already reads t.castable, so texture sharing follows the filtered list. On Windows drivers it is a no-op: a commenter measured 21 of 21 formats kept on an RTX 4090. The 128-entry cache covers castable's 1..=115. The motivation is Wine/Proton, but the code is host-neutral and adds no platform-specific path. CI has not run on this head.


Generated by Claude Code

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.

5 participants