Skip to content

Shaders: emulate Wave64 compute shaders on Wave32 and narrower hosts - #189

Open
alfycs wants to merge 5 commits into
Marvisak:mainfrom
alfycs:feat/wave64-compute-emulation
Open

alfycs wants to merge 5 commits into
Marvisak:mainfrom
alfycs:feat/wave64-compute-emulation

Conversation

@alfycs

@alfycs alfycs commented Nov 24, 2026 •

Copy link
Copy Markdown

Problem

Wave64 compute shaders that rely on lane layout (console_lanes or single-wave LDS) currently emit WaveSize(64) (PSV0 min/max = 64). On 32-lane GPUs (NVIDIA/Intel) and narrower hosts such as WARP (WaveLaneCountMin = 4), D3D12 rejects these PSOs in CreateComputePipelineState with E_INVALIDARG (0x80070057).

Related to #71, #85, #97, #3.

Summary of Changes

  • Translation modes (victory-shader::emit):
    • Added Wave64Mode (Native, Wave32, Emulate), TranslateOptions, translate_with, and emit_with. Default translate/emit keep Wave64Mode::Native.
    • Added Host::supports_wave32 and Host::recommended_wave64_mode in emit::host, and checked DXGI_ADAPTER_FLAG_SOFTWARE in Host::new(true) for WARP environments.
  • Constant-lane SGPR spill resolution (victory-shader::resource):
    • Extracted index_values and added spilled_sgprs so constant-lane v_readlane_b32 reads from v_writelane_b32 (including spills to lanes >= 32 in <= 32-thread groups) resolve directly to their scalar values or constants.
  • Wave64 lowering (victory-shader::emit::lower):
    • Wave64Mode::Wave32:
      • <= 32 threads: runs inside one native 32-lane wave with zero scratch LDS or cross-half barriers, resolving SGPR spills, zeroing the high ballot dword, and supporting <= 32-thread LDS accesses directly.
      • > 32 threads: emits WaveSize(32) when wave emulation is needed and maps each virtual 64-lane wave onto two aligned 32-lane host waves ((waveReadLaneFirst(flattenedThreadIdInGroup) & !31) + waveGetLaneIndex()). ds_swizzle_b32, DPP (with out-of-range lane indices clamped via inside and row_mask indexed by 64-lane console_lane), v_mbcnt_*, v_writelane_b32, and lane_bit execute without cross-half barriers; 64-lane ballots, Shape::Active/Shape::Prefix, uniform-block non-uniform v_readfirstlane_b32 (with empty-EXEC fallback to lane 0), and unresolved v_readlane_b32 exchange through disjoint scratch LDS slots (handling partial virtual waves and enforcing the 32 KiB / 8192-dword TGSM limit).
    • Wave64Mode::Emulate:
      • Emits wave_size = None without setting flags::WAVE_OPS, using flattenedThreadIdInGroup + TGSM + barrier(1 | 8) for ballots (atomicOr), tree reductions (Shape::Active), Hillis-Steele scans (Shape::Prefix), v_readlane_b32, v_readfirstlane_b32 (atomicMin, with lane 0 fallback when empty), ds_swizzle_b32, and DPP.
    • Deadlock / divergence & LDS fence safety:
      • Post-dominator (compute_postdoms) + group-uniformity analysis (compute_uniformity, preserving val_uniform across unguarded v_mov_b32) ensures barriers are never emitted inside divergent control flow or inside begin_guarded blocks; unsafe divergent cross-half operations fail cleanly with ShaderError::Unsupported.
      • Cross-block ballots are pre-emitted in defining uniform blocks (preemit_masks), and per-instruction ballots/guards are materialized before operand evaluation (materialize_masks).
      • For 32 < threads <= 64 (Wave32) or 1 < threads <= 64 (Emulate) accessing LDS (has_lds_mem), plan_lds_fences inserts group-uniform barrier(1 | 8) checkpoints at uniform joins/exits (lds_fences.enter / lds_fences.leave), permits multiple divergent pure LDS reads, and refuses unfenceable divergent LDS write/read or write/write conflicts cleanly (LDS accesses without a uniform LDS fence in split wave64).
  • Host integration & cache (victory-gpu, apps/victory):
    • victory-gpu::Host queries D3D12 wave capabilities on open (recommended_wave64_mode) and updates shader_cache: native 64-lane hosts use Wave64Mode::Native, while < 64-lane hosts (including 32-lane NVIDIA/Intel GPUs and WARP) default to Wave64Mode::Emulate (which still leaves non-lane-dependent shaders native without scratch LDS, while avoiding Wave32 divergent/cross-half miscompilations). VICTORY_WAVE64_EMULATE=auto|wave32|1|0 remains available as an override (with the mode byte included in cache keys).
    • victory translate --pipelines passes the host's recommended Wave64Mode via emit_with.
  • Tests (crates/victory-shader/src/emit/wave64_tests.rs):
    • Added synthetic RDNA2 translation, validator, and live D3D12/WARP GPU readback tests (running under Wave32 and Emulate, plus host capability and Native PSO rejection checks).

