Work around an amdvlk64 pipeline-creation crash (0xC0000005 on RX 9070 XT)
triggered when GLSL.std.450 PackHalf2x16 on an OpImageSampleExplicitLod d16
result feeds a structured loop (OpLoopMerge inside OpSelectionMerge) using
OpGroupNonUniformAny.
Replace PackHalf2x16 at the two d16 image_gather4*/image_sample* sites in
tools/rdna2spirv.py with a branchless pure-integer IEEE-754 binary16 RTE
packer (Gen.f32_to_f16_int / Gen.pack_f16_pair_int). Leave all other
PackHalf2x16 call sites unchanged.
Add unit tests covering edge cases and a 58,368-value sweep across all 256
exponents (tests/test_d16_pack.py), SPIR-V translation/validation tests for
d16 image_sample and image_gather4 (tests/test_translate.py), and a synthetic
GPU sample shader (runtime/test/shaders/ps_texture_sample_d16.asm).
cs_cvt_f32_sat (#300) takes its binary32 input in s4, so neither runner
ran it. Now both do: one dispatch per input of
tests/semantic/test_float_to_int.py (check.CVT_F32_SAT_CASES), each
judged on both words (v_cvt_u32_f32 in out[0], v_cvt_i32_f32 in out[1]).
- check.cvt_f32_sat_test() and the run_gpu_tests.py branch report
"16/16 inputs exact", or how many were wrong and the first one.
- tests/test_shader_checks.py: the fake device answers from the word in
VKC_SGPRS; every input must be sent, one wrong input must fail and be
named, and the table must equal the interpreter test's CASES.
On NVIDIA this checks the fixed translation, but it cannot catch the old
bug: with the translator from before #300 (273e53c^1) the RTX 4060 Ti
also gives 16/16, since SPIR-V leaves an out-of-range conversion
undefined and this hardware saturates anyway. A driver that does not
(@EchoTD's RADV case on #300, constant inputs) is where it can fail;
tests/semantic/test_float_to_int.py pins the rule itself.
AI-assisted (Claude Code). Tested on NVIDIA GeForce RTX 4060 Ti (Ada,
subgroup 32), driver 32.0.16.2124, Windows 11, on main d937b7f:
run_gpu_tests.py cs_cvt_f32_sat "16/16 inputs exact" natively and with
LEONIDA_W64_EMULATE=1; check.py cs_cvt_f32_sat ok;
tests/test_shader_checks.py 18/18.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
vk_compute_test always put the output V# in s[0:3] and zero in every
other user SGPR, so a compute test shader could not be given an input
word: #300's cs_cvt_f32_sat reads its float from s4 and could only be
checked on a GPU by building one shader variant per input by hand.
- VKC_SGPRS=w4,w5,... sets s4, s5, ... up to s31 (s[0:3] stay the output
V#), with the same syntax and checks as vk_harness's VKH_SGPRS: decimal
or 0x hex, no sign, nothing above 32 bits, no trailing comma, at most
28 words; anything else exits 2 with a message.
- cs_user_sgprs.asm declares eight user SGPRs (RSRC2 0x8090) and stores
s4..s7 back. Both runners seed it with 0x4f000000,0xdeadbeef,7,
0xffffffff (check.USER_SGPRS) and expect those words, then the
0xEEEEEEEE fill.
- check.compute_test() takes an env for vk_compute_test.
- tests/test_shader_checks.py: the fake harness only answers
cs_user_sgprs with the seeded words when VKC_SGPRS was passed, and no
other test may get VKC_SGPRS.
AI-assisted (Claude Code). Tested on NVIDIA GeForce RTX 4060 Ti (Ada,
subgroup 32), driver 32.0.16.2124, Windows 11, on main d937b7f:
- run_gpu_tests.py cs_user_sgprs PASS natively and with
LEONIDA_W64_EMULATE=1; check.py cs_user_sgprs ok
- vk_compute_test directly: unset -> s4..s7 read 0; "5" sets s4 only;
28 words accepted; "1,2,", "-1", "0x1ffffffff", "abc" and 29 words
exit 2
- test_shader_checks.py fails (7) if check.py stops passing VKC_SGPRS
- full suite: see the PR
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
spirv_mini_interp.py: keep main's _F32 (sNaN bits, #533) and its vector-aware
RoundEven/Floor/Ceil/Trunc; keep this branch's fma_f32, OpFDiv and
Exp2/Log2/Sqrt/InverseSqrt. regen_fixtures.py: both sides' shaders.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
cs_wqm_w32 (SHADER-34) and cs_w32_lane_wrap (SHADER-52) check 32-lane
EXEC/VCC masks and lane selects. On Mesa llvmpipe, whose compute
subgroups are 8 wide, they can't produce their words, and the
"GPU tests on llvmpipe" step in runtime.yml has failed on main since
91b36cf. Skip them where vk_compute_test reports a widest subgroup
below 32 lanes, the rule ps_bitmask_perm already uses, in check.py and
run_gpu_tests.py (which reuses check.py's helper). Devices with 32 or
more lanes still run and judge them.
AI-assisted.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01D7JEiKsTUaHQbCTdc4Eghy
(cherry picked from commit be466779a2a1e988f58803ab1eedca6cc6a07375)
VGPR[D + M0[25:16]] = VGPR[S0 + M0[9:0]] (RDNA2 ISA VOP1 opcode 72; same
fields in the RDNA3 ISA). It raised Unsupported before (noted in #496).
- tools/rdna2spirv.py: masks M0 per side on the existing movrel path.
- tests/semantic/test_alu_movrelsd_2.py: 7 hand-computed cases through the
translator and the interpreter, including ignored M0 bits set, the _e32
spelling and a check that it differs from v_movrelsd_b32.
- runtime/test/shaders/cs_movrelsd_2.asm: GPU test (wave32 dump) with the
ISA's own example; registered in check.py and run_gpu_tests.py.
- docs/design.md: contract row for the v_movrel* forms.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
check_uniform_branch (ps_uniform_branch, ps_scc_mask32) only asked for some
s5 = 8 and some s5 = 7, so a translator that decides the branch per lane
passed too. Like check.py, it now also needs a pixel whose own bit is 0 but
got 8 (the wave-wide vote). Reported by @Vonsek in #477: the parent 4abd545
gave 0 such pixels and still passed the runner.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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>
v_add_f64 is VOP3Inst<"v_add_f64", VOP3_Profile<VOP_F64_F64_F64>> in LLVM
AMDGPU; VOPProfile gives it HasClamp (f64 is a modifier type) and HasOMod
(floating-point destination). The translator dropped both. The double sum
is now scaled by mul:2/mul:4/div:2, then clamped to [0, 1] (FClamp, as the
f32 clamp_mods does), before it is split into the register pair.
- tests/test_f64_output_modifiers.py: SPIR-V data-flow check per modifier
combination, plus NoContraction on the f64 add/scale.
- runtime/test/shaders/ps_f64_mods.asm: GPU test (registered in check.py,
run_gpu_tests.py and regen_fixtures.py). vk_harness enables shaderFloat64
when the fragment shader declares Float64, else exits 77 (SKIP).
- docs/design.md: contract row with the LLVM profile names.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
RDNA2 uses S1[4:0] in wave32 and S1[5:0] in wave64. Always ANDing with 63
left selects 32..63 pointing past a 32-wide subgroup. Fixture cs_w32_lane_wrap
checks lane 40 wraps to 8 on an RTX 5060.
Keep both sides in docs/design.md (contract rows), regen_fixtures.py
(ps_f32_mods + ps_fma_literal), spirv_mini_interp.py (our OpFDiv,
Floor/Ceil/Trunc, Exp2/Log2/Sqrt/InverseSqrt and RoundEven sign fix;
upstream's OpIsNan/OpIsInf, OpConvertUToF/SToF and FMax/FClamp) and
rdna2spirv.py (upstream fmamk/fmaak fix; v_mac_f32 stays with v_mad_f32).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
tools/cf_diff.py generates seeded wave32/wave64 pixel shaders from the
control-flow shapes compilers emit (saveexec if/else, v_cmpx, VCC- and
SCC-voted branches, uniform and per-lane loops, two-entry cycles) and
compares every lane's export between:
* tools/cf_ref.py: cpu_ref's Machine plus branches, compares, v_cmpx,
saveexec and 64-bit masks (the ISA model, one wave)
* rdna2spirv + tests/semantic/spirv_wave_interp.py: every invocation of
one subgroup in lockstep, split at selections and rejoined at merges,
with the subgroup operations the translator emits
in both the structured and the dispatch-loop form; --spirv-val also
validates each module, --minimize reduces a mismatch.
Finding (fixed here): in a wave32 program s_and/or/xor/andn2/orn2/nand/
nor/xnor_b32 on lane masks set SCC from the lane's own bit instead of the
whole mask, so `s_and_b32 s0, vcc_lo, exec_lo; s_cbranch_scc0` and loops
closed by `s_andn2_b32 exec_lo, ...; s_cbranch_scc1` split the wave. SCC
is now the same subgroup vote as for the _b64 forms. GPU test
ps_scc_mask32 (not run on a GPU yet).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Each process added its output hash to `hashes` before a later process of
the same configuration could fail. The failed configuration got no row,
but its partial hashes stayed, so the "every configuration ran" check
passed, it was compared as if it had run, and the script could print
"emulated output equals the reference" and exit 0. A reference that
failed after its first process was used as the reference all the same.
Hashes are now kept only for a configuration whose every process ran.
The test replaces the builds and the GPU runs with stubs.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
SHADER-14. runtime/test/shaders/ps_texoff.asm samples vk_texture_test's 8x8
texture (every texel different, point sampler, clamp to edge) through the
translated shader and exports the texel coordinates it read as integers:
- image_sample_lz_o with an offset computed per pixel: all 64 pairs of x, y
in -4..3 from the centre of texel (4, 4), each a different texel, none
clamped;
- image_sample_l_o with (-3, +2) and image_sample_lz_o with (+16, -32), the
offset dword loaded from an immediate. The second one tells 4-bit, 5-bit
and 6-bit fields apart; it is outside Vulkan's guaranteed -8..7 and is
judged only where the device's texel offset limits cover it;
- image_gather4_lz_o of red and of green with the per-pixel offset, at a
texel corner (shaderImageGatherExtended, not maintenance8).
Expected words are derived by hand from the docs/design.md rule (signed
6-bit fields, x [5:0], y [13:8]) and the texture contents, before any run;
the derivation is in the .asm header and check.py's texoff_words().
Harness: vk_texture_test enables VK_KHR_maintenance8 and
shaderImageGatherExtended when the device has them, prints the texel offset
limits, and with VKT_NEED_MAINTENANCE8=1 exits 77 without the extension
(SKIP in check.py and scripts/run_gpu_tests.py).
vk_harness.cpp is unchanged: its maintenance8 guard (#if defined() on the
structure-type enumerator, never true) was already fixed upstream, which now
uses #ifdef VK_KHR_MAINTENANCE_8_EXTENSION_NAME.
tests/conftest.py: the sample validator retries with
--allow-offset-texture-operand (what rdna2spirv.py validates with) when
spirv-val rejects a non-gather Offset, and skips on a spirv-val that does not
know the flag.
Tested on an AMD Radeon RX 6800, Windows, driver 26.11.2 (texel offset limits
-64..63, gather -32..31, maintenance8 enabled):
run_gpu_tests.py: 49/50 passed, 1 skipped (was 48/49, 1 skipped)
PASS ps_texoff 4096/4096 pixels exact (offsets +16/-32 judged)
check.py: 45 of 45 pass, 0 skipped (was 44 of 44)
No translator bug found: tools/rdna2spirv.py is unchanged.
Negative controls (translator sabotaged, test run, reverted). FAIL: sample
offset dropped, x/y swapped, y field at bit 6, 4-bit fields, 5-bit fields;
gather offset dropped, x/y swapped, y field at bit 6; three corrupted
expectations. PASS, so not detected on this GPU:
- fields read unsigned (sample and gather): Offset 60..63 sampled as -4..-1
and +32 as -32, so the sign extension cannot be seen through Vulkan here;
- 4-bit and 5-bit gather fields: the gather offsets stay in -4..3.
Both are pinned by the new structural test tests/test_texel_offsets.py
instead (signed, bit 8k, 6 bits; it fails with OpBitFieldUExtract).
The test shows that the translated SPIR-V implements the documented rule on
Vulkan; it does not measure the field layout on the hardware. Still not
GPU-tested: sign extension, gather field width, image_sample_o, _b_o,
_c_lz_o, image_gather4_l_o, the z field (3D), 1D/2D-array/cube targets, wrap
or mirror addressing, linear filtering, mips other than 0, other vendors'
drivers, devices without maintenance8.
unittest tests/semantic: 388 OK before and after.
pytest tests (LLVM_MC set): 1467 passed, 6 skipped, 1 xfailed before;
1478 passed, 6 skipped, 1 xfailed after.
AI-assisted.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Reports were named after the image's stem, so game.exe + game.dll, or a/x.exe +
b/x.exe, in one call wrote the same <out>/<stem>.json/.md and the last one won,
with exit 0. Reports are now named after the full file name (game.exe.json,
game.dll.md); a second image with the same file name from another directory
gets a numbered suffix (x.exe-2.json), compared case-insensitively, and the
name used is printed to stderr. The same path given twice is inspected once.
scripts/first_look.ps1, the only consumer of the report name, reads
<exe file name>.json. Tests cover the exe/dll pair and the two-directory case.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Unpacking the full GFX10 address as half pairs reads sample coordinates from derivative words. Decode the full-width gradient prefix before the packed coordinates and check the resulting image against a synthetic RGBA gradient.
global_mem read the instruction offset with int(..., 0) and then did
"if inst & 0x800: inst -= 0x1000". llvm-mc prints the 12-bit field signed
(offset:-4 for 0xffc, range -2048..2047; it rejects offset:0xffc and
disassembles 0xffc back as offset:-4), so -4 & 0x800 was true and every
negative offset became base - 4096 + offset. Both repo paths (shader_disasm
--disassemble, build.py -show-encoding) deliver only the signed spelling. The
offset is now taken as written; a raw unsigned field (0x800..0xfff), which
llvm-mc never prints, still means the same negative offset, and anything
outside 12 bits raises Unsupported instead of being guessed.
Hardware (AMD Radeon RX 6800, gfx1030, raw compute kernel, wave32 = wave64):
dword at byte n = 0x10000000+n, pointer 0x1000: offset 0 reads 0x10001000,
-4 0x10000ffc, -2048 0x10000800, 2044 0x100017fc, -1024 0x10000c00.
Audit of the other offset / signed-immediate sites in rdna2spirv.py (widths
checked by assembling and disassembling with llvm-mc 21): MUBUF offset:
(12-bit unsigned; llvm-mc assembles a hand-written offset:4096 to field 0 while
echoing offset:4096, reachable only from hand-written sources, left alone),
DS offset: (16-bit unsigned), offset0/offset1 (8-bit
unsigned), ds_bpermute offset (16-bit unsigned), s_movk/s_addk/s_mulk and
s_cmpk_*_i32 (16-bit, masked then sign-extended, so 0xfffc and -4 agree),
s_cmpk_*_u32 (zero-extended), branch targets (16-bit signed, disassembled
unsigned as 65532, masked then sign-extended): all right. Not changed here:
scalar_load zero-extends a negative SMEM immediate (21-bit signed; -0x4 adds
0xfffffffc), which another branch is changing.
Tests: tests/semantic/test_global_mem_offset.py runs the emitted address
code (both addressing modes, dword/x2/x4, ubyte/sbyte/ushort/sshort, stores,
offsets -4, -2048, 2047 and 0, raw-field and out-of-range spellings): the negative-offset
cases fail on main's translator (0 and 2047 pass there too), all pass here. New GPU test
runtime/test/shaders/cs_global_neg_offset.asm (wired into check.py and
scripts/run_gpu_tests.py), expected words derived from its seeds. On AMD
Radeon RX 6800 / Windows / driver 26.11.2: run_gpu_tests 57/57, check.py
51 of 51; with main's translator the new test returns the 4096-lower seeds
and fails.
AI-assisted.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>