diff --git a/.github/workflows/runtime.yml b/.github/workflows/runtime.yml index d7e6fd8a68..e355ca32be 100644 --- a/.github/workflows/runtime.yml +++ b/.github/workflows/runtime.yml @@ -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 | diff --git a/docs/testing.md b/docs/testing.md index 62f5ced44a..a41e5d41e5 100644 --- a/docs/testing.md +++ b/docs/testing.md @@ -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 to ` (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) | diff --git a/runtime/test/shaders/cs_fma_fused.asm b/runtime/test/shaders/cs_fma_fused.asm index 31282c47af..c75e14d7ea 100644 --- a/runtime/test/shaders/cs_fma_fused.asm +++ b/runtime/test/shaders/cs_fma_fused.asm @@ -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 @@ -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 diff --git a/tests/semantic/README.md b/tests/semantic/README.md index 5360ab2443..e53b0d3a48 100644 --- a/tests/semantic/README.md +++ b/tests/semantic/README.md @@ -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 diff --git a/tests/semantic/test_fma_fused_fixture.py b/tests/semantic/test_fma_fused_fixture.py new file mode 100644 index 0000000000..901f0109ba --- /dev/null +++ b/tests/semantic/test_fma_fused_fixture.py @@ -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"(?