Repository navigation
d3d12: an sRGB render-target clear picks D3D's code instead of the driver's encode (D3D-993) - #9353
DeerSilver wants to merge 1 commit into
Conversation
…iver's encode (D3D-993) The colour channels of an R8G8B8A8/B8G8R8A8 sRGB clear went to Vulkan as the linear float, so the driver applied the sRGB curve and rounded it. WARP rounds to the nearest code; the Intel UHD Graphics driver (Xe-LP, Windows 101.7088) truncates, one code low whenever the encoded fraction is .5 or more (0.5 is 187.516: WARP 188, Intel 187). d3d12_clear_formats failed 10 of 251 there. quantize_srgb now picks D3D's code and hands Vulkan the linear value a quarter of a code above that code's start, which a rounding and a truncating encoder both store as that code. NaN is 0 and out-of-range values clamp, as for UNORM. clear_color_test checks the encoded value of what Vulkan gets lies in [code, code + 0.5) for both replay paths. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Grimkaaah
left a comment
There was a problem hiding this comment.
Independent Linux CPU review
Checked: quantize_srgb / sRGB encode path so clears match D3D vs truncating drivers (D3D-993); docs + clear_color_test notes. C++ clear path not built here.
Looks correct from review; no game files.
abnalstlll-byte
left a comment
There was a problem hiding this comment.
Independent Windows & MSVC Review
What changed:
runtime/src/vulkan_replay.h:- Implements
quantize_srgb()encoding linear clear colors to target sRGB values. - Ensures round-to-nearest (NVIDIA, WARP) and truncating (Intel) encoders both reproduce the exact expected D3D target code.
- Implements
Verification on Windows 11 host:
- Build passes under MSVC 19.44 / CMake.
clear_color_testpasses all test vectors.- Clean diff: no game files or retail assets.
LGTM!
al3xar
left a comment
There was a problem hiding this comment.
Independent Windows + GPU + Vulkan validation verification of 71e1959c2 (AI-assisted).
- Environment: Windows 11 x64, MSVC 19.44.35230.0 (Ninja Release), Windows SDK 10.0.26100.0, NVIDIA GeForce RTX 3060 (driver
621.24), Vulkan SDK1.4.363.0(LEONIDA_VK_VALIDATION=1), no game files. - Test runs (
LEONIDA_VK_VALIDATION=1):clear_color_test: PASS (521 full/rectangle integer, normalised and float replay checks passed, exit 0).d3d12_clear_formats_test: PASS (clears: 251 matched WARP, 0 differ, 0 failed, exit 0, 0 Vulkan validation errors).
- Code review:
quantize_srgbcleanly handlesNaN/<= 0(0.0f),>= 1(1.0f), and interior codes viasrgb_decode((code + 0.25) / 255.0), placing the linear float inside[code, code + 0.5)so both round-to-nearest and truncating GPU sRGB encoders produce the exact D3D code while leaving alpha on plain UNORM.- Built with 0 warnings in the changed files.
LGTM.
|
Tested
So NVIDIA's Vulkan driver already rounds the sRGB clear to the nearest code like WARP; the Intel UHD truncation doesn't happen here, and the CPU-side encode gives the same 251 answers. |
|
Verified on native Windows 11 (
AI-assisted. |
|
Tested 71e1959 on NVIDIA GeForce RTX 4080 SUPER, driver 621.24 (Vulkan 1.4.357), Windows 11 Pro 26300, MSVC 14.44, Ninja RelWithDebInfo (fresh build folder), applied on
(AI-assisted check, Claude Code.) |
|
Tested
Intel's driver encodes these sRGB clears one code lower than D3D (e.g. 12.648 → AI-assisted (Claude Code); run on my own machine, no game files involved. |
Claimed in the coordination issue as: D3D-993 (#9235 (comment); the finding: #9065 (comment))
Depends on: #5425 (conflicts: both change
render_target_clear_colorinruntime/src/vulkan_replay.h; whichever lands second needs a small rebase)What and why
render_target_clear_colorhanded the colour channels of anR8G8B8A8_SRGB/B8G8R8A8_SRGBclear to Vulkan as the linear float, so the driver applied the sRGB curve and rounded it. WARP rounds to the nearest code. The Intel UHD Graphics driver (Xe-LP, Windows 101.7088) truncates, one code low whenever the encoded value's fraction is .5 or more:bcbb0d0cfffeThat is the 10 of 251 clears
d3d12_clear_formatsfails on that GPU (D3D-993).The fix follows what the layer already does for UNORM/SNORM: the CPU picks the code.
quantize_srgbencodes the clamped linear value with the sRGB curve in double, rounds to nearest (ties to even,round_half_even), and hands Vulkan the linear value a quarter of a code above that code's start (srgb_decode((code + 0.25) / 255)). A rounding encoder and a truncating one both store it as that code; the exactsrgb_decode(code / 255)would not survive a truncating encoder, since float error can land it just below the code. Code 0 and 255 go as 0.0 and 1.0. NaN is 0 and out-of-range values clamp, as for UNORM. Alpha stays plain UNORM.clear_color_test's two sRGB rows used to require the linear input unchanged. They are replaced by five rows (including 0.0039 / 0.5019 / 0.9961, NaN, ±inf and out-of-range) that check, for both replay paths, that the encoded value of what Vulkan gets lies in[code, code + 0.5). That is exactly the condition for rounding and truncating encoders to agree. Thedocs/d3d12_vulkan.mdnote that called SRGB a 1-ulp driver difference now describes this.About #5425: its first commit had an
srgb_clear_value, but its current head45e81b28passes the sRGB colour through unchanged (vulkan_replay.h:1167, "the GPU's sRGB curve") and tolerates one code off. Built and run here on that head, the Intel UHD still gives241 matched WARP, 10 differ. So this PR doesn't duplicate it; the two touch the same function.Tested
Windows 11 26H2 (build 26300.9974), MSVC 2022 Build Tools (14.4x), Ninja RelWithDebInfo, Vulkan-Headers 1.4.363 (
LEONIDA_VULKAN_HEADERS_FETCH), on main6312c057f, with the layer on each GPU of one laptop viaLEONIDA_VK_DEVICE. No game files.d3d12_clear_formats, Intel UHD (Xe-LP, 101.7088)d3d12_clear_formats, RTX 5060 Laptop (621.24)ctest -R "^(clear_color|d3d12_clear_formats|d3d12_clear|d3d12_typeless_rtv|d3d12_typeless_families|typeless_rtv|d3d12_uav_clear)$": 7/7 on each GPU.clear_color_test: 521 checks.ctest(239 tests) on both GPUs: the only failures are onesmainhas as well on this machine.d3d12_vulkan_deviceandd3d12_depth_resolvefail on both GPUs; I comparedd3d12_vulkan_device's failure lines with and without the fix and they are identical. On the Intel UHD,d3d12_buffer_tilesandd3d12_dxr_validation_khralso fail; they fail to allocate synthetic buffers, the GPU has no mesh shaders or ray tracing, and they don't clear render targets.scripts/check_no_game_data.pypasses on the changed files.tests/test_docs_*.py: the same 3 failures as main (cli_flags,design_rows,links, in files this PR doesn't touch).LEONIDA_VK_VALIDATION=1(no validation layer installed here).AI-assisted: yes (Claude Code)
Checklist
docs/design.md, with how it was confirmed. (n/a: no translator change)🤖 Generated with Claude Code