Skip to content

Shader tests: a cross-device VALU fuzzer (hardware adapters vs WARP) - #1614

Open
alexdeliu wants to merge 8 commits into
Marvisak:mainfrom
alexdeliu:valu-fuzz
Open

alexdeliu wants to merge 8 commits into
Marvisak:mainfrom
alexdeliu:valu-fuzz

Conversation

@alexdeliu

@alexdeliu alexdeliu commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

An ignored test that looks for shaders that compute different values on different GPUs. Every VOP3-encoded opcode the translator lowers runs as a one-thread compute shader on every hardware adapter and on WARP, on the same inputs, and the test reports where the devices disagree. The inputs are signed zeros, denormals, infinities, quiet and signalling NaNs, integer and f16 edges in either half, and seeded pseudo-random dwords.

Comparison rules:

  • Results must match bit for bit.
  • Any NaN matches any NaN.
  • Approximate ops (rcp, rsq, sqrt, log, exp, sin, cos) get a few ULPs.

A disagreement means the translation leans on behaviour that DXIL leaves to the device. The test is test-only and doesn't run in CI:

cargo test -p victory-shader --lib fuzz_tests -- --ignored --nocapture

Environment variables:

  • VICTORY_FUZZ_CASES: inputs per opcode (default 160).
  • VICTORY_FUZZ_OPS: comma-separated name filter.
  • VICTORY_FUZZ_OUT: write a Markdown report.

Each device runs alone, because two at once suspend WARP. A removed device is released before a new one is made, because D3D12 hands back the same removed device while a reference is alive.

What it found on main @ ffe310eb

Devices: RX 9070 (RDNA4), Ryzen 7700 iGPU (gfx1036, RDNA2) and WARP. 212 opcodes, 200 inputs each.

Finding Devices Status
Ordered v_cmp_*_{i64,u64} wrong when the operands share a dword AMD fixed in #1599
f16 results rounded toward zero by legacyF32ToF16 AMD #422 fixes it (0 differences with it)
fcmp false / fcmp true (v_cmp_f/tru_f{16,32}) remove the device WARP #1326 fixes it
Denormal inputs: AMD and WARP flush or keep them, and pick the sign of a flushed zero, differently. Affects v_min/max/min3/max3/med3_f32, v_cubesc/tc_f32, v_sin_f32 all open: the translation sets no fp32 denorm mode
v_fma_f32 / v_fmac_f32 are fused on AMD and not on WARP (1 ULP) known FMad shortcut (lower.rs)
v_cvt_f32_u32 misrounds, v_log_f32 is 20% off at 1 - 2^-24 WARP WARP's own; CI results can mislead

The full report and the per-opcode tables are in the gist: https://gist.github.com/alexdeliu/ef9ef0ebc1776ff104b5aa8eaea18e87

Later commits add VOP3P (v_pk_*, v_fma_mix*) and modifier variants (VICTORY_FUZZ_MODS=1): #422 also fixes the packed f16 ops and v_fmac_f16/v_fma_f16 on AMD.

Checks

  • Both CI clippy runs are clean.
  • The test is #[ignore]d, so cargo test --workspace is unchanged.
  • It is skipped where no SM 6.6 hardware device exists.

🤖 Generated with Claude Code

An ignored test runs every VOP3-encoded opcode the translator lowers as a
one-thread compute shader on each hardware adapter and on WARP, on the
same inputs (signed zeros, denormals, infinities, quiet and signalling
NaNs, integer and f16 edges, pseudo-random dwords), and reports where the
devices disagree: any NaN matches any NaN, approximate operations get a
few ULPs. A disagreement means the translation leans on behaviour DXIL
leaves to the device.

  cargo test -p victory-shader --lib fuzz_tests -- --ignored --nocapture

VICTORY_FUZZ_CASES, VICTORY_FUZZ_OPS and VICTORY_FUZZ_OUT set the inputs
per opcode, an opcode-name filter and a Markdown report.

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

