Skip to content

wave64_halves: EXEC written from a constant or plain data is tier C tainted-exec - #8521

Open
paratustra wants to merge 2 commits into
ItsNotRexed:mainfrom
paratustra:shader-wave64-halves-exec-from-data
Open

paratustra wants to merge 2 commits into
ItsNotRexed:mainfrom
paratustra:shader-wave64-halves-exec-from-data

Conversation

@paratustra

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: new item

What and why

Bit L of a 64-bit EXEC value is lane L in the wave, but lane L − 32 of the second half when the wave runs as two 32-lane halves. Only lane masks, EXEC itself and 0 / −1 select the same lanes in both. Four forms were tier A on main, while the wave interpreter gives different results for 64 lanes and 2×32 (run_cut, vs() listings):

listing lanes that differ
s_xor_b64 exec, s[10:11], 0xff 8
s_bfm_b64 exec, 40, 0 24
v_readfirstlane_b32 exec_hi, v0 32
s_and_saveexec_b64 s[12:13], s[20:21] with s[20:21] = 0xff 8

Why each was missed:

  • s_bfm_b64 and the VALU writes to exec_hi never reached exec_write(): earlier handlers took them, and their put() skips EXEC.
  • A constant or plain-data source carries no taint, so nothing flagged it.

This PR does two things:

  • It routes every EXEC write to exec_write() before those handlers.
  • It flags tainted-exec when a source is not a lane mask (is_mask), 0 / −1 or null. A 32-bit half write also stays mask-half, as before.

One exemption is needed. The legacy GS prologue's s_bfm_b64 exec, sN, …, where sN = s3[15:8] from s_bfe s3, 0x80008, is pinned at 64 lanes by the translator (s3 = 0x4000), so EXEC is the same in the wave and in the halves. Without the exemption, gs_w64_a_ring and the other GS fixtures would drop to C (3 failures in test_wave64_halves.py).

This is the EXEC counterpart of #8164, which covers VALU mask operands.

Tested

CPython 3.12 (uv), macOS arm64, CPU only, base main:

  • test_wave64_halves.py, _readlane_uniform and _soundness pass. The new tests:
    • test_c_exec_from_data_differs: the 4 listings above are C, and the test checks the differing lane counts.
    • test_a_exec_from_a_mask_0_or_minus_1_invariant: s_mov_b64 exec, -1, a saved mask, and 0 stay A, with equal results.
    • test_exec_from_a_bfm_of_a_constant_is_tier_c.
  • Negative control: with main's tools/wave64_halves.py, the 4 C subtests and the s_bfm test fail; the A controls pass.
  • Full suite: scripts/run_semantic_tests.py tests/semantic gives 5,959 tests on this branch and 5,956 on the base. Both fail the same 2 files: test_image_atomics_guard and test_image_store_d16, which are red on main.
  • tests/test_wave64_halves_fixtures.py and test_wave64_emulate_opt_cfg.py (pytest): 35 passed, 1 skipped, the same as on the base.
  • test_docs*.py: the same 3 failures as the base.

Not measured: the corpus effect. Any game shader that loads EXEC from data that lane_masks does not track as a mask moves from A to C. That costs performance, not correctness. A census before and after would show how many move.

AI-assisted: yes

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed: one sentence in the Wave64 graphics: partition invariance row.

…ainted-exec

Bit L of a 64-bit EXEC value is lane L in the wave but lane L - 32 of the
second half, so only lane masks, EXEC itself and 0 / -1 select the same lanes.
s_xor_b64 exec with 0xff, s_bfm_b64 exec, 40, 0, v_readfirstlane_b32 exec_hi and
a saveexec of a data pair were tier A with different 64 vs 2x32 results. Route
every EXEC write to exec_write() before the VALU and bitfield handlers, and flag
any source that is not a mask, 0 / -1 or null. The legacy GS prologue's
s_bfm_b64 exec of s3[15:8], which the translator pins at 64 lanes, is exempt.

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

Independent Windows 11 / Python 3.12.10 review of dc2a5ea7 merged onto origin/main (867d922f) — CPU-only, synthetic inputs, no game files.

