Skip to content

d3d12_pso_fuzz_test: random blend, logic-op, depth-stencil, rasterizer, viewport and MRT state against the same GPU's D3D12 - #5637

Closed
Exopus-0x65f7ad0 wants to merge 6 commits into
ProjectLeonida:mainfrom
Exopus-0x65f7ad0:test/pso-fuzz
Closed

Exopus-0x65f7ad0 wants to merge 6 commits into
ProjectLeonida:mainfrom
Exopus-0x65f7ad0:test/pso-fuzz

Conversation

@Exopus-0x65f7ad0

@Exopus-0x65f7ad0 Exopus-0x65f7ad0 commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue: #5256 (comment)

What and why

This is a seeded differential fuzzer for graphics pipeline state: the draw counterpart of the copy (#5272), clear (#5425) and fence (#5180) fuzzers. Every draw the game makes goes through this state, and nothing compared it systematically with D3D12.

Each program does the following:

  • Targets: it clears a 32x32 colour target and an optional depth-stencil target. Colour formats:

    • R8G8B8A8/B8G8R8A8 UNORM, sRGB, R10G10B10A2, R16G16B16A16_FLOAT, R32G32B32A32_FLOAT, R11G11B10_FLOAT;
    • UINT: R8G8B8A8, R16G16B16A16, R32G32B32A32, R32.

    Depth formats: D16, D24S8, D32, D32S8. A third of the float/UNORM programs add a second render target of a random format. Formats are kept where both devices support them (CheckFeatureSupport).

  • Draws: 1-5 batches of triangles, each through its own PSO with random state:

    • blend: all colour/alpha factors except dual-source, all five ops, per-channel write masks, OMSetBlendFactor; with two targets, IndependentBlendEnable half the time, giving RenderTarget[1] its own blend state and mask;
    • logic ops: on UINT targets, half the draws enable one of the sixteen D3D12_LOGIC_OPs, where both devices report OutputMergerLogicOp;
    • depth-stencil: depth on/off, write mask, all eight functions; stencil with random read/write masks, all eight ops for fail/depth-fail/pass and all eight functions, on front and back faces separately, and OMSetStencilRef;
    • rasterizer: cull none/front/back, either winding, DepthClipEnable on/off, z from -0.125 to 1.125 so clipping and clamping both happen, and a constant DepthBias with --all (see below);
    • viewport and scissor: half the draws get a viewport other than the whole target (whole-pixel offsets from -16 to 24, sizes 8 to 48, a depth range in 64ths), and a third get a scissor rect.
  • Comparison: every byte of every colour target and of every depth-stencil plane is compared.

So that only the state can make a difference:

  • each triangle has one depth and one colour (flat/nointerpolation from the first vertex, which D3D12 and Vulkan both use; UINT targets get the colour's bits);
  • the vertices sit on pixel corners or half-pixels.

Blending may still round within D3D12's tolerance, so the comparison allows:

  • colour: one code (UNORM) or one ulp (float);
  • depth: one code (D16/D24) or two ulps (D32);
  • stencil and UINT: no tolerance, they compare exactly.

The reference is the host's D3D12 on the layer's own GPU, matched by LUID (the D3D-188 rule other tests use). --warp compares with WARP instead. On NVIDIA, WARP and the GPU's own D3D12 disagree within D3D12's rules (an edge through a pixel centre, blending roundings), and the GPU's Vulkan driver shares its D3D12 driver's choices. Against WARP, 8 of 20 seeds differ, and each one matches NVIDIA's D3D12. So the same-GPU host is what isolates the translation.

The layer is the device the runtime makes (create_vulkan_device_standalone, which enables depthClamp, independentBlend and logicOp). Shaders: GLSL stand-ins written to the translator's contract (test/glsl/vs_pso.vert, ps_pso.frag, ps_pso_mrt.frag, ps_pso_uint.frag), found by FSSM hash as in d3d12_typeless_families; the reference runs the same programs in HLSL via d3dcompiler_47. --reduce SEED shrinks a differing program to its fewest draws and triangles. --verbose prints every program, both target formats, and whether logic ops run.

Modes for the open methods

  • --stream creates every PSO through ID3D12Device2::CreatePipelineState, on both sides. The pipeline-state stream follows the d3dx12.h layout: subobjects in a random order, one equal to its default left out half the time, and DEPTH_STENCIL or DEPTH_STENCIL1 alternately. The layout comes from its own generator, so the programs are the same as without it. On main every PSO is refused, since there's no CreatePipelineState yet. On Runtime: mesh-shader PSOs from pipeline state streams and DispatchMesh (D3D-29) #1712 (D3D-29), 1,000 seeds give 0 differences and match the desc path seed for seed.
  • --render-pass runs the draws inside BeginRenderPass/EndRenderPass. Even seeds clear through the pass's CLEAR access; odd seeds clear first and begin PRESERVE; every pass ends PRESERVE. On main it's unimplemented and 18 of 20 seeds differ. On Runtime: record and replay D3D12 render passes as Vulkan dynamic rendering (D3D-27) #2064 (D3D-27), 1,000 seeds under validation give 0 differences.

UNORM targets are cleared to 0 or 1 per channel. A clear value on a code tie is #5425's subject, and NVIDIA's D3D12 and D3D12's ties-to-even disagree there.

What it found

DepthBias is applied about twice on NVIDIA. With --all over 600 seeds, main differs in 25, all in the depth plane. Examples: D24 0x34001e against 0x34000f, and D16 0xec21 against 0xec10. A reduced case: one triangle on D24S8 with DepthBias = -6 gives 12 codes of bias where D3D12 applies 6. That's the shadow-map case and the open #2718 (D3D-325, exact bias through VK_EXT_depth_bias_control). On #2718's head with this fuzzer, 0 of 600 differ, bit-identical (measurement). Until it lands, the default run leaves DepthBias at 0 so ctest stays green on main, and --all puts it back.

Everything else matches the same-GPU host: every blend factor and op, write masks, independent blend on two targets, all sixteen logic ops, every stencil op and function on both faces, culling and winding, depth clip and clamp, and viewport offsets, sizes and depth ranges with scissors.

Tested

RTX 5060 Ti / 621.14, Windows 11 26300, MSVC 14.51, Vulkan SDK 1.4.363.0.

run result
default, 40 seeds 0 differ
1,000 seeds, LEONIDA_VK_VALIDATION=1 0 differ, 0 validation messages
--all, 600 seeds 25 differ, all DepthBias (0 on #2718)
LEONIDA_VK_VALIDATION=1 ctest -j4 with -DLEONIDA_LLVM_MC 168/168, d3d12_pso_fuzz included

One unrelated note: in one full run, d3d12_fence_timing segfaulted once under -j4. It passed 10 of 10 alone and in the next full run. It's pre-existing and doesn't involve this test; I'll look into it separately.

Not covered yet: MSAA and alpha-to-coverage, slope-scaled bias (constant-depth triangles have no slope), and more than two render targets.

No game files. AI-assisted (Claude Code, Claude Opus 5.5).

…GPU's D3D12, every byte compared

Each program clears a colour target (UNORM, sRGB, 10:10:10:2, half, float, R11G11B10) and an optional
D16/D24S8/D32/D32S8 target, then draws triangles through PSOs with random blend state (all non-dual-
source factors, all ops, write masks, OMSetBlendFactor), depth-stencil state (all functions and stencil
ops, masks, both faces, OMSetStencilRef) and rasterizer state (cull, winding, constant DepthBias, depth
clip), and compares every byte of the colour target and every depth-stencil plane. Triangles have one
depth and a flat colour on pixel corners, so only the state can differ; blending may round by one code
or ulp. The reference is the host's D3D12 on the layer's GPU by LUID (--warp for WARP, which differs
from GPUs within D3D12's rules); --reduce SEED shrinks a differing program.

Over 400 seeds on an RTX 5060 Ti it finds DepthBias applied about twice (26 seeds, all depth), which
ProjectLeonida#2718 (VK_EXT_depth_bias_control) fixes: 0 of 400 with it. The default 40 seeds pass on main.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… scissors per draw

Half the draws get a viewport other than the whole target: whole-pixel offsets from -16 to 24, sizes
8 to 48, and a depth range in 64ths. A third get a scissor rect. Vertices stay on pixel corners or
half-pixels and depths stay exact. This covers the layer's viewport y-flip and depth range.

Over 600 seeds against the RTX 5060 Ti's D3D12, only the DepthBias seeds (ItsNotRexed#2718) differ; with ItsNotRexed#2718,
0 of 600.

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

Copy link
Copy Markdown
Contributor Author

Pushed 0299224e: each draw now gets a random viewport half the time (whole-pixel offsets from -16 to 24, sizes 8 to 48, a depth range in 64ths) and a random scissor a third of the time. That covers the layer's y-flip, viewport offsets and depth range. RTX 5060 Ti against its own D3D12, 600 seeds: on main, 28 differ, every one in the depth plane with the doubled-bias pattern. On #2718's head with this fuzzer, 0 of 600. So viewports and scissors translate exactly here, and DepthBias is the only difference left. Default run: 40 seeds, 0 differ. AI-assisted (Claude Code).

@SirKingg

Copy link
Copy Markdown
Contributor

Independent Windows check of head 0299224e1823ef6de5f41489b6cc32cb4cc3d38b, RTX 4070 Ti / NVIDIA 610.88, native same-GPU D3D12 reference matched by LUID (no WARP or game files). AI-assisted.

  • d3d12_pso_fuzz_test.exe --seeds 200 --verbose: 200/200 ran, no reference skips or layer refusals; five seeds (45, 68, 154, 160, 195) differed, first in D16/D24 depth. Each reduced to one draw with nonzero constant DepthBias; deltas match the known doubled-bias pattern in d3d12: exact depth bias through VK_EXT_depth_bias_control (D3D-325) #2718. A separate local-only build that preserves RNG consumption but forces constant DepthBias to zero ran the same 200 seeds with zero differences or skips. This is not a test of d3d12: exact depth bias through VK_EXT_depth_bias_control (D3D-325) #2718 itself and cannot exclude other discrepancies masked by bias.
  • All seven listed colour formats and all five depth choices appeared in these seeds. Synthetic mutations exercised the actual compare implementation independently: one-code/ULP tolerance and beyond-tolerance colour/depth changes, exact stencil changes for both stencil formats, D24 padding and R10G10B10A2 alpha. These samples are not exhaustive; randomized seeds do not prove feature coverage, and MSAA, multiple render targets, logic ops and slope-scaled bias are not covered.

One actionable oracle issue: in runtime/test/d3d12_pso_fuzz_test.cpp:803-806, any reference error (including timeout or readback failure) is silently skipped by default, and :836 can return success when no seeds ran. I injected a synthetic reference error into a local-only copy: --seeds 1 --verbose printed 0 seeds run and exited 0. Please make reference execution errors fail explicitly (or otherwise ensure an all-skipped run cannot pass). Also, the header/PR describes one ULP for float colour, while compare allows two for R32 float (:586); R10 2-bit alpha has zero slack (:577). Please align the stated and actual tolerances.

@milas6669

Copy link
Copy Markdown

Tested 0299224e on NVIDIA GeForce RTX 3070 (Ampere, GA104, driver 32.0.16.2124), Windows 11, MSVC 19.44 + Ninja, RelWithDebInfo, Vulkan SDK 1.4.363, llvm-mc 21.1.8, with LEONIDA_VK_VALIDATION=1, native same-GPU D3D12 reference: the finding reproduces on Ampere, and the default run is clean.

  • Default 40 seeds: 0 differ, 0 refused by the layer, exit 0 (so ctest passes on main here too, as the description says).
  • --seeds 400: 17 differ, exit 1: 45, 68, 154, 160, 195, 206, 213, 230, 239, 247, 277, 285, 291, 301, 337, 376, 384. All 17 first differ in the depth plane (none in colour or stencil), 0 refused by the layer, 0 validation messages (counted over the whole output).
  • --reduce 45: one draw, D24_UNORM_S8_UINT, bias -6, triangle z 0.890625: first difference depth at (13,0): layer c7cff3, reference c7cff9, i.e. 12 codes of bias where D3D12 applies 6, the doubled-bias pattern the description gives.

How this fits the other runs: the five seeds in 1..200 (45, 68, 154, 160, 195) are the same five @SirKingg lists on the RTX 4070 Ti, so Ada and Ampere agree over that range; seeds 201..400 add 12 more here. The description's RTX 5060 Ti (Blackwell) run has 26 of 400 and seeds 64, 77, 89 and 100 in its first 100, which are not in this list, so the differing set is not the same across generations. I did not investigate why.

Not tested: #2718 (it conflicts with main and with this head in d3d12_vulkan_device.cpp, and I did not hand-resolve it, so I cannot say whether it takes this card to 0 of 400), --warp, --verbose, and the oracle points @SirKingg raised (silent skip of reference errors, the stated vs actual float tolerance).

AI-assisted. Synthetic only; no game data.

A third of the programs draw to two targets (a second random format) through a pixel shader that
writes the colour to SV_Target0 and its bgra swizzle to SV_Target1. Half their draws set
IndependentBlendEnable with RenderTarget[1]'s own blend state and write mask. Both targets are
compared.

Over 600 seeds (197 with two targets) against the RTX 5060 Ti's D3D12, only the DepthBias seeds
differ; with ItsNotRexed#2718, 0 of 600.

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

Copy link
Copy Markdown
Contributor Author

Pushed f938e488: a third of the programs now draw to two render targets. The second target has a random format, and the pixel shader writes the colour and its bgra swizzle so the targets differ. Half of those draws set IndependentBlendEnable with RenderTarget[1]'s own blend state and write mask. RTX 5060 Ti, 600 seeds, 197 with two targets: main still differs only in the 28 DepthBias seeds, and #2718's head gives 0 of 600. MRT and independent blend translate exactly here. --verbose now names the second target too. AI-assisted (Claude Code).

…as behind --all

Four UINT target formats (R8G8B8A8, R16G16B16A16, R32G32B32A32, R32) drawn by a pixel shader that
writes the colour's bits, so both sides see exact integers; where both devices report
OutputMergerLogicOp, half their draws enable one of the sixteen logic ops. UINT texels compare
exactly. --verbose names both targets and says whether logic ops run.

A nonzero DepthBias is now generated only with --all: on NVIDIA the layer applies about twice
D3D12's bias (D3D-325, fixed by ItsNotRexed#2718), and the default run should stay green on main until that
lands. With --all and ItsNotRexed#2718, 0 of 600 differ.

RTX 5060 Ti against its own D3D12: default 40 seeds and 1,000 seeds under validation, 0 differ, 0
validation messages; --all 600 seeds, 25 differ, all DepthBias.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Exopus-0x65f7ad0 Exopus-0x65f7ad0 changed the title d3d12_pso_fuzz_test: random blend/depth-stencil/rasterizer state against the same GPU's D3D12 (finds the DepthBias doubling #2718 fixes) d3d12_pso_fuzz_test: random blend, logic-op, depth-stencil, rasterizer, viewport and MRT state against the same GPU's D3D12 Nov 23, 2026
@Exopus-0x65f7ad0

Exopus-0x65f7ad0 commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor Author

Pushed 427528a4. UINT targets (R8G8B8A8, R16G16B16A16, R32G32B32A32, R32) now get all sixteen logic ops: half their draws, where both devices report OutputMergerLogicOp, with exact comparison. Nonzero DepthBias is now behind --all until #2718 lands, so the default run stays green on main. RTX 5060 Ti against its own D3D12: 1,000 seeds under validation give 0 differences and 0 validation messages. --all gives 25 of 600, all DepthBias, and 0 on #2718. Full ctest 168/168. The description is updated with the whole coverage. AI-assisted (Claude Code).

@slint6614-dev

Copy link
Copy Markdown
Contributor

Tested 427528a4 on AMD (the runs above are all NVIDIA): pass, and the DepthBias finding reproduces on AMD with the same doubled pattern.

Windows 11 build 26300, MSVC 14.44 + Ninja, RelWithDebInfo, Vulkan SDK 1.4.363.1; reference = the host's D3D12 on the same GPU (LEONIDA_VK_DEVICE and LEONIDA_HOST_ADAPTER set to the GPU, the summary line names it). Two AMD GPUs, same results on both: Radeon RX 9070 (RDNA4, 32.0.32015.7029) and the Radeon Graphics iGPU of a Ryzen 5 9600X (RDNA2 gfx1036, 32.0.21045.16010).

run RX 9070 iGPU
default, 40 seeds 0 differ, 0 refused, exit 0 0 differ, 0 refused, exit 0
1,000 seeds, LEONIDA_VK_VALIDATION=1 0 differ, no validation message 0 differ, no validation message
--all, 600 seeds 13 differ, all in the depth plane the same 13 seeds

Reduced on the RX 9070, each to one triangle on D16 with a constant DepthBias: seed 384 (bias 2) gives layer 0x5804 against 0x5802, and seed 336 (bias -20) gives 0x5598 against 0x55ac. In both cases the layer adds the bias a second time, as on NVIDIA, so #2718 applies to AMD too. I didn't run #2718's head here.

Two notes from the log: this AMD driver has no D24_UNORM_S8_UINT in Vulkan, so the layer uses D32_SFLOAT_S8_UINT (format 45) and the D24 programs still compare clean. The layer also warns that vs/ps_uint are 32-wide shaders that can't require that size on this device (sizes 32..64, default 64), which made no difference here. No game files. AI-assisted (Claude).

…State; exact clears

--stream creates each PSO from a pipeline-state stream (d3dx12.h layout) on both the layer and the
reference: subobjects in a random order, one equal to its default left out half the time, and
DEPTH_STENCIL or DEPTH_STENCIL1 alternately. The stream layout comes from its own generator, so the
programs are the same as without --stream. On main every PSO is refused (no CreatePipelineState
yet). On ItsNotRexed#1712 (D3D-29), 1,000 seeds give 0 differences, and the results match the desc path seed
for seed.

UNORM targets are now cleared to 0 or 1 per channel. A clear value between two codes rounds by the
clear's rules, which d3d12_clear_fuzz_test checks and where NVIDIA's D3D12 and D3D12's ties-to-even
part (a 2-bit alpha of 0.5); this test checks the draws.

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

Copy link
Copy Markdown
Contributor Author

Pushed 8cdcadd1:

Default run 40/40, d3d12_draw and d3d12_typeless_families still pass; --all under validation: 13 of 300 differ, all DepthBias, 0 validation messages. AI-assisted (Claude Code).

…nderPass

Even seeds clear through the pass (BEGINNING_ACCESS_TYPE_CLEAR with the clear values; stencil
NO_ACCESS on depth-only formats), odd seeds clear first and begin PRESERVE; every pass ends PRESERVE.
On main the layer logs BeginRenderPass as unimplemented and 18 of 20 seeds differ; on ProjectLeonida#2064
(D3D-27), 1,000 seeds under validation give 0 differences and 0 validation messages.

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

Copy link
Copy Markdown
Contributor Author

Pushed 5bd5840e: --render-pass runs each program's draws inside BeginRenderPass/EndRenderPass. Even seeds clear through the pass's CLEAR access, odd seeds clear first and begin PRESERVE, and every pass ends PRESERVE. On main, 18 of 20 seeds differ (BeginRenderPass unimplemented). On #2064 (D3D-27), 1,000 seeds under validation give 0 differences, 0 validation messages (report). The three methods on the critical path are now measured: CreatePipelineState (#1712), the render passes (#2064) and DepthBias (#2718). AI-assisted (Claude Code).

@searyecheesepeaceful

Copy link
Copy Markdown

Tested 5bd5840 on NVIDIA GeForce RTX 4080, driver 617.42: d3d12_pso_fuzz_test with its default run exits 0 and prints "pso fuzz (layer against NVIDIA GeForce RTX 4080): 40 seeds run, 0 differ, 0 refused by the layer; 0 texels within the rounding tolerance". Only the default run was executed; --all, --stream, --render-pass, the 1,000-seed run and --warp were not.

AI-assisted.

@xelerb-debug

Copy link
Copy Markdown

Tested 5bd5840e on NVIDIA GeForce RTX 4060 (Ada, AD107), driver 621.01 (32.0.16.2101, Vulkan 1.4.357), Windows 11 Pro 26200, MSVC 19.51.36260, Vulkan SDK 1.4.363.1, RelWithDebInfo with -DLEONIDA_REQUIRE_VULKAN=ON, reference = the host's D3D12 on the same GPU: pass, all modes as described, on the PR head and merged with current main.

The branch is 1,806 commits behind main (561b65a8); git merge pr-5637 onto it is clean (only runtime/CMakeLists.txt auto-merged), giving 6977ecbf. #2718, #1712 and #2064 are all still unmerged, so --all, --stream and --render-pass are expected to differ on both.

Run PR head 5bd5840e Merged with main 561b65a8
ctest -R pso_fuzz 1/1 passed 1/1 passed
default (40 seeds) 0 differ, 0 refused; 0 texels within tolerance 0 differ, 0 refused; 0 within tolerance
--seeds 1000, LEONIDA_VK_VALIDATION=1 0 differ, 0 refused, 0 validation messages; 0 within tolerance 0 differ, 0 refused, 0 validation messages; 1,758 within tolerance
--all --seeds 600 25 differ (all depth), 0 refused; 0 within tolerance 25 differ, same seeds and values; 779 within tolerance
--stream --seeds 20 20 refused (CreatePipelineState) 20 refused
--render-pass --seeds 20 18 differ; 21 within tolerance 18 differ; 21 within tolerance
  • DepthBias reproduces on Ada with the same pattern as the other NVIDIA runs: 25 of 600, every one first in the depth plane, e.g. seed 10 (D24) layer af7fe5 vs reference af7ff2, seed 136 (D16) 5be2 vs 5bf1. Seeds 154, 195 and 213 are among them, as on the RTX 4070 Ti / 3070 runs.
  • --stream and --render-pass give exactly the counts in the description for main (all refused; 18 of 20).
  • One thing that changed on current main: the differ counts are identical, but the "within the rounding tolerance" count goes from 0 to 1,758 (1,000 seeds) and from 0 to 779 (--all, 600 seeds) after merging. So something between 3faac557 and 561b65a8 now rounds blending or depth by one code / ulp where it used to be exact on this GPU. Still inside D3D12's tolerance, so the test passes, but it may be worth a look (or a --verbose run on a few seeds) before this lands, since on the old base it was bit-exact.

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

@Jadiac5

Jadiac5 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested 5bd5840 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.

8 participants