Skip to content

wave64_halves: recognize UVOTE under non-zero EXEC and boolean UVOTE combinations (SHADER-10) - #805

Open
madhyn wants to merge 2 commits into
ProjectLeonida:mainfrom
madhyn:fix/shader10-uvote-nonzero-combine
Open

madhyn wants to merge 2 commits into
ProjectLeonida:mainfrom
madhyn:fix/shader10-uvote-nonzero-combine

Conversation

@madhyn

@madhyn madhyn commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

What and why

In tools/wave64_halves.py, several wave-uniform compare/branch idioms in the retail 1.0.2.1 graphics corpus were conservatively marked Tier C (tainted-branch):

  1. Non-zero EXEC after s_cbranch_execz / s_cbranch_execnz (st["nz"]): when a block narrows EXEC and immediately skips empty halves with s_cbranch_execz (or enters the non-empty edge via s_cbranch_execnz), every 32-lane half reaching the non-zero edge has EXEC != 0. A subsequent uniform v_cmp_* (all scalar/immediate non-tainted operands) ANDed with EXEC produces the exact same branch decision in each reaching half as in the full 64-lane wave.
  2. Wave64 SGPR pair writes with n=1: disassemblies often print v_cmp_*_e64 sN, ... with a single-register operand (n=1), whereas wave64 v_cmp writes the 64-bit pair s[N:N+1]. Propagate UVOTE and taint to s[N+1] as well so s_and_b64 vcc, exec, s[N:N+1] sees UVOTE on both halves of the pair.
  3. Boolean UVOTE combinations: s_cselect_b64 dst, exec, 0 (or 0, exec) from an untainted SCC under launch/non-zero EXEC, and s_and_b64 / s_or_b64 combining UVOTE masks (e.g., two uniform compares combined before s_and_b64 vcc, exec, ...), preserve UVOTE.

Testing

  • Added 4 tests in tests/semantic/test_wave64_halves.py:
    • test_a_uvote_under_nonzero_exec
    • test_c_uvote_under_narrowed_exec_without_execz_guard (negative control: without s_cbranch_execz, stays Tier C)
    • test_a_uvote_and_or_combine
    • test_a_uvote_cselect_from_uniform_scc
  • python3 -m unittest tests/semantic/test_wave64_halves*.py tests/test_w64_graphics*.py: 190/190 passed.
  • Corpus check on the 745 retail 1.0.2.1 VS/PS shaders that previously had wave64_graphics_reasons == ['tainted-branch']: 276 shaders moved out of Tier C (11 Tier A, 265 Tier B).

AI-assisted: yes

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

Linux CPU review of the Wave64 classifier change. On this exact head, these four focused modules passed: tests/semantic/test_wave64_halves.py (130), test_wave64_halves_soundness.py (33), test_wave64_halves_partial_dst.py (13), and test_wave64_halves_readlane_uniform.py (2), for 178/178 total. git diff --check also passed.

The new nz fact is propagated only along the non-empty branch of s_cbranch_execz / the taken branch of s_cbranch_execnz, and is intersected at joins. I found no issue in that flow by inspection.

tests/test_wave64_halves_fixtures.py was not run: it requires pytest, which is absent from the local Python/tool image; installing it in a temporary container stalled on network access. No GPU or game data was used, and no GPU result is claimed.

@GeorgiyDemo

Copy link
Copy Markdown
Contributor

Tested 3986b73a on Apple M5 Pro, macOS 26.7.3 (25G342), Python 3.15.2, against main d42773d07:

  • tests/semantic/test_wave64_halves.py: 130 tests OK at this head.
  • The same file against main's tools/wave64_halves.py fails 2 of 130, so the two new UVOTE classifications are covered.

No GPU leg: no w64_graphics tier fixture exercises UVOTE, and I did not run the tier harness on this head. AI-assisted; synthetic fixtures only, no game data.

@KernelSmoker

Copy link
Copy Markdown
Contributor

Follow-up on the latest PR head 3f7e9f2d3a7eb3d2ec1c80f3ef480bf7362f6699 (including the WQM/EXEC restore change): I reran the full semantic suite in an isolated Fedora 45 tool container with Python 3.15.2, LLVM and SPIRV-Tools. Result: 465 files, 6,113 tests, 0 files failed in 105 seconds with 16 jobs. This is CPU/interpreter validation only; no Vulkan/GPU execution or game data.

