Skip to content

Runtime: clears match WARP on every format class: tie rounding, and the SNORM/SINT/R8/R16 formats (D3D-45) - #521

Merged
ItsNotRexed merged 8 commits into
ProjectLeonida:mainfrom
NWX10:d3d-45-clear-comparison
Nov 23, 2026
Merged

ItsNotRexed merged 8 commits into
ProjectLeonida:mainfrom
NWX10:d3d-45-clear-comparison

Conversation

@NWX10

@NWX10 NWX10 commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Claimed in #374 as: D3D-45

What and why

D3D-45 asks for the clears to be compared with the host runtime across the format classes. This adds d3d12_clear_formats_test (run explicitly, like d3d12_uint_clear_test, which it extends) and fixes what it found. It clears, copies the result into a readback buffer through D3D12 and compares the bytes with WARP's: 178 cases over UNORM, SNORM, SRGB, FLOAT, UINT and SINT render targets and the four depth formats (depth and stencil planes), each with a full clear and a rectangle clear.

On main (4abd545) the test found two things, one commit each:

  • Rounding at exact ties (29 of the 105 cases that could run). D3D rounds a float clear value to nearest even, so 0.5 on an 8-bit channel is 128. NVIDIA's vkCmdClearColorImage and clear attachments write 127. The same step showed on R10G10B10A2_UNORM (0.5 -> 512), R16G16B16A16_UNORM, the alpha of the sRGB formats and D16_UNORM depth. The layer now rounds the value itself and hands Vulkan the exact fraction, so no GPU can round it differently (NaN is 0, values outside 0..1 clamp, as in D3D). The sRGB colour channels stay with the GPU's curve.
  • Formats the layer refused (73 cases, 15 formats). SNORM (6 formats), SINT (5), R8_UINT, R16_UINT, R16_UNORM and R16G16_UNORM gave "texture format not supported yet". They are mapped now, with their copy sizes, and clear like D3D: SINT clamps to the component range and truncates toward zero, SNORM rounds to nearest even on a scale of 127 or 32767 with -1.0 as -127.

The conversions were measured against WARP, not taken from the documentation.

Tested

  • RTX 3060 Ti (Ampere), NVIDIA 621.24, Windows 11 Pro 10.0.26300, MSVC 14.44, Vulkan SDK 1.4.363.1, with WARP as the reference.
  • d3d12_clear_formats_test: 178 cases match WARP, with and without LEONIDA_VK_VALIDATION=1, no validation errors. Before the commits: 29 differ and 73 are not exposed (the test lists such formats as "not exposed" instead of failing, so it stays usable on a layer that lacks a format).
  • ctest: 19/19. clear_color_test (CPU only) now also checks the rounded UNORM/SNORM values and the SINT and small UINT conversions (110 checks); with vulkan_replay.h from main its new checks fail (normalised clear: format 37 ... got 0.5, expected 0.501960814).
  • d3d12_com_test, d3d12_vulkan_device_test, d3d12_descriptor_test, d3d12_uint_clear_test, vk_command_replay_test and device_proxy_test: exit 0 with and without validation.
  • Not tested: AMD and Intel GPUs. The tie behaviour is NVIDIA's; rounding in the layer makes the written value independent of the GPU.
  • Overlap: Runtime: preserve explicit RGBA8 typeless RTV formats for clears (D3D-41) #388 (D3D-41) and runtime: ClearUnorderedAccessViewUint/Float on the Vulkan device (D3D-25) #391 (D3D-25) also edit runtime/CMakeLists.txt and runtime/src/vulkan_replay.h near the clear code; they merge with this one apart from adjacent lines, so whichever lands second needs a rebase.

AI-assisted (Claude Code).

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a: no translator change)

🤖 Generated with Claude Code

@VictorJulianiR

Copy link
Copy Markdown
Contributor

