shader: lower clamped integer, carry-out, MAD/SAD, and f16 pack VALU ops #520

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

@⁠Sheffy007 on GitHub · 2026-11-27 23:42 UTC · original
Sheffy007:feat/clamped-integer-and-packed-ops → main · +557 −48 · 4 files · 1 commits · open

Summary

  • Follow RDNA2 ISA CLAMP semantics across VALU operations routed through Lower::write_i, valu16, and packed16 that previously failed as "integer output modifiers" or "modifiers on a 16-bit/packed integer operation" (while leaving non-clamped emission unchanged and keeping omod != 0 and bitwise/shift clamp refused):
    • v_add_nc_i32 and v_sub_nc_i32 (sadd.sat.i32 / ssub.sat.i32 with clamp, wrapping without clamp), v_cvt_pk_u16_u32, v_cvt_pk_i16_i32, and v_mad_i32_i16.
    • v_add_co_u32, v_sub_co_u32, v_subrev_co_u32, v_add_co_ci_u32, v_sub_co_ci_u32, and v_subrev_co_ci_u32 with clamp (saturating vdst at 0xffffffff or 0 while keeping the un-clamped carry/borrow mask in sdst).
    • v_mul_{u32_u24,i32_i24}, v_mad_{u32_u24,i32_i24,u32_u16,i32_i16}, v_mad_{u64_u32,i64_i32}, and v_sad_{u8,hi_u8,u16,u32} / v_msad_u8 with clamp.
    • v_cvt_f16_f32 (opsel == 0, matching valu16), v_cvt_pkrtz_f16_f32 ([0.0, 1.0] float clamp before RTZ conversion), and v_cvt_pknorm_{u16,i16}_f32 / v_cvt_norm_{u16,i16}_f16 with clamp.
    • 16-bit and VOP3P packed v_add_nc_u16, v_sub_nc_u16, v_subrev_nc_u16, v_mul_lo_u16, and v_pk_{add,sub,mad}_{u16,i16} / v_pk_mul_lo_u16 with clamp.

Verification

  • Unit and negative refusal tests in victory_shader::emit::lower::tests and victory_shader::emit::valu_tests
  • Metal GPU value test victory_gpu::native::tests::addr_tests::clamped_integer_carry_mad_sad_and_half_packs_saturate_on_the_gpu (16 boundary/saturation cases on Metal)
  • cargo test -p victory-hle -p victory -p victory-gpu -p victory-metal -p victory-shader -p xtask
  • cargo clippy --workspace --all-targets --target x86_64-pc-windows-gnullvm -- -D warnings
  • cargo clippy --workspace --all-targets --all-features --target x86_64-pc-windows-gnullvm -- -D warnings
  • cargo xtask policy

Closes #519
Refs #4, #258
cc @⁠Olima34

**@⁠Sheffy007** on GitHub · 2026-11-27 23:42 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/516) `Sheffy007:feat/clamped-integer-and-packed-ops` → `main` · +557 −48 · 4 files · 1 commits · open ## Summary - Follow RDNA2 ISA `CLAMP` semantics across VALU operations routed through `Lower::write_i`, `valu16`, and `packed16` that previously failed as `"integer output modifiers"` or `"modifiers on a 16-bit/packed integer operation"` (while leaving non-clamped emission unchanged and keeping `omod != 0` and bitwise/shift `clamp` refused): - `v_add_nc_i32` and `v_sub_nc_i32` (`sadd.sat.i32` / `ssub.sat.i32` with `clamp`, wrapping without `clamp`), `v_cvt_pk_u16_u32`, `v_cvt_pk_i16_i32`, and `v_mad_i32_i16`. - `v_add_co_u32`, `v_sub_co_u32`, `v_subrev_co_u32`, `v_add_co_ci_u32`, `v_sub_co_ci_u32`, and `v_subrev_co_ci_u32` with `clamp` (saturating `vdst` at `0xffffffff` or `0` while keeping the un-clamped carry/borrow mask in `sdst`). - `v_mul_{u32_u24,i32_i24}`, `v_mad_{u32_u24,i32_i24,u32_u16,i32_i16}`, `v_mad_{u64_u32,i64_i32}`, and `v_sad_{u8,hi_u8,u16,u32}` / `v_msad_u8` with `clamp`. - `v_cvt_f16_f32` (`opsel == 0`, matching `valu16`), `v_cvt_pkrtz_f16_f32` (`[0.0, 1.0]` float clamp before RTZ conversion), and `v_cvt_pknorm_{u16,i16}_f32` / `v_cvt_norm_{u16,i16}_f16` with `clamp`. - 16-bit and VOP3P packed `v_add_nc_u16`, `v_sub_nc_u16`, `v_subrev_nc_u16`, `v_mul_lo_u16`, and `v_pk_{add,sub,mad}_{u16,i16}` / `v_pk_mul_lo_u16` with `clamp`. ## Verification - Unit and negative refusal tests in `victory_shader::emit::lower::tests` and `victory_shader::emit::valu_tests` - Metal GPU value test `victory_gpu::native::tests::addr_tests::clamped_integer_carry_mad_sad_and_half_packs_saturate_on_the_gpu` (16 boundary/saturation cases on Metal) - `cargo test -p victory-hle -p victory -p victory-gpu -p victory-metal -p victory-shader -p xtask` - `cargo clippy --workspace --all-targets --target x86_64-pc-windows-gnullvm -- -D warnings` - `cargo clippy --workspace --all-targets --all-features --target x86_64-pc-windows-gnullvm -- -D warnings` - `cargo xtask policy` Closes #519 Refs #4, #258 cc @⁠Olima34
Follow RDNA2 ISA CLAMP semantics across integer, carry-out, multiply-add,
SAD, and 16-bit/packed VALU operations that previously failed with
"integer output modifiers" or "modifiers on a 16-bit/packed integer
operation":
- v_add_nc_i32 and v_sub_nc_i32 (wrapping and signed-saturating saddsat/
  ssubsat), v_cvt_pk_u16_u32, v_cvt_pk_i16_i32, and v_mad_i32_i16;
