diff --git a/docs/design.md b/docs/design.md index 7b7797ae67..df6f0c8e6b 100644 --- a/docs/design.md +++ b/docs/design.md @@ -495,7 +495,7 @@ How the generated SPIR-V expects the runtime to work: | Denormal flush in `v_mad_f32`, `v_mac_f32`, `v_mad_legacy_f32` (SHADER-118) | The three have no f32 denormal support: a subnormal operand, the rounded product or the result reads as signed zero, whatever the MODE register says. `Gen.flush_f32` emits ` \| x \| < FLT_MIN → copysign(0, x)` on the three operands, after the product rounding and (via `Gen.flush_f32_mods`) both before and after `omod`/`clamp`; inf and NaN compare false and pass through, and 0 keeps its sign. Source: LLVM AMDGPU `SIISelLowering.cpp`, `SITargetLowering::isFMADLegal` (llvm-project `1922c0c`), which forms `v_mad_f32`/`v_mac_f32` only when f32 denormals are flushed. Corpus count with `tools/shader_profile.py` over the 26,503 gfx1013 shaders: `v_mad_f32` in 7,298 shaders (139,287 occurrences), `v_mac_f32` in 5,889 (276,806: 265,901 `_e32`, 10,811 `_e64`, 94 `_dpp`), `v_mad_legacy_f32` in 6,059 (24,765); 9,297 shaders (35.1%) use at least one, 440,858 occurrences (0.99% of the corpus's 44,406,870 instructions). **Measured natively on RDNA1** (`AMD Radeon RX 5600 XT`, `gfx1010`, Windows driver `32.0.21045.29003`, `tools/mad_denorm_probe.py --oracle hw`, SHADER-340): 48 of 48 cases match in wave32 and wave64 across `game` (`IEEE=0`, `denorm32=0`), `dx10_clamp=0` and `denorm32=3` (`v_mul_f32(FLT_MIN, 0.5)` confirms `denorm32=3` keeps subnormals on the GPU while the mad/mac ops still flush them), and all 40 non-`omod` cases match under `IEEE=1` (where hardware ignores `mul:2`/`mul:4`/`div:2` as for other f32 VALU ops). Before SHADER-340 the translator ran `flush_f32` only after `clamp_mods`, which gave `FLT_MIN` (`0x00800000`) instead of `+0` (`0x00000000`) on `(1.5*2^-126 - 2^-126) mul:2` (and `0x01000000` on `mul:4`), whereas hardware flushes the sum before `omod` (`+0`) as well as after (`FLT_MIN div:2` → `+0`, `-FLT_MIN div:2` → `-0`). Checked on the CPU by `tests/semantic/test_valu_f32_min3_max3_mad.py` (`DenormalFlushTests`: the flush column, pre- and post-`omod` cases, NaN/inf/zero pass-through, and a sabotaged pass-through that fails) and `tests/test_mad_denorm_probe.py`. No RDNA2 part has these opcodes, and on gfx103x the encodings of `v_mad_legacy_f32` (VOP3 0x140) and `v_mac_legacy_f32` (VOP2 0x06) are the fused `v_fma_legacy_f32` / `v_fmac_legacy_f32`, so a raw-encoding run on a gfx1036 oracle would measure a different instruction (see the GFX10.1/GFX10.3 opcode row). | | 16-bit high-half reads (`Gen.u16_half` / `Gen.i16_half`, #1506) | Reading the high 16 bits of a 32-bit word emits `OpShiftRightLogical %uint u 16` (`u16_half`) or `OpShiftRightArithmetic %int (as_int(u)) 16` (`i16_half`) alone, without a trailing `OpBitwiseAnd ... 0xFFFF` or `OpBitFieldSExtract ... 0 16` (used for the low half only). On 32-bit inputs `>> 16` already zero- or sign-extends bits 31..16, and AMD's Windows LLPC compiler (measured on RDNA2, drivers 22.40.84.06 in #1506 and 24.10.24 on Ryzen 5 7600 iGPU) miscompiles both `(u >> 16) & 0xFFFF` and `OpBitFieldSExtract (u >> 16) 0 16` after two partial-half writes to `u` by dropping the `>> 16` when the result feeds `OpIAdd`, `OpIMul`, or `OpShiftLeftLogical` (e.g. `(0x41b1 << 1) & 0xFFFF` became `0x0000` instead of `0x8362` in `cs_f16fuzz_s2_163_w64`, `s_bitreplicate`'s `((0x41b1 << 8) \| 0x41b1) & 0x00ff00ff` became `0xb10000` instead of `0x4100b1`, and `SExtract(0x91b1138b >> 16, 0, 16) + 1` became `0x91b10001` instead of `0xffff91b2`). Applies across all 16-bit half readers (`v_*_b16`/`u16`/`i16`, `v_mad_{u,i}16`, `v_min3/max3/med3_{u,i}16`, `v_cvt_f16_{u,i}16`, `v_pack_b32_f16`, `v_frexp_*_f16`, `v_ldexp_f16`, `s_bitreplicate_b64_b32`, and `buffer_store_format_d16_*`). Checked by the unit tests in `tests/test_u16_high_half.py` and `tools/valu_fuzz.py --family f16 --seed 2 --programs 200 --wave both` on AMD Ryzen 5 7600 iGPU (driver 24.10.24: 400/400 native, up from 399/400; 200/200 wave64 emulated on both AMD and NVIDIA). **The packed 16-bit shifts follow the same rule** (`v_pk_lshlrev_b16`, `v_pk_lshrrev_b16`, `v_pk_ashrrev_i16`, since 2026-11-23): the shift amount comes from `OpShiftRightLogical %uint s0 16` then `& 15`, and the value from `OpShiftRight{Logical,Arithmetic} %uint s1 16`, where the code used `OpBitField{S,U}Extract … 16 16`. A field extract at offset 16 is what an AMD Windows driver 25.10.36 on a gfx1036 iGPU reads with the offset taken mod 16, so both result halves got the **low** half of the source: 5 of 2,000 `tools/valu_fuzz.py --family f16 --programs 2000 --seed 1 --wave 32` programs, all in wave32 and none in native wave64 (@Darkz0rz, reported in the coordination issue as SHADER-777). The same 2,000 programs match 2000/2000 on a second gfx1036 (Radeon iGPU of a Ryzen 7 7800X3D, driver 31.0.24002.92), where the field-extract form was already correct, and its SPIR-V does contain the offset-16 extracts, so the change is a lowering that survives both drivers, not a value change: `OpBitField{S,U}Extract(x, 16, 16)` equals `x >> 16` with the matching right shift and `OpBitFieldUExtract(x, 16, 4)` equals `(x >> 16) & 15`, checked for 200,010 inputs including 0, 1, 0xFFFF, 0x10000, 0x80000000, 0xFFFFFFFF, 0x7FFFFFFF and 0x8000. Counted over the 26,503 listings: 1 `v_pk_lshlrev_b16` in 1 compute listing (`op_sel_hi:[0,1]`) and 1 `v_pk_lshrrev_b16` in 1 other (`op_sel:[1,0] op_sel_hi:[0,0]`), no `v_pk_ashrrev_i16` and no `_sdwa` form; those two modules are the only ones whose output changes. Values are checked by the unit tests in `tests/test_pk16_diff.py` and the `ps_ops4` / `ps_ops6` fixtures. | | `v_mac_legacy_f32` | The GFX10.1 VOP2 form of `v_mad_legacy_f32` with D as the addend: D = legacy(S0 * S1) + D, where 0 times anything (inf and NaN included) is +0, with the same denormal flush and VOP3 modifiers. D is read before it is written, as for `v_mac_f32` (LLVM `VOP2Instructions.td`: `V_MAC_LEGACY_F32` has `$src2` tied to `$vdst`). Until 2026-11-22 it raised `Unsupported`. CPU-checked by `MacLegacyF32Tests` in `tests/semantic/test_valu_f32_min3_max3_mad.py` (a 15x8x6 grid against the `v_mad_legacy_f32` reference, the zero rule, clamp/neg, D aliased as a source). **Not GPU-verified**: like the other mad opcodes it exists on gfx1010-1013 only, so no RDNA2 desktop part runs it. | -| `v_cmp_*_f64`, `v_cmpx_*_f64` | All 16 binary64 vector compare predicates (`f`, `lt`, `eq`, `le`, `gt`, `lg`, `ge`, `o`, `u`, `nge`, `nlg`, `ngt`, `nle`, `neq`, `nlt`, `tru`) for both `v_cmp_` (VCC/SGPR lane mask) and `v_cmpx_` (EXEC narrowing), lowered in `Gen.compare_f64_cond` via pure 32-bit `%uint` IEEE-754 ordering (NaN detection, `-0.0` canonicalized to `+0.0`, sign-magnitude to monotonic unsigned 64-bit key) with no `Float64` capability required and no denormal flushing. Supports VGPR/SGPR pairs, `fimm`, sign-extended inline integers (`-16..64`), 32-bit upper-half literals, and VOP3 `abs`/`neg` sign-bit modifiers on both sources; inactive lanes write 0 for `v_cmp_*_f64` and stay inactive for `v_cmpx_*_f64`. Source: AMD RDNA2 ISA VOPC/VOP3 binary64 compares. CPU-checked by `tests/semantic/test_cmp_f64.py` (all 16 predicates across full IEEE-754 edge grid including subnormals/1-ULP pairs/±0/±inf/sNaN/qNaN, SGPR pairs, constants, `abs`/`neg`, `v_cmpx_*_f64`, inactive lanes, no `Float64` capability, bad-operand rejections). **Not GPU-verified.** Measured on native gfx1100 (single thread, 116 cases): all 16 predicates return IEEE-754 results (`eq` on `NaN` is 0 while `neq`/`nlt`/`nge`/`ngt` are 1, `lg` is 0 for `NaN` with `o`/`u` splitting on it, `eq(+0.0, -0.0)` is 1, `inf` compares equal to itself) and `v_cmpx_*_f64` narrows `EXEC` instead of writing `VCC`. | +| `v_cmp_*_f64`, `v_cmpx_*_f64` | All 16 binary64 vector compare predicates (`f`, `lt`, `eq`, `le`, `gt`, `lg`, `ge`, `o`, `u`, `nge`, `nlg`, `ngt`, `nle`, `neq`, `nlt`, `tru`) for both `v_cmp_` (VCC/SGPR lane mask) and `v_cmpx_` (EXEC narrowing), lowered in `Gen.compare_f64_cond` via pure 32-bit `%uint` IEEE-754 ordering (NaN detection, `-0.0` canonicalized to `+0.0`, sign-magnitude to monotonic unsigned 64-bit key) with no `Float64` capability required and no denormal flushing. Supports VGPR/SGPR pairs, `fimm`, sign-extended inline integers (`-16..64`), 32-bit upper-half literals, and VOP3 `abs`/`neg` sign-bit modifiers on both sources; inactive lanes write 0 for `v_cmp_*_f64` and stay inactive for `v_cmpx_*_f64`. Source: AMD RDNA2 ISA VOPC/VOP3 binary64 compares. CPU-checked by `tests/semantic/test_cmp_f64.py` (all 16 predicates across full IEEE-754 edge grid including subnormals/1-ULP pairs/±0/±inf/sNaN/qNaN, SGPR pairs, constants, `abs`/`neg`, `v_cmpx_*_f64`, inactive lanes, no `Float64` capability, bad-operand rejections). GPU-checked by `runtime/test/shaders/cs_w32_cmp_f64.asm`: all 16 predicates of both forms on 256 memory-fed pairs (the product of 16 values: ±inf, ±max, the 1-ULP neighbours of ±1, the smallest subnormals, ±0, the smallest normal, a NaN with its payload in the low dword only, a negative quiet NaN), `tru` with the odd threads off (an inactive lane gets VCC 0 and stays off through `v_cmpx_`), and `lt`/`nge` with `abs`/`neg`, all 1536 heap words exact on an RTX 4070 Ti (NVIDIA 620.70.06, Linux) and on llvmpipe (subgroup 8). That run checks the translated SPIR-V on a driver against IEEE-754, not RDNA2 itself; SGPR-pair and constant operands are not in it. Measured on native gfx1100 (single thread, 116 cases): all 16 predicates return IEEE-754 results (`eq` on `NaN` is 0 while `neq`/`nlt`/`nge`/`ngt` are 1, `lg` is 0 for `NaN` with `o`/`u` splitting on it, `eq(+0.0, -0.0)` is 1, `inf` compares equal to itself) and `v_cmpx_*_f64` narrows `EXEC` instead of writing `VCC`. | | Whole-quad mode (`s_wqm_b64` / `s_wqm_b32`) | A lane mask register holds only this lane's bit, so WQM on one (EXEC, VCC, an SGPR the mask analysis found) ORs the bit of the lane's quad, lanes 4n..4n+3 of the wave: two `OpGroupNonUniformQuadSwap` (horizontal, then vertical; capability `GroupNonUniformQuad`) in the default mode in fragment and compute shaders (quad operations are only guaranteed there; vertex, geometry and mesh shaders shuffle from the quad's four lanes), or the four lanes' values read through `%x_buf` under `--wave64-emulate` (no subgroup operation there). A quad never crosses lane 31/32, so the mask bits are exact per half on a 32-wide subgroup; SCC is a wave vote, so on wave64 it needs a 64-wide subgroup or `--wave64-emulate` (as every wave-wide mask op). The result goes to EXEC, VCC or an SGPR pair as a mask, SCC = the wave-wide any of it (same vote as the other mask ops). A 32-bit form in wave64 (`exec_lo`/`exec_hi`, `vcc_lo`/`vcc_hi`, a half-mask SGPR) writes only its own half (`exec_half_write`) and votes SCC over that half only (`cs_wqm_w64_half`). A source that is not a lane mask (a value loaded from memory, a literal) is data: `((x \| x>>1 \| x>>2 \| x>>3) & 0x11111111) * 15` per 32-bit word and SCC = result != 0, no subgroup operation. Assumptions: in compute and mesh shaders the subgroup lane is `LocalInvocationIndex` mod the subgroup size (as for every cross-lane op); a hardware quad is four consecutive lanes of a wave, and in a pixel shader Vulkan's quad (the 2x2 pixels, helper invocations included) is the same four lanes; GPU-checked on both AMD and NVIDIA with `ps_wqm.asm` (every 2x2 block of a 64x64 target, fully covered). **Helper lanes at a triangle edge, measured on RDNA2** (gfx1036, wave64, raw ISA through `tools/ps_oracle.py` on RADV; `tools/ps_helper_probe.py`, docs/shader_validation.md): a pixel wave's entry EXEC is exactly its covered pixels (helpers off); `s_wqm_b64 exec, exec` turns on exactly the quads with a covered pixel, which are packed from lane 0 (a quad with no covered pixel isn't in the wave); lane % 4 = (x & 1) + 2 (y & 1), so lanes 0-3 are top-left, top-right, bottom-left, bottom-right; a helper's `v_interp` gives its own pixel centre (extrapolated, as precisely as a covered pixel), and its v0/v1 hold its own I/J before `s_wqm` too; without `s_wqm` its VGPRs aren't written; an `exp ... vm` with helpers on in EXEC writes no pixel outside the triangle. Not covered: helper-invocation behaviour at triangle edges is untested, and in native mode an absent invocation in a partial quad (a compute group whose size is not a multiple of 4) gives an undefined value (emulated, the missing lanes of a partial wave read as 0). Before this the instruction was the identity, so helper lanes stayed off (#156 SHADER-34: `s_wqm_b64` appears in 4,285 pixel shaders). GPU-checked with `runtime/test/shaders/cs_wqm_w64.asm`, `cs_wqm_w64_half.asm`, `cs_wqm_w32.asm` and `ps_wqm.asm` on AMD Radeon 880M (subgroup 64) and NVIDIA GeForce RTX 5070 Laptop (subgroup 32; `cs_wqm_w64` there needs `LEONIDA_W64_EMULATE=1`), with and without `--wave64-emulate`. | | `buffer_atomic_{and,or,xor,swap}_x2` | `M = op(M, DATA)` on the 64-bit element at the MUBUF address (two dwords, low first); with `glc` the old 64 bits are returned in `vdata[0:1]`. A bitwise op or an exchange leaves the same memory done one dword at a time, so each dword is its own 32-bit `OpAtomic*` and no Int64 atomics are needed. **Approximation:** the returned pair comes from two reads, so another lane's 64-bit op on the same element between them can show up half done. Each dword is its own 32-bit `OpAtomic*`, so no Int64 atomics are needed; a bitwise op leaves the same memory that way, since its bits are independent. **Approximation:** an exchange can tear, since two lanes swapping into one element at once can leave one's low dword with the other's high dword (A.lo, B.lo, B.hi, A.hi), and the returned pair comes from two reads, so another lane's 64-bit op on the same element between them can show up half done. **Bounds:** the check covers the whole 8-byte element, all or nothing, as for a typed 32_32 element (`buffer_address(elem="fmt")`). An out-of-range or inactive lane leaves memory alone and returns 0, as `buffer_atomic` does. How hardware treats a 64-bit atomic that is only partly in range is **not measured**. Still `Unsupported`: `add/sub/min/max_x2` and `cmpswap_x2`. Until 2026-11-22 every `_x2` buffer atomic was rejected. CPU-checked by `tests/semantic/test_buffer_atomics_x2.py` (the four ops with and without `glc`, an element ending exactly at `num_records`, half and fully out of range, seeded values, rejected forms). **Not GPU-verified.** | | Wave64 graphics: partition invariance (SHADER-10) | A wave64 VS/PS/GS on a 32-wide subgroup is exact **iff its observable results do not change when the wave is cut into two 32-lane halves** (the host forms the subgroups of graphics stages, so there is no partner half to exchange with). `tools/wave64_halves.py` decides it from the code (forward taint dataflow over the basic blocks, plus control dependence on wave-wide votes) and the translator records it in `index.json` as `wave64_graphics` (`A`/`B`/`C`), `wave64_graphics_reasons` (tier C) and `wave64_graphics_idioms` (tier B). **A**: only per-lane arithmetic, votes that skip lane-masked work (`s_cbranch_execz/execnz`; `vccz/vccnz` whose run side starts by narrowing EXEC to that VCC and whose other side is the join, with no code of its own: a half that votes no runs that side, the wave does not; the same holds for `s_cbranch_execz/execnz`: the side that runs when EXEC is zero is taken by a half with no active lane, so it must be the join (or only jumps to it) or the exit of a loop the vote closes, else tier C `unsafe-execz-branch`; `s_cbranch_scc*` after a vote is the same kind of skip, any other reader of that SCC, `s_cselect`/`s_cmov`/`s_addc`, is tier C; a vote is on the mask register's value when it was taken, so a new value in that register before the branch (`v_cmp` into the pair or VCC, `s_mov_b64`, `s_cselect_b64`: none of them writes SCC) ends it, and the branch is judged as a plain SCC branch, SHADER-820), whole-quad masks, `ds_bpermute`/`ds_permute`/`v_permlane16`/`v_permlanex16`/`ds_swizzle` (they stay inside a half), a `ds_bpermute`/`ds_permute` address made from the lane id (`v_mbcnt_lo` then `v_mbcnt_hi` of -1) when it is the same modulo 128 bytes in the wave and in a half (the id is 0..63 there and 0..31 here, equal modulo 32 lanes; sums, differences and bitwise ops with invariant values keep that, a left shift by c multiplies the modulus by 2^c, and the permute uses address bits 2..6 of its half only: `(id ^ 1) << 2` is exact, `id << 1`, a right shift of the id or the low count alone stay tier C `lane-id`), loops closed by `execnz` with no scalar state carried, and the early exit of a pixel kill: `s_cbranch_scc0/scc1` (or `vccz/vccnz`) on a lane mask's own "not empty" (the last SCC writer is a 64-bit logic op into that mask, e.g. `s_andn2_b64 live, live, exec`, or `s_cmp_lg_u64 mask, 0`, and nothing rewrites the mask before the branch) to a block that only sets EXEC from that mask or 0 (`s_mov_b64 exec`, or `s_and_b64 exec` with it), may then export with that EXEC (an export is allowed, not required), and ends (no other code, store or successor), while the run side narrows EXEC into the mask's whole quads before anything but mask arithmetic (`s_mov_b64`, `s_and_b64`, `s_wqm_b64`) runs, the narrowing itself possibly an `s_and_saveexec_b64` / `s_andn2_saveexec_b64` (or `_wrexec_`) whose source is inside, and keeps it inside on every path from there, loops included (a must-dataflow: an EXEC write keeps it inside only when it is provably a subset: `v_cmpx`, `s_and_b64` with one operand known inside, `s_andn2_b64` / `s_andn2_saveexec_b64` whose first operand is, `s_and_saveexec_b64` while inside or from one that is, `s_andn1`/`s_or`/`s_xor_saveexec_b64` only while inside (the latter two also from one that is), and copies, `s_wqm_b64`, `s_or_b64` and `s_xor_b64` of operands known to be inside (0 counts as inside); a saveexec destination holds the old EXEC and a wrexec one the new, each inside only if that EXEC was), and no `exp ... vm` can run before the vote. A half whose mask is empty then writes nothing and discards its pixels in the exit, and in the wave its lanes are off to the end, so the wave discards them too; an exit shared by several kills reads a mask redefined behind the earlier votes and stays tier C. GPU-checked by `ps_w64_a_discard` (below). `s_cbranch_scc*` after a vote is the same kind of skip, any other reader of that SCC, `s_cselect`/`s_cmov`/`s_addc`, is tier C; a vote is on the mask register's value when it was taken, so a new value in that register before the branch (`v_cmp` into the pair or VCC, `s_mov_b64`, `s_cselect_b64`: none of them writes SCC) ends it, and the branch is judged as a plain SCC branch, SHADER-820), whole-quad masks, `ds_bpermute`/`v_permlane16` (they stay inside a half, not GPU-tested here: no fixture; `s_cbranch_scc*` after a vote is the same kind of skip, any other reader of that SCC, `s_cselect`/`s_cmov`/`s_addc`, is tier C), whole-quad masks, `ds_bpermute`/`v_permlane16` (they stay inside a half, not GPU-tested here: no fixture; `ds_swizzle` and `v_permlanex16` likewise; GPU-checked at required 64 and 32 lanes by `ps_w64_a_bpermute`, `ps_w64_a_permlane` (`v_permlane16` and `v_permlanex16`) and `ps_w64_a_swizzle` in `w64_graphics.py`, TEST-433), loops closed by `execnz` with no scalar state carried. `ds_swizzle` and `v_permlanex16` likewise), loops closed by `execnz` with no scalar state carried. A `vccz`/`vccnz` on a wave-uniform compare is no lane vote and is tier A too: a `v_cmp` made while EXEC is the launch mask from untainted immediates, scalars that are no lane mask and VGPRs written from them (optionally ANDed with EXEC, the LLVM form `s_and_b64 vcc, exec, s[..]`) gives every launch lane or none, so each half votes as the wave does and both sides may have code and scalars of their own (if/else, a uniform loop back edge; the mask itself read as data, e.g. exported, is still tier C `cross-lane`), while the same compare under a narrowed EXEC (a half with no active lane votes no and keeps its own scalars) or on a tainted value (`v_readfirstlane` of a varying VGPR, a lane count, an AND with a lane mask) stays tier C; confirmed on the wave interpreter (`UniformVote` in `tests/semantic/test_wave64_halves.py`: 64 lanes against two waves of 32, equal for the accepted forms with s4 = 9 and s4 = 1, different for each near miss) and by `ps_w64_a_uniform_vote`, which gives its derived words on an NVIDIA GeForce RTX 5080 (Linux, driver 580.65.06, 32 only). **B**: also a waterfall loop (`v_readfirstlane` of a varying value, `v_cmp_eq` against the same VGPR, `saveexec`, body, `s_xor exec`, `execnz`; the scalar only used inside the body), a wave-aggregated atomic (`s_bcnt1` of EXEC, `v_mbcnt` rank of that same EXEC, one `buffer_atomic_add` of that count (the count of the mask the rank ranks) by the rank-0 lane only, at a wave-uniform address (a uniform VGPR, or one the elected lane wrote from scalars and constants since EXEC last changed; a per-lane address such as a pixel coordinate is tier C `elected-lane`, since each half elects its own lane and bumps another counter), `v_readfirstlane` of the result with EXEC restored, base + rank as a store address, the rank counting the very mask the atomic's count was taken of (a rank of the entry EXEC or of a saved copy next to a base of the narrowed one is tier C `lane-rank`); the rank alone or the base alone is not a slot: exact as a set of slots, **the order of the slots within a wave is not preserved**, a 64-lane wave takes one run of slots, two halves take two), `v_readfirstlane` / `v_readlane` of a VGPR written from scalars and constants while EXEC was the launch mask (the same in every lane), a `v_writelane` / `v_readlane` spill pair on one constant lane below 32. **C**: anything else that reaches an export, a store's data, a branch or EXEC: lane count / rank / first-lane index / raw lane id (`v_mbcnt` of -1), `v_readlane` of a varying value at any lane (on a wave64 every lane gets hardware lane N, in halves each half gets its own lane N, so lane 7 is as wrong as lane 40; the research note's row 9 is too generous here); an analysis failure is tier C with reason `analysis-error` (the translation does not fail), `v_writelane` to a non-constant or >= 32 lane, a 32-bit access to half of a lane mask (`exec_hi`, `vcc_hi`, a mask pair's odd register), a mask read as data (including a mask combined by `s_and/or/andn2_b64` with a register that is not one: a user value, a loaded mask), a scalar defined behind a wave-wide vote and read where it may not have run (`s_add s5, s5, 1` after `s_cbranch_vccz`; a trip count in an SGPR of a divergent loop: the halves vote differently), a branch on a count, an elected-lane side effect that is not a count, `ds_append`/`ds_consume`. The check is conservative: unknown means C. `--wave64-graphics=warn` (default) marks tier C and counts it in the summary line, `error` refuses it (`Unsupported`), `off` skips the analysis; `python tools/wave64_halves.py --census /index.json` prints tier, reason and idiom counts (no names); it complements `tools/wave64_graphics_scan.py` (#1132), which counts candidate cross-half opcodes in the disassembly before translation and decides nothing. **Corpus census** (1.0.2.1, all 26,503 shaders translated at `main` `f847748c` with `--wave64-emulate`, `--census` over that index): 13,405 wave64 graphics shaders (2,236 VS, 10,974 PS, 195 GS, the FSSM header's wave size, see *Wave size*); tier A 4,033 (30.1%), B 85 (0.6%), C 9,287 (69.3%): VS 1,455/79/702, PS 2,383/6/8,585, GS 195/0/0. Tier C reasons (a shader can have several): unsafe-vote-branch 8,285, tainted-branch 6,547, tainted-exec 5,189, cross-lane 4,764, stale-scalar 3,415, mask-half 759, unsafe-execz-branch 583, first-lane 353, waterfall-scalar 161, lane-id 152, lane-count 1. Idiom tags, counted on every shader that carries one whatever its tier (`--census` prints them as "tier B idioms"; 85 shaders are tier B): readfirstlane-uniform 626, lane-spill 287, waterfall 35. (Earlier censuses counted 11,405 shaders, from when the wave size came from code markers: TEST-319 had A 1,919, B 17, C 9,469 with all 195 GS in C; its re-run with the GS ring rule below and #1982 had A 2,117, B 17, C 9,271 with all 195 GS in A.) The lane-id bpermute rule moves no corpus shader. (The TEST-319 census, from when the wave size came from code markers and before the GS ring-address rule below, counted 11,405 shaders: A 1,919, B 17, C 9,469, with all 195 GS in C.) The lane-id bpermute rule moves no corpus shader. **Corpus census** (TEST-319, 1.0.2.1, `--census` over the translated index, re-run with the GS ring rule below and #1982): 11,405 wave64 graphics shaders (1,179 VS, 10,031 PS, 195 GS); tier A 2,117 (18.6%), B 17 (0.1%), C 9,271 (81.3%): VS 479/14/686, PS 1,443/3/8,585, GS 195/0/0. Tier C reasons (a shader can have several): unsafe-vote-branch 8,285, tainted-branch 6,550, tainted-exec 5,189, cross-lane 4,760, stale-scalar 3,415, mask-half 758, unsafe-execz-branch 583, first-lane 353, waterfall-scalar 161, lane-id 152, lane-count 1. 11,405 wave64 graphics shaders (1,179 VS, 10,031 PS, 195 GS); tier A 1,919 (16.8%), B 17 (0.1%), C 9,469 (83.0%): VS 465/14/700, PS 1,454/3/8,574, GS 0/0/195. Tier C reasons (a shader can have several): unsafe-vote-branch 8,175, tainted-branch 6,582, cross-lane 6,111, tainted-exec 4,959, stale-scalar 3,162, mask-half 758, unsafe-execz-branch 583, first-lane 353, lane-id 277, waterfall-scalar 167, lane-count 1. Tier B idioms: readfirstlane-uniform 558, lane-spill 287, waterfall 35. The lane-id bpermute rule moves no corpus shader. **Corpus coverage is not measured here**: it needs a run over the game's shaders by someone who has them. **Rewrite (the only one the emission needs)**: `v_readlane_b32` of a proven-uniform VGPR reads the lane's own copy instead of shuffling from lane N, because a subgroup shuffle from lane >= 32 of a 32-wide subgroup is undefined (143 of 144 test shaders translate byte-identically to origin/main, only `ps_w64_b_readlane_uniform` changed). Everything else tier B needs is what the translator already emits per subgroup: the ballot/count/rank/first-lane words of `wave_mask` are the subgroup's own (the high word is 0), `v_readfirstlane` is the subgroup's first active lane, a waterfall runs once per distinct value of the subgroup. GPU-checked on AMD Radeon 880M (driver 26.11.2; `requiredSubgroupSizeStages` has FRAGMENT, size 32..64) with `runtime/test/shaders/w64_graphics.py`: each `ps_w64_*` fixture drawn with the fragment subgroup size required to 64 (one hardware wave) and to 32 (two halves). `ps_w64_a_skip`, `_b_waterfall`, `_b_readfirstlane`, `_b_readlane_uniform` and `_b_ballot_atomic` (counter 1024 and the 1024 slot words as a set; slot order differs) match each other and the words their headers derive; `_c_bcnt_export`, `_c_lane_id`, `_c_readlane`, `_c_vote_stale`, `_c_vote_else`, `_c_scc_vote`, `_c_execz_sgpr` (an SGPR written on the exec-zero side and exported) and `_c_waterfall_count` differ between 64 and 32 (the detector is right). `ps_w64_a_one_lane` is the case where only one pixel votes yes (so one half votes and the other does not, in the wave and in the halves): its skip regions (`execz`, `vccz`, `vccnz` with a jump-only fall-through) give equal images at 64 and 32; `_c_vote_else` (code on the vote's no side) and `_c_scc_vote` (SCC of a vote as data) differ. `ps_w64_a_discard` (three kills, two of them dropping whole regions so that some halves lose every pixel while the other half of their wave lives) was drawn on an AMD Radeon RX 580 (RADV, Mesa 26.0.8, required size 64, saved with `W64G_SAVE_REF`) and an NVIDIA GeForce RTX 5070 (32 only, driver 620.73.04, compared with `W64G_REF`): both equal the derived words, discarded pixels keeping the clear value, and each other. NVIDIA GeForce RTX 5070 Laptop (32 only, driver 617.42): tier A/B fixtures equal the derived words and the 880M@64 images (`W64G_SAVE_REF` / `W64G_REF`), tier C fixtures differ from the 880M@64 images. `ps_w64_a_permlane`, `_a_swizzle` and `_a_bpermute` (TEST-319: permlane16 neighbour selects, permlanex16 there and back, swizzle quad-permute, swap and broadcast modes, bpermute from lane-id addresses; every read stays in the pixel's 2x2 quad or comes back, so the words do not depend on how pixels are packed into lanes) give the derived words on an NVIDIA GeForce RTX 5070 (Linux, driver 620.73.04, 32 only). With an AMD Radeon RX 580 (Polaris, RADV Mesa 26.0.8) as the 64-lane reference (`W64G_SAVE_REF`; GCN has one subgroup size, 64, in every stage but no FRAGMENT in `requiredSubgroupSizeStages`, so `vk_harness` counts a requested size equal to a device's only size as applied), the RTX 5070 run of every fixture (`W64G_REF`) equals the reference for all 13 tier A/B fixtures and differs from it for all 11 tier C ones, pixel and vertex; the same reads in a vertex shader run on the wave interpreter (64 lanes against two waves of 32, equal) because a GPU's partial vertex waves leave the lanes they would read empty. Vertex shaders: the VS stage cannot be forced on the 880M (no VERTEX in `requiredSubgroupSizeStages`), so VS is covered by the strict wave interpreter (`tests/semantic/test_wave64_halves.py`: 64 lanes against two waves of 32; tier A/B equal, tier C differs); geometry shaders are not tested (the corpus ones are wave64, see *Wave size*; no fixture). 64 lanes against two waves of 32; tier A/B equal, tier C differs), and on RADV also on the GPU (TEST-251): RADV runs the VS stage (NGG) as wave64 by default and as wave32 with `RADV_PERFTEST=gewave32` (GFX10+, seen in the `RADV_DEBUG=shaders` dump: 64-bit EXEC operations against `exec_lo`), so `w64_graphics.py` draws each `vs_w64_*` fixture both ways, 960 zero-area vertices (`VKH_VERTICES`) that store four words each to the heap, with `vs_w64_c_lane_id` as the probe that the wave size changed (largest lane id 63, then 31). RADV packs 62 or 64 vertices into a wave64 and 30 or 32 into a wave32, so the 32-lane run repacks the vertices rather than halving the waves; tier A/B words are keyed on the vertex index, which makes this the stricter test. `vs_w64_a_skip`, `_b_waterfall`, `_b_readlane_uniform` (readfirstlane and readlane 40/63 of uniform VGPRs) and `_b_ballot_atomic` (240 slots as a set) give the derived words at both sizes; `_c_bcnt_export`, `_c_readlane` and `_c_lane_id` differ (the detector is right), on an RX 9070 XT (GFX1201) and a Ryzen 9800X3D iGPU (GFX1036, RDNA2), RADV Mesa 26.3.1; geometry shaders are not tested (no fixture; the corpus has 195 wave64 geometry shaders, all tier C, see the census). `_c_bcnt_export`, `_c_readlane` and `_c_lane_id` differ (the detector is right), on an RX 9070 XT (GFX1201) and a Ryzen 9800X3D iGPU (GFX1036, RDNA2), RADV Mesa 26.3.1; geometry shaders likewise (TEST-251): RADV runs the GS stage (NGG) as wave64 by default and as wave32 with `gewave32`, and `w64_graphics.py` draws each `gs_w64_*` fixture after `vs_ids` (960 vertices, 320 triangles, `VKH_GS`), each invocation finding its triangle from `vs_ids`'s vertex number and storing four words to the heap, with `gs_w64_c_lane_id` as the probe (largest lane id 41, RADV puts at most 42 GS invocations in a wave64, then 31). **LDS writes of a legacy GS:** `rdna2spirv.gs_ds` maps one to an output slot from its offset alone and drops the VGPR address (the lane's GSVS area), so `wave64_halves.py` checks only the data a GS `ds_write` writes, not its address; before, a lane id that only formed the GSVS base made the shader tier C `lane-id`. Confirmed three ways: a hand-written GS with the base `lane id * 96` translates, after `spirv-opt -O`, to the same instructions as without it; `gs_w64_a_ring` (that shape) gives the derived records at wave64 and wave32 on both GPUs; and `tests/semantic/test_wave64_halves.py` (`GeometryRing`) keeps the lane id in the written data, or in a memory store's address, tier C. The corpus GS were that false tier C: all 195 contain `v_mbcnt_hi`, all 195 were tier C in the TEST-319 census, and `wave64_halves.py --census` on the corpus translated at `f847748c` puts all 195 in tier A. `_c_bcnt_export`, `_c_readlane` and `_c_lane_id` differ (the detector is right), on an RX 9070 XT (GFX1201) and a Ryzen 9800X3D iGPU (GFX1036, RDNA2), RADV Mesa 26.3.1; geometry shaders are not tested (the corpus ones are wave64, see *Wave size*; no fixture). The corpus GS form their GSVS base from `v_mbcnt_lo/hi` (all 195 contain `v_mbcnt_hi`): they were all a false tier C, and the census above has all 195 at tier A. `wave64_halves.py --census` on a translated corpus shows it. `_c_bcnt_export`, `_c_readlane` and `_c_lane_id` differ (the detector is right), on an RX 9070 XT (GFX1201) and a Ryzen 9800X3D iGPU (GFX1036, RDNA2), RADV Mesa 26.3.1; geometry shaders are not tested (the corpus ones are wave32; no fixture). Not checked: helper lanes of partial quads; `VK_KHR_shader_maximal_reconvergence` is assumed for waterfall and election loops. Tiers A and B assume subgroups of at least 32 lanes: a fragment stage may run fewer live lanes than the subgroup size it reports (Intel UHD 770: gl_SubgroupSize 32, ballot count 16, a shuffle from lane L^16 returns garbage; measured by kapitche, TEST-433), so `w64_graphics.py` skips the tier A/B pixel fixtures on a device whose minimum subgroup size is below 32 when neither the 64 nor the 32 run took effect; deriving the skip from a measured live fragment width (ballot count) in `vk_harness` is a follow-up. **ADD_TID_ENABLE** (SHADER-833, finding by @shdann in #4571): an access with no `idxen` through a V# whose word3 is a literal (`s_mov_b32` earlier in the block, the notion `rdna2spirv` uses for `sgpr_imm`) with bit 23 set takes the wave lane as its index (`idxen` ignores the bit, see *Swizzled buffer addressing*), so its `buffer_load*`/`tbuffer_load*` result and its `buffer_store*`/`tbuffer_store*`/`buffer_atomic*` address carry the raw lane id: tier C `lane-id`. A literal with the bit clear, and every access with `idxen`, are unchanged. **Assumption**: through a run-time V# (loaded from memory or user data) tiers A and B take ADD_TID_ENABLE as 0 for an access without `idxen`; the code cannot say otherwise. The literal is tracked with the same folds `rdna2spirv` applies to `sgpr_imm` (mirrored in `Analysis.literal_sgpr`: `s_mov_b32/b64`, `s_movk_i32`, `s_pack_*`, `s_bfm_b32`, `s_not_b32`, `s_and/lshl/lshr_b32`, `s_mul_i32`; other folded ops count as run-time). The corpus census was not re-measured with this rule: its tier counts above are from before it and may change. Follow-up, needs the game: count the bound V#s with word3 bit 23 set at run time, and re-run `--census`. | diff --git a/docs/testing.md b/docs/testing.md index 46da2eba79..83ce287d0e 100644 --- a/docs/testing.md +++ b/docs/testing.md @@ -347,6 +347,22 @@ It needs shader Int64 support; a device that lacks it reports a skip. This is a independent of wave64 emulation. On RTX 3080 Ti (616.92, Windows 11), all 640 words matched; replacing the count mask with 31 or the arithmetic shift with a logical shift made the test fail at words 66 and 251 respectively. +`cs_w32_cmp_f64` checks the 32 binary64 vector compares, `v_cmp_*_f64` into VCC and `v_cmpx_*_f64` on EXEC, with +256 memory-fed operand pairs: the product of 16 values (±inf, ±max, the 1-ULP neighbours of ±1, the smallest +subnormals, ±0, the smallest normal, a NaN whose payload is only in the low dword and a negative quiet NaN). Each +thread stores one bit per predicate for both forms, a bit for `tru` run with the odd threads turned off (an inactive +lane gets VCC 0 from `v_cmp_` and stays off through `v_cmpx_`) and two bits for `lt` and `nge` with VOP3 `abs`/`neg`. +The expected words come from Python floats (`cmp_f64_words` in `check.py`): IEEE-754 ordering, with every pair that +has a NaN unordered. Both GPU runners compare all 1536 heap words (512 result words and 1024 unchanged input words); +the operands are loaded at run time, so neither the translator nor the driver can fold a compare. Run it alone with +`python -I scripts/run_gpu_tests.py --build runtime/build --filter cs_w32_cmp_f64 --require-pass`. +It is a wave32 test and no step of it needs a particular subgroup width, so it also runs on llvmpipe; the SGPR-pair +and constant operand forms are CPU-checked only (`tests/semantic/test_cmp_f64.py`). On an RTX 4070 Ti (NVIDIA +620.70.06, Linux) all 1536 words matched, and seven translator rules broken one at a time each failed it: no `-0` +canonicalization at word 206, a NaN test that ignores the low dword at word 28, an ordering key without the low +dword at word 70, the raw result written to an inactive lane's VCC at word 2, `v_cmpx_` replacing EXEC at word 3, +`abs` ignored and `nlt` lowered as the negation of `le` at word 0. + ## Wave64 pixel, vertex and geometry shaders (`w64_graphics.py`) Graphics stages have no emulation: on a 32-wide subgroup a wave64 VS, PS or GS runs as two 32-lane halves, and the diff --git a/runtime/test/shaders/check.py b/runtime/test/shaders/check.py index 34d56ddd02..8a93ab5cfd 100644 --- a/runtime/test/shaders/check.py +++ b/runtime/test/shaders/check.py @@ -387,6 +387,68 @@ def shift64_test(tools, spirv, env=None): return dump_test(tools, spirv, "cs_w32_shift64", expected, len(expected), child) +# cs_w32_cmp_f64.asm: the 16 binary64 compare predicates in opcode order (bit n of a result word is predicate n), and +# the operand values every pair is drawn from, in ascending order and then two NaNs. +CMP_F64_PREDICATES = ("f", "lt", "eq", "le", "gt", "lg", "ge", "o", + "u", "nge", "nlg", "ngt", "nle", "neq", "nlt", "tru") +CMP_F64_VALUES = ( + 0xFFF0000000000000, # -inf + 0xFFEFFFFFFFFFFFFF, # -max + 0xBFF0000000000001, # -1 - 1 ulp + 0xBFF0000000000000, # -1 + 0xBFEFFFFFFFFFFFFF, # the value above -1: its high dword is the smaller one, its low dword all ones + 0x8000000000000001, # the negative smallest subnormal + 0x8000000000000000, # -0 + 0x0000000000000000, # +0 + 0x0000000000000001, # the smallest subnormal + 0x0010000000000000, # the smallest normal + 0x3FF0000000000000, # 1 + 0x3FF0000000000001, # 1 + 1 ulp + 0x7FEFFFFFFFFFFFFF, # +max + 0x7FF0000000000000, # +inf + 0x7FF0000000000001, # a NaN whose payload is only in the low dword: its high dword is +inf's + 0xFFF8000000000000) # a negative quiet NaN +CMP_F64_SIGN = 1 << 63 + + +def cmp_f64_predicates(a_bits, b_bits): + """The 16 results of comparing two binary64 bit patterns, as a mask with bit n for CMP_F64_PREDICATES[n]. + IEEE-754 through Python floats: a pair with a NaN is unordered, so lt, eq and gt are all false for it and every + negated predicate is true; -0 equals +0 and a subnormal is not zero.""" + a, b = (struct.unpack(" b + results = (False, lt, eq, lt or eq, gt, lt or gt, gt or eq, not unordered, + unordered, not (gt or eq), not (lt or gt), not gt, not (lt or eq), not eq, not lt, True) + return sum(1 << bit for bit, result in enumerate(results) if result) + + +def cmp_f64_words(): + """cs_w32_cmp_f64: the input heap and the full expected readback, with Python floats as the oracle. Record + 16 * ia + ib compares value ia with value ib. Thread i handles records i and i + 128, so a record's thread has + the record's parity.""" + inputs, results = [], [] + for record, (a, b) in enumerate((a, b) for a in CMP_F64_VALUES for b in CMP_F64_VALUES): + inputs.extend((a & 0xFFFFFFFF, a >> 32, b & 0xFFFFFFFF, b >> 32)) + word = cmp_f64_predicates(a, b) + word |= (record % 2 == 0) << 16 # tru with the odd threads turned off first + word |= (cmp_f64_predicates(a & ~CMP_F64_SIGN, b ^ CMP_F64_SIGN) >> 1 & 1) << 17 # lt of |a| and -b + word |= (cmp_f64_predicates(a ^ CMP_F64_SIGN, b & ~CMP_F64_SIGN) >> 9 & 1) << 18 # nge of -a and |b| + results.extend((word, word)) # the v_cmp_ word (VCC), then the v_cmpx_ word (EXEC) + return [0xEEEEEEEE] * len(results) + inputs, results + inputs + + +def cmp_f64_test(tools, spirv, env=None): + """Verify the 32 binary64 compares on 256 memory-fed operand pairs, including the untouched input records.""" + initial, expected = cmp_f64_words() + with tempfile.TemporaryDirectory(prefix="leonida-cmp-f64-") as tmp: + path = Path(tmp) / "input.bin" + path.write_bytes(struct.pack(f"<{len(initial)}I", *initial)) + child = dict(os.environ if env is None else env, VKC_HEAP_INIT=str(path)) + child.setdefault("VKC_SUBGROUP_SIZE", str(subgroup_size(spirv, "cs_w32_cmp_f64") or 32)) + return dump_test(tools, spirv, "cs_w32_cmp_f64", expected, len(expected), child) + + # cs_user_sgprs.asm: vk_compute_test puts these words in s4..s7 and the shader stores them back. USER_SGPRS = [0x4F000000, 0xDEADBEEF, 7, 0xFFFFFFFF] USER_SGPRS_ENV = {"VKC_SGPRS": ",".join(hex(w) for w in USER_SGPRS)} @@ -1883,6 +1945,7 @@ def main(): results.append(("cs_heap_init", compute_test(tools, spirv, "cs_heap_init", "1", "dump", expected_words=HEAP_INIT_EXPECTED, env=heap_init_env()))) results.append(("cs_w32_shift64", shift64_test(tools, spirv))) + results.append(("cs_w32_cmp_f64", cmp_f64_test(tools, spirv))) results.append(("cs_cvt_f32_sat", cvt_f32_sat_test(tools, spirv))) results.append(("cs_fma_fused", fma_fused_test(tools, spirv))) results.append(("cs_cvt_pk_u8", compute_test(tools, spirv, "cs_cvt_pk_u8", "1", "dump", diff --git a/runtime/test/shaders/cs_w32_cmp_f64.asm b/runtime/test/shaders/cs_w32_cmp_f64.asm new file mode 100644 index 0000000000..99ddb94dde --- /dev/null +++ b/runtime/test/shaders/cs_w32_cmp_f64.asm @@ -0,0 +1,270 @@ +; GPU-CMP-F64: the 16 binary64 vector compares, v_cmp_*_f64 into VCC and v_cmpx_*_f64 on EXEC. +; group: 128,1,1 +; mattr: +wavefrontsize32,-wavefrontsize64 +; check.py seeds 256 records at byte 0x800: {a.lo, a.hi, b.lo, b.hi}, the Cartesian product of 16 binary64 values +; (record 16 * ia + ib holds values ia and ib), in ascending order and then two NaNs: -inf, -max, -1 - 1 ulp, -1, +; the value above -1 (high dword smaller, low dword all ones), the negative smallest subnormal, -0, +0, the smallest +; subnormal, the smallest normal, 1, 1 + 1 ulp, +max, +inf, a NaN whose payload is only in the low dword (its high +; dword is +inf's) and a negative quiet NaN. +; Thread i reads records i and i + 128 from memory, so neither the translator nor the driver can fold a compare, +; and writes two words per record at byte 8 * record: the v_cmp_ word, then the v_cmpx_ word. +; Bits 0..15 of both words are the 16 predicates in opcode order (RDNA2 ISA, VOPC compare operations): +; f lt eq le gt lg ge o u nge nlg ngt nle neq nlt tru +; lt, eq and gt are IEEE-754 (false when either operand is a NaN, -0 == +0, no denormal flush), o is "neither is a +; NaN", u its negation, and le/lg/ge/nge/nlg/ngt/nle/neq/nlt are the unions and negations their names say, so every +; n* predicate is true for a NaN. v_cmp_ sets the lane's VCC bit; v_cmpx_ leaves the lane active only when true. +; bit 16: v_cmp_tru / v_cmpx_tru with the odd threads turned off first: set on even threads only. A lane EXEC has +; off gets VCC 0 from v_cmp_ and stays off through v_cmpx_. +; bit 17: lt with VOP3 modifiers, |a| < -b. bit 18: nge with VOP3 modifiers, !(-a >= |b|). +; Bits 19..31 are 0. EXEC is put back with a constant after each v_cmpx_, so no step needs a particular subgroup +; width. The input records must come back unchanged. +; Run with the heap initialized by check.py's cmp_f64_test; compare all 1536 words. +v_lshlrev_b32_e32 v1, 4, v0 +v_add_nc_u32_e32 v11, 0x800, v1 +v_lshlrev_b32_e32 v10, 3, v0 +v_and_b32_e32 v9, 1, v0 +buffer_load_dwordx4 v[2:5], v1, s[0:3], 0 offen offset:2048 +s_waitcnt vmcnt(0) +v_mov_b32_e32 v6, 0 +v_mov_b32_e32 v7, 0 +v_cmp_f_f64_e32 vcc_lo, v[2:3], v[4:5] +v_or_b32_e32 v8, 0x1, v6 +v_cndmask_b32_e32 v6, v6, v8, vcc_lo +v_cmp_lt_f64_e32 vcc_lo, v[2:3], v[4:5] +v_or_b32_e32 v8, 0x2, v6 +v_cndmask_b32_e32 v6, v6, v8, vcc_lo +v_cmp_eq_f64_e32 vcc_lo, v[2:3], v[4:5] +v_or_b32_e32 v8, 0x4, v6 +v_cndmask_b32_e32 v6, v6, v8, vcc_lo +v_cmp_le_f64_e32 vcc_lo, v[2:3], v[4:5] +v_or_b32_e32 v8, 0x8, v6 +v_cndmask_b32_e32 v6, v6, v8, vcc_lo +v_cmp_gt_f64_e32 vcc_lo, v[2:3], v[4:5] +v_or_b32_e32 v8, 0x10, v6 +v_cndmask_b32_e32 v6, v6, v8, vcc_lo +v_cmp_lg_f64_e32 vcc_lo, v[2:3], v[4:5] +v_or_b32_e32 v8, 0x20, v6 +v_cndmask_b32_e32 v6, v6, v8, vcc_lo +v_cmp_ge_f64_e32 vcc_lo, v[2:3], v[4:5] +v_or_b32_e32 v8, 0x40, v6 +v_cndmask_b32_e32 v6, v6, v8, vcc_lo +v_cmp_o_f64_e32 vcc_lo, v[2:3], v[4:5] +v_or_b32_e32 v8, 0x80, v6 +v_cndmask_b32_e32 v6, v6, v8, vcc_lo +v_cmp_u_f64_e32 vcc_lo, v[2:3], v[4:5] +v_or_b32_e32 v8, 0x100, v6 +v_cndmask_b32_e32 v6, v6, v8, vcc_lo +v_cmp_nge_f64_e32 vcc_lo, v[2:3], v[4:5] +v_or_b32_e32 v8, 0x200, v6 +v_cndmask_b32_e32 v6, v6, v8, vcc_lo +v_cmp_nlg_f64_e32 vcc_lo, v[2:3], v[4:5] +v_or_b32_e32 v8, 0x400, v6 +v_cndmask_b32_e32 v6, v6, v8, vcc_lo +v_cmp_ngt_f64_e32 vcc_lo, v[2:3], v[4:5] +v_or_b32_e32 v8, 0x800, v6 +v_cndmask_b32_e32 v6, v6, v8, vcc_lo +v_cmp_nle_f64_e32 vcc_lo, v[2:3], v[4:5] +v_or_b32_e32 v8, 0x1000, v6 +v_cndmask_b32_e32 v6, v6, v8, vcc_lo +v_cmp_neq_f64_e32 vcc_lo, v[2:3], v[4:5] +v_or_b32_e32 v8, 0x2000, v6 +v_cndmask_b32_e32 v6, v6, v8, vcc_lo +v_cmp_nlt_f64_e32 vcc_lo, v[2:3], v[4:5] +v_or_b32_e32 v8, 0x4000, v6 +v_cndmask_b32_e32 v6, v6, v8, vcc_lo +v_cmp_tru_f64_e32 vcc_lo, v[2:3], v[4:5] +v_or_b32_e32 v8, 0x8000, v6 +v_cndmask_b32_e32 v6, v6, v8, vcc_lo +v_cmpx_eq_u32_e32 0, v9 +v_cmp_tru_f64_e32 vcc_lo, v[2:3], v[4:5] +s_mov_b32 exec_lo, -1 +v_or_b32_e32 v8, 0x10000, v6 +v_cndmask_b32_e32 v6, v6, v8, vcc_lo +v_cmp_lt_f64_e64 vcc_lo, |v[2:3]|, -v[4:5] +v_or_b32_e32 v8, 0x20000, v6 +v_cndmask_b32_e32 v6, v6, v8, vcc_lo +v_cmp_nge_f64_e64 vcc_lo, -v[2:3], |v[4:5]| +v_or_b32_e32 v8, 0x40000, v6 +v_cndmask_b32_e32 v6, v6, v8, vcc_lo +v_cmpx_f_f64_e32 v[2:3], v[4:5] +v_or_b32_e32 v7, 0x1, v7 +s_mov_b32 exec_lo, -1 +v_cmpx_lt_f64_e32 v[2:3], v[4:5] +v_or_b32_e32 v7, 0x2, v7 +s_mov_b32 exec_lo, -1 +v_cmpx_eq_f64_e32 v[2:3], v[4:5] +v_or_b32_e32 v7, 0x4, v7 +s_mov_b32 exec_lo, -1 +v_cmpx_le_f64_e32 v[2:3], v[4:5] +v_or_b32_e32 v7, 0x8, v7 +s_mov_b32 exec_lo, -1 +v_cmpx_gt_f64_e32 v[2:3], v[4:5] +v_or_b32_e32 v7, 0x10, v7 +s_mov_b32 exec_lo, -1 +v_cmpx_lg_f64_e32 v[2:3], v[4:5] +v_or_b32_e32 v7, 0x20, v7 +s_mov_b32 exec_lo, -1 +v_cmpx_ge_f64_e32 v[2:3], v[4:5] +v_or_b32_e32 v7, 0x40, v7 +s_mov_b32 exec_lo, -1 +v_cmpx_o_f64_e32 v[2:3], v[4:5] +v_or_b32_e32 v7, 0x80, v7 +s_mov_b32 exec_lo, -1 +v_cmpx_u_f64_e32 v[2:3], v[4:5] +v_or_b32_e32 v7, 0x100, v7 +s_mov_b32 exec_lo, -1 +v_cmpx_nge_f64_e32 v[2:3], v[4:5] +v_or_b32_e32 v7, 0x200, v7 +s_mov_b32 exec_lo, -1 +v_cmpx_nlg_f64_e32 v[2:3], v[4:5] +v_or_b32_e32 v7, 0x400, v7 +s_mov_b32 exec_lo, -1 +v_cmpx_ngt_f64_e32 v[2:3], v[4:5] +v_or_b32_e32 v7, 0x800, v7 +s_mov_b32 exec_lo, -1 +v_cmpx_nle_f64_e32 v[2:3], v[4:5] +v_or_b32_e32 v7, 0x1000, v7 +s_mov_b32 exec_lo, -1 +v_cmpx_neq_f64_e32 v[2:3], v[4:5] +v_or_b32_e32 v7, 0x2000, v7 +s_mov_b32 exec_lo, -1 +v_cmpx_nlt_f64_e32 v[2:3], v[4:5] +v_or_b32_e32 v7, 0x4000, v7 +s_mov_b32 exec_lo, -1 +v_cmpx_tru_f64_e32 v[2:3], v[4:5] +v_or_b32_e32 v7, 0x8000, v7 +s_mov_b32 exec_lo, -1 +v_cmpx_eq_u32_e32 0, v9 +v_cmpx_tru_f64_e32 v[2:3], v[4:5] +v_or_b32_e32 v7, 0x10000, v7 +s_mov_b32 exec_lo, -1 +v_cmpx_lt_f64_e64 |v[2:3]|, -v[4:5] +v_or_b32_e32 v7, 0x20000, v7 +s_mov_b32 exec_lo, -1 +v_cmpx_nge_f64_e64 -v[2:3], |v[4:5]| +v_or_b32_e32 v7, 0x40000, v7 +s_mov_b32 exec_lo, -1 +buffer_store_dwordx2 v[6:7], v10, s[0:3], 0 offen +buffer_load_dwordx4 v[2:5], v11, s[0:3], 0 offen offset:2048 +s_waitcnt vmcnt(0) +v_mov_b32_e32 v6, 0 +v_mov_b32_e32 v7, 0 +v_cmp_f_f64_e32 vcc_lo, v[2:3], v[4:5] +v_or_b32_e32 v8, 0x1, v6 +v_cndmask_b32_e32 v6, v6, v8, vcc_lo +v_cmp_lt_f64_e32 vcc_lo, v[2:3], v[4:5] +v_or_b32_e32 v8, 0x2, v6 +v_cndmask_b32_e32 v6, v6, v8, vcc_lo +v_cmp_eq_f64_e32 vcc_lo, v[2:3], v[4:5] +v_or_b32_e32 v8, 0x4, v6 +v_cndmask_b32_e32 v6, v6, v8, vcc_lo +v_cmp_le_f64_e32 vcc_lo, v[2:3], v[4:5] +v_or_b32_e32 v8, 0x8, v6 +v_cndmask_b32_e32 v6, v6, v8, vcc_lo +v_cmp_gt_f64_e32 vcc_lo, v[2:3], v[4:5] +v_or_b32_e32 v8, 0x10, v6 +v_cndmask_b32_e32 v6, v6, v8, vcc_lo +v_cmp_lg_f64_e32 vcc_lo, v[2:3], v[4:5] +v_or_b32_e32 v8, 0x20, v6 +v_cndmask_b32_e32 v6, v6, v8, vcc_lo +v_cmp_ge_f64_e32 vcc_lo, v[2:3], v[4:5] +v_or_b32_e32 v8, 0x40, v6 +v_cndmask_b32_e32 v6, v6, v8, vcc_lo +v_cmp_o_f64_e32 vcc_lo, v[2:3], v[4:5] +v_or_b32_e32 v8, 0x80, v6 +v_cndmask_b32_e32 v6, v6, v8, vcc_lo +v_cmp_u_f64_e32 vcc_lo, v[2:3], v[4:5] +v_or_b32_e32 v8, 0x100, v6 +v_cndmask_b32_e32 v6, v6, v8, vcc_lo +v_cmp_nge_f64_e32 vcc_lo, v[2:3], v[4:5] +v_or_b32_e32 v8, 0x200, v6 +v_cndmask_b32_e32 v6, v6, v8, vcc_lo +v_cmp_nlg_f64_e32 vcc_lo, v[2:3], v[4:5] +v_or_b32_e32 v8, 0x400, v6 +v_cndmask_b32_e32 v6, v6, v8, vcc_lo +v_cmp_ngt_f64_e32 vcc_lo, v[2:3], v[4:5] +v_or_b32_e32 v8, 0x800, v6 +v_cndmask_b32_e32 v6, v6, v8, vcc_lo +v_cmp_nle_f64_e32 vcc_lo, v[2:3], v[4:5] +v_or_b32_e32 v8, 0x1000, v6 +v_cndmask_b32_e32 v6, v6, v8, vcc_lo +v_cmp_neq_f64_e32 vcc_lo, v[2:3], v[4:5] +v_or_b32_e32 v8, 0x2000, v6 +v_cndmask_b32_e32 v6, v6, v8, vcc_lo +v_cmp_nlt_f64_e32 vcc_lo, v[2:3], v[4:5] +v_or_b32_e32 v8, 0x4000, v6 +v_cndmask_b32_e32 v6, v6, v8, vcc_lo +v_cmp_tru_f64_e32 vcc_lo, v[2:3], v[4:5] +v_or_b32_e32 v8, 0x8000, v6 +v_cndmask_b32_e32 v6, v6, v8, vcc_lo +v_cmpx_eq_u32_e32 0, v9 +v_cmp_tru_f64_e32 vcc_lo, v[2:3], v[4:5] +s_mov_b32 exec_lo, -1 +v_or_b32_e32 v8, 0x10000, v6 +v_cndmask_b32_e32 v6, v6, v8, vcc_lo +v_cmp_lt_f64_e64 vcc_lo, |v[2:3]|, -v[4:5] +v_or_b32_e32 v8, 0x20000, v6 +v_cndmask_b32_e32 v6, v6, v8, vcc_lo +v_cmp_nge_f64_e64 vcc_lo, -v[2:3], |v[4:5]| +v_or_b32_e32 v8, 0x40000, v6 +v_cndmask_b32_e32 v6, v6, v8, vcc_lo +v_cmpx_f_f64_e32 v[2:3], v[4:5] +v_or_b32_e32 v7, 0x1, v7 +s_mov_b32 exec_lo, -1 +v_cmpx_lt_f64_e32 v[2:3], v[4:5] +v_or_b32_e32 v7, 0x2, v7 +s_mov_b32 exec_lo, -1 +v_cmpx_eq_f64_e32 v[2:3], v[4:5] +v_or_b32_e32 v7, 0x4, v7 +s_mov_b32 exec_lo, -1 +v_cmpx_le_f64_e32 v[2:3], v[4:5] +v_or_b32_e32 v7, 0x8, v7 +s_mov_b32 exec_lo, -1 +v_cmpx_gt_f64_e32 v[2:3], v[4:5] +v_or_b32_e32 v7, 0x10, v7 +s_mov_b32 exec_lo, -1 +v_cmpx_lg_f64_e32 v[2:3], v[4:5] +v_or_b32_e32 v7, 0x20, v7 +s_mov_b32 exec_lo, -1 +v_cmpx_ge_f64_e32 v[2:3], v[4:5] +v_or_b32_e32 v7, 0x40, v7 +s_mov_b32 exec_lo, -1 +v_cmpx_o_f64_e32 v[2:3], v[4:5] +v_or_b32_e32 v7, 0x80, v7 +s_mov_b32 exec_lo, -1 +v_cmpx_u_f64_e32 v[2:3], v[4:5] +v_or_b32_e32 v7, 0x100, v7 +s_mov_b32 exec_lo, -1 +v_cmpx_nge_f64_e32 v[2:3], v[4:5] +v_or_b32_e32 v7, 0x200, v7 +s_mov_b32 exec_lo, -1 +v_cmpx_nlg_f64_e32 v[2:3], v[4:5] +v_or_b32_e32 v7, 0x400, v7 +s_mov_b32 exec_lo, -1 +v_cmpx_ngt_f64_e32 v[2:3], v[4:5] +v_or_b32_e32 v7, 0x800, v7 +s_mov_b32 exec_lo, -1 +v_cmpx_nle_f64_e32 v[2:3], v[4:5] +v_or_b32_e32 v7, 0x1000, v7 +s_mov_b32 exec_lo, -1 +v_cmpx_neq_f64_e32 v[2:3], v[4:5] +v_or_b32_e32 v7, 0x2000, v7 +s_mov_b32 exec_lo, -1 +v_cmpx_nlt_f64_e32 v[2:3], v[4:5] +v_or_b32_e32 v7, 0x4000, v7 +s_mov_b32 exec_lo, -1 +v_cmpx_tru_f64_e32 v[2:3], v[4:5] +v_or_b32_e32 v7, 0x8000, v7 +s_mov_b32 exec_lo, -1 +v_cmpx_eq_u32_e32 0, v9 +v_cmpx_tru_f64_e32 v[2:3], v[4:5] +v_or_b32_e32 v7, 0x10000, v7 +s_mov_b32 exec_lo, -1 +v_cmpx_lt_f64_e64 |v[2:3]|, -v[4:5] +v_or_b32_e32 v7, 0x20000, v7 +s_mov_b32 exec_lo, -1 +v_cmpx_nge_f64_e64 -v[2:3], |v[4:5]| +v_or_b32_e32 v7, 0x40000, v7 +s_mov_b32 exec_lo, -1 +buffer_store_dwordx2 v[6:7], v10, s[0:3], 0 offen offset:1024 +s_endpgm diff --git a/scripts/run_gpu_tests.py b/scripts/run_gpu_tests.py index 8f17a4028b..c2da9234fc 100644 --- a/scripts/run_gpu_tests.py +++ b/scripts/run_gpu_tests.py @@ -37,6 +37,7 @@ from check import cbv_modulate_test from check import HEAP_INIT_EXPECTED, heap_init_env # cs_heap_init: vk_compute_test's VKC_HEAP_INIT from check import shift64_test # dynamic 64-bit vector shifts and overlapping destinations +from check import cmp_f64_test # the 32 binary64 vector compares on memory-fed operands from check import judged_words, words_match # dump words not judged on some devices (cs_signed_zero_nan) from check import TEXOFF_ARGS, texoff_problem # ps_texoff's expected words and arguments live in check.py from check import TEXOFF_FALLBACK, texoff_env # LEONIDA_TEXOFF_FALLBACK=1: texel offsets without maintenance8 @@ -1000,6 +1001,10 @@ def run_suite(a, work: str) -> int: detail = shift64_test(a.build, spirv_dir, cs_env) results.append((name, None if isinstance(detail, Skip) else not detail, detail or "640 words exact (64 shift cases and unchanged inputs)")) + elif name == "cs_w32_cmp_f64": + detail = cmp_f64_test(a.build, spirv_dir, cs_env) + results.append((name, None if isinstance(detail, Skip) else not detail, + detail or "1536 words exact (256 operand pairs and unchanged inputs)")) elif name == "cs_workgroup_yz": rc, msg = run_cmd([vk_compute, spv, "2x3x4", "workgroup_yz"], env=cs_env) results.append((name,) + compute_result(rc, msg, rc == 0 and "2x3x4 workgroup Y/Z: 0 mismatches" diff --git a/tests/test_gpu_cmp_f64.py b/tests/test_gpu_cmp_f64.py new file mode 100644 index 0000000000..3fc51c30ac --- /dev/null +++ b/tests/test_gpu_cmp_f64.py @@ -0,0 +1,194 @@ +"""GPU-CMP-F64: the binary64 compare oracle, the readback and the runner verdicts, without needing a GPU.""" +import contextlib +import io +import math +from pathlib import Path +import re +import struct +import sys +import tempfile +from types import SimpleNamespace +import unittest +from unittest.mock import patch + +ROOT = Path(__file__).resolve().parents[1] +sys.path.insert(0, str(ROOT / "scripts")) +import run_gpu_tests as rgt +import check + +WORDS = 1536 # 256 records of two result words, then 256 records of four input words +RESULTS = 512 +FIXTURE = ROOT / "runtime" / "test" / "shaders" / "cs_w32_cmp_f64.asm" + + +def as_float(bits): + return struct.unpack(" b else "eq") + seen.add(relation) + want = sum(1 << bit for bit, name in enumerate(check.CMP_F64_PREDICATES) if relation in unions[name]) + self.assertEqual(check.cmp_f64_predicates(a_bits, b_bits), want, (hex(a_bits), hex(b_bits))) + self.assertEqual(seen, {"lt", "eq", "gt", "un"}) + + def test_known_words(self): + initial, expected = check.cmp_f64_words() + self.assertEqual((len(initial), len(expected)), (WORDS, WORDS)) + self.assertEqual(initial[:RESULTS], [0xEEEEEEEE] * RESULTS) + self.assertEqual(initial[RESULTS:], expected[RESULTS:]) + # Each record's v_cmp_ word and v_cmpx_ word are the same. + self.assertEqual(expected[0:RESULTS:2], expected[1:RESULTS:2]) + self.assertTrue(all(word >> 19 == 0 for word in expected[:RESULTS])) + # Record 0, -inf with -inf on an even thread: eq le ge o nlg ngt nlt tru, bit 16, and neither modifier bit. + self.assertEqual(expected[0], 0x1CCCC) + # Record 1, -inf with -max on an odd thread: lt le lg o nge ngt neq tru and no bit 16. + self.assertEqual(expected[2], 0xAAAA) + # Record 14, -inf with the low-dword NaN on an even thread: u, the six n* predicates and tru, bit 16, and + # bit 18, since -(-inf) >= |NaN| is not true. + self.assertEqual(expected[28], 0x5FF00) + # Record 103, -0 with +0 (odd thread): equal. Record 120, +0 with the smallest subnormal: less. + self.assertEqual(expected[2 * 103], 0xCCCC) + self.assertEqual(expected[2 * 120] & 0xFFFF, 0xAAAA) + # Record 35, -1 - 1 ulp with -1: less, by the low dword alone. + self.assertEqual(expected[2 * 35] & 0xFFFF, 0xAAAA) + # Record 163, 1 with -1 (odd thread): gt ge lg o nle neq nlt tru; |1| < 1 is false; !(-1 >= 1) is true. + self.assertEqual(expected[2 * 163], 0x4F0F0) + # The inputs: record 163 is {1.lo, 1.hi, -1.lo, -1.hi}. + self.assertEqual(expected[RESULTS + 4 * 163:RESULTS + 4 * 164], [0, 0x3FF00000, 0, 0xBFF00000]) + + def test_fixture_gives_each_predicate_the_oracle_s_bit(self): + """In the assembly, each compare is followed by the OR of its result bit. For both records a thread handles, + the v_cmp_ and the v_cmpx_ predicates come in opcode order with bit n for predicate n, and the two compares + behind bits 16..18 are the ones the oracle models.""" + lines = [ln.strip() for ln in FIXTURE.read_text(encoding="utf-8").splitlines()] + code = [ln for ln in lines if ln and not ln.startswith(";")] + self.assertIn("; group: 128,1,1", lines) + + def bits(compare, accumulate): + """(compare operands and predicate, bit) of every compare whose next instruction ORs a bit in.""" + found = [] + for ln, after in zip(code, code[1:]): + m, bit = re.fullmatch(compare, ln), re.fullmatch(accumulate, after) + if m and bit: + found.append((m.group(1), m.group(2), int(bit.group(1), 16))) + return found + + plain = [("v[2:3], v[4:5]", name, 1 << bit) for bit, name in enumerate(check.CMP_F64_PREDICATES)] + modified = [("|v[2:3]|, -v[4:5]", "lt", 1 << 17), ("-v[2:3], |v[4:5]|", "nge", 1 << 18)] + # v_cmp_: the odd-thread tru is followed by the EXEC restore, not by its OR, so it is not in this list. + got = bits(r"v_cmp_(\w+?)_f64_e(?:32|64) vcc_lo, (.+)", r"v_or_b32_e32 v8, (0x[0-9a-f]+), v6") + self.assertEqual([(operands, name, bit) for name, operands, bit in got], (plain + modified) * 2) + got = bits(r"v_cmpx_(\w+?)_f64_e(?:32|64) (.+)", r"v_or_b32_e32 v7, (0x[0-9a-f]+), v7") + odd_off = [("v[2:3], v[4:5]", "tru", 1 << 16)] + self.assertEqual([(operands, name, bit) for name, operands, bit in got], (plain + odd_off + modified) * 2) + # Bit 16 of the v_cmp_ word: the odd threads go off, tru runs, EXEC comes back, then the bit is taken from VCC. + at = [i for i, ln in enumerate(code) if ln == "v_cmpx_eq_u32_e32 0, v9"] + self.assertEqual(len(at), 4) + for i in at[0::2]: + self.assertEqual(code[i + 1:i + 5], ["v_cmp_tru_f64_e32 vcc_lo, v[2:3], v[4:5]", "s_mov_b32 exec_lo, -1", + "v_or_b32_e32 v8, 0x10000, v6", + "v_cndmask_b32_e32 v6, v6, v8, vcc_lo"]) + for i in at[1::2]: + self.assertEqual(code[i + 1], "v_cmpx_tru_f64_e32 v[2:3], v[4:5]") + self.assertIn("v_and_b32_e32 v9, 1, v0", code) + # The records are read from byte 0x800 on and the two words of a record go to byte 8 * record. + self.assertEqual([ln for ln in code if ln.startswith("buffer_")], + ["buffer_load_dwordx4 v[2:5], v1, s[0:3], 0 offen offset:2048", + "buffer_store_dwordx2 v[6:7], v10, s[0:3], 0 offen", + "buffer_load_dwordx4 v[2:5], v11, s[0:3], 0 offen offset:2048", + "buffer_store_dwordx2 v[6:7], v10, s[0:3], 0 offen offset:1024"]) + self.assertEqual(code[:4], ["v_lshlrev_b32_e32 v1, 4, v0", "v_add_nc_u32_e32 v11, 0x800, v1", + "v_lshlrev_b32_e32 v10, 3, v0", "v_and_b32_e32 v9, 1, v0"]) + self.assertEqual(code[-1], "s_endpgm") + + +class CmpF64Readback(unittest.TestCase): + def run_readback(self, mutate=None, code=0, output="", missing=False): + paths = [] + + def launch(*args, env): + paths.append(Path(env["VKC_HEAP_INIT"])) + initial, expected = check.cmp_f64_words() + self.assertEqual(args[1:], (str(Path("unused") / "cs_w32_cmp_f64.spv"), "1", "dump")) + self.assertEqual(paths[-1].read_bytes(), struct.pack(f"<{WORDS}I", *initial)) + self.assertEqual(env["VKC_SUBGROUP_SIZE"], "32") + self.assertEqual(env["VKC_OUT_WORDS"], str(WORDS)) + self.assertEqual(env["LEONIDA_VK_DEVICE"], "synthetic device") + if mutate: + mutate(expected) + if not missing: + Path(env["VKC_DUMP"]).write_bytes(struct.pack(f"<{len(expected)}I", *expected)) + return code, output + + with patch.object(check, "run", side_effect=launch): + result = check.cmp_f64_test("unused", "unused", {"LEONIDA_VK_DEVICE": "synthetic device"}) + self.assertEqual(len(paths), 1) + self.assertFalse(paths[0].exists(), "private heap input must be cleaned up") + return result + + def test_complete_readback_passes(self): + self.assertEqual(self.run_readback(), "") + + def test_one_wrong_result_bit_or_a_changed_input_fails(self): + for word in (0, 1, RESULTS - 1, RESULTS, WORDS - 1): + with self.subTest(word=word): + result = self.run_readback(lambda data: data.__setitem__(word, data[word] ^ 0x8000)) + self.assertIn(f"word {word}:", result) + + def test_truncated_and_missing_dump_fail(self): + self.assertIn(f"expected {4 * WORDS} dump bytes, got {4 * WORDS - 4}", + self.run_readback(lambda data: data.pop())) + self.assertIn("no VKC_DUMP", self.run_readback(missing=True)) + + def test_unsupported_module_skips_but_nonzero_exit_fails(self): + self.assertIsInstance(self.run_readback(code=77, output="unsupported: no Int64\n"), check.Skip) + self.assertIn("exit 1", self.run_readback(code=1, output="dispatch failed")) + + +class CmpF64Runner(unittest.TestCase): + def test_filtered_runner_counts_pass_failure_and_skip(self): + for detail, expected, verdict in (("", 0, "1/1 passed"), ("word 28: mismatch", 1, "0/1 passed"), + (check.Skip("SKIP (no Int64)"), 0, "0/1 passed, 1 skipped")): + with self.subTest(detail=detail), tempfile.TemporaryDirectory() as tmp: + args = SimpleNamespace(filter="cs_w32_cmp_f64", build=tmp, llvm_mc="unused") + + def translate(_cmd, **_kwargs): + (Path(tmp) / "spirv" / "cs_w32_cmp_f64.spv").touch() + return 0, "" + + output = io.StringIO() + with (patch.object(rgt, "assemble_to_s", side_effect=lambda _mc, _src, dst, _name: Path(dst).touch()), + patch.object(rgt, "spirv_as"), patch.object(rgt, "run_cmd", side_effect=translate), + patch.object(rgt, "cmp_f64_test", return_value=detail) as readback, + contextlib.redirect_stdout(output)): + self.assertEqual(rgt.run_suite(args, tmp), expected) + readback.assert_called_once() + self.assertIn(verdict, output.getvalue()) + self.assertIn("cs_w32_cmp_f64", output.getvalue()) + + +if __name__ == "__main__": + unittest.main() diff --git a/tests/test_shader_checks.py b/tests/test_shader_checks.py index b700f91018..2e1bdee4c8 100644 --- a/tests/test_shader_checks.py +++ b/tests/test_shader_checks.py @@ -36,9 +36,9 @@ + len(check.PIXEL_TESTS) + len(check.CLIP_TESTS) + len(check.BOUNDS) + len(check.GLOBAL_OFFSET) + len(check.MIP_TEST_PASSES) + len(check.GRADIENT_TESTS) + len(check.STORE_WORDS) + len(check.GET_LOD_TESTS) - + len(check.TEXTURE_CONSTANTS) + 17) # three mesh fixtures, ps_tex, ps_imgatomic, ps_table_fetch, six compute fixtures, - # ps_ssharp, vs_base_ids, main's standalone cs_fmt_d16_xyz / cs_heap_init dumps (net one more case), cs_fmt_all - # and cs_w32_shift64 + + len(check.TEXTURE_CONSTANTS) + 18) # three mesh fixtures, ps_tex, ps_imgatomic, ps_table_fetch, six compute fixtures, + # ps_ssharp, vs_base_ids, main's standalone cs_fmt_d16_xyz / cs_heap_init dumps (net one more case), cs_fmt_all, + # cs_w32_shift64 and cs_w32_cmp_f64 CVT = {bits: [u, s] for bits, u, s in check.CVT_F32_SAT_CASES} @@ -105,6 +105,14 @@ def harness(_tool, shader, *args, env=None): words = expected if seeded else initial Path(env["VKC_DUMP"]).write_bytes(struct.pack(f"<{len(words)}I", *words)) return 0, "" + if name == "cs_w32_cmp_f64": + # The compare words come back only if check.py seeded the operand records through VKC_HEAP_INIT. + initial, expected = check.cmp_f64_words() + self.assertEqual((args, env["VKC_OUT_WORDS"]), (("1", "dump"), str(len(expected)))) + seeded = Path(env["VKC_HEAP_INIT"]).read_bytes() == struct.pack(f"<{len(initial)}I", *initial) + words = expected if seeded else initial + Path(env["VKC_DUMP"]).write_bytes(struct.pack(f"<{len(words)}I", *words)) + return 0, "" if name == "cs_user_sgprs": # The seeded words come back only if check.py passed them in VKC_SGPRS. seeded = (env or {}).get("VKC_SGPRS") == check.USER_SGPRS_ENV["VKC_SGPRS"]