Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .github/workflows/runtime.yml
Original file line number Diff line number Diff line change
Expand Up @@ -596,11 +596,9 @@ jobs:
if: ${{ !cancelled() && steps.macos-build.outcome == 'success' }} # also after a runtime test failure
shell: bash
env:
# ps_ssharp: #1845 (the S#'s LOD bias, which a Metal sampler can't take). cs_fma_fused is newer than the job
# and wrong on MoltenVK: https://github.com/ItsNotRexed/Leonida/issues/3796#issuecomment-7086691314
# ps_ssharp: #1845 (the S#'s LOD bias, which a Metal sampler can't take).
EXPECTED_FAILURES: >-
ps_ssharp
cs_fma_fused
run: |
set +e
python3 -I scripts/run_gpu_tests.py --build runtime/build --llvm-mc "$LLVM_MC" --work "$RUNNER_TEMP/gpu" 2>&1 |
Expand Down
3 changes: 2 additions & 1 deletion docs/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -796,13 +796,14 @@ game's device ignores it`, so leaving them set cannot slow a game down (`run_tin
| On a Mac, a translated shader's GPU time is 1.5 to 16 times what it would be without the precise-arithmetic overhead | MoltenVK's SPIRV-Cross turns every `NoContraction` float add, subtract and multiply into a call to an `[[clang::optnone]]` helper that Metal does not inline. MoltenVK 1.4.2 and `main` up to at least `5189f8de` are affected (SHADER-234, [design notes](design.md#translator-status-and-runtime-contract)) | Expected with these MoltenVK versions, and the output is still exact. Before you time shaders on a Mac, build MoltenVK with SPIRV-Cross `98cbb7c0` or newer in `ExternalRevisions/SPIRV-Cross_repo_revision` (KhronosGroup/MoltenVK#2917 moves it to `57e4efcc`), and point `LEONIDA_VULKAN_LOADER` at its `libMoltenVK.dylib` |
| `d3d12_descriptor_test` reports that the set had room for fewer than 5001 2D views and 2100 samplers, and the device logs that the bindless set holds fewer samplers than a full shader-visible sampler heap | The device's descriptor limits, or its `vkGetDescriptorSetLayoutSupport`, allow no bigger bindless set ([d3d12_vulkan.md](d3d12_vulkan.md) section 5). MoltenVK's answer is ignored, since it rejects every layout of `maxPerSetDescriptors` (1212) or more although it runs the full set | Expected where the limits are low. The test still checks the last index of each array and that the next view and sampler are refused |
| `cs_dpp_ops` fails on a Mac with MoltenVK 1.4.2: `out[0..7] = 100 100 11 ...`, want `100 10 11 ...` | MoltenVK 1.4.2's SPIRV-Cross moves the DPP lowering's subgroup ballot and shuffle into a short-circuiting `&&` and `?:`, so only some lanes run them and lane 1 sees its source lane 0 as inactive. SPIRV-Cross `5c372ffb` (in MoltenVK `main`) keeps them out of `?:`; a ballot on the right of `&&` is still moved there in SPIRV-Cross `57e4efcc` | Fixed in the translator (SHADER-529, #3227): it stores the ballot and the shuffle to variables of their own, so the MSL that MoltenVK 1.4.2 generates (`MVK_CONFIG_DEBUG=1`) runs each as a statement in every lane. Translate again with current `main`; MoltenVK `main` and KosmicKrisp are no longer needed for it. A pass alone does not show the fix: an Apple M5 Pro (macOS 26.5.1) returns the right words with 1.4.2 even when the ballot is on the right of `&&` |
| `check.py`'s `cs_fma_fused` fails on a Mac with MoltenVK 1.4.2: word 7 reads `15360` (`0x3c00`), want `29521` (`0x7351`) | The f16 multiply-add (round to odd). The MSL of 1.4.2 and of MoltenVK `main` differ only in SPIRV-Cross's precise-arithmetic helpers (`[[clang::optnone]]` and `fma(l, r, 0)` against `math_mode(safe)` and `fma(l, r, -0.0)`, the SHADER-182 / SHADER-234 change) | Expected with MoltenVK 1.4.2; it passes with MoltenVK `main` |
| On a Mac with MoltenVK 1.4.2, an f16 multiply-add whose three operands are all constants gives a wrong constant: while `cs_fma_fused` had literals there, its word 7 read `15360` (`0x3c00`), or `0` on an Apple M5 and M5 Pro, want `29521` (`0x7351`) | The f16 multiply-add (round to odd), evaluated at compile time. With any one of the three operands taken at run time the same translation gives `0x7351` (Apple M5). The MSL of 1.4.2 and of MoltenVK `main` differ only in SPIRV-Cross's precise-arithmetic helpers (`[[clang::optnone]]` and `fma(l, r, 0)` against `math_mode(safe)` and `fma(l, r, -0.0)`, the SHADER-182 / SHADER-234 change) | `cs_fma_fused` takes its f16 operands at run time since TEST-FMA-FUSED-F16-RUNTIME, as it does its f32 ones, and passes with MoltenVK 1.4.2 on an Apple M5 and on the `macos` job's runner (Apple Paravirtual device), which no longer lists it in `EXPECTED_FAILURES`. The all-literal form passes with MoltenVK `main` |
| `ps_imgatomic` fails in about two of three runs on a Mac with MoltenVK 1.4.2: 1 to 6 of the 256 image-atomic texels are wrong while the render target is exact, for example `2D umax texel 48: got 0x00000d45, want 0x00000dc7` | MoltenVK 1.4.2 lowers the four `OpAtomic*` on image texels to Metal's texture atomics (`atomic_fetch_max`, `atomic_fetch_min` and `atomic_fetch_or` on `access::read_write` textures), and the texels read back the way a read-modify-write that is not atomic between two groups of fragment threads leaves them. A wrong `umax` texel always holds the id of one of its own 64 pixels, the largest of only some of them: on an Apple M5 it was the last pixel of the texel's first four rows in 43 of 90 cases, with all 32 larger ids gone. A wrong `umin` texel mirrors that (the first pixel of its last four rows in 39 of 48). The `or` image did not differ in 150 runs there. It is not the translator's first-lane broadcast of the descriptor index (54 of 60 runs fail with the index used directly) and not the readback (42 of 60 fail with the copies in a submission of their own after the draw). Measured on an Apple M5 (macOS 27.2.1, 101 of 150 runs fail) and an M5 Pro (#543) | Expected with MoltenVK 1.4.2. KosmicKrisp passed the same module and binary 10 times of 10 on the M5 Pro (#543). The macOS CI job does not reach it: on the runner's paravirtual device the test skips because its bindless set does not fit the descriptor limits. Do not weaken the test's expected texels |
| `gs_tri` and `ms_tri` fail on a Mac | MoltenVK has no geometry stage and no `VK_EXT_mesh_shader` | Current `main` reports them as skipped |
| With `LEONIDA_W64_EMULATE=1` on llvmpipe, the `ms_*` tests fail. Measured with Mesa 26.3.1: on x86_64 at 256-bit vectors (the default there) all six abort with "LLVM ERROR: Cannot emit physreg copy instruction"; on arm64 (128-bit) `ms_tri` draws nothing (the frame stays at the clear color); on x86_64 at 128 bits (`LP_NATIVE_VECTOR_WIDTH=128`) `ms_tri` happened to draw correctly, but with Mesa 26.0.3 `ms_wave_info_s3` and `ms_v5_workgroup` draw nothing there (4 of 6 pass, [measured by @TreXito](https://github.com/ItsNotRexed/Leonida/pull/3838#issuecomment-7086696759)) ([measured runs](https://github.com/ItsNotRexed/Leonida/issues/3127#issuecomment-7086469679)) | An llvmpipe bug: a mesh shader's runtime `CullPrimitiveEXT` is stored through an invalid `bitcast <N x i1> to <N x float>` (TEST-782, #3127; see "Without a GPU: Mesa llvmpipe") | Run the mesh tests on llvmpipe without `LEONIDA_W64_EMULATE`, or add `LEONIDA_MESH_COMPUTE=1` (the compute fallback): with it all 6 `ms_*` pass emulated on llvmpipe (x86_64, 256-bit) |
| On a Mac, `valu_fuzz.py --family f16` reads `+0` where the model wants `-0`, from a multiply whose exact product is -0 (`v_mul_f16`, `v_pk_mul_f16`) or from an FMA whose product and addend are both -0 (`v_fma_f16`, `v_fmac_f16`, `v_pk_fma_f16`) | MoltenVK computes a `NoContraction` multiply as `fma(l, r, +0)`, which drops the sign. MoltenVK 1.4.2 and `main` up to at least `5189f8de` are affected (SHADER-182, [design notes](design.md#translator-status-and-runtime-contract)) | Expected with these MoltenVK versions. To run the rest of the fuzzer clean, add `--skip-op` for each of the five ops. To see them match, install Homebrew's `mesa` and use its KosmicKrisp driver: `LEONIDA_VULKAN_LOADER=/opt/homebrew/opt/vulkan-loader/lib/libvulkan.1.dylib VK_DRIVER_FILES=/opt/homebrew/share/vulkan/icd.d/kosmickrisp_mesa_icd.aarch64.json python3 -I tools/valu_fuzz.py --family f16 --build runtime/build/linux`. Or build MoltenVK with SPIRV-Cross `300681bb` or newer in `ExternalRevisions/SPIRV-Cross_repo_revision`, and point `LEONIDA_VULKAN_LOADER` at its `libMoltenVK.dylib` |
| A pixel shader exporting non-canonical f32 NaNs reads back `0x7fc00000` from an RGBA32F color attachment | KosmicKrisp (Mesa 26.3.1), reproduced on Apple M3 Max, M2 Ultra and M1 Pro ([#3125](https://github.com/ItsNotRexed/Leonida/issues/3125)): `nir_to_msl` emits `(NAN)` for `float`-typed NaN constants (`MESA_KK_DEBUG=msl`); MoltenVK 1.4.2 preserved both tested payloads on the same hardware | `ps_nan_payload` allows the measured canonical word only for the NaN channels and only when `vk_harness` reports `driver: KosmicKrisp`. Finite channels and other drivers still require exact words. Integer or storage-buffer readback still canonicalizes constants that NIR infers as `float` (see the `cs_bvh` row below). |
| `cs_bvh` and `cs_bvh32` fail on a Mac with KosmicKrisp: `out[3]` reads `0x7fc00000`, want `0xffffffff` | KosmicKrisp's `nir_to_msl` compiler (Mesa 26.3.1, measured on Apple M2 Ultra, macOS 27.3), not the translator or the buffer format. The triangle branch writes bitcast `float` words and the box branch writes `OpSelect %uint` with `0xffffffff` (`-1`) into the same VGPRs; NIR erases `OpBitcast`, type inference marks the shared register and `bcsel` as `float`, and `nir_to_msl` prints any `float`-typed 32-bit constant in the IEEE-754 NaN range (`0x7f800001..0x7fffffff`, `0xff800001..0xffffffff`) as `(NAN)` (`0x7fc00000`) | Expected with KosmicKrisp in Mesa 26.3.1; MoltenVK 1.4.2 and llvmpipe (Mesa 26.3.1) return `0xffffffff` on the same machine. Do not weaken `vk_compute_test`'s expected BVH words |
| `cs_fma_fused` fails on a Mac with KosmicKrisp: word 7 reads `0x7352`, want `0x7351` | The f16 multiply-add (round to odd), computed at run time, comes out as if the product were rounded first: the exact product, 14988, is halfway between the f16 values 14984 (`0x7351`) and 14992 (`0x7352`), the addend is -2^-22, and one rounding gives `0x7351`. Measured on an Apple M3 with Mesa 26.3.1, 20 of 20 runs (the review of #1724). While the fixture's f16 operands were literals the constant was folded exactly, so the test passed there | Expected with KosmicKrisp in Mesa 26.3.1; MoltenVK 1.4.2 and llvmpipe (Mesa 26.3.1) give `0x7351` on the same machine. The f32 words KosmicKrisp splits are accepted under `--fma glsl`; the f16 word is not, since it does not use `Fma` |
| CMake stops with "needs the Windows SDK 10.0.26100 or newer", or MSVC reports `'Desc_1_2': is not a member of 'D3D12_VERSIONED_ROOT_SIGNATURE_DESC'` | A Windows SDK older than 10.0.26100 (10.0.22621 is the common one), which has no version 1.2 root signatures | `winget install Microsoft.WindowsSDK.10.0.26100`, or add it in the Visual Studio Installer, then delete `runtime/build` and configure again |
| `scripts/build_runtime.ps1` stops at once: "The checkout path ... contains '%'" (`build_llvm_mc.ps1`: "-Temp ... contains '%'") | A `%` in the checkout's path (or in `-Temp`). cmd.exe expands `%...%` in the generated `_build.cmd` (twice on a `CALL` line), and even with that escaped, `cl` rejects a `%` in the path-valued `/D` definitions of the test targets (`D8038: invalid argument`) however it is quoted. Older scripts failed in configure or a few hundred steps into Ninja instead | Move or clone the checkout (or choose a `-Temp`) in a folder without `%` in its path |
| `ctest` lists `fsr_dispatch` and `bvh_builder` as failed (`Not Run`) after clang-cl hits an internal compiler error in `fsr_dispatch_test.cpp` and `bvh_builder_test.cpp` | clang-cl 22.1.8 on Fedora (Linux cross-build) and Windows, plus 22.1.7 on Windows | Use clang-cl 23.1.6 (both files compile on Windows) |
Expand Down
12 changes: 9 additions & 3 deletions runtime/test/shaders/cs_fma_fused.asm
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@
; --fma glsl and --fma khr.
; The operands come in through s4..s7 (VKC_SGPRS=0x3f800800,0x3f800001,0x3f7ffffe,0xbf800002: a, 1+2^-23, 1-2^-23,
; -(1+2^-22)), so a driver cannot fold the multiply-adds at compile time; only the fmaak/fmamk constants are literals.
; The f16 triple is a XOR a literal each (0x3f800800 ^ 0x3f8064e1 = 0x6ce1, ^ 0x3f804a00 = 0x4200, ^ 0x3f808804 =
; 0x8004) for the same reason (TEST-FMA-FUSED-F16-RUNTIME). As three literals the whole f16 multiply-add was a
; compile-time constant, and MoltenVK 1.4.2 gave the wrong one: word 7 read 0x0000 on an Apple M5 (0x3c00 in an
; earlier report), while the same translation with any one of the three taken at run time gave 0x7351.
; Computed at run time the word reads 0x7352 on KosmicKrisp (Mesa 26.3.1, Apple M3), the product-rounded-first
; value: docs/testing.md, Known problems.
; Run: VKC_SGPRS=0x3f800800,0x3f800001,0x3f7ffffe,0xbf800002 vk_compute_test cs_fma_fused.spv 1 dump
; out[0..7] = 33800000 a8800000 3a000400 33800000 33800000 33800000 28800000 00007351 (hex)
; group: 1,1,1
Expand All @@ -47,9 +53,9 @@ buffer_store_dword v12, v20, s[0:3], 0 offen offset:20
v_mov_b32_e32 v13, s7
v_fma_f32 v14, v5, v5, v13
buffer_store_dword v14, v20, s[0:3], 0 offen offset:24
v_mov_b32_e32 v15, 0x6ce1
v_mov_b32_e32 v16, 0x4200
v_mov_b32_e32 v17, 0x8004
v_xor_b32_e32 v15, 0x3f8064e1, v0
v_xor_b32_e32 v16, 0x3f804a00, v0
v_xor_b32_e32 v17, 0x3f808804, v0
v_fma_f16 v18, v15, v16, v17
v_and_b32_e32 v18, 0xffff, v18
buffer_store_dword v18, v20, s[0:3], 0 offen offset:28
Expand Down
4 changes: 4 additions & 0 deletions tests/semantic/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@ instruction family per file; the list below describes some of them, not every fi
modifiers on `v_cvt_f32_ubyte*`/`u32`/`f16` and `v_rcp_iflag_f32`), found by `tools/f32_fuzz.py` (FUZZ-3), and
tests the interpreter's float operations against GLSL.std.450 (signed zeros, undefined inputs, a single-rounding
`Fma`).
- `test_fma_fused_fixture.py` (TEST-FMA-FUSED-F16-RUNTIME) runs the GPU test `cs_fma_fused` in the interpreter with
the four operand words of its header and expects the header's eight words, and checks that every register one of
its multiply-adds reads comes from `s4..s7`: with three literal operands the f16 one was a compile-time constant,
which MoltenVK 1.4.2 gets wrong (`docs/testing.md`, Known problems).
- `test_fixtures.py` checks `tests/semantic/fixtures/disasm/*.s` equals what `regen_fixtures.py` makes from
`runtime/test/shaders/*.asm` (`python tests/semantic/regen_fixtures.py` rewrites them).
- `test_dpp_eager_subgroup.py` (SHADER-529) checks that no DPP ballot or shuffle is left where SPIRV-Cross
Expand Down
96 changes: 96 additions & 0 deletions tests/semantic/test_fma_fused_fixture.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
"""runtime/test/shaders/cs_fma_fused.asm: its eight words, and no multiply-add a compiler can fold
(TEST-FMA-FUSED-F16-RUNTIME).
The fixture takes the operands of its f32 multiply-adds from s4..s7, so that a driver has to compute them at run
time. The three operands of its v_fma_f16 were literals. That made the whole f16 multiply-add a compile-time
constant, and MoltenVK 1.4.2 gave the wrong one: word 7 read 0x0000 on an Apple M5 (0x3c00 in an earlier report)
instead of 0x7351, the cs_fma_fused row of docs/testing.md, while the same translation with any one of the three
operands taken at run time gave 0x7351. The triple is now s4 XOR a literal each.
Checked here, without a GPU: the translated fixture gives the eight words of its header in the interpreter (so the
new operands are the triple the header derives 0x7351 from), and every register a multiply-add reads comes from
s4..s7, so a literal operand cannot come back unnoticed. What a driver does with the module is the GPU test's
business (runtime/test/shaders/check.py, scripts/run_gpu_tests.py).
Standard library only; no GPU, no LLVM, no SPIRV-Tools, no game files.
"""
import os
import re
import struct
import sys
import unittest

HERE = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, HERE)

import support # noqa: E402 (puts tools/ on the path)
import spirv_mini_interp as si # noqa: E402

FIXTURE = os.path.join(HERE, "..", "..", "runtime", "test", "shaders", "cs_fma_fused.asm")
VSHARP = [0, 0, 0x1000, 0x31016FAC] # s[0:3], the output buffer
REG = re.compile(r"(?<![\w.])([vs])(\d+)\b")


def read_fixture():
"""(instruction lines, {header field: text}) of the fixture."""
with open(FIXTURE, encoding="utf-8") as f:
text = f.read()
header = dict(re.findall(r"^; (group|rsrc2|Run|out\[0\.\.7\]):? =? ?(.+)$", text, re.M))
lines = [ln.strip() for ln in text.splitlines() if ln.strip() and not ln.lstrip().startswith(";")]
return lines, header


def run_time_registers(lines):
"""{line index: the VGPR sources of a multiply-add that are not run-time values}, by a pass over the listing: a
VGPR is a run-time value when the instruction that wrote it read s4..s7 or another run-time VGPR."""
run_time, literal_only = set(), {}
for i, line in enumerate(lines):
op, _, rest = line.partition(" ")
regs = REG.findall(rest)
if not op.startswith("v_") or not regs or regs[0][0] != "v":
continue # stores and the like write no VGPR
dst, sources = int(regs[0][1]), regs[1:]
if op.startswith(("v_fma", "v_fmac")):
if op.startswith("v_fmac"):
sources = regs # d += a * b reads its destination as well
literal_only[i] = [f"v{n}" for kind, n in sources if kind == "v" and int(n) not in run_time]
fed = any(kind == "s" and 4 <= int(n) <= 7 or kind == "v" and int(n) in run_time for kind, n in sources)
(run_time.add if fed else run_time.discard)(dst)
return literal_only


class FmaFusedFixture(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.lines, cls.header = read_fixture()

def test_the_eight_words_of_the_header(self):
operands = [int(w, 16) for w in re.search(r"VKC_SGPRS=([0-9a-fx,]+)", self.header["Run"]).group(1).split(",")]
want = [int(w, 16) for w in self.header["out[0..7]"].split("(")[0].split()]
self.assertEqual((len(operands), len(want), want[7]), (4, 8, 0x7351))
group = [int(v) for v in self.header["group"].split(",")]
fssm = bytearray(0x148)
struct.pack_into("<4I", fssm, 0x138, int(self.header["rsrc2"], 0), *group)
spv = support.translate_lines("cs_fma_fused", self.lines, fssm=bytes(fssm))
memory = si.run_workgroup(
spv, 1, 32, inputs_for=lambda i: {"%wg_id": (0, 0, 0), "%local_id": (i, 0, 0), "%sg_lane": i},
push_constants=VSHARP + operands + [0] * 24, memory={})
self.assertEqual([memory.get(4 * k) for k in range(8)], want)

def test_every_multiply_add_reads_run_time_registers_only(self):
literal_only = run_time_registers(self.lines)
self.assertEqual(len(literal_only), 8) # seven f32 forms and the f16 one
for i, regs in literal_only.items():
self.assertEqual(regs, [], f"`{self.lines[i]}` reads {regs}, which only literals fed: a compiler can "
"fold it, and MoltenVK 1.4.2 folds the f16 form to the wrong word")

def test_the_pass_sees_a_literal_operand(self):
# The f16 lines as they were: three literal moves in front of the multiply-add.
old = ["v_mov_b32_e32 v0, s4", "v_mov_b32_e32 v15, 0x6ce1", "v_mov_b32_e32 v16, 0x4200",
"v_mov_b32_e32 v17, 0x8004", "v_fma_f16 v18, v15, v16, v17", "v_fma_f32 v4, v0, v0, -1.0",
"v_mov_b32_e32 v0, 0", "v_fmac_f32_e32 v4, v0, v0"]
self.assertEqual(run_time_registers(old), {4: ["v15", "v16", "v17"], 5: [], 7: ["v0", "v0"]})


if __name__ == "__main__":
unittest.main()
Loading