Skip to content

Wave64 VS / PS on 32-lane GPUs: the lanes 32..63 they read (NVIDIA) - #133

Merged
ivall merged 3 commits into
xcl-dev:mainfrom
Foniass:nvidia/wave64-graphics-lanes
Nov 23, 2026
Merged

ivall merged 3 commits into
xcl-dev:mainfrom
Foniass:nvidia/wave64-graphics-lanes

Conversation

@Foniass

@Foniass Foniass commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

The last open NVIDIA gap from HANDOFF / #42: wave64 VS / PS on GPUs with 32-lane waves only.

Problem

On NVIDIA the driver runs a console wave64 VS / PS in waves of 32: a console wave whose lanes 32..63 aren't populated. On the console those lanes exist (inactive) and hold whatever v_writelane or whole-wave code put there. Here they don't exist, and WaveReadLaneAt of a lane ≥ 32 reads lane & 31. wave_hazards flagged 749 programs of the retail pack.

What those programs do (748 PS, 1 VS)

pattern reads programs what the console reads there before, on NVIDIA
whole-wave reduction (identity into lanes outside the mask, DPP8 xor 1/2/4, row_mirror, v_permlanex16, v_readlane 32; min_u32 / max_u32 / or_b32) 1 082 436 the identity right only by accident: lane 32 read lane 0, and min / max / or are idempotent
waterfall read v_readlane v, s_ff1(mask & exec) 355 353 a lane < 32 right
SGPR spill slots in lanes 32..47 of one VGPR 200 11 the spilled SGPR wrong: the v_writelane was lost, the read returned slot lane & 31
ds_bpermute 0 0 — —

Change

  • Analysis: gpu/recomp/upper_lanes.rs, a forward pass. It follows EXEC's upper word (0 / all ones / anything) through the SGPRs, and what each VGPR's lanes 32..63 hold:
    • unwritten;
    • a constant (it evaluates whole-wave moves, selects, integer min / max / logic / add and their DPP and permlane forms);
    • a spill slot;
    • unknown.
  • Translation (split_wave64, when WaveGetLaneCount() < 64):
    • A lane ≥ 32 that holds a constant reads the constant.
    • A spill slot is read from a scalar shadow that its v_writelanes also write.
    • Spill slots < 32 come from their shadows at any wave size, because a lane a partial wave didn't launch loses its slot. 287 PS spill to lanes < 32.
    • Only programs with such a read get the new form: 613 in the pack, and DXC compiles all of them.
  • Unchanged HLSL: without split_wave64 (AMD and other 64-lane GPUs) the HLSL of all 26 698 programs is unchanged. The 32-lane form of the other modes is unchanged too; retail_wave64_graphics_lane_forms compares the digests.
  • Graphics pipelines (hle/d3d12x/real.rs): the pipeline hook compiled VS / PS with console_to_dxil (split_wave64 false), so on NVIDIA the split form never reached a title. VS / PS, and the PS of two-pass (MS / GS) pipelines, now pass wave32_only(device) like compute and the geometry stages.
  • wave_hazards: now reports only the reads the pass can't follow; there are none in the pack. xcl shaders --recomp prints the resolved reads by kind.

Tests (RTX 5070 Ti, 32-lane waves)

  • GPU tests: these three fail with the old translation on this card, and pass now:
    • gpu_wave64_ps_whole_wave_reductions: the pack's reduction as min and as a sum, plus the waterfall read, per hardware wave against a console wave of the same lanes.
    • gpu_wave64_ps_spill_slots: full target and a 6-pixel triangle.
    • gpu_wave64_vs_spill_slots_and_identity: 3 vertices.
  • Unit tests: upper_lanes has 9, including v_swaprel, SDWA v_cmpx and absorbing constants found in review; they fail without the fix.
  • Workspace: cargo test --workspace --release with XCL_SAMPLE_RPF: 560 passed, 0 failed, 2 no wave64 skips as on main.
  • Retail census: the ignored retail_wave64_graphics_lane_census / _forms run on the retail pack.
  • Minecraft (NVIDIA): menu and a world render the same as main, 60 fps.

