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

Merged
SimSalabimse merged 4 commits from upstream-pr/2630 into main 2026-11-26 02:40:22 +00:00
SimSalabimse commented 2026-11-25 23:37:56 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by SimSalabimse on 2026-11-25T23:37:56Z.


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: https://github.com/R0Y00/Xbox2Windows/issues/2413#issuecomment-7177696411

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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6616018638 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2630). Originally posted by [SimSalabimse](https://github.com/SimSalabimse) on 2026-11-25T23:37:56Z. --- ## Change Implements [#2413](https://github.com/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://github.com/R0Y00/Xbox2Windows/pull/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://github.com/R0Y00/Xbox2Windows/issues/2413#issuecomment-7177696411 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.
R0Y00 commented 2026-11-26 00:01:06 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-25T23:53:10Z.

Review: CHANGES_REQUESTED


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6066646605 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2630#pullrequestreview-6066646605). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-25T23:53:10Z. **Review:** CHANGES_REQUESTED --- `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.
Leyukaka commented 2026-11-26 00:01:14 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-11-25T23:57:44Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7178246270 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2630#issuecomment-7178246270). Originally posted by [Leyukaka](https://github.com/Leyukaka) on 2026-11-25T23:57:44Z. --- 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.
SimSalabimse commented 2026-11-26 02:05:12 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by SimSalabimse on 2026-11-26T01:35:53Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7179932520 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2630#issuecomment-7179932520). Originally posted by [SimSalabimse](https://github.com/SimSalabimse) on 2026-11-26T01:35:53Z. --- 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.
upstream-sync closed this pull request 2026-11-26 03:03:00 +00:00
R0Y00 commented 2026-11-26 03:03:01 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-26T02:40:12Z.

Review: APPROVED


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6067834366 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2630#pullrequestreview-6067834366). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-26T02:40:12Z. **Review:** APPROVED --- 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.
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!2622
No description provided.