Skip to content
Open
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
7 changes: 7 additions & 0 deletions docs/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,13 @@ runs them anyway, set `LEONIDA_MESH_COMPUTE=1` for `run_gpu_tests.py`, together
compute and drawn by a generated vertex shader (`docs/design.md`, "Mesh shaders as compute"), so the device needs
`bufferDeviceAddress` and `shaderInt64` instead.

A GPU with neither mesh shaders nor fragment barycentrics (Pascal) needs both fallbacks in one draw: `ms_tri_bary`
draws `ms_tri` through `ps_bary`, so with `LEONIDA_MESH_COMPUTE=1 LEONIDA_W64_EMULATE=1 LEONIDA_BARY_FALLBACK=1` the
generated vertex shader feeds `ps_bary`'s pass-through geometry shader. It runs with `--filter ms_tri` and is judged
like `ps_bary`. A native mesh stage can't be followed by a geometry shader, so `LEONIDA_BARY_FALLBACK=1` without
`LEONIDA_MESH_COMPUTE=1` skips it. Passes on a GTX 1050 Ti (NVIDIA 580.196.07, Linux) and on llvmpipe (Mesa 25.0.7)
with both fallbacks.

## Without a GPU: Mesa llvmpipe

Mesa's llvmpipe is a software Vulkan driver (`mesa-vulkan-drivers` on Debian and Ubuntu). CI runs the suite on it
Expand Down
35 changes: 34 additions & 1 deletion scripts/run_gpu_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,36 @@ def check_bary(raw_path: str) -> tuple[bool, str]:
return not problem, problem or "4096/4096 pixels match"


def mesh_bary_case(vk_harness: str, spirv_dir: str, raw_dir: str, gfx_env, run_cmd) -> tuple[bool | None, str]:
"""ms_tri_bary: ms_tri drawn through ps_bary. ms_tri exports attr0 = (0,0), (2,0), (0,2) on the vs_ids triangle,
so ps_bary's raw barycentrics must again be its interpolated attr0.xy / 2 on every pixel (check_bary).
On a device with neither VK_EXT_mesh_shader nor fragment barycentrics (NVIDIA Pascal) this is the one draw where
both fallbacks meet: under LEONIDA_MESH_COMPUTE=1 the mesh shader runs as compute and the generated vertex shader
(tools/mesh_compute_vs.py) feeds ps_bary's pass-through geometry shader (tools/bary_fallback_gs.py). A native mesh
stage can't be followed by a geometry shader (VUID-VkGraphicsPipelineCreateInfo-pStages-02095), so the bary
fallback without --mesh-compute is a skip."""
fs = os.path.join(spirv_dir, "ps_bary.spv")
if not os.path.isfile(fs):
return False, "missing ps_bary.spv"
env = mesh_env(spirv_dir, "ms_tri", gfx_env)
if bary_fallback():
if "VKH_MESH_COMPUTE" not in env:
return None, ("SKIP (--bary-fallback's geometry shader can't follow a native mesh stage; "
"set LEONIDA_MESH_COMPUTE=1)")
gs = os.path.join(spirv_dir, "ps_bary.bary_gs.spv")
if not os.path.isfile(gs):
return False, "missing ps_bary.bary_gs.spv"
env = dict(env, VKH_GS=gs, VKH_GS_HELPER="1")
raw = os.path.join(raw_dir, "ms_tri_bary.raw")
rc, msg = run_readback(raw, run_cmd, [vk_harness, os.path.join(spirv_dir, "ms_tri.spv"), fs, raw], env=env)
if rc == UNSUPPORTED:
return None, unsupported_skip(msg)
if rc != 0:
return False, msg
return check_bary(raw)


def check_bitmask_perm(raw_path: str, msg: str = "") -> tuple[bool | None, str]:
px = read_raw_u32(raw_path)
if skip := bitmask_perm_narrow_skip(msg, px):
Expand Down Expand Up @@ -611,7 +641,8 @@ def check_clip_half(raw_path: str, want_b: float, want_a: float) -> tuple[bool,
"ps_interp_f16_high": "vs_f16_pack.asm", "ms_f16_pack": "ps_interp_f16_high.asm",
"ps_interp_f32_mods": "vs_interp_consts.asm", "ps_interp_mov_mods": "vs_interp_consts.asm",
SIGNED_MIP_TEST: "vs_ids.asm", UINT_MIP_TEST: "vs_ids.asm",
"vs_base_ids": "ps_flat.asm"}
"vs_base_ids": "ps_flat.asm",
"ms_tri": "ps_bary.asm"} # ms_tri_bary: ms_tri drawn through ps_bary (mesh_bary_case)
DRAWN_WITH.update({name: "vs_ids.asm" for name in GET_LOD_TESTS})


