shader: lower v_readlane_b32 and v_writelane_b32 in the direct C++ compute path #2950

Merged
Leyukaka merged 1 commit from upstream-pr/2950 into cpp-migration 2026-11-26 23:17:07 +00:00
Leyukaka commented 2026-11-26 22:54:13 +00:00 (Migrated from github.com)

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


Fixes #2940 (it needs closing by hand, since the base is not the default branch). Part of #2935. Target branch cpp-migration.

Change (src/gfx1013_compute_native.cpp, src/gfx1013_direct_compute.inl):

  • v_readlane_b32 sD, vS, lane is now lowered in direct compute.
    • It reads the selected lane with waveReadLaneAt.
    • For a split guest wave64, it takes the half from the lane index and exchanges halves as v_readfirstlane_b32 does.
  • v_writelane_b32 vD, sS, lane writes sS to the selected lane only. It uses the unpredicated register store, so guest EXEC does not apply, as in the RDNA2 ISA description.
  • The lane is a constant or an SGPR, masked to the wave width.
  • Refusals:
    • a lane that may have no host thread (a partial wave with an SGPR lane, or a constant lane at or beyond the threads of its wave);
    • modifiers, and other lane operands.
  • v_readlane_b32 joins the multi-wave64 convergence guard.
  • Direct compute now refuses v_readfirstlane_b32 with DPP control or VOP3 modifiers ("readfirstlane modifiers"); they were ignored before. The HLSL profile now names v_readlane_b32 in its refusal ("unsupported HLSL instruction v_readlane_b32") instead of "unsupported opcode".
  • In wave32, s107 starts at zero, like s127.
  • VCC destinations: lane reads may write vcc_lo (s106) and vcc_hi (s107) in direct compute.
    • In wave32, VCC is s106 only and s107 is ordinary scalar data: it can be read by any instruction and written by s_mov_b32 and the lane reads. A 64-bit read of VCC reads s106:s107. s107 is refused as a wave32 v_cndmask mask.
    • In wave64, s107 stays the high half of VCC.
    • The graphics and HLSL paths still refuse both destinations.
  • This differs from the plan in #2940, which kept vcc_hi refused. The measured programs refill a spilled VCC pair with v_readlane_b32 vcc_lo, … followed by v_readlane_b32 vcc_hi, …, so refusing vcc_hi would stop them one instruction later.

Tests. The setup was Windows 11 with an NVIDIA GeForce RTX 5080 and DXC from the Windows SDK 10.0.26100, on cpp-migration a990f323 plus this commit.

  • native_lane_access_hardware passed. It covers two 32-lane wave32 groups, 768 words plus guards, against an independent CPU model:
    • spill and refill through lanes 0, 5 and 31;
    • an SGPR lane selector that changes with the group;
    • v_writelane with EXEC narrowed to one lane;
    • lane reads into vcc_lo feeding v_cndmask_b32, and into vcc_hi;
    • s_mov_b32 vcc_hi read back, and the high word of a wave32 VCC pair copy.
  • The same test also checks refusals: partial waves, lane operands, encodings, s108, and VCC destinations in the HLSL profile.
  • Not covered by the fixture: the wave64 half selection, multi-wave groups, and an accepted partial-wave constant lane.
  • native_dpp_quad_*, native_dpp_mirror_hardware and native_compute_clear still pass.

Mutation checks, run by hand; each fails the test:

  • reading lane lane ^ 1;
  • letting v_writelane honour EXEC;
  • reading vcc_hi as 0 in wave32;
  • reading the high word of a wave32 VCC pair as 0.

