fix(shader): keep v_permlane16 lanes whose source lane is inactive #606

Merged
adriadam10 merged 1 commit from upstream-pr/606 into main 2026-10-05 05:12:26 +00:00
adriadam10 commented 2026-10-05 02:39:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-05T02:39:22Z.


What

On hardware, when a v_permlane16_b32 or v_permlanex16_b32 lane reads from an inactive source lane, the result depends on the two op_sel bits:

  • fetch inactive (op_sel[0]) set: the lane reads the inactive lane's value anyway (main already did this).
  • fetch inactive clear, bound_ctrl (op_sel[1]) clear: the lane is not written and keeps its old value. main wrote 0 here.
  • fetch inactive clear, bound_ctrl set: the lane gets 0.

main decoded bound_ctrl into PermlaneFlags::boundControl but never used it. The translator now passes the old destination value to Permlane16U32, and the emitter picks the old value or 0 depending on bound_ctrl. The rule is the same as the one the hardware uses for DPP16 with an inactive source lane.

Neither opcode had an execution test. This PR adds agc_driver_permlane16 (Permlane16.cpp), which runs in wave32, native wave64 and wave64 split into two wave32 halves (ComputeTarget(32)):

  • full EXEC: v_permlane16_b32 with identity, reverse and mixed selects, plus inline constant selects 0 and -1; v_permlanex16_b32 with identity, reverse, mixed and broadcast selects
  • partial EXEC: both opcodes with every op_sel combination that matters (none, fi, bc, fi+bc), with the destination pre-filled so a lane that isn't written shows up

Behaviour measured on HW

Measured on gfx1035 (RDNA2), wave32 and wave64, 3 random input sets per wave size, 0 mismatches against this model:

  • the source lane is (lane & ~15) | sel, where sel is the nibble lane & 7 of src1 for lanes 0-7 of the row and of src2 for lanes 8-15
  • for x16, the row is XORed with 16: rows 0↔1 and 2↔3 in wave64
  • inactive source lane: as in the list above
  • a lane that is inactive itself is never written

The expected values in the test come from the hardware output. Operand syntax op_sel:[fi,bound_ctrl] follows llvm-mc -mcpu=gfx1013.

Tested

Linux, RADV (Mesa 26.2): the new test passes in all three wave modes. On lavapipe it skips (8-lane subgroups), like the other cross-lane tests, so CI only builds it. Full Release ctest: everything passes except agc_driver_pixel_helper_lanes, which also fails on local RADV on main.

Negative checks: the test fails when the code is mutated in any of these ways:

  • main's behaviour (inactive source writes 0): fails on inactive_permlane16
  • bound_ctrl ignored (always keeps the old value)
  • fetch inactive ignored
  • x16 row XOR dropped
  • src1 used for the upper 8 lanes of the row

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4739518623 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/606). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-05T02:39:22Z. --- ### What On hardware, when a `v_permlane16_b32` or `v_permlanex16_b32` lane reads from an inactive source lane, the result depends on the two `op_sel` bits: - fetch inactive (`op_sel[0]`) set: the lane reads the inactive lane's value anyway (`main` already did this). - fetch inactive clear, bound_ctrl (`op_sel[1]`) clear: the lane is **not written** and keeps its old value. `main` wrote 0 here. - fetch inactive clear, bound_ctrl set: the lane gets 0. `main` decoded bound_ctrl into `PermlaneFlags::boundControl` but never used it. The translator now passes the old destination value to `Permlane16U32`, and the emitter picks the old value or 0 depending on bound_ctrl. The rule is the same as the one the hardware uses for DPP16 with an inactive source lane. Neither opcode had an execution test. This PR adds `agc_driver_permlane16` (`Permlane16.cpp`), which runs in wave32, native wave64 and wave64 split into two wave32 halves (`ComputeTarget(32)`): - full EXEC: `v_permlane16_b32` with identity, reverse and mixed selects, plus inline constant selects `0` and `-1`; `v_permlanex16_b32` with identity, reverse, mixed and broadcast selects - partial EXEC: both opcodes with every `op_sel` combination that matters (none, fi, bc, fi+bc), with the destination pre-filled so a lane that isn't written shows up #### Behaviour measured on HW Measured on gfx1035 (RDNA2), wave32 and wave64, 3 random input sets per wave size, 0 mismatches against this model: - the source lane is `(lane & ~15) | sel`, where `sel` is the nibble `lane & 7` of src1 for lanes 0-7 of the row and of src2 for lanes 8-15 - for `x16`, the row is XORed with 16: rows 0↔1 and 2↔3 in wave64 - inactive source lane: as in the list above - a lane that is inactive itself is never written The expected values in the test come from the hardware output. Operand syntax `op_sel:[fi,bound_ctrl]` follows `llvm-mc -mcpu=gfx1013`. ### Tested Linux, RADV (Mesa 26.2): the new test passes in all three wave modes. On lavapipe it skips (8-lane subgroups), like the other cross-lane tests, so CI only builds it. Full Release ctest: everything passes except `agc_driver_pixel_helper_lanes`, which also fails on local RADV on `main`. Negative checks: the test fails when the code is mutated in any of these ways: - `main`'s behaviour (inactive source writes 0): fails on `inactive_permlane16` - bound_ctrl ignored (always keeps the old value) - fetch inactive ignored - x16 row XOR dropped - src1 used for the upper 8 lanes of the row ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes
oneandonlydean commented 2026-10-05 03:09:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-05T03:09:19Z.


