Skip to content

Shaders: console wave64 compute on 32-lane hosts (split waves) - #1890

Open
beamdotdev wants to merge 4 commits into
Marvisak:mainfrom
beamdotdev:shader/split-wave64
Open

beamdotdev wants to merge 4 commits into
Marvisak:mainfrom
beamdotdev:shader/split-wave64

Conversation

@beamdotdev

@beamdotdev beamdotdev commented Nov 25, 2026 •

Copy link
Copy Markdown

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 by CreateComputePipelineState with E_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.

  • Within a half, nothing extra: DPP, ds_swizzle and v_permlanex16 stay within 32 lanes; v_mbcnt, v_writelane and lane bits of masks use the console lane.
  • Exact where the group runs together: ballots of masks read as data, v_readlane, v_readfirstlane of 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.
  • Per half elsewhere: in divergent code each half works over its own 32 lanes, as pixel and vertex programs already do over the host's wave (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 marked shortcut: in lower.rs.
  • v_readfirstlane of a value that is the same in every lane (scalar arithmetic in VGPRs) needs no exchange, so it works in divergent code too.
  • One-wave groups get the LDS barriers the console compiler leaves out (after writes, and at joins after divergent code).
  • Refused when split: 16-bit wave reductions and 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-gpu creates the device (a run now creates it before its first translation), and when the offline victory translate --pipelines and the warm-up translate --cache do (both print host waves up to N lanes first). 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=32 translates 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 current main; the shader code is the same):

translated host pipelines created
compute 1,439 of 2,582 1,439
vertex/pixel 12,243 of 14,039 12,243
mesh 8,214 of 8,713 8,214

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_triangleClip programs 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, and s_ff1_i32_b64 of a high-lanes-only mask, built for 64-lane and for 32-lane hosts; and a v_readlane inside 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 warnings and 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, two stride_tests, gathers_at_a_level_match_the_hardware) fail on main without 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 Emulate mode 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 current main; if #189 is taken instead, the GPU tests here can check it.

The wave-wide loop exit (Atom::WaveAny) is not on main; 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

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>
@upipibi

upipibi commented Nov 25, 2026

Copy link
Copy Markdown

Ran on the kind of device this is for: RTX 3070 (Ampere, WaveLaneCountMin = Max = 32), driver 616.56, Windows 11, debug, at d047e12.

Not run: a title.

AI-assisted (Claude Code).

@catminou4 catminou4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Marvisak commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

The current head (73ee4dd) still conflicts with main, in crates/victory-gpu/src/shader_cache.rs, crates/victory-shader/src/emit/host.rs, lower.rs, mod.rs and several *_tests.rs files under crates/victory-shader/src/emit/. It will be reviewed once it is rebased onto current main.


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>
@KainanP

KainanP commented Nov 25, 2026

Copy link
Copy Markdown

On a 16-lane Intel iGPU (UHD 8086:a78b, WaveLaneCount 16..16), host_wave_max = 16 still splits and declares WaveSize(32), which that driver refuses at pipeline creation. a_split_wave64_gives_the_consoles_lanes_masks_and_reads then fails with no device ran the program; it fails the same way with VICTORY_WARP=1. On the RTX 4060 both split tests pass. Details and table: #2220 (comment)

AI use: Claude Code (Claude Opus 5.5) ran the tests and wrote this.

MfDev0 pushed a commit to MfDev0/victory that referenced this pull request Nov 26, 2026
…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>
@steven-seagull27

Copy link
Copy Markdown

I found a first-lane mismatch in a converged 64-thread workgroup on 73ee4dd. The guest computes v5 = 100 + tid, narrows EXEC with a vector compare and s_and_saveexec_b64, reads v_readfirstlane_b32 s14, v5, restores EXEC, and writes s14 to all 64 outputs. The whole shader is one basic block. The five masks select first lane 0, 7, 39, 63, or no lanes (which should return lane 0's value, 100).

Wrong output dwords out of 320 PR head Elect inside guest EXEC in each host wave¹ Also choose the participating half
RTX 5080, split Wave32 192 128 0
WARP 1.0.22, split Wave32 192 128 0
WARP 1.0.22, native Wave64 192 0 0

¹ 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

Slay326 pushed a commit to Slay326/VIctory that referenced this pull request Nov 26, 2026
… 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).
@luciano-repetti

