Commit Graph

13 Commits

Author SHA1 Message Date
85cb97ee42 fix(shader): saturate unsigned D16 buffer fetches
Native RDNA2 clamps 32-bit unsigned contents to the 16-bit range before packing both halves. Reuse the integer narrowing helper for MUBUF and MTBUF while preserving full-width fetches and the unused high half.
2026-11-22 12:27:12 +01:00
2dfd8d4752 fix(shader): suppress MTBUF loads from unbound descriptors
The instruction format overrides a bound descriptor. Native gfx1036 returns zeros for FORMAT=INVALID even when its address and extent are otherwise usable. Gate the existing guarded load before reading memory.
2026-11-22 11:58:00 +01:00
7adce0dcbf fix(shader): use instruction identity selectors for MTBUF loads
Native RDNA2 ignores descriptor selectors for MTBUF and supplies zero for absent components. Preserve runtime descriptor swizzles for MUBUF and cover both paths with the same conflicting selectors.
2026-11-22 11:13:51 +01:00
761c532c7c feat(shader): translate packed fixed-format buffer loads
MTBUF encodes a format independently of the vertex buffer descriptor. Route its D16 loads through the existing fixed-format decode and packed destination writer so a valid vertex fetch can reach a draw.
2026-11-22 10:51:31 +01:00
6e17ca8071 fix(shader): preserve the trailing VGPR half in packed buffer loads
The RDNA2 buffer unit updates only the addressed components even on an out-of-bounds load. Clearing the last high half clobbers unrelated values held across an x or xyz load.
2026-11-22 10:24:54 +01:00
14887e6828 Translator: honour V# OOB_SELECT in MUBUF/MTBUF bounds checks
buffer_address() picked the bounds check from the stride alone and never read
word3. It now reads OOB_SELECT (bits 29:28) and applies the rule measured
natively on RDNA2 (gfx1036, docs/buffer_bounds.md; Mesa's GFX11 column): a
dword is out of range in mode 0 at idx >= NR or off + 4 > stride, mode 1 at
idx >= NR, mode 2 at NR == 0, mode 3 (RAW) at offs + 4 > NR, where off is
inst_offset + vaddr and offs adds soffset. A literal word3 folds the mode, a
run-time one selects with OpSelect.

Builds on the raw tail rule of #443 (per-dword loads): x2..x4 loads AND stores
are per dword in modes 0 and 3 (a store that straddled the edge used to write
past it), modes 1 and 2 take the whole access, a typed element
(buffer_load/store_format) is all or nothing at its format's size, an atomic
checks its dword's end. Measured on a Radeon 880M (gfx1150), a valid proxy for
RDNA2: 504 buffer_load_dword cases over idxen/offen/inst_offset/soffset at the
stride and record edges agree with the rules, plus the x2/x4, typed and atomic
edges.

Swizzle (V# word1 bit 31 SWIZZLE_ENABLE, word3 bit 23 ADD_TID_ENABLE; Mesa
gfx10-rsrc.json lines 326 and 337): a literal V# with either is Unsupported in
every mode; a run-time one is translated unswizzled (documented known gap).

A V# with word3 = 0 is mode 0 / stride 0 and so always out of range, as on
hardware: the harness output V# (vk_compute_test, interpreter push constants),
cs_bounds, cs_fmt_1010102, cs_store, mem_diff and the format tests now say
OOB_SELECT 3 (or 1 with a stride) explicitly.

Tests: tests/semantic/test_buffer_oob_select.py (33 hand-tabulated cases plus
multi-dword stores, typed elements and the swizzle gate, literal and run-time
V#), GPU tests cs_oob_select.asm and cs_oob_tail.asm (the second tells the end
check from Mesa's GFX10 start check). docs/design.md, Buffer bounds checking,
has the per-mode rule; docs/buffer_bounds.md notes the translator reads it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 07:40:20 +01:00
af153ed92a Merge upstream D16 load tests with fixed-format coverage 2026-11-21 21:22:14 -07:00
9bc8e17919 Honor the default format of GFX10 typed buffer loads 2026-11-21 20:51:44 -07:00
d8a9fd133a Tests: no PackHalf2x16 in d16 buffer loads and f16 buffer stores, and d16 normalized loads round to nearest even 2026-11-21 23:42:19 -04:00
178a4b47ff SHADER-86 follow-up: correctly rounded UNORM/SNORM decode with integer ops; add 8_SNORM, 16_SNORM, 8_8_SNORM
OpFDiv is allowed 2.5 ULP, and on an RX 6700 (AMD Windows 26.11.2) and an
RTX 5090 it returns the reciprocal-multiply bits, so #599's decode was only
correctly rounded in the CPU model (8_UNORM 130/256 exact on the RX 6700).

x/(2^n-1) in binary is x's n bits repeated, so a 64-bit multiply by the repeat
pattern, FindUMsb and the round bit give the correctly rounded f32 with integer
ops only; the tail never ends, so there are no ties. SNORM uses the same on the
magnitude with n-1 bits; the most negative code is -1.0.

Formats 2 (8_SNORM), 8 (16_SNORM) and 15 (8_8_SNORM) were missing from
FORMATS and decoded to 0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 03:36:22 +01:00
baa6beed3a SHADER-86: match RX 6700 typed buffer decode (repeat, OpFDiv, DST_SEL 1)
Missing channels use c mod n, UNORM/SNORM divide by (2^n-1), and DST_SEL 1 is integer 1 for UINT formats.
2026-11-21 22:23:21 -03:00
f9fb9f02a8 Translator: load mid-dword buffer_load_format elements from every dword they span
need used to be ceil(size/4) and only the first dword was shifted, so a
4-byte format at byte 3 (or an 8-byte format at byte 6) took its tail
from dword 0. Load ceil((byte_shift + size) / 4) dwords and shift the
whole window so the packed stream starts at the element. Found by the
FUZZ-5 fuzzer; left open in #234.
2026-11-21 16:25:42 -08:00
e4cacf51fa Translator: keep the buffer_load_format sub-dword merge shift below 32
buffer_load_format_* merges dword 1 above a sub-dword element with
w1 << (32 - bsh) and picks dword 0 when bsh is 0. For every dword-aligned
element, the discarded side shifts by 32, undefined in SPIR-V.
(32 - bsh) & 31 keeps it in range.

tests/semantic/test_buffer_load_format.py runs u32, u32x2/x4, uint8x4,
uint16x2/x4 and f16 loads from interpreter memory. spirv_mini_interp.py learns
the two things the format decode needs: OpConvertUToF/OpConvertSToF and GLSL
FMin/FMax (NaN operands raise UnsupportedConstruct).
2026-11-21 18:46:50 -03:00