Repository navigation
feat(shader): retry refused 64-thread wave64 compute with whole-wave control flow - #435
Conversation
…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
de49289 to
9a4652e
Compare
|
Independent M4 Pro result on D3DMetal 4.0 beta 3, using Kolkka’s updated #435 head 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. |
|
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.
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: Prepared with Claude Code. |
|
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
Only #435 was needed for the picture. #433 on top made no visible difference. Prepared with Claude Code. |
|
Thanks for this. Many pull requests landed today, and this one now conflicts with main. Could you merge or rebase main into it, rerun the checks and ping here? I will review and merge it as soon as CI is green. |
|
Heads-up for the rebase, now that #408 is on main. In our local stack (#435 + #408 + #401 on Our resolution of the Prepared with Claude Code. |
DispatchX(x, y, z, flags) with flag 0x20 (the console's dispatch initiator bit "use thread dimensions") gives thread counts. The host ignored the flags and ran x * y * z groups, so a ray-tracing structure builder stage dispatched this way ran up to 64 times its threads and stored over the structures after its own. The host now runs the groups that hold the threads (div_ceil by the program's numthreads, kept in pipeline::Translated). Where the last group along x is a part of one, the dispatch takes a second form of the pipeline (pipeline::thread_limited), made on the first such dispatch: its shader translated again with emit::Options::thread_limits, under a cache key of its own (bit 9 of translation_build, after pragyaangaur#511's halves apart and pragyaangaur#506's cap barriers). In that form a compute program of one dimension whose lanes never wait for each other (no s_barrier, no barriers for narrow host waves, not in 32-lane halves that pass values, not in literal halves, whose group must take one path) reads a user-data word, emit::USER_DISPATCH_THREADS_X, the threads along x that run, and the lanes past it leave before anything else, so wave counts, first-lane reads and stores see only the lanes the console starts. The host sets the word after binding. Every other translation is as before, so programs no such dispatch reaches keep their DXIL; containers of one-dimensional compute programs are kept for the second translation (at most the ~22 MB all compute containers came to in a world run). The lowering's part is in lower/thread_limits.rs and lower/retry.rs, so lower.rs stays under the file limit. Each pipeline's first dispatch counted in threads is logged ("a dispatch counted in threads"), with a warning where a part of a group runs whole. VICTORY_THREAD_DIMENSIONS=0 takes the counts for groups again. Ported from DexNom/VIctory bc3cd4b0 (DexNom: the flag, and the lanes past the count leaving in two builder programs chosen by digest), as carried in the cool_fox fork's 810efe5 (RyanLockwoood/VIctory-cool_fox- LockWood). This tree has no builder detection, hence the form made on demand. Tests: halves_tests::the_lanes_past_a_count_of_threads_do_not_run (wave32 and wave64 on the host, counts 0 to 128 over two groups of 64); halves_tests::only_programs_whose_lanes_never_wait_leave_past_a_count_ of_threads (pragyaangaur#435's whole-wave retry included: a program it takes reads no count); thread_dispatch_tests::a_dispatch_counted_in_threads_runs_ only_those_threads, from a console container through State::dispatch_x: threads 70 to 127 write nothing, the pipeline's own translation reads no count (fails with VICTORY_THREAD_DIMENSIONS=0). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
DispatchX(x, y, z, flags) with flag 0x20 (the console's dispatch initiator bit "use thread dimensions") gives thread counts. The host ignored the flags and ran x * y * z groups, so a ray-tracing structure builder stage dispatched this way ran up to 64 times its threads and stored over the structures after its own. The host now runs the groups that hold the threads (div_ceil by the program's numthreads, kept in pipeline::Translated). Where the last group along x is a part of one, the dispatch takes a second form of the pipeline (pipeline::thread_limited), made on the first such dispatch: its shader translated again with emit::Options::thread_limits, under a cache key of its own (bit 9 of translation_build, after pragyaangaur#511's halves apart and pragyaangaur#506's cap barriers). In that form a compute program of one dimension whose lanes never wait for each other (no s_barrier, no barriers for narrow host waves, not in 32-lane halves that pass values, not in literal halves, whose group must take one path) reads a user-data word, emit::USER_DISPATCH_THREADS_X, the threads along x that run, and the lanes past it leave before anything else, so wave counts, first-lane reads and stores see only the lanes the console starts. The host sets the word after binding. Every other translation is as before, so programs no such dispatch reaches keep their DXIL; containers of one-dimensional compute programs are kept for the second translation (at most the ~22 MB all compute containers came to in a world run). The lowering's part is in lower/thread_limits.rs and lower/retry.rs, so lower.rs stays under the file limit. Each pipeline's first dispatch counted in threads is logged ("a dispatch counted in threads"), with a warning where a part of a group runs whole. VICTORY_THREAD_DIMENSIONS=0 takes the counts for groups again. Ported from DexNom/VIctory bc3cd4b0 (DexNom: the flag, and the lanes past the count leaving in two builder programs chosen by digest), as carried in the cool_fox fork's 810efe5 (RyanLockwoood/VIctory-cool_fox- LockWood). This tree has no builder detection, hence the form made on demand. Tests: halves_tests::the_lanes_past_a_count_of_threads_do_not_run (wave32 and wave64 on the host, counts 0 to 128 over two groups of 64); halves_tests::only_programs_whose_lanes_never_wait_leave_past_a_count_ of_threads (pragyaangaur#435's whole-wave retry included: a program it takes reads no count); thread_dispatch_tests::a_dispatch_counted_in_threads_runs_ only_those_threads, from a console container through State::dispatch_x: threads 70 to 127 write nothing, the pipeline's own translation reads no count (fails with VICTORY_THREAD_DIMENSIONS=0). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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
structure::split_literal):Atom::Any, a 64-lane ballot through the existing exchange).s_cmp_eqon lane masks) sets SCC only when all lanes compare equal, so its scc0/scc1 polarity is the vote's inverse.v_writelane_b32writes its lane regardless of EXEC.group_uniforminbarriers.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.VICTORY_LITERAL_HALVES=0turns the retry off and gets its own shader cache key.lower.rsstays under the asset policy's 512 KiB limit (521,528 bytes).Still refused
Tests
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_NATIVEWINEDLLOVERRIDES="d3d12,d3d12core,dxgi=b" tools/macos/test-wine.sh --workspace --no-fail-fastwith D3DMetal 4.0 beta 3 on an M5: RESULT_WINECost: only for programs refused before. They pay a 64-lane ballot per lane-dependent branch, and the barriers the hazard pass adds.