Skip to content

d3d12_vulkan_device_test: 0.6 ULP tolerance for placed SRGB-cast clears (D3D-221) - #1752

Merged
ItsNotRexed merged 2 commits into
ItsNotRexed:mainfrom
CowBoYdu76:d3d-221-placed-clear-tie
Nov 22, 2026
Merged

ItsNotRexed merged 2 commits into
ItsNotRexed:mainfrom
CowBoYdu76:d3d-221-placed-clear-tie

Conversation

@CowBoYdu76

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: D3D-221 (claim, from #1725)

What and why

On main (89b047cd), d3d12_vulkan_device still fails on an Intel UHD 770 (101.7092), but differently from #1725. The cross-adapter tie rule from cb43923 now accepts the plain clear. On this machine the Intel D3D12 adapter is not used as the host, so the test falls back to WARP. The remaining failure is the SRGB-cast clear:

placed SRGB-cast clear row 0 byte 1: ours bb, host bc
line 4943: host_side(warp10.p, false)

The ideal encoding of linear 0.5 is 1.055 * 0.5^(1/2.4) - 0.055 = 0.73536, which scales to 187.516. Intel's Vulkan driver writes 187 and WARP writes 188; NVIDIA's Vulkan driver also writes 188. D3D11.3 spec 3.2.3.8 (FLOAT -> SRGB) permits "a tolerance of 0.6f ULP (on the integer side)", the same as 3.2.3.6 (FLOAT -> UNORM), so both codes are valid.

The change generalises the existing tie rule instead of adding a second special case. Against another adapter or WARP, a byte may differ from the host when both sides are within 0.6 ULP of the ideal value:

  • For the plain clear, this accepts exactly what the tie rule accepted: 127/128 for 127.5, and nothing else in this clear colour.
  • For the SRGB-cast clear, it accepts 187/188 for 0.5. It still rejects anything off by 2 or more.
  • At 0.75 (224.61), 224 is 0.61 away and stays rejected.
  • Alpha stays linear.

The layer's own adapter (same LUID) is still compared exactly. The summary line now reports plain and SRGB-cast bytes separately.

Tested

Windows 11, MSVC 19.44, Vulkan SDK 1.4.363.0:

Device (LEONIDA_VK_DEVICE) Host Before After
RTX 4070 SUPER (NVIDIA 616.64) own adapter pass, exact pass, exact
RTX 4070 SUPER WARP (LEONIDA_HOST_ADAPTER=warp) pass (16 plain tie bytes) pass: 16 plain, 0 SRGB-cast bytes within tolerance
Intel UHD 770 (101.7092) WARP (fallback) fail, line 4943 pass: 0 plain, 16 SRGB-cast bytes within tolerance

Full ctest:

  • RTX 4070 SUPER: 97/98. The one failure is d3d12_draw ("bundle blend pixel (0, 0): got 255,0,0,255, expected red 64"). It also fails on unchanged main and is not touched here, see the note below.
  • UHD 770: 95/98. The failures are d3d12_draw (same as above) and d3d12_descriptor / d3d12_copy_xfmt (D3D-219 and D3D-220, unchanged).

Note: d3d12_draw fails on 89b047cd on both GPUs at the bundle blend check added by #1660.

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. (No translator change.)

AI-assisted (Claude).

🤖 Generated with Claude Code

…rs (D3D-221)

Against another adapter or WARP, a placed clear byte may differ from the
host when both sides are within 0.6 ULP of the ideal value, the
tolerance D3D11.3 spec 3.2.3.6 (FLOAT -> UNORM) and 3.2.3.8
(FLOAT -> SRGB) allow. The plain tie rule already did this for
0.5 * 255; the SRGB-cast clear's 0.5 encodes to 187.516, where Intel's
Vulkan driver (UHD 770, 101.7092) writes 187 and WARP 188. The layer's
own adapter stays exact.

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

HQasper commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Tested 146a9f02 on NVIDIA GeForce RTX 5090 (driver 621.24), Windows 11 Pro 10.0.26300, Vulkan SDK 1.4.363.0, Visual Studio 18 BuildTools x64 (RelWithDebInfo): pass. No game files.

What I ran, from the PR head in its own worktree:

  • Build of d3d12_vulkan_device_test: clean; the only warning is the pre-existing C4456 in vulkan_replay.h:2960 that XDXR builder follow-up: small-build sort, and MSVC C4456 in vulkan_replay.h (D3D-178) #1743 is fixing.
  • Own adapter (the default host, WARP not involved): exit 0, and the D3D-90 line names the RTX 5090 as the layer's own adapter, so the comparison is the exact one — no bytes needed the tolerance.
  • LEONIDA_HOST_ADAPTER=warp: exit 0, placed clears: 16 plain and 0 SRGB-cast bytes differ from the host by one code — the same 16 plain tie bytes your table shows on the 4070 SUPER.

Reproducing the Intel case without Intel hardware — I changed only the layer's SRGB clear colour inside placed_cast_scenario (to 0.4982f, which encodes to 187.2, so the Vulkan side lands on 187) and left the host at the real 0.5f (WARP → 188):

Variant Result
this PR's rule, 187 vs 188 exit 0, 16 plain and 16 SRGB-cast bytes differ … within the 0.6 ULP tolerance
main's comparison (89b047cd's file), same 187 vs 188 exit 1, placed SRGB-cast clear row 0 byte 1: ours bb, host bc — the failure you report on the UHD 770
this PR's rule, 189 vs 188 (two codes) exit 1, … ours bd, host bc — the tolerance does not absorb a real error