@DenRakEiw DenRakEiw left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified locally merged onto origin/main (Windows 11 x64, Rust 1.98.1 MSVC):

  • cargo test -p victory-shader --lib emit::fuzz_tests:: — compiles cleanly and respects #[ignore]
  • cargo clippy -p victory-shader --all-targets — 0 warnings
  • cargo xtask policy — ok

Clean opt-in cross-device VALU fuzzer comparing hardware adapters against WARP. Looks good.

AI-assisted (Gemini 4 Neon).

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

Static review only: fuzz_tests is #[cfg(all(test, windows))] and every case is #[ignore]d (run via cargo test -p victory-shader --lib fuzz_tests -- --ignored), so nothing here executes on macOS (suite stays at 96). The harness design is sound — deterministic cross-device VALU fuzzing of hardware adapters vs WARP with per-case reporting is exactly what this codebase needs for the lowering churn. Two requests: (1) wire the --ignored run into the Windows CI leg (or document the exact command in the PR/README), since ignored tests rot quickly; (2) a note on how failures are minimized/reportered (shrinking to a minimal VALU case would make reports actionable).

The fuzzer also runs every VOP3P opcode the translator lowers
(v_pk_*, v_fma_mix*), comparing each f16 half on its own and the high
half of v_fma_mixhi_f16, with any NaN matching any NaN.

On main, v_pk_add_f16, v_pk_fma_f16 and v_fma_mix{lo,hi}_f16 differ on
AMD (f16 rounded toward zero by legacyF32ToF16); with Marvisak#422 the RX 9070,
a gfx1036 iGPU and WARP agree on all of them.

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

