Skip to content

Runtime: clears of the D3D-60 integer formats match WARP, and R8_TYPELESS (follow-up to #600) - #589

Merged
ItsNotRexed merged 10 commits into
ItsNotRexed:mainfrom
NWX10:d3d-60-formats
Nov 23, 2026
Merged

ItsNotRexed merged 10 commits into
ItsNotRexed:mainfrom
NWX10:d3d-60-formats

Conversation

@NWX10

@NWX10 NWX10 commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Claimed in #374 as: D3D-60. #600 (merged) added the format mappings. This is the part it left out.

Depends on #521: its commit (a7b9ea1) comes first here. Review the second, 23827fe.

What and why

#600 made CreateCommittedResource accept R8G8, R16G16 and R32G32 UINT/SINT, R16G16B16A16 UINT/SINT and R10G10B10A2_UINT. But render_target_clear_color still treats them as float formats, so ClearRenderTargetView writes the float's bits. A clear to 255 stores 0x437f0000 in an R8G8_UINT target.

  • Those formats now convert like WARP: each channel clamps to the component range and truncates toward zero, and NaN is 0. R10G10B10A2_UINT clamps per channel (10, 10, 10 and 2 bits).
  • R8_TYPELESS is mapped too (R8_UNORM with the mutable-format flag, like the other TYPELESS forms). It was the last of these TYPELESS forms still refused.

d3d12_clear_formats_test (from #521) gets the new formats and four TYPELESS cases.

Tested

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

@NWX10

NWX10 commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

The two red CI jobs are #509 (the mini interpreter quiets signalling NaNs), not this change, which touches no Python:

  • check: tests/test_mem_diff.py, s_load with today's date seed 20261122: expected 0x7f8295f4, translated 0x7fc295f4 (bit 22). The same case fails on main today.
  • semantic-tests (ubuntu-latest): test_alu_shift_b64 v_ashrrev_i64 seeded case, off by exactly 2^22 (the windows job was cancelled by the matrix).

#533 fixes both; I ran test_mem_diff on its head and it passes. linux-gpu-tools fails on main as well (llvmpipe cs_w32_lane_wrap, cs_wqm_w32).

@evilclanker9000

Copy link
Copy Markdown
Contributor

On 3c6e72df09561a9f37f8dbcde5834a7791e8fb6e, I checked a typed R16G16_SINT shader-resource view on RTX 5080, driver 616.92, Windows 11. I adapted the synthetic descriptor test locally: the Xbox-ABI device created and uploaded an 8×8 signed texture and created two SRVs. A Vulkan compute shader used the device’s set 0, looking up each SRV and sampler by its descriptor words, point-sampling through isampler2D, and writing four 32-bit integers per texel.

For linear texel i, the uploaded values were R = -32768 + 37*i and G = 32767 - 43*i. The default SRV returned (R,G,0,1) for all 64 texels. Changing only Shader4ComponentMapping to swap R and G returned (G,R,0,1) for all 64. Each readback failed the other view’s reference at all 64 positions. The first texel went from (-32768,32767,0,1) to (32767,-32768,0,1).

The unmodified clear suite also matched WARP in all 251 cases, with zero skips. Khronos validation was enabled for both runs. I excluded third-party implicit overlay layers for the measured runs after a loader error from an installed overlay on the first descriptor-test launch. The sampling probe uses a Vulkan dispatch with the device-created descriptor set, as the existing test does. The resource and both SRVs are typed throughout.

AI-assisted. Synthetic data only.

@NWX10

NWX10 commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

Rebased with #521 (now one commit, f53f7de, after #525 merged). This PR's own commit is now a67497e, and it merges cleanly with main. Re-tested on the RTX 3060 Ti: ctest 24/24, and 251 clear cases match WARP. The class-changing TYPELESS views that this PR's description lists as not covered are fixed in #621, which is stacked on this one.

NWX10 and others added 2 commits November 22, 2026 04:20
…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>
ItsNotRexed#600 mapped R8G8, R16G16 and R32G32 UINT/SINT, R16G16B16A16 UINT/SINT
and R10G10B10A2_UINT, but render_target_clear_color still treats them
as float formats: a ClearRenderTargetView writes the float's bits
(255.0 becomes 0x437f0000). They now clamp to the component range and
truncate toward zero like WARP, with per-channel limits for
R10G10B10A2_UINT (10, 10, 10 and 2 bits). R8_TYPELESS, the last
two-channel/one-channel TYPELESS form still refused, is mapped as
R8_UNORM with the mutable-format flag.

d3d12_clear_formats_test goes from 178 to 251 cases against WARP, all
matching on an RTX 3060 Ti; without this change 54 differ and R8_TYPELESS
is not exposed. clear_color_test checks the integer conversions on the CPU.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@NWX10 NWX10 changed the title Runtime: two-channel and packed integer formats and their TYPELESS forms (D3D-60) Runtime: clears of the D3D-60 integer formats match WARP, and R8_TYPELESS (follow-up to #600) Nov 22, 2026
@oVolkra

oVolkra commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Tested a67497e on NVIDIA GeForce RTX 3060, driver 617.14, Windows 11: pass

Setup: Windows 11 Pro 24H2 (10.0.26100), RTX 3060 (Ampere), NVIDIA 617.14, MSVC 14.44.35207 + Windows SDK 10.0.26100, Ninja RelWithDebInfo, Khronos Vulkan-Headers 1.4.369, VK_LAYER_KHRONOS_validation 1.4.357. PR head built as-is (not rebased; it conflicts with main c432cdc now).

Build: 0 errors, 0 warnings. ctest: 24/24, also with LEONIDA_VK_VALIDATION=1.
d3d12_clear_formats_test: "251 matched WARP, 0 differ, 0 failed, 0 in formats the layer does not expose, 0 skipped", the same with LEONIDA_VK_VALIDATION=1 (0 validation messages).
clear_color_test: 120 checks passed.
This matches the 251 cases in the description, on a second Ampere card (RTX 3060 next to the 3060 Ti).

AI-assisted: the build and test runs were done with an AI coding assistant (Claude Code) on my machine; the numbers above are its unedited output.

@troythedecoyx

Copy link
Copy Markdown
Contributor

Tested 23827fe 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.

Besides ctest, I ran each test program this PR changes directly (several aren't registered with ctest):

  • clear_color_test: exit 0 (clear_color_test: 120 full/rectangle UINT, SINT, normalised and float replay checks passed)
  • d3d12_clear_formats_test: exit 0 (clears: 251 matched WARP, 0 differ, 0 failed, 0 in formats the layer does not expose, 0 skipped (WARP does not offer the format))
  • typeless_rtv_test: exit 0 (typeless_rtv_test: 22 format, snapshot, whole/rectangle and rejection scenarios passed)

ctest: 100% tests passed, 0 tests failed out of 27.

AI-assisted.

@kotorvr

kotorvr commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Tested 23827fe 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. It carries #521's tie rounding, so main's NVIDIA d3d12_clear_test failure is gone here too.

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

@matheuskshn

Copy link
Copy Markdown
Contributor

Code review at 23827fe. I followed the packed R10G10B10A2_UINT case through conversion: alpha uses 3 rather than the RGB maximum of 1023, and the range check precedes each cast. For an explicit packed-format edge case, a fractional alpha above 3 should saturate to 3 while an adjacent positive RGB fraction truncates within its 10-bit range. AI-assisted code review.

@evilclanker9000

Copy link
Copy Markdown
Contributor

Checked the packed-format edge case requested above on 23827fe. A 5×3 R10G10B10A2_UINT target was cleared once in full, then cleared in a 3×2 rectangle. I read every 32-bit texel through CopyTextureRegion and Map. Native D3D12 on RTX 5080 (616.92), Radeon(TM) Graphics (26.10.1) and WARP all gave these exact words. The PR’s Vulkan runtime matched all 15 texels on both hardware drivers with validation enabled.

Clear Input RGBA floats Expected integer channels Readback
Outside the rectangle (9 texels) 1022.875, 511.75, −2.5, 4.75 1022, 511, 0, 3 0xC007FFFE
Inside the rectangle (6 texels) 1.75, 1024.5, 547.875, 2.875 1, 1023, 547, 2 0xA23FFC01

With exactly the same inputs, parent a7b9ea1 missed all 15 texels on each Vulkan driver. The first sampled word inside and outside was 0xFFFFFFFF on RTX and 0x00000000 on Radeon. On the PR head, changing only rectangle alpha from 2.875 to 1.875 changed exactly six texels to 0x623FFC01, leaving all nine exterior texels intact.

The unchanged d3d12_clear_formats_test also ran on both GPUs. RTX matched WARP in 251/251 cases. Radeon matched 247/251; all four mismatches were D24_UNORM_S8_UINT depth cases.

- render_target_clear_color: main's integer conversion (every exposed UINT/SINT
  format, A2B10G10R10_UINT's 2-bit alpha) with this branch's normalised
  rounding (quantize_unorm, quantize_snorm) for the UNORM, SNORM and sRGB-alpha
  channels.
- Depth clears: main's D24-as-float conversion, then D16_UNORM through
  quantize_unorm.
- Format tables: main and this branch both mapped DXGI R16_UNORM and R8G8_SNORM
  and the R8G8_SNORM copy size; the duplicates are dropped.
- clear_color_test: main's table-driven integer checks plus this branch's
  normalised and integer cases. The float pass-through loop now uses
  R32_SFLOAT and R16G16B16A16_SFLOAT, since R8G8B8A8_UNORM values are rounded.
…in ctest

quantize_unorm/quantize_snorm used std::nearbyint, which follows the thread's
rounding mode (matheuskshn's review): under FE_DOWNWARD 0.5 on 8 bits gave 127
and 0.5 on SNORM8 gave 63. round_half_even uses floor() plus an explicit tie
check, which does not depend on the mode. clear_color_test converts the ties
under FE_DOWNWARD, FE_UPWARD and FE_TOWARDZERO and checks them once the
default mode is back; with nearbyint it fails as above.

d3d12_clear was left out of ctest until this lands (3fc0b21); it is registered
again, with SKIP_RETURN_CODE 77 as before.
…own adapter

The placed plain clear (D3D-90/D3D-221) is compared byte for byte with the host
D3D12 runtime when the host is the layer's own adapter. Its 0.5 * 255 = 127.5 is
a tie: NVIDIA's D3D12 driver writes 0x7f, WARP and AMD 0x80, and the D3D11.3
spec (3.2.3.6) permits either within 0.6 ULP. With this branch the layer rounds
normalised clear values itself, to nearest even, so on an NVIDIA adapter it
writes 0x80 and the exact same-adapter comparison failed (RTX 5070, 621.24).

On the same adapter a differing plain byte is now accepted only when it is
exactly the nearest-even code and within 0.6 ULP; every other difference still
fails, and the SRGB-cast comparison is unchanged.
NWX10 and others added 3 commits November 23, 2026 01:45
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Main's render_target_clear_color already converts the D3D-60 integer formats and
the 10:10:10:2 alpha, so this branch now carries only its tests. The R8_TYPELESS
mapping is on main too; the duplicate case label the merge produced is dropped.

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

NWX10 commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

Updated to ffe9b18: the refreshed #521 branch is merged in, and through it main aa2988c. That clears the conflicts.

Main's render_target_clear_color already converts the D3D-60 integer formats, including the R10G10B10A2_UINT alpha capped at 3. So the conflict in vulkan_replay.h resolves to main's version, and this PR now adds only its tests: the clear_color_test rows, including the two 10:10:10:2 rows, and the extra d3d12_clear_formats_test cases, including the TYPELESS-resource ones. The merge had also added a second DXGI_FORMAT_R8_TYPELESS case to vulkan_format (main already maps it); I removed it.

matheuskshn's packed-alpha case: Vonsek's 15-texel run covers it, and those rows are now in clear_color_test against main's code.

I couldn't build locally (no C++ toolchain on this machine), so CI will be the first build.

AI-assisted (Claude Code).

@sh1shu1

sh1shu1 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested ffe9b18 on NVIDIA RTX 4070 SUPER (driver 616.92), Windows 11 26200, MSVC 14.44, Vulkan SDK 1.4.363, RelWithDebInfo: fail.

  • ctest: 154/155 passed; fails here, passes on main aa2988c: d3d12_typeless_families, same 9 skips as main aa2988c
  • clear_color, d3d12_clear_formats, d3d12_vulkan_device, typeless_rtv: 4/4
  • run_gpu_tests (LEONIDA_VK_VALIDATION=1): 164/210 native, 195/210 with LEONIDA_W64_EMULATE=1, 0 failed; identical to main aa2988c
    AI-assisted (Claude Code, Claude Fable 5.1).

@kapitche

Copy link
Copy Markdown
Contributor

Tested ffe9b18 merged with main 2d3369a on Windows 11 (Python 3.13.1 not used; MSVC 14.51 / Ninja, RelWithDebInfo): concern.

  • Full build OK (508/508). ctest -R "clear|typeless|d3d12_vulkan_device" (11 tests): on the RTX 4080 SUPER 10/11, d3d12_typeless_families fails (82 clears compared, 14 differ, 8 draws 0 differ). Every mismatch is an SNORM clear of 0.5 (for example host 7fff00ff, layer 80ff00ff = WARP). Same test on main 2d3369a (built from a clean worktree): 0 differ, exit 0. So the layer now matches WARP, but the test compares against the host GPU, which differs from WARP on those 14 cases (it prints "WARP differs from the host in 14").
  • Intel UHD 770 (NVIDIA ICD disabled): d3d12_typeless_families passes; d3d12_clear_formats fails, 233 matched / 18 differ: 5 + 5 SRGB (R8G8B8A8, B8G8R8A8) and 4 + 4 stencil bytes (D24_UNORM_S8_UINT, D32_FLOAT_S8X24_UINT). On the NVIDIA GPU it is 251 matched / 0 differ. None of those formats are the integer ones this PR changes, and I did not have a main baseline for that test (it comes from Runtime: clears match WARP on every format class: tie rounding, and the SNORM/SINT/R8/R16 formats (D3D-45) #521), so I can't say whether the Intel diffs predate this PR.
  • Not run: negative control for the integer clears.

opit80 added a commit to opit80/Leonida that referenced this pull request Nov 23, 2026
@ItsNotRexed
ItsNotRexed merged commit da44e54 into ItsNotRexed:main Nov 23, 2026
3 of 10 checks passed
Exopus-0x65f7ad0 added a commit to Exopus-0x65f7ad0/Leonida that referenced this pull request Nov 23, 2026
…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>
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.

10 participants