fix: translate image_load_mip glc on 2D through the coherent storage view #143

Closed
Andretuta wants to merge 1 commit from upstream-pr/143 into main
Andretuta commented 2026-11-24 02:27:19 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Andretuta on 2026-11-24T02:27:19Z.


Carried over from old PR 9875 by tedin7 in the original Leonida repository, which went private on 23 Nov 2026. The code is the branch old-pr/9875, 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.
tedin7: 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):

What

image_load_mip with glc on a plain 2D image no longer raises Unsupported. It reads through the same Coherent storage view that image_load glc already uses (image_load_coherent). The read is taken when the mip operand is 0. Any other mip writes zeros to the result registers, which is what an out-of-range image_load_mip returns on hardware, because the storage view has exactly one level. Other dims and the tfe/lwe forms still raise Unsupported, now with the dim in the message.

Why

A shader containing a coherent mip load could not be translated at all, so the pipeline that uses it fails to build. That blocks PSO creation and the first frame for any shader that hits it. This makes the translation succeed and validate.

Tested

  • pytest tests/semantic/test_image_coherent.py: 16 passed, 15 subtests passed.
  • Negative control: with tools/rdna2spirv.py restored to origin/main (the test file kept), 8 tests fail (CoherentMipLoad x3 plus the subtests per dmask, and Validation spirv-val f32 and d16). With the fix they pass.
  • Neighbours: the -k 'image or mip or coherent' selection of tests/semantic has the same 47 failures with and without this change, all in test_image_atomics_guard.py. Those fail on current origin/main already ("OpImageTexelPointer in unguarded block"), unrelated to this PR.
  • Not run: no GPU or lavapipe run. Only translation plus spirv-val.

