Commit Graph

7 Commits

Author SHA1 Message Date
e520d4b381 test(semantic): add stride wrapping, negative offsets, and negative controls 2026-11-22 17:36:48 +01:00
9d241bc6f3 test(semantic): add SIMD multi-lane tests modeling partial component OOB zero fill 2026-11-22 17:30:52 +01:00
49615d0b45 test(semantic): add reference oracle for buffer resource descriptor OOB clamping 2026-11-22 17:28:39 +01:00
06cec1d6ba fix(translator): snapshot source literals before destination stores in mov64 and s_mov_b32
In s_mov_b64, snapshot both source halves from sgpr_imm before store_reg
and destination assignments to prevent overlapping 64-bit copies (such as
s_mov_b64 s[6:7], s[5:6]) from overwriting the high word source before it
is read. Likewise read s_mov_b32 source sgpr_imm before dst so self-copies
do not invalidate the source entry.

Added tests covering s_mov_b64 64-bit pair copies and overlapping copies.
Thanks to @josevictorp for catching the overlapping copy issue in PR review.
2026-11-22 19:29:38 +06:00
77506e2f6d perf(translator): track s_mov_b64, s_movk_i32 and SGPR copies in sgpr_imm
buffer_bounds evaluates mode = None if lit3 is None else lit3 >> 28 & 3 to fold the OOB_SELECT mode into a single static bounds-check branch at translate time. When lit3 is unknown, it falls back to run-time extraction (OpBitFieldUExtract), 3x OpIEqual comparisons, and 6x cascading OpSelect instructions.

Previously, self.sgpr_imm only recorded literals from s_mov_b32. Shaders routinely load 64-bit descriptor pairs using s_mov_b64, or 16-bit sign-extended mode words using s_movk_i32, or copy preloaded constants via SGPR moves.

- In mov64, track immediate constants for both low and high SGPRs when desc_cache_ok(), and propagate copies from known SGPR pairs.
- In s_mov_b32, propagate known scalar immediates on SGPR-to-SGPR moves.
- In s_movk_i32, record the sign-extended 16-bit immediate in sgpr_imm.

Added tests in tests/semantic/test_buffer_oob_select.py verifying that s_mov_b64, s_movk_i32, and SGPR copy moves eliminate run-time OOB mode extraction and fold into static mode paths.
2026-11-22 19:29:17 +06:00
ee7c52a102 Translator: swizzled buffer V#s and ADD_TID_ENABLE (SHADER-231)
MUBUF/MTBUF accesses follow the RDNA2 ISA's swizzled buffer addressing
(8.1.5, tables 33/35/37) with the V# fields of Mesa's gfx10-rsrc.json:
SWIZZLE_ENABLE word1 bit 31, INDEX_STRIDE word3 [22:21], ADD_TID_ENABLE
word3 bit 23, element size fixed at 4 bytes. ADD_TID adds the wave lane to
the index (swizzled or linear), dword k of a swizzled access is 4 * IS bytes
after dword k - 1, and OOB_SELECT 3 with swizzle and a stride checks like
mode 0. Literal V# words fold; run-time ones use IS = 2^(swz * (3 + n)), so
IS = 1 is the linear address. A literal swizzled V# used to be Unsupported
and a run-time one was translated unswizzled.

Tests: tests/semantic/test_buffer_swizzle.py (hand-worked addresses, literal
and run-time V#s) and the GPU fixture cs_buf_swizzle.asm.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 13:06:51 +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