Lower GFX7 v_cvt_pkaccum_u8_f32 onto v_cvt_pk_u8_f32 #141

Closed
Yeetbot159 wants to merge 2 commits from upstream-pr/141 into main
Yeetbot159 commented 2026-11-22 15:16:46 +00:00 (Migrated from github.com)

Imported from omonkeyz/xbox-emulator. Originally posted by Yeetbot159 on 2026-11-22T15:16:46Z.


Summary

  • GFX7 v_cvt_pkaccum_u8_f32 is the two-source form of v_cvt_pk_u8_f32. The integer source is repeated: its low two bits select the byte, and that byte of the same dword is replaced by the converted float.
  • A NaN becomes 0. The value is rounded to nearest even and clamped to 0..255, which is what v_cvt_pk_u8_f32 already does. Clamp, an output modifier, or abs/neg on the integer source is refused, because the packed byte would not match.
  • This is separate from the legacy min/max change. Both add a Vop2Map arm, so this needs a rebase if that pull request merges first.

Test plan

  • cargo test -p tombox-xshader --lib gcn::tests passed (20 tests).
  • pkaccum_u8_updates_the_byte_selected_by_its_integer_source checks the VOP2 form, the VOP3 form, and that a clamp modifier is an error.
<!-- greyfinch-sync:omonkeyz/xbox-emulator:issue:6544060908 --> Imported from [omonkeyz/xbox-emulator](https://github.com/omonkeyz/xbox-emulator/pull/141). Originally posted by [Yeetbot159](https://github.com/Yeetbot159) on 2026-11-22T15:16:46Z. --- ## Summary - GFX7 `v_cvt_pkaccum_u8_f32` is the two-source form of `v_cvt_pk_u8_f32`. The integer source is repeated: its low two bits select the byte, and that byte of the same dword is replaced by the converted float. - A NaN becomes 0. The value is rounded to nearest even and clamped to 0..255, which is what `v_cvt_pk_u8_f32` already does. Clamp, an output modifier, or abs/neg on the integer source is refused, because the packed byte would not match. - This is separate from the legacy min/max change. Both add a `Vop2Map` arm, so this needs a rebase if that pull request merges first. ## Test plan - `cargo test -p tombox-xshader --lib gcn::tests` passed (20 tests). - `pkaccum_u8_updates_the_byte_selected_by_its_integer_source` checks the VOP2 form, the VOP3 form, and that a clamp modifier is an error.
omonkeyz commented 2026-11-22 15:19:02 +00:00 (Migrated from github.com)

Imported from omonkeyz/xbox-emulator. Originally posted by omonkeyz on 2026-11-22T15:19:02Z.


Thanks! The lowering is close, but the accumulator is the wrong register. v_cvt_pkaccum_u8_f32 packs the converted byte into the existing destination (D keeps its other three bytes). In RDNA2 v_cvt_pk_u8_f32, src2 is the value whose other bytes are kept, so src2 must be vdst, not the byte-select source. With [src0, vsrc1, vsrc1] the other bytes come from the selector register instead of D.

Please change both the VOP2 and VOP3 paths to [src0, src1, vdst]. Update the test to expect Vgpr(1) as src2, and add an exec test that packs four bytes into one register in sequence.

Also: #139 adds psv_numthreads to ShaderExtract, so after it lands translate_lowered here will need psv_numthreads: None.

<!-- greyfinch-sync:omonkeyz/xbox-emulator:comment:7081209174 --> Imported from [omonkeyz/xbox-emulator](https://github.com/omonkeyz/xbox-emulator/pull/141#issuecomment-7081209174). Originally posted by [omonkeyz](https://github.com/omonkeyz) on 2026-11-22T15:19:02Z. --- Thanks! The lowering is close, but the accumulator is the wrong register. `v_cvt_pkaccum_u8_f32` packs the converted byte into the existing destination (D keeps its other three bytes). In RDNA2 `v_cvt_pk_u8_f32`, src2 is the value whose other bytes are kept, so src2 must be **vdst**, not the byte-select source. With `[src0, vsrc1, vsrc1]` the other bytes come from the selector register instead of D. Please change both the VOP2 and VOP3 paths to `[src0, src1, vdst]`. Update the test to expect `Vgpr(1)` as src2, and add an exec test that packs four bytes into one register in sequence. Also: #139 adds `psv_numthreads` to `ShaderExtract`, so after it lands `translate_lowered` here will need `psv_numthreads: None`.
Yeetbot159 commented 2026-11-22 15:52:47 +00:00 (Migrated from github.com)

Imported from omonkeyz/xbox-emulator. Originally posted by Yeetbot159 on 2026-11-22T15:52:47Z.


Both the VOP2 and VOP3 paths now pass the destination as src2, so the other three bytes stay in D. translate_lowered sets psv_numthreads: None. pkaccum_u8_packs_four_bytes_into_one_register passed on WARP: 1.0, 2.0, 3.0 and 4.0 pack to 0x04030201.

<!-- greyfinch-sync:omonkeyz/xbox-emulator:comment:7081643242 --> Imported from [omonkeyz/xbox-emulator](https://github.com/omonkeyz/xbox-emulator/pull/141#issuecomment-7081643242). Originally posted by [Yeetbot159](https://github.com/Yeetbot159) on 2026-11-22T15:52:47Z. --- Both the VOP2 and VOP3 paths now pass the destination as src2, so the other three bytes stay in D. `translate_lowered` sets `psv_numthreads: None`. `pkaccum_u8_packs_four_bytes_into_one_register` passed on WARP: 1.0, 2.0, 3.0 and 4.0 pack to `0x04030201`.
MiguelMatMar commented 2026-11-22 16:03:35 +00:00 (Migrated from github.com)

Imported from omonkeyz/xbox-emulator. Originally posted by MiguelMatMar on 2026-11-22T16:03:35Z.


Independent hardware run: pkaccum_u8_packs_four_bytes_into_one_register passes on WARP and on hardware (TOMBOX_EXEC_HW=1, NVIDIA Ada / RTX 40-series), PR head bf64545. opcodes, synthetic and gcn_dims also pass.

<!-- greyfinch-sync:omonkeyz/xbox-emulator:comment:7081779798 --> Imported from [omonkeyz/xbox-emulator](https://github.com/omonkeyz/xbox-emulator/pull/141#issuecomment-7081779798). Originally posted by [MiguelMatMar](https://github.com/MiguelMatMar) on 2026-11-22T16:03:35Z. --- Independent hardware run: `pkaccum_u8_packs_four_bytes_into_one_register` passes on WARP and on hardware (`TOMBOX_EXEC_HW=1`, NVIDIA Ada / RTX 40-series), PR head bf64545. `opcodes`, `synthetic` and `gcn_dims` also pass.
omonkeyz commented 2026-11-22 16:11:01 +00:00 (Migrated from github.com)

Imported from omonkeyz/xbox-emulator. Originally posted by omonkeyz on 2026-11-22T16:11:01Z.


Applied in fcb99ba (merged in 1a1e283) with your authorship kept, thanks! I squashed both commits into one, and fixed a merge conflict with #140 in gcn.rs and exec.rs, keeping both lowerings and all tests.

<!-- greyfinch-sync:omonkeyz/xbox-emulator:comment:7081877350 --> Imported from [omonkeyz/xbox-emulator](https://github.com/omonkeyz/xbox-emulator/pull/141#issuecomment-7081877350). Originally posted by [omonkeyz](https://github.com/omonkeyz) on 2026-11-22T16:11:01Z. --- Applied in fcb99ba (merged in 1a1e283) with your authorship kept, thanks! I squashed both commits into one, and fixed a merge conflict with #140 in gcn.rs and exec.rs, keeping both lowerings and all tests.

Pull request closed

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
omonkeyz/xbox-emulator!141
No description provided.