shader: cover subvector loop markers #3675

Merged
lambirou merged 2 commits from upstream-pr/3675 into main 2026-12-02 19:03:51 +00:00
lambirou commented 2026-12-01 00:08:12 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by lambirou on 2026-12-01T00:08:12Z.


Problem

pixel_aot refused s_subvector_loop_begin and s_subvector_loop_end, so both SOPK forms stayed unobserved and any source-built pixel program using the pair could not be translated. The RDNA 2 ISA defines the pair as a conditional two-half EXEC loop, not as a generic no-op; a reduction is valid only for a restricted per-lane body.

Change

  • Adds plan_subvector_loops(), which validates the SOPK pair against the RDNA 2 ISA section 12.2, opcodes 27 and 28 before lowering it.
  • Both markers must name the same s0-s105 scratch SGPR. Begin targets the instruction after end, end targets the instruction after begin, the displacements must fit signed 16 bits, the pair must be top-level with the entry mask, and the scratch SGPR must be dead outside the pair.
  • The body is restricted to per-lane vector ALU plus NOP/wait/prefetch/priority/sleep/clause hints. EXEC/VCC/SCC writes, compares, cross-lane operations, DPP, carry/borrow writers, memory, exports and crossing branches are refused. Under that contract one full-mask pass has the same per-lane register effect as the wave64 two-half passes, and wave32 runs the entry-mask pass once. The markers emit no state and the body lowers once.
  • Unpaired, nested, mistargeted, empty, post-export and masked-region pairs are refused with explicit messages. s_endpgm_saved and s_endpgm_ordered_ps_done are unaffected.
  • Adds controls, a source-built draw, LLVM encoding checks, CTest entries, a coverage pin and docs/experiments/pixel-subvector-loops.md.

Tests

Commands run in the worktree:

C:/Users/rolandedi/dev/labs/xbox-recomp/Xbox2Windows/out/pe-env/Scripts/python.exe -B tests/form_coverage_check.py
C:/Users/rolandedi/dev/labs/xbox-recomp/Xbox2Windows/out/pe-env/Scripts/python.exe -B tests/docs_links_check.py
C:/Users/rolandedi/dev/labs/xbox-recomp/Xbox2Windows/out/pe-env/Scripts/python.exe -B tests/rdna2_tools_check.py
ctest --test-dir out/build/dev --no-tests=error -R ^pixel_aot_subvector_loops_ -V

Results:

  • CTest controls, WARP draw and hardware draw: 3/3 passed in 18.0 s, no skips.
  • Hardware: AMD Radeon RX 9060 XT, driver 32.0.32029.2010, Windows 11 build 26300, debug layer unavailable. WARP: Microsoft Basic Render Driver 10.0.26100.10068.
  • form_coverage_check.py: form coverage checks passed.
  • docs_links_check.py: 193 Markdown files and 746 links checked.
  • rdna2_tools_check.py: 161 tests OK, with 19 LLVM-dependent capability skips reported separately.
  • LLVM 15 binary/encoding controls pin the two gfx10 SOPK words.

Coverage delta

The records contain exactly s_subvector_loop_begin and s_subvector_loop_end, both present in docs/coverage/gfx1013.tsv and docs/coverage/rdna2.tsv: +2 gfx1013 and +2 gfx1030 in the isolated measurement.

Limits

