Skip to content

Shaders: lower Wave32 compute branches that reuse lane masks as scalar data - #2091

Open
rezioliver-collab wants to merge 8 commits into
Marvisak:mainfrom
talleyrand222:fix/wave32-compute-scalar-control
Open

rezioliver-collab wants to merge 8 commits into
Marvisak:mainfrom
talleyrand222:fix/wave32-compute-scalar-control

Conversation

@rezioliver-collab

@rezioliver-collab rezioliver-collab commented Nov 25, 2026 •

Copy link
Copy Markdown

Why these 40 shaders

We started with 40 RDNA 2 Wave32 compute shaders. On main, every one stopped with a register joining a lane mask and data, read as data. At a branch or loop join, the guest could use the same scalar register as a 32-bit number and as a mask with one bit per lane. The goal was to emit DXIL for every shader in that fixed set while preserving the word that all lanes read after reconvergence. This PR emits all 40.

What changed and why

The compiler keeps the complete scalar word at joins it can lower directly. For the remaining supported compute groups made up of complete Wave32 waves, it follows native scalar branches with an explicit 32-bit EXEC. If the wave reaches a scalar write with EXEC == 0, that write still takes effect. Vector writes respect the enabled lanes. A later scalar read sees the last write reached by the wave. These rules follow AMD's wavefront execution model, §3.3 on EXEC, §4.1 on program control and the S_AND_SAVEEXEC_B32 definition in §12.3. AMD RDNA 2 ISA reference

Some of these programs also read resource descriptor word zero as a number. For a buffer view, that word is the low 32 bits of its guest byte address, including the first-element offset. An image stores its base in 256-byte units, so word zero contains guest address bits 39–8. The host supplies this value when the shader reads the descriptor numerically. AMD RDNA 2 ISA, §8.1.8 table 37 and §8.2.6 table 45

Translation and validation

All four configurations use main at 940d32f, the same archive and the Windows x64 SDK validator (dxil.dll 1.8.2502.11). The last two columns cover all 25,889 matched entries.

Build Target 40 emitted Target 40 SDK accepted Archive emitted Archive SDK accepted
Main 0 0 25,591 23,918
This PR 40 16 25,633 23,936
Main + Halfect’s #1065 0 0 25,591 24,653
This PR + #1065, tested locally 40 40 25,633 24,695

This PR gains 42 emissions (the target 40 plus two more programs) and 18 SDK passes over main, with zero losses in either set. The remaining 24 shaders in the target group use compute derivatives and pass with the validator 1.8 metadata supplied by Halfect’s separate #1065. That accounts for the 42 additional SDK passes when Wave32 is applied on top of #1065. The metadata commit has been removed from this branch. YaBulochka independently measured the standalone gain of 18 on AMD/Linux at 93685fe, before the descriptor layout revision. Independent archive run

Compatibility with #2048

The host and compiler use two dwords (8 bytes) per slot in the t1 view-address table. A buffer keeps its original low/high address pair. For a view that supplies only native word zero, the first dword holds that word and bit 16 in the second identifies the entry. A buffer-pointer read of such a slot yields zero. Clearing the slot publishes two zeros.

Both PRs edit descriptor/host.rs. The linked merge of this head and #2048 (dfb8093) publishes staged descriptors and their two address words together and initializes the table from already-published slots. An RTX 5080 readback checked the value before and after flushing an image replacement and a clear. It also checked that an older queued update could not overwrite a newer direct write at the next flush. All five staging regressions from #2048 passed. Tested merge and conflict resolution

Seven hand-written Wave32 fixtures passed SDK validation and produced the expected four dwords for all 704 threads on the RTX 5080. The archive measurements cover offline translation and SDK acceptance. The GPU execution results cover the synthetic fixtures. Both workspace Clippy configurations and the upstream CI job passed. GitHub CI

Full local Windows test suite

Six tests failed in the full local run. Five also failed in the unmodified-main suite. The sixth, a_page_list_filled_after_its_request_starts, failed intermittently on unmodified main and passed three isolated reruns of the PR test binary.

AI-assisted with OpenAI Codex.

@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 + WARP, Rust 1.98.1 MSVC, with dxil.dll validator):

  • cargo test -p victory-shader --lib wave32 — passed on RTX 5090 hardware + WARP
  • cargo test -p victory-shader --lib emit::memory_tests:: — 3 passed, 0 failed
  • cargo test -p victory-gpu --lib descriptor_base_word_tracks_the_guest_view_address — passed
  • cargo clippy -p victory-shader -p victory-gpu --all-targets — 0 warnings
  • cargo xtask policy — ok (184 files ok)

Clean Wave32 compute branch scalar mask preservation and guest view base word tracking across victory-shader and victory-gpu. Looks great.

AI-assisted (Gemini 4 Neon).

@jeremygold02

Copy link
Copy Markdown
Contributor

Triage verdict — Review the Wave32 work independently of #1065 (00f14fa)

Evidence