Trade-offs & Known Limitations

  • Translator refusal count delta vs Wave64Mode::Native: Because Native emits WaveSize(64) DXIL that passes translation even when a Wave32 host rejects it in CreateComputePipelineState (E_INVALIDARG), enabling Wave32/Emulate replaces unsafe split-wave barriers/hazards with explicit ShaderError::Unsupported refusals. On the 26,084-program corpus tested by @bittertea0323, host CreateComputePipelineState compute rejections dropped from 97 to 0, while offline translation reported +26 refusals (14× "LDS accesses without a uniform LDS fence in split wave64" and 12× "a cross-lane wave operation in divergent control flow"). Translator refusal totals before and after this PR are therefore not directly comparable without accounting for PSO rejections.
  • v_readfirstlane_b32 in divergent control flow (Wave32): Because separate 32-lane hardware warps cannot enter a group barrier inside divergent control flow without risking a GPU deadlock, emulated_readfirstlane in Wave32 returns each half's own first active lane when divergent (Emulate refuses). This is exact when the value is uniform across active lanes or in half-local waterfall iteration, but if both halves are active in divergent control flow with differing first active lane values, the upper half (32..63) observes its own first active lane rather than the lower half's (0..31) as on Wave64.

Verification

On Windows (feat/wave64-compute-emulation @ 54b333f):

  • cargo xtask policy: 155 files ok
  • cargo clippy --workspace --all-targets --locked -- -D warnings -A deprecated: 0 errors, 0 warnings
  • cargo test -p victory-shader --locked -- wave64 --test-threads=1: 26 passed, 0 failed (including live GPU execution tests)
  • cargo test -p victory-gpu --locked -- --test-threads=1: 50 passed, 0 failed, 1 ignored
  • VICTORY_WARP=1 cargo test -p victory-shader --locked -- wave64 --test-threads=1: 26 passed, 0 failed

@ifBars

ifBars commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Tested d0fd9bf on Windows 10, RTX 3060 Ti, driver 610.88, with Agility SDK 620 exports added to the probe executable for this OS. I used four locally held compute shaders from first-story loading, including three large-group programs previously rejected by CreateComputePipelineState. On the build with #54 only the small-group program created a pipeline.

With this change, three of the four passed the Windows SDK DXIL validator and created native D3D12 compute pipelines. Two previously refused large-group shaders now work at pipeline creation. The remaining program (02384a60fda6f2d0) returned the translator diagnostic v_readfirstlane in divergent control flow at 0x1d0. This probe measured pipeline creation only.

@AKA0GHOST

Copy link
Copy Markdown

Tested on an RTX 5070 (Blackwell, 12 GB, driver 621.14, 32-lane waves only), Windows 11, diag build of d0fd9bf (main d2a4bae + this PR), own 1.0.2.1 copy.

Synthetic tests: all 14 wave64_tests pass on the hardware. I also added two lane-order probes: one console wave in 64×1×1, 8×8×1 and 4×4×4 groups, and four console waves in 256×1×1, 16×16×1 and 8×8×4 groups. The ballot count across halves and v_readlane of lane 50 come out right in both Wave32 and Emulate modes. So the (waveReadLaneFirst(flat) & !31) + lane mapping holds on Blackwell, 3-D groups included.

World run (VICTORY_D3D12_DRED=1), compared with an earlier run of main + #20 + #55 (a slightly older main, plus a local render-target view guard):

before this PR
compute pipelines refused (E_INVALIDARG) 88 0
compute shaders that do not translate 121 239
ended DEVICE_HUNG, frame 2967, 7.2 s submission DEVICE_HUNG, frame 2846, 7.7 s submission

Matching by hash: of the 88 refused before, 35 now build and 53 no longer translate. 107 shaders that translated and built before now fail with v_readfirstlane in divergent control flow (about 50) or a cross-lane wave operation in divergent control flow (about 38). That makes more dropped dispatches than before.

