Skip to content

feat(shader): retry refused 64-thread wave64 compute with whole-wave control flow - #435

Open
Kolkka wants to merge 1 commit into
pragyaangaur:mainfrom
Kolkka:shader/literal-halves-retry
Open

Kolkka wants to merge 1 commit into
pragyaangaur:mainfrom
Kolkka:shader/literal-halves-retry

Conversation

@Kolkka

@Kolkka Kolkka commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

In halves (#180), a console wave64 program runs as two host waves of 32 lanes. Some programs are still refused at a cross-half gate: a lane mask read as data, LDS one wave shares without a barrier, or a reduction, first-lane read or lane read across the halves. In GTA VI (Series S) 107 compute shaders were refused this way.

How

  • When the halves translation of a wave64 compute program of exactly 64 threads is refused at one of those gates, the program is translated again with whole-wave ("literal") control flow (structure::split_literal):
    • Every lane follows the console wave's blocks.
    • Raw EXEC guards vector instructions.
    • Per-lane branch predicates become whole-wave votes (Atom::Any, a 64-lane ballot through the existing exchange).
  • Details:
    • Mask equality (s_cmp_eq on lane masks) sets SCC only when all lanes compare equal, so its scc0/scc1 polarity is the vote's inverse.
    • v_writelane_b32 writes its lane regardless of EXEC.
    • The existing LDS hazard pass runs on the literal control flow. Barriers go outside per-lane EXEC guards.
    • Cross-half operations need proven group convergence (group_uniform in barriers.rs), and lane reads need a uniform selector. First-lane reads ballot EXEC before choosing the source half. FP16 reductions keep the original order and rounding.
  • Only programs the halves translation refuses are retried, so programs that translate today are unchanged.
  • VICTORY_LITERAL_HALVES=0 turns the retry off and gets its own shader cache key.
  • lower.rs stays under the asset policy's 512 KiB limit (521,528 bytes).

Still refused

  • Groups other than exactly 64 threads. In GTA VI that is 30 of the 39 that remain.
  • Programs that hit another lowering limit or whose convergence cannot be proved.

Tests

  • New tests in halves_tests.rs. 12 synthetic programs run on the host GPU, and every lane matches the expected console result.
  • cargo clippy --workspace --all-targets -- -D warnings, with and without --all-features, for x86_64-pc-windows-gnullvm.
  • cargo test --workspace: RESULT_NATIVE
  • WINEDLLOVERRIDES="d3d12,d3d12core,dxgi=b" tools/macos/test-wine.sh --workspace --no-fail-fast with D3DMetal 4.0 beta 3 on an M5: RESULT_WINE
  • In the game (M5 MacBook Air, 16 GB), refused compute shaders went from 107 to 39 in the same run.

Cost: only for programs refused before. They pay a 64-lane ballot per lane-dependent branch, and the barriers the hazard pass adds.

…control flow

When the narrow-wave translation refuses a wave64 compute program of
exactly 64 threads at a cross-half gate (a lane mask read as data, LDS
one wave shares without a barrier, a reduction, first-lane or lane read
across the halves), it is translated again with whole-wave control flow:
every lane follows the console wave's blocks, raw EXEC guards vector
instructions, and per-lane branch predicates become whole-wave votes
(Atom::Any). Mask equality sets SCC only when all lanes compare equal,
v_writelane_b32 writes its lane outside EXEC, and LDS barriers go outside
per-lane guards. Ported onto halves from an earlier
split-waves prototype. VICTORY_LITERAL_HALVES=0 turns the retry off (own cache key).

An offline replay of Grand Theft Auto VI's Series S shaders recovers 68 of
the 107 compute shaders refused before. Tests: 378 victory-shader and
364 victory-gpu under Wine/D3DMetal, 223 victory-shader native.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017tiHubszVmvo5uoUAc34Br
@Kolkka Kolkka changed the title Shaders: literal halves retry for 64-thread wave64 compute on 32-lane hosts feat(shader): retry refused 64-thread wave64 compute with whole-wave control flow Nov 26, 2026
@Kolkka
Kolkka force-pushed the shader/literal-halves-retry branch from de49289 to 9a4652e Compare November 26, 2026 21:14
@evan-kolberg

Copy link
Copy Markdown
Contributor

Independent M4 Pro result on D3DMetal 4.0 beta 3, using Kolkka’s updated #435 head 9a4652e on Mac bf99e728 with Lyrnc’s #3365 lowering. The generated cross-half read was refused with retry disabled and matched all 128 lanes with retry enabled. MODE set before the EXEC split survived a conversion after restore. The signed pairs were 0x0bad0000 / 0x0bad8000 in MODE 4 and 0x0bad0001 / 0x0bad8001 in MODE 12. Exact #435 head · Lyrnc’s #3365

The already accepted tagged half reduction and broadcast copy from earpjonathan and draggygaggy-maker also kept 8/8 DXIL pairs byte-identical with retry allowed or disabled, across 32/64/96/128 threads. All 640 hardware lane results matched. This covers the tested ordinary conversion after EXEC restore. earpjonathan’s #425 · draggygaggy-maker’s #3342

Prepared and tested with Codex.

@hackgods

Copy link
Copy Markdown
Contributor

In-game test on an M5 Pro (18-core CPU, 20-core GPU, 64 GB), macOS 27.2.1, CrossOver Wine with D3DMetal 4.0b3, Series X, build 1.0.2.1 from my own dump. Diagnostics build, same prologue autosave and scripted input in both runs. Text and numbers only, no game data.

main bf99e72 + #409 + #401 same + #435 + #433
compute shaders "does not translate" 110 39
draws dropped without a host pipeline, per frame 94–106 ~53
indirect calls dropped, per frame (all indirect dispatch) 68 21
indirect dispatches with work in one captured frame 62 of 895 169 of 950

What it changes on screen: without #435, the producers of the opaque-lighting indirect records were among the refused wave64 programs. So the lighting dispatches ran with zero groups, and the lit HDR target kept pixels from shots many frames old. That showed up as the stale, ghosted layers and the flat dark player silhouette that testers keep reporting, plus overexposure metered from a near-black scene. With #435 the cell scene is correctly lit, the stale layers are gone, and walking and camera input through the movement tutorial look right.

I applied #433 together with #435 and have not separated their effects. Still refused here, by dispatches per frame: b22a16a178976e1b (~25), ceb5eb68cd99cb07 (~8), 82a2ad6d07417d36 (~7), and a few at 1–2.

Prepared with Claude Code.

@earpjonathan

Copy link
Copy Markdown
Contributor

In-game check on an M5 Pro (macOS 27.0.1, CrossOver 26.3 Wine with the repo's current patches, D3DMetal 4.0 beta 3, Series X), with #435 applied on main at bf99e72. Same opening and scripted input each run.

Only #435 was needed for the picture. #433 on top made no visible difference.

Prepared with Claude Code.

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.

4 participants