Rebased cleanly on current main (cherry-pick, no conflicts).
Coordination: https://github.com/ProjectLeonida/Leonida/issues/9677

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5464927398 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/143). Originally posted by [Andretuta](https://github.com/Andretuta) on 2026-11-24T02:27:19Z. --- > Carried over from **old PR 9875** by `tedin7` in the original Leonida repository, which went private on 23 Nov 2026. The code is the branch `old-pr/9875`, 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. > `tedin7`: 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): ## What `image_load_mip` with `glc` on a plain 2D image no longer raises `Unsupported`. It reads through the same Coherent storage view that `image_load` glc already uses (`image_load_coherent`). The read is taken when the mip operand is 0. Any other mip writes zeros to the result registers, which is what an out-of-range `image_load_mip` returns on hardware, because the storage view has exactly one level. Other dims and the tfe/lwe forms still raise `Unsupported`, now with the dim in the message. ## Why A shader containing a coherent mip load could not be translated at all, so the pipeline that uses it fails to build. That blocks PSO creation and the first frame for any shader that hits it. This makes the translation succeed and validate. ## Tested - `pytest tests/semantic/test_image_coherent.py`: 16 passed, 15 subtests passed. - Negative control: with `tools/rdna2spirv.py` restored to origin/main (the test file kept), 8 tests fail (CoherentMipLoad x3 plus the subtests per dmask, and Validation spirv-val f32 and d16). With the fix they pass. - Neighbours: the `-k 'image or mip or coherent'` selection of tests/semantic has the same 47 failures with and without this change, all in test_image_atomics_guard.py. Those fail on current origin/main already ("OpImageTexelPointer in unguarded block"), unrelated to this PR. - Not run: no GPU or lavapipe run. Only translation plus spirv-val. Rebased cleanly on current main (cherry-pick, no conflicts). Coordination: https://github.com/ProjectLeonida/Leonida/issues/9677
ImLele69 commented 2026-11-24 11:37:23 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by ImLele69 on 2026-11-24T11:37:23Z.


Tested on Linux, merged onto main 21625bca8 (PR head 8c9a4745b, merges cleanly).

GPU: NVIDIA GeForce RTX 2070 SUPER (Turing, subgroup 32), proprietary driver 620.70.06, Fedora 44, llvm-mc 22.1.8, SPIRV-Tools 2026.1.

Run This PR main alone
run_gpu_tests.py native 197/248 passed, 49 skipped 197/248 passed, 49 skipped
LEONIDA_W64_EMULATE=1 229/248 passed, 17 skipped 229/248 passed, 17 skipped
run_semantic_tests.py tests/semantic 465 files, 6114 tests, 0 files failed in 97 s with 16 jobs 465 files, 6108 tests, 0 files failed

No new GPU fixture; no change in the GPU results against main.

The only failures in both runs are the known cs_imgload_tfe / cs_imgload_d16_tfe pair (#31), as on main. No regressions.

AI-assisted: yes (Claude Code ran the build and tests on my machine; numbers are the runners' own output).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7130334973 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/143#issuecomment-7130334973). Originally posted by [ImLele69](https://github.com/ImLele69) on 2026-11-24T11:37:23Z. --- Tested on Linux, merged onto `main` `21625bca8` (PR head `8c9a4745b`, merges cleanly). GPU: NVIDIA GeForce RTX 2070 SUPER (Turing, subgroup 32), proprietary driver 620.70.06, Fedora 44, llvm-mc 22.1.8, SPIRV-Tools 2026.1. | Run | This PR | `main` alone | |---|---|---| | `run_gpu_tests.py` native | 197/248 passed, 49 skipped | 197/248 passed, 49 skipped | | `LEONIDA_W64_EMULATE=1` | 229/248 passed, 17 skipped | 229/248 passed, 17 skipped | | `run_semantic_tests.py tests/semantic` | 465 files, 6114 tests, 0 files failed in 97 s with 16 jobs | 465 files, 6108 tests, 0 files failed | No new GPU fixture; no change in the GPU results against `main`. The only failures in both runs are the known `cs_imgload_tfe` / `cs_imgload_d16_tfe` pair (#31), as on `main`. No regressions. AI-assisted: yes (Claude Code ran the build and tests on my machine; numbers are the runners' own output).
aslan2142 commented 2026-12-01 11:33:15 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T11:33:15Z.

Review: COMMENTED


Draft review against current main:

  • Merge conflicts / stale base: Conflicts in tools/rdna2spirv.py because image_load_mip has since been refactored on main.
  • API mismatch & d16 edge case: tools/rdna2spirv.py:14213 passes self.sgpr_word(a[2], 1) to image_load_coherent (which now takes the descriptor operand a[2]), and tools/rdna2spirv.py:14228-14231 writes full 32-bit zero to all d16 destination registers on mip != 0 instead of preserving the high 16 bits via write_lo16 on odd-component dmask.
  • Overlap: #1572 carries this work with a16/d16 refinements and docs/design.md updates — please coordinate which PR should move forward once rebased.

(AI-assisted review.)

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6130381886 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/143#pullrequestreview-6130381886). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-01T11:33:15Z. **Review:** COMMENTED --- Draft review against current `main`: - **Merge conflicts / stale base:** Conflicts in `tools/rdna2spirv.py` because `image_load_mip` has since been refactored on `main`. - **API mismatch & d16 edge case:** `tools/rdna2spirv.py:14213` passes `self.sgpr_word(a[2], 1)` to `image_load_coherent` (which now takes the descriptor operand `a[2]`), and `tools/rdna2spirv.py:14228-14231` writes full 32-bit zero to all `d16` destination registers on `mip != 0` instead of preserving the high 16 bits via `write_lo16` on odd-component `dmask`. - **Overlap:** `#1572` carries this work with `a16`/`d16` refinements and `docs/design.md` updates — please coordinate which PR should move forward once rebased. *(AI-assisted review.)*
aslan2142 commented 2026-12-01 11:48:58 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T11:48:58Z.


Closing this carried-over draft in favor of #1572 (OLD-9875), which carries this PR's tedin7 commit forward and fixes its remaining gaps.

Side-by-side comparison:

  • #143 (draft, conflicting with main, cancelled CI): lacks a16 support and docs/design.md contract documentation, passes self.sgpr_word(a[2], 1) to image_load_coherent (which expects the full descriptor operand a[2] on main), and writes full 32-bit zero on mip != 0 for d16 instead of preserving the high 16 bits via write_lo16 on odd-component dmask.
  • #1572 (non-draft, preserves tedin7's authorship): adds a16 handling, passes a[2] cleanly to image_load_coherent, preserves high 16 bits with write_lo16 on odd-component d16 mip != 0, updates docs/design.md, and expands tests/semantic/test_image_coherent.py (+103/-2 lines).

Thanks to @tedin7 and @Andretuta for the original work and carry-over.

(AI-assisted review.)

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7310184561 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/143#issuecomment-7310184561). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-01T11:48:58Z. --- Closing this carried-over draft in favor of **#1572** (`OLD-9875`), which carries this PR's `tedin7` commit forward and fixes its remaining gaps. **Side-by-side comparison:** - **#143** (draft, conflicting with `main`, cancelled CI): lacks `a16` support and `docs/design.md` contract documentation, passes `self.sgpr_word(a[2], 1)` to `image_load_coherent` (which expects the full descriptor operand `a[2]` on `main`), and writes full 32-bit zero on `mip != 0` for `d16` instead of preserving the high 16 bits via `write_lo16` on odd-component `dmask`. - **#1572** (non-draft, preserves `tedin7`'s authorship): adds `a16` handling, passes `a[2]` cleanly to `image_load_coherent`, preserves high 16 bits with `write_lo16` on odd-component `d16` `mip != 0`, updates `docs/design.md`, and expands `tests/semantic/test_image_coherent.py` (`+103/-2` lines). Thanks to `@tedin7` and `@Andretuta` for the original work and carry-over. *(AI-assisted review.)*

Pull request closed

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!143
No description provided.