Repository navigation
Shaders: console wave64 compute on 32-lane hosts (split waves) - #1890
beamdotdev wants to merge 4 commits into
Conversation
A compute program that depends on its lane layout declares the console's wave size, so on a device without 64-lane waves (NVIDIA: WaveLaneCountMax 32) every wave64 one was refused by CreateComputePipelineState. Such a program now runs split: it declares WaveSize(32), and each console wave runs as two host waves, its low and high half, with the console's thread ids, lane numbers and masks. DPP, ds_swizzle and v_permlanex16 stay within 32 lanes. Ballots, v_readlane, v_readfirstlane of a varying value, and whole-wave reductions and prefix sums combine the halves through group-shared dwords between barriers, exactly, where the whole group runs together (emit::split::convergent); elsewhere each half works over its own lanes, as pixel and vertex programs do over the host's wave. One-wave groups also get the LDS barriers the console compiler leaves out. The device's width reaches the translator when victory-gpu (and the offline `translate --pipelines`) creates the device; the shader cache keys on it, and VICTORY_HOST_WAVE_MAX=32 translates split on any device. 16-bit wave reductions and ds_bpermute_b32 are refused when split. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Ran on the kind of device this is for: RTX 3070 (Ampere,
Not run: a title. AI-assisted (Claude Code). |
catminou4
left a comment
There was a problem hiding this comment.
Mixed PR: shader/formats parts are macOS-tested in the batch; GPU/HLE parts are Windows-only statics.
Console wave64 compute on 32-lane hosts (split waves): apps+docs+gpu+shader mixed — the wave64 split is the riskiest shader change this wave; shader part tested in batch, GPU part Windows-only.
|
Automated triage for the maintainers. The current head ( Generated by Claude Code |
The cache's folder is named by its key, which includes the host's widest wave; it was opened at start-up, before any device had set the width, so its key always said 64. The warm-up (`translate --cache`) also translated before making a device, so on a 32-lane host it cached WaveSize(64) translations that a run then took from the cache and the host refused. The cache now opens on its first translation, and a run creates its device before translating; the warm-up makes one before it starts, so both translate for the device and key the cache the same way. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
On a 16-lane Intel iGPU (UHD AI use: Claude Code (Claude Opus 5.5) ran the tests and wrote this. |
…s even around LDS the halves cannot meet for A console wave64 compute program whose LDS accesses sit in lane branches (where a group barrier would hang the group) or that has an indirect exit kept WaveSize(64) through every form, and a 32-lane host refuses that pipeline outright (E_INVALIDARG; 02384a60fda6f2d0, 2cc4c197ee29e291, 2da4beb386509b77, 369cbe906ea72764, 5dc3b25986622949, 6f225b641c5b0708 in every run on an RTX 4060: their dispatches dropped). The last resort (each host wave on its own, every mask and lane read per host wave) now splits those too, the halves meeting where every lane runs as before and not inside such branches: the split-wave approach of the open VIctory PRs (Marvisak#1890 split waves, JMAN730#233), taken further where they refuse. Also per host wave there: wave-wide branches, ds_bpermute (this wave's lane of that number), 16-bit wave sums and masks with lanes elsewhere. VICTORY_WAVE_FORCE_SPLIT=0 keeps them refused. Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
|
I found a first-lane mismatch in a converged 64-thread workgroup on
¹ For the middle column I ported only the physical-wave ballot/election from #2830 onto this head. That fixes lane 7. For lane 39, each split Wave32 dispatch still returned 100 in all 64 outputs, where 139 was expected. EXEC's entire low word is zero in this case. Built-in WARP advertises only Wave4 here, so neither pipeline ran. Commit 6cfdabb adds the regression and elects across halves with the existing two-dword exchange. Each half supplies its value and whether it has a participating lane. When both are empty, the lower half supplies lane zero. The three split tests passed on the RTX and the shader crate passed Clippy with warnings denied. The commit is based directly on this PR head for use during the rebase. git fetch https://github.com/steven-seagull27/VIctory.git codex/pr1890-masked-first-lane
git cherry-pick 6cfdabb
cargo test -p victory-shader --lib emit::split_tests:: -- --nocapture |
… the version a63eb93 as in s20) GPU: view heaps on hosts capped below 2^21 descriptors, the version of a63eb93 (wrothgaril, on 70564ae) that was in test/nv3 and f7/bundle: a capped heap mirrors the title's first 721,469 slots in place (title slot = host slot), 2^18 dynamic slots, 2^14 pair slots, null views at the end; shaders clamp below heap_views() and read null past title_views(). No blocks, no view-block table (that is Marvisak#1779's newer head 9323a74, which regressed in run 20261125-185042). Conflicts, both sides kept: main's view marks/read marks/VIEW_* consts beside heap_views()/title_views()/null_buffer_view(); buffer_guard does the title clamp first, then Marvisak#2342's clamp_view_index (below heap_views()) and the stride lookup; shader_cache: main's view_marks options and Marvisak#1890's cache() with this version's host_build(views, title); draw.rs fresh_range (main moved the fixed-function helpers); descriptor tests of main and this version. Ported from 48ba524 (Marvisak#1779 in the version active in s20 (a63eb93 port), not its head 9323a74; on main, whose own cap at 1,000,000 left about 310,000 title slots past the host heap per run (senior 24, main24); Host::from_device as on main).
|
Tested on two GPUs this PR hasn't been run on yet, both with 32-lane waves at most: NVIDIA RTX 3050 6GB Laptop (Ampere, driver 566.07) and Intel Arc iGPU (Meteor Lake, Core Ultra 9 185H, driver 32.0.101.6127). Windows 11 26200, MSVC 2022, Rust 1.98.1 (pinned), debug,
AI-assisted. |
Distinguish two active halves from an empty low half and from an empty guest wave. Compare the selected value and the half's participation using the existing two-dword exchange. The regression checks five branch-free EXEC masks, including a nonzero lane-zero fallback.
|
I resolved the conflicts between On D3D12 Agility 1.620.2 / WARP 1.0.22 with DXIL validation, I ran the same five masks through split Wave32 and native Wave64 three times. The merge alone returned 384 wrong dwords out of 640 each time. With the fix all 640/640 matched each time. All three split tests passed. The full shader suite was 302 passed, 4 failed, 3 ignored. The same four tests failed on @beamdotdev, the integration branch can fast-forward the current PR head. A run of the new regression on a physical 32-lane adapter would complement the WARP results. The Intel 16-lane case reported above and the game were outside this run. Please retain the Git authors when picking up the branch. If folding my integration into another commit, use |
|
Confirmed the integration on a physical RTX 5070 Ti. D3D12 reports 32 lanes for both the minimum and maximum. I ran the five masks from
The parent returned 100 where the three affected masks expected 107, 139, and 163. The full and empty masks returned the expected 100 on both revisions. Each run counts five 64-dword readbacks. The driver declined native Wave64 as expected on this adapter. This was a synthetic shader test. |
|
Thanks @andrewpozdnakov7-jpg. I fast-forwarded the PR branch to your integration branch, so the head is now Before pushing I ran the split tests on a physical 32-lane adapter (RTX 4060) at I didn't run the full shader suite this time. The 16-lane Intel case is still open. AI use: Claude Code (Claude Opus 5.5) ran the tests and wrote this. |
…e halves What was wrong: in halves, three reads into the other half were still refused wherever they were made: `v_readfirstlane_b32` of a value that may differ between the halves, lane masks read as data (`s_bcnt1`, `v_mbcnt`, `vcc_hi` moved to a VGPR, scalar compares of masks), and the whole-wave reductions and prefix sums the console compiler expands (sections the wave simulation follows). The census on b15a57b counted 188, 164 and 96 refused programs needing them. What changed (emit/lower/halves.rs): - `Lower::trade`: the lane-read trade, generalized. Each half's words (each the same in every lane of its host wave) are stored by every lane, then a group barrier, then both halves' words are loaded, then a second barrier. A console wave whose high half has no threads (a group ending inside its low half) gives the word's identity there. The slots grow to two dwords per half. `v_readlane_b32` uses it too. - `v_readfirstlane_b32`: each half reads its first lane in EXEC (the instruction's guard) and its ballot of EXEC. The console's first lane is the low half's where that has one, else the high half's, else lane 0 (EXEC empty). Scalars, values the same in every lane of the console wave and groups of 32 threads or fewer keep the host wave's own read. `main` drops the guard of an instruction with a scalar result (Marvisak#2830 fixes that there), so the trade reads the guard itself. - Lane masks read as data: each half's ballot is one dword of the console's mask, traded at the end of the block writing the mask. - Whole-wave reductions combine the two halves' parts, low half first. A prefix sum in the high half adds the low half's total. - Each stays refused, with its reason, where not every thread of the group meets: inside a branch only some lanes take, and, in a group of several console waves, inside any branch. Relation to other PRs: Marvisak#1890 (beamdotdev's) and Marvisak#189 (alfycs's) trade these reads through group-shared memory too. This builds on Marvisak#2633's trade and refuses where the halves cannot meet; Marvisak#1890 lets each half work over its own 32 lanes there. Evidence, translate --list --wave32 --validate over shaders.rpf, the executable, XboxBvhBuilder.dll and the FidelityFX DLL: compute programs emitted 2,443 -> 2,463, every new one validated and none lost: - first lanes: CS_Slod_BatchCull and five of its variants, CS_HighDetailDeltas_ComputeDeltas; - masks read as data: XboxBvhBuilder.dll (2), CS_DepthProcessing, CS_DepthProcessingHBO, CS_UpdateParticles, CS_UpdateSkinnedAttachMeshParticles, CS_CollisionWithWaterSim, CS_DownsampleAlphaShadowMap, CS_GenerateMaterialMasks; - reductions: CS_RegenerateMinMaxDepth, CS_SortRayTiles, CS_GenerateNormalConesFirstPass, CS_FeedbackToParent4x4x4. Still refused where not every thread of the group meets: 87 masks read as data, 20 first-lane reads and 16 reductions. Those need the two halves to follow the console's flow through the branch, the next step. Tests (emit::halves_tests): - collectives_are_traded_where_every_thread_meets (offline): masks, first lanes, a wave sum and small_group translate in groups of 48, 64, 96 and 128; a first-lane read and a mask inside a lane branch are refused; a sum under a uniform branch translates in a group of 64 and is refused in one of 128. - collectives_cross_the_halves_on_every_gpu: in groups of 48 (an upper half of 16 threads), 64, 96 (a second console wave with no upper half) and 128, the count and both dwords of a mask of lanes below 40, the first lane, a first lane in the upper half under a narrowed EXEC, the exclusive prefix sum and the total of the thread ids, and small_group's results. 0 lanes differ from the console on an RTX 3070 Ti (halves) and the Radeon iGPU of a Ryzen 9 7900X (halves and wave64). The first lane under a narrowed EXEC runs in halves only: the wave64 form gives lane 0's thread id on `main` (Marvisak#2830). - reads_across_32_lane_halves_are_refused_with_their_reason and a_group_one_host_wave_holds_reads_nothing_across_halves: updated, the buffer-load first lane rule now checked inside a branch. Checks: cargo clippy --workspace --all-targets --locked -- -D warnings, and with --all-features: clean. cargo xtask policy: ok. cargo test -p victory-shader --lib -- --test-threads=1: 313 passed, 3 failed, the same 3 as on main on this NVIDIA machine; heap_direct_texture_reads_mark_their_heap_index skipped as before. lower.rs shrinks by 259 bytes (523,196). Co-Authored-By: Claude Opus 5.5
Problem
A compute program that depends on its lane layout (cross-lane reads, lane masks read as numbers, LDS shared within one wave) declares the console's wave size. On a device without 64-lane waves (NVIDIA:
WaveLaneCountMin = Max = 32), every wave64 one is refused byCreateComputePipelineStatewithE_INVALIDARG("Shader wants wave lane count of 64 but maximum wave lane count for device is 32"), and its dispatches are dropped.What this does
Such a program now runs split: it declares
WaveSize(32), and each console wave runs as two host waves, its low and high half (console lanes 0-31 and 32-63). Thread ids, lane numbers and masks stay the console's.ds_swizzleandv_permlanex16stay within 32 lanes;v_mbcnt,v_writelaneand lane bits of masks use the console lane.v_readlane,v_readfirstlaneof a varying value, and whole-wave reductions and prefix sums combine the two halves' parts through a few group-shared dwords between two thread-group barriers. A barrier needs the whole group, so this happens only in blocks no lane branch decides whether (or how often) a lane reaches (emit::split::convergent, a post-dominator pass): with one console wave per group, outside any lane branch's region; with several waves, before the first branch.MaskData::Host). This is right for what that code mostly does (wave-aggregated atomics, scalarization loops) and wrong where the code needs one value for all 64 lanes; it is markedshortcut:inlower.rs.v_readfirstlaneof a value that is the same in every lane (scalar arithmetic in VGPRs) needs no exchange, so it works in divergent code too.ds_bpermute_b32(both would need the other half's lanes), and programs whose LDS leaves no room for the exchange dwords in 32 KiB.The device's width reaches the translator when
victory-gpucreates the device (a run now creates it before its first translation), and when the offlinevictory translate --pipelinesand the warm-uptranslate --cachedo (both printhost waves up to N lanesfirst). The shader cache keys on it and now opens on its first translation, after the device: before, it opened at start-up with the width still unset, so its key always said 64, and the warm-up cached WaveSize(64) translations that a run on a 32-lane host then took from the cache (found by a second session testing the warm-up: 395 pipelines still refused).VICTORY_HOST_WAVE_MAX=32translates split on any device. Devices with 64-lane waves translate exactly as before.Measured
Windows 11, RTX 3070 (32-lane waves only), Series X 1.0.2.1 files,
victory translate --pipelines(before the port onto currentmain; the shader code is the same):Every compute program that translates gets a pipeline. The same files on a 64-lane host translate 1,441 compute programs; the 2 not translated split are
vfx_triangleClipprograms with no group-shared memory left for the exchange. Without this change, all ~320 programs that need 64-lane waves are refused on the 3070.The title ran with it on the 3070 to the first mission's title card ("Vice City, two years ago") at about 1 fps, then the host device was removed after a 7 s submission (the world hang the README describes, also seen on AMD). That submission held about 8 split programs among 69 pipelines, so this run does not show whether they are involved; a run with them skipped is the next check.
Tests
emit::split_tests(new, GPU): a wave64 program of one console wave checking per lane a mask count across both halves (s_bcnt1_i32_b64), the lane index (v_mbcnt), a read of high-half lane 45 (v_readlane),v_readfirstlane, ands_ff1_i32_b64of a high-lanes-only mask, built for 64-lane and for 32-lane hosts; and av_readlaneinside a lane branch, which reads within its half. Both pass on the RTX 3070 (the 64-lane build is skipped there, and WARP, at 4 lanes, skips both).emit::split::tests: post-dominators of an if and a loop.cargo clippy --workspace --all-targets --locked -- -D warningsand with--all-features: clean.cargo test --workspace --locked --no-fail-fast: 474 passed, 5 failed, 7 ignored. The 5 failures (dynamic_slots_are_held_until_released,lists_share_a_table_and_copies_keep_their_views, twostride_tests,gathers_at_a_level_match_the_hardware) fail onmainwithout this change on the same machine.Relation to #189 / #1589 / #1638
#189 (bundled in #1589 and #1638) solves the same problem with the same layout (two 32-lane waves per console wave, group-shared memory between barriers) and more besides: a barrier-free path for groups of 32 threads or fewer, an
Emulatemode without a declared wave size, which also covers WARP, and SGPR spills to lanes 32 and up. Those bundles are stacked on other open pull requests. This is a smaller change written against currentmain; if #189 is taken instead, the GPU tests here can check it.The wave-wide loop exit (
Atom::WaveAny) is not onmain; when it lands, a split program needs it exchanged as well.AI-assisted (Claude Code); no game data is used or committed.
🤖 Generated with Claude Code