diff options
| author | ItsNotRexed <300290919+ItsNotRexed@users.noreply.github.com> | 2026-11-21 20:38:54 -0500 |
|---|---|---|
| committer | ItsNotRexed <300290919+ItsNotRexed@users.noreply.github.com> | 2026-11-21 20:38:54 -0500 |
| commit | d11e39bb3967d94de4333c0c0b23e7e847b2e3e5 (patch) | |
| tree | 731c53d4860ec95b4fce0a93ee9661cb5413e84c /tests | |
| parent | fa7f38b45f043408a75e1f0cc5d04d69058c0279 (diff) | |
| parent | 14d81dd093e91c2f9b4a21f74fe0db2d26db1199 (diff) | |
Merge pull request #599 from LuanFreitas
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/semantic/spirv_mini_interp.py | 12 | ||||
| -rw-r--r-- | tests/semantic/test_buffer_load_format.py | 66 | ||||
| -rw-r--r-- | tests/test_mem_diff.py | 24 |
3 files changed, 81 insertions, 21 deletions
diff --git a/tests/semantic/spirv_mini_interp.py b/tests/semantic/spirv_mini_interp.py index a4b871f22..8bb599003 100644 --- a/tests/semantic/spirv_mini_interp.py +++ b/tests/semantic/spirv_mini_interp.py | |||
| @@ -709,10 +709,16 @@ def _invocation(text, inputs, push_constants, memory, step=False): | |||
| 709 | values[res] = x or y | 709 | values[res] = x or y |
| 710 | elif op == "OpLogicalNot": | 710 | elif op == "OpLogicalNot": |
| 711 | values[res] = not val(a[1]) | 711 | values[res] = not val(a[1]) |
| 712 | elif op in ("OpFAdd", "OpFSub", "OpFMul"): | 712 | elif op in ("OpFAdd", "OpFSub", "OpFMul", "OpFDiv"): |
| 713 | x, y = val(a[1]), val(a[2]) | 713 | x, y = val(a[1]), val(a[2]) |
| 714 | fn = (lambda p, q: f32(p + q)) if op == "OpFAdd" else ( | 714 | |
| 715 | (lambda p, q: f32(p - q)) if op == "OpFSub" else (lambda p, q: f32(p * q))) | 715 | def _fdiv(p, q): |
| 716 | if q != 0.0: | ||
| 717 | return f32(p / q) | ||
| 718 | return f32(math.copysign(math.inf, p) if p != 0.0 else math.nan) | ||
| 719 | |||
| 720 | fn = {"OpFAdd": (lambda p, q: f32(p + q)), "OpFSub": (lambda p, q: f32(p - q)), | ||
| 721 | "OpFMul": (lambda p, q: f32(p * q)), "OpFDiv": _fdiv}[op] | ||
| 716 | if isinstance(x, tuple) and isinstance(y, tuple) and len(x) == len(y) and all( | 722 | if isinstance(x, tuple) and isinstance(y, tuple) and len(x) == len(y) and all( |
| 717 | isinstance(p, float) and isinstance(q, float) for p, q in zip(x, y)): | 723 | isinstance(p, float) and isinstance(q, float) for p, q in zip(x, y)): |
| 718 | values[res] = tuple(fn(p, q) for p, q in zip(x, y)) | 724 | values[res] = tuple(fn(p, q) for p, q in zip(x, y)) |
diff --git a/tests/semantic/test_buffer_load_format.py b/tests/semantic/test_buffer_load_format.py index 0e6a369a4..d20706f4c 100644 --- a/tests/semantic/test_buffer_load_format.py +++ b/tests/semantic/test_buffer_load_format.py | |||
| @@ -7,6 +7,8 @@ OpSelect), so every dword-aligned load here also checks that the merge keeps its | |||
| 7 | 7 | ||
| 8 | Integer and f16 formats are used: their decode is exact, so the expected words need no rounding model. | 8 | Integer and f16 formats are used: their decode is exact, so the expected words need no rounding model. |
| 9 | """ | 9 | """ |
| 10 | from __future__ import annotations | ||
| 11 | |||
| 10 | import os | 12 | import os |
| 11 | import struct | 13 | import struct |
| 12 | import sys | 14 | import sys |
| @@ -30,7 +32,10 @@ BASE = 0x1000 | |||
| 30 | MEMORY = {BASE: 0x11223344, BASE + 4: 0xDEADBEEF, BASE + 8: 0xCAFEF00D, BASE + 12: 0x0BADC0DE} | 32 | MEMORY = {BASE: 0x11223344, BASE + 4: 0xDEADBEEF, BASE + 8: 0xCAFEF00D, BASE + 12: 0x0BADC0DE} |
| 31 | # V# FORMAT codes (word3 bits 12-18), from rdna2spirv.FORMATS | 33 | # V# FORMAT codes (word3 bits 12-18), from rdna2spirv.FORMATS |
| 32 | FMT_U32, FMT_U32X2, FMT_U32X4, FMT_UINT8X4, FMT_UINT16X2, FMT_UINT16X4, FMT_F16 = 20, 62, 75, 60, 27, 69, 13 | 34 | FMT_U32, FMT_U32X2, FMT_U32X4, FMT_UINT8X4, FMT_UINT16X2, FMT_UINT16X4, FMT_F16 = 20, 62, 75, 60, 27, 69, 13 |
| 35 | FMT_F32, FMT_F32X2, FMT_F32X3, FMT_UNORM8, FMT_UNORM8X4 = 22, 64, 74, 1, 56 | ||
| 33 | DST_SEL_XYZW = 4 | 5 << 3 | 6 << 6 | 7 << 9 | 36 | DST_SEL_XYZW = 4 | 5 << 3 | 6 << 6 | 7 << 9 |
| 37 | # DST_SEL (X, 0, 1, 1): code 4, 0, 1, 1 — SHADER-86 measures float 1.0 vs integer 1 | ||
| 38 | DST_SEL_X_0_1_1 = 4 | 0 << 3 | 1 << 6 | 1 << 9 | ||
| 34 | 39 | ||
| 35 | _TMP_DIR = None | 40 | _TMP_DIR = None |
| 36 | _SRC_PATH = None | 41 | _SRC_PATH = None |
| @@ -53,8 +58,9 @@ def tearDownModule(): | |||
| 53 | _TMP_DIR = None | 58 | _TMP_DIR = None |
| 54 | 59 | ||
| 55 | 60 | ||
| 56 | def load_format(fmt: int, offset: int, ncomp: int = 4) -> tuple: | 61 | def load_format(fmt: int, offset: int, ncomp: int = 4, dst_sel: int = DST_SEL_XYZW, |
| 57 | """buffer_load_format_<x..xyzw> of format `fmt` at byte `offset` of MEMORY; returns the four mrt0 words.""" | 62 | memory: dict | None = None) -> tuple: |
| 63 | """buffer_load_format_<x..xyzw> of format `fmt` at byte `offset`; returns the four mrt0 words.""" | ||
| 58 | if _TMP_DIR is None: | 64 | if _TMP_DIR is None: |
| 59 | setUpModule() | 65 | setUpModule() |
| 60 | suffix = "xyzw"[:ncomp] | 66 | suffix = "xyzw"[:ncomp] |
| @@ -65,7 +71,7 @@ def load_format(fmt: int, offset: int, ncomp: int = 4) -> tuple: | |||
| 65 | f"\ts_mov_b32 s0, {BASE:#x}\n" | 71 | f"\ts_mov_b32 s0, {BASE:#x}\n" |
| 66 | "\ts_mov_b32 s1, 0\n" # base high bits 0, stride 0 (raw) | 72 | "\ts_mov_b32 s1, 0\n" # base high bits 0, stride 0 (raw) |
| 67 | "\ts_mov_b32 s2, 0x100\n" # num_records (bytes) | 73 | "\ts_mov_b32 s2, 0x100\n" # num_records (bytes) |
| 68 | f"\ts_mov_b32 s3, {fmt << 12 | DST_SEL_XYZW:#x}\n" | 74 | f"\ts_mov_b32 s3, {fmt << 12 | dst_sel:#x}\n" |
| 69 | f"\tv_mov_b32 v1, {offset:#x}\n" | 75 | f"\tv_mov_b32 v1, {offset:#x}\n" |
| 70 | f"\tbuffer_load_format_{suffix} {vdata}, v1, s[0:3], 0 offen\n" | 76 | f"\tbuffer_load_format_{suffix} {vdata}, v1, s[0:3], 0 offen\n" |
| 71 | "\ts_waitcnt vmcnt(0)\n" | 77 | "\ts_waitcnt vmcnt(0)\n" |
| @@ -77,7 +83,11 @@ def load_format(fmt: int, offset: int, ncomp: int = 4) -> tuple: | |||
| 77 | with warnings.catch_warnings(): | 83 | with warnings.catch_warnings(): |
| 78 | warnings.simplefilter("ignore", ResourceWarning) | 84 | warnings.simplefilter("ignore", ResourceWarning) |
| 79 | spv = rdna2spirv.translate(_SRC_PATH) | 85 | spv = rdna2spirv.translate(_SRC_PATH) |
| 80 | return si.run_fragment(spv, memory=dict(MEMORY))["%out_mrt0"] | 86 | return si.run_fragment(spv, memory=dict(memory if memory is not None else MEMORY))["%out_mrt0"] |
| 87 | |||
| 88 | |||
| 89 | def f32_bits(x: float) -> int: | ||
| 90 | return struct.unpack("<I", struct.pack("<f", x))[0] | ||
| 81 | 91 | ||
| 82 | 92 | ||
| 83 | def f16_word(h: int) -> int: | 93 | def f16_word(h: int) -> int: |
| @@ -134,6 +144,50 @@ class CrossingDwordBoundary(unittest.TestCase): | |||
| 134 | self.assertEqual(load_format(FMT_UINT16X4, 6), (0xDEAD, 0xF00D, 0xCAFE, 0xC0DE)) | 144 | self.assertEqual(load_format(FMT_UINT16X4, 6), (0xDEAD, 0xF00D, 0xCAFE, 0xC0DE)) |
| 135 | 145 | ||
| 136 | 146 | ||
| 147 | class MissingComponentsRepeat(unittest.TestCase): | ||
| 148 | """SHADER-86 / RX 6700: missing channels are c mod n, not 0 or 1.""" | ||
| 149 | |||
| 150 | def test_one_component_formats_xxxx(self): | ||
| 151 | self.assertEqual(load_format(FMT_U32, 4), (0xDEADBEEF,) * 4) | ||
| 152 | self.assertEqual(load_format(FMT_F32, 4), (0xDEADBEEF,) * 4) | ||
| 153 | # 8_UNORM at offset 4: low byte 0xEF → 239/255; all four channels match. | ||
| 154 | want = f32_bits(239.0 / 255.0) | ||
| 155 | self.assertEqual(load_format(FMT_UNORM8, 4), (want,) * 4) | ||
| 156 | |||
| 157 | def test_two_and_three_component_xyxy_and_xyzx(self): | ||
| 158 | self.assertEqual(load_format(FMT_U32X2, 4), (0xDEADBEEF, 0xCAFEF00D, 0xDEADBEEF, 0xCAFEF00D)) | ||
| 159 | self.assertEqual(load_format(FMT_F32X2, 4), (0xDEADBEEF, 0xCAFEF00D, 0xDEADBEEF, 0xCAFEF00D)) | ||
| 160 | self.assertEqual(load_format(FMT_F32X3, 0), (0x11223344, 0xDEADBEEF, 0xCAFEF00D, 0x11223344)) | ||
| 161 | |||
| 162 | |||
| 163 | class UnormCorrectlyRounded(unittest.TestCase): | ||
| 164 | """SHADER-86: UNORM is OpFDiv by (2^n-1), not a reciprocal multiply. Raw 3 → 0x3c40c0c1.""" | ||
| 165 | |||
| 166 | def test_unorm8x4_raw_3(self): | ||
| 167 | mem = {BASE: 0x03030303} | ||
| 168 | want = 0x3C40C0C1 | ||
| 169 | self.assertEqual(load_format(FMT_UNORM8X4, 0, memory=mem), (want,) * 4) | ||
| 170 | # f32 reciprocal multiply disagrees (BetterJdue: 504 mismatches on rgba8). | ||
| 171 | recip = f32_bits(struct.unpack("<f", struct.pack("<f", 3.0))[0] | ||
| 172 | * struct.unpack("<f", struct.pack("<f", 1.0 / 255.0))[0]) | ||
| 173 | self.assertNotEqual(want, recip) | ||
| 174 | |||
| 175 | |||
| 176 | class DstSelOneByFormat(unittest.TestCase): | ||
| 177 | """SHADER-86: DST_SEL 1 is 1.0f for float/unorm, integer 1 for UINT.""" | ||
| 178 | |||
| 179 | def test_dst_sel_one_float_vs_uint(self): | ||
| 180 | # DST_SEL (X, 0, 1, 1): Z and W come from the constant-1 code. | ||
| 181 | f32 = load_format(FMT_F32, 4, dst_sel=DST_SEL_X_0_1_1) | ||
| 182 | self.assertEqual(f32, (0xDEADBEEF, 0, 0x3F800000, 0x3F800000)) | ||
| 183 | u32 = load_format(FMT_U32, 4, dst_sel=DST_SEL_X_0_1_1) | ||
| 184 | self.assertEqual(u32, (0xDEADBEEF, 0, 1, 1)) | ||
| 185 | unorm = load_format(FMT_UNORM8, 4, dst_sel=DST_SEL_X_0_1_1) | ||
| 186 | self.assertEqual(unorm[2:], (0x3F800000, 0x3F800000)) | ||
| 187 | u8 = load_format(FMT_UINT8X4, 4, dst_sel=DST_SEL_X_0_1_1) | ||
| 188 | self.assertEqual(u8[2:], (1, 1)) | ||
| 189 | |||
| 190 | |||
| 137 | class InterpreterConversions(unittest.TestCase): | 191 | class InterpreterConversions(unittest.TestCase): |
| 138 | """The ops the format decode needs from spirv_mini_interp: integer to float and GLSL FMin/FMax.""" | 192 | """The ops the format decode needs from spirv_mini_interp: integer to float and GLSL FMin/FMax.""" |
| 139 | 193 | ||
| @@ -159,6 +213,10 @@ class InterpreterConversions(unittest.TestCase): | |||
| 159 | self.assertEqual(self.run_expr(consts, "%r = OpExtInst %float %glsl FMax %a %b\n"), 0x3FC00000) | 213 | self.assertEqual(self.run_expr(consts, "%r = OpExtInst %float %glsl FMax %a %b\n"), 0x3FC00000) |
| 160 | self.assertEqual(self.run_expr(consts, "%r = OpExtInst %float %glsl FMin %a %b\n"), 0xC0000000) | 214 | self.assertEqual(self.run_expr(consts, "%r = OpExtInst %float %glsl FMin %a %b\n"), 0xC0000000) |
| 161 | 215 | ||
| 216 | def test_fdiv_correctly_rounded(self): | ||
| 217 | consts = "%a = OpConstant %float 3\n%b = OpConstant %float 255\n" | ||
| 218 | self.assertEqual(self.run_expr(consts, "%r = OpFDiv %float %a %b\n"), 0x3C40C0C1) | ||
| 219 | |||
| 162 | 220 | ||
| 163 | if __name__ == "__main__": | 221 | if __name__ == "__main__": |
| 164 | unittest.main() | 222 | unittest.main() |
diff --git a/tests/test_mem_diff.py b/tests/test_mem_diff.py index 4a1ded18e..a46249860 100644 --- a/tests/test_mem_diff.py +++ b/tests/test_mem_diff.py | |||
| @@ -39,10 +39,7 @@ class Harness(unittest.TestCase): | |||
| 39 | self.assertEqual(counts["mismatch"], 0, first) | 39 | self.assertEqual(counts["mismatch"], 0, first) |
| 40 | self.assertEqual(counts["harness-error"], 0, first) | 40 | self.assertEqual(counts["harness-error"], 0, first) |
| 41 | self.assertEqual(counts["skip"], {}, counts["skip"]) | 41 | self.assertEqual(counts["skip"], {}, counts["skip"]) |
| 42 | # Two typed-buffer questions await a hardware measurement and are counted apart (see mem_diff.py). | 42 | self.assertEqual(counts["pass"], 60) |
| 43 | self.assertEqual(counts["pass"] + counts["norm-ulp1"] + counts["missing-w32"], 60) | ||
| 44 | if family != "buffer_format": | ||
| 45 | self.assertEqual(counts["pass"], 60) | ||
| 46 | 43 | ||
| 47 | 44 | ||
| 48 | class Reference(unittest.TestCase): | 45 | class Reference(unittest.TestCase): |
| @@ -95,29 +92,28 @@ class FormatDecode(unittest.TestCase): | |||
| 95 | def test_decode_examples(self): | 92 | def test_decode_examples(self): |
| 96 | # 8_8_8_8_UINT: X in the low byte; four channels, nothing missing. | 93 | # 8_8_8_8_UINT: X in the low byte; four channels, nothing missing. |
| 97 | self.assertEqual(md.decode_element(0xDDCCBBAA, [8, 8, 8, 8], "UINT"), [0xAA, 0xBB, 0xCC, 0xDD]) | 94 | self.assertEqual(md.decode_element(0xDDCCBBAA, [8, 8, 8, 8], "UINT"), [0xAA, 0xBB, 0xCC, 0xDD]) |
| 98 | # 16_16_SNORM: X = 0x8000 clamps to -1.0, Y = 0x7FFF is 1.0; Z/W missing -> 0, 1.0. | 95 | # 16_16_SNORM: X = 0x8000 clamps to -1.0, Y = 0x7FFF is 1.0; Z/W repeat XYXY (SHADER-86). |
| 99 | self.assertEqual(md.decode_element(0x7FFF8000, [16, 16], "SNORM"), [0xBF800000, 0x3F800000, 0, 0x3F800000]) | 96 | self.assertEqual(md.decode_element(0x7FFF8000, [16, 16], "SNORM"), |
| 97 | [0xBF800000, 0x3F800000, 0xBF800000, 0x3F800000]) | ||
| 100 | # 2_10_10_10_UNORM: X10 at bit 0 ... W2 at bit 30. All ones in X, W = 3 -> 1.0, Y = Z = 0. | 98 | # 2_10_10_10_UNORM: X10 at bit 0 ... W2 at bit 30. All ones in X, W = 3 -> 1.0, Y = Z = 0. |
| 101 | self.assertEqual(md.decode_element(0xC00003FF, [10, 10, 10, 2], "UNORM"), | 99 | self.assertEqual(md.decode_element(0xC00003FF, [10, 10, 10, 2], "UNORM"), |
| 102 | [0x3F800000, 0, 0, 0x3F800000]) | 100 | [0x3F800000, 0, 0, 0x3F800000]) |
| 103 | # 32_UINT: missing Y, Z, W -> 0, 0, 1 (integer one). | 101 | # 32_UINT: missing Y/Z/W repeat X (SHADER-86). |
| 104 | self.assertEqual(md.decode_element(7, [32], "UINT"), [7, 0, 0, 1]) | 102 | self.assertEqual(md.decode_element(7, [32], "UINT"), [7, 7, 7, 7]) |
| 105 | 103 | ||
| 106 | def test_open_questions_are_counted_apart(self): | 104 | def test_shader86_closed_open_questions(self): |
| 107 | """A 32-bit format's missing W (translator 0) and a UNORM 1-ULP difference are their own statuses.""" | 105 | """Missing W repeats X; UNORM raw 3 matches correctly rounded 0x3c40c0c1 (no 1-ULP split).""" |
| 108 | base = ["s_mov_b32 s0, 0x7000", "s_mov_b32 s1, 0", "s_mov_b32 s2, 0x100"] | 106 | base = ["s_mov_b32 s0, 0x7000", "s_mov_b32 s1, 0", "s_mov_b32 s2, 0x100"] |
| 109 | w32 = program(base + [f"s_mov_b32 s3, {22 << 12 | md.XYZW:#x}", "v_mov_b32 v2, 0", | 107 | w32 = program(base + [f"s_mov_b32 s3, {22 << 12 | md.XYZW:#x}", "v_mov_b32 v2, 0", |
| 110 | "buffer_load_format_xyzw v[4:7], v2, s[0:3], 0 offen", "s_waitcnt vmcnt(0)", | 108 | "buffer_load_format_xyzw v[4:7], v2, s[0:3], 0 offen", "s_waitcnt vmcnt(0)", |
| 111 | "v_mov_b32 v8, v4", "v_mov_b32 v9, v5", "v_mov_b32 v10, v6", "v_mov_b32 v11, v7"], | 109 | "v_mov_b32 v8, v4", "v_mov_b32 v9, v5", "v_mov_b32 v10, v6", "v_mov_b32 v11, v7"], |
| 112 | {0x7000: 0x40000000}) | 110 | {0x7000: 0x40000000}) |
| 113 | w32.missing_w32_regs, w32.export_sources = {7}, {0: 4, 1: 5, 2: 6, 3: 7} | 111 | self.assertEqual(md.run_one("ps_mem_w32", w32)[0], "match") |
| 114 | self.assertEqual(md.run_one("ps_mem_w32", w32)[0], "missing-w32") | ||
| 115 | unorm = program(base + [f"s_mov_b32 s3, {56 << 12 | md.XYZW:#x}", "v_mov_b32 v2, 0", | 112 | unorm = program(base + [f"s_mov_b32 s3, {56 << 12 | md.XYZW:#x}", "v_mov_b32 v2, 0", |
| 116 | "buffer_load_format_x v4, v2, s[0:3], 0 offen", "s_waitcnt vmcnt(0)", | 113 | "buffer_load_format_x v4, v2, s[0:3], 0 offen", "s_waitcnt vmcnt(0)", |
| 117 | "v_mov_b32 v8, v4", "v_mov_b32 v9, v4", "v_mov_b32 v10, v4", "v_mov_b32 v11, v4"], | 114 | "v_mov_b32 v8, v4", "v_mov_b32 v9, v4", "v_mov_b32 v10, v4", "v_mov_b32 v11, v4"], |
| 118 | {0x7000: 3}) | 115 | {0x7000: 3}) |
| 119 | unorm.norm_regs, unorm.export_sources = {4}, {0: 4, 1: 4, 2: 4, 3: 4} | 116 | self.assertEqual(md.run_one("ps_mem_unorm3", unorm)[0], "match") |
| 120 | self.assertEqual(md.run_one("ps_mem_unorm3", unorm)[0], "norm-ulp1") | ||
| 121 | 117 | ||
| 122 | 118 | ||
| 123 | class GlobalOffsetRegression(unittest.TestCase): | 119 | class GlobalOffsetRegression(unittest.TestCase): |