[PR #1114] [MERGED] tests: GPU readback for 38 scalar ALU ops on run-time operands (GPU-SALU-EXT) #1149

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

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1114
Author: @milk4sale
Created: 11/24/2026
Status: ✅ Merged
Merged: 11/25/2026
Merged by: @ubiquitarianism

Base: main ← Head: gpu-test/salu-ext


📝 Commits (2)

  • cec2c70 tests: GPU readback for 38 scalar ALU ops on run-time operands (GPU-SALU-EXT)
  • 0c3acdc Merge main into gpu-test/salu-ext

📊 Changes

8 files changed (+879 additions, -5 deletions)

View changed files

📝 docs/design.md (+2 -2)
📝 docs/testing.md (+22 -0)
📝 runtime/test/shaders/check.py (+28 -0)
➕ runtime/test/shaders/cs_w32_salu_ext.asm (+516 -0)
📝 scripts/run_gpu_tests.py (+5 -0)
➕ tests/test_gpu_salu_ext.py (+270 -0)
📝 tests/test_rdna2_decode.py (+26 -1)
📝 tests/test_shader_checks.py (+10 -2)

📄 Description

Claimed in the coordination issue as: GPU-SALU-EXT (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7140488039)

What and why

38 scalar ALU ops had no fixture in runtime/test/shaders, so no GPU test ran the SPIR-V their rules emit:
s_sub_i32, s_andn2_b32, s_orn2_b32, s_xor_b32, s_ashr_i32, s_mul_hi_u32, s_lshl3_add_u32,
s_lshl4_add_u32, s_pack_ll_b32_b16, s_pack_hh_b32_b16, s_abs_i32, s_bcnt0_i32_b32, s_bitset0_b32,
s_bitset1_b32, s_brev_b32, s_flbit_i32, s_flbit_i32_b32, s_sext_i32_i8, the six s_cmp_*_i32,
s_cmp_gt_u32, s_cmp_le_u32, s_bitcmp0_b32, s_bitcmp1_b32, s_addk_i32, s_mulk_i32, s_cmovk_i32,
s_ashr_i64, s_lshl_b64, s_lshr_b64, s_bcnt0_i32_b64, s_bitset0_b64, s_cmov_b64 and s_ff0_i32_b64.

cs_w32_salu_ext runs them in one thread and stores 73 words:

  • Its sixteen operand words arrive in s4..s19 through VKC_SGPRS. A scalar op on literals is folded by the
    translator (the "Chained scalar constant folding" row of docs/design.md) and only its result reaches the
    driver; with run-time operands each op reaches it as SPIR-V.
  • Every destination is stored, and four words of SCC bits: SCC after each of the 24 ops that write it, each run on
    operands that set it and on operands that clear it (each compare and bit test both ways, the signed and the
    unsigned ones on words that tell the two apart), and SCC after each of the 14 ops that must keep it, set to 1
    and to 0 in turn before them.
  • The expected words are literals in check.py, derived in the fixture's header. tests/test_gpu_salu_ext.py
    recomputes them from the fixture's own instruction lines with the reference of tools/salu_diff.py and checks
    that every op that writes SCC is seen with both values.

All 38 ops gave the expected words on both devices, so nothing changes in the translator.

One existing test had to change to let the fixture in. This is the first fixture with bit 15 set in the immediate
of a signed SOPK op (s_addk_i32 s52, 0x8000). tools/rdna2_decode.py gives that immediate sign-extended
(-32768) and llvm-mc 23.1.4 prints the same word as 0x8000, so test_parity_with_llvm_mc_on_shader_fixtures
failed on it. It now compares the immediates of the ten signed SOPK ops as the 16 bits they are, which is what it
already does for SOPP branch offsets. The encodings are still compared whole, and the translator reads the low
16 bits of either spelling. A new hand-encoded test pins which of the sixteen SOPK ops with an immediate the
decoder sign-extends. The decoder itself is not changed.

Docs: a paragraph in docs/testing.md; the rows of s_sext_i32_i8 / s_flbit_i32 (marked "not GPU-checked"
until now) and of s_lshl1..4_add_u32 in docs/design.md name the fixture.

It does not build on #1012, #1034, #1047 or #1063: its case is counted in a different term of TOTAL in
tests/test_shader_checks.py, and a merge of main, this branch and those four passes that file.

Tested

RTX 4070 Ti (NVIDIA 620.70.06, Linux) and llvmpipe (Mesa 26.2.6, LLVM 23.1.4); llvm-mc 23.1.4, SPIRV-Tools v2026.4.

  • python -I scripts/run_gpu_tests.py --build runtime/build --filter cs_w32_salu_ext --require-pass:
    80 words exact (73 results of 38 scalar ops and the untouched fill) on both devices, natively and with
    LEONIDA_W64_EMULATE=1.
  • The whole GPU suite on the 4070 Ti at this commit: 204/253 passed, 49 skipped natively and 236/253 passed,
    17 skipped with LEONIDA_W64_EMULATE=1; none failed.
  • Nine translator rules broken one at a time; each failed the fixture on both devices: s_ashr_i32 shifting in
    zeros (word 8), s_lshlN_add_u32 taking SCC from the add's carry alone (word 69), s_abs_i32 negating
    (word 17), s_mulk_i32 and s_addk_i32 zero-extending their immediate (words 37 and 21), s_cmovk_i32
    ignoring SCC (word 38), the 64-bit shifts taking their count modulo 32 and s_ashr_i64 shifting in zeros
    (word 51 each), and the 64-bit shifts taking SCC from the low dword alone (word 72).
  • python -I tests/test_gpu_salu_ext.py (13 tests), tests/test_shader_checks.py (87), tests/test_run_gpu_tests.py
    (64) and tests/test_rdna2_decode.py (20; before the change its parity test failed at
    cs_w32_salu_ext.asm: s_addk_i32).
  • Three decoder controls for the changed test, in a scratch copy: the decoder no longer sign-extending
    s_addk_i32, and sign-extending s_cmpk_gt_u32 as well, each fail the new test; one wrong low bit in the
    immediate of s_mulk_i32 still fails the parity test at cs_w32_salu_ext.asm: s_mulk_i32.
  • Every standalone test file under tests/ with python -I (490 files): all pass.
  • python -I scripts/run_semantic_tests.py tests/semantic: 470 files, 6168 tests, 0 files failed.
  • python -I scripts/check_no_game_data.py on the eight changed files, and python -m compileall.

Not run: llvm-mc 19 (the version CI uses), Windows, and an AMD or Intel GPU.

GPUs tested: NVIDIA GeForce RTX 4070 Ti, driver 620.70.06, Linux (CachyOS, kernel 7.3.3); llvmpipe (Mesa 26.2.6, LLVM 23.1.4)

AI-assisted: yes (Claude Code)

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (No new rule; two rows now name the GPU fixture.)

🤖 Generated with 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/1114 **Author:** [@milk4sale](https://github.com/milk4sale) **Created:** 11/24/2026 **Status:** ✅ Merged **Merged:** 11/25/2026 **Merged by:** [@ubiquitarianism](https://github.com/ubiquitarianism) **Base:** `main` ← **Head:** `gpu-test/salu-ext` --- ### 📝 Commits (2) - [`cec2c70`](https://github.com/ubiquitarianism/leonida/commit/cec2c7074c8b086b28d276f573573c22899200af) tests: GPU readback for 38 scalar ALU ops on run-time operands (GPU-SALU-EXT) - [`0c3acdc`](https://github.com/ubiquitarianism/leonida/commit/0c3acdc03056908d30724e9fd2bcc7acc8021936) Merge main into gpu-test/salu-ext ### 📊 Changes **8 files changed** (+879 additions, -5 deletions) <details> <summary>View changed files</summary> 📝 `docs/design.md` (+2 -2) 📝 `docs/testing.md` (+22 -0) 📝 `runtime/test/shaders/check.py` (+28 -0) ➕ `runtime/test/shaders/cs_w32_salu_ext.asm` (+516 -0) 📝 `scripts/run_gpu_tests.py` (+5 -0) ➕ `tests/test_gpu_salu_ext.py` (+270 -0) 📝 `tests/test_rdna2_decode.py` (+26 -1) 📝 `tests/test_shader_checks.py` (+10 -2) </details> ### 📄 Description Claimed in the coordination issue as: GPU-SALU-EXT (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7140488039) ### What and why 38 scalar ALU ops had no fixture in `runtime/test/shaders`, so no GPU test ran the SPIR-V their rules emit: `s_sub_i32`, `s_andn2_b32`, `s_orn2_b32`, `s_xor_b32`, `s_ashr_i32`, `s_mul_hi_u32`, `s_lshl3_add_u32`, `s_lshl4_add_u32`, `s_pack_ll_b32_b16`, `s_pack_hh_b32_b16`, `s_abs_i32`, `s_bcnt0_i32_b32`, `s_bitset0_b32`, `s_bitset1_b32`, `s_brev_b32`, `s_flbit_i32`, `s_flbit_i32_b32`, `s_sext_i32_i8`, the six `s_cmp_*_i32`, `s_cmp_gt_u32`, `s_cmp_le_u32`, `s_bitcmp0_b32`, `s_bitcmp1_b32`, `s_addk_i32`, `s_mulk_i32`, `s_cmovk_i32`, `s_ashr_i64`, `s_lshl_b64`, `s_lshr_b64`, `s_bcnt0_i32_b64`, `s_bitset0_b64`, `s_cmov_b64` and `s_ff0_i32_b64`. `cs_w32_salu_ext` runs them in one thread and stores 73 words: - Its sixteen operand words arrive in `s4..s19` through `VKC_SGPRS`. A scalar op on literals is folded by the translator (the "Chained scalar constant folding" row of `docs/design.md`) and only its result reaches the driver; with run-time operands each op reaches it as SPIR-V. - Every destination is stored, and four words of SCC bits: SCC after each of the 24 ops that write it, each run on operands that set it and on operands that clear it (each compare and bit test both ways, the signed and the unsigned ones on words that tell the two apart), and SCC after each of the 14 ops that must keep it, set to 1 and to 0 in turn before them. - The expected words are literals in `check.py`, derived in the fixture's header. `tests/test_gpu_salu_ext.py` recomputes them from the fixture's own instruction lines with the reference of `tools/salu_diff.py` and checks that every op that writes SCC is seen with both values. All 38 ops gave the expected words on both devices, so nothing changes in the translator. One existing test had to change to let the fixture in. This is the first fixture with bit 15 set in the immediate of a signed SOPK op (`s_addk_i32 s52, 0x8000`). `tools/rdna2_decode.py` gives that immediate sign-extended (-32768) and llvm-mc 23.1.4 prints the same word as `0x8000`, so `test_parity_with_llvm_mc_on_shader_fixtures` failed on it. It now compares the immediates of the ten signed SOPK ops as the 16 bits they are, which is what it already does for SOPP branch offsets. The encodings are still compared whole, and the translator reads the low 16 bits of either spelling. A new hand-encoded test pins which of the sixteen SOPK ops with an immediate the decoder sign-extends. The decoder itself is not changed. Docs: a paragraph in `docs/testing.md`; the rows of `s_sext_i32_i8` / `s_flbit_i32` (marked "not GPU-checked" until now) and of `s_lshl1..4_add_u32` in `docs/design.md` name the fixture. It does not build on #1012, #1034, #1047 or #1063: its case is counted in a different term of `TOTAL` in `tests/test_shader_checks.py`, and a merge of `main`, this branch and those four passes that file. ### Tested RTX 4070 Ti (NVIDIA 620.70.06, Linux) and llvmpipe (Mesa 26.2.6, LLVM 23.1.4); llvm-mc 23.1.4, SPIRV-Tools v2026.4. - `python -I scripts/run_gpu_tests.py --build runtime/build --filter cs_w32_salu_ext --require-pass`: `80 words exact (73 results of 38 scalar ops and the untouched fill)` on both devices, natively and with `LEONIDA_W64_EMULATE=1`. - The whole GPU suite on the 4070 Ti at this commit: 204/253 passed, 49 skipped natively and 236/253 passed, 17 skipped with `LEONIDA_W64_EMULATE=1`; none failed. - Nine translator rules broken one at a time; each failed the fixture on both devices: `s_ashr_i32` shifting in zeros (word 8), `s_lshlN_add_u32` taking SCC from the add's carry alone (word 69), `s_abs_i32` negating (word 17), `s_mulk_i32` and `s_addk_i32` zero-extending their immediate (words 37 and 21), `s_cmovk_i32` ignoring SCC (word 38), the 64-bit shifts taking their count modulo 32 and `s_ashr_i64` shifting in zeros (word 51 each), and the 64-bit shifts taking SCC from the low dword alone (word 72). - `python -I tests/test_gpu_salu_ext.py` (13 tests), `tests/test_shader_checks.py` (87), `tests/test_run_gpu_tests.py` (64) and `tests/test_rdna2_decode.py` (20; before the change its parity test failed at `cs_w32_salu_ext.asm: s_addk_i32`). - Three decoder controls for the changed test, in a scratch copy: the decoder no longer sign-extending `s_addk_i32`, and sign-extending `s_cmpk_gt_u32` as well, each fail the new test; one wrong low bit in the immediate of `s_mulk_i32` still fails the parity test at `cs_w32_salu_ext.asm: s_mulk_i32`. - Every standalone test file under `tests/` with `python -I` (490 files): all pass. - `python -I scripts/run_semantic_tests.py tests/semantic`: 470 files, 6168 tests, 0 files failed. - `python -I scripts/check_no_game_data.py` on the eight changed files, and `python -m compileall`. Not run: llvm-mc 19 (the version CI uses), Windows, and an AMD or Intel GPU. GPUs tested: NVIDIA GeForce RTX 4070 Ti, driver 620.70.06, Linux (CachyOS, kernel 7.3.3); llvmpipe (Mesa 26.2.6, LLVM 23.1.4) AI-assisted: yes (Claude Code) ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [x] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (No new rule; two rows now name the GPU fixture.) 🤖 Generated with [Claude Code](https://claude.com/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:20:15 +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#1149
No description provided.