Shaders: scope wave64 ds_bpermute_b32 to 32-lane halves #573
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!573
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/573/head"
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?
@banbanzhige on GitHub · 2026-11-24 05:10 UTC · original
banbanzhige:feat/shader-ds-bpermute→main· +274 −7 · 3 files · 1 commits · merged 2026-11-25 21:39 UTCSummary
0b35b7faddedds_bpermute_b32lowering invictory-shader::emit::lower::Lower::ds, masking the source lane with((addr + offset) >> 2) & (self.wave() - 1).On RDNA 2 / GFX10 (AMD RDNA 2 ISA §10.4.4, and confirmed on gfx1036 hardware in this thread), Wave64
ds_bpermute_b32operates on two independent 32-lane halves (0..31and32..63) rather than permuting across all 64 lanes.This PR fixes that Wave64 half-wave semantics bug and adds regression coverage:
((addr + offset) >> 2) & 31and, whenwave64is set, preserves the calling lane's half with(self.lane_index() & !31) | within_halfwhile reusingmain's existingwaveActiveBallot+Lower::lane_bit_ofactive-lane check.emit::lower::tests(ds_bpermute_wave64_preserves_32_lane_halfandds_bpermute_refuses_gds, backed by#[cfg(test)]-only inspection helpers onbitcode::Module/Lowered) so Wave64 half-wave emission is verified even without a Wave64 GPU.emit::synthetic_testsalongsidepermutes_read_the_lane_named_and_zero_from_lanes_left_out(following42363ab/ccfb029's adapter-skip convention):permutes_mask_high_address_bits_and_divergent_branches(Wave32: high/sub-dword address bit masking + divergents_cbranch_execzzeroing)wave64_permutes_stay_within_each_32_lane_half(Wave64: half-wave isolation, wrap-around, and high/sub-dword bit masking)wave64_permutes_check_exec_within_each_half(Wave64: per-halfEXECmasking so upper-half lanes pulling inactive upper-half lanes read0even when the corresponding lower-half lanes are active)Validation
Rebased onto
main(ccfb029, head8b96041):rustfmt --edition 2024 --check crates/victory-shader/src/emit/bitcode.rs crates/victory-shader/src/emit/synthetic_tests.rs— 0 diffs (0 diffs in modified hunks oflower.rs)cargo clippy --workspace --all-targets --locked -- -D warnings— 0 warningscargo clippy --workspace --all-targets --all-features --locked -- -D warnings— 0 warningscargo test --locked -p victory-shader --lib permute— 6 passed, 0 failed:cargo xtask policy— 182 files okvictory translate <shaders.rpf> --validate, 26,503 containers / 26,084 programs,dxil.dll10.0.26100.0) against42363ab:14,205emitted /14,205validated (unchanged, 0 regressions)2,621emitted /1,886validated (unchanged, 0 regressions)8,765emitted /8,694validated (unchanged, 0 regressions)AI-assisted implementation; semantics, tests, and asset-policy checks verified locally.
@Raxstreams on GitHub · 2026-11-24 05:12 UTC · original
I tested the related split-wave implementation on an RTX 3080 Ti. On RDNA2 the wave64 case uses two independent 32-lane groups for this instruction (AMD RDNA 2 ISA, section 10.4). That matters for the
& 63in the PR description. For example, with all lanes active and values equal to their lane IDs, a byte address of zero in destination lane 32 should select lane 32. A full-wave permutation would select lane 0.The two 64-result fixtures in r4tedx/VIctory#2 cover the group boundary, offset wrap and masked lanes. Both passed on the 3080 Ti. A real checkerboard shadow-mask shader using that implementation also created its D3D12 pipeline and ran 460,800 GPU invocations in a captured scene. Those results are for the linked implementation. I have not run this PR head on a wave64 GPU.
@banbanzhige on GitHub · 2026-11-24 05:36 UTC · original
Good catch, thanks for pointing that out! You are completely right — on RDNA 2 (ISA §10.4),
ds_bpermute_b32in wave64 operates as two independent 32-lane halves rather than permuting across all 64 lanes.I have pushed a follow-up commit to mask
((addr + offset) >> 2)to& 31and preserve(lane & !31)in wave64 (keeping the wave32 path unchanged), updated the PR description, and added two wave64 synthetic tests invalu_tests.rscovering the 32-lane group boundary, offset wrap-around, and per-halfEXECmasking (DXIL-validated on a 32-lane GPU; ready to execute all 64 lanes on a native wave64 device).@iurysf on GitHub · 2026-11-24 06:17 UTC · original
Tested offline against main
d2a4baewithvictory translate --list --validateover the title'sshaders.rpf+ executable (26,096 programs), dxil.dll 1.9.2602.17:AI-assisted.
@Lyrnc on GitHub · 2026-11-24 06:26 UTC · original
RDNA2 hardware check of the wave64 point raised above:
ds_bpermute_b32in wave64 works on two independent 32-lane halves, as your follow-up commit models.Setup. AMD Radeon iGPU of a Ryzen 7 9800X3D, gfx1036 (RDNA2), AMD driver 32.0.21042.62, Windows 11 Pro 26200. Hand-written instructions in a HIP kernel (assembled by the AMD driver's amd_comgr). RDNA2 desktop silicon, not the console's. No game data. Lane
iholdsi + 1, the byte address is4 * source. Wave32 and wave64 kernels, all lanes active.n - 1 - i)31 - i31 - i; lanes 32-63:95 - i(reverse within the half)(i + 33) % 64(i + 1) & 31(i & 32) | ((i + 1) & 31)i + 1(i + 1) & 31(i & 32) | ((i + 1) & 31)So the address selects lane
(addr >> 2) & 31within the lane's own half (i & 32), in all 4 patterns × 2 wave sizes. A full 64-lane index matches none of the wave64 patterns. That is the& 31pluslane & !31in your follow-up.AI use: Claude Code (Claude Opus 5.5) wrote the probes, ran them on the GPU above and drafted this comment; the numbers come from the hardware run.
@slint6614-dev on GitHub · 2026-11-24 10:16 UTC · original
AMD hardware check attempt (RX 9070 / RDNA2 iGPU, Windows 11): at the PR head the
victory-shadertests do not compile:lowersgained anrsrc2argument on main (#612 / #719), so this call needslowers(&words, 0). The newds_bpermute_b32_*GPU tests could not run until that is fixed.@slint6614-dev on GitHub · 2026-11-24 10:42 UTC · original
Measured on the full retail shader pack (26,503 containers) with
victory translate --validate --pipelines(pipelines on an AMD RX 9070, Windows 11, dxil.dll from SDK 10.0.26100). Counts are emitted / validated / pipelines. Merged locally with current mainc7a5f49(main: CS 1440 / 1417 / 1440).CS 1445 / 1422 / 1445 (+5 validated): the
ds_bpermute_b32refusals are gone and those programs validate. VS/PS and MS unchanged. (The tests still need thelowers(&words, 0)fix, see above.)@banbanzhige on GitHub · 2026-11-24 10:46 UTC · original
Thanks for testing on AMD hardware! That
lowers(&words)error was in our previous base commit (58fed37), whichmainfixed in8e79c80.I've rebased this branch onto
main(ffe310e) — picking up8e79c80, resolving theONE_AT_A_TIMEconflict from #566, and updating the testresource::trackcalls to the new 4-argument signature. Bothcargo clippy --workspace --all-targets [--all-features] --locked -- -D warningsandcargo test --workspace --lockedpass locally, so it's ready to test on RX 9070 / RDNA2 Wave64 now.@Halfect on GitHub · 2026-11-24 11:03 UTC · original
Independent check of the rebased head
1d09f19on Windows 11:cargo test --locked -p victory-shader --lib -- --test-threads=1: 127 passed, 0 failed, 1 ignored.ds_bpermutetests passed. The three Wave32 synthetic execution tests ran successfully on the default D3D12 hardware adapter. WARP was unavailable.WaveSize(64)pipeline creation returnedE_INVALIDARGon this adapter; they are not claimed as 64-lane hardware executions here.cargo clippy --locked -p victory-shader --lib --tests -- -D warnings: clean.cargo xtask policy: 154 files ok.The earlier
lowers(&words)/E0061compile failure is gone at this head. No game data or title execution used.@bvtterbroot on GitHub · 2026-11-24 17:54 UTC · original
AMD check at
1d09f19(baseffe310e), on an RDNA3 and an RDNA2 GPU:run_caseswith a local adapter-selection patch that is not part of this PR. WARP runs in each pass as well.cargo test -p victory-shader -p victory-gpu --locked: 177 passed, 0 failed, 2 ignored, on both GPUs. That includes its 7 new tests (ds_bpermute_b32_divergent_branch_zeroes_skipped_lanes,ds_bpermute_b32_gathers_with_offset_and_wrap,ds_bpermute_b32_wave64_exec_mask_per_half,ds_bpermute_b32_wave64_stays_within_each_32_lane_half,ds_bpermute_b32_zeroes_inactive_source_and_preserves_inactive_dst,ds_bpermute_lowers_without_lds_in_wave32_and_wave64, ...).Synthetic tests only, no game files. Tested with AI assistance (Claude Code).
@Melow-code on GitHub · 2026-11-24 23:02 UTC · original
Thanks for this. We wrote the same lowering in our fork (fxceless/victory-gta6) and got the same result. The index is
((addr + offset) >> 2) & 31, the base islane & !31in wave64, and a ballot zeroes reads from inactive source lanes.Rebase note. Main has its own
ds_bpermute_b32block inLower::dssince0b35b7f(24 Nov). That block masks the lane withself.wave() - 1, so in wave64 it reads across the two halves. The RDNA2 check by Lyrnc in this thread and ISA section 10.4.4 show that this is wrong. This is probably the conflict on the PR. To fix it:lane_bit_ofin place of the newmask_bit. They do the same test.Tests we can add, if they help:
0x104gives lane 1). This shows that the instruction uses only bits 6:2.ds_bpermute_b32andds_permute_b32from ISA sections 10.4.4 and 12.13, with the ISA examples as tests.Gap. Main does not lower
ds_permute_b32(scatter) yet. We can send the scatter model and an explicit refusal as a separate PR.@Melow-code on GitHub · 2026-11-24 23:14 UTC · original
Here are three tests for the half-wave semantics, written in the style of
valu_tests.rs. They cover:0x104(dword index 65, low 5 bits = 1) reads lane 1 of the calling half, not lane 65.The CPU reference function:
Happy to send the full file as a PR if it helps.
@Marvisak on GitHub · 2026-11-25 00:26 UTC · original · edited 2026-11-25 16:48 UTC
Automated triage for the maintainers.
Merge candidate.
This fixes the wave64
ds_bpermute_b32lowering inLower::ds(crates/victory-shader/src/emit/lower.rs). On main the source lane is((addr + offset) >> 2) & (wave - 1), which lets wave64 read across all 64 lanes. The PR masks the index with& 31and, in wave64, ORs in the calling lane's half (lane_index() & !31). The existing ballot /lane_bit_ofcheck for inactive source lanes is kept. This matches the RDNA 2 ISA (section 10.4.4) and the gfx1036 hardware results posted in this thread. Wave32 is unchanged. The new synthetic tests cover the half boundary, wrap-around, high address bits and per-half EXEC. The offline test checks that the half mask is only emitted for wave64. The test-only helpers onModuleandLoweredare#[cfg(test)].CI (
check) passes on this head.Generated by Claude Code
@banbanzhige on GitHub · 2026-11-25 01:27 UTC · original
Rebased onto
main(ccfb029, head8b96041) and resolved the conflicts from0b35b7f:0b35b7f'sds_bpermute_b32lowering (& (self.wave() - 1)→(self.lane_index() & !31) | (((addr + offset) >> 2) & 31)per RDNA 2 ISA §10.4.4).mask_bithelper and reusedmain'sLower::lane_bit_of(thanks @Melow-code for the rebase note).emit::synthetic_testsalongsidepermutes_read_the_lane_named_and_zero_from_lanes_left_out(removing thevalu_tests.rsconflict), added high-address-bit (0x100++3) masking and divergents_cbranch_execzcoverage, and added an offline Wave64 half-wave check inemit::lower::tests.Verified locally:
clippy(default and--all-features) clean,cargo test --locked -p victory-shader --lib permute6/6 passed,cargo xtask policy182 files ok, and fullshaders.rpf --validateA/B shows 0 regressions. Ready for review (and a Wave64 AMD hardware re-check if helpful).@banbanzhige on GitHub · 2026-11-25 16:20 UTC · original
Rebased cleanly onto
main(67e8ae1, head95c761e), resolving theemit/synthetic_tests.rsconflict and addingview_marks: falsetoPartsin the offline test.clippy(default +--all-features),permute/bitcode/synthetic_tests, andcargo xtask policyall pass locally.