Skip to content

fix(shader): translate two wave64 compute shapes on 32-lane hosts again - #593

Merged
pragyaangaur merged 6 commits into
pragyaangaur:mainfrom
earpjonathan:shader/wave64-reduce
Nov 28, 2026
Merged

pragyaangaur merged 6 commits into
pragyaangaur:mainfrom
earpjonathan:shader/wave64-reduce

Conversation

@earpjonathan

Copy link
Copy Markdown
Contributor

Two wave64 compute shapes have been refused on hosts of 32-lane waves (D3DMetal) since recent changes. Each refusal dropped a program's dispatches every frame. This makes both translate again, with a synthetic test for each.

A wave reduction after a loop the lanes leave one by one (a1bf269d5b19f025, refused at 0x1d4 as "a wave reduction over both 32-lane halves")

A branch both of whose targets are loop back edges (fdd56d97a806bcca, refused at 0x93c as "a wave64 branch with two loop back edges")

  • Two nested loops share a latch. Its branch goes back to the inner loop's header or falls through to the outer loop's header. The whole-wave retry from feat(shader): retry refused 64-thread wave64 compute with whole-wave control flow #435 refused it, because a branch could cap only one of its two back edges.
  • Each side now gets a block of its own. It counts that loop's iteration, goes to the header below the limit, and leaves the program at the limit, as an unconditional back edge does. In whole-wave control flow both halves take the same side with the same counts.
  • The new code is in lower/back_edges.rs.

cbf9b65f2249ba96 also translates now. Its per-lane translation was refused through the same cap analysis, and the whole-wave retry then refused a gather in it.

Tests

  • New in halves_tests.rs:
    • A per-lane counted loop with an unconditional back edge, followed by the console compiler's whole-wave sum, in groups of 64, 96 and 128 threads. It is refused with the switch on and translates with it off.
    • Two loops sharing a latch, in whole-wave halves.
  • Both run on the host GPU. Under Wine with D3DMetal, 0 lanes differ from the console.
  • WINEDLLOVERRIDES="d3d12,d3d12core,dxgi=b" tools/macos/test-wine.sh -p victory-shader --no-fail-fast: 481 passed, 0 failed, 5 ignored.
  • cargo test -p xtask passed, and cargo xtask policy reports 299 files ok.
  • Clippy for x86_64-pc-windows-gnullvm --workspace --all-targets -- -D warnings, with and without --all-features: clean.
  • Offline translation of 39 dumped compute programs with the runtime's Wine options:
    • Three more translate.
    • 6b82bc7d22016cb5 is still refused, now for "no group-shared memory left" at 0x36fc.
    • The other 35 translate byte-for-byte as on main.

In game (M5 Pro, 48 GB, macOS 27.0.1, CrossOver 26.3 Wine with the repo's patches, D3DMetal 4.0 beta 3, Series X, a scripted opening run cold and then warm; figures from the warm run)

  • a1bf269d5b19f025, fdd56d97a806bcca and cbf9b65f2249ba96 translate in both runs. 35 compute programs are refused, against 38 on main a31fcca1.
  • Dropped dispatches ("dropped N/frame without a host pipeline" reports over the run), main a31fcca1 → this branch:
    • a1bf269d: 58 → 0
    • fdd56d97: 58 → 0
    • cbf9b65f: 2 → 0
  • No new errors: 76 matches for panic, device removed or hang, against 77 and 75 in two main baselines. All of them are copystat info lines.
  • Frame time: median 399 ms (GPU 224 ms), and 461 ms over the last part of the run. The nearest baseline, a d1609d9d build, had a 385 ms median and 388 ms late. That is a different base, so the two runs are not directly comparable.
  • Late in the run the scene is dark (frames at 13–18), the same as main without fix(shader): let each 32-lane half run a register-index waterfall itself #589. That darkness comes from another program this base still refuses, not from this change.

🤖 Generated with Claude Code

A wave reduction after a loop the lanes leave one by one was refused in
halves since pragyaangaur#408: its half-wave analysis took a lane as possibly
leaving at a capped back edge's iteration limit, both in the step
analysis and through a virtual exit in `branch_regions`, so everything
after such a loop looked divergent. pragyaangaur#506 made the matching `s_barrier`
refusal opt-in (`VICTORY_CAP_BARRIERS=1`); the halves pass values
through group barriers too, so the cap-escape analysis now follows the
same switch. Off, the cap is taken as never reached where the loop has
a way out of its own, as the console runs every loop to its end; a
closed loop keeps its virtual exit. Tests run with the refusal on
unless they turn it off.

In whole-wave halves (pragyaangaur#435), a branch both of whose targets are loop
back edges (two nested loops sharing a latch) was refused. Each side
now gets a block of its own that counts its loop's iteration and leaves
the program at the limit, as an unconditional back edge does
(`lower/back_edges.rs`).

Tests: synthetic programs for both shapes, checked against the console
on the host GPU.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@hackgods

Copy link
Copy Markdown
Contributor

A note for merging: a1bf269d5b19f025 is also among the programs #591 brings back. #591 runs single-exit while loops in lockstep in halves, so the reduction after the loop sees the halves in step. The two routes differ (#591 changes predication; this PR changes the capped-latch analysis), and both touch halves_tests.rs. Whichever goes in second may just need its tests appended after the other's. fdd56d97a806bcca is not covered by #591, so the two complement each other.

Claude Code (Claude Opus 5.5).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants