startup: lower constant-trip mesh57 loops outside exchanges (#2413 T6) #2630

Manually merged
github merged 4 commits from gh-pr/2630/head into gh-pr/2630/base 2026-11-27 01:09:05 +00:00
Owner

@⁠SimSalabimse on GitHub · 2026-11-25 23:37 UTC · original
SimSalabimse:cursor/mesh57-t6-loop-lowering-f5d7 → main · +571 −9 · 8 files · 4 commits · merged 2026-11-26 02:40 UTC

Change

Implements #2413 T6 constant-trip loop lowering in translate_mesh57: one proven scalar counted back-edge outside the two modelled group-memory exchanges is unrolled; data-dependent trips, EXEC-carrying bodies, and unconditional back-edges stay refused by slot 57 mesh: a loop outside the group-memory exchanges is not covered.

Extends / supersedes the host-only refusal fixture in #2622: the accepted constant-trip program translates and draws; unsupported shapes keep the exact-string refusal oracle; the once-through mutant (back-edge → s_nop) must fail the constant-trip draw reference.

Refs #2413
Refs #2622
Refs #1759
Refs #870

No R1 runtime, no T5/T7, no compute Dispatch, no shared-interface change beyond mesh_skeleton.

Verification

Commit: e8adb6b7 on SimSalabimse:cursor/mesh57-t6-loop-lowering-f5d7
Tip base: d371ce46 (R0Y00/main)
Claim: #2413

Host (Linux agent):

python3 -B tests/startup_mesh57_loop_check.py
python3 -B tests/startup_mesh57_skeleton_check.py

Result: both ok.

Windows Release (when available on a mesh-capable machine):

ctest --preset release --no-tests=error -j 1 -V -R '^startup_mesh57_loop($|_(warp|hardware)$)'

WARP and one mesh-capable GPU should match the CPU rasteriser; adapters without mesh tier skip 77 (report separately). This agent host is Linux-only, so WARP/hardware draws were not run here.

Evidence and follow-up

  • Source-built gfx1013 program (tests/startup_mesh57_loop.s); no retail .m57.
  • Constant-trip shape: s_mov_b32 s40, 0 then four iterations of s_add_u32 / s_cmp_lt_u32 / s_cbranch_scc1; final s40 == 4 selects vertex red = 1.0.
  • Negative controls: unconditional s_branch back-edge, compare against root constant s8, v_cmpx in the loop body; once-through mutant fails the draw oracle.
  • Follow-up: data-dependent / barrier-crossing / nested loops remain refused; R1 still owns runtime load/forward of translated pairs.

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed.
  • I did not include game files, dumps, distribution links or secrets.

AI-assisted contribution.

**@⁠SimSalabimse** on GitHub · 2026-11-25 23:37 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2630) `SimSalabimse:cursor/mesh57-t6-loop-lowering-f5d7` → `main` · +571 −9 · 8 files · 4 commits · merged 2026-11-26 02:40 UTC ## Change Implements [#2413](https://git.gtahub.st/github/R0Y00--Xbox2Windows/issues/2413) **T6** constant-trip loop lowering in `translate_mesh57`: one proven scalar counted back-edge outside the two modelled group-memory exchanges is unrolled; data-dependent trips, EXEC-carrying bodies, and unconditional back-edges stay refused by `slot 57 mesh: a loop outside the group-memory exchanges is not covered`. Extends / supersedes the host-only refusal fixture in [#2622](https://git.gtahub.st/github/R0Y00--Xbox2Windows/pulls/2622): the accepted constant-trip program translates and draws; unsupported shapes keep the exact-string refusal oracle; the once-through mutant (back-edge → `s_nop`) must fail the constant-trip draw reference. Refs #2413 Refs #2622 Refs #1759 Refs #870 No R1 runtime, no T5/T7, no compute Dispatch, no shared-interface change beyond `mesh_skeleton`. ## Verification Commit: `e8adb6b7` on `SimSalabimse:cursor/mesh57-t6-loop-lowering-f5d7` Tip base: `d371ce46` (`R0Y00/main`) Claim: https://git.gtahub.st/github/R0Y00--Xbox2Windows/issues/2413 Host (Linux agent): ``` python3 -B tests/startup_mesh57_loop_check.py python3 -B tests/startup_mesh57_skeleton_check.py ``` Result: both `ok`. Windows Release (when available on a mesh-capable machine): ``` ctest --preset release --no-tests=error -j 1 -V -R '^startup_mesh57_loop($|_(warp|hardware)$)' ``` WARP and one mesh-capable GPU should match the CPU rasteriser; adapters without mesh tier skip **77** (report separately). This agent host is Linux-only, so WARP/hardware draws were not run here. ## Evidence and follow-up - Source-built gfx1013 program (`tests/startup_mesh57_loop.s`); no retail `.m57`. - Constant-trip shape: `s_mov_b32 s40, 0` then four iterations of `s_add_u32` / `s_cmp_lt_u32` / `s_cbranch_scc1`; final `s40 == 4` selects vertex red = 1.0. - Negative controls: unconditional `s_branch` back-edge, compare against root constant `s8`, `v_cmpx` in the loop body; once-through mutant fails the draw oracle. - Follow-up: data-dependent / barrier-crossing / nested loops remain refused; R1 still owns runtime load/forward of translated pairs. ## Checklist - [x] This pull request covers one reviewable behavior. - [x] I included the exact command and result for every check I ran. - [x] I considered a negative control or failure case for a new fixture. - [x] I updated README/docs when a capability or build requirement changed. - [x] I did not include game files, dumps, distribution links or secrets. AI-assisted contribution.
Accept one proven constant-trip SCC back-edge in translate_mesh57 by unrolling
it; keep data-dependent, EXEC-carrying, and unconditional loops refused by the
existing named reason. Source-built fixture draws with a CPU rasteriser oracle;
the once-through mutant fails that reference.

