Skip to content
1 change: 1 addition & 0 deletions docs/design.md

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions runtime/test/shaders/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
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.
Under that, ps_ij_computed isn't built: its computed I/J pair needs PerVertexKHR inputs (or --f16-interp-fallback
without --bary-fallback), 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 +45,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_BARY_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 @@ -225,9 +225,9 @@ 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 is refused under --bary-fallback (whereas --f16-interp-fallback lowers it via
# DerivativeControl): check.py and run_gpu_tests.py report it as SKIP under --bary-fallback.
if 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):",
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 @@ -760,7 +760,7 @@ def salu_ext_test(tools, spirv, env=None):
# 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 (computed I/J pairs use DerivativeControl instead).
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 @@ -2097,9 +2097,10 @@ 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 BARY_FALLBACK:
# Before the .spv check: under --bary-fallback the translator refuses a computed I/J pair (no .spv).
return Skip("SKIP (computed I/J pairs need PerVertexKHR inputs or BaryCoordKHR; "
"unsupported under --bary-fallback)")
if not os.path.isfile(path):
return f"missing {name}.spv"
if name == "ps_cbv_modulate":
Expand Down
10 changes: 5 additions & 5 deletions scripts/run_gpu_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1013,11 +1013,11 @@ 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 bary_fallback():
# Before the .spv check: under --bary-fallback the translator refuses a computed I/J pair, so there
# is no .spv (--f16-interp-fallback alone lowers it via DerivativeControl + BaryCoordKHR).
results.append((name, None, "SKIP (computed I/J pairs need PerVertexKHR inputs or BaryCoordKHR; "
"unsupported under --bary-fallback)"))
continue
if not os.path.isfile(spv):
results.append((name, False, "missing .spv (translation failed)"))
Expand Down
30 changes: 30 additions & 0 deletions tests/semantic/fixtures/ps_ij_computed_deriv_fallback.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
; Hand-written synthetic pixel shader exercising computed I/J interpolation without PerVertexKHR:
; 1. Pristine center f32 read of attr0.x first (matching the 200-shader corpus pattern).
; 2. EXEC-masked branch modifying (v0, v1) on lanes where I > 0.20 (non-uniform across a 2x2 quad),
; then evaluating computed f32 attr0.y and computed f16 low/high halves of attr1.x inside a branch.
v_interp_p1_f32_e32 v6, v0, attr0.x ; encoding: [0x00,0x00,0x00,0x00]
v_interp_p2_f32_e32 v6, v1, attr0.x ; encoding: [0x00,0x00,0x00,0x00]
v_interp_p1_f32_e32 v2, v0, attr0.y ; encoding: [0x00,0x00,0x00,0x00]
v_interp_p2_f32_e32 v2, v1, attr0.y ; encoding: [0x00,0x00,0x00,0x00]
v_mov_b32_e32 v10, v0 ; encoding: [0x00,0x00,0x00,0x00]
v_mov_b32_e32 v11, v1 ; encoding: [0x00,0x00,0x00,0x00]
v_cmp_lt_f32_e32 vcc_lo, 0x3e4ccccd, v0 ; encoding: [0xff,0x00,0x02,0x7c,0xcd,0xcc,0x4c,0x3e]
s_and_saveexec_b32 s4, vcc_lo ; encoding: [0x00,0x00,0x00,0x00]
s_cbranch_execz 4 ; encoding: [0x00,0x00,0x00,0x00]
v_mov_b32_e32 v0, 0.25 ; encoding: [0x00,0x00,0x00,0x00]
v_mov_b32_e32 v1, 0.25 ; encoding: [0x00,0x00,0x00,0x00]
v_interp_p1_f32_e32 v2, v0, attr0.y ; encoding: [0x00,0x00,0x00,0x00]
v_interp_p2_f32_e32 v2, v1, attr0.y ; encoding: [0x00,0x00,0x00,0x00]
s_mov_b32 exec_lo, s4 ; encoding: [0x00,0x00,0x00,0x00]
v_mov_b32_e32 v0, 0 ; encoding: [0x00,0x00,0x00,0x00]
v_mov_b32_e32 v1, 0 ; encoding: [0x00,0x00,0x00,0x00]
v_interp_p1ll_f16 v3, v0, attr1.x ; encoding: [0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00]
v_interp_p2_f16 v3, v1, attr1.x, v3 ; encoding: [0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00]
v_cvt_f32_f16_e32 v3, v3 ; encoding: [0x00,0x00,0x00,0x00]
v_mul_f32_e32 v1, 0.5, v11 ; encoding: [0x00,0x00,0x00,0x00]
v_mov_b32_e32 v0, v10 ; encoding: [0x00,0x00,0x00,0x00]
v_interp_p1ll_f16 v4, v0, attr1.x high ; encoding: [0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00]
v_interp_p2_f16 v4, v1, attr1.x, v4 high ; encoding: [0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00]
v_cvt_f32_f16_e32 v4, v4 ; encoding: [0x00,0x00,0x00,0x00]
exp mrt0 v6, v2, v3, v4 done vm ; encoding: [0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00]
s_endpgm ; encoding: [0x00,0x00,0x00,0x00]
24 changes: 24 additions & 0 deletions tests/semantic/spirv_mini_interp.py
Original file line number Diff line number Diff line change
Expand Up @@ -521,13 +521,32 @@ def advance(i, value):
f"{subgroup_size}-wide subgroup")
ident %= subgroup_size
results.append(group[ident][2] if ident in group else UNDEF)
elif kind in ("OpDPdxFine", "OpDPdyFine"):
# SPIR-V 3.32.16: fine screen-quad derivatives over 2x2 quads (lanes 0:(0,0), 1:(1,0), 2:(0,1),
# 3:(1,1) within each group of 4 contiguous invocations; helper invocations participate).
if invocations % 4 or slots != list(range(invocations)):
raise UnsupportedConstruct(f"{kind} requires complete 2x2 pixel quads (4*n contiguous invocations)")
qbase = i & ~3
lo_idx, hi_idx = ((qbase + (i & 2), qbase + (i & 2) + 1) if kind == "OpDPdxFine"
else (qbase + (i & 1), qbase + 2 + (i & 1)))
lo_v, hi_v = pending[lo_idx][2], pending[hi_idx][2]
diff = lambda h, l: f32(ieee_nan(h - l, h, l)) # noqa: E731
results.append(tuple(diff(h, l) for h, l in zip(hi_v, lo_v)) if isinstance(lo_v, tuple)
else diff(hi_v, lo_v))
else:
raise UnsupportedConstruct(kind)
for i in range(invocations):
advance(i, results[i])
return (memory, invocation_outputs) if return_outputs else memory