That last row is the one I most wanted: the rule is not a blanket one-byte allowance. Exhaustively over all byte pairs, the predicate accepts only (187, 188) at the 0.5 SRGB ideal, only (127, 128) at the plain 127.5, and nothing at 0.25, 0.75 or alpha — including 224 at 0.75, exactly as your note says.

Spec check: 3.2.3.8 gives the ideal as c <= 0.0031308f ? 12.92*c : 1.055*c^(1/2.4) - 0.055, then *(2ⁿ-1), +0.5f, fraction dropped, followed by "This conversion is permitted tolerance of 0.6f ULP (on the integer side) … any value within 0.6f ULP of a representable target format value is permitted to map to that value" — the same sentence 3.2.3.6 carries for FLOAT → UNORM, which this test already relied on (docs/d3d12_vulkan.md:215 records it for the D24 path). 19.1.3.2 says an _SRGB format's A channel is stored in Gamma 1.0, so i % 4 == 3 ? c : ideal_srgb(c) is the right exception. Your ideal_srgb is that formula.

One non-blocking thing. The accept side of the new SRGB rule is only reached when the host rounds differently, i.e. on Intel: here and on your 4070 the bytes agree, both this PR and unchanged main pass, and only the plain tie path runs. So a future edit of that 0.6 — or a quiet return to an exact SRGB compare — would leave the test green on every NVIDIA/AMD machine the maintainers run. Pinning the predicate itself would cover it, e.g. next to the loop: accept (187, 188, 187.516), reject (186, 188, 187.516), reject (224, 225, 224.6104) — the comment would then have an executable statement of what the tolerance allows, in the spirit of replay_readback_stages_test.cpp:182.

I did not run the full ctest (the PR touches one test file), and I have no Intel adapter to re-run your UHD 770 row. AI-assisted review.

The accept side of the SRGB-cast rule only runs where the host rounds
differently (Intel), so a change to it would stay green on NVIDIA and
AMD. ideal_srgb and within_06_ulp move to file scope, and the test
checks the predicate directly: (187, 188) at 187.516 and (127, 128) at
127.5 are accepted; (186, 188), (126, 128), (224, 225) at 224.61,
(136, 137) at 136.97 and (254, 255) at 255 are not. Raising the
tolerance to 1.6 fails the test on an RTX 4070 SUPER. Suggested in review.

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

Copy link
Copy Markdown
Contributor Author

Thanks for the review and for reproducing the Intel case without Intel hardware.

I've pushed the pin: ideal_srgb and within_06_ulp are now at file scope, and the test checks the predicate directly before the host comparison:

  • Accepted: (187, 188) at 187.516 and (127, 128) at 127.5.
  • Rejected: (186, 188), (126, 128), (224, 225) at 224.61, (136, 137) at 136.97 and (254, 255) at 255.

As a mutation check, raising the tolerance to 1.6 makes the test fail at the pinned line on an RTX 4070 SUPER.

Re-run after the change: exit 0 on the 4070 SUPER against its own adapter and against WARP, and on the UHD 770 (16 SRGB-cast bytes within tolerance).

@kapitche

Copy link
Copy Markdown
Contributor

Tested on Windows 11 with two GPUs on one machine (runtime built from this PR's head, MSVC 14.51). This fixes d3d12_vulkan_device on the Intel UHD 770: it fails there on current main (line 3768, #1548) and passes with this PR. On the RTX 4080 SUPER, 100/101 pass. d3d12_draw fails on both GPUs, but it fails the same way on every PR built on current main (bundle blend pixel (0, 0): got 255,0,0,255, expected red 64), so it's a main regression, not from this PR. I'm bisecting it now and will report in the coordination issue. Other Intel UHD 770 failures are the known ones in #1548.

@mesterember104-cpu

mesterember104-cpu commented Nov 22, 2026 •

Copy link
Copy Markdown

Tested ceb244b on Intel(R) UHD Graphics (Tiger Lake (Xe-LP) iGPU 0x9a78, subgroup 8..32, no mesh), driver 32.0.101.7088, Windows 11, MSVC 14.44: pass

AI-assisted (GLM, operated by the account owner).

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.

5 participants