Checks run

  • Clean merge onto origin/main (867d922f): clean.
  • python -m unittest discover -s tests/semantic -p test_wave64_halves.py: 128/128 OK.
  • python -m unittest discover -s tests/semantic -p test_wave64_halves_soundness.py: 33/33 OK.
  • python -m unittest discover -s tests/semantic -p test_wave64_halves_readlane_uniform.py: 2/2 OK.
  • Negative control (reverted tools/wave64_halves.py to origin/main with the PR tests): 5 failures across all 4 test_c_exec_from_data_differs subtests (vs_c_exec_xor_const, vs_c_exec_bfm, vs_c_exec_rfl_hi, vs_c_saveexec_data) and test_exec_from_a_bfm_of_a_constant_is_tier_c, while test_a_exec_from_a_mask_0_or_minus_1_invariant stays green.
  • python -m compileall -q tools/wave64_halves.py tests/semantic/test_wave64_halves.py: exit 0.
  • python -I scripts/check_no_game_data.py tools/wave64_halves.py tests/semantic/test_wave64_halves.py docs/design.md: exit 0.
  • git diff --check origin/main: clean.

Code audit

  • Moving the EXEC-write dispatch ahead of the s_bfm_b64 / v_readfirstlane / v_readlane handlers cleanly closes the hole where their put() skipped EXEC.
  • Requiring EXEC-writing ops to be lane-wise on lane masks, 0/-1/0xFFFFFFFFFFFFFFFF, or null (with v_cmp/v_cmpx and gs_prologue_bfm handled explicitly) is sound for 64-vs-2×32 partition invariance.
  • gs_prologue_bfm() properly pins GS stage, non-looping entry block 0, single-SGPR s_bfe_{i,u}32 sN, s3, 0x80008 with s3 untouched beforehand (s3 = 0x4000 -> count 64 -> 64 & 63 == 0 -> zero mask in both full and halved waves), and excluding s_bfm_b64 from the SCC-clobber at exec_write matches SCC_LESS.

LGTM. AI-assisted (Antigravity).

@neoisg8

neoisg8 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Verified on Windows 11 x64 (Python 3.14.0rc2, CPU-only; pure synthetic fixtures, zero game data).

Head verification

On HEAD (dc2a5ea776f4e90d3e22d1d24e8951e8027f367e):

  • python -I -m unittest discover -s tests/semantic -p test_wave64_halves.py: 128/128 passed.
  • Explicitly verified the new test suites:
    • test_c_exec_from_data_differs: all 4 synthetic listings (vs_c_exec_xor_const, vs_c_exec_bfm, vs_c_exec_rfl_hi, vs_c_saveexec_data) correctly classified as Tier C (tainted-exec), matching the interpreter's divergent 64-lane vs 2×32-lane execution.
    • test_exec_from_a_bfm_of_a_constant_is_tier_c: properly classified as Tier C (tainted-exec).
    • test_a_exec_from_a_mask_0_or_minus_1_invariant: invariant mask/immediate sources stay Tier A.
  • python -I tests/test_design_contract_rows.py: 4/4 passed.

Negative control (discrimination check)

Restoring tools/wave64_halves.py to HEAD~1:

  • Both test_c_exec_from_data_differs and test_exec_from_a_bfm_of_a_constant_is_tier_c reproduce 5 failures:
    FAIL: vs_c_exec_xor_const: AssertionError: ('A', []) != ('C', ['tainted-exec'])
    FAIL: vs_c_exec_bfm: AssertionError: ('A', []) != ('C', ['tainted-exec'])
    FAIL: vs_c_exec_rfl_hi: AssertionError: ('A', []) != ('C', ['mask-half', 'tainted-exec'])
    FAIL: vs_c_saveexec_data: AssertionError: ('A', []) != ('C', ['tainted-exec'])
    FAIL: test_exec_from_a_bfm_of_a_constant_is_tier_c: AssertionError: ('A', []) != ('C', ['tainted-exec'])
    
  • Confirms the discrimination: base incorrectly marked non-mask/data EXEC writes as Tier A partition-invariant, while PR properly identifies them as Tier C with tainted-exec (and preserves legacy GS prologue exemption).

