upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/docs/buffer_bounds.md
diff options
context:
space:
mode:
authorStørm <52797150+AC-Storm-YT@users.noreply.github.com>2026-11-21 22:04:38 -0500
committerStørm <52797150+AC-Storm-YT@users.noreply.github.com>2026-11-21 22:04:38 -0500
commit0ff02e06306f921e2131f59653fcc66472c7ca11 (patch)
treeb0585521df833e8547aa69e0af3dc8397b7b538e /docs/buffer_bounds.md
parent8df277fb035b384971497f6f9790f7fc4b9ec1d1 (diff)
docs: V# OOB_SELECT bounds measured on RDNA2 (SHADER-116)
docs/buffer_bounds.md records which buffer accesses are out of range per the V# OOB_SELECT field, measured natively on a Ryzen 7 9800X3D iGPU (gfx1036, RDNA2) with raw buffer_load_dword / buffer_store_dword: 732 cases (modes 0-3, stride 0/16/18, NUM_RECORDS 0/3/18/48, offen / idxen / both, raw with soffset), three identical runs. RDNA2 follows Mesa's GFX11 column, not GFX10 (729 vs 696 of 732): mode 0 checks offset + 4 > stride and raw mode offset + 4 > N. Raw mode also counts soffset. Modes 1 and 2 match both columns. Loads and stores agree. The console's gfx1013 (GFX10.1) is left open: it needs an RDNA1 card. docs/README.md lists the new note. AI-assisted (Claude Code).
Diffstat (limited to 'docs/buffer_bounds.md')
-rw-r--r--docs/buffer_bounds.md51
1 files changed, 51 insertions, 0 deletions
diff --git a/docs/buffer_bounds.md b/docs/buffer_bounds.md
new file mode 100644
index 000000000..3593a6f1e
--- /dev/null
+++ b/docs/buffer_bounds.md
@@ -0,0 +1,51 @@
1# Buffer bounds: V# `OOB_SELECT`, measured on hardware
2
3Which buffer accesses the hardware treats as out of range, per the V# `OOB_SELECT` field (word 3 bits [29:28]),
4measured natively on AMD GPUs (SHADER-116). The translator does not read this field yet; SHADER-110 (@AlxcBTW)
5makes it pick the bounds check by mode, and the contract row is "Buffer bounds checking" in
6[design.md](design.md). Out of range, a load returns 0 and a store or atomic does not touch memory.
7
8## Measured rules
9
10`N` is `NUM_RECORDS` (V# word 2), `index` the VGPR index (`idxen`), `offset` the VGPR byte offset (`offen`) and
11`soffset` the scalar offset. Every access below is a 4-byte `buffer_load_dword` / `buffer_store_dword`.
12
13| `OOB_SELECT` | Out of range on RDNA2 (gfx1036) when | Mesa GFX10 column | Mesa GFX11 column |
14|---|---|---|---|
15| 0 structured with offset | `index >= N` or `offset + 4 > stride` | `offset >= stride`: differs | same |
16| 1 structured | `index >= N` | same | same |
17| 2 disabled | `N == 0` | same | same |
18| 3 raw | `offset + soffset + 4 > N`; `index * stride` moves the address but is not checked | `offset >= N`: differs | `offset + 4 > N`, without `soffset` |
19
20- **RDNA2 follows Mesa's GFX11 column**, not the GFX10 one: of 732 cases, 729 match GFX11 and 696 match GFX10.
21 Every GFX10 miss is an access that only partly fits, for example a raw buffer with `N = 3` read at offset 0.
22- **In raw mode `soffset` is part of the checked offset.** The 3 cases that match neither column are raw reads at
23 offset 8 with `soffset` 8 and `N = 18`: 8 + 8 + 4 > 18, out of range on hardware.
24- Loads and stores agree in every case.
25- In-range accesses at a dword-aligned address read and wrote the expected dword (0 exceptions). An address that is
26 not a multiple of 4 (stride 18 with `index > 0`) is rounded by the hardware; where such an access lands was not
27 part of this measurement.
28- @AlxcBTW measured RDNA3.5 (Radeon 880M, gfx1150) through the HIP runtime and found it matches the GFX11 column
29 ([finding](https://github.com/ItsNotRexed/Leonida/issues/374#issuecomment-7072793165)). The RDNA2 result here
30 agrees with it, plus the `soffset` rule.
31
32**Open:** the console target is gfx1013 (GFX10.1); gfx1036 is GFX10.3. Mesa uses one GFX10 column for both, and
33this measurement shows that column is wrong for GFX10.3. Whether GFX10.1 matches GFX10.3 here needs an RDNA1 card
34(gfx1010–1012, RX 5000 series).
35
36## How it was measured
37
38Ryzen 7 9800X3D integrated GPU (gfx1036, RDNA2), AMD driver 3679.0 (PAL, LC), Windows 11. A standalone OpenCL
39host (not in this repository) loads the driver's `OpenCL.dll`, and each case is a one-lane kernel whose inline
40assembly runs a single `buffer_load_dword` or `buffer_store_dword` with a V# built by hand:
41
42- word 0–1: the buffer's address, `STRIDE` in word 1 [29:16];
43- word 2: `NUM_RECORDS`;
44- word 3: `DST_SEL` x/y/z/w, `FORMAT` = GFX10 `32_FLOAT` (22), `RESOURCE_LEVEL` = 1, `OOB_SELECT` = 0–3.
45
46The buffer holds a pattern (dword `i` = `0xA0000000 | i`), so a non-zero load names the dword it read, and a store
47writes a marker whose position is found by comparing the whole buffer afterwards. The cases are modes 0–3 × stride
480, 16, 18 × `N` 0, 3, 18, 48 × `offen` (offsets 0, 12, 16, 44, 48), `idxen` (indices 0, 2, 3, 4) and
49`idxen offen` (six index/offset pairs), plus raw cases with `soffset` 8: 732 in all, each a load and a store.
50Three runs gave identical results. Each case was compared with both Mesa columns as listed in @AlxcBTW's finding
51(Mesa `src/amd/common/ac_descriptors.c`).