Measured on a local capture (counts and instruction shape only) with compile_dxil --jobs 8 gfx1013-direct-cs@36 --requests built from this branch.

  • Of 2,689 compute requests, 243 compiled without this commit (with #2937 and #2939) and 264 with it.
  • The 625 requests that stopped at "invalid scalar lane read destination" (v_readlane_b32 vcc_lo) now get past it.
  • The largest group of them then stops at "direct resource-heap load requires the selected GPU slot and its view type" (#2908).
  • The runtime still uses the Python translator, so I matched pipelines by request key against a 600 s start-up run. 9 of the 21 newly compiled pipelines were dispatched 4,994 times in that run, and the Python translator had left 2,838 of those dispatches untranslated.
  • Values are lowered numerically. A spilled descriptor, pointer or lane mask does not keep its symbol through a refill.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5518241747 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2950). Originally posted by [Leyukaka](https://github.com/Leyukaka) on 2026-11-26T22:54:13Z. --- Fixes #2940 (it needs closing by hand, since the base is not the default branch). Part of #2935. Target branch `cpp-migration`. **Change** (`src/gfx1013_compute_native.cpp`, `src/gfx1013_direct_compute.inl`): - `v_readlane_b32 sD, vS, lane` is now lowered in direct compute. - It reads the selected lane with `waveReadLaneAt`. - For a split guest wave64, it takes the half from the lane index and exchanges halves as `v_readfirstlane_b32` does. - `v_writelane_b32 vD, sS, lane` writes `sS` to the selected lane only. It uses the unpredicated register store, so guest EXEC does not apply, as in the RDNA2 ISA description. - The lane is a constant or an SGPR, masked to the wave width. - Refusals: - a lane that may have no host thread (a partial wave with an SGPR lane, or a constant lane at or beyond the threads of its wave); - modifiers, and other lane operands. - `v_readlane_b32` joins the multi-wave64 convergence guard. - Direct compute now refuses `v_readfirstlane_b32` with DPP control or VOP3 modifiers ("readfirstlane modifiers"); they were ignored before. The HLSL profile now names `v_readlane_b32` in its refusal ("unsupported HLSL instruction v_readlane_b32") instead of "unsupported opcode". - In wave32, s107 starts at zero, like s127. - **VCC destinations:** lane reads may write `vcc_lo` (s106) and `vcc_hi` (s107) in direct compute. - In wave32, VCC is s106 only and s107 is ordinary scalar data: it can be read by any instruction and written by `s_mov_b32` and the lane reads. A 64-bit read of VCC reads s106:s107. s107 is refused as a wave32 `v_cndmask` mask. - In wave64, s107 stays the high half of VCC. - The graphics and HLSL paths still refuse both destinations. - **This differs from the plan in #2940**, which kept `vcc_hi` refused. The measured programs refill a spilled VCC pair with `v_readlane_b32 vcc_lo, …` followed by `v_readlane_b32 vcc_hi, …`, so refusing `vcc_hi` would stop them one instruction later. **Tests.** The setup was Windows 11 with an NVIDIA GeForce RTX 5080 and DXC from the Windows SDK 10.0.26100, on `cpp-migration` `a990f323` plus this commit. - `native_lane_access_hardware` passed. It covers two 32-lane wave32 groups, 768 words plus guards, against an independent CPU model: - spill and refill through lanes 0, 5 and 31; - an SGPR lane selector that changes with the group; - `v_writelane` with EXEC narrowed to one lane; - lane reads into `vcc_lo` feeding `v_cndmask_b32`, and into `vcc_hi`; - `s_mov_b32 vcc_hi` read back, and the high word of a wave32 VCC pair copy. - The same test also checks refusals: partial waves, lane operands, encodings, s108, and VCC destinations in the HLSL profile. - Not covered by the fixture: the wave64 half selection, multi-wave groups, and an accepted partial-wave constant lane. - `native_dpp_quad_*`, `native_dpp_mirror_hardware` and `native_compute_clear` still pass. **Mutation checks**, run by hand; each fails the test: - reading lane `lane ^ 1`; - letting `v_writelane` honour EXEC; - reading `vcc_hi` as 0 in wave32; - reading the high word of a wave32 VCC pair as 0. **Measured on a local capture** (counts and instruction shape only) with `compile_dxil --jobs 8 gfx1013-direct-cs@36 --requests` built from this branch. - Of 2,689 compute requests, 243 compiled without this commit (with #2937 and #2939) and 264 with it. - The 625 requests that stopped at "invalid scalar lane read destination" (`v_readlane_b32 vcc_lo`) now get past it. - The largest group of them then stops at "direct resource-heap load requires the selected GPU slot and its view type" (#2908). - The runtime still uses the Python translator, so I matched pipelines by request key against a 600 s start-up run. 9 of the 21 newly compiled pipelines were dispatched 4,994 times in that run, and the Python translator had left 2,838 of those dispatches untranslated. - Values are lowered numerically. A spilled descriptor, pointer or lane mask does not keep its symbol through a refill. AI-assisted.
MasterDomino commented 2026-11-26 23:17:04 +00:00 (Migrated from github.com)

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

Review: APPROVED


Review of head d8a40dc1, tested merged onto cpp-migration ea07313b. It merges cleanly, and CI on the head is green. Approving and merging.

Code read:

  • v_writelane_b32 selects only on the lane and ignores EXEC, as in RDNA 2.
  • The lane is masked to the wave width.
  • In wave32 compute, s107 is ordinary scalar data that starts at 0, so a 64-bit read of vcc now sees the real s107 instead of a forced 0. v_cndmask_b32 with s107 as its mask source is refused.
  • An SGPR lane in a partial wave, and a constant lane past the last thread, are refused before lowering.
  • The guest wave64 path reads within the physical half and picks the half through exchange_halves. As you note, the fixture does not cover it.

Run on AMD: Windows 11 26300.9974, AMD Radeon RX 9070 XT (driver 32.0.32029.2010), release. ctest --preset release --no-tests=error -R '^native_' gives 38 tests, 37 passed and 1 skipped (77, native_comparison_pso_warp), including native_lane_access_hardware.

Mutation here: reading lane ^ 1 in v_readlane_b32 (physical ^ 1) fails native_lane_access_hardware. With it restored, it passes.

On the VCC change against #2940's plan: allowing vcc_hi for the spilled-pair refill is the right call in wave32 compute, given the s107 handling above.

Small nit, same as on #2937: docs/experiments.md gains a pointer section, while the folder guide asks for the topic file only. I will close #2940 by hand.

AI-assisted; the commands above were run locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6081402125 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2950#pullrequestreview-6081402125). Originally posted by [MasterDomino](https://github.com/MasterDomino) on 2026-11-26T23:17:04Z. **Review:** APPROVED --- Review of head `d8a40dc1`, tested merged onto `cpp-migration` `ea07313b`. It merges cleanly, and CI on the head is green. Approving and merging. **Code read:** - `v_writelane_b32` selects only on the lane and ignores EXEC, as in RDNA 2. - The lane is masked to the wave width. - In wave32 compute, `s107` is ordinary scalar data that starts at 0, so a 64-bit read of `vcc` now sees the real `s107` instead of a forced 0. `v_cndmask_b32` with `s107` as its mask source is refused. - An SGPR lane in a partial wave, and a constant lane past the last thread, are refused before lowering. - The guest wave64 path reads within the physical half and picks the half through `exchange_halves`. As you note, the fixture does not cover it. **Run on AMD:** Windows 11 26300.9974, AMD Radeon RX 9070 XT (driver 32.0.32029.2010), release. `ctest --preset release --no-tests=error -R '^native_'` gives 38 tests, 37 passed and 1 skipped (77, `native_comparison_pso_warp`), including `native_lane_access_hardware`. **Mutation here:** reading `lane ^ 1` in `v_readlane_b32` (`physical ^ 1`) fails `native_lane_access_hardware`. With it restored, it passes. On the VCC change against #2940's plan: allowing `vcc_hi` for the spilled-pair refill is the right call in wave32 compute, given the `s107` handling above. Small nit, same as on #2937: `docs/experiments.md` gains a pointer section, while the folder guide asks for the topic file only. I will close #2940 by hand. AI-assisted; the commands above were run locally.
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
R0Y00/Xbox2Windows!2950
No description provided.