[PR #398] rdna2spirv: support VOP3 clamp on v_mad_u64_u32 and v_mad_i64_i32 (SHADER-MAD64-CLAMP) #449

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

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/398
Author: @tahffo68hk-hash
Created: 11/24/2026
Status: 🔄 Open

Base: main ← Head: fix/shader-mad64-clamp


📝 Commits (1)

  • 44f9113 rdna2spirv: support VOP3 clamp saturation on v_mad_u64_u32 and v_mad_i64_i32 (SHADER-MAD64-CLAMP)

📊 Changes

3 files changed (+64 additions, -5 deletions)

View changed files

📝 docs/design.md (+1 -1)
📝 tests/semantic/test_alu_mad64.py (+44 -2)
📝 tools/rdna2spirv.py (+19 -2)

📄 Description

Claimed in the coordination issue as: SHADER-MAD64-CLAMP

Problem

tools/rdna2spirv.py rejected v_mad_u64_u32 and v_mad_i64_i32 with Unsupported whenever VOP3 clamp was set.

On native AMD RDNA2 hardware (gfx1036), VOP3 clamp saturates the 64-bit destination pair v[d:d+1] to 0xFFFFFFFFFFFFFFFF (for v_mad_u64_u32) or [0x8000000000000000, 0x7FFFFFFFFFFFFFFF] (for v_mad_i64_i32), while sdst continues to report the exact bit 64 (unsigned carry out / exact 65-bit sign).

Fix

  • Allow clamp in v_mad_u64_u32 / v_mad_i64_i32 in tools/rdna2spirv.py:
    • Unsigned: saturate (r_lo, r_hi) to (0xFFFFFFFF, 0xFFFFFFFF) when bit64 != 0.
    • Signed: detect 64-bit signed overflow via bit64 != sr (exact 65-bit sign differs from wrapped sign) and saturate to INT64_MIN / INT64_MAX accordingly.
    • Keep sdst reporting the unmodified bit64 lane mask.
  • Add Mad64Tests.test_clamp_saturation_preserves_sdst in tests/semantic/test_alu_mad64.py (directed + randomized cases).
  • Document the hardware-verified rule in docs/design.md.

Verification

  • CPU semantic tests: python -I tests/semantic/test_alu_mad64.py -> all tests OK.
  • Hardware differential verification (Native AMD RDNA2 vs. Translated Vulkan + spirv-val):
    • Native reference: AMD GFX1036 (RDNA2) via tools/hw_oracle -> 12 dwords across u64 overflow/exact-max and i64 positive/negative overflow + sdst bits.
    • Translated execution: NVIDIA GeForce RTX 5060 Ti (driver 617.42, Windows 11) via vk_compute_test.exe:
      • Wave32: 12/12 exact dwords (spirv-val PASS)
      • Wave64 (--wave64-emulate): 12/12 exact dwords (spirv-val PASS)
  • No game files used (synthetic assembly only).
  • AI-assisted: Yes (Antigravity).
中文翻译

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

问题描述

tools/rdna2spirv.py 在 v_mad_u64_u32 与 v_mad_i64_i32 携带 VOP3 clamp 修饰符时直接抛出 Unsupported。

经原生 AMD RDNA2(gfx1036)硬件实测,VOP3 clamp 会将 64 位目标寄存器对 v[d:d+1] 饱和至 0xFFFFFFFFFFFFFFFF(无符号)或 [0x8000000000000000, 0x7FFFFFFFFFFFFFFF](有符号),同时 sdst 仍保持报告真实的第 64 位(无符号进位 / 精确 65 位符号位)。

修复方案

  • 在 tools/rdna2spirv.py 中支持 v_mad_u64_u32 与 v_mad_i64_i32 的 clamp 饱和,同时保留 sdst 原始掩码输出。
  • 在 tests/semantic/test_alu_mad64.py 中新增定向及随机回归测试(test_clamp_saturation_preserves_sdst)。
  • 在 docs/design.md 契约表中记录硬件实测结论。

验证结果

  • CPU 语义测试:tests/semantic/test_alu_mad64.py 全部通过。
  • 跨架构硬件差分验证(原生 AMD GFX1036 vs 翻译后 NVIDIA RTX 5060 Ti,驱动 617.42):Wave32 12/12 精确一致,Wave64 模拟(--wave64-emulate)12/12 精确一致,spirv-val 全部通过。
  • 仅使用手写合成汇编,无游戏文件。
  • AI 辅助:是(Antigravity)。

🔄 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/398 **Author:** [@tahffo68hk-hash](https://github.com/tahffo68hk-hash) **Created:** 11/24/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/shader-mad64-clamp` --- ### 📝 Commits (1) - [`44f9113`](https://github.com/ubiquitarianism/leonida/commit/44f9113e8851b320cc73af944c3fac1a0b12d6b4) rdna2spirv: support VOP3 clamp saturation on v_mad_u64_u32 and v_mad_i64_i32 (SHADER-MAD64-CLAMP) ### 📊 Changes **3 files changed** (+64 additions, -5 deletions) <details> <summary>View changed files</summary> 📝 `docs/design.md` (+1 -1) 📝 `tests/semantic/test_alu_mad64.py` (+44 -2) 📝 `tools/rdna2spirv.py` (+19 -2) </details> ### 📄 Description Claimed in the coordination issue as: `SHADER-MAD64-CLAMP` ## Problem `tools/rdna2spirv.py` rejected `v_mad_u64_u32` and `v_mad_i64_i32` with `Unsupported` whenever VOP3 `clamp` was set. On native AMD RDNA2 hardware (`gfx1036`), VOP3 `clamp` saturates the 64-bit destination pair `v[d:d+1]` to `0xFFFFFFFFFFFFFFFF` (for `v_mad_u64_u32`) or `[0x8000000000000000, 0x7FFFFFFFFFFFFFFF]` (for `v_mad_i64_i32`), while `sdst` continues to report the exact bit 64 (unsigned carry out / exact 65-bit sign). ## Fix - Allow `clamp` in `v_mad_u64_u32` / `v_mad_i64_i32` in `tools/rdna2spirv.py`: - Unsigned: saturate `(r_lo, r_hi)` to `(0xFFFFFFFF, 0xFFFFFFFF)` when `bit64 != 0`. - Signed: detect 64-bit signed overflow via `bit64 != sr` (exact 65-bit sign differs from wrapped sign) and saturate to `INT64_MIN` / `INT64_MAX` accordingly. - Keep `sdst` reporting the unmodified `bit64` lane mask. - Add `Mad64Tests.test_clamp_saturation_preserves_sdst` in `tests/semantic/test_alu_mad64.py` (directed + randomized cases). - Document the hardware-verified rule in `docs/design.md`. ## Verification - **CPU semantic tests**: `python -I tests/semantic/test_alu_mad64.py` -> all tests OK. - **Hardware differential verification (Native AMD RDNA2 vs. Translated Vulkan + `spirv-val`)**: - Native reference: AMD GFX1036 (RDNA2) via `tools/hw_oracle` -> 12 dwords across u64 overflow/exact-max and i64 positive/negative overflow + `sdst` bits. - Translated execution: NVIDIA GeForce RTX 5060 Ti (driver 617.42, Windows 11) via `vk_compute_test.exe`: - Wave32: **12/12 exact dwords** (`spirv-val` PASS) - Wave64 (`--wave64-emulate`): **12/12 exact dwords** (`spirv-val` PASS) - No game files used (synthetic assembly only). - AI-assisted: Yes (Antigravity). <details> <summary>中文翻译</summary> 在协调帖 #14 中认领的 ID:`SHADER-MAD64-CLAMP` ## 问题描述 `tools/rdna2spirv.py` 在 `v_mad_u64_u32` 与 `v_mad_i64_i32` 携带 VOP3 `clamp` 修饰符时直接抛出 `Unsupported`。 经原生 AMD RDNA2(`gfx1036`)硬件实测,VOP3 `clamp` 会将 64 位目标寄存器对 `v[d:d+1]` 饱和至 `0xFFFFFFFFFFFFFFFF`(无符号)或 `[0x8000000000000000, 0x7FFFFFFFFFFFFFFF]`(有符号),同时 `sdst` 仍保持报告真实的第 64 位(无符号进位 / 精确 65 位符号位)。 ## 修复方案 - 在 `tools/rdna2spirv.py` 中支持 `v_mad_u64_u32` 与 `v_mad_i64_i32` 的 `clamp` 饱和,同时保留 `sdst` 原始掩码输出。 - 在 `tests/semantic/test_alu_mad64.py` 中新增定向及随机回归测试(`test_clamp_saturation_preserves_sdst`)。 - 在 `docs/design.md` 契约表中记录硬件实测结论。 ## 验证结果 - CPU 语义测试:`tests/semantic/test_alu_mad64.py` 全部通过。 - 跨架构硬件差分验证(原生 AMD GFX1036 vs 翻译后 NVIDIA RTX 5060 Ti,驱动 617.42):Wave32 **12/12 精确一致**,Wave64 模拟(`--wave64-emulate`)**12/12 精确一致**,`spirv-val` 全部通过。 - 仅使用手写合成汇编,无游戏文件。 - AI 辅助:是(Antigravity)。 </details> --- <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#449
No description provided.