Skip to content

d3d12: clear values convert as D3D12/WARP do, found by a new differential clear fuzzer (d3d12_clear_fuzz_test) - #5425

Closed
Exopus-0x65f7ad0 wants to merge 3 commits into
ProjectLeonida:mainfrom
Exopus-0x65f7ad0:test/clear-fuzz
Closed

Exopus-0x65f7ad0 wants to merge 3 commits into
ProjectLeonida:mainfrom
Exopus-0x65f7ad0:test/clear-fuzz

Conversation

@Exopus-0x65f7ad0

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue: #5256 (comment)

What and why

A seeded differential fuzzer for the shaderless clears, built on the same harness as #5272 (WARP is the reference, --hardware, --reduce SEED). It found that the layer hands the application's clear float to the Vulkan driver and lets the driver convert it. NVIDIA's driver converts differently from D3D12, WARP and AMD, and AMD is the Xbox's own hardware. This PR has two commits: the fix, then the fuzzer.

1. d3d12: clear values convert as D3D12 does (WARP). Each case below was reduced by the fuzzer to one clear (RTX 5060 Ti, 621.14):

clear layer on main WARP
R8 UNORM 0.5 (a tie, 127.5) 0x7f 0x80 (ties to even)
B5G6R5 green 0.373858 (23.55) 23 (via 8 bits, then >>2) 24
B5G5R5A1 green 0.753251 (23.35) 24 23
R8G8B8A8_UNORM_SRGB 0.5/255 7 6
D16 depth 0.5 0x7fff 0x8000
R32_FLOAT colour / D32 depth 1e-40 the denormal ±0
ClearUnorderedAccessViewFloat R8_UNORM 0.5/255 1 (lround in double) 0

The layer now computes D3D12's code itself: a float multiply, then round to nearest, ties to even. depth24_quantize already does this for D24, with the same reasoning in its comment. The layer then hands the driver the nearest float to code / max, which any rounding rule turns back into that code. This covers render_target_clear_color (UNORM, SNORM, 4/5/6-bit packed, sRGB colour and linear alpha, float denormals), a new depth_clear_value (D16, denormals) and uav_clear::encode.

Four existing tests encoded the driver's rounding, and I adapted them:

  • clear_color and typeless_rtv expected UNORM floats to reach the driver unchanged. They now expect the code's float, and clear_color adds the measured cases above.
  • d3d12_typeless_families compares with the host D3D12 on the same adapter. Its log already said "WARP differs from the host in 14". On this branch the layer gives WARP's bytes in all 14, and NVIDIA's host gives 0x7f where WARP gives 0x80. Where the host and WARP disagree it now accepts either.
  • d3d12_vulkan_device's placed-clear check applied its 0.6 ULP tolerance (D3D11.3 3.2.3.6 and 3.2.3.8) only against another adapter. The layer no longer copies its own driver's rounding, so the tolerance now applies on the same adapter too. Its comment already names the tie: "WARP and AMD give the upper code, NVIDIA's D3D12 driver and its Vulkan driver the lower".

2. d3d12_clear_fuzz_test (ctest d3d12_clear_fuzz, 40 seeds by default):

  • Setup: each program fills one texture with known bytes. There are 19 families: typeless colour families viewed through their typed formats, packed 16-bit formats, R11G11B10, and D16/D24S8/D32/D32S8 with their typeless forms; with mips and array layers.
  • Clears: it then runs 3-14 random ClearRenderTargetView, ClearDepthStencilView and ClearUnorderedAccessViewUint/Float calls, through views of one mip and an array range, with 0-3 rects.
  • Comparison: every byte of every plane of every subresource is compared with WARP.
  • Format support: formats either device can't use are left out (CheckFeatureSupport), and --verbose lists them.
  • Tolerated differences: a NaN from a float clear compares equal whatever its payload, which D3D12 leaves unspecified (WARP writes 0xfffd for a half, NVIDIA 0xfe00). An sRGB colour byte may be one code off, within D3D's tolerance: 0.349108 encodes to 159.50.