Copy link
Copy Markdown

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, cargo test -p victory-shader --locked, PR head 73ee4dd against its base 70564ae. No game files, so only the unit and GPU tests. Each GPU was made the default adapter for the test executable through the Windows per-app GPU preference.

RTX 3050 (Ampere) Arc (Meteor Lake)
base 70564ae 206 passed, 3 failed 202 passed, 7 failed
PR 73ee4dd 209 passed, 3 failed 205 passed, 7 failed
  • emit::split_tests (both tests) pass on both GPUs on the 32-lane path; the 64-lane builds are refused there and skipped, as expected.
  • No regressions in the existing suite: the failing tests are the same set at the base and at the PR head on each GPU. This says nothing about the v_readfirstlane_b32 mismatch reported above, which these tests don't cover; I haven't run that case.
  • RTX 3050 failures (same as the RTX 3070 run above, Test report: RTX 5070 (Blackwell), Windows 11, 70564ae: 471 passed, 5 failed, 7 ignored (4 from the 1,000,000 view heap cap) #1744): stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride, stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros, synthetic_tests::gathers_at_a_level_match_the_hardware.
  • Arc failures, also on the base (not from this PR), in case they're useful elsewhere:
    • semantics_tests::arithmetic_matches_the_hardware: v_mad_f32 / v_mac_f32 mismatch the model on 102 of 14,440 inputs (WARP 0), e.g. in [00800000, 80800000, 00000000] want 00000000 got 80000000 (sign of a zero from an underflowing product).
    • bvh_tests::intersections_* (3 tests): hit distance off by 1 ULP (1118671093 vs 1118671094).
    • valu_tests::fspx_programs_run_with_the_hardwares_dot_products: 2147483504 vs 2147483312.
    • valu_tests::image_atomics_of_64_bits and stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros: E_INVALIDARG creating the pipeline / dispatching.

AI-assisted.

andrewpozdnakov7-jpg and others added 2 commits November 26, 2026 13:57
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.
@andrewpozdnakov7-jpg

Copy link
Copy Markdown
Contributor

I resolved the conflicts between 73ee4dd and current main (63bcca4) in ab0d7e8. It keeps both parents, including the current view-mark and shader-cache paths. e400c3f adds @steven-seagull27's first-lane fix and regression with his Git authorship intact. The integration passes guest EXEC to source-lane election and keeps the scalar write unconditional.

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 main in this WARP setup. Strict all-feature workspace Clippy and the repository asset-policy check passed.

@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 Co-authored-by: andrewpozdnakov7-jpg <andrewpozdnakov7-jpg@users.noreply.github.com>.

@Venom2054

Copy link
Copy Markdown

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 converged_first_lane_respects_both_exec_words three times per revision, with Windows SDK DXIL validation and GPU readback.

Revision Wrong dwords out of 320 per run (split Wave32)
ab0d7e8 192, 192, 192
e400c3f 0, 0, 0

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.

@beamdotdev

Copy link
Copy Markdown
Author

Thanks @andrewpozdnakov7-jpg. I fast-forwarded the PR branch to your integration branch, so the head is now e400c3f (from 73ee4dd). Nothing was rewritten: you stay the author of the merge ab0d7e8, and @steven-seagull27 stays the author of the first-lane fix. If this is squash-merged, GitHub will add Co-authored-by lines for both of you.

Before pushing I ran the split tests on a physical 32-lane adapter (RTX 4060) at e400c3f. All three passed, including the new regression:

emit::split_tests::a_split_wave64_gives_the_consoles_lanes_masks_and_reads ... ok
emit::split_tests::converged_first_lane_respects_both_exec_words ... ok
emit::split_tests::a_split_lane_read_in_a_lane_branch_reads_within_its_half ... ok

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.

chippy01 added a commit to chippy01/VIctory that referenced this pull request Nov 26, 2026
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants