Skip to content

Tools: image_load differential fuzzer and its GPU harness - #863

Merged
ItsNotRexed merged 4 commits into
ItsNotRexed:mainfrom
SuarezPM:image-load-fuzzer
Nov 22, 2026
Merged

ItsNotRexed merged 4 commits into
ItsNotRexed:mainfrom
SuarezPM:image-load-fuzzer

Conversation

@SuarezPM

Copy link
Copy Markdown
Contributor

New FUZZ item (claimed in #634); docs/shader_validation.md still said "Not covered yet: images", and FUZZ-1..13 cover VALU, memory, LDS, crosslane and control flow but not one image instruction.

What this is

  • runtime/test/vk_image_fuzz.cpp — headless harness. It reads a key=value spec (width, height, format, texels path, the 8 T# words), creates one DEVICE_LOCAL 2D sampled image, uploads the texels through staging, registers the T# → bindless index in the descriptor table through BindlessSet, and draws a 64×64 full-screen triangle with the VS/PS it is given, dumping RGBA32F. It enables fragmentStoresAndAtomics and the without-format storage-image reads/writes the translated image path declares; LEONIDA_VK_VALIDATION=1 turns any validation error into a failure.
  • tools/image_fuzz.py — assembles a pixel shader that reads one texel with image_load (dmask:0xf, T# in s[8:15], coordinates from the interpolated UV), translates it with rdna2spirv.py, runs the harness and compares every pixel with an independent CPU oracle for the T# format. A texel fetch is a memory read, so the oracle is exact (UNORM divide in f32, binary16 → float, missing components (0,0,1)).
  • tests/test_image_fuzz.py — the oracle, the texel mapping, the T# word and the generated shader, no GPU.
cmake --build runtime/build --target vk_image_fuzz
python -I tools/image_fuzz.py --programs 40 --seed 11 [--show]
python -m pytest tests/test_image_fuzz.py

Covered: R8G8B8A8_UNORM, R16G16B16A16_SFLOAT, R32G32B32A32_SFLOAT, R32_SFLOAT; 8/16/32/64 square sizes that divide the draw, every texel read; a fifth of the values are NaN, ±inf, ±0 or denormals.

Not covered yet (follow-ups): dmask variants, UINT/SINT formats (they read through the storage views), mips, 1D/2D-array/3D/cube, image_sample/gather with filters and borders, and texel offsets with VK_KHR_maintenance8.

Verified on an NVIDIA RTX 2060 SUPER (Linux, 620.73.04, Vulkan 1.4.357): 40/40 programs match under LEONIDA_VK_VALIDATION=1; ctest 11/11; the GPU suite is unchanged with a clean build (73/100 + 27 64-wide skips, 0 failures); pytest tests/test_image_fuzz.py 11/11.

No game data; synthetic fixtures only. AI-assisted.

Depends on: nothing. Touches runtime/test/ and tools/ only.

@SuarezPM

Copy link
Copy Markdown
Contributor Author

Two review notes:

  • Not vacuous. Adding v_add_nc_u32_e32 v2, 1, v2 before the image_load of a generated case (the shader reads the next texel) turns 6+ pixels into mismatches against the oracle; 40/40 cases match without it. The oracle is the fuzzer's own, not the translator's.
  • Why the harness enables what it does. The translated image_load declares the storage-image views even when only the float path runs (image_load_typed picks uint/sint/float from the T# FORMAT at run time), so the layout needs fragmentStoresAndAtomics and the without-format storage-image read/write features. With LEONIDA_VK_VALIDATION=1 a validation error fails the run; that is what caught the missing features while building this.

@kapitche

Copy link
Copy Markdown
Contributor

Tested 8f5d428 on Windows 11 with two GPUs on one machine (runtime built from this PR's head, MSVC 14.51, ctest 32/32, llvm-mc 23.1.6):

  • NVIDIA GeForce RTX 4080 SUPER (32.0.16.1714): image_fuzz.py --self-test ok; --programs 50 --seed 1: 50/50 match.
  • Intel UHD Graphics 770 (Xe-LP, 32.0.101.6129): 0/0 ran, 50 skipped. vk_image_fuzz exits 77 with unsupported: the device lacks bufferDeviceAddress, runtimeDescriptorArray, shaderInt64, … or the without-format storage-image reads/writes.

The harness requires more than the fuzzed shaders use. vulkaninfo on this iGPU shows every listed feature present except shaderStorageImageReadWithoutFormat = false. The same holds on Mesa/ANV for this part, per #619.

The translator only declares StorageImageReadWithoutFormat when a shader reads an integer image (gen.uses_store_reads, rdna2spirv.py ~6315). Float formats load with OpImageFetch through the sampled view (the design.md "Typed image loads" row). All four FORMATS here are float/UNORM, so none of the generated shaders need the feature, yet every program skips on Intel.

Suggestion:

  • Enable shaderStorageImageReadWithoutFormat only when the device has it, and don't make it a requirement.
  • Leave the decision to pipeline creation, or to a check of whether the PS SPIR-V declares the capability.

Then Intel iGPUs, and other devices without the feature, can still fuzz the float path. The split into two messages (which feature is missing) would also have saved a vulkaninfo round trip here.

@SuarezPM

Copy link
Copy Markdown
Contributor Author

@kapitche thank you — the RTX 4080 SUPER numbers are the first Windows/Ada confirmation (50/50), and the Intel run is the more useful one.

On the skip: it is real, and it comes from the translator rather than from the harness asking for more than the case needs. image_load_typed (tools/rdna2spirv.py:5391) sets uses_store_reads for every image_load in STORE_DIMS, because the uint/sint/float branch is chosen from the T# FORMAT at run time; the module therefore declares StorageImageReadWithoutFormat (and the storage views) even when the fuzzed T# is float or UNORM. Vulkan requires the feature for a declared capability, so a pipeline for any translated image_load is invalid on Xe-LP without shaderStorageImageReadWithoutFormat — the case would not run even if the harness stopped requiring the feature.

What I did change, from your review:

  • the harness now prints exactly which features are missing, one line, with a second line naming the reason when the without-format ones are involved, so no vulkaninfo round trip;
  • the shaderStorageImageWriteWithoutFormat requirement stays because the module declares it too, but your iGPU has it — Read is the only blocker.

The portability issue itself (translated image_load cannot run on devices without without-format storage reads) is a translator finding, not this harness; I posted it in #634. Thanks for testing both GPUs on one machine — that is the comparison that surfaced it.

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

Tested 7da4428 on NVIDIA GeForce RTX 5070, driver 621.24, Windows 11 Pro (26300), VS 2022 Build Tools, Vulkan SDK 1.4.363.0, with LEONIDA_VK_VALIDATION=1 and LEONIDA_D3D12=vulkan: pass

  • ctest -C RelWithDebInfo: 100% tests passed, 0 tests failed out of 32
  • 33 test programs in the build pass with 0 validation errors
  • d3d12_clear_test fails (R8G8B8A8_UNORM/SNORM 0.5 ties and a D16 clear byte differ from WARP) exactly as on main 4a36bb1 here, so not from this PR; #521 addresses it

Implicit Vulkan layers (overlays) were off through an empty VK_IMPLICIT_LAYER_PATH.

@SuarezPM

Copy link
Copy Markdown
Contributor Author

@quackottu thank you — this is the first run on the final head (7da4428) that covers the runtime suite as well as the new harness, and the "0 validation errors over 33 programs" line is exactly the evidence I wanted from a Windows/Ada machine.

Noted on d3d12_clear_test: it reproduces on main 4a36bb1 in your same run, so it is the R8G8B8A8 tie / D16 clear-byte difference, not this PR; #521 (D3D-45) is the one carrying it. Nothing in this change touches the layer or the clear path — vk_image_fuzz is a standalone binary and the fuzzer drives it directly, so the runtime is only exercised by ctest here.

For the record, the branch as pushed also passes the full GitHub CI on this head (check, semantic both OS, translator, viewer, windows, linux-gpu-tools, wine, change-scope, no-game-data). Thanks for turning off the implicit overlay layers too — that is the same trap that made @rafaelpssz's first run on #696 look red.

@caua-an

caua-an commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Tested PR head 7da4428 on AMD Radeon RX 7600 (RDNA3/Navi 33), RADV Mesa 26.2.4, Zorin OS 18.1, LLVM 21.1.8 and SPIRV-Tools 2025.1.

  • python3 -m pytest tests/test_image_fuzz.py -q: 11/11 passed.
  • image_fuzz.py --self-test: passed.
  • image_fuzz.py --programs 40 --seed 11: 40/40 matched with LEONIDA_VK_VALIDATION=1; no validation errors reported by the harness.
  • ctest --test-dir runtime/build/linux --output-on-failure: 11/11 passed.

The run covered the four formats supported by the fuzzer. Implicit Vulkan layers were disabled. No game files or game-derived data were used.

@Pierre-Kookis

Copy link
Copy Markdown

Tested 7da4428 on AMD's proprietary Windows driver (the earlier AMD run was RADV): pass.

Windows 11. AMD Radeon Graphics (Ryzen 7 7800X3D iGPU, RDNA2), driver 26.3.1 (32.0.21043.5001). RTX 4070 Ti SUPER, driver 610.88. vk_image_fuzz built from this head with llvm-mingw clang (Release), llvm-mc 23.1.6.

result
AMD --self-test ok (4 formats, 64x64 draw)
AMD --programs 50, seeds 1, 2, 3 50/50, 50/50, 50/50 match
NVIDIA --programs 50 --seed 1 50/50 match
pytest tests/test_image_fuzz.py 11 passed

No validation layer is installed here, so these runs are without LEONIDA_VK_VALIDATION.

(AI-assisted run, counts only.)

AI-assisted. docs/shader_validation.md said "Not covered yet: images", and
FUZZ-1..13 touch VALU, memory, LDS, crosslane and control flow but not a single
image instruction. This is the first slice of that gap:

- runtime/test/vk_image_fuzz.cpp: headless harness that binds one 2D sampled
  image from a key=value spec (format, size, texels, T# key) through the
  bindless set and the descriptor table, draws a 64x64 full-screen triangle with
  a caller-supplied VS/PS, and dumps RGBA32F. It enables the without-format
  storage-image reads/writes and fragment atomics the translated image path
  declares, and fails on validation errors with LEONIDA_VK_VALIDATION=1.
- tools/image_fuzz.py: assembles a pixel shader that reads one texel with
  image_load (dmask 0xf, T# in s[8:15]), translates it with rdna2spirv.py, runs
  the harness, and compares every pixel with an independent CPU oracle for the
  T# format. A fetch is a memory read, so the oracle is exact.
- tests/test_image_fuzz.py: the oracle, the texel mapping, the T# word and the
  generated shader, without a GPU.

Covered: R8G8B8A8_UNORM, R16G16B16A16_SFLOAT, R32G32B32A32_SFLOAT and
R32_SFLOAT, at 8/16/32/64 square sizes that divide the draw; a fifth of the
values are NaN, +-inf, +-0 or denormals.
Not covered yet: dmask variants, UINT/SINT formats (they read through the
storage views), mips, 1D/2D-array/3D/cube, image_sample/gather with filters and
borders, and texel offsets with VK_KHR_maintenance8.

Verified on an NVIDIA RTX 2060 SUPER (Linux, 620.73.04, Vulkan 1.4.357):
40/40 programs match under LEONIDA_VK_VALIDATION=1; ctest 11/11; the GPU suite
is unchanged with a clean build. Synthetic fixtures only, no game data.
The skip message said 'lacks ... or the without-format reads/writes', which cost kapitche a vulkaninfo round trip on an Intel UHD 770. It now prints the exact features that are missing, plus the reason when the without-format ones are involved: the translated image_load declares those capabilities for every shader, because its uint/sint path is chosen from the T# FORMAT at run time.
@SuarezPM

Copy link
Copy Markdown
Contributor Author

Two more GPUs and both AMD drivers on the same PR — thank you both.

  • @caua-an, RX 7600 (RDNA3, RADV Mesa 26.2.4, Linux): 11/11 pytest, self-test, 40/40 under LEONIDA_VK_VALIDATION=1, ctest 11/11.
  • @Pierre-Kookis, Ryzen 7 7800X3D iGPU (RDNA2, AMD proprietary 26.3.1, Windows): 50/50 on seeds 1, 2 and 3, and 50/50 on an RTX 4070 Ti SUPER (610.88), 11 pytest passes. That is the first non-RADV result, and the first with the proprietary AMD driver.

Both match the oracle with zero mismatches, which is the outcome the fuzzer is built to produce for these four formats.

Heads-up: main moved while you were testing. The head is now 6169f9b (rebased; the only conflict was runtime/CMakeLists.txt, where depth24_convert_test had merged next to the new target). I re-ran on it here: 40/40 under validation, ctest 11/11, GPU suite 74/101 with the usual 27 64-wide skips and 0 failures. No need to re-run unless you want the new head on record.

@Vonsek

Vonsek commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

The float oracle accepts a wrong binding when the only difference is the sign of zero. I reproduced this on head 7da44289 with the PR's harness and validation enabled, on Windows RTX 5080 (616.92) and Radeon Graphics (26.10.1).

8×8 RGBA32F, all 4096 pixels fetch texel (0,0) Pixels with different raw RGBA32 words Mismatches reported by compare()
Correct key, texel (−0, +0, −0, +0) 0 0
Change only T# word 7 in the shader (s_mov_b32 s15, 1 before image_load), select the cleared fallback 4096 0
Same key miss, source red changed from −0 to 1 4096 6 (report cap)

There is also a case with the normal varying coordinates and the PR's generated input. With make_texels("R32G32B32A32_SFLOAT", 8, 8, random.Random(11)), the unmodified shader matched every raw word. Changing only red −0 to +0 after the fetch changed 192/4096 pixels on each GPU. The comparator still returned an empty list. All draws returned success with validation on. I repeated both controls after locally integrating the PR with main 067d3e8 (preserved both CMake targets), with the same counts. After the rebase I rebuilt the harness on the published head 6169f9be and repeated the draws on both GPUs: the wrong-binding case still passed with 4096 wrong pixels and the generated case still passed with 192.

In tools/image_fuzz.py::compare the ordinary float equality treats +0 and −0 as equal. Comparing the packed f32 bits while preserving the existing any-NaN-equals-any-NaN policy would make the signed-zero coverage observable. A CPU regression can put −0 in a single expected channel and +0 in just one output pixel and assert its coordinates. AI-assisted, synthetic data only.

Vonsek reproduced a blind spot: +0.0 == -0.0 in Python, so a wrong binding that returns +0 where the texture holds -0 passed silently (4096/4096 raw words differ, compare() reported none; 192/4096 on a generated float case).

same_component() now compares the packed f32 words and keeps the any-NaN policy (payloads are not modelled). Two CPU regressions: one flips a single output channel from -0 to +0 and expects exactly that pixel; the other feeds a different NaN payload and expects no mismatch. 40/40 programs still match on the RTX 2060 SUPER with validation, so the GPU preserves signed zeros for these formats.
@SuarezPM

Copy link
Copy Markdown
Contributor Author

@Vonsek caught and fixed — thank you, that was a real blind spot in the comparator, and the raw-word counts made it unambiguous (4096/4096 differing words with 0 reported, and the 192 on a generated case).

The fix is in same_component(): it now compares the packed f32 words, so +0 and -0 differ, and keeps the previous policy that any NaN matches any NaN (payloads are still not modelled). Two CPU regressions pin it:

  • one builds an 8×8 float case of -0.0 red, fills the expected 64×64 output, flips a single channel to +0 and asserts compare() reports exactly that pixel;
  • the other feeds a different NaN payload and expects no mismatch.

Both fail on the old comparator. Re-ran 40/40 on the RTX 2060 SUPER with LEONIDA_VK_VALIDATION=1 after the change: the GPU preserves signed zeros for these formats, so the suite stays clean, but the wrong-binding control you built now reports its 4096 pixels.

New head: the rebased 6169f9b plus this commit; thanks also for re-checking it after the rebase on both GPUs.

@Vonsek

Vonsek commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Retested 67c22b3 with the same six draws on RTX 5080 and Radeon Graphics, validation enabled. The wrong-key fallback still differs at 4096 pixels (8192 channel words), and red −0 canonicalization still differs at 192 pixels. Both now report six mismatches, the comparator's reporting cap, on each GPU. Correct-key and unmodified generated draws report zero. The finite control still detects the wrong key. All 13 CPU tests passed, including the NaN-payload control. This addresses my finding. AI-assisted.

@SuarezPM

Copy link
Copy Markdown
Contributor Author

@Vonsek confirmed on our side too: 67c22b3 is the head, and the six-mismatch cap is intentional so a failing case prints coordinates instead of a wall of pixels. Thank you for the two-GPU retest and for the NaN-payload control — the comparator is stricter than it was when you started.

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.

7 participants