Repository navigation
d3d12: 8-bit sRGB UAV textures are mutable UNORM images where the sRGB format has no storage - #9531
tibzejoker wants to merge 2 commits into
Conversation
…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>
|
Tested
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. |
|
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.
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. |
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_SRGBrender target withALLOW_UNORDERED_ACCESSthrough 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:
GetResourceAllocationInfoanswers 22,413,312 bytes for RT, RT+UAV and UAV alike, andCreateCommittedResourcesucceeds 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_SRGBwith STORAGE usage, which most GPUs, the RTX 4090 included, don't support.The change
R8G8B8A8_UNORM_SRGBorB8G8R8A8_UNORM_SRGBtexture 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.ClearUnorderedAccessViewFloatwrite 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.B8G8R8A8_UNORMstorage. GPUs with native sRGB storage keep the plain path.docs/d3d12_vulkan.mddescribes 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:bc 89 e1 fffor 0.5/0.25/0.75/1).80 40 bf ff).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_proxyandxs_proxy_mock.Retail (own 1.0.2.1 copy, on my integration branch with #9336, #7679 and #7759):
ExecuteCommandLists(before: a stop at 24 s).AI-assisted: yes (Claude Code).
🤖 Generated with Claude Code