Repository navigation
perf(shader): reduce a glc-clear 64-bit umax to a representative a texel - #304
Merged
Merged
Conversation
The title's 64-bit image atomics are one operation (pragyaangaur#240): an unsigned maximum of keys into R32G32_UINT texels, the alpha pre-passes' all lanes a wave. The lock cost ~6 s of a 7.4 s world frame on an M2 Pro, and the negative result on pragyaangaur#240 says why no lock-skipping form helps: most of these writes win, so the cost is the serialized sections themselves. A glc-clear umax reads no old value, and the maximum is associative, so the wave first folds each texel's lanes to their maximum key, in registers — one wave-uniform pass a group, two wave maxima a pass — and one representative a group alone runs the rounds and the turns the merged pragyaangaur#257 lands. The reduced lanes are done from the start, as the rounds' helper lanes are. A wave whose lanes meet on one texel locks once instead of 32 times. The reduction rides the rounds (VICTORY_ATOMIC_UMAX=1, only with VICTORY_ATOMIC_LOCK_ROUNDS=1, its own translation cache entry): without them a reduced-to-nothing lane would still take its empty turn. The representative applies the group's maximum key, which equals every member's contribution in any order, ties included, so the result is exact; the first ballot is taken where the guard is live, the loop is wave-uniform, and the lanes the guard kept out contribute the wave maxima's identity. The lock-free forms this replaces cannot be exact: a low-dword maximum is undisplaceable once written, a winner's low-dword store erases a same-high tie's, and every check-then-write leaves a window a racing raiser enters. The reduction never writes outside the lock. The bench gains the form's model: one texel for every lane falls from 64 barriers and 32 attempts to 2 and 1; four lanes a texel to 2 and 8. The test the issue asked for compares the form against the locks on random keys with high-dword ties, one group and eight. Co-Authored-By: GLM 5.3 <noreply@z.ai>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
#240 measured the emulated 64-bit image atomics at ~6 s of every 7.4 s world frame on an M2 Pro, and its disassembly found the title's one operation: an unsigned maximum of 64-bit keys into R32G32_UINT texels, all lanes of a wave, in the alpha pre-passes. The issue's negative result is the guide: most of these writes win, so the cost is not lanes waiting on locks but the serialized sections themselves — and the rounds of #257 (opt-in, merged) still leave the colliding shapes at today's cost.
The issue's thread also invited "a special case for 64-bit unsigned max", gated on glc. A lock-free special case cannot be exact — four interleavings close the door:
(0, 7), one lane with(1, 2): raise the high dword, installmax(lo)→(1, 7), a key nobody wrote, bigger than every contribution, and no laterumaxcan remove it.(5,3)raises; T(5,9)ties and writes 9; W installs 3 →(5,3); the max is(5,9).So the form this lands keeps the lock and attacks the count of sections instead: with glc clear, a umax reads no old value and the maximum is associative, so the wave first folds each texel's lanes to their maximum key — in registers, one wave-uniform pass a group, two wave maxima a pass (the group's high dword, then the low dwords of its best) — and one representative a group alone runs the rounds and the turns. The reduced lanes are done from the start, exactly as the rounds' helper lanes are. A wave whose lanes meet on one texel locks once instead of 32 times; the tie case the issue set is decided inside the reduction, in registers, where no other wave can interleave.
Measured — the #261 ruler gains the form's model
Wine/Rosetta medians of the committed bench, 32 lanes a wave (barriers / lock attempts / loop iterations / wave ops a visit):
ns a visit (Wine/Rosetta): the colliding shape falls from 174.7 (turns) and 1839.9 (rounds) to 87.6; the honest price is the all-distinct shape (328.8 — the reduction's wave ops buy nothing there), reported, not hidden. The model asserts what the form claims: same texels as a plain umax, every form, the members never reading an old value, every lock word freed.
The exactness gate, per the issue's ask
image_atomics_of_64_bits_umax_matches_the_locks: random keys, 8 texels, high dwords 0 to 3 so keys often tie and the low dword decides, glc-clear, one group and eight, row 0 identical to the CPU model and to the unreduced rounds; no lock left taken. The existing rounds test now also runs reduced: its glc-set umax must keep the general form (the reduction's gate — the old value is read there), and its per-lane old-value checks would catch a mis-route. WARP gives the triple check where itsheap_atomics64allows.The switch
VICTORY_ATOMIC_UMAX=1(opt-in while measured, only withVICTORY_ATOMIC_LOCK_ROUNDS=1, its own translation-cache slot; the pipeline library's cache test covers the new key). The representative applies the group's maximum key, which equals every member's contribution in any order — so flipping the default after the M2 Pro tables would be its own commit.Verification
cargo build -p victory-gpu --target x86_64-pc-windows-gnullvmgreen; clippy on both feature lanes, the CI-faithful target, true exit 0.victory-shadersuite: 63 environment failures (no SM 6.6 device locally) identical to the clean base, stash-free A/B verified — zero new failures; the new tests' lowering runs locally (they skip only at the device gate).victory-gpusuite: the two pre-existing feat(gpu): add opt-in mach_vm_remap zero-copy title buffer aliasing #207 alias failures only.lower_cs32_withpath on every run.