rdna2spirv: forward DPP src0 neg/abs to op readers instead of eager 32-bit modify (SHADER-DPP-F16-AND-SIGN-MODS) #2362

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

@⁠ShotTechOp on GitHub · 2026-11-26 15:30 UTC · original
ShotTechOp:fix/dpp-f16-and-sign-mods → main · +193 −2 · 3 files · 1 commits · open

Item ID: SHADER-DPP-F16-AND-SIGN-MODS

Summary

Fixes Gen.dpp_insn() in tools/rdna2spirv.py so src0's neg/abs modifiers are forwarded on the post-select ssa operand instead of eagerly applying 32-bit float Gen.modify(src0, src) (bit 31 FAbs/OpFNegate) before dispatching to _insn():

  1. All 16-bit float DPP ops (v_add_f16_dpp, v_sub_f16_dpp, v_subrev_f16_dpp, v_mul_f16_dpp, v_min_f16_dpp, v_max_f16_dpp, v_fmac_f16_dpp, v_cvt_f32_f16_dpp, v_cmp_*_f16_dpp, etc.): previously Gen.modify() cleared/flipped bit 31 (the unused high half) and stripped neg/abs, so -v1 and |v1| were completely ignored on the f16 low half (bit 15), and bound_ctrl:1 with -v1 produced +0.0h instead of -0.0h. Forwarding neg/abs lets f16_in / f16_in_bits / modify_f / cmp_class apply them to bit 15 after the invalid-lane zero select.
  2. Sign-bit-move / sNaN-preserving f32 DPP ops (v_cndmask_b32_dpp, v_min_f32_dpp, v_max_f32_dpp, v_cmp_class_f32_dpp): previously eager Gen.modify() emitted FAbs/OpFNegate (which can quiet sNaNs and flush denormals) before those ops ran their raw integer bit-31 sign-move paths (src_u_sign_mods / src_f_sign_mods / cmp_class).
  3. Preserves HW-DPP-NEG-INVALID-LANE (test_dpp_bound_ctrl_modifiers.py): modifiers still apply after OpSelect %uint %src_ok %shuffled %c0, so v_mov_b32_dpp v2, -v1 ... bound_ctrl:1 still produces -0.0f (0x80000000) with OpBitcast %float + FAbs/OpFNegate on the select result.

Updates the DPP contract row in docs/design.md and adds tests/semantic/test_dpp_f16_mods.py.

Verification

  • AI-assisted: yes
  • Environment: Windows 11, Python 3.12.10 (CPU semantic interpreter spirv_mini_interp & spirv_wave_interp; no local GPU/Vulkan/spirv-val installed)
  • GREEN checks:
    • python -I tests/semantic/test_dpp_f16_mods.py -v -> 4/4 OK (wave32 & --wave64-emulate)
    • python -I tests/semantic/test_dpp_bound_ctrl_modifiers.py -> 2/2 OK
    • python -I tests/semantic/test_dpp_compare.py -> 9/9 OK (2 skipped)
    • python -I tests/semantic/test_dpp_eager_subgroup.py -> 8/8 OK
    • python -I tests/test_text_write_line_endings.py -> 3/3 OK
    • python -m compileall -q tools/rdna2spirv.py tests/semantic/test_dpp_f16_mods.py -> exit 0
    • python -I scripts/check_no_game_data.py tools/rdna2spirv.py tests/semantic/test_dpp_f16_mods.py docs/design.md -> exit 0
    • git diff --check -> clean
  • RED control against origin/main (tools/ extracted from origin/main):
    • tests/semantic/test_dpp_f16_mods.py fails 4/4 tests (v_add_f16_dpp/v_mul_f16_dpp ignore f16 -/| |, v_cvt_f32_f16_dpp yields +0.0f instead of -0.0f, v_min_f16_dpp yields +1.0h instead of -3.0h, and v_cndmask_b32_dpp/v_cmp_class_f32_dpp emit OpFNegate).