Co-authored-by: SimSalabimse <[email protected]>
llvm-mc encodes labeled s_cbranch targets differently from the relative
SIMM16 words the fixture embeds; match startup_mesh57_skeleton.s style.

Co-authored-by: SimSalabimse <[email protected]>
Take compare signedness alone, refuse reversed s_sub trip steps, and require
a real draw-reference mismatch for the once-through mutant.

Refs #2413

Co-authored-by: SimSalabimse <[email protected]>
#2405 added s_mul_hi_i32 (and an early arity refuse for both mul_hi forms).
The negative control still expected only one non-IndexError survivor.

Co-authored-by: SimSalabimse <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 01:09:04 +00:00
github manually merged commit 4d6ccf1dd9 into gh-pr/2630/base 2026-11-27 01:09:05 +00:00
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-25 23:53 UTC · original · requested changes

mesh_trip_count currently lets the update opcode pick the comparison's signedness. At 2be6d420, mesh_trip_count(0x7fffffff, 's_add_i32', 1, 's_cmp_gt_u32', 4, 's_cbranch_scc1', True) returns 1. The first update produces 0x80000000, so the unsigned comparison is true and the back-edge is taken. This loop cannot be unrolled within the current 64-step bound. Please take signedness from the compare alone and cover a signed update followed by an unsigned compare across bit 31 in the source-built path. Please also tighten the once-through check to require an actual draw-reference mismatch, like the wrong-pixel control does. Its current assertion can pass on an unrelated PSO or command failure.

**@⁠R0Y00** on GitHub · 2026-11-25 23:53 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2630#pullrequestreview-6066646605) · **requested changes** `mesh_trip_count` currently lets the update opcode pick the comparison's signedness. At `2be6d420`, `mesh_trip_count(0x7fffffff, 's_add_i32', 1, 's_cmp_gt_u32', 4, 's_cbranch_scc1', True)` returns `1`. The first update produces `0x80000000`, so the **unsigned** comparison is true and the back-edge is taken. This loop cannot be unrolled within the current 64-step bound. Please take signedness from the compare alone and cover a signed update followed by an unsigned compare across bit 31 in the source-built path. Please also tighten the once-through check to require an actual draw-reference mismatch, like the wrong-pixel control does. Its current assertion can pass on an unrelated PSO or command failure.
Author
Owner

@⁠Leyukaka on GitHub · 2026-11-25 23:57 UTC · original

Review of head 2be6d420, by reading the diff against main (not run). Two findings that are not in the current review, and one sequence for the signedness point already raised.

1. Reversed subtraction simulates the wrong recurrence. gfx2hlsl.py:1487-1490 accepts the counter as either source (elif ops[2] == counter ...) and keeps only (name, imm), and mesh_trip_count (:1405-1409) then always computes counter - step. Add is commutative, but s_sub_* is not:

s_mov_b32 s40, 5
L: s_sub_u32 s40, 6, s40     ; 6-5 = 1 (taken), 6-1 = 5 (exit): 2 trips, s40 = 5
s_cmp_lt_u32 s40, 4
s_cbranch_scc1 L

The simulation computes 5 - 6 = 0xffffffff, which is not < 4, so it emits one trip and leaves s40 = 1. Refusing a s_sub_* step whose counter is the second source would close it.

2. Dropping the latch hides SCC reads after the loop from descriptor_scc_reads. region_walk (:1641-1653) repeats the body and skips the latch (i = latch + 1), so Stage.ins has no instruction at the latch offset. Stage.descriptor_scc_reads (main :2746-2764) walks by off + size from 0 and stops at off not in instructions (main :2753), so it ends at the body's final s_cmp and checks nothing after the loop. The refusal it would have given is scc from descriptor data in <reader>. A control: after the fixture loop, s_add_u32 s41, s10, 4 (an SCC write the translator does not model, on the descriptor table pointer) then s_cselect_b32 s42, 1, 0 should refuse with that message (not run). A branch reader would be caught separately (a branch reads SCC that is not proven wave-uniform) and would hide the gap.

3. Signedness (already in the review), the other direction: signed = step_name.endswith('_i32') or '_i32' in cmp_name (:1399) also over-unrolls:

