mirror of
https://github.com/ProjectLeonida/mandy.git
synced 2026-12-06 09:08:38 +00:00
Merge pull request #222 from simonbronk
# Conflicts: # docs/design.md # tests/semantic/test_alu_perm_alignbit.py # tools/rdna2spirv.py
This commit is contained in:
@ -248,7 +248,8 @@ How the generated SPIR-V expects the runtime to work:
|
||||
| Typed image stores | `image_store` (2D, 2D array, 3D) writes the dmask components (missing ones = 0). The image's numeric type lives in the T# (word 1 FORMAT [28:20], 512 GFX10 formats), so it is decided at run time. A 512-bit table built from `tools/gfx10_formats.json` (30 UINT and 15 SINT formats) picks a **sint**, **uint** or **float** view (bindings 8 + 3·dim + class; dim 0 = 2D, 1 = 2D array, 2 = 3D; class 0 float, 1 uint, 2 sint). Views have Unknown format (`shaderStorageImageWriteWithoutFormat`). **The runtime binds every storage image into all three arrays of its dimension, or at least the one matching its format.** The earlier path wrote only component 0 as `r32ui`, which was wrong for every other format. GPU-checked with `runtime/test/shaders/cs_imgstore.asm` through `runtime/test/vk_store_test.cpp`: rgba8 unorm, r32 uint and r32 sint images, every texel correct. |
|
||||
| Typed image loads | `image_load` on 1D/2D/2D-array/3D images uses the same T# FORMAT tables as stores: UINT/SINT formats are read with `OpImageRead` through the uint/sint storage views (`shaderStorageImageReadWithoutFormat`), everything else with `OpImageFetch` through the float sampled view as before. Results are the raw bits of the dmask components. **The runtime binds integer-format images into the uint/sint storage arrays of their dimension** (bindings 8–19), as for stores. Before this, every load went through the float view, which is undefined for integer formats. GPU-checked with `runtime/test/shaders/cs_imgload.asm` (r32 uint read back exactly). |
|
||||
| SDWA | `_sdwa` forms: each source is narrowed to `src0_sel`/`src1_sel` (BYTE_n/WORD_n, zero-extended, or sign-extended under `sext()`) **before** neg/abs and the op. A VGPR result goes to `dst_sel`, with `dst_unused` setting the other bits: PAD = 0, SEXT = sign copies above the field, PRESERVE = old bits kept. VOPC has no `dst_sel`, and GFX10 `v_cmpx` has no written destination. **Until 2026-11-20 the selects were silently ignored.** That affected 3,826 of the 13,926 translated shaders: they passed `spirv-val` but computed wrong values. GPU-checked with `runtime/test/shaders/ps_sdwa.asm` and `ps_ops.asm` (also `v_pk_fma_f16`, `v_min3_u32`, `v_max3_i32`, `v_bfe_i32`): byte/word source selects, `sext()`, `UNUSED_PRESERVE` into WORD_1 and `UNUSED_SEXT` at BYTE_2 all match on every pixel. |
|
||||
| Known approximations | `v_cvt_pkrtz_f16_f32` is now **exact round-toward-zero** (finite overflow gives ±65504, not inf). The GPU smoke test caught the old round-to-nearest version producing inf in `PS_ImposterShadow`. The other f16 packs (`v_cvt_f16_f32`, d16 results, mix ops) round to nearest, which matches the default mode. The MODE register (`s_setreg`) is ignored, so denormal and rounding behaviour is Vulkan's default. Whole-quad mode on non-EXEC masks is the identity. `v_mul_legacy_f32` now keeps the `0 × anything = 0` rule like `v_mad_legacy_f32` (GPU-checked with `runtime/test/shaders/ps_legacy_mul.asm` on AMD Radeon RX 9070 XT). For `pos1..pos3` exports, because `PA_CL_VS_OUT_CNTL` is not in the shader blob, the clip/cull/misc split and component indices follow `OSG1` (assuming contiguous hardware packing clip→cull as in Mesa/LLPC), and without `OSG1` declaring `SV_ClipDistance`/`SV_CullDistance` any `pos1..pos3` export is discarded rather than guessed; `PointSize`/`EdgeFlag`/`ShadingRate` in `pos1` misc are not emitted as Vulkan built-ins, and in mesh shaders a misc `OSG1` entry shifts clip/cull to `pos2..pos3` without emitting per-vertex `Layer`/`ViewportIndex`. |
|
||||
| Byte permute | `v_perm_b32`: result byte i = BYTE_PERMUTE({src0, src1}, selector byte i), src1 = bytes 0–3 (AMD "RDNA 2" ISA reference, VOP3 opcode 836 V_PERM_B32, `byte_permute` pseudocode, page 189 of the PDF). Selector 0–7 picks that byte; **8, 9, 10, 11 give 0xff if bit 7 of byte 1, 3, 5, 7 is set, else 0x00**; 12 gives 0x00; 13 and above give 0xff. **Until 2026-11-21 selectors 8–11 gave 0x00 regardless of the sign bit**. How many corpus shaders use selectors 8–11 is not counted yet. GPU-checked with `runtime/test/shaders/ps_ops7.asm` (also `v_alignbit_b32` with a shift of 36, `v_med3_i32` vs `v_med3_u32`) and `ps_ops8.asm` (`v_mul_hi_u32/i32`, `v_bcnt_u32_b32`, `v_ffbl_b32`, `v_ffbh_u32` of 0, `v_xad_u32`, `v_add3_u32`), 4096/4096 pixels on an AMD Radeon iGPU (Ryzen 7 9800X3D, RDNA2, AMD driver 25.10.36) and an NVIDIA GeForce RTX 5070 (driver 621.24); before the fix `ps_ops7` gave 0x00000000 for the sign-selector word on both. Also executed by `tests/semantic/test_value_semantics.py`. |
|
||||
| Known approximations | `v_cvt_pkrtz_f16_f32` is now **exact round-toward-zero** (finite overflow gives ±65504, not inf). The GPU smoke test caught the old round-to-nearest version producing inf in `PS_ImposterShadow`. The other f16 packs (`v_cvt_f16_f32`, d16 results, mix ops) round to nearest, which matches the default mode. The MODE register (`s_setreg`) is ignored, so denormal and rounding behaviour is Vulkan's default. Whole-quad mode on non-EXEC masks is the identity. `v_mul_legacy_f32` now keeps the `0 × anything = 0` rule like `v_mad_legacy_f32` (GPU-checked with `runtime/test/shaders/ps_legacy_mul.asm` on AMD Radeon RX 9070 XT). |
|
||||
| Buffer bounds checking | MUBUF `buffer_load*`, `buffer_store*`, and `buffer_atomic*` enforce `num_records` (V# word 2): raw buffers (`stride == 0`) check the starting byte offset (`offset < num_records`; per-dword tail bounds on multi-dword accesses aren't split yet), and structured buffers (`stride != 0`) check `index < num_records` (`idxen`) or `offset < num_records * stride`. Out-of-bounds stores/atomics skip memory access completely and out-of-bounds loads return 0. GPU-checked with `runtime/test/shaders/cs_bounds.asm` on AMD Radeon RX 9070 XT. |
|
||||
| Wave64 mask ballot | `tools/lane_masks.py` tracks per-lane masks (including 32-bit `MASK_LO`/`MASK_HI` halves, `vcc_lo`/`vcc_hi`, and `s_bfm_b64` bitfields). `s_bcnt1_i32_b64`/`b32`, `s_bcnt0_i32_b64`/`b32`, `s_ff1_i32_b64`/`b32`, `s_ff0_i32_b64`/`b32`, and `s_bitcmp0/1_b32/b64` reconstruct the 64-bit wave mask via `OpGroupNonUniformBitwiseOr` (`GroupNonUniformArithmetic`), restricting 32-bit half ops and `s_cmp_eq/lg_u32` (`wave_equal`) to the known 32-bit half in wave64. Known remaining gaps: `s_cmp_eq/lg_u32` comparing opposite halves (lo vs hi) falls back to a whole-wave vote. GPU-checked with `runtime/test/shaders/cs_wave64_ballot.asm` and `cs_wm_*.asm` on AMD Radeon RX 9070 XT (64-wide subgroup); semantic test coverage in `tests/semantic/test_scalar_bitcmp.py` and `tests/semantic/test_scalar_alu_shifts.py`. |
|
||||
| Mesh/compute input registers (historical measurement) | An early read-before-write analysis over all compute and mesh shaders found **compute** v0 (880), v0–v1 (614), v0–v2 (50), consistent with AMD's local thread ID x/y/z in v0/v1/v2, and scalar inputs centred on a pointer at s[4:5] and s6/s7. **Mesh:** every one of 2,969 reads exactly **v5**, plus s3 (always arithmetic), s[16:17] and s19–s23. The early pass also read FSSM 0x13C as the group width and compared the first SGPR multiply against it (82 match, 151 don't, 1,447 no simple multiply) and wrongly concluded that 0x13C was not the group width; the matching register varied by shader (s6/s10/s7/s9…). PSV0 gave the real thread-group sizes (32×1×1 for 1,253, 8×8×1 for 416, …). **Superseded:** 0x13C/0x140/0x144 are the thread-group size, `COMPUTE_PGM_RSRC2` at 0x138 gives the per-shader user-SGPR count and enabled workgroup IDs, and mesh takes NumThreads, limits and topology from PSV0 with v5 as the workgroup index. All 2,689 CS and 9,282 mesh shaders translate now (see the Compute shaders and Mesh shaders rows). |
|
||||
|
||||
@ -56,6 +56,8 @@ PIXEL_BITS = {"ps_legacy_mul": (0, 0, 0, 0x40c00000),
|
||||
"ps_ops3": (0xfffffffa, 0x44660066, 0x44aabbcc, 16), "ps_ops4": (0x34000010, 0x00120800, 0xbeef0000, 0x12343c00),
|
||||
"ps_ops5": (0x12340010, 0xbeef0800, 0xaaaaffff, 0xdeadbc00),
|
||||
"ps_ops6": (0xf800ffff, 0x01000010, 0x00800800, 0x8000fff0),
|
||||
"ps_ops7": (0x00ff8077, 0xff0000ff, 0x89abcdef, 0x00070003),
|
||||
"ps_ops8": (0x80000000, 0xffffffff, 0x000f100e, 0x0f0f0f1f),
|
||||
"ps_scc": (1, 1, 3, 0x80000000), "ps_sdwa": (0x000000f1, 0xfffefff2, 0x3c003344, 0xfff70000)}
|
||||
PIXEL_TESTS = sorted((*PIXEL_BITS, "ps_bary", "ps_flat", "ps_bitmask_perm", "ps_uniform_branch"))
|
||||
|
||||
|
||||
18
runtime/test/shaders/ps_ops7.asm
Normal file
18
runtime/test/shaders/ps_ops7.asm
Normal file
@ -0,0 +1,18 @@
|
||||
; v_perm_b32 (byte selects 0-7, 12 = 0x00, >= 13 = 0xff, 8-11 = sign of bytes 1/3/5/7 of {S0, S1}),
|
||||
; v_alignbit_b32 (shift taken mod 32), v_med3_i32 vs v_med3_u32 on the same operands.
|
||||
; Expected mrt0 bits: 0x00ff8077, 0xff0000ff, 0x89abcdef, 0x00070003
|
||||
v_mov_b32_e32 v0, 0x80112233
|
||||
v_mov_b32_e32 v1, 0x4455e677
|
||||
v_mov_b32_e32 v2, 0x0c0d0700
|
||||
v_perm_b32 v3, v0, v1, v2
|
||||
v_mov_b32_e32 v2, 0x0b0a0908
|
||||
v_perm_b32 v4, v0, v1, v2
|
||||
v_mov_b32_e32 v5, 0x12345678
|
||||
v_mov_b32_e32 v6, 0x9abcdef0
|
||||
v_alignbit_b32 v7, v5, v6, 36
|
||||
v_mov_b32_e32 v8, -5
|
||||
v_med3_i32 v9, v8, 7, 3
|
||||
v_med3_u32 v10, v8, 7, 3
|
||||
v_lshl_add_u32 v11, v10, 16, v9
|
||||
exp mrt0 v3, v4, v7, v11 done vm
|
||||
s_endpgm
|
||||
23
runtime/test/shaders/ps_ops8.asm
Normal file
23
runtime/test/shaders/ps_ops8.asm
Normal file
@ -0,0 +1,23 @@
|
||||
; v_mul_hi_u32 / v_mul_hi_i32, v_bcnt_u32_b32 with an accumulator, v_ffbl_b32 / v_ffbh_u32 (and v_ffbh_u32 of 0
|
||||
; = 0xffffffff), v_xad_u32 and v_add3_u32 wrapping.
|
||||
; Expected mrt0 bits: 0x80000000, 0xffffffff, 0x000f100e, 0x0f0f0f1f
|
||||
v_mov_b32_e32 v0, 0x80000001
|
||||
v_mov_b32_e32 v1, -1
|
||||
v_mul_hi_u32 v2, v0, v1
|
||||
v_mov_b32_e32 v3, -2
|
||||
v_mov_b32_e32 v4, 0x40000000
|
||||
v_mul_hi_i32 v5, v3, v4
|
||||
v_mov_b32_e32 v6, 0xf0f00001
|
||||
v_bcnt_u32_b32 v7, v6, 5
|
||||
v_mov_b32_e32 v8, 0x00010000
|
||||
v_ffbl_b32_e32 v9, v8
|
||||
v_ffbh_u32_e32 v10, v8
|
||||
v_lshl_add_u32 v11, v9, 8, v7
|
||||
v_lshl_add_u32 v11, v10, 16, v11
|
||||
v_mov_b32_e32 v12, 0xf0f0f0f0
|
||||
v_xad_u32 v13, v12, -1, 1
|
||||
v_mov_b32_e32 v14, 0
|
||||
v_ffbh_u32_e32 v15, v14
|
||||
v_add3_u32 v16, v13, 16, v15
|
||||
exp mrt0 v2, v5, v11, v16 done vm
|
||||
s_endpgm
|
||||
@ -581,6 +581,8 @@ def run_suite(a, work: str) -> int:
|
||||
"ps_legacy_mul": (0, 0, 0, 0x40C00000), # same expectation as check.py
|
||||
"ps_ops5": (0x12340010, 0xBEEF0800, 0xAAAAFFFF, 0xDEADBC00), # from the .asm headers
|
||||
"ps_ops6": (0xF800FFFF, 0x01000010, 0x00800800, 0x8000FFF0),
|
||||
"ps_ops7": (0x00FF8077, 0xFF0000FF, 0x89ABCDEF, 0x00070003),
|
||||
"ps_ops8": (0x80000000, 0xFFFFFFFF, 0x000F100E, 0x0F0F0F1F),
|
||||
}
|
||||
if name in const_wants:
|
||||
ok, detail = check_pixel_const(raw, const_wants[name])
|
||||
|
||||
16
tests/semantic/fixtures/disasm/ps_ops7.s
Normal file
16
tests/semantic/fixtures/disasm/ps_ops7.s
Normal file
@ -0,0 +1,16 @@
|
||||
; ps_ops7 test fixture generated by tests/semantic/regen_fixtures.py from runtime/test/shaders/ps_ops7.asm
|
||||
v_mov_b32_e32 v0, 0x80112233
|
||||
v_mov_b32_e32 v1, 0x4455e677
|
||||
v_mov_b32_e32 v2, 0x0c0d0700
|
||||
v_perm_b32 v3, v0, v1, v2
|
||||
v_mov_b32_e32 v2, 0x0b0a0908
|
||||
v_perm_b32 v4, v0, v1, v2
|
||||
v_mov_b32_e32 v5, 0x12345678
|
||||
v_mov_b32_e32 v6, 0x9abcdef0
|
||||
v_alignbit_b32 v7, v5, v6, 36
|
||||
v_mov_b32_e32 v8, -5
|
||||
v_med3_i32 v9, v8, 7, 3
|
||||
v_med3_u32 v10, v8, 7, 3
|
||||
v_lshl_add_u32 v11, v10, 16, v9
|
||||
exp mrt0 v3, v4, v7, v11 done vm
|
||||
s_endpgm
|
||||
21
tests/semantic/fixtures/disasm/ps_ops8.s
Normal file
21
tests/semantic/fixtures/disasm/ps_ops8.s
Normal file
@ -0,0 +1,21 @@
|
||||
; ps_ops8 test fixture generated by tests/semantic/regen_fixtures.py from runtime/test/shaders/ps_ops8.asm
|
||||
v_mov_b32_e32 v0, 0x80000001
|
||||
v_mov_b32_e32 v1, -1
|
||||
v_mul_hi_u32 v2, v0, v1
|
||||
v_mov_b32_e32 v3, -2
|
||||
v_mov_b32_e32 v4, 0x40000000
|
||||
v_mul_hi_i32 v5, v3, v4
|
||||
v_mov_b32_e32 v6, 0xf0f00001
|
||||
v_bcnt_u32_b32 v7, v6, 5
|
||||
v_mov_b32_e32 v8, 0x00010000
|
||||
v_ffbl_b32_e32 v9, v8
|
||||
v_ffbh_u32_e32 v10, v8
|
||||
v_lshl_add_u32 v11, v9, 8, v7
|
||||
v_lshl_add_u32 v11, v10, 16, v11
|
||||
v_mov_b32_e32 v12, 0xf0f0f0f0
|
||||
v_xad_u32 v13, v12, -1, 1
|
||||
v_mov_b32_e32 v14, 0
|
||||
v_ffbh_u32_e32 v15, v14
|
||||
v_add3_u32 v16, v13, 16, v15
|
||||
exp mrt0 v2, v5, v11, v16 done vm
|
||||
s_endpgm
|
||||
@ -16,7 +16,7 @@ HERE = os.path.dirname(os.path.abspath(__file__))
|
||||
ROOT = os.path.dirname(os.path.dirname(HERE))
|
||||
ASM_DIR = os.path.join(ROOT, "runtime", "test", "shaders")
|
||||
FIXTURE_DIR = os.path.join(HERE, "fixtures", "disasm")
|
||||
SHADERS = ("ps_sdwa", "ps_ops", "ps_ops2", "ps_ops3", "ps_ops4", "ps_ops5", "ps_ops6", "ps_legacy_mul",
|
||||
SHADERS = ("ps_sdwa", "ps_ops", "ps_ops2", "ps_ops3", "ps_ops4", "ps_ops5", "ps_ops6", "ps_ops7", "ps_ops8", "ps_legacy_mul",
|
||||
"ps_vcc_x2", "ps_flat", "cs_bounds")
|
||||
|
||||
|
||||
|
||||
@ -400,6 +400,13 @@ def run_fragment(text, inputs=None, push_constants=None, memory=None):
|
||||
elif op == "OpISubBorrow":
|
||||
x, y = val(a[1]) & MASK, val(a[2]) & MASK
|
||||
values[res] = ((x - y) & MASK, 1 if x < y else 0)
|
||||
elif op in ("OpUMulExtended", "OpSMulExtended"):
|
||||
# Result struct {low, high} of the full 64-bit product (SPIR-V spec, 32-bit scalars only).
|
||||
x, y = val(a[1]) & MASK, val(a[2]) & MASK
|
||||
if op == "OpSMulExtended":
|
||||
x, y = _s32(x), _s32(y)
|
||||
p = (x * y) & 0xFFFFFFFFFFFFFFFF
|
||||
values[res] = (p & MASK, p >> 32)
|
||||
elif op == "OpIEqual":
|
||||
values[res] = val(a[1]) == val(a[2])
|
||||
elif op == "OpINotEqual":
|
||||
@ -479,8 +486,27 @@ def run_fragment(text, inputs=None, push_constants=None, memory=None):
|
||||
values[res] = f32(abs(args[0]))
|
||||
elif name == "UMin":
|
||||
values[res] = min(args)
|
||||
elif name == "UMax":
|
||||
values[res] = max(args)
|
||||
elif name == "SMax":
|
||||
values[res] = max(args, key=_s32)
|
||||
elif name == "SMin":
|
||||
values[res] = min(args, key=_s32)
|
||||
elif name in ("UClamp", "SClamp"):
|
||||
# min(max(x, minVal), maxVal) (GLSL.std.450; undefined if minVal > maxVal, which raises here).
|
||||
key = _s32 if name == "SClamp" else (lambda v: v)
|
||||
x, lo, hi = args
|
||||
if key(lo) > key(hi):
|
||||
raise UnsupportedConstruct(f"{name} with minVal > maxVal (undefined)")
|
||||
values[res] = min(max(x, lo, key=key), hi, key=key)
|
||||
elif name == "FindILsb":
|
||||
# Bit number of the least significant 1 bit, -1 if the value is 0 (GLSL.std.450).
|
||||
x = args[0] & MASK
|
||||
values[res] = (x & -x).bit_length() - 1 & MASK if x else MASK
|
||||
elif name == "FindUMsb":
|
||||
# Bit number of the most significant 1 bit, -1 if the value is 0 (GLSL.std.450).
|
||||
x = args[0] & MASK
|
||||
values[res] = x.bit_length() - 1 if x else MASK
|
||||
elif name == "FindSMsb":
|
||||
x = _s32(args[0])
|
||||
if x in (0, -1):
|
||||
|
||||
@ -173,6 +173,22 @@ class InterpreterTests(unittest.TestCase):
|
||||
self.assertEqual(run_word("%res = OpExtInst %uint %glsl FindSMsb %cFF\n"), 0xFFFFFFFF)
|
||||
self.assertEqual(run_word("%res = OpExtInst %uint %glsl FindSMsb %c80\n"), 7)
|
||||
self.assertEqual(run_word("%res = OpExtInst %uint %glsl FindSMsb %cF0\n"), 3)
|
||||
# FindILsb / FindUMsb: bit number of the lowest / highest 1 bit, -1 for 0 (GLSL.std.450).
|
||||
self.assertEqual(run_word("%res = OpExtInst %uint %glsl FindILsb %c0\n"), 0xFFFFFFFF)
|
||||
self.assertEqual(run_word("%res = OpExtInst %uint %glsl FindILsb %cF0\n"), 4)
|
||||
self.assertEqual(run_word("%res = OpExtInst %uint %glsl FindUMsb %c0\n"), 0xFFFFFFFF)
|
||||
self.assertEqual(run_word("%res = OpExtInst %uint %glsl FindUMsb %cF0\n"), 31)
|
||||
self.assertEqual(run_word("%res = OpExtInst %uint %glsl FindUMsb %c80\n"), 7)
|
||||
# UMax / SMin and the clamps compare as the name says: 0xffffffff is the largest unsigned, -1 signed.
|
||||
self.assertEqual(run_word("%res = OpExtInst %uint %glsl UMax %cFF %c1\n"), 0xFFFFFFFF)
|
||||
self.assertEqual(run_word("%res = OpExtInst %uint %glsl SMin %cFF %c1\n"), 0xFFFFFFFF)
|
||||
self.assertEqual(run_word("%res = OpExtInst %uint %glsl UClamp %cFF %c1 %c8\n"), 8)
|
||||
self.assertEqual(run_word("%res = OpExtInst %uint %glsl SClamp %cFF %c1 %c8\n"), 1)
|
||||
self.assertEqual(run_word("%res = OpExtInst %uint %glsl SClamp %c4 %cF0 %c8\n"), 4)
|
||||
with self.assertRaises(si.UnsupportedConstruct): # minVal > maxVal
|
||||
run_word("%res = OpExtInst %uint %glsl UClamp %c4 %c8 %c1\n")
|
||||
self.assertEqual(run_word("%b = OpUGreaterThanEqual %bool %c8 %c8\n%res = OpSelect %uint %b %c1 %c0\n"), 1)
|
||||
self.assertEqual(run_word("%b = OpUGreaterThanEqual %bool %c1 %cFF\n%res = OpSelect %uint %b %c1 %c0\n"), 0)
|
||||
self.assertEqual(run_word("%x = OpBitcast %float %c0\n%s = OpExtInst %float %glsl Sin %x\n"
|
||||
"%res = OpBitcast %uint %s\n"), 0)
|
||||
|
||||
@ -203,7 +219,7 @@ class InterpreterTests(unittest.TestCase):
|
||||
|
||||
def test_unsupported_constructs_are_rejected(self):
|
||||
for body in ("%res = OpUDiv %uint %c2 %c1\n", # opcode not modelled
|
||||
"%res = OpExtInst %uint %glsl FindUMsb %c2\n", # ext inst not modelled
|
||||
"%res = OpExtInst %uint %glsl Ldexp %c2 %c1\n", # ext inst not modelled
|
||||
"%res = OpBitFieldUExtract %uint %cFF %c32 %c1\n", # undefined per spec
|
||||
"%res = OpShiftLeftLogical %uint %cFF %c32\n", # undefined per spec
|
||||
"%res = OpShiftRightLogical %uint %cFF %c32\n", # undefined per spec
|
||||
|
||||
@ -16,6 +16,15 @@ ISA semantics used (AMD RDNA2 ISA reference, VALU/VOP3/VOP3P chapters):
|
||||
v_sin_f16/v_cos_f16 input is a number of turns: sin/cos(S * 2*pi), rounded to binary16; high half kept.
|
||||
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.
|
||||
|
||||
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
|
||||
@ -32,6 +41,8 @@ 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_FLAT = [0x00000101, 0x00000102, 0x3F000000, 0x3E800000]
|
||||
EXPECTED_BOUNDS = {0x00: 0x12345678, 0x04: 0x12345678, 0x08: 0x00000000, 0x0C: 0xEEEEEEEE}
|
||||
@ -103,6 +114,49 @@ def reference_ops6():
|
||||
_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_vcc_x2():
|
||||
return [0x11223344, 0x55667788, 0, 0]
|
||||
|
||||
@ -154,6 +208,8 @@ class OracleTests(unittest.TestCase):
|
||||
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_flat(), EXPECTED_FLAT)
|
||||
self.assertEqual(reference_bounds(), EXPECTED_BOUNDS)
|
||||
@ -185,6 +241,16 @@ class TranslatorValueSemantics(unittest.TestCase):
|
||||
# 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_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
|
||||
|
||||
Reference in New Issue
Block a user