Skip to content

Shaders: preserve scalar mask words across Wave32 compute branches - #2091

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

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

Conversation

@rezioliver-collab

Copy link
Copy Markdown

Shaders: preserve scalar mask words across Wave32 compute branches

Change

A native Wave32 has one scalar register value for all 32 lanes. When two branches run with different EXEC masks, the last scalar write reached by the wave determines what all lanes read at reconvergence. An active-lane ballot inside one branch can lose bits that belong to lanes outside that branch.

This change retains scalar dwords at supported mask/data joins. For remaining eligible cases in full Wave32 compute groups, it lowers the native scalar control flow with a shared 32-bit EXEC. Scalar writes follow native execution order, including writes reached with empty EXEC. Vector writes use their lane's EXEC bit. The host descriptor table also supplies the native base word when a scalar instruction reads it numerically. The existing GPU page-write tracking uses its own table.

The final commit is Halfect’s compute-derivative metadata change from #1065, ported with the original author attribution. Review the Wave32 compiler and runtime changes through 93685fe74. Related mask work is tracked in #1407 and #1420.

Archive validation

Tested against Marvisak/VIctory:main at 940d32f69b22265690a0b5a15d6ded572ba33baf. The same fixed cohort of 40 compute programs was measured in all four configurations with the Windows x64 SDK DXIL validator.

Configuration DXIL emitted SDK accepted SDK rejected
Upstream main 0 0 0
Main with #1065 0 0 0
Wave32 commits 40 16 24
All commits in this PR 40 40 0

Full, unfiltered scans matched all 25,889 archive entries by position and stage.

Configuration DXIL emitted SDK accepted SDK rejected
Upstream main 25,591 23,918 1,673
Main with #1065 25,591 24,653 938
PR head 25,633 24,695 938

With #1065 held constant, the Wave32 commits gained 42 SDK passes and lost 0. The full PR gained 777 and lost 0 against unmodified main.

Regression tests

The seven hand-written Wave32 fixtures all failed to lower on unmodified main when the same fixture source was backported. On the PR head all seven passed SDK validation. On an RTX 5080, all 704 thread outputs matched their CPU expectations across empty, full and sparse EXEC, ordered scalar writes, inactive-lane reads, descriptor base words and loop joins. The host descriptor-address regression and the upstream page-write-mark regression also passed.

Both workspace Clippy variants passed with warnings denied. The asset-policy check passed. The complete workspace suite on Windows recorded 696 passed, 5 failed and 10 ignored on main, and 707 passed, 5 failed and 10 ignored on the PR head.

The same 5 tests failed on both revisions.

  • descriptor::host::tests::dynamic_slots_are_held_until_released
  • emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride
  • emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros
  • emit::synthetic_tests::gathers_at_a_level_match_the_hardware
  • memory::tests::lists_share_a_table_and_copies_keep_their_views

The hardware results cover synthetic dispatches. The archive exercise measured offline translation and SDK acceptance. Game rendering and performance were outside this measurement.

AI assistance was provided by OpenAI Codex (GPT-6) for the Wave32 follow-up, integration and validation.

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

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

The last commit (00f14fa, validator 1.8 for compute derivatives) is #1065 by another contributor, which is still open; by the retail-dump counts posted here it accounts for about +759 of the +777 validated programs, while the four Wave32 commits give +18 to +42. Please drop it from this branch and let it land through #1065, and retitle/describe the PR by what remains.

On the Wave32 part (emit/lower.rs, emit/lower/wave32.rs, structure.rs, and the three-dword records in descriptor/host.rs address_words/write_address): this changes shader semantics (shared scalar values across EXEC-divergent branches, the native descriptor base word read numerically). The hardware runs compare against your own CPU model, so please state the reference these semantics come from (public RDNA ISA documentation, or what the title's shaders rely on). The three-dword view-address layout also needs to be reconciled with #2048, which stages two-dword records. CI passes.


Generated by Claude Code

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