Skip to content

GPU: a Wave64 lowering that refuses a program tries the other emulation, then native - #3

Closed
KevinPratap wants to merge 13 commits into
alfycs:feat/wave64-compute-emulationfrom
KevinPratap:wave64/fallback-other-lowering
Closed

KevinPratap wants to merge 13 commits into
alfycs:feat/wave64-compute-emulationfrom
KevinPratap:wave64/fallback-other-lowering

Conversation

@KevinPratap

Copy link
Copy Markdown

A small addition for Marvisak#189, on top of its head 9db4e94.

What

shader_cache::host_shader translated with the one Wave64 mode the host asked for. The two emulations refuse different programs, so a program refused by the asked-for mode now tries the other emulation, then Native. The error kept is the asked-for mode's. lowerings(mode) gives the order, and there's a unit test for it.

Why

On an RTX 4050 Laptop (32 lanes, driver 621.24, Windows 11), the translate report gives these compute programs emitted (of 2,679):

Mode Emitted Top refusals
native 2,621 (about 394 of these need WaveSize(64), which the host then refuses)
emulate 2,165 v_readfirstlane in divergent control flow (217), LDS without a uniform fence (148), 64-lane ballot in divergent flow (76)
wave32 2,363 LDS without a uniform fence (146), cross-lane op in divergent flow (111)

translate --cache --pipelines on the full shader pack:

Container refusals Pipelines the host refuses
native 307 395
emulate alone 768 1 (plus 517 compute that don't translate)
wave32 + this fallback 307 257

So the fallback keeps every program native could translate, and still gains the ones only one emulation handles.

Testing

  • cargo test -p victory-gpu --lib shader_cache: 4 passed.
  • cargo clippy -p victory-gpu --all-targets: clean.
  • Same machine, a world run with this on (VICTORY_WAVE64_EMULATE=wave32): draws dropped as "refused" fell from about 100 to 69 per frame. Total drops fell from about 175 to 125.

AI-assisted (Claude Code).

🤖 Generated with Claude Code

alfycs and others added 13 commits November 25, 2026 11:18
Add Wave64Mode (Native, Wave32, Emulate) and TranslateOptions so Wave64 compute shaders lower and run on 32-lane GPUs (NVIDIA/Intel) and narrower hosts such as WARP instead of failing CreateComputePipelineState with E_INVALIDARG on WaveSize(64).

- Add Wave64Mode, TranslateOptions, translate_with, and emit_with while keeping translate/emit defaulting to Wave64Mode::Native.
- Resolve constant-lane SGPR spills across v_writelane_b32/v_readlane_b32 via resource::spilled_sgprs.
- Implement virtual 64-lane mapping for Wave32 (two aligned 32-lane waves) and portable LDS emulation without WAVE_OPS for narrower hosts, with post-dominator uniformity checks to reject cross-half barriers in divergent control flow rather than hanging.
- Auto-detect host wave capabilities in victory-gpu::Host (with VICTORY_WAVE64_EMULATE override and mode byte in shader_cache keys) and in victory translate --pipelines.
- Add synthetic RDNA2 compute tests (PSO validation + execution on hardware GPU and WARP).
…PP, host)

Incorporate verified follow-up fixes from PR Marvisak#189 reviewers and contributors:

- Fence single-console-wave LDS accesses at group-uniform joins/exits and reject unfenceable divergent regions (fixes marquezinii's split-block stale LDS readback; from alfycs#1 by @erickbobd).
- Allow Wave32 divergent v_readfirstlane per half without LDS barriers (fixes waterfall loops / common divergent refusals reported by @AKA0GHOST and @NuraadGit), preserve ValUniform propagation across unguarded v_mov_b32 copies for uniform v_readfirstlane in divergent branches (@marquezinii), and return lane 0 when EXEC == 0 in emulated_readfirstlane.
- Clamp DPP row_shr/row_shl lane indices using inside before read_lane/exchange_64 to avoid out-of-range waveReadLaneAt on WARP 1.0.22 (@ifBars).
- Verify DXGI_ADAPTER_FLAG_SOFTWARE in shader::emit::host::Host::new(true) for Wine/DXVK (@dpalacios69, @tanishq-dubey), base recommended_wave64_mode_matches_device_capabilities on queried capabilities (@ifBars), and serialize wave64 GPU tests under valu_tests::ONE_AT_A_TIME (@r4tedx).

Co-authored-by: erickbobd <188809599+erickbobd@users.noreply.github.com>
Avoid false positives in plan_lds_fences on Wave32:

- Skip need_lds_barriers in Wave32 when total_threads <= 32 (single native host wave).
- Track reads vs writes/atomics separately in plan_lds_fences so multiple pure ds_read* instructions inside a divergent region or loop are allowed while RAW/WAW/WAR hazards remain rejected.
Log every rejected adapter and WARP in Host::all_adapters(), and print SKIPPED <test>: no SM 6.6 adapter instead of panicking on an empty host list. This makes Turing/SM 6.5 machines diagnosable instead of producing identical failures.
…on, then native

The two 64-lane emulations refuse different programs: Wave32 those with a
cross-lane operation in divergent control flow, Emulate those with a
non-uniform v_readfirstlane there. A program the asked-for lowering refuses
now tries the other one, then the native lowering; the refusal reported is
the asked-for one's. On an RTX 4050 Laptop (32 lanes) this takes the shader
pack's pipelines the host refuses from 395 (native) to 257, with the same
307 container refusals as native.

AI-assisted (Claude Code).

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

alfycs commented Nov 25, 2026

Copy link
Copy Markdown
Owner

Cherry-picked into feat/wave64-compute-emulation, rebased onto 67e8ae1, and verified locally (38 passed; 0 failed + a_lowering_refused ok). Thank you!

@alfycs alfycs closed this Nov 25, 2026
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.

4 participants