rdna2spirv: accept VOP3P clamp as hardware no-op on packed 16-bit shifts (SHADER-PK-SHIFT-CLAMP) #422

Open
github-bot wants to merge 1 commit from github-bot/gh-422 into main AGit
Owner

@⁠tahffo68hk-hash on GitHub · 2026-11-24 04:57 UTC · original
tahffo68hk-hash:fix/shader-pk-shift-clamp → main · +15 −7 · 3 files · 1 commits · open

Claimed in the coordination issue as: SHADER-PK-SHIFT-CLAMP

Problem

tools/rdna2spirv.py rejected v_pk_lshlrev_b16, v_pk_lshrrev_b16, and v_pk_ashrrev_i16 with Unsupported whenever VOP3P clamp was set.

Measured natively on AMD RDNA2 (gfx1036 via tools/hw_oracle): VOP3P clamp is a valid encoding and a hardware no-op on all three packed 16-bit shift instructions (each 16-bit half wraps without saturating, matching v_pk_mul_lo_u16 / v_pk_max_*16 / v_pk_min_*16).

Fix

  • Accept clamp as a hardware no-op on v_pk_lshlrev_b16, v_pk_lshrrev_b16, and v_pk_ashrrev_i16 in tools/rdna2spirv.py.
  • Update tests/semantic/test_valu_pk_shift_b16.py with test_clamp_is_hardware_noop covering all three opcodes.
  • Document the hardware-confirmed rule in docs/design.md.

Verification

  • CPU semantic tests: python -I tests/semantic/test_valu_pk_shift_b16.py -> OK.
  • Hardware differential verification (Native AMD RDNA2 vs. Translated Vulkan + spirv-val):
    • Native reference: AMD GFX1036 (RDNA2) via tools/hw_oracle -> 4 dwords across all 3 opcodes + op_sel/op_sel_hi with clamp.
    • Translated execution: NVIDIA GeForce RTX 5060 Ti (driver 617.42, Windows 11) via vk_compute_test.exe:
      • Wave32: 4/4 exact dwords (spirv-val PASS)
      • Wave64 (--wave64-emulate): 4/4 exact dwords (spirv-val PASS)
  • No game files used (synthetic assembly only).
  • AI-assisted: Yes (Antigravity).
中文翻译

在协调帖 #14 中认领的 ID:SHADER-PK-SHIFT-CLAMP

问题描述

tools/rdna2spirv.py 此前对携带 VOP3P clamp 的 v_pk_lshlrev_b16、v_pk_lshrrev_b16、v_pk_ashrrev_i16 抛出 Unsupported。

经原生 AMD RDNA2(gfx1036)实测确认,VOP3P clamp 在这三条打包 16 位移位指令上为合法编码且属于硬件空操作(各 16 位通道正常回绕不饱和)。

修复方案

  • 在 tools/rdna2spirv.py 中允许上述三条指令携带 clamp(按硬件空操作处理)。
  • 在 tests/semantic/test_valu_pk_shift_b16.py 中补充 test_clamp_is_hardware_noop 回归测试并更新 docs/design.md。

验证结果

  • CPU 语义测试:tests/semantic/test_valu_pk_shift_b16.py 全部通过。
  • 跨架构硬件差分验证(原生 AMD GFX1036 vs 翻译后 NVIDIA RTX 5060 Ti,驱动 617.42):Wave32 4/4 精确一致,Wave64 模拟(--wave64-emulate)4/4 精确一致,spirv-val 全部通过。
  • 仅使用手写合成汇编,无游戏文件。
  • AI 辅助:是(Antigravity)。