Likely cause: in Wave32 mode, need_emu = console_lanes || !sections.is_empty() || has_non_uniform_firstlane. On main, wave64 programs whose only lane use is a whole-wave section or a v_readfirstlane of a non-uniform value get no WaveSize and run on host waves. A waterfall loop's readfirstlane is likely still correct per 32-lane wave. This PR pulls those programs into the split form, and where the ops sit in divergent flow the check refuses the whole shader. Suggestion: refuse in divergent flow only when console_lanes is set. For programs split only because of sections or a non-uniform firstlane, fall back to the host-wave lowering (or retry without the split) instead of failing.

The world hang itself is unchanged with or without this PR.

AI-assisted (Claude Code); no game files attached.

@DaviTostes

Copy link
Copy Markdown

Tested d0fd9bf on Arch Linux x86_64, rustc 1.98.1: pass.

No game data used.

@dpalacios69

Copy link
Copy Markdown
Contributor

Validated PR #189 (d0fd9bf, clean mergeable against main d2a4bae) on a 32-lane NVIDIA Turing GPU under Linux + Wine + vkd3d-proton (AI-assisted).

Environment

  • GPU / Driver: NVIDIA GeForce GTX 1660 SUPER (Turing, 32-lane waves) / NVIDIA 620.70.06
  • Runtime: wine-11.21 (Staging) + vkd3d-proton 3.1.0 (4522cc1a8b1347f) + DXVK DXGI 2.7.1
  • Target: x86_64-pc-windows-msvc (--release)

Results

  • cargo test --release -p victory-shader --target x86_64-pc-windows-msvc: 82 passed, 2 failed, 0 ignored
    • All 14/14 emit::wave64_tests::* tests PASS on real 32-lane hardware, including all 9 emit::wave64_tests::gpu::* GPU execution tests (gpu_128_threads_cross_block_ballot_and_constant_mask, gpu_128_threads_ds_swizzle_and_dpp_row_mask, gpu_128_threads_readlane_writelane_spills_and_firstlane, gpu_64_threads_lockstep_lds_without_s_barrier, gpu_32_threads_wave32_fast_path_with_high_lane_spills, gpu_96_threads_partial_virtual_wave, gpu_128_threads_whole_wave_active_and_prefix, gpu_128_threads_uniform_loop_cross_half_ballot, gpu_64_threads_mbcnt_ballot_and_high_ff1).
    • Failures (2):
      1. emit::tests::stub_pipeline_is_created — baseline vkd3d-proton behavior (zero digest accepted).
      2. emit::host::tests::recommended_wave64_mode_matches_device_capabilities — panicked at crates/victory-shader/src/emit/host.rs:1465 (left: Wave32, right: Emulate). Under Wine + DXVK, EnumWarpAdapter is not supported and falls back to returning the first hardware adapter (DxgiFactory::EnumWarpAdapter: WARP not supported, returning first hardware adapter), so Host::new(true) opens the hardware GTX 1660 SUPER (Wave32) instead of a software WARP adapter. Checking DXGI_ADAPTER_FLAG_SOFTWARE in Host::new(true) (as victory-gpu/src/host.rs does) would avoid this false failure on Wine/DXVK.
  • cargo test --release -p victory-gpu --target x86_64-pc-windows-msvc: 40 passed, 3 failed, 1 ignored (matches main d2a4bae baseline: indirect::tests::argument_clamp_builds, pipeline::library::tests::a_rejected_blob_gives_an_empty_library, resource::tests::buffer_data_reaches_the_host_texture)
  • cargo xtask policy: PASS (asset policy: 152 files ok)

Summary

All 14 Wave64 translation and GPU execution tests pass on NVIDIA GTX 1660 SUPER (Wave32) under Wine 11.21 + vkd3d-proton 3.1.0. One minor test-harness issue: recommended_wave64_mode_matches_device_capabilities assumes EnumWarpAdapter only returns a software adapter, which fails under Wine/DXVK's hardware fallback.

No game data used.

@Vyral1978

Copy link
Copy Markdown

Tested d0fd9bf on Ampere, in the title up to the world. Pipeline refusals go away; the world hang stays, as in #71.

Setup: RTX 3070 8 GB (Ampere, 32-lane waves only), driver 610.88, i7-12700, 32 GB, Windows 11 26300. Release build of main d2a4bae + this PR, plus #40, #55, #74 and a local render-target-view guard (the one described in #71). #54 is not included: it conflicts with this PR in lower.rs and mod.rs, and this PR covers the same small-group case. Own 1.0.2.1 copy, two runs (cold, then warm shader cache).

