rdna2spirv: out-of-range s_buffer_load reads safely from heap base without branch (OLD-9916) #650

Open
github-bot wants to merge 3 commits from github-bot/gh-650 into main AGit
Owner

@⁠TanmaySatyam on GitHub · 2026-11-24 10:58 UTC · original
TanmaySatyam:fix/old-9916-smem-oob-safe-address → main · +317 −28 · 8 files · 3 commits · open

Claimed in the coordination issue as: OLD-9916

AI-assisted.

What and why

Carries forward old-pr/9916 (draft #184, original author LouisRiverstone / Luiz Neves) onto main (21625bca8), preserving both original author commits and adding one follow-up commit to mark runtime/test/shaders/cs_smem_oob_far.asm for tests/semantic/regen_fixtures.py (main's marker-based discovery):

  1. Preserved commits (Luiz Neves): Makes run-time-bounded s_buffer_load* branchless via OpSelect(in_range, addr, heap_base) so out-of-range dwords read safely from Xbox VA 0 (the always-mapped heap base) and select 0, avoiding llvmpipe hoisting loads out of OpSelectionMerge and segfaulting on >4 GB out-of-range offsets or zero-size descriptors with far bases; adds cs_smem_oob_far.asm and tests/semantic/test_smem_oob_safe_address.py.
  2. Rebase adaptation commit: Adds the ; regen_fixtures: header marker to runtime/test/shaders/cs_smem_oob_far.asm so tests/test_regen_fixtures.py passes on current main.

Testing & Verification

  • GPUs tested: NVIDIA GeForce RTX 5070 (Blackwell, Driver 591.74, Windows 11, Vulkan validation enabled):
    • vk_compute_test cs_smem_oob_far.spv 1 dump → 1 groups x 64: 0 mismatches, out[0..7] = 0 4008636142 0 0 0 4008636142 0 4008636142 (0 validation errors).
  • python -m unittest discover -s tests/semantic -p test_smem_oob_safe_address.py -v (6/6 OK)
  • python -m unittest discover -s tests/semantic -p test_scalar_mem_smem.py (44/44 OK)
  • python -I tests/test_regen_fixtures.py (7/7 OK)
  • python -I tests/test_text_write_line_endings.py (3/3 OK)
  • Clean-room verified: python -I scripts/check_no_game_data.py exited 0 on all modified/added files.
**@⁠TanmaySatyam** on GitHub · 2026-11-24 10:58 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/650) `TanmaySatyam:fix/old-9916-smem-oob-safe-address` → `main` · +317 −28 · 8 files · 3 commits · open Claimed in the coordination issue as: OLD-9916 AI-assisted. ### What and why Carries forward `old-pr/9916` (draft #184, original author `LouisRiverstone` / Luiz Neves) onto `main` (`21625bca8`), preserving both original author commits and adding one follow-up commit to mark `runtime/test/shaders/cs_smem_oob_far.asm` for `tests/semantic/regen_fixtures.py` (`main`'s marker-based discovery): 1. **Preserved commits (`Luiz Neves`):** Makes run-time-bounded `s_buffer_load*` branchless via `OpSelect(in_range, addr, heap_base)` so out-of-range dwords read safely from Xbox VA 0 (the always-mapped heap base) and select `0`, avoiding llvmpipe hoisting loads out of `OpSelectionMerge` and segfaulting on >4 GB out-of-range offsets or zero-size descriptors with far bases; adds `cs_smem_oob_far.asm` and `tests/semantic/test_smem_oob_safe_address.py`. 2. **Rebase adaptation commit:** Adds the `; regen_fixtures:` header marker to `runtime/test/shaders/cs_smem_oob_far.asm` so `tests/test_regen_fixtures.py` passes on current `main`. ### Testing & Verification - **GPUs tested:** NVIDIA GeForce RTX 5070 (Blackwell, Driver 591.74, Windows 11, Vulkan validation enabled): - `vk_compute_test cs_smem_oob_far.spv 1 dump` → `1 groups x 64: 0 mismatches`, `out[0..7] = 0 4008636142 0 0 0 4008636142 0 4008636142` (0 validation errors). - `python -m unittest discover -s tests/semantic -p test_smem_oob_safe_address.py -v` (6/6 OK) - `python -m unittest discover -s tests/semantic -p test_scalar_mem_smem.py` (44/44 OK) - `python -I tests/test_regen_fixtures.py` (7/7 OK) - `python -I tests/test_text_write_line_endings.py` (3/3 OK) - Clean-room verified: `python -I scripts/check_no_game_data.py` exited 0 on all modified/added files.
Rebuilt on main, which replaced one selection per dword with one per load (to
cut the blocks of the cascade-shadow CS). That still segfaults llvmpipe (Mesa
26.0.8, LLVM 21) on #3039's s12 = -4, offset:20 and on cs_smem_oob_far: the
load inside the selection is hoisted and reads 4 GB past the buffer.

The loads now have no branch: they read through OpSelect(dword 0 in range,
the address, the V#'s base), at index i when in range and 0 otherwise (main's
indexing), and each value is OpSelect(dword i in range, loaded, 0). Out of
range they read the buffer's first dword and the values are discarded; no
extra blocks at all.

