Skip to content

d3d12: 8-bit sRGB UAV textures are mutable UNORM images where the sRGB format has no storage - #9531

Open
tibzejoker wants to merge 2 commits into
ItsNotRexed:mainfrom
tibzejoker:srgb-uav-backed
Open

tibzejoker wants to merge 2 commits into
ItsNotRexed:mainfrom
tibzejoker:srgb-uav-backed

Conversation

@tibzejoker

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue: #9235 (comment). The claim announced a proxy-side stand-in; I measured first and changed the approach, see below.

Depends on: #7604 (Format::uint_backed). This branch is #7604's head plus one commit.

What was wrong

The retail title sizes a 2D 2048x2048, 12-mip R8G8B8A8_UNORM_SRGB render target with ALLOW_UNORDERED_ACCESS through device slot 25. I measured it with a temporary log on slot 25, on my integration branch, where it is the next stop: 3 runs out of 3 stopped at 24 s on the title's 32-bit size check, the int3 at +0x344196.

The host runtime accepts that texture. Measured with a stand-alone D3D12 program on an RTX 4090 (617.42) and on WARP: GetResourceAllocationInfo answers 22,413,312 bytes for RT, RT+UAV and UAV alike, and CreateCommittedResource succeeds for all three. What D3D12 forbids is an sRGB typed UAV view, not the resource. So the proxy-side "drop the UAV flag" stand-in I first claimed would have been wrong.

The layer refused the texture because it made the Vulkan image in VK_FORMAT_R8G8B8A8_SRGB with STORAGE usage, which most GPUs, the RTX 4090 included, don't support.

