Skip to content

GPU+shader: translate wave64 programs for 32-lane host waves when WaveLaneCountMax < 64 - #2176

Open
n-romanovich wants to merge 3 commits into
Marvisak:mainfrom
n-romanovich:pr/wave32-translation
Open

n-romanovich wants to merge 3 commits into
Marvisak:mainfrom
n-romanovich:pr/wave32-translation

Conversation

@n-romanovich

Copy link
Copy Markdown

Summary

NVIDIA and Intel GPUs only execute 32-lane compute waves (WaveLaneCountMax < 64) and reject pipelines declaring WaveSize(64).

This adds Wave32 host translation mode so wave64 console programs run as two 32-lane host waves instead of failing pipeline creation:

  • Query D3D12_FEATURE_DATA_D3D12_OPTIONS1 in victory-gpu (host_wave32(), overridable via VICTORY_HOST_WAVE32).
  • Add set_host_wave32 / host_wave32 in victory_shader::emit and emit WaveSize(32) when enabled, masking wave lane indices in read_lane, ds_bpermute, and cross_lane via host_wave() / host_lane().
  • Include the Wave32 setting in victory-gpu::shader_cache::key so Wave32 and Wave64 shader caches stay isolated.

Verification

Tested on NVIDIA GeForce RTX 5060 Ti:

  • cargo test --release -p victory-shader --lib -- diff_tests valu_tests: 33 passed; 0 failed
  • cargo test --release -p victory-gpu --lib -- shader_cache: 3 passed; 0 failed

@iGoldenNinja

iGoldenNinja commented Nov 25, 2026 •

Copy link
Copy Markdown

Correction. My original ds_bpermute_b32 fixture used the wrong expected result. On RDNA2 the permute stays within each 32-lane half of a Wave64. The observed values, 1000 in lanes 0–31 and 1032 in lanes 32–63, match that rule. I withdraw the claim that the fixture found a ds_bpermute_b32 regression. Thank you @upipibi for pointing out the distinction. AMD RDNA2 ISA, section 10.4.4 · XCL native hardware checks

The original PSO result stands. RTX 5080, driver 617.14, Windows 11 Pro build 26200.9974, PR head 3feadc6. Three of four matched compute inputs translated and validated with host Wave32 off and with it on. Those PSOs went from 0/3 created to 3/3. The fourth input reached a separate descriptor translation refusal in both modes. Successful PSO creation does not establish shader output parity.

I also independently reproduced @Dathinel's actual v_readlane_b32 issue on this RTX 5080. Selecting guest lane 5 produced 5 in the lower half and 37 in the upper half. Selecting guest lane 32 produced 0 and 32, respectively. Every lane should receive the selected guest lane's value. Both synthetic DXIL pipelines validated, ran, and failed their readback assertions. The corrected permute fixture passed.

Corrected test report · Synthetic fixtures

OpenAI Codex (GPT-6) ran the RTX 5080 tests and drafted this correction.

@Dathinel

Dathinel commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

The cross-half issue also affects scalar v_readlane_b32. I ran the same ten synthetic GFX10 words on an RTX 3050 Laptop with host Wave32 explicitly enabled on the revisions below. One 64-thread group starts with v0 = tid.x, executes v_readlane_b32 s12, v0, 32, and stores the result to out[tid.x].

Revision Threads 0–31 Threads 32–63
This PR, 3feadc6 0 32
#189, 9580571, Wave32 mode 32 32
#439, 5a11cf4, 32-lane target 32 32
Expected 32 32

All three pipelines dispatched successfully. This tests scalar v_readlane_b32 specifically. Until the two waves exchange values, it would be safer to reject this cross-half read than return the wrong scalar.

Fixture words (hex), raw UAV at heap index 0: d760000c 00014100 7e06020c be810380 f4080200 fa000000 341e0082 e0701000 8002030f bf810000.

Control with lane 5: changing only the source lane from 32 to 5 produced 5 for threads 0–31 and 37 for threads 32–63 on this PR. On #189 and #439 all 64 threads returned 5. A guard that only rejects indices above 31 would miss this case.

AI-assisted; synthetic inputs only.

@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, Rust 1.98.1 MSVC):

  • cargo test -p victory-gpu --lib shader_cache:: — 3 passed, 0 failed
  • cargo test -p victory-shader --lib emit::lower::tests:: — 21 passed, 0 failed
  • cargo clippy -p victory-gpu -p victory-shader --all-targets — 0 warnings
  • cargo xtask policy — ok (183 files ok)

Clean host-wave32 translation path and cache-key inclusion for wave64 programs on hosts with WaveLaneCountMax < 64. Looks good.

AI-assisted (Gemini 4 Neon).

@upipibi

upipibi commented Nov 25, 2026 •

Copy link
Copy Markdown

