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

Closed
tahffo68hk-hash wants to merge 1 commit from upstream-pr/422 into main
tahffo68hk-hash commented 2026-11-24 04:57:57 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by tahffo68hk-hash on 2026-11-24T04:57:57Z.


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)。
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5466365378 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/422). Originally posted by [tahffo68hk-hash](https://github.com/tahffo68hk-hash) on 2026-11-24T04:57:57Z. --- 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>
Oliwettoo commented 2026-11-24 10:36:36 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Oliwettoo on 2026-11-24T10:36:36Z.


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.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7129008168 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/422#issuecomment-7129008168). Originally posted by [Oliwettoo](https://github.com/Oliwettoo) on 2026-11-24T10:36:36Z. --- 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.
MoonEyes commented 2026-11-27 23:19:37 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-27T23:19:37Z.


Hi @tahffo68hk-hash, thanks for this pull request. It currently conflicts with main (conflicting file(s): docs/design.md), so it carries the needs rebase label. CONTRIBUTING.md asks authors to rebase their branch on main; once it merges cleanly the label goes within the hour, and reviews start with the pull requests that do. Could you update the branch when you have a moment? If you no longer plan to continue with it, please say so here.

AI-assisted (Claude Code, Claude Opus 5.5).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7230053687 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/422#issuecomment-7230053687). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-27T23:19:37Z. --- Hi @tahffo68hk-hash, thanks for this pull request. It currently conflicts with `main` (conflicting file(s): `docs/design.md`), so it carries the `needs rebase` label. CONTRIBUTING.md asks authors to rebase their branch on `main`; once it merges cleanly the label goes within the hour, and reviews start with the pull requests that do. Could you update the branch when you have a moment? If you no longer plan to continue with it, please say so here. AI-assisted (Claude Code, Claude Opus 5.5).
aslan2142 commented 2026-12-01 11:50:59 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T11:50:59Z.

Review: CHANGES_REQUESTED


Reviewed against current main: the VOP3P packed 16-bit shift clamp no-op change in tools/rdna2spirv.py and test look solid, but this branch conflicts with main in docs/design.md and has failing CI. Please rebase onto current main so CI runs cleanly.

(AI-assisted review.)

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6130676071 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/422#pullrequestreview-6130676071). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-01T11:50:59Z. **Review:** CHANGES_REQUESTED --- Reviewed against current `main`: the VOP3P packed 16-bit shift clamp no-op change in `tools/rdna2spirv.py` and test look solid, but this branch conflicts with `main` in `docs/design.md` and has failing CI. Please rebase onto current `main` so CI runs cleanly. *(AI-assisted review.)*
aslan2142 commented 2026-12-01 16:30:10 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T16:30:10Z.


Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (d3d12/) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, d3d12/, or general docs), please feel free to reopen it.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7317712765 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/422#issuecomment-7317712765). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-01T16:30:10Z. --- Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (`d3d12/`) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, `d3d12/`, or general docs), please feel free to reopen it.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
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.

Reference
ProjectLeonida/mandy!422
No description provided.