diff --git a/docs/design.md b/docs/design.md index ba4c33fa1c..0955f85bda 100644 --- a/docs/design.md +++ b/docs/design.md @@ -510,6 +510,7 @@ How the generated SPIR-V expects the runtime to work: | Formerly untranslated | Mesh (9,282), geometry (195) and compute (2,689) now translate; `s_swappc_b64` is replaced by Vulkan vertex inputs (see *Vertex fetch*) and the `tbuffer_load_format_*` forms use the instruction's format. Packed `tbuffer_load_format_d16_{x,xy,xyz,xyzw}` load two 16-bit components per VGPR, with the same final partial write as MUBUF. Native gfx1036 wave32/64 confirmed all four widths for RGBA8_UINT and RGBA8_UNORM with a conflicting 32_UINT V# format. Both packed and ordinary MTBUF loads ignore the V# channel selectors and use identity for the instruction format, zero-filling missing channels. Native gfx1036 measurements compared multiple V# permutations with MUBUF as a control. An INVALID V# format (0) suppresses the MTBUF fetch even at a valid address inside its bounds. Native gfx1036 wave32/64 returned zero components at all four widths and preserved the untouched half of an odd D16 destination, as specified for unbound resources in the [RDNA2 ISA, §8.1.4](https://www.amd.com/content/dam/amd/en/documents/radeon-tech-docs/instruction-set-architectures/rdna2-shader-instruction-set-architecture.pdf). A translated vertex fetch on RTX 5080 and Radeon Graphics also followed a change to the instruction format between two draws with identical vertex records and V#. Fixed UNORM and SNORM loads share the exact integer quotient for each magnitude width across instructions and channels (checked against rationally rounded binary32 values on RTX 5080 and Radeon Graphics). The gfx1013 disassembler omits `format:` for the [GFX10 MTBUF default](https://llvm.org/docs/AMDGPUModifierSyntax.html#ufmt), `BUF_FMT_8_UNORM` (code 1). A few rare ops are still reported by name rather than guessed. | | `v_cubema_f32` signed zero | Whenever the selected major axis is ±0.0, `v_cubema_f32` returns `+0.0` (`0x00000000`), never `-0.0` (`0x80000000`), while preserving NaNs and signed non-zero major-axis values (`2.0 * m`). Emitted as `OpFOrdEqual %bool m %f0` selecting `%f0` over `OpFMul m 2.0`, so `-0.0` maps to `+0.0`, NaN compares false and propagates, and non-zero finite/infinite values double with sign preserved. Until 2026-11-22 both `tools/rdna2spirv.py` and `tools/f32_fuzz.py` multiplied `m` by `2.0` directly and returned `-0.0` when `z = -0.0` on `(±0.0, ±0.0, -0.0)` (or when `-0.0` was selected alongside NaN axes). **Measured natively on RDNA2** (`gfx1036`, AMD Radeon(TM) Graphics, Windows driver `32.0.21042.62`, wave32 & wave64, all four MODE combinations `flush`/`keep`/`no_dx10`/`ieee` via `tools/hw_oracle/`): all 8 `(±0.0, ±0.0, ±0.0)` triples, `-v` source negation of `+0.0`, `mul:2`, negative denormals, and `(-0.0, qNaN, qNaN)` returned `0x00000000`, while `(-qNaN, 1.0, 1.0)` returned `0xffc00000` and `(-1.0, qNaN, qNaN)` returned `0xc0000000`. Checked by `tests/semantic/test_valu_cube.py` (`test_signed_zero_triples_and_nan_cubema`), `tests/test_f32_fuzz.py` (`test_cube_major_axis`), and `tools/f32_fuzz.py --oracle hw --ops v_cubema_f32,v_cubeid_f32,v_cubesc_f32,v_cubetc_f32`. | | `v_dot2c_i32_i16`, `v_dot8c_i32_i4` | VOP2/VOP3 accumulating forms of `v_dot2_i32_i16` and `v_dot8_i32_i4` (`D = sum(S0.elem[k] * S1.elem[k]) + D`, signed 2×16-bit and 8×4-bit). Wraps at 32 bits by default and saturates to `[INT32_MIN, INT32_MAX]` with VOP3 `clamp` (sharing the `v_dot2_i32_i16`/`v_dot8_i32_i4` signed-carry path); `op_sel`, `neg`/`abs`, and DPP/SDWA are refused. Registered in read-before-write VGPR tracking alongside `v_dot4c_i32_i8`. Source: LLVM AMDGPU `VOP2Instructions.td` (`HasDot4Insts` / `HasDot3Insts`, `gfx908` VOP2/VOP3 syntax; not in the default `gfx1013`/`gfx103x` feature set). **Not measured on AMD hardware** (translated Vulkan lowering checked on RTX 5070 by @duudiis: 40,960/40,960 exact words across wave32 and emulated wave64). Checked bit-for-bit on the CPU (`spirv_mini_interp`) and with `spirv-val` by `tests/semantic/test_alu_dotc.py`; not run on the shader corpus. | +| Wave64 graphics: three-component D16 buffer loads | With full EXEC, X/Y overwrite the first destination word. Only the second word retains old bits (its high half). Address and descriptor dependencies apply to both words. The classifier keeps its conservative result for masked writes and values carrying proof tags. The synthetic `ps_wave64_d16_xyz.asm` fixture and RTX 4090 pixel readbacks cover the split. | | Out-of-bounds typed buffer loads and `DST_SEL=1` | When a MUBUF `buffer_load_format_{x,xy,xyz,xyzw}` or `buffer_load_format_d16_{x,xy,xyz,xyzw}` is out of bounds (`OOB_SELECT` 0–3, `num_records == 0`, partial-element spill, or swizzled OOB), memory is not accessed and raw data channels (`DST_SEL` 4..7) read 0, while the V# `DST_SEL` swizzle still runs: `DST_SEL=0` returns 0 and `DST_SEL=1` returns `1.0f` (`0x3F800000`, `d16` `0x3C00`) iff V# `FORMAT[6:0]` is a valid float, normalized or scaled buffer format (`1..77` ending in `_UNORM`, `_SNORM`, `_USCALED`, `_SSCALED`, or `_FLOAT`), and integer `1` (`0x00000001`, `d16` `0x0001`) for `UINT`/`SINT`, `INVALID` (`0`), and reserved codes (`78..127`). `d16_x` and `d16_xyz` preserve the unaddressed upper 16 bits of the final destination VGPR, and MTBUF `tbuffer_load_format_*` ignores V# `DST_SEL` on both out-of-bounds and `FORMAT=0` loads (returning 0 in addressed channels). Until 2026-11-22 `Gen.buffer_load_format` clamped the post-swizzle result to 0 when `in_b` was false (`SHADER-429`), dropping `DST_SEL=1` on out-of-bounds loads and returning `1.0f` instead of `1` for `DST_SEL=1` with `FORMAT=0`. **Hardware-verified on RDNA2** (`gfx1036`, Windows 11, driver `32.0.21042.62`, wave32 and wave64, 746 kernels via `tools/hw_oracle`: all 41 `Gen.FORMATS` across `xyzw`/`d16_xyzw`/`d16_xyz`/`d16_x`, all 128 7-bit `FORMAT` codes `0..127` for both `f32` and `d16`, `OOB_SELECT` 0–3, partial spill, swizzled OOB, MTBUF controls, and inactive EXEC lanes), Vulkan GPU-checked across all 128 7-bit `FORMAT` codes (`xyzw`, `d16_xyzw`, `d16_xyz`, `d16_x`) and the `cs_fmt_*`/`cs_oob_*`/`cs_bounds`/`cs_buf_*` fixtures on NVIDIA GeForce RTX 5090 (driver `32.0.16.1088`) and AMD Radeon Graphics (`gfx1036`, driver `32.0.21042.62`), and CPU/`spirv-val`-checked by `tests/semantic/test_buffer_oob_dst_sel.py`. | | `v_div_fixup_f32` | Measured natively on an AMD Radeon(TM) Graphics RDNA2 GPU (`gfx1036`, not the console's `gfx1013`; Windows driver 32.0.21042.62, `tools/hw_oracle`, wave32 and wave64 identical on every case: 256 seeded triples across 4 MODEs plus 73 targeted special-case/modifier rows, 0 mismatches). Computes `div_fixup_f32(S0=quotient, S1=denom, S2=numer)` with pure integer SPIR-V ops under the game's inferred MODE (`IEEE=0`, `denorm32=0`, `DX10_CLAMP=1`): VOP3 `abs` (clear bit 31) then `neg` (flip bit 31) apply bitwise to `S0`/`S1`/`S2` before classification (including NaN payloads); `S1`/`S2` subnormals flush to signed zero (`exp == 0`) while `S0` subnormals are preserved; priority order is (1) `NaN(S2) → S2`, (2) `NaN(S1) → S1` (signalling NaNs pass unchanged under `IEEE=0`, quieted only when `IEEE=1`), (3) `0/0` or `±inf/±inf → 0xFFC00000` (`-qNaN`), (4) `zero(S2) ∨ inf(S1) → ±0.0`, (5) `zero(S1) ∨ inf(S2) → ±inf`, (6) `exp(S2) − exp(S1) ≤ −151 → ±0.0` (pure biased-exponent check, beats `NaN(S0)` and `inf(S0)`; no overflow check), (7) `NaN(S0) → ±inf`, (8) `copysign(S0, sign(S1) ⊕ sign(S2))`. Output modifiers `mul:2`/`mul:4`/`div:2` apply before `clamp`, and `clamp` maps NaN to `+0.0` (`DX10_CLAMP=1`) before `FClamp` to `[0, 1]`. Not modelled: `IEEE=1` sNaN quieting, `denorm32=3` keeping `S1`/`S2` subnormals, and the hardware `omod` `-0 → +0` quirk (same as the other f32 ops). Checked bit-for-bit against 73 measured `gfx1036` words in `tests/semantic/test_alu_div_fixup_f32.py`. | | Atomic natural alignment, 64-bit bounds, and `buffer_atomic_{fmin,fmax}` | Measured natively on RDNA2 (AMD Radeon(TM) Graphics, `gfx1036`, Windows driver `32.0.21042.62`, wave32 and wave64 via `tools/hw_oracle/`): **natural alignment** is enforced on every 32-bit and 64-bit buffer/global atomic (`buffer_atomic*`, `buffer_atomic*_x2`, `global_atomic*`, `global_atomic*_x2`), even under `OOB_SELECT = 2` (DISABLED). A 32-bit atomic requires `(addr & 3) == 0` (`offset = 1, 2` and `base + 2, offset = 0` are dropped; `base + 2, offset = 2` succeeds) and a 64-bit `_x2` atomic requires `(addr & 7) == 0` (`offset = 2, 4` and `base + 4, offset = 0` are dropped; `base + 4, offset = 4` succeeds). When dropped (OOB or unaligned), memory is untouched, an active `glc` lane receives `0` (32-bit) or `(0, 0)` (64-bit) in `vdst`/`vdata`, and an inactive lane (`EXEC = 0`) preserves `vdst`/`vdata`. Independently confirmed on a second `gfx1036` (driver `24.10.24`): without the alignment guard, an unaligned SPIR-V `OpAtomicAdd` corrupts the aligned dword (`100 -> 0xDEADBEF3`), whereas with the guard memory stays untouched and `0` is returned. `Gen.atomic_aligned` guards all six atomic emitters on `addr & 3 == 0` / `addr & 7 == 0`, merges `0` via `OpPhi` on skipped paths, and writes through `Gen.dst` so inactive lanes keep their prior register value while active unaligned/OOB lanes receive `0`. **64-bit partial bounds (`buffer_atomic*_x2`)**: the same `gfx1036` wave32/wave64 measurements confirm the all-or-nothing 8-byte bounds rule (`fixed_fmt = 62`) across all four `OOB_SELECT` modes (answering the unmeasured note in the `buffer_atomic_{and,or,xor,swap}_x2` row): mode 3 (RAW) requires `offs + 8 <= num_records` (`0/8` and `8/16` succeed; `0/7`, `0/5`, `0/4`, `8/15`, `8/12` drop cleanly); mode 0 (STRUCTURED_WITH_OFFSET) requires `idx < num_records` and `off + 8 <= stride` (`stride = 8, off = 0`, `stride = 16, off = 8`, `stride = 12, off = 0` succeed; `stride = 7, off = 0` and `stride = 12, off = 8` drop); mode 1 (STRUCTURED) checks `idx < num_records`; mode 2 (DISABLED) checks `num_records != 0`. **`buffer_atomic_{fmin,fmax}`**: lowered via `Gen.buffer_atomic_float` sharing `Gen._emit_atomic_fminmax_cas` (relaxed Device-scope `OpAtomicLoad` seed + `OpAtomicCompareExchange` + `GLSL.std.450` `NMin`/`NMax` CAS loop, no float-atomic extension required), enforcing V# bounds, 4-byte alignment, and `glc` return (`lds` and non-1-VGPR `vdata` raise `Unsupported`). On `gfx1036`, normal floats, `±inf`, `-0` vs `+0` (`fmin(-0, +0) = -0`, `fmax(-0, +0) = +0`), and `qNaN` (returns the non-NaN operand) match `NMin`/`NMax`; **known approximation**: the `gfx1036` L2 atomic unit quiets `sNaN` (`0x7f800001 -> 0x7fc00001`) regardless of `MODE`, while f32 subnormal handling follows the wave's `MODE.denorm32` and preserves sign (independently verified on a second `gfx1036`, wave32/wave64: under `denorm32 = 0`, subnormals flush to signed zero — `fmax(0x80000001, 0x80000002) -> 0x80000000 (-0)`, `fmax(0x00000001, 0x00000002) -> +0` — whereas under `denorm32 = 3`, subnormals are preserved and `NMin`/`NMax` is exact); `NMin`/`NMax` does not model `sNaN` quieting or `denorm32 = 0` subnormal flushing. CPU-checked by `tests/semantic/test_buffer_atomic_fminmax_and_align.py` (value grid, multi-lane CAS contention, OOB/partial-bounds matrix, inactive vs active-unaligned distinction across all six atomic families, and SPIR-V structural checks). | diff --git a/tests/semantic/fixtures/ps_wave64_d16_xyz.asm b/tests/semantic/fixtures/ps_wave64_d16_xyz.asm new file mode 100644 index 0000000000..8d84c95d5d --- /dev/null +++ b/tests/semantic/fixtures/ps_wave64_d16_xyz.asm @@ -0,0 +1,15 @@ +; X/Y replace v6. A lane-dependent high half in v7 cannot reach an export of v6. +s_mov_b64 s[10:11], exec +v_mov_b32_e32 v6, 0 +v_mbcnt_lo_u32_b32 v7, -1, 0 +v_mbcnt_hi_u32_b32 v7, -1, v7 +v_lshlrev_b32_e32 v7, 16, v7 +s_mov_b32 s4, 0 +s_mov_b32 s5, 0 +s_mov_b32 s6, 0x10000 +s_mov_b32 s7, 0x31045fac +v_mov_b32_e32 v5, 0x100 +buffer_load_format_d16_xyz v[6:7], v5, s[4:7], 0 offen +s_waitcnt vmcnt(0) +exp mrt0 v6, v6, v6, v6 done vm +s_endpgm diff --git a/tests/semantic/test_wave64_halves_partial_dst.py b/tests/semantic/test_wave64_halves_partial_dst.py index 6f8260df26..0535913d57 100644 --- a/tests/semantic/test_wave64_halves_partial_dst.py +++ b/tests/semantic/test_wave64_halves_partial_dst.py @@ -13,6 +13,7 @@ python -I tests/semantic/test_wave64_halves_partial_dst.py """ import os +from pathlib import Path import sys import unittest @@ -271,6 +272,51 @@ def test_dpp_clean_controls(self): ]) # -- 4. Partial d16 loads and operands() edge cases + def test_d16_xyz_result_words(self): + fixture = Path(HERE) / "fixtures" / "ps_wave64_d16_xyz.asm" + lines = [line.strip() for line in fixture.read_text(encoding="ascii").splitlines() + if line.strip() and not line.lstrip().startswith(";")] + with self.subTest(fixture=fixture.name): + (tier, _, _), _ = meta_of("ps_wave64_d16_xyz", lines) + self.assertEqual(tier, "A") + + for op, fmt in (("buffer_load_format_d16_xyz", ""), + ("tbuffer_load_format_d16_xyz", " format:[BUF_FMT_16_16_16_16_FLOAT]")): + for seed, address, export, expected in ( + (6, 5, 6, "A"), (6, 5, 7, "A"), (7, 5, 6, "A"), (7, 5, 7, "C"), + (6, 6, 6, "C"), (6, 6, 7, "C"), (7, 7, 6, "C"), (7, 7, 7, "C")): + with self.subTest(op=op, seed=seed, address=address, export=export): + program = [ + "s_mov_b64 s[10:11], exec", + "v_mov_b32_e32 v5, 0", "v_mov_b32_e32 v6, 0", "v_mov_b32_e32 v7, 0", + f"v_mbcnt_lo_u32_b32 v{seed}, -1, 0", + f"v_mbcnt_hi_u32_b32 v{seed}, -1, v{seed}", + f"v_lshlrev_b32_e32 v{seed}, 16, v{seed}", + f"{op} v[6:7], v{address}, s[0:3], 0{fmt} offen", + f"exp mrt0 v{export}, v{export}, v{export}, v{export} done vm", "s_endpgm", + ] + (tier, reasons, _), _ = meta_of("ps_d16_word", program) + self.assertEqual(tier, expected, reasons) + + def test_d16_xyz_descriptor_lane_and_partial_exec(self): + for export in (6, 7): + (tier, reasons, _), _ = meta_of("ps_d16_tid", [ + "s_mov_b64 s[10:11], exec", "s_mov_b32 s3, 0x00800000", + "v_mov_b32_e32 v5, 0", "v_mov_b32_e32 v6, 0", "v_mov_b32_e32 v7, 0", + "buffer_load_format_d16_xyz v[6:7], v5, s[0:3], 0 offen", + f"exp mrt0 v{export}, v{export}, v{export}, v{export} done vm", "s_endpgm", + ]) + self.assertEqual(tier, "C", reasons) + + (tier, reasons, _), _ = meta_of("ps_d16_masked", [ + "s_mov_b64 s[10:11], exec", + "v_mbcnt_lo_u32_b32 v6, -1, 0", "v_mbcnt_hi_u32_b32 v6, -1, v6", + "v_mov_b32_e32 v5, 0", "v_cmp_eq_u32_e32 vcc, 0, v0", "s_and_saveexec_b64 s[12:13], vcc", + "buffer_load_format_d16_xyz v[6:7], v5, s[0:3], 0 offen", + "s_mov_b64 exec, s[12:13]", "exp mrt0 v6, v6, v6, v6 done vm", "s_endpgm", + ]) + self.assertEqual(tier, "C", reasons) + def test_partial_d16_loads_preserve_prior_taint(self): for tag, body in ( ("global_short_d16", [ diff --git a/tools/wave64_halves.py b/tools/wave64_halves.py index 9b5305344b..c7c24f8dea 100644 --- a/tools/wave64_halves.py +++ b/tools/wave64_halves.py @@ -619,9 +619,9 @@ def idiom(name): if ev is not None: ev["idioms"].add(name) - def src_taint(): + def src_taint(inputs): t = 0 - for x in srcs: + for x in inputs: t |= self.rd(st, ins, x) for r in uses: t |= T.get(r, 0) | (CTRL if (id(ins), r) in self.stale else 0) @@ -767,7 +767,7 @@ def bits_violation(t, allowed=0): put(dests[0], BASE | (ELECT if elected else 0), ("elect", st["xg"][1]) if elected else None) return - t_src = src_taint() + t_src = src_taint(srcs) # a lane mask read as data (not as a mask operand of a mask instruction, a select or an exec write): on # hardware it is the 64 lane bits, here the bits of the lanes of the half md = 0 @@ -783,7 +783,20 @@ def bits_violation(t, allowed=0): md |= MASKD | X t_src |= md if op.startswith(("buffer_load", "tbuffer_load")): - t_src |= self.add_tid_lane(n, i, a, mods) + implicit_lane = self.add_tid_lane(n, i, a, mods) + t_src |= implicit_lane + if (op in ("buffer_load_format_d16_xyz", "tbuffer_load_format_d16_xyz") + and len(a) >= 3 and a[0].get("k") == "vgpr" and a[0].get("n") == 2 and st["f"] + and not t_src & (TAG_BITS | BASE | CNT)): + # Full EXEC overwrites X/Y. Only Z keeps the upper half of its old word. + # Leave masked writes and proof-carrying values to the conservative transfer below. + xy = {"k": "vgpr", "r": a[0]["r"]} + z = {"k": "vgpr", "r": a[0]["r"] + 1} + address = src_taint(a[1:]) | md | implicit_lane + packed_z = address | self.rd(st, ins, z) + put(xy, address) + put(z, packed_z) + return # --- lane masks and counts if op in ("s_bcnt1_i32_b64", "s_ff1_i32_b64") and len(a) == 2 and self.is_mask(ins, a[1]):