Skip to content

Shaders: compute reading lanes only within aligned groups declares no wave size - #2117

Open
rminzao wants to merge 1 commit into
Marvisak:mainfrom
rminzao:shaders-narrow-lane-groups-no-wave-size
Open

rminzao wants to merge 1 commit into
Marvisak:mainfrom
rminzao:shaders-narrow-lane-groups-no-wave-size

Conversation

@rminzao

@rminzao rminzao commented Nov 25, 2026

Copy link
Copy Markdown

Claimed in #1633 (claim).

Problem

A compute program that reads other lanes declares the console's exact wave size (lower.rs, the console_lanes decision; WaveSize(32) or WaveSize(64)). A host refuses a WaveSize outside its [WaveLaneCountMin, WaveLaneCountMax]:

host lanes refused today
NVIDIA 32-32 every lane-dependent wave64 program
Intel UHD (Xe-LP, #1829) 16-16 lane-dependent wave32 and wave64
WARP 4-4 lane-dependent wave32 and wave64

Many such reads never leave a small aligned group of lanes, though: DPP quad_perm stays in a quad, DPP8 in 8 lanes, DPP row controls in 16, ds_swizzle in quad mode in a quad and in bitmask mode in 2^(highest lane bit it changes + 1). Any host wave of at least G lanes, aligned on G, gives each group the same lanes, whatever the host's wave size.

Change

  • lane_group gives each instruction the aligned group it reads (table below). When the widest group G of a compute program is smaller than the console wave N, and nothing in it needs the whole wave, the program declares no WaveSize and Lowered/HostShader carry min_lanes = G.
  • Thread ids of such a program are relabelled with the host's wave size (waveGetLaneCount) instead of the constant N (narrow_thread_id, lane_thread), on the same assumption thread_id makes today: a host wave holds an aligned run of flat thread ids. DPP row_mask/bank_mask and constant lane bits take the console lane from the relabelled id (console_lane).
  • victory-gpu: Host::wave_lanes_min reads OPTIONS1 once (logged), and a compute pipeline whose shader has min_lanes above it is refused as "the host GPU's waves are narrower than the lane groups the shader reads". min_lanes is in the shader cache entry.
instruction G
DPP quad_perm, ds_swizzle quad mode 4
DPP8 8
DPP16 row_shl/shr/ror, row_mirror, row_half_mirror, row_share, row_xmask 16
ds_swizzle bitmask mode 1-32, from the bits the masks change
other DPP controls, permutes, v_mbcnt*, v_readlane/v_writelane, masks read as data N (whole wave)

Kept whole-wave (declaring WaveSize exactly as before): programs with s_barrier (a host wave whose lanes all skip it would hang the host, where the console's wave still arrives), any LDS use (the console compiler leaves out barriers within one wave, so an intra-wave LDS exchange would race across host waves), v_permlane*, a v_readfirstlane that isn't a waterfall read, opaque or constant lane-mask guards, one-wave groups with LDS, and whole-wave sections. A narrow attempt that fails to lower for any reason, or reads a lane mask as data, is lowered again whole-wave, so narrowing never makes a program fail that translates today.

Unchanged for every other program: the narrow path is separate (thread_id gets one early branch). Hashing lowered.dxil for every input the shader suite lowers, on main 940d32f and on this branch: all 484 that main lowers whole-wave or lane-free give byte-identical DXIL; only the new tests' narrow programs differ.

Tested

Intel UHD Graphics (driver 31.0.101.4146), RTX 4050 Laptop (595.97) and WARP, Windows 11. New module emit::lane_group_tests; each GPU test reads back 128 threads lane by lane against a CPU model of the console, with encodings checked against the decoder's text and DXIL validated.

test Intel UHD (16) RTX 4050 (32) WARP (4)
quad_reads_run_on_any_host_wave (wave32 + wave64: quad_perm with row/bank masks, quad swizzle) pass pass pass
row_reads_run_on_host_waves_of_16_lanes (row_shr:3 with masks, row_mirror, DPP8, swizzle xor) pass pass skipped (4 lanes)
half_reads_of_wave64_run_on_host_waves_of_32_lanes skipped (16 lanes) pass skipped
lane_groups_set_the_fewest_host_lanes, reads_of_the_whole_wave_keep_its_size (readlane, mbcnt, readfirstlane, s_barrier, a whole-wave section), lds_shared_within_the_wave_keeps_its_size pass (CPU)
pipeline::host::tests::shaders_reading_lane_groups_need_host_waves_that_hold_them pass (CPU)

The RTX 4050 ran through a local, uncommitted switch of the test host to the high-performance adapter. Breaking the console-lane computation, the section fallback or the barrier/LDS rules each makes a test fail.

Overlap: #1922's gate refuses wave64 compute without a declared wave size on hosts under 64 lanes; with this PR the narrow wave64 programs are such programs, so the two need reconciling (whichever lands second). #2035 (barrier sync on narrow waves) is orthogonal: programs with barriers don't narrow here.

Not run: the title, AMD hardware (a 32-64 lane host runs narrow programs at the driver's choice of size), and how many of the title's programs narrow. Programs with LDS or barriers, likely the bulk of lane-dependent compute, are deliberately left as they are.

AI-assisted (Claude Code).

🤖 Generated with Claude Code

… wave size

A compute program reading other lanes declared the console's WaveSize(32)
or WaveSize(64), so hosts without that size refused it: NVIDIA every
wave64 one, a 16-lane Intel iGPU and WARP both sizes. When every
cross-lane read stays inside an aligned group of G lanes smaller than the
wave (DPP quad_perm, DPP8 and row controls, ds_swizzle in quad mode or
with a narrow bitmask), host waves of at least G lanes give each group the
same lanes: such a program declares no wave size, takes its thread ids by
the host's wave size, and carries min_lanes = G, which the runtime checks
against the host's WaveLaneCountMin before making the pipeline.

Programs that also use s_barrier, LDS, lane masks as data, v_mbcnt,
readlane/writelane, permutes, v_permlane* or whole-wave sections keep
WaveSize, and their DXIL is unchanged. A narrow attempt that fails to
lower is redone whole-wave.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@DenRakEiw DenRakEiw left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Verified locally merged onto origin/main (940d32f, Windows 11 x64, NVIDIA GeForce RTX 5090 + WARP, Rust 1.98.1 MSVC, with dxil.dll validator):

  • cargo test -p victory-shader --lib wave — 14 passed, 0 failed (including shaders_reading_lane_groups_need_host_waves_that_hold_them)
  • cargo clippy -p victory-shader --all-targets — 0 warnings
  • cargo xtask policy — ok (184 files ok)

Clean refinement omitting WaveSize when compute lane reads stay within aligned groups, improving Wave32/NVIDIA compatibility while guarding host minimum wave lanes. Looks great.

AI-assisted (Gemini 4 Neon).

@andrewpozdnakov7-jpg

Copy link
Copy Markdown

A remaining narrow-wave case on b3b5c93: DPP16 row_xmask:3 selects lane XOR 3, which stays within each four-lane group. The current classifier assigns it 16 lanes and excludes four-lane WARP. ISA modifier semantics

571b78a sizes this lane group from the mask in one commit on that exact head. The same synthetic dispatch test skipped WARP and failed before. After, the compiled shader ran on WARP for guest wave32 and wave64. All 128 readbacks for each mode matched the lane oracle, including old destination values in masked rows and banks.

Full forced-WARP shader suite: 250 passed, 4 failed, 3 ignored before. After: 251 passed, 3 failed, 3 ignored. The gather, lane-permute and edge-flagged triangle failures were shared. Strict shader Clippy and staged asset policy passed.

@fiestorra

Copy link
Copy Markdown
Contributor

This and #2126 rewrite the same arithmetic, they conflict, and one may be a precondition of the other

Two pull requests in the same window are changing how a thread's lane is arranged for cross-lane reads, and they are not independent.

Measured: they conflict, in the one file where it matters:

#2126 + #2117  → conflict in crates/victory-shader/src/emit/lower.rs

#2126 (console_flat, "compute threads that read other lanes keep unique ids in 2-D groups") changes how a thread's console flat id is derived, using a group-shared ticket, because a host may put threads of several rows into one wave; #2117 changes whether a wave size is declared at all, adding min_lanes and a Stop::Wide re-lowering for programs that only read within aligned groups of 4, 8, 16 or 32.

The question that decides how they land is about your premise for narrow groups. The argument for "an aligned group of k lanes never straddles a host wave" needs the host to fill its waves from consecutive flat ids in group order. #2126's description says that is not what some hosts do: an RTX 5070 Ti fills 2-D groups in 16 × 2 tiles ("24, 32 or 64 wide or not a power of two wide"), and XCL's notes report 2 × 2 quads on an RX 9070. If threads of one aligned group land in different host waves, then a narrow-group read is not within one wave after all, and #2126's ticket is what makes the ids line up again.

So:

I am not asking for both to be merged together; I am asking for the sentence that says which mechanism owns the 2-D case. At the moment two of them claim it and they disagree by construction.

A note on the evidence, since it decides what a reviewer can check: translate --validate will not show this. A declared or missing WaveSize is refused by the host when the pipeline is created, so the number that moves is the --pipelines count (or a boot), not the validated count. If either description has a before/after of that count on a host whose lane count differs from the console's, it would settle the review in one line; on this machine (NVIDIA, 32 lanes, 32.0.16.2124) I can measure it for whichever of the two lands first, and for the pair once they agree.

No game data is involved: file names, hosts and counts.

Written with an AI assistant.

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

Tested locally: macOS arm64, rustc 1.98.1, PR head merged into main 940d32f, cargo test -p victory-shader --locked.

144 passed / 0 failed / 2 ignored. Compute reading lanes only within aligned groups declares... — lane-group constraint declaration; mixed gpu+shader.

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

The lane-group table in lane_group (crates/victory-shader/src/emit/lower.rs) matches the GFX10 DPP and ds_swizzle encodings, and the whole-wave fallbacks (Stop::Wide, barriers, LDS, sections) are conservative. The blocker is lane_thread: it relabels threads as "first flat id of the host wave rounded down to the wave size, plus the lane". This is the assumption #2126 shows to be false for 2-D groups. On an RTX 5070 Ti, an RTX 4070 Ti and a Radeon iGPU, two host waves get the same base and half the ids are never used. With no WaveSize declared, the driver picks the wave size as well, so this PR applies that assumption on more hosts than main does.

This needs one of two changes: limit narrowing to 1-D groups ([n,1,1]), or take each wave's base from #2126's ticket using waveGetLaneCount(). It also needs a 2-D group shape in lane_group_tests. Separately, row_xmask with a mask below 4 is classed as 16 lanes. That is safe, only less narrow (see the comment linking 571b78a).


Generated by Claude Code

@KainanP

KainanP commented Nov 25, 2026 •

Copy link
Copy Markdown

Data for the triage's 2-D question, from an Intel UHD (Xe-LP, 16-lane waves). This head's 6 new tests pass there (the wave64-half test skips), and they all use a 1-D group. #2126's wave-layout probe on the same iGPU, without WaveSize, shows 1-D groups in aligned 16-lane runs but most 2-D groups in 4×4 tiles ([8,8,1] first wave = ids 0-3, 8-11, 16-19, 24-27). The probe reports relabel bijective false for 13 of the 19 shapes that are not [n,1,1], so lane_thread would repeat ids there as well. Full list in item 5 of #1829 (comment)

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

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.

7 participants