**@⁠ShotTechOp** on GitHub · 2026-11-26 15:30 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2362) `ShotTechOp:fix/dpp-f16-and-sign-mods` → `main` · +193 −2 · 3 files · 1 commits · open Item ID: `SHADER-DPP-F16-AND-SIGN-MODS` ## Summary Fixes `Gen.dpp_insn()` in `tools/rdna2spirv.py` so `src0`'s `neg`/`abs` modifiers are forwarded on the post-select `ssa` operand instead of eagerly applying 32-bit float `Gen.modify(src0, src)` (bit 31 `FAbs`/`OpFNegate`) before dispatching to `_insn()`: 1. **All 16-bit float DPP ops (`v_add_f16_dpp`, `v_sub_f16_dpp`, `v_subrev_f16_dpp`, `v_mul_f16_dpp`, `v_min_f16_dpp`, `v_max_f16_dpp`, `v_fmac_f16_dpp`, `v_cvt_f32_f16_dpp`, `v_cmp_*_f16_dpp`, etc.)**: previously `Gen.modify()` cleared/flipped **bit 31** (the unused high half) and stripped `neg`/`abs`, so `-v1` and `|v1|` were completely ignored on the f16 low half (bit 15), and `bound_ctrl:1` with `-v1` produced `+0.0h` instead of `-0.0h`. Forwarding `neg`/`abs` lets `f16_in` / `f16_in_bits` / `modify_f` / `cmp_class` apply them to bit 15 after the invalid-lane zero select. 2. **Sign-bit-move / sNaN-preserving f32 DPP ops (`v_cndmask_b32_dpp`, `v_min_f32_dpp`, `v_max_f32_dpp`, `v_cmp_class_f32_dpp`)**: previously eager `Gen.modify()` emitted `FAbs`/`OpFNegate` (which can quiet sNaNs and flush denormals) before those ops ran their raw integer bit-31 sign-move paths (`src_u_sign_mods` / `src_f_sign_mods` / `cmp_class`). 3. **Preserves `HW-DPP-NEG-INVALID-LANE` (`test_dpp_bound_ctrl_modifiers.py`)**: modifiers still apply **after** `OpSelect %uint %src_ok %shuffled %c0`, so `v_mov_b32_dpp v2, -v1 ... bound_ctrl:1` still produces `-0.0f` (`0x80000000`) with `OpBitcast %float` + `FAbs`/`OpFNegate` on the select result. Updates the DPP contract row in `docs/design.md` and adds `tests/semantic/test_dpp_f16_mods.py`. ## Verification - **AI-assisted**: yes - **Environment**: Windows 11, Python 3.12.10 (CPU semantic interpreter `spirv_mini_interp` & `spirv_wave_interp`; no local GPU/Vulkan/`spirv-val` installed) - **GREEN checks**: - `python -I tests/semantic/test_dpp_f16_mods.py -v` -> 4/4 OK (wave32 & `--wave64-emulate`) - `python -I tests/semantic/test_dpp_bound_ctrl_modifiers.py` -> 2/2 OK - `python -I tests/semantic/test_dpp_compare.py` -> 9/9 OK (2 skipped) - `python -I tests/semantic/test_dpp_eager_subgroup.py` -> 8/8 OK - `python -I tests/test_text_write_line_endings.py` -> 3/3 OK - `python -m compileall -q tools/rdna2spirv.py tests/semantic/test_dpp_f16_mods.py` -> exit 0 - `python -I scripts/check_no_game_data.py tools/rdna2spirv.py tests/semantic/test_dpp_f16_mods.py docs/design.md` -> exit 0 - `git diff --check` -> clean - **RED control against `origin/main` (`tools/` extracted from `origin/main`)**: - `tests/semantic/test_dpp_f16_mods.py` fails 4/4 tests (`v_add_f16_dpp`/`v_mul_f16_dpp` ignore f16 `-`/`| |`, `v_cvt_f32_f16_dpp` yields `+0.0f` instead of `-0.0f`, `v_min_f16_dpp` yields `+1.0h` instead of `-3.0h`, and `v_cndmask_b32_dpp`/`v_cmp_class_f32_dpp` emit `OpFNegate`).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 15:33:56 +00:00
Author
Owner

