Commit Graph

19 Commits

Author SHA1 Message Date
4add048803 Merge pull request #1516 from milk4sale/tests/mutations-one-copy
tests: test_mutations copies tools/ once and runs only the test each mutation must break (TEST-MUTATIONS-COST)
2026-12-01 16:16:31 +01:00
660872215a Merge branch 'main' of https://github.com/ProjectLeonida/mandy into test/round10
# Conflicts:
#	make_game.py
#	runtime/README.md
#	tools/shader_meta.py
2026-11-28 16:35:38 -05:00
73fdc2a4c6 rdna2spirv: enable FTZ32/fmulz and per-load NonWritable SMEM with outlined slow paths
Enable DenormFlushToZero 32 alongside DenormPreserve 16 (with --no-ftz32
override and fmulz fusion), add sound per-load NonWritable scalar memory
analysis for descriptor/read-only SMEM loads, and outline wide s_buffer_load
partial-OOB slow paths into shared helper functions.

AI-assisted: Antigravity (Gemini 4 Neon).
2026-11-27 21:13:24 -05:00
2382568082 rdna2spirv: sign-extend an SDWA source with shifts, not OpBitFieldSExtract (SHADER-SDWA-SEXT-SHIFTS)
On an RTX 4050 Laptop (NVIDIA 621.01) a sext() SDWA source feeding
v_cvt_f32_u32 was converted as signed: v1 = 0x4fbdc08a with src0_sel:BYTE_2
gave -67.0 where the reference model has 0x4f800000. 7 of 400
v_cvt_f32_u32 programs differed; with two shifts (left, then arithmetic
right) the same 400 match, and so do the 4,500 programs of three full
sdwa_diff seeds except one unrelated f16 compare. The bits are the same
as before; the CPU interpreter agrees with the model either way.

Adds tests/semantic/test_sdwa_sext_source.py (every selector, nine values,
no OpBitFieldSExtract in the output), moves the two test_mutations anchors
that named the changed lines, and records the finding in the SDWA row of
docs/design.md.
2026-11-25 12:14:14 -03:00
a94c7e0c4d tests: test_mutations copies tools/ once and runs only the test each mutation must break (TEST-MUTATIONS-COST)
test_mutations.py is the last file still running in every semantic-tests (windows-latest) run measured for #1462,
250-381 s there against 33-46 s on the Linux leg of the same runs, while the rest of the suite took 0.76-1.61 times
as long on Windows as on Linux. For each of its 14 runs of test_ps_semantics.py (the baseline and 13 mutations) it
copied tools/ (about 330 files) into a new temporary folder, deleted it afterwards, and ran the whole file.

test_each_mutation_is_caught now makes one copy for all 13 mutations: each starts from the original translator and
writes it back in a finally, so 14 copies become 2. Each mutation runs only the test it must break
(test_ps_semantics.TranslatorSemantics.<test>), so its child translates one shader instead of six. failed_tests
counts only failures reported for TranslatorSemantics: a name the class does not have fails too, as
"ERROR: test_x (unittest.loader._FailedTest.test_x)", and with one test per run the old pattern would have counted
a misspelled expected test as caught.

What the file checks is unchanged: the whole of test_ps_semantics.py passes on an unmutated copy, each anchor
matches exactly once, each mutation makes its test fail, the CRLF anchor test is untouched and the repository's
tools/ is never written. The children keep PYTHONDONTWRITEBYTECODE=1, which now also keeps a .pyc of an earlier
mutant from being run for a later one of the same size written in the same second; a comment says so.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-24 21:01:23 -06:00
908a063f4a Merge pull request #4622 from Ivan
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