Update for fb99078: this note was on an earlier head. fb99078 refuses cross-half v_readlane_b32 / v_writelane_b32 in compute and ballots or s_bcnt1 / s_ff1 that read EXEC or VCC as numbers. A constant 64-bit EXEC is still taken from the low word in both halves (measured: #2176 (comment)). (Edited: I removed a sentence claiming s_cbranch_execz / vccz can send the halves different ways. That was wrong: here each lane branches on its own bit.)


Overlap note: #189 (alfycs) and #233 / #320 / #439 (r4tedx) also run wave64 programs on 32-lane hosts, and they emulate the operations that cross the halves. This PR runs each half as its own 32-lane wave, and host_lane maps a console lane to lane & 31, so anything that needs the other half or the whole 64-bit mask comes out per-half:

  • v_readlane_b32 / v_writelane_b32 with lanes 32–63 read or write the reader's own half (Dathinel's v_readlane_b32 s12, v0, 32 above), and v_readfirstlane_b32 in the high half returns a high-half lane.
  • 64-bit masks: v_cmp into VCC and s_*_saveexec are per-lane booleans here and are fine. Reading EXEC or VCC as a number (ballots, s_bcnt1 / s_ff1) sees 32 bits; fb99078 refuses those. A constant or SGPR-pair EXEC still takes the low word in both halves (measured, linked above). (Edited: the first version said v_cmp and s_*_saveexec see 32 bits; they don't.)
  • ds_bpermute_b32 is fine with the mask: in wave64 it stays inside each 32-lane half. XCL Shaders: signature rows of one register in the validator's order #1022's test of that passes on native wave64 AMD hardware (RX 7600 XT, RDNA3); I know of no RDNA2 measurement.

Programs without cross-half operations run correctly this way, which matches iGoldenNinja's 3/3 PSOs. For the rest, #233 refuses by name what it can't emulate yet. Taking this as a fallback only for programs with no cross-half operation, or building on #233's split, would avoid silently wrong lanes.

AI-assisted (Claude Code); source read only.

@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 (shader half; the GPU half is Windows-only).

144 passed / 0 failed / 2 ignored. Wave64 programs translated for 32-lane host waves — wave64→wave32 translation; relates to #189/#233/#1960's wave64 cluster. Shader side green; GPU execution path needs Windows hardware validation.

@sinan-cmyk

Copy link
Copy Markdown

Offline measurement on a retail dump

Result: no count change against main.

I merged head 3feadc6 onto main 940d32f (clean merge) and ran victory translate --validate --list on shaders.rpf (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with main program by program (25,889 programs). Validated: 23,918 on main, 23,918 with this PR.

No program changes its failure reason. The count shows that the change rejects nothing on this data. It does not show whether the output is right.

No shader names or data are included, per the asset policy. AI-assisted (Claude Code).

@imrealynailong

Copy link
Copy Markdown

RTX 4060 Laptop: the PR takes compute PSO refusals from 115 to 0, and the world still fails on the descriptor heap

Independent check on a card not yet reported: RTX 4060 Laptop (Ada), driver 32.0.15.6607, Windows 11 build 26200, i7-13620H, 16 GB. Ran main 940d32f and this PR's head 3feadc6 through the same scenario, in separate worktrees, same package, same cache cleared between.

The detection works here: INFO victory_gpu::host: host wave lanes min=32 max=32 wave32=true.

The PR does what it says for pipeline creation

Counted from a --features diagnostics run over the prologue into the world:

main 940d32f this PR 3feadc6
host pipeline refused (0x80070057, all compute) 115 0
host wave lanes ... wave32= (not present) true, min=32 max=32
highest frame= seen 151 159

So on this machine every one of the 115 wave64 compute pipelines that main refuses now creates. That is a clean result and consistent with @iGoldenNinja's 3/4 → 3/3 on the 5080 (mine is a wider count because it goes through the whole prologue, not a four-input fixture).

What it does not change: the world still dies on the capped descriptor heap

Same two runs, the counters that matter for reaching the world:

main 940d32f this PR 3feadc6
title slot past the host heap 310,720 310,720
host view heap capped at 1000000 ... count=1245184 1 1
device removed 4 4
run length 38.5 s 29.3 s

310,720 is exactly 1,245,184 − 934,464, the unmirrored-slot count in #1760. It does not move at all with this PR, because it is not a wave problem.

So on this card the two failures are independent, and fixing the wave side does not get the world up. That may be worth stating plainly in the PR body: this PR removes the host pipeline refused error class entirely, but a run that had only the wave problem fixed still dies at the same place for an unrelated reason.

Agreement with @sinan-cmyk's offline result

Their translate --validate comparison found the same validated count on both sides (23,918). Mine is the runtime half of the same picture: the offline pass count does not move and the runtime PSO refusals go to zero, because the wave64 programs previously failed at CreateComputePipelineState, not at translation. Both measurements are consistent with "the change rejects nothing and unblocks pipeline creation".

Not tested / not claimed

Logs and the failing-test detail available if useful.

Marvisak commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Needs work. The rebased head fb99078 moves host_wave32 into emit::Options / lower::Parts (no global state any more), fixes the earlier CI error, and adds a refusal for one-wave LDS sharing (Lower::run) with tests. CI check passes and it merges cleanly.

Two points still hold it back:

  1. The 32-lane refusals still reach pixel and mesh programs. Lower::host_wave() (crates/victory-shader/src/emit/lower.rs) returns 32 whenever x.host_wave32 is set, whatever the stage, so the new host_wave() < wave() checks in cross_lane, the ballot-as-data path and the wave scan also refuse wave64 pixel and mesh programs, which never get WaveSize(32). A tester measured this on an RTX 5080 (pixel programs not translating 3 -> 330, mesh 0 -> 67). This was the open point from the earlier note. Please make host_wave() return 32 only for the compute programs that are given WaveSize(32), and add a test showing a wave64 pixel program with a cross-lane op still translates with host_wave32: true.
  2. Constant/SGPR-pair EXEC masks are wrong on a 32-lane host (reported with a measured case at this head). lane_bit picks the low or high mask word with lane < 32, but the lane comes from waveGetLaneIndex, which is 0..31 in each host wave, so the high word is never used: s_mov_b64 exec, 1 stores in lanes 0 and 32, and exec = 1 << 32 stores nothing. Either select the word by the half the host wave stands for, or refuse such masks on a 32-lane host, with a test.

On your reply: the move to Options and the LDS refusal address those points; the pixel/mesh scope above is the part still open. Note also that #2177 changes the same Options and shader_cache::key, so one of the two will need a rebase.


Generated by Claude Code

@n-romanovich

Copy link
Copy Markdown
Author

@Marvisak, updated pr/wave32-translation (b2ea86a) to address the triage points:

  1. Refuse cross-half operations by name when host_wave() < wave() (crates/victory-shader/src/emit/lower.rs):
    • Lower::cross_lane(false) now returns Err("a cross-half operation on a 32-lane host") (covering v_readlane_b32, v_writelane_b32, v_readfirstlane_b32, ds_bpermute_b32, v_mbcnt, and wave-wide DPP; 4-lane quad == true ops remain allowed).
    • Lower::mask_dword and the wave-scan waveActiveBallot path return Err("a 64-bit wave mask read as data on a 32-lane host") / Err("a cross-half wave scan on a 32-lane host").
    • The WaveSize(32) split now applies only to wave64 compute shaders without cross-half operations.
  2. Test: added emit::tests::wave64_cross_half_readlane_is_refused_on_wave32_host verifying that a wave64 compute shader using v_readlane_b32 is refused on a 32-lane host.

@Bladureau

Bladureau commented Nov 25, 2026 •

Copy link
Copy Markdown

RTX 4060 Laptop, in the world: wave64 mesh draws without a hang; BVH-builder programs hang; other wave64 compute makes GPU frames ~80× longer (both heads)

Machine: RTX 4060 Laptop 8 GB (driver 617.14), i7-13650HX, 32 GB RAM, Windows 11 26300. The log shows host wave lanes min=32 max=32 wave32=true. Series X mode, title 1.0.2.1. Diagnostics build with VICTORY_D3D12_DEBUG=1 and VICTORY_D3D12_DRED=1. No input once in the world.

Tree: main 940d32f + #2121 (40bd210) + #1763 (50d91b1) + #1630 (3c036f7) + this PR + #579 (rebased, patch from its thread) + #2332 (0e350ab, without it this card loses the device on the format-115 render target before or just after world entry, #1952). The only conflict was shader_cache.rs: I kept both #2121's view_pages and this PR's wave32 in the cache key. Each translator was warmed with translate --cache before its runs.

Offline, whole retail set (25,985 containers): 3feadc6 refuses 307; b2ea86a refuses 1,021, so 714 more.

Run Head Skipped World GPU per world frame End
4 3feadc6 nothing 6,754 draws in the first world frame — DXGI_ERROR_DEVICE_HUNG 33 s after world entry. DRED: the list stopped at command 1799 of 6978, dispatch 229x1x1 [compute 28918b7150a7aad5], in a stretch alternating with caa78b8ca62bc3d6
5 3feadc6 VICTORY_SKIP_WAVE64=compute 950–9,800 draws/frame 0.1–0.4 s (1.6–2.3 s in the frames I captured) none in 6 min, stopped by hand
6 3feadc6 the 52 XboxBvhBuilder.dll programs + f607780aa8e502d0 (VICTORY_SKIP_PIPELINES) 1,070–5,800 draws/frame 18–22 s the title's watchdog, +0x23cf683 write 0x0 (#1118), 2 min 10 s in, 10 s after a 42 s capture frame (see the edit)
7 b2ea86a same as run 6 760–1,850 draws/frame 9–20 s same watchdog, 1 min 50 s in, 1 s after a 38 s capture frame
8 b2ea86a same as run 6, plus VICTORY_SHADER_LOOP_LIMIT=1024 200–1,850 draws/frame 0.1–0.7 s (2.1–3.0 s in captured frames) same watchdog, 2 min 47 s in, right after a 41 s capture frame
9 b2ea86a same as run 8, every pack pipeline prebuilt (translate --cache --pipelines) 480–5,900 draws/frame 0.05–0.8 s (2.1–2.6 s in captured frames) none in 6 min 40 s, stopped by hand

What I read from it:

  1. Wave64 mesh runs here without a hang. In run 5, mesh programs run through this PR and compute wave64 is skipped. For the first time on this card, the dumped depth target and G-buffer of the first world frames hold the scene's geometry. Before, with wave64 mesh refused or skipped, they were empty. The presented frame is still black.
  2. The BVH builder hangs the GPU through this PR (run 4). Neither head refuses 28918b7150a7aad5 / caa78b8ca62bc3d6. These are the LDS-sharing builder programs GPU: programs that walk the BVH wait until the builder has run whole (NVIDIA device hang at world entry) #2311 names, so b2ea86a's guard does not cover what they need: both halves in one flow.
  3. Something in the remaining wave64 compute makes GPU frames ~80× longer (runs 5 vs 6). In run 7, b2ea86a refused 95 programs at run time (90 compute, 3 pixel, 2 mesh; 70 for "a 64-bit wave mask read as data", 25 for "a cross-half operation"), and the frames stayed as long. So the slow programs are not the ones the new guard catches.
  4. The extra GPU time is loops that run to the limit (runs 7 vs 8). With VICTORY_SHADER_LOOP_LIMIT=1024, the GPU part of a world frame falls from 9–20 s to 0.1–0.7 s outside captured frames. Why they run that long is my reading, not a measurement: I think they wait on values the other half writes. A console wave64 runs both halves in lockstep, so a value written by lanes 32–63 is already there when lanes 0–31 read it. As two host waves, one half can spin until the limit. Such programs use no cross-lane instruction, so the new guard cannot see them.

Edit (after a ninth run): I first wrote that run 8's long frames were pipeline compilation. They were my own captures. VICTORY_DUMP_TARGETS wrote 550–780 targets for each captured frame, which took 22–42 s. Every frame over 20 s in runs 8 and 9 is one of them, and so are the 2–3 s GPU values. The watchdog in runs 6, 7 and 8 fired 1–10 s after a 38–42 s capture frame, and capture frames of 22–30 s never set it off. So those three stops say more about my captures than about this PR (runs 6 and 7 still spend 9–22 s of GPU time per frame). Run 9 repeats run 8 with every pack pipeline prebuilt, none made during the run. It ran 6 min 40 s in the world with five capture frames of 22–28 s, no watchdog, no device removal and 0 ERROR lines, until I stopped it. Its G-buffer holds the outdoor scene's geometry, and the presented frame is still black.

If it helps, I can name the programs that hit the limit: VICTORY_GPU_TIMING=1 on run 6's settings, then their hashes here.

One run per row. Counts, hashes and messages only, no game data. AI-assisted (Claude Code).

chippy01 added a commit to chippy01/VIctory that referenced this pull request Nov 25, 2026
…-lane waves

What was wrong: a console wave64 compute program that needs the
console's lanes (cross-lane reads, masks as numbers, LDS one wave shares)
declares WaveSize(64). NVIDIA and Intel run waves of 32 lanes at most
(WaveLaneCountMax 32) and refuse it: on an RTX 3070 Ti (driver
32.0.16.2124) the debug layer gives "Shader wants wave lane count of 64
but maximum wave lane count for device is 32" (id 622), and every such
pipeline is refused with E_INVALIDARG. A Series S run to the loading
screen refused 100 compute pipelines, 95 of them for this.

What changed: on such a host, a wave64 program that needs the console's
lanes is translated for waves of 32 (`emit::Options::host_wave32`;
`emit::lower::halves`). The thread relabelling gives each host wave a
32-aligned run of thread ids, so host wave 2w + h is console wave w's
lanes 32h..32h + 31. What a lane reads within its half is exact: DPP
rows, ds_swizzle, and ds_bpermute_b32, which the console's wave64
permutes within each half on its own (RDNA2 ISA; measured in Marvisak#573). A
lane's bit of a mask held as a number, v_writelane_b32 and v_mbcnt take
the console lane. Reads across the halves have no host form and are
refused where they are lowered, with a reason that names the host:
ballots (masks read as data), v_readlane_b32 of a lane that may be in the
other half, whole-wave reductions and prefix sums; one a program never
uses costs nothing (the lowering's retry with the value missing). A group
of 33 to 64 threads with LDS, which the console compiler orders without
barriers as one wave, is refused too. v_readfirstlane_b32 reads the host
wave's first lane, as it already does in every program without console
lanes (marked as that shortcut).

victory-gpu asks the device once (OPTIONS1) and translates for it; the
shader cache keys on it, so entries made for 64-lane hosts are not read.
`victory translate --wave32` translates for such a host offline; with
--pipelines it follows the GPU that makes them.

Approach after DexNom's fork (DexNom/Victory 5f4c3df: the host's wave
width and the relabelling into halves) and Marvisak#2176 (n-romanovich: the
setting in the cache key); here the setting is a translation option, and
cross-half reads are refused at the sites that make them instead of by
instruction name, which keeps programs whose crossing value is unused.

Evidence, `translate --list --pipelines` over shaders.rpf, the
executable, XboxBvhBuilder.dll and the FidelityFX DLL, RTX 3070 Ti:

| | main 67e8ae1 | this |
|---|---|---|
| compute programs emitted | 2,733 | 2,372 |
| compute pipelines made | 2,328 | 2,372 |
| refused by the driver | 405 | 0 |

No program that made a pipeline on main fails to now (25,347 pipelines,
all kept). In the title (Series S mode, diagnostics build, to the
loading screen, 2.5 min): no pipeline refused, against 100 on main; the
113 programs that do not translate say why (51 LDS, the rest mostly
ballots). The 44 new ones include the depth pyramids (occlusion),
the sky and atmosphere gathers (scattering_transmittance_system),
shader binning and the mipmap generators. The 361 still refused now say
why: 192 LDS in a one-wave group, 107 ballots, 48 lane reads across
halves, 20 reductions (those need an exchange between the two host waves,
a change of its own).

Tests (halves_tests): one wave64 program (DPP, ds_swizzle, ds_bpermute,
v_mbcnt, v_writelane to lane 40, a constant mask's high dword) runs on
every hardware adapter, in halves and, where the adapter has 64-lane
waves, as one wave64: all 64 lanes give the console's results on the RTX
3070 Ti (halves) and the Radeon iGPU of a Ryzen 9 7900X (RDNA2: halves
and wave64). The refusals and the LDS rule each have an offline test;
the hand-encoded words are checked against the disassembler.

Found on the way, not changed here: a wave64 mask built by two
s_mov_b32 (low and high dword written apart) reads its low dword for all
64 lanes (`Lower::pair_high` looks for the high dword in the instruction
that wrote the low one); the same with and without this change, on AMD's
own wave64 too.

Co-Authored-By: Claude Opus 5.5
chippy01 added a commit to chippy01/VIctory that referenced this pull request Nov 25, 2026
…-lane waves

What was wrong: a console wave64 compute program that needs the
console's lanes (cross-lane reads, masks as numbers, LDS one wave shares)
declares WaveSize(64). NVIDIA and Intel run waves of 32 lanes at most
(WaveLaneCountMax 32) and refuse it: on an RTX 3070 Ti (driver
32.0.16.2124) the debug layer gives "Shader wants wave lane count of 64
but maximum wave lane count for device is 32" (id 622), and every such
pipeline is refused with E_INVALIDARG. A Series S run to the loading
screen refused 100 compute pipelines, 95 of them for this.

What changed: on such a host, a wave64 program that needs the console's
lanes is translated for waves of 32 (`emit::Options::host_wave32`;
`emit::lower::halves`). The thread relabelling gives each host wave a
32-aligned run of thread ids, so host wave 2w + h is console wave w's
lanes 32h..32h + 31. What a lane reads within its half is exact: DPP
rows, ds_swizzle, and ds_bpermute_b32, which the console's wave64
permutes within each half on its own (RDNA2 ISA; measured in Marvisak#573). A
lane's bit of a mask held as a number, v_writelane_b32 and v_mbcnt take
the console lane. Reads across the halves have no host form and are
refused where they are lowered, with a reason that names the host:
ballots (masks read as data), v_readlane_b32 of a lane that may be in the
other half, whole-wave reductions and prefix sums; one a program never
uses costs nothing (the lowering's retry with the value missing). A group
of 33 to 64 threads with LDS, which the console compiler orders without
barriers as one wave, is refused too. v_readfirstlane_b32 reads the host
wave's first lane, as it already does in every program without console
lanes (marked as that shortcut).

victory-gpu asks the device once (OPTIONS1) and translates for it; the
shader cache keys on it, so entries made for 64-lane hosts are not read.
`victory translate --wave32` translates for such a host offline; with
--pipelines it follows the GPU that makes them.

Approach after DexNom's fork (DexNom/Victory 5f4c3df: the host's wave
width and the relabelling into halves) and Marvisak#2176 (n-romanovich: the
setting in the cache key); here the setting is a translation option, and
cross-half reads are refused at the sites that make them instead of by
instruction name, which keeps programs whose crossing value is unused.

Evidence, `translate --list --pipelines` over shaders.rpf, the
executable, XboxBvhBuilder.dll and the FidelityFX DLL, RTX 3070 Ti:

| | main 67e8ae1 | this |
|---|---|---|
| compute programs emitted | 2,733 | 2,372 |
| compute pipelines made | 2,328 | 2,372 |
| refused by the driver | 405 | 0 |

No program that made a pipeline on main fails to now (25,347 pipelines,
all kept). In the title (Series S mode, diagnostics build, to the
loading screen, 2.5 min): no pipeline refused, against 100 on main; the
113 programs that do not translate say why (51 LDS, the rest mostly
ballots). The 44 new ones include the depth pyramids (occlusion),
the sky and atmosphere gathers (scattering_transmittance_system),
shader binning and the mipmap generators. The 361 still refused now say
why: 192 LDS in a one-wave group, 107 ballots, 48 lane reads across
halves, 20 reductions (those need an exchange between the two host waves,
a change of its own).

Tests (halves_tests): one wave64 program (DPP, ds_swizzle, ds_bpermute,
v_mbcnt, v_writelane to lane 40, a constant mask's high dword) runs on
every hardware adapter, in halves and, where the adapter has 64-lane
waves, as one wave64: all 64 lanes give the console's results on the RTX
3070 Ti (halves) and the Radeon iGPU of a Ryzen 9 7900X (RDNA2: halves
and wave64). The refusals and the LDS rule each have an offline test;
the hand-encoded words are checked against the disassembler.

Found on the way, not changed here: a wave64 mask built by two
s_mov_b32 (low and high dword written apart) reads its low dword for all
64 lanes (`Lower::pair_high` looks for the high dword in the instruction
that wrote the low one); the same with and without this change, on AMD's
own wave64 too.

Co-Authored-By: Claude Opus 5.5
@moe-miau

Copy link
Copy Markdown

Tested on an RTX 4070 SUPER (driver 32.0.16.1742, Windows 11 26300), title 1.0.2.1, Series X profile, diag build, 6-minute runs with scripted Enter presses. Base stack: main 67e8ae1 + #1906 + #2098 + #2626 + #2628 + #2464 (with #2464 the world draws on NVIDIA).

refused pipelines not translated device removed picture at 6 min
base 166 (WaveSize(64)) 7 no world draws, heavily overexposed and blocky
base + #189 (auto: Emulate) 98 2 no similar
base + this PR 0 118 no credits artwork correct, world still partly missing
base + this PR, the 3 refusals below lifted 0 0 yes, at 110 s (0x887A0006)
same + #2118 + builder held back on 32-lane hosts 0 4 no credits complete over a lit city skyline, exposure normal

Of the 118 programs this PR leaves untranslated here, 80 fail with a 64-bit wave mask read as data on a 32-lane host and 32 with a cross-half operation on a 32-lane host (plus the cross-half scan). Each host wave already stands for one half (ballot high dword 0, host_lane masks to 31), so I tried letting those three cases through with exactly those semantics, the way Zettrox/ztrx's default wave-local fallback does:

-                if self.host_wave() < self.wave() {
+                if self.host_wave() < self.wave() && !super::wave32_approx() {
                     return Err("a cross-half wave scan on a 32-lane host");
...
-                if self.host_wave() < self.wave() {
+                if self.host_wave() < self.wave() && !super::wave32_approx() {
                     return Err("a 64-bit wave mask read as data on a 32-lane host");
...
-        if !quad && self.host_wave() < self.wave() {
+        if !quad && self.host_wave() < self.wave() && !super::wave32_approx() {
             return Err("a cross-half operation on a 32-lane host");

Everything translates then, but the BVH builder (XboxBvhBuilder.dll; the hung submission held 14394a32 and 28918b71) really needs 64 lanes and hangs the GPU. With #2118 merged as well, plus one line holding the builder back on such hosts, the run went 6 minutes without a removal and the picture improved a lot:

-    let open = all_made(&states);
+    let open = all_made(&states) && !victory_shader::emit::host_wave32();

The builder then stays off on NVIDIA, as it does on main today, where its programs are refused. The approximation is exact for programs whose waves only work within themselves (compaction, reductions, one atomic per wave), and approximate for real cross-half exchanges. If you'd like it in this PR, I can send the change on top of it. Otherwise I can open it as a follow-up once this and #2118 are in.

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

@frenziedcoder

Copy link
Copy Markdown

RTX 5080 (Blackwell), driver 621.40, this PR (9857ed1) on top of the stack from #2464: no compute pipeline is refused any more (171 → 0), but on this 32-lane host it also stops pixel and mesh programs from translating that translate without it (pipelines skipped for that reason: pixel 3 → 330, mesh 0 → 67). The world still draws and the run had no device removal in 10 minutes.

Setup: NVIDIA GeForce RTX 5080 16 GB (driver 621.40), Ryzen 7 9800X3D, 64 GB, Windows 11 Pro 26200. Title 1.0.2.1, Series X profile, diag build with diagnostics, VICTORY_D3D12_DRED=1, scripted Enter. The log says host wave lanes min=32 max=32 wave32=true.

Trees: "stack" = main 13f91ca + #1906 + #2098 + #2626 + #2628 + #2464, as reported on #2464. "+ this PR" merges 9857ed1 on top. Two conflicts with #2628, resolved by keeping both settings: emit::Options gets both portable_views and host_wave32, and the shader cache key in shader_cache.rs hashes both the view heap limit and the wave32 flag. One test initializer #2628 adds (memory_tests.rs, lower::Parts) needed host_wave32: false. Workspace tests build; shader_cache and wave tests pass.

translate --cache --pipelines (whole pack, --jobs 12):

stack stack + this PR
programs translated / refused 25,752 / 233 24,906 / 1,079
pipelines refused by the host 397 1
skipped: compute shader does not translate 24 391
skipped: pixel shader does not translate 3 330
skipped: mesh shader does not translate 0 67

In the title (one 600 s run each):

stack stack + this PR
host pipelines refused 171 0
shader does not translate; its pipelines' draws are dropped 8 (7 compute, 1 pixel) 173 (166 compute, 5 pixel, 2 mesh)
first world frame frame 1,191, 1,002 draws frame 1,322, 8,231 draws
world frame rate ~1.5–2.5 fps ~1.3 fps (726 frames in 548 s)
slow host submissions 72 (median 334 ms) 203 (median 280 ms)
device removed no no
picture blocky, over-bright patches about the same; more geometry, still large patches

Reasons for the 166 compute programs: 80 wave64 compute shader sharing LDS within one wave on a 32-lane host, the rest a 64-bit wave mask read as data on a 32-lane host and a cross-half operation on a 32-lane host. So in the run most of the 171 refusals became translation refusals, and their dispatches are still skipped, as @moe-miau found (118 on the 4070 SUPER).

The pixel and mesh refusals carry the same two messages. Without this PR those programs translate and the host takes them, so it looks like the new host_wave() < wave() refusals in Lower also reach pixel and mesh stages, which the PR doesn't split. Limiting them to the compute programs that get WaveSize(32) would keep those draws.

Not tested: more than one run per tree; @moe-miau's wave32_approx change, #2118 and the builder hold-back on top; Series S profile.

AI use: Claude Code (Claude Opus 5.5) merged the trees, resolved the conflicts, ran the title on my machine (sandboxed at Low integrity, game folder read-only), read the logs and frame captures, and wrote this report.

@frenziedcoder

Copy link
Copy Markdown

Follow-up on the RTX 5080 (621.40): @moe-miau's wave32_approx change plus #2118 and the builder hold-back, on top of this PR and the #2464 stack, removes the pixel / mesh regression I reported above, and the run is the best on this card so far: exposure normal, ~1.8 fps, no device removal in 600 s.

Tree: the stack from #2464 + this PR (9857ed1) + #2118 (60632d3, clean merge) + the two local changes from @moe-miau's comment, applied as written: && !super::wave32_approx() on the three host_wave() < wave() refusals in lower.rs (with wave32_approx() returning true), and let open = all_made(&states) && !crate::host::host_wave32(); in pipeline/builder.rs (victory_shader::emit::host_wave32() is not on this head; victory-gpu's own host::host_wave32() stands in). Same machine, switches and scripted Enter as before.

translate --cache --pipelines (on the triage's minor point: --cache translates through victory_gpu::shader_cache::host_shader, which fills host_wave32 from the host, so these offline counts do include the 32-lane refusals; only plain translate without --cache passes ..Default::default()):

stack + this PR + this PR, #2118, the two changes
programs refused 233 1,079 430
skipped: pixel shader does not translate 3 330 3
skipped: mesh shader does not translate 0 67 0
skipped: compute shader does not translate 24 391 219
refused by the host 397 1 1

In the title (one 600 s run each):

stack + this PR + this PR, #2118, the two changes
host pipelines refused 171 0 0
draws dropped: programs that don't translate 8 173 85 (84 compute, 1 pixel)
frame reached by ~590 s 2,151 2,048 2,311
world frame rate ~1.5–2.5 fps ~1.3 fps ~1.8 fps (960 frames in 530 s; 263 in the last 88 s)
slow host submissions 72 203 83
picture blocky, over-bright about the same exposure normal; geometry still mostly flat
device removed no no no

80 of the 84 compute programs still dropped are wave64 compute shader sharing LDS within one wave on a 32-lane host, which the two changes don't touch (this head refuses that case; @moe-miau's run may have been on an earlier head, with 4 left).

Not tested: more than one run; the changes one at a time; Series S profile.

AI use: Claude Code (Claude Opus 5.5) merged the tree, applied the changes from the comment, ran the title on my machine (sandboxed at Low integrity, game folder read-only), read the logs and frame captures, and wrote this report.

@walterwallaceson

Copy link
Copy Markdown

RTX 3070 on Windows 10: 3feadc6 hung the card during loading in 2 of 2 runs; fb99078 runs the same program and goes 15 minutes with no removal.

Setup: RTX 3070 8 GB, driver 621.14, Windows 10 22H2 (19045), host wave lanes min=32 max=32 wave32=true. Diag build, a scripted Enter at the start screen, nothing skipped.

3feadc6 (2 runs) fb99078
end 0x887A0006 at ~1:37 and ~1:42, during loading 15 min, no removal
the submission before it 2 lists, 8.3-8.4 s (no submission over 1.3 s)
D3D12 refusals 2 0
not translated 13 168 (77 one-wave LDS, 59 64-bit mask as data, 28 cross-half, 4 other)

Where 3feadc6 stopped (DRED, run 2): list 2 of the submission at command 4,673 of 15,360; the command it names is a dispatch 1x1x1 of a wave64 compute program with 6 user-data words, first bound around frame 1,660. The same program runs with #189's wave32 mode on the old stack, and with fb99078 it is translated (not among the refusals) and bound at frame 1,769 and the run goes on. So one of the refusals added since 3feadc6 (cross-half operations, 64-bit masks as data, one-wave LDS) most likely covers what hung here; I haven't narrowed it to which one.

For comparison on the same new base: with #189 (3e39e34, wave32) instead of this PR, 117 programs don't translate and none are refused. With this PR, 168 don't translate (the debug layer makes this run's frame rate, about 1 fps, not comparable).

On the stack where the world draws on NVIDIA (main 63bcca4 + #463 + #2626 + #2098 + #2464 + #2628), one 15-minute run each:

that stack + #2118 + #2118 + this PR
end 15 min, no removal 15 min, no removal 15 min, no removal
D3D12 refusals / not translated 168 / 7 171 / 7 0 / 171
world speed, last 40 readings 0.7 fps 1.2 fps 1.2 fps
picture at 10 min (same spot) mostly white haze fence, buildings, sky readable the same

So on this card the clearer picture and the speed come from #2118; adding this PR changes which programs don't run (refused by D3D12 before, refused by the translator now) without changing the picture or the frame rate, and with no removal.

Merging with #2628: both add a field to emit::Options and an input to shader_cache's key, so they conflict in shader_cache.rs and emit/mod.rs. Keeping both (portable_views and host_wave32 in Options, options() setting both, key() taking the view heap limit and the wave32 flag) builds, and the tests compile.

Not tested: a second run of any of these; fb99078 on the old base; which refusal covers the hang.

No game data attached. I'm testing with Claude's help, and Claude drafted this comment.

@ghost ghost mentioned this pull request Nov 26, 2026
moe-miau added a commit to moe-miau/VIctory that referenced this pull request Nov 26, 2026
Triage asked for Marvisak#2176's refusals to stay the default: lifting them makes
programs that combine work across the two halves silently approximate
(Venom2054's ballot test counts 128 where the console counts 138). The
three refusals (cross-half lane operations, 64-bit wave masks read as data,
cross-half scans) are back unless emit::Options::wave32_approx is set; the
GPU sets it with VICTORY_WAVE32_APPROX=1 on a 32-lane host, and the shader
cache key includes it. The test checks both: refused by default,
translated when approximate. The BVH builder stays held back on such hosts
either way.

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

Copy link
Copy Markdown

For the test the triage asks for (a wave64 pixel program that should still translate with host_wave32: true): a fixture, run on fb99078. It puts one 64-bit wave mask read as data (v_cmp_lt_f32 vcc, 0.5, v1; s_bcnt1_i32_b64 s12, vcc) into a wave64 compute, pixel and mesh program, keeps the result live (LDS store / exp mrt0 / folded into the position), and runs each through emit_with with host_wave32 off and on. CPU-only translation, synthetic instruction words only.

wave64 program host_wave32: false host_wave32: true
compute translates refused: a 64-bit wave mask read as data on a 32-lane host (intended)
pixel translates refused: same message
mesh translates refused: same message

Once host_wave() is scoped to the programs that get WaveSize(32), the pixel and mesh rows should read "translates" in both columns. The cross-lane forms I tried first (v_readlane_b32 of lane 1 or 33, exec_hi as data) don't work for this: pixel and mesh refuse them already without host_wave32 (a cross-lane operation outside compute is not supported, a hardware SGPR input is not supported), so the mask-as-data form is the one that isolates the stage scope. The four forms are all in the file; it prints a row per case rather than asserting, so it can be turned into asserts once the scope is decided.

crates/victory-shader/src/emit/stage_scope_fixture_tests.rs (plus #[cfg(test)] mod stage_scope_fixture_tests; in emit/mod.rs)
//! LOCAL FIXTURE (not for upstream as is): one cross-lane operation
//! (readlane of lane 1 or 33, or exec_hi read as data, into v8, which is then
//! stored / exported so it is not dead code) in a wave64 compute,
//! pixel and mesh program, translated with `host_wave32` off and on. Prints
//! whether each translates, to show which stages #2176's 32-lane refusals
//! reach. Only compute programs get `WaveSize(32)` and are split.

use super::container::SigElement;
use super::{Options, container, emit_with};
use crate::dxbc::{Container, FourCC};
use crate::native::{ComputeIo, HwStage, MeshIo, NativeProgram, StageIo};
use crate::{io, ir, resource, structure};

const SET_V5: u32 = 0x7E0A_02F2; // v_mov_b32 v5, 1.0
/// The operations tried: (name, words).
const OPS: [(&str, &[u32]); 4] = [
    ("vcc popcount", &[0x7E02_02F2, 0x7C02_02F0, 0xBE8C_106A, 0x7E10_020C]), // v_mov_b32 v1, 1.0; v_cmp_lt_f32 vcc, 0.5, v1; s_bcnt1_i32_b64 s12, vcc; v_mov_b32 v8, s12
    ("readlane lane 1", &[SET_V5, 0xD760_000C, 0x0001_0305, 0x7E10_020C]), // v_readlane_b32 s12, v5, 1; v_mov_b32 v8, s12
    ("readlane lane 33", &[SET_V5, 0xD760_000C, 0x0001_4305, 0x7E10_020C]), // v_readlane_b32 s12, v5, 33; v_mov_b32 v8, s12
    ("exec_hi as data", &[0x7E10_027F]), // v_mov_b32 v8, exec_hi
];
const ENDPGM: u32 = 0xBF81_0000;

fn sig(name: &str, kind: u8) -> Vec<u8> {
    container::signature(
        &[SigElement {
            name: name.into(),
            index: 0,
            kind,
            comp: 9,
            interp: 0,
            row: Some(0),
            col: 0,
            cols: 4,
            usage: 0xF,
            half: false,
        }],
        false,
    )
}

fn outcome(native: &NativeProgram, bytes: &[u8], host_wave32: bool) -> String {
    let c = Container::parse(bytes).unwrap();
    let p = ir::build(&native.patched_code(), native.wave64, native.vgprs).unwrap();
    let st = structure::structure(&p).unwrap();
    let res = resource::track(&p, &native.layout, native.stage, Some(&st)).unwrap();
    let io = match io::raise(&p, native) {
        Ok(io) => io,
        Err(e) => return format!("(fixture input not accepted: {e})"),
    };
    let opts = Options { host_wave32, ..Default::default() };
    match emit_with(&c, native, &p, &st, &io, &res, opts) {
        Ok(_) => "translates".into(),
        Err(e) => format!("refused: {e}"),
    }
}

fn compute(op: &[u32]) -> (NativeProgram, Vec<u8>) {
    let mut w = op.to_vec();
    w.extend_from_slice(&[0xD834_0000, 0x0000_0800]); // ds_write_b32 v0, v8
    w.push(ENDPGM);
    let native = NativeProgram {
        stage: HwStage::Cs,
        wave64: true,
        vgprs: 9,
        layout: vec![],
        used: vec![],
        io: StageIo::Cs(ComputeIo { rsrc2: 1 << 15, threads: [128, 1, 1] }), // 64 LDS dwords, two waves
        code: w.iter().flat_map(|x| x.to_le_bytes()).collect(),
    };
    (native, crate::dxbc::build(&[]))
}

fn pixel(op: &[u32]) -> (NativeProgram, Vec<u8>) {
    let mut w = vec![0x7E02_02FF, 0x3F80_0000, 0x7E04_02FF, 0x3F00_0000]; // v1 = 1.0, v2 = 0.5
    w.extend_from_slice(op);
    w.extend_from_slice(&[0xF800_180F, 0x0102_0208]); // exp mrt0 v8, v2, v2, v1 done vm
    w.push(ENDPGM);
    let native = NativeProgram {
        stage: HwStage::Ps,
        wave64: true,
        vgprs: 9,
        layout: vec![],
        used: vec![],
        io: StageIo::Ps { inputs: vec![], input_addr: 0, db_shader_control: 0, patches: vec![] },
        code: w.iter().flat_map(|x| x.to_le_bytes()).collect(),
    };
    let osg1 = sig("SV_Target", 16);
    (native, crate::dxbc::build(&[(FourCC::OSG1, &osg1)]))
}

fn mesh(op: &[u32]) -> (NativeProgram, Vec<u8>) {
    // `triangle_mesh` from emit/mod.rs's tests (TRIANGLE-style prim word 0),
    // with the cross-lane operation after v_mbcnt.
    let mut w = vec![0xD765_0001u32, 0x0001_00C1];
    w.extend_from_slice(op);
    w.extend_from_slice(&[
        0x3604_0281, 0x3606_0282, 0x7E04_0D02, 0x7E06_0D03, 0x1008_04F6, 0x0608_08F3,
        0x100A_06F4, 0x060A_0AF3, 0x7E0C_02F0, 0x7E0E_02F2, 0x7E12_02FF, 0x0000_0000,
        0xF800_0941, 0x0000_0009, 0x0608_0908, 0xF800_08CF, 0x0706_0504, ENDPGM, // v_add_f32 v4, v8, v4 before exp pos0
    ]);
    let native = NativeProgram {
        stage: HwStage::Ms,
        wave64: true,
        vgprs: 10,
        layout: vec![],
        used: vec![],
        io: StageIo::Ms(MeshIo {
            outputs: vec![],
            clip_cntl: 0,
            threads: 64,
            max_vertices: 32,
            max_primitives: 32,
            topology: 2,
            lds_bytes: 0,
        }),
        code: w.iter().flat_map(|x| x.to_le_bytes()).collect(),
    };
    let osg1 = sig("SV_Position", 3);
    (native, crate::dxbc::build(&[(FourCC::OSG1, &osg1)]))
}

#[test]
fn stage_scope_of_32_lane_refusals() {
    for (op_name, op) in OPS {
        for (name, (native, bytes)) in [("compute", compute(op)), ("pixel", pixel(op)), ("mesh", mesh(op))] {
            for host_wave32 in [false, true] {
                println!("FIXTURE {op_name:16} {name:8} wave64 host_wave32={host_wave32:5}: {}", outcome(&native, &bytes, host_wave32));
            }
        }
    }
}

AI use: Claude Code (Claude Opus 5.5) wrote the fixture, ran it on my machine (RTX 5080 box; this check needs no GPU) and wrote this comment.

@Creaa

Creaa commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

@n-romanovich a small follow-up on this PR's 32-lane path, as #3115 (stacked on fb99078, one commit): DPP rows/DPP8, ds_swizzle_b32 (group-of-32 mode) and ds_bpermute_b32 only read lanes of their own half, so cross_lane no longer refuses them as cross-half (DPP rows only when the row mask is the same for both halves). On an RTX 4070 a GPU test checks all 64 lanes of a wave64 program against RDNA2; offline the refusal falls from 69 to 51 programs of the title's pack. Happy for you to fold it into this PR instead if you prefer.

AI use: Claude Code (Claude Opus 5.5) wrote the change and this note.

Creaa added a commit to Creaa/VIctory that referenced this pull request Nov 26, 2026
…osts

On a host of 32-lane waves (Marvisak#2176) every cross-lane operation that is not
quad-local was refused as "a cross-half operation", but DPP rows (16 lanes),
DPP8 (8 lanes), ds_swizzle_b32 in its group-of-32 mode and ds_bpermute_b32
(each 32-lane half on its own, RDNA2 ISA 10.4.4) only read lanes of their
own half, which one host wave holds whole (FIND-7 in Marvisak#1633).

cross_lane now takes how far an operation reaches. A DPP row write mask
numbers the wave's four rows, so a row operation stays in its half only
when the mask has the same bits for both halves (0xF, 0x5, 0xA, 0x0).

Offline `translate --list` of the title's shader pack as a 32-lane host:
"a cross-half operation on a 32-lane host" 69 -> 51 programs; compute
programs emitted 2291 -> 2309 (the 2D and array mip-chain programs of
levels 2-3, a cascade-shadow min/max and a trail-map mip program).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.