Tested 175b0ff on GitHub-hosted Windows Server 2022 using native D3D12 WARP readback as the reference. For R8_UNORM, I compared the full-clear and rectangle-clear values submitted by Leonida's production replay with the actual WARP bytes under three caller rounding modes.

Caller rounding mode Inputs 0.25, 0.125, 0.75 on both paths
Nearest 64, 32, 191
Downward 63, 31, 191
Upward 64, 32, 192

All 18 comparisons matched with MSVC /fp:precise, and all 18 matched with /fp:strict. I checked every pixel in each 5×3 WARP readback, including both sides of the clear rectangle. WARP itself followed the caller's rounding mode for these inputs, which is worth retaining if the conversion changes again.

The Vulkan side used the PR's replay callbacks to capture VkClearColorValue. The native readback used Microsoft's software adapter, vendor 0x1414, device 0x008c. AI-assisted, no physical GPU or game files. Hosted comparison

@kacper-serewis

Copy link
Copy Markdown
Contributor

Tested 175b0ff on RTX 5070 (Blackwell, subgroup 32..32), NVIDIA 616.56, Windows 11 Pro 26200: pass, also merged onto current main (91b36cf, clean merge).

  • PR head: ctest 19/19; merged: ctest 23/23
  • d3d12_clear_formats_test (both): "178 matched WARP, 0 differ, 0 failed, 0 in formats the layer does not expose, 0 skipped"
  • clear_color_test (merged): 110 replay checks passed

For comparison, #525's d3d12_clear_test fails on this GPU at the RGBA8_UNORM 0.5 tie (NVIDIA 0x7f, WARP 0x80), which this PR's tie rounding covers.

@luisbaker

Copy link
Copy Markdown
Contributor

Ran d3d12_clear_formats_test (from this PR) on the Intel GPU, as requested.

  • GPU: Intel(R) Graphics, driver 32.0.101.6737
  • Result: clears: 168 matched WARP, 10 differ, 0 failed, 0 in formats the layer does not expose, 0 skipped (WARP does not offer the format)

The 10 differences are all sRGB, and they are exactly the .5 boundary rounding you expected — the Intel GPU's linear→sRGB encode is 1 ulp off from WARP:

DIFF SRGB   R8G8B8A8_UNORM_SRGB    case 0 colour byte 2: layer bb, WARP bc
DIFF SRGB   R8G8B8A8_UNORM_SRGB    case 1 colour byte 26: layer bb, WARP bc
DIFF SRGB   R8G8B8A8_UNORM_SRGB    case 2 colour byte 2: layer bb, WARP bc
DIFF SRGB   R8G8B8A8_UNORM_SRGB    case 3 colour byte 0: layer 0c, WARP 0d
DIFF SRGB   R8G8B8A8_UNORM_SRGB    case 4 colour byte 26: layer bb, WARP bc
DIFF SRGB   B8G8R8A8_UNORM_SRGB    case 0 colour byte 0: layer bb, WARP bc
DIFF SRGB   B8G8R8A8_UNORM_SRGB    case 1 colour byte 24: layer bb, WARP bc
DIFF SRGB   B8G8R8A8_UNORM_SRGB    case 2 colour byte 0: layer bb, WARP bc
DIFF SRGB   B8G8R8A8_UNORM_SRGB    case 3 colour byte 0: layer fe, WARP ff
DIFF SRGB   B8G8R8A8_UNORM_SRGB    case 4 colour byte 24: layer bb, WARP bc

So on Intel, leaving the sRGB curve to the GPU does not reproduce WARP byte-for-byte — the same 1-ulp .5-boundary difference that #525 omits sRGB to avoid. Everything else (UNORM, SNORM, FLOAT, UINT, SINT, and every depth/stencil plane) matches WARP. Identical result with LEONIDA_VK_VALIDATION=1 (no validation errors).

@73N1X