@⁠lixonik on GitHub · 2026-11-26 15:35 UTC · original · reviewed

Windows 11: 21 DPP semantic tests passed, including the new f16 modifier and sign-bit cases. Two existing assembly checks skipped because AMDGPU llvm-mc was unavailable in this test environment. No correctness findings from the semantic runs.

AI-assisted.

**@⁠lixonik** on GitHub · 2026-11-26 15:35 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2362#pullrequestreview-6076850330) · **reviewed** Windows 11: 21 DPP semantic tests passed, including the new f16 modifier and sign-bit cases. Two existing assembly checks skipped because AMDGPU `llvm-mc` was unavailable in this test environment. No correctness findings from the semantic runs. AI-assisted.
Author
Owner

@⁠ecox982745 on GitHub · 2026-11-26 16:18 UTC · original

I compared the translator at cf622ce9c2 with its parent fbf100b1b1 using synthetic compute shaders on a physical RTX 4090, Windows 11, NVIDIA 616.64. A dispatch passed only if every output word and the trailing buffer sentinel matched the CPU reference.

Shader mode Parent PR head
Native wave32 14/48 48/48
Wave64 emulated on 32-lane subgroups 14/48 48/48

The quad-shuffle cases cover half-precision add, multiply, minimum and compare with negation, absolute value, both modifiers, and an unmodified control. The row-shift cases check both settings of bound_ctrl. At the first lane of a row, v_cvt_f32_f16_dpp with negation and bound_ctrl:1 returned positive zero on the parent and the expected negative zero (0x80000000) on the PR. The raw 32-bit select and classification cases also checked signaling and quiet NaN inputs, payload bits and signed zeros.

All 18 generated modules per revision passed spirv-val --target-env vulkan1.2. Vulkan validation was enabled throughout. The four focused DPP test files also passed all 23 tests with LLVM available.

**@⁠ecox982745** on GitHub · 2026-11-26 16:18 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2362#issuecomment-7197476395) I compared the translator at `cf622ce9c2` with its parent `fbf100b1b1` using synthetic compute shaders on a physical RTX 4090, Windows 11, NVIDIA 616.64. A dispatch passed only if every output word and the trailing buffer sentinel matched the CPU reference. | Shader mode | Parent | PR head | | --- | ---: | ---: | | Native wave32 | 14/48 | 48/48 | | Wave64 emulated on 32-lane subgroups | 14/48 | 48/48 | The quad-shuffle cases cover half-precision add, multiply, minimum and compare with negation, absolute value, both modifiers, and an unmodified control. The row-shift cases check both settings of `bound_ctrl`. At the first lane of a row, `v_cvt_f32_f16_dpp` with negation and `bound_ctrl:1` returned positive zero on the parent and the expected negative zero (`0x80000000`) on the PR. The raw 32-bit select and classification cases also checked signaling and quiet NaN inputs, payload bits and signed zeros. All 18 generated modules per revision passed `spirv-val --target-env vulkan1.2`. Vulkan validation was enabled throughout. The four focused DPP test files also passed all 23 tests with LLVM available.
Author
Owner

@⁠wavehs on GitHub · 2026-11-26 18:19 UTC · original · reviewed

macOS arm64 check of #2362 (SHADER-DPP-F16-AND-SIGN-MODS). Translator-only plus one semantic test, so it runs here; the GPU part is MoltenVK/KosmicKrisp.

Tested head cf622ce9c merged onto main bdbc7e923 as merge f181a4193 (clean; branch 21 commits behind, git merge-tree clean).

Environment: Apple M3 Pro, arm64 (subgroups 4..32), macOS 27.2.1, CPython 3.15.2, SPIRV-Tools v2026.4, llvm-mc 23.1.5, MoltenVK 1.4.0; KosmicKrisp and lavapipe = Mesa 26.3.0.

