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

Closed
leonida/mandy
tahffo68hk-hash wants to merge 0 commits from fix/shader-pk-shift-clamp into main

Pull request closed

This pull request cannot be reopened because the branch was deleted.

tahffo68hk-hash commented 2026-11-24 04:57:57 +00:00

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)。
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

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.

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

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).

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 reviewed 2026-12-01 11:50:59 +00:00
aslan2142 left a comment
No description provided.
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

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.

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.
Sign in to join this conversation.
No description provided.