Repository navigation
d3d12: a Uint UAV clear of a typeless texture writes its bits exactly (NaN payloads, SNORM 0x80) - #5537
d3d12: a Uint UAV clear of a typeless texture writes its bits exactly (NaN payloads, SNORM 0x80)#5537Exopus-0x65f7ad0 wants to merge 4 commits into
Conversation
|
Independent Windows check of ff639993 on 3faac557. RTX 3080 Ti / 621.35, Windows 11, MSVC 19.44.35230, Vulkan SDK 1.4.363.0. The stock The scratch GPU fixture ran six fixed synthetic cases. Core and synchronization validation reported zero errors. AI-assisted. |
Kam471
left a comment
There was a problem hiding this comment.
Review at head ff6399937 (Windows 11, RTX 5070 Ti; RelWithDebInfo + Ninja + Vulkan 1.4.363).
Setup: cmake -S runtime -B b5537 -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DBUILD_TESTING=ON -DLEONIDA_BUILD_WINDOWS_RUNTIME=ON -DVulkan_INCLUDE_DIR=C:/VulkanSDK/1.4.363.0/Include -DVulkan_LIBRARY=C:/VulkanSDK/1.4.363.0/Lib/vulkan-1.lib.
Commands / results (LEONIDA_VK_DEVICE='RTX 5070 Ti'):
replay_uav_uint_bits_test -> OK
d3d12_clear_fuzz_test -> 40 seeds, 0 differ
d3d12_clear_fuzz_test --seeds 2000 -> 2000 seeds, 0 differ
d3d12_clear_fuzz_test --all --seeds 200 -> 28 differ, all R11G11B10_FLOAT plane 0 or stencil plane 1
clear_color_test -> 478 checks; typeless_rtv_test -> 93; d3d12_typeless_families_test -> 8 draws, 0 differ; d3d12_vulkan_device_test -> pass
The CPU test compares exact bits: SNORM 0x80/0xff survive, half NaN 0xfffd survives, R32 0x7fc12345 survives; uint_twin is applied only for !is_float && binding.typeless, and the remaining --all diffs are exactly the documented non-typeless R11G11B10 and NVIDIA stencil cases.
Stacked on #5425: the branch contains that PR's two commits (0a19daa64, f13305d55). Merge #5425 first or expect a duplicate-commit diff. Independent of #5489.
Verdict: approve after #5425.
…river rounds Clears handed the application's float to vkCmdClear*/loadOp and let the driver convert it. NVIDIA's (621.14) rounds differently from D3D12, WARP and AMD (the Xbox's own hardware): - UNORM/SNORM: 0.5 * 255 = 127.5 gives 0x7f, not the even 0x80; 4-, 5- and 6-bit channels go through 8 bits first (B5G6R5 green 0.3739 is 23, not 24); - sRGB: 0.5 / 255 encodes to 7, not 6; - D16: depth 0.5 clears to 0x7fff, not 0x8000; - a denormal R32_FLOAT colour or D32 depth is kept, where D3D12 flushes it to a zero of its sign. The layer now computes D3D12's code itself (a float multiply, round to nearest, ties to even, as depth24_quantize already does for D24) and hands the driver the nearest float to code / max, which any rounding turns back into that code. ClearUnorderedAccessViewFloat's model (uav_clear::encode) rounded ties away from zero in double; it now matches WARP too. Three tests encoded the driver's rounding: clear_color and typeless_rtv expected UNORM floats to pass through; d3d12_typeless_families and d3d12_vulkan_device compared exactly with the host D3D12 on the same adapter. On NVIDIA they now accept the WARP value where the host and WARP disagree (0.6 ULP, D3D11.3 3.2.3.6). clear_color checks the measured cases. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e compared Each program fills one texture (19 families: typeless colour families viewed through their typed formats, packed 16-bit, R11G11B10, D16/D24S8/D32/D32S8 and their typeless forms; mips and arrays) with known bytes, then runs random ClearRenderTargetView, ClearDepthStencilView and ClearUnorderedAccessViewUint/Float through views of a mip and an array range, with 0-3 rects, and compares every byte of every plane of every subresource with WARP. --hardware compares with the GPU's D3D12, --reduce SEED shrinks a differing program, --seeds/--start choose them. The default leaves out two known differences (--all puts them back): the UINT patterns uav_clear.h documents as inexact, and on NVIDIA stencil clears with rects past mip 0 (the driver writes a stencil attachment view of mip > 0 into mip 0). A NaN from a float clear compares equal whatever its payload, and an sRGB colour may be one code off (D3D's tolerance). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…product Two problems the clear fuzzer found after the rebase on main 561b65a: - AMD's Vulkan driver can store to R5G6B5, A1R5G5B5 and A4R4G4B4, so the layer reports typed UAV stores for B5G6R5, B5G5R5A1 and B4G4R4A4 there, but uav_clear.h had no layout for them: a ClearUnorderedAccessView* on one made ExecuteCommandLists refuse the whole list, its other work included (found by @Jadiac5 on an RX 9070 XT). The three layouts are added. - quantize_unorm/quantize_snorm (ItsNotRexed#589) multiplied in double. D3D multiplies in float: a D16 depth of 0.681063533 is 44633.5 in float, a tie that WARP writes as the even 44634, but 44633.4999... in double, which rounds to 44633 (on main, 70 of 2,000 fuzzer seeds, all D16 and 16-bit UNORM). The exact double product is now rounded to the nearest float first (nearest_float, ties to even, by nextafter so the thread's FP rounding mode doesn't matter), then to the code. uav_clear::encode does the same. The sRGB colour channels stay on the GPU's curve, as main decided (ItsNotRexed#589); this branch no longer quantises them. clear_color_test checks the packed layouts and the D16 tie under all four rounding modes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ClearUnorderedAccessViewUint copies raw bits into each channel. The replay decoded those bits into a VkClearColorValue of the view's format, so a float, UNORM or SNORM view handed the driver a float to encode again: NaN payloads were canonicalised (a half 0xfffd came back 0xfe00 on NVIDIA) and SNORM 0x80.. came back 0x81.., the limit uav_clear.h documented. A typeless image is mutable with no format list, so the replay now clears it through the family's UINT format of the same layout (uav_clear::uint_twin), whose decode is the bits themselves. Float clears and textures that aren't typeless (R11G11B10_FLOAT, castable lists) are unchanged. replay_uav_uint_bits_test checks the format and value handed to Vulkan (fails without the change); d3d12_clear_fuzz_test now leaves the documented patterns out only on textures that aren't typeless. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ff63999 to
36f05e6
Compare
|
Rebased on |
|
Tested 36f05e6 on Windows 11, AMD Radeon RX 9070 XT (RDNA4), driver 32.0.32029.2010: pass
AI-assisted (Claude Code). |
shayderrr
left a comment
There was a problem hiding this comment.
Review
Reviewed change in PR #5537: d3d12: a Uint UAV clear of a typeless texture writes its bits exactly (NaN payloads, SNORM 0x80).
Scope: runtime/CMakeLists.txt, runtime/src/depth24.h, runtime/src/uav_clear.h, +4 more
Diff: +1163 / -15 across 7 file(s).
The change stays inside the stated scope and the touched files line up with the description. No unrelated production paths are pulled in, and the stated behavior is directly exercised by the diff. I'm approving this one.
Reviewed by shayderrr via automated batch review.
|
Thanks @Exopus-0x65f7ad0 - I went through d3d12: a Uint UAV clear of a typeless texture writes its bits exactly (NaN payloads, SN... and the diff around |
|
Tested on MoltenVK: Apple M5 Pro, macOS 27.2.1, MoltenVK 1.4.2, through the #7446 macOS host. This PR merged onto
Heads-up: this PR and #5124 both rewrite the UAV clear path in No game files used. AI-assisted. |
Claimed in the coordination issue: #5256 (comment)
Depends on #5425. This branch contains #5425's two commits, and this PR adds only the last one. It is independent of #5489.
What and why
ClearUnorderedAccessViewUintwrites raw bits: D3D copies the low n bits of each value into each channel, whatever the format's type. The replay encoded those bits for the view's format, then decoded them into aVkClearColorValueof that format forvkCmdClearColorImage/vkCmdClearAttachments. For a float, UNORM or SNORM view, that turns the bits into a float, and the driver encodes the float again.uav_clear.halready documented the two cases where this isn't exact:0xfffdcame back0xfe00on NVIDIA, and an R32 NaN's payload is canonicalised.0x80..pattern. It means -1.0, and Vulkan writes -1.0 as0x81...#5425's fuzzer finds both against WARP with
--all, on RGBA16F, RG16F and RGBA8 SNORM views of typeless textures.Change
When the texture is typeless, the replay clears through the family's UINT format with the same bit layout. A typeless image is created mutable, with no format list. The new
uav_clear::uint_twinmaps the formats as follows:R8G8B8A8_UINTR16G16B16A16_UINTR32_UINTDecoding the element in a UINT format is the bits themselves. This uses the same attachment path the replay already takes for typed views of typeless textures.
Unchanged:
R11G11B10_FLOAT, castable lists): no UINT view is allowed, so their documented limit stays and the comment says so.Tests
replay_uav_uint_bits_test(CPU, no GPU) checks the format and value handed to Vulkan. The cases are SNORM 0x80 on a typeless RGBA8, half NaN payloads on RGBA16F, an R32F NaN, a non-typeless texture (unchanged), and a Float clear (unchanged). It fails 3 checks without the change.d3d12_clear_fuzz_test: its default run now leaves the documented patterns out only for non-typeless textures. Results on the RTX 5060 Ti / 621.14:--all, 1,000 seeds: the typeless cases are gone (seeds 68, 363, 547 match WARP). What still differs isR11G11B10_FLOAT(not typeless, out of scope), one float-clear NaN payload (--allcompares those bit for bit), and the NVIDIA stencil-mip clears that d3d12: a stencil clear with rects past mip 0 is copied into the stencil aspect (NVIDIA writes such views to mip 0) #5489 handles.LEONIDA_VK_VALIDATION=1 ctest -j4with-DLEONIDA_LLVM_MC: 169/169 (clean build).No game files. AI-assisted (Claude Code, Claude Opus 5.5).