Skip to content

[BUNDLE] Wave64 compute on 32-lane hosts: #189 merged onto the shader stack, stacked on #1511 - #1589

Closed
MamaLeVrai wants to merge 106 commits into
Marvisak:mainfrom
MamaLeVrai:bundle/wave64-189
Closed

MamaLeVrai wants to merge 106 commits into
Marvisak:mainfrom
MamaLeVrai:bundle/wave64-189

Conversation

@MamaLeVrai

@MamaLeVrai MamaLeVrai commented Nov 24, 2026 •

Copy link
Copy Markdown

A merge resolution for one PR. #189 emulates Wave64 compute shaders on 32-lane and narrower hosts. The open issues from NVIDIA owners keep hitting that wall: compute pipelines refused because the shaders ask for wave size 64 and the device maximum is 32 (#1107, #1323, #1001). This is #189 merged onto the whole shader stack (#1319, #1402, #1492, #1504, #1511), where it conflicts and fails to compile in a few places. Every head is merged unchanged onto main plus #1511, and the result is built and tested together.

For reviewers and for anyone verifying with an agent (Claude, Codex, a person): this is a [BUNDLE] PR. The re-verification commands are below, so one run covers all of it.

What is inside

PR Author Head Title
#189 alfycs 54b333fc5 Shaders: emulate Wave64 compute shaders on Wave32 and narrower hosts

Changes made while bundling

No change inside #189. Two things came up when merging it onto the stack:

That is all of the merge: #189 does not conflict with the stack in the lowering itself.

Left out, and why

Verification

Windows 11, RX 6950 XT, Rust 1.98.1 (the pinned toolchain):

Check Result
cargo clippy --workspace --all-targets --locked -- -D warnings clean
cargo clippy --workspace --all-targets --all-features --locked -- -D warnings clean
cargo test --workspace --locked 430 passed, 0 failed, 6 ignored (main: 342 passed, 6 ignored)

The title was not run, so this says nothing about in-game effect. No game data is used or committed.

Re-verify in one go

git fetch https://github.com/MamaLeVrai/VIctory.git bundle/wave64-189
git checkout FETCH_HEAD
cargo clippy --workspace --all-targets --locked -- -D warnings
cargo clippy --workspace --all-targets --all-features --locked -- -D warnings
cargo test --workspace --locked

To confirm that no component PR moved since this was built, compare each Head above with gh pr view <n> --repo Marvisak/VIctory --json headRefOid. If one differs, the branch needs a rebuild: merge the new head in the same order.

If this lands

The component heads are in the history unchanged, so each PR's commits and authorship are kept and GitHub should mark them merged. Merging them one by one instead works too, with the exceptions noted above.

AI-assisted (Claude Code); no game data.

🤖 Generated with Claude Code

Pedro Fortunato and others added 30 commits November 23, 2026 23:25
Pixel programs that use the I/J VGPRs as plain values (custom
interpolation, math on the weights) failed with "barycentrics read
directly". They are now channels y and z of an SV_Barycentrics input
(SM 6.1+, the emitter targets 6.6) declared with the interpolation mode
of their kind (perspective/linear, center/centroid/sample), one element
per mode (semantic index 0 and 1), with the Barycentrics shader flag and
SFI0 feature. GFX10 interpolates P0 + i (P1 - P0) + j (P2 - P0) with P0
the provoking vertex, which the host's barycentrics weight as vertex 0,
so i = y and j = z.

The VGPRs are loaded on first use as a value, so programs that only feed
them to v_interp_* declare nothing new. A console signature's own
SV_Barycentrics row (D3D name 23) is parsed and reused. Pull-model
barycentrics stay unsupported.

SV_Barycentrics is left unpacked (no row, packing location -1), like
other non-packed system values: the DXIL validator refuses it in a row.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AZ9pSB4ZoXYUifuXg8gm66
v_interp_p1/p2 (and the f16 forms) fed with an i or j that is not the
loaded input VGPR now evaluate each half as the hardware does: P0 + i
(P1 - P0) for the first, the old dst + j (P2 - P0) for the second, with
the vertex values read by attributeAtVertex. That needs the element
declared constant, so every other interpolation of the same attribute
row is weighed from its vertices with SV_Barycentrics of its mode, and
flat reads stay loadInput of the provoking vertex. v_interp_mov of P10
and P20 reads P1 - P0 and P2 - P0 the same way when the program also
interpolates the attribute (so the hardware holds the deltas); alone it
is still refused.

The translate command's tally counts Interp::Weighted as interpolated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AZ9pSB4ZoXYUifuXg8gm66
image_sample_d_cl was refused by name, and behind it every program hit
a cube sample with explicit gradients, refused as "a cube sample with
... gradients". Both now translate to sampleGrad:

- A cube's gradients on GFX10 are of the face coordinates (s, t), four
  addresses rather than six, so the coordinates follow at 4. They become
  the direction's gradients through the face's linear part of
  cube_direction (u = 2s - 3, v = 2t - 3; the major axis does not move),
  in the new cube_gradient.
- `_cl`: the level-of-detail clamp follows the coordinates and is passed
  as sampleGrad's clamp.

translate --validate on shaders.rpf: vertex/pixel 12172 -> 12197
validated; both errors are gone from the list. Not yet compared against
the console's sampling at runtime.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
lower.rs: keep the PR's lazy barycentric VGPR inputs next to main's
`Reg::S(n)` arm for uninitialized SGPRs. mod.rs: the barycentric test
helper passes the structure to resource::track, which now takes it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AZ9pSB4ZoXYUifuXg8gm66
DXIL allows at most two SV_Barycentrics input elements, one perspective
and one linear. A program reading both perspective center and centroid
I/J as values declared two perspective elements, which the validator
refuses ("There can only be up to two input attributes of
SV_Barycentrics with different perspective interpolation mode").

The second mode of the same kind is now an Unsupported reason rather
than a second element. Reusing the first element would hand centroid
reads center weights (or the reverse), which differ on edge pixels: a
silent wrong value. Before this PR such reads were refused anyway.

Test: center + centroid values are refused; centroid alone still
translates with one element.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AZ9pSB4ZoXYUifuXg8gm66
The ISA's special cases in its order: a NaN numerator or denominator comes
back quieted, 0/0 and inf/inf give NaN, x/0 and inf/x a signed infinity,
0/x and x/inf a signed zero, otherwise |S0| with the quotient's sign.
Worked on the f32 values of the f16 operands, which are exact.
The ISA's "exponent of S0 all ones -> overflow" check runs before the
final |S0| case, so a NaN quotient with a finite, non-zero numerator and
denominator gives sign | infinity, as measured on gfx1036 hardware. The
zero, infinity and invalid checks still come first.
These write SCC, but their lowering gave no SCC value, so the generic
"result is not zero" stood in. The ISA sets it otherwise:

- s_min_i32/u32, s_max_i32/u32: SCC = 1 when src0 is the value chosen
  (src0 < src1 for min, src0 > src1 for max).
- s_lshl1..4_add_u32: SCC = 1 when (src0 << n) + src1 overflows 32
  bits, through bits shifted out of src0 or the add's carry.

So s_min_u32(5, 3) left SCC = 1 (3 is not zero) where the hardware
leaves 0, and s_lshl1_add_u32(1, 0xFFFFFFFE) left 0 where it leaves 1;
an s_cselect or s_cbranch_scc after them took the wrong side.
The d16 forms of the typed buffer loads return each channel as 16 bits,
two per VGPR, low half first; the decoder already sizes their data that
way. The lowering only treated `buffer_` names as d16, so a
tbuffer_load_format_d16_* went through the 32-bit path: the first VGPR
got channel x as a 32-bit value (the f32 bits of 1.0 instead of the f16
pair (1.0, 2.0)) and the other channels were dropped.

The format path now packs its channels for d16: integer formats keep
their low 16 bits, the other formats become f16 (as the MUBUF d16 path
converts them).
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).
SDATA on s_atc_probe and s_atc_probe_buffer is a 7-bit immediate, the buffer resource is four dwords, and GLC/DLC are not operands of either.
…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.
buffer_gl0_inv and buffer_gl1_inv name a buffer but read no descriptor, so resource tracking refused them before lowering. Skip descriptor tracking for _inv buffer instructions and lower the pair to nothing, as the existing scalar cache instructions already are. Add a synthetic full-pipeline test.
…e a buffer view

