shader: lower v_cvt_pknorm_u16_f32 and v_cvt_pknorm_i16_f32 #55

Merged
Sandile-0511 merged 3 commits from upstream-pr/55 into main 2026-11-26 12:58:09 +00:00
Sandile-0511 commented 2026-11-26 11:35:09 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Sandile-0511 on 2026-11-26T11:35:09Z.


What this changes

A vertex and pixel pair was refused at world load with v_cvt_pknorm_u16_f32 is not supported. This adds the instruction and its signed sibling next to v_cvt_pkrtz_f16_f32: each source is clamped to [0, 1] (signed: [-1, 1]), scaled by 65535 (32767), rounded to nearest even and masked to 16 bits; src0 goes in the low half and src1 in the high half. VOP3 abs and neg are honoured through fsrc. The _f16 forms stay refused.

Sources: AMD's machine-readable RDNA2 ISA (VOP3-only on GFX10, "packed unsigned normalized short"), LLVM VOP2Instructions.td (VOP3Only_Real_gfx10<0x369>), Mesa ACO instruction selection (operand order) and NIR pack_unorm_1x16 / pack_snorm_1x16 (clamp and round-to-even).

One guess, marked in the code: a NaN source gives 0. No public source states the hardware result; this follows D3D's float-to-normalized rule, as the file already does for v_cvt_pk_u8_f32.

How it was tested

  • cargo test -p victory-shader: 220 passed, 0 failed, 2 ignored. New test normalized_16_bit_packing_lowers_in_pixel_shader (u16, i16, abs/neg, an inline constant, both host wave sizes; _f16 still refused).
  • The value test normalized_packing_matches_the_hardware is Windows-only like the rest of semantics_tests. It was type-checked only and needs a Windows run. Its 19 known answers were derived separately from the translator.
  • cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings (clean, run on a Mac)
  • cargo xtask policy (365 files ok)
  • Ran the game in a combined local build: the refusal no longer appears.

Checklist

  • No game files, game code, disassembly listings or SDK files are included
  • Guesses about undocumented console behaviour are marked in the code and in docs/native-host.md (marked in the code; native-host.md only lists graphics-pipeline guesses, so I did not add an entry there. Say if you want one.)
  • New diagnostics are behind a VICTORY_* variable and documented (none added)
<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:issue:6625789010 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/55). Originally posted by [Sandile-0511](https://github.com/Sandile-0511) on 2026-11-26T11:35:09Z. --- ## What this changes A vertex and pixel pair was refused at world load with `v_cvt_pknorm_u16_f32 is not supported`. This adds the instruction and its signed sibling next to `v_cvt_pkrtz_f16_f32`: each source is clamped to [0, 1] (signed: [-1, 1]), scaled by 65535 (32767), rounded to nearest even and masked to 16 bits; src0 goes in the low half and src1 in the high half. VOP3 abs and neg are honoured through `fsrc`. The `_f16` forms stay refused. Sources: AMD's machine-readable RDNA2 ISA (VOP3-only on GFX10, "packed unsigned normalized short"), LLVM `VOP2Instructions.td` (`VOP3Only_Real_gfx10<0x369>`), Mesa ACO instruction selection (operand order) and NIR `pack_unorm_1x16` / `pack_snorm_1x16` (clamp and round-to-even). One guess, marked in the code: a NaN source gives 0. No public source states the hardware result; this follows D3D's float-to-normalized rule, as the file already does for `v_cvt_pk_u8_f32`. ## How it was tested - [x] `cargo test -p victory-shader`: 220 passed, 0 failed, 2 ignored. New test `normalized_16_bit_packing_lowers_in_pixel_shader` (u16, i16, abs/neg, an inline constant, both host wave sizes; `_f16` still refused). - [ ] The value test `normalized_packing_matches_the_hardware` is Windows-only like the rest of `semantics_tests`. It was type-checked only and needs a Windows run. Its 19 known answers were derived separately from the translator. - [x] `cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings` (clean, run on a Mac) - [x] `cargo xtask policy` (365 files ok) - [x] Ran the game in a combined local build: the refusal no longer appears. ## Checklist - [x] No game files, game code, disassembly listings or SDK files are included - [ ] Guesses about undocumented console behaviour are marked in the code and in docs/native-host.md (marked in the code; native-host.md only lists graphics-pipeline guesses, so I did not add an entry there. Say if you want one.) - [x] New diagnostics are behind a `VICTORY_*` variable and documented (none added)
LakshanSivakumar commented 2026-11-26 11:51:43 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-26T11:51:43Z.

Review: CHANGES_REQUESTED


The half order matches the RDNA ISA, and the clamp, scale, and nearest-even rounding match Mesa's packing model. Please document NaN-to-zero in docs/native-host.md as a Direct3D-based assumption for this opcode. Heads-up: this conflicts with #56 in gfx_refusal_tests.rs, so whichever lands second will need a rebase.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:review:6073656832 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/55#pullrequestreview-6073656832). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-26T11:51:43Z. **Review:** CHANGES_REQUESTED --- The half order matches the RDNA ISA, and the clamp, scale, and nearest-even rounding match Mesa's packing model. Please document NaN-to-zero in `docs/native-host.md` as a Direct3D-based assumption for this opcode. Heads-up: this conflicts with #56 in `gfx_refusal_tests.rs`, so whichever lands second will need a rebase.
Sandile-0511 commented 2026-11-26 12:30:37 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Sandile-0511 on 2026-11-26T12:30:37Z.


Documented NaN-to-zero in docs/native-host.md as an assumption based on Direct3D's float-to-normalized rule, and noted which parts are not guesses (half order, clamp, scale, rounding). I merged main to clear the conflict with #58 in gfx_refusal_tests.rs. It will conflict with #56 in the same file again; I'll rebase whichever lands second.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7192093912 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/55#issuecomment-7192093912). Originally posted by [Sandile-0511](https://github.com/Sandile-0511) on 2026-11-26T12:30:37Z. --- Documented NaN-to-zero in `docs/native-host.md` as an assumption based on Direct3D's float-to-normalized rule, and noted which parts are not guesses (half order, clamp, scale, rounding). I merged `main` to clear the conflict with #58 in `gfx_refusal_tests.rs`. It will conflict with #56 in the same file again; I'll rebase whichever lands second.
LakshanSivakumar commented 2026-11-26 12:48:04 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-26T12:48:04Z.

Review: APPROVED


Thanks, the earlier requests are addressed and the checks pass (tests incl. Metal, Windows clippy, policy). Approved.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:review:6074382180 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/55#pullrequestreview-6074382180). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-26T12:48:04Z. **Review:** APPROVED --- Thanks, the earlier requests are addressed and the checks pass (tests incl. Metal, Windows clippy, policy). Approved.
Sign in to join this conversation.
No reviewers
No labels
No milestone
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.

Reference
LakshanSivakumar/Native-Victory-macOS!55
No description provided.