rdna2spirv: route ds_add_f32, ds_cmpst_f32, and ds_*_addtid_b32 through lds_access bounds check #521

Open
github-bot wants to merge 2 commits from github-bot/gh-521 into main AGit
Owner

@⁠tahffo68hk-hash on GitHub · 2026-11-24 06:52 UTC · original
tahffo68hk-hash:fix/shader-lds-bound-access → main · +166 −29 · 2 files · 2 commits · open

Summary

(AI-assisted) Fixes SHADER-LDS-BOUND-ACCESS: in ools/rdna2spirv.py, three LDS handlers still called self.lds_ptr() directly instead of routing through self.lds_load() / self.lds_store() / self.lds_access():

  • ds_read_addtid_b32 / ds_write_addtid_b32
  • ds_add_f32 / ds_add_rtn_f32
  • ds_cmpst_f32 / ds_cmpst_rtn_f32

When self.lds_bound is active (SHADER-309: a compute shader's LDS array is sized to its RSRC2 LDS_SIZE allocation rather than a power-of-two wrapped buffer):

  1. Out-of-bounds accesses silently wrapped and corrupted live LDS instead of dropping writes and returning
**@⁠tahffo68hk-hash** on GitHub · 2026-11-24 06:52 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/521) `tahffo68hk-hash:fix/shader-lds-bound-access` → `main` · +166 −29 · 2 files · 2 commits · open ### Summary (AI-assisted) Fixes SHADER-LDS-BOUND-ACCESS: in ools/rdna2spirv.py, three LDS handlers still called self.lds_ptr() directly instead of routing through self.lds_load() / self.lds_store() / self.lds_access(): - ds_read_addtid_b32 / ds_write_addtid_b32 - ds_add_f32 / ds_add_rtn_f32 - ds_cmpst_f32 / ds_cmpst_rtn_f32 When self.lds_bound is active (SHADER-309: a compute shader's LDS array is sized to its RSRC2 LDS_SIZE allocation rather than a power-of-two wrapped buffer): 1. **Out-of-bounds accesses silently wrapped and corrupted live LDS** instead of dropping writes and returning
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:05:50 +00:00
Author
Owner

@⁠thesubtleties on GitHub · 2026-11-24 20:30 UTC · original

CPU check of 205540176 merged onto main 3aa97542.

The new tests check structure only, so I ran six value cases in spirv_mini_interp with a 384-dword bound: ds_add_rtn_f32, ds_cmpst_rtn_f32 and the addtid pair, each at byte 512 and at 1536 (out of range). All six are right here and pass spirv-val; with main's translator four are wrong (byte 512 wraps to 0). Worth adding as tests.

lds_access finds its exit label dynamically, so passing it a CAS loop is fine. run_semantic_tests.py tests/semantic: 471 files / 6,172 tests, 0 failed.

Not tested: wave64 emulation values, GPU, game corpus. AI-assisted (Claude Code)

**@⁠thesubtleties** on GitHub · 2026-11-24 20:30 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/521#issuecomment-7143661118) CPU check of `205540176` merged onto main `3aa97542`. The new tests check structure only, so I ran six value cases in `spirv_mini_interp` with a 384-dword bound: `ds_add_rtn_f32`, `ds_cmpst_rtn_f32` and the addtid pair, each at byte 512 and at 1536 (out of range). All six are right here and pass `spirv-val`; with main's translator four are wrong (byte 512 wraps to 0). Worth adding as tests. `lds_access` finds its exit label dynamically, so passing it a CAS loop is fine. `run_semantic_tests.py tests/semantic`: 471 files / 6,172 tests, 0 failed. Not tested: wave64 emulation values, GPU, game corpus. AI-assisted (Claude Code)
Author
Owner

@⁠PierreEbele on GitHub · 2026-11-24 21:52 UTC · original

Reviewed 20554017: the translator change in tools/rdna2spirv.py is solid — no lds_ptr callers remain outside lds_access, the 3 bounded-LDS tests in tests/semantic/test_lds_bound_access.py pass here and fail on origin/main (missing OpULessThan %bool, still masking with %c17f), all 28 other test_lds*.py files plus test_cs_shared_memory_limit.py (29 files) pass on both trees, native spirv_mini_interp probes (384-dword bound rsrc2=0x18088, unbounded 0x40008, LDS_SIZE=0) confirm the OOB-drop/in-bounds fixes for ds_add[_rtn]_f32, ds_cmpst[_rtn]_f32, and ds_*_addtid_b32, real wave64-emulate (wave64=True, emulate=True) validates with spirv-as/spirv-val (including x_round and shrunk LDS_SIZE=100), and run_compute_workgroup executes emulated ds_*_addtid_b32 cleanly. One test bug to fix first: test_wave64_emulate_structure_valid never actually enables wave64 emulation (wave64=False, emulate=False, output identical to w64_emulate=False) because _make_cs_fssm omits the FSSM magic and the assembly lacks a wave64 marker, and it doesn't assert last_gen.emulate or the bounds check (so it also passes on main). Adding s_mov_b64 exec, -1, asserting rdna2spirv.translate.last_gen.emulate, and checking the bounds assertions makes it genuinely cover wave64 emulation (verified passing _check_cfg and spirv-val here and failing on main). Pre-existing side finding on main (not this PR): rsrc2 with TIDIG_COMP_CNT=3 (e.g. 0x1F888) emits OpCompositeExtract %uint %lci 3 on %v3uint, rejected by spirv-val. AI-assisted review.
Recommendation: Fix first

**@⁠PierreEbele** on GitHub · 2026-11-24 21:52 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/521#issuecomment-7145506705) Reviewed 20554017: the translator change in `tools/rdna2spirv.py` is solid — no `lds_ptr` callers remain outside `lds_access`, the 3 bounded-LDS tests in `tests/semantic/test_lds_bound_access.py` pass here and fail on `origin/main` (missing `OpULessThan %bool`, still masking with `%c17f`), all 28 other `test_lds*.py` files plus `test_cs_shared_memory_limit.py` (29 files) pass on both trees, native `spirv_mini_interp` probes (384-dword bound `rsrc2=0x18088`, unbounded `0x40008`, `LDS_SIZE=0`) confirm the OOB-drop/in-bounds fixes for `ds_add[_rtn]_f32`, `ds_cmpst[_rtn]_f32`, and `ds_*_addtid_b32`, real `wave64-emulate` (`wave64=True, emulate=True`) validates with `spirv-as`/`spirv-val` (including `x_round` and shrunk `LDS_SIZE=100`), and `run_compute_workgroup` executes emulated `ds_*_addtid_b32` cleanly. One test bug to fix first: `test_wave64_emulate_structure_valid` never actually enables wave64 emulation (`wave64=False, emulate=False`, output identical to `w64_emulate=False`) because `_make_cs_fssm` omits the `FSSM` magic and the assembly lacks a wave64 marker, and it doesn't assert `last_gen.emulate` or the bounds check (so it also passes on `main`). Adding `s_mov_b64 exec, -1`, asserting `rdna2spirv.translate.last_gen.emulate`, and checking the bounds assertions makes it genuinely cover wave64 emulation (verified passing `_check_cfg` and `spirv-val` here and failing on `main`). Pre-existing side finding on `main` (not this PR): `rsrc2` with `TIDIG_COMP_CNT=3` (e.g. `0x1F888`) emits `OpCompositeExtract %uint %lci 3` on `%v3uint`, rejected by `spirv-val`. AI-assisted review. **Recommendation:** Fix first
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

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

Merge

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