Repository hygiene

  • python -I scripts/check_no_game_data.py tools/wave64_halves.py tests/semantic/test_wave64_halves.py docs/design.md: passed.
  • python -m compileall -q tools/wave64_halves.py tests/semantic/test_wave64_halves.py: passed.
  • git diff --check HEAD~1: clean (strict LF line endings, zero trailing whitespace).

LGTM!

AI-assisted: verified and reviewed on Windows 11 environment.

@RAINighty

Copy link
Copy Markdown

Tested dc2a5ea77 merged with main 867d922f0 (clean merge) on Windows 11 (10.0.26300), Python 3.13.15 in UTF-8 mode (PYTHONUTF8=1; venv with the pinned tests/requirements.txt), with llvm-mc 21.1.8 (AMDGPU) and SPIRV-Tools v2026.4 on PATH: pass.

  • tests/semantic/test_wave64_halves.py with this PR: passes (Ran 128 tests in 6.975s, OK). On main: passes (Ran 125 tests in 7.249s, OK).
  • Negative control: this PR's test with main's version of docs/design.md, tools/wave64_halves.py fails (Ran 128 tests in 7.345s, FAILED (failures=5)), so the new test does catch the problem.
  • Code not reviewed beyond running it. No GPU or game files.

AI-assisted (Claude Code).

@Atomic258

Copy link
Copy Markdown
Contributor

Tested dc2a5ea7 on Windows Server 2022, CPython 3.13.12: pass

  • python -I -m unittest discover -s tests/semantic -p "test_wave64_halves.py" -> OK

git diff --check clean; python -m compileall -q exit 0. No game files, no GPU. AI-assisted (Devin).

@IxMxAMAR

Copy link
Copy Markdown

Checked dc2a5ea7 on Windows 11 Pro 26200, CPython 3.12.10, with an RX 9070 XT (RDNA4, AMD 26.11.2).

  • tests/semantic/test_wave64_halves.py: OK at the head. With the base's tools/wave64_halves.py (867d922f), 5 tests fail.
  • runtime/test/shaders/w64_graphics.py with shaders built by this head and by the base (vk_harness from a main 867d922f build): identical output, 25 ok and 4 SKIP (the GS/VS tier C fixtures, which need RADV). The pixel tier C fixtures run on this GPU, so every existing fixture keeps its tier and its result.

No game files. AI-assisted.

@slint6614-dev

Copy link
Copy Markdown
Contributor

AMD RDNA2 GPU-suite check of dc2a5ea77 (AI-assisted): full scripts/run_gpu_tests.py with this branch's translator, against the same run on main 867d922f. Ryzen 5 9600X iGPU "AMD Radeon(TM) Graphics" (gfx1036, the console's RDNA2 family), native wave32/wave64, AMD Adrenalin 26.11.2 (Vulkan driver 2.0.353), Windows 11 26300, Python 3.12; test programs from a RelWithDebInfo build of 561b65a (LEONIDA_GPU_TEST_TIMEOUT=60).

Same per-fixture results as main: every fixture all translated and pass spirv-val; main: 222/241 passed, 17 skipped, 2 FAIL (ps_sample_implicit_uint, ps_table_fetch: vk_texture_test usage errors from the older test-program build, identical on both sides). No fixture changes status.

@wavehs

wavehs commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

macOS arm64 verification (Apple M3 Pro)

The PR head dc2a5ea7 is already rebased on current main, so the merge fast-forwarded with no conflicts.

Host: macOS 27.2.1, Apple M3 Pro (arm64), CPython 3.15.2.

Check Result
tests/semantic/test_wave64_halves.py 128/128 pass
Full translator suite 447 files, 5,960 tests, 61 s — 2 files failed
main baseline 447 files, 5,957 tests, the same 2 files

+3 tests over the baseline (the three new methods), no new failures. The two (test_image_atomics_guard, test_image_store_d16) reproduce on unmodified main here.

Negative control: main's tools/wave64_halves.py with the new tests → 5 failures, e.g. ('A', []) where this PR gives ('C', ['tainted-exec']). The tests bind to the change.

Spot-checked the tier rule through meta_of directly, not just via the suite:

body tier
s_mov_b64 exec, -1 A
s_and_b64 exec, exec, s[10:11] A
s_xor_b64 exec, s[10:11], 0xff C tainted-exec
s_bfm_b64 exec, 40, 0 C tainted-exec

That is the intended line: lane masks and 0/-1 stay invariant, "a constant that is not 0/-1, or plain data" does not, because bit L means lane L in the wave but lane L−32 in the second half.

One structural note on where this sits

exec_write is dispatched before the generic handlers and returns, so it now intercepts every non-SAVEEXEC EXEC write in the analysis. That is the right shape (one place instead of a rule per opcode) but it makes exec_write a choke point: every future EXEC-writing instruction has to be classified here, and the only things that can escape the taint rule are the lanewise prefixes (MASK_BITWISE + SAVEEXEC + s_cmov_b + v_readfirstlane), v_cmp*, and the GS-prologue s_bfm_b64 exemption. Reading it top to bottom I could not find an opcode that reaches the new early return and loses a classification it used to get — the saveexec branch and the exec-destination branch both replicate the previous logic — but that is the invariant to keep, and a one-line comment on the whitelist saying "anything that writes EXEC and is not listed is tainted by construction" would make a later addition obviously safe or obviously wrong.

Cross-PR, worth doing when both land: #8526 makes s_bitreplicate_b64_b32 exec, s4 translatable. It writes EXEC and is not in the lanewise set, so this analysis will correctly call it tier C tainted-exec — bit L is s4[L >> 1], which is lane L in the wave and s4[(L-32) >> 1] in the second half, so the two halves disagree for any non-trivial word. That consistency is by construction, not by accident, but a fixture with the two PRs together would pin it.

On the doc row: it grew 20,054 → 20,418 characters and adds the s_bfm_b64 case (it is an addition, not a trim), and all the key terms (ADD_TID_ENABLE, SHADER-833, the census counts, lane-id) are still there.

No functional issues found.

No game files. AI-assisted.

…t too

lane_masks tracks VCC (or a pair) written from a constant as a mask, so
s_mov_b64 vcc, 1 then s_mov_b64 exec, vcc, s_cselect_b64 vcc, 1, 0 into a
saveexec, or v_cndmask with that VCC passed the EXEC check while 64 vs 2x32
results differ. Taint such a constant (other than 0 / -1) with LANE when the
destination is a mask right after the write, and stop accepting 0xffffffff
(the low 32 lanes) as a safe operand of a mask op.
@paratustra

Copy link
Copy Markdown
Contributor Author

Pushed 49ff53b6, which closes a hole in this PR's own check that I found by probing it further. lane_masks tracks VCC, or a pair, written from a constant as a lane mask. is_mask() therefore accepted it as an EXEC source, and these were still tier A with different 64 vs 2×32 results:

listing lanes that differ
s_mov_b64 vcc, 1 then s_mov_b64 exec, vcc 1
s_or_b64 vcc, 0, 1 then s_mov_b64 exec, vcc 1
s_cselect_b64 vcc, 1, 0 then s_and_saveexec_b64 …, vcc 1
v_cmp…vcc then s_and_b64 vcc, vcc, 0xffffffff then s_and_b64 exec, exec, vcc 32
s_mov_b64 vcc, 1 then v_cndmask_b32_e32 v6, 7, v0, vcc (A on main too) 1

The fix has two parts:

  • A 64-bit constant other than 0 / −1, written by a mask op, s_cselect or s_bfm, gets the LANE taint when its destination is a lane mask right after the write (defines_mask, from lane_masks' state there). A constant pair that is no mask, such as s_mov_b64 s[16:17], 0x1234 read as data, stays A.
  • 0xffffffff (the low 32 lanes) is no longer accepted as a safe operand of a mask op.

The new test_c_constant_lane_mask_through_vcc covers the five listings above and the data-pair control. Its 5 C subtests fail at the previous head dc2a5ea7. The test_wave64_halves*.py files pass. tests/semantic (3.12) fails the same 2 files as main, and the fixture tests are unchanged (35 passed, 1 skipped).

AI-assisted.

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.

8 participants