Skip to content

Elect the first active Wave64 lane before an EXEC branch splits the group - #4

Open
steven-seagull27 wants to merge 2 commits into
alfycs:feat/wave64-compute-emulationfrom
steven-seagull27:codex/pr189-firstlane-before-exec-split
Open

steven-seagull27 wants to merge 2 commits into
alfycs:feat/wave64-compute-emulationfrom
steven-seagull27:codex/pr189-firstlane-before-exec-split

Conversation

@steven-seagull27

Copy link
Copy Markdown

Fixes the divergent v_readfirstlane_b32 readback reported in upstream #189. Based on feat/wave64-compute-emulation at 3e39e34.

A read at the beginning of a single-entry active EXEC edge can elect across the whole guest wave in its group-uniform predecessor. The source VGPR must already be available there. This uses the existing Wave64 election and its shared scratch before the branch, then uses the elected value inside. It covers both s_cbranch_execz fallthrough and s_cbranch_execnz taken edges. Waterfalls and sources produced inside divergent control flow continue through the existing lowering. The latter can still return a host-local answer.

The regression uses two guest waves per group, six 128-thread readbacks per mode, and three masks. It exercises 40 active lanes spanning both halves, a first active lane at 39, and an entirely inactive second guest wave. Expected values include 0/64 and 39/103. Inactive destinations retain 42.

Adapter and lowering Wrong output dwords before → after, out of 768
RTX 5080, Emulate 48 → 0
RTX 5080, explicit Wave32 48 → 0
Windows built-in WARP (Wave4), Emulate 312 → 0
Microsoft.Warp 1.0.22, Emulate 208 → 0
Microsoft.Warp 1.0.22, explicit Wave32 48 → 0

The portable WARP emulation results repeated in three fresh processes. As a separate Native Wave64 control on that runtime, high-half-only cases intermittently returned the wrong SGPR on both revisions. This patch changes the two emulated modes. An AMD native Wave64 or Intel Wave16 run would be valuable.

The stock emit::wave64_tests:: suite passed 35/35 on the patched tree, as did a_lowering_refused_tries_supported_fallbacks, strict shader Clippy, and cargo xtask policy. The unfiltered shader library run stopped in heap_direct_texture_reads_mark_their_heap_index with Windows exception 0xc0000005 on this machine. The same test also stopped on the original code. No title run.

cargo test -p victory-shader --lib gpu_divergent_readfirstlane_spans_host_waves -- --nocapture

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.

1 participant