Skip to content

d3d12_copy_fuzz_test: random copy programs against WARP, every byte compared (shows #4997's hazard on NVIDIA) - #5272

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

Exopus-0x65f7ad0 wants to merge 2 commits into
ItsNotRexed:mainfrom
Exopus-0x65f7ad0:test/copy-fuzz

Conversation

@Exopus-0x65f7ad0

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: a new TEST item (claim).

Depends on: none. It complements #4997: this test passes on main and with #4997, and with LEONIDA_VK_VALIDATION=1 it is what shows #4997's hazard on NVIDIA.

What and why

d3d12_copy_fuzz_test runs seeded random copy programs on the layer and on WARP, and compares every byte of every resource afterwards.

  • Resources: two 256 KiB buffers and three textures of one format: RGBA8, BGRA8, RGBA16F, R32F, RG32UI, R8, R16UI, RGB10A2, RGBA32UI, BC1, BC3 or BC7, with random sizes, mips and array layers. All are filled with known bytes.
  • The program (12–42 copies, sometimes split over several command lists):
    • CopyBufferRegion at any offset and size;
    • CopyTextureRegion buffer→texture and texture→buffer through placed footprints, with block-aligned boxes;
    • CopyTextureRegion texture→texture between subresources;
    • CopyResource between two textures of the same description.
  • Barriers: transitions only when a resource changes between COPY_SOURCE and COPY_DEST. Back-to-back copies on a resource that stays in one state get no barrier, so they must run in program order.
  • Readback: buffers whole, texture subresources at each device's own footprints, padding excluded.

Why WARP and not the GPU's D3D12: NVIDIA's driver (621.14) does not keep program order for a texture→buffer copy followed by an overlapping CopyBufferRegion with no barrier between them. WARP and the layer do. I computed the expected bytes from the fill pattern to confirm which side is right; details on #4997. --hardware compares with the GPU's D3D12 anyway.

--reduce SEED drops copies and list breaks while the layer still differs, and prints the smallest program left. That is how this program was found:

CopyBufferRegion(b0 + far, b1, 64)          // both buffers already in their copy states
CopyTextureRegion(b0 footprint, tex, box)
CopyBufferRegion(b0 + overlap, b1, 1500)    // no barrier before it

Results

RTX 5060 Ti / 621.14, LEONIDA_VK_VALIDATION=1 (synchronization validation on):

300 seeds against WARP synchronization validation
main 3faac557 0 differ 10 × SYNC-HAZARD-WRITE-AFTER-WRITE (vkCmdCopyBuffer ↔ vkCmdCopyImageToBuffer)
#4997 13a9d807 0 differ 0

ctest runs 30 seeds (about 30 s) and doesn't count validation messages. The hazard needs the validation layer to be seen on this card, because the NVIDIA Vulkan driver happens to serialize these copies. A GPU that doesn't serialize them, such as the RX 9060 XT in #4997, fails on bytes.

Tested

Same host/WARP differential approach as #5180 (fences), #5218 (GetCopyableFootprints) and #5239 (CPU-heap buffers). AI-assisted (Claude Code). Synthetic data only, no game files.

🤖 Generated with Claude Code

…ry byte compared

Each program runs CopyBufferRegion, CopyTextureRegion (buffer to texture, texture to buffer, texture to texture,
with boxes) and CopyResource over two buffers and three textures of one of 12 formats (BC1/3/7 among them, mips
and arrays), with no barrier between back-to-back copies on a resource that stays in COPY_DEST or COPY_SOURCE.
Every byte is read back and compared with WARP, which keeps program order; NVIDIA's own D3D12 driver (621.14)
does not for a texture-to-buffer copy followed by an overlapping CopyBufferRegion, so it is only an option
(--hardware). --reduce SEED shrinks a failing program. On main, 300 seeds match WARP; under synchronization
validation they report 10 write-after-write hazards between buffer copies, which ItsNotRexed#4997's barriers remove.

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

shdann commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

AI-assisted. At a1110cc, a missing seed count can make an automated run pass without testing any copies.

Run d3d12_copy_fuzz_test.exe --seeds --verbose. The test prints 0 seeds, 0 differ and exits 0. The parser consumes --verbose as the count. Expected: report a missing or invalid count and exit 2. Check that the numeric argument contains decimal digits and that the conversion consumes the whole argument. The parent 3faac55 has no copy fuzz executable.

I also ran the default 30 seeds against WARP on Windows 11 with LEONIDA_VK_VALIDATION=1. I built with cmake --build E:/Leonida-review-work-build --config RelWithDebInfo --target d3d12_copy_fuzz_test --parallel 8. I ran the executable once with LEONIDA_VK_DEVICE=4090 and once with LEONIDA_VK_DEVICE=Radeon. The device log confirms the RTX 4090 and AMD Radeon(TM) Graphics respectively. Both runs exit 0 with 30 seeds and zero byte differences. Each run logs three SYNC-HAZARD-WRITE-AFTER-WRITE errors.

@CharlyRien

Copy link
Copy Markdown

Tested a1110cc (merged on main 3faac55) on RTX 3090 (NVIDIA 616.56, Windows 11 23H2 22631, in-box WARP 10.0.22621.5415): pass. AI-assisted.

  • The full ctest run gives the same results as main on this host. d3d12_copy_fuzz passes in 1.8 s.
  • With LEONIDA_VK_VALIDATION=1 d3d12_copy_fuzz_test --seeds 300, the output is 300 seeds, 0 differ, and there are exactly 10 SYNC-HAZARD-WRITE-AFTER-WRITE messages. That matches the main row of your table, so the result holds on Ampere and on the older 23H2 WARP oracle.

I didn't get the #4997 row: #4997 conflicts with this branch in runtime/CMakeLists.txt.

…f 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

@shdann thanks, confirmed and fixed in 1f91eef4. A count (--seeds, --start, --reduce) must now be decimal digits that fit in 32 bits; anything else exits 2 with <option> needs a decimal count. On the RTX 5060 Ti / 621.14: --seeds --verbose, --seeds (last argument), --seeds -1 and --start 99999999999 all exit 2; --seeds 2 exits 0, and the default run is unchanged (30 seeds, 0 differ). #5218 and #5180 had the same parser and got the same fix (bc2b6c11, 554ddf43; for #5180 --queues also goes through it now instead of atoi). AI-assisted (Claude Code).

@AmazingMoaaz

Copy link
Copy Markdown
Contributor

Tested 1f91eef (based on main 3faac55) on Intel UHD Graphics (Xe-LP, driver 101.7088) and NVIDIA RTX 3050 Laptop (617.42), Windows 11 Pro build 26300, d3d12_copy_fuzz_test built with MSVC 19.51: pass.

GPU (layer) default --seeds 300 LEONIDA_VK_VALIDATION=1 --seeds 300 --hardware --seeds 300
Intel UHD 30 seeds, 0 differ 300 seeds, 0 differ 300 seeds, 0 differ; 10 SYNC-HAZARD-WRITE-AFTER-WRITE, no other validation messages against Intel UHD's D3D12: 300 seeds, 0 differ
RTX 3050 30 seeds, 0 differ 300 seeds, 0 differ 300 seeds, 0 differ; 10 SYNC-HAZARD-WRITE-AFTER-WRITE, no other validation messages against Intel UHD's D3D12: 300 seeds, 0 differ
  • Intel's D3D12 driver (101.7088) keeps program order for these copies: --hardware against it gives 0 differ over 300 seeds, unlike NVIDIA 621.14 in your description. That's a first non-NVIDIA hardware reference.
  • The 10 write-after-write hazards match @CharlyRien's RTX 3090 count.
  • Nit: --hardware ignores LEONIDA_HOST_ADAPTER. reference_device takes the first hardware adapter (line 46: "the first hardware adapter with --hardware"). On this laptop that's the Intel iGPU, so the RTX 3050 run compared against Intel's driver even with LEONIDA_HOST_ADAPTER=3050, and NVIDIA's own D3D12 couldn't be the reference. d3d12_buffer_tiles had the same issue (TEST-670, d3d12_buffer_tiles: honour LEONIDA_HOST_ADAPTER and print the tile that differs (TEST-670) #3446); the usual matching is warp or part of an adapter name, as in d3d12_copy_compare.h. With it, the 3050 row's --hardware column would show NVIDIA's reordering on a second card.

@milas6669

Copy link
Copy Markdown

Tested 1f91eef4 on Windows 11 with an NVIDIA GeForce RTX 3070 (driver 32.0.16.2124), MSVC 14.44, built from this branch (cmake --build runtime/build --target d3d12_copy_fuzz_test).

  • default (30 seeds, layer against WARP): copy fuzz (layer against WARP): 30 seeds, 0 differ, exit 0.
  • --seeds 200: 200 seeds, 0 differ, exit 0, 13 s.
  • --seeds 50 --hardware (layer against the RTX 3070's own D3D12): 50 seeds, 0 differ, exit 0, 7 s.
  • LEONIDA_VK_VALIDATION=1: still 30 seeds, 0 differ and exit 0, but the run reports 3 × SYNC-HAZARD-WRITE-AFTER-WRITE (0x5c0ec5d6) on vkCmdCopyBuffer writing one 256 KiB buffer. So the Runtime: order back-to-back copies that read or write a buffer #4997 hazard does show up on Ampere under validation, as the description says for NVIDIA, and the byte comparison still passes — the test is green in all four runs.

Device lines from the run: maxPushConstantsSize: 256, subgroup sizes 32..32, upload heaps in VRAM (DEVICE_LOCAL | HOST_VISIBLE, Resizable BAR).

The --seeds/--start validation works as described: --seeds xyz and a bare --seeds both exit 2 instead of running 0 seeds.

AI-assisted. No game data.

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

Reviewed 1f91eef (2 commits; the argument parsing is in 1f91eef). Built target d3d12_copy_fuzz_test with vcvars64/Ninja, RelWithDebInfo, Vulkan 1.4.363; no warnings.

On Windows 11, RTX 5070 Ti (LEONIDA_VK_DEVICE='RTX 5070 Ti'):

  • d3d12_copy_fuzz_test.exe (default 30 seeds) -> "copy fuzz (layer against WARP): 30 seeds, 0 differ", exit 0.
  • ctest --test-dir build-5272 -R "^d3d12_copy_fuzz$" -> 1/1 passed (1.24 s).
  • --hardware --seeds 2 -> 2 seeds, 0 differ, exit 0.
  • --seeds / --seeds 12x -> exit 2, "needs a decimal count"; --start 4294967295 --seeds 2 runs seeds 4294967295 and 0, exit 0; --reduce 1 -> "seed 1 does not differ from WARP", exit 0.
  • LEONIDA_VK_VALIDATION=1 --seeds 10 -> 10 seeds, 0 differ, and the expected SYNC-HAZARD-WRITE-AFTER-WRITE messages (the #4997 gap); the ctest entry does not count them, as stated.
  • git diff --check -> clean.

Verdict: passes; no blockers. Overlap: byte-exact pass on GPUs whose driver does not serialize these copies depends on #4997.

@Koro4e

Koro4e commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested a1110cc on RTX 3060, driver 617.14, Windows 11, MSVC 14.44 RelWithDebInfo: pass

  • Built d3d12_copy_fuzz_test clean; registered ctest (d3d12_copy_fuzz, WARP reference, seeds 1-30) passed in 1.71 s.
  • Longer runs: WARP reference seeds 1-1000: 1000/1000 programs compared, 0 mismatches, 0 run errors.
  • --hardware (NVIDIA D3D12 as the reference, the layer on the RTX 3060): seeds 1-30 and 1-1000 fully agree; seeds 1-5000 produced 7 mismatches (0.14%), all between 2000 and 5000 - the PR's hazard shows up exactly as claimed, against the NVIDIA D3D12 driver, while the layer always matches WARP (including seeds 2219 and 3476).
  • --reduce 2219 gives a 3-copy single-list minimal case: CopyBufferRegion, CopyTextureRegion (R8_UNORM, 3 bytes), CopyBufferRegion overlapping those bytes; NVIDIA lands the texture bytes after the later buffer copy, the layer keeps program order. --reduce 4904 is the same triple with B8G8R8A8_UNORM 2x9 m4.

One note: the hazard reproduces on driver 617.14 too, while the test header pins it to 621.14 - same bug class, just rarer; the wording could say "621.14 and 617.14" or "617.14+". Also worth documenting that the demonstration needs --hardware with ~5000 seeds (~6.5 min), beyond the registered test's 30-seed WARP pass and 600 s timeout.

AI-assisted.

@gertify

gertify commented Nov 23, 2026

Copy link
Copy Markdown

Tested 1f91eef on NVIDIA GeForce RTX 4080, driver 617.42: d3d12_copy_fuzz_test exits 0 with "copy fuzz (layer against WARP): 30 seeds, 0 differ". The LEONIDA_VK_VALIDATION=1 synchronization-validation leg was not run, so the #4997 hazard in the description is not reproduced here.

AI-assisted.

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