# Conflicts:
#	docs/design.md
2026-11-22 23:16:33 -05:00
06b47de1ed Fix what merging main into the round-43 branch broke
- rdna2spirv: %fmt_size_tab (main's typed-load size table) registers its length and entry constants when a load
  first uses it; created at assembly, %c128 came after the OpTypeArray naming it and spirv-val refused
  buffer_store_format_d16 modules (test_u16_high_half).
- test_vs_packed_inputs matches main's wording of the same SHADER-644 rule ("mixed component types").
- test_mutations: the v_mul_legacy_f32 anchor follows the SHADER-340 flushes (it had stopped matching on main).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 22:30:40 -05:00
a148559ba8 rdna2spirv: the packed 16-bit shifts read a half with a shift, not a field extract
docs/design.md already says a high 16-bit half is read with `>> 16` alone, with
no narrowing after it, because AMD's Windows LLPC miscompiles that combination
(#1506). The three packed 16-bit shifts were the exception: they took the shift
amount with `OpBitFieldUExtract(s0, 16, 4)` and the value with
`OpBitField{S,U}Extract(s1, 16, 16)`. An AMD Windows driver 25.10.36 on a
gfx1036 reads a field extract at offset 16 with the offset taken mod 16, so both
result halves got the low half of the source - 5 of 2000 wave32 programs of
`tools/valu_fuzz.py --family f16 --programs 2000 --seed 1` (@Darkz0rz, SHADER-777
in the coordination issue). The same 2000 programs match 2000/2000 on a second
gfx1036 (Radeon iGPU of a Ryzen 7 7800X3D, Windows driver 31.0.24002.92), and
the SPIR-V that run produced does contain those offset-16 extracts. So this is a
lowering that survives both drivers, not a value change: BitField{S,U}Extract(x,
16, 16) equals `x >> 16` with the matching right shift, and BitFieldUExtract(x,
16, 4) equals `(x >> 16) & 15`; checked over 200,010 inputs including 0, 1,
0xFFFF, 0x10000, 0x80000000, 0xFFFFFFFF, 0x7FFFFFFF and 0x8000. Extracts at
offset 0 are left as they were.

Coordinated as SHADER-784 in #4571, verifying SHADER-777. Counted over all 26 503
listings: 1 v_pk_lshlrev_b16 in 1 compute listing and 1 v_pk_lshrrev_b16 in another,
no v_pk_ashrrev_i16 and no
_sdwa form. Translating the corpus before and after with the same flags gives
26 503 translated and 26 473 valid in both, with 26 471 of the .spv identical
in size and SHA-256; the two that change are the two holding those instructions,
and their differences are only the replaced extracts. ps_ops4 and ps_ops6 pass
on that gfx1036 iGPU and on an NVIDIA RTX 4090 (driver 32.0.16.2124).
2026-11-23 04:21:02 +01:00
ec761c5ac0 tests/semantic: keep the mutation exact-once guard active under -O
apply_mutation() checked the exact-once invariant with a bare assert,
which python -O strips: with an anchor duplicated (e.g. a comment
quoting it) both occurrences were replaced and the mutation test
passed instead of failing loudly. Raise AssertionError directly so
the guard survives -O. Found by Desamodeth in review.
2026-11-22 21:02:42 +01:00
55e23b1486 tests/semantic: match mutation anchors on CRLF checkouts
A checkout made before .gitattributes pinned eol=lf (or a branch applied
through a CRLF-translating editor) stores tools/ with CRLF, so the four
multiline mutation anchors counted 0 and test_each_mutation_is_caught
stopped before any mutation ran. apply_mutation() normalizes both sides
to LF for the match and restores the file's line-ending style on write;
behavior on LF checkouts is byte-identical. A regression test covers the
CRLF path end to end. Found by @Ingenioeren.
2026-11-22 19:33:45 +01:00
4cb0e0d884 translator: reduce v_sin/v_cos in turns before scaling by 2*pi
RDNA takes the operand in turns and range-reduces in turns. Scaling by
2*pi first loses the fractional part for large inputs (up to 1e-4 at 255
turns) and leaves Sin outside [-pi, pi], where Vulkan does not guarantee
its precision. Add Gen.turn_angle: Fract, centre to [-0.5, 0.5), keep -0
as -0, then scale. Use it for both the f32 and f16 paths.

Adds semantic tests at 100.3 and 254.51 turns (old translation is 1.4e-5
off), f16 at 100 turns, and -0 sign preservation; the mutation anchor is
updated to the shared helper.
2026-11-22 10:36:36 +01:00
6f4bd2a9bb Merge remote-tracking branch 'origin/main' into shader-55-56
# Conflicts:
#	docs/design.md
#	tests/spirv_interp.py
#	tools/rdna2spirv.py
2026-11-22 02:22:31 +01:00
5c8cc4fade Part 3: f16 FMAs round once, to f16 (SHADER-55)
v_fma_f16, v_fmac_f16 and v_pk_fma_f16 used GLSL Fma (rounded to f32) and then narrowed, a double rounding;
an RX 6700 matches a correctly rounded f16 FMA in 12,612/12,612 cases (#374). fma_f16_odd: exact f32 product,
TwoSum, round-to-odd at f32, then f16_bits. Design row for f16 rounding.
2026-11-22 01:53:21 +01:00
3a83c29eae GPU tests for f16 op_sel and partial writes, hardware-measured; f16 inline constants fixed (SHADER-13)
Covers the "16-bit results" contract row, which ended with "not yet GPU-verified".

Hardware evidence: AMD RX 6800 (gfx1030), the instructions run as a raw compute kernel in wave32 and
wave64, IEEE off, DX10 clamp on, denormals kept, round to nearest. The bytes assemble identically for
gfx1013 and gfx1030 (llvm-mc 21; the kernels themselves were assembled by the driver's comgr).
- v_med3_f16: all 16 op_sel patterns, neg/abs on a selected high half, clamp, destination also a source.
- v_add/sub/mul/max/min_f16 (_e32, _e64 with neg/abs/clamp), v_fmac_f16 (_e32, _e64), f16 unary
  (rndne/floor/ceil/trunc/fract/sqrt/rcp/rsq, _e32 and _e64), v_cvt_f16_f32: low halves in, low half out,
  high half of the destination kept; the v_fmac_f16 accumulator is the low half of the destination.
  336 words per wave size, all as the rule says and as the translator computes.
- Not expressible: op_sel on the VOP2/VOP1 ops in VOP3 encoding (v_add/sub/mul/max/min_f16_e64,
  v_fmac_f16_e64, unary _e64). llvm-mc rejects the modifier and its disassembler drops the bits, so
  nothing was measured there and nothing was hand-encoded.

Translator fix (tools/rdna2spirv.py, new src_h): an inline float constant in an f16 operand is the f16
value in the low half over a zero high half. The translator unpacked the f32 pattern, whose low half is
zero, so v_add_f16 d, 1.0, v added 0.0 and v_cvt_f32_f16 d, 0.5 gave 0. Measured for v_add/mul/max_f16,
v_sub_f16_e64, v_fma_f16, v_fmac_f16, v_rcp_f16, v_med3_f16, v_cmp_lt_f16, v_cvt_f32_f16, v_cos_f16,
v_pk_add/mul_f16 and v_pack_b32_f16 (0.15915494 is 0x3118); the high half op_sel selects from a constant
reads +0.0. v_fma_mix* operands were not
measured and are unchanged.

Tests:
- runtime/test/shaders/ps_f16_{med3_opsel,med3_mods,vop2,vop2b,vop1,vop1b,const,const2,pack}.asm, wired into
  check.py and scripts/run_gpu_tests.py. Their expected words are the ones the hardware gave for the same
  instructions. Vulkan, AMD Radeon RX 6800, Windows, driver 26.11.2: 9/9 pass; with one expected word
  flipped per test 0/9 pass; without the translator fix ps_f16_const, ps_f16_const2 and ps_f16_pack fail.
- tests/test_f16_hw_words.py: header, check.py and run_gpu_tests.py hold the hardware words; a
  plain-Python reference of the rule and the translator (tests/spirv_interp.py) both give them. 12 of its
  tests fail without the fix.
- tests/semantic: ps_f16_vop2 fixture and value test; the v_sin_f16 mutation anchor follows the edit.
- tests/spirv_interp.py: Floor/Ceil/Trunc/RoundEven keep the sign of a zero result (trunc(-0.75) is
  0x8000 on the hardware and on Vulkan), Sin/Cos, component-wise vector arithmetic.
- python -m unittest discover -s tests/semantic: 388 -> 389, OK. pytest tests: 1467 -> 1514 passed.
  scripts/run_gpu_tests.py (test tools rebuilt): 48/49 -> 57/58 passed, 1 skipped.

docs/design.md: the "16-bit results" row says what was verified and what is not expressible; new row
"f16 inline constants".

AI-assisted.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-21 17:17:58 -07:00
eef6f14297 Translator: keep bitfield extracts inside 32 bits (v_bfe, s_bfe)
v_bfe_u32/v_bfe_i32 and s_bfe_u32/s_bfe_i32 passed offset and width straight to
OpBitFieldU/SExtract. SPIR-V leaves offset + count > 32 undefined, and that
happens for any field that runs past bit 31 (v_bfe: both are 5 bits; s_bfe: the
width is 7 bits). The width is now cut to 32 - offset, so the field stops at
bit 31: zero-filled for the unsigned extract, sign-filled for the signed one.
That is the value LLVM's constantFoldBFE (AMDGPUISelLowering.cpp) gives,
Src0 >> Offset.

test_alu_bfe.py: the i32 reference shifts arithmetically, the sweep no longer
skips offset + width > 32, and new tests cover such fields and s_bfe with
widths up to 127. test_mutations.py follows the renamed width operand.
2026-11-21 18:41:30 -03:00
8ea0e072dc tests: repair the stale stdin handle pytest's fd capture leaves on Windows; mutation test without cwd=HERE
On Windows `python -m pytest tests` fails at random places with
"OSError: [WinError 6] The handle is invalid" (subprocess.py, _make_inheritable).
pytest's default fd capture replaces fd 0 with os.dup2(), which closes the
handle fd 0 had, but the process's STD_INPUT_HANDLE keeps that number.
subprocess starts from GetStdHandle(), so a child that has its output captured
but is given no stdin=/input= (23 of the 25 call sites in tests/) gets a closed
handle, or, once the number has been reused, some unrelated file. Logged per
hook, the same number was a file, a pipe and invalid within one two-test
session. In conftest._has_amdgpu the OSError is caught, so a working llvm-mc
was reported as missing and all of test_translate.py skipped.

Fix in one place: when tests/conftest.py loads (before its llvm-mc probe) and
STD_INPUT_HANDLE is not fd 0's handle, point it at a NUL handle of our own.
Nothing happens on Linux, with -s or --capture=sys, or without pytest: there
the two handles are equal (checked for python -I <file>, python -m unittest
and unittest discover with console, NUL and pipe stdin), so the stdlib entry
points cannot hit this and need nothing. Per-call stdin=DEVNULL was the
alternative; the next new test would bring the failure back. A config file
forcing --capture=sys would change what is captured for everyone.
_has_amdgpu keeps catching OSError: a candidate that is not a program arrives
as a plain OSError (WinError 216), and it must be skipped, not crash collection.

Only stdin is repaired. STD_OUTPUT_HANDLE and STD_ERROR_HANDLE go stale the
same way, but fd 1 and fd 2 change handles for every test phase, and every
test that redirects a child's output redirects both streams, so subprocess
never reads those two. A test that redirects only one (stdout=PIPE alone,
check_output) would still fail under fd capture: use capture_output=True.

Separately, run_semantics() started its child with cwd=tests/semantic. Windows
refuses a working directory over 258 characters (WinError 267), so the mutation
tests failed in a checkout in a deep folder (measured with a 250-character
root, where tests/semantic is 265). The child now finds test_ps_semantics
through PYTHONPATH.

Tested on Windows 11, Python 3.14.7, pytest 9.2.0, main d51bddc:
- pytest tests, two runs each. Before: 6 and 44 failed without LLVM_MC, 94 and
  6 failed with it. After: 6 failed, 823 passed, 65 skipped without, and
  6 failed, 883 passed, 4 skipped, 1 xfailed with, both runs. The 6 are
  test_rtti_scan needing pefile, which is not installed here; the skip reasons
  are unchanged (ffmpeg, SCARAB_REF, llvm-mc).
- STD_INPUT_HANDLE forced to a number that is never valid, LLVM_MC set:
  44 failed and all 61 translator tests skipped before (the probe rejected
  llvm-mc), same as the clean run after. The unforced 94-failure run above has
  50 of them in conftest's Shader.validate (spirv-as).
- A copy with a 250-character root: test_mutations 14 failed before, passes after.
- Ubuntu (WSL), Python 3.14.4: unittest discover -s tests/semantic and the
  python -I tests/test_*.py loop print the same before and after.
No GPU involved. AI-assisted.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-21 13:27:44 -07:00
4f4189ef3e tests: follow #38 (f16 op_sel helpers) in the mutation/negative controls; test_shader_checks knows #73's wave64 dumps
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-21 14:09:15 -05:00
5f3007f393 tests/semantic: cover ps_ops2, ps_ops3, ps_ops4 and ps_legacy_mul (+ check.py) 2026-11-21 15:05:54 -03:00
695ae01d21 tests: value-level regression tests for RDNA2 -> SPIR-V pixel shaders
Add tests/semantic: translate two hand-written, branch-free pixel shaders
(ps_sdwa, ps_ops) and execute the resulting SPIR-V with a small strict
interpreter, asserting every mrt0 word against hand-derived expectations.
Catches wrong-value regressions (SDWA selects/sext, min3/max3, bfe_i32,
packed f16 FMA) that spirv-val cannot.

- Standard library only; no LLVM, SPIRV-Tools, GPU or game files.
- Interpreter rejects unmodelled constructs instead of approximating.
- Negative controls sabotage translated output; mutation tests sabotage a
  temporary copy of tools/ and require the matching test to fail.
- Fixtures are generated from runtime/test/shaders/*.asm.
- CI job semantic-tests (Windows + Ubuntu, Python 3.12), discovery limited
  to tests/semantic.
2026-11-21 18:27:51 +02:00