Skip to content

d3d12: sRGB and depth-only textures with unordered access created as the host does (D3D-466) - #4493

Open
martingouv wants to merge 2 commits into
ItsNotRexed:mainfrom
martingouv:d3d-466-uav-srgb-depth
Open

martingouv wants to merge 2 commits into
ItsNotRexed:mainfrom
martingouv:d3d-466-uav-srgb-depth

Conversation

@martingouv

Copy link
Copy Markdown

D3D-466 (listed in #313; claimed in #4421 (comment)). Found by @gabsilvs in #4257 (comment).

What was wrong

TextureCreateInfo (runtime/shims/d3d12_vulkan_device.cpp) gave every texture with ALLOW_UNORDERED_ACCESS VK_IMAGE_USAGE_STORAGE_BIT. For typed R8G8B8A8_UNORM_SRGB, B8G8R8A8_UNORM_SRGB, D32_FLOAT and D16_UNORM the Vulkan format may have no storage feature, so check_image_support refused a texture the host creates. D3D12 has no UAV view in these formats, and without a castable-format list no view leaves the resource's format, so the image never needs storage usage.

The change

  • These four typed formats get no storage usage (nor the UAV-clear attachment usage that goes with it) unless the texture has a castable-format list, which keeps today's behaviour for that case.
  • The new host comparison showed what the storage bit had been refusing by chance, and the layer now refuses it explicitly in texture_format, so creation and GetResourceAllocationInfo agree with the host on every driver:
    • unordered access on D24_UNORM_S8_UINT and D32_FLOAT_S8X24_UINT (the host refuses it);
    • a volume texture in any depth format, with or without flags (the host refuses it; the layer created D32_FLOAT/D16_UNORM/... 3D textures before).
  • docs/d3d12_vulkan.md: one bullet next to the B8G8R8X8 (D3D-87) one.

Test

d3d12_vulkan_device_test gets a host comparison next to D3D-87's: 6 formats (the four above plus D24S8 and D32S8) x 1D/2D/3D x {no flags, ALLOW_UNORDERED_ACCESS}, comparing CreateCommittedResource success and whether GetResourceAllocationInfo gives a size. All mismatches are printed before the test fails.

  • Before the change, on the RTX 5060 Ti host: 12 of 72 mismatches (sRGB + UAV refused in 1D/2D/3D; depth formats in 3D accepted).
  • After: 0 of 72, against the NVIDIA host and against WARP (LEONIDA_HOST_ADAPTER=warp).
  • ctest --test-dir runtime/build: 147 of 147 pass (10 skipped/disabled that need game files or other hardware).

Tested on Windows 11 (10.0.26200), NVIDIA GeForce RTX 5060 Ti, driver 621.24, MSVC 2022 Build Tools, Vulkan SDK 1.4.363. Not tested on AMD, where the finding saw D32_FLOAT/D16_UNORM refused too; a check there is welcome.

AI-assisted (Claude Code).

🤖 Generated with Claude Code

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

Built and ran d3d12_vulkan_device_test at 8c51f567 on Windows 11, RTX 5070 Ti: exit 0; the full device suite passes, including the sRGB/depth-only UAV cases and the placed castable-format comparison. No blocking issue.

@paratustra

Copy link
Copy Markdown
Contributor

Code read at 8c51f56 (not built). One path the new differential test doesn't reach: GetResourceAllocationInfo for a depth format that has both ALLOW_DEPTH_STENCIL and ALLOW_UNORDERED_ACCESS.

  • Creation refuses that combination explicitly (committed_resource_refusal, (ds && uav) → "resource flag combination", ~line 1382).
  • allocation() (~6791) has no such rule. On main, a UAV on D32_FLOAT or D16_UNORM made the image ask for storage usage, which those Vulkan formats lack, so allocation() failed by that route.
  • With this change, typed_without_uav covers D32_FLOAT and D16_UNORM, so no storage usage is requested and nothing else refuses the pair.

As far as I can tell from the code, D32_FLOAT with ALLOW_DEPTH_STENCIL | ALLOW_UNORDERED_ACCESS now gets a real size, where the host returns the invalid answer (SizeInBytes UINT64_MAX). The test loops over flags {NONE, UAV} only. Adding ALLOW_DEPTH_STENCIL | ALLOW_UNORDERED_ACCESS to it would settle this. If it fails, moving the ds && uav rule into allocation() would make creation and allocation info agree.

No game files. AI-assisted (Claude Code).

@itsonlysimbo

Copy link
Copy Markdown
Contributor

Tested 8c51f567 on RTX 4070, NVIDIA 621.14, Windows 11 (10.0.26300), MSVC 19.44, Ninja, RelWithDebInfo, Vulkan SDK 1.4.363: pass.

  • d3d12_vulkan_device passes.
  • ctest: 145 passed, 10 skipped, 0 failed; run_gpu_tests.py: 164/210 passed, 46 skipped, 0 failed, same as main 03b09a08.

AI-assisted (Claude Code).

@mrbean56

Copy link
Copy Markdown

Reading review (no Windows/Vulkan-on-Windows here): the reasoning is sound and the change is narrowly scoped.

Cannot run the Windows test. No game data. AI-assisted.

@justr4mzi

Copy link
Copy Markdown
Contributor

Verified 8c51f567 on Windows 11 25H2 + AMD Radeon RX 6700 XT (gfx1031, Adrenalin 26.11.2, Vulkan 1.4.315, MSVC 19.44.35230.0 RelWithDebInfo).

Hardware & validation results (standard and LEONIDA_VK_VALIDATION=1 + VK_LAYER_KHRONOS_validation)

  • Built d3d12_vulkan_device_test.exe ([11/11], 0 compiler warnings).
  • Both runs report 0 Vulkan validation errors on AMD Radeon RX 6700 XT and pass all D3D-466 and comparison checks:
    • sRGB/depth with unordered access: resource creation and allocation match the host runtime
    • B8G8R8X8: typed UAV support and UAV/RTV resource creation match the host runtime
    • copy comparison: 0 of 75 cases differ from the host (including R8G8B8A8_UNORM_SRGB 108 regions, D16_UNORM 36 regions, D32_FLOAT 36 regions, D32_FLOAT_S8X24_UINT 72 regions, BC1_UNORM_SRGB 108, BC7_UNORM_SRGB 108)
    • new formats: 11 of 11 created and copied both ways bit for bit (host compared), 10 render-target clears matched the host, A4B4G4R4 render target cleared to R, G, B and A, 0 failures
  • Note: the executable exits 1 only at pre-existing elevated-session host check d3d12_vulkan_device_test.cpp:5244 (command_queue(host.p, rt_desc) == S_OK, #2422), unrelated to this PR.

Docs & hygiene checks

  • All 7 tests/test_docs_*.py suites: 7/7 passed.
  • python -I scripts/check_no_game_data.py (rc=0), git diff --check clean.

AI-assisted (Gemini, Antigravity).

@Alpaca-exe

Copy link
Copy Markdown
Contributor

AI-assisted Windows hardware verification for D3D-466 on AMD Radeon RX 6750 XT (0x1002:0x73df, RDNA2, Windows 11, AMD driver 26.11.2 / 32.0.21045.29003, Vulkan 1.4.315, MSVC 19.44.35230.0, VK_LOADER_LAYERS_DISABLE=~implicit~):

  • Built d3d12_vulkan_device_test from commit 8c51f567d (rc=0).
  • Ran d3d12_vulkan_device_test.exe with LEONIDA_D3D49_VERBOSE=1 against the host Windows D3D12 runtime: rc=0 (1080 verbose lines).
  • All 17 D3D-466 / sRGB / depth / UAV / D3D-90 placed castable checks matched the host runtime:
  sRGB/depth with unordered access: resource creation and allocation match the host runtime
  copy case R8G8B8A8_UNORM_SRGB: matches the host (108 regions)
  copy case D16_UNORM: matches the host (36 regions)
  copy case D32_FLOAT: matches the host (36 regions)
  copy case D24_UNORM_S8_UINT: matches the host (72 regions)
  copy case D32_FLOAT_S8X24_UINT: matches the host (72 regions)
  copy case BC1_UNORM_SRGB: matches the host (108 regions)
  copy case BC7_UNORM_SRGB: matches the host (108 regions)
  depth24 typeless: R24G8_TYPELESS with a D24 DSV, 200 values, match the host
  invalid arguments committed: plain texture in UNORDERED_ACCESS state: ours 0x80070057 host 0x80070057
  invalid arguments committed: UAV texture in UNORDERED_ACCESS state: ours 0x00000000 host 0x00000000
  invalid arguments committed: buffer in RENDER_TARGET | UNORDERED_ACCESS state: ours 0x00000000 host 0x00000000
  invalid arguments placed: depth texture with ALLOW_UNORDERED_ACCESS: ours 0x80070057 host 0x80070057
  invalid arguments placed: upload buffer with ALLOW_UNORDERED_ACCESS: ours 0x80070057 host 0x80070057
  invalid arguments placed: plain texture in UNORDERED_ACCESS: ours 0x80070057 host 0x80070057
  invalid arguments reserved: D24S8 depth texture: ours 0x80070057 host 0x80070057
  placed castable formats (D3D-90): SRGB-cast and plain clears read back and compared with the host runtime on AMD Radeon RX 6750 XT (the layer's own adapter); refusals matched the host's
[rt] d3d12: CreateCommittedResource refused (UNORDERED_ACCESS state without ALLOW_UNORDERED_ACCESS), dimension 3
[rt] d3d12: CreatePlacedResource refused (UNORDERED_ACCESS state without ALLOW_UNORDERED_ACCESS), dimension 3

@memorypressure

Copy link
Copy Markdown

Merges cleanly into main 3faac55; compileall clean, the three docs guards over d3d12_vulkan.md green, and nothing on main mentions D3D-466 (no supersession). The format logic reads consistently — the same texture_format() gates both CreateCommittedResource and GetResourceAllocationInfo, D32_FLOAT/D16_UNORM keep UAV while the sRGB and D24/D32S8 pair lose storage usage exactly as the doc row claims. Two concerns: the branch reports no CI checks at all, and the new 38-line case is gated on a host D3D12 device — on Linux it prints skipped, so right now nothing executes it. A push to trigger CI plus one Linux-reachable assertion would fix the coverage hole. One question: should CreateUnorderedAccessView on such a resource now be refused up front, since the only remaining signal is the later vkCreateImageView failure (note_storage_image is bookkeeping, not a usage upgrade)? AI-assisted: yes. Tested on Linux (RTX 5080 host, CPU-only run).

@SpositoDouglas

Copy link
Copy Markdown
Contributor

A gap I hit while rebasing #4581, which carries this PR's commit. This PR's test doesn't cover it.

On an RX 9060 XT (AMD Software 26.11.2), a typed R8G8B8A8_UNORM_SRGB or B8G8R8A8_UNORM_SRGB texture with ALLOW_UNORDERED_ACCESS and a castable-format list naming its UNORM format is refused with E_INVALIDARG, committed and placed alike.

  • With a list, TextureCreateInfo gives the image VK_IMAGE_USAGE_STORAGE_BIT (castable_list || !typed_without_uav(...)). That part is right: a UAV view in the listed UNORM format needs it.
  • But the image is created in the sRGB format, and that format has no STORAGE_IMAGE feature here in optimal tiling (vulkaninfo --show-formats; R8G8B8A8_UNORM has it).
  • Without VK_IMAGE_CREATE_EXTENDED_USAGE_BIT, every usage must be one the image's own format supports. So check_image_support answers E_INVALIDARG.
  • Measured at 64x64, and at 256x256 and 2048x2048 with full chains.

A possible fix, the one #4581 uses for B8G8R8X8: when an image gets storage usage its own format can't take, add VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT | VK_IMAGE_CREATE_EXTENDED_USAGE_BIT. Its views in formats without storage then stay sampling-only, through VkImageViewUsageCreateInfo, as bind_image does there with extended_usage.

This is the layer's side only. I haven't measured what the host runtime answers for this texture, or what a store through the UNORM view writes.

AI-assisted (Claude Code). No game data.

martingouv and others added 2 commits November 23, 2026 16:45
…the host does (D3D-466)

Typed R8G8B8A8_UNORM_SRGB, B8G8R8A8_UNORM_SRGB, D32_FLOAT and D16_UNORM have no
UAV view in D3D12 without a castable-format list, so their UAV-flagged images no
longer get VK_IMAGE_USAGE_STORAGE_BIT, which these Vulkan formats lack. The host
creates them; the layer refused them (sRGB on NVIDIA, all four on AMD).

The test this adds also showed what the storage bit had been refusing by chance:
the host refuses unordered access on D24_UNORM_S8_UINT and D32_FLOAT_S8X24_UINT,
and any volume texture in a depth format (with or without flags). Both are now
refused explicitly, in creation and GetResourceAllocationInfo alike.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- GetResourceAllocationInfo refuses ALLOW_DEPTH_STENCIL with ALLOW_UNORDERED_ACCESS,
  as creation does and the host answers (paratustra): with D32_FLOAT/D16_UNORM no
  longer asking for storage usage, nothing else refused the pair.
- CreateUnorderedAccessView refuses a view whose format is a typed sRGB or depth
  one, as it does for B8G8R8X8 (memorypressure).
- The host comparison adds the DEPTH_STENCIL | UNORDERED_ACCESS flags, and the
  answers are also pinned without a host device, so Linux and Wine run them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@martingouv
martingouv force-pushed the d3d-466-uav-srgb-depth branch from 8c51f56 to c0e3b80 Compare November 23, 2026 15:53
@martingouv

Copy link
Copy Markdown
Author

Thanks all. Rebased on main (f5ff1546e) and pushed c0e3b8082 with the follow-ups:

  • @paratustra: confirmed. With the pair added to the host comparison, D32_FLOAT/D16_UNORM with ALLOW_DEPTH_STENCIL | ALLOW_UNORDERED_ACCESS got a size from GetResourceAllocationInfo where the host answers UINT64_MAX (4 mismatches, 2D and 1D). allocation() now refuses ds && uav as committed_resource_refusal does. The test loops over {NONE, UAV, DS | UAV}.
  • @memorypressure: the answers are now also pinned outside the host block (sRGB/D32/D16 + UAV create and are sized; D24S8/D32S8 + UAV, a 3D D32_FLOAT and D32_FLOAT with DS | UAV are refused), so Linux and Wine run them. On CreateUnorderedAccessView: yes, it now refuses a view whose format (the view's, else the resource's) is one of these four, as it already did for B8G8R8X8. A UNORM view of a castable sRGB texture still goes through. CI needs a maintainer's approval for a fork PR.
  • @SpositoDouglas: agreed, that one is real, but it isn't new here. With a castable list this PR keeps main's storage usage on purpose, so a sRGB image with a UNORM-castable list is refused on drivers without sRGB storage, as on main. The EXTENDED_USAGE route you describe belongs with RT-303: typed B8G8R8X8 textures with unordered access through a castable-format list #4581's B8G8R8X8 change, so I've left it to that PR rather than fixing it twice.
  • @mrbean56: the asymmetry is on purpose. The stencil formats are refused up front in texture_format, which says so.

Thanks @Kam471, @itsonlysimbo, @justr4mzi and @Alpaca-exe for the runs. The two AMD ones cover what I couldn't test.

Re-tested c0e3b8082 on Windows 11, RTX 5060 Ti, NVIDIA 621.24, against the NVIDIA host and against WARP: the D3D-466 block matches the host (0 mismatches). ctest: 254 of 256. The two failures, d3d12_vulkan_device stopping at tiles == 1 (reserved RGBA8 tiling, CreateReservedResource2) and d3d12_indirect_dispatch_count, fail the same way on unmodified main f5ff1546e on this machine, so they're not from this PR.

AI-assisted (Claude Code).

@thehollowedone

Copy link
Copy Markdown

Independent native Windows check of c0e3b808. RTX 3080 Ti, NVIDIA 621.35, Vulkan SDK 1.4.363.0.

The focused d3d12_vulkan_device run matched native D3D12 on the same RTX and WARP in all 16 valid creation and allocation-query cases. These covered typed RGBA8 and BGRA8 sRGB, D32_FLOAT, and D16_UNORM in 1D and 2D, with and without the unordered-access flag. Each case checked successful creation and a finite allocation size. Khronos core and synchronization validation reported zero errors.

The adapter reported no optimal-tiling storage support for either sRGB format. This run covered creation and allocation queries, without a castable UAV write.

AI-assisted.

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.

10 participants