Checks and limits

  • Compared the commit patches and the two side-table layouts. The hardware/WARP and descriptor checks in the existing review are the execution evidence for this head. I did not run the combined branches.

Next step

This verification was AI-assisted.

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

144 passed / 0 failed / 2 ignored. Scalar mask words preserved across Wave32 compute branches — mask-word liveness fix; mixed gpu+shader, gpu half Windows-only.

@YaBulochka

Copy link
Copy Markdown

AMD/Linux validation run of this stack, on the full retail dump. It is not a small win: +777 programs validate, and almost all of it comes from the last commit, not the scalar-mask ones.

Method: victory translate shaders.rpf --validate --list, retail 1.0.2.1, x86_64-pc-windows-gnu release under Wine, dxil.dll 1.9.2609.5. Same dump for every build.

Build validated vs 940d32f
940d32f (main) 23,918 -
93685fe (this stack without the last commit) 23,936 +18
pr2091 (all five commits) 24,695 +777

So of the +777, +759 is the "validator 1.8 for compute derivatives" commit alone, and the four scalar-mask/Wave32 commits give +18. Nothing is lost in either step (validated sets grow, no program disappears from the list).

What the 777 are: the whole RaytracingResolve family - standard 388, ped 114, prop 50, normal 32, rtdirectionalshadows 28, trees 26, weapon 22, trunk 12, indirect 11, sr 10 and the rest. On main they fail with

validator: Function: main: error: Entry function performs some operation that is
incompatible with the shader stage or other entry properties. See other errors for details.

which is the gradient-in-compute rejection the last commit describes; the validator gives no further detail in this path.

Two process notes, since the title only mentions scalar masks:

  • the behavioural weight of the PR is in its last commit; a reviewer skimming the title will not expect +759 validated programs, and it would be worth a line in the description (or splitting the validator bump out, if that is easier to review);
  • it needs dxil.dll 1.8+ at run time. With 1.9 here it is fine; on a host that ships 1.6/1.7 the derivative modules would be emitted and then rejected, so the version requirement is worth stating explicitly.

I did not check whether these 777 also compile in DXC or run; this is the DXIL validator count only.

clquwu pushed a commit to clquwu/leonida-ultimate that referenced this pull request Nov 25, 2026
…nt 2D mip loads, Win11 timer opt-out

Translator (tools/rdna2spirv.py)
- ubiquitarianism/leonida#1585 (whoalin1, GPL-3.0): the low-16 mask of every
  int-derived value merged into a preserved 16-bit half is OpBitFieldUExtract
  (base 0, count 16), not OpBitwiseAnd & 0xFFFF, which NVIDIA's compiler
  miscompiles (the kept high half corrupted). Six sites: VOP3 16-bit integer
  results, mad_i16/u16, min/max/med3, signed cvt_i16_f16 / cvt_norm_i16_f16,
  signed saturate_int16. Two tests that pinned the old shape updated; new
  tests/semantic/test_nv_and16_extract.py (shape census + interpreter values,
  negative control; fails on the previous translator).
- ubiquitarianism/leonida#1572 (tedin7, GPL-3.0), refined: 2D image_load_mip
  with glc reads the coherent storage view for mip 0; any other mip takes the
  sampled fetch at that level instead of upstream's zero-fill, which is only
  right for a single-level T#. Other dims and tfe/lwe stay Unsupported.
  CoherentMipLoad tests + spirv-val on four forms; design.md row updated.

Decoder (tools/rdna2_decode.py + native port)
- ubiquitarianism/leonida#1525 / #1524 (GPL-3.0): inline constants 240..248 on
  16-bit integer operands decode to their binary16 patterns (LLVM
  printImmediateInt16), so the translator no longer reads f32 bits there;
  ds_condxchg32 keeps one offset; ds_swizzle omits offset 0 and prints
  ROTATE/FFT as LLVM does. Ported to tools/rdna2_decode_native (tables passed
  through the blob, _src_is_int16 added to the fingerprint).

Runtime (runtime/src/main.cpp)
- FVF-07, after ThatRecompDev/five-star-recomp@344f05b (GPL-3.0):
  ScopedTimerResolution also opts out of Windows 11 timer-resolution
  throttling (PROCESS_POWER_THROTTLING_IGNORE_TIMER_RESOLUTION) and hands it
  back to the system with timeEndPeriod.

Guard only: Marvisak/VIctory#2091's Wave32 scalar-mask fix is already how this
translator works (EXEC is a per-lane flag, scalar ops unmasked, wave-uniform
branches); tests/semantic/test_wave32_scalar_mask_branches.py pins it.

Skipped: ubiquitarianism/leonida#742 (XMem view coalescing). Natively it saves
about 230 ms once at startup (99,776 per-page views 233 ms vs 4 MiB views
4 ms), but every partial unmap would then tear down up to 63 neighbouring
pages, including GPU host-pointer imports and pages under in-flight I/O.

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

