Skip to content

wave64: keep SCC live for explicit src_scc reads - #4300

Merged
ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
DoubleD17:fix/wave64-src-scc-liveness
Nov 23, 2026
Merged

ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
DoubleD17:fix/wave64-src-scc-liveness

Conversation

@DoubleD17

@DoubleD17 DoubleD17 commented Nov 23, 2026 •

Copy link
Copy Markdown

Claimed in the coordination thread.

What and why

The emitter reads the src_scc operand from the same SCC value as scc, but the wave64 optimizer only kept the latter live. An explicit src_scc read could therefore see a stale value after the optimizer removed the vote from s_and_saveexec_b64.

This change recognizes both spellings in the shared SCC analysis. The regression runs the translated shader for scalar and vector reads with 64 and 128 threads. With the original analysis, all 384 lane results were zero instead of one. With the fix, all 384 match. The existing test for eliminating a dead vote still passes.

Tested

The focused wave64 semantic run (test_wave64*.py) passed all 165 tests.

Synthetic fixtures only. This changes analysis of an existing operand. No GPU or game package was used.

No game files. AI-assisted.

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

Ran this at 7b1836fd on Windows 11: python -I tests/semantic/test_wave64_emulate_opt.py -> 23 tests, OK; git diff --check clean.

Explicit src_scc readers now keep SCC live through the wave64 emulation analysis instead of letting the optimizer drop a write it cannot see. The new cases cover the explicit read; the rest of the CFG suite passes. No blocking issue.

@Juryii

Juryii commented Nov 23, 2026

Copy link
Copy Markdown

Independently reviewed and tested 7b1836fde8321208cdf576ed93695dbdf482a8fd on Windows / CPython 3.12.5, CPU only, synthetic fixtures.

  • python -I tests/semantic/test_wave64_emulate_opt.py -q: 23 passed.
  • python -I tests/semantic/test_fspx_rules.py -q: 9 passed.
  • Changed-file compilation and git diff --check pass; checkout clean.

Additional execution checks through the actual translator and the suite's workgroup interpreter: 48 shader runs, 4,864 lane values, zero mismatches. Both scc and src_scc were read via scalar and vector consumers, with 64- and 128-thread workgroups. Selected global lane IDs straddled the 31/32 and 63/64 boundaries, included the final lane, and included an ID outside the group (zero EXEC). Unlike the new regression's per-wave lane selection, these cases activate at most one logical wave: in 128-thread groups one wave must return 1 and the other 0. Both spellings agree, including those mixed-wave results.

Negative control: restored the actual parent commit's reads_scc function in memory, leaving all other code and the same synthetic inputs unchanged. The 24 src_scc runs then contain 20 incorrect programs / 1,280 incorrect lane values; the four zero-EXEC cases remain correctly zero. The 24 canonical scc controls still match. The PR's own new regression also fails in all four thread-count/consumer subcases with that parent analysis.

No blocking findings within this scope. The emitter already treats the two spellings as the same SCC value; routing the alias through reads_scc also gives _scalar_rw its implicit SCC read bit. This checks translated execution in the CPU interpreter, not GPU execution, external SPIR-V validation or the game corpus.

AI-assisted review with Codex; tests and negative controls executed locally. No repository files edited.

@tunczzz

tunczzz commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Tested 7b1836fd (base main aa2988cc) on an NVIDIA GeForce RTX 5070 Ti (Blackwell, driver 616.56, subgroup 32..32), Windows 11 10.0.26300, with LEONIDA_W64_EMULATE=1, which is the path wave64_emulate_opt.py takes on a 32-wide GPU: pass, no change from main.

  • scripts/run_gpu_tests.py (translator from this head; runtime built from aa2988cc with MSVC 19.44, since this PR doesn't touch runtime/): 195/210 passed, 15 skipped, 0 failed.
  • The same run on main aa2988cc on this machine: 195/210 passed, 15 skipped, 0 failed, with the same set of PASS lines (diffed).

I did not check whether any GPU fixture contains the src_scc shapes this PR fixes, so read this as no regression on hardware, not as a hardware check of the fix; the PR's CPU workgroup-interpreter cases cover the fix. No game files. AI-assisted (Claude Code).

@akimfomin

Copy link
Copy Markdown

Independent targeted GPU check of 7b1836fde8321208cdf576ed93695dbdf482a8fd against current main 03b09a08 on RTX 4070 Ti SUPER (Ada), driver 617.14, Windows 11 28000.3501. The same portable vk_compute_test and physical 32-lane subgroups were used for all wave64-emulated cases.

  • Four src_scc cases from the PR (scalar/vector × 64/128 logical lanes): main 0/384, PR 384/384 expected words. Main wrote zero where the fixture expects one.
  • Two extra 128-lane variants with only the second logical wave active: the PR produced 64 zeros followed by 64 ones in both cases, 256/256 words. Main wrote zero everywhere, 128/256.
  • Six equivalent scc controls: 640/640 on both versions.

All 24 modules passed Khronos spirv-val --target-env vulkan1.2 and all 24 dispatches exited 0. The comparison checked the GPU readback. Vulkan validation layers were off. Synthetic fixtures only. AI-assisted.

@TreXito

TreXito commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested 7b1836fd (base main aa2988cc) on AMD Radeon RX 7800 XT (RDNA3, gfx1101, subgroup 32..64; wave64 runs natively here), AMD Windows driver 26.11.2 (32.0.32029.2010), Windows 10 Pro 22H2 build 19045.7846, MSVC build of main's test programs (the PR changes only Python), VVL 1.4.363.0, llvm-mc 21.1.8: pass, no regression.

main aa2988cc 7b1836fd
python -I tests/semantic/test_wave64_emulate_opt.py FAILED (failures=4): test_src_scc_keeps_mask_vote_live for threads 64/128 × scalar/vector (main's tools/wave64_emulate_opt.py swapped in) Ran 23 tests, OK
run_gpu_tests.py, native wave64 196/210, 14 skipped, 0 failed 196/210, 14 skipped, 0 failed
LEONIDA_W64_EMULATE=1 (AMD's default 64-wide subgroup) 196/210, 14 skipped, 0 failed 196/210, 14 skipped, 0 failed
LEONIDA_W64_EMULATE=1 with VKC_SUBGROUP_SIZE=32 VKH_SUBGROUP_SIZE=32 (32-wide, as on NVIDIA) 196/210, 14 skipped, 0 failed 196/210, 14 skipped, 0 failed

In all three GPU modes the per-test PASS/SKIP list is identical between main and the PR (210 rows). The GPU suite has no explicit src_scc reader after an s_and_saveexec_b64, so on hardware this only shows the optimizer change is neutral. The bug and the fix show in the semantic test.

AI-assisted (Claude Code). Synthetic fixtures only, no game files.

@ItsNotRexed
ItsNotRexed merged commit 1aa3e38 into ItsNotRexed:main Nov 23, 2026
@DoubleD17
DoubleD17 deleted the fix/wave64-src-scc-liveness branch November 23, 2026 14:26
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.

7 participants