s_mov_b32 s40, -3
L: s_add_i32 s40, s40, 1
s_cmp_lt_u32 s40, 0          ; unsigned: 0xfffffffe < 0 is false, so 1 trip
s_cbranch_scc1 L

The simulation compares signed and emits 3 trips.

AI-assisted.

**@⁠Leyukaka** on GitHub · 2026-11-25 23:57 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2630#issuecomment-7178246270) Review of head `2be6d420`, by reading the diff against main (not run). Two findings that are not in the current review, and one sequence for the signedness point already raised. **1. Reversed subtraction simulates the wrong recurrence.** `gfx2hlsl.py:1487-1490` accepts the counter as either source (`elif ops[2] == counter ...`) and keeps only `(name, imm)`, and `mesh_trip_count` (`:1405-1409`) then always computes `counter - step`. Add is commutative, but `s_sub_*` is not: ``` s_mov_b32 s40, 5 L: s_sub_u32 s40, 6, s40 ; 6-5 = 1 (taken), 6-1 = 5 (exit): 2 trips, s40 = 5 s_cmp_lt_u32 s40, 4 s_cbranch_scc1 L ``` The simulation computes 5 - 6 = 0xffffffff, which is not < 4, so it emits one trip and leaves s40 = 1. Refusing a `s_sub_*` step whose counter is the second source would close it. **2. Dropping the latch hides SCC reads after the loop from `descriptor_scc_reads`.** `region_walk` (`:1641-1653`) repeats the body and skips the latch (`i = latch + 1`), so `Stage.ins` has no instruction at the latch offset. `Stage.descriptor_scc_reads` (main `:2746-2764`) walks by `off + size` from 0 and stops at `off not in instructions` (main `:2753`), so it ends at the body's final `s_cmp` and checks nothing after the loop. The refusal it would have given is `scc from descriptor data in <reader>`. A control: after the fixture loop, `s_add_u32 s41, s10, 4` (an SCC write the translator does not model, on the descriptor table pointer) then `s_cselect_b32 s42, 1, 0` should refuse with that message (not run). A branch reader would be caught separately (`a branch reads SCC that is not proven wave-uniform`) and would hide the gap. **3. Signedness (already in the review), the other direction:** `signed = step_name.endswith('_i32') or '_i32' in cmp_name` (`:1399`) also over-unrolls: ``` s_mov_b32 s40, -3 L: s_add_i32 s40, s40, 1 s_cmp_lt_u32 s40, 0 ; unsigned: 0xfffffffe < 0 is false, so 1 trip s_cbranch_scc1 L ``` The simulation compares signed and emits 3 trips. AI-assisted.
Author
Owner

@⁠SimSalabimse on GitHub · 2026-11-26 01:35 UTC · original

Rebased onto current main (includes the pre-exchange execz / mesh_wave_loads path) and addressed the review notes on the prior head:

  • Trip signedness comes from the compare opcode alone; host control covers signed update + unsigned compare across bit 31.
  • Reversed s_sub_* (counter as SRC1) is refused; only commutative s_add_* keeps that operand order.
  • Once-through draw oracle now requires a real draw-reference mismatch (Draw reference mismatch + non-zero mismatches=), not a generic non-zero exit.

Host: python3 -B tests/startup_mesh57_loop_check.py and startup_mesh57_loop_refusal_check.py report ok here. Windows WARP/hardware draw re-run still needed on this head.

AI-assisted.

**@⁠SimSalabimse** on GitHub · 2026-11-26 01:35 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2630#issuecomment-7179932520) Rebased onto current `main` (includes the pre-exchange `execz` / `mesh_wave_loads` path) and addressed the review notes on the prior head: - Trip signedness comes from the compare opcode alone; host control covers signed update + unsigned compare across bit 31. - Reversed `s_sub_*` (counter as SRC1) is refused; only commutative `s_add_*` keeps that operand order. - Once-through draw oracle now requires a real draw-reference mismatch (`Draw reference mismatch` + non-zero `mismatches=`), not a generic non-zero exit. Host: `python3 -B tests/startup_mesh57_loop_check.py` and `startup_mesh57_loop_refusal_check.py` report `ok` here. Windows WARP/hardware draw re-run still needed on this head. AI-assisted.
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-26 02:40 UTC · original · approved these changes

Re-reviewed the current head. The comparison determines signedness, reversed subtraction is refused, and the wrong-trip control requires the intended pixel mismatch. The host loop and scalar-table checks passed. WARP and RTX 4060 Laptop rendered all 1,024 expected pixels and rejected the once-through shader.

**@⁠R0Y00** on GitHub · 2026-11-26 02:40 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2630#pullrequestreview-6067834366) · **approved these changes** Re-reviewed the current head. The comparison determines signedness, reversed subtraction is refused, and the wrong-trip control requires the intended pixel mismatch. The host loop and scalar-table checks passed. WARP and RTX 4060 Laptop rendered all 1,024 expected pixels and rejected the once-through shader.
This discussion has been locked. Commenting is limited to contributors.
No description provided.