Repository navigation
vulkan_replay: sRGB render-target clears are encoded in the layer, as WARP encodes them (D3D-CLEAR-SRGB-ENCODE) - #1179
Conversation
… WARP encodes them (D3D-CLEAR-SRGB-ENCODE) ClearRenderTargetView on R8G8B8A8_UNORM_SRGB and B8G8R8A8_UNORM_SRGB handed the linear float to vkCmdClearColorImage or vkCmdClearAttachments and the GPU encoded it. D3D permits FLOAT -> SRGB 0.6 of a step of tolerance and each implementation puts the steps between two codes somewhere else, so the byte depended on the GPU: against WARP, d3d12_clear_formats differed in 10 clears and d3d12_srgb_uav in 2 on an Intel Iris Xe (0.5 is bb there and bc on WARP), and an RTX 4060 passed because the five colours miss the values it encodes differently (3 648 of 60 000 random ones; the Iris Xe 6 649, never more than one code). render_target_clear_color now encodes the colour channels itself (srgb8_from_linear) the way WARP was measured to: the value to 12 bits with x * 4095 in single precision rounded half up, then the nearest code of the sRGB curve. All 255 floats at which WARP's byte changes are the ones this gives, and 84 582 further values agree. Vulkan gets the linear value of that code (srgb8_linear), which both GPUs store as that code for all 256. Alpha is unchanged. A GPU's own D3D12 driver encodes as its Vulkan driver does, so the layer now differs from that driver where it differs from WARP, as it does for UNORM ties and D24. d3d12_state_sweep_test compares with that driver and cleared its sRGB targets to 0.2, 0.4 and 0.6 (0.2 is 124 on WARP, 123 on the Iris Xe); it now starts them from the values of codes 124, 170 and 203. clear_color_test pins 38 values to WARP's bytes, the round trip of every code and the result under each rounding mode. d3d12_clear_formats_test clears the sRGB formats to the value of every code and of every place halfway between two codes as well: 178 of 352 cases differed from WARP on the Iris Xe and 170 on the RTX 4060 before, none after. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
abnalstlll-byte
left a comment
There was a problem hiding this comment.
Reviewed and verified. Eliminates vendor-specific 1-ulp clear variations on sRGB render targets (R8G8B8A8_UNORM_SRGB / B8G8R8A8_UNORM_SRGB) by performing software quantization via srgb8_from_linear / srgb8_linear in runtime/src/vulkan_replay.h, matching WARP 12-bit precision across 84,582 values and passing 593/593 cases in d3d12_clear_formats. 100% clean-room.
|
Tested
AI-assisted: yes |
|
Recommendation: [WAIT] Reasoning: Clears on sRGB render targets now encode the clear colour in the layer the way WARP does, instead of letting each GPU encode it, which removes vendor-dependent bytes (e.g. 0xbb vs 0xbc on Iris Xe). The analysis is thorough and four tests plus docs are updated. But the change affects every sRGB RTV clear, and it has only been measured on the author's Intel/NVIDIA machines with no second-person run. Get one independent run of Impact level: 5/10 |
|
@madhyn thank you for running this; a Wine run is one I can't do here.
What this commit cannot change is every difference you name. In the layer it changes What it can change is the SRGB group of Two things from the same setup would let the numbers be split, if you have the time:
On the independent run the triage comment asks for: agreed, and I can't supply it, since both GPUs in the description are mine. (Rerun just now on the RTX 4060, which has moved to NVIDIA 621.40: AI-assisted: yes |
|
Tested e2c13db applied onto main 66d4f5a on an AMD Radeon RX 7900 XT (AMD Radeon RX 7900 XT (RDNA3, gfx1100), AMD proprietary driver 32.0.32029.2010 (26.11.2), Windows 11 build 26300, VS 2022 RelWithDebInfo, Vulkan SDK 1.4.363.0). No game files.
This answers the open AMD question. So, for these values at least, AMD's native D3D12 encodes sRGB clears the same way WARP does. |
|
@MalexAson Here are the split numbers from the same Arch Linux + Wine 11.22 + RTX 3060 Ti setup:
AI-assisted: yes |
Claimed in the coordination issue as: D3D-CLEAR-SRGB-ENCODE
What and why
ClearRenderTargetViewonR8G8B8A8_UNORM_SRGBandB8G8R8A8_UNORM_SRGBhanded the linear float tovkCmdClearColorImageorvkCmdClearAttachmentsand the GPU encoded it, so the stored byte depended on the GPU. Against WARP,d3d12_clear_formatsdiffered in 10 clears andd3d12_srgb_uavin 2 on an Intel Iris Xe (0.5 isbbthere andbcon WARP).What I measured (the new "sRGB RTV clears" item in
docs/d3d12_vulkan.mdhas the details):mainonly because the five test colours miss those values.x * 4095in single precision, rounded half up) and then takes the nearest code of the sRGB curve. All 255 floats at which its byte changes are the ones this rule gives, and 84 582 further values agree.The change:
render_target_clear_colorencodes the colour channels itself by WARP's rule (srgb8_from_linear) and hands Vulkan the linear value of that code (srgb8_linear). Alpha is unchanged. This is whatquantize_unormdoes for UNORM ties.One thing for a maintainer to decide. A GPU's own D3D12 driver encodes as its Vulkan driver does, so the layer used to equal that driver and differ from WARP; now it equals WARP on every GPU and differs from that driver where the driver differs from WARP. I followed what the layer does for UNORM ties and D24: the layer converts, WARP is the reference, and a host that does otherwise is a host quirk. If you would rather keep the GPU's encoding, the alternative is to leave the layer alone and compare the sRGB colour channels with WARP within one code in the two tests. Say so and I will redo it that way.
d3d12_state_sweep_testcompares with the same adapter's D3D12 driver and cleared its sRGB targets to 0.2, 0.4 and 0.6, of which Intel's driver stores the first two as 123 and 169 where WARP has 124 and 170. With the layer change it differed in 4 of 482 cases on the Iris Xe, so its sRGB targets now start from the values of codes 124, 170 and 203, which every implementation measured stores alike. The sweep is about blending.Not changed: a draw into an sRGB target is still encoded by the GPU, and
d3d12_clear_teststill compares castable sRGB views within 1.Tested
On
main6293c1c with MSVC 14.50 (Build Tools 2026), RelWithDebInfo, WARP 10.0.26100.5074, each on both GPUs throughLEONIDA_VK_DEVICE:d3d12_clear_formats: before, 241 matched WARP and 10 differ on the Iris Xe (251 and 0 on the RTX 4060). With the extended sRGB colours on the unfixed layer, 178 of the 352 sRGB cases differ on the Iris Xe and 170 on the RTX 4060. After: 593 matched and 0 differ on both.d3d12_srgb_uav: before, 2 of 4 clears differ on the Iris Xe; after, 0 failures on both.clear_color(no GPU): 567 checks pass.ctestfor the 23 tests that clear or present sRGB targets or use the changed code (d3d12_clear,d3d12_clear_restricted_depth,d3d12_clear_formats,d3d12_srgb_uav,d3d12_uav_clear,d3d12_short_uav_clear,d3d12_typeless_rtv,d3d12_typeless_families,d3d12_typeless_depth,d3d12_state_sweep,d3d12_draw,d3d12_present,d3d12_close_parity,d3d12_vulkan_device,dxgi_swapchain,xbox_present,xs_proxy_mock,vk_presenter_sync,typeless_rtv,clear_color,replay_clear_gate,replay_uav_clear_offset,d3d12_rgb9e5_rtv): on both GPUs 21 pass,d3d12_rgb9e5_rtvskips andd3d12_vulkan_devicefails. It fails the same way without this change (three resource-flag cases ofcompare_invalid_argumentsagainst the host runtime), which has nothing to do with clears.ctest(only these targets were built),LEONIDA_VK_VALIDATION=1(no validation layer on this PC), an AMD GPU, Linux.GPUs tested: Intel Iris Xe (Raptor Lake-P, 8086:a7a0), Intel 32.0.101.7092, Windows 11 build 26100; NVIDIA GeForce RTX 4060 Laptop GPU, NVIDIA 616.92, Windows 11 build 26100
AI-assisted: yes
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed. (not applicable: no translator change)🤖 Generated with Claude Code