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.

…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

@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"].

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