**@⁠tahffo68hk-hash** on GitHub · 2026-11-24 04:57 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/422) `tahffo68hk-hash:fix/shader-pk-shift-clamp` → `main` · +15 −7 · 3 files · 1 commits · open Claimed in the coordination issue as: `SHADER-PK-SHIFT-CLAMP` ## Problem `tools/rdna2spirv.py` rejected `v_pk_lshlrev_b16`, `v_pk_lshrrev_b16`, and `v_pk_ashrrev_i16` with `Unsupported` whenever VOP3P `clamp` was set. Measured natively on AMD RDNA2 (`gfx1036` via `tools/hw_oracle`): VOP3P `clamp` is a valid encoding and a **hardware no-op** on all three packed 16-bit shift instructions (each 16-bit half wraps without saturating, matching `v_pk_mul_lo_u16` / `v_pk_max_*16` / `v_pk_min_*16`). ## Fix - Accept `clamp` as a hardware no-op on `v_pk_lshlrev_b16`, `v_pk_lshrrev_b16`, and `v_pk_ashrrev_i16` in `tools/rdna2spirv.py`. - Update `tests/semantic/test_valu_pk_shift_b16.py` with `test_clamp_is_hardware_noop` covering all three opcodes. - Document the hardware-confirmed rule in `docs/design.md`. ## Verification - **CPU semantic tests**: `python -I tests/semantic/test_valu_pk_shift_b16.py` -> OK. - **Hardware differential verification (Native AMD RDNA2 vs. Translated Vulkan + `spirv-val`)**: - Native reference: AMD GFX1036 (RDNA2) via `tools/hw_oracle` -> 4 dwords across all 3 opcodes + `op_sel`/`op_sel_hi` with `clamp`. - Translated execution: NVIDIA GeForce RTX 5060 Ti (driver 617.42, Windows 11) via `vk_compute_test.exe`: - Wave32: **4/4 exact dwords** (`spirv-val` PASS) - Wave64 (`--wave64-emulate`): **4/4 exact dwords** (`spirv-val` PASS) - No game files used (synthetic assembly only). - AI-assisted: Yes (Antigravity). <details> <summary>中文翻译</summary> 在协调帖 #14 中认领的 ID:`SHADER-PK-SHIFT-CLAMP` ## 问题描述 `tools/rdna2spirv.py` 此前对携带 VOP3P `clamp` 的 `v_pk_lshlrev_b16`、`v_pk_lshrrev_b16`、`v_pk_ashrrev_i16` 抛出 `Unsupported`。 经原生 AMD RDNA2(`gfx1036`)实测确认,VOP3P `clamp` 在这三条打包 16 位移位指令上为合法编码且属于硬件空操作(各 16 位通道正常回绕不饱和)。 ## 修复方案 - 在 `tools/rdna2spirv.py` 中允许上述三条指令携带 `clamp`(按硬件空操作处理)。 - 在 `tests/semantic/test_valu_pk_shift_b16.py` 中补充 `test_clamp_is_hardware_noop` 回归测试并更新 `docs/design.md`。 ## 验证结果 - CPU 语义测试:`tests/semantic/test_valu_pk_shift_b16.py` 全部通过。 - 跨架构硬件差分验证(原生 AMD GFX1036 vs 翻译后 NVIDIA RTX 5060 Ti,驱动 617.42):Wave32 **4/4 精确一致**,Wave64 模拟(`--wave64-emulate`)**4/4 精确一致**,`spirv-val` 全部通过。 - 仅使用手写合成汇编,无游戏文件。 - AI 辅助:是(Antigravity)。 </details>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 08:59:20 +00:00
Author
Owner

@⁠Oliwettoo on GitHub · 2026-11-24 10:36 UTC · original

Code and test look right, and test_valu_pk_shift_b16.py passes with the PR on current main. The measured words are only in the PR text, so nobody can reproduce them: please commit a reproducible gfx103x case (an int_hw_probe.py case, or the tools/hw_oracle .asm plus its raw output), as the maintainer asked on #392/#398 (AGENTS.md: a new rule goes in with how it was confirmed). Merge note: this edits the same 'Integer clamp' row as #392, #398 and #426, and git merge-tree shows it conflicts with all three. AI-assisted review.

**@⁠Oliwettoo** on GitHub · 2026-11-24 10:36 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/422#issuecomment-7129008168) Code and test look right, and `test_valu_pk_shift_b16.py` passes with the PR on current `main`. The measured words are only in the PR text, so nobody can reproduce them: please commit a reproducible gfx103x case (an `int_hw_probe.py` case, or the `tools/hw_oracle` .asm plus its raw output), as the maintainer asked on #392/#398 (AGENTS.md: a new rule goes in with how it was confirmed). Merge note: this edits the same 'Integer clamp' row as #392, #398 and #426, and `git merge-tree` shows it conflicts with all three. AI-assisted review.
This pull request has changes conflicting with the target branch.
  • docs/design.md
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/422/head:github-bot/gh-422'
git switch 'github-bot/gh-422'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-422'
git switch 'github-bot/gh-422'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-422'
git switch 'github-bot/gh-422'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-422'
git switch 'main'
git merge --squash 'github-bot/gh-422'
git switch 'main'
git merge --ff-only 'github-bot/gh-422'
git switch 'main'
git merge 'github-bot/gh-422'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.