shader: pack integer pairs to 16 bits with saturation (#401) #406

Manually merged
github merged 1 commit from github-bot/gh-402 into main 2026-11-28 00:29:55 +00:00 AGit
Owner

@⁠tiagonogueiraa-bit on GitHub · 2026-11-27 16:55 UTC · original
tiagonogueiraa-bit:shader-cvt-pk-u16 → main · +75 −0 · 3 files · 1 commits · merged 2026-11-28 00:28 UTC

Refs #405

Shape. v_cvt_pk_u16_u32 (VOP3 0x36a) was refused by name in 9 pixel shaders. It packs two 32-bit integers into one dword, src0 in the low half and src1 in the high one, each saturated to 16 bits. Mesa's ACO selects NIR's pack_uint_2x16 and pack_sint_2x16, which NIR defines as clamping, to v_cvt_pk_u16_u32 and v_cvt_pk_i16_i32.

Change. In Lower::valu_op, both are lowered:

  • the unsigned form clamps each source to 0..=0xffff;
  • the signed form clamps to -32768..=32767 and keeps the low 16 bits;
  • the halves are then packed.

Nothing else changes.

By-output corpus sweep. 26,849 containers from my own runs (Series S, boot to the story load), native host options, main b998bb6 against this head:

Stage Gained Lost Changed Other reason now
pixel 9 0 0 0
vertex 0 0 0 0
compute 0 0 0 0

Gained: 28e8d398fb691e37, 312178ad7218ccd3, 422f7a28d73c331e, 95e450f40c72b9b0, a574d44728bcfe55, e72b5ea82a653237, ebfb717fd259810a, f1d1ccf768189e23, f218c31ec76c0efe.

Test. split_wave_tests::integer_pairs_pack_to_16_bits_with_saturation (victory-gpu, on Metal with MSC 4.0 beta 3). Over 32 lanes, each form packs values that cross both limits:

  • unsigned: i << 12 past 0xffff, and 0x10002 - i;
  • signed: (i << 12) - 0x10000 below -32768 and above 32767.

The values are checked against Rust's min/clamp. On main the program fails at translation.

Checks.

  • cargo test -p victory-shader -p victory-hle -p victory -p victory-gpu -p victory-metal -p xtask: 1054 passed, 0 failed, 11 ignored.
  • Windows clippy -D warnings: clean.
  • cargo xtask policy: ok.

docs/native-host.md has a short section on it. @⁠Olima34, for the board.

**@⁠tiagonogueiraa-bit** on GitHub · 2026-11-27 16:55 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/402) `tiagonogueiraa-bit:shader-cvt-pk-u16` → `main` · +75 −0 · 3 files · 1 commits · merged 2026-11-28 00:28 UTC Refs #405 **Shape.** `v_cvt_pk_u16_u32` (VOP3 0x36a) was refused by name in 9 pixel shaders. It packs two 32-bit integers into one dword, src0 in the low half and src1 in the high one, each saturated to 16 bits. Mesa's ACO selects NIR's `pack_uint_2x16` and `pack_sint_2x16`, which NIR defines as clamping, to `v_cvt_pk_u16_u32` and `v_cvt_pk_i16_i32`. **Change.** In `Lower::valu_op`, both are lowered: - the unsigned form clamps each source to `0..=0xffff`; - the signed form clamps to `-32768..=32767` and keeps the low 16 bits; - the halves are then packed. Nothing else changes. **By-output corpus sweep.** 26,849 containers from my own runs (Series S, boot to the story load), native host options, main `b998bb6` against this head: | Stage | Gained | Lost | Changed | Other reason now | |---|---|---|---|---| | pixel | 9 | 0 | 0 | 0 | | vertex | 0 | 0 | 0 | 0 | | compute | 0 | 0 | 0 | 0 | Gained: `28e8d398fb691e37`, `312178ad7218ccd3`, `422f7a28d73c331e`, `95e450f40c72b9b0`, `a574d44728bcfe55`, `e72b5ea82a653237`, `ebfb717fd259810a`, `f1d1ccf768189e23`, `f218c31ec76c0efe`. **Test.** `split_wave_tests::integer_pairs_pack_to_16_bits_with_saturation` (`victory-gpu`, on Metal with MSC 4.0 beta 3). Over 32 lanes, each form packs values that cross both limits: - unsigned: `i << 12` past `0xffff`, and `0x10002 - i`; - signed: `(i << 12) - 0x10000` below -32768 and above 32767. The values are checked against Rust's `min`/`clamp`. On main the program fails at translation. **Checks.** - `cargo test -p victory-shader -p victory-hle -p victory -p victory-gpu -p victory-metal -p xtask`: 1054 passed, 0 failed, 11 ignored. - Windows clippy `-D warnings`: clean. - `cargo xtask policy`: ok. `docs/native-host.md` has a short section on it. @⁠Olima34, for the board.
v_cvt_pk_u16_u32 and v_cvt_pk_i16_i32 pack src0 into the low half and
src1 into the high half of a dword, each saturated to 16 bits. Mesa's
ACO selects NIR's clamping pack_uint_2x16 and pack_sint_2x16 to them.
They were refused by name.

Corpus sweep (26,849 shaders, main b998bb6): 9 pixel shaders gained,
no regressions, no changed outputs.

Refs #401
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 17:05:38 +00:00
github manually merged commit a50108d439 into main 2026-11-28 00:29:55 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.