Skip to content
Draft
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: 4 additions & 3 deletions docs/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -648,8 +648,8 @@ fallback"), so the device needs geometry shaders instead.

`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
exports decoded instead (see Macs, below) and run with or without the bary fallback; `run_gpu_tests.py` turns that
on by itself where the device lacks the extension. Under the bary fallback without it they skip.
exports decoded instead (see Macs, below) and run with or without the bary fallback; `run_gpu_tests.py`,
`build.py` and `check.py` turn that on by themselves where the device can't take `PerVertexKHR` inputs. Under the bary fallback without it they skip.

Intel Arc with Mesa ANV currently advertises the native barycentric feature but has a driver bug where translated
pixel shaders can read `BaryCoordKHR.i` as zero (SHADER-925). `make_game.py` detects ANV and automatically translates
Expand All @@ -676,7 +676,8 @@ MoltenVK can't convert to Metal ("PerVertexKHR decoration is not supported in MS
`tools/vk_subgroup_info.py` whether the device can take them and, on MoltenVK, translates with
`--f16-interp-fallback` by itself: the vertex or mesh shader then also exports the decoded f16 halves
(`docs/design.md`, "16-bit interpolation without `PerVertexKHR`"). `LEONIDA_F16_INTERP_FALLBACK=1` or `0` forces it
on or off; `build.py` (for `check.py`) translates with the flag only when that variable is `1`. `ms_f16_pack` also runs
on or off; unset, `build.py` and `check.py` follow the same `per_vertex_inputs` answer, so a standalone `check.py` run
on a Mac takes the fallback too. `ms_f16_pack` also runs
on a Mac with `LEONIDA_MESH_COMPUTE=1 LEONIDA_W64_EMULATE=1`.

## GPUs without VK_KHR_maintenance8 (NVIDIA Pascal and older)
Expand Down
36 changes: 31 additions & 5 deletions runtime/test/shaders/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@
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.
With LEONIDA_F16_INTERP_FALLBACK=1, 16-bit interpolants are translated with --f16-interp-fallback; unset, it is on
where tools/vk_subgroup_info.py reports per_vertex_inputs false (MoltenVK), as in run_gpu_tests.py and check.py.
Under either fallback, ps_ij_computed isn't built: its computed I/J pair needs PerVertexKHR inputs, 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 +47,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 the bary or the f16 interpolation fallback (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 @@ -73,6 +75,30 @@ def barycentric_fallback():
return False


_F16_INTERP_FALLBACK = []


def f16_interp_fallback():
"""LEONIDA_F16_INTERP_FALLBACK=1 (or 0): translate with --f16-interp-fallback. Unset, it follows the device as
scripts/run_gpu_tests.py does: on where tools/vk_subgroup_info.py reports per_vertex_inputs false (MoltenVK, which
can't convert PerVertexKHR inputs to Metal). check.py asks the same question, so the two agree. Cached."""
v = (os.environ.get("LEONIDA_F16_INTERP_FALLBACK") or "").strip().lower()
if v in ("1", "true", "yes", "on"):
return True
if v in ("0", "false", "no", "off"):
return False
if not _F16_INTERP_FALLBACK:
answer = None
try:
r = subprocess.run([sys.executable, "-I", os.path.join(TOOLS, "vk_subgroup_info.py")],
capture_output=True, text=True, timeout=60)
answer = json.loads(r.stdout.strip().splitlines()[-1]).get("per_vertex_inputs")
except (OSError, ValueError, IndexError, subprocess.SubprocessError):
pass
_F16_INTERP_FALLBACK.append(answer is False)
return _F16_INTERP_FALLBACK[0]


def asm_mattr(path):
for ln in Path(path).read_text(encoding="utf-8").splitlines():
s = ln.strip()
Expand Down Expand Up @@ -191,7 +217,7 @@ def translate_tests(work, names):
cmd.append("--bary-fallback")
if os.environ.get("LEONIDA_FMA") in ("glsl", "khr", "exact"): # GLSL Fma (default), OpFmaKHR, or emulated
cmd += ["--fma", os.environ["LEONIDA_FMA"]]
if os.environ.get("LEONIDA_F16_INTERP_FALLBACK") == "1": # f16 interpolation without PerVertexKHR (MoltenVK)
if f16_interp_fallback(): # f16 interpolation without PerVertexKHR (MoltenVK)
cmd.append("--f16-interp-fallback")
if os.environ.get("LEONIDA_TEXOFF_FALLBACK") == "1": # texel offsets without VK_KHR_maintenance8
cmd.append("--texel-offset-fallback")
Expand Down Expand Up @@ -227,7 +253,7 @@ def main():
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":
if barycentric_fallback() or f16_interp_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):",
Expand Down
24 changes: 21 additions & 3 deletions runtime/test/shaders/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,23 @@ def barycentric_fallback():
except (OSError, ValueError, IndexError, subprocess.SubprocessError):
return False


def f16_interp_fallback():
"""LEONIDA_F16_INTERP_FALLBACK=1 (or 0), as build.py reads it; unset, on where tools/vk_subgroup_info.py reports
per_vertex_inputs false (MoltenVK), the answer build.py and scripts/run_gpu_tests.py take too."""
v = (os.environ.get("LEONIDA_F16_INTERP_FALLBACK") or "").strip().lower()
if v in ("1", "true", "yes", "on"):
return True
if v in ("0", "false", "no", "off"):
return False
try:
tools = os.path.abspath(os.path.join(HERE, "..", "..", "..", "tools"))
r = subprocess.run([sys.executable, "-I", os.path.join(tools, "vk_subgroup_info.py")],
capture_output=True, text=True, timeout=60)
return json.loads(r.stdout.strip().splitlines()[-1]).get("per_vertex_inputs") is False
except (OSError, ValueError, IndexError, subprocess.SubprocessError):
return False

# The programs every run needs. Multi-config CMake generators (Visual Studio, Xcode, Ninja Multi-Config) put each of
# them in build/<Config> instead of build/ (TEST-38).
TEST_PROGRAMS = ("vk_compute_test", "vk_store_test", "vk_harness")
Expand Down Expand Up @@ -756,9 +773,10 @@ def salu_ext_test(tools, spirv, env=None):
W64_EMULATED = os.environ.get("LEONIDA_W64_EMULATE") == "1"
# 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.
F16_HALVES = os.environ.get("LEONIDA_F16_INTERP_FALLBACK") == "1"
# The f16 interpolation fallback (LEONIDA_F16_INTERP_FALLBACK, else the device, as build.py decides 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.
F16_HALVES = f16_interp_fallback()
W64X_DUMPS = [("cs_dpp_w64", [1, 0, 3, 2, 5, 4, 7, 6]),
("cs_w64x_readlane", [121, 121, 16, 97, 16, 100, 100, 121]),
("cs_w64x_writelane", [4660, 77, 99, 2748, 0, 0, 4660, 99]),
Expand Down
Loading