@Sangonapou

Copy link
Copy Markdown
Contributor

Tested 3f7e9f2 on NVIDIA GeForce RTX 3080 Ti Laptop (Ampere, subgroup 32..32), NVIDIA 621.24, Vulkan 1.4.357, Windows 11 Pro (build 26300): pass, GPU regression check

Runtime built at this head with scripts\build_runtime.ps1 (MSVC 19.51); shaders from runtime/test/shaders/build.py at this head (llvm-mc 23.1.6, SPIRV-Tools 2026.4); then python -I runtime/test/shaders/w64_graphics.py <spirv dir> runtime\build, exit 0. No game files.

  • Tier A 9/9 and tier B 8/8 ok, running as two 32-lane halves on this device.
  • Tier C 12/12 SKIP (tier C needs a device that can require both 64 and 32, or W64G_REF).

This is the GPU leg the CPU checks above did not cover, but as noted there no w64_graphics fixture uses the new UVOTE patterns, so it shows the tier harness still passes on a 32-wide device at this head rather than exercising the new classifications themselves.

@madhyn
madhyn force-pushed the fix/shader10-uvote-nonzero-combine branch from 3f7e9f2 to 62e5472 Compare November 25, 2026 01:56
@madhyn

madhyn commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto current main (871e4b8b9, head 62e547220), resolving the tools/wave64_halves.py conflict with SHADER-W64-WQM-UVOTE (#1091):

  • Preserved st["q"] / st["qr"] and uniform_cmp's VGPR refusal outside launch EXEC.
  • Kept st["q"] = quads on the s_wqm_b64 exec, exec path alongside wqm_base tracking so restoring launch EXEC via s_and_b64 exec, exec, s[saved] still restores st["f"] while clearing st["q"].

Verified after rebase (Python 3.14, Arch Linux):

  • python3 -I scripts/check_no_game_data.py tools/wave64_halves.py tests/semantic/test_wave64_halves.py: pass
  • python3 -m unittest tests/semantic/test_wave64_halves*.py tests/test_w64_graphics*.py: 210/210 passed (including all test_wave64_halves_wqm_uvote.py cases and NearMisses)
  • python3 -I scripts/run_semantic_tests.py tests/semantic: 484 files, 6,267 tests, 0 failures

AI-assisted: yes

@github-actions github-actions Bot removed the needs rebase Conflicts with the base branch: rebase it on main label Nov 25, 2026
@potatoe0100

Copy link
Copy Markdown
Contributor

Tested the rebased head 62e547220 merged onto main 57ba40bd6 (clean merge) on Windows 11 Pro 26300, Python 3.14: tests/semantic/test_wave64_halves.py 132 passed. On the same machine (RTX 4060, 621.14) w64_graphics.py on today's main gives 18 ok / 12 tier C SKIP / 0 failed; this change touches no GPU fixture, so I didn't rerun it per head.

No game files. AI-assisted (Claude Code), run for a non-developer tester.

clquwu added a commit to clquwu/leonida-ultimate that referenced this pull request Nov 25, 2026
… UVOTE (SHADER-10)

Adapted from ProjectLeonida/mandy#805 (madhyn, GPL-3.0, head 62e54722010c)
with exec-scope soundness tracking and monotonic WQM-base tracking:
- Track non-zero EXEC (st['nz']) on the EXEC!=0 edge of s_cbranch_execz
  (fallthrough) and s_cbranch_execnz (taken), cleared on every EXEC write.
- Scope UVOTE tags ('all', exec token, or WQM superset) so s_cselect_b64,
  s_and_b64, s_or_b64, and s_andn2_b64 combine masks only when one scope
  covers the other, rejecting incomparable narrowed EXEC scopes and
  WQM(L) & ~L helper-lane differences that diverge 1x64 vs 2x32.
- Propagate UVOTE and taint to s[N+1] for un-widened n=1 SGPR destinations
  on v_cmp_* and UVOTE 64-bit mask ops.
- Generalize WQM launch-mask restore to monotonic st['wb'] (WQM(M) & M == M).

Measured over all 13,268 wave64 VS/PS/GS shaders in the retail 1.0.2.1 corpus:
+56 Tier-C -> Tier-A/B promotions (21 Tier A, 35 Tier B), 0 regressions.
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.

5 participants