- v_add_co_u32, v_sub_co_u32, v_subrev_co_u32, and v_*_co_ci_u32 with clamp
  (saturating vdst while preserving the un-clamped carry/borrow mask);
- v_mul_{u32_u24,i32_i24}, v_mad_{u32_u24,i32_i24,u32_u16,i32_i16},
  v_mad_{u64_u32,i64_i32}, and v_sad_*/v_msad_u8 with clamp;
- v_cvt_f16_f32 (opsel == 0), v_cvt_pkrtz_f16_f32, and
  v_cvt_pknorm_{u16,i16}_f32 with clamp;
- 16-bit and VOP3P packed v_add_nc_u16, v_sub_nc_u16, v_subrev_nc_u16,
  v_mul_lo_u16, and v_pk_{add,sub,mad}_{u16,i16}/v_pk_mul_lo_u16 with clamp.

Closes #515
Refs #4, #258
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 23:48:30 +00:00
Author
Owner

@⁠Olima34 on GitHub · 2026-11-27 23:48 UTC · original

Thanks @⁠Sheffy007! Integer output modifiers are one of the refusal classes we see most often in world shaders, so this is welcome. Keeping omod != 0 and bitwise/shift clamp refused rather than guessing reads right to us.

Heads-up: main moved an hour ago to 86cefd22 (the maintainer merged the preview branch: page-crossing reads, mesh rules, the compute heap-index rule, LOD clamp and bias). We'll sweep #520 on that main over our two boot corpora (4,921 and 4,129 containers) and on the 21,600-container world corpus, then post newly translated / regressions / changed outputs per stage here, the same way as on #468. We'll also flag any overlap with your #452, #468 and #516 where they touch the same lowering.

**@⁠Olima34** on GitHub · 2026-11-27 23:48 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/516#issuecomment-7230424520) Thanks @⁠Sheffy007! Integer output modifiers are one of the refusal classes we see most often in world shaders, so this is welcome. Keeping `omod != 0` and bitwise/shift `clamp` refused rather than guessing reads right to us. Heads-up: main moved an hour ago to `86cefd22` (the maintainer merged the preview branch: page-crossing reads, mesh rules, the compute heap-index rule, LOD clamp and bias). We'll sweep #520 on that main over our two boot corpora (4,921 and 4,129 containers) and on the 21,600-container world corpus, then post newly translated / regressions / changed outputs per stage here, the same way as on #468. We'll also flag any overlap with your #452, #468 and #516 where they touch the same lowering.
github-bot force-pushed github-bot/gh-516 from 4dccd5ab8e to 497baed68d 2026-11-28 00:51:16 +00:00 Compare
github-bot force-pushed github-bot/gh-516 from 497baed68d to 65a04a4b58 2026-11-28 01:48:13 +00:00 Compare
Author
Owner

@⁠Olima34 on GitHub · 2026-11-28 01:55 UTC · original

Thanks for this PR! Here is the corpus sweep I promised, with no game run.

Corpus sweep (examples/sweep + tools/corpus/compare.sh), measured on main a6a58361. That main translates shaders the same way as 226645f9.

  • Head swept: 497baed6.
  • Your rebase to 65a04a4b only changes test context; the shader-side diff is the same, and main's newer victory-shader commits since a6a58361 only add tests.
set newly translated output changed regressions
A (4,921 boot shaders) 0 0 0
B (4,129 boot shaders) 0 0 0
W (21,600 world shaders) 0 0 0

The same holds at the earlier head 4dccd5ab, which still had the v_cvt_pk_u16_u32 part: 0 / 0 / 0 on all three sets.

No shader in these sets is refused first for "integer output modifiers" or "modifiers on a 16-bit/packed integer operation" on current main. So this is a no-regression check rather than a coverage measurement. Shaders whose first refusal is something else may still carry these ops further in.

Overlap with #452, #468 and #516: #520 merges cleanly with each of them, and with all three together, on a6a58361. Since #520 changes no output in these sets, its gains cannot overlap theirs.

**@⁠Olima34** on GitHub · 2026-11-28 01:55 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/516#issuecomment-7232006241) Thanks for this PR! Here is the corpus sweep I promised, with no game run. **Corpus sweep** (`examples/sweep` + `tools/corpus/compare.sh`), measured on main a6a58361. That main translates shaders the same way as 226645f9. - Head swept: 497baed6. - Your rebase to 65a04a4b only changes test context; the shader-side diff is the same, and main's newer victory-shader commits since a6a58361 only add tests. | set | newly translated | output changed | regressions | |---|---|---|---| | A (4,921 boot shaders) | 0 | 0 | 0 | | B (4,129 boot shaders) | 0 | 0 | 0 | | W (21,600 world shaders) | 0 | 0 | 0 | The same holds at the earlier head 4dccd5ab, which still had the `v_cvt_pk_u16_u32` part: 0 / 0 / 0 on all three sets. No shader in these sets is refused first for "integer output modifiers" or "modifiers on a 16-bit/packed integer operation" on current main. So this is a no-regression check rather than a coverage measurement. Shaders whose first refusal is something else may still carry these ops further in. **Overlap with #452, #468 and #516:** #520 merges cleanly with each of them, and with all three together, on a6a58361. Since #520 changes no output in these sets, its gains cannot overlap theirs.
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/520/head:github-bot/gh-516'
git switch 'github-bot/gh-516'

Merge

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