Repository navigation
Conversation
…xit test (VICTORY_LOOP_ENTRY_EXIT=1, off by default) In a wave64 program predicated for 32-lane halves, lanes that took an early exit (s_cbranch_execz to s_endpgm, predicated in lower/predicate.rs) run on with their block predicate false. The console runs no pass of a later loop for them (its mask starts as EXEC), but here they followed the loop's own exit test, which the structurisation simplified for lanes in EXEC. A stale counter that never meets the test spins them to LOOP_LIMIT (16384) and holds their whole host wave: CS_VisHair (b6df66af105d8b2d) exits on `fcmp oge 0, v15` only, and lanes the stochastic test dropped keep v15 in [0,1), about 0.3 s a frame. With emit::Options::loop_entry_exit (VICTORY_LOOP_ENTRY_EXIT=1, in the shader cache key) a loop exit test becomes `exit || !active` (a select, not an xor of a compare) or `stay && active`, active being the predicate the test runs under, only where that changes nothing but how long those lanes run (lower/entry_exit.rs): every block of the loop runs under that same predicate (no linearised, skip, diamond or lockstep region), no lane operation (barrier, wave or quad op, or one taking implicit derivatives from the quad: Sample, SampleBias, SampleCmp, CalculateLOD, Deriv*) is written in it outside the 64-bit atomics' guarded lock and umax reduction (which involve only the guard's lanes, others offering umax's identity), no s_barrier, scalar memory write, message or v_writelane, and no scalar the loop writes is read after it. For b6df66af105d8b2d the one change is the pixel loop's exit, `select %2950, (fcmp oge 0, %3599), true`, in both the plain and the umax forms. The fixture of its shape (halves_tests) matches the console on the GPU with and without the switch and runs 32768 groups in 3 ms instead of 120. An implicit-LOD image_sample in the loop refuses the rewrite (a fixture spoiler): lanes leaving early would drop out of their quad's derivatives, which in halves they otherwise feed with their preserved, console-equal coordinates. Over the game's 19,139 cached containers: refusals are the same with the switch off and on (72), with it off every translation hashes as before, and with it on 58 translations change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Measured in game on an M5 Pro (48 GB, CrossOver 26.3). Base: d1609d9 + #589 #593 #605 #606 #608 #592 #595 + #594 #604 #607 #609 #613 + this PR. It's the same exe in both rows, run once without the switch and once with
@4TheDoctor This fits your suspicion about the GPU level. Here the switch takes about 80 ms of GPU time off every world frame, and no report line went over 500 ms with it on (7 without). Prepared with Claude Code. |
|
Thanks. We found the same thing independently while profiling an offline replay of one prison-cell Exactness. I read
Survey (19,106 containers of 1.0.2.1, Wine's options, 8 threads):
Replay A/B (one cell frame recorded in the game, interleaved loops, median of 9):
The 13-program runs shared the machine with other jobs (loops vary ±25%), but submissions 2 and 8 Test suggestion. The fixture covers 64 threads and nothing after the loop. I ran an extra test on
I can push the test to a branch if you want it. Default. I'd argue for on, with Relation to #591 (lockstep while loops). #591 also runs this loop in lockstep ( |
…xture upstream pragyaangaur#610 deliberately skips lockstep loops. With pragyaangaur#591 also merged, its fixture loop is taken by pragyaangaur#591's lockstep form (FlatExit::LockstepExit), so the entry-exit rewrite counts 0 there and the test asserts that. A fixture pragyaangaur#591 does not match is needed to cover the rewrite again. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
I merged main into this branch (conflicts in |
|
Tried this on top of current main ( The merge needs the usual both-sides fix in If that's right, #591 may already stop the |
|
A note after reading the lowering code: |
|
Cause: #591. Since 06a9ea2, CS_VisHair (
What #610 still changes on current main (19,106 containers of 1.0.2.1, Wine's options):
Fixture fix. I kept the existing fixture, which now asserts 0 rewrites because #591 takes its pub(in crate::emit) fn fixture(spoiler: Spoiler) -> Vec<u32> {
+ fixture_shaped(spoiler, false)
+}
+/// [`fixture`]'s loop inside an outer loop of the same kind ... as in `63381c3250b287fa`.
+pub(in crate::emit) fn nested_fixture(spoiler: Spoiler) -> Vec<u32> {
+ fixture_shaped(spoiler, true)
+}
+fn fixture_shaped(spoiler: Spoiler, nested: bool) -> Vec<u32> {
...
0xBE98_047E, // s_mov_b64 s[24:25], exec
+ ]);
+ let outer = w.len() + 2;
+ if nested {
+ w.extend([
+ 0xBEA4_047E, // s_mov_b64 s[36:37], exec
+ 0xBF82_0001, // s_branch outer body
+ 0x87FE_2426, // outer latch: s_and_b64 exec, s[38:39], s[36:37]
+ 0xBEA6_047E, // outer body: s_mov_b64 s[38:39], exec
+ 0xBEAC_047E, // s_mov_b64 s[44:45], exec
+ ]);
+ }
+ w.extend([
0xBE94_047E, // s_mov_b64 s[20:21], exec
...
w.push(0xBF85_0000 | (back as u32 & 0xFFFF)); // s_cbranch_scc1 latch
+ if nested {
+ w.extend([
+ 0xBEFE_042C, // s_mov_b64 exec, s[44:45]
+ 0x7C2C_1E80, // v_cmpx_ge_f32 0, v15
+ 0x8AA4_7E24, // s_andn2_b64 s[36:37], s[36:37], exec
+ ]);
+ let back = outer as i32 - (w.len() as i32 + 1);
+ w.push(0xBF85_0000 | (back as u32 & 0xFFFF)); // s_cbranch_scc1 outer latch
+ }
...
fn the_loop_exit_is_rewritten_only_with_the_switch_and_where_exact() {
- let plain = fixture(Spoiler::None);
+ assert_eq!(rewritten(&fixture(Spoiler::None), true), 0);
+ let plain = nested_fixture(Spoiler::None);
assert_eq!(rewritten(&plain, false), 0);
- assert_eq!(rewritten(&plain, true), 1);
- assert_eq!(rewritten(&fixture(Spoiler::ScalarAfter), true), 0);
+ assert_eq!(rewritten(&plain, true), 2);
+ assert_eq!(rewritten(&nested_fixture(Spoiler::ScalarAfter), true), 0);
(likewise NeighbourInside and SampleInside on nested_fixture)
// halves_tests.rs, early_exited_lanes_leave_a_later_loop_as_the_console_on_every_gpu:
- let words = fixture(Spoiler::None);
+ let words = nested_fixture(Spoiler::None);
- assert_eq!((on.loop_entry_exits, off.loop_entry_exits), (1, 0));
+ assert_eq!((on.loop_entry_exits, off.loop_entry_exits), (2, 0));The commit also adds Results on that branch:
Recommendation. There's no need to move the rewrite. The loops #591 takes are already handled: Keep #610 with the fixture fix and the switch off by default:
If you'd rather close it, the cost today is unknown but bounded to those 68 programs (16 in the cell |
|
Ran this PR's tests on an M2 Ultra (64 GB, macOS 26.7.1, D3DMetal 4.0b3) at the current head
At Both in-game measurements above were taken on Everything else passed: |
|
Open PR; please review when time permits. I’m not seeing a merge conflict yet. |
|
Requesting changes: update the fixture and merge to current main. The CI failure is exactly the fixture no longer accounting for #591's lockstep path. The rewrite itself should stay on the per-lane path, unless you can show a lockstep loop that still needs an exit rewrite. |
Summary
In a wave64 compute program predicated for 32-lane halves (#440), lanes that took an early exit keep running with their block predicate false. On the console they run no pass of a later loop (the loop's mask starts as EXEC), but in the translation they follow the loop's own exit test, which the structurisation simplified for lanes in EXEC. A stale counter that never meets the test spins them until
LOOP_LIMIT(16384, #123), and one such lane holds its whole 32-lane host wave.GTA VI's strand hair visibility pass
CS_VisHair(b6df66af105d8b2d) hits this: its pixel loop exits onfcmp oge 0, v15only, and lanes dropped by the stochastic test keepv15in [0, 1).With
VICTORY_LOOP_ENTRY_EXIT=1(off by default, part of the shader cache key), a loop's exit test becomesexit || !active(as a select) orstay && active,activebeing the predicate the test runs under, only where that changes nothing but how long those lanes run (lower/entry_exit.rs):s_barrier, scalar memory write, message orv_writelanein the loop, and no scalar it writes is read after it.Results
Apple M5 (10-core GPU), 16 GB, macOS 27.2, D3DMetal 4.0b3, Series S profile, native 1280x720 (
VICTORY_UPSCALER=6 VICTORY_RENDER_SCALE=1.0), 40 world frames, warm shader cache, on top ofd1609d9:VICTORY_LOOP_ENTRY_EXIT=1With
VICTORY_GPU_TIMING=1and a per-list ranking, the hair list group goes from ~241 ms to ~4 ms per frame. Captures of the same scenes show the hair, faces and the rest unchanged.Verification
d1609d9; with it on 58 translations change, all wave64 compute predicated for halves.halves_tests(early exit, then readfirstlane, then an EXEC-mask loop with a positive dead-lane counter): matches the console on the GPU with and without the switch; 32,768 groups take 3 ms with it and 120 ms without.entry_exit.rs(fixture decode, loop membership, refusals for a scalar read after the loop,s_barrier,v_writelane, implicit-LOD sampling inside the loop).cargo test -p victory-shader --lib: 273 passed. Winehalves: 60 passed.the_loop_entry_exit_switch_keys_the_cachepasses.Not covered: other GPUs and Series X; default stays off until others confirm.
🤖 Generated with Claude Code