r"""SHADER-337: measure the y and z texel-offset fields of image_sample_lz_o on an AMD GPU (tools/hw_oracle). python -I tools/texoff_probe.py # the rule's expectation only (no GPU) python -I tools/texoff_probe.py --oracle hw # native AMD GPU, wave32 and wave64, compared with the rule docs/design.md ("Texel offsets") has x measured on hardware (signed 6-bit field at bits [5:0], bits 6-7 ignored) and the y and z signs only from a structural test. Here a raw kernel samples a linear R32_SFLOAT texture whose texel holds its own index, with a point sampler that clamps to the last texel, so each result names the texel that was read: 2D 64x64, texel (x, y) = 64 y + x: y field = offset dword bits [13:8] 3D 64x1x64, texel (x, 0, z) = 64 z + x: z field = offset dword bits [21:16] Each row starts at a texel and uses one offset dword. The values are chosen so that a signed and an unsigned reading land on different texels (or one clamps), and some rows set the bits just above a field to see whether they are ignored. The rule checked is the translator's: every field is sign-extended from 6 bits, the bits above it ignored (tests/test_texel_offsets.py). Standard library only; the texture is built here, no game files. Exit codes: 0 every row matches the rule, 1 a mismatch, 2 harness error, 77 no hardware oracle. Usage: `python -I tools/texoff_probe.py --help` lists the options. """ import argparse import os import struct import sys HERE = os.path.dirname(os.path.abspath(__file__)) sys.path.insert(0, os.path.join(HERE, "hw_oracle")) W = 64 H2D = 64 D3D = 64 SQ_RSRC_IMG_3D = 10 CLAMP_LAST_TEXEL = 2 def sext6(v): v &= 0x3F return v - 64 if v & 0x20 else v def clamp(v, n): return max(0, min(n - 1, v)) # (name, dim, start (x, y_or_z), offset dword) ROWS = [ # y field, 2D: from row 40 (0x20 signed is -32 -> 8, unsigned 32 -> clamps to 63; 0x3c is -4 -> 36 vs 60) ("y_0x20_from40", "2d", (5, 40), 0x20 << 8), ("y_0x3c_from40", "2d", (5, 40), 0x3C << 8), ("y_0x1f_from10", "2d", (5, 10), 0x1F << 8), # +31 -> 41 either way (control) ("y_0x20_from10", "2d", (5, 10), 0x20 << 8), # signed -32 clamps to 0, unsigned 32 -> 42 ("y_0x21_from40", "2d", (5, 40), 0x21 << 8), # -31 -> 9 vs 33 -> clamp 63 ("y_bits14_15", "2d", (5, 40), 0xC0 << 8), # field 0 with bits 14-15 set: 40 if they are ignored ("y_0x3f_bit14", "2d", (5, 40), 0x7F << 8), # field 0x3f (-1) with bit 14: 39 if ignored ("y_with_x", "2d", (20, 40), (0x3C << 8) | 0x3E), # x -2, y -4 together # z field, 3D: same values on bits [21:16] ("z_0x20_from40", "3d", (5, 40), 0x20 << 16), ("z_0x3c_from40", "3d", (5, 40), 0x3C << 16), ("z_0x1f_from10", "3d", (5, 10), 0x1F << 16), ("z_0x20_from10", "3d", (5, 10), 0x20 << 16), ("z_0x21_from40", "3d", (5, 40), 0x21 << 16), ("z_bits22_23", "3d", (5, 40), 0xC0 << 16), ("z_with_x_y", "3d", (20, 40), (0x3C << 16) | (0x3F << 8) | 0x3E), # y -1 on a 1-texel-high image clamps ] def expected(dim, start, off): x0, b0 = start x = clamp(x0 + sext6(off), W) if dim == "2d": y = clamp(b0 + sext6(off >> 8), H2D) return float(y * W + x) z = clamp(b0 + sext6(off >> 16), D3D) return float(z * W + x) # y is clamped to the single row def texture(dim): n = W * (H2D if dim == "2d" else D3D) return b"".join(struct.pack("