xshader: check group shared accesses against the guest's LDS allocation #225

Manually merged
github merged 4 commits from github-bot/gh-225 into main 2026-11-26 14:39:30 +00:00 AGit
Owner

@⁠ReverendOzmund on GitHub · 2026-11-26 11:40 UTC · original
ReverendOzmund:xshader-lds-bounds → main · +211 −34 · 9 files · 4 commits · merged 2026-11-26 14:39 UTC

not run yet. The GPU suites don't execute translated programs with out-of-range LDS addresses, so I'd value an AMD or NVIDIA run of tools/check_translator_gpu.py from someone whose host builds the full check.

**@⁠ReverendOzmund** on GitHub · 2026-11-26 11:40 UTC · [original](https://github.com/brcly/TuxBox/pull/225) `ReverendOzmund:xshader-lds-bounds` → `main` · +211 −34 · 9 files · 4 commits · merged 2026-11-26 14:39 UTC not run yet. The GPU suites don't execute translated programs with out-of-range LDS addresses, so I'd value an AMD or NVIDIA run of `tools/check_translator_gpu.py` from someone whose host builds the full check.
RDNA2 reads 0 past a group's LDS allocation and drops the write. The translator masked addresses with 8191 into an array that is often smaller, an undefined access that NVIDIA can trap on. Route every compute LDS access through bounds-checked helpers.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

Claude-Session: https://claude.ai/code/session_01KP1nQKEc17PvmrwfPtLi8Z
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 11:41:40 +00:00
The translated program writes each lane's word and a second value 32 KiB further on, then reads both back. The lane's word must keep its value and the far read must return 0. A wrapping index overwrites the first and reads it back.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

Claude-Session: https://claude.ai/code/session_01KP1nQKEc17PvmrwfPtLi8Z
A group of 32 or 96 lanes ends in half a guest wave64, and a lane read can name a lane of the missing half, past tb_swizzle. Read 0 there instead of indexing past the array.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

Claude-Session: https://claude.ai/code/session_01KP1nQKEc17PvmrwfPtLi8Z
Author
Owner

@⁠ReverendOzmund on GitHub · 2026-11-26 11:59 UTC · original

Added tools/check_lds_bounds_gpu.py and registered it as lds-bounds in the translator GPU checks. Each lane writes its own word and a second value 32 KiB past it, then reads both back: the lane's word must survive and the far read must return 0. With the old & 8191u index the far write wraps onto the lane's word, so this fails on main. I can't run the translator GPU checks on my host (no lld-link for the full check); a run on any NVIDIA or AMD card with python tools/check_translator_gpu.py --only lds-bounds ... would be appreciated.

**@⁠ReverendOzmund** on GitHub · 2026-11-26 11:59 UTC · [original](https://github.com/brcly/TuxBox/pull/225#issuecomment-7191429709) Added `tools/check_lds_bounds_gpu.py` and registered it as `lds-bounds` in the translator GPU checks. Each lane writes its own word and a second value 32 KiB past it, then reads both back: the lane's word must survive and the far read must return 0. With the old `& 8191u` index the far write wraps onto the lane's word, so this fails on main. I can't run the translator GPU checks on my host (no lld-link for the full check); a run on any NVIDIA or AMD card with `python tools/check_translator_gpu.py --only lds-bounds ...` would be appreciated.
Author
Owner

@⁠NickStallman on GitHub · 2026-11-26 12:02 UTC · original

AMD run of python tuxbox.py check on this PR's head (6f510a5):

  • GPU: AMD Raphael iGPU of a Ryzen 9 9950X (1002:13c0), Mesa RADV, Linux 7.0.0, GE-Proton11-14 (Proton backend). Host profile wave 64-64.
  • All groups passed, 100 gates, including "Shader translator on the GPU" (tools/check_translator_gpu.py), "Lanes and fixtures on the GPU" and the D3D12 regression controls.
  passed   Shader compiler tests
  passed   Build
  passed   Lanes and fixtures on the GPU
  passed   D3D12 regression controls
  passed   Shader translator on the GPU
All checks passed.

The RTX 5090 is busy with a game run right now. I can add an NVIDIA run afterwards if it's still needed.

**@⁠NickStallman** on GitHub · 2026-11-26 12:02 UTC · [original](https://github.com/brcly/TuxBox/pull/225#issuecomment-7191491668) AMD run of `python tuxbox.py check` on this PR's head (`6f510a5`): - GPU: AMD Raphael iGPU of a Ryzen 9 9950X (`1002:13c0`), Mesa RADV, Linux 7.0.0, GE-Proton11-14 (Proton backend). Host profile wave 64-64. - All groups passed, 100 gates, including "Shader translator on the GPU" (`tools/check_translator_gpu.py`), "Lanes and fixtures on the GPU" and the D3D12 regression controls. ``` passed Shader compiler tests passed Build passed Lanes and fixtures on the GPU passed D3D12 regression controls passed Shader translator on the GPU All checks passed. ``` The RTX 5090 is busy with a game run right now. I can add an NVIDIA run afterwards if it's still needed.
Author
Owner

@⁠ReverendOzmund on GitHub · 2026-11-26 12:03 UTC · original

Also covered the lane-exchange array: tb_swizzle is sized to the group, and groups of 32 or 96 lanes (allowed by the "complete blocks of 32 lanes" check) end in half a guest wave64, so (tb_lane & ~63u) | lane could index past it. Those reads now go through tb_swizzle_read() and return 0 past the end. 335 translator tests pass; exec_group assertions updated for the new form.

**@⁠ReverendOzmund** on GitHub · 2026-11-26 12:03 UTC · [original](https://github.com/brcly/TuxBox/pull/225#issuecomment-7191516065) Also covered the lane-exchange array: tb_swizzle is sized to the group, and groups of 32 or 96 lanes (allowed by the "complete blocks of 32 lanes" check) end in half a guest wave64, so `(tb_lane & ~63u) | lane` could index past it. Those reads now go through tb_swizzle_read() and return 0 past the end. 335 translator tests pass; exec_group assertions updated for the new form.
Author
Owner

@⁠ReverendOzmund on GitHub · 2026-11-26 12:04 UTC · original

Thanks Nick! Since that run I pushed two more commits (head be9055c): the lds-bounds translator GPU check (each lane writes its word and a second value 32 KiB past it; the word must survive and the far read must be 0), and the same bounds treatment for lane reads through tb_swizzle in 32/96-lane groups. If you get a chance after your game run, --only lds-bounds on the 5090 would be the most useful one, since NVIDIA is where out-of-range shared memory can actually fault.

**@⁠ReverendOzmund** on GitHub · 2026-11-26 12:04 UTC · [original](https://github.com/brcly/TuxBox/pull/225#issuecomment-7191527896) Thanks Nick! Since that run I pushed two more commits (head be9055c): the `lds-bounds` translator GPU check (each lane writes its word and a second value 32 KiB past it; the word must survive and the far read must be 0), and the same bounds treatment for lane reads through `tb_swizzle` in 32/96-lane groups. If you get a chance after your game run, `--only lds-bounds` on the 5090 would be the most useful one, since NVIDIA is where out-of-range shared memory can actually fault.
Author
Owner

@⁠NickStallman on GitHub · 2026-11-26 13:38 UTC · original

NVIDIA run of python tuxbox.py check on be9055c: RTX 5090 (10de:2b85), driver 595.99.02, GE-Proton11-14, Linux 7.0.0.

Everything passes except lds-bounds (FAIL lds-bounds False 8 2048 failed 8). The shader never ran, though: lds-bounds.json has guest_exit: 1 and error: "invalid compute seed lds00".

The cause seems to be the seed size, not the GPU:

  • tools/reference/independent-shaders/compute.cpp:8 has constexpr UINT words = 384. At lines 37–41 it rejects a .seed whose size isn't exactly 384 * 4 bytes.
  • check_lds_bounds_gpu.py writes WORDS = 4 * LANES = 256 words (1,024 bytes).

So every case is rejected before dispatch, and I'd expect the same on AMD. My earlier AMD run was on 6f510a5, before this check existed. Padding the seed to 384 words, and comparing the first 256 of the readback (or the full 384 against an expected buffer padded the same way), should let it run. I'm happy to rerun it on the 5090 once that's pushed.

The other groups all passed: Lanes and fixtures on the GPU, the D3D12 regression controls, and every other translator case.

**@⁠NickStallman** on GitHub · 2026-11-26 13:38 UTC · [original](https://github.com/brcly/TuxBox/pull/225#issuecomment-7193633907) NVIDIA run of `python tuxbox.py check` on `be9055c`: RTX 5090 (`10de:2b85`), driver 595.99.02, GE-Proton11-14, Linux 7.0.0. Everything passes except `lds-bounds` (`FAIL lds-bounds False 8 2048 failed 8`). The shader never ran, though: `lds-bounds.json` has `guest_exit: 1` and `error: "invalid compute seed lds00"`. The cause seems to be the seed size, not the GPU: - `tools/reference/independent-shaders/compute.cpp:8` has `constexpr UINT words = 384`. At lines 37–41 it rejects a `.seed` whose size isn't exactly `384 * 4` bytes. - `check_lds_bounds_gpu.py` writes `WORDS = 4 * LANES` = 256 words (1,024 bytes). So every case is rejected before dispatch, and I'd expect the same on AMD. My earlier AMD run was on `6f510a5`, before this check existed. Padding the seed to 384 words, and comparing the first 256 of the readback (or the full 384 against an expected buffer padded the same way), should let it run. I'm happy to rerun it on the 5090 once that's pushed. The other groups all passed: Lanes and fixtures on the GPU, the D3D12 regression controls, and every other translator case.
compute.cpp rejects any seed that isn't 384 words, and the shader's output view starts at word 96. Seed and compare the whole buffer, and write each lane's results over its own inputs inside the view.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

Claude-Session: https://claude.ai/code/session_01KP1nQKEc17PvmrwfPtLi8Z
Author
Owner

@⁠ReverendOzmund on GitHub · 2026-11-26 13:51 UTC · original

Thanks, that was my mistake: I missed that compute.cpp takes exactly 384 seed words and exposes a 192-word view from word 96. Pushed a fix: the whole 384-word buffer is seeded and compared, the inputs sit at word 96, and each lane writes its two results over its own inputs. With the old & 8191u index the far write wraps onto the lane's word, so the check still fails on main. Would appreciate the 5090 rerun when you get a chance.

**@⁠ReverendOzmund** on GitHub · 2026-11-26 13:51 UTC · [original](https://github.com/brcly/TuxBox/pull/225#issuecomment-7193925270) Thanks, that was my mistake: I missed that compute.cpp takes exactly 384 seed words and exposes a 192-word view from word 96. Pushed a fix: the whole 384-word buffer is seeded and compared, the inputs sit at word 96, and each lane writes its two results over its own inputs. With the old `& 8191u` index the far write wraps onto the lane's word, so the check still fails on main. Would appreciate the 5090 rerun when you get a chance.
github manually merged commit 3b8a220fbb into main 2026-11-26 14:39:30 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.