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 1 commit into
ItsNotRexed:mainfrom
martingouv:d3d-466-uav-srgb-depth
Open

martingouv wants to merge 1 commit 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

…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>

@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

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

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

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.

7 participants