perf: M0-indexed register reads as a select tree on M0's bits (up to 7.6x on a 4060 Laptop) #571
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/571"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from LooperSalty/AnyXboxX. Originally posted by KainanP on 2026-11-28T00:02:32Z.
Stacked on #570. This PR uses its census in one test. Merge #570 first, then this PR is the commits
b9adbab8(the change) and446fb7a6(more test cases).What
v_movrels_b32(and the source side ofv_movrelsd_b32) reads the register M0 names,v[src + M0]. It was lowered as oneicmp eq M0, kand oneselectfor every register M0 may name, up to the program's VGPR count. Each select took the one before as its operand, so it was one dependent chain as long as the program's VGPR count.It is now a tree of selects on M0's bits,
log2(count)deep, followed by oneM0 < 2^levelsselect for M0 past the registers. M0 past the registers still reads 0, as before. That is still one select per register, but each read waits for about 8 levels instead of up to 129. The write side (v_movreld) already used independent selects, one per destination register, and is unchanged.Why
This is part of the follow-up to the GPU-timed run on Marvisak/VIctory#3505 (4060 Laptop). 92 % of the card's time is the title's own compute dispatches, so how we translate expensive constructs matters more than our passes. GCN/RDNA compilers emit
v_movrel*for dynamically indexed register arrays. In a loop, the chain was the costliest construct I found in a synthetic bench. Whether the title's slow shaders use it will show in theindexed_selectcount of #570's census (requested on #3505).Bench (RTX 4060 Laptop, driver as installed, synthetic program only)
cargo test -p victory-shader --lib movrel_bench -- --ignored --nocapture. The test runs 2048 groups × 64 threads × 256 rounds ofacc += v[1 + (round & s2)]. Both the round count and the mask are root constants, so no compiler can unroll the loop or prune the range. The figures are median GPU timestamps over 30 dispatches, and every run checks the sums.The tree is now within about 1.4-1.9× of what dxc makes of an HLSL
switch. An indexed local array (alloca) would be closer to HLSL, but the bitcode writer has noallocayet, and storing every candidate register at each read would cost as much as the selects.Tests
an_indexed_read_takes_the_register_m0_names_and_0_past_them(GPU) runs programs whose M0 may name 9, 19 and 129 registers. None is a power of two, and 129 makes the tree 8 levels deep. Each run tries every M0 from 0 to one past the last register (the exact upper bound), the values at, below and past the next power of two, and 1000, 0x80000000 and 0xFFFFFFFF. It compares 64 threads withv[1+M0], or 0 past the program's registers. The console's result past the allocated registers is not specified; 0 is the translation's choice. akimfomin suggested the 9- and 129-register cross-check. It passes on the RTX 4060 Laptop, Intel UHD and WARP, before and after the change, so it guards correctness.an_indexed_read_compares_m0_bits_not_every_register: the read adds at most 126 (fills it keeps alive) + 3 × 8 + 2 arithmetic instructions. It fails before (256: one compare per register) and passes after (151).movrel_bench(ignored): the table above.cargo test -p victory-shader --libon the RTX 4060 Laptop: all pass (342 + 7 ignored). Full pytest (WARP): 1454 passed, 529 skipped.The translator changes, so the shader cache key changes once.
AI use: written, benched and tested by Claude Code (Claude Opus 5.5) for KainanP, on synthetic programs only (no game shader was used).
🤖 Generated with Claude Code
Imported from LooperSalty/AnyXboxX. Originally posted by LooperSalty on 2026-11-28T00:15:44Z.
Main just took #563 (the VIctory copy moved to Vice-Tay
4f15f09e) and #564 (memory stack), and this PR now conflicts inthird_party/victory/crates/victory-shader/src/emit/bitcode.rs,third_party/victory/crates/victory-shader/src/emit/mod.rs. Please rebase on current main, rerun the tests for the files you touch, and force-push.Imported from LooperSalty/AnyXboxX. Originally posted by akimfomin on 2026-11-28T00:26:04Z.
PortBridge checked the #570 → #571 stack at both exact heads. The two heads combine cleanly with each other, but each conflicts against current main
132da61inemit/bitcode.rsandemit/mod.rs. Rebase the census layer first, then replay the M0 change. No build was run.I found Marvisak/VIctory #3630 independently working on the same bit-tree mechanism. Their WARP test has a nine-register case. An independent CPU model also checked all legal indexes at sizes 1–256. Once #570 is rebased, the practical cross-check is a non-power-of-two range such as 9 or 129 and the exact upper boundary, using your expected guest behavior only where it is specified. That keeps the comparison useful without importing either implementation. PortBridge merge-check entry.
The VIctory control now has an independent execution result. On WARP with required DXIL validation, sizes 7, 8 and 9 hit the first and last legal registers, returned zero at the first excluded index, and did not alias on the large index tested. Keep it scoped to the translated-code result on those two VIctory revisions. Exact result and settings.
Imported from LooperSalty/AnyXboxX. Originally posted by LooperSalty on 2026-11-28T00:49:04Z.
Nice speedup, and the tree keeps the old semantics (0 when M0 matches no register, including above the tree). Two points:
TRANSLATOR_VERSION.indexed_readinlower.rschanges the emitted DXIL of every shader that usesv_movrels_b32/v_movrelsd_b32, butvictory-shader/src/lib.rs:29stays at 16, so caches from earlier builds would keep serving the old translation. 17, 18 and 19 are taken by open PRs (#456, #535, #489), so please use 20 (and re-bump if another lands first).movrel_tests.rschecks explicit expected values on the host GPU, which covers non-power-of-two counts and out-of-range M0 well. Please also compare against the reference interpreter (AGENTS.md rule 4), coverv_movrelsd_b32's source path, and add a count of at least 129 registers so the 8-level tree and the1 << levelsbound are exercised. Also confirm the test runs on WARP rather than skipping when there is no GPU.Imported from LooperSalty/AnyXboxX. Originally posted by KainanP on 2026-11-28T00:59:01Z.
Rebased onto the rebased #570 (
a37407f1). The change is nowb9adbab8, and the head is446fb7a6, which adds test cases. It shows MERGEABLE.cargo test -p victory-shader --libon the RTX 4060 Laptop: 369 passed, 0 failed, 21 ignored.@akimfomin, thanks for the cross-check.
an_indexed_read_takes_the_register_m0_names_and_0_past_themnow runs programs whose M0 may name 9, 19 and 129 registers. None is a power of two, and at 129 the tree is 8 levels deep. Each run tries:0x80000000and0xFFFFFFFF.Past the program's registers, the test expects 0. That is the translation's choice; the ISA does not say what the console reads there.
It passes on the RTX 4060 Laptop, Intel UHD and WARP, and also against the old compare chain, so it is a correctness guard. The shape test
an_indexed_read_compares_m0_bits_not_every_registerstill fails on the chain and passes on the tree.Marvisak/VIctory#3630 works independently toward the same select tree; its nine-register case matches the kind of cross-check above. No code was taken from it.
Imported from LooperSalty/AnyXboxX. Originally posted by KainanP on 2026-11-28T12:53:40Z.
@LooperSalty, les deux points de ta revue sont traités dans
a1df4861(nouvelle tête ;b9adbab8, le changement lui-même, ne bouge pas).TRANSLATOR_VERSION= 20. Si une des PR #456, #535 ou #489 passe avant, je remonte le numéro.an_indexed_read_takes_the_register_m0_names_and_0_past_them:v_movrelsd_b32(19 et 129 registres).v_movrelsd_b32 vh, v1écritv[h+M0] = v[1+M0], puisv_movrels_b32relit, pour chaque M0 dont l'écriture reste dans les registres du programme ;1 << levelset au-delà ;crates/anyxboxx-rdna2-ref, règle 4) pour chaque M0 dans les registres du programme. Le binaire est pris dansANYXBOXX_RDNA2_REFou dans letargetdu dépôt, et le test dit quand il ne le trouve pas. Résultat : 232 programmes par adaptateur, identiques à l'interpréteur sur la RTX 4060 Laptop, sur l'Intel UHD et sur WARP. Au-delà des 256 registres que modélise l'interpréteur, celui-ci refuse ; le test garde alors l'attente explicite (0).Par ailleurs, la mesure sur la forme de la dispatch lente du titre (#3505 : 80 groupes, deux vagues de 32, donc limitée par la latence) donne, chaîne → arbre : 0,280 → 0,106 ms (20 VGPR), 0,437 → 0,177 (34), 0,83-1,00 → 0,212 (66), 2,932 → 0,243 (130), soit 2,6 à 12×. Le census de YUYING234 compte
indexed_select=561dans cette dispatch (7b2c3c1d, 50 ms). Je lui ai demandé un A/B en jeu.Assisté par IA (Claude Code) ; tests exécutés sur RTX 4060 Laptop, Intel UHD et WARP.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.