Skip to content

Test packed 16-bit typed UAV clear boundaries - #5616

Closed
Hiiva wants to merge 4 commits into
ProjectLeonida:mainfrom
Hiiva:fix/packed-uav-clears
Closed

Hiiva wants to merge 4 commits into
ProjectLeonida:mainfrom
Hiiva:fix/packed-uav-clears

Conversation

@Hiiva

@Hiiva Hiiva commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Regression coverage

#5425 now supplies the three packed 16-bit UAV layouts and the required float-to-channel rounding. This PR keeps focused regression coverage for B5G6R5_UNORM, B5G5R5A1_UNORM, and B4G4R4A4_UNORM on devices that advertise typed UAV stores.

The added literal-byte checks cover channel order, high-bit Uint truncation, even and odd one-bit alpha, Float clamp and NaN handling, and alpha at and just above 0.5. The existing GPU fixture also clears each supported format across two mips and two array layers, using whole views and clipped rectangles, and checks every texel.

Dependency and review range

Depends on: #5425

Current parent: 45e81b282132788c5a9de4524df89678479e5926, based on main 561b65a832218fbb9e6d2effd392a8eef093a3f8.

Current child: 7cd3ccd6ef62d822da31f79fb067e5f988055202.

Review 45e81b28..7cd3ccd6: 39 test lines and four documentation lines. There is no production delta in that range. The earlier three layout rows were removed from this child because the updated parent already contains identical rows. The dependency still matters for the one-bit alpha tie: Float 0.5 rounds to the even result 0.

Fresh validation

Windows 11 x64 build 26200, MSVC 19.44, Vulkan SDK 1.4.363.0, AMD Radeon(TM) Graphics driver 32.0.21043.5001, native WARP reference. Rebuilt against the exact parent above. All fixtures are synthetic.

  • clear_color_test: 535 checks pass.
  • typeless_rtv_test: 100 scenarios pass.
  • d3d12_uav_clear_test: all supported packed texture cases and existing controls pass on Radeon with Vulkan validation enabled.
  • The unchanged local native probe runs 42 deterministic programs. Native WARP and replay both match all 13,440 literal readback bytes, including untouched upload bytes around the clear. It covers Uint masking, Float mixed values, NaN, clamp, infinities, and alpha at/above 0.5.
  • The same probe replays the 83 originally failing packed-format seeds and compares all 241,598 bytes directly with WARP, without the fuzzer's tolerance comparator. All match.
  • The parent's unchanged d3d12_clear_fuzz_test --seeds 1000 passes: zero differences and zero refusals. This broader run uses the fuzzer's documented comparison rules.
  • The GPU runs above use explicit Khronos validation logging and synchronization validation. No VUID or synchronization-hazard messages were emitted. The stock UAV fixture's intentional invalid-input diagnostics remain expected.
  • Independent source review confirmed the parent layouts, retained edge-case coverage, and literal oracle compatibility. git diff --check passes.

The native probe is local validation evidence; the committed regression is d3d12_uav_clear_test. No new GPU capability or game behavior is claimed.

Original reproduction

Before the parent adopted these layouts, the same 1,000 programs had 83 packed-format submission failures: 37 B5G6R5, 22 B5G5R5A1, and 24 B4G4R4A4. Against old parent f13305d5, the 42 literal programs plus those 83 seeds produced 125 unsupported submissions; the original child fixed all of them. That is historical evidence, separate from the fresh current-parent results above.

Claim: #5361 (comment), carried through the coordinator rollovers.

No game files accessed or included. AI-assisted: yes.

@shdann

shdann commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested 27eda42 on Windows 11. The AMD Radeon iGPU passes the GPU clear checks for all three new packed formats. The RTX 4090 reports no typed UAV support for these formats and skips all three. Both device test runs exit 0 with Vulkan validation enabled.

I built d3d12_uav_clear_test with cmake --build E:/Leonida-review-work-build --config RelWithDebInfo --target d3d12_uav_clear_test --parallel 8. I ran RelWithDebInfo/d3d12_uav_clear_test.exe with LEONIDA_VK_VALIDATION=1 and selected each adapter with LEONIDA_VK_DEVICE.

I also checked every possible 16-bit Uint result on the CPU. For each word w from 0 through 65535, I supplied channel values (w>>11, w>>5, w, 0) for 565, (w>>10, w>>5, w, w>>15) for 1555, and (w>>8, w>>4, w, w>>12) for 4444. I checked that encode returned two bytes equal to w in little-endian order. All 196,608 cases match on the head. The same probe against dependency head f13305d reports unsupported for every case.

AI-assisted.

@Hiiva

Hiiva commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Round 44 status: main is now 561b65a. The added three-file packed-layout patch applies cleanly to that main (git apply --check). The stacked #5425 parent needs its own rebase across the newly merged clear-conversion changes in vulkan_replay.h and four existing test files.

