rdna2spirv: zero the tfe/lwe status VGPR on image_load and image_load_mip (OLD-10022) #1334

Closed
github-bot wants to merge 1 commit from gh-pr/1334/head into gh-pr/1334/base
Owner

@⁠ambroseautomation on GitHub · 2026-11-24 21:58 UTC · original
ambroseautomation:carry/old-10022-image-load-tfe-zero → main · +113 −10 · 3 files · 1 commits · closed without merging

Summary

Coordination item: OLD-10022 (carry-forward of old-pr/10022, preserving original author Nikita Romanovich).

Problem & Root Cause

On RDNA2, image_load and image_load_mip with tfe or lwe write a trailing status VGPR vdata[data_vgprs] (where data_vgprs = (popcount(dmask) + 1) // 2 under d16, else popcount(dmask)) with 0 on resident accesses for active lanes while preserving inactive lanes. Previously tools/rdna2spirv.py did not zero that trailing status VGPR, leaving stale values in the status register.

Implementation

  • Updates tools/rdna2spirv.py to write 0 to the trailing tfe/lwe status VGPR on image_load and image_load_mip (respecting d16 packed register count and active EXEC lanes).
  • Adds the contract documentation sentence to the Typed image loads row in docs/design.md.
  • Adds CPU semantic regression tests in tests/semantic/test_image_load_tfe.py covering tfe, lwe, coherent/mip loads, and d16 packed offset calculation.

Tests Run

Environment: Windows 11 Pro 64-bit, Python 3.12.10, synthetic fixtures only (no game data).

  • python -I -m py_compile tools/rdna2spirv.py tests/semantic/test_image_load_tfe.py — PASS
  • python tests/semantic/test_image_load_tfe.py -v — 3/3 PASS
  • pytest tests/test_docs_links.py -v — 16/16 PASS
  • python -I scripts/run_semantic_tests.py tests/semantic — 472 files, 6,180 tests, 0 files failed (519 s, 16 jobs)
  • python -I scripts/check_no_game_data.py docs/design.md tests/semantic/test_image_load_tfe.py tools/rdna2spirv.py — PASS

Disclosure

AI-assisted: yes (carry-forward, rebase onto current main, and full semantic suite verification; original implementation by Nikita Romanovich).

**@⁠ambroseautomation** on GitHub · 2026-11-24 21:58 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1334) `ambroseautomation:carry/old-10022-image-load-tfe-zero` → `main` · +113 −10 · 3 files · 1 commits · closed without merging ## Summary Coordination item: `OLD-10022` (carry-forward of `old-pr/10022`, preserving original author `Nikita Romanovich`). ### Problem & Root Cause On RDNA2, `image_load` and `image_load_mip` with `tfe` or `lwe` write a trailing status VGPR `vdata[data_vgprs]` (where `data_vgprs = (popcount(dmask) + 1) // 2` under `d16`, else `popcount(dmask)`) with `0` on resident accesses for active lanes while preserving inactive lanes. Previously `tools/rdna2spirv.py` did not zero that trailing status VGPR, leaving stale values in the status register. ### Implementation - Updates `tools/rdna2spirv.py` to write `0` to the trailing `tfe`/`lwe` status VGPR on `image_load` and `image_load_mip` (respecting `d16` packed register count and active `EXEC` lanes). - Adds the contract documentation sentence to the `Typed image loads` row in `docs/design.md`. - Adds CPU semantic regression tests in `tests/semantic/test_image_load_tfe.py` covering `tfe`, `lwe`, coherent/mip loads, and `d16` packed offset calculation. ## Tests Run Environment: Windows 11 Pro 64-bit, Python 3.12.10, synthetic fixtures only (no game data). - `python -I -m py_compile tools/rdna2spirv.py tests/semantic/test_image_load_tfe.py` — PASS - `python tests/semantic/test_image_load_tfe.py -v` — 3/3 PASS - `pytest tests/test_docs_links.py -v` — 16/16 PASS - `python -I scripts/run_semantic_tests.py tests/semantic` — **472 files, 6,180 tests, 0 files failed** (519 s, 16 jobs) - `python -I scripts/check_no_game_data.py docs/design.md tests/semantic/test_image_load_tfe.py tools/rdna2spirv.py` — PASS ## Disclosure AI-assisted: yes (carry-forward, rebase onto current `main`, and full semantic suite verification; original implementation by Nikita Romanovich).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:47:47 +00:00
github-bot closed this pull request 2026-11-26 09:47:47 +00:00
Author
Owner

