[PR #508] wave64_halves: v_sat_pk_u8_i16 keeps its high half (SHADER-SATPK-HALVES) #556

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

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/508
Author: @milk4sale
Created: 11/24/2026
Status: 🔄 Open

Base: main ← Head: shader-satpk-halves


📝 Commits (6)

  • 6446e3c rdna2spirv: translate v_sat_pk_u8_i16 (SHADER-SATPK-U8)
  • 8fd02b4 Merge main into shader-satpk-u8 (#338) for the wave64_halves partial-write code of #265
  • 4234449 wave64_halves: v_sat_pk_u8_i16 keeps its high half (SHADER-SATPK-HALVES)
  • d093c0c Merge main into shader-satpk-halves
  • 232a2ce design.md: the v_sat_pk_u8_i16 high-half keep is the translator's choice (SHADER-SATPK-HALVES)
  • 38623a9 Merge main into shader-satpk-halves

📊 Changes

14 files changed (+439 additions, -5 deletions)

View changed files

📝 docs/design.md (+2 -0)
📝 docs/fssm_crosscheck.md (+1 -1)
➕ runtime/test/shaders/ps_w64_a_sat_pk_hi.asm (+49 -0)
➕ runtime/test/shaders/ps_w64_c_sat_pk_hi.asm (+35 -0)
📝 runtime/test/shaders/w64_graphics.py (+23 -0)
➕ tests/semantic/fixtures/sat_pk_u8_i16.asm (+16 -0)
➕ tests/semantic/fixtures/w64_sat_pk_hi.asm (+23 -0)
➕ tests/semantic/test_alu_sat_pk_u8_i16.py (+94 -0)
➕ tests/semantic/test_wave64_halves_sat_pk.py (+149 -0)
📝 tests/test_f16_op_sel.py (+1 -1)
📝 tests/test_translate.py (+1 -1)
📝 tests/test_wave64_halves_fixtures.py (+10 -0)
📝 tools/rdna2spirv.py (+29 -0)
📝 tools/wave64_halves.py (+6 -2)

📄 Description

Claimed in the coordination issue as: SHADER-SATPK-HALVES

Depends on: #338

What and why

#265 added v_sat_pk to _FULL32_V16_PREFIXES in tools/wave64_halves.py, so _preserves_dst treats v_sat_pk_u8_i16 as a full 32-bit write. partial_write also read the op's first type, u8, as an 8-bit result. #338 translates the op and writes the two saturated bytes with write_lo16, which keeps the high half in the _e32, _e64 and DPP forms. With both merged, a high half that depends on the lane lost its taint, and a wave64 VS/PS/GS passed as tier A, or tier B through readlane-uniform, although its export changes when the wave is cut into two 32-lane halves. NolanCotter reported this in #14.

This change removes v_sat_pk from the tuple, so the op falls to the _i16 rule, and makes partial_write say partial for it. Per encoding:

  • _e32 (VOP1 0x62), _e64 (VOP3 0x1e2) and DPP keep the high half.
  • SDWA keeps the rest only with a BYTE/WORD dst_sel and UNUSED_PRESERVE; dst_sel:DWORD, UNUSED_PAD and UNUSED_SEXT write the whole register. This was already right.
  • llvm-mc 23.1.4 rejects op_sel on the _e64 form for gfx1030.

References. Neither compiler says the high half is kept on GFX10, and the cited references don't either:

  • Mesa ACO's instr_is_16bit is false for the op before GFX11. It is not in the list, and can_use_opsel falls through to get_gfx11_true16_mask, which lists it next to v_cvt_f16_f32 for GFX11+ only (aco_ir.cpp, Mesa 99abc485).
  • LLVM's VOP1Inst_t16 is the plain VOP1 instruction on GFX10, with the true16 forms GFX11+ only. GCNSubtarget::zeroesHigh16BitsOfDest does not list the op (LLVM e2b0a1e1).

The rule here follows what the translator emits. If RDNA2 turns out to zero the high half, calling the op partial is still the safe side: it costs tier A at most, never exactness. The RDNA2 behaviour is not measured. The contract row in docs/design.md says so.

#338's own v_sat_pk_u8_i16 row cited ACO instr_is_16bit for the kept high half, which the halves row contradicts (review on this PR). This branch rewords that row: the keep is the translator's choice (write_lo16), not measured on RDNA2, with a pointer to the halves row's references. If #338 rewords the row first, take #338's wording when merging. #338's translator comment and the test_alu_sat_pk_u8_i16.py docstring cite ACO the same way; they are left to #338, where this was raised.

The halves analysis runs only for wave64 VS/PS/GS, never for compute or under --wave64-emulate (halves_analysis in rdna2spirv.py). So the GPU fixtures are ps_w64_* ones run by w64_graphics.py, not cs_*:

  • ps_w64_a_sat_pk_hi, tier A: the four encodings that keep the high half, a different high half per pixel, and both halves of SRC0 saturating below 0 and above 255 across the target. Every word is a function of the pixel, so a 32-only GPU checks all of them.
  • ps_w64_c_sat_pk_hi, tier C: the high half is the lane id. It is pinned to tier C, lane-id, in tests/test_wave64_halves_fixtures.py. On a GPU it needs both subgroup sizes, or W64G_REF.

Tested

  • tests/semantic/test_wave64_halves_sat_pk.py with the hand-written tests/semantic/fixtures/w64_sat_pk_hi.asm: 5 OK. It runs on the strict wave interpreter as 64 lanes and as two waves of 32, covers every encoding and the readlane-uniform case, and checks operands() and partial_write per encoding.
    • On #338's head (6446e3ce7): 12 subtests fail. That head predates #265, so it has no partial-destination handling at all.
    • On #338 plus main without this change: 9 fail (e32/e64/DPP tier A instead of C, readlane tier B instead of C).
  • python -I scripts/run_semantic_tests.py tests/semantic: 467 files, 6114 tests, 0 failed (70 s, 24 jobs).
  • python -m pytest tests/test_wave64_halves_fixtures.py tests/test_w64_graphics_args.py tests/test_w64_graphics_probe.py tests/test_w64_graphics_reference.py: 22 passed. Without the fix, test_fixtures_are_classified_as_their_headers_say fails: ps_w64_c_sat_pk_hi is tier A instead of C.
  • tests/test_design_contract_rows.py, tests/test_docs_design_rows.py, tests/test_text_write_line_endings.py and tests/test_semantic_translator_use.py pass. So do python -m compileall -q make_game.py tools tests and python -I scripts/check_no_game_data.py on every added or changed file.
  • After the row rewording (232a2ce6d, docs only): the four tests above, tests/test_wave64_halves_fixtures.py and the two sat_pk semantic test files pass again, and check_no_game_data.py docs/design.md exits 0.
  • w64_graphics.py on the RTX 4070 Ti: ps_w64_a_sat_pk_hi A ok, ps_w64_c_sat_pk_hi C SKIP (32 is the only fragment subgroup size). The verdicts are the same without the fix: a 32-only GPU cannot see the classification, so the tests above catch it. NVIDIA runs the translated SPIR-V, so this confirms the translator's semantics, not the AMD instruction. The expected low half comes from the ISA pseudocode's SAT8 packing; the expected high half is the translator's rule.
  • python -I scripts/run_gpu_tests.py on the RTX 4070 Ti, #338's head against this branch, each with its own runtime build. Both: 257 shaders, 257 translated, 257 pass spirv-val.
    • Native: 197/248 passed, 49 skipped.
    • LEONIDA_W64_EMULATE=1: 229/248 passed, 17 skipped.
    • Every test has the same verdict before and after. The only failures, cs_imgload_tfe and cs_imgload_d16_tfe, fail on #338's head too. They are the pair reported on an RTX 3080 Ti in #338's review.

GPUs tested: NVIDIA GeForce RTX 4070 Ti, driver 620.70.06, Vulkan 1.4.357, CachyOS Linux (kernel 7.3.3), pinned with VK_LOADER_DRIVERS_SELECT=*nvidia* and LEONIDA_VK_DEVICE=4070. llvm-mc 23.1.4, SPIRV-Tools v2026.4.

AI-assisted: yes (Claude Code)

Checklist

  • Based on #338's head (6446e3ce7) plus main 1c93c8697, merged in rather than rebased so #338's commit keeps its SHA. Once #338 lands, the diff is this change only.
  • 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.

🤖 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/508 **Author:** [@milk4sale](https://github.com/milk4sale) **Created:** 11/24/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `shader-satpk-halves` --- ### 📝 Commits (6) - [`6446e3c`](https://github.com/ubiquitarianism/leonida/commit/6446e3ce76483c5c3ba2b539258ab5d80482369e) rdna2spirv: translate v_sat_pk_u8_i16 (SHADER-SATPK-U8) - [`8fd02b4`](https://github.com/ubiquitarianism/leonida/commit/8fd02b447432f35757b8cc2764703d26310d7246) Merge main into shader-satpk-u8 (#338) for the wave64_halves partial-write code of #265 - [`4234449`](https://github.com/ubiquitarianism/leonida/commit/423444931dbe04789601eac5f580bb4d19e7fbf1) wave64_halves: v_sat_pk_u8_i16 keeps its high half (SHADER-SATPK-HALVES) - [`d093c0c`](https://github.com/ubiquitarianism/leonida/commit/d093c0cb8d7f403d8946f17014f841df3f53326b) Merge main into shader-satpk-halves - [`232a2ce`](https://github.com/ubiquitarianism/leonida/commit/232a2ce6da0cc4f4b62631f4085fb3cefa64e879) design.md: the v_sat_pk_u8_i16 high-half keep is the translator's choice (SHADER-SATPK-HALVES) - [`38623a9`](https://github.com/ubiquitarianism/leonida/commit/38623a957c0fc7d32833cb0f7c1d46b72cf539e7) Merge main into shader-satpk-halves ### 📊 Changes **14 files changed** (+439 additions, -5 deletions) <details> <summary>View changed files</summary> 📝 `docs/design.md` (+2 -0) 📝 `docs/fssm_crosscheck.md` (+1 -1) ➕ `runtime/test/shaders/ps_w64_a_sat_pk_hi.asm` (+49 -0) ➕ `runtime/test/shaders/ps_w64_c_sat_pk_hi.asm` (+35 -0) 📝 `runtime/test/shaders/w64_graphics.py` (+23 -0) ➕ `tests/semantic/fixtures/sat_pk_u8_i16.asm` (+16 -0) ➕ `tests/semantic/fixtures/w64_sat_pk_hi.asm` (+23 -0) ➕ `tests/semantic/test_alu_sat_pk_u8_i16.py` (+94 -0) ➕ `tests/semantic/test_wave64_halves_sat_pk.py` (+149 -0) 📝 `tests/test_f16_op_sel.py` (+1 -1) 📝 `tests/test_translate.py` (+1 -1) 📝 `tests/test_wave64_halves_fixtures.py` (+10 -0) 📝 `tools/rdna2spirv.py` (+29 -0) 📝 `tools/wave64_halves.py` (+6 -2) </details> ### 📄 Description Claimed in the coordination issue as: [SHADER-SATPK-HALVES](https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7123523547) Depends on: #338 ### What and why #265 added `v_sat_pk` to `_FULL32_V16_PREFIXES` in `tools/wave64_halves.py`, so `_preserves_dst` treats `v_sat_pk_u8_i16` as a full 32-bit write. `partial_write` also read the op's first type, `u8`, as an 8-bit result. #338 translates the op and writes the two saturated bytes with `write_lo16`, which keeps the high half in the `_e32`, `_e64` and DPP forms. With both merged, a high half that depends on the lane lost its taint, and a wave64 VS/PS/GS passed as tier A, or tier B through `readlane-uniform`, although its export changes when the wave is cut into two 32-lane halves. NolanCotter reported this in #14. This change removes `v_sat_pk` from the tuple, so the op falls to the `_i16` rule, and makes `partial_write` say partial for it. Per encoding: - `_e32` (VOP1 0x62), `_e64` (VOP3 0x1e2) and DPP keep the high half. - SDWA keeps the rest only with a `BYTE`/`WORD` `dst_sel` and `UNUSED_PRESERVE`; `dst_sel:DWORD`, `UNUSED_PAD` and `UNUSED_SEXT` write the whole register. This was already right. - llvm-mc 23.1.4 rejects `op_sel` on the `_e64` form for gfx1030. References. Neither compiler says the high half is kept on GFX10, and the cited references don't either: - Mesa ACO's `instr_is_16bit` is false for the op before GFX11. It is not in the list, and `can_use_opsel` falls through to `get_gfx11_true16_mask`, which lists it next to `v_cvt_f16_f32` for GFX11+ only (`aco_ir.cpp`, Mesa `99abc485`). - LLVM's `VOP1Inst_t16` is the plain VOP1 instruction on GFX10, with the true16 forms GFX11+ only. `GCNSubtarget::zeroesHigh16BitsOfDest` does not list the op (LLVM `e2b0a1e1`). The rule here follows what the translator emits. If RDNA2 turns out to zero the high half, calling the op partial is still the safe side: it costs tier A at most, never exactness. The RDNA2 behaviour is not measured. The contract row in `docs/design.md` says so. #338's own `v_sat_pk_u8_i16` row cited ACO `instr_is_16bit` for the kept high half, which the halves row contradicts (review on this PR). This branch rewords that row: the keep is the translator's choice (`write_lo16`), not measured on RDNA2, with a pointer to the halves row's references. If #338 rewords the row first, take #338's wording when merging. #338's translator comment and the `test_alu_sat_pk_u8_i16.py` docstring cite ACO the same way; they are left to #338, where this was raised. The halves analysis runs only for wave64 VS/PS/GS, never for compute or under `--wave64-emulate` (`halves_analysis` in `rdna2spirv.py`). So the GPU fixtures are `ps_w64_*` ones run by `w64_graphics.py`, not `cs_*`: - `ps_w64_a_sat_pk_hi`, tier A: the four encodings that keep the high half, a different high half per pixel, and both halves of SRC0 saturating below 0 and above 255 across the target. Every word is a function of the pixel, so a 32-only GPU checks all of them. - `ps_w64_c_sat_pk_hi`, tier C: the high half is the lane id. It is pinned to tier C, `lane-id`, in `tests/test_wave64_halves_fixtures.py`. On a GPU it needs both subgroup sizes, or `W64G_REF`. ### Tested - `tests/semantic/test_wave64_halves_sat_pk.py` with the hand-written `tests/semantic/fixtures/w64_sat_pk_hi.asm`: 5 OK. It runs on the strict wave interpreter as 64 lanes and as two waves of 32, covers every encoding and the `readlane-uniform` case, and checks `operands()` and `partial_write` per encoding. - On #338's head (`6446e3ce7`): 12 subtests fail. That head predates #265, so it has no partial-destination handling at all. - On #338 plus `main` without this change: 9 fail (e32/e64/DPP tier A instead of C, readlane tier B instead of C). - `python -I scripts/run_semantic_tests.py tests/semantic`: 467 files, 6114 tests, 0 failed (70 s, 24 jobs). - `python -m pytest tests/test_wave64_halves_fixtures.py tests/test_w64_graphics_args.py tests/test_w64_graphics_probe.py tests/test_w64_graphics_reference.py`: 22 passed. Without the fix, `test_fixtures_are_classified_as_their_headers_say` fails: `ps_w64_c_sat_pk_hi` is tier A instead of C. - `tests/test_design_contract_rows.py`, `tests/test_docs_design_rows.py`, `tests/test_text_write_line_endings.py` and `tests/test_semantic_translator_use.py` pass. So do `python -m compileall -q make_game.py tools tests` and `python -I scripts/check_no_game_data.py` on every added or changed file. - After the row rewording (`232a2ce6d`, docs only): the four tests above, `tests/test_wave64_halves_fixtures.py` and the two `sat_pk` semantic test files pass again, and `check_no_game_data.py docs/design.md` exits 0. - `w64_graphics.py` on the RTX 4070 Ti: `ps_w64_a_sat_pk_hi` A ok, `ps_w64_c_sat_pk_hi` C SKIP (32 is the only fragment subgroup size). The verdicts are the same without the fix: a 32-only GPU cannot see the classification, so the tests above catch it. NVIDIA runs the translated SPIR-V, so this confirms the translator's semantics, not the AMD instruction. The expected low half comes from the ISA pseudocode's SAT8 packing; the expected high half is the translator's rule. - `python -I scripts/run_gpu_tests.py` on the RTX 4070 Ti, #338's head against this branch, each with its own runtime build. Both: 257 shaders, 257 translated, 257 pass spirv-val. - Native: 197/248 passed, 49 skipped. - `LEONIDA_W64_EMULATE=1`: 229/248 passed, 17 skipped. - Every test has the same verdict before and after. The only failures, `cs_imgload_tfe` and `cs_imgload_d16_tfe`, fail on #338's head too. They are the pair reported on an RTX 3080 Ti in #338's review. GPUs tested: NVIDIA GeForce RTX 4070 Ti, driver 620.70.06, Vulkan 1.4.357, CachyOS Linux (kernel 7.3.3), pinned with `VK_LOADER_DRIVERS_SELECT=*nvidia*` and `LEONIDA_VK_DEVICE=4070`. llvm-mc 23.1.4, SPIRV-Tools v2026.4. AI-assisted: yes (Claude Code) ### Checklist - [x] Based on #338's head (`6446e3ce7`) plus `main` `1c93c8697`, merged in rather than rebased so #338's commit keeps its SHA. Once #338 lands, the diff is this change only. - [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. 🤖 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>
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#556
No description provided.