cpp-migration: lower v_readlane_b32 and v_writelane_b32 in the direct C++ compute path #2940

Closed
opened 2026-11-26 22:25:12 +00:00 by Leyukaka · 2 comments
Leyukaka commented 2026-11-26 22:25:12 +00:00 (Migrated from github.com)
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-11-26T22:25:12Z.


Target branch cpp-migration. Part of #2935 (instruction coverage). I am taking this; please say if you already have it locally and I will drop it.

Gap: the direct C++ compute path lowers v_readfirstlane_b32 but not v_readlane_b32 or v_writelane_b32. Those two exist only inside pixel full-wave islands (gfx1013_direct_graphics.inl). On top of that, the decoder refuses a lane read whose scalar destination is above s105, so vcc_lo gets "invalid scalar lane read destination" (gfx1013_compute_native.cpp:361-365). The usual source of these instructions is SGPR spilling into VGPR lanes.

Measured on a local capture of 2,689 compute requests (counts and instruction shape only). Occurrences are static instruction counts in each program up to its s_endpgm, not executed counts. A request counts once per row if it contains at least one such instruction, and can appear in several rows.

Form Requests Occurrences
v_readlane_b32 to an SGPR, constant lane 1,066 411,343
v_writelane_b32, constant lane 887 417,790
v_readlane_b32 to vcc_lo, constant lane 686 13,022
v_readlane_b32 to an SGPR, lane in an SGPR 72 3,375

I also ran compile_dxil --jobs 8 gfx1013-direct-cs@36 --requests over the same capture. Its request reader was patched locally to main's 28cs revision (the change in #2939), and #2937 was applied. 625 requests stop first at "invalid scalar lane read destination".

Plan (in gfx1013_compute_native.cpp and gfx1013_direct_compute.inl, next to v_readfirstlane_b32):

  • v_readlane_b32 sD, vS, lane:
    • waveReadLaneAt(vS, lane & 31) for wave32;
    • for a split guest wave64, take the half that lane & 63 selects, with exchange_halves as v_readfirstlane_b32 does;
    • the lane is a constant, or an SGPR read as a uniform value.
  • v_writelane_b32 vD, sS, lane: write sS to vD only in the selected lane; other lanes keep vD. Per the RDNA2 ISA description, v_writelane_b32 ignores EXEC, and the test checks that.
  • Accept vcc_lo (106) as the destination of v_readlane_b32 and v_readfirstlane_b32 in direct compute, written like the other scalar writes to VCC. In wave64 only 106 is written and 107 is kept.
    • The decoder check at line 361 is shared, so it is relaxed and 106 is refused again in the graphics paths and in the HLSL-native compute path (gfx1013_compute_native.cpp:1062).
    • vcc_hi, exec, m0 and the rest stay refused.
  • Add v_readlane_b32 to the multi-wave64 convergence guard (gfx1013_compute_native.cpp:1474), since it uses exchange_halves.
  • Refuse when the selected lane may have no host thread: a thread count that is not a multiple of 32, or a constant lane beyond the wave's thread count. A lane held in an SGPR requires full waves.
  • Keep refused: modifiers, a lane source that is not a constant or an SGPR, and VGPR ranges out of bounds.
  • Scope: values are lowered numerically. transfer clears the destination symbol (gfx1013_compute_native.cpp:504-507), so a spilled descriptor, pointer or lane mask does not keep its symbol through a refill. Carrying the symbol through is a follow-up; main needed #2759 for the same thing. Some of the 625 requests will therefore stop later on that.

Tests, in the style of native_dpp_mirror_check.py, on hardware against a CPU reference, with a capability skip where 32-lane waves are unavailable:

  • spill and refill round trips through several lanes;
  • a readlane into vcc_lo that then feeds v_cndmask;
  • a lane held in an SGPR;
  • v_writelane with lanes disabled by EXEC;
  • refusals for a partial wave and for vcc_hi.

