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

Closed
github-bot wants to merge 2 commits from gh-pr/98/head into gh-pr/98/base
Owner

@⁠Mouad-Scriptz-0 on GitHub · 2026-11-24 02:17 UTC · original
Mouad-Scriptz-0:fix/shader-1266-tfe-status → main · +113 −10 · 3 files · 2 commits · closed without merging

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).

**@⁠Mouad-Scriptz-0** on GitHub · 2026-11-24 02:17 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/98) `Mouad-Scriptz-0:fix/shader-1266-tfe-status` → `main` · +113 −10 · 3 files · 2 commits · closed without merging 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).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 08:44:25 +00:00
github-bot closed this pull request 2026-11-26 08:44:25 +00:00
Author
Owner

@⁠milk4sale on GitHub · 2026-11-24 02:51 UTC · original

Tested at head f19ec5193 on two more GPUs (CachyOS, kernel 7.3.3, llvm-mc 23.1.4, SPIRV-Tools v2026.4), reusing a runtime build of main 84347bbb6 (this PR doesn't touch runtime/):

GPU Driver main 84347bbb6 this PR
NVIDIA RTX 4070 Ti (Ada, subgroup 32) proprietary 620.70.06 cs_imgload_tfe and cs_imgload_d16_tfe FAIL, native and LEONIDA_W64_EMULATE=1 both PASS, native and emulated
Radeon 610M, Ryzen 9 7900X iGPU (gfx1036, RDNA2, subgroup 32..64) RADV, Mesa 26.2.6 both FAIL, native and emulated both PASS, native and emulated

run_gpu_tests.py --filter tfe gave 2/2 in all four runs, with implicit layers off and the device picked by VK_LOADER_DRIVERS_SELECT. python -m unittest discover -s tests/semantic -p test_image_load_tfe.py passes 3/3. On main, these two fixtures were the only failures on either GPU in the full suite (records in #234).

No game files. AI-assisted (Claude Code).

**@⁠milk4sale** on GitHub · 2026-11-24 02:51 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/98#issuecomment-7120543881) Tested at head `f19ec5193` on two more GPUs (CachyOS, kernel 7.3.3, llvm-mc 23.1.4, SPIRV-Tools v2026.4), reusing a runtime build of main `84347bbb6` (this PR doesn't touch `runtime/`): | GPU | Driver | main `84347bbb6` | this PR | |---|---|---|---| | NVIDIA RTX 4070 Ti (Ada, subgroup 32) | proprietary 620.70.06 | `cs_imgload_tfe` and `cs_imgload_d16_tfe` FAIL, native and `LEONIDA_W64_EMULATE=1` | both PASS, native and emulated | | Radeon 610M, Ryzen 9 7900X iGPU (gfx1036, RDNA2, subgroup 32..64) | RADV, Mesa 26.2.6 | both FAIL, native and emulated | both PASS, native and emulated | `run_gpu_tests.py --filter tfe` gave 2/2 in all four runs, with implicit layers off and the device picked by `VK_LOADER_DRIVERS_SELECT`. `python -m unittest discover -s tests/semantic -p test_image_load_tfe.py` passes 3/3. On main, these two fixtures were the only failures on either GPU in the full suite (records in #234). No game files. AI-assisted (Claude Code).
Author
Owner

@⁠tahffo68hk-hash on GitHub · 2026-11-24 02:59 UTC · original · reviewed

I reproduced a resident image_load ... tfe regression at f19ec5193 using the independent dense fixture from Reforge #9. The pass results above for the two inherited fixtures reproduce here; those fixtures expect the seeded status to be cleared.

Native RDNA2. On Windows 11 build 26200, AMD GFX1036, HIP runtime 60450101, LLVM 23.1.6, I checked the assembled code object and HIP readback path. For a resident R32_UINT texel at (62,0), the kernel seeds v13 = 0x000003e8, executes image_load v[12:13], v[2:3], s[8:15] dmask:0x1 dim:SQ_RSRC_IMG_2D unorm tfe, waits for VM, then stores those VGPRs for device-to-host readback. Expected and observed (v12 data, v13 status) were (0x7eb9e229, 0x000003e8). This is one of 48 native kernels / 192 lane readbacks.

Translated Vulkan. On the same Windows build, RTX 5060 Ti / 617.42, LLVM 23.1.6, SPIRV-Tools 2026.4, Wave64 emulation enabled, I ran cs_image_tfe_dense on PR base 9ec34cdff, then applied the exact PR diff and verified its three changed blobs against f19ec5193. The fixture and Vulkan harness were identical between runs.

R32_UINT, in bounds at (0,0) Expected data / status Readback
PR base 0x00000064 / 0x5a5a03f5 0x00000064 / 0x5a5a03f5
PR HEAD same 0x00000064 / 0x00000000
Base + explicit zero of the fixture's status VGPRs after the loads same 0x00000064 / 0x00000000

HEAD and the explicit-zero control both failed the same 16 of 64 SINT word comparisons. D16 showed the same status regression, while its data word remained 0x5a5a0064. All translated modules in these targeted runs passed spirv-val.

Please resolve this resident TFE behavior before merging the lowering. The probe covers these plain dense image_load ... tfe forms. Sparse page NACK, LWE and other instruction variants were outside the measurement.

AI-assisted.

中文翻译

在 Windows 11 build 26200、AMD GFX1036、HIP 60450101 和 LLVM 23.1.6 上,检查了原生 code object 的指令及 HIP 读回路径。常驻 R32_UINT 的 (62,0) 用例先将 v13 置为 0x3e8,执行 image_load v[12:13] ... tfe,等待后直接写回两个 VGPR,读到 v12=0x7eb9e229、v13=0x000003e8。另有同组 48 个原生 kernel、192 个 lane 的证据,见上方 Reforge #9。

在同一 Windows 版本、RTX 5060 Ti / 617.42、LLVM 23.1.6、SPIRV-Tools 2026.4、Wave64 模拟开启下,独立对照在 PR 基线 9ec34cdff 通过。应用 #98 的 exact diff 并验证三个文件与 f19ec5193 一致后,正常坐标的读回为数据 0x64、状态 0,预期状态为 0x5a5a03f5。在基线上显式清零两个状态寄存器的负对照,和 PR HEAD 一样有 16 个 SINT 字失败。D16 数据字仍匹配,状态同样被清零。旧两项测试通过的现象也已复现。

建议在合入翻译规则前先解决常驻 TFE 的语义分歧。本次没有验证稀疏页 NACK、LWE 或其他指令变体。

AI-assisted(AI 辅助)。

**@⁠tahffo68hk-hash** on GitHub · 2026-11-24 02:59 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/98#pullrequestreview-6033017384) · **reviewed** I reproduced a resident `image_load ... tfe` regression at `f19ec5193` using the independent dense fixture from [Reforge #9](https://github.com/LeonidaReforge/Leonida/issues/9#issuecomment-7120453070). The pass results above for the two inherited fixtures reproduce here; those fixtures expect the seeded status to be cleared. **Native RDNA2.** On Windows 11 build 26200, AMD GFX1036, HIP runtime `60450101`, LLVM 23.1.6, I checked the assembled code object and HIP readback path. For a resident R32_UINT texel at `(62,0)`, the kernel seeds `v13 = 0x000003e8`, executes `image_load v[12:13], v[2:3], s[8:15] dmask:0x1 dim:SQ_RSRC_IMG_2D unorm tfe`, waits for VM, then stores those VGPRs for device-to-host readback. Expected and observed `(v12 data, v13 status)` were `(0x7eb9e229, 0x000003e8)`. This is one of 48 native kernels / 192 lane readbacks. **Translated Vulkan.** On the same Windows build, RTX 5060 Ti / 617.42, LLVM 23.1.6, SPIRV-Tools 2026.4, Wave64 emulation enabled, I ran `cs_image_tfe_dense` on PR base `9ec34cdff`, then applied the exact PR diff and verified its three changed blobs against `f19ec5193`. The fixture and Vulkan harness were identical between runs. | R32_UINT, in bounds at (0,0) | Expected data / status | Readback | |---|---|---| | PR base | `0x00000064 / 0x5a5a03f5` | `0x00000064 / 0x5a5a03f5` | | PR HEAD | same | `0x00000064 / 0x00000000` | | Base + explicit zero of the fixture's status VGPRs after the loads | same | `0x00000064 / 0x00000000` | HEAD and the explicit-zero control both failed the same 16 of 64 SINT word comparisons. D16 showed the same status regression, while its data word remained `0x5a5a0064`. All translated modules in these targeted runs passed `spirv-val`. Please resolve this resident TFE behavior before merging the lowering. The probe covers these plain dense `image_load ... tfe` forms. Sparse page NACK, LWE and other instruction variants were outside the measurement. AI-assisted. <details> <summary>中文翻译</summary> 在 Windows 11 build 26200、AMD GFX1036、HIP `60450101` 和 LLVM 23.1.6 上,检查了原生 code object 的指令及 HIP 读回路径。常驻 R32_UINT 的 `(62,0)` 用例先将 `v13` 置为 `0x3e8`,执行 `image_load v[12:13] ... tfe`,等待后直接写回两个 VGPR,读到 `v12=0x7eb9e229`、`v13=0x000003e8`。另有同组 48 个原生 kernel、192 个 lane 的证据,见上方 Reforge #9。 在同一 Windows 版本、RTX 5060 Ti / 617.42、LLVM 23.1.6、SPIRV-Tools 2026.4、Wave64 模拟开启下,独立对照在 PR 基线 `9ec34cdff` 通过。应用 #98 的 exact diff 并验证三个文件与 `f19ec5193` 一致后,正常坐标的读回为数据 `0x64`、状态 `0`,预期状态为 `0x5a5a03f5`。在基线上显式清零两个状态寄存器的负对照,和 PR HEAD 一样有 16 个 SINT 字失败。D16 数据字仍匹配,状态同样被清零。旧两项测试通过的现象也已复现。 建议在合入翻译规则前先解决常驻 TFE 的语义分歧。本次没有验证稀疏页 NACK、LWE 或其他指令变体。 AI-assisted(AI 辅助)。 </details>
Author
Owner

@⁠Mouad-Scriptz-0 on GitHub · 2026-11-24 03:15 UTC · original

Thanks @⁠tahffo68hk-hash, this is convincing, and I'm closing this PR.

My runs only showed that this change makes cs_imgload_tfe / cs_imgload_d16_tfe pass. They never tested whether those fixtures' expectation (status = 0 on a resident read) is what the hardware does. Your native GFX1036 readback says it isn't: 48 kernels, 192 lanes and three seeds, and every resident access kept its seed.

LLVM agrees. SIISelLowering.cpp initializes the TFE/LWE result itself before the instruction. With the default PRTStrictNull it zeroes every result register, and without it, "just the error indication register (VGPRn+1)". A compiler only does that if the hardware doesn't write the status on a successful fetch.

So:

  • main's current translator is the hardware-exact one. It leaves the status VGPR as it was. This PR would make it less exact.
  • Compiled game shaders are not affected either way. The compiler zeroes the status VGPR before the load, so it reads 0 with or without this change.
  • The fix is in the two fixtures, not the translator. Your fixture-only patch (Reforge #9, comment) is the right change, along with cs_image_tfe_dense. If you can't open a PR here, I'm glad to open one with your commits and authorship kept. Just say so.
  • #291 (old-pr/10022, the original of this change) has the same problem.
  • #31 reports these two fixtures failing on the 780M. By this measurement it isn't a translator bug: the fixtures expect the wrong value.

Still open, as you note: the status on a real sparse-page NACK.

AI-assisted (Claude Code).

**@⁠Mouad-Scriptz-0** on GitHub · 2026-11-24 03:15 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/98#issuecomment-7120919542) Thanks @⁠tahffo68hk-hash, this is convincing, and I'm closing this PR. My runs only showed that this change makes `cs_imgload_tfe` / `cs_imgload_d16_tfe` pass. They never tested whether those fixtures' expectation (status = 0 on a resident read) is what the hardware does. Your native GFX1036 readback says it isn't: 48 kernels, 192 lanes and three seeds, and every resident access kept its seed. LLVM agrees. `SIISelLowering.cpp` initializes the TFE/LWE result itself before the instruction. With the default PRTStrictNull it zeroes every result register, and without it, "just the error indication register (VGPRn+1)". A compiler only does that if the hardware doesn't write the status on a successful fetch. So: - **`main`'s current translator is the hardware-exact one.** It leaves the status VGPR as it was. This PR would make it less exact. - **Compiled game shaders are not affected either way.** The compiler zeroes the status VGPR before the load, so it reads 0 with or without this change. - **The fix is in the two fixtures, not the translator.** Your fixture-only patch (Reforge #9, [comment](https://github.com/LeonidaReforge/Leonida/issues/9#issuecomment-7120453070)) is the right change, along with `cs_image_tfe_dense`. If you can't open a PR here, I'm glad to open one with your commits and authorship kept. Just say so. - **#291** (`old-pr/10022`, the original of this change) has the same problem. - **#31** reports these two fixtures failing on the 780M. By this measurement it isn't a translator bug: the fixtures expect the wrong value. Still open, as you note: the status on a real sparse-page NACK. AI-assisted (Claude Code).
Author
Owner

@⁠tahffo68hk-hash on GitHub · 2026-11-24 03:38 UTC · original · edited 2026-11-24 03:42 UTC

Thanks, @⁠Mouad-Scriptz-0. I’d be glad to take you up on your offer to open the TFE fixture PR. Please preserve the original Git author and author date from both patches (author: tahffo68hk-hash). The original commits are 6dd337e07ff92bd6ddb90c1308820f424e05e8da (independent dense control, readback check and one documentation row) and a7d72f949791ae7218ecfc3f118e7d82c1b5e8c8 (legacy D16/D32 fixtures). The mbox below covers only the synthetic fixtures, checker and documentation. The inline mbox refreshes the design-table context against main ece4ba5b, preserving both original author dates. On RTX 5060 Ti (617.42), two legacy cases failed before the fixture update. After applying both patches, all three targeted TFE cases passed in Wave64 emulation and all three modules passed spirv-val.

The native GFX1036 evidence covers 48 kernels and 192 lane observations. The RTX 5060 Ti negative control shows that forcing zero changes the preserved seeded status without changing the fetched data. This scope is resident image_load TFE, including coordinate OOB. Sparse-page NACK and LWE were unverified.

Separately, if you are also interested in helping with the runner verdict fix (c178a889a), I’d appreciate a pointer or a separate PR. The TFE fixture PR can proceed independently.

AI-assisted.

中文翻译

谢谢你主动提出帮忙开 TFE 测试 PR。请保留两份补丁原始 Git 作者及作者日期,作者为 tahffo68hk-hash。6dd337e07 添加独立 dense 合成对照、读回检查和一行文档,a7d72f949 修正旧 D16/D32 测试。下方 mbox 不含翻译器修改。下方 mbox 已按 main ece4ba5b 调整设计文档表格的上下文并保留两份补丁的原始作者日期。在 RTX 5060 Ti(617.42)的 Wave64 模拟模式下,修改前两个旧用例均失败,修改后三个 TFE 用例均通过,三个模块均通过 spirv-val。

公开的 GFX1036 实验覆盖 48 个 kernel 和 192 个 lane 读回。RTX 5060 Ti 负对照显示强制清零会改变预置状态字,读取的数据保持一致。结论限于常驻资源的 image_load TFE,包括坐标越界。稀疏页 NACK 和 LWE 尚未验证。

另有一项独立的 runner 判定修复 c178a889a。如果你也愿意指点提交途径或代开单独 PR,非常感谢。TFE 测试 PR 可以独立推进。

AI-assisted(AI 辅助)。

Source-only git am mbox for Continued main
From 337b3c0a3661ab0dfe57cd53f716ce1f87f7f2ea Mon Sep 17 00:00:00 2001
From: tahffo68hk-hash <[email protected]>
Date: Tue, 24 Nov 2026 10:21:30 +0800
Subject: [PATCH 1/2] Test dense image-load TFE with seeded status and
 out-of-bounds coordinates

Record the dense GFX1036 observations and test the integer readback without changing the older fixtures.

AI-assisted.
---
 docs/design.md                              |  1 +
 runtime/test/shaders/check.py               |  7 +++
 runtime/test/shaders/cs_image_tfe_dense.asm | 48 +++++++++++++++++++++
 3 files changed, 56 insertions(+)
 create mode 100644 runtime/test/shaders/cs_image_tfe_dense.asm

diff --git a/docs/design.md b/docs/design.md
index 6bb4173..d6e444b 100644
--- a/docs/design.md
+++ b/docs/design.md
@@ -413,6 +413,7 @@ How the generated SPIR-V expects the runtime to work:
 | LDS 2-address b64 (`ds_read2_b64`, `ds_write2_b64`, `ds_read2st64_b64`, `ds_write2st64_b64`) | Two elements at vaddr + offset0·unit and vaddr + offset1·unit, unit = 8 bytes (×64 for st64); each element is two consecutive dwords, low first. `read2_b64` fills v[d:d+3] after all four loads (a vdst overlapping vaddr is safe); `write2_b64` takes two VGPR pairs. The b32 forms share the code with unit 4. Source: RDNA2 ISA DS 2-address forms. CPU-checked by `tests/semantic/test_lds_read2_write2_b64.py` (compute listings, LDS as a Workgroup variable); GPU-checked by `runtime/test/shaders/cs_lds_b64_cmpst.asm` (unit 8 and the 512-byte st64 forms, plus vdst/vaddr overlap, on an RTX 3070, driver 621.01, Windows 11; the same eight words also on an AMD RX 7600 (`gfx1102`) and a Ryzen 5 9600X iGPU (`gfx1036`, RDNA2, RADV Mesa 27.0.0-devel)). |
 | Compute workgroup IDs Y/Z | With four user SGPRs and only TGID_Y and TGID_Z enabled (RSRC2 `0x308`), s4 receives Y and s5 receives Z. The synthetic `cs_workgroup_yz.asm` fixture checks a 2 × 3 × 4 dispatch and each of its 24 origins against a CPU reference. |
 | Typed image stores | `image_store` (2D, 2D array, 3D, cube) writes the dmask components (missing ones = 0). The image's numeric type lives in the T# (word 1 FORMAT [28:20], 512 GFX10 formats), so it is decided at run time. A 512-bit table built from `tools/gfx10_formats.json` (30 UINT and 15 SINT formats) picks a **sint**, **uint** or **float** view (bindings 8 + 3·dim + class; dim 0 = 2D, 1 = 2D array, 2 = 3D; class 0 float, 1 uint, 2 sint). Views have Unknown format (`shaderStorageImageWriteWithoutFormat`). **The runtime binds every storage image into all three arrays of its dimension, or at least the one matching its format.** The earlier path wrote only component 0 as `r32ui`, which was wrong for every other format. GPU-checked with `runtime/test/shaders/cs_imgstore.asm` through `runtime/test/vk_store_test.cpp`: rgba8 unorm, r32 uint and r32 sint images, every texel correct. A cube storage image is bound as a six-layer 2D array (bindings 11/12/13 for float/uint/sint, `OpTypeImage ... 2D 0 1 0 2 Unknown`, `%v3int` coordinates (x, y, face)); `tfe` and `lwe` are refused. CPU-checked by `tests/semantic/test_image_cube_store_glc.py`; **not GPU-verified**: no GPU fixture covers a cube store yet. |
+| Dense `image_load tfe` | RDNA2 ISA §8.2 associates the trailing status VGPR with a texture NACK. [LLVM](https://github.com/llvm/llvm-project/blob/main/llvm/lib/Target/AMDGPU/SIISelLowering.cpp) and [Mesa ACO](https://github.com/chaotic-cx/mesa-mirror/blob/main/src/amd/compiler/instruction_selection/aco_isel_helpers.cpp) initialize that register in the generated shader. Native gfx1036 kept a nonzero status seed for both in-bounds and out-of-bounds reads of resident R32 and R32G32 images. Out-of-bounds data was zero, the unused high half of a single D16 word was preserved, and an inactive lane kept its data and status. The status follows the packed data words (one word for two D16 components). `cs_image_tfe_dense` checks data and preserved status on Vulkan. Sparse page NACK behavior is outside this dense fixture. |
 | Typed image loads | A noncoherent cube `image_load` reads the 2D-array sampled binding (3) with integer coordinates and layer. Its T# format selects the float, uint or sint alias, including for D16. The [RDNA2 ISA §8.2.1](https://docs.amd.com/v/u/en-US/rdna2-shader-instruction-set-architecture) assigns D16 conversion to the image format. The synthetic `cube_load_d16.asm` checks the generated views and format choices on the CPU. `image_load` on 1D/2D/2D-array/3D images uses the same T# FORMAT tables as stores, and fetches every format with `OpImageFetch` from the sampled array of its dimension (bindings 0, 3, 6, 5): UINT/SINT formats through **uint/sint aliases of that array** (same set and binding, an `OpTypeImage` of `%uint`/`%int`; Vulkan allows several variables on one binding when the descriptor type fits), everything else through the float array. A lookup miss (index 0) takes the float path, since the fallback there is RGBA8_UNORM. Results are the raw bits of the dmask components. **The runtime binds each image's view in its own format at its index of the sampled array** (what `bind_image` in `runtime/shims/d3d12_vulkan_device.cpp` already does for SRVs and UAVs), so the view's numeric type matches the alias that reads it. No storage image is read, so shaders that only load need neither `shaderStorageImageReadWithoutFormat` (missing on Intel Xe-LP, #619) nor `shaderStorageImageWriteWithoutFormat` (SHADER-151). Until 2026-11-22 integer formats were read with `OpImageRead` from the uint/sint storage arrays (bindings 8–19), which hold only unordered-access views and 256 entries: a read-only integer texture found the fallback there, or an index past the array's end. Like the float path, the fetch goes through the texture path, so it sees writes made before the dispatch, not ones made earlier in the same dispatch. **d16 loads take the same branch** (#1136) and pack the dmask components two per VGPR, low half first: f16 (round to nearest even, integer ops, no `PackHalf2x16`) from the float array, the low 16 bits of each value from the uint/sint aliases (truncated). **d16 loads take the same branch** (#1136) and pack the dmask components two per VGPR, low half first: f16 (round to nearest even, integer ops, no `PackHalf2x16`) from the float array, each value from the uint/sint aliases saturated to the 16-bit range of its signedness (`saturate_int16`). For odd component counts (1 or 3 in `dmask`), the trailing destination VGPR preserves its existing high 16 bits (`write_lo16`), matching native `gfx1036` hardware where a seeded `0x5a5a` high half survived 1-component UINT/SINT `image_load` and `image_load_mip`; until 2026-11-22 the unused high half was zeroed. Before #1136, a d16 load always read the float view, so a `Texture2D<min16uint>` `Load` returned garbage. CPU-checked by `tests/test_image_load_typed.py` (capabilities, bindings and component types for every dimension; the branch for all 512 FORMAT values, found and missed). GPU-checked with `runtime/test/shaders/cs_imgload.asm` through `vk_store_test load`, on a device made without `shaderStorageImageReadWithoutFormat`: r32 uint and r32 sint images filled before the dispatch, both read with `image_load` and their sum stored, every texel exact on an RTX 2080 Ti (NVIDIA 621.14, Windows 11), clean under the validation layer with GPU-assisted validation; the test fails a module that declares `StorageImageReadWithoutFormat`. d16: CPU-checked by `tests/test_image_load_d16_typed.py` (the uint/sint fetches go through the aliases, no storage image is read, the SPIR-V validates); GPU-checked with `runtime/test/shaders/cs_imgload_d16.asm` through `vk_store_test load`: both pre-filled texels read with d16 loads (the sint one sign-extended from bit 15 in the shader) and their sum stored, every texel exact on the RTX 2080 Ti with GPU-assisted validation (#1136 checked its first form, a store and d16 read-back in one dispatch, on an RTX 5070, and `cs_imgload_d16` passes unchanged on an AMD RX 7600 (gfx1102, RADV Mesa 27.0.0-devel) in `run_gpu_tests.py`). GPU-checked with `runtime/test/shaders/cs_imgload_d16.asm` through `vk_store_test load`: both pre-filled texels read with d16 loads (the sint one sign-extended from bit 15 in the shader) and their sum stored, every texel exact on the RTX 2080 Ti with GPU-assisted validation (#1136 checked its first form, a store and d16 read-back in one dispatch, on an RTX 5070). 2D `image_load_mip` uses the same numeric-type selection and passes the address register's mip to each fetch. Its D16 form packs the selected components in ascending order, two per VGPR. An RGBA8 two-level texture was checked on RTX 5080 and Radeon Graphics: all four exported halves matched the CPU reference for UINT, SINT and UNORM, and forcing level 0 changed every pixel. Checked on RTX 5080 and Radeon Graphics with R8G8B8A8 UINT, SINT and UNORM textures: level 1 matched the CPU reference at every pixel with GPU-assisted validation, and forcing level 0 changed all 4096 pixels for each format. Native gfx1036 saturated 32-bit UINT/SINT texels to the unsigned/signed 16-bit range in both D16 load forms; the translated 2D load matched both limits on RTX 5080 and Radeon Graphics. Native gfx1036 does the same on every dimension (SHADER-387, `tools/image_d16_probe.py`): 32_UINT and 32_32_UINT texels saturate to [0, 0xffff] and 32_SINT and 32_32_SINT texels to [-32768, 32767], never truncate, in 1D, 2D, 2D-array and 3D images, through `image_load` and `image_load_mip` alike; two-channel results pack x low and y high, and a one-channel result keeps the seeded high half. The translated d16 loads on 1D, 2D-array and 3D images still lack GPU checks. |
 | Packed 2D mip-load addresses | For `image_load_mip` with `a16`, the first VGPR holds unsigned X (low half) and Y (high half). The low half of the second VGPR selects the mip and its high half is unused. Both ordinary and D16 results use the same address. LLVM gfx1030 assembles both forms in `tests/semantic/fixtures/packed_mip_load_2d.asm`. `tests/test_image_load_typed.py` checks the texel and mip operands of the float, UINT and SINT fetches, including noncontiguous address registers. [AMD RDNA 2 ISA, MIMG A16 field](https://www.amd.com/content/dam/amd/en/documents/radeon-tech-docs/instruction-set-architectures/rdna2-shader-instruction-set-architecture.pdf) |
 | 3D explicit-mip loads | `image_load_mip` reads x, y, z and mip from four address VGPRs. T# FORMAT selects the float, UINT or SINT 3D sampled view at binding 6. D16 narrows the selected components before packing them low half first. The unit test `test_volume_mip_fetch_uses_xyz_level_and_descriptor_type` in `tests/test_image_load_typed.py` checks the four address registers and the RGBA32 format selection on the translated module. Native gfx1036 measured UINT and SINT saturation for 3D `image_load_mip` at mip zero. [Volume load measurements](https://github.com/ItsNotRexed/Leonida/pull/2217) |
diff --git a/runtime/test/shaders/check.py b/runtime/test/shaders/check.py
index 7b37772..a6d6144 100644
--- a/runtime/test/shaders/check.py
+++ b/runtime/test/shaders/check.py
@@ -603,6 +603,13 @@ STORE_WORDS = {
     "cs_resinfo": ({**dict(enumerate([16, 4, 0, 5, 8, 2, 0, 5, 2, 1, 0, 5, 4, 1, 0xABCD])), 16: 2, 17: 5, 18: 5,
                     20: 0, 21: 0, 22: 0, 23: 5},
                    {}, {}),
+    # TFE leaves both seeded status words intact. D16 updates only the low half of its single data word.
+    "cs_image_tfe_dense": ({}, dict(enumerate([
+        0, 100, 101, 102, 0, 0, 0, 0,
+        *[0x5A5A03F5] * 8,
+        0x5A5A0000, 0x5A5A0064, 0x5A5A0065, 0x5A5A0066, *[0x5A5A0000] * 4,
+        *[0x5A5A03F6] * 8,
+    ])), {}),
 }
 # TEST-184: image_get_lod on vk_texture_test's textures. Per fixture, its draws: S# word 1 (MIN_LOD [11:0], MAX_LOD
 # [23:12], 4.8 fixed point), whether the two-mip texture is drawn, and mrt0, as derived in the .asm header:
diff --git a/runtime/test/shaders/cs_image_tfe_dense.asm b/runtime/test/shaders/cs_image_tfe_dense.asm
new file mode 100644
index 0000000..dfe475b
--- /dev/null
+++ b/runtime/test/shaders/cs_image_tfe_dense.asm
@@ -0,0 +1,48 @@
+; TFE on a resident R32_UINT image, measured with raw image_load on GFX1036.
+; vk_store_test words fills the 8x8 input with 100+i. Read row zero at x = -1,0,1,2,8,9,10,11.
+; Copy the full-width data and status and the D16 data and status to the first four rows of the SINT image.
+; Data rows 0 and 2 contain zero (preserving D16's high half) outside the image. The two status rows retain
+; their distinct seeds on all accesses. A coordinate outside a resident view does not give a residency NACK.
+; Run: vk_store_test cs_image_tfe_dense.spv words
+; mattr: +wavefrontsize32,-wavefrontsize64
+v_cmpx_gt_u32_e32 32, v0
+v_and_b32_e32 v1, 7, v0
+v_lshrrev_b32_e32 v2, 3, v0
+v_add_nc_u32_e32 v3, -1, v1
+v_add_nc_u32_e32 v4, 4, v1
+v_cmp_gt_u32_e32 4, v1
+v_cndmask_b32_e64 v3, v4, v3, vcc_lo
+v_mov_b32_e32 v4, 0
+
+s_mov_b32 s8, 0x2000
+s_mov_b32 s9, 0x1400000
+s_mov_b32 s10, 0x22
+s_mov_b32 s11, 0x22
+s_mov_b32 s12, 0x22
+s_mov_b32 s13, 0x22
+s_mov_b32 s14, 0x22
+s_mov_b32 s15, 0x22
+s_mov_b32 s16, 0x3000
+s_mov_b32 s17, 0x1500000
+s_mov_b32 s18, 0x33
+s_mov_b32 s19, 0x33
+s_mov_b32 s20, 0x33
+s_mov_b32 s21, 0x33
+s_mov_b32 s22, 0x33
+s_mov_b32 s23, 0x33
+
+v_mov_b32_e32 v8, 0x5a5a03f5
+v_mov_b32_e32 v9, 0x5a5a03f4
+v_mov_b32_e32 v10, 0x5a5a03f6
+image_load v[7:8], v[3:4], s[8:15] dmask:0x1 dim:SQ_RSRC_IMG_2D unorm tfe
+image_load v[9:10], v[3:4], s[8:15] dmask:0x1 dim:SQ_RSRC_IMG_2D unorm tfe d16
+s_waitcnt vmcnt(0)
+
+v_cmp_eq_u32_e32 2, v2
+v_cndmask_b32_e64 v11, v10, v9, vcc_lo
+v_cmp_eq_u32_e32 1, v2
+v_cndmask_b32_e64 v11, v11, v8, vcc_lo
+v_cmp_eq_u32_e32 0, v2
+v_cndmask_b32_e64 v11, v11, v7, vcc_lo
+image_store v11, v[1:2], s[16:23] dmask:0x1 dim:SQ_RSRC_IMG_2D unorm
+s_endpgm

From ea9475da49364bd0d1ec0114f92f8fcf2296dbc7 Mon Sep 17 00:00:00 2001
From: tahffo68hk-hash <[email protected]>
Date: Tue, 24 Nov 2026 10:42:52 +0800
Subject: [PATCH 2/2] Check that resident TFE loads preserve the seeded status
 words

Raw GFX1036 readback matched 48 cases covering D16 and D32, R32 and R32G32, three seeds, in-range and out-of-range coordinates, and inactive lanes. Check both words independently and signal corruption through the existing Vulkan readback.

AI-assisted.
---
 runtime/test/shaders/cs_imgload_d16_tfe.asm | 18 +++++++++++-------
 runtime/test/shaders/cs_imgload_tfe.asm     | 18 +++++++++++-------
 2 files changed, 22 insertions(+), 14 deletions(-)

diff --git a/runtime/test/shaders/cs_imgload_d16_tfe.asm b/runtime/test/shaders/cs_imgload_d16_tfe.asm
index 0739810..0e24135 100644
--- a/runtime/test/shaders/cs_imgload_d16_tfe.asm
+++ b/runtime/test/shaders/cs_imgload_d16_tfe.asm
@@ -1,7 +1,7 @@
-; tfe status VGPR on a d16 image_load (SHADER-1266): cs_imgload_d16 with tfe on both loads. Under d16 one
-; component fills one VGPR, and with tfe the fetch status follows it, so vdata is v[7:8] and v[11:12]. Every texel is
-; resident, so the status is 0. Each status VGPR is seeded with 1000 and added into the result, so a stale status
-; moves every texel by 2000. The unpacking and the result are cs_imgload_d16's, checked by vk_store_test load-d16
+; tfe status VGPR on a d16 image_load (SHADER-1266): the status follows the packed data word, so vdata is
+; v[7:8] and v[11:12]. Raw gfx1036 reads of resident textures kept the status seeds 0, 1000 and 0xa5a5ffe1.
+; Compare both status registers against their seeds and store a sentinel on any mismatch.
+; The unpacking and the result are cs_imgload_d16's, checked by vk_store_test load-d16
 ; (including its saturation row). Suggested by @nnonno91, who ran the same companion on gfx1036 and an RTX 5090 in #8968.
 v_and_b32_e32 v1, 7, v0
 v_lshrrev_b32_e32 v2, 3, v0
@@ -38,14 +38,18 @@ s_mov_b32 s28, 0x33
 s_mov_b32 s29, 0x33
 s_mov_b32 s30, 0x33
 s_mov_b32 s31, 0x33
-v_mov_b32_e32 v12, 0x3e8
+v_mov_b32_e32 v12, 0xa5a5ffe1
 image_load v[11:12], v[1:2], s[24:31] dmask:0x1 dim:SQ_RSRC_IMG_2D unorm tfe d16
 s_waitcnt vmcnt(0)
 v_and_b32_e32 v7, 0xffff, v7
 v_bfe_i32 v11, v11, 0, 16
 v_add_nc_u32_e32 v11, v7, v11
-v_add_nc_u32_e32 v11, v8, v11
-v_add_nc_u32_e32 v11, v12, v11
+v_xor_b32_e32 v8, 0x3e8, v8
+v_xor_b32_e32 v12, 0xa5a5ffe1, v12
+v_or_b32_e32 v8, v8, v12
+v_cmp_eq_u32_e32 0, v8
+v_mov_b32_e32 v8, 0x7fffffff
+v_cndmask_b32_e64 v11, v8, v11, vcc_lo
 v_mov_b32_e32 v12, 0
 v_mov_b32_e32 v13, 0
 v_mov_b32_e32 v14, 0
diff --git a/runtime/test/shaders/cs_imgload_tfe.asm b/runtime/test/shaders/cs_imgload_tfe.asm
index 63ad9dc..996cbde 100644
--- a/runtime/test/shaders/cs_imgload_tfe.asm
+++ b/runtime/test/shaders/cs_imgload_tfe.asm
@@ -1,7 +1,7 @@
-; tfe status VGPR on image_load (SHADER-1266): cs_imgload with tfe on both loads. With tfe an MIMG read returns one
-; more dword after its data, the fetch status, at vdata[data_count] (RDNA2 ISA, MIMG TFE/LWE). Every texel here is
-; resident, so the status is 0. Each status VGPR is seeded with 1000 before its load and added into the result, so a
-; status that keeps its old value moves every texel by 1000 or 2000. vk_store_test fills the r32 uint image with
+; tfe status VGPR on image_load (SHADER-1266): the status follows the data and is written on a texture NACK
+; (RDNA2 ISA, MIMG). Every texel here is resident. Raw gfx1036 reads preserved the status seeds 0, 1000 and
+; 0xa5a5ffe1. Compare the two status registers separately against their seeds and store a sentinel on any mismatch.
+; vk_store_test fills the r32 uint image with
 ; 100 + 8y + x and the r32 sint image with -2 (8y + x) before the dispatch; the rgba8 image is stored as in
 ; cs_imgstore. Run: vk_store_test cs_imgload_tfe.spv load -> sint = 100 - (8y + x), uint unchanged.
 v_and_b32_e32 v1, 7, v0
@@ -39,12 +39,16 @@ s_mov_b32 s28, 0x33
 s_mov_b32 s29, 0x33
 s_mov_b32 s30, 0x33
 s_mov_b32 s31, 0x33
-v_mov_b32_e32 v12, 0x3e8
+v_mov_b32_e32 v12, 0xa5a5ffe1
 image_load v[11:12], v[1:2], s[24:31] dmask:0x1 dim:SQ_RSRC_IMG_2D unorm tfe
 s_waitcnt vmcnt(0)
 v_add_nc_u32_e32 v11, v7, v11
-v_add_nc_u32_e32 v11, v8, v11
-v_add_nc_u32_e32 v11, v12, v11
+v_xor_b32_e32 v8, 0x3e8, v8
+v_xor_b32_e32 v12, 0xa5a5ffe1, v12
+v_or_b32_e32 v8, v8, v12
+v_cmp_eq_u32_e32 0, v8
+v_mov_b32_e32 v8, 0x7fffffff
+v_cndmask_b32_e64 v11, v8, v11, vcc_lo
 v_mov_b32_e32 v12, 0
 v_mov_b32_e32 v13, 0
 v_mov_b32_e32 v14, 0
**@⁠tahffo68hk-hash** on GitHub · 2026-11-24 03:38 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/98#issuecomment-7121281645) · edited 2026-11-24 03:42 UTC Thanks, @⁠Mouad-Scriptz-0. I’d be glad to take you up on your offer to open the TFE fixture PR. Please preserve the original Git author and author date from both patches (author: tahffo68hk-hash). The original commits are 6dd337e07ff92bd6ddb90c1308820f424e05e8da (independent dense control, readback check and one documentation row) and a7d72f949791ae7218ecfc3f118e7d82c1b5e8c8 (legacy D16/D32 fixtures). The mbox below covers only the synthetic fixtures, checker and documentation. The inline mbox refreshes the design-table context against main ece4ba5b, preserving both original author dates. On RTX 5060 Ti (617.42), two legacy cases failed before the fixture update. After applying both patches, all three targeted TFE cases passed in Wave64 emulation and all three modules passed spirv-val. The [native GFX1036 evidence](https://github.com/LeonidaReforge/Leonida/issues/9#issuecomment-7120453070) covers 48 kernels and 192 lane observations. The [RTX 5060 Ti negative control](https://git.gtahub.st/github/ubiquitarianism--leonida/pulls/98) shows that forcing zero changes the preserved seeded status without changing the fetched data. This scope is resident image_load TFE, including coordinate OOB. Sparse-page NACK and LWE were unverified. Separately, if you are also interested in helping with the [runner verdict fix](https://git.gtahub.st/github/ubiquitarianism--leonida/issues/14) (c178a889a), I’d appreciate a pointer or a separate PR. The TFE fixture PR can proceed independently. AI-assisted. <details> <summary>中文翻译</summary> 谢谢你主动提出帮忙开 TFE 测试 PR。请保留两份补丁原始 Git 作者及作者日期,作者为 tahffo68hk-hash。6dd337e07 添加独立 dense 合成对照、读回检查和一行文档,a7d72f949 修正旧 D16/D32 测试。下方 mbox 不含翻译器修改。下方 mbox 已按 main ece4ba5b 调整设计文档表格的上下文并保留两份补丁的原始作者日期。在 RTX 5060 Ti(617.42)的 Wave64 模拟模式下,修改前两个旧用例均失败,修改后三个 TFE 用例均通过,三个模块均通过 spirv-val。 公开的 GFX1036 实验覆盖 48 个 kernel 和 192 个 lane 读回。RTX 5060 Ti 负对照显示强制清零会改变预置状态字,读取的数据保持一致。结论限于常驻资源的 image_load TFE,包括坐标越界。稀疏页 NACK 和 LWE 尚未验证。 另有一项独立的 runner 判定修复 c178a889a。如果你也愿意指点提交途径或代开单独 PR,非常感谢。TFE 测试 PR 可以独立推进。 AI-assisted(AI 辅助)。 </details> <details> <summary>Source-only git am mbox for Continued main</summary> ````diff From 337b3c0a3661ab0dfe57cd53f716ce1f87f7f2ea Mon Sep 17 00:00:00 2001 From: tahffo68hk-hash <[email protected]> Date: Tue, 24 Nov 2026 10:21:30 +0800 Subject: [PATCH 1/2] Test dense image-load TFE with seeded status and out-of-bounds coordinates Record the dense GFX1036 observations and test the integer readback without changing the older fixtures. AI-assisted. --- docs/design.md | 1 + runtime/test/shaders/check.py | 7 +++ runtime/test/shaders/cs_image_tfe_dense.asm | 48 +++++++++++++++++++++ 3 files changed, 56 insertions(+) create mode 100644 runtime/test/shaders/cs_image_tfe_dense.asm diff --git a/docs/design.md b/docs/design.md index 6bb4173..d6e444b 100644 --- a/docs/design.md +++ b/docs/design.md @@ -413,6 +413,7 @@ How the generated SPIR-V expects the runtime to work: | LDS 2-address b64 (`ds_read2_b64`, `ds_write2_b64`, `ds_read2st64_b64`, `ds_write2st64_b64`) | Two elements at vaddr + offset0·unit and vaddr + offset1·unit, unit = 8 bytes (×64 for st64); each element is two consecutive dwords, low first. `read2_b64` fills v[d:d+3] after all four loads (a vdst overlapping vaddr is safe); `write2_b64` takes two VGPR pairs. The b32 forms share the code with unit 4. Source: RDNA2 ISA DS 2-address forms. CPU-checked by `tests/semantic/test_lds_read2_write2_b64.py` (compute listings, LDS as a Workgroup variable); GPU-checked by `runtime/test/shaders/cs_lds_b64_cmpst.asm` (unit 8 and the 512-byte st64 forms, plus vdst/vaddr overlap, on an RTX 3070, driver 621.01, Windows 11; the same eight words also on an AMD RX 7600 (`gfx1102`) and a Ryzen 5 9600X iGPU (`gfx1036`, RDNA2, RADV Mesa 27.0.0-devel)). | | Compute workgroup IDs Y/Z | With four user SGPRs and only TGID_Y and TGID_Z enabled (RSRC2 `0x308`), s4 receives Y and s5 receives Z. The synthetic `cs_workgroup_yz.asm` fixture checks a 2 × 3 × 4 dispatch and each of its 24 origins against a CPU reference. | | Typed image stores | `image_store` (2D, 2D array, 3D, cube) writes the dmask components (missing ones = 0). The image's numeric type lives in the T# (word 1 FORMAT [28:20], 512 GFX10 formats), so it is decided at run time. A 512-bit table built from `tools/gfx10_formats.json` (30 UINT and 15 SINT formats) picks a **sint**, **uint** or **float** view (bindings 8 + 3·dim + class; dim 0 = 2D, 1 = 2D array, 2 = 3D; class 0 float, 1 uint, 2 sint). Views have Unknown format (`shaderStorageImageWriteWithoutFormat`). **The runtime binds every storage image into all three arrays of its dimension, or at least the one matching its format.** The earlier path wrote only component 0 as `r32ui`, which was wrong for every other format. GPU-checked with `runtime/test/shaders/cs_imgstore.asm` through `runtime/test/vk_store_test.cpp`: rgba8 unorm, r32 uint and r32 sint images, every texel correct. A cube storage image is bound as a six-layer 2D array (bindings 11/12/13 for float/uint/sint, `OpTypeImage ... 2D 0 1 0 2 Unknown`, `%v3int` coordinates (x, y, face)); `tfe` and `lwe` are refused. CPU-checked by `tests/semantic/test_image_cube_store_glc.py`; **not GPU-verified**: no GPU fixture covers a cube store yet. | +| Dense `image_load tfe` | RDNA2 ISA §8.2 associates the trailing status VGPR with a texture NACK. [LLVM](https://github.com/llvm/llvm-project/blob/main/llvm/lib/Target/AMDGPU/SIISelLowering.cpp) and [Mesa ACO](https://github.com/chaotic-cx/mesa-mirror/blob/main/src/amd/compiler/instruction_selection/aco_isel_helpers.cpp) initialize that register in the generated shader. Native gfx1036 kept a nonzero status seed for both in-bounds and out-of-bounds reads of resident R32 and R32G32 images. Out-of-bounds data was zero, the unused high half of a single D16 word was preserved, and an inactive lane kept its data and status. The status follows the packed data words (one word for two D16 components). `cs_image_tfe_dense` checks data and preserved status on Vulkan. Sparse page NACK behavior is outside this dense fixture. | | Typed image loads | A noncoherent cube `image_load` reads the 2D-array sampled binding (3) with integer coordinates and layer. Its T# format selects the float, uint or sint alias, including for D16. The [RDNA2 ISA §8.2.1](https://docs.amd.com/v/u/en-US/rdna2-shader-instruction-set-architecture) assigns D16 conversion to the image format. The synthetic `cube_load_d16.asm` checks the generated views and format choices on the CPU. `image_load` on 1D/2D/2D-array/3D images uses the same T# FORMAT tables as stores, and fetches every format with `OpImageFetch` from the sampled array of its dimension (bindings 0, 3, 6, 5): UINT/SINT formats through **uint/sint aliases of that array** (same set and binding, an `OpTypeImage` of `%uint`/`%int`; Vulkan allows several variables on one binding when the descriptor type fits), everything else through the float array. A lookup miss (index 0) takes the float path, since the fallback there is RGBA8_UNORM. Results are the raw bits of the dmask components. **The runtime binds each image's view in its own format at its index of the sampled array** (what `bind_image` in `runtime/shims/d3d12_vulkan_device.cpp` already does for SRVs and UAVs), so the view's numeric type matches the alias that reads it. No storage image is read, so shaders that only load need neither `shaderStorageImageReadWithoutFormat` (missing on Intel Xe-LP, #619) nor `shaderStorageImageWriteWithoutFormat` (SHADER-151). Until 2026-11-22 integer formats were read with `OpImageRead` from the uint/sint storage arrays (bindings 8–19), which hold only unordered-access views and 256 entries: a read-only integer texture found the fallback there, or an index past the array's end. Like the float path, the fetch goes through the texture path, so it sees writes made before the dispatch, not ones made earlier in the same dispatch. **d16 loads take the same branch** (#1136) and pack the dmask components two per VGPR, low half first: f16 (round to nearest even, integer ops, no `PackHalf2x16`) from the float array, the low 16 bits of each value from the uint/sint aliases (truncated). **d16 loads take the same branch** (#1136) and pack the dmask components two per VGPR, low half first: f16 (round to nearest even, integer ops, no `PackHalf2x16`) from the float array, each value from the uint/sint aliases saturated to the 16-bit range of its signedness (`saturate_int16`). For odd component counts (1 or 3 in `dmask`), the trailing destination VGPR preserves its existing high 16 bits (`write_lo16`), matching native `gfx1036` hardware where a seeded `0x5a5a` high half survived 1-component UINT/SINT `image_load` and `image_load_mip`; until 2026-11-22 the unused high half was zeroed. Before #1136, a d16 load always read the float view, so a `Texture2D<min16uint>` `Load` returned garbage. CPU-checked by `tests/test_image_load_typed.py` (capabilities, bindings and component types for every dimension; the branch for all 512 FORMAT values, found and missed). GPU-checked with `runtime/test/shaders/cs_imgload.asm` through `vk_store_test load`, on a device made without `shaderStorageImageReadWithoutFormat`: r32 uint and r32 sint images filled before the dispatch, both read with `image_load` and their sum stored, every texel exact on an RTX 2080 Ti (NVIDIA 621.14, Windows 11), clean under the validation layer with GPU-assisted validation; the test fails a module that declares `StorageImageReadWithoutFormat`. d16: CPU-checked by `tests/test_image_load_d16_typed.py` (the uint/sint fetches go through the aliases, no storage image is read, the SPIR-V validates); GPU-checked with `runtime/test/shaders/cs_imgload_d16.asm` through `vk_store_test load`: both pre-filled texels read with d16 loads (the sint one sign-extended from bit 15 in the shader) and their sum stored, every texel exact on the RTX 2080 Ti with GPU-assisted validation (#1136 checked its first form, a store and d16 read-back in one dispatch, on an RTX 5070, and `cs_imgload_d16` passes unchanged on an AMD RX 7600 (gfx1102, RADV Mesa 27.0.0-devel) in `run_gpu_tests.py`). GPU-checked with `runtime/test/shaders/cs_imgload_d16.asm` through `vk_store_test load`: both pre-filled texels read with d16 loads (the sint one sign-extended from bit 15 in the shader) and their sum stored, every texel exact on the RTX 2080 Ti with GPU-assisted validation (#1136 checked its first form, a store and d16 read-back in one dispatch, on an RTX 5070). 2D `image_load_mip` uses the same numeric-type selection and passes the address register's mip to each fetch. Its D16 form packs the selected components in ascending order, two per VGPR. An RGBA8 two-level texture was checked on RTX 5080 and Radeon Graphics: all four exported halves matched the CPU reference for UINT, SINT and UNORM, and forcing level 0 changed every pixel. Checked on RTX 5080 and Radeon Graphics with R8G8B8A8 UINT, SINT and UNORM textures: level 1 matched the CPU reference at every pixel with GPU-assisted validation, and forcing level 0 changed all 4096 pixels for each format. Native gfx1036 saturated 32-bit UINT/SINT texels to the unsigned/signed 16-bit range in both D16 load forms; the translated 2D load matched both limits on RTX 5080 and Radeon Graphics. Native gfx1036 does the same on every dimension (SHADER-387, `tools/image_d16_probe.py`): 32_UINT and 32_32_UINT texels saturate to [0, 0xffff] and 32_SINT and 32_32_SINT texels to [-32768, 32767], never truncate, in 1D, 2D, 2D-array and 3D images, through `image_load` and `image_load_mip` alike; two-channel results pack x low and y high, and a one-channel result keeps the seeded high half. The translated d16 loads on 1D, 2D-array and 3D images still lack GPU checks. | | Packed 2D mip-load addresses | For `image_load_mip` with `a16`, the first VGPR holds unsigned X (low half) and Y (high half). The low half of the second VGPR selects the mip and its high half is unused. Both ordinary and D16 results use the same address. LLVM gfx1030 assembles both forms in `tests/semantic/fixtures/packed_mip_load_2d.asm`. `tests/test_image_load_typed.py` checks the texel and mip operands of the float, UINT and SINT fetches, including noncontiguous address registers. [AMD RDNA 2 ISA, MIMG A16 field](https://www.amd.com/content/dam/amd/en/documents/radeon-tech-docs/instruction-set-architectures/rdna2-shader-instruction-set-architecture.pdf) | | 3D explicit-mip loads | `image_load_mip` reads x, y, z and mip from four address VGPRs. T# FORMAT selects the float, UINT or SINT 3D sampled view at binding 6. D16 narrows the selected components before packing them low half first. The unit test `test_volume_mip_fetch_uses_xyz_level_and_descriptor_type` in `tests/test_image_load_typed.py` checks the four address registers and the RGBA32 format selection on the translated module. Native gfx1036 measured UINT and SINT saturation for 3D `image_load_mip` at mip zero. [Volume load measurements](https://github.com/ItsNotRexed/Leonida/pull/2217) | diff --git a/runtime/test/shaders/check.py b/runtime/test/shaders/check.py index 7b37772..a6d6144 100644 --- a/runtime/test/shaders/check.py +++ b/runtime/test/shaders/check.py @@ -603,6 +603,13 @@ STORE_WORDS = { "cs_resinfo": ({**dict(enumerate([16, 4, 0, 5, 8, 2, 0, 5, 2, 1, 0, 5, 4, 1, 0xABCD])), 16: 2, 17: 5, 18: 5, 20: 0, 21: 0, 22: 0, 23: 5}, {}, {}), + # TFE leaves both seeded status words intact. D16 updates only the low half of its single data word. + "cs_image_tfe_dense": ({}, dict(enumerate([ + 0, 100, 101, 102, 0, 0, 0, 0, + *[0x5A5A03F5] * 8, + 0x5A5A0000, 0x5A5A0064, 0x5A5A0065, 0x5A5A0066, *[0x5A5A0000] * 4, + *[0x5A5A03F6] * 8, + ])), {}), } # TEST-184: image_get_lod on vk_texture_test's textures. Per fixture, its draws: S# word 1 (MIN_LOD [11:0], MAX_LOD # [23:12], 4.8 fixed point), whether the two-mip texture is drawn, and mrt0, as derived in the .asm header: diff --git a/runtime/test/shaders/cs_image_tfe_dense.asm b/runtime/test/shaders/cs_image_tfe_dense.asm new file mode 100644 index 0000000..dfe475b --- /dev/null +++ b/runtime/test/shaders/cs_image_tfe_dense.asm @@ -0,0 +1,48 @@ +; TFE on a resident R32_UINT image, measured with raw image_load on GFX1036. +; vk_store_test words fills the 8x8 input with 100+i. Read row zero at x = -1,0,1,2,8,9,10,11. +; Copy the full-width data and status and the D16 data and status to the first four rows of the SINT image. +; Data rows 0 and 2 contain zero (preserving D16's high half) outside the image. The two status rows retain +; their distinct seeds on all accesses. A coordinate outside a resident view does not give a residency NACK. +; Run: vk_store_test cs_image_tfe_dense.spv words +; mattr: +wavefrontsize32,-wavefrontsize64 +v_cmpx_gt_u32_e32 32, v0 +v_and_b32_e32 v1, 7, v0 +v_lshrrev_b32_e32 v2, 3, v0 +v_add_nc_u32_e32 v3, -1, v1 +v_add_nc_u32_e32 v4, 4, v1 +v_cmp_gt_u32_e32 4, v1 +v_cndmask_b32_e64 v3, v4, v3, vcc_lo +v_mov_b32_e32 v4, 0 + +s_mov_b32 s8, 0x2000 +s_mov_b32 s9, 0x1400000 +s_mov_b32 s10, 0x22 +s_mov_b32 s11, 0x22 +s_mov_b32 s12, 0x22 +s_mov_b32 s13, 0x22 +s_mov_b32 s14, 0x22 +s_mov_b32 s15, 0x22 +s_mov_b32 s16, 0x3000 +s_mov_b32 s17, 0x1500000 +s_mov_b32 s18, 0x33 +s_mov_b32 s19, 0x33 +s_mov_b32 s20, 0x33 +s_mov_b32 s21, 0x33 +s_mov_b32 s22, 0x33 +s_mov_b32 s23, 0x33 + +v_mov_b32_e32 v8, 0x5a5a03f5 +v_mov_b32_e32 v9, 0x5a5a03f4 +v_mov_b32_e32 v10, 0x5a5a03f6 +image_load v[7:8], v[3:4], s[8:15] dmask:0x1 dim:SQ_RSRC_IMG_2D unorm tfe +image_load v[9:10], v[3:4], s[8:15] dmask:0x1 dim:SQ_RSRC_IMG_2D unorm tfe d16 +s_waitcnt vmcnt(0) + +v_cmp_eq_u32_e32 2, v2 +v_cndmask_b32_e64 v11, v10, v9, vcc_lo +v_cmp_eq_u32_e32 1, v2 +v_cndmask_b32_e64 v11, v11, v8, vcc_lo +v_cmp_eq_u32_e32 0, v2 +v_cndmask_b32_e64 v11, v11, v7, vcc_lo +image_store v11, v[1:2], s[16:23] dmask:0x1 dim:SQ_RSRC_IMG_2D unorm +s_endpgm From ea9475da49364bd0d1ec0114f92f8fcf2296dbc7 Mon Sep 17 00:00:00 2001 From: tahffo68hk-hash <[email protected]> Date: Tue, 24 Nov 2026 10:42:52 +0800 Subject: [PATCH 2/2] Check that resident TFE loads preserve the seeded status words Raw GFX1036 readback matched 48 cases covering D16 and D32, R32 and R32G32, three seeds, in-range and out-of-range coordinates, and inactive lanes. Check both words independently and signal corruption through the existing Vulkan readback. AI-assisted. --- runtime/test/shaders/cs_imgload_d16_tfe.asm | 18 +++++++++++------- runtime/test/shaders/cs_imgload_tfe.asm | 18 +++++++++++------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/runtime/test/shaders/cs_imgload_d16_tfe.asm b/runtime/test/shaders/cs_imgload_d16_tfe.asm index 0739810..0e24135 100644 --- a/runtime/test/shaders/cs_imgload_d16_tfe.asm +++ b/runtime/test/shaders/cs_imgload_d16_tfe.asm @@ -1,7 +1,7 @@ -; tfe status VGPR on a d16 image_load (SHADER-1266): cs_imgload_d16 with tfe on both loads. Under d16 one -; component fills one VGPR, and with tfe the fetch status follows it, so vdata is v[7:8] and v[11:12]. Every texel is -; resident, so the status is 0. Each status VGPR is seeded with 1000 and added into the result, so a stale status -; moves every texel by 2000. The unpacking and the result are cs_imgload_d16's, checked by vk_store_test load-d16 +; tfe status VGPR on a d16 image_load (SHADER-1266): the status follows the packed data word, so vdata is +; v[7:8] and v[11:12]. Raw gfx1036 reads of resident textures kept the status seeds 0, 1000 and 0xa5a5ffe1. +; Compare both status registers against their seeds and store a sentinel on any mismatch. +; The unpacking and the result are cs_imgload_d16's, checked by vk_store_test load-d16 ; (including its saturation row). Suggested by @nnonno91, who ran the same companion on gfx1036 and an RTX 5090 in #8968. v_and_b32_e32 v1, 7, v0 v_lshrrev_b32_e32 v2, 3, v0 @@ -38,14 +38,18 @@ s_mov_b32 s28, 0x33 s_mov_b32 s29, 0x33 s_mov_b32 s30, 0x33 s_mov_b32 s31, 0x33 -v_mov_b32_e32 v12, 0x3e8 +v_mov_b32_e32 v12, 0xa5a5ffe1 image_load v[11:12], v[1:2], s[24:31] dmask:0x1 dim:SQ_RSRC_IMG_2D unorm tfe d16 s_waitcnt vmcnt(0) v_and_b32_e32 v7, 0xffff, v7 v_bfe_i32 v11, v11, 0, 16 v_add_nc_u32_e32 v11, v7, v11 -v_add_nc_u32_e32 v11, v8, v11 -v_add_nc_u32_e32 v11, v12, v11 +v_xor_b32_e32 v8, 0x3e8, v8 +v_xor_b32_e32 v12, 0xa5a5ffe1, v12 +v_or_b32_e32 v8, v8, v12 +v_cmp_eq_u32_e32 0, v8 +v_mov_b32_e32 v8, 0x7fffffff +v_cndmask_b32_e64 v11, v8, v11, vcc_lo v_mov_b32_e32 v12, 0 v_mov_b32_e32 v13, 0 v_mov_b32_e32 v14, 0 diff --git a/runtime/test/shaders/cs_imgload_tfe.asm b/runtime/test/shaders/cs_imgload_tfe.asm index 63ad9dc..996cbde 100644 --- a/runtime/test/shaders/cs_imgload_tfe.asm +++ b/runtime/test/shaders/cs_imgload_tfe.asm @@ -1,7 +1,7 @@ -; tfe status VGPR on image_load (SHADER-1266): cs_imgload with tfe on both loads. With tfe an MIMG read returns one -; more dword after its data, the fetch status, at vdata[data_count] (RDNA2 ISA, MIMG TFE/LWE). Every texel here is -; resident, so the status is 0. Each status VGPR is seeded with 1000 before its load and added into the result, so a -; status that keeps its old value moves every texel by 1000 or 2000. vk_store_test fills the r32 uint image with +; tfe status VGPR on image_load (SHADER-1266): the status follows the data and is written on a texture NACK +; (RDNA2 ISA, MIMG). Every texel here is resident. Raw gfx1036 reads preserved the status seeds 0, 1000 and +; 0xa5a5ffe1. Compare the two status registers separately against their seeds and store a sentinel on any mismatch. +; vk_store_test fills the r32 uint image with ; 100 + 8y + x and the r32 sint image with -2 (8y + x) before the dispatch; the rgba8 image is stored as in ; cs_imgstore. Run: vk_store_test cs_imgload_tfe.spv load -> sint = 100 - (8y + x), uint unchanged. v_and_b32_e32 v1, 7, v0 @@ -39,12 +39,16 @@ s_mov_b32 s28, 0x33 s_mov_b32 s29, 0x33 s_mov_b32 s30, 0x33 s_mov_b32 s31, 0x33 -v_mov_b32_e32 v12, 0x3e8 +v_mov_b32_e32 v12, 0xa5a5ffe1 image_load v[11:12], v[1:2], s[24:31] dmask:0x1 dim:SQ_RSRC_IMG_2D unorm tfe s_waitcnt vmcnt(0) v_add_nc_u32_e32 v11, v7, v11 -v_add_nc_u32_e32 v11, v8, v11 -v_add_nc_u32_e32 v11, v12, v11 +v_xor_b32_e32 v8, 0x3e8, v8 +v_xor_b32_e32 v12, 0xa5a5ffe1, v12 +v_or_b32_e32 v8, v8, v12 +v_cmp_eq_u32_e32 0, v8 +v_mov_b32_e32 v8, 0x7fffffff +v_cndmask_b32_e64 v11, v8, v11, vcc_lo v_mov_b32_e32 v12, 0 v_mov_b32_e32 v13, 0 v_mov_b32_e32 v14, 0 ```` </details>
Author
Owner

@⁠Mouad-Scriptz-0 on GitHub · 2026-11-24 21:08 UTC · original

@⁠tahffo68hk-hash opened as #1271. Your first commit is applied with git am, so author and date are yours (2026-11-24 10:21:30 +0800). Two notes:

  • Your second patch isn't in it. #892 (moffington) landed on main at 17:15 UTC and already rewrote cs_imgload_tfe / cs_imgload_d16_tfe to expect the preserved status, with its own seeds. The PR says so.
  • One context fix in docs/design.md. main had since edited the "Typed image stores" row next to yours, so I kept main's version of that row and added yours unchanged.

On Intel Meteor Lake (ANV), cs_image_tfe_dense passes natively and emulated. With #98's translator it fails with the same 16 of 64 sint words you saw on the 5060 Ti.

AI-assisted (Claude Code).

**@⁠Mouad-Scriptz-0** on GitHub · 2026-11-24 21:08 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/98#issuecomment-7144530646) @⁠tahffo68hk-hash opened as #1271. Your first commit is applied with `git am`, so author and date are yours (`2026-11-24 10:21:30 +0800`). Two notes: - **Your second patch isn't in it.** #892 (moffington) landed on `main` at 17:15 UTC and already rewrote `cs_imgload_tfe` / `cs_imgload_d16_tfe` to expect the preserved status, with its own seeds. The PR says so. - **One context fix in `docs/design.md`.** `main` had since edited the "Typed image stores" row next to yours, so I kept `main`'s version of that row and added yours unchanged. On Intel Meteor Lake (ANV), `cs_image_tfe_dense` passes natively and emulated. With #98's translator it fails with the same 16 of 64 sint words you saw on the 5060 Ti. AI-assisted (Claude Code).

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.