From 08ba945d067381b65129fdfa656566b890831683 Mon Sep 17 00:00:00 2001 From: Vonsek <45567075+Vonsek@users.noreply.github.com> Date: Sun, 22 Nov 2026 16:27:27 +0100 Subject: [PATCH] GPU tests for v_mad_legacy_f32, v_mac_legacy_f32, v_mad_f32, v_mac_f32 Two pixel tests for ops that had CPU checks only. ps_mad_legacy: the legacy zero rule (0 * inf, NaN * -0 give +0) and the denormal flush of a product and of a v_mac_legacy_f32 operand. ps_mad_flush: the SHADER-118 flush of a v_mad_f32 operand, a v_mac_f32 product, a denormal sum, and FLT_MIN div:2 (flush after omod). Expected words derived by hand in the .asm headers; registered in check.py and run_gpu_tests.py and added as semantic fixtures with hand constants and a Python reference. The design.md rows name the tests. AI-assisted. --- docs/design.md | 4 +- runtime/test/shaders/check.py | 6 ++- runtime/test/shaders/ps_mad_flush.asm | 27 ++++++++++ runtime/test/shaders/ps_mad_legacy.asm | 30 +++++++++++ scripts/run_gpu_tests.py | 4 ++ tests/semantic/fixtures/disasm/ps_mad_flush.s | 14 +++++ .../semantic/fixtures/disasm/ps_mad_legacy.s | 15 ++++++ tests/semantic/regen_fixtures.py | 4 +- tests/semantic/test_value_semantics.py | 53 +++++++++++++++++++ 9 files changed, 153 insertions(+), 4 deletions(-) create mode 100644 runtime/test/shaders/ps_mad_flush.asm create mode 100644 runtime/test/shaders/ps_mad_legacy.asm create mode 100644 tests/semantic/fixtures/disasm/ps_mad_flush.s create mode 100644 tests/semantic/fixtures/disasm/ps_mad_legacy.s diff --git a/docs/design.md b/docs/design.md index 3f0dfbe8ec..d839b4e837 100644 --- a/docs/design.md +++ b/docs/design.md @@ -382,8 +382,8 @@ How the generated SPIR-V expects the runtime to work: | `v_fmac_f16`, `v_interp_p2/mov_f32` output modifiers | VOP3 `mul:2`/`mul:4`/`div:2` (applied first) and `clamp` to [0, 1] apply to `v_fmac_f16_e64` (before narrowing to f16, matching `v_fma_f16`, high half preserved) and to `v_interp_p2_f32_e64` / `v_interp_mov_f32_e64` (no-op when no modifier is present). Until 2026-11-22 all three dropped output modifiers. Source: LLVM `llvm/test/MC/AMDGPU/gfx10_asm_vop2.s` (`v_fmac_f16_e64`) and `gfx10_asm_vop3.s` (`v_interp_p2_f32_e64`, `v_interp_mov_f32_e64`). Checked on the CPU by `tests/semantic/test_f16_fma_rounding.py` (`test_fmac_output_modifiers`) and `tests/semantic/test_interp_f32_mods.py`, and on a GPU by `ps_fmac_f16_mods.asm`, `ps_interp_f32_mods.asm` and `ps_interp_mov_mods.asm` (the last two drawn with `vs_interp_consts.asm`, whose params are constant over the triangle; each modifier and the omod-before-clamp order change a word; Tesla V100 (NVIDIA 580.95.05, Linux)). | | 16-bit vector compare `op_sel` (`v_cmp(x)_*_{f16,u16,i16}`) | VOP3 `op_sel:[s0,s1]` selects bit `[15:0]` (`0`) or `[31:16]` (`1`) of each source before f16 input modifiers (`neg`/`abs`, via `Gen.f16_in`) or `u16`/`i16` zero-/sign-extension (`OpBitFieldUExtract`/`OpBitFieldSExtract` at bit offset 16 when set, 0 otherwise); VOPC writes a scalar lane mask (VCC/SGPR or EXEC for `v_cmpx`), so there is no destination `op_sel` bit. Until 2026-11-22 `Gen.compare` hardcoded the low half and ignored `mods`. Source: AMD RDNA2 ISA VOP3 `op_sel` and Mesa ACO `can_use_opsel`. Checked on the CPU by `tests/semantic/test_vcmp16_opsel.py` (all four `op_sel` combinations across `f16` relations/ordered/unordered/NaN/`neg`/`abs`, `u16`, signed `i16`, and `v_cmpx` wave32/wave64 EXEC updates via `spirv_mini_interp` and `spirv_wave_interp`); **not GPU-verified**. | | Known approximations | `v_cvt_pkrtz_f16_f32` is now **exact round-toward-zero** (finite overflow gives ±65504, not inf). The GPU smoke test caught the old round-to-nearest version producing inf in `PS_ImposterShadow`. The other f16 packs (`v_cvt_f16_f32`, d16 results, mix ops) round to nearest, which matches the default mode; the ALU ones follow a MODE toward-zero write (below; ALU sites: see the f16 rounding row). MODE: `s_setreg_imm32_b32 hwreg(HW_REG_MODE, 2, 2)` (f16/f64 rounding) is tracked in a per-invocation variable, the only MODE field the corpus writes (9,417 writes in 6,333 shaders: 6,694 toward zero, 2,723 back to nearest even). While it is toward zero, every VALU f16 result except the transcendentals listed below (`v_cvt_f16_f32`, f16 arithmetic, `v_pk_*_f16`, `v_fma_mix{lo,hi}_f16`, `v_interp_p2_f16`) rounds toward zero exactly, with the integer conversion `v_cvt_pkrtz_f16_f32` uses (`f16_bits(rtz=True)`, see the f16 rounding row), and `v_add_f64` steps back one ulp when the TwoSum error shows it rounded away from zero; finite overflow gives the largest finite value. The `v_add_f64` output modifiers apply after that step and round to nearest, so an omod that overflows or lands on a subnormal is not toward zero. **omod versus denormal mode is unmodelled:** the translator applies `mul:2`/`mul:4`/`div:2` regardless of the MODE denormal fields (as before this change), whereas hardware ignores omod when denormals are kept (denorm fields = 3) and applies it when they are flushed (both measured on an RX 6800: `v_add_f64 (1 - 2^-60) mul:2` with denormals kept gave 3ff00000:00000000 nearest and 3fefffff:ffffffff toward zero, unscaled; mul:2 was applied with denormals flushed); the tests therefore claim no omod order. CPU-checked by `tests/test_mode_round.py` (the RX 6800 words for f16 add/sub, `v_fma_mix`, the transcendentals, f64 overflow). f16 add and sub (f16 operands) and `v_pk_add_f16` take the exact TwoSum error of the f32 result into account, so they are exact toward zero too (f32 then f16 rounding alone would be wrong: 2 - 2^-24 is an f32 tie that rounds up to 2.0); f16 FMAs need nothing extra, since their round-to-odd f32 value (SHADER-55) narrows exactly in either mode. `v_fma_mix{lo,hi}_f16` rounds the exact fma once, straight to f16, in both nearest-even and toward-zero modes (measured on AMD RDNA2 gfx1036 and verified by `tools/fma_mix_probe.py`; finding 7079901079): `Gen.fma_mix_odd` corrects the f32 `Fma` to round-to-odd by the sign of its exact residual (product error by `Fma(x, y, -x*y)`, TwoSum of the sum), which narrows exactly in either direction. `fma_mix_odd` also handles a tiny product (|x*y| < 2^-64: its error underflows or is flushed, so the residual sign is sign(x) xor sign(y), independent of the driver's denormal mode) and an f32 overflow with finite operands (toward zero gives ±FLT_MAX, so f16 ±65504). `v_rcp_f16`, `v_rsq_f16`, `v_sqrt_f16` and `v_sin_f16` ignore the rounding mode on hardware (RX 6800: the same words in every mode), so they always narrow to nearest even; `v_cos_f16`, `v_exp_f16` and `v_log_f16` are unmeasured, assumed like those four and treated the same. The "every VALU f16 result rounds toward zero" sentence above therefore excludes these seven; the f16 results of `v_floor/ceil/trunc/rndne/fract_f16` are exact and need no rounding. The `v_add_f64` step needs f64 denormals preserved (not flushed) by the driver for subnormal sums. Shaders that never write MODE emit the same code as without this. Writes to other MODE bits (f32 rounding, denormals), directed rounding (+inf/-inf) and register-valued writes are refused, so nothing changes silently; none occur in the corpus. Denormal behaviour is still Vulkan's default. Format conversions in memory and texture units don't follow MODE. `v_mul_legacy_f32` now keeps the `0 × anything = 0` rule like `v_mad_legacy_f32` (GPU-checked with `runtime/test/shaders/ps_legacy_mul.asm` on AMD Radeon RX 9070 XT). | -| 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 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). Checked on the CPU by `tests/semantic/test_valu_f32_min3_max3_mad.py` (`DenormalFlushTests`: the flush column, NaN/inf/zero pass-through, and a sabotaged pass-through that fails); **not GPU-verified** — a native measurement still needs an RDNA1/RDNA2 part that has these opcodes. The `omod` order is an assumption: the flush runs after `div:2`/`mul:2`/`mul:4`, so `FLT_MIN div:2` is flushed, as pinned by that test. | -| `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. | +| 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 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). Checked on the CPU by `tests/semantic/test_valu_f32_min3_max3_mad.py` (`DenormalFlushTests`: the flush column, NaN/inf/zero pass-through, and a sabotaged pass-through that fails). The translated flush runs on the GPU in `ps_mad_flush` (`v_mad_f32`/`v_mac_f32`: a denormal operand, product and sum, and `FLT_MIN div:2`) and `ps_mad_legacy` (RTX 5080 and an RDNA2 iGPU, 2026-11-22). On the RDNA2 iGPU the denormal-product case (2^-70 * 2^-70 + FLT_MIN) also passed with the translator's product flush removed, so only the NVIDIA run tells that flush apart; without the result flush `ps_mad_flush` fails on both. The rule is **not measured natively**: that still needs an RDNA1/RDNA2 part that has these opcodes. The `omod` order is an assumption: the flush runs after `div:2`/`mul:2`/`mul:4`, so `FLT_MIN div:2` is flushed, as pinned by that test. | +| `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). GPU-checked through the translator by `ps_mad_legacy` (with `v_mad_legacy_f32`: 0 * inf, NaN * -0, the flushed operand of a `v_mac_legacy_f32`; RTX 5080 and an RDNA2 iGPU). **Not measured natively**: like the other mad opcodes it exists on gfx1010-1013 only, so no RDNA2 desktop part runs it. | | 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). 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 bounds checking | MUBUF `buffer_load*`, `buffer_store*`, and `buffer_atomic*` enforce `num_records` (V# word 2). Out-of-bounds stores/atomics skip memory access completely and out-of-bounds loads return 0 without a load. **The RX 6800 measurement behind RAW loads** (`buffer_load_dword`/`x2`/`x3`/`x4`, stride 0, no `idxen`, OOB_SELECT 3; the per-mode rule below covers every mode, stride and `idxen`): the byte offset O = inst_offset + soffset + (offen ? vaddr : 0) is exact (nothing truncated, and the address keeps base & 3), and dword i is data when O + 4·i + 4 ≤ num_records, else 0, measured on AMD Radeon RX 6800 (gfx1030, Windows driver 32.0.21045.29003) by running the instructions as a raw compute kernel, wave32 and wave64 (155 runs, every result either 0 or the stored data, wave32 = wave64 in every dword), for x1/x2/x4 with V# word3 0x31016fac (OOB_SELECT 3) at offsets 0..63 per lane, NUM_RECORDS 17..23 and 0x1000, base & 3 = 0 and 3: a dword at 0xf with NUM_RECORDS 18 is 0 (a start-only check reads it); x4 at 3 with 18 gives three data dwords and 0 for the fourth, which starts at 15 < 18 (so neither a whole-load nor a per-dword start check), and the zero is a whole 0, not partial bytes; x4 at offset:13 with 20 gives data, 0, 0, 0; inst_offset, soffset and offen are summed before the check; base & 3 = 3 flips at the same offsets. `x3` gets the rule without a measurement. **Per-mode check (V# OOB_SELECT, word3 bits [29:28])**, for every MUBUF/MTBUF access, as measured natively on RDNA2 (gfx1036, 732 cases, `docs/buffer_bounds.md`; Mesa's GFX11 column, not its GFX10 one). `idx` = `vindex` (0 without `idxen`), `off` = inst_offset + vaddr offset (offen), `offs` = `off` + soffset. A dword at byte 4·k of the access is out of range when: **0 STRUCTURED_WITH_OFFSET** `idx >= num_records` or `off + 4k + 4 > stride`; **1 STRUCTURED** `idx >= num_records` (no `idxen`: idx 0, so only `num_records == 0`); **2 DISABLED** `num_records == 0`; **3 RAW** `offs + 4k + 4 > num_records` (`idx * stride` is in the address, not in the check). A literal word3 (`s_mov_b32` earlier in the block) folds the mode, a run-time one selects with `OpSelect`. Multi-dword accesses, measured on the Radeon 880M (gfx1150, a valid proxy: gfx1036 follows the same column and gfx1150 matched it bit-exactly): in modes 0 and 3 **`buffer_load_dwordx2..x4` and `buffer_store_dwordx2..x4` are per dword**, for loads and stores alike (x4 at off 20 of 32 in RAW loads/stores 3 dwords, at 28 one, at 32 none; mode 0 likewise at the stride); modes 1 and 2 check once and always take the whole access. **A typed element (`buffer_load_format_*`, `buffer_store_format_*`) is all or nothing and ends at its format's size** (32_32_32_32 at off 20 of 32 reads or writes nothing), and an atomic checks its dword's end like a dword access. The translator does the same: per-dword guarded loads and stores for modes 0 and 3 (a store that straddled the edge used to write past it), the element size from the instruction's format, a literal word3 or the V#. The same oracle confirmed the terms (504 `buffer_load_dword` probes, idxen/offen/inst_offset/soffset at the stride and record edges, 0 disagreements): mode 0's `off` has `inst_offset` and no soffset, mode 1 reads nothing but the index, mode 3 adds inst_offset and soffset. `s_buffer_load` (SMEM) is separate: it keeps the `num_records` bound of the Scalar/buffer row and ignores OOB_SELECT (the same pattern for 0 to 3). **Swizzle**: SWIZZLE_ENABLE (V# word1 bit 31, Mesa `gfx10-rsrc.json` line 326; word1 [31:30] on GFX11, `gfx11-rsrc.json` line 259) and ADD_TID_ENABLE (word3 bit 23, line 337) change the address and the bounds in every mode and are not modelled: a literal V# with either set is `Unsupported`, a run-time V# with them is translated unswizzled, which is silently wrong (known gap). Until 2026-11-22 the translator ignored OOB_SELECT and checked by stride alone (`offset < num_records`, `index < num_records`, or `offset < num_records * stride`): a V# with word3 = 0 (mode 0, stride 0) was fully readable and is now always out of range, as on hardware, so the test harnesses' output V# is `0x31016fac` now (`vk_compute_test`, the interpreter tests, `cs_bounds.asm`, `cs_fmt_1010102.asm`, `cs_store.asm`). **How confirmed**: the native RDNA2 measurement (gfx1036) and the gfx1150 oracle (RDNA3.5, same column); GPU test `cs_oob_select.asm` (every mode, literal and run-time V#, words derived from the rules) on an NVIDIA RTX 5070 and an AMD Radeon 880M, which checks the translation, not RDNA2; `tests/semantic/test_buffer_oob_select.py` (a hand-written table of 33 cases over the four modes, loads and stores, both V# forms, plus the multi-dword stores and typed elements); `cs_oob_tail.asm` pins the end-based edge, per-dword x4 loads and stores and the all-or-nothing element, where Mesa's GFX10 column gives other words. **Unmeasured**: gfx1013/GFX10.1 itself (see `docs/buffer_bounds.md`), swizzle, unaligned addresses, and the mode 1/2 boundary of `buffer_load_dwordx2..x4` on RDNA2 hardware proper (the gfx1150 proxy shows all dwords in). Checked by `tests/semantic/test_value_semantics.py` (`RawBufferTailBounds`: the RX 6800 rows, values and the addresses loaded) and the GPU tests `runtime/test/shaders/cs_bounds.asm` (AMD Radeon RX 9070 XT, RX 6800), `cs_buf_tail.asm` (RX 6800, Vulkan, driver 26.11.2; aligned offsets only, since the translator's `Aligned 4` loads at byte-exact addresses were not checked on a Vulkan driver) `cs_oob_select.asm` and `cs_oob_tail.asm`. `cs_fmt_xy_xyz.asm` shows the whole element deciding for `_xy` and `_xyz` too, measured natively on a Radeon 680M (gfx1035, RDNA2): components that end inside num_records, in an element that doesn't, read 0 and store nothing. | | `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. **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.** | diff --git a/runtime/test/shaders/check.py b/runtime/test/shaders/check.py index 77f55f5b13..b329bfb6b5 100644 --- a/runtime/test/shaders/check.py +++ b/runtime/test/shaders/check.py @@ -287,7 +287,11 @@ def not_found_message(build, missing): "ps_valu16_mad": (0x00000002, 0x00030002, 0x00008000, 0x00000004), "ps_valu16_subrev": (0xaaaabc00, 0xaaaac000, 0xaaaa3c00, 0x42003800), # v_readlane_b32 across both halves of a wave64 (the .asm header derives the words) - "ps_w64x_readlane": (0x40000079, 0x40000010, 0x40000064, 0x400000be)} + "ps_w64x_readlane": (0x40000079, 0x40000010, 0x40000064, 0x400000be), + # v_mad_legacy_f32 / v_mac_legacy_f32: legacy zero rule and denormal flush (the .asm header derives the words) + "ps_mad_legacy": (0x3f800000, 0xc0000000, 0x00800000, 0x40400000), + # v_mad_f32 / v_mac_f32 denormal flush: operand, product, result, after div:2 (.asm header) + "ps_mad_flush": (0x3f800000, 0x00800000, 0x80000000, 0x00000000)} # Pixel shaders that are exact only when the pixel stage really ran 64 lanes wide. vk_harness says so when it chained # a required subgroup size onto the fragment stage ("fragment subgroup size: N required"). A device that cannot # require 64 there (NVIDIA: 32 only; llvmpipe: 8) has no frame to judge: the test is skipped, not failed. diff --git a/runtime/test/shaders/ps_mad_flush.asm b/runtime/test/shaders/ps_mad_flush.asm new file mode 100644 index 0000000000..1d49867607 --- /dev/null +++ b/runtime/test/shaders/ps_mad_flush.asm @@ -0,0 +1,27 @@ +; v_mad_f32 and v_mac_f32 (D is the addend): D = S0 * S1 + S2 with the product rounded to f32 before the add (not +; fused). docs/design.md (SHADER-118, "Denormal flush in v_mad_f32 ..."): these opcodes have no f32 denormals, so a +; subnormal operand, the rounded product and the result (after omod) read as zero of their sign. +; v0 = 0x00000001 (the smallest denormal), v1 = 2^126 (0x7e800000), v2 = 2^-70 (0x1c800000), +; v3 = FLT_MIN = 2^-126 (0x00800000), v4 = -2^-125 (0x81000000), v5 = 1.5 * 2^-126 (0x00c00000), v8 = FLT_MIN. +; x: v_mad_f32 v6, v0, v1, 1.0: S0 flushed to +0, so 0 * 2^126 + 1.0 = 1.0 -> 0x3f800000 +; (unflushed: 2^-149 * 2^126 = 2^-23, 1.0 + 2^-23 = 0x3f800001) +; y: v_mac_f32 v8, v2, v2: 2^-70 * 2^-70 = 2^-140, a denormal product, flushed to +0; +; D = +0 + 2^-126 = 0x00800000 (unflushed 2^-126 + 2^-140 = 0x00800200) +; z: v_mad_f32 v7, v4, 1.0, v5: -2^-125 + 1.5 * 2^-126 = -0.5 * 2^-126 = -2^-127, a denormal result, +; flushed to -0 -> 0x80000000 (unflushed 0x80400000) +; w: v_mad_f32 v9, v3, 1.0, 0 div:2: 2^-126 + 0 = 2^-126, div:2 gives 2^-127, then the flush: +0 -> 0x00000000 +; (a flush before the omod would leave 0x00400000) +; Expected mrt0 bits: 0x3f800000, 0x00800000, 0x80000000, 0x00000000 +v_mov_b32 v0, 1 +v_mov_b32 v1, 0x7e800000 +v_mov_b32 v2, 0x1c800000 +v_mov_b32 v3, 0x00800000 +v_mov_b32 v4, 0x81000000 +v_mov_b32 v5, 0x00c00000 +v_mov_b32 v8, 0x00800000 +v_mad_f32 v6, v0, v1, 1.0 +v_mac_f32 v8, v2, v2 +v_mad_f32 v7, v4, 1.0, v5 +v_mad_f32 v9, v3, 1.0, 0 div:2 +exp mrt0 v6, v8, v7, v9 done vm +s_endpgm diff --git a/runtime/test/shaders/ps_mad_legacy.asm b/runtime/test/shaders/ps_mad_legacy.asm new file mode 100644 index 0000000000..5a417f78a9 --- /dev/null +++ b/runtime/test/shaders/ps_mad_legacy.asm @@ -0,0 +1,30 @@ +; v_mad_legacy_f32 (VOP3) and v_mac_legacy_f32 (VOP2, D is the addend), which had CPU checks only. +; RDNA ISA: D = S0 * S1 + S2 with the legacy multiply: if S0 == 0.0 or S1 == 0.0 the product is +0.0, whatever the +; other operand is (inf and NaN included); otherwise the product is an ordinary f32 multiply. docs/design.md +; (SHADER-118, "Denormal flush in v_mad_f32 ..."): these opcodes have no f32 denormals, so a subnormal operand, the +; rounded product and the result read as zero of their sign. +; v0 = +0, v1 = -0, v2 = +inf, v3 = qNaN, v7 = 2^-70 (0x1c800000), v9 = 0x80000001 (the smallest negative denormal), +; v10 = FLT_MIN = 2^-126 (0x00800000), v8 = 3.0. +; x: v_mad_legacy_f32 v4, v0, v2, 1.0: S0 is 0, so 0 * inf is +0 (an ordinary multiply gives NaN); +; +0 + 1.0 = 1.0 -> 0x3f800000 +; y: v_mad_legacy_f32 v5, v3, v1, -2.0: S1 is -0, so NaN * -0 is +0; +0 + -2.0 = -2.0 -> 0xc0000000 +; z: v_mad_legacy_f32 v6, v7, v7, v10: 2^-70 * 2^-70 = 2^-140, a denormal product, flushed to +0; +; +0 + 2^-126 = 0x00800000 (unflushed it would be 2^-126 + 2^-140 = +; 0x00800200, 2^-140 being 2^9 ulps of 2^-126) +; w: v_mac_legacy_f32 v8, v9, v2: S0 = -denormal flushed to -0, so the legacy product is +0 (unflushed +; it is -inf); D = +0 + 3.0 = 3.0 -> 0x40400000 +; Expected mrt0 bits: 0x3f800000, 0xc0000000, 0x00800000, 0x40400000 +v_mov_b32 v0, 0 +v_mov_b32 v1, 0x80000000 +v_mov_b32 v2, 0x7f800000 +v_mov_b32 v3, 0x7fc00000 +v_mov_b32 v7, 0x1c800000 +v_mov_b32 v9, 0x80000001 +v_mov_b32 v10, 0x00800000 +v_mov_b32 v8, 0x40400000 +v_mad_legacy_f32 v4, v0, v2, 1.0 +v_mad_legacy_f32 v5, v3, v1, -2.0 +v_mad_legacy_f32 v6, v7, v7, v10 +v_mac_legacy_f32 v8, v9, v2 +exp mrt0 v4, v5, v6, v8 done vm +s_endpgm diff --git a/scripts/run_gpu_tests.py b/scripts/run_gpu_tests.py index d1d6e402d5..2bddb987da 100644 --- a/scripts/run_gpu_tests.py +++ b/scripts/run_gpu_tests.py @@ -1141,6 +1141,10 @@ def run_suite(a, work: str) -> int: "ps_valu16_mad": (0x00000002, 0x00030002, 0x00008000, 0x00000004), "ps_valu16_subrev": (0xAAAABC00, 0xAAAAC000, 0xAAAA3C00, 0x42003800), "ps_w64x_readlane": (0x40000079, 0x40000010, 0x40000064, 0x400000BE), # same expectation as check.py + # v_mad_legacy_f32 / v_mac_legacy_f32: legacy zero rule and denormal flush (.asm header) + "ps_mad_legacy": (0x3F800000, 0xC0000000, 0x00800000, 0x40400000), + # v_mad_f32 / v_mac_f32 denormal flush: operand, product, result, after div:2 (.asm header) + "ps_mad_flush": (0x3F800000, 0x00800000, 0x80000000, 0x00000000), } if skip := wide_pixel_skip(name, msg): # a 64-wide pixel stage the device could not give: nothing to judge results.append((name, None, str(skip))) diff --git a/tests/semantic/fixtures/disasm/ps_mad_flush.s b/tests/semantic/fixtures/disasm/ps_mad_flush.s new file mode 100644 index 0000000000..6007b4c09f --- /dev/null +++ b/tests/semantic/fixtures/disasm/ps_mad_flush.s @@ -0,0 +1,14 @@ +; ps_mad_flush test fixture generated by tests/semantic/regen_fixtures.py from runtime/test/shaders/ps_mad_flush.asm + v_mov_b32 v0, 1 + v_mov_b32 v1, 0x7e800000 + v_mov_b32 v2, 0x1c800000 + v_mov_b32 v3, 0x00800000 + v_mov_b32 v4, 0x81000000 + v_mov_b32 v5, 0x00c00000 + v_mov_b32 v8, 0x00800000 + v_mad_f32 v6, v0, v1, 1.0 + v_mac_f32 v8, v2, v2 + v_mad_f32 v7, v4, 1.0, v5 + v_mad_f32 v9, v3, 1.0, 0 div:2 + exp mrt0 v6, v8, v7, v9 done vm + s_endpgm diff --git a/tests/semantic/fixtures/disasm/ps_mad_legacy.s b/tests/semantic/fixtures/disasm/ps_mad_legacy.s new file mode 100644 index 0000000000..ca8c2a423f --- /dev/null +++ b/tests/semantic/fixtures/disasm/ps_mad_legacy.s @@ -0,0 +1,15 @@ +; ps_mad_legacy test fixture generated by tests/semantic/regen_fixtures.py from runtime/test/shaders/ps_mad_legacy.asm + v_mov_b32 v0, 0 + v_mov_b32 v1, 0x80000000 + v_mov_b32 v2, 0x7f800000 + v_mov_b32 v3, 0x7fc00000 + v_mov_b32 v7, 0x1c800000 + v_mov_b32 v9, 0x80000001 + v_mov_b32 v10, 0x00800000 + v_mov_b32 v8, 0x40400000 + v_mad_legacy_f32 v4, v0, v2, 1.0 + v_mad_legacy_f32 v5, v3, v1, -2.0 + v_mad_legacy_f32 v6, v7, v7, v10 + v_mac_legacy_f32 v8, v9, v2 + exp mrt0 v4, v5, v6, v8 done vm + s_endpgm diff --git a/tests/semantic/regen_fixtures.py b/tests/semantic/regen_fixtures.py index a7c9cb6960..e4f81a5763 100644 --- a/tests/semantic/regen_fixtures.py +++ b/tests/semantic/regen_fixtures.py @@ -31,7 +31,9 @@ "ps_f16_pack_mods", # v_pack_b32_f16 neg/abs (SHADER-260) "cs_w64x_andn2_exec", # s_andn2_saveexec_b64 / s_andn2_wrexec_b64 (test_andn2_exec_b64.py) "cs_w64x_saveexec_b64", # s_and/s_or/s_andn2_saveexec_b64, s_andn2_wrexec_b64 (test_saveexec_b64.py) - "ps_valu16_mad", "ps_valu16_subrev") # v_mad_u32_u16 / v_mad_i32_i16, v_subrev_f16 + "ps_valu16_mad", "ps_valu16_subrev", # v_mad_u32_u16 / v_mad_i32_i16, v_subrev_f16 + "ps_mad_legacy", # v_mad_legacy_f32 / v_mac_legacy_f32: legacy zero rule and denormal flush + "ps_mad_flush") # v_mad_f32 / v_mac_f32: denormal flush of operand, product and result def render(name): diff --git a/tests/semantic/test_value_semantics.py b/tests/semantic/test_value_semantics.py index e75d4392c1..aded49023b 100644 --- a/tests/semantic/test_value_semantics.py +++ b/tests/semantic/test_value_semantics.py @@ -36,6 +36,10 @@ v_mad_u32_u16 / D = S0.lo * S1.lo + S2 mod 2^32, the halves zero- (u16) or sign-extended (i16); op_sel bit v_mad_i32_i16 0/1 reads the high half of S0/S1. D is a whole dword (nothing of the old value is kept). v_subrev_f16 D.lo = S1.lo - S0.lo; the high half of D is kept in the VOP2 and the VOP3 form. + v_mad_legacy_f32 / D = S0 * S1 + S2 (mac: + D), the product +0 when S0 or S1 is 0 (inf/NaN included); + v_mac_legacy_f32 a denormal operand, product or result reads as zero of its sign (SHADER-118). + v_mad_f32 / v_mac_f32 D = S0 * S1 + S2 (mac: + D), product rounded before the add; the same flush, the result's + after omod. s_*_saveexec_b32/b64, a constant used as a lane mask gives lane L its bit L: of the 32-bit value for a b32 op, s_andn2_wrexec_*, of the 64-bit value for a b64 op (inline constants sign-extended, literals with a zero s_mov/s_not/s_and_b64 high word). cs_w32_mask_imm / cs_w64_mask_imm run every lane of a wave (LaneMaskConstants). @@ -76,6 +80,8 @@ EXPECTED_SFF_IMM = [0x00000002, 0x00000001, 0x00000014, 0x00000010] EXPECTED_VALU16_MAD = [0x00000002, 0x00030002, 0x00008000, 0x00000004] EXPECTED_VALU16_SUBREV = [0xAAAABC00, 0xAAAAC000, 0xAAAA3C00, 0x42003800] +EXPECTED_MAD_LEGACY = [0x3F800000, 0xC0000000, 0x00800000, 0x40400000] +EXPECTED_MAD_FLUSH = [0x3F800000, 0x00800000, 0x80000000, 0x00000000] def _f32_bits(x): @@ -293,6 +299,41 @@ def reference_valu16_subrev(): 0x42000000 | _half(a - d)] +def _from_bits(b): + return struct.unpack("