Not exact yet (documented in docs/wave64-on-wave32.md)

  • Partial waves, on every GPU: in a partial wave (a triangle edge) the reduction reads lanes the PC GPU never launched; the console runs whole-wave code in its inactive lanes too. On the 5070 Ti those read 0, so a min reduction over a 3-quad wave returns 0. max, or and sum come out right. 325 of the 436 reduction programs contain a min. This predates the change and also happens on AMD.
  • Possible fix: recognise the whole reduction and use WaveActiveMin / Max / BitOr. That would change the HLSL AMD gets, so it isn't part of this PR; your call.

Once, during a full test run with another heavy session on the machine, the lib test binary died with an access violation in the hle::d3d12x descriptor-heap tests. It didn't come back in 35 further runs (25 of that module alone, 10 of the whole lib).

🤖 Generated with Claude Code

Foniass and others added 3 commits November 23, 2026 15:22
On a GPU with 32-lane waves only (NVIDIA) the driver runs a console wave64
VS / PS in waves of 32: a console wave whose lanes 32..63 are not populated.
Those lanes exist on the console (inactive) and hold what v_writelane or
whole-wave code put there; here they do not exist, and WaveReadLaneAt of a
lane >= 32 reads lane & 31.

The 749 programs wave_hazards flagged in the retail pack (748 PS, 1 VS):
- 1 082 reads in 436 programs: whole-wave reductions (identity into the
  lanes outside the mask, DPP8 xor 1/2/4, row_mirror, v_permlanex16,
  v_readlane 32 for the upper half; min_u32 / max_u32 / or_b32). Right only
  because lane 32 reads lane 0 and those ops are idempotent.
- 355 reads in 353 programs: waterfall reads, v_readlane v, s_ff1(mask &
  EXEC) - a lane < 32. Right.
- 200 reads in 11 programs: SGPR spill slots in lanes 32..47. Wrong: the
  v_writelane is lost, the read gets another slot.

upper_lanes.rs follows what the console's lanes 32..63 hold through the
program (forward pass: EXEC's upper word through the SGPRs as 0 / all ones /
anything; per VGPR lane unwritten / a constant / a spill slot / unknown,
evaluating whole-wave moves, selects, integer min / max / logic / add and
their DPP forms). With split_wave64 a wave64 VS / PS reads a lane >= 32 that
holds a constant as the constant, and a spill slot from a scalar shadow its
v_writelanes also write, when WaveGetLaneCount() < 64. Spill slots < 32 come
from their shadows at any wave size: a lane a partial wave did not launch
loses its slot (287 PS spill to lanes < 32). Only programs with such a read
get the form (613 of the pack; DXC compiles all). Without split_wave64 the
HLSL of all 26 698 programs is unchanged, and so is the 32-lane form of the
other modes (digests compared with main, retail_wave64_graphics_lane_forms).

wave_hazards now reports only reads the pass cannot follow: none in the pack.

GPU tests on an RTX 5070 Ti: gpu_wave64_ps_whole_wave_reductions (the pack's
reduction as min and as a sum, and the waterfall read, per hardware wave
against a console wave of the same lanes), gpu_wave64_ps_spill_slots (full
target and a 6-pixel triangle), gpu_wave64_vs_spill_slots_and_identity (3
vertices). With the old form all three fail there.

Not exact yet, on every GPU: whole-wave code in a partial wave reads lanes
the PC never launched. On the 5070 Ti they read 0, so a min reduction gives
0 in a partial pixel wave (325 programs have one); max / or are right.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The pipeline hook compiled console VS / PS with console_to_dxil (split_wave64
false), so on a GPU with 32-lane waves the upper_lanes form never reached a
title: only the tests saw it. VS / PS of a graphics pipeline and the PS of a
two-pass (MS / GS) pipeline now pass wave32_only(device), as compute and the
geometry stages already did.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Found in review, none of them reached in the retail pack:
- v_swaprel_b32 writes v[src0 + m0] and v[dst + m0]: any VGPR, as v_movrel*.
- An SDWA v_cmpx writes EXEC only; it was taken as writing VCC (with EXEC's
  zero upper word), so a stale all-ones VCC read as a lane mask.
