Wave64 on 32-lane hosts: several console waves per group, wave reductions, permlanes and ds_(b)permute in halves (+ three fixes) #128
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Belobug--VIctory-Belobug-AMD!128
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-128"
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?
@God489 on GitHub · 2026-11-25 15:03 UTC · original
God489:wave64/multi-wave-groups→main· +1790 −145 · 7 files · 6 commits · openBuilds on #68 (its two commits are the first two here; this adds four). It does the rest of
docs/wave64-on-wave32.md's plan,ds_(b)permuteincluded, and fixes three wrong results:ds_bpermute_b32on hosts with 64-lane waves (5);On 32-lane hosts (every NVIDIA card) a wave64 compute program that reads other lanes still stopped at translation when its group held more than one console wave, or when it used a whole-wave reduction or prefix (HLSL
WaveActiveSum,WavePrefixSumand the like). Both stopped withconsole wave64 lanes on a host without 64-lane waves, the larger of the two reasons in #9 and #15. What #68 left, measured on the title's ownshaders.rpfby adrianmjim (victory translate --validate --list --host-lanes 32-32):01aadd1;console wave64 lanes on a host without 64-lane waves, and this PR is aimed at them.Yoshi-233 measured on #68 that it lowers 147 of the 285 programs a 32-lane build refused; this is aimed at the rest too.
Measured on this PR by adrianmjim (
dc79d82, same run, comment below): all 2,682 compute programs emit and 2,680 validate. No program stops withconsole wave64 lanesany more. The two that fail validation are 384 bytes over 32 KiB of group-shared memory (see "Not tested"). On a 32-64 host 9 programs change, and all validate.What
1. Groups of several console waves (
Lower::pair_meet)A group barrier cannot order the two halves of one console wave when the group holds others, because those take branches of their own. So in a group of more than 64 threads, each console wave's two halves meet on their own, for every exchange (ballots,
v_readlane,v_readfirstlane,v_mbcnt, branch tests) and every LDS meeting from #68:Lower::meet_before), and a branch's test at the end of its block.MEET_INSIDE) instead of splitting the instruction.exitnow records the block an IR block really ends in. The phis after a loop pointed at the block before the meeting, which the validator caught.loop_limit()polls, so a half that left the program early cannot hang the GPU.console_flow_okloses itsthreads <= 64condition. The program's owns_barrierstays a group barrier.2. Whole-wave reductions and prefixes in halves (
Lower::both_halves)A section's value is a reduction or a prefix over the console wave, while the host's wave operation covers one half:
and).console_flow_okno longer excludes programs with sections.3.
v_permlane16/v_permlanex16in halvesThey read within the two rows of a 32-lane half, which is what the doc says and what the lowering already computes from the host lane. They now count as in-half reads, as DPP and
ds_swizzledo, and the refusal in halves is gone. A program whose other-lane reads are only these, DPP and swizzles now splits into two waves of 32 without the console flow.4. A mask operation's SCC read as a number (bug, every host)
WaveActiveAnyTrue(c) ? a : bcompiles tos_and_b64 s, vcc, execthens_cselect. Nothing counted that SCC as reading the mask whole, so the program got no wave size, and each host wave answered for its own lanes:any_lane_of_the_console_wave_chooses_a_value);It counts now:
WaveSize(64)for wave64);5.
ds_bpermute_b32/ds_permute_b32: each half on its own (and a wrong lane on hosts with 64-lane waves)AMD's RDNA ISA reference, 10.4.4: "in wave64 mode the permute operates only across 32 lanes at a time of each half of a wave64. In other words, it executes as if were two independent wave32's." Its list of changes says "DS_PERMUTE/DS_BPERMUTE are limited to 32-lane permutation". Only the index's bits 6:2 count, and a lane that does not run the instruction gives 0. The opcode table's
mod 64is the general form. Measurements on RDNA2 parts reported elsewhere (RX 6800M, the 9800X3D's gfx1036) agree.ds_bpermute_b32read lane((addr + offset) >> 2) & (wave - 1), so in wave64 it crossed into the other half: wrong on hosts with 64-lane waves, and refused on 32-lane hosts. It reads(lane & 32) | (((addr + offset) >> 2) & 31)now, on every host. A lane the host wave runs elsewhere gives 0 (one ballot), where it gave whatever the host had.ds_permute_b32was not translated on any host ("an LDS operation"). Each lane now looks at the 32 lanes of its half: it takes the value of the highest lane that runs the instruction and names it, else 0 (12.13). That is one ballot and 64 lane reads, for an instruction compilers rarely emit.ds_swizzle: a program whose other-lane reads stay in halves splits into two waves of 32 without the console flow, andconsole_flow_okno longer excludes them.opcode_refusals.txtloses both lines: both lower in the audit.6. Scalars a divergent branch leaves (bug, every host) (
Lower::scalars_join_apart)The console wave runs each side of an if/else some lane takes, in code order, so after the join every lane reads the scalars the last side run left. The per-lane form ranks each lane's side and takes the highest with a wave maximum (
Lower::join_scalars), over the host wave. On a 32-lane host that is half the console wave. With lanes 0-31 on the then side and 32-63 on the else side, lanes 0-31 read the then side's value (1) where the console reads the else side's (2). #68 fixed the same thing for scalars after a divergent loop (leave_loops); joins were left.WaveSize(64). Left to choose, RDNA2 drivers ran them in waves of 32, with the same half counts: the twoscalar_counted_in_*tests failed on an RX 6950 XT and an RX 6700 XT (#92, by dutch2005, closed unmerged). #92 asked for 64 lanes for every wave64 program. This asks only for the programs whose scalars depend on it.Programs that translated before
On 32-lane hosts, these move to the console flow:
console_flow_okcovers them);All three gave wrong results before. All three fall back to the per-lane form when the console flow cannot lower them.
On hosts with 64-lane waves, three things change:
WaveSize(64);ds_bpermute_b32reads within its half, and gives 0 from a lane that does not run it;WaveSize(64).Tests
NVIDIA GeForce RTX 3050 (32-32 lanes, driver 610.88), Windows 11 Pro build 26200, debug build. Each test runs on every hardware adapter and is checked lane by lane against the console:
s_bcnt1);v_readlaneof the other half, inside a branch too;v_readfirstlaneacross halves,v_mbcnt, and a mask operation's SCC;wave::tests):v_permlane16/v_permlanex16reversing rows, in groups of 32, 64 and 128.ds_bpermute_b32naming lanet ^ 33(the other half) readst ^ 1. In a branch only even lanes take, it reads 0 from the odd lanes, which keep their value. Groups of 32, 64, 96 and 128.ds_permute_b32where lanes 2d and 2d + 1 both send to lane d: the higher one's value stays, and lanes 16-31 of each half get 0. Also with only even lanes sending, and in groups of 32, 48, 64, 96 and 128.v_readlanein the console flow, in groups of 64, 112, 128 and 256.valu_tests); and in groups of 64, 96, 112, 128 and 256 where each console wave splits its lanes differently (from wave 3 on, every lane takes the then side, so they read 1).On
0e9b505(#68) the 11 new or changedsplit_testsfail:console wave64 lanes on a host without 64-lane wavesora lane permutation in a program split in halves;any_lane_of_the_console_wave_chooses_a_valuegives 7 in the lower half.With this PR they pass, exact. Two tests in
emit::testsasserted the same old refusal and now assert that the program translates and the adapter takes the pipeline.On
1d8a05e(before the permutes) the 4 permute tests fail, each withconsole wave64 lanes on a host without 64-lane waves.On
dc79d82(before (6)) its 3 tests fail: lanes 0-31 read 1, the multi-wave groups read 1 in the halves that took only the then side, and no wave size is declared.Translation corpus, before and after the permutes. I took every opcode-audit fixture, as wave32 programs in groups of 32 and 64 and as wave64 programs in groups of 64, 96, 128 and 256. Each was translated for four hosts (any, 32-64, 32-32, 64-64): 25,152 cases. I compared a hash of the DXIL, or the refusal, between
1d8a05eand this head:ds_bpermute_b32ords_permute_b32: 8 refused before and translated now (32-32), 36 with other DXIL;The same corpus between
dc79d82and this head: all 25,152 are byte-identical. The fixtures are single instructions without branches, so this shows only that (6) moves nothing else.The DXIL for a 32-64 host, read with
dxc -dumpbin(Windows SDK 10.0.26100):WaveSize=64and readsWaveReadLaneAt(x, (WaveGetLaneIndex() & 32) | (((addr + offset) >> 2) & 31)), then a ballot bit test for the zero;ds_permute_b32has one ballot and 64WaveReadLaneAt;Full suite,
cargo test --workspace --locked --no-fail-fast, this machine:main71652a20e9b505)No new failures. The 6 left are the same as on #68: five
xmemtests on Windows 26200 (#8, #107) andrepository_passes_policy(lower.rssize).cargo test -p victory-shader --lib -- --test-threads=1: 287 passed, 0 failed.Two test processes sharing the GPU sometimes hang, on
maintoo. While stress-testing this, I ran the split tests in two processes at once, 15 to 40 rounds each, every round stopped after 120 s:01aadd1, 1 round of 80 hung.Each time several tests hang together,
main's own included (three_dimensional_groups_keep_the_consoles_lanes,in_half_lane_reads_match_the_console_on_every_adapter). The GPU sits idle (6 % utilisation) whileHost::dispatchandHost::drawspin onfence.GetCompletedValue() < 1, which has no time limit. I did not chase it further. A time limit there would turn it into a failure instead of a hang. One process at a time never hung.Clippy finds the same 10 things in
victory-shaderas on #68, none on the lines this changes. I formatted the code I added withrustfmtand the repository'srustfmt.toml, and left the rest of each file as it was.Not tested
dc79d82, before (6), which moves more programs to the console flow on 32-lane hosts and addsWaveSize(64)to some on 64-lane hosts.cargo test -p victory-shader --lib -- split_tests valu_tests --test-threads=1to check it. On an RDNA2 card the twoscalar_counted_in_*tests should pass now.vfx_triangleClip'sCS_CollectTrianglesandCS_CollectTriangles_Meshlets) use all 32 KiB in groups of 1,024 threads, so the 16 console waves' 384 bytes do not fit.MaxGroupSharedMemoryPerGroupand[GroupSharedLimit]. I left them as they are.AI use: Claude Code (Claude Opus 5.5) wrote the change and the tests, ran them on my machine and wrote this description.
🤖 Generated with Claude Code
@God489 on GitHub · 2026-11-25 19:32 UTC · original
@adrianmjim, @Praisser: you both measured #68 on the title itself. This PR is aimed at what was left after it, the programs that still stop with
console wave64 lanes on a host without 64-lane waves. If you have time, could you run the same measurement on this head (dc79d82)?victory translate --validate --list --host-lanes 32-32onshaders.rpf. How many of the 138 now validate, and which reasons the rest stop with.console wave64 lanesrefusals (73 with #68), the draws dropped per frame, and the frame times. When a group has more than 64 threads, the two halves of a console wave meet through polling in group-shared memory. I have not measured what that costs in a frame, so the frame times matter here too.On a Radeon,
ds_bpermute_b32now reads within its 32-lane half (section 5 above).cargo test -p victory-shader --lib -- split_testscovers that, if anyone wants to check it there. Run it as one process: two test processes sharing the GPU can hang, onmaintoo.@adrianmjim on GitHub · 2026-11-25 19:52 UTC · original
@God489, here is the same run as on #68, on this head. Offline numbers from the game's
shaders.rpfon an RX 7900 XT (Windows 11 build 26300, dxil.dll 10.0.26100.0), headdc79d82on01aadd1:victory translate --validate --list, translation and validation only (no pipelines, no readback, no NVIDIA card here, so the 32-lane host is set with--host-lanes 32-32).--host-lanes 32-32, compute01aadd1So of the 138 programs that still stopped with "console wave64 lanes on a host without 64-lane waves" after #68, all 138 now emit and 136 validate; no program stops with that reason any more. The two that fail validation are the case the description mentions under "Groups past 32 KiB of group-shared memory":
vfx_triangleClip:CS_CollectTriangles_cb481f38andCS_CollectTriangles_Meshlets_cb481f38, with "Total Thread Group Shared Memory storage is 33152, exceeded 32768" (384 bytes over). They are the only two in the archive. VS/PS (14,247) and mesh (8,694 of 8,765) are unchanged.On a 64-lane host (
--host-lanes 32-64) the DXIL of 9 programs changes and all of them validate: the fourbvh_skinning:CSComputeSkinningPedBlendShapes*_1c34db0a,ped_standard_head_cs:CS_ComputeStickyLips_18b9c0dcand fourshadowmask:CS_GenerateShadowMasks*Checkerboard*. Every other program is byte for byte the same as on01aadd1(compared by a hash of each program's DXIL).cargo test -p victory-shader --lib -- --test-threads=1: 284 passed, 0 failed, 6 ignored. Not run in the game.@qtLkz on GitHub · 2026-11-25 22:09 UTC · original
Tested on NVIDIA (32-lane waves only): RTX 4070 Ti, driver 621.01, Windows 11 Pro 26300, Rust 1.98.1, this PR on main
4f62c2a.cargo test -p victory-shader --lib --locked -- --test-threads=1: 298 passed, 0 failed. On main this card fails 4 (loop_exit_mask_counted_after_the_loopandmask_grown_inside_a_branch_counted_after_itwith E_INVALIDARG at pipeline creation;scalar_counted_in_a_divergent_loop_read_after_itandscalar_counted_in_nested_divergent_loopswith lanes 0-31 and 32-63 counting different values). All 4 pass with this PR.Note: it doesn't compile together with #110, whose new test calls
build_lanes_cs(body)without theTargetargument this PR adds (valu_tests.rs:1673).AI-assisted (Claude).
@HAL9000RELOADED on GitHub · 2026-11-25 22:53 UTC · original
Radeon run of
bb6f2fc, as asked: RX 7900 XTX (RDNA3, native wave64), driver 32.0.32015.7029, Windows 10 22H2 (19045), Agility SDK 1.620 (#44). Base:a7fa35e(main + #44).victory-shader298 passed, 0 failed (split_testsincluded).ds_bpermutecase (5):bpermute_reads_within_its_halfandpermutes_in_the_console_flowread the wrong lanes on this card. Fort ^ 33with 64 threads, lane 0 gets 33, i.e. it crosses into the other half.So the 64-lane fix is confirmed on real wave64 hardware, and the 32-lane paths cause no regression here.
@Praisser on GitHub · 2026-11-26 03:44 UTC · original
Measured on the RTX 3070 Laptop 8 GB from #121 (32-lane waves), at this PR's current head
bb6f2fc9(one commit pastdc79d82) plus the local pool-size option, release build, no settings. One run into the prologue, 11.4 min, closed by hand. Compared with the #68 run from #121 (01aadd1+ #68, 8.2 min).Shaders refused at translation in the run (distinct programs):
Per frame, median over the 5 s lines with more than 300 draws (37 lines for #68, 38 here):
The two runs did not reach the same spot, so the counts per frame are not like for like. The frame was quicker with about twice the draws, so I see no sign of a cost from the polling in group-shared memory at this level, but I did not isolate it. None of the dropped draws was waiting on a pipeline being made. I did not break them down by program.
Also in this run:
(Run and this report by Claude Code with Claude Opus 5.5 on the account owner's machine, at their request. No title data in it.)
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.