Skip to content

Tests: placed castable clears compare with the layer's own adapter; a different adapter may differ by one code at an exact .5 tie - #1616

Merged
ItsNotRexed merged 3 commits into
ItsNotRexed:mainfrom
AlxcBTW:placed-clear-rounding
Nov 22, 2026
Merged

ItsNotRexed merged 3 commits into
ItsNotRexed:mainfrom
AlxcBTW:placed-clear-rounding

Conversation

@AlxcBTW

@AlxcBTW AlxcBTW commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

What and why

d3d12_vulkan_device_test failed on NVIDIA at the placed castable clear (D3D-90 / #1083): placed plain clear row R byte 1/5/9/13: ours 7f, host 80. A float 0.5 clear of a UNORM channel is an exact rounding tie (0.5 * 255 = 127.5), and D3D does not pin it: the D3D11.3 functional spec, 3.2.3.6 FLOAT -> UNORM, computes c * (2^n - 1) + 0.5 and drops the fraction but permits a tolerance of 0.6 ULP on the integer side, so either neighbouring code is valid. Native D3D12 gives 0x7f on NVIDIA (RTX 3080 616.64, RTX 3090 610.88, measured by @Flyander and @Rainmaker33) and 0x80 on Radeon and WARP; the layer's Vulkan path gives 0x7f on NVIDIA and 0x80 on AMD. The failure came only from comparing the layer on the NVIDIA GPU with a host device on a different adapter.

The layer is unchanged. (An earlier revision of this PR changed the layer to round ties up; it is reverted, thanks to the 610.88 measurement and review.) The test changes:

  • The host device for the placed castable comparison is the layer's own adapter (matched by LUID, then PCI ids) unless LEONIDA_HOST_ADAPTER names one, and the comparison against it is exact.
  • Against a different adapter or WARP, an exact tie byte of the plain clear may differ by one code; every other byte stays exact.
  • The output names the host adapter and says whether it is the layer's own.

Tested

Tested cb43923 on NVIDIA GeForce RTX 5070 Laptop (617.42) and AMD Radeon 880M (26.11.2), Windows 11: pass.

  • d3d12_vulkan_device_test on each GPU, default host and LEONIDA_HOST_ADAPTER=warp: 4/4 pass. Default host is the GPU's own adapter (exact comparison); WARP, and a Radeon host under the NVIDIA layer, take the tie tolerance on 16 bytes.
  • Full ctest on each GPU with LEONIDA_VK_VALIDATION=1: 87/87 pass (NVIDIA: d3d12_rgb9e5_rtv skipped), 0 VUIDs.
  • pytest tests/test_ctest_registration.py: 3 passed.

AI-assisted (Claude Code).

Checklist

  • Built and tested locally
  • No game data, keys or decryption
  • Test not weakened: same-adapter comparison is exact, the tolerance covers exact ties only
  • merge-tree against origin/main clean

🤖 Generated with Claude Code

D3D12 converts a float clear to the nearest UNORM code with a tie going up
(0.5 * 255 = 127.5 is 0x80, per WARP and the Radeon host). Vulkan leaves the
tie to the GPU and NVIDIA rounds it down (0x7f), so the placed castable clear
in d3d12_vulkan_device_test differed on the RTX 5070. render_target_clear_color
now hands Vulkan the code above an exact tie (code / max) for the 8- and 16-bit
UNORM formats; every other value is passed through. Pinned in
replay_clear_gate_test; clear_color_test expects the same.

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

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

The fix covers 8-bit and 16-bit UNORM formats, but the runtime also maps DXGI_FORMAT_R10G10B10A2_UNORM through VK_FORMAT_A2B10G10R10_UNORM_PACK32. Exact ties in the 10-bit RGB channels (0.5 * 1023) and the 2-bit alpha channel (0.5 * 3) still pass through unchanged, so the same rounding mismatch can remain on this common render-target format. Please handle per-channel maxima (1023 for RGB, 3 for alpha) and add a packed-format regression case, or document why this format is intentionally excluded.

Comment thread runtime/src/vulkan_replay.h Outdated
case VK_FORMAT_R16_UNORM:
case VK_FORMAT_R16G16_UNORM:
case VK_FORMAT_R16G16B16A16_UNORM: unorm_max = 65535; break;
default: break;

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.

This switch omits VK_FORMAT_A2B10G10R10_UNORM_PACK32, the backing format for DXGI_FORMAT_R10G10B10A2_UNORM. RGB and alpha have different UNORM maxima (1023 and 3), so a scalar maximum is insufficient, but the exact-tie rule should cover this format too.

@whattheflop

Copy link
Copy Markdown
Contributor

AI-assisted independent verification of the published head f4eab25ec289de1d9e2f6a0eb04d98953bd66e45 against the advertised base 41f448261e1de8a410b4d760e69a7e5656cef858. The head's parent is 99f99890. Both production libraries were built directly from their published trees.

Native D3D12 on the RTX 3080 returned 0x7f for the green midpoint on both revisions. On that card the patch changes Vulkan from matching native D3D12 to matching WARP, which returned 0x80. Native D3D12 on the Ryzen 7 9800X3D Radeon iGPU returned 0x80 in this run.

Adapter and driver Revision Vulkan RGBA Native D3D12 RGBA WARP RGBA Vulkan bytes matching native / WARP
GeForce RTX 3080, NVIDIA 616.64 (10de:2216) Base 40 7f bf ff 40 7f bf ff 40 80 bf ff 64/64 / 48/64
GeForce RTX 3080, NVIDIA 616.64 (10de:2216) Head 40 80 bf ff 40 7f bf ff 40 80 bf ff 48/64 / 64/64
Radeon iGPU, AMD 25.10.30.02 (1002:13c0) Base 40 80 bf ff 40 80 bf ff 40 80 bf ff 64/64 / 64/64
Radeon iGPU, AMD 25.10.30.02 (1002:13c0) Head 40 80 bf ff 40 80 bf ff 40 80 bf ff 64/64 / 64/64

The table is for the no-list R8G8B8A8_UNORM control. Each RGBA tuple occurred in all 16 texels. Each 48/64 comparison differed in all 16 green bytes only. The sRGB cast was 89 bc e1 ff in all 16 texels on every path (64/64 bytes). Two runs per GPU and revision produced identical results.

The focused variant extracted the unchanged stock placed_cast_scenario and ran just those two valid clear/readback paths against each revision's production gta6rt_d3d12_com library. Native D3D12 was created on the explicitly selected hardware DXGI adapter and checked by LUID. WARP was explicitly selected as the Microsoft Basic Render Driver (1414:008c). Each process used one pinned Vulkan ICD and Khronos 1.4.363 synchronization validation, with zero validation diagnostics. Windows 11 25H2 build 26200.9974, MSVC 19.38.33145.0. The CPU-only clear_color and replay_clear_gate tests passed on both revisions. GPU coverage here is limited to these two 8-bit placed clears.

The earlier #1083 pre-rebase Radeon result recorded 0x7f on its host path. The explicitly selected Radeon host here gave 0x80. As historical context, Microsoft's D3D11.3 functional spec §3.2.3.6 specifies ideal half-up conversion with a 0.6 integer-side ULP tolerance, which admits both adjacent codes at an exact midpoint. The RTX 3080 readback is direct D3D12 evidence against the PR's universal host-rounding statement for this clear.

Tracking is already in place under D3D-188 in #1548, carrying forward the original finding and claim in #1380.

@Rainmaker33

Copy link
Copy Markdown

Tested f4eab25 on NVIDIA GeForce RTX 3090 (Ampere), driver 610.88 (Vulkan 1.4.341), Windows 11 Pro 26300: this PR makes d3d12_vulkan_device fail here; main passes.

The PR's diff applied cleanly to main 41f4482. Runtime built with scripts\build_runtime.ps1 (VS 2022, CMake, RelWithDebInfo), Vulkan SDK 1.4.363.0. Same result with and without LEONIDA_VK_VALIDATION=1.

d3d12_vulkan_device_test exit placed plain clear, 0.5 on R8G8B8A8_UNORM
main 0 ours and host agree (no mismatch lines)
this PR 1 placed plain clear row 0 byte 1: ours 80, host 7f (bytes 1/5/9/13 of each row), then line 3850: host_side(host10.p)

So the host the test compares against, the NVIDIA D3D12 driver on this adapter, also rounds the 127.5 tie down to 0x7f on 610.88. It isn't a fixed D3D12 rule. WARP and the 880M give 0x80, NVIDIA's D3D12 610.88 gives 0x7f, and NVIDIA Vulkan gives 0x7f here. On this driver, main already matches the host, and forcing 0x80 breaks that.

Which NVIDIA driver failed on main for you, with 0x7f from Vulkan and 0x80 from the D3D12 host? If it's a newer branch, the tie rule may need to follow the host's answer, or the test may need to accept either value for an exact tie rather than hard-coding round-up.

@Flyander

Copy link
Copy Markdown
Contributor

New independent GPU data changes my read of the rounding rule: native D3D12 returned 0x7f on an RTX 3080 (driver 616.64) and RTX 3090 (610.88), while Radeon and WARP returned 0x80. On those NVIDIA systems, this patch changes a native-matching result into a mismatch. The current helper and test therefore should not encode round-up as a universal D3D12 rule; please resolve the host-vs-layer behavior per adapter and update the test to compare against the same adapter. My packed 10:10:10:2 coverage note is secondary until the expected rule is clear.

NVIDIA's own D3D12 driver rounds the 127.5 tie down too (RTX 3090, 610.88),
so D3D12 has no single tie rule and the layer passes clear values through
as before. The mismatch was a host device on another adapter.

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

Copy link
Copy Markdown
Contributor

Two-vendor desktop data, adding to whattheflop's and Rainmaker33's results above: it's the comparison's host choice that fails, not the layer's rounding. AI-assisted (omp orchestrator), no game files.

Setup. RTX 5060 Ti (621.24) and RX 9060 XT (AMDVLK 32.0.32029.2010), Windows 11. I made default-flag builds of main 99f99890 (with an unrelated GCL9 commit on top) and of f4eab25e. The Vulkan layer was pinned to one GPU at a time through the loader, and LEONIDA_HOST_ADAPTER picked the host. The default adapter here is the RTX. Each cell is the result of line 3768: host_side(host10.p):

layer host main #1616
RTX 5060 Ti default = RTX 5060 Ti pass fail, ours 80 / host 7f
RTX 5060 Ti RX 9060 XT, or WARP fail, ours 7f / host 80 pass
RX 9060 XT default = RTX 5060 Ti fail, ours 80 / host 7f fail, ours 80 / host 7f
RX 9060 XT RX 9060 XT, or WARP pass pass

What the table shows.

  • The third row is the other direction of your laptop case: an AMD layer against an NVIDIA default host.
  • It fails on both revisions. No tie rule in the layer can pass it together with the fourth row: AMD's Vulkan and AMD's D3D12 both write 0x80, and NVIDIA's D3D12 writes 0x7f.
  • Every failing cell pairs two vendors.
  • With a same-GPU host, main passes on both GPUs and this PR fails on the NVIDIA one.

The test already has a fix. The castable placed comparison creates its host with create_host_device(), which uses the default adapter, just before EXPECT(host_side(host10.p)).

  • The same file has create_host_device_for_physical(vk.instance, vk.physical, vk.instance_proc, ...), which matches the Vulkan GPU by LUID, then by PCI ids. compare_options1 uses it, and its comment explains why: on a PC with two GPUs, the default adapter is the wrong oracle.
  • Using it at that one call site makes each GPU compare against its own D3D12 driver, without changing what the layer writes.
  • The WARP fallback, used when that host can't cast, would still compare across implementations for an exact tie.

It's your claim (D3D-188), so I'm leaving the fix with you. I'm happy to run a revision on this box, on both GPUs and with either host.

@Flyander

Copy link
Copy Markdown
Contributor

Additional finding in the coordination issue (#1548, comment by abilliontokens): this failing placed comparison uses create_host_device() (the default D3D12 adapter), while the same test suite already has create_host_device_for_physical() to match LUID/PCI IDs. On RTX 5060 Ti and RX 9060 XT the baseline main passes when compared to the same physical GPU. That points to a host-selection bug in the comparison as the original signal; please verify against the same GPU before changing clear values. The reported native 0x7f on RTX 3080/3090 also means an unconditional 0x80 can regress real same-adapter behavior.

@Flyander

Copy link
Copy Markdown
Contributor

The coordinator has now confirmed in #1548 that the castable-clear comparison is using the wrong D3D12 adapter: the same-GPU helper makes baseline main pass on RTX 5060 Ti and RX 9060 XT, while this tie-up change fails on NVIDIA because native D3D12 writes 0x7f. Please replace the unconditional clear rewrite with a same-physical-adapter host comparison in d3d12_vulkan_device_test.cpp and rerun the case; the data now points to a test-comparator bug, not a missing clear conversion.

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

The main blocker is now the comparator, not the conversion: the existing d3d12_vulkan_device_test clear comparison uses create_host_device() (default adapter) while the Vulkan device may be another GPU. The coordination issue reports baseline main passes with create_host_device_for_physical() on RTX 5060 Ti and RX 9060 XT, and this forced tie-up rule fails on NVIDIA where native D3D12 returns 0x7f. Please fix the host match and retest before changing clear values. The packed 10:10:10:2 coverage question is secondary until same-adapter behavior is established.

… layer's own adapter

Float -> UNORM at an exact tie (0.5 * 255 = 127.5) may map to either code
(D3D11.3 functional spec 3.2.3.6, 0.6 ULP tolerance). Native D3D12 gives 0x7f on
NVIDIA (RTX 3080 616.64, RTX 3090 610.88; Vulkan too) and 0x80 on Radeon and
WARP, so comparing the layer on NVIDIA with a host on another adapter failed
the placed plain clear. The host is now the layer's own adapter (LUID, then PCI
ids) unless LEONIDA_HOST_ADAPTER names one, and the output says which adapter
it was and whether it is the layer's. Against a different adapter or WARP an
exact tie may differ by one code; every other byte stays exact. The layer is
unchanged.

Measurements and review by @Rainmaker33 and @Flyander.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@AlxcBTW AlxcBTW changed the title Runtime: UNORM clears round an exact tie up like D3D12 (NVIDIA gave 0x7f for 0.5; d3d12_vulkan_device failed there) Tests: placed castable clears compare with the layer's own adapter; a different adapter may differ by one code at an exact .5 tie Nov 22, 2026

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

The new head removes the unconditional clear rewrite and fixes the comparator to use the Vulkan device's matching D3D12 adapter. It keeps same-adapter comparisons exact and allows only the documented one-code difference for exact UNORM ties against a different adapter/WARP. No blocking issue remains in this review.

@whattheflop

Copy link
Copy Markdown
Contributor

AI-assisted follow-up on exact head cb439236d1abb0fa2c0160b1e1bdc182f02961d6 (reported base 41f448261e1de8a410b4d760e69a7e5656cef858, upstream main a0acd33d77babe67a28e398b2936a9f735a50f5d at verification). The PR diff is test-only, and the runtime tie-up is reverted.

  • With LEONIDA_HOST_ADAPTER unset, the stock selector chose native D3D12 on the same LUID as both Vulkan instances. RTX 3080 / 616.64 matched 00000000:0000f789 with plain RGBA 40 7f bf ff. Ryzen 7 9800X3D Radeon iGPU / 25.10.30.02 matched 00000000:00012761 with 40 80 bf ff. Both strict comparisons matched 64/64 bytes and 16/16 texels for each clear.
  • With WARP explicitly selected (LUID 00000000:0001272e), RTX → WARP matched 48/64 plain bytes and Radeon → WARP matched 64/64. The two opposite hardware pairings each matched 48/64 plain bytes. The shipped comparator accepted exactly 16 green-byte differences of one code (0x7f ↔ 0x80) in each 48/64 pairing. All six sRGB comparisons were 64/64, with 89 bc e1 ff in every texel.
  • The disposable valid-only wrapper linked the exact head's production library and reused the stock clear scenario, selector, and byte comparator. Scope was the two placed clears, excluding refusal cases. Six GPU pairings passed twice with one process-local ICD and Khronos 1.4.363 synchronization validation, with zero validation diagnostics. The extracted comparator passed six CPU checks, including rejection of a same-LUID midpoint mismatch, a two-code cross-adapter delta, a non-tie mismatch, and an sRGB mismatch.

These runs directly verify the revised selector and comparator on the hardware from my earlier report. Existing tracking is under D3D-188 in #1548.

@ItsNotRexed
ItsNotRexed merged commit 51dc01f into ItsNotRexed:main Nov 22, 2026
3 of 4 checks passed
@UlteriorMotive00

Copy link
Copy Markdown
Contributor

Tested cb43923 (0 behind main) on a desktop with an AMD Radeon RDNA2 iGPU (Ryzen 7 9800X3D, 32.0.21042.62) and an RTX 5070 (617.42), where the NVIDIA card is the default DXGI adapter. That's the pairing that fails on main: with the layer on the iGPU, main's check compares it with the NVIDIA host and fails at line 3768: host_side(host10.p) (placed plain clear ... ours 80, host 7f). Windows 11 Home 10.0.26300, MSVC 14.44, Vulkan SDK 1.4.363.0, LEONIDA_VK_VALIDATION=1.

layer GPU host d3d12_vulkan_device_test
AMD iGPU default: AMD Radeon(TM) Graphics, "the layer's own adapter" pass, exact
AMD iGPU LEONIDA_HOST_ADAPTER=warp pass
RTX 5070 default: RTX 5070, "the layer's own adapter" pass, exact
RTX 5070 LEONIDA_HOST_ADAPTER=warp pass, "the host rounds the exact .5 tie the other way in 16 bytes"

Full ctest (-E queue_proxy, see #1548): 86/86 on both GPUs, no validation messages. Before finding this PR, I'd made the same host-adapter change locally (create_host_device_for_physical unless LEONIDA_HOST_ADAPTER is set) and it passed the same way. This PR covers it, plus the tolerance for a different adapter, so I'm not opening mine.

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

@requiemsnkrp

Copy link
Copy Markdown

Tested cb43923 on NVIDIA GeForce RTX 3060 (driver 32.0.16.1714), Windows 11, MSVC 19.51, Windows SDK 10.0.26100: pass.

Built runtime/ (RelWithDebInfo) and ran ctest -E "present|swapchain|frame_pacer": 83/83 passed. The window tests (d3d12_present, xbox_present, dxgi_swapchain, frame_pacer) were not run for this PR. No Vulkan validation layers on this machine. No game files.

AI-assisted (Claude).

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.

8 participants