- An operation on a lane nothing wrote is not "unwritten" when a constant
  decides it (0 & x, -1 | x, min / max with their extreme); x ^ x may be
  0 – unknown.

Unit tests for each; they fail without the change.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
ivall added a commit that referenced this pull request Nov 23, 2026
@ivall
ivall merged commit 84414e1 into xcl-dev:main Nov 23, 2026
@ivall

ivall commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator

Merged - thanks, a very clean one. Checked on Windows 11 with an RX 9070 (RDNA4, 64-lane waves):

  • cargo test --workspace green with the retail samples (529 lib tests), and the lib tests with XCL_SPLIT_WAVE64=1; the three new GPU tests pass on AMD too.
  • retail_wave64_graphics_lane_forms: 613 changed VS / PS, all compile. I also ran the same test (with XCL_FORMS_NO_DXC=1) on main before the merge: native-form digest ac67db269b7452be and other-modes 32-lane digest 09d45ad13eddc30d on both, so AMD's HLSL is indeed unchanged.
  • Retail survey still 26 698 / 26 698.
  • XDefiant and Minecraft run, with and without XCL_SPLIT_WAVE64=1 (the forced 32-lane form on AMD; XDefiant stays black for a while there since that form starts from a cold shader cache).

On the partial-wave min reduction: recognising the whole reduction and emitting WaveActiveMin / Max / BitOr sounds right to me, even if it changes AMD's HLSL - as a separate PR, with a GPU test of a partial wave and the census numbers like here.

mastrr9 added a commit to mastrr9/xcl that referenced this pull request Nov 24, 2026
CreateCommittedResource (xcl-dev#127) and CreatePlacedResourceX (xcl-dev#133) of the
newer device layout take a D3D12_BARRIER_LAYOUT for the initial state,
which layout_state() turns into a legacy resource state. It knew layouts
0 to 10 only, so the DIRECT_QUEUE_* and COMPUTE_QUEUE_* layouts (18 to 29)
and SHADING_RATE_SOURCE (11) all became COMMON: a texture made in
DIRECT_QUEUE_SHADER_RESOURCE or COMPUTE_QUEUE_UNORDERED_ACCESS started in
COMMON on the PC while the title treats it as already in that layout.

Assisted-by: Claude Code (Claude Opus 5.5)
IvyNotFound pushed a commit to IvyNotFound/xcl that referenced this pull request Nov 25, 2026
…rceBarrier

Console command list slot xcl-dev#146 is ID3D12GraphicsCommandList7::Barrier(NumBarrierGroups, pBarrierGroups) on both older and newer layouts; previously it emitted only a wildcard UAV barrier, dropping every texture layout transition.

- Parse D3D12_BARRIER_GROUP (GLOBAL, TEXTURE, BUFFER) safely with readable() checks; unparseable calls fall back to the legacy global UAV barrier.
- Map D3D12_BARRIER_LAYOUT 0..=31 including 0x1F (DIRECT_QUEUE_GENERIC_READ_COMPUTE_QUEUE_ACCESSIBLE) and fall back to access bits for console-only layouts > 0x1F; align device xcl-dev#127/xcl-dev#133 initial layout states with texture-vs-buffer awareness.
- Track whole-resource states across xcl-dev#127/xcl-dev#133 creation, legacy xcl-dev#26, and enhanced xcl-dev#146 (cleared on res_release) for UNDEFINED Before layouts, forward emitted transitions to title_textures::note_transitions, emit wildcard aliasing barriers for UNDEFINED placed textures, keep non-UAV textures out of UNORDERED_ACCESS, and skip states disallowed on compute/copy lists.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants