Shaders: ds_bpermute_b32 and ds_permute_b32 across two host waves through a table past the LDS #43
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/43"
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 Zettrox/ztrx. Originally posted by ablmontazer2 on 2026-11-25T05:41:07Z.
The permute pair across two host waves: backward read (
ds_bpermute_b32) and forward write (ds_permute_b32) through a 64-dword table past the LDS.What
The write-up's known gap — five shadow-mask trace programs do not translate yet (
docs/fork-ray-tracing.md) — goes through the checkerboard shadow-mask generators' neighbour read,ds_bpermute_b32. On a host whose waves are at most 32 lanes, a console wave64 program splits into two host waves that exchange through two dwords past the program's LDS. That pair can carry one value per half; a backward permute needs every lane's dword. The lowering refused witha lane permute across two host waveseven where every lane runs the block, and the program fell through the wave64 forms to refusal — which is how the shadow-mask trace programs stayed out.In addition, the write side (
ds_permute_b32) had no lowering: a DXIL wave has no scatter primitive, so programs using it refused as "an LDS operation" (or "LDS the program does not allocate").This PR lowers both instructions through 64 table dwords past the exchange dwords (allocated in the wave64 pre-pass when the program uses either permute and the group is over 32 threads):
ds_bpermute_b32(backward gather)table + 64 * (thread >> 6) + console_lane, unconditionally — a lane its guard holds off stores 0, which is what the console reads for a source lane outside EXEC;(address + offset) >> 2 & 63), and a second barrier lets the slots be reused.ds_permute_b32(forward scatter)(address + offset) >> 2 & 63), taken under its guard — the console writes nothing for a lane outside EXEC, and a zero from a held-off lane could race a lane that does name the slot (this is the one place the pair differ);console_lane), and a second barrier lets the slots be reused;Shared semantics
a lane permute across two host waves where not every lane runs— and names the block, sobranches_aroundfinds the branch for the wave-wide form;with_local_waves(each host wave on its own) it refuses: the console's permutes cross the halves, and local forms cannot exchange;Tests
Backward permute (
ds_bpermute_b32):a_backward_permute_across_two_host_waves_lowers_through_the_table(runs everywhere): the permute throughemiton a host of 32-lane waves.a_backward_permute_across_two_host_waves_needs_its_branch_wave_wide(runs everywhere): the permute in a lane branch — refused per lane, the branch named bybranches_around, and it lowers with the branch taken wave-wide.a_backward_permute_reads_across_the_two_host_waves(Windows + card): every lane reads 32 lanes on, across both halves, and each lane stores its own dword — checked per lane againsts0 + ((t + 32) & 63)on a 32-lane card when the suite has one.a_backward_permute_in_a_lane_branch_needs_the_branch_wave_wide(Windows + card): the wave-wide form on the card, including source lanes outside EXEC reading 0.Forward permute (
ds_permute_b32):a_forward_permute_across_two_host_waves_lowers_through_the_table(runs everywhere): the scatter throughemiton a host of 32-lane waves.a_forward_permute_in_one_host_wave_is_refused(runs everywhere): the same program on a host that keeps the console wave whole refuses with the new reason.a_forward_permute_across_two_host_waves_needs_its_branch_wave_wide(runs everywhere): the permute in a lane branch — refused per lane, the branch named bybranches_around, and it lowers with the branch taken wave-wide.a_forward_permute_writes_across_the_two_host_waves(Windows + card): every lane takes what the lane 32 on wrote to it —s0 + ((t + 32) & 63)on a 32-lane card when the suite has one.a_forward_permute_in_a_lane_branch_needs_the_branch_wave_wide(Windows + card): the wave-wide form on the card; a lane outside EXEC writes nothing and reads no result, and a slot no lane names holds what it had.cargo test -p victory-shader— 175 passed, 2 ignored (no card here).Card test address fix
The two card tests of the backward permute encode their permute's address as v0 (the thread index) where the rest of each test takes it for the lane's byte address v2:
0x0300_0100should be0x0300_0102. They have never run (no card in the suite), and on a card the assertions0 + ((t + 32) & 63)would fail for lanes not divisible by 4. Fixed here; without it the two card tests fail on hardware.Notes
Imported from Zettrox/ztrx. Originally posted by copilot-pull-request-reviewer[bot] on 2026-11-25T05:41:27Z.
Review: COMMENTED
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
[PR #43] Shaders: ds_bpermute_b32 across two host waves through a table past the LDSto [PR #43] Shaders: ds_bpermute_b32 and ds_permute_b32 across two host waves through a table past the LDSImported from Zettrox/ztrx. Originally posted by futurepro62 on 2026-11-25T06:38:36Z.
Full-suite run on Windows. Tested exact head
fa62a17(on its base90b529f). Both new hardware tests fail on this card, the same way every time, off by one lane.Tested
rust-toolchain.toml), DXC + dxil.dll 1.9.2602.17, debug.cargo test --workspace --locked --no-fail-fast: 498 passed, 2 failed, 7 ignored (main90b529fon this machine: 496 passed, 0 failed, 7 ignored).cargo test --locked -p victory-shader --lib a_backward_permute -- --test-threads=1):a_backward_permute_reads_across_the_two_host_waves:lane 1, s0 0x7, left 39, right 40 (wave64_tests.rs:512).a_backward_permute_in_a_lane_branch_needs_the_branch_wave_wide:lane 1, 64 lanes inside, left 96, right 97 (wave64_tests.rs:592).a_backward_permutetests pass.cargo clippy ... -D warningspasses (with and without--all-features): passed.Reading the numbers (not checked further)
s0 + ((t + 32) & 63), so lane 1 with s0 = 7 should be 7 + 33 = 40. It gets 39 = 7 + 32, which is lane 32's value, as if the read lands one lane early when it crosses into the other host wave. The lane-branch test is also short by exactly one at lane 1.Not tested
AI use
Imported from Zettrox/ztrx. Originally posted by ablmontazer2 on 2026-11-25T06:48:38Z.
Thanks for the run. The off-by-one is in the two card tests, not in the lowering: their
ds_bpermute_b32encodes the address asv0(the thread index) instead ofv2(the byte address,v0 << 2), so lane 1 reads(1 + 128) >> 2 = 32instead of 33, which is exactly the 39 vs 40 (and 96 vs 97) you saw; lane 0 happens to pass.Fixed in
657d80c(0x0300_0100->0x0300_0102), which also adds the forward permute (ds_permute_b32) with two more card tests. Could you rerun on the new head657d80c? The four card tests:a_backward_permute_reads_across_the_two_host_wavesa_backward_permute_in_a_lane_branch_needs_the_branch_wave_widea_forward_permute_writes_across_the_two_host_wavesa_forward_permute_in_a_lane_branch_needs_the_branch_wave_wideImported from Zettrox/ztrx. Originally posted by futurepro62 on 2026-11-25T06:51:57Z.
Retest at the new head
657d80c(on base90b529f), on the same machine as my run above: the two tests that failed there now pass.Tested
rust-toolchain.toml), DXC + dxil.dll 1.9.2602.17, debug.cargo test --workspace --locked: 505 passed, 0 failed, 7 ignored.a_backward_permute_reads_across_the_two_host_wavesanda_backward_permute_in_a_lane_branch_needs_the_branch_wave_wide(off by one lane atfa62a17) pass, and so do the new forward-permute tests:a_forward_permute_writes_across_the_two_host_waves,a_forward_permute_in_a_lane_branch_needs_the_branch_wave_wide, and theemit::testslowering tests for both directions.cargo clippy ... -D warningspasses (with and without--all-features): passed.Not tested
AI use
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.