Thanks, this checks out. I disassembled both kernels with llvm-mc -mcpu=gfx1013: v_permlane16_b32 and v_permlanex16_b32 with the SGPR selects, the inline 0 and -1 selects, and every op_sel combination (none, [1,0], [0,1], [1,1]) under the partial EXEC.

The change does what the table says: with fetch inactive set the shuffle is returned as before; otherwise an inactive source lane gives 0 when bound_ctrl is set and the old destination value (now passed in through readRawU32 of the destination) when it isn't. The extra Permlane16U32 argument has no other users to update. The new test fails on main (inactive_permlane16 is 0x00000000, expected 0xdeaddead) and passes with the fix, and it merges cleanly with your other open shader PRs.

One note for the merge order: PPSA21564 has 704 v_permlanex16_b32 with op_sel:[0,1], whose output doesn't change, but also 56 v_permlane16_b32 with no op_sel in two shaders, which is exactly the case that now keeps the old value. So I'll run it through my visual check of PPSA21564 before it goes in.

Ready to merge from my side once that run is done.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5987417786 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/606#issuecomment-5987417786). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-05T03:09:19Z. --- Thanks, this checks out. I disassembled both kernels with `llvm-mc -mcpu=gfx1013`: `v_permlane16_b32` and `v_permlanex16_b32` with the SGPR selects, the inline `0` and `-1` selects, and every `op_sel` combination (none, `[1,0]`, `[0,1]`, `[1,1]`) under the partial EXEC. The change does what the table says: with fetch inactive set the shuffle is returned as before; otherwise an inactive source lane gives 0 when bound_ctrl is set and the old destination value (now passed in through `readRawU32` of the destination) when it isn't. The extra `Permlane16U32` argument has no other users to update. The new test fails on main (`inactive_permlane16 is 0x00000000, expected 0xdeaddead`) and passes with the fix, and it merges cleanly with your other open shader PRs. One note for the merge order: PPSA21564 has 704 `v_permlanex16_b32` with `op_sel:[0,1]`, whose output doesn't change, but also 56 `v_permlane16_b32` with no `op_sel` in two shaders, which is exactly the case that now keeps the old value. So I'll run it through my visual check of PPSA21564 before it goes in. Ready to merge from my side once that run is done.
oneandonlydean commented 2026-10-05 05:04:11 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-05T05:04:11Z.


Gated on PPSA21564: no visual or FPS change.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5988443545 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/606#issuecomment-5988443545). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-05T05:04:11Z. --- Gated on PPSA21564: no visual or FPS change.
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
boykopovar/AnyPS5!606
No description provided.