def run_quad(text, inputs_for, push_constants=None, memory=None, resources=None):
"""Execute one 2x2 pixel quad (lanes 0:(x,y), 1:(x+1,y), 2:(x,y+1), 3:(x+1,y+1)) and return its four Output dicts."""
_, outs = run_workgroup(text, 4, 4, inputs_for=inputs_for, push_constants=push_constants, memory=memory,
return_outputs=True, resources=resources)
return outs


_TICK = ("tick", None, None, None)
_PARSED = {}

Expand Down Expand Up @@ -1237,6 +1256,11 @@ def _fdiv(p, q):
elif op == "OpConvertUToPtr":
values[res] = ("psb", val(a[1]))
pointers[res] = values[res]
elif op in ("OpDPdxFine", "OpDPdyFine"):
v = val(a[1])
if not (isinstance(v, float) or (isinstance(v, tuple) and all(isinstance(c, float) for c in v))):
raise UnsupportedConstruct(f"{op} on non-float")
values[res] = yield (op, pc - 1, v, None)
elif op == "OpExtInst":
if len(a) < 3 or a[1] != "%glsl":
raise UnsupportedConstruct("extended instruction set")
Expand Down
14 changes: 7 additions & 7 deletions tests/semantic/test_interp_computed_ij.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,22 +293,22 @@ def test_computed_pair_under_bary_fallback(self):
self.refuse(["v_mov_b32_e32 v0, 0", "v_mov_b32_e32 v1, 0",
"v_interp_p1_f32_e32 v2, v0, attr0.x", "v_interp_p2_f32_e32 v2, v1, attr0.x",
"exp mrt0 v2, v2, v2, v2 done vm", "s_endpgm"],
"computed I/J pair under --bary-fallback")
"bary-fallback")
finally:
rdna2spirv.BARY_FALLBACK = old

def test_computed_pair_under_f16_interp_fallback(self):
# --f16-interp-fallback reads decoded halves from the producer: no per-vertex inputs to
# weight with a computed pair (same regime as --bary-fallback)
old = rdna2spirv.F16_HALVES
rdna2spirv.F16_HALVES = True
try:
self.refuse(["v_mov_b32_e32 v0, 0", "v_mov_b32_e32 v1, 0",
"v_interp_p1_f32_e32 v2, v0, attr0.x", "v_interp_p2_f32_e32 v2, v1, attr0.x",
"exp mrt0 v2, v2, v2, v2 done vm", "s_endpgm"],
"computed I/J pair under --f16-interp-fallback")
spv = support.translate_lines("ps_ij_f16_fb", [
"v_mov_b32_e32 v0, 0", "v_mov_b32_e32 v1, 0",
"v_interp_p1_f32_e32 v2, v0, attr0.x", "v_interp_p2_f32_e32 v2, v1, attr0.x",
"exp mrt0 v2, v2, v2, v2 done vm", "s_endpgm"])
finally:
rdna2spirv.F16_HALVES = old
self.assertNotIn("PerVertexKHR", spv)
self.assertIn("OpCapability DerivativeControl", spv)


if __name__ == "__main__":
Expand Down
Loading
Loading