@⁠whoalin1 on GitHub · 2026-11-24 23:18 UTC · original

Independent GPU verification — request changes (AI-assisted, verified by a Devin subagent on real hardware; no game data used).

Tested head c778ef95f. Runtime test binaries from a origin/main build (this PR touches only tools/ + tests, so binaries are unaffected); llvm-mc = WSL LLVM 21.1.8; spirv-as/spirv-val from Vulkan SDK 1.4.363.0.

Semantic suite (CPU):

  • python -I scripts/run_semantic_tests.py tests/semantic -p "test_image*.py" → 13 files, 84 tests, 0 failed
  • python -I scripts/run_semantic_tests.py tests/semantic (full) → 472 files, 6,180 tests, 0 failed in 361 s

GPU — run_gpu_tests.py --filter img (11 image shaders), both run twice on AMD:

GPU env cs_imgload_tfe cs_imgload_d16_tfe rest
AMD Radeon iGPU (gfx1035, driver 24.10.24) VK_LOADER_DRIVERS_SELECT=*amd-vulkan* LEONIDA_VK_DEVICE=radeon VK_LOADER_LAYERS_DISABLE=~implicit~ LEONIDA_VK_VALIDATION=1 LEONIDA_PC_TAIL_UBO=1 FAIL exit 1: r32 sint (sint view): 64 bad, texel(5,3) = 2111 FAIL same 8/10 pass
NVIDIA RTX 4070 SUPER VK_LOADER_DRIVERS_SELECT=*nv-vk* LEONIDA_VK_DEVICE=4070 VK_LOADER_LAYERS_DISABLE=~implicit~ FAIL same signature FAIL same 8/10 pass

Baseline origin/main @ 51a6074d2, same commands/env:

  • AMD --filter img: 10/10 pass, both tfe tests give 0 bad, texel(5,3) = 71
  • NVIDIA --filter imgload: 4/4 pass