Marvisak commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Needs work. Merging main fixed the conflicts; it merges cleanly and CI passes (check). The two earlier asks are still open:

  • Split the descriptor change. This PR still carries the view-address change: descriptor/host.rs::address_words/view_addresses publish a native base word with VIEW_NO_BUFFER_POINTER for non-buffer views, and resource.rs changes too. It is a separate change to runtime state and needs its own PR and evidence, e.g. the RDNA2 ISA descriptor layout for word 0 and a readback like the one you ran with GPU: stage HostHeap descriptor updates until submission flush #2048.
  • Evidence for the Wave32 lowering. The seven synthetic fixtures check that the RTX 5080 output matches what the fixtures expect, and Capi360's run shows the programs translate. Neither compares the whole-wave lowering in emit/lower/wave32.rs (explicit EXEC, scalar writes taking effect with EXEC == 0) with the console. A reference would do: an RDNA2 ISA citation for scalar writes under EXEC == 0, or expected values derived from that behaviour rather than from this lowering.

The translation numbers (40 targets emitted, 16 validated, all 40 with #1065) are useful context. They show the modules are accepted, not that they are right.


Generated by Claude Code

@rezioliver-collab
rezioliver-collab force-pushed the fix/wave32-compute-scalar-control branch from 00f14fa to 20ed9d4 Compare November 25, 2026 13:21
@rezioliver-collab rezioliver-collab changed the title Shaders: preserve scalar mask words across Wave32 compute branches Shaders: lower Wave32 compute branches that reuse lane masks as scalar data Nov 25, 2026
@rezioliver-collab

Copy link
Copy Markdown
Author

Thanks for the review, @Marvisak. We removed Halfect’s validator commit so it can land through #1065. The updated PR explains why reusing a lane mask as scalar data blocked 40 Wave32 compute shaders. This branch now emits DXIL for all 40. The SDK validator accepts 16 on this branch and all 40 with #1065 applied.

We also tested this branch together with #2048. On an RTX 5080, we verified descriptor slot reuse and clearing with the two-dword layout. Tested merge with #2048

Ready for another review.

zhaibingye added a commit to zhaibingye/VIctory-AISpeede that referenced this pull request Nov 25, 2026
Port Marvisak/VIctory#2091 as one descriptor ABI change, keeping retry-on-use for placed textures under pressure and the existing early-depth and descriptor-table behavior. Keep GPU address records at two words with a native-base tag for non-buffer views.

Co-authored-by: rezioliver-collab <256438629+rezioliver-collab@users.noreply.github.com>
@Capi360

Capi360 commented Nov 25, 2026

Copy link
Copy Markdown

Offline follow-up on RTX 3060 Ti (8 GiB, NVIDIA 616.56), Ryzen 7 5700X3D, 32 GiB RAM, Windows 11 Pro build 26200.

I tested this PR together with #1065 on a code-only integration of 940d32f with the NVIDIA graphics compatibility changes. All five compute shaders that had produced the mixed mask/data join refusal during the preceding Series X run translated successfully. The seven synthetic emit::semantics_tests::wave32 tests passed.

The run produced nine intervals above 200 draws/frame (0.77 FPS average). The captures still did not show a usable scene. Windows dropped below 2 GiB of available commit and the monitor stopped the run, so this does not establish that the later GPU reset is fixed.

AI-assisted testing. Integration branch: https://github.com/Capi360/VIctory/tree/codex/rtx-3060-ti-wave32-data

Resolve the descriptor and shader conflicts against the four-dword view-address table. Preserve the original Wave32 history and publish the tree tested on macOS arm64.
@rezioliver-collab

Copy link
Copy Markdown
Author

I’m on a Mac until Friday. Could someone with Windows and an RTX 5080 run the Wave32 and D3D12 checks on the updated PR head, 8bd4b17?

This head includes upstream main at 13f91ca and uses its 16-byte view-address records. On macOS arm64, 158 shader tests passed, two benchmarks were ignored, and the asset-policy check passed. All the fixtures below are synthetic.

Please run these with the RTX 5080 as the hardware adapter and a current x64 dxil.dll available for SDK validation.

cargo test -p victory-shader --lib --locked wave32_ -- --nocapture --test-threads=1
cargo test -p victory-shader --lib --locked title_memory_is_read_and_written_at_computed_addresses -- --nocapture --test-threads=1
cargo test -p victory-gpu --lib --locked a_reused_title_slot_publishes_the_native_base_word -- --nocapture --test-threads=1

Please reply with your NVIDIA driver version, the seven DXIL validated and readback matched results (704 threads total), and the D3D12 readback matched both 16-byte slots line. The last test reads two adjacent slots back from the GPU after an image write, a clear, and reuse as a buffer. If a test skips or fails, the skip message or first error would help too. Thanks!

Keep dynamic 16-byte descriptor records and native EXEC source selection for Wave32 DPP. Preserve the Wave64 and partial-group test coverage, and split DPP lowering to stay within the repository file-size limit.
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.

7 participants