[PR #95] rdna2spirv: guard image_bvh PhysicalStorageBuffer loads on active EXEC lanes #145

Open
opened 2026-11-26 20:16:56 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/95
Author: @Andretuta
Created: 11/24/2026
Status: 🔄 Open

Base: main ← Head: old-pr/9827


📝 Commits (1)

  • 1820512 rdna2spirv: guard image_bvh PhysicalStorageBuffer loads on active EXEC lanes

📊 Changes

2 files changed (+51 additions, -1 deletions)

View changed files

📝 tests/semantic/test_image_bvh_box.py (+42 -0)
📝 tools/rdna2spirv.py (+9 -1)

📄 Description

Carried over from old PR 9827 by Lewandox in the original Leonida repository, which went private on 23 Nov 2026. The code is the branch old-pr/9827, exactly that PR's last commit. All carried-over PRs are listed in #17.
Opened as a draft, and the CI runs the opening started were cancelled so 250 PRs don't fill the queue. Re-run CI here when you review it.
Lewandox: this is your work. Feel free to take it over, by pushing to the branch or opening your own PR and closing this one.


Original description (mentions and #N references are disabled; the numbers refer to the old repository):

Gen.image_bvh() in tools/rdna2spirv.py only predicated the final vgpr writes (out(k, ...)) on EXEC, never the PhysicalStorageBuffer loads (OpConvertUToPtr / OpLoad). In a divergent BVH traversal loop where finished lanes are masked off in EXEC and hold stale or null node pointers, inactive lanes still entered the triangle/box branches and issued 10-40 PSB loads from invalid addresses (risking VK_ERROR_DEVICE_LOST), unlike global_mem, global_sub, buffer_load, buffer_load_sub, and global_atomic which all guard their loads with self.active_b().

Wrap the PSB pointer conversion and node-type dispatch in an outer OpSelectionMerge / OpBranchConditional on self.active_b() so inactive lanes skip all PSB loads and leave v[vd:vd+3] untouched.

Added an inactive-lane (EXEC == 0) regression test in tests/semantic/test_image_bvh_box.py covering triangle (type=0) and box (type=4, 5) nodes with a read-tracking memory map (fails with 10 / 40 PSB reads before the fix, passes with 0 reads and preserved vdst after).

Claimed in #9065. AI-assisted; tested on Windows 11 / Python 3.12.10 with python -I -m unittest discover -s tests/semantic -p "*bvh*.py" -v, python -m compileall -q tools/rdna2spirv.py tests/semantic/test_image_bvh_box.py, and python -I scripts/check_no_game_data.py tools/rdna2spirv.py tests/semantic/test_image_bvh_box.py (no game files).

Reopened after mass PR cleanup (previously #9170).


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/95 **Author:** [@Andretuta](https://github.com/Andretuta) **Created:** 11/24/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `old-pr/9827` --- ### 📝 Commits (1) - [`1820512`](https://github.com/ubiquitarianism/leonida/commit/1820512d3eae1486268d66fdebdb731d38a59430) rdna2spirv: guard image_bvh PhysicalStorageBuffer loads on active EXEC lanes ### 📊 Changes **2 files changed** (+51 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `tests/semantic/test_image_bvh_box.py` (+42 -0) 📝 `tools/rdna2spirv.py` (+9 -1) </details> ### 📄 Description > Carried over from **old PR 9827** by `Lewandox` in the original Leonida repository, which went private on 23 Nov 2026. The code is the branch `old-pr/9827`, exactly that PR's last commit. All carried-over PRs are listed in #17. > Opened as a draft, and the CI runs the opening started were cancelled so 250 PRs don't fill the queue. Re-run CI here when you review it. > `Lewandox`: this is your work. Feel free to take it over, by pushing to the branch or opening your own PR and closing this one. --- Original description (mentions and `#N` references are disabled; the numbers refer to the old repository): `Gen.image_bvh()` in `tools/rdna2spirv.py` only predicated the final `vgpr` writes (`out(k, ...)`) on `EXEC`, never the `PhysicalStorageBuffer` loads (`OpConvertUToPtr` / `OpLoad`). In a divergent BVH traversal loop where finished lanes are masked off in `EXEC` and hold stale or null node pointers, inactive lanes still entered the triangle/box branches and issued 10-40 PSB loads from invalid addresses (risking `VK_ERROR_DEVICE_LOST`), unlike `global_mem`, `global_sub`, `buffer_load`, `buffer_load_sub`, and `global_atomic` which all guard their loads with `self.active_b()`. Wrap the PSB pointer conversion and node-type dispatch in an outer `OpSelectionMerge` / `OpBranchConditional` on `self.active_b()` so inactive lanes skip all PSB loads and leave `v[vd:vd+3]` untouched. Added an inactive-lane (`EXEC == 0`) regression test in `tests/semantic/test_image_bvh_box.py` covering triangle (`type=0`) and box (`type=4, 5`) nodes with a read-tracking memory map (fails with 10 / 40 PSB reads before the fix, passes with 0 reads and preserved `vdst` after). Claimed in `#9065`. AI-assisted; tested on Windows 11 / Python 3.12.10 with `python -I -m unittest discover -s tests/semantic -p "*bvh*.py" -v`, `python -m compileall -q tools/rdna2spirv.py tests/semantic/test_image_bvh_box.py`, and `python -I scripts/check_no_game_data.py tools/rdna2spirv.py tests/semantic/test_image_bvh_box.py` (no game files). Reopened after mass PR cleanup (previously `#9170`). --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
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.

Dependencies

No dependencies set

Reference
starred/leonida#145
No description provided.