rdna2spirv: treat VOP3P v_dot2_f32_f16 clamp as hardware no-op (SHADER-DOT2-F32-F16-CLAMP) #410

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

@⁠tahffo68hk-hash on GitHub · 2026-11-24 04:46 UTC · original
tahffo68hk-hash:fix/shader-dot2-f32-f16-clamp → main · +23 −4 · 3 files · 1 commits · open

Claimed in the coordination issue as: SHADER-DOT2-F32-F16-CLAMP

Problem

tools/rdna2spirv.py applied clamp_mods ([0.0, 1.0] saturation) when VOP3P v_dot2_f32_f16 had the clamp modifier set. As noted in docs/design.md, v_dot2_f32_f16 had not previously been hardware-measured on RDNA2.

Measured natively on AMD RDNA2 (gfx1036 via tools/hw_oracle) across all four ieee / dx10_clamp / denorm32 / denorm16_64 MODE combinations: the VOP3P clamp bit on v_dot2_f32_f16 is a hardware no-op:

  • 1.0*1.0 + 1.0*1.0 + 1.0 with clamp -> 0x40400000 (+3.0f), whereas the translator returned 0x3f800000 (1.0f).
  • -1.0*1.0 + -1.0*1.0 + -1.0 with clamp -> 0xc0400000 (-3.0f), whereas the translator returned 0x00000000 (0.0f).
  • +inf with clamp -> 0x7f800000; NaN with clamp -> 0x7fc00000.

Fix

  • Do not apply clamp_mods on VOP3P v_dot2_f32_f16 in tools/rdna2spirv.py.
  • Update tests/semantic/test_alu_dot_complete.py to match the hardware-measured no-op behavior and add explicit +3.0f / -3.0f / +inf regression assertions.
  • Record the hardware-measured result in docs/design.md.

Verification

  • CPU semantic tests: python -I tests/semantic/test_alu_dot_complete.py -> OK.
  • Hardware differential verification (Native AMD RDNA2 vs. Translated Vulkan + spirv-val):
    • Native reference: AMD GFX1036 (RDNA2) via tools/hw_oracle -> 4/4 dwords across +3.0f, -3.0f, +inf, and op_sel+neg_lo+clamp (verified across all 4 MODE combinations).
    • 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-DOT2-F32-F16-CLAMP

问题描述

tools/rdna2spirv.py 此前对带有 clamp 的 VOP3P 指令 v_dot2_f32_f16 施加了 [0.0, 1.0] 截断(docs/design.md 注明此前尚未在 RDNA2 硬件实测)。

经原生 AMD RDNA2(gfx1036)在全部 4 种 ieee / dx10_clamp / denorm MODE 组合下实测确认:VOP3P v_dot2_f32_f16 的 clamp 位为硬件空操作(+3.0f 保持 0x40400000、-3.0f 保持 0xc0400000、+inf 保持 0x7f800000、NaN 保持 0x7fc00000)。

修复方案

  • 在 tools/rdna2spirv.py 中对 VOP3P v_dot2_f32_f16 不再施加 clamp_mods。
  • 更新 tests/semantic/test_alu_dot_complete.py 并新增 +3.0f / -3.0f / +inf 回归用例。
  • 在 docs/design.md 契约表中记录硬件实测结果。

验证结果

  • CPU 语义测试:tests/semantic/test_alu_dot_complete.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:46 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/410) `tahffo68hk-hash:fix/shader-dot2-f32-f16-clamp` → `main` · +23 −4 · 3 files · 1 commits · open Claimed in the coordination issue as: `SHADER-DOT2-F32-F16-CLAMP` ## Problem `tools/rdna2spirv.py` applied `clamp_mods` (`[0.0, 1.0]` saturation) when VOP3P `v_dot2_f32_f16` had the `clamp` modifier set. As noted in `docs/design.md`, `v_dot2_f32_f16` had not previously been hardware-measured on RDNA2. Measured natively on AMD RDNA2 (`gfx1036` via `tools/hw_oracle`) across all four `ieee` / `dx10_clamp` / `denorm32` / `denorm16_64` MODE combinations: the VOP3P `clamp` bit on `v_dot2_f32_f16` is a **hardware no-op**: - `1.0*1.0 + 1.0*1.0 + 1.0` with `clamp` -> `0x40400000` (`+3.0f`), whereas the translator returned `0x3f800000` (`1.0f`). - `-1.0*1.0 + -1.0*1.0 + -1.0` with `clamp` -> `0xc0400000` (`-3.0f`), whereas the translator returned `0x00000000` (`0.0f`). - `+inf` with `clamp` -> `0x7f800000`; `NaN` with `clamp` -> `0x7fc00000`. ## Fix - Do not apply `clamp_mods` on VOP3P `v_dot2_f32_f16` in `tools/rdna2spirv.py`. - Update `tests/semantic/test_alu_dot_complete.py` to match the hardware-measured no-op behavior and add explicit `+3.0f` / `-3.0f` / `+inf` regression assertions. - Record the hardware-measured result in `docs/design.md`. ## Verification - **CPU semantic tests**: `python -I tests/semantic/test_alu_dot_complete.py` -> OK. - **Hardware differential verification (Native AMD RDNA2 vs. Translated Vulkan + `spirv-val`)**: - Native reference: AMD GFX1036 (RDNA2) via `tools/hw_oracle` -> 4/4 dwords across `+3.0f`, `-3.0f`, `+inf`, and `op_sel`+`neg_lo`+`clamp` (verified across all 4 MODE combinations). - 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-DOT2-F32-F16-CLAMP` ## 问题描述 `tools/rdna2spirv.py` 此前对带有 `clamp` 的 VOP3P 指令 `v_dot2_f32_f16` 施加了 `[0.0, 1.0]` 截断(`docs/design.md` 注明此前尚未在 RDNA2 硬件实测)。 经原生 AMD RDNA2(`gfx1036`)在全部 4 种 `ieee` / `dx10_clamp` / `denorm` MODE 组合下实测确认:VOP3P `v_dot2_f32_f16` 的 `clamp` 位为**硬件空操作**(`+3.0f` 保持 `0x40400000`、`-3.0f` 保持 `0xc0400000`、`+inf` 保持 `0x7f800000`、`NaN` 保持 `0x7fc00000`)。 ## 修复方案 - 在 `tools/rdna2spirv.py` 中对 VOP3P `v_dot2_f32_f16` 不再施加 `clamp_mods`。 - 更新 `tests/semantic/test_alu_dot_complete.py` 并新增 `+3.0f` / `-3.0f` / `+inf` 回归用例。 - 在 `docs/design.md` 契约表中记录硬件实测结果。 ## 验证结果 - CPU 语义测试:`tests/semantic/test_alu_dot_complete.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:58:37 +00:00
Author
Owner

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

Code and test look right, and test_alu_dot_complete.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). AI-assisted review.

**@⁠Oliwettoo** on GitHub · 2026-11-24 10:36 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/410#issuecomment-7129007466) Code and test look right, and `test_alu_dot_complete.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). AI-assisted review.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

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

Merge

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