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
4 changes: 2 additions & 2 deletions docs/design.md

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion docs/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,9 @@ llvmpipe and some other drivers. Where the device lacks it those four are skippe
To test the fallback that runs them anyway, set `LEONIDA_BARY_FALLBACK=1`, **for both `build.py` and `check.py`**
(or for `run_gpu_tests.py`; CI does this on llvmpipe). The shaders are then translated with `--bary-fallback` and
drawn through a pass-through geometry shader that supplies the barycentrics (`docs/design.md`, "Barycentric
fallback"), so the device needs geometry shaders instead.
fallback"), so the device needs geometry shaders instead. `ps_ij_computed` (a computed I/J pair) also
runs that way: the geometry shader passes it the three vertices' values of the attribute, with or without
`LEONIDA_F16_INTERP_FALLBACK`; only that fallback on its own (Macs) skips it.

`ps_interp_f16_high` and `ms_f16_pack` read 16-bit interpolants as `PerVertexKHR` inputs, which need the extension
too and which `--bary-fallback` can't express. With `LEONIDA_F16_INTERP_FALLBACK=1` they read halves the producer
Expand Down Expand Up @@ -584,6 +586,7 @@ game's device ignores it`, so leaving them set cannot slow a game down (`run_tin
| `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` |
| `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) |
| `ps_ij_computed` is skipped on a Mac, with or without `LEONIDA_BARY_FALLBACK=1` ("computed I/J pairs need per-vertex inputs", or `unsupported: no geometryShader`) | A computed I/J pair needs the three vertices' values of the attribute: `PerVertexKHR` inputs, or under `--bary-fallback` the geometry shader that passes them (`docs/design.md`, "Barycentric fallback"). MoltenVK has neither, and `--f16-interp-fallback` alone has no per-vertex inputs | Expected; nothing to do. Devices with geometry shaders (NVIDIA Pascal, for one) run it with `LEONIDA_BARY_FALLBACK=1` |
| 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 |
Expand Down
16 changes: 9 additions & 7 deletions runtime/test/shaders/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
With LEONIDA_BARY_FALLBACK=1, pixel shaders that read raw barycentrics are translated with --bary-fallback, and
each gets a pass-through geometry shader, <name>.bary_gs.spv, that check.py draws it with (tools/bary_fallback_gs.py).
With the variable unset, build.py/check.py follow the Mesa ANV probe automatically.
Under that or LEONIDA_F16_INTERP_FALLBACK=1, ps_ij_computed isn't built: its computed I/J pair needs PerVertexKHR
inputs, and check.py reports it as SKIP.
A PS with a computed I/J pair (ps_ij_computed) also reads the three vertices' values of the attribute through that
geometry shader. Under LEONIDA_F16_INTERP_FALLBACK=1, ps_ij_computed isn't built: its computed I/J pair needs the
per-vertex values, which that fallback doesn't have, and check.py reports it as SKIP.
With LEONIDA_PC_TAIL_UBO=1, every shader is translated with --pc-tail-ubo (s0..s31 in 128 push-constant bytes, the
heap base and code base in a uniform block at set 1), for devices whose maxPushConstantsSize is 128; set it for
check.py too, whose test programs then bind that block (runtime/test/vk_pc_tail.h).
Expand All @@ -45,7 +46,7 @@

MC = mc_command.mc_command()
RSRC2, GROUP = 0x8088, (64, 1, 1)
# Not built under LEONIDA_BARY_FALLBACK=1 or LEONIDA_F16_INTERP_FALLBACK=1 (see main).
# Not built under LEONIDA_F16_INTERP_FALLBACK=1 (see main).
NEEDS_PER_VERTEX_INPUTS = ("ps_ij_computed",)
sys.path.insert(0, HERE) # this script is also run with python -I
from compute_fixture import compute_header, shift_user_data, user_data_shift # noqa: E402
Expand Down Expand Up @@ -224,12 +225,13 @@ def main():
if skipped:
print("not built (need a DXBC container with signatures):", ", ".join(skipped))
names = [n for n in names if n not in skipped]
# A computed I/J pair needs PerVertexKHR inputs, which both fallbacks take away: the translator refuses it there,
# and check.py and run_gpu_tests.py report it as SKIP. Leave it out instead of losing the whole batch.
if barycentric_fallback() or os.environ.get("LEONIDA_F16_INTERP_FALLBACK") == "1":
# A computed I/J pair needs the three vertices' values, which --f16-interp-fallback doesn't have (--bary-fallback
# gets them from its geometry shader): the translator refuses it there, and check.py and run_gpu_tests.py report
# it as SKIP. Leave it out instead of losing the whole batch.
if os.environ.get("LEONIDA_F16_INTERP_FALLBACK") == "1" and not barycentric_fallback():
per_vertex = [n for n in names if n in NEEDS_PER_VERTEX_INPUTS]
if per_vertex:
print("not built (computed I/J pairs need PerVertexKHR inputs, off under the fallback):",
print("not built (computed I/J pairs need per-vertex inputs, off under --f16-interp-fallback):",
", ".join(per_vertex))
names = [n for n in names if n not in per_vertex]
if not names:
Expand Down
9 changes: 5 additions & 4 deletions runtime/test/shaders/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,8 @@ def heap_init_env():
# LEONIDA_BARY_FALLBACK=1/0 overrides the device probe for raw barycentrics. Unset, Mesa ANV selects the fallback.
BARY_FALLBACK = barycentric_fallback()
# LEONIDA_F16_INTERP_FALLBACK=1 (as build.py reads it): *_f16 interps were translated from decoded-half inputs, with no
# PerVertexKHR inputs at all, so the translator refuses a computed I/J pair (ps_ij_computed) there.
# PerVertexKHR inputs at all, so the translator refuses a computed I/J pair (ps_ij_computed) there. (--bary-fallback
# translates it: its geometry shader passes the three vertices' values.)
F16_HALVES = os.environ.get("LEONIDA_F16_INTERP_FALLBACK") == "1"
W64X_DUMPS = [("cs_dpp_w64", [1, 0, 3, 2, 5, 4, 7, 6]),
("cs_w64x_readlane", [121, 121, 16, 97, 16, 100, 100, 121]),
Expand Down Expand Up @@ -1664,9 +1665,9 @@ def nan_payload_problem(px, out):

def pixel_test(tools, spirv, name):
path = os.path.join(spirv, name + ".spv")
if name == "ps_ij_computed" and (BARY_FALLBACK or F16_HALVES):
# Before the .spv check: without PerVertexKHR inputs the translator refuses a computed I/J pair (no .spv).
return Skip("SKIP (computed I/J pairs need PerVertexKHR inputs: no --bary-fallback / --f16-interp-fallback)")
if name == "ps_ij_computed" and F16_HALVES and not BARY_FALLBACK:
# Before the .spv check: without per-vertex inputs the translator refuses a computed I/J pair (no .spv).
return Skip("SKIP (computed I/J pairs need per-vertex inputs: --f16-interp-fallback without --bary-fallback)")
if not os.path.isfile(path):
return f"missing {name}.spv"
if name in ("ps_texoff", "ps_texoff_implicit", "ps_texoff_forms"):
Expand Down
11 changes: 6 additions & 5 deletions scripts/run_gpu_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -956,11 +956,12 @@ def run_suite(a, work: str) -> int:
for fname in asm_files:
name = os.path.splitext(fname)[0]
spv = os.path.join(spirv_dir, f"{name}.spv")
if name == "ps_ij_computed" and (bary_fallback() or f16_interp_fallback()):
# Before the .spv check: without PerVertexKHR inputs the translator refuses a computed I/J pair, so there
# is no .spv (the f16 fallback is on by default where PerVertexKHR doesn't compile: MoltenVK).
results.append((name, None, "SKIP (computed I/J pairs need PerVertexKHR inputs: "
"no --bary-fallback / --f16-interp-fallback)"))
if name == "ps_ij_computed" and f16_interp_fallback() and not bary_fallback():
# Before the .spv check: without per-vertex inputs the translator refuses a computed I/J pair, so there
# is no .spv (the f16 fallback is on by default where PerVertexKHR doesn't compile: MoltenVK). Under
# --bary-fallback the geometry shader passes the three vertices' values, so it runs.
results.append((name, None, "SKIP (computed I/J pairs need per-vertex inputs: "
"--f16-interp-fallback without --bary-fallback)"))
continue
if not os.path.isfile(spv):
results.append((name, False, "missing .spv (translation failed)"))
Expand Down
6 changes: 4 additions & 2 deletions tests/semantic/support.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,14 @@ def mrt0_words(spvasm, **run_options):
def varyings(spvasm, attrs, bary):
"""Input values for a translated PS, given {attribute n: three per-vertex vec4s of the producer's raw 32-bit
words} and the barycentric weights `bary` of vertices 0..2, as Vulkan hands them over: a PerVertexKHR input gets
the three vertices, a Flat one vertex 0, any other the words read as f32 and interpolated; %bary gets `bary`."""
the three vertices, a Flat one vertex 0, any other the words read as f32 and interpolated; %bary gets `bary`.
A Flat vec4[3] (--bary-fallback's per-vertex attribute) gets the three vertices, as its geometry shader writes
them."""
f = lambda w: struct.unpack("<f", struct.pack("<I", w))[0] # noqa: E731
out = {"%bary": tuple(bary)}
for n, verts in attrs.items():
name, fv = f"%in_attr{n}", [tuple(f(w) for w in v) for v in verts]
if f"OpDecorate {name} PerVertexKHR" in spvasm:
if f"OpDecorate {name} PerVertexKHR" in spvasm or f"{name} = OpVariable %_ptr_Input_pv4 Input" in spvasm:
out[name] = tuple(fv)
elif f"OpDecorate {name} Flat" in spvasm:
out[name] = fv[0]
Expand Down
Loading
Loading