From 71db4c4051492c2ccd7a6cd67c2872d88d36cc21 Mon Sep 17 00:00:00 2001 From: Zack Date: Sun, 29 Nov 2026 05:04:10 -0800 Subject: [PATCH] test(semantic): align computed-I/J f16 interp oracle with toward-zero p2 narrow Update `tests/semantic/test_interp_computed_ij_fallback.py` (#2239) to narrow `v_interp_p2_f16` reference expectations toward zero (`f16_rtz` / `f16_rtz_bits`), matching `SHADER-468` (#1181). AI-assisted. --- .../test_interp_computed_ij_fallback.py | 38 ++++++++++++++++--- 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/tests/semantic/test_interp_computed_ij_fallback.py b/tests/semantic/test_interp_computed_ij_fallback.py index 7cccca54ea..863e6d66eb 100644 --- a/tests/semantic/test_interp_computed_ij_fallback.py +++ b/tests/semantic/test_interp_computed_ij_fallback.py @@ -18,6 +18,7 @@ """ from __future__ import annotations +import bisect import math import os import pathlib @@ -49,6 +50,27 @@ def pack_f16_pair(lo: float, hi: float) -> int: return struct.unpack(" int: + """Narrow ``x`` to f16 bits toward zero, matching v_interp_p2_f16 (SHADER-468).""" + if math.isnan(x): + return 0x7E00 + if math.isinf(x): + return 0x7C00 | (0x8000 if x < 0 else 0) + sign = 0x8000 if x < 0 else 0 + a = abs(x) + if a >= 65520.0: + return sign | 0x7BFF + i = bisect.bisect_right(_F16_POS, a) - 1 + return sign | (i if i >= 0 else 0) + + +def f16_rtz(x: float) -> float: + return half_to_float(f16_rtz_bits(x)) + + def ulp32(x: float) -> float: """Binary32 ULP of f32(x) (subnormal-aware, distinct from Python's binary64 math.ulp).""" v = abs(f32(x)) @@ -241,11 +263,12 @@ def test_perspective_fixture_branch_and_f16_halves(self): self.assertLess(abs(got[0] - want_x), 2e-6) self.assertLess(abs(got[1] - ref_y), 2e-6) self.assertLess(abs(got[1] - want_y), 1e-4) - # On 64x64 (|alpha| + |beta| <= 32 px), 1.5 narrows to exact f16 (0 ulp); see 2048px test below for wide drift. - self.assertEqual(got[2], float(struct.unpack(" list[str]: quad1, _ = perspective_quad_inputs(spv_one, self.VERTS_PERSP, {1: self.ATTR1_WORDS}) outs0 = run_quad(spv_zero, lambda lane: quad0[lane]) outs1 = run_quad(spv_one, lambda lane: quad1[lane]) - # LO_HALVES = (1.5, 3.5, 5.5) at (0.25, 0.5) -> 1.5 + 0.25*2.0 + 0.5*4.0 = 4.0 (f16 0x4400). + # LO_HALVES = (1.5, 3.5, 5.5) at (0.25, 0.5) -> analytical 4.0 (0x4400); 1-pixel binary32 quad + # quantization lands ~3e-6..3e-7 below 4.0, which v_interp_p2_f16 narrows toward zero (SHADER-468) to 0x43ff. for lane in range(4): + ref_p1lv, _, _ = quad_jacobian_ref64(quad0, lane, 0.25, 0.5, "%in_f16h1_0", 0) self.assertEqual(outs0[lane]["%out_mrt0"], outs1[lane]["%out_mrt0"]) - self.assertEqual(outs0[lane]["%out_mrt0"][0] & 0xFFFF, 0x4400) + self.assertEqual(outs0[lane]["%out_mrt0"][0] & 0xFFFF, f16_rtz_bits(ref_p1lv)) + self.assertEqual(outs0[lane]["%out_mrt0"][0] & 0xFFFF, 0x43FF) def test_1080p_perspective_precision_subpixel_vs_full_viewport_jump(self): """At 1920x1080 with perspective W = (1.0, 2.5, 4.0), sub-pixel barycentric shifts stay within ~5e-6, while