vulkan_replay: sRGB render-target clears are encoded in the layer, as WARP encodes them (D3D-CLEAR-SRGB-ENCODE) #1179
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1179"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from ubiquitarianism/leonida. Originally posted by MalexAson on 2026-11-24T19:40:57Z.
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
main6293c1c4fwith 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
Imported from ubiquitarianism/leonida. Originally posted by abnalstlll-byte on 2026-11-24T19:42:33Z.
Review: APPROVED
Reviewed and verified. Eliminates vendor-specific 1-ulp clear variations on sRGB render targets (
R8G8B8A8_UNORM_SRGB/B8G8R8A8_UNORM_SRGB) by performing software quantization viasrgb8_from_linear/srgb8_linearinruntime/src/vulkan_replay.h, matching WARP 12-bit precision across 84,582 values and passing 593/593 cases ind3d12_clear_formats. 100% clean-room.Imported from ubiquitarianism/leonida. Originally posted by madhyn on 2026-11-24T20:09:42Z.
Tested
e2c13db54on Arch Linux + Wine 11.22 + NVIDIA RTX 3060 Ti (595.58.03 / Vulkan):clear_color(Linux): Passed (0.01 s)d3d12_state_sweep(Wine): Skippedd3d12_clear(Wine): Failed (6.26 s — host D3D12 under Wine differs from WARP, e.g.R8G8B8A8_UNORM case 0 byte 2: Vulkan 80, WARP 7f,R8G8_UINT case 3 byte 13: Vulkan ff, WARP 00)d3d12_clear_formats(Wine): Failed (clears: 324 matched WARP, 269 differ, 0 failed— Wine host D3D12 vs layer differences onUINT/SINT/D16/D24S8/D32S8)AI-assisted: yes
Imported from ubiquitarianism/leonida. Originally posted by Deedlyy on 2026-11-24T20:09:47Z.
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
d3d12_clear_formats/clear_color/d3d12_srgb_uavon AMD or NVIDIA before merging. CI (label, change-scope, no-game-data and the Runtime jobs) is still queued awaiting maintainer workflow approval, so nothing has run in CI yet; GitHub reports no merge conflict withmain.Impact level: 5/10
Imported from ubiquitarianism/leonida. Originally posted by MalexAson on 2026-11-24T20:26:19Z.
@madhyn thank you for running this; a Wine run is one I can't do here.
clear_colorpassing andd3d12_state_sweepskipping are as expected (the sweep already has thehost_wine.hskip). The two failures are a comparison with vkd3d, not with WARP:d3d12_clearandd3d12_clear_formatstake their reference fromEnumWarpAdapter, which under Wine is vkd3d, and onmainneither has thehost_wine.hskip. #1086 adds it and reports both failing onmainunder WineHQ 11.22 (integer clears saturate differently, SNORM -1, D32S8 stencil).What this commit cannot change is every difference you name. In the layer it changes
render_target_clear_coloronly for the three colour channels ofR8G8B8A8_UNORM_SRGBandB8G8R8A8_UNORM_SRGB; UNORM, UINT and SINT go through the same branches as onmain, depth clears are a separate path, andd3d12_clear_test.cppchanged in two comments only.80against7fis the 0.5 UNORM tie, which the layer already rounds itself onmain.What it can change is the SRGB group of
d3d12_clear_formats, and your total shows it did. That group has 352 cases here instead of 10, and only 241 of the 593 cases are outside it, so at least 28 of your 269 are SRGB lines; the five groups you list hold at most 127. I expect that against a reference that lets the GPU encode: the layer now follows WARP's rule, and half of the added values sit where implementations disagree (my RTX 4060's own encoding differed from WARP on 170 of the 352). I haven't measured what vkd3d stores, so that is an expectation, not a result. That comparison is with vkd3d, so it doesn't measure the change against WARP, and with #1086 the test skips under Wine.Two things from the same setup would let the numbers be split, if you have the time:
d3d12_clearandd3d12_clear_formatson unchangedmain(6293c1c4f).DIFFlines ofd3d12_clear_formatsstart withDIFF SRGB.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:
d3d12_clear_formats593 matched and 0 differ,d3d12_srgb_uav0 failures,clear_colorpasses.) What would settle it isd3d12_clear_formats,d3d12_srgb_uavandclear_coloron native Windows, on an AMD GPU or on someone else's NVIDIA one; the first two compare with Microsoft's WARP, so Wine can't stand in.AI-assisted: yes
Imported from ubiquitarianism/leonida. Originally posted by adrianmjim on 2026-11-24T21:42:53Z.
Tested
e2c13db54applied onto main66d4f5aa3on 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.66d4f5aa3clear_color(no GPU)d3d12_clear_formatsd3d12_vulkan_deviced3d12_state_sweep,d3d12_typeless_rtv,d3d12_rgb9e5_rtv,d3d12_clear_restricted_depthd3d12_clearctestd3d12_texture_tiles#964,d3d12_close_parity, since fixed by #1286,d3d12_clear#787)This answers the open AMD question.
d3d12_vulkan_devicecompares an sRGB-cast clear of {0.25, 0.5, 0.75} on a placed castable resource with the host runtime on the layer's own adapter, here the AMD D3D12 driver. It still passes with the WARP-style encoding:So, for these values at least, AMD's native D3D12 encodes sRGB clears the same way WARP does.
Imported from ubiquitarianism/leonida. Originally posted by madhyn on 2026-11-24T21:47:58Z.
@MalexAson Here are the split numbers from the same Arch Linux + Wine 11.22 + RTX 3060 Ti setup:
main(6293c1c4f):d3d12_clear_test.exe: exit1—d3d12_clear_test: 20 color/depth format(s) differ from WARPd3d12_clear_formats_test.exe: exit1—clears: 152 matched WARP, 99 differ, 0 failed(8DIFF SRGBlines,91non-SRGB)e2c13db54):d3d12_clear_formats_test.exe: exit1—clears: 324 matched WARP, 269 differ, 0 failedDIFF SRGBlines: 178 of 269 (leaving the exact same 91 non-SRGB vkd3d diffs asmain).AI-assisted: yes
Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-11-28T21:19:30Z.
Review: COMMENTED
Merged "
e2c13db54" locally with current main "aa918e5d9". Windows 10 22H2, MSVC 19.44: clear_color_test passed all 567 full and rectangular replay checks, including the sRGB command-value checks. This is CPU replay coverage.AI-assisted.
Imported from ubiquitarianism/leonida. Originally posted by zmasi on 2026-11-29T02:00:27Z.
Verification Report (
e2c13db54amerged intomain59e65849b0)610.88, subgroup32..32) + native Windows Microsoft WARP, Vulkan SDK1.4.363.1(LEONIDA_VK_VALIDATION=1withVK_LAYER_KHRONOS_validation). No game data used (check_no_game_data.pyrc=0).e2c13db54acleanly intoorigin/main(59e65849b0, 0 conflicts; 6 files changed:docs/d3d12_vulkan.md,runtime/src/vulkan_replay.h,runtime/test/clear_color_test.cpp,runtime/test/d3d12_clear_formats_test.cpp,runtime/test/d3d12_clear_test.cpp,runtime/test/d3d12_state_sweep_test.cpp). Verifiedsrgb8_from_linear(roundingdouble(value) * 4095.0to 24-bit single-precision mantissa viafrexp/ldexp/round_half_evenindependent of host FP rounding mode, thenfloor(single + 0.5) / 4095.0-> IEC 61966-2-1 nearest 8-bit code) andsrgb8_linear(center linear float of the target code for RGB channels while keeping alpha on linear UNORM quantization).Red -> Green Results (Independent Native Windows NVIDIA + WARP + Validation Run)
mainvulkan_replay.h+#1179testsmain+#1179(e2c13db54a,LEONIDA_VK_VALIDATION=1)d3d12_clear_formats_test(RTX 3090 vs WARP)rc=1:clears: 428 matched WARP, 170 differ, 0 failed— all 170 diffs areDIFF SRGB, matching the 170/352 NVIDIA hardware sRGB step differences measured on RTX 4060)rc=0:clears: 598 matched WARP, 0 differ, 0 failed, 0 in formats the layer does not expose, 0 skipped,0validation errors)d3d12_srgb_uav_test(RTX 3090 vs WARP)rc=0:8-bit sRGB UAV textures: 4 clears compared with WARP, 0 failures, 0 Vulkan validation errors)clear_color_test(CPU replay)rc=0:567 full/rectangle integer, normalised, sRGB and float replay checks passed)d3d12_state_sweep_test(RTX 3090 vs native D3D12)rc=0:498 cases compared with NVIDIA GeForce RTX 3090, 0 differ; 0 skipped,0validation errors)d3d12_clear_test(RTX 3090 vs WARP)rc=0:RTV and DSV clears: 232 full/rectangle readbacks matched WARP,0validation errors)test_docs_table_rows.py&test_docs_encoding.pyrc=0)mainand passes 598/598 against WARP and 498/498 ind3d12_state_sweepwith 0 validation errors).AI-assisted.
Imported from ubiquitarianism/leonida. Originally posted by enlight3d on 2026-11-29T09:03:25Z.
RUN #1179 | head
e2c13db54a, merged cleanly with main54b2a81e95(local merge, not pushed)Commands (from the repository root, in a worktree):
Green (merged tree, GPU tests one at a time):
clear_color,d3d12_clear_formats,d3d12_clear,d3d12_state_sweep,d3d12_srgb_uav,replay_clear_gateall pass (6/6).Red, with the PR's tests kept and only
runtime/src/vulkan_replay.hchanged:render_target_clear_colorthat encodes the sRGB colour channels is removed.clear_colorfails (0.5 on an sRGB target is passed on as 0.5, which encodes to 187.5, expected code 188) andd3d12_clear_formatsfails (428 matched WARP, 170 differ).d3d12_clear,d3d12_state_sweepandd3d12_srgb_uavstill pass in that state on this GPU.vulkan_replay.hfully reverted to main,clear_color_testdoes not build (srgb8_linearis not a member ofleonida::detail).Link: no new imports vs main (gta6rt.exe, 723 DLL!symbol entries, same list as the baseline built from main).
The description asks a maintainer to decide between the layer encoding like WARP (this change) and keeping each GPU's own encoding; I did not weigh in on that, only checked that the tests behave as described on an RTX 3090.
Machine: RTX 3090 24 GB, NVIDIA 621.40, Windows 11 Pro 10.0.26300, MSVC 19.44, Vulkan SDK 1.4.363.1.
Imported from ubiquitarianism/leonida. Originally posted by enlight3d on 2026-11-29T18:22:53Z.
RUN #1179 | head
e2c13db54a, merged cleanly with main4364a4fa61(local merge, not pushed)Commands (repository root, temporary worktree):
Green (merged): 5 passed (
clear_color,d3d12_clear,d3d12_clear_restricted_depth,d3d12_clear_formats,d3d12_state_sweep);d3d12_rgb9e5_rtvreports Skipped here (same on main, it is not about sRGB).Red:
runtime/src/vulkan_replay.hand the doc taken back from main, tests kept.clear_color_test: build failure only (srgb8_linearandsrgb8_from_lineardo not exist inleonida::detail).d3d12_clear_formats(builds on main, only uses the D3D12 API) FAILS with the layer change reverted;d3d12_clear,d3d12_clear_restricted_depthandd3d12_state_sweepstill pass, so those three do not detect the change on this GPU.Link: no new imports vs main (gta6rt.exe, 723 DLL!symbol entries on both, dumpbin /imports).
#2566: no conflict with #2566 (merge-tree of the two heads is clean).
Machine: RTX 3090 24 GB, NVIDIA 621.40, Windows 11 Pro 10.0.26300, MSVC 19.44, Vulkan SDK 1.4.363.1.
Imported from ubiquitarianism/leonida. Originally posted by merzleckeier on 2026-11-29T18:41:44Z.
Independent native Vulkan replay check of
e2c13db54onmain7c330c76(merge tree4497bc4a). CachyOS, clang 23.1.5, AMD Raphael iGPU / RADV Mesa 26.3.1 and RTX 4070 SUPER / NVIDIA 620.73.04. Khronos validation 1.4.363 with synchronization validation enabled.A synthetic fixture called the real
leonida::replayclear path and read every pixel back from 4×4 images. It ran 98 clear colors per path across RGBA/BGRA, typed/UNORM-backed sRGB views, and whole-view/rectangle clears. The references are the 38 WARP-recorded points fromclear_color_testplus 255 analytical sRGB half-code inputs evaluated with the documented WARP model. The typed whole-view path usedvkCmdClearColorImage; rectangles and cast views usedvkCmdClearAttachments.mainRGB bytes differentmain+ PRThe RADV typed whole-image clear on
mainstored 255 for the tested NaN in both formats (WARP reference 0). All other deviations were at most one code. Alpha and the pixels outside each rectangle matched on both revisions, with zero validation errors. The stock CPUclear_color_testalso passed all 567 checks. Synthetic inputs only. AI-assisted with OpenAI Codex.Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-29T19:00:25Z.
Merging. Head
e2c13db54has red/green verdicts from reviewers other than the author (above), merges cleanly withmain947c54aba, does not force a rebase of #2566, and carries a claim ID. Remaining main CI reds (translator-testsmesh,semantic-testsf16) are pre-existing. Merged by MoonEyes.AI-assisted (Claude Code).