73N1X commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Independent AMD validation of exact PR head 175b0ff04ed7e208431b8643d4ea42e3fb400ca0 on a Radeon RX 5700 XT, Windows driver 32.0.21045.5002, MSVC 19.44, with native D3D12 WARP as the reference. Synthetic fixtures only; Vulkan validation and synchronization validation enabled.

PR head: full runtime build succeeded; CTest 19/19 passed. d3d12_clear_formats_test reported:

clears: 174 matched WARP, 4 differ, 0 failed, 0 in formats the layer does not expose, 0 skipped (WARP does not offer the format)

All four differences are the depth plane of D24_UNORM_S8_UINT (cases 0-3). The device reports D24_UNORM_S8_UINT unavailable, using D32_SFLOAT_S8_UINT. First differing bytes:

  • case 0: byte 2, layer 80, WARP 40
  • case 1: byte 0, layer 00, WARP ff
  • case 2: byte 0, layer 4c, WARP 26
  • case 3: byte 2, layer 00, WARP 80

Baseline control: I built the same comparison fixture against the PR's base 4abd54571b6efa02d97eda4711792fa00b455dc3, adding only the fixture and its CMake target. It reported 101 matches, the exact same four D24 differences, and 73 cases in formats not exposed. Thus these AMD D24 readback differences predate this PR; the 73 newly exposed cases pass here. All color cases, including sRGB, matched WARP on this AMD device. No Vulkan validation errors were reported. The UINT comparison (21 readbacks), COM test and GPU replay suites A-D also passed on the PR head.

Integration note now that #388 has merged: I separately combined this head with #388 head 58019e85ecefde734a4e39b26c72e0792248eff8 in an isolated worktree. Only CMake conflicted; retaining both test targets resolved it. The combined GPU tests passed 13 typeless WARP readbacks plus 12 invalid-view rejections, 21 UINT readbacks, and replay suites A-E including predication. The broad format comparison retained the same 174/4 result.

However, the combined CPU CTest initially fails typeless_rtv_test.cpp:94: it expects unchanged float inputs for UNORM/sRGB, whereas this PR intentionally clamps/quantizes normalized channels before Vulkan. For its existing {1.5f, 2.5f, 256, -1} input, the literal callback expectations should be:

  • explicit RGBA8 UNORM: {1, 1, 1, 0}
  • explicit RGBA8 sRGB: {1.5f, 2.5f, 256, 0} (RGB is still passed to the GPU; alpha is UNORM)
  • UINT remains {1, 2, 255, 0}; the legacy undefined-format pass-through assertion stays unchanged.

Changing only those test expectations in the isolated combination gives CTest 24/24. That adjustment is local validation only, not pushed to either branch. Please include it when updating #521 onto the main containing #388. This is an integration-test expectation change, not evidence of a typeless GPU regression. The D24 fallback remains a separate inherited issue; I would not describe this AMD run as a full 178/178 pass.

@NWX10

NWX10 commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

Rebased after #525 merged: the branch is now one commit on main, f53f7de. It keeps only what #525 doesn't cover: round-half-to-even for UNORM/SNORM, the remaining format classes, sRGB alpha, D16, and the 178-case d3d12_clear_formats_test. typeless_rtv_test now expects the rounded value from render_target_clear_color instead of the raw float. Re-tested on the RTX 3060 Ti: ctest 24/24. d3d12_clear_formats_test (178), d3d12_typeless_rtv_test (13 readbacks) and d3d12_clear_test (59) all match WARP, with and without LEONIDA_VK_VALIDATION=1.

…D-45)

Rebased onto main after ItsNotRexed#525, which added SNORM/SINT render targets for four formats.
This keeps ItsNotRexed#525's formats and adds what it leaves out:

