[PR #98] [CLOSED] rdna2spirv: zero the tfe/lwe status VGPR on image_load and image_load_mip (SHADER-1266) #150

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

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/98
Author: @Mouad-Scriptz-0
Created: 11/24/2026
Status: ❌ Closed

Base: main ← Head: fix/shader-1266-tfe-status


📝 Commits (2)

  • 78f4e5d rdna2spirv: zero the tfe/lwe status VGPR on image_load and image_load_mip
  • f19ec51 docs/design.md: the tfe status row is also GPU-checked on Intel Meteor Lake (ANV) (SHADER-1266)

📊 Changes

3 files changed (+113 additions, -10 deletions)

View changed files

📝 docs/design.md (+1 -1)
➕ tests/semantic/test_image_load_tfe.py (+95 -0)
📝 tools/rdna2spirv.py (+17 -9)

📄 Description

Fixes #31 (SHADER-1266). Claimed in #14.

Problem

With tfe (or lwe), an MIMG read returns one more dword after its data: the fetch status, at vdata[data_vgprs] (RDNA2 ISA, MIMG TFE/LWE). tools/rdna2spirv.py already counts that VGPR as a destination (vgpr_dest_registers(ins, extra=int("tfe" in ins["mods"]))), but image_load and image_load_mip emit only the OpImageFetch/OpImageRead of the data, so nothing writes the status VGPR and the shader reads back whatever it held before. The GPU fixtures cs_imgload_tfe and cs_imgload_d16_tfe (on main since 9c4c5f92a) fail because of this, as #31 reports on an AMD 780M.

Fix

This re-lands old-pr/10022 (n-romanovich, from the original repository; their commit is cherry-picked unchanged and keeps its authorship). The patch applied cleanly onto main 9ec34cdff.

  • image_read_typed takes a status flag. When it is set, it writes 0 to vdata[r + data_vgprs] after the data, with data_vgprs = (popcount(dmask) + 1) // 2 under d16 and popcount(dmask) otherwise. The write goes through self.dst, so inactive lanes keep their value.
  • The flag is passed from every image_load / image_load_mip path that reaches image_read_typed: the typed fetch, the coherent (glc) read, the 3D mip load and the 2D mip load.
  • The status is always 0 because every texel the translated shader can reach is resident. SPIR-V has no residency status in this path. Paths that already refuse tfe/lwe (a16 mip, d16 3D mip, stores, sample_d on 3D) are unchanged.
  • docs/design.md: the "Typed image loads" row gets the rule and its confirmation (second commit: the Intel GPU result below).
  • tests/semantic/test_image_load_tfe.py: new CPU test (3 tests).

Tested

Fedora Linux, Python 3.15.2, LLVM 23.1.5 llvm-mc. The GPU is Intel Meteor Lake graphics (Intel(R) Graphics (MTL), ANV, Mesa 26.2.7), selected with LEONIDA_VK_DEVICE=Intel.

check main 9ec34cdff this branch
tests/semantic/test_image_load_tfe.py 4 failures (new test run against main's translator) OK, 3 tests
scripts/run_semantic_tests.py tests/semantic 2 files failed: test_exec_computed (#15/#24), test_image_atomics_guard (#20) 464 files, 6078 tests, the same 2 files failed, nothing new
run_gpu_tests.py --filter imgload 2/4: cs_imgload_tfe, cs_imgload_d16_tfe FAIL 4/4 PASS
run_gpu_tests.py (full) 193/248 passed, 52 skipped, 3 failed 195/248 passed, 52 skipped, 1 failed

In the full GPU run, the only per-test difference between the two is cs_imgload_tfe and cs_imgload_d16_tfe going from FAIL to PASS. The one failure left is cs_w32_exec_computed, which is #15 (fixed in #24). Translation was 256/257 with all 256 passing spirv-val, the same on both. The one shader not translated is a computed I/J pair under --bary-fallback, because this GPU has no PerVertexKHR. It has nothing to do with this change.

Also run, all OK: pytest tests/test_image_load_typed.py tests/test_image_load_d16_typed.py (29 passed), python -m compileall -q make_game.py tools tests, tests/test_text_write_line_endings.py, tests/test_docs_links.py, and scripts/check_no_game_data.py on every changed file.

Commands:

python3 -m unittest discover -s tests/semantic -p test_image_load_tfe.py
python3 -I scripts/run_semantic_tests.py tests/semantic
cmake -S runtime -B runtime/build/linux -G Ninja && cmake --build runtime/build/linux --parallel
LEONIDA_VK_DEVICE=Intel python3 -I scripts/run_gpu_tests.py --build runtime/build/linux

@Mby159 offered in #15 to rerun the GPU suite on the 780M from #31. An AMD result would confirm the fix on the hardware the bug was reported on.

No game files and nothing online. AI-assisted (Claude Code).


🔄 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/98 **Author:** [@Mouad-Scriptz-0](https://github.com/Mouad-Scriptz-0) **Created:** 11/24/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/shader-1266-tfe-status` --- ### 📝 Commits (2) - [`78f4e5d`](https://github.com/ubiquitarianism/leonida/commit/78f4e5d69b4e33bb0221f7cff256a365f94acd21) rdna2spirv: zero the tfe/lwe status VGPR on image_load and image_load_mip - [`f19ec51`](https://github.com/ubiquitarianism/leonida/commit/f19ec5193b36c5ce4fc877184a1cce0dd64cf607) docs/design.md: the tfe status row is also GPU-checked on Intel Meteor Lake (ANV) (SHADER-1266) ### 📊 Changes **3 files changed** (+113 additions, -10 deletions) <details> <summary>View changed files</summary> 📝 `docs/design.md` (+1 -1) ➕ `tests/semantic/test_image_load_tfe.py` (+95 -0) 📝 `tools/rdna2spirv.py` (+17 -9) </details> ### 📄 Description Fixes #31 (SHADER-1266). Claimed in #14. ## Problem With `tfe` (or `lwe`), an MIMG read returns one more dword after its data: the fetch status, at `vdata[data_vgprs]` (RDNA2 ISA, MIMG TFE/LWE). `tools/rdna2spirv.py` already counts that VGPR as a destination (`vgpr_dest_registers(ins, extra=int("tfe" in ins["mods"]))`), but `image_load` and `image_load_mip` emit only the `OpImageFetch`/`OpImageRead` of the data, so nothing writes the status VGPR and the shader reads back whatever it held before. The GPU fixtures `cs_imgload_tfe` and `cs_imgload_d16_tfe` (on `main` since 9c4c5f92a) fail because of this, as #31 reports on an AMD 780M. ## Fix This re-lands `old-pr/10022` (n-romanovich, from the original repository; their commit is cherry-picked unchanged and keeps its authorship). The patch applied cleanly onto `main` 9ec34cdff. - `image_read_typed` takes a `status` flag. When it is set, it writes `0` to `vdata[r + data_vgprs]` after the data, with `data_vgprs = (popcount(dmask) + 1) // 2` under `d16` and `popcount(dmask)` otherwise. The write goes through `self.dst`, so inactive lanes keep their value. - The flag is passed from every `image_load` / `image_load_mip` path that reaches `image_read_typed`: the typed fetch, the coherent (`glc`) read, the 3D mip load and the 2D mip load. - The status is always 0 because every texel the translated shader can reach is resident. SPIR-V has no residency status in this path. Paths that already refuse `tfe`/`lwe` (a16 mip, d16 3D mip, stores, sample_d on 3D) are unchanged. - `docs/design.md`: the "Typed image loads" row gets the rule and its confirmation (second commit: the Intel GPU result below). - `tests/semantic/test_image_load_tfe.py`: new CPU test (3 tests). ## Tested Fedora Linux, Python 3.15.2, LLVM 23.1.5 `llvm-mc`. The GPU is Intel Meteor Lake graphics (`Intel(R) Graphics (MTL)`, ANV, Mesa 26.2.7), selected with `LEONIDA_VK_DEVICE=Intel`. | check | `main` 9ec34cdff | this branch | |---|---|---| | `tests/semantic/test_image_load_tfe.py` | 4 failures (new test run against `main`'s translator) | OK, 3 tests | | `scripts/run_semantic_tests.py tests/semantic` | 2 files failed: `test_exec_computed` (#15/#24), `test_image_atomics_guard` (#20) | 464 files, 6078 tests, the same 2 files failed, nothing new | | `run_gpu_tests.py --filter imgload` | 2/4: `cs_imgload_tfe`, `cs_imgload_d16_tfe` FAIL | **4/4 PASS** | | `run_gpu_tests.py` (full) | 193/248 passed, 52 skipped, 3 failed | **195/248 passed**, 52 skipped, 1 failed | In the full GPU run, the only per-test difference between the two is `cs_imgload_tfe` and `cs_imgload_d16_tfe` going from FAIL to PASS. The one failure left is `cs_w32_exec_computed`, which is #15 (fixed in #24). Translation was 256/257 with all 256 passing `spirv-val`, the same on both. The one shader not translated is a computed I/J pair under `--bary-fallback`, because this GPU has no `PerVertexKHR`. It has nothing to do with this change. Also run, all OK: `pytest tests/test_image_load_typed.py tests/test_image_load_d16_typed.py` (29 passed), `python -m compileall -q make_game.py tools tests`, `tests/test_text_write_line_endings.py`, `tests/test_docs_links.py`, and `scripts/check_no_game_data.py` on every changed file. Commands: ```sh python3 -m unittest discover -s tests/semantic -p test_image_load_tfe.py python3 -I scripts/run_semantic_tests.py tests/semantic cmake -S runtime -B runtime/build/linux -G Ninja && cmake --build runtime/build/linux --parallel LEONIDA_VK_DEVICE=Intel python3 -I scripts/run_gpu_tests.py --build runtime/build/linux ``` @Mby159 offered in #15 to rerun the GPU suite on the 780M from #31. An AMD result would confirm the fix on the hardware the bug was reported on. No game files and nothing online. AI-assisted (Claude Code). --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
4ld0 2026-11-26 20:16:57 +01:00
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#150
No description provided.