Skip to content

wave64_halves: preserve destination taint on partial writes and reject asymmetric DPP row_mask - #4373

Open
kotekompotek wants to merge 1 commit into
ItsNotRexed:mainfrom
kotekompotek:contribution/wave64-halves-partial-dst-rmw
Open

kotekompotek wants to merge 1 commit into
ItsNotRexed:mainfrom
kotekompotek:contribution/wave64-halves-partial-dst-rmw

Conversation

@kotekompotek

Copy link
Copy Markdown

Claimed in the coordination issue as: #4257 (comment)

What and why

AI-assisted contribution (CPU-verified locally on Windows 10 Pro / Python 3.12.6; synthetic shaders only, no game data).

Fixes missing destination-read tracking for partial-destination writes and half-asymmetric DPP row_mask handling in tools/wave64_halves.py:

  1. Prevent dropped taint and false uniform_readlane miscompilation: operands(ins) previously included a[0] in srcs only for RMW_DEST. As a result, a partial overwrite of a divergent VGPR with scalar/immediate sources dropped prior taint and marked the destination VGPR uniform (st["u"]), causing rdna2spirv.py to replace v_readlane_b32 with per-lane reads. _preserves_dst() now includes a[0] in srcs (keeping implicit-vcc length checks intact) for:
    • "v_fmac_legacy_f32" (RMW_DEST);
    • SDWA dst_unused:UNUSED_PRESERVE with dst_sel != DWORD (while dst_sel:DWORD stays full-write);
    • Single-half 16-bit VALU ops (including 8-byte VOP3 _INT16_VOP2_OPS without _e64, _nc_16, and v_interp_p2_f16, excluding 32-bit packed/compare/v_interp_p1*/up-conversion ops);
    • Partial-lane DPP (row_mask != 0xf, bank_mask != 0xf, or bound_ctrl:0 on non-dpp8:);
    • Odd/single-half d16 loads (global_*_d16*, ds_read_*_d16*, buffer_load_format_d16_{x,xyz}, odd-dmask d16 image loads/samples).
  2. DPP half-asymmetry & dpp8:: transfer() now also routes dpp8: through the DPP handler and marks half-asymmetric row_mask ((row_mask & 3) != (row_mask >> 2)) as tier C cross-lane because rows 0..1 execute on both 32-lane halves while rows 2..3 are ignored by half 1.

Checked open PRs #2469 and #4138: changes are confined to RMW_DEST, _preserves_dst/operands(), and the DPP transfer() check, avoiding overlap, and rebased cleanly on main.

Tested

CPU-only (Windows 10 Pro x64, Python 3.12.6; no llvm-mc, spirv-as/spirv-val, Windows SDK 10.0.26100, or GPU runtime build available locally):

  • Pre-fix reproduction: 3 clean-control tests in tests/semantic/test_wave64_halves_partial_dst.py passed (ok), all 10 regression tests failed (failures=10), including live spirv_wave_interp.py divergence + readlane-uniform miscompilation.
  • Post-rebase & post-fix (47b43d81 on 03b09a08):
    • python -I tests/semantic/test_wave64_halves_partial_dst.py -v -> Ran 13 tests in 4.297s OK
    • python -I tests/semantic/test_wave64_halves_soundness.py -v -> Ran 30 tests in 4.643s OK
    • python -I tests/semantic/test_wave64_halves.py -v -> Ran 73 tests in 6.081s OK
    • python tests/semantic/test_wave64_cross_half.py -v -> Ran 9 tests in 9.035s OK
    • python tests/semantic/test_wave64_subgroup_ops.py -v -> Ran 6 tests in 12.487s OK
    • python -m pytest tests/test_wave64_halves_fixtures.py tests/test_wave64_graphics_scan.py -q -> 25 passed, 1 skipped in 1.08s (no fixture tier changes)
    • tests/test_docs_design_rows.py (2 OK), test_docs_repo_paths.py (2 OK), test_docs_links.py (6 OK), test_docs_list_items.py (2 OK), test_text_write_line_endings.py (3 OK), test_resource_hygiene.py (2 OK), compileall, git diff --check -> all passed.

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.

@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 47b43d81 on Windows 11: tests/semantic/test_wave64_halves_partial_dst.py -> 13 tests, OK; tests/test_wave64_halves_fixtures.py -> 9 passed; compileall and git diff --check clean.

The analysis now preserves destination taint across partial writes and rejects an asymmetric DPP row_mask; the new cases cover both, and the fixture tests still pass. No blocking issue.

@2-CD

2-CD commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

