mirror of
https://github.com/ProjectLeonida/mandy.git
synced 2026-12-06 18:48:38 +00:00
Covers the "16-bit results" contract row, which ended with "not yet GPU-verified".
Hardware evidence: AMD RX 6800 (gfx1030), the instructions run as a raw compute kernel in wave32 and
wave64, IEEE off, DX10 clamp on, denormals kept, round to nearest. The bytes assemble identically for
gfx1013 and gfx1030 (llvm-mc 21; the kernels themselves were assembled by the driver's comgr).
- v_med3_f16: all 16 op_sel patterns, neg/abs on a selected high half, clamp, destination also a source.
- v_add/sub/mul/max/min_f16 (_e32, _e64 with neg/abs/clamp), v_fmac_f16 (_e32, _e64), f16 unary
(rndne/floor/ceil/trunc/fract/sqrt/rcp/rsq, _e32 and _e64), v_cvt_f16_f32: low halves in, low half out,
high half of the destination kept; the v_fmac_f16 accumulator is the low half of the destination.
336 words per wave size, all as the rule says and as the translator computes.
- Not expressible: op_sel on the VOP2/VOP1 ops in VOP3 encoding (v_add/sub/mul/max/min_f16_e64,
v_fmac_f16_e64, unary _e64). llvm-mc rejects the modifier and its disassembler drops the bits, so
nothing was measured there and nothing was hand-encoded.
Translator fix (tools/rdna2spirv.py, new src_h): an inline float constant in an f16 operand is the f16
value in the low half over a zero high half. The translator unpacked the f32 pattern, whose low half is
zero, so v_add_f16 d, 1.0, v added 0.0 and v_cvt_f32_f16 d, 0.5 gave 0. Measured for v_add/mul/max_f16,
v_sub_f16_e64, v_fma_f16, v_fmac_f16, v_rcp_f16, v_med3_f16, v_cmp_lt_f16, v_cvt_f32_f16, v_cos_f16,
v_pk_add/mul_f16 and v_pack_b32_f16 (0.15915494 is 0x3118); the high half op_sel selects from a constant
reads +0.0. v_fma_mix* operands were not
measured and are unchanged.
Tests:
- runtime/test/shaders/ps_f16_{med3_opsel,med3_mods,vop2,vop2b,vop1,vop1b,const,const2,pack}.asm, wired into
check.py and scripts/run_gpu_tests.py. Their expected words are the ones the hardware gave for the same
instructions. Vulkan, AMD Radeon RX 6800, Windows, driver 26.11.2: 9/9 pass; with one expected word
flipped per test 0/9 pass; without the translator fix ps_f16_const, ps_f16_const2 and ps_f16_pack fail.
- tests/test_f16_hw_words.py: header, check.py and run_gpu_tests.py hold the hardware words; a
plain-Python reference of the rule and the translator (tests/spirv_interp.py) both give them. 12 of its
tests fail without the fix.
- tests/semantic: ps_f16_vop2 fixture and value test; the v_sin_f16 mutation anchor follows the edit.
- tests/spirv_interp.py: Floor/Ceil/Trunc/RoundEven keep the sign of a zero result (trunc(-0.75) is
0x8000 on the hardware and on Vulkan), Sin/Cos, component-wise vector arithmetic.
- python -m unittest discover -s tests/semantic: 388 -> 389, OK. pytest tests: 1467 -> 1514 passed.
scripts/run_gpu_tests.py (test tools rebuilt): 48/49 -> 57/58 passed, 1 skipped.
docs/design.md: the "16-bit results" row says what was verified and what is not expressible; new row
"f16 inline constants".
AI-assisted.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
394 lines
19 KiB
Python
394 lines
19 KiB
Python
"""Value-level regression tests for the recent RDNA2 -> SPIR-V semantic fixes.
|
|
|
|
Each pixel shader ends with `exp mrt0 v.., v.., v.., v..`, so four 32-bit words are checked per shader. The
|
|
expectations are written down by hand as constants and recomputed by plain-Python reference functions (checked
|
|
against each other in OracleTests). Neither the constants nor the references use the translator or the SPIR-V
|
|
interpreter.
|
|
|
|
ISA semantics used (AMD RDNA2 ISA reference, VALU/VOP3/VOP3P chapters):
|
|
v_mul_legacy_f32 0 * anything, inf/NaN included, is +0.0; otherwise a normal IEEE binary32 multiply.
|
|
v_lshlrev_b16 D.lo = (S1.lo << (S0.lo & 15)) & 0xffff; the VOP3 form keeps D's high half.
|
|
v_lshrrev_b16 same with >>; v_ashrrev_i16 sign-extends S1.lo before the arithmetic shift.
|
|
v_pk_lshrev_b16 / per half: D.h = (S1.half <</>> (S0.half & 15)) & 0xffff. op_sel picks the source half
|
|
v_pk_lshlrev_b16 / used for the low result half, op_sel_hi for the high result half.
|
|
v_pk_ashrrev_i16
|
|
v_add_nc_u16 D.lo = (S0.lo + S1.lo) & 0xffff; the VOP3 form keeps D's high half (carry is dropped).
|
|
v_sin_f16/v_cos_f16 input is a number of turns: sin/cos(S * 2*pi), rounded to binary16; high half kept.
|
|
v_add/sub/mul_f16, low halves in, D.lo out, D's high half kept; neg/abs in the VOP3 form apply to the low
|
|
v_fmac_f16 half that is read. v_fmac_f16: D.lo = S0.lo * S1.lo + D.lo. The ps_f16_vop2 words were
|
|
measured on an RX 6800 (gfx1030), wave32 and wave64 (see its .asm header).
|
|
s_buffer_load_dwordx2 with destination vcc: dword 0 -> vcc_lo, dword 1 -> vcc_hi.
|
|
v_interp_mov_f32 reads the flat (provoking-vertex) input attribute; the translator must declare it Flat.
|
|
v_perm_b32 byte i = BYTE_PERMUTE({S0, S1}, S2 byte i) over 8 bytes, S1 = bytes 0-3: selector 0-7 picks
|
|
that byte; 8/9/10/11 give 0xff if bit 7 of byte 1/3/5/7 is set, else 0; 12 gives 0;
|
|
13 and above give 0xff.
|
|
v_alignbit_b32 D = ({S0, S1} >> (S2 & 31)) & 0xffffffff.
|
|
v_med3_i32/u32 the middle of three values, compared signed or unsigned.
|
|
v_mul_hi_u32/i32 bits 63:32 of the unsigned or signed 64-bit product.
|
|
v_bcnt_u32_b32 D = popcount(S0) + S1.
|
|
v_ffbl_b32/ffbh_u32 index of the lowest set bit / count of leading zeros; 0xffffffff when S0 = 0.
|
|
v_xad_u32/add3_u32 D = (S0 ^ S1) + S2 / D = S0 + S1 + S2, both mod 2^32.
|
|
s_min/max_i32/u32 D = S0 < S1 ? S0 : S1 (max: >), SCC = 1 when S0 is chosen, so a tie gives S1 and SCC 0.
|
|
v_fmamk_f32/madmk_f32 D = S0 * K + S1, K the literal (printed vdst, src0, K, vsrc1); fmamk is fused.
|
|
v_fmaak_f32/madak_f32 D = S0 * S1 + K (printed vdst, src0, vsrc1, K).
|
|
|
|
The appended cases for ps_ops5/ps_ops6 also pin the op_sel source-half selection for packed shifts, which the
|
|
GPU-checked ps_ops4 does not exercise. cs_bounds (compute) pins the buffer num_records bounds checks: an
|
|
out-of-bounds store must not modify memory and an out-of-bounds load must return 0. cs_fmt_1010102 (compute) pins
|
|
the channel order of the 10:10:10:2 typed-buffer formats: the names list the channel widths from the top bit, so
|
|
2_10_10_10 (50) is R10G10B10A2 and 10_10_10_2 (44) has a 2-bit x (Mesa gfx10_format_table.py, ac_formats.c).
|
|
"""
|
|
import math
|
|
import struct
|
|
import unittest
|
|
|
|
import support
|
|
|
|
# Independent constants, written down by hand (derivations are in the reference functions).
|
|
EXPECTED_LEGACY_MUL = [0x00000000, 0x00000000, 0x00000000, 0x40C00000]
|
|
EXPECTED_OPS4 = [0x34000010, 0x00120800, 0xBEEF0000, 0x12343C00]
|
|
EXPECTED_OPS5 = [0x12340010, 0xBEEF0800, 0xAAAAFFFF, 0xDEADBC00]
|
|
EXPECTED_OPS6 = [0xF800FFFF, 0x01000010, 0x00800800, 0x8000FFF0]
|
|
EXPECTED_OPS7 = [0x00FF8077, 0xFF0000FF, 0x89ABCDEF, 0x00070003]
|
|
EXPECTED_OPS8 = [0x80000000, 0xFFFFFFFF, 0x000F100E, 0x0F0F0F1F]
|
|
EXPECTED_VCC_X2 = [0x11223344, 0x55667788, 0x00000000, 0x00000000]
|
|
EXPECTED_F16_VOP2 = [0xAAAA4000, 0xAAAAC000, 0xAAAA3A00, 0x42003F00] # hardware-measured
|
|
EXPECTED_FLAT = [0x00000101, 0x00000102, 0x3F000000, 0x3E800000]
|
|
EXPECTED_SCC_MINMAX = [0x00030205, 0x00030207, 0x00030209, 0x00030203]
|
|
EXPECTED_FMA_LITERAL = [0x41B80000, 0x41800000, 0x40E00000, 0x41A40000]
|
|
EXPECTED_BOUNDS = {0x00: 0x12345678, 0x04: 0x12345678, 0x08: 0x00000000, 0x0C: 0xEEEEEEEE}
|
|
EXPECTED_FMT_1010102 = {0x00: 0x00000000, 0x04: 0x3F800000, 0x08: 0x00000000, 0x0C: 0x3F800000,
|
|
0x10: 0x3F800000, 0x14: 0x00000000, 0x18: 0x3F800000, 0x1C: 0x00000000,
|
|
0x20: 0x00000000, 0x24: 0x3F800000, 0x28: 0x00000000, 0x2C: 0x3F800000,
|
|
0x30: 0xC00FFC00, 0x34: 0x003FF003, 0x38: 0xE00003FF, 0x3C: 0xFFE00003}
|
|
|
|
|
|
def _f32_bits(x):
|
|
return struct.unpack("<I", struct.pack("<f", x))[0]
|
|
|
|
|
|
def _half(x):
|
|
return struct.unpack("<H", struct.pack("<e", x))[0]
|
|
|
|
|
|
def _unhalf(h):
|
|
return struct.unpack("<e", struct.pack("<H", h))[0]
|
|
|
|
|
|
def _s16(x):
|
|
return x - 0x10000 if x & 0x8000 else x
|
|
|
|
|
|
def _legacy_mul(x, y):
|
|
"""v_mul_legacy_f32: zero wins over inf and NaN, including a negative zero."""
|
|
return 0 if x == 0.0 or y == 0.0 else _f32_bits(x * y)
|
|
|
|
|
|
def reference_legacy_mul():
|
|
return [_legacy_mul(0.0, float("inf")), _legacy_mul(0.0, float("nan")),
|
|
_legacy_mul(-0.0, float("-inf")), _legacy_mul(2.0, 3.0)]
|
|
|
|
|
|
def _pk_shift(kind, sh, val, sel=(0, 0), selhi=(1, 1)):
|
|
"""One packed 16-bit shift. sel selects (shift-half, value-half) for the low result, selhi for the high."""
|
|
def half(x, n):
|
|
return (x >> (16 * n)) & 0xFFFF
|
|
|
|
def one(shalf, vhalf):
|
|
amount = half(sh, shalf) & 15
|
|
x = half(val, vhalf)
|
|
if kind == "ashr":
|
|
return (_s16(x) >> amount) & 0xFFFF
|
|
return ((x << amount) if kind == "lshl" else (x >> amount)) & 0xFFFF
|
|
|
|
return one(sel[0], sel[1]) | (one(selhi[0], selhi[1]) << 16)
|
|
|
|
|
|
def reference_ops4():
|
|
v0, shift = 0x12348001, 0x00080004
|
|
sin = _half(math.sin(_unhalf(0x3400) * 2.0 * math.pi)) # 0.25 turns -> 1.0
|
|
add = (0xBEEF0000 & 0xFFFF0000) | ((0x0001 + 0xFFFF) & 0xFFFF) # carry out of the low half is dropped
|
|
return [_pk_shift("lshl", shift, v0), _pk_shift("lshr", shift, v0), add,
|
|
0x12340000 | sin]
|
|
|
|
|
|
def reference_ops5():
|
|
lshl = 0x12340000 | ((0x8001 << 4) & 0xFFFF)
|
|
lshr = 0xBEEF0000 | ((0x8001 >> 4) & 0xFFFF)
|
|
ashr = 0xAAAA0000 | ((_s16(0xFFF0) >> 4) & 0xFFFF)
|
|
cos = 0xDEAD0000 | _half(math.cos(_unhalf(0x3800) * 2.0 * math.pi)) # 0.5 turns -> -1.0
|
|
return [lshl, lshr, ashr, cos]
|
|
|
|
|
|
def reference_ops6():
|
|
return [_pk_shift("ashr", 0x00040004, 0x8000FFF0),
|
|
# op_sel:[1,0,0] -> low result shifts by the high half of src0; op_sel_hi:[0,0,0] -> high result
|
|
# shifts by the low half. Both use the low half of the value.
|
|
_pk_shift("lshl", 0x00040008, 0x12348001, sel=(1, 0), selhi=(0, 0)),
|
|
_pk_shift("lshr", 0x00040008, 0xBEEF8001, sel=(1, 0), selhi=(0, 0)),
|
|
_pk_shift("ashr", 0, 0x8000FFF0)]
|
|
|
|
|
|
def _perm(s0, s1, sel):
|
|
data = list(s1.to_bytes(4, "little")) + list(s0.to_bytes(4, "little"))
|
|
out = 0
|
|
for i in range(4):
|
|
k = (sel >> (8 * i)) & 0xFF
|
|
if k >= 13:
|
|
b = 0xFF
|
|
elif k == 12:
|
|
b = 0
|
|
elif k >= 8:
|
|
b = 0xFF if data[2 * (k - 8) + 1] & 0x80 else 0
|
|
else:
|
|
b = data[k]
|
|
out |= b << (8 * i)
|
|
return out
|
|
|
|
|
|
def _s(v):
|
|
return v - (1 << 32) if v & 0x80000000 else v
|
|
|
|
|
|
def reference_ops7():
|
|
m = 0xFFFFFFFF
|
|
med_i = sorted([_s(0xFFFFFFFB), 7, 3])[1] & m
|
|
med_u = sorted([0xFFFFFFFB, 7, 3])[1]
|
|
return [_perm(0x80112233, 0x4455E677, 0x0C0D0700),
|
|
_perm(0x80112233, 0x4455E677, 0x0B0A0908), # sign of bytes 1, 3, 5, 7: E6, 44, 22, 80
|
|
(((0x12345678 << 32) | 0x9ABCDEF0) >> (36 & 31)) & m,
|
|
((med_u << 16) + med_i) & m]
|
|
|
|
|
|
def reference_ops8():
|
|
m = 0xFFFFFFFF
|
|
bcnt = bin(0xF0F00001).count("1") + 5
|
|
ffbl = (0x00010000 & -0x00010000).bit_length() - 1
|
|
ffbh = 32 - 0x00010000.bit_length()
|
|
xad = ((0xF0F0F0F0 ^ m) + 1) & m
|
|
return [(0x80000001 * 0xFFFFFFFF) >> 32,
|
|
((_s(0xFFFFFFFE) * 0x40000000) >> 32) & m,
|
|
((ffbh << 16) + (ffbl << 8) + bcnt) & m,
|
|
(xad + 16 + m) & m] # v_ffbh_u32(0) = 0xffffffff
|
|
|
|
|
|
def reference_scc_minmax():
|
|
def minmax(op, x, y):
|
|
"""(D, SCC) of s_min/s_max _i32/_u32 on 32-bit words: SCC = 1 only when S0 is the one chosen."""
|
|
kx, ky = (_s(x), _s(y)) if op.endswith("i32") else (x, y)
|
|
pick = kx < ky if op.startswith("min") else kx > ky
|
|
return x if pick else y, int(pick)
|
|
|
|
words = []
|
|
m1 = 0xFFFFFFFF # the inline constant -1 as a register word
|
|
for op, tie, strict in (("min_i32", 5, (m1, 1)), ("max_i32", 7, (1, m1)),
|
|
("min_u32", 9, (1, m1)), ("max_u32", 3, (m1, 1))):
|
|
d, scc_tie = minmax(op, tie, tie)
|
|
_, scc_strict = minmax(op, *strict)
|
|
words.append(d | ((1 if scc_tie else 2) << 8) | ((3 if scc_strict else 4) << 16))
|
|
return words
|
|
|
|
|
|
def reference_fma_literal():
|
|
# Every product and sum is exact in f32, so fused and unfused give the same bits.
|
|
k1, k2 = 10.0, 0.5
|
|
return [_f32_bits(2.0 * k1 + 3.0), _f32_bits(2.0 * 3.0 + k1), # fmamk, fmaak
|
|
_f32_bits(4.0 * k2 + 5.0), _f32_bits(4.0 * 5.0 + k2)] # madmk, madak
|
|
|
|
|
|
def reference_f16_vop2():
|
|
a, b, acc = _unhalf(0x3E00), _unhalf(0x3800), _unhalf(0x3C00) # low halves: 1.5, 0.5, accumulator 1.0
|
|
return [0xAAAA0000 | _half(a + b), 0xAAAA0000 | _half(-a - abs(b)), 0xAAAA0000 | _half(a * b),
|
|
0x42000000 | _half(a * b + acc)]
|
|
|
|
|
|
def reference_vcc_x2():
|
|
return [0x11223344, 0x55667788, 0, 0]
|
|
|
|
|
|
def reference_flat():
|
|
return [0x101, 0x101 + 1, _f32_bits(0.5), _f32_bits(0.25)]
|
|
|
|
|
|
def reference_bounds():
|
|
# num_records = 16: store 0 and load 0 are in bounds, the store and load at offset 16 are not. The OOB load
|
|
# feeds a store of 0 into offset 8; the OOB store must leave offset 16 untouched (it is not in the map).
|
|
return {0x00: 0x12345678, 0x04: 0x12345678, 0x08: 0, 0x0C: 0xEEEEEEEE}
|
|
|
|
|
|
WIDTHS_1010102 = {50: (10, 10, 10, 2), # 2_10_10_10_UNORM, R10G10B10A2
|
|
44: (2, 10, 10, 10)} # 10_10_10_2_UNORM
|
|
|
|
|
|
def _unorm_unpack(word, widths):
|
|
out, bit = [], 0
|
|
for w in widths:
|
|
out.append(_f32_bits(((word >> bit) & ((1 << w) - 1)) / ((1 << w) - 1)))
|
|
bit += w
|
|
return out
|
|
|
|
|
|
def _unorm_pack(values, widths):
|
|
word, bit = 0, 0
|
|
for v, w in zip(values, widths):
|
|
word |= round(min(max(v, 0.0), 1.0) * ((1 << w) - 1)) << bit
|
|
bit += w
|
|
return word
|
|
|
|
|
|
def reference_fmt_1010102():
|
|
# Every field is 0 or full scale, so the decoded floats are exact.
|
|
src50, src44, stored = 0xC00FFC00, 0x003FF003, (1.0, 0.0, 0.5, 1.0)
|
|
words = (_unorm_unpack(src50, WIDTHS_1010102[50]) + _unorm_unpack(src44, WIDTHS_1010102[44])
|
|
+ _unorm_unpack(src50, WIDTHS_1010102[50])
|
|
+ [src50, src44, _unorm_pack(stored, WIDTHS_1010102[50]), _unorm_pack(stored, WIDTHS_1010102[44])])
|
|
return {4 * i: w for i, w in enumerate(words)}
|
|
|
|
|
|
def _isg1_dxbc(elements):
|
|
"""A DXBC container with one ISG1 input signature. elements: (register, mask, system value, component type)."""
|
|
payload = bytearray(struct.pack("<II", len(elements), 8))
|
|
for reg, mask, sysv, ctype in elements:
|
|
e = bytearray(32)
|
|
struct.pack_into("<6I", e, 0, 0, 0, 0, sysv, ctype, reg)
|
|
e[24], e[25] = mask, 1 # read/write mask: the shader reads it
|
|
payload += e
|
|
part = b"ISG1" + struct.pack("<I", len(payload)) + bytes(payload)
|
|
part += bytes((-len(part)) % 4)
|
|
header = b"DXBC" + bytes(16) + struct.pack("<III", 1, 0, 1)
|
|
return header + struct.pack("<I", len(header) + 8) + bytes(4) + part
|
|
|
|
|
|
def _fssm(rsrc2, group):
|
|
"""The compute-shader header words the translator reads: COMPUTE_PGM_RSRC2 and the thread-group size."""
|
|
header = bytearray(0x148)
|
|
struct.pack_into("<4I", header, 0x138, rsrc2, *group)
|
|
return bytes(header)
|
|
|
|
|
|
# attr0 = TEXCOORD0 (x/y interpolated), attr1 = TEXCOORD1 (read through v_interp_mov only, so Flat).
|
|
PS_FLAT_DXBC = _isg1_dxbc([(0, 0x3, 0, 3), (1, 0x1, 0, 3)])
|
|
FLAT_ATTR1_X = struct.unpack("<f", struct.pack("<I", 0x101))[0]
|
|
# 4 user SGPRs (the output V#), workgroup id in s4, 512 bytes of LDS, 64x1x1 threads: the header cs_bounds was
|
|
# written for in runtime/test/shaders/build.py.
|
|
CS_BOUNDS_FSSM = _fssm(0x8088, (64, 1, 1))
|
|
|
|
|
|
class OracleTests(unittest.TestCase):
|
|
"""The hand-written constants and the plain-Python reference agree (so the oracle is self-consistent)."""
|
|
|
|
def test_reference_matches_constants(self):
|
|
self.assertEqual(reference_legacy_mul(), EXPECTED_LEGACY_MUL)
|
|
self.assertEqual(reference_ops4(), EXPECTED_OPS4)
|
|
self.assertEqual(reference_ops5(), EXPECTED_OPS5)
|
|
self.assertEqual(reference_ops6(), EXPECTED_OPS6)
|
|
self.assertEqual(reference_ops7(), EXPECTED_OPS7)
|
|
self.assertEqual(reference_ops8(), EXPECTED_OPS8)
|
|
self.assertEqual(reference_vcc_x2(), EXPECTED_VCC_X2)
|
|
self.assertEqual(reference_f16_vop2(), EXPECTED_F16_VOP2)
|
|
self.assertEqual(reference_flat(), EXPECTED_FLAT)
|
|
self.assertEqual(reference_scc_minmax(), EXPECTED_SCC_MINMAX)
|
|
self.assertEqual(reference_fma_literal(), EXPECTED_FMA_LITERAL)
|
|
self.assertEqual(reference_bounds(), EXPECTED_BOUNDS)
|
|
self.assertEqual(reference_fmt_1010102(), EXPECTED_FMT_1010102)
|
|
|
|
|
|
class TranslatorValueSemantics(unittest.TestCase):
|
|
def check(self, name, expected, dxbc=None, **run_options):
|
|
spv = support.translate_fixture(name, dxbc=dxbc) if dxbc is not None else support.translate_fixture(name)
|
|
words = support.mrt0_words(spv, **run_options)
|
|
self.assertEqual(len(words), 4, "mrt0 has four components")
|
|
for i, (got, want) in enumerate(zip(words, expected)):
|
|
with self.subTest(shader=name, component="xyzw"[i]):
|
|
self.assertEqual(f"{got:#010x}", f"{want:#010x}")
|
|
|
|
def test_v_mul_legacy_f32_zero_times_inf_nan(self):
|
|
# 0*inf, 0*NaN and -0*-inf all give +0.0; 2*3 is an ordinary multiply.
|
|
self.check("ps_legacy_mul", EXPECTED_LEGACY_MUL)
|
|
|
|
def test_packed_b16_shifts_add_nc_u16_and_sin_f16(self):
|
|
# Per-half shifts with independent amounts (4 and 8), a 16-bit add whose carry is dropped while the
|
|
# destination's high half is kept, and sin_f16 reading its input as turns.
|
|
self.check("ps_ops4", EXPECTED_OPS4)
|
|
|
|
def test_scalar_b16_shifts_and_cos_f16(self):
|
|
# VOP3 forms keep the destination's high half; ashrrev sign-extends the 16-bit value before shifting.
|
|
self.check("ps_ops5", EXPECTED_OPS5)
|
|
|
|
def test_packed_b16_shifts_with_op_sel(self):
|
|
# Packed ashrrev (both halves negative) and lshl/lshr selecting source halves through op_sel/op_sel_hi.
|
|
self.check("ps_ops6", EXPECTED_OPS6)
|
|
|
|
def test_perm_alignbit_and_med3(self):
|
|
# v_perm_b32 with plain byte picks, the 0x00/0xff constants and the sign selectors 8-11; v_alignbit_b32
|
|
# with a shift of 36 (taken mod 32); v_med3_i32 and v_med3_u32 on the same operands (-5, 7, 3).
|
|
self.check("ps_ops7", EXPECTED_OPS7)
|
|
|
|
def test_mul_hi_bit_counts_xad_add3(self):
|
|
# High halves of unsigned and signed products, popcount with an accumulator, lowest/highest set bit,
|
|
# v_ffbh_u32(0) = -1 feeding a wrapping v_add3_u32, and v_xad_u32.
|
|
self.check("ps_ops8", EXPECTED_OPS8)
|
|
|
|
def test_s_min_max_scc_on_a_tie(self):
|
|
# Equal operands give S1 and SCC 0 for s_min/s_max _i32 and _u32; -1 vs 1 sets SCC only when compared
|
|
# with the op's own signedness. A tie that set SCC turns byte 1 of a word from 2 into 1.
|
|
self.check("ps_scc_minmax", EXPECTED_SCC_MINMAX)
|
|
def test_fmamk_madmk_multiply_by_the_literal(self):
|
|
# fmamk/madmk multiply S0 by the literal and add vsrc1; fmaak/madak multiply S0 by vsrc1 and add the
|
|
# literal. Swapping K and vsrc1 changes every word (16 and 20.5 instead of 23 and 7, and back).
|
|
self.check("ps_fma_literal", EXPECTED_FMA_LITERAL)
|
|
|
|
def test_f16_vop2_partial_writes(self):
|
|
# Low halves in (the high halves hold other values), low half out, the destination's high half kept;
|
|
# v_fmac_f16 accumulates into the low half of its destination.
|
|
self.check("ps_f16_vop2", EXPECTED_F16_VOP2)
|
|
|
|
def test_s_buffer_load_dwordx2_into_vcc(self):
|
|
# The V# in s[0:3] points at 0x1000; the two dwords must come back in vcc_lo and vcc_hi, not be lost.
|
|
push = [0x1000, 0, 16, 0] + [0] * 28
|
|
self.check("ps_vcc_x2", EXPECTED_VCC_X2, push_constants=push,
|
|
memory={0x1000: 0x11223344, 0x1004: 0x55667788})
|
|
|
|
def test_flat_input_and_interpolated_input(self):
|
|
# attr1.x is read only through v_interp_mov, so it carries the provoking vertex's 0x101 unchanged and
|
|
# integer maths works on it; attr0.xy is read through v_interp and keeps the supplied values.
|
|
self.check("ps_flat", EXPECTED_FLAT, dxbc=PS_FLAT_DXBC,
|
|
inputs={"%in_attr0": (0.5, 0.25, 0.0, 1.0), "%in_attr1": (FLAT_ATTR1_X,) * 4})
|
|
|
|
def test_flat_input_is_declared_flat(self):
|
|
spv = support.translate_fixture("ps_flat", dxbc=PS_FLAT_DXBC)
|
|
self.assertIn("OpDecorate %in_attr1 Flat", spv)
|
|
self.assertNotIn("OpDecorate %in_attr0 Flat", spv)
|
|
|
|
def test_buffer_num_records_bounds(self):
|
|
# cs_bounds builds a V# with base 0, stride 0, num_records 16 and runs one thread. The output V# in
|
|
# s[0:3] is the same memory. The out-of-bounds store at offset 16 must not land anywhere, and the OOB
|
|
# load must come back as 0.
|
|
spv = support.translate_fixture("cs_bounds", fssm=CS_BOUNDS_FSSM)
|
|
memory = {0x0C: 0xEEEEEEEE}
|
|
outputs = support.run_fragment(
|
|
spv, inputs={"%wg_id": (0, 0, 0), "%local_id": (0, 0, 0)},
|
|
push_constants=[0, 0, 16, 0] + [0] * 28, memory=memory)
|
|
self.assertEqual(outputs, {})
|
|
for address, want in EXPECTED_BOUNDS.items():
|
|
with self.subTest(address=address):
|
|
self.assertEqual(memory.get(address), want)
|
|
with self.subTest(what="out-of-bounds store"):
|
|
self.assertNotIn(0x10, memory)
|
|
|
|
def test_buffer_format_10_10_10_2_channel_order(self):
|
|
# The layout of out[] is in the comment at the top of cs_fmt_1010102.asm.
|
|
spv = support.translate_fixture("cs_fmt_1010102", fssm=CS_BOUNDS_FSSM)
|
|
memory = {}
|
|
outputs = support.run_fragment(
|
|
spv, inputs={"%wg_id": (0, 0, 0), "%local_id": (0, 0, 0)},
|
|
push_constants=[0, 0, 0x100, 0] + [0] * 28, memory=memory)
|
|
self.assertEqual(outputs, {})
|
|
for address, want in EXPECTED_FMT_1010102.items():
|
|
with self.subTest(address=address):
|
|
self.assertEqual(f"{memory.get(address, 0):#010x}", f"{want:#010x}")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|