Files
mandy/tests/test_texoff_probe.py
S1m0ne1997 14f7cce13f SHADER-337: texel-offset y and z fields measured on RDNA2 (signed 6-bit, upper bits ignored)
tools/texoff_probe.py samples a linear R32_SFLOAT texture whose texel holds its index (2D 64x64 for y, 3D 64x1x64
for z) with image_sample_lz_o through tools/hw_oracle on gfx1036, wave32 and wave64. All 15 rows fit the
translator's rule. tests/test_texoff_probe.py checks that each row with a negative field tells signed from unsigned.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 17:30:13 +01:00

65 lines
2.7 KiB
Python

"""tools/texoff_probe.py without a GPU: the rows tell a signed field from an unsigned one, and the kernels build.
python -I tests/test_texoff_probe.py
"""
import os
import sys
import unittest
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.insert(0, os.path.join(ROOT, "tools"))
sys.path.insert(0, os.path.join(ROOT, "tools", "hw_oracle"))
import texoff_probe as p # noqa: E402
def unsigned_reading(dim, start, off):
"""The same sample if the fields were read unsigned (the rule the rows must rule out)."""
x0, b0 = start
x = p.clamp(x0 + (off & 0x3F), p.W)
shift, n = (8, p.H2D) if dim == "2d" else (16, p.D3D)
b = p.clamp(b0 + ((off >> shift) & 0x3F), n)
return float(b * p.W + x)
class RowsTest(unittest.TestCase):
def test_sext6(self):
self.assertEqual([p.sext6(v) for v in (0, 0x1F, 0x20, 0x3F, 0x40, 0x7F)], [0, 31, -32, -1, 0, -1])
def test_rows_with_a_negative_field_tell_signed_from_unsigned(self):
for name, dim, start, off in p.ROWS:
field = (off >> (8 if dim == "2d" else 16)) & 0x3F
if field & 0x20 and field != 0x3F:
with self.subTest(name):
self.assertNotEqual(p.expected(dim, start, off), unsigned_reading(dim, start, off))
def test_both_axes_are_covered(self):
self.assertEqual({d for _n, d, _s, _o in p.ROWS}, {"2d", "3d"})
self.assertEqual(len({n for n, *_ in p.ROWS}), len(p.ROWS))
def test_expected_values(self):
self.assertEqual(p.expected("2d", (5, 40), 0x20 << 8), 8 * 64 + 5) # 40 - 32
self.assertEqual(p.expected("2d", (5, 10), 0x20 << 8), 0 * 64 + 5) # clamps at row 0
self.assertEqual(p.expected("2d", (5, 40), 0xC0 << 8), 40 * 64 + 5) # bits 14-15 ignored
self.assertEqual(p.expected("3d", (20, 40), (0x3C << 16) | (0x3F << 8) | 0x3E), 36 * 64 + 18)
def test_kernels_build_for_rdna2_and_rdna3(self):
for arch in ("gfx1036", "gfx1150"):
for dim in ("2d", "3d"):
rows = [r for r in p.ROWS if r[1] == dim]
lines = p.kernel(arch, dim, rows)
with self.subTest(arch=arch, dim=dim):
self.assertEqual(sum("image_sample_lz_o" in ln for ln in lines), len(rows))
self.assertIn(f"dim:SQ_RSRC_IMG_{dim.upper()}", "\n".join(lines))
self.assertEqual(lines[-1].startswith(" .long"), True)
def test_3d_descriptor_type_and_depth(self):
t = p.words("gfx1036", "3d")
self.assertEqual(t[3] >> 28, p.SQ_RSRC_IMG_3D)
self.assertEqual(t[4], p.D3D - 1)
self.assertEqual(p.sampler_words()[0] & 0x1FF, 2 | 2 << 3 | 2 << 6)
if __name__ == "__main__":
unittest.main()