Tests: cargo test --release -p victory-gpu -p victory-shader passes on this card, including all GPU wave64_tests (64, 96 and 128 threads, cross-half ballots, readlane/writelane, DPP row masks, the 32-thread fast path).

In the title:

d2a4bae + #40/#54/#55/#74 + this PR (no #54)
mode logged n/a wave64_mode=Wave32
compute pipelines refused (unique) 111 (0x80070057) 1 (0x8007000E, out of memory)
compute programs that do not translate (unique) 297 404
menus 30 fps 30 fps
world ~1 fps, ~64 s, then 0x887A0006 0.4–2.6 fps, ~40 s and ~44 s, then 0x887A0006
last slow host submission 5332 ms / 19 lists 5330 ms / 32 lists, 4938 ms / 31 lists

World time varies between 40 s and 2 min 20 s from run to run on this machine without any change, so I read the difference in world time as noise.

Where the refusals went: of the 111 programs refused on d2a4bae, 69 are now rejected at translation instead and about 41 build. The new translation failures (unique programs) are mostly this PR's own guards:

  • v_readfirstlane in divergent control flow is not supported: 77 (0 before)
  • a cross-lane wave operation in divergent control flow is not supported: 51 (0 before)
  • a lane mask holding lanes elsewhere read as data is not supported: +37

So on this title a large share of the wave64 compute programs still does not run on a 32-lane host, now as dropped dispatches instead of refused pipelines. That matches what others reported in #71: refusals are not what hangs the world.

No game files, captures or logs attached. AI-assisted (Claude Code).

@ifBars

ifBars commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

I ran the 128-thread gpu_128_threads_ds_swizzle_and_dpp_row_mask test from this branch on Windows 10 using Agility SDK 620 and app-local Microsoft WARP 1.0.22. In the Wave32 path, WARP removed its software device. The test passes with a small change in DPP row shifts.

For the first lane of a row, row_shr:1 subtracts one before the inside predicate gets applied. The lowerer still issues the lane read for that edge. Selecting the lane's own index when inside is false before the shuffle avoids passing an out-of-range source and preserves the existing bound_ctrl and write-mask behavior. All 128 outputs matched the synthetic reference afterward. WARP also reports support for native Wave64 on this version, so the test expectation that every software adapter selects Emulate needs to follow the advertised capabilities.

Causeway change. This was software-only. Gameplay and hardware-driver effects remain unmeasured. AI-assisted testing.

@Kam471

Kam471 commented Nov 24, 2026

Copy link
Copy Markdown

Data point from an RTX 5070 Ti (D3D12 wave range 32..32), diag build, retail title:

  • With Shaders: emulate Wave64 compute shaders on Wave32 and narrower hosts #189 applied, compute pipeline refusals go from ~111 to 0; 425 compute programs translate and the title gets past the intro.
  • The remaining device removal is not compute. Every DRED stop is a mesh dispatch. The console mesh programs have FSSM flags 0x110000 (bit 5 clear = wave64); their ISA derives lane numbers with v_mbcnt_lo/hi and 64-bit EXEC. On a 32-lane host wave, lanes 32..63 get the wrong numbers, mesh output is corrupted and the device eventually hangs.
  • Mesh PSOs cannot declare WaveSize(64), so today those pipelines are refused instead of run. That avoids the hang but drops the terrain/mesh geometry.

So #189 fixes the compute half of the wave64 problem; mesh needs the same two-halves-per-console-wave emulation through groupshared memory. No game data attached, only the header flag, instruction names and counts.

@tanishq-dubey

Copy link
Copy Markdown

Independent synthetic test of head d0fd9bf4b9a2b63d303e692c82c9fc8669642cc2 on Linux x86_64 with an RTX 5090 (NVIDIA 620.70.06), Wine 11.22, vkd3d-proton 3.2.0 and DXVK 3.1.1. Cross-built the Windows victory-shader test binary and ran wave64_tests --nocapture --test-threads=1: 14 passed, 0 failed. The native-wave64 rejection messages on the 32-wide adapter were expected by the tests.

Wine/DXVK reported that EnumWarpAdapter returned a hardware adapter, so this is not an independent WARP result. DXIL validator use was not separately confirmed. No game files used in these tests. AI-assisted.