AMD + 32-wide GPU check: AMD Radeon 610M iGPU (Ryzen 9 9950X3D, driver 32.0.13018.6, RDNA2-class, wave32 subgroups 32..64), Windows 11, MSVC (VS BuildTools 18) + Ninja, RelWithDebInfo, llvm-mc 21.1.8 (gfx1013), spirv-as/spirv-val. Tested head 47b43d81 (base 03b09a08).

This PR changes only tools/wave64_halves.py + a semantic test + docs - no C++ and no ctest test, so the ctest suite is unchanged from base. The wave64_halves tool drives wave64 emulation on a 32-wide device, which is what the iGPU exercises.

Semantic (CPU):

  • New tests/semantic/test_wave64_halves_partial_dst.py: 13 tests OK.
  • Existing wave64 semantic regression (-p *wave64*): 177 tests OK.

GPU wave64 fixtures emulated on the 32-wide RDNA2 iGPU (scripts/run_gpu_tests.py --filter w64, LEONIDA_VK_DEVICE=Radeon): 25/26 PASS, 1 expected SKIP.

  • The skip is ps_w64x_readlane: "this device cannot require a 64-wide fragment subgroup (subgroup 32..64)" - a pixel shader needing a 64-wide fragment subgroup, which a 32-wide device can't require. All compute/mesh wave64 fixtures (dpp, ballot, bpermute, readlane/writelane, partial writes incl. cs_w64x_partial/cs_w64x_partial_scmp, saveexec_b64, barriers) pass exact.
  • The destination-taint-on-partial-writes and asymmetric DPP row_mask behaviour this PR fixes is exercised by cs_w64x_partial* and cs_dpp_w64, all exact on the RDNA2 iGPU.

Synthetic fixtures only, no game files. AI-assisted (opencode); runs on my machine.

@sperm

sperm commented Nov 23, 2026

Copy link
Copy Markdown

Tested 47b43d8 on AMD Radeon RX 9070 XT (RADV GFX1201, wave32/64) and the Ryzen 7 9800X3D iGPU (RADV RAPHAEL_MENDOCINO, gfx1036, RDNA2), Mesa 26.2.6, Linux 7.3.4: pass, no regressions.

No game files. AI-assisted.

@shdann

shdann commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

AI-assisted review (Claude Code). I used no game files. All listings are hand-written.

Head 47b43d81. Windows 11, Python 3.14.7, CPU wave interpreter only (no GPU, no llvm-mc).

What I ran

  • tests/semantic/test_wave64_halves_partial_dst.py (13 tests), test_wave64_halves.py (73) and test_wave64_halves_soundness.py (30): all pass.
  • pytest on tests/test_wave64_halves_fixtures.py, the two test_w64_graphics_* files, test_wave64_graphics_scan.py and the docs row tests: 45 passed, 1 skipped (it needs llvm-mc).
  • Negative control: the new test file with the analyser of main d0835dd9 gives 10 failures.
  • This head merged with wave64_halves: a vote on a wave-uniform compare is not a lane vote (new SHADER item) #4138 in a local tree (one text conflict in tools/wave64_halves.py, the two blocks are independent): test_wave64_halves.py 83 OK, test_wave64_halves_partial_dst.py 13 OK.

Result: pass for the rule in the title. This pull request moves no pattern to tier A or B.

It also closes a defect of #4138. At the head of #4138 (9c7a8619), a VGPR that gets a part of its bits from a scalar counts as wave-uniform, and a vote on it becomes tier A although the two runs differ. Two examples: v_mov_b32_sdwa v1, s4 dst_sel:BYTE_0 dst_unused:UNUSED_PRESERVE src0_sel:DWORD after v_lshlrev_b32_e32 v1, 8, v0, and v_add_u16_e64 v1, 1, s4 after v_lshlrev_b32_e32 v1, 16, v0. With this pull request merged in, the two examples are tier C again. Thus #4373 must merge before #4138. The steps are in my review of #4138.

One class of partial write that stays open. A VGPR write under a narrowed EXEC writes only the lanes that are on. put() replaces the taint and the tags of the full register. This is tier A on main also, so this pull request does not cause it.

v_mbcnt_lo_u32_b32 v6, -1, 0
v_mbcnt_hi_u32_b32 v6, -1, v6         ; v6 = lane id (taint lane-id)
v_cmp_eq_u32_e32 vcc, 1, v0           ; v0 = lane number
s_and_saveexec_b64 s[12:13], vcc
v_mov_b32_e32 v6, 0                   ; lane 1 only; the analyser clears the taint of v6
s_or_b64 exec, exec, s[12:13]
; v6 is exported