So the two cs_imgload*_tfe failures are a regression introduced by this PR on both GPUs, not the known pre-existing issue (#31 does not reproduce on current main with these drivers).

Why it fails: runtime/test/shaders/cs_imgload_tfe.asm documents measured RDNA2 behaviour — on a resident texel the TFE/LWE status VGPR is left unchanged, not zeroed. The fixture seeds v8 = 0x3e8 / v12 = 0x7d0 and verifies they survive the loads. Zeroing the status VGPR makes (v8 ^ 0x3e8) | (v12 ^ 0x7d0) non-zero and shifts every result word (observed 2111 instead of the 71-based values). Unless the fixture's documented hardware behaviour is itself wrong, the premise "resident accesses report 0" needs re-checking against the ISA/GPU before this lands.

**@⁠whoalin1** on GitHub · 2026-11-24 23:18 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1334#issuecomment-7147248453) Independent GPU verification — **request changes** (AI-assisted, verified by a Devin subagent on real hardware; no game data used). Tested head `c778ef95f`. Runtime test binaries from a `origin/main` build (this PR touches only `tools/` + tests, so binaries are unaffected); `llvm-mc` = WSL LLVM 21.1.8; `spirv-as`/`spirv-val` from Vulkan SDK 1.4.363.0. **Semantic suite (CPU):** - `python -I scripts/run_semantic_tests.py tests/semantic -p "test_image*.py"` → 13 files, 84 tests, 0 failed - `python -I scripts/run_semantic_tests.py tests/semantic` (full) → 472 files, 6,180 tests, 0 failed in 361 s **GPU — `run_gpu_tests.py --filter img` (11 image shaders), both run twice on AMD:** | GPU | env | cs_imgload_tfe | cs_imgload_d16_tfe | rest | |---|---|---|---|---| | AMD Radeon iGPU (gfx1035, driver 24.10.24) | `VK_LOADER_DRIVERS_SELECT=*amd-vulkan* LEONIDA_VK_DEVICE=radeon VK_LOADER_LAYERS_DISABLE=~implicit~ LEONIDA_VK_VALIDATION=1 LEONIDA_PC_TAIL_UBO=1` | **FAIL** `exit 1: r32 sint (sint view): 64 bad, texel(5,3) = 2111` | **FAIL** same | 8/10 pass | | NVIDIA RTX 4070 SUPER | `VK_LOADER_DRIVERS_SELECT=*nv-vk* LEONIDA_VK_DEVICE=4070 VK_LOADER_LAYERS_DISABLE=~implicit~` | **FAIL** same signature | **FAIL** same | 8/10 pass | **Baseline `origin/main` @ `51a6074d2`, same commands/env:** - AMD `--filter img`: **10/10 pass**, both tfe tests give `0 bad, texel(5,3) = 71` - NVIDIA `--filter imgload`: **4/4 pass** So the two `cs_imgload*_tfe` failures are a **regression introduced by this PR on both GPUs**, not the known pre-existing issue (#31 does not reproduce on current main with these drivers). **Why it fails:** `runtime/test/shaders/cs_imgload_tfe.asm` documents measured RDNA2 behaviour — on a *resident* texel the TFE/LWE status VGPR is left **unchanged**, not zeroed. The fixture seeds `v8 = 0x3e8` / `v12 = 0x7d0` and verifies they survive the loads. Zeroing the status VGPR makes `(v8 ^ 0x3e8) | (v12 ^ 0x7d0)` non-zero and shifts every result word (observed `2111` instead of the `71`-based values). Unless the fixture's documented hardware behaviour is itself wrong, the premise "resident accesses report 0" needs re-checking against the ISA/GPU before this lands.
Author
Owner

@⁠JesusACD on GitHub · 2026-11-24 23:31 UTC · original

### Hardware GPU test result: regresses cs_imgload_tfe and cs_imgload_d16_tfe on current main

Tested this PR (c778ef95fa48edb489f4e2410b43e7816191f7b1) merged cleanly onto main (e8fee01cd32d16b689a23aac9b320d6870d3ca4d) on an NVIDIA GeForce RTX 4060 Ti (PCI 10de:2803, subgroup 32..32, driver 621.14, Vulkan 1.4.357, Windows 11 x64, llvm-mc 23.1.6 + SPIRV-Tools 2026.4, runtime-windows built from e8fee01cd32d16b689a23aac9b320d6870d3ca4d; no game files).

Run main (e8fee01cd) main + #1334 (c778ef95)
rdna2spirv.py + spirv-val 262 / 262 translated & valid 262 / 262 translated & valid
run_gpu_tests.py (native) 204/253 passed, 49 skipped, 0 failed (exit 0) 202/253 passed, 49 skipped, 2 failed (exit 1)
run_gpu_tests.py (LEONIDA_W64_EMULATE=1) 236/253 passed, 17 skipped, 0 failed (exit 0) 234/253 passed, 17 skipped, 2 failed (exit 1)

Failing tests (both native and LEONIDA_W64_EMULATE=1)

FAIL  cs_imgload_d16_tfe    exit 1: r32 sint (sint view): 64 bad, texel(5,3) = 2111
FAIL  cs_imgload_tfe        exit 1: r32 sint (sint view): 64 bad, texel(5,3) = 2111

Why

old-pr/10022 predates 8afbba14b (SHADER-1266, runtime/test/shaders/cs_imgload_tfe.asm and cs_imgload_d16_tfe.asm on main), which measured on RDNA2 hardware (gfx1036) that a resident image_load with tfe leaves the trailing status VGPR unchanged rather than zeroing it. Both fixtures seed v8 = 0x3e8 and v12 = 0x7d0 and add (v8 ^ 0x3e8) | (v12 ^ 0x7d0) into v11; zeroing v8 and v12 adds 0x3e8 | 0x7d0 = 0x7f8 = 2040 to every texel (71 + 2040 = 2111).

(Minor note as well: python -I tests/semantic/test_image_load_tfe.py raises ModuleNotFoundError: No module named 'support' because -I omits the script directory from sys.path.)

(AI-assisted hardware test & review.)

**@⁠JesusACD** on GitHub · 2026-11-24 23:31 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1334#issuecomment-7147505433) ### Hardware GPU test result: regresses `cs_imgload_tfe` and `cs_imgload_d16_tfe` on current `main` Tested this PR (`c778ef95fa48edb489f4e2410b43e7816191f7b1`) merged cleanly onto `main` (`e8fee01cd32d16b689a23aac9b320d6870d3ca4d`) on an **NVIDIA GeForce RTX 4060 Ti** (`PCI 10de:2803`, subgroup `32..32`, driver `621.14`, Vulkan `1.4.357`, Windows 11 x64, `llvm-mc` 23.1.6 + `SPIRV-Tools` 2026.4, `runtime-windows` built from `e8fee01cd32d16b689a23aac9b320d6870d3ca4d`; no game files). | Run | `main` (`e8fee01cd`) | `main` + `#1334` (`c778ef95`) | |---|---|---| | `rdna2spirv.py` + `spirv-val` | 262 / 262 translated & valid | 262 / 262 translated & valid | | `run_gpu_tests.py` (native) | **204/253 passed**, 49 skipped, **0 failed** (exit 0) | **202/253 passed**, 49 skipped, **2 failed** (exit 1) | | `run_gpu_tests.py` (`LEONIDA_W64_EMULATE=1`) | **236/253 passed**, 17 skipped, **0 failed** (exit 0) | **234/253 passed**, 17 skipped, **2 failed** (exit 1) | #### Failing tests (both native and `LEONIDA_W64_EMULATE=1`) ```text FAIL cs_imgload_d16_tfe exit 1: r32 sint (sint view): 64 bad, texel(5,3) = 2111 FAIL cs_imgload_tfe exit 1: r32 sint (sint view): 64 bad, texel(5,3) = 2111 ``` #### Why `old-pr/10022` predates `8afbba14b` (`SHADER-1266`, `runtime/test/shaders/cs_imgload_tfe.asm` and `cs_imgload_d16_tfe.asm` on `main`), which measured on RDNA2 hardware (`gfx1036`) that a **resident** `image_load` with `tfe` leaves the trailing status VGPR **unchanged** rather than zeroing it. Both fixtures seed `v8 = 0x3e8` and `v12 = 0x7d0` and add `(v8 ^ 0x3e8) | (v12 ^ 0x7d0)` into `v11`; zeroing `v8` and `v12` adds `0x3e8 | 0x7d0 = 0x7f8 = 2040` to every texel (`71 + 2040 = 2111`). *(Minor note as well: `python -I tests/semantic/test_image_load_tfe.py` raises `ModuleNotFoundError: No module named 'support'` because `-I` omits the script directory from `sys.path`.)* *(AI-assisted hardware test & review.)*
Author
Owner

@⁠ThomasHFWright on GitHub · 2026-11-25 00:09 UTC · original

Additional Linux/NVIDIA check: the fixture version explains why this change can look like a fix on the older #939 integration.

AI-assisted. RTX 5090, NVIDIA 620.73.04, Linux 7.3.6-1-cachyos, LLVM 23.1.5, wave64 emulation enabled. Synthetic inputs only.

I tested #939 at eb6a08cd359d98b5777e70d54d0ae8a75879495a, then applied c778ef95f separately, adapting its status argument propagation to #939's descriptor/volume/storage helper signatures. Runtime code and native GPU test executables were unchanged.

Fixture input Original #939 translator With adapted #1334
Old TFE fixtures shipped in #939 both fail: 64 bad texels, sample 2071 both pass: sample 71
Corrected fixtures from upstream 8afbba14b both pass: zero bad texels, sample 71 both fail: 64 bad texels, sample 2111

The corrected pair was assembled from that commit and supplied with --disasm-dir ... --filter imgload --require-pass, using separate output directories. The full older-fixture GPU suite changed from 232 pass / 2 fail / 20 skip to 234 pass / 0 fail / 20 skip; those totals alone would therefore give the wrong recommendation. The adapted branch also passes 6,126 semantic tests, which does not resolve the incorrect expectation.

This agrees with the existing reviews: keep resident status values as required by the newer fixtures. The native RDNA2 behavior basis is the upstream hardware measurement; this additional check used translated shaders on NVIDIA. I am keeping #1334 out of the title integration and retaining the failed experiment separately. No game files or game-derived data used or attached.

**@⁠ThomasHFWright** on GitHub · 2026-11-25 00:09 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1334#issuecomment-7148202798) Additional Linux/NVIDIA check: the fixture version explains why this change can look like a fix on the older #939 integration. AI-assisted. RTX 5090, NVIDIA 620.73.04, Linux 7.3.6-1-cachyos, LLVM 23.1.5, wave64 emulation enabled. Synthetic inputs only. I tested #939 at `eb6a08cd359d98b5777e70d54d0ae8a75879495a`, then applied `c778ef95f` separately, adapting its status argument propagation to #939's descriptor/volume/storage helper signatures. Runtime code and native GPU test executables were unchanged. | Fixture input | Original #939 translator | With adapted #1334 | |---|---|---| | Old TFE fixtures shipped in #939 | both fail: 64 bad texels, sample 2071 | both pass: sample 71 | | Corrected fixtures from upstream `8afbba14b` | **both pass: zero bad texels, sample 71** | **both fail: 64 bad texels, sample 2111** | The corrected pair was assembled from that commit and supplied with `--disasm-dir ... --filter imgload --require-pass`, using separate output directories. The full older-fixture GPU suite changed from 232 pass / 2 fail / 20 skip to 234 pass / 0 fail / 20 skip; those totals alone would therefore give the wrong recommendation. The adapted branch also passes 6,126 semantic tests, which does not resolve the incorrect expectation. This agrees with the existing reviews: keep resident status values as required by the newer fixtures. The native RDNA2 behavior basis is the upstream hardware measurement; this additional check used translated shaders on NVIDIA. I am keeping #1334 out of the title integration and retaining the failed experiment separately. No game files or game-derived data used or attached.
Author
Owner

@⁠ambroseautomation on GitHub · 2026-11-25 12:46 UTC · original

Closing: thank you @⁠whoalin1, @⁠JesusACD, and @⁠ThomasHFWright for the hardware GPU verification. As confirmed, old-pr/10022 predates 8afbba14b (SHADER-1266), where RDNA2 hardware measurement showed resident image_load with tfe leaves the status VGPR unchanged rather than zeroing it. Zeroing it regresses cs_imgload_tfe and cs_imgload_d16_tfe on current main, so this carry-forward is obsoleted.

**@⁠ambroseautomation** on GitHub · 2026-11-25 12:46 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1334#issuecomment-7162833813) Closing: thank you @⁠whoalin1, @⁠JesusACD, and @⁠ThomasHFWright for the hardware GPU verification. As confirmed, old-pr/10022 predates 8afbba14b (SHADER-1266), where RDNA2 hardware measurement showed resident image_load with tfe leaves the status VGPR unchanged rather than zeroing it. Zeroing it regresses cs_imgload_tfe and cs_imgload_d16_tfe on current main, so this carry-forward is obsoleted.

Pull request closed

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