@miniongk

Copy link
Copy Markdown

Tested head d0fd9bf on Windows 11 26300, RTX 5080 (32-lane), driver 621.24, with a local 1.0.2.1 copy.

  • cargo test --workspace: 279 passed, 0 failed, 4 ignored.
  • The title selected wave64_mode=Wave32.
  • It reached the world with no host-pipeline refusal in the run, versus refusals on current main.
  • The host device was still removed with DXGI_ERROR_DEVICE_HUNG after a compute submission; 450 shader translation attempts remained unsupported, many reported as cross-lane wave operations in divergent control flow.

So this improves the Wave64 path here but does not by itself close #97. Menus and first-boot rendering remained stable. Only counts and error classes are shared. AI-assisted (Kimi Code).

@Raxstreams

Copy link
Copy Markdown

Tested the PR head at d0fd9bf with 96 distinct compute shaders whose DXIL validated but whose D3D12 compute pipelines were refused on an RTX 3080 Ti. On this PR alone, 33/96 passed both validation and pipeline creation, including all three depth-pyramid shaders. Five more created a pipeline but failed DXIL validation. Of the 58 that did not emit, 30 reported a cross-lane operation in divergent control flow, 26 reported read-first-lane in divergent control flow, and two reported byte/half LDS writes. This was an offline test of pipeline creation.

@r4tedx

r4tedx commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Test report on a machine with a 32-lane and a 64-lane adapter.