Expand Down Expand Up @@ -1424,6 +1455,8 @@ def run_suite(a, work: str) -> int:
else:
ok, detail = check_grad(raw, 0.5, 1.0)
results.append((name, ok, detail))
if name == "ms_tri":
results.append(("ms_tri_bary", *mesh_bary_case(vk_harness, spirv_dir, raw_dir, gfx_env, run_cmd)))
elif name == "ms_f16_pack": # mesh producer of packed f16 params, drawn with ps_interp_f16_high
raw = os.path.join(raw_dir, f"{name}.raw")
env = mesh_env(spirv_dir, name, gfx_env) # VKH_MESH=1, or the --mesh-compute pass and its VS
Expand Down
88 changes: 88 additions & 0 deletions tests/test_run_gpu_tests_mesh_bary.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
"""run_gpu_tests.py: ms_tri_bary (ms_tri drawn through ps_bary) picks its fallback wiring without a GPU.
The case only runs on a device, so a refactor that drops or rewires it would otherwise go unnoticed on machines that
skip it. These checks call mesh_bary_case with the test program stubbed out: the bary fallback without
--mesh-compute must skip with a reason naming LEONIDA_MESH_COMPUTE (a geometry shader can't follow a native mesh
stage), missing fixtures must fail rather than skip, and with both fallbacks the draw must get the generated vertex
shader and ps_bary's pass-through geometry shader."""
import os
from pathlib import Path
import sys
import tempfile
import unittest
from unittest.mock import patch

ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(ROOT / "scripts"))
import run_gpu_tests

NATIVE_MESH = {"VKH_MESH": "1"}
MESH_COMPUTE = {"VKH_MESH_COMPUTE": "ms_tri.mesh_vs.spv", "VKH_MESH_SLOT": "3088", "VKH_MESH_PRIMS": "64"}


def never_run(*args, **kwargs):
raise AssertionError("vk_harness must not run in this case")


class MeshBaryCase(unittest.TestCase):
def setUp(self):
self.tmp = tempfile.TemporaryDirectory()
self.spirv = self.tmp.name
for name in ("ms_tri.spv", "ps_bary.spv", "ps_bary.bary_gs.spv"):
Path(self.spirv, name).write_bytes(b"\x03\x02\x23\x07")

def tearDown(self):
self.tmp.cleanup()

def case(self, mesh_env, bary_fallback, readback=never_run):
env = {"LEONIDA_BARY_FALLBACK": "1" if bary_fallback else "0"}
with patch.dict(os.environ, env), patch.object(run_gpu_tests, "mesh_env", return_value=dict(mesh_env)), \
patch.object(run_gpu_tests, "run_readback", side_effect=readback):
return run_gpu_tests.mesh_bary_case("vk_harness", self.spirv, self.spirv, None, None)

def test_bary_fallback_on_a_native_mesh_stage_skips_with_its_reason(self):
ok, detail = self.case(NATIVE_MESH, bary_fallback=True)
self.assertIsNone(ok)
self.assertTrue(detail.startswith("SKIP"), detail)
self.assertIn("LEONIDA_MESH_COMPUTE=1", detail)

def test_missing_pixel_shader_is_a_failure(self):
os.remove(os.path.join(self.spirv, "ps_bary.spv"))
self.assertEqual(self.case(MESH_COMPUTE, bary_fallback=True), (False, "missing ps_bary.spv"))

def test_missing_geometry_shader_is_a_failure(self):
os.remove(os.path.join(self.spirv, "ps_bary.bary_gs.spv"))
self.assertEqual(self.case(MESH_COMPUTE, bary_fallback=True), (False, "missing ps_bary.bary_gs.spv"))

def test_both_fallbacks_draw_through_the_geometry_shader(self):
seen = {}

def readback(raw, run_cmd, cmd, env=None):
seen.update(cmd=cmd, env=env)
return run_gpu_tests.UNSUPPORTED, "unsupported: stub"

ok, _ = self.case(MESH_COMPUTE, bary_fallback=True, readback=readback)
self.assertIsNone(ok) # the stub reports an unsupported device: a skip, judged after the wiring below
self.assertEqual(seen["cmd"][1:3], [os.path.join(self.spirv, "ms_tri.spv"),
os.path.join(self.spirv, "ps_bary.spv")])
self.assertEqual(seen["env"]["VKH_MESH_COMPUTE"], "ms_tri.mesh_vs.spv")
self.assertEqual(seen["env"]["VKH_GS"], os.path.join(self.spirv, "ps_bary.bary_gs.spv"))
self.assertEqual(seen["env"]["VKH_GS_HELPER"], "1")

def test_without_the_bary_fallback_no_geometry_shader_is_added(self):
seen = {}

def readback(raw, run_cmd, cmd, env=None):
seen.update(env=env)
return run_gpu_tests.UNSUPPORTED, "unsupported: stub"

self.case(NATIVE_MESH, bary_fallback=False, readback=readback)
self.assertNotIn("VKH_GS", seen["env"])
self.assertEqual(seen["env"]["VKH_MESH"], "1")

def test_ms_tri_brings_ps_bary(self):
self.assertEqual(run_gpu_tests.with_draw_shaders(["ms_tri.asm"]), ["ms_tri.asm", "ps_bary.asm"])


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