A descriptor fetched from the resource heap by index has no used-resource
entry, so a scalar buffer load (s_buffer_load_dword*) through it was
lowered through a 64 KiB constant buffer handle. When vector buffer loads
read the same descriptor, the slot holds a buffer SRV (the title made it
one), and reading it through a CBV handle is a descriptor of the wrong
type, which D3D12 leaves undefined. Such loads now read the slot as a raw
buffer, as table SRVs already do. A descriptor also written through
(a UAV) and one only scalar loads read are unchanged.

In the title's shaders.rpf this changes 38,829 scalar loads in about 1,900
of 26,084 programs; emit and validation counts are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
s_buffer_load_dword* through a table's UAV took the constant buffer
path: a CBV handle at the heap index of a UAV. Reading through it
removes the device (WARP: "The GPU device instance has been
suspended"). Such a load now reads the UAV raw, as a raw SRV is read
and as vector buffer accesses read a UAV.

The test writes a value to the VALU tests' raw UAV, reads it back with
a scalar buffer load and stores that; it removed the WARP device before
this change and passes on the hardware GPU and WARP after.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
An s_load_dword* whose address is a root descriptor's, and whose
result the program never uses as a descriptor, reads that buffer's
data. It stopped with "a descriptor read only as data". It is now read
as global loads from a root view already are: a root SRV raw, a root
CBV (or a root view the used-resource list does not name) as a
constant buffer. A root UAV still stops, with its own reason.

Test: dwords 2 and 3 of a root SRV and of a root CBV read with one
s_load_dwordx2 and stored, exact on the hardware GPU and WARP; main
refuses the program.

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

Copy link
Copy Markdown

Test report for this bundle on a 32-lane host under Linux (not a code review).

Setup: Arch Linux, Wine from GE-Proton11-6 + vkd3d-proton (Proton Experimental), GTX 1660 6 GB (Turing, 32-lane waves only), NVIDIA 620.73.04, Series X mode, diagnostics build, empty shader cache, native d3dcompiler_47 in the prefix so indirect execution runs.

Tree: this bundle + #1077 #1175 #523 #530 #1040 #1406 #542 #1056 #1392 #1516 #1388 #1189 #1523 (all merge cleanly except #542, a small conflict in emit/lower.rs; #1407 conflicts in emit/lower.rs and is left out). cargo test -p victory-shader --lib: 153 passed, 0 failed, 1 ignored.

One run into the world, to frame 2073 (about 7 minutes):

without this bundle (#1511 stack, same extra PRs) with this bundle
compute pipelines made 477 474
compute pipelines refused by the host 111 0
device removed no no
shaders translated 1621 1475

So the refusals for WaveSize(64) are gone on this card.

Compute programs that now do not translate, by reason (distinct shaders warned about in this run): a lane mask holding lanes elsewhere read as data (67), v_readfirstlane in divergent control flow (64), a structured buffer of unknown stride (56), LDS accesses without a uniform LDS fence in split wave64 (40), a 64-lane wave ballot in divergent control flow (35), an address not from a root parameter (29).

By dropped work per frame the first one is LDS accesses without a uniform LDS fence in split wave64 (10 shaders actually dispatched).

The final image is still dark at frame 2048, and the title's stop of #1323 still comes at about frame 2000-2070. Runs differ in how many shaders they reach, so the two columns are one run each, not an exact A/B.

@MamaLeVrai

Copy link
Copy Markdown
Author

Thank you, Impre-visible: 111 compute pipelines refused by the host down to 0 on a 32-lane card is the number this PR is for, and the list of walls that remain (lane mask holding lanes elsewhere, v_readfirstlane in divergent flow, unknown stride, split wave64 LDS fence, wave ballot in divergent flow, address not from a root parameter) is the useful next map. I see #1407 conflicts with #189 in emit/lower.rs in your tree; I am building your whole tree as one branch on top of this PR (the list you ran, with #1523, and #1407 resolved against #189 if it can be), and will post it here and on #1495 with the checks. AI-assisted (Claude Code); no game data.

@MamaLeVrai

Copy link
Copy Markdown
Author

Impre-visible: your tree is now one branch, #1638, stacked on this PR: #189 as merged here plus #1077 #1175 #523 #530 #1040 #1406 #1392 #1516 #1388 #1189 #1523 #542 (#1056 is already in #1319). Clippy (both runs) and cargo test --workspace pass on it (461 passed, two runs). #1407 is left out for the reason you found: it rewrites the lane-mask ballot in the same function as #189 (mask_dword), and I did not try to join two different rewrites. What it took beyond your list is described in #1638: the one-line keep_dynamic change after #1388, root_uavs in four test literals, the duplicate RENDER_TARGET constant between #1523 and #1040, #542's bound applied to the stack's raw-view branch, and a fix of #1040's test (it assumed every adapter refuses a typed UAV on B5G5R5A1; an RX 6950 XT accepts it). If your counts differ on that branch (MamaLeVrai/VIctory, bundle/nvidia-stack), I would like to know. AI-assisted (Claude Code); no game data.

@MamaLeVrai

Copy link
Copy Markdown
Author

Impre-visible: the unknown-stride wall (56 shaders in your list) has its own PR now, #1644 (#704 on #193, on top of #1511; branch bundle/stride-stack). Clippy (both runs) and 412 tests pass here; I did not run the title. It is built on #1511, not on #1589 or on your tree, so it does not change your wave64 numbers by itself.

I tried merging it onto your tree (#1638): 11 files and 28 conflict hunks (emit/lower.rs 6, emit/shader.rs 6, emit/mod.rs 4, pipeline/host.rs 3, shader_cache.rs 3, one in each of the other six), among them the root-UAV and wave64 changes. That is not a mechanical merge and I have not built it. If you want #1589 and the stride stack in one tree to run now, bundle/all has both (751 tests; it does not have your world-run list). The other walls in your list are not touched by it.

AI-assisted (Claude Code); no game data.

…on old validators

PSV0 shared one string-table copy of a repeated semantic name (TEXCOORD0
and TEXCOORD1 pointing at the same "TEXCOORD"). DXC's PSV writer writes
one copy per element, and validators before 1.8 compare PSV0 byte for
byte, so any signature repeating a name was rejected there ("Pipeline
State Validation does not match"); 1.8 compares the strings and accepted
both. Checked against dxil.dll 1.7, 1.8 and 1.9.

Validator::version() reads IDxcVersionInfo; the compute-derivative test
skips dxil.dll validation when the validator predates 1.8, which rejects
dx.valver 1.8 outright. Translated shaders never go through dxil.dll.

Reported by @alexdeliu.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MamaLeVrai and others added 5 commits November 24, 2026 21:51
….dll is older than validator 1.8"

This reverts commit 119b763.
…tic names per element, skip on validators older than 1.8)

The author's head now does what the bundle's own commit did (a validator version query and the
skip below 1.8), and fixes the second failing test at its cause; the bundle's commit is
reverted just before this merge.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…ring

The shader chain moved: Marvisak#306 is at its author's new head (e3067ae), and the bundle's own
validator commit is reverted.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…centrics

The shader chain moved: Marvisak#306 is at its author's new head (e3067ae), and the bundle's own
validator commit is reverted.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…bustness

The shader chain moved: Marvisak#306 is at its author's new head (e3067ae), and the bundle's own
validator commit is reverted.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The shader chain moved: Marvisak#306 is at its author's new head (e3067ae), and the bundle's own
validator commit is reverted.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@Marvisak

Copy link
Copy Markdown
Owner

Automated triage for the maintainers. Closing because this pull request re-packages other open pull requests. Each of those is reviewed on its own, so a bundle cannot be merged.

If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

@Marvisak Marvisak 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.