Repository navigation
Shaders: scope wave64 ds_bpermute_b32 to 32-lane halves - #573
banbanzhige wants to merge 1 commit into
Conversation
|
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 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. |
|
Good catch, thanks for pointing that out! You are completely right — on RDNA 2 (ISA §10.4), I have pushed a follow-up commit to mask |
|
Tested offline against main
AI-assisted. |
|
RDNA2 hardware check of the wave64 point raised above: 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
So the address selects lane 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. |
289b812 to
beae3ee
Compare
|
AMD hardware check attempt (RX 9070 / RDNA2 iGPU, Windows 11): at the PR head the
|
|
Measured on the full retail shader pack (26,503 containers) with CS 1445 / 1422 / 1445 (+5 validated): the |
beae3ee to
1d09f19
Compare
|
Thanks for testing on AMD hardware! That I've rebased this branch onto |
|
Independent check of the rebased head
The earlier |
catminou4
left a comment
There was a problem hiding this comment.
Solid ds_bpermute_b32 lowering. The semantics match the RDNA2 ISA description in the comment: backward pull permute within the lane's own 32-lane half (((addr + offset) >> 2) & 31, with the wave64 high-half base OR'd in), zero when the source lane is inactive, and GDS correctly rejected. The refactor extracting mask_bit from the existing ballot helper avoids duplication.
Test coverage is good:
ds_bpermute_lowers_without_lds_in_wave32_and_wave64andds_bpermute_refuses_gdsrun on macOS (lowering-level).- The new
run_wave_csharness invalu_tests.rsis a proper host-execution test (hardware + WARP, DXIL validation fallback, fixed-wave-size skips) — it's#[cfg(windows)]-gated like the rest of that suite, so it will exercise the permute on the Windows CI lane.
Verified locally: test-merge with current main (ffe310e) clean; cargo test -p victory-shader --locked (macOS arm64, rustc 1.98.1) → 98 passed / 0 failed / 1 ignored (Windows-gated execution tests not run here, as usual).
Merged by hand: its wave tests and helpers were appended to the module, which had gained dot2 and thread-group-info tests since its base. Its own duplicate copy of the shared vop2 helper was dropped in favour of the identical definition already present. Applied as the net diff of upstream PR Marvisak#573 (head 1d09f19), 2 commits.
|
AMD check at
Synthetic tests only, no game files. Tested with AI assistance (Claude Code). |
|
Thanks for this. We wrote the same lowering in our fork (fxceless/victory-gta6) and got the same result. The index is Rebase note. Main has its own
Tests we can add, if they help:
Gap. Main does not lower |
|
Here are three tests for the half-wave semantics, written in the style of
The CPU reference function: fn bpermute(src: &[u32], addresses: &[u32], offset: u32, exec: u64, wave64: bool) -> Vec<Option<u32>> {
let lanes = if wave64 { 64 } else { 32 };
(0..lanes)
.map(|l| {
if exec >> l & 1 == 0 { return None; }
let idx = usize::from(((addresses[l].wrapping_add(offset)) >> 2) & 31);
let base = if wave64 { l & 32 } else { 0 };
let s = base | idx;
Some(if exec >> s & 1 == 0 { 0 } else { src[s] })
})
.collect()
}Happy to send the full file as a PR if it helps. |
…ot-tracing Shaders: extend spill-table, arithmetic, join, and first-lane address tracing
|
Automated triage for the maintainers. Recommended for a maintainer's look. This fixes the The tests cover high address bits, divergent EXEC and per-half EXEC in Generated by Claude Code |
1d09f19 to
8b96041
Compare
|
Rebased onto
Verified locally: |
Melow-code
left a comment
There was a problem hiding this comment.
The half-wave masking is correct: idx = ((addr + offset) >> 2) & 31, source lane = (WaveGetLaneIndex() & !31) | idx, inactive lanes stay zero through the ballot guard. This matches the RDNA2 ISA §10.4.4 ds_bpermute_b32 description and the gfx1036 hardware results from the thread.
We independently implemented and verified the same lowering on a fork (commit fa92ce0): CPU reference against all 1024 permutations, ballot-based liveness, wave32 passthrough. The semantics are identical.
The rebase on ccfb029 and the added tests (high-address-bits, divergent execz, offline wave64) look clean. No regressions.
🤖 Generated with Claude Code
Summary
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.