Skip to content

Runtime: SNORM/SINT render targets and clear conversion (D3D-45) - #525

Merged
ItsNotRexed merged 1 commit into
ProjectLeonida:mainfrom
luisbaker:d3d-45-clear-compare
Nov 22, 2026
Merged

ItsNotRexed merged 1 commit into
ProjectLeonida:mainfrom
luisbaker:d3d-45-clear-compare

Conversation

@luisbaker

Copy link
Copy Markdown
Contributor

D3D-45: compare clears with the host runtime across format classes and depth/stencil.

Extends the clear differential test (renamed d3d12_uint_clear_test -> d3d12_clear_test) and adds the missing format support it needs:

  • �ulkan_format and �lock_format: map R8G8B8A8_SNORM, R8G8B8A8_SINT, R32_SINT, R32G32B32A32_SINT.

ender_target_clear_color: convert SINT clears numerically (NaN -> 0, clamp to the signed range, truncate toward zero) instead of copying float bits.

The test now compares full/rectangle ClearRenderTargetView readbacks against Windows WARP across UNORM, SNORM, FLOAT, UINT and SINT render targets, and ClearDepthStencilView depth/stencil (D32_FLOAT, D16_UNORM, D32_FLOAT_S8X24_UINT).

SRGB clears are omitted from the byte-exact comparison: the linear->sRGB encoding rounds differently at the .5 boundary on WARP vs Vulkan (a 1-ulp driver difference the shim cannot control).

No game files. AI-assisted.

Tested: d3d12_clear_test (59 readbacks) on Intel(R) Graphics, all matched WARP; clear_color_test and d3d12_vulkan_device_test still pass.

Claim: #374 (comment)

Add DXGI->Vulkan mappings and footprint sizes for SNORM and SINT render-target formats, and extend render_target_clear_color to convert SINT clears numerically (NaN to zero, clamp to the signed range, truncate toward zero) instead of copying float bits. Rename d3d12_uint_clear_test to d3d12_clear_test and widen it to compare UNORM/SNORM/FLOAT/UINT/SINT render-target and depth/stencil clears against Windows WARP, full and rectangle. SRGB clears are left out of the byte-exact comparison: the linear->sRGB encoding rounds differently at the .5 boundary on WARP vs Vulkan (a 1-ulp driver difference).
@luisbaker

luisbaker commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor Author

CI note: the red checks are pre-existing on main (main@91b36cf is also red on the same jobs), not caused by this PR. They are date-seeded translator fuzzer tests (seed 20261122) hitting pre-existing translator bugs, e.g.:

  • check: test_every_family_runs_clean (family='s_load') - ps_mem_00008 ... expected 0x7f8295f4, translated 0x7fc295f4.
  • semantic-tests (windows): test_seeded (test_alu_shift_b64), op v_ashrrev_i64.

This PR only changes the D3D12 layer (SNORM/SINT format mappings + clear conversion) and d3d12_clear_test; the windows (MSVC) build passes, so nothing here touches the translator.

AI-assisted.

@ItsNotRexed
ItsNotRexed merged commit 1ce7964 into ProjectLeonida:main Nov 22, 2026
5 of 9 checks passed
@kacper-serewis

Copy link
Copy Markdown
Contributor

Tested e816f20 on RTX 5070 (Blackwell, subgroup 32..32), NVIDIA 616.56, Windows 11 Pro 26200: d3d12_clear_test fails, on the PR head and merged onto current main (91b36cf, clean merge).

format 28 case 0 byte 2: Vulkan 7f, WARP 80 (exit 1)

That's DXGI_FORMAT_R8G8B8A8_UNORM cleared to {0, 0.25, 0.5, 1}: the 0.5 channel comes out 0x7f on the RTX 5070 and 0x80 on WARP. That's the .5 tie that #521 rounds explicitly; #521's d3d12_clear_formats_test passes 178/178 here.

  • ctest: 19/19 on the head, 23/23 merged, so ctest alone doesn't show it

Tools: MSVC 19.50, Vulkan SDK 1.4.363.0.

NWX10 added a commit to NWX10/Leonida that referenced this pull request Nov 22, 2026
…D-45)

Rebased onto main after ProjectLeonida#525, which added SNORM/SINT render targets for four formats.
This keeps ProjectLeonida#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>
@woreksami

Copy link
Copy Markdown

Tested e816f20 on an RTX 3060 (driver 610.88), Windows 11: d3d12_clear_test fails:

format 28 case 0 byte 2: Vulkan 7f, WARP 80

Format 28 is R8G8B8A8_UNORM; case 0 is {0, 0.25, 0.5, 1}, so byte 2 is 0.5 × 255 = 127.5, an exact tie. WARP rounds it to 128 and NVIDIA's Vulkan clear gives 127. That looks like the tie-rounding case #521 (also D3D-45) handles, so the two PRs may need to land together or be merged into one. Everything else passes: ctest 19/19, d3d12_vulkan_device_test, d3d12_com_test, d3d12_descriptor_test.

Setup: Windows 11 Pro, NVIDIA GeForce RTX 3060 (Ampere), driver 610.88, Vulkan 1.4.341, MSVC (VS 18 Build Tools), Ninja, RelWithDebInfo. No validation layer installed, so not run with LEONIDA_VK_VALIDATION=1. AI-assisted (Claude Code).

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>
Vonsek pushed a commit to Vonsek/Leonida that referenced this pull request Nov 23, 2026
…D-45)

Rebased onto main after ProjectLeonida#525, which added SNORM/SINT render targets for four formats.
This keeps ProjectLeonida#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>
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.

4 participants