The change

  • The image: where the 8-bit sRGB format has no storage support, an R8G8B8A8_UNORM_SRGB or B8G8R8A8_UNORM_SRGB texture with UAV becomes a mutable image of the UNORM format of the same order. Both formats are in its format list (Format::uint_backed, d3d12: B5G5R5A1 UAV textures are mutable R16_UINT images where A1R5G5B5 has no storage #7604's mechanism for B5G5R5A1 and R9G9B9E5). A probe at device creation (probe_uint_backed_uav(SRGB, UNORM)) checks the GPU can make that image.
  • The views: the storage view is UNORM, which is what every D3D12 typed UAV of these textures is, so shader stores and ClearUnorderedAccessViewFloat write raw bytes. SRVs are sRGB, so sampling decodes. RTVs are forced to the sRGB format, as d3d12: B5G5R5A1 UAV textures are mutable R16_UINT images where A1R5G5B5 has no storage #7604 does for A1R5G5B5, so clears and draws encode.
  • Unchanged: multisampled sRGB UAV textures stay refused. BGRA8 needs B8G8R8A8_UNORM storage. GPUs with native sRGB storage keep the plain path.
  • Docs: docs/d3d12_vulkan.md describes it next to the B5G5R5A1 entry.

Tested

RTX 4090 (617.42), Windows 11 26200, MSVC 2022 RelWithDebInfo, LEONIDA_VK_VALIDATION=1.

New d3d12_srgb_uav_test, against WARP, for RGBA8 and BGRA8:

  • The retail shape gets a size with WARP's alignment and is created.
  • A clear through the sRGB RTV writes the same encoded bytes as WARP (bc 89 e1 ff for 0.5/0.25/0.75/1).
  • A clear through a UNORM UAV writes the same raw bytes as WARP (80 40 bf ff).
  • 4x MSAA stays refused.
  • Result: 4 clears compared, 0 failures, 0 validation errors. Without the change it fails.

These pass on the same build: d3d12_b5g5r5a1_uav, d3d12_uav_clear, d3d12_clear, d3d12_clear_formats, d3d12_typeless_rtv, d3d12_descriptor, d3d12_texture1d_target, d3d12_placed_dimensions, d3d12_subresource_copy, device_proxy and xs_proxy_mock.

Retail (own 1.0.2.1 copy, on my integration branch with #9336, #7679 and #7759):

  • The log shows the texture is created, backed by UNORM, and slot 25 no longer refuses it.
  • In the longest of two runs, the boot ran 294 s, with 103,955 D3D12 calls and 2,336 ExecuteCommandLists (before: a stop at 24 s).
  • Both runs still end on the same size check later, from other descriptions that I'm looking at next.

AI-assisted: yes (Claude Code).

🤖 Generated with Claude Code

NiiRoZz and others added 2 commits November 23, 2026 18:06
…B5 has no storage

A B5G5R5A1_UNORM texture with ALLOW_UNORDERED_ACCESS was refused on a GPU whose
VK_FORMAT_A1R5G5B5_UNORM_PACK16 has no STORAGE_IMAGE (NVIDIA): GetResourceAllocationInfo answered
UINT64_MAX and creation failed. A title's boot creates a 2560x1440 render-target + UAV one and
asserts on that size.

The R9G9B9E5 route generalizes: Format::r9g9b9e5_as_r32_uint becomes Format::uint_backed, the format
a UAV texture stored as a mutable unsigned image is viewed in (E5B9G9R9 for R32_UINT, A1R5G5B5 for
R16_UINT). For B5G5R5A1 the image is R16_UINT with {R16_UINT, A1R5G5B5} listed; its storage view is
R16_UINT in the uint class, SRVs are A1R5G5B5 sampled views, and RTVs and clears go through an
A1R5G5B5 attachment view (ResourceBinding::uint_backed lets replay's color_view_format take it). The
SRV and UAV T#s keep the 1_5_5_5_UNORM format. A shader store still needs the translator to pack
the bits for that view, so CheckFeatureSupport does not advertise the typed UAV yet.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…B format has no storage

The host runtime sizes and creates R8G8B8A8_UNORM_SRGB and B8G8R8A8_UNORM_SRGB textures with
ALLOW_UNORDERED_ACCESS (RTX 4090 617.42 and WARP). The layer created their image in the sRGB format with
STORAGE usage, which most GPUs lack, so it refused them: a retail title sizes a 2048x2048, 12-mip
R8G8B8A8_UNORM_SRGB render target with unordered access through device slot 25, got UINT64_MAX and
stopped on its 32-bit size check.

Such a texture is now a mutable image of the UNORM format of the same order (Format::uint_backed, from
ItsNotRexed#7604), where the GPU can make that image with both formats listed. Its storage view is UNORM, as every
D3D12 typed UAV of these textures is; RTVs and SRVs are sRGB, so clears and draws encode and sampling
decodes. Multisampled ones are still refused.

d3d12_srgb_uav_test compares with WARP: the retail shape's size alignment and creation, a clear
through the sRGB RTV and one through a UNORM UAV, byte for byte, for RGBA8 and BGRA8. Without the
change it fails.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@VibeClauding

Copy link
Copy Markdown

Tested 57d08d2fd merged onto main 5d74c2723 on Windows 11 26200, MSVC 14.44 RelWithDebInfo, RTX 3070 (Ampere, NVIDIA 610.88): pass, with a negative control. This is a GPU with no native sRGB storage, so the new path is the one exercised.

  • With the PR: d3d12_srgb_uav and d3d12_b5g5r5a1_uav pass, plain and with LEONIDA_VK_VALIDATION=1. The layer logs 8-bit sRGB UAV unavailable natively, using a mutable UNORM image for formats 29 and 91. All four clears match WARP byte for byte: format 29 RTV bc 89 e1 ff, UAV 80 40 bf ff; format 91 RTV e1 89 bc ff, UAV bf 40 80 ff. 0 Vulkan validation errors.
  • Control (the PR's tests with main's runtime/shims + runtime/src): both fail. d3d12_b5g5r5a1_uav stops at line 129 (the 2560x1440 size check, d3d12: B5G5R5A1 UAV textures are mutable R16_UINT images where A1R5G5B5 has no storage #7604's part), and d3d12_srgb_uav fails too.

So the UAV clear writes UNORM bytes and the RTV clear writes sRGB-encoded bytes, as on the host runtime, on Ampere as well as on the 4090 in the description. #7604 merged cleanly underneath here.

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

@LukeOsland1

Copy link
Copy Markdown

Independent Windows verification on 57d08d2. I tested whether sampling through an sRGB SRV decodes a value written through a linear UNORM UAV on the same resource.

A synthetic compute probe cleared RGBA8_SRGB and BGRA8_SRGB textures through their UNORM UAVs to (0.5, 0.25, 0.75, 0.5), transitioned them, sampled 64 texel centers through sRGB SRVs and read back packed logical RGBA. All 64 texels in each format returned (55, 13, 132, 128) on each adapter. This checks channel order and linear alpha as well as sRGB decoding. Vulkan validation was enabled. On parent 0dc7f58 the BGRA probe failed at resource creation on the RTX.

Adapter Windows driver RGBA8 BGRA8 Unmodified clear comparison
RTX 4070 Ti SUPER 32.0.16.1088 64/64 64/64 4/4 matched WARP
AMD Radeon(TM) Graphics 32.0.21042.62 64/64 64/64 4/4 matched WARP

Both drivers advertised BGRA8_UNORM storage and neither advertised native storage for either sRGB format. The readback exercised the mutable UNORM resource path. WARP supplied the clear reference only. Windows 11 build 26300, MSVC 19.51.36248, Vulkan SDK 1.4.341.1. AI-assisted verification with synthetic inputs.

Coordination claim

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.

4 participants