Repository navigation
Shaders: scope wave64 ds_bpermute_b32 to 32-lane halves - #573
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. Merge candidate. This fixes the wave64 CI ( Generated by Claude Code |
1d09f19 to
8b96041
Compare
…-lane waves What was wrong: a console wave64 compute program that needs the console's lanes (cross-lane reads, masks as numbers, LDS one wave shares) declares WaveSize(64). NVIDIA and Intel run waves of 32 lanes at most (WaveLaneCountMax 32) and refuse it: on an RTX 3070 Ti (driver 32.0.16.2124) the debug layer gives "Shader wants wave lane count of 64 but maximum wave lane count for device is 32" (id 622), and every such pipeline is refused with E_INVALIDARG. A Series S run to the loading screen refused 100 compute pipelines, 95 of them for this. What changed: on such a host, a wave64 program that needs the console's lanes is translated for waves of 32 (`emit::Options::host_wave32`; `emit::lower::halves`). The thread relabelling gives each host wave a 32-aligned run of thread ids, so host wave 2w + h is console wave w's lanes 32h..32h + 31. What a lane reads within its half is exact: DPP rows, ds_swizzle, and ds_bpermute_b32, which the console's wave64 permutes within each half on its own (RDNA2 ISA; measured in Marvisak#573). A lane's bit of a mask held as a number, v_writelane_b32 and v_mbcnt take the console lane. Reads across the halves have no host form and are refused where they are lowered, with a reason that names the host: ballots (masks read as data), v_readlane_b32 of a lane that may be in the other half, whole-wave reductions and prefix sums; one a program never uses costs nothing (the lowering's retry with the value missing). A group of 33 to 64 threads with LDS, which the console compiler orders without barriers as one wave, is refused too. v_readfirstlane_b32 reads the host wave's first lane, as it already does in every program without console lanes (marked as that shortcut). victory-gpu asks the device once (OPTIONS1) and translates for it; the shader cache keys on it, so entries made for 64-lane hosts are not read. `victory translate --wave32` translates for such a host offline; with --pipelines it follows the GPU that makes them. Approach after DexNom's fork (DexNom/Victory 5f4c3df: the host's wave width and the relabelling into halves) and Marvisak#2176 (n-romanovich: the setting in the cache key); here the setting is a translation option, and cross-half reads are refused at the sites that make them instead of by instruction name, which keeps programs whose crossing value is unused. Evidence, `translate --list --pipelines` over shaders.rpf, the executable, XboxBvhBuilder.dll and the FidelityFX DLL, RTX 3070 Ti: | | main 67e8ae1 | this | |---|---|---| | compute programs emitted | 2,733 | 2,372 | | compute pipelines made | 2,328 | 2,372 | | refused by the driver | 405 | 0 | No program that made a pipeline on main fails to now (25,347 pipelines, all kept). In the title (Series S mode, diagnostics build, to the loading screen, 2.5 min): no pipeline refused, against 100 on main; the 113 programs that do not translate say why (51 LDS, the rest mostly ballots). The 44 new ones include the depth pyramids (occlusion), the sky and atmosphere gathers (scattering_transmittance_system), shader binning and the mipmap generators. The 361 still refused now say why: 192 LDS in a one-wave group, 107 ballots, 48 lane reads across halves, 20 reductions (those need an exchange between the two host waves, a change of its own). Tests (halves_tests): one wave64 program (DPP, ds_swizzle, ds_bpermute, v_mbcnt, v_writelane to lane 40, a constant mask's high dword) runs on every hardware adapter, in halves and, where the adapter has 64-lane waves, as one wave64: all 64 lanes give the console's results on the RTX 3070 Ti (halves) and the Radeon iGPU of a Ryzen 9 7900X (RDNA2: halves and wave64). The refusals and the LDS rule each have an offline test; the hand-encoded words are checked against the disassembler. Found on the way, not changed here: a wave64 mask built by two s_mov_b32 (low and high dword written apart) reads its low dword for all 64 lanes (`Lower::pair_high` looks for the high dword in the instruction that wrote the low one); the same with and without this change, on AMD's own wave64 too. Co-Authored-By: Claude Opus 5.5
…-lane waves What was wrong: a console wave64 compute program that needs the console's lanes (cross-lane reads, masks as numbers, LDS one wave shares) declares WaveSize(64). NVIDIA and Intel run waves of 32 lanes at most (WaveLaneCountMax 32) and refuse it: on an RTX 3070 Ti (driver 32.0.16.2124) the debug layer gives "Shader wants wave lane count of 64 but maximum wave lane count for device is 32" (id 622), and every such pipeline is refused with E_INVALIDARG. A Series S run to the loading screen refused 100 compute pipelines, 95 of them for this. What changed: on such a host, a wave64 program that needs the console's lanes is translated for waves of 32 (`emit::Options::host_wave32`; `emit::lower::halves`). The thread relabelling gives each host wave a 32-aligned run of thread ids, so host wave 2w + h is console wave w's lanes 32h..32h + 31. What a lane reads within its half is exact: DPP rows, ds_swizzle, and ds_bpermute_b32, which the console's wave64 permutes within each half on its own (RDNA2 ISA; measured in Marvisak#573). A lane's bit of a mask held as a number, v_writelane_b32 and v_mbcnt take the console lane. Reads across the halves have no host form and are refused where they are lowered, with a reason that names the host: ballots (masks read as data), v_readlane_b32 of a lane that may be in the other half, whole-wave reductions and prefix sums; one a program never uses costs nothing (the lowering's retry with the value missing). A group of 33 to 64 threads with LDS, which the console compiler orders without barriers as one wave, is refused too. v_readfirstlane_b32 reads the host wave's first lane, as it already does in every program without console lanes (marked as that shortcut). victory-gpu asks the device once (OPTIONS1) and translates for it; the shader cache keys on it, so entries made for 64-lane hosts are not read. `victory translate --wave32` translates for such a host offline; with --pipelines it follows the GPU that makes them. Approach after DexNom's fork (DexNom/Victory 5f4c3df: the host's wave width and the relabelling into halves) and Marvisak#2176 (n-romanovich: the setting in the cache key); here the setting is a translation option, and cross-half reads are refused at the sites that make them instead of by instruction name, which keeps programs whose crossing value is unused. Evidence, `translate --list --pipelines` over shaders.rpf, the executable, XboxBvhBuilder.dll and the FidelityFX DLL, RTX 3070 Ti: | | main 67e8ae1 | this | |---|---|---| | compute programs emitted | 2,733 | 2,372 | | compute pipelines made | 2,328 | 2,372 | | refused by the driver | 405 | 0 | No program that made a pipeline on main fails to now (25,347 pipelines, all kept). In the title (Series S mode, diagnostics build, to the loading screen, 2.5 min): no pipeline refused, against 100 on main; the 113 programs that do not translate say why (51 LDS, the rest mostly ballots). The 44 new ones include the depth pyramids (occlusion), the sky and atmosphere gathers (scattering_transmittance_system), shader binning and the mipmap generators. The 361 still refused now say why: 192 LDS in a one-wave group, 107 ballots, 48 lane reads across halves, 20 reductions (those need an exchange between the two host waves, a change of its own). Tests (halves_tests): one wave64 program (DPP, ds_swizzle, ds_bpermute, v_mbcnt, v_writelane to lane 40, a constant mask's high dword) runs on every hardware adapter, in halves and, where the adapter has 64-lane waves, as one wave64: all 64 lanes give the console's results on the RTX 3070 Ti (halves) and the Radeon iGPU of a Ryzen 9 7900X (RDNA2: halves and wave64). The refusals and the LDS rule each have an offline test; the hand-encoded words are checked against the disassembler. Found on the way, not changed here: a wave64 mask built by two s_mov_b32 (low and high dword written apart) reads its low dword for all 64 lanes (`Lower::pair_high` looks for the high dword in the instruction that wrote the low one); the same with and without this change, on AMD's own wave64 too. Co-Authored-By: Claude Opus 5.5
The integration has a different lowering input layout and only permits direct title-address fallback for compute shaders. Exercise that fallback in the same SSA regression and use the available input fields for the permute test. Make the cached sums copyable and close the device creation block after retaining the fork’s adapter selection. Based-on: Marvisak#139 Based-on: Marvisak#244 Based-on: Marvisak#573 Tested-on: Intel Xeon E5-2670 v3, Fedora Linux 45, five shader regressions and Windows-target Cargo checks Assisted-by: gpt-6.2 sol xhigh
The integration has a different lowering input layout and only permits direct title-address fallback for compute shaders. Exercise that fallback in the same SSA regression and use the available input fields for the permute test. Make the cached sums copyable and close the device creation block after retaining the fork’s adapter selection. Based-on: Marvisak#139 Based-on: Marvisak#244 Based-on: Marvisak#573 Tested-on: Intel Xeon E5-2670 v3, Fedora Linux 45, five shader regressions and Windows-target Cargo checks Assisted-by: gpt-6.2 sol xhigh
The integration has a different lowering input layout and only permits direct title-address fallback for compute shaders. Exercise that fallback in the same SSA regression and use the available input fields for the permute test. Make the cached sums copyable and close the device creation block after retaining the fork’s adapter selection. Based-on: Marvisak#139 Based-on: Marvisak#244 Based-on: Marvisak#573 Tested-on: Intel Xeon E5-2670 v3, Fedora Linux 45, five shader regressions and Windows-target Cargo checks Assisted-by: gpt-6.2 sol xhigh
Conflicts resolved: - emit/lower.rs: ds_bpermute_b32 takes main's lowering (Marvisak#573: within the reader's own 32-lane half, the half's base from the host lane), which in halves is the host wave itself, so halves::permute_lanes, which did that for halves alone, is gone. Lowered keeps both sides' test fields (wave_size, and main's uses_lane_index and has_half_wave_mask). - emit/host.rs: main's Host::new (one shared WARP device, the warp field). Host::each_hardware and create_device share one SM 6.6 check, the sm66 function. - apps/victory/src/main.rs: --wave32 beside main's non-zero --jobs. - README.md: main's "GPU: world" row, this branch's "Shaders" row. For main's new code: host_wave32: false in four new tests' lower::Parts and in one emit::Options; victory-gpu takes its shader host by Host::from_device, as main now has it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The integration has a different lowering input layout and only permits direct title-address fallback for compute shaders. Exercise that fallback in the same SSA regression and use the available input fields for the permute test. Make the cached sums copyable and close the device creation block after retaining the fork’s adapter selection. Based-on: Marvisak#139 Based-on: Marvisak#244 Based-on: Marvisak#573 Tested-on: Intel Xeon E5-2670 v3, Fedora Linux 45, five shader regressions and Windows-target Cargo checks Assisted-by: gpt-6.2 sol xhigh
The integration has a different lowering input layout and only permits direct title-address fallback for compute shaders. Exercise that fallback in the same SSA regression and use the available input fields for the permute test. Make the cached sums copyable and close the device creation block after retaining the fork’s adapter selection. Based-on: Marvisak#139 Based-on: Marvisak#244 Based-on: Marvisak#573 Tested-on: Intel Xeon E5-2670 v3, Fedora Linux 45, five shader regressions and Windows-target Cargo checks Assisted-by: gpt-6.2 sol xhigh
The integration has a different lowering input layout and only permits direct title-address fallback for compute shaders. Exercise that fallback in the same SSA regression and use the available input fields for the permute test. Make the cached sums copyable and close the device creation block after retaining the fork’s adapter selection. Based-on: Marvisak#139 Based-on: Marvisak#244 Based-on: Marvisak#573 Tested-on: Intel Xeon E5-2670 v3, Fedora Linux 45, five shader regressions and Windows-target Cargo checks Assisted-by: gpt-6.2 sol xhigh
The integration has a different lowering input layout and only permits direct title-address fallback for compute shaders. Exercise that fallback in the same SSA regression and use the available input fields for the permute test. Make the cached sums copyable and close the device creation block after retaining the fork’s adapter selection. Based-on: Marvisak#139 Based-on: Marvisak#244 Based-on: Marvisak#573 Tested-on: Intel Xeon E5-2670 v3, Fedora Linux 45, five shader regressions and Windows-target Cargo checks Assisted-by: gpt-6.2 sol xhigh
The integration has a different lowering input layout and only permits direct title-address fallback for compute shaders. Exercise that fallback in the same SSA regression and use the available input fields for the permute test. Make the cached sums copyable and close the device creation block after retaining the fork’s adapter selection. Based-on: Marvisak#139 Based-on: Marvisak#244 Based-on: Marvisak#573 Tested-on: Intel Xeon E5-2670 v3, Fedora Linux 45, five shader regressions and Windows-target Cargo checks Assisted-by: gpt-6.2 sol xhigh
Upstream main merged Marvisak#2143, Marvisak#2162, Marvisak#158, Marvisak#1906 and Marvisak#1152 and took up what Marvisak#1769 (LDS bounds, Marvisak#1949) and Marvisak#1763 (typed UAV formats, Marvisak#2462) did; main's code is kept for those. - emit/lower.rs: ds_bpermute within each half (main's Marvisak#573, same as Marvisak#439's); LDS bounds as main's Marvisak#1949 (Marvisak#1769's test-only counter kept, its and_guard dropped); title-memory marks: main's straddling-write lookup (Marvisak#2484) with Marvisak#2167's current head (3cb308d, rebased on 63bcca4): guarded dirty atomics, raw_dword2, memory_null, synthetic_mark_dxil in lower/mark_tests.rs; the old Marvisak#2167 head taken out first. - emit/host.rs: main's shared WARP device and lock (Marvisak#244) with Marvisak#439's adapter list and Host::on (create_device takes an optional adapter). - descriptor/host.rs: main's Marvisak#2462 format checks; Marvisak#1763's tests kept. - gpu host.rs: main's multi-plane present with Marvisak#2310's crumbed copy. - pipeline.rs: Marvisak#2118/Marvisak#2311's builder and BVH checks with main's skip hashes (Marvisak#1320); draw.rs, shadow.rs, main.rs: both sides. - Tests main added since get Marvisak#439's Parts fields and emit's Target. - README: base 63bcca4; rows of PRs merged upstream, superseded or closed taken out, with a note. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The integration has a different lowering input layout and only permits direct title-address fallback for compute shaders. Exercise that fallback in the same SSA regression and use the available input fields for the permute test. Make the cached sums copyable and close the device creation block after retaining the fork’s adapter selection. Based-on: Marvisak#139 Based-on: Marvisak#244 Based-on: Marvisak#573 Tested-on: Intel Xeon E5-2670 v3, Fedora Linux 45, five shader regressions and Windows-target Cargo checks Assisted-by: gpt-6.2 sol xhigh
The integration has a different lowering input layout and only permits direct title-address fallback for compute shaders. Exercise that fallback in the same SSA regression and use the available input fields for the permute test. Make the cached sums copyable and close the device creation block after retaining the fork’s adapter selection. Based-on: Marvisak#139 Based-on: Marvisak#244 Based-on: Marvisak#573 Tested-on: Intel Xeon E5-2670 v3, Fedora Linux 45, five shader regressions and Windows-target Cargo checks Assisted-by: gpt-6.2 sol xhigh
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.