Review follow-up. Each finding lists its simplest disagreeing inputs
first (fewest non-zero dwords) and ends with the instruction words and
the v1..v4 inputs a regression test needs. With fewer than two devices
(CI's runners have WARP only) the test returns instead of failing. The
README names the command.

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

Copy link
Copy Markdown
Contributor Author

@catminou4 thanks, both done in f1125da, and @DenRakEiw thanks for the approval:

  1. Running it. The README now gives the command next to cargo test --workspace. I didn't wire it into CI: the fuzzer only learns something by comparing two devices, and CI's runners have WARP alone. With fewer than two SM 6.6 devices it now returns ("nothing to compare") instead of failing. The useful runs are the ones contributors make on their own GPUs. @DrDarkDK's RTX 4070 Ti + Ryzen iGPU run on Shaders: 64-bit integer compares on their dwords (AMD orders a shared-dword i64 compare wrong) #1599 is the model.
  2. Actionable reports. Every finding is one instruction with four input dwords, so there is little left to shrink. Rows are now sorted simplest first (fewest non-zero dwords), and each finding ends with the instruction words and inputs a regression test needs:
Repro: `build(&[0xd4e10014, 0x02020501, 0xd5010000, 0x00510280])` with v1..v4 = `[0x00000000, 0xffff8000, 0x83ff7bff, 0x1fbd4000]`.

- VICTORY_FUZZ_MODS=1 also runs each float VOP3 opcode with abs, neg,
  clamp and omod (seven combinations).
- v0 now starts as v4, so v_mac_*/v_fmac_*, which read their
  destination, no longer accumulate an undefined register. Their earlier
  signed-zero "differences" were that.
- A conversion's result type is the first one in its name
  (v_cvt_f32_f16 gives f32), and v_cvt_pkrtz_f16_f32 is compared half by
  half, so NaNs no longer count as differences there.
- The report shows v4 too.

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

tumbubu commented Nov 24, 2026

Copy link
Copy Markdown

A run on RDNA3 (RX 7900 XT): same findings as on the RX 9070 and gfx1036, nothing specific to RDNA3.

c3372c1, cargo test -p victory-shader --locked --lib fuzz_tests -- --ignored --nocapture --test-threads=1, default 160 inputs. RX 7900 XT, driver 32.0.31036.15, Windows 11 26300.

  • 234 opcodes compared, 31 differ, 112 refused, 4 lost a device. It took about 6 minutes.
  • The 31 opcodes that differ are the ones in your gist's 200-input run. The only one missing is v_med3_f16, at 2 of 200 there, which 160 inputs may not reach. Counts per opcode are in the same range: i64/u64 compares 57 to 110, v_cubetc_f32 32, v_sin_f32 54, v_pk_add_f16 11, and so on.
  • The 4 lost devices are WARP on v_cmp_f/tru_f{32,16} ("device instance has been suspended"), as in your table (Shaders: fold always-false and always-true compares to boolean constants #1326). The 7900 XT lost no device.
  • WARP's v_cvt_f32_u32(0xde84975e) = 0x4f5e8498 against 0x4f5e8497 on the 7900 XT: the same WARP misrounding you report. There is a second case: 0xeb8bc49b gives 0x4f6b8bc4 on WARP and 0x4f6b8bc5 on AMD.
  • v_cos_f32 at half a turn gives exactly -1.0 (0xbf800000) on the 7900 XT against 0xbf7ffff9 on WARP. That is WARP being inexact once more (FIND-5).

The full report is available if useful. AI-assisted (Claude Code); every run was on this machine.

…r fields

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

tumbubu commented Nov 24, 2026

Copy link
Copy Markdown

The new main on RDNA3: the same 17 disagreements as on the RX 9070 and gfx1036, and no lost device.

50cbc89 (this PR merged onto 70564ae), VICTORY_FUZZ_CASES=200. RX 7900 XT, driver 32.0.31036.15, against WARP.

So on all three AMD generations the f16 rounding, min/max/med3 and WARP device-loss findings are gone with 77053a0.

AI-assisted (Claude Code); every run was on this machine.

@DeerSilver

Copy link
Copy Markdown

Ran the fuzzer at 50cbc89 on a machine with two hardware adapters, so all three columns are filled. Setup: one laptop with an NVIDIA GeForce RTX 5060 Laptop GPU (Blackwell, 10de:2d59, driver 621.24) and an Intel UHD Graphics (Raptor Lake Xe-LP, 8086:a788, driver 32.0.101.7088), Windows 11 26300, Rust 1.98.1. The PR was merged onto main 70564ae.

  • cargo test --workspace --all-features --locked --no-fail-fast -- --test-threads=1 with the D3D12 debug layer on (VICTORY_D3D12_DEBUG=1, and a local, uncommitted change that also turns the debug layer on in victory-shader's test Host): 475 passed, 5 failed, 8 ignored (the fuzzer is the new ignored one). The 5 failures are the ones main 70564ae has by itself on NVIDIA (the view-heap cap and the structured-view stride, already reported in Test report: RTX 5070 (Blackwell), Windows 11, 70564ae: 471 passed, 5 failed, 7 ignored (4 from the 1,000,000 view heap cap) #1744); this PR adds none.
  • cargo clippy --workspace --all-targets --locked -- -D warnings, with and without --all-features: clean
  • cargo test --locked -p victory-shader --lib fuzz_tests -- --ignored --nocapture --test-threads=1 with VICTORY_FUZZ_OUT set and default settings (160 inputs) finished in 1583 s in a debug build. 243 opcodes compared on the RTX 5060 Laptop, the Intel UHD and WARP: 28 differ, 107 refused by the translator, 0 lost a device.

I also ran the earlier head, c3372c1, on ffe310e: 234 compared, 31 differ, 4 lost. The difference between the two runs shows what the main update changed. The v_min/max_f32, v_min3/max3_f32 and v_med3_f32 differences are gone. So are the 4 WARP device losses on v_cmp_f/tru_f32/f16. Everything below still differs on 70564ae. For each opcode the table names the odd device out, counted over the rows the report shows:

Odd one out Opcodes What it looks like
Intel UHD all 14 f16 compares (v_cmp_lt/eq/le/gt/lg/ge/nge/nlg/ngt/nle/neq/nlt_f16) subnormal halves compare as zero, e.g. v_cmp_le_f16(0x0001, 0x8001) is 1 on Intel, 0 on the RTX and WARP
Intel UHD v_cmp_o_f32, v_cmp_u_f32 inverted when an operand is NaN: v_cmp_o_f32(NaN, π) is 1 on Intel. This looks like the fcmp ord/uno fold that med3 had, and these two compares don't use the bit test
Intel UHD v_cvt_flr_i32_f32 (7), v_cvt_rpi_i32_f32 (14) new on 70564ae. A NaN input gives 0 on Intel and 0x7fffffff or 0x80000000 on the RTX and WARP. I haven't checked which one RDNA2 gives
Intel UHD v_mac_f32, v_mad_f32, v_fract_f32 (1–2 rows each)
RTX 5060 v_cubesc_f32, v_cubetc_f32 keeps subnormal results (0x80000001) that Intel and WARP flush to -0
all three differ v_sin_f16 (34), v_log_f32 (3) low bits on subnormal inputs (0x0003 / 0x0006 / 0x0006), precision
WARP v_sin_f32 (57), v_cos_f32, v_fmac_f32, v_fma_f32, v_cvt_f32_u32 precision, and f32 subnormals WARP keeps

I stopped the VICTORY_FUZZ_MODS=1 pass before it finished. I can attach either report (about 38 KB of synthetic inputs and results) if that helps.

No game data used. AI-assisted (Claude Code).

Marvisak commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Merge candidate. This adds an #[ignore]d test, emit/fuzz_tests.rs, that runs each lowered VOP3/VOP3P opcode as a one-thread compute shader on every hardware adapter and on WARP and reports where they disagree, plus a short README note. It is test-only, uses only the existing windows features and Host, holds ONE_AT_A_TIME, and writes a file only when VICTORY_FUZZ_OUT is set. Since the last review it has three changes. It merges main and fills in the new view_marks fields. agree now takes a result's type from the first type token in the opcode name, which is right for v_cvt_* and v_dot2_f32_f16 alike. hardware_adapters now also requires DedicatedVideoMemory > 0, as host.rs's hardware_adapter does.

Thanks for taking up the adapter nit; that point is resolved.

CI: passing (check).


Generated by Claude Code

alexdeliu and others added 2 commits November 25, 2026 06:49
…eir own

The lowering's Parts and HostShader gained view_marks (cd94d35). And as
host.rs's hardware_adapter (Marvisak#1911, Marvisak#1925), an adapter without dedicated
video memory (CI's basic render driver) is not a hardware column.

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

Copy link
Copy Markdown
Contributor Author

Merged main (940d32f) in as 170a6c8; 03593cb follows it. 03593cb adds view_marks (cd94d35) and takes up the triage nit: hardware_adapters now requires dedicated video memory as well as no software flag, like host.rs's hardware_adapter from #1911/#1925. On the RX 9070 + gfx1036 machine, both CI clippy runs are clean and cargo test --workspace --locked passes, except the 2 PSV0 tests main itself fails with the SDK's dxil.dll 1.7. A full fuzz of the new main is running; I'll post it if anything changed from the 17 known disagreements.

v_dot2_f32_f16 counted as an f16 result (its name has 16 and _f),
so two f32 NaNs with different payloads read as a disagreement. The
first type in the name (v_cvt_f16_f32, v_dot2_f32_f16) is the result's.
A full run on 940d32f (RX 9070, gfx1036, WARP) gives the same 17
disagreements as before.

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

Copy link
Copy Markdown
Contributor Author

The full fuzz of 940d32f on the RX 9070, gfx1036 and WARP (200 inputs per opcode) shows the same 17 disagreements as before. There are now 251 opcodes compared, up from 243 (8 more are lowered), and 0 lost devices. c147a18 fixes a fuzzer classification bug: an op like v_dot2_f32_f16 had its f32 result treated as f16 for NaN matching. The result type is now the first type in the name. It changes no finding here.

github-actions Bot pushed a commit to KevinPratap/VIctory that referenced this pull request Nov 25, 2026
v_cubeid/sc/tc/ma_f32 pick a coordinate (or its negation) as the
result, so a denormal coordinate came out as the host's: kept on AMD,
flushed to -0 on WARP, where the console's float mode reads it as a zero
of its sign. The coordinates now go through ftz first, as min and max's
operands do (77053a0).

A semantics probe runs the four over signed zeros, denormals,
infinities and NaN in each coordinate (14,440 inputs) against the RDNA2
model. Without the change: 2,193 model mismatches on an RX 9070, 1,276
on WARP, and the two disagree on 917.

Found by the cross-device fuzzer (Marvisak#1614).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ai2n-dev pushed a commit to ai2n-dev/VIctory-NVIDIA that referenced this pull request Nov 25, 2026
… ignored by default

Every VOP3/VOP3P opcode the translator lowers runs alone on every adapter
and on WARP, on special floats, integer and f16 edges and random dwords;
the test reports each opcode whose results differ, simplest inputs first,
with the words and inputs a regression test needs. Ignored by default
(minutes of GPU time); with one device it returns. A port of the fuzzer
of Marvisak/VIctory#1614.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
TheBiemGamer pushed a commit to TheBiemGamer/VIctory-Belobug-AMD that referenced this pull request Nov 25, 2026
… ignored by default

Every VOP3/VOP3P opcode the translator lowers runs alone on every adapter
and on WARP, on special floats, integer and f16 edges and random dwords;
the test reports each opcode whose results differ, simplest inputs first,
with the words and inputs a regression test needs. Ignored by default
(minutes of GPU time); with one device it returns. A port of the fuzzer
of Marvisak/VIctory#1614.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 25, 2026
Marvisak pushed a commit that referenced this pull request Nov 25, 2026
v_cubeid/sc/tc/ma_f32 pick a coordinate (or its negation) as the
result, so a denormal coordinate came out as the host's: kept on AMD,
flushed to -0 on WARP, where the console's float mode reads it as a zero
of its sign. The coordinates now go through ftz first, as min and max's
operands do (77053a0).

A semantics probe runs the four over signed zeros, denormals,
infinities and NaN in each coordinate (14,440 inputs) against the RDNA2
model. Without the change: 2,193 model mismatches on an RX 9070, 1,276
on WARP, and the two disagree on 917.

Found by the cross-device fuzzer (#1614).

Co-authored-by: alexdeliu <240865807+alexdeliu@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
@fuzeofficlal

Copy link
Copy Markdown
Contributor

Code review and triple-adapter (NVIDIA RTX 5090 + AMD Radeon iGPU + WARP) verification at head c147a1894e56 merged onto main (63bcca43c6a0; emit/lower.rs untouched):

  • Compile blocker after merging onto main (crates/victory-shader/src/emit/fuzz_tests.rs:716):
    • Git merges cleanly with zero text conflicts, but victory-shader fails to compile on main (63bcca43):
      error: cannot construct 'emit::host::Host' with struct literal syntax due to private fields
    • Host now has a private warp: bool field (emit/host.rs:17-20, 194-197); changing Ok(Host { device }) at fuzz_tests.rs:716 to Ok(Host::from_device(device)) fixes compilation and clippy cleanly with 0 warnings.
  • Two non-blocking agree() edge notes (fuzz_tests.rs:376-391):
    1. Line 376 let float = name.contains("_f") || ... matches integer-destination conversions like v_cvt_i32_f32/v_cvt_u32_f32, which would let integer results > 0x7F80_0000 (e.g. i32::MAX) pass as is_f32_nan; checking the destination type (first type suffix) avoids false matches.
    2. Lines 385-391 (approximate f16 path) compare only a & 0xFFFF / b & 0xFFFF without verifying the preserved upper half a >> 16 == b >> 16 (unlike line 380's NaN branch), and 0x7BFF vs 0x7C00 (+inf) are 1 bit apart.
  • Triple-adapter live run (with only line 716 locally changed to Host::from_device(device)):
    • cargo xtask policy: 192 files ok; cargo clippy --locked -p victory-shader --tests -- -D warnings: 0 warnings
    • VICTORY_FUZZ_OPS=v_add_f32,v_rcp_f32,v_pk_add_f16,v_bfe_u32 VICTORY_FUZZ_CASES=32 VICTORY_FUZZ_MODS=1 cargo test --locked -p victory-shader --lib fuzz_tests -- --ignored --nocapture (with dxil.dll 10.0.26100.0):
      Passed across NVIDIA GeForce RTX 5090 + AMD Radeon Graphics + WARP (18 opcodes compared, 32 inputs each; 0 differ; 0 refused by the translator; 0 lost a device, 51.07s).

Updating line 716 to Host::from_device(device) will make this build cleanly on main.

github-actions Bot pushed a commit to KevinPratap/VIctory that referenced this pull request Nov 26, 2026
What was wrong: the `neg` source modifier was lowered as `-0.0 - x`.
IEEE 754 leaves the sign of a NaN out of a subtraction to the host, and
WARP keeps it: a negated NaN reached the instruction with the sign it
had. The console's modifier flips bit 31 alone, NaN or not. The floor
conversions show it, as they saturate a NaN by its sign:
`v_cvt_rpi_i32_f32 -v1` and `v_cvt_flr_i32_f32 -v1` of 0x7fc00000 gave
0x7fffffff on WARP, 0x80000000 on an RX 7900 XTX (RDNA3) and the model.
Found by the VALU fuzzer of Marvisak#1614 with VICTORY_FUZZ_MODS=1 (20 and 9 of
200 inputs differed, all NaNs).

`neg` is now an integer XOR of the sign bit (`fneg`), the same on every
host, for f32 sources, v_fma_mix sources, f16 sources read as f32 and
packed f16 sources. The 16-bit and select paths already flipped the bit.

New test: source_modifiers_set_the_sign_of_a_nan checks both floor
conversions with abs, neg and -|x| against the model on the hardware
adapter and WARP; without the fix it fails on WARP only.

Checked on Windows 11, RX 7900 XTX (driver 32.0.32029.2010) and WARP:
cargo test --workspace --locked passes (780), both CI clippy runs are
clean, and the fuzzer with modifiers on the four float-to-integer
conversions shows 0 of 400 inputs differing.

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

Copy link
Copy Markdown

RDNA1 run on current main — RX 5700 XT (Navi 10), driver 32.0.21045.29003, Windows 11 26200; main 63bcca4 with this PR merged locally.

Build note: on current main fuzz_tests.rs:716 no longer compiles (Host has a private warp field); Ok(Host::from_device(device)) fixes it.

251 opcodes × 160 inputs: 4 differ, 99 refused, 0 device losses. All four are transcendental:

  • v_log_f32 (1/160): log2(1 − 2⁻²⁴), RX 5700 XT 0xb3b8aa3c is right, WARP 0xb3e00000 is ~21 % off (FIND-5).
  • v_cos_f32 (4/160): near 0.5/1 revolution the RX 5700 XT gives the correctly rounded ±1.0, WARP is 7 ULP off.
  • v_sin_f16 (12/160): on the rows checked the RX 5700 XT is right and WARP is ~10 f16 ULP off.
  • v_sin_f32 (54/160): mixed. On small inputs the RX 5700 XT is ~6–7 ULP low (sin(2π·2⁻¹²⁶): 0x01c90fd5, exact 0x01c90fdb); on others WARP flushes to 0 or is percent-level off.

None of the findings in the PR description (i64 shared-dword compares, f16 rounding, denormals) show up on RDNA1 at current main.

AI use: Claude Code (Claude Opus 5.5).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants