diff options
| author | AlxcBTW <187763517+AlxcBTW@users.noreply.github.com> | 2026-11-22 07:40:20 +0100 |
|---|---|---|
| committer | AlxcBTW <187763517+AlxcBTW@users.noreply.github.com> | 2026-11-22 07:40:20 +0100 |
| commit | 14887e68280eb8fcd9f90953000ff4ff052e4c7e (patch) | |
| tree | 2169426acb0c53fe26a88c745705a220c7185113 /tools/mem_diff.py | |
| parent | 48ad23f0262452b6c3d09db98941bfedb8e9684d (diff) | |
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>
Diffstat (limited to 'tools/mem_diff.py')
| -rw-r--r-- | tools/mem_diff.py | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/tools/mem_diff.py b/tools/mem_diff.py index 0469d763e..56eac018d 100644 --- a/tools/mem_diff.py +++ b/tools/mem_diff.py | |||
| @@ -15,7 +15,7 @@ Addressing modelled (AMD RDNA2 ISA, buffer resource descriptor and MUBUF/SMEM ad | |||
| 15 | * s_buffer_load = V# base + soffset + imm. | 15 | * s_buffer_load = V# base + soffset + imm. |
| 16 | 16 | ||
| 17 | Every generated access lies inside its buffer (index < num_records for structured buffers, the whole access | 17 | Every generated access lies inside its buffer (index < num_records for structured buffers, the whole access |
| 18 | below num_records for raw ones), is dword aligned, and uses a word3 with no format: out-of-bounds behaviour, the | 18 | below num_records for raw ones), is dword aligned, and uses a word3 with no format (only OOB_SELECT: STRUCTURED with a stride, RAW without): out-of-bounds behaviour, the |
| 19 | s_buffer_load alignment truncation and swizzling depend on descriptor fields docs/design.md lists as not modelled, | 19 | s_buffer_load alignment truncation and swizzling depend on descriptor fields docs/design.md lists as not modelled, |
| 20 | so they are left to a GPU-confirmed follow-up instead of being guessed here. | 20 | so they are left to a GPU-confirmed follow-up instead of being guessed here. |
| 21 | 21 | ||
| @@ -352,7 +352,9 @@ def _soffset(rng, prog, budget): | |||
| 352 | 352 | ||
| 353 | def _emit_vsharp(rng, prog, base, stride, num_records): | 353 | def _emit_vsharp(rng, prog, base, stride, num_records): |
| 354 | word1 = (base >> 32) & 0xFFFF | (stride & 0x3FFF) << 16 | 354 | word1 = (base >> 32) & 0xFFFF | (stride & 0x3FFF) << 16 |
| 355 | for i, w in enumerate((base & MASK32, word1, num_records, 0)): | 355 | # word3: only OOB_SELECT (bits 29:28), the bounds check the accesses stay inside of: STRUCTURED for a stride, |
| 356 | # RAW without (the two RADV uses); every generated access is in range under either | ||
| 357 | for i, w in enumerate((base & MASK32, word1, num_records, OOB_STRUCTURED if stride else OOB_RAW)): | ||
| 356 | prog.lines.append(f"s_mov_b32 s{VSHARP + i}, {w:#x}") | 358 | prog.lines.append(f"s_mov_b32 s{VSHARP + i}, {w:#x}") |
| 357 | 359 | ||
| 358 | 360 | ||
| @@ -529,6 +531,7 @@ def gen_global(rng, prog): | |||
| 529 | # The five formats tbuffer loads use in the 1.0.2.1 corpus (counted over all 26,503 shaders). | 531 | # The five formats tbuffer loads use in the 1.0.2.1 corpus (counted over all 26,503 shaders). |
| 530 | TBUFFER_FORMATS = ("16_16_SNORM", "8_8_8_8_UNORM", "8_8_8_8_UINT", "2_10_10_10_UNORM", "16_16_16_16_UINT") | 532 | TBUFFER_FORMATS = ("16_16_SNORM", "8_8_8_8_UNORM", "8_8_8_8_UINT", "2_10_10_10_UNORM", "16_16_16_16_UINT") |
| 531 | XYZW = 4 | 5 << 3 | 6 << 6 | 7 << 9 | 533 | XYZW = 4 | 5 << 3 | 6 << 6 | 7 << 9 |
| 534 | OOB_STRUCTURED, OOB_RAW = 1 << 28, 3 << 28 # V# word3 OOB_SELECT | ||
| 532 | 535 | ||
| 533 | 536 | ||
| 534 | def _typed_codes(): | 537 | def _typed_codes(): |
| @@ -560,14 +563,14 @@ def gen_buffer_format(rng, prog): | |||
| 560 | records = REGION // stride | 563 | records = REGION // stride |
| 561 | index = rng.randrange(0, records) | 564 | index = rng.randrange(0, records) |
| 562 | _emit_vsharp(rng, prog, base, stride, records) | 565 | _emit_vsharp(rng, prog, base, stride, records) |
| 563 | prog.lines[-1] = f"s_mov_b32 s{VSHARP + 3}, {word3:#x}" | 566 | prog.lines[-1] = f"s_mov_b32 s{VSHARP + 3}, {word3 | OOB_STRUCTURED:#x}" |
| 564 | prog.lines.append(f"v_mov_b32 v{VADDR}, {index:#x}") | 567 | prog.lines.append(f"v_mov_b32 v{VADDR}, {index:#x}") |
| 565 | operands = f"v{VADDR}, s[{VSHARP}:{VSHARP + 3}], 0" | 568 | operands = f"v{VADDR}, s[{VSHARP}:{VSHARP + 3}], 0" |
| 566 | addr_mods = "idxen" | 569 | addr_mods = "idxen" |
| 567 | else: | 570 | else: |
| 568 | voff = rng.randrange(0, (REGION - 16) // size) * size | 571 | voff = rng.randrange(0, (REGION - 16) // size) * size |
| 569 | _emit_vsharp(rng, prog, base, 0, REGION) | 572 | _emit_vsharp(rng, prog, base, 0, REGION) |
| 570 | prog.lines[-1] = f"s_mov_b32 s{VSHARP + 3}, {word3:#x}" | 573 | prog.lines[-1] = f"s_mov_b32 s{VSHARP + 3}, {word3 | OOB_RAW:#x}" |
| 571 | prog.lines.append(f"v_mov_b32 v{VADDR}, {voff:#x}") | 574 | prog.lines.append(f"v_mov_b32 v{VADDR}, {voff:#x}") |
| 572 | operands = f"v{VADDR}, s[{VSHARP}:{VSHARP + 3}], 0" | 575 | operands = f"v{VADDR}, s[{VSHARP}:{VSHARP + 3}], 0" |
| 573 | addr_mods = "offen" | 576 | addr_mods = "offen" |
| @@ -683,7 +686,7 @@ def self_test(): | |||
| 683 | """Canaries: a hand-written case matches, and a corrupted reference is caught.""" | 686 | """Canaries: a hand-written case matches, and a corrupted reference is caught.""" |
| 684 | prog = Program() | 687 | prog = Program() |
| 685 | prog.memory = {0x2000: 0x11111111, 0x2004: 0x22222222, 0x2008: 0x33333333, 0x200C: 0x44444444} | 688 | prog.memory = {0x2000: 0x11111111, 0x2004: 0x22222222, 0x2008: 0x33333333, 0x200C: 0x44444444} |
| 686 | prog.lines = ["s_mov_b32 s0, 0x2000", "s_mov_b32 s1, 0", "s_mov_b32 s2, 0x10", "s_mov_b32 s3, 0", | 689 | prog.lines = ["s_mov_b32 s0, 0x2000", "s_mov_b32 s1, 0", "s_mov_b32 s2, 0x10", "s_mov_b32 s3, 0x30000000", |
| 687 | "v_mov_b32 v2, 4", "buffer_load_dwordx3 v[8:10], v2, s[0:3], 0 offen", "s_waitcnt vmcnt(0)", | 690 | "v_mov_b32 v2, 4", "buffer_load_dwordx3 v[8:10], v2, s[0:3], 0 offen", "s_waitcnt vmcnt(0)", |
| 688 | "v_mov_b32 v11, 7"] | 691 | "v_mov_b32 v11, 7"] |
| 689 | status, detail = run_one("ps_mem_canary", prog) | 692 | status, detail = run_one("ps_mem_canary", prog) |