Lower GFX7 v_cvt_pkaccum_u8_f32 onto v_cvt_pk_u8_f32 #141

Closed
github-bot wants to merge 2 commits from gh-pr/141/head into gh-pr/141/base
Owner

@⁠Yeetbot159 on GitHub · 2026-11-22 15:16 UTC · original
Yeetbot159:yeet/pkaccum-u8 → main · +93 −1 · 2 files · 2 commits · closed without merging

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.
**@⁠Yeetbot159** on GitHub · 2026-11-22 15:16 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/141) `Yeetbot159:yeet/pkaccum-u8` → `main` · +93 −1 · 2 files · 2 commits · closed without merging ## 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.
The low two bits of that source choose the byte, and the converted float replaces that byte of the same dword. A NaN becomes 0 and the value is rounded to nearest even, clamped to 0..255.

Co-authored-by: Cursor <[email protected]>
v_cvt_pkaccum_u8_f32 updates one byte of its destination. The RDNA2 form keeps the other bytes from src2, so that source is the destination register, not the byte selector.

Co-authored-by: Cursor <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:11:34 +00:00
github-bot closed this pull request 2026-11-26 06:11:34 +00:00
Author
Owner

@⁠omonkeyz on GitHub · 2026-11-22 15:19 UTC · original

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.

**@⁠omonkeyz** on GitHub · 2026-11-22 15:19 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/141#issuecomment-7081209174) 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`.
Author
Owner

@⁠Yeetbot159 on GitHub · 2026-11-22 15:52 UTC · original

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.

**@⁠Yeetbot159** on GitHub · 2026-11-22 15:52 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/141#issuecomment-7081643242) 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`.
Author
Owner

@⁠MiguelMatMar on GitHub · 2026-11-22 16:03 UTC · original

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.

**@⁠MiguelMatMar** on GitHub · 2026-11-22 16:03 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/141#issuecomment-7081779798) 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.
Author
Owner

@⁠omonkeyz on GitHub · 2026-11-22 16:11 UTC · original

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.

**@⁠omonkeyz** on GitHub · 2026-11-22 16:11 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/141#issuecomment-7081877350) 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

This discussion has been locked. Commenting is limited to contributors.
No description provided.