tooling: ps_input_scan misses live-in registers read only as an accumulator (v_mac/v_fmac/v_writelane) #2528

Closed
opened 2026-11-25 20:16:38 +00:00 by Asimmimx · 0 comments
Asimmimx commented 2026-11-25 20:16:38 +00:00 (Migrated from github.com)
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by Asimmimx on 2026-11-25T20:16:38Z.


Commit or build

main at 2b883ea6.

Summary

tools/startup/ps_input_scan.py takes a pixel shader's live-in vector registers to be the ones read before any write. parse_instruction treats the first operand of any form with a vector destination as written only. Some forms also read their destination:

  • the multiply- and dot-accumulate forms (v_mac_*, v_fmac_*, v_pk_fmac_f16, v_dot*c_*) compute D = S0 * S1 + D;
  • v_writelane_b32 writes one lane and keeps the others.

A register first used as such an accumulator is therefore a hardware-loaded input, but it is missing from the contract. Rule C1 (coverage) then accepts masks with too few registers, and the tight/informative counts for a candidate location are wrong for that shader.

Reproduction

A source-built gfx1013 shader: v_fmac_f32_e32 v2, v0, v1 (VOP2 op 0x2b), then exp mrt0 v2, v2, v2, v2 done vm, then s_endpgm. Compute ps_input_scan.contract(code) and consistent(contract, mask).

Observed

decoded: ['v_fmac_f32_e32 v2, v0, v1', 'exp mrt0 v2, v2, v2, v2 done vm', 's_endpgm']
live_in [0, 1] mask 0x0001 -> (True, '') mask 0x0003 -> (True, '')

v_mac_f32_e32 (0x1f), v_mac_legacy_f32_e32 (0x06), v_fmac_f16_e32 (0x36) and v_pk_fmac_f16 (0x3c) give the same [0, 1]. v_writelane_b32 v2, s0, 1 gives [].

Expected

live_in [0, 1, 2]. Mask 0x0001 (PERSP_SAMPLE, 2 registers) then fails C1 coverage; 0x0003 (4 registers) stays consistent.

Reference

  • AMD RDNA (gfx10) ISA VOP2 descriptions: V_MAC_F32 / V_FMAC_F32 are D = S0 * S1 + D, and V_WRITELANE_B32 writes one lane of the destination.
  • tools/startup/gfx2hlsl.py already lists v_mac and v_fmac in READ_MODIFY_WRITE.

Not established

  • How many shaders in a real corpus begin with such an accumulator read, and whether any reported location verdict changes.
  • SDWA dst_unused:UNUSED_PRESERVE and DPP forms with partial row or bank masks also keep part of their destination. They are not covered here.

AI-assisted (Claude Code).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6612913023 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/2536). Originally posted by [Asimmimx](https://github.com/Asimmimx) on 2026-11-25T20:16:38Z. --- ### Commit or build `main` at `2b883ea6`. ### Summary `tools/startup/ps_input_scan.py` takes a pixel shader's live-in vector registers to be the ones read before any write. `parse_instruction` treats the first operand of any form with a vector destination as written only. Some forms also read their destination: - the multiply- and dot-accumulate forms (`v_mac_*`, `v_fmac_*`, `v_pk_fmac_f16`, `v_dot*c_*`) compute D = S0 * S1 + D; - `v_writelane_b32` writes one lane and keeps the others. A register first used as such an accumulator is therefore a hardware-loaded input, but it is missing from the contract. Rule C1 (coverage) then accepts masks with too few registers, and the tight/informative counts for a candidate location are wrong for that shader. ### Reproduction A source-built gfx1013 shader: `v_fmac_f32_e32 v2, v0, v1` (VOP2 op 0x2b), then `exp mrt0 v2, v2, v2, v2 done vm`, then `s_endpgm`. Compute `ps_input_scan.contract(code)` and `consistent(contract, mask)`. ### Observed ``` decoded: ['v_fmac_f32_e32 v2, v0, v1', 'exp mrt0 v2, v2, v2, v2 done vm', 's_endpgm'] live_in [0, 1] mask 0x0001 -> (True, '') mask 0x0003 -> (True, '') ``` `v_mac_f32_e32` (0x1f), `v_mac_legacy_f32_e32` (0x06), `v_fmac_f16_e32` (0x36) and `v_pk_fmac_f16` (0x3c) give the same `[0, 1]`. `v_writelane_b32 v2, s0, 1` gives `[]`. ### Expected `live_in [0, 1, 2]`. Mask 0x0001 (`PERSP_SAMPLE`, 2 registers) then fails `C1 coverage`; 0x0003 (4 registers) stays consistent. ### Reference - AMD RDNA (gfx10) ISA VOP2 descriptions: `V_MAC_F32` / `V_FMAC_F32` are D = S0 * S1 + D, and `V_WRITELANE_B32` writes one lane of the destination. - `tools/startup/gfx2hlsl.py` already lists `v_mac` and `v_fmac` in `READ_MODIFY_WRITE`. ### Not established - How many shaders in a real corpus begin with such an accumulator read, and whether any reported location verdict changes. - SDWA `dst_unused:UNUSED_PRESERVE` and DPP forms with partial row or bank masks also keep part of their destination. They are not covered here. AI-assisted (Claude Code).
Sign in to join this conversation.
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
R0Y00/Xbox2Windows#2528
No description provided.