Commit Graph

7 Commits

Author SHA1 Message Date
f698bf2206 tools: a path outside the console's code page no longer crashes a tool's output
On Windows a redirected stdout uses the console's ANSI code page, and python -I ignores PYTHONUTF8 and
PYTHONIOENCODING, so a caller path with a character outside that code page ended a run with
UnicodeEncodeError as soon as a tool printed it. #1406 fixed make_game.py; every CLI tool in tools/ now starts
its __main__ block the same way (stdout errors="replace").

tests/test_tool_stdout_encoding.py checks every tool's __main__ block and reruns two measured crashes
(analyze_4240_full.py, meshlet_page.py) with a private-use-named input. Found by @abilliontokens.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 11:27:00 +00:00
ac844cb2f2 Merge pull request #1094 from bbareth 2026-11-22 02:09:04 -05:00
6678bab00d cpu_ref.py: a malformed --sgpr or --vgpr is a usage error, not a traceback
main() split each --sgpr/--vgpr assignment with item.split("=", 1) and
int(), so "--sgpr 3" (no "=") or "--sgpr 3=x" ended in ValueError. The
assignments are now parsed right after argparse, before the listing is run;
a bad one is one line naming the option and its N=VALUE form, exit 2.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 07:53:06 +01:00
7d05488f85 cpu_ref: an integer inline constant in a float source is its bit pattern
llvm-mc prints AMD float inline constants with a decimal point (2.0, -1.0);
a bare integer token (0..64, -16..-1) is an integer inline constant, and a
float instruction uses its 32 bits as they are. LLVM's AMDGPU operand
syntax page gives v_add_f32 v0, -1, 0 as src0 = 0xFFFFFFFF (NaN).
_float_src turned those integers into the float of the same value, so
v_mul_f32 v1, -1, v0 gave -2.0 where rdna2spirv.py (raw bits) gives a NaN,
and shader_diff.py would report that as a translator mismatch.

test_float_add_sub_mul asserted the old reading for v_add_f32 v5, v1, 2;
it now expects 2.0 (2.0 plus the denormal 0x2). A new test checks -1 and 1
in float sources.
2026-11-22 10:53:15 +05:30
e166d2eb34 fix(fuzz): v_perm_b32 selectors 9/11 read bit 31, not bit 23
The oracle took bit 23 as the sign bit for selector bytes 9 and 11.
The ISA takes bit 7 of bytes 1/3 of each source: bits 15/31 of src1 and
47/63 of src0, so the second sign bit of each source is bit 31. The
translated SPIR-V was already right; this was a false mismatch in the
oracle, found by @kotorvr reviewing #325.

Adds a pinned test with both sign-bit patterns, and makes half of the
generated v_perm cases use a pinned selector built from bytes 0..15 so
the sign-bit, 0x00 and 0xff ranges are exercised instead of depending
on the seeded scratch values.

Verified: 29 cpu_ref tests, 6 shader_diff tests, 440 semantic tests,
and 3000 seeded programs with 0 mismatches and 0 skips.
2026-11-22 00:31:28 +01:00
10d6d4b876 test(fuzz): differential coverage for the integer and bit VALU family
FUZZ-1: model the integer/bit VALU block in tools/cpu_ref.py and add
those ops to the shader_diff program table: v_add_nc_u32, v_sub_nc_u32,
v_subrev_nc_u32, v_mul_u32_u24, v_mul_i32_i24, v_mul_lo_u32,
v_mul_hi_u32/i32, v_mad_u32_u24/i32_i24, v_min_u32/u32, v_max_i32/u32,
v_bfe_u32/i32, v_bfi_b32, v_alignbit_b32, v_alignbyte_b32, v_perm_b32
and v_med3_i32/u32.

Pinned known-answer tests cover the boundaries: bfe width cut and zero,
perm selector ranges (bytes, sign bits, constants), align shift 0 and
24, signed mul_hi, 24-bit sign extension and mad wraparound.

The generator keeps integer ops away from registers last written by a
float op: Vulkan does not promise a NaN payload and the comparison
accepts both-NaN, so reusing those bits as an integer would compare an
unobservable payload. Unobservable as a float, not as an integer.

Verified CPU-only: 28 cpu_ref tests, 6 shader_diff tests, 423 semantic
tests, and 8000 seeded programs (8 seeds x 1000) with 0 mismatches and
0 skips. GPU confirmation on the 5090 is pending.
2026-11-21 23:57:59 +01:00
d9db324af6 Docs+tool: add CPU reference for differential shader validation
Add docs/shader_validation.md describing why spirv-val is not enough, the CPU/GPU differential model, test-program construction with llvm-mc, the harness design, coverage plan, limits, and prior art.

Add tools/cpu_ref.py, a standard-library interpreter for a small straight-line RDNA2 subset from a shader_ir listing. It models SGPR/VGPR state, VCC/EXEC/SCC, one or 64 lanes, inline constants and literals, exact f32 FMA and the requested integer/float ops. Anything outside the subset raises Unsupported.

Add tests/test_cpu_ref.py with hand-written listings pinning NaN, signed zero, denormals, FMA single rounding, cndmask, EXEC masking, 16-bit packed halves and shifts.
2026-11-21 18:09:38 +00:00