The new test passes, and its control bites on values

  • python -I tests/semantic/test_dpp_f16_mods.py: Ran 4 tests ... OK at the head and after merging onto bdbc7e923.
  • Negative control (test kept, tools/rdna2spirv.py put back to main's): FAILED (failures=4), all four tests. Unlike a structural test, these fail on the computed words: test_v_add_f16_dpp_neg_and_abs_wave32_and_emulate lane 0 2882387968 != 2882356224; test_v_cvt_f32_f16_dpp_neg_and_bound_ctrl_zero lane 0 0 != 0x80000000; test_v_min_f16_and_v_cmp_gt_f16_dpp_neg [0x3C00 ...] != [0xC200 ...]; test_v_cndmask_b32_and_cmp_class_f32_dpp_preserve_sign_bit_moves finds OpFNegate in a path that must keep raw sign bits. The old translator's behaviour the test describes is what I measured on main.
  • The changed path does not lose modifiers on the readers it is not aimed at: I translated and ran v_mov_b32_dpp -v1, v_add_f32_dpp -v1, 0.5 and v_max_f32_dpp |v1|, 0 (quad_perm, full masks, bound_ctrl:1) with the head and with main's translator through the same interpreter. v_mov_b32 reads through src_u -> modify, so forwarding the flag still applies it: the outputs were identical (0xbf800000, 0xbf000000, 0x3f800000 in every lane). Those three ops are not in the new test.

No regressions

  • Semantic suite: 500 files / 6,367 tests / 0 failed at main bdbc7e923; 501 files / 6,371 tests / 0 failed at the merge (+1 file, +4 tests).
  • GPU fixtures (268): MoltenVK 195 PASS / 3 FAIL / 70 SKIP, KosmicKrisp 190 / 5 / 73, identical at main and the merge after normalising the per-run temp directory. Same pre-existing failures (cs_fma_fused, cs_imgatomic_ext, ps_ssharp on MV; cs_bvh, cs_bvh32, cs_imgatomic_ext, ps_cndmask_sign_mods, ps_valu16_mad_sel on KK).

Findings

  1. The rule has no GPU fixture: none of cs_dpp.asm, cs_dpp8.asm, cs_dpp_bank.asm, cs_dpp_bound.asm, cs_dpp_cmp.asm, cs_dpp_fi.asm, cs_dpp_mask.asm, cs_dpp_ops.asm, cs_dpp_row.asm, cs_dpp_w64.asm uses neg/abs on a _dpp op, and the doc row says "not yet GPU-verified". So the f16 sign-bit behaviour (and the sNaN-preserving cndmask/class path) rests on spirv_mini_interp only. A cs_dpp_f16_mods.asm with the four cases of the new test (one word per lane stored) would settle it on any GPU, the same way cs_dpp_cmp.asm does for compares.
  2. Coverage narrows to the ops in the test (v_add_f16, v_mul_f16, v_min_f16, v_cmp_gt_f16, v_cvt_f32_f16, v_cndmask_b32, v_cmp_class_f32). The mechanism is shared, and I checked v_mov_b32/f32 add/max by hand as above, so this is a note rather than a hole; adding one f32 op to the test (v_add_f32_dpp -v1) would pin that forwarding still goes through modify for the 32-bit readers that have no f16 half to fix.

python -I scripts/check_no_game_data.py on the changed files: clean. git diff --check: clean.

No game files. AI-assisted.

**@⁠wavehs** on GitHub · 2026-11-26 18:19 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2362#pullrequestreview-6078896263) · **reviewed** **macOS arm64 check of #2362** (SHADER-DPP-F16-AND-SIGN-MODS). Translator-only plus one semantic test, so it runs here; the GPU part is MoltenVK/KosmicKrisp. Tested head `cf622ce9c` merged onto `main` `bdbc7e923` as merge `f181a4193` (clean; branch 21 commits behind, `git merge-tree` clean). Environment: Apple M3 Pro, arm64 (subgroups 4..32), macOS 27.2.1, CPython 3.15.2, SPIRV-Tools v2026.4, llvm-mc 23.1.5, MoltenVK 1.4.0; KosmicKrisp and lavapipe = Mesa 26.3.0. **The new test passes, and its control bites on values** - `python -I tests/semantic/test_dpp_f16_mods.py`: `Ran 4 tests ... OK` at the head and after merging onto `bdbc7e923`. - Negative control (test kept, `tools/rdna2spirv.py` put back to `main`'s): `FAILED (failures=4)`, all four tests. Unlike a structural test, these fail on the computed words: `test_v_add_f16_dpp_neg_and_abs_wave32_and_emulate` lane 0 `2882387968 != 2882356224`; `test_v_cvt_f32_f16_dpp_neg_and_bound_ctrl_zero` lane 0 `0 != 0x80000000`; `test_v_min_f16_and_v_cmp_gt_f16_dpp_neg` `[0x3C00 ...] != [0xC200 ...]`; `test_v_cndmask_b32_and_cmp_class_f32_dpp_preserve_sign_bit_moves` finds `OpFNegate` in a path that must keep raw sign bits. The old translator's behaviour the test describes is what I measured on `main`. - The changed path does not lose modifiers on the readers it is not aimed at: I translated and ran `v_mov_b32_dpp -v1`, `v_add_f32_dpp -v1, 0.5` and `v_max_f32_dpp |v1|, 0` (quad_perm, full masks, `bound_ctrl:1`) with the head and with `main`'s translator through the same interpreter. `v_mov_b32` reads through `src_u` -> `modify`, so forwarding the flag still applies it: the outputs were identical (`0xbf800000`, `0xbf000000`, `0x3f800000` in every lane). Those three ops are not in the new test. **No regressions** - Semantic suite: 500 files / 6,367 tests / 0 failed at `main` `bdbc7e923`; 501 files / 6,371 tests / 0 failed at the merge (+1 file, +4 tests). - GPU fixtures (268): MoltenVK 195 PASS / 3 FAIL / 70 SKIP, KosmicKrisp 190 / 5 / 73, identical at `main` and the merge after normalising the per-run temp directory. Same pre-existing failures (`cs_fma_fused`, `cs_imgatomic_ext`, `ps_ssharp` on MV; `cs_bvh`, `cs_bvh32`, `cs_imgatomic_ext`, `ps_cndmask_sign_mods`, `ps_valu16_mad_sel` on KK). **Findings** 1. The rule has no GPU fixture: none of `cs_dpp.asm`, `cs_dpp8.asm`, `cs_dpp_bank.asm`, `cs_dpp_bound.asm`, `cs_dpp_cmp.asm`, `cs_dpp_fi.asm`, `cs_dpp_mask.asm`, `cs_dpp_ops.asm`, `cs_dpp_row.asm`, `cs_dpp_w64.asm` uses `neg`/`abs` on a `_dpp` op, and the doc row says "not yet GPU-verified". So the f16 sign-bit behaviour (and the sNaN-preserving cndmask/class path) rests on `spirv_mini_interp` only. A `cs_dpp_f16_mods.asm` with the four cases of the new test (one word per lane stored) would settle it on any GPU, the same way `cs_dpp_cmp.asm` does for compares. 2. Coverage narrows to the ops in the test (`v_add_f16`, `v_mul_f16`, `v_min_f16`, `v_cmp_gt_f16`, `v_cvt_f32_f16`, `v_cndmask_b32`, `v_cmp_class_f32`). The mechanism is shared, and I checked `v_mov_b32`/f32 add/max by hand as above, so this is a note rather than a hole; adding one f32 op to the test (`v_add_f32_dpp -v1`) would pin that forwarding still goes through `modify` for the 32-bit readers that have no f16 half to fix. `python -I scripts/check_no_game_data.py` on the changed files: clean. `git diff --check`: clean. No game files. AI-assisted.
This pull request has changes conflicting with the target branch.
  • docs/design.md
  • tools/rdna2spirv.py
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/2362/head:github-bot/gh-2362'
git switch 'github-bot/gh-2362'

Merge

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