The default run leaves out two known differences, and --all puts them back:

  • the ClearUnorderedAccessViewUint patterns that uav_clear.h already documents as inexact (SNORM 0x80.., float NaN bits);
  • on NVIDIA only, stencil clears with rects past mip 0. This is a driver bug, posted with a standalone Vulkan repro in Coordinating who works on what (30) (moved to #5361) #5256 (comment): a stencil attachment view of mip > 0 writes mip 0, through vkCmdClearAttachments and loadOp = CLEAR alike, with no validation message.

Results (RTX 5060 Ti / 621.14, Windows 11 26300, MSVC 14.51, Vulkan SDK 1.4.363.0)

main 3faac557 (fuzzer only) this branch
default (40 seeds) 7 differ 0 differ
1,000 seeds 139 differ 0 differ
5,000 seeds — 0 differ
200 seeds, LEONIDA_VK_VALIDATION=1 — 0 differ, 0 validation messages

Before the fixes and the comparator rules, 91 of the first 300 seeds differed. Full LEONIDA_VK_VALIDATION=1 ctest -j4 with -DLEONIDA_LLVM_MC: 168/168 pass.

Not covered

  • Other GPUs: AMD and Intel may round some of these cases differently. A run of d3d12_clear_fuzz_test --seeds 1000 (and --all) there would be welcome.
  • MSAA: resolves and MSAA targets aren't generated yet.
  • The stencil driver bug: it isn't worked around in the layer; only the fuzzer avoids it on NVIDIA.

No game files. AI-assisted (Claude Code, Claude Opus 5.5).

@SirKingg

Copy link
Copy Markdown
Contributor

Independent Windows verification of head f13305d55d57ff8e693b2081ff88060332514dd0 (AI-assisted).

Machine: Windows 11 Pro build 26300, NVIDIA GeForce RTX 4070 Ti, driver 610.88; VS 2022 MSVC 14.44.35230, Windows SDK 10.0.26100.0, Vulkan SDK 1.4.363.0, Ninja. No game files.

With LEONIDA_VK_VALIDATION=1, VK_LAYER_PATH set to the SDK's Bin, and LEONIDA_VK_DEVICE=4070 Ti:

  • ctest --test-dir runtime\build -V -R "^(d3d12_clear_fuzz|clear_color|d3d12_typeless_families|typeless_rtv|d3d12_typeless_rtv|d3d12_vulkan_device)$" --output-on-failure: 6/6 passed. The default fuzzer ran seeds 1-40 against WARP: 0 differences, 0 layer refusals.
  • runtime\build\d3d12_clear_fuzz_test.exe --seeds 100 --verbose: seeds 1-100 against WARP, 100 run, 0 differences, 0 layer refusals or reference refusals. No Vulkan validation messages appeared in either run.
  • d3d12_typeless_families reported 82 clears compared against the NVIDIA host, 0 differences under its comparator; WARP differed from the host in 14. Its 8 draws also matched.

Coverage and comparator limits: verbose output excluded B4G4R4A4_UNORM entirely because the required support was not present on both devices. The default also adjusts the documented inexact UINT SNORM/NaN patterns and redirects NVIDIA stencil clears with rectangles at mip > 0 to mip 0; --all was not run, and this does not independently reproduce or disprove the stencil driver issue. The comparator accepts differing NaN payloads, allows a one-code sRGB colour difference, and zeroes the undefined D24 X8 byte. MSAA is not generated. These are bounded results on one NVIDIA GPU/driver, not exhaustive conformance or AMD/Intel results.

Comparator concern confirmed with a synthetic CPU probe against these actual functions: srgb_tolerance (runtime/test/d3d12_clear_fuzz_test.cpp:579) accepts a one-byte difference in an unrelated mip merely because some clear in the program uses an sRGB view; same_nan (:598) accepts differing R32_UINT bit patterns 0x7fc00001 and 0x7fc00002 as matching NaNs on an R32 typeless family even when the clear uses a UINT view. Both checks lack per-texel/view provenance and can therefore mask genuine integer or untouched-subresource differences. This probe demonstrates comparator behavior, not an observed GPU divergence; the 0-difference counts above are subject to these tolerances.

@Hiiva Hiiva left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Independent Windows Radeon review of f13305d55d57ff8e693b2081ff88060332514dd0, using native WARP as the reference. Windows 11 build 26200, AMD Radeon(TM) Graphics / 32.0.21043.5001, MSVC 19.44.35228, SDK 10.0.26100.0, Vulkan SDK 1.4.363.0. Synthetic inputs only.

The normalization change removes 25 differences in the same 1,000 generated cases, with no newly differing seeds. The new default test still fails on this Radeon setup because it reaches a separate, pre-existing packed-format UAV clear gap.

Run Main production 3faac557 This head
Default seeds 1-40, core + synchronization validation 6 differences 5 differences
Default seeds 1-1000 108 differences 83 differences
--all seeds 1-40, core + synchronization validation Not run Same 5 differences

Both 1,000-seed runs execute all 1,000 seeds with no reference refusals. The 25 corrected cases are D16_UNORM (20), R8_TYPELESS (1), R16G16B16A16_TYPELESS (1) and R32G32B32A32_TYPELESS (3). The head's focused CPU tests also pass: 478 clear_color checks and 93 typeless_rtv scenarios. The main control uses the same new fuzzer and build configuration, with only the three production headers changed by this PR restored to 3faac557.

Remaining packed-UAV coverage gap

All 83 shared failures are B5G6R5_UNORM (37), B5G5R5A1_UNORM (22) or B4G4R4A4_UNORM (24). Each logs ExecuteCommandLists failed: unsupported; nothing was submitted. Although the fuzzer's summary says zero layer refusals, these submissions are rejected and leave the initialized texture bytes in place; they are not additional rounding mismatches.

The capability query admits these views on this machine. CheckFeatureSupport derives typed-UAV support from the Vulkan storage features, while the relevant packed formats are absent from uav_clear::layouts. For example, B5G6R5 maps to VK_FORMAT_R5G6B5_UNORM_PACK16, encode returns false, and vulkan_replay.h:2547-2549 returns unsupported before emission. The layout table and relevant feature-reporting block are identical on main and this head.

Reproduced with LEONIDA_VK_DEVICE=AMD Radeon(TM) Graphics, LEONIDA_VK_VALIDATION=1, and:

d3d12_clear_fuzz_test.exe --seeds 40 --verbose
d3d12_clear_fuzz_test.exe --reduce 14 --verbose
d3d12_clear_fuzz_test.exe --reduce 15 --verbose

Seed 14 reduces to one whole-view ClearUnorderedAccessViewUint on B5G6R5, mip 1, values 0xa62e, 0xfffffffd, 0x4b, 0xdd. Main and head give the same rejection and 351 differing bytes; WARP writes the expected packed value 0x77ab. Seed 15 reduces to one whole-view float clear with (-166, 1, 2.5, 1), again rejected by the layer while WARP writes 0x07ff.

The validated runs and reductions have zero VUID or synchronization-error entries. The larger 1,000-seed pair was run without validation. These counts use this PR's comparator, including its NaN/sRGB tolerances; SirKingg's comparator-provenance finding still applies. No MSAA, game, exhaustive-conformance or clean-default-test claim. No production changes are included in this review. AI-assisted: yes.

@Kam471 Kam471 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Head: f13305d55d57ff8e693b2081ff88060332514dd0

Windows 11, RTX 5070 Ti (621.24), vcvars64 + Ninja + Vulkan 1.4.363, RelWithDebInfo:

  • Configure/build: cmake -S runtime -B runtime\build ... && cmake --build runtime\build --target d3d12_clear_fuzz_test
  • d3d12_clear_fuzz_test (default 40 seeds) -> 40 seeds run, 0 differ, 0 refused
  • d3d12_clear_fuzz_test --seeds 200 -> 200 run, 0 differ, 0 refused
  • Baseline: main 3faac557 + the same fuzzer source -> 40 run, 7 differ (seeds 5, 16, 21, 27, 31, 33, 40), matching the PR's claim.
  • clear_color_test -> 478 checks pass; typeless_rtv_test -> 93 scenarios pass; d3d12_typeless_families_test -> 8 draws, 0 differ; tests/test_ctest_registration.py -> 4/4 OK
  • d3d12_clear_fuzz_test --all (40 seeds) -> 5 differ, all the documented --all cases (4 NVIDIA stencil plane>0, 1 UINT pattern); exit 1 is expected for --all.
  • git diff --check main...HEAD -> clean

Verdict: LGTM.

@timbot103

Copy link
Copy Markdown

Tested f13305d on two GPUs: AMD Radeon Graphics (Ryzen 9000 iGPU, RDNA2, subgroup 32..64), AMD driver 25.10.30.02, and NVIDIA GeForce RTX 5080, driver 616.64. Windows 11 Pro 26200, MSVC 14.44.35207, Vulkan SDK 1.4.363.0. Merged onto main 3faac55. The control is main with only the fuzzer commit added.

d3d12_clear_fuzz_test RTX 5080 Radeon (RDNA2)
control, 40 seeds 7 differ 6 differ
control, 1,000 seeds 139 differ 108 differ
this PR, 40 seeds 0 5
this PR, 1,000 seeds 0 83
this PR, --all, 1,000 seeds 122 99
  • NVIDIA: the RTX 5080 gives the same counts as your 5060 Ti: 7 and 139 on the control, 0 and 0 here.
  • AMD: the PR removes every AMD difference it targets. The 25 seeds that differ on the control but not here are D16_UNORM (20) and typeless families (5). No seed differs here that didn't differ on the control.
  • The 83 left on AMD: all are ClearUnorderedAccessView{Uint,Float} on B5G6R5_UNORM (37), B4G4R4A4_UNORM (24) or B5G5R5A1_UNORM (22). They're the same seeds on the control, so the bug predates this PR.
    • NVIDIA has no typed UAVs for these formats, so the fuzzer leaves them out there, which matches SirKingg's note about B4G4R4A4.
    • The likely cause: runtime/src/uav_clear.h has no layout for R5G6B5, A1R5G5B5 or A4R4G4B4_UNORM_PACK16, the formats d3d12_vulkan_device.cpp:252/275/276 map these DXGI formats to. So encode() fails, and the image path returns unsupported (vulkan_replay.h:2491-2494 on main), yet the fuzzer reports 0 refusals.
    • Reduced example, seed 15: a B5G6R5_UNORM 30x7 texture, ClearUnorderedAccessViewFloat(-166, 1, 2.5, 1). WARP writes ff 07; the layer leaves fb 5e.
    • Fixing it isn't this PR's job. Hiiva has claimed the fix in Coordinating who works on what (31) (moved to #5581) #5361, and my counts match theirs.
  • Validation: seed 15 with LEONIDA_VK_VALIDATION=1 on the Radeon gave no validation messages.
  • The changed tests pass on both GPUs:
    • d3d12_clear_test: 197 readbacks matched WARP
    • clear_color_test: 478 checks
    • typeless_rtv_test: 93 scenarios
    • d3d12_typeless_families_test: 8 draws, 0 differ
    • d3d12_vulkan_device_test
  • d3d12_clear_test: main fails it on the RTX 5080 (depth format 55 case 1 byte 12: Vulkan ff, WARP 00, "5 color/depth format(s) differ from WARP"), and this PR passes it. That's D3D-421, which D3D12 → Vulkan layer: critical path, who builds what, open methods #313 lists under Runtime: clears match WARP on every format class: tie rounding, and the SNORM/SINT/R8/R16 formats (D3D-45) #521, so the two PRs overlap there. main already passes it on the Radeon.

No game files. AI-assisted (Claude Code).

@zarkovkirill1-alt

Copy link
Copy Markdown

Tested f13305d on NVIDIA GeForce GTX 1660 (Turing, 32-wide), driver 32.0.16.1742, Windows 10 19045, MSVC 2022, Vulkan SDK 1.4.363.0: pass.

No game files. AI-assisted.

@caltr98

caltr98 commented Nov 23, 2026

Copy link
Copy Markdown

Tested f13305d on NVIDIA GeForce RTX 5080 Laptop GPU, driver 621.14, Windows 11 (build 26300), MSVC 14.44, RelWithDebInfo: pass. ctest -R "clear|typeless|^d3d12_vulkan_device$": 10 of 10 pass, including the new d3d12_clear_fuzz (2.4 s), d3d12_vulkan_device, d3d12_typeless_rtv and d3d12_typeless_families. AI-assisted.

@searyecheesepeaceful

Copy link
Copy Markdown

Tested f13305d on NVIDIA GeForce RTX 4080, driver 617.42: d3d12_clear_fuzz_test exits 0 with "clear fuzz (layer against WARP): 40 seeds run, 0 differ, 0 refused by the layer". clear_color_test prints "478 full/rectangle integer and float replay checks passed", typeless_rtv_test prints "93 format, snapshot, whole/rectangle and rejection scenarios passed", and d3d12_typeless_families_test prints "82 clears compared with NVIDIA GeForce RTX 4080, 0 differ" and "8 draws compared with NVIDIA GeForce RTX 4080, 0 differ". d3d12_vulkan_device_test exits 0 with no summary line. The run on main that gives 7 differences was not repeated, and --all and --seeds 1000 were not run.

AI-assisted.

@Jadiac5

Jadiac5 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested f13305d on Windows 11, AMD Radeon RX 9070 XT (RDNA4), driver 32.0.32029.2010: concern (the clear conversions pass; the new fuzzer test fails on this GPU for a format the layer already refused)

  • Full build, RelWithDebInfo, MSVC 19.44, Ninja, no game files. ctest -R "^(d3d12_clear_fuzz|clear_color|d3d12_typeless_families|typeless_rtv|d3d12_typeless_rtv|d3d12_vulkan_device)$" with LEONIDA_VK_VALIDATION=1: 5 of 6 pass (clear_color 478 checks, typeless_rtv 93 scenarios, d3d12_typeless_families, d3d12_typeless_rtv, d3d12_vulkan_device). d3d12_clear_fuzz fails: 40 seeds, 5 differ, 0 refused. Also pass: d3d12_uav_clear, d3d12_short_uav_clear, d3d12_depth24_draw, d3d12_depth_resolve, d3d12_buffer_uav, d3d12_r9g9b9e5_uav, d3d12_rgb9e5_rtv, depth24_convert, replay_clear_gate, replay_uav_clear_offset (10 of 10).
  • Every seed that differs is a texture in B5G6R5_UNORM, B5G5R5A1_UNORM or B4G4R4A4_UNORM created with the UAV flag. Seeds 1-300: 32 differ (19 B5G6R5, 8 B5G5R5A1, 5 B4G4R4A4). Seeds 1-1000: 83 differ, and the log has 83 ExecuteCommandLists failed: unsupported; nothing was submitted lines. The seeds that don't use one of these three formats all match WARP: 917 of 1000, 0 differences (200 seeds with LEONIDA_VK_VALIDATION=1: 24 differ, all the same three formats, 0 validation messages).
  • Cause: d3d12_vulkan_device.cpp:6754 reports typed UAV store for every format Vulkan can store to, and AMD's Vulkan driver can for the three packed 16-bit formats. uav_clear.h layouts[] (line 58) has no entry for R5G6B5, A1R5G5B5 or A4R4G4B4, so uav_clear::encode fails and vulkan_replay.h:2549 returns unsupported for the whole list; nothing is written, including the RTV clears in the same list. The fuzzer includes a format when the layer and WARP both report typed UAV store (d3d12_clear_fuzz_test.cpp:132), so on this GPU these formats are included. On the NVIDIA runs in the PR the host does not report them. The "0 refused by the layer" line does not count a failed ExecuteCommandLists, so the summary says 0 refused next to 5 differ.
  • Merge base control: main 3faac55 with only the fuzzer (the PR's CMakeLists.txt and d3d12_clear_fuzz_test.cpp), same GPU: seeds 1-300, 43 differ. The 32 above (same unsupported failure, so not caused by this PR) plus 11 that the fix removes: 8 D16_UNORM, 2 D32_FLOAT_S8X24_UINT, 1 R8_TYPELESS (for example a D16 depth clear of 0.818822 writes one code off WARP). So the conversion fix is confirmed on RDNA4: the driver rounds differently from WARP on main, and does not on this head.
  • --all --seeds 300: 36 differ, the same 32 plus 3 R11G11B10_FLOAT and 1 R16G16_TYPELESS (the UINT patterns --all puts back).
  • Suggested fix, either one: exclude formats from the fuzzer's UAV list when uav_clear::layout has no entry for them (or count the failed ExecuteCommandLists as a layer refusal), or add the three packed layouts to uav_clear.h. Without it the default ctest run is red on this GPU.
  • Code read: no bug in normalized_clear_value, srgb_clear_value or depth_clear_value. d3d12_vulkan_device_test.cpp now ignores same_adapter for the 0.6 ULP rule, so an off-by-one on the same adapter is accepted there; the PR comment explains why.
  • Not done: Intel, MSAA. Head checked again at the end: unchanged.

AI-assisted (Claude Code).

Exopus-0x65f7ad0 and others added 2 commits November 23, 2026 13:15
…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>
@mrp1no

mrp1no commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested f13305d5 on Windows 11 with an Intel UHD Graphics 750 and an NVIDIA RTX 3060 (MSVC RelWithDebInfo), with two results that may help.

1. This PR should also fix d3d12_clear_formats on Intel once rebased. On main 561b65a8 that test fails on the UHD 750 with 10 sRGB differences. For example, R8G8B8A8_UNORM_SRGB 0.5 gives bb where WARP gives bc (187.52), and 0.0039 gives 0c where WARP gives 0d (12.85, 0.85 ULP off). Before I found this PR, I tried the same idea locally on main's render_target_clear_color: hand the driver the linear value of D3D's sRGB code, as your srgb_clear_value does. With that, d3d12_clear_formats gives 251/251 matched on both GPUs. The test came to main after this PR's base 3faac557, so it isn't in your branch yet. The PR now conflicts with main in six files, so I didn't test a merge.

2. d3d12_clear_fuzz finds one difference on the UHD 750 (40 seeds, 1 differs, 0 refused). It passes on the RTX 3060 (40/40, 0 differ). --reduce 21 brings it down to a single clear:

seed 21 reduced to 1 clear(s), 120 byte(s) differ; first: mip 0 layer 0 plane 0 texel (0,0): layer 82 81 01 3f, reference 82 81 01 00
  texture R24G8_TYPELESS (D24S8 view) 12x3, 3 layers, 2 mips
  ClearDepthStencilView(D24_UNORM_S8_UINT mip 1 layers 1+1, DS depth 0.359754324 stencil 61)

A D24S8 clear of mip 1, layer 1 changes the stencil byte of mip 0, layer 0 on Intel. It looks like the stencil-aspect cousin of #5489, on a different driver. clear_color_test passes (478 checks).

AI-assisted (Claude Code).

…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>
@Exopus-0x65f7ad0

Copy link
Copy Markdown
Contributor Author

@Jadiac5 thank you. The diagnosis was right, and the bug is real beyond the test: with no layout, one UAV clear on those formats made ExecuteCommandLists drop the whole list. I rebased on main 561b65a8 (#589 had landed with the same idea for 8/10/16-bit formats) and pushed 45e81b28:

RTX 5060 Ti / 621.14:

  • Clear fuzzer: 3,000 seeds, 0 differ.
  • clear_color: 535 checks.
  • Full LEONIDA_VK_VALIDATION=1 ctest -j4: 235 of 237. d3d12_indirect_rt and d3d12_indirect_dispatch_count fail on main 561b65a8 alone too, on this machine.
  • Flaky under load: d3d12_bindless_churn_validated failed once under -j4 and passed 6 of 6 alone.

I can't run AMD here. Could you re-run the fuzzer on the 9070 XT? AI-assisted (Claude Code).

@thehollowedone

Copy link
Copy Markdown

Independent Windows check of 45e81b28 on 561b65a8. Windows 11 x64, RTX 3080 Ti / 621.35, MSVC 19.44.35230, Windows SDK 10.0.26100, Vulkan SDK 1.4.363.0, RelWithDebInfo.

All five stock CTests passed. The 40 default d3d12_clear_fuzz seeds had zero differences or refused cases against WARP. All 251 d3d12_clear_formats cases matched WARP. d3d12_typeless_families matched native D3D12 across 82 clears and 16 draws. CPU tests passed all 535 clear_color and 100 typeless_rtv checks. Vulkan core and synchronization validation reported zero errors.

A logging-only fixture run confirmed packed RTV coverage for B5G6R5 and B5G5R5A1. The format intersection exposed no packed UAV path on this setup, so the new packed UAV encodings were covered by the CPU checks. Synthetic inputs only. AI-assisted.

@Hiiva Hiiva left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow-up Radeon verification of 45e81b282132788c5a9de4524df89678479e5926 on main 561b65a8. Windows 11 x64 build 26200, MSVC 19.44, Vulkan SDK 1.4.363.0, AMD Radeon(TM) Graphics driver 32.0.21043.5001, native WARP reference.

  • Rebuilt your unchanged d3d12_clear_fuzz_test and ran 1,000 seeds on Radeon: zero differences, zero refused cases.
  • An independent exact-byte probe replays all 83 packed-format seeds from my earlier review: all 241,598 readback bytes now match WARP. Its separate 42 deterministic whole/rectangle programs match all 13,440 literal bytes on both WARP and replay, including Uint high-bit masking, clamp/NaN/infinities, and alpha at/above 0.5. These comparisons bypass the fuzzer's tolerance comparator.
  • CPU clear_color_test: 535 checks pass; typeless_rtv_test: 100 pass. The stock UAV clear fixture plus the additional packed mip/array/rectangle coverage also passes.
  • All GPU runs used Khronos validation and synchronization validation, with no VUID or synchronization-hazard messages.

The test tree is the restacked #5616 child, whose only delta from your exact head is 39 test lines and four documentation lines. Production source and your fuzzer source are byte-identical to your head. I removed the child's duplicate layout rows now that this PR supplies them; #5616 retains the additional boundary and GPU regression coverage. This confirms the previously reported packed-format failures are resolved on this Radeon device. No game files. AI-assisted: yes.

@sennecools

Copy link
Copy Markdown
Contributor

Tested 45e81b2 on main 561b65a, on the GPU where the packed-UAV bug was found: AMD Radeon RX 9070 XT (RDNA4), driver 32.0.32029.2010, Windows 11, MSVC RelWithDebInfo, Vulkan SDK 1.4.363.0. Pass.

  • CTests: d3d12_clear_fuzz, clear_color, d3d12_clear, d3d12_clear_formats, d3d12_typeless_families and typeless_rtv all pass, 6 of 6, with and without LEONIDA_VK_VALIDATION=1.
  • Fuzzer against WARP:
    • 40 seeds, three runs: 0 differ, 0 refused each time.
    • 1,000 seeds: 0 differ, 0 refused.
    • 200 seeds under validation: 0 differ and no validation messages.
    • --all --seeds 300: 4 differ (seeds 94, 154, 193, 196), all the documented UINT patterns.
  • Negative control: with main's uav_clear.h and the rest of this head, seeds 1-300 give 32 differ. The log has 32 ExecuteCommandLists failed: unsupported lines, the same 32 Jadiac5 reported. So the new packed layouts are what fixes it here.

New: --hardware against native D3D12 on the same RX 9070 XT, 1,000 seeds:

vs WARP vs native AMD
main + only the fuzzer 123 differ 101 differ (83 are the dropped packed lists)
this PR 0 22 differ (the same 22 seeds on a second run)

The 22 seeds are exactly the ones where main matches native AMD but not WARP. The PR's float-product, ties-to-even rounding follows WARP there, and AMD's hardware doesn't. Reduced to single clears:

  • D16 depths where the float product lands on .5 but the exact product doesn't. AMD rounds the exact product, the way main's double quantize_unorm did.
    • Seed 10: ClearDepthStencilView(D16_UNORM, 0.0241016243) gives layer 2c 06, AMD 2b 06. The exact product is 1579.49995; the float product is 1579.5.
    • Seed 846, D16_UNORM 0.272808433: d6 45 vs AMD d7 45.
    • Seed 129, D16_UNORM 0.751560211: 66 c0 vs AMD 65 c0.
  • RTV 0.00196078 (0.5/255):
    • Seed 150, R8_UNORM: layer 00, AMD 01.
    • Seed 656, R16G16B16A16_UNORM: layer 80 00, AMD 81 00.

Overall the PR brings the layer much closer to AMD (101 to 22). For those tie cases, though, WARP and the Xbox's own GPU vendor disagree, and the PR picks WARP. It may be worth a line in the quantize_unorm comment, or a decision on which reference wins. No game files. AI-assisted.

@Hiiva Hiiva left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additional reference-policy evidence for exact head 45e81b282132788c5a9de4524df89678479e5926, compared with unchanged main 561b65a8.

WARP's normalized color clears change with the submission thread's FP rounding mode on this machine. Native AMD D3D12, main, and this head remain mode independent for the measured inputs. The parent changes one 16-bit tie to match default-mode WARP; that tie differs from this AMD driver's result.

Identical 42 phase cases Main This head
Cases differing from WARP 24 16
Cases differing from native AMD D3D12 0 14

These are differing-case counts, with zero setup errors, skipped formats, or FP-state errors. Both native backends return byte-identical results between the main/head runs.

The six fixed programs use one whole-view ClearRenderTargetView or ClearUnorderedAccessViewFloat on an 8x8 texture:

  • R8G8B8A8_UNORM: input words 3f000000, 3e800000, 3effffff, 3f000001.
  • R16G16B16A16_UNORM: 3f000000, 3f2e5a2e, 3effffff, 3f000001.
  • R8G8B8A8_SNORM: bf000000, 3f000000, be800000, 3e800000.

Each runs with default rounding, three recording-only mode changes, and three submission-only mode changes. Recording-only changes leave all results unchanged. For example, both APIs give these literal RGBA8 UNORM bytes for the first vector:

Submission mode WARP Native AMD Main / this head
Nearest 80 40 7f 80 80 40 7f 80 80 40 7f 80
Upward 80 40 80 80 80 40 7f 80 80 40 7f 80
Downward / toward zero 7f 3f 7f 7f 80 40 7f 80 80 40 7f 80

The only main-to-head output change is the UNORM16 component with input 0x3f2e5a2e (0.6810635328292847). Its exact product with 65535 is 44633.49862396717; the nearest float product is 44633.5. Main and native AMD return 44633 in every phase. This head returns 44634 in every phase. WARP returns 44634 under nearest/upward submission and 44633 under downward/toward-zero submission. This accounts for all 14 newly differing AMD comparisons. No internal AMD conversion algorithm is inferred from its output.

The probe retains the stock fixture's resource setup, barriers, initialization, and readback. Visible adaptations only scope FP modes around the clear-recording call and ExecuteCommandLists. It compares every defined byte directly, without the fuzzer's tolerance comparator. Default WARP bytes have literal checks, and all 28,672 native readback bytes match across the two production builds.

Native AMD selection uses the Vulkan device's valid LUID, 2726010000000000, and verifies that ID3D12Device::GetAdapterLuid() matches exactly. Device: AMD Radeon(TM) Graphics, PCI 1002:164e, driver 32.0.21043.5001. MSVC 19.44.35228, Windows SDK 10.0.26100.0, Vulkan SDK 1.4.363.0, native D3D12 runtime 10.0.26100.8521. Each API call retains the requested rounding mode. The harness restores its saved full environment; final rounding mode and MXCSR equal their initial values. Khronos core and synchronization validation report zero VUID or synchronization-hazard messages.

This is bounded evidence about the reference policy, with no new implementation-defect claim. The head library comes from the test-only #5616 child; production and stock fixture source are byte-identical to this exact head. The main control uses a clean 561b65a8 library and the identical probe. No production or game files were changed. AI-assisted.

@Exopus-0x65f7ad0

Copy link
Copy Markdown
Contributor Author

@Hiiva thank you, that measurement changes the picture for 16-bit ties. At 45e81b28 the layer follows WARP's default-mode result: a float product, then ties to even, independent of the FP mode. AMD's native D3D12 rounds the exact product (44633 for 0x3f2e5a2e), and WARP itself flips with the submitting thread's mode. I tried switching to the exact product to match AMD, but then 8-bit UAV-float near-ties diverge from WARP (8 of 2,000 fuzzer seeds, and the 0.5f/255 UAV case), and I have no AMD measurement for those. So I'm leaving this head as it is and raising the choice instead: should the layer's reference for clear rounding be WARP (default mode) or AMD's driver (the Xbox's vendor)? Both are within D3D's 0.6 ULP tolerance. Once that's decided, the change is small: the product in quantize_unorm/uav_clear::encode plus the fuzzer tolerance. AI-assisted (Claude Code).

@sh1shu1

sh1shu1 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested 45e81b2 on NVIDIA RTX 4070 SUPER (driver 616.92), Windows 11 26200, MSVC 14.44, Vulkan SDK 1.4.363, RelWithDebInfo: pass, no regression against main 561b65a.

  • ctest: 244/248 passed; d3d12_indirect_dispatch_count, d3d12_indirect_rt, dxgi_device, dxgi_swapchain fails on main 561b65a too (not from this PR), same 11 skips as main 561b65a
  • clear_color, d3d12_clear_fuzz: 2/2
  • run_gpu_tests (LEONIDA_VK_VALIDATION=1): 183/232 native, 214/232 with LEONIDA_W64_EMULATE=1, 2 failed; ms_wave_info_s3 fails on main 561b65a too
    AI-assisted (Claude Code, Claude Fable 5.1).

@wuhuaiyu

Copy link
Copy Markdown

Independent Intel run of exact head 45e81b282132788c5a9de4524df89678479e5926 (no local merge), Windows 11 build 26200, Intel RaptorLake-S Mobile iGPU (driver 32.0.101.7085), MSVC 19.51, Ninja RelWithDebInfo, Vulkan SDK 1.4.363.0, LEONIDA_VK_VALIDATION=1:

  • Against WARP: default 40 seeds: 1 differs (seed 21), 0 refused, exit 1; reproduced on a second run. --seeds 1000: 18 differ, 0 refused, exit 1. --all --seeds 1000: 43 differ, 0 refused, exit 1 (includes documented UINT patterns). No validation error/VUID lines appeared in these logs.
  • --reduce 21 reproduces mrp1no’s earlier UHD 750 result on this different Intel device/driver: one D24S8 clear of mip 1, layer 1, with the first differing bytes in mip 0, layer 0: layer 82 81 01 3f, WARP 82 81 01 00.
  • --reduce 997: one D32_FLOAT_S8X24_UINT clear of mip 1, layer 1; 10 bytes differ, first at mip 1, layer 0, texel (16,0): layer d3 cf 52 3f, WARP bb ec 3a 3f. I have not isolated the cause or compared this seed against main.
  • NVIDIA RTX 5060 Laptop / 32.0.16.2101 on the same machine: default 40 seeds against WARP: 0 differ, 0 refused, exit 0. Device-specific format support and NVIDIA exclusions can change generated cases.

No claim that this PR introduced these differences; no baseline tested. Synthetic inputs only, no game files. AI-assisted (Codex).

@wuhuaiyu

Copy link
Copy Markdown

Follow-up baseline control for my Intel result above: same Windows 11 / RaptorLake-S Mobile iGPU / driver 32.0.101.7085 and LEONIDA_VK_VALIDATION=1. In a separate worktree at head 45e81b28, I restored the three production files changed by this PR (runtime/src/depth24.h, runtime/src/uav_clear.h, runtime/src/vulkan_replay.h) to the PR parent 561b65a8, retaining the identical head fuzzer and CMake registration. Built both with MSVC 19.51 / Ninja RelWithDebInfo.

Against WARP, 1,000 default seeds: control 43 differ, PR head 18 differ. Comparing seed numbers: 25 control differences disappear and none are new in the PR run. The remaining 18 include 21 and 997. --reduce 21 and --reduce 997 produce the same single-clear descriptions and first differing bytes in both builds as reported above. No validation error/VUID lines appeared in the control run.

This is a controlled comparison of the three changed production files, not a diagnosis of the remaining differences; the fuzzer comparator’s documented tolerances apply. Synthetic inputs only; no game files. AI-assisted (Codex).

@DeerSilver

Copy link
Copy Markdown

Tested head 45e81b282 on Windows 11 26H2 (build 26300.9974), MSVC 2022 Build Tools, Ninja RelWithDebInfo, Vulkan-Headers 1.4.363, with the layer on each GPU of one laptop via LEONIDA_VK_DEVICE. No game files.

NVIDIA GeForce RTX 5060 Laptop GPU, 621.24: pass. ctest -R "^(d3d12_clear_fuzz|clear_color|d3d12_typeless_families|typeless_rtv|d3d12_typeless_rtv|d3d12_vulkan_device|d3d12_clear_formats|d3d12_clear|d3d12_uav_clear)$": 9/9. d3d12_clear_formats: 251 matched WARP. d3d12_clear_fuzz_test: 40 seeds and --seeds 1000, 0 differ, 0 refused.

Intel UHD Graphics (Raptor Lake mobile, Xe-LP), 101.7088: 7/9.

  • d3d12_clear_fuzz: 40 seeds, 1 differs (seed 21: mip 1 layer 0 ... layer 81 37 01 3f, reference 81 37 01 00), the same seed @wuhuaiyu reduced on 101.7085.
  • d3d12_clear_formats: 241 matched WARP, 10 differ, the same 10 sRGB bytes as on main (0.5 → bb vs bc, 0.0039 → 0c vs 0d, 0.9961 → fe vs ff). On this head the sRGB colour channels go to the driver unchanged (runtime/src/vulkan_replay.h:1167, "the GPU's sRGB curve"), and this driver truncates the encode. So @mrp1no's note that this PR fixes d3d12_clear_formats on Intel doesn't hold for the current head; the srgb_clear_value from b64eb28 is gone.

I've opened #9353 for that (D3D-993). It picks the sRGB code on the CPU and hands the driver the linear value a quarter of a code above the code's start, so a rounding and a truncating encoder agree; 251/251 on both GPUs here. It changes render_target_clear_color too, so whichever of the two lands second needs a small rebase. If you'd rather fold it into this PR, that works as well.

AI-assisted (Claude Code).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.