Mutants: read lane lane ^ 1, and let v_writelane honour EXEC.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6636089980 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/2940). Originally posted by [Leyukaka](https://github.com/Leyukaka) on 2026-11-26T22:25:12Z. --- Target branch `cpp-migration`. Part of #2935 (instruction coverage). I am taking this; please say if you already have it locally and I will drop it. **Gap:** the direct C++ compute path lowers `v_readfirstlane_b32` but not `v_readlane_b32` or `v_writelane_b32`. Those two exist only inside pixel full-wave islands (`gfx1013_direct_graphics.inl`). On top of that, the decoder refuses a lane read whose scalar destination is above `s105`, so `vcc_lo` gets "invalid scalar lane read destination" (`gfx1013_compute_native.cpp:361-365`). The usual source of these instructions is SGPR spilling into VGPR lanes. **Measured** on a local capture of 2,689 compute requests (counts and instruction shape only). Occurrences are static instruction counts in each program up to its `s_endpgm`, not executed counts. A request counts once per row if it contains at least one such instruction, and can appear in several rows. | Form | Requests | Occurrences | |---|---:|---:| | `v_readlane_b32` to an SGPR, constant lane | 1,066 | 411,343 | | `v_writelane_b32`, constant lane | 887 | 417,790 | | `v_readlane_b32` to `vcc_lo`, constant lane | 686 | 13,022 | | `v_readlane_b32` to an SGPR, lane in an SGPR | 72 | 3,375 | I also ran `compile_dxil --jobs 8 gfx1013-direct-cs@36 --requests` over the same capture. Its request reader was patched locally to main's `28cs` revision (the change in #2939), and #2937 was applied. 625 requests stop first at "invalid scalar lane read destination". **Plan** (in `gfx1013_compute_native.cpp` and `gfx1013_direct_compute.inl`, next to `v_readfirstlane_b32`): - `v_readlane_b32 sD, vS, lane`: - `waveReadLaneAt(vS, lane & 31)` for wave32; - for a split guest wave64, take the half that `lane & 63` selects, with `exchange_halves` as `v_readfirstlane_b32` does; - the lane is a constant, or an SGPR read as a uniform value. - `v_writelane_b32 vD, sS, lane`: write `sS` to `vD` only in the selected lane; other lanes keep `vD`. Per the RDNA2 ISA description, `v_writelane_b32` ignores EXEC, and the test checks that. - Accept `vcc_lo` (106) as the destination of `v_readlane_b32` and `v_readfirstlane_b32` in direct compute, written like the other scalar writes to VCC. In wave64 only 106 is written and 107 is kept. - The decoder check at line 361 is shared, so it is relaxed and 106 is refused again in the graphics paths and in the HLSL-native compute path (`gfx1013_compute_native.cpp:1062`). - `vcc_hi`, `exec`, `m0` and the rest stay refused. - Add `v_readlane_b32` to the multi-wave64 convergence guard (`gfx1013_compute_native.cpp:1474`), since it uses `exchange_halves`. - Refuse when the selected lane may have no host thread: a thread count that is not a multiple of 32, or a constant lane beyond the wave's thread count. A lane held in an SGPR requires full waves. - Keep refused: modifiers, a lane source that is not a constant or an SGPR, and VGPR ranges out of bounds. - Scope: values are lowered numerically. `transfer` clears the destination symbol (`gfx1013_compute_native.cpp:504-507`), so a spilled descriptor, pointer or lane mask does not keep its symbol through a refill. Carrying the symbol through is a follow-up; main needed #2759 for the same thing. Some of the 625 requests will therefore stop later on that. **Tests**, in the style of `native_dpp_mirror_check.py`, on hardware against a CPU reference, with a capability skip where 32-lane waves are unavailable: - spill and refill round trips through several lanes; - a readlane into `vcc_lo` that then feeds `v_cndmask`; - a lane held in an SGPR; - `v_writelane` with lanes disabled by EXEC; - refusals for a partial wave and for `vcc_hi`. Mutants: read lane `lane ^ 1`, and let `v_writelane` honour EXEC. AI-assisted.
Leyukaka commented 2026-11-26 22:54:15 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-11-26T22:54:15Z.


Scope change in the pull request for this issue: vcc_hi is accepted as a lane-read destination in direct compute after all. In wave32 it is ordinary scalar data (s107), and a 64-bit read of VCC reads s106:s107. The measured programs refill a spilled VCC pair with v_readlane_b32 vcc_lo followed by v_readlane_b32 vcc_hi, so keeping vcc_hi refused would stop them one instruction later. In wave64 s107 stays the high half of VCC; the graphics and HLSL paths still refuse both.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7205084372 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/2940#issuecomment-7205084372). Originally posted by [Leyukaka](https://github.com/Leyukaka) on 2026-11-26T22:54:15Z. --- Scope change in the pull request for this issue: `vcc_hi` is accepted as a lane-read destination in direct compute after all. In wave32 it is ordinary scalar data (s107), and a 64-bit read of VCC reads s106:s107. The measured programs refill a spilled VCC pair with `v_readlane_b32 vcc_lo` followed by `v_readlane_b32 vcc_hi`, so keeping `vcc_hi` refused would stop them one instruction later. In wave64 s107 stays the high half of VCC; the graphics and HLSL paths still refuse both. AI-assisted.
MasterDomino commented 2026-11-26 23:17:10 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by MasterDomino on 2026-11-26T23:17:10Z.


Closed by #2950, merged into cpp-migration as 641add96. native_lane_access_hardware passes on an RTX 5080 (author) and on an RX 9070 XT, and a lane-^1 mutation fails it. AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7205413073 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/2940#issuecomment-7205413073). Originally posted by [MasterDomino](https://github.com/MasterDomino) on 2026-11-26T23:17:10Z. --- Closed by #2950, merged into `cpp-migration` as `641add96`. `native_lane_access_hardware` passes on an RTX 5080 (author) and on an RX 9070 XT, and a lane-^1 mutation fails it. AI-assisted.
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#2940
No description provided.