shader: lower v_cvt_pknorm_u16_f32 and v_cvt_pknorm_i16_f32 #55

Manually merged
github merged 3 commits from gh-pr/55/head into gh-pr/55/base 2026-11-26 14:44:17 +00:00
Owner

@⁠Sandile-0511 on GitHub · 2026-11-26 11:35 UTC · original
Sandile-0511:fix/cvt-pknorm → main · +176 −0 · 4 files · 3 commits · merged 2026-11-26 12:58 UTC

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)
**@⁠Sandile-0511** on GitHub · 2026-11-26 11:35 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/55) `Sandile-0511:fix/cvt-pknorm` → `main` · +176 −0 · 4 files · 3 commits · merged 2026-11-26 12:58 UTC ## 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)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 14:44:15 +00:00
github manually merged commit fc239bbcd8 into gh-pr/55/base 2026-11-26 14:44:17 +00:00
Author
Owner

@⁠LakshanSivakumar on GitHub · 2026-11-26 11:51 UTC · original · requested changes

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.

**@⁠LakshanSivakumar** on GitHub · 2026-11-26 11:51 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/55#pullrequestreview-6073656832) · **requested changes** 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.
Author
Owner

@⁠Sandile-0511 on GitHub · 2026-11-26 12:30 UTC · original

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.

**@⁠Sandile-0511** on GitHub · 2026-11-26 12:30 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/55#issuecomment-7192093912) 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.
Author
Owner

@⁠LakshanSivakumar on GitHub · 2026-11-26 12:48 UTC · original · approved these changes

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

**@⁠LakshanSivakumar** on GitHub · 2026-11-26 12:48 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/55#pullrequestreview-6074382180) · **approved these changes** Thanks, the earlier requests are addressed and the checks pass (tests incl. Metal, Windows clippy, policy). Approved.
This discussion has been locked. Commenting is limited to contributors.
No description provided.