- test_scalar_mem_smem.py's evaluator models OpSelect %uint and keeps loads
  through the out-of-range side of an address select out of reads.
- tests/semantic/test_smem_oob_safe_address.py: the no-branch shape (one
  selected pointer on dword 0's bound, a value select per dword), discarded
  reads only at the V# base's first dword, values unchanged, the fixture on
  the CPU.
- runtime/test/shaders/cs_smem_oob_far.asm: passes on llvmpipe with this rule,
  segfaults vk_compute_test with main's translator.
- docs/design.md row added.
@memorypressure on #4573: with no readable bytes (dword 0 out of range,
num_records 0 included) main read nothing, while the branchless form read the
V# base, which such a descriptor may leave anywhere. The fallback is now Xbox
VA 0: the start of the host buffer the runtime maps the GPU window into
(host_addr), so always readable. The earlier claim that 'the heap base is 0 in
vk_compute_test' was wrong (its output buffer is the heap); the heap-base
variant had segfaulted because it still selected the address inside the
branch.

- test_smem_oob_safe_address.py: discarded reads at VA 0, and a zero-size
  descriptor with a far base (num_records 0) reads only VA 0 and gives 0.
- cs_smem_oob_far: word 4 is now that zero-size far-base case; header refreshed
  for the branchless form. Passes on llvmpipe with LLVM 21 and 23.
- docs/design.md row corrected.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:13:56 +00:00
Author
Owner

@⁠trigger337 on GitHub · 2026-11-24 11:08 UTC · original

Hardware verification on AMD Radeon RX 6900 XT (RADV NAVI21, Mesa 26.2.5, Linux CachyOS, Vulkan 1.4.333):

  • Built cs_smem_oob_far.asm with runtime/test/shaders/build.py:
    • Native: vk_compute_test cs_smem_oob_far.spv 1 dump
      device: AMD Radeon RX 6900 XT (RADV NAVI21) (subgroup 32..64)
      1 groups x 64: 0 mismatches
      out[0..7] = 0 4008636142 0 0 0 4008636142 0 4008636142
      
    • Emulated (LEONIDA_W64_EMULATE=1): vk_compute_test cs_smem_oob_far.spv 1 dump
      device: AMD Radeon RX 6900 XT (RADV NAVI21) (subgroup 32..64)
      1 groups x 64: 0 mismatches
      out[0..7] = 0 4008636142 0 0 0 4008636142 0 4008636142
      
  • Semantic tests:
    • python3 -m unittest discover -s tests/semantic -p test_smem_oob_safe_address.py -v: 6/6 passed.
    • python3 -m unittest discover -s tests/semantic -p test_scalar_mem_smem.py: 44/44 passed.
    • python3 -I tests/test_regen_fixtures.py: 7/7 passed.
    • python3 -I tests/test_text_write_line_endings.py: 3/3 passed.
  • Clean-room check: python3 -I scripts/check_no_game_data.py passed on all modified files.

LGTM!

agent: yes
AI-assisted: yes

**@⁠trigger337** on GitHub · 2026-11-24 11:08 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/650#issuecomment-7129711867) Hardware verification on AMD Radeon RX 6900 XT (RADV NAVI21, Mesa 26.2.5, Linux CachyOS, Vulkan 1.4.333): * Built `cs_smem_oob_far.asm` with `runtime/test/shaders/build.py`: * Native: `vk_compute_test cs_smem_oob_far.spv 1 dump` ``` device: AMD Radeon RX 6900 XT (RADV NAVI21) (subgroup 32..64) 1 groups x 64: 0 mismatches out[0..7] = 0 4008636142 0 0 0 4008636142 0 4008636142 ``` * Emulated (`LEONIDA_W64_EMULATE=1`): `vk_compute_test cs_smem_oob_far.spv 1 dump` ``` device: AMD Radeon RX 6900 XT (RADV NAVI21) (subgroup 32..64) 1 groups x 64: 0 mismatches out[0..7] = 0 4008636142 0 0 0 4008636142 0 4008636142 ``` * Semantic tests: * `python3 -m unittest discover -s tests/semantic -p test_smem_oob_safe_address.py -v`: 6/6 passed. * `python3 -m unittest discover -s tests/semantic -p test_scalar_mem_smem.py`: 44/44 passed. * `python3 -I tests/test_regen_fixtures.py`: 7/7 passed. * `python3 -I tests/test_text_write_line_endings.py`: 3/3 passed. * Clean-room check: `python3 -I scripts/check_no_game_data.py` passed on all modified files. LGTM! agent: yes AI-assisted: yes
This pull request has changes conflicting with the target branch.
  • docs/design.md
  • scripts/run_gpu_tests.py
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/650/head:github-bot/gh-650'
git switch 'github-bot/gh-650'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-650'
git switch 'github-bot/gh-650'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-650'
git switch 'github-bot/gh-650'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-650'
git switch 'main'
git merge --squash 'github-bot/gh-650'
git switch 'main'
git merge --ff-only 'github-bot/gh-650'
git switch 'main'
git merge 'github-bot/gh-650'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.