Tier A with no reasons. One 64-lane wave exports 32 in lane 32. Two 32-lane waves export 0 (32 lanes differ). The same occurs with a v_readlane_b32 result (5 against 37 in lane 32), with an s_bcnt1_i32_b64 count (64 against 32, 63 lanes differ), and with the "equal modulo 32" tag of a lane id that goes into a ds_bpermute_b32 address (31 lanes differ). It is reported as a finding: in the coordination issue, because it is larger than this pull request. If you prefer to include it here: when EXEC is not the launch mask (st["f"] is false), a VGPR destination keeps its old taint, and loses its tag and its place in st["u"].

shdann added a commit to shdann/Leonida that referenced this pull request Nov 23, 2026
main now has ItsNotRexed#2469 and ItsNotRexed#2674 in tools/wave64_halves.py and a memory in tests/semantic/spirv_wave_interp.py
(TEST-722), so:

- tools/wave64_halves.py: both sides kept (mem_writes next to pure_spill_vgprs; uniform_load after the
  scaled lane-count tag).
- tests/semantic/spirv_wave_interp.py: main's memory replaces the read-only memory of this branch. One
  correction: main has the PhysicalStorageBuffer branch of OpLoad inside OpAccessChain, behind a return, so
  a load through such a pointer raises IndexError. The branch is moved to OpLoad.
- tests/semantic/test_spirv_wave_interp.py: main's file, plus MemoryLoad (3 tests; 2 of them raise
  IndexError with main's interpreter).
- tests/semantic/test_wave64_uniform_load.py: each wave gets its own copy of the memory.
- docs/design.md: main's SHADER-10 row, with the sentence of ItsNotRexed#4373 and the text of this branch put back.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@465d6a0eac

Copy link
Copy Markdown
Contributor

Census (TEST-1006) of 47b43d81: no tier moves; 6 PS that were already tier C gain cross-lane.

Setup. This head conflicts with today's main, so I compared it with its merge base d0835dd9, from my own 1.0.2.1 copy, counts only. Native mode: halves_analysis returns early under --wave64-emulate. The run covers the 13,405 wave64 VS/PS/GS, picked by the FSSM wave-size flag and the carve-index stage. WSL Ubuntu, Python 3.14.4, llvm-mc 21.1.8, SPIRV-Tools v2026.1, CPU only. On both sides 13,401 pass spirv-val, and the .spv files are byte-identical. The 4 that fail are SHADER-718's %fmt_size_arr, the same 4 at both commits, and already fixed on main. On d0835dd9, --census gives A 4,033 / B 85 / C 9,283. Today's main has #2674, so a rebase will change the base numbers.

At the head the tiers are the same A 4,033 / B 85 / C 9,283, with all per-stage counts equal. 6 PS that were already
tier C gain cross-lane, nothing is lost, and tier C cross-lane goes from 4,764 to 4,770.

AI-assisted (Claude Code). Part of TEST-1006 on the coordination issue.

@bobcatchris

Copy link
Copy Markdown
Contributor

Tested d18c968c82500c3cec248c0fa092733ebef488d4 on AMD Radeon Pro V540 (Navi 12; tools/hw_oracle reports gfx1011), RADV Mesa 25.2.8-0ubuntu0.24.04.4, Ubuntu 24.04.4, kernel 7.0.0-31-generic, Vulkan 1.4.318, subgroup 32..64. Cards pinned with DRI_PRIME=pci-0000_1c:00.0! and pci-0000_1f:00.0!, one process each. Adds the missing RDNA1 data point to the RDNA2 (gfx1036) and RDNA4 (gfx1201) results, and re-checks the current head (earlier comments were at 47b43d81).

  • python3 -I scripts/run_gpu_tests.py --build runtime/build/linux: 188/217 passed, 27 skipped, 2 failed on both cards (221 shaders translated, 221 pass spirv-val), identical to the PR's base 3faac557 with the same toolchain; no regression. The two failures (cs_signed_zero_nan, cs_w32_salu64) are pre-existing with identical words on base.
  • pytest -q tests/semantic/test_wave64_halves_partial_dst.py: 13 passed.
  • Toolchain: Khronos Vulkan-Headers 1.4.335 locally (-DVulkan_INCLUDE_DIR=...), GCC 13.3.0, llvm-mc 21.1.8, SPIRV-Tools 2026.1.

Counts and pass/fail only; no game data. No code changes.

AI-assisted.

@thesubtleties

Copy link
Copy Markdown

Tested d18c968c on both halves, CachyOS Linux 7.3.5, LLVM 23.1.5: pass, no regressions.

