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

Merged
tahffo68hk-hash merged 2 commits from upstream-pr/521 into main 2026-11-28 10:56:58 +00:00
tahffo68hk-hash commented 2026-11-24 06:52:31 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by tahffo68hk-hash on 2026-11-24T06:52:31Z.


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
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5467544949 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/521). Originally posted by [tahffo68hk-hash](https://github.com/tahffo68hk-hash) on 2026-11-24T06:52:31Z. --- ### 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
thesubtleties commented 2026-11-24 20:30:50 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by thesubtleties on 2026-11-24T20:30:50Z.


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)

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7143661118 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/521#issuecomment-7143661118). Originally posted by [thesubtleties](https://github.com/thesubtleties) on 2026-11-24T20:30:50Z. --- 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)
PierreEbele commented 2026-11-24 21:52:39 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by PierreEbele on 2026-11-24T21:52:39Z.


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

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7145506705 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/521#issuecomment-7145506705). Originally posted by [PierreEbele](https://github.com/PierreEbele) on 2026-11-24T21:52:39Z. --- 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
MoonEyes commented 2026-11-28 10:56:53 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T10:56:53Z.


Red/green: the PR's tests fail on main and pass with this PR (Linux, Python 3.13.18).
Targeted batch of 23 PRs (their tests, the tests importing the changed modules, the docs tests) on main 3ca0707: no new failure, Linux / Python 3.13.
AI-assisted (Claude Code, Claude Opus 5.5)

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7238225243 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/521#issuecomment-7238225243). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-28T10:56:53Z. --- Red/green: the PR's tests fail on main and pass with this PR (Linux, Python 3.13.18). Targeted batch of 23 PRs (their tests, the tests importing the changed modules, the docs tests) on main 3ca0707: no new failure, Linux / Python 3.13. AI-assisted (Claude Code, Claude Opus 5.5)
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
ProjectLeonida/mandy!521
No description provided.