Tested

  • NVIDIA RTX 5070 (D3D12 wave range 32..32) and an AMD Radeon iGPU (RDNA2, 32..64); Windows 11; Rust 1.98.1; debug.
  • This PR at d0fd9bf, translating with TranslateOptions { wave64: host.recommended_wave64_mode() }: Wave32 on the RTX 5070, Native on the Radeon.
  • Hand-assembled wave64 GFX10 compute programs (the ones in Shaders: wave64 compute on 32-lane hosts, in halves and in the console flow #233's split_tests.rs plus two more), each lane's output checked against the console's result, five runs each with identical results:
Program (64 threads unless noted) RTX 5070 (Wave32) Radeon (Native)
ds_swizzle xor 16 + DPP row_mirror, 64 and 128 threads exact exact
s_bcnt1 of lanes below 40, 64, 48 and 32 threads exact exact
v_readlane 40 exact exact
DPP row_mask:0x3 exact exact
DPP + v_readfirstlane (all lanes active) exact exact
LDS without s_barrier: every lane writes dword t, lanes below 20 then read dword t + 40 exact exact
v_readlane 10 inside a branch only lanes below 20 take refused exact
a loop lane t runs t times with v_readlane 40 in each iteration refused wrong, as on main (#225)

The two refusals are a cross-lane read in divergent control flow, as the description says. On main the RTX 5070 creates no pipeline for any of these programs, so every exact cell in its column is new. Forcing Wave32 and Emulate on the Radeon gives the RTX 5070 column there too.

  • cargo test -p victory-shader: 84 passed, 0 failed. One caveat: the first of 15 runs of the suite hung (the wave64_tests::gpu and valu_tests GPU tests still running after 10 minutes) and was killed. Other GPU tests were running on the same machine at the time, it did not happen again in 14 further runs, and I have no cause, so treat it as an observation, not a finding.

The two refused programs are the kind #233 / #320 run in their console flow (both halves take every branch together, so an exchange inside a divergent branch or loop is reached by both). The approaches fit together: this PR's exchanges for what the whole group reaches, including groups of several console waves, LDS and reductions, which #233 does not do; the console flow for exchanges in divergent code.

Not tested: the LDS case is exact in five runs with two groups, which does not rule out a race; release build; the title (no game files used).

AI-assisted.

@noxite-four-life

Copy link
Copy Markdown

Tested on a real RTX 5070 Laptop GPU (32-lane) with a GTA VI dump. With this PR applied (on main + #205 + #334), the host logs Wave64 compute lowering mode selected wave64_mode=Wave32 and the CreateComputeShader: wave lane count of 64 … maximum … is 32 rejections drop from 112 to 0 — every previously-refused compute PSO now creates (the "compute pipelines refused" from #71). The title progresses further into the world.

The world still doesn't render yet, but for a different reason now: ~395 compute shaders still fail translation on divergent lane ops (v_readfirstlane / cross-lane wave op / select on an untracked mask in divergent control flow — looks like #320's territory), plus some vertex/pixel/mesh gaps. The Wave64 size rejection this PR fixes is fully resolved on real NVIDIA hardware. Thanks!

edsuuu pushed a commit to edsuuu/VIctory-fork that referenced this pull request Nov 24, 2026
A wave64 program split over two 32-lane waves took the DPP row index
from the host lane, so the upper half (console rows 2 and 3) read
row_mask bits 0 and 1. The row now comes from the console lane there.
New test: v_mov_b32_dpp with row_mask:0x3 writes lanes 0 to 31 only,
exact on an RTX 5070 (split) and a Radeon iGPU (native).

Found in review against #189 and #192, which both get this right.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
itsonlysimbo pushed a commit to itsonlysimbo/VIctory that referenced this pull request Nov 24, 2026
A wave64 program split over two 32-lane waves took the DPP row index
from the host lane, so the upper half (console rows 2 and 3) read
row_mask bits 0 and 1. The row now comes from the console lane there.
New test: v_mov_b32_dpp with row_mask:0x3 writes lanes 0 to 31 only,
exact on an RTX 5070 (split) and a Radeon iGPU (native).

Found in review against Marvisak#189 and Marvisak#192, which both get this right.

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

Copy link
Copy Markdown

@Bullet18x, both examples from your WARP Wave32 report on Windows build 28000 point to the masked DPP shift-and-add. The combined shader packs the XOR-2 shuffle into the low 16 bits and the shifted sum into the high 16 bits, so we can check each half of the words you posted.

Lane Packed word, expected → got XOR-2 shuffle, expected → got Masked shift-and-add, expected → got
20 2555926 → 2818070 22 → 22 39 → 43
21 2686999 → 2424855 23 → 23 41 → 37

Both lanes are in an enabled 16-lane row. The expected sums are 20 + 19 = 39 and 21 + 20 = 41. This identifies which output differed in the combined shader. Running the operations separately on build 28000 would tell us whether the shift also fails on its own.

I ran the original 128-lane test and two new single-operation tests at PR head 54b333f on Windows 11 build 26300.10075. All 128 lanes matched in each test, in every mode listed. Each WARP version ran in five fresh processes, with the RTX 5080 tested alongside it.

Adapter Reported wave range Modes exercised Mismatches per 128 lanes, shuffle / masked shift / combined
RTX 5080, driver 621.24 32–32 Wave32, Emulate 0 / 0 / 0
Built-in Windows WARP 4–4 Emulate 0 / 0 / 0
App-local Microsoft WARP 1.0.22 4–128 Wave32, Emulate 0 / 0 / 0

Rerun on the affected machine. I kept the original combined test and added one shader for each operation. The test commit is directly on top of 54b333f. There’s also a downloadable patch.

From your checkout of this PR at 54b333f, using the same WARP setup as in your report:

git fetch https://github.com/steven-seagull27/VIctory.git refs/heads/codex/pr189-lane-checks
git cherry-pick 99135ba50a2392b3e7e444ea03625306e2efaa37
cargo test -p victory-shader --lib --locked -- gpu_128_threads_ds_swizzle gpu_128_threads_dpp_row_shr_mask_a --nocapture --test-threads=1

That command runs exactly the three tests. If the mismatch reproduces, could you share which test names fail for (Wave32, warp=true) and the actual and expected values at the first differing lane?

@meqsedus

Copy link
Copy Markdown

Tested this PR (54b333f) on NVIDIA: the world hangs come from translated shader loops running to the loop limit.

Setup: Windows 11, RTX 3050 Ti Laptop (4 GB, driver 32.0.16.2140), i7-11800H, 32 GB RAM. Each run used its own fresh VICTORY_CACHE_DIR.

Run Build / settings Result Slowest submission
main release, TdrDelay 10 device removed at 1:48 (cutscene start) 11.7 s
PR #189 release, TdrDelay 10 device removed at 2:04 11.4 s
PR #189 release, TdrDelay 60 device removed at 2:32, nvlddmkm 153 ~9 s into the submission 14.4 s
PR #189 diagnostics, VICTORY_D3D12_DRED=1 VICTORY_GPU_TIMING=1 device removed at 3:13 8.1 s
PR #189 diagnostics, VICTORY_SHADER_LOOP_LIMIT=4096 no hang, ran 8:40 until closed 0.44 s (avg 0.35 s)

DRED (diagnostics run): there was no page fault, so the GPU hung rather than faulted. The list stopped at command 82 of 135 (op 42). Commands 79..133 are mesh draws, mostly [mesh c962201cddbdd7dd, pixel 57a27c5e2e1d62a9], plus some [mesh 857b2e13c9cc107f, pixel 63051e97862e7dad]. Earlier crashes had other mesh pipelines in the failing submission, so I don't think it is one specific shader.

Takeaways:

  • On NVIDIA, this PR doesn't change stability compared to main: both hang once the world/cutscene starts.
  • Raising TDR doesn't help: the driver resets before 60 s.
  • With a lower loop limit the hangs go away, which per the README points at loops that hit the limit, i.e. likely a translation issue in some shaders' loop exit conditions.

I haven't found which shader yet. Happy to bisect with VICTORY_SKIP_PIPELINES or run other builds if useful.

@MrEjecutor

Copy link
Copy Markdown

RTX 5060 Ti (32-lane waves), offline over the retail shaders: the default Emulate mode leaves 43 fewer working compute pipelines than main; Wave32 gives 115 more; every program Emulate handles, Wave32 handles too

Tested 54b333f (this PR alone on main ffe310e), with victory translate <game dir> --validate --pipelines --list on an RTX 5060 Ti (driver 621.24, Windows 11 26200, Rust 1.100). "Working" below means the compute program translated, validated, and its host pipeline was created on this card.

working compute pipelines vs main
main ffe310e 1,121 of 2,582
this PR, default mode (Emulate) 1,078 +94, −137
this PR, Wave32 mode 1,236 +117, −2

What Emulate loses (working on main, refused here): 132 with v_readfirstlane in divergent control flow (emulated_readfirstlane refuses it unless the mode is Wave32), 3 with a lane mask from a carry, 2 with LDS exceeding 32 KiB with wave64 emulation. The families include sr_denoising (10), indirect_diffuse_lighting (7), WaterSimMgr (7), smh_accessory (6), ambient_map (5), water_shading (5).

Per program, the set that works with Emulate is a subset of the one that works with Wave32 (0 programs work only with Emulate; 158 only with Wave32). So a per-program fallback, Emulate first and Wave32 only for a program the emulation refuses, would keep Emulate wherever it applies and reach the same 1,236.

The same numbers come out of #1589 at d83d4f8 against the stack under it (ca601f0): 1,652 → 1,609 working compute pipelines (+97, −140, 135 of them v_readfirstlane in divergent control flow). So it is this PR's default, not the bundle's merge.

Caveat: this counts what translates and builds, not what runs correctly. The comment in host.rs says Wave32 has divergent and cross-half miscompilations, and I have not checked any of these programs' output. To count Wave32 offline I changed one line locally in apps/victory/src/translate.rs so it honours VICTORY_WAVE64_EMULATE=wave32 (the runtime already does, through shader_cache.rs); that change is not proposed here.

Not tested: the title with either mode; AMD (native wave64, unaffected); #1589's newer head 60fa5d7.

AI use: Claude Code (Claude Opus 5.5) built, measured and wrote this; checked by mrejecutor.

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Needs rebase. This PR does not merge cleanly into current main (ac2525d). Conflicting files: crates/victory-gpu/src/host.rs, crates/victory-gpu/src/shader_cache.rs, crates/victory-shader/src/emit/lower.rs, crates/victory-shader/src/emit/mod.rs, crates/victory-shader/src/emit/valu_tests.rs.

The content has not been reviewed yet; it will be once the branch is rebased onto main.


Generated by Claude Code

@alfycs
alfycs force-pushed the feat/wave64-compute-emulation branch from 54b333f to cde7bff Compare November 25, 2026 00:28
alfycs added a commit to alfycs/VIctory that referenced this pull request Nov 25, 2026
…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 #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>
@moe-miau

Copy link
Copy Markdown

#189 carried onto main 70564ae, with in-game results on an RTX 4070 SUPER

@alfycs, since main moved by 28 commits last night, this PR conflicts in gpu/host.rs, gpu/shader_cache.rs, emit/mod.rs, emit/valu_tests.rs and emit/lower.rs (9 hunks). I carried it onto 70564ae. Use it or ignore it as you like:

How the conflicts were resolved

  • mod.rs: options goes into main's new parts closure, so both of its lowering attempts (with and without killed helper lanes) get it.
  • shader_cache.rs: main's redesigned cache (refusals stored, from-disk flag) with your mode byte in the key and VICTORY_WAVE64_EMULATE.
  • host.rs: main's multiply-add fusing check and your mode selection both run.
  • lower.rs:
    • find_sections gives way to your compute_sections (main had not changed its body).
    • mask_dword keeps your emulated path, and the native path takes main's new mask_number for a mask holding lanes elsewhere. The high dword is zeroed for Wave32 with 32 threads or fewer, as you do for ballots.
    • The DPP code keeps your in-range source lane, plus main's helpers_read quad path.
    • Main's new ds_bpermute_b32 stays ahead of your check on the title's own LDS size.
  • New on main, needing handling in your code:
    • Op::AddH added to apply_wave_op.
    • Shape::Half refused in a split 64-lane wave, since its host wave operation would only cover one half.

One harness change was needed. After the merge, all 11 wave64_tests::gpu tests removed the device on NVIDIA. The DXIL of your emulation was identical before and after (checked with dxc -dumpbin). The only difference was main's new view-stride table: every heap buffer read now goes through root SRV t255, and run_on_hosts passed no roots, so the shader read an unbound root view. The port binds a stride table for the raw UAV in heap slot 0. With that, all 26 wave64 tests pass on the RTX 4070 SUPER, the 11 GPU ones included. On your original head on ffe310e they also pass here.

I added one test, gpu_8x8x4_threads_console_lanes_follow_the_flat_thread_index. XCL's notes on the same technique (docs/wave64-on-wave32.md) report that an RTX 5070 Ti does not form its 32-lane waves from consecutive flat thread indices for an 8×8×4 group, which would break the (waveReadLaneFirst(flat) & !31) + laneIndex mapping. The test checks v_mbcnt against flat % 64 for an 8×8×4 group. It passes in both modes on the RTX 4070 SUPER, so it is a guard for other GPUs, not a reproduction.

CI-equivalent checks on the branch: both clippy configurations are clean, and cargo xtask policy passes. In cargo test --workspace, 5 tests fail, the same 5 that fail on plain 70564ae on this card: the two NVIDIA heap-cap tests (#1770 covers them) and three host-GPU shader tests.

In-game. Setup:

Build Pipelines refused Shaders not translated GPU removal
70564ae + #968 (no port) 137 about 19 none in 240 s and 420 s runs
+ port, Emulate (default on this GPU) 0 155, 77 of them split-wave refusals 0x887A0006 at 224 s
+ port, VICTORY_WAVE64_EMULATE=wave32 0 112, 43 of them split-wave refusals 0x887A0006 at 271 s
+ port + #1733, wave32 0 96, 38 of them split-wave refusals 0x887A0006 at 203 s

The 3D picture stays black in all of them. Two points:

  1. Wave32 beats Emulate on coverage here too: 43 split-wave refusals against 77. That agrees with the offline counts above. On this evidence I'd make Wave32 the default on 32-lane hosts.
  2. The removal is the watchdog, not an invalid command.
    • Before each removal, single submissions take 2.5 to 7 s.
    • With VICTORY_D3D12_DRED=1 VICTORY_GPU_TIMING=1, the slowest single command is dispatch 16x16x16 [compute 00167d58cc5a78d7] at about 7 s. That is the same with the port (6.9 s) and without it (7.2 s), and that baseline also timed out under the timing overhead.
    • Next come dispatch 128x64x1 [compute 42683eebec081520] (1.5 s) and indirect mesh draws (about 1.2 s each).
    • VICTORY_SHADER_LOOP_LIMIT=1024 makes cutscene frames about ten times faster (about 1.1 fps against 0.1 fps).
    • So loops with huge trip counts dominate, as in World frames hang the GPU (TDR) on an RTX 4070: compute shaders with ~1 s dispatches, wave64 refused by NVIDIA #1581. The port only adds work by running the roughly 140 programs that were refused before.
    • VICTORY_SKIP_PIPELINES on the shader DRED named (f607780aa8e502d0, indirect) does not prevent the removal.

These are single runs per build, with no debug layer and no cache warm-up. Counts and times only, no game data.

AI-assisted (Claude Code); runs done on my machine.

@alfycs
alfycs force-pushed the feat/wave64-compute-emulation branch from cde7bff to d3cd1cb Compare November 25, 2026 00:31
alfycs added a commit to alfycs/VIctory that referenced this pull request Nov 25, 2026
…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 #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>
alfycs and others added 5 commits November 25, 2026 01:44
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 #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.
@alfycs
alfycs force-pushed the feat/wave64-compute-emulation branch from d3cd1cb to 9580571 Compare November 25, 2026 00:45
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.