Test programs rebuilt from the PR head; compared against main 3faac557 on the same machine. No game files. AI-assisted (Claude Code).

…t asymmetric DPP row_mask

Fixes partial-destination writes in tools/wave64_halves.py that dropped prior taint and falsely marked divergent VGPRs uniform (miscompiling v_readlane_b32 in rdna2spirv.py):
- Track destination read in operands() for SDWA dst_unused:UNUSED_PRESERVE with sub-dword dst_sel, single-half 16-bit VALU ops (including 8-byte VOP3 / _nc_16 / v_interp_p2_f16), partial-lane DPP (row_mask/bank_mask != 0xf or bound_ctrl:0), v_fmac_legacy_f32, and partial d16 loads.
- Flag half-asymmetric DPP row_mask ((row_mask & 3) != (row_mask >> 2)) and dpp8 in transfer().

Verified locally (CPU-only):
- tests/semantic/test_wave64_halves_partial_dst.py (13 OK)
- tests/semantic/test_wave64_halves_soundness.py (30 OK)
- tests/semantic/test_wave64_halves.py (73 OK)
- tests/semantic/test_wave64_cross_half.py (9 OK)
- tests/semantic/test_wave64_subgroup_ops.py (6 OK)
- pytest tests/test_wave64_halves_fixtures.py tests/test_wave64_graphics_scan.py (25 passed, 1 skipped)
- docs, line-ending, resource hygiene, tool startup, compileall, git diff --check

# Conflicts:
#	docs/design.md

# Conflicts:
#	tools/wave64_halves.py
@nicknickalive

Copy link
Copy Markdown

Tested ad1e53e (trial-merged onto main 561b65a) on NVIDIA GeForce RTX 5090 (610.88, subgroup 32..32) and AMD Radeon iGPU (RDNA2, AMD 32.0.21036.18, subgroup 32..64), Windows 11 Pro 26200: pass.

  • pytest test_wave64_halves_partial_dst.py: 13 passed
  • tools-only; no GPU test changed.

No game files. AI-assisted.

@JRamos1993

Copy link
Copy Markdown
Contributor

Tested ad1e53e4 merged onto main 561b65a8 on Windows 11, CPython 3.14.3, CPU only: pass.

  • python -I -m unittest discover -s tests/semantic -p test_wave64_halves_partial_dst.py: 13 tests OK.
  • Negative control (tools/wave64_halves.py from main, the PR's tests kept): tests/semantic/test_wave64_halves_partial_dst.py 13 tests FAILED (failures=8).
  • py_compile on the 2 changed Python files: OK; git diff --check: clean.

No game files. AI-assisted (Claude Code).

@lunarminus

Copy link
Copy Markdown

Tested ad1e53e4 merged onto main d0835dd9 on an AMD Radeon 760M (RDNA3 iGPU, gfx1103, subgroup 32..64), RADV Mesa 26.3.1, CachyOS Linux: pass

The merge is a fast-forward because the head already sits on main 561b65a8, so the tree tested is ad1e53e4 itself. runtime/ and scripts/ are identical to 561b65a8, so I used the test programs built at 561b65a8.

  • python -I tests/semantic/test_wave64_halves_partial_dst.py -v: 13 tests OK.
  • python -m unittest discover -s tests/semantic -p '*wave64*': 244 tests OK.
  • pytest tests/test_wave64_halves_fixtures.py tests/test_wave64_graphics_scan.py (AMDGPU clang/llvm-mc 23.1.5): 28 passed.
  • python -I scripts/run_gpu_tests.py --build runtime/build/linux, once without and once with LEONIDA_W64_EMULATE=1 (device AMD Radeon 760M Graphics (RADV PHOENIX)):
    • 238/238 shaders translated and pass spirv-val.
    • 216/232 passed, 16 skipped, 0 failed in both modes.
  • Per-test comparison:
    • Against main 561b65a8 without the PR, every test's PASS/FAIL/SKIP word is identical in both modes (232/232).
    • Against d0835dd9 (196/210, 14 skipped), no shared test changed result. The 22 extra tests (20 pass, 2 skip) come from main after d0835dd9.
    • The PR adds no GPU fixture.
  • run_gpu_tests.py --filter w64 (the AMD 32-wide check from the earlier comment) gave 26/26 passed in both modes, the same per test as on 561b65a8.
    • cs_w64x_partial, cs_w64x_partial_scmp and cs_dpp_w64 pass.
    • ps_w64x_readlane runs here and reports 4096/4096 pixels exact.

No game files. AI-assisted (Claude Code).

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.