- Normalised clears round to nearest even like D3D, so 0.5 on an 8-bit channel is 128
  (NVIDIA's clears write 127). The layer hands Vulkan the exact fraction; NaN is 0 and
  out-of-range values clamp. Covers UNORM, SNORM (scale 127 or 32767, -1.0 is -127), the
  alpha of the sRGB formats, R10G10B10A2_UNORM and D16_UNORM depth.
- More formats: R8/R8G8/R16/R16G16/R16G16B16A16 SNORM, R8/R16 SINT, R8/R16 UINT,
  R16_UNORM and R16G16_UNORM, with their copy sizes; SINT and UINT of every width clamp to
  the component range and truncate toward zero.
- d3d12_clear_formats_test: 178 cases against WARP over UNORM, SNORM, sRGB, FLOAT, UINT,
  SINT and the four depth formats. typeless_rtv_test now expects the rounded UNORM value.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@NWX10

NWX10 commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

Rebased again, onto main c432cdc (after #600), as a7b9ea1. The only conflict was block_format, where both sides added cases; I kept both. Re-tested on the RTX 3060 Ti: ctest 27/27, and d3d12_clear_formats_test (178), d3d12_typeless_rtv_test and d3d12_clear_test (59) all match WARP. The one red check, linux-gpu-tools, is the llvmpipe cs_w32_lane_wrap / cs_wqm_w32 failure that main has too; #555 fixes it.

@AlxcBTW

AlxcBTW commented Nov 22, 2026

Copy link
Copy Markdown
Member

I tested a7b9ea1 on an AMD Radeon 880M (AMD driver 26.11.2) and an NVIDIA RTX 5070 Laptop (617.42), Windows 11, MSVC 17.14: pass, with one finding for D24S8 on AMD.

Test Radeon 880M RTX 5070
d3d12_clear_test (with and without LEONIDA_VK_VALIDATION=1) 59 of 59 cases match WARP 59 of 59 match WARP
d3d12_clear_formats_test 174 match, 4 differ 178 of 178 match
clear_color_test (CPU) 110 checks pass 110 checks pass

Why this matters. On plain main the RTX 5070 fails d3d12_clear_test with format 28 case 0 byte 2: Vulkan 7f, WARP 80. That case is a 0.5 channel of R8G8B8A8_UNORM, and 0.5×255 = 127.5 is an exact tie. NVIDIA's vkCmdClearColorImage writes 127, while WARP and AMD write 128. D3D11.3 §3.2.3.6 defines FLOAT→UNORM as c·(2ⁿ−1)+0.5 truncated, which gives 128, with 0.6 ULP of tolerance. So NVIDIA's 127 is within tolerance but not what an AMD-targeted title gets. This PR fixes it.

The 4 AMD differences are all D24_UNORM_S8_UINT depth cases, for example case 2 depth byte 0: layer 4c, WARP 26. The 880M has no native D24, so the layer substitutes D32S8, and the depth clear value is probably converted for D24 but read back from a D32 image, or the reverse. That looks separate from this PR. I'll post it as a finding: in #374 unless you'd rather take it here.

A note on ties. The spec rounds ties up, while this PR rounds half to even. They agree on every value 8-bit and 10-bit UNORM can produce, because 0.5 is the only tie there.

AI-assisted (Claude Code).

@tylerstraub

Copy link
Copy Markdown
Contributor

Replying to @AlxcBTW.

There’s a baseline control for the D24 finding. On the RX 5700 XT, @73N1X ran the same comparison fixture on both 175b0ff and its base 4abd545. All four D24 depth cases differed on both, including your case 2 byte 0 (4c versus WARP’s 26). That device also reported the D32S8 fallback. The matching signature on the 880M at a7b9ea1 supports tracking this separately from the color-clear change. The exact point where the depth bytes diverge remains open. If you file the finding, the active tracker is #634. RX 5700 XT baseline and per-case bytes

AI-assisted.

@troythedecoyx

Copy link
Copy Markdown
Contributor

Tested a7b9ea1 merged onto main c432cdc on NVIDIA GeForce RTX 4060 Ti (Ada), driver 32.0.16.2124 (NVIDIA 621.24), Windows 11 Home 26300, MSVC 2022 / Ninja, Vulkan SDK 1.4.363: pass, and it fixes an existing failure on this card.

  • d3d12_clear_formats_test: exit 0, 178 matched WARP, 0 differ, 0 failed.
  • d3d12_uint_clear_test: exit 0, 21 readbacks matched WARP on three formats.
  • d3d12_clear_test: exit 0, 59 RTV/DSV readbacks matched WARP. On main c432cdc without this PR it exits 1 at format 28 case 0 byte 2: Vulkan 7f, WARP 80, the exact-tie rounding this PR describes (I hit it while checking Runtime: clear selected slices of 3D color targets (D3D-64) #643, which fails the same way for that reason).
  • ctest 27/27.

AI-assisted.

@MrCheese5

Copy link
Copy Markdown
Contributor

Tested a7b9ea1 on RTX 4090 (driver 621.14), Windows 11 26200, MSVC 19.44: pass

  • Clean RelWithDebInfo Ninja build of runtime/ (Vulkan SDK 1.4.363.0), then ctest --test-dir runtime/build --output-on-failure: 27/27 passed.
  • GPU tests with LEONIDA_VK_VALIDATION=1 and VK_LAYER_KHRONOS_validation: d3d12_clear_formats_test, d3d12_clear_test, d3d12_com_test, d3d12_descriptor_test, d3d12_method_variants_test, d3d12_sampler2_test, d3d12_typeless_rtv_test, d3d12_vulkan_device_test, vk_command_replay_test all exit 0, with 0 validation messages.

d3d12_clear_formats_test and d3d12_clear_test pass. On current main, d3d12_clear_test (from #525) fails on this GPU with format 28 case 0 byte 2: Vulkan 7f, WARP 80, NVIDIA's tie rounding, and every other branch based on current main I tested today fails it the same way. This PR fixes that.

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

@Flyander Flyander 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.

Review of the current clear-rounding implementation.

// changes the mode would round differently. floor() does not depend on it, and x + 0.5 is exact here (x is at most
// a float times 65535, well inside a double's 53 bits).
inline double round_half_even(double x) {
const double r = std::floor(x + 0.5);

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.

[P2] Avoid the mode-sensitive addition for tiny positive values

x can be much smaller than one double ULP at 0.5 (for example, float denorm_min multiplied by 255). Under FE_UPWARD, x + 0.5 rounds to the next double above 0.5, so floor returns 1 and the clear becomes 1/255 instead of 0. This contradicts the comment that the sum is exact and breaks the intended rounding-mode independence for near-zero inputs. Please handle this range without adding the tiny value to 0.5, and include a near-zero case in the rounding-mode coverage.

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.

Thanks for catching the assumption about x + 0.5. I ran the three clear helpers verbatim from c0a92ebc with native MSVC /fp:strict and all four fesetround modes.

For float denorm_min() scaled by 255, FE_UPWARD moves the sum to nextafter(0.5, 1.0). That is still below 1, so floor returns 0. R8 UNORM with the positive input and R8 SNORM with both signs returned zero in all four modes.

I also checked 598,284 scaled inputs per mode at the half-integer thresholds and neighboring float values across the supported scales 3, 127, 255, 1023, 32767 and 65535. All selected the expected integer. A near-zero regression case would cover the distinction: the addition can round while staying in the same interval for floor.

AI-assisted.

@oVolkra

oVolkra commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested c0a92eb (merged onto main 64b45d0) on RTX 3060 (Ampere, subgroup 32..32), driver 617.14, Windows 11: d3d12_clear is fixed, but d3d12_typeless_families now fails.

Ran: ctest, ctest with LEONIDA_VK_VALIDATION=1, the unregistered *_test.exe, and run_gpu_tests.py native and with LEONIDA_W64_EMULATE=1, each compared with main 64b45d0 on the same machine.

  • d3d12_clear_test: exit 0 with this PR; it fails on main (the 0.5 tie, Vulkan 7f, WARP 80).
  • d3d12_typeless_families (ctest Do you guys have the game exe file? #121): passes on main, fails with this PR, with and without validation, and fails again on the retry. The ctest line, d3d12_typeless_families_test.exe run alone: exit 1, 82 clears compared with NVIDIA GeForce RTX 3060, 14 differ; ... WARP differs from the host in 14, 8 draws compared ... 0 differ.
  • Example: typeless 60 view 63 clear (0.5, 7, -1, 300): host 3f, layer 40 MISMATCH WARP 40.

My reading, not checked beyond this output: the test counts a clear as a failure when the layer differs from the host adapter's own D3D12 result (failed += !same, d3d12_typeless_families_test.cpp). With this PR the layer rounds the tie like WARP, and this NVIDIA host rounds it the other way (3f vs 40), so the 14 tie cases now differ from the host. The draws are unaffected. Either the test should compare ties with WARP when the host and WARP differ, or it should accept either value there.

Nothing else new: no other ctest or GPU-test failure compared with main.

AI-assisted: the build and test run were done with Claude Code on my machine; the numbers above are its unedited output.

@mixyt

mixyt commented Nov 23, 2026

Copy link
Copy Markdown

Independent A/B on a GTX 1650 Mobile (Turing), NVIDIA 621.24, Windows 11. Built aa2988cc (main) and c0a92ebc (this PR on the same base) locally with MSVC 14.44.35207, Release, Windows SDK 10.0.26100. The two test sources were byte-identical between builds.

Test Main aa2988cc PR c0a92ebc
d3d12_clear_test.exe (no arguments) Exit 1: 5 color/depth formats differ from WARP Exit 0: all 197 full/rectangle readbacks match WARP
d3d12_typeless_families_test.exe Exit 0: 0/82 clears differ from native D3D12 on the GTX 1650 Exit 1: 14/82 clears differ from native D3D12; the layer matches WARP in all 14

All 8 typeless draws match the native adapter in both builds; no typeless view formats were skipped. WARP differs from native D3D12 in 14/82 typeless clears in both builds. Example: typeless 60 view 63 (R8_SNORM view), clear (0.5, 7, -1, 300) -> native D3D12 3f, PR layer 40, WARP 40.

This reproduces the RTX 3060 report on Turing: the test fails because it checks the native-adapter result, even when the layer now matches WARP in those cases.

AI-assisted build and test run; synthetic fixtures only.

@kingzzim7-create

Copy link
Copy Markdown
Contributor

Tested c0a92eb merged onto main ec34b54 on an RTX 4060 Ti (Ada), driver 621.01, Windows 11 build 26300, VS 2026 / MSVC 14.52.37025: the same result as the RTX 3060 and GTX 1650 reports above.

  • d3d12_clear: passes with this PR (it failed on main on this card earlier: 5 diffs vs WARP).
  • d3d12_typeless_families: passes on main, fails with this PR. The same 14 of 82 tie clears (0.5, 7, -1, 300) differ from native D3D12, and in all 14 the layer equals WARP, e.g. typeless 60 view 63: host 3f, layer 40, WARP 40; typeless 27 view 28: host 7fff00ff, layer 80ff00ff, WARP 80ff00ff.
    So Turing, Ampere and Ada NVIDIA all round these ties the other way from WARP. The test failure is the comparison against the native adapter, not a layer regression; accepting WARP's value where the host and WARP differ (as suggested above) would cover all three. Happy to re-run once the test is updated, since Tests: register d3d12_clear in ctest again (TEST-919) #4294 waits on this PR. No game files. AI-assisted (Claude).

@searyecheesepeaceful

Copy link
Copy Markdown

Tested c0a92eb on Intel UHD 770 (driver 32.0.101.7088), Windows 11, MSVC 19.44, Vulkan SDK 1.4.357.0: fail in d3d12_clear_formats_test, all on the two sRGB colour formats.

d3d12_clear_formats_test exits 1 with and without LEONIDA_VK_VALIDATION=1: "clears: 168 matched WARP, 10 differ, 0 failed, 0 in formats the layer does not expose, 0 skipped". Every difference is one step off WARP in an sRGB colour byte:

  • R8G8B8A8_UNORM_SRGB cases 0, 1, 2 and 4: layer bb, WARP bc; case 3: layer 0c, WARP 0d
  • B8G8R8A8_UNORM_SRGB cases 0, 1, 2 and 4: layer bb, WARP bc; case 3: layer fe, WARP ff
    No validation messages were printed.

With validation on, clear_color_test (505 replay checks passed), d3d12_com_test, d3d12_vulkan_device_test, d3d12_descriptor_test, device_proxy_test and d3d12_typeless_rtv_test pass. ctest -R over the clear, COM, device, descriptor and replay tests: 92% tests passed, 1 tests failed out of 13 (d3d12_clear_formats). The PR body also names d3d12_uint_clear_test, which is not a target at this head.

AI-assisted.

@Hanioe2

Hanioe2 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

@kingzzim7-create Thanks for the Ada comparison. The test-only update is open at NWX10/Leonida#2, head efde95cc, one commit on top of this PR's c0a92ebc.

That update checks that the layer matches WARP byte for byte and the same-adapter normalized components are within one code. The Ada rerun you offered can use efde95cc to check whether it accounts for the same 14 cases.

AI-assisted.

@kingzzim7-create

Copy link
Copy Markdown
Contributor

@Hanioe2 re-ran with efde95c (NWX10#2) merged onto main 3faac55, RTX 4060 Ti (Ada), driver 621.01, Windows 11, MSVC 14.52: all pass.

  • d3d12_clear: passed, 197 full/rectangle readbacks matched WARP.
  • d3d12_typeless_families: passed. "82 clears compared, 0 differ, 14 one-code ties where the layer matches WARP"; 8 draws, 0 differ. These are the same 14 cases that failed on c0a92eb.
  • d3d12_clear_formats: passed, 178 matched WARP, 0 differ. So the sRGB one-step differences gertify saw on Intel UHD 770 don't appear on NVIDIA.
    AI-assisted (Claude).

@zzEmmazz

Copy link
Copy Markdown
Contributor

Tested c0a92ebc applied onto main 3faac557 (gh pr diff 521 with git apply, no conflicts) on an AMD and an NVIDIA GPU in the same machine, Windows 11 26200, VS 2026, RelWithDebInfo, Vulkan SDK 1.4.363.0, WARP as the reference.

Test Radeon (Ryzen 7 9700X iGPU), AMD 32.0.21042.62, Vulkan driver 2.0.353 RTX 3070, NVIDIA 610.74
d3d12_clear_test, main exit 0, 197 full/rectangle readbacks matched WARP exit 1, 5 color/depth format(s) differ from WARP
d3d12_clear_test, this PR exit 0, 197 matched exit 0, 197 matched
d3d12_clear_formats_test, this PR exit 0, 178 matched WARP, 0 differ, 0 failed exit 0, 178 matched WARP, 0 differ, 0 failed
clear_color_test, this PR 505 full/rectangle integer, normalised and float replay checks passed (CPU only)

The five on main on the RTX 3070:

R8G8B8A8_UNORM case 0 byte 2: Vulkan 7f, WARP 80
R8G8B8A8_SNORM case 0 byte 2: Vulkan 3f, WARP 40
B8G8R8A8_UNORM case 0 byte 0: Vulkan 7f, WARP 80
B8G8R8X8_UNORM case 0 byte 0: Vulkan 7f, WARP 80
depth format 55 case 1 byte 12: Vulkan ff, WARP 00

The last one is the D16_UNORM rectangle clear to 0.5 (0x7fff where WARP has 0x8000), which the D16_UNORM branch of this PR in vulkan_replay.h fixes. That is the failure D3D-421 was opened for, so D3D-421 needs no change of its own.

D16 in more detail. A separate probe (not in the repository) clears 7934 depth values into D16_UNORM, 700 of them as whole-view clears and all of them as one rectangle clear each, and compares the layer with WARP and with the native D3D12 drivers of both adapters. The values are steps, the floats around half steps, 1/64 steps and random values.

whole-view clears that differ from WARP rectangle clears that differ from WARP
layer on main, Radeon 6 of 700 334 of 7934
layer on main, RTX 3070 23 of 700 2708 of 7934
layer with this PR, Radeon 6 of 700 334 of 7934
layer with this PR, RTX 3070 6 of 700 334 of 7934
native D3D12, AMD driver 6 of 700 334 of 7934
native D3D12, NVIDIA driver 23 of 700 2708 of 7934
  • With this PR the layer writes the same on both GPUs, so the result no longer depends on the Vulkan driver. On main NVIDIA rounds down more than exact ties (a product of 37550.5247 gives 0x92ae, 16.5347 gives 0x0010).
  • The 334 that remain are not exact ties. 0.5 is the only depth value whose product with 65535 is exactly a half. They are values where WARP's float multiply lands on a half although the real product does not: WARP equals "multiply by 65535 in float, round to nearest even" on all 7934 values, and AMD's D3D12 driver equals "round the exact product to nearest even", which is this PR's quantize_unorm, on all 7934. Example: 0.9f (product 58981.4984) is 0xe666 on WARP and 0xe665 on AMD's D3D12 driver and in the layer with this PR. The two references differ by one code there, and the PR follows the AMD driver. depth24.h takes the float product for D24, where WARP and AMD were measured to agree, so D16 and D24 now use different products. Whether D16 should follow WARP at these values is a choice for the maintainers. With the float product in the D16 branch the layer matched WARP on all 7934 values on both GPUs.
  • The float handed to Vulkan is read back as the same code by both drivers: all 65536 codes as float(q / 65535) come back as q through rectangle clears, and 2048 of them through whole-view clears, on the Radeon and the RTX 3070.

Not checked: d3d12_typeless_families with this PR (reported above by others), LEONIDA_VK_VALIDATION=1, Intel, and the same float-product comparison for the colour formats.

AI-assisted.

@ItsNotRexed
ItsNotRexed merged commit d16bf99 into ProjectLeonida:main Nov 23, 2026
3 of 10 checks passed
ItsNotRexed pushed a commit that referenced this pull request Nov 23, 2026
#525 (D3D-45) renamed the test and widened it, but this paragraph kept the
old name and its "seven input sets on all three formats". It now names the
test, its eleven integer input sets on the UINT/SINT formats, and that ctest
runs only its --rgb9e5 mode until #521 lands.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
gregoirener pushed a commit to gregoirener/Leonida-latest-backup-Monday-23-nov-Japanese-time- that referenced this pull request Nov 23, 2026
…rojectLeonida#521), three close-parity copies now match WARP, the source-size checks start from 300x200 again after ResizeTarget, one test_attribute_trace in xmem_test

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@marquezinii

Copy link
Copy Markdown
Contributor

@Flyander, thanks for the review. I checked the near-zero case. You were right that the comment overstated it: x + 0.5 is only exact for |x| >= 2^-14. The result is still right, though. Under FE_UPWARD the sum rounds to just above 0.5, floor() of that is 0, and r - x == 0.5 is false, so denorm_min * 255 clears to 0, not 1/255. To be sure I ran quantize_unorm/quantize_snorm verbatim against the exact nearest-even code. It covered every float in range, at scales 255, 1023, 65535, 127 and 32767, under all four modes: 29.8 billion cases, 0 mismatches. A std::nearbyint version fails 7.8 billion of them, so the check does catch mode-dependent rounding. #5704 corrects the comment and adds the near-zero cases you asked for to clear_color_test (denorm_min, FLT_MIN, 1e-20 on 8/16-bit UNORM and SNORM under the three non-default modes).

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.