Skip to content

d3d12_fence_fuzz_test: a differential fence/queue fuzzer against the host D3D12 (found a main crash fixed by #4740) - #5180

Open
Exopus-0x65f7ad0 wants to merge 4 commits into
ItsNotRexed:mainfrom
Exopus-0x65f7ad0:test/fence-fuzz
Open

Exopus-0x65f7ad0 wants to merge 4 commits into
ItsNotRexed:mainfrom
Exopus-0x65f7ad0:test/fence-fuzz

Conversation

@Exopus-0x65f7ad0

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: a new TEST item, the differential fence/queue fuzzer (claim).

Depends on: none.

What and why

D3D-496, the VUID-05149 regression found on #4725, and the three Signal(UINT64_MAX) cases on #4609 were each found with a hand-written probe that runs the same calls on the layer and on the host D3D12. d3d12_fence_fuzz_test makes that systematic.

Programs. A seeded random program of:

  • queue Signal / Wait;
  • CPU Signal;
  • SetEventOnCompletion;
  • ExecuteCommandLists.

It runs on the DIRECT, COMPUTE and COPY queues with four fences, and is replayed on the layer (a vktest::Device, so validation errors are counted) and on the host device.

Comparison. At settle points (the state stable for three reads 20 ms apart), every fence's completed value and every event's state must match.

Why the settled state is deterministic:

  • each fence has one signaller (the CPU or one queue);
  • a queue waits only for a value already given to that signaller, or for a CPU fence;
  • the program ends by signalling each CPU fence to the highest value anything waits for.

So no wait cycle can form, and any correct implementation settles to the same values.

  • Default (ctest): monotonic values, no fence released in use, steps below 2^31. 40 seeds × 48 operations, about 40 s.
  • Options for the known gaps:
  • Fixed case: --case pending-wait-release, the crash below.
  • Output: a mismatch prints the seed and the program up to the first settle point that differs.
  • Skips (77): without Vulkan, without a host adapter, and under Wine, whose D3D12 is vkd3d and so no reference.

What it found

Each head below has this file added. RTX 5060 Ti / 621.14, LEONIDA_VK_VALIDATION=1, 30 seeds per mode:

Head default --release --rewinds --big
main 3faac557 identical segfault differs VUID-03260
#4740 d7e53406 (+ #4663) identical identical – –
#4486 047b789d identical segfault, VUID-05149 – –
#4577 c7cc36bc identical 3 of 30 differ identical identical

The --release mode can join ctest once #4740 (or an equivalent) is on main.

Tested

AI-assisted (Claude Code). Synthetic fences only, no game files.

🤖 Generated with Claude Code

…he host D3D12, compared once settled

Each program mixes queue Signal/Wait, CPU Signal, SetEventOnCompletion and ExecuteCommandLists on three queues
and four fences. A fence has one signaller and a queue waits only for a value already given to it (or a CPU
fence signalled later), so no wait cycle forms and the settled state is the same on any correct implementation.
Fence values and event states are compared at settle points; with LEONIDA_VK_VALIDATION=1 any validation error
fails the seed. ctest runs the default mode; --release, --rewinds and --big cover the known gaps (D3D-496,
D3D-472, the timeline limit), and --case pending-wait-release is the main crash they found.

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

gertify commented Nov 23, 2026

Copy link
Copy Markdown

Tested e277c5b on NVIDIA GeForce RTX 4080, driver 617.42, Windows 11 (clang-cl cross-build): d3d12_fence_fuzz_test in its default mode exits 0 with "fence fuzz: 40 seeds, 280 settle points, layer and host identical". The --release, --rewinds and --big modes, the pending-wait-release case and the validation-layer run were not done here.

AI-assisted.

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

Built and ran d3d12_fence_fuzz_test at e277c5b1d on Windows 11, RTX 5070 Ti: exit 0 — host D3D12: NVIDIA GeForce RTX 5070 Ti; seeds 1..40, 48 operations each; fence fuzz: 40 seeds, 280 settle points, layer and host identical; git diff --check clean.

The new fuzzer generates seeded fence/queue programs (signals, waits, rewinds, CPU and GPU paths, multiple queues) and compares the layer's answers with the host D3D12 once settled; all 40 seeds and 280 settle points match on this machine. The PR notes the fuzzer found a crash on main that #4740 fixes; that fix is not needed to pass the committed seed range here, and the test skips cleanly without a host device. No blocking issue.

@Atomic258

Copy link
Copy Markdown
Contributor

Independent check — PASS (Windows 11, NVIDIA RTX 5090, driver 617.42, Vulkan SDK 1.4.363.0).

Default run: d3d12_fence_fuzz_test — 40 seeds × 48 ops, 280 settle points, layer and host D3D12 identical. Queue Signal/Wait, CPU Signal and SetEventOnCompletion orderings all match the NVIDIA host driver's timeline semantics exactly.

The "any validation error fails the seed" wiring also held — clean run, no Vulkan validation output.

AI-assisted (Devin); no game files.

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

Reproduced on head e277c5b1 with a synthetic in-memory D3D12 harness:

  1. Q0 and Q1 each wait on an unsignalled CPU gate; queue a probe-fence signal after each wait.
  2. Queue drain signals at value 1 on Q0, 2 on Q1, and 3 on Q2.
  3. Wait for drain value 3. Its event fires while both Q0/Q1 probe fences are still WAIT_TIMEOUT; signalling the CPU gate then lets those queues finish.

execute() signals the same drain fence from DIRECT/COMPUTE/COPY with values 1/2/3 and waits only for 3. A later value reaching 3 on one queue does not establish that the earlier signals on the other queues completed, so cleanup may close event handles and continue with work still in flight. Please use a distinct completion fence/event per queue, or otherwise wait for each queue's own completion before cleanup. Synthetic D3D12 only; no game files.

--wide adds fences created above 0, SetEventOnMultipleFenceCompletion (ALL and ANY) and cross-queue
Wait-before-Signal (a queue waits only on a higher-numbered queue's fence, which that queue signals by the end, so no
cycle forms). --queues 6 adds a second queue of each type, --standalone runs the layer's own device, whose D3D12
queues can map to distinct VkQueues. On main 3faac55 (RTX 5060 Ti) all match the host: --wide 60 seeds, and 40
seeds each of --wide --queues 6, --wide --standalone and both, with validation on.

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

Copy link
Copy Markdown
Contributor

Independent Windows GPU verification at 7bb107dcf32cc9b706a9264e3afe408df6e11cad (AI-assisted; no game files).

Windows 11 Pro build 26300, NVIDIA GeForce RTX 4070 Ti, driver 610.88; MSVC 19.44, Vulkan SDK 1.4.363.0. Built the d3d12_fence_fuzz_test target in RelWithDebInfo. LEONIDA_VK_VALIDATION=1 enabled VK_LAYER_KHRONOS_validation; both runs reported validation on and used the NVIDIA host D3D12 adapter.

  • ctest --test-dir runtime\build -R ^d3d12_fence_fuzz$ -V: passed, seeds 1–40, 48 operations per seed, 280 settle points identical; 38.89 seconds.
  • d3d12_fence_fuzz_test.exe --start 41 --seeds 60 --ops 64: exit 0, seeds 41–100, 64 operations per seed, 540 settle points identical.

Neither run reported skipped seeds or Vulkan validation errors. The test device uses one Vulkan queue; this does not establish behavior on distinct Vulkan queues. These runs do not address the previously reported multi-queue drain concern and did not exercise --release, --rewinds, --big, --wide, or --standalone. --help is not implemented (exit 2); options were checked in source.

@gertify

gertify commented Nov 23, 2026

Copy link
Copy Markdown

Tested 7bb107d on NVIDIA GeForce RTX 4080, driver 617.42: d3d12_fence_fuzz_test in its default mode exits 0 and prints "host D3D12: NVIDIA GeForce RTX 4080; seeds 1..40, 48 operations each" and "fence fuzz: 40 seeds, 280 settle points, layer and host identical". The --release, --rewinds and --big modes were not run, and this run had no validation layer, so the validation-error claims in the description were not checked.

AI-assisted.

… cannot wrap the seed range to none

The same wrap @shdann found in d3d12_footprint_fuzz_test (ItsNotRexed#5218).

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

gertify commented Nov 23, 2026

Copy link
Copy Markdown

Tested 4bb567a on NVIDIA GeForce RTX 4080, driver 617.42: d3d12_fence_fuzz_test in its default mode exits 0 and prints "host D3D12: NVIDIA GeForce RTX 4080; seeds 1..40, 48 operations each" and "fence fuzz: 40 seeds, 280 settle points, layer and host identical". The --release, --rewinds and --big modes were not run, and this run had no validation layer.

AI-assisted.

@oVolkra

oVolkra commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested 4bb567a (merged onto main 3faac55) on RTX 3060, driver 617.14, Windows 11: pass.

Ran: ctest (with and without LEONIDA_VK_VALIDATION=1), the unregistered *_test.exe, and scripts/run_gpu_tests.py (native and LEONIDA_W64_EMULATE=1). Same failures as main (d3d12_clear and vk_texture, both failing on main too); no new failures.

AI-assisted: the run and this comment were produced with Claude Code (Claude Haiku 5.5); the numbers above are its unedited output.

…of running 0 seeds

A count option (--seeds, --start, --ops, --cases, --reduce, --queues) now needs decimal digits
that fit in 32 bits. A missing value, the next option, "-1" or "12x" exits 2 with a usage
message. Before, "--seeds --verbose" read as 0 seeds and exited 0 without testing anything.

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

Copy link
Copy Markdown
Contributor Author

Same argument-parsing hole as @shdann found in #5272 (--seeds --verbose ran 0 seeds and passed). Fixed in 554ddf43: --seeds, --start, --ops and --queues (was atoi) refuse a missing, negative, non-numeric or >32-bit count with exit 2. RTX 5060 Ti / 621.14: those cases exit 2; --seeds 2 and --queues 6 --seeds 3 still report layer and host identical. AI-assisted (Claude Code).

@kormocicsaba

Copy link
Copy Markdown

Tested 4bb567a2 (up to date with main 3faac557) on Windows 11 Pro 26300, VS 2026 (MSVC) + Ninja, RelWithDebInfo, Vulkan SDK 1.4.363.0, llvm-mc 21.1.8, no game files: pass

GPU driver default (40 seeds) with LEONIDA_VK_VALIDATION=1
NVIDIA GeForce RTX 4070 621.01, Vulkan 1.4.357 pass, 280 settle points identical pass, 0 validation errors
AMD Radeon iGPU 24.10.34, Vulkan 1.3.287 pass, 280 settle points identical pass, 0 validation errors

The AMD rows use the AMD Vulkan device for the layer. The host reference is still the RTX 4070, because native_device() takes the first hardware adapter.

What I ran, all on the RTX 4070 with validation unless noted:

  • Longer run: --start 41 --seeds 200 --ops 64. 1,800 settle points identical, no validation errors, 312 s.
  • --wide, --queues 6: 40 seeds each, identical.
  • --start 4294967295 --seeds 2: runs seeds 4294967295 and 0, identical. The wrap fix in 4bb567a2 works.
  • Full ctest -j4: 169/169 passed, 10 not run (the usual no-game-data skips, gameinput, vk_sync_validation, d3d12_rgb9e5_rtv). d3d12_fence_fuzz is registered and passed in 42 s.

The other modes on the PR head, which is main plus this file:

  • --rewinds: 20 of 30 seeds differ (D3D-472).
  • --big: 7 of 30 seeds differ, with VUID-03260, -03243 and -03244 (the 2^31-1 limit).
  • --release: segfault, after VUID-05149 and an invalid VkSemaphore in vkQueueSubmit.
  • --case pending-wait-release: segfault, plain and with validation.

This matches the main row of the table in the description.

Negative control: #4740 is still open, so the PR head is the build without the fix. To check the other side, I merged #4740's head d7e53406 onto this head (clean merge) and built the test:

  • --case pending-wait-release: passes, plain and with validation. The fixed case catches the crash and passes with the fix.
  • --release --seeds 30: 29 of 30 identical. Seed 1 differed once, then passed 3 of 3 reruns on this build and 3 of 3 on the PR head. See the first point below.
  • --standalone --wide --queues 6: identical, with no VUID-05149 (see the second point below).

Things I noticed:

  • The settle check can pass too early under load. The one mismatch above was COMPUTE Signal(f1, 2) with nothing waiting before it. The host had 2 at settle point 0, the layer 0. No fence had been released yet. The GPU was busy with a parallel ctest at the time. Three equal reads 20 ms apart (line 269) seem able to catch a queue before its first submission completes. This could flake under ctest -j.
  • --standalone prints VUID-05149 on main, and the test still passes. With --standalone --wide --queues 6 (40 seeds, all identical), the validation layer printed VUID-vkDestroySemaphore-semaphore-05149 10 times before its duplicate limit. Line 386 says these are printed but not counted, so the run passes. With Runtime: a queue waiting on a released fence goes on, as on the host (D3D-496, case 2) #4740 merged, the message is gone. My guess, not verified: the layer destroys a released fence's semaphore at once (D3D-486), and the drain lets the fences go while other queues may still be running (next point).
  • Flyander's drain point is still open on this head. Lines 289-295 signal one drain fence with 1, 2 and 3 from the three queues and wait only for 3. On the test device all queues share one VkQueue, so this holds. With --standalone the queues can map to distinct VkQueues.
  • --help exits 2 as an unknown option. The options are only listed in the header comment.

Machine note, not about this PR: for part of the session, the AMD Vulkan driver took about 60 s to initialize. Every Vulkan process start pays that, even on the RTX 4070. In the first ctest run, d3d12_queue_wait, d3d12_queue_wait_timeout, d3d12_xdxr_rt (and so d3d12_xdxr_rt_check) and queue_proxy failed by timeout. With VK_LOADER_DRIVERS_DISABLE=*amd* they pass, and the ctest count above is from that run.

AI-assisted (Claude Code).

@Krashgamer

Krashgamer commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Tested 554ddf43 (it already contains main 3faac557) on an NVIDIA RTX 3080 (Ampere) with driver 610.88, Windows 11 Pro 26200, MSVC 14.51, Vulkan SDK 1.4.363.0, RelWithDebInfo, LEONIDA_VK_VALIDATION=1 (device: ... (validation on)): pass, with two observations below.

  • Default (the ctest mode): 40 seeds, 280 settle points, layer and host identical, 0 VUIDs. Also identical: --wide --seeds 40 (280), --queues 6 --seeds 20 (140), --seeds 200 --ops 64 (1,800).
  • The new argument check: --seeds --verbose, --seeds -1, --seeds 12x, --ops (no value) and --seeds 99999999999 all exit 2.
  • The table's main row reproduces on Ampere: --release segfaults (exit 139, with VUID-VkSubmitInfo-pWaitSemaphores-parameter and VUID-vkDestroySemaphore-semaphore-05149 before it), and so does --case pending-wait-release. --rewinds gives 20 of 30 seeds differ. --big gives 7 of 30 differ, with VUID-03260/03243/03244 (10 each).
  • With Runtime: a queue waiting on a released fence goes on, as on the host (D3D-496, case 2) #4740 d7e53406 merged on top (clean merge): --release --seeds 30 is identical in 4 of 5 runs. One run had seed 24 differ at settle point 0: host 0 0 3 0, layer 3 0 3 0. So the host's f0 was still 0 after COMPUTE Signal(f0, 3) (in that program the compute queue waits on nothing) while the layer's was 3. Seed 24 alone then passed 80 of 80 times (40 with validation, 40 without), and a 30-seed run without validation passed too. It looks like a rare settle-window timing flake on the host side rather than a layer bug, but it matters for the plan to add --release to ctest once Runtime: a queue waiting on a released fence goes on, as on the host (D3D-496, case 2) #4740 is on main. @kormocicsaba's run above (posted while I was testing) saw the mirror case: there the layer lagged (host 2, layer 0, seed 1). One run each way points at the settle check (three equal reads 20 ms apart) rather than at either device.
  • --standalone under validation, on the default (no-release) programs: fence fuzz: 10 seeds, 70 settle points, layer and host identical, exit 0, but the layer's own device prints 20 × VUID-vkDestroySemaphore-semaphore-05149 (10 seeds; 8 for seed 1 alone, 2 with --ops 4), the same with --queues 6. The source says standalone messages are "printed but not counted", so this is by design. Still, it shows that on main the multi-VkQueue device destroys a semaphore still referenced by a submitted batch even when no fence is released in use. With Runtime: a queue waiting on a released fence goes on, as on the host (D3D-496, case 2) #4740 merged it drops to 0. Maybe worth a line in the D3D-496 notes, since the test device (one queue) never shows it.

Not run: the other heads in the table (#4486, #4577).

AI-assisted (Claude Code). Synthetic fences only.

@trvxoo-glitch

Copy link
Copy Markdown

Tested 554ddf4 on AMD Radeon RX 6700 XT (RDNA2), AMD driver 32.0.21045.29003 (Vulkan 26.11.2), Windows 10 Pro 22H2 (19045), MSVC 14.51, Ninja RelWithDebInfo: pass. The host D3D12 device is the AMD driver on the same GPU.

  • ctest -R "^d3d12_fence_fuzz$": passed (fence fuzz: 40 seeds, 280 settle points, layer and host identical).
  • Longer run: d3d12_fence_fuzz_test --seeds 400 --start 41 --ops 96 gave fence fuzz: 400 seeds, 5200 settle points, layer and host identical in 709 s, with no mismatches or hangs.

AI-assisted comment.

@caltr98

caltr98 commented Nov 23, 2026

Copy link
Copy Markdown

Tested 554ddf4 on NVIDIA GeForce RTX 5080 Laptop GPU, driver 621.14, Windows 11 (build 26300), MSVC 14.44, RelWithDebInfo: pass. ctest -R fence: 5 of 5 pass: d3d12_fence_fuzz (45.2 s), d3d12_fence_timing, d3d12_fence_events, d3d12_fence_waiter and vk_fence_dispatcher_sync. AI-assisted.

@caltr98

caltr98 commented Nov 23, 2026

Copy link
Copy Markdown

Tested 554ddf4 on NVIDIA GeForce RTX 5080 Laptop GPU, driver 621.14, Windows 11 (build 26300), MSVC 14.44, RelWithDebInfo: pass. ctest -R fence: 5 of 5 pass, including the new d3d12_fence_fuzz (45.2 s, with the NVIDIA host D3D12 adapter present), plus d3d12_fence_timing, d3d12_fence_events, d3d12_fence_waiter and vk_fence_dispatcher_sync. AI-assisted.

@Jadiac5

Jadiac5 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

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

  • Built d3d12_fence_fuzz_test at the head (RelWithDebInfo, Ninja, MSVC 19.44). The host reference is the AMD D3D12 driver; the earlier checks on this PR were all NVIDIA.
  • Default mode, without and with LEONIDA_VK_VALIDATION=1: "host D3D12: AMD Radeon RX 9070 XT; seeds 1..40, 48 operations each", "fence fuzz: 40 seeds, 280 settle points, layer and host identical", exit 0 (39 s; 54 s while other jobs ran).
  • ctest -R fence -j1: 5 of 5 pass (d3d12_fence_fuzz 39 s, d3d12_fence_timing, d3d12_fence_events, d3d12_fence_waiter and one more).
  • Argument checks (exit 2 with "needs a decimal count"): --seeds alone, --seeds --verbose, --seeds -1, --start abc, --ops alone, --queues x. --start 4294967295 --seeds 2 runs "seeds 4294967295..0", 2 seeds, 14 settle points, identical, exit 0.
  • Known-gap modes on this head (which has no Runtime: a queue waiting on a released fence goes on, as on the host (D3D-496, case 2) #4740) behave as the description says for main: --case pending-wait-release and --release --seeds 10 crash (exit 0xC0000005, validation prints "vkQueueSubmit(): pWaitSemaphores[0] Invalid VkSemaphore"); --rewinds --seeds 10: 7 of 10 seeds differ from the host; --big --seeds 10: 7 of 10 differ, seed 10 with 3 validation errors. These are the results of production code not in this PR, so they are not failures of it.
  • The PR adds a test, a CMake entry and docs only; no production code to review.
  • Not done: the fixed-state rows (Runtime: a queue waiting on a released fence goes on, as on the host (D3D-496, case 2) #4740, Runtime: preserve D3D12 fence rewinds across CPU and GPU signals (D3D-472) #4577) from the description's table, since that needs those PRs merged in.

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.