I preserved this reviewed head and will restack on the updated #5425 head, retaining the one-bit alpha tie regression and rerunning the focused Radeon/native controls. The published patch and its current validation evidence are unchanged.

AI-assisted: yes.

@whattheflop

Copy link
Copy Markdown
Contributor

AI-assisted Windows CPU follow-up to the round-44 apply check. The 27eda42e top header hunk applies to 561b65a8, but its own conversion_checks() then fails two assertions. I compiled the actual uav_clear.h from each tree with MSVC x64.

A1R5G5B5 input Stacked head Round-44 main plus top hunk
Float alpha 0.5 00 00 00 80
Float RGBA (1, 0.25, 0.75, 0.5) 17 7d 17 fd
Float alpha just above 0.5 00 80 00 80

Packed UINT masking and RGB565/ARGB4444 controls matched. The R8_UNORM half-step control also changed from 00 on the exact #5425 parent to 01 on round-44 main. The top patch alone therefore does not preserve the stack’s nearest-even conversion contract. This is CPU encoder evidence; I did not rerun WARP or any GPU tests.

Exopus-0x65f7ad0 and others added 4 commits November 23, 2026 13:15
…river rounds

Clears handed the application's float to vkCmdClear*/loadOp and let the driver convert it. NVIDIA's
(621.14) rounds differently from D3D12, WARP and AMD (the Xbox's own hardware):
- UNORM/SNORM: 0.5 * 255 = 127.5 gives 0x7f, not the even 0x80; 4-, 5- and 6-bit channels go
  through 8 bits first (B5G6R5 green 0.3739 is 23, not 24);
- sRGB: 0.5 / 255 encodes to 7, not 6;
- D16: depth 0.5 clears to 0x7fff, not 0x8000;
- a denormal R32_FLOAT colour or D32 depth is kept, where D3D12 flushes it to a zero of its sign.

The layer now computes D3D12's code itself (a float multiply, round to nearest, ties to even, as
depth24_quantize already does for D24) and hands the driver the nearest float to code / max, which any
rounding turns back into that code. ClearUnorderedAccessViewFloat's model (uav_clear::encode) rounded
ties away from zero in double; it now matches WARP too.

Three tests encoded the driver's rounding: clear_color and typeless_rtv expected UNORM floats to pass
through; d3d12_typeless_families and d3d12_vulkan_device compared exactly with the host D3D12 on the
same adapter. On NVIDIA they now accept the WARP value where the host and WARP disagree (0.6 ULP,
D3D11.3 3.2.3.6). clear_color checks the measured cases.

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

Each program fills one texture (19 families: typeless colour families viewed through their typed
formats, packed 16-bit, R11G11B10, D16/D24S8/D32/D32S8 and their typeless forms; mips and arrays)
with known bytes, then runs random ClearRenderTargetView, ClearDepthStencilView and
ClearUnorderedAccessViewUint/Float through views of a mip and an array range, with 0-3 rects, and
compares every byte of every plane of every subresource with WARP. --hardware compares with the GPU's
D3D12, --reduce SEED shrinks a differing program, --seeds/--start choose them.

The default leaves out two known differences (--all puts them back): the UINT patterns uav_clear.h
documents as inexact, and on NVIDIA stencil clears with rects past mip 0 (the driver writes a stencil
attachment view of mip > 0 into mip 0). A NaN from a float clear compares equal whatever its payload,
and an sRGB colour may be one code off (D3D's tolerance).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…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 (ProjectLeonida#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 (ProjectLeonida#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>
@Hiiva
Hiiva force-pushed the fix/packed-uav-clears branch from 27eda42 to 7cd3ccd Compare November 23, 2026 13:01
@Hiiva Hiiva changed the title Support packed 16-bit typed UAV clears Test packed 16-bit typed UAV clear boundaries Nov 23, 2026
@Hiiva

Hiiva commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Restacked on #5425 45e81b282132788c5a9de4524df89678479e5926 at 7cd3ccd6ef62d822da31f79fb067e5f988055202.

The updated parent now contains the three packed layouts, so this child retains only 39 lines of boundary/texture regression coverage and four documentation lines. Its production source matches the parent exactly. The one-bit alpha 0.5 and nextafter controls remain in the test, preserving the behavioral dependency identified above.

Fresh Radeon validation: stock UAV clear passes; the independent native probe passes all 42 literal programs and 83 prior failing seeds with exact WARP bytes. The parent's unchanged 1,000-seed clear fuzzer reports zero differences/refusals. CPU clear_color 535 and typeless_rtv 100 checks pass. No VUID or synchronization-hazard messages. The body now separates these current-parent results from the historical negative controls. AI-assisted: yes.

@Jadiac5

Jadiac5 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested 7cd3ccd on Windows 11, AMD Radeon RX 9070 XT (RDNA4), driver 32.0.32029.2010: pass

AI-assisted (Claude Code).

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.

6 participants