Skip to content
Closed
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
2 changes: 1 addition & 1 deletion docs/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,7 @@ game's device ignores it`, so leaving them set cannot slow a game down (`run_tin
| `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). |
| 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`, and so do the exact-word pixel tests that expect a NaN word (`ps_cndmask_sign_mods`, `ps_valu16_mad_sel`; `kosmickrisp_canonical_f32` in `check.py`, also used by `run_gpu_tests.py`). 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 |
| 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 |
Expand Down
27 changes: 25 additions & 2 deletions runtime/test/shaders/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -2070,6 +2070,30 @@ def barycentric_problem(px: list[tuple[float, float, float, float]], abs_tol: fl
return ""


def kosmickrisp(out):
"""Whether a test program's output names Mesa's KosmicKrisp driver (vk_harness's "driver: KosmicKrisp")."""
return "driver: KosmicKrisp" in out.splitlines()


def f32_nan(word):
return (word & 0x7F800000) == 0x7F800000 and word & 0x007FFFFF != 0


def kosmickrisp_canonical_f32(actual, expected, out):
"""KosmicKrisp (Mesa 26.3.1) writes any f32 NaN to an RGBA32F attachment as 0x7fc00000 (#3125, docs/testing.md):
where a test expects another NaN word, that canonical word is all the device can show."""
return f32_nan(expected) and actual == 0x7FC00000 and kosmickrisp(out)


def pixel_words_problem(px, want, out):
""""" when every pixel is the `want` words, else how many differ. On KosmicKrisp an expected f32 NaN may read back
as the canonical 0x7fc00000 (kosmickrisp_canonical_f32); every other word stays exact."""
def differs(p):
return any(a != e and not kosmickrisp_canonical_f32(a, e, out) for a, e in zip(p, want))
wrong = [p for p in px if differs(p)]
return "" if not wrong else f"{len(wrong)} of {len(px)} pixels differ, e.g. {[hex(x) for x in wrong[0]]}"


def nan_payload_problem(px, out):
"""Check the exact words, except for the measured KosmicKrisp RGBA32F canonicalization (#3125)."""
if len(px) != 64 * 64:
Expand Down Expand Up @@ -2120,8 +2144,7 @@ def pixel_test(tools, spirv, name):
if name == NAN_PAYLOAD_TEST:
return nan_payload_problem(px, out)
if name in PIXEL_BITS:
wrong = sum(p != PIXEL_BITS[name] for p in px)
return "" if not wrong else f"{wrong} of {n} pixels differ, e.g. {[hex(x) for x in next(p for p in px if p != PIXEL_BITS[name])]}"
return pixel_words_problem(px, PIXEL_BITS[name], out)
if name == "ps_bary":
return barycentric_problem(px, 1e-6)
if name == "ps_persp_bary":
Expand Down
11 changes: 8 additions & 3 deletions scripts/run_gpu_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
unpinned_subgroup_skip, vcmpx_forms_narrow_skip, wave32_lane_skip) # as in check.py
from check import PIXEL_VERTEX, VINT_ENV, interp_f16_high_problem, ij_computed_problem, mandelbrot_problem # pixel producers and checks
from check import barycentric_problem
from check import NAN_PAYLOAD_TEST, nan_payload_problem
from check import NAN_PAYLOAD_TEST, kosmickrisp, nan_payload_problem, pixel_words_problem
from check import GET_LOD_TESTS, STORE_WORDS, get_lod_test, store_words_problem # TEST-184: image atomics and queries
from check import wide_pixel_skip # ps_w64x_readlane: judged only where the fragment stage was required 64-wide
from check import FMA_FUSED_ENV, judge_fma_fused # cs_fma_fused: strict under LEONIDA_FMA=khr, fused/split under glsl
Expand Down Expand Up @@ -457,10 +457,15 @@ def judge_cs_dump(rc: int, msg: str, want: list[int], *, wave64: bool, partial:
return words_match(vals, want), " ".join((hex if hexwords else str)(x) for x in vals)


def check_pixel_const(raw_path: str, want: tuple[int, int, int, int]) -> tuple[bool, str]:
def check_pixel_const(raw_path: str, want: tuple[int, int, int, int], out: str = "") -> tuple[bool, str]:
"""Every pixel exact, except that on KosmicKrisp an expected f32 NaN may read back as the canonical 0x7fc00000
(check.py's kosmickrisp_canonical_f32; `out` is the test program's output, which names the driver)."""
px = read_raw_u32(raw_path)
if len(px) != 64 * 64:
return False, f"expected 4096 pixels, got {len(px)}"
if kosmickrisp(out) and not pixel_words_problem(px, want, out):
exact = all(p == want for p in px)
return True, "4096/4096 pixels exact" if exact else "4096/4096 pixels exact but for KosmicKrisp's canonical NaN"
bad = [(i, p) for i, p in enumerate(px) if p != want]
if bad:
i, p = bad[0]
Expand Down Expand Up @@ -1567,7 +1572,7 @@ def run_suite(a, work: str) -> int:
if name == "ps_vcmpx_forms" and (skip := vcmpx_forms_narrow_skip(msg)):
ok, detail = None, str(skip)
else:
ok, detail = check_pixel_const(raw, const_wants[name])
ok, detail = check_pixel_const(raw, const_wants[name], msg)
elif name == NAN_PAYLOAD_TEST:
problem = nan_payload_problem(read_raw_u32(raw), msg)
ok, detail = not problem, problem or "4096/4096 pixels match the driver-aware NaN payload check"
Expand Down
28 changes: 28 additions & 0 deletions tests/test_shader_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -1213,6 +1213,34 @@ def test_a_dropped_or_swapped_offset_fails(self):
self.assertIn("pixels differ", problem)


class KosmicKrispCanonicalNaN(unittest.TestCase):
"""KosmicKrisp writes every f32 NaN to an RGBA32F attachment as 0x7fc00000 (docs/testing.md): an exact-word pixel
test accepts that word in a channel that expects a NaN, on that driver only."""
KK = "device: Apple M3\ndriver: KosmicKrisp\n"
OTHER = "device: Apple M3\ndriver: MoltenVK\n"

def test_a_nan_channel_may_read_canonical_on_kosmickrisp_only(self):
want = check.PIXEL_BITS["ps_cndmask_sign_mods"] # (0xff800001, 0x7f800001, 0x80000001, ...)
canonical = tuple(0x7FC00000 if check.f32_nan(w) else w for w in want)
self.assertNotEqual(canonical, want)
self.assertEqual(check.pixel_words_problem([canonical] * 4096, want, self.KK), "")
self.assertIn("4096 of 4096", check.pixel_words_problem([canonical] * 4096, want, self.OTHER))
self.assertEqual(check.pixel_words_problem([want] * 4096, want, self.OTHER), "")

def test_only_the_canonical_word_and_only_in_a_nan_channel(self):
want = check.PIXEL_BITS["ps_valu16_mad_sel"] # channel 2 is 0xffffffff, a NaN
other_nan = tuple(0x7FC00001 if check.f32_nan(w) else w for w in want)
self.assertIn("pixels differ", check.pixel_words_problem([other_nan] * 4096, want, self.KK))
finite_changed = (want[0] ^ 1, *want[1:]) # channel 0 is not a NaN
self.assertIn("pixels differ", check.pixel_words_problem([finite_changed] * 4096, want, self.KK))

def test_the_nan_test(self):
self.assertTrue(check.f32_nan(0x7F800001))
self.assertTrue(check.f32_nan(0xFFFFFFFF))
self.assertFalse(check.f32_nan(0x7F800000)) # +inf
self.assertFalse(check.f32_nan(0x3F800000))


class PixelTestRegistry(unittest.TestCase):
def test_pixel_tests_include_every_pixel_fixture(self):
# A repeated PIXEL_TESTS assignment silently dropped ps_texoff once; keep the registry explicit.
Expand Down