This is desktop DXIL evidence, not a console run. The wave64 reduction is proven only for the stated per-lane body with no wave-state, memory or cross-lane effects; nested loops and bodies that let the working EXEC half become zero remain refused. No claim is made about arbitrary real-world subvector bodies.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5576138812 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3675). Originally posted by [lambirou](https://github.com/lambirou) on 2026-12-01T00:08:12Z. --- ## Problem pixel_aot refused s_subvector_loop_begin and s_subvector_loop_end, so both SOPK forms stayed unobserved and any source-built pixel program using the pair could not be translated. The RDNA 2 ISA defines the pair as a conditional two-half EXEC loop, not as a generic no-op; a reduction is valid only for a restricted per-lane body. ## Change - Adds plan_subvector_loops(), which validates the SOPK pair against the RDNA 2 ISA section 12.2, opcodes 27 and 28 before lowering it. - Both markers must name the same s0-s105 scratch SGPR. Begin targets the instruction after end, end targets the instruction after begin, the displacements must fit signed 16 bits, the pair must be top-level with the entry mask, and the scratch SGPR must be dead outside the pair. - The body is restricted to per-lane vector ALU plus NOP/wait/prefetch/priority/sleep/clause hints. EXEC/VCC/SCC writes, compares, cross-lane operations, DPP, carry/borrow writers, memory, exports and crossing branches are refused. Under that contract one full-mask pass has the same per-lane register effect as the wave64 two-half passes, and wave32 runs the entry-mask pass once. The markers emit no state and the body lowers once. - Unpaired, nested, mistargeted, empty, post-export and masked-region pairs are refused with explicit messages. s_endpgm_saved and s_endpgm_ordered_ps_done are unaffected. - Adds controls, a source-built draw, LLVM encoding checks, CTest entries, a coverage pin and docs/experiments/pixel-subvector-loops.md. ## Tests Commands run in the worktree: C:/Users/rolandedi/dev/labs/xbox-recomp/Xbox2Windows/out/pe-env/Scripts/python.exe -B tests/form_coverage_check.py C:/Users/rolandedi/dev/labs/xbox-recomp/Xbox2Windows/out/pe-env/Scripts/python.exe -B tests/docs_links_check.py C:/Users/rolandedi/dev/labs/xbox-recomp/Xbox2Windows/out/pe-env/Scripts/python.exe -B tests/rdna2_tools_check.py ctest --test-dir out/build/dev --no-tests=error -R ^pixel_aot_subvector_loops_ -V Results: - CTest controls, WARP draw and hardware draw: 3/3 passed in 18.0 s, no skips. - Hardware: AMD Radeon RX 9060 XT, driver 32.0.32029.2010, Windows 11 build 26300, debug layer unavailable. WARP: Microsoft Basic Render Driver 10.0.26100.10068. - form_coverage_check.py: form coverage checks passed. - docs_links_check.py: 193 Markdown files and 746 links checked. - rdna2_tools_check.py: 161 tests OK, with 19 LLVM-dependent capability skips reported separately. - LLVM 15 binary/encoding controls pin the two gfx10 SOPK words. ## Coverage delta The records contain exactly s_subvector_loop_begin and s_subvector_loop_end, both present in docs/coverage/gfx1013.tsv and docs/coverage/rdna2.tsv: +2 gfx1013 and +2 gfx1030 in the isolated measurement. ## Limits This is desktop DXIL evidence, not a console run. The wave64 reduction is proven only for the stated per-lane body with no wave-state, memory or cross-lane effects; nested loops and bodies that let the working EXEC half become zero remain refused. No claim is made about arbitrary real-world subvector bodies. AI-assisted.
lukaslw-lab commented 2026-12-01 02:39:50 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by lukaslw-lab on 2026-12-01T02:39:50Z.

Review: APPROVED


Reviewed 68264630 by reading the diff; not built or run.

Verdict: approve. The pair checks are tight, and under the body contract one entry-mask pass equals the two wave64 half passes. No MUST, no SHOULD.

  • NIT The wave64 reduction holds only if no body instruction writes an SGPR lane mask, because the second half pass would overwrite the first pass's bits. _co, v_cmp*, div_scale and the lane ops are blocked (tools/pixel_aot.py:4144-4148). The VOP3b v_mad_u64_u32 / v_mad_i64_i32 (SGPR carry-out) are blocked only because pixel_aot does not lower them yet. Adding mad_[iu]64 to SUBVECTOR_BODY_CONTROL would keep the proof true once they are lowered.
  • Checked, no finding:
    • Pairing: the begin/end targets are cross-checked against each other's next instruction, the simm16 field is accepted in both LLVM spellings and sign-extended, nesting and unpaired markers are refused, and both markers must name the same SGPR, which may not be an entry SGPR.
    • The scratch SGPR is checked dead everywhere else, ranges included (names_sgpr), so its post-loop value never matters.
    • Branches into or across the pair, calls and indirect branches are refused for the whole program. plan_subvector_loops runs on the pre-inline list, but inline_calls is then a no-op, so the subvector_at indices match positioned.
    • The markers are refused in a masked region, under a non-entry mask and after the export. The body admits only plain v_ ALU and scalar hints and waits, with no memory, export, EXEC/VCC/SCC, DPP or cross-lane forms.
    • The new CMake fragment only registers pixel_aot_subvector_loops_{controls,warp,hardware} (skip 77 on the draws).

Tests: subvector-controls proves each pairing, liveness, branch, placement and body refusal, plus the LLVM 15 SOPK encodings. The draw shows that the lowered body matches the CPU reference on WARP and hardware. CI ran the controls at this head (they are in pixel_aot_check.py's default subcheck list). The draws are outside the pr filter.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6124199847 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3675#pullrequestreview-6124199847). Originally posted by [lukaslw-lab](https://github.com/lukaslw-lab) on 2026-12-01T02:39:50Z. **Review:** APPROVED --- Reviewed `68264630` by reading the diff; not built or run. **Verdict: approve.** The pair checks are tight, and under the body contract one entry-mask pass equals the two wave64 half passes. No MUST, no SHOULD. - **NIT** The wave64 reduction holds only if no body instruction writes an SGPR lane mask, because the second half pass would overwrite the first pass's bits. `_co`, `v_cmp*`, `div_scale` and the lane ops are blocked (`tools/pixel_aot.py:4144-4148`). The VOP3b `v_mad_u64_u32` / `v_mad_i64_i32` (SGPR carry-out) are blocked only because `pixel_aot` does not lower them yet. Adding `mad_[iu]64` to `SUBVECTOR_BODY_CONTROL` would keep the proof true once they are lowered. - Checked, no finding: - Pairing: the begin/end targets are cross-checked against each other's next instruction, the simm16 field is accepted in both LLVM spellings and sign-extended, nesting and unpaired markers are refused, and both markers must name the same SGPR, which may not be an entry SGPR. - The scratch SGPR is checked dead everywhere else, ranges included (`names_sgpr`), so its post-loop value never matters. - Branches into or across the pair, calls and indirect branches are refused for the whole program. `plan_subvector_loops` runs on the pre-inline list, but `inline_calls` is then a no-op, so the `subvector_at` indices match `positioned`. - The markers are refused in a masked region, under a non-entry mask and after the export. The body admits only plain `v_` ALU and scalar hints and waits, with no memory, export, EXEC/VCC/SCC, DPP or cross-lane forms. - The new CMake fragment only registers `pixel_aot_subvector_loops_{controls,warp,hardware}` (skip 77 on the draws). Tests: `subvector-controls` proves each pairing, liveness, branch, placement and body refusal, plus the LLVM 15 SOPK encodings. The draw shows that the lowered body matches the CPU reference on WARP and hardware. CI ran the controls at this head (they are in `pixel_aot_check.py`'s default subcheck list). The draws are outside the `pr` filter.
R0Y00 commented 2026-12-02 05:45:35 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-12-02T05:45:35Z.

Review: COMMENTED


The reviewed head now conflicts in tests/form_coverage_check.py and tests/pixel_aot_check.py. Please keep main's SOPP coverage checks and draw-saveexec-family entry alongside the new subvector-loop coverage and draw mode. The assertion that still bans both subvector markers needs to admit those two specifically while keeping the unimplemented control-flow forms refused. Please rerun form_coverage_check.py and the pixel_aot_subvector_loops_ family on the integrated head.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6145406220 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3675#pullrequestreview-6145406220). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-12-02T05:45:35Z. **Review:** COMMENTED --- The reviewed head now conflicts in `tests/form_coverage_check.py` and `tests/pixel_aot_check.py`. Please keep main's SOPP coverage checks and `draw-saveexec-family` entry alongside the new subvector-loop coverage and draw mode. The assertion that still bans both subvector markers needs to admit those two specifically while keeping the unimplemented control-flow forms refused. Please rerun `form_coverage_check.py` and the `pixel_aot_subvector_loops_` family on the integrated head.
R0Y00 commented 2026-12-02 19:02:39 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-12-02T19:02:39Z.

Review: APPROVED


Reviewed 5a6e0d70 on the updated branch. The conflict resolution keeps the existing SOPP and draw-saveexec coverage alongside the subvector fixtures. The controls verify paired markers and refusal of invalid bodies. Independent Windows 11 build 26300 / MSVC Debug ctest --preset dev --no-tests=error -V -j 1 -R '^pixel_aot_subvector_loops_(controls|warp|hardware)$' passed 3/3, with WARP 10.0.26100.9818 and RTX 4060 Laptop 32.0.16.1656 for the GPU fixtures.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6157019674 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3675#pullrequestreview-6157019674). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-12-02T19:02:39Z. **Review:** APPROVED --- Reviewed 5a6e0d70 on the updated branch. The conflict resolution keeps the existing SOPP and draw-saveexec coverage alongside the subvector fixtures. The controls verify paired markers and refusal of invalid bodies. Independent Windows 11 build 26300 / MSVC Debug `ctest --preset dev --no-tests=error -V -j 1 -R '^pixel_aot_subvector_loops_(controls|warp|hardware)$'` passed 3/3, with WARP 10.0.26100.9818 and RTX 4060 Laptop 32.0.16.1656 for the GPU fixtures.
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!3675
No description provided.