Skip to content

rdna2spirv, lane_masks: support null/exec/wave32-vcc_hi compare SDSTs and wave32 vcc_hi masks - #8448

Open
Vadson159 wants to merge 1 commit into
ItsNotRexed:mainfrom
Vadson159:shader/vcmp-dst-wave32-vcchi
Open

Vadson159 wants to merge 1 commit into
ItsNotRexed:mainfrom
Vadson159:shader/vcmp-dst-wave32-vcchi

Conversation

@Vadson159

Copy link
Copy Markdown
Contributor

Claimed on #8186: #8186 (comment)

Problem

  1. v_cmp_*_e64 and v_cmp_class_f64_e64 rejected null, exec/exec_lo, and wave32 vcc_hi SDSTs:
    On RDNA2 (gfx1013), llvm-mc accepts null (0x7d), exec_lo (wave32, 0x7e) / exec (wave64, 0x7e), and wave32 vcc_hi (0x6b) as scalar destinations on VOPC/VOP3 compare and class instructions. While 64-bit integer compares (v_cmp_*_u64/i64) and v_cmp_class_f32/f16 already delegated their destinations to Gen.mask_dst, Gen.compare (f64 branch), Gen.write_compare_result (f32, f16, u16, i16, u32, i32, and constant f/t/tru 64-bit compares), and Gen.cmp_class_f64 only accepted vcc/vcc_lo and sgpr, raising Unsupported on null, exec/exec_lo, and wave32 vcc_hi.
  2. Wave32 vcc_hi was not tracked or lowered as an independent 32-bit scalar/mask register:
    In wave32 (not wave64), vcc_lo is VCC[31:0] (%vcc) and vcc_hi (0x6b) is an independent 32-bit scalar/mask register (%vcc_hi). Previously:
    • tools/lane_masks.py (kind, put, step) always treated vcc_hi as the upper half of state["vcc"], so writing plain scalar data to vcc_hi in wave32 cleared state["vcc"] (vcc_lo), and writing a mask to vcc_hi overwrote state["vcc"] instead of tracking "vcc_hi".
    • Gen.mask_dst rejected vcc_hi in wave32 with Unsupported("mask destination").
    • Gen.holds_lane_mask returned False for vcc_hi in wave32, Gen.mask_half returned "hi" for vcc_hi in wave32, and Gen.mask_src unconditionally emitted OpLoad %uint %vcc (vcc_lo) when reading vcc_hi as a mask operand (v_cndmask_b32_e64, v_add_co_ci_u32_e64, s_bcnt1_i32_b32, etc.).

Fix

  • tools/lane_masks.py:
    • Thread wave64=True through kind() and put() from step(). When not wave64, track vcc_hi under its own "vcc_hi" key and vcc_lo under "vcc", while keeping existing wave64 half-VCC behavior unchanged.
  • tools/rdna2spirv.py:
    • Route Gen.compare (f64 branch), Gen.write_compare_result, Gen.cmp_class, Gen.cmp_class_f64 (validated via Gen.is_mask_dst), and 64-bit integer compare destinations through Gen.mask_dst.
    • In Gen.mask_dst: accept vcc_hi when not self.wave64 (OpStore %vcc_hi), and use self.exec_half_write if self.wave64 and d["t"] in ("exec_lo", "exec_hi"). Malformed VGPR/immediate destinations and wave64 vcc_hi compare destinations continue to raise Unsupported.
    • In Gen.holds_lane_mask, Gen.mask_half (None when not self.wave64), Gen.wave_mask, Gen.wqm, and Gen.mask_src (sharing Gen._scalar_word_lane_bit): load %vcc_hi directly when wave32 vcc_hi holds a tracked lane mask, and extract bit lane & 31 when %vcc_hi holds plain scalar data.
  • docs/design.md:
    • Add the contract table row "Compare SDST (null, exec/exec_lo) and wave32 vcc_hi lane masks" with confirmation methods and scope.
  • tests/test_lane_masks.py & tests/semantic/test_vcmp_dst_wave32_vcchi.py:
    • Unit tests in test_lane_masks.py (test_wave32_vcc_hi_isolation) covering wave32 vcc_hi/vcc_lo isolation, mask producers (v_cmp, v_add_co_u32, v_mad_u64_u32, s_and_saveexec_b32, s_wqm_b32), CFG joins, and wave64 preservation.
    • End-to-end semantic interpreter (spirv_mini_interp, spirv_wave_interp) and spirv-val --target-env vulkan1.2 tests in tests/semantic/test_vcmp_dst_wave32_vcchi.py across 12 compare/class families (null and exec_lo/exec in wave32, wave64 native, and --wave64-emulate), 9 wave32 vcc_hi mask producers + consumers, plain-data vcc_hi reads, and negative controls.

Verification

Tested on Windows 11, Python 3.14.6 (python -I), LLVM llvm-mc 21.1.8, Vulkan SDK spirv-as / spirv-val (Vulkan 1.2), and runtime/build/vk_compute_test.exe on AMD Radeon(TM) Graphics (gfx1036, driver 32.0.21045.29003) and AMD Radeon RX 9070 XT (driver 32.0.32029.2010). No game files used.

  • python -m compileall -q make_game.py tools tests — pass (exit 0)
  • python -I tests/test_lane_masks.py — pass (ok)
  • python -I tests/test_semantic_translator_use.py — pass (3/3)
  • python -I tests/test_design_contract_rows.py — pass (4/4)
  • python -I tests/test_runner_calls_all_tests.py — pass (3/3)
  • python -I tests/semantic/test_vcmp_dst_wave32_vcchi.py -v — pass (7/7)
  • python -I tests/semantic/test_wave64_vcc_half_write.py — pass (7/7)
  • python -I tests/semantic/test_cmp_class_f64.py — pass (6/6)
  • python -I tests/semantic/test_carry_exec_mask.py — pass (9/9)
  • python -I tests/semantic/test_salu_b32_lane_masks.py — pass (8/8)
  • python -I tools/cf_diff.py --programs 20 — 40 pass, 0 mismatch
  • python -I tools/salu_diff.py --programs 20 — 20 pass, 0 mismatch
  • python -I scripts/check_no_game_data.py --diff main — pass (exit 0)
  • python -I scripts/run_semantic_tests.py tests/semantic — 445/448 files passed (5,963 tests total); the 3 failing files (test_image_atomics_guard, test_image_cube_store_glc, test_image_store_d16) fail identically on unmodified main (dde82f27e).
  • Vulkan GPU execution (vk_compute_test.exe on AMD Radeon(TM) Graphics gfx1036 and AMD Radeon RX 9070 XT): wave32 (vcc_hi compare/mask/data + null + exec_lo) and wave64 (native --require-wave64 and --wave64-emulate f64/class_f64 null + exec) all passed with 0 mismatches.

AI-assisted.

@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 (08906660144d2d6c17e3be977759dc233beffec7):

  • python -I tests/test_lane_masks.py: passed (ok).
  • python -I -m unittest discover -s tests/semantic -p test_vcmp_dst_wave32_vcchi.py -v: passed (7/7 tests OK).
    • test_exec_destination_narrows_exec_without_clobbering_vcc
    • test_negative_controls_invalid_compare_destinations
    • test_null_destination_preserves_vcc_and_exec
    • test_wave32_vcc_hi_mask_producers_and_consumers_isolate_vcc_lo
    • test_wave32_vcc_hi_overwrite_data_and_cmp_with_vcc_lo
    • test_wave32_vcc_hi_plain_data_scalar_and_mask_reads_preserve_vcc_lo
    • test_wave64_emulate_null_and_exec_destinations_validate
  • python -I tests/test_design_contract_rows.py: 4/4 passed.
  • python -I tests/test_runner_calls_all_tests.py: 3/3 passed.
  • python -I tests/test_semantic_translator_use.py: 3/3 passed.

Negative control (discrimination check)

Checking out origin/main for tools/rdna2spirv.py and tools/lane_masks.py against the new tests:

  • tests/test_lane_masks.py failed with AssertionError in test_wave32_vcc_hi_isolation:
    assert m_data_hi == {"vcc": L.MASK}
    AssertionError
    
    confirming that on main, wave32 vcc_hi writes clobber vcc_lo state rather than maintaining independent register tracking.
  • tests/semantic/test_vcmp_dst_wave32_vcchi.py failed with 71 errors across the compare and class subcases:
    rdna2spirv.Unsupported: v_cmp destination
    rdna2spirv.Unsupported: v_cmp_class_f64 destination
    
    confirming main rejected null, exec/exec_lo, and wave32 vcc_hi SDSTs.

Repository hygiene

  • python -I scripts/check_no_game_data.py --diff origin/main: passed.
  • python -m compileall -q tools/rdna2spirv.py tools/lane_masks.py tests/test_lane_masks.py tests/semantic/test_vcmp_dst_wave32_vcchi.py: passed.
  • git diff --check origin/main: clean.

LGTM!

@molodayamama

Copy link
Copy Markdown

Verified commit 47494e72548447eb23c0326cd20e919dfce577ad. All seven compare-destination semantic tests passed on Windows, and the standalone lane-mask check also passed. The synthetic cases exercise the wave32 VCC_HI and alternate compare-destination paths without requiring a native GPU.

AI-assisted verification.

@morodirule

Copy link
Copy Markdown

Tested 47494e7 on Arch Linux, Python 3. pesticide: SKIPPED

@morodirule

Copy link
Copy Markdown

Correction to my previous comment on this PR, which was garbled — please disregard it. Real result: Tested 47494e7 on Arch Linux, Python 3.14.10, CPU only: pass. New tests/semantic/test_vcmp_dst_wave32_vcchi.py 7/7 OK + test_lane_masks 38/38 OK (via discover runner; the file needs the tests/semantic path). Negative control: base translator errors on all 7 new subtests; restored, green again. No game files. AI-assisted.

@edubox

edubox commented Nov 23, 2026

Copy link
Copy Markdown

Independent run of the CPU side of 47494e7254 on Linux (CachyOS), CPython 3.14.10, LLVM 23.1.5, SPIRV-Tools 2026.4 — the same suites the PR lists for Windows:

  • tests/test_lane_masks.py: pass.
  • tests/semantic/test_vcmp_dst_wave32_vcchi.py: 7/7.
  • tests/semantic/test_wave64_vcc_half_write.py: 7/7.
  • tests/semantic/test_cmp_class_f64.py: 6/6.
  • tests/semantic/test_carry_exec_mask.py: 9/9.
  • tests/semantic/test_salu_b32_lane_masks.py: 8/8.
  • tests/test_design_contract_rows.py: 4/4.
  • tools/cf_diff.py --programs 20: 40 pass, 0 mismatch, 0 harness errors.
  • tools/salu_diff.py --programs 20: 20 pass, 0 mismatch.

Negative control: restoring tools/lane_masks.py from origin/main e0f40f47 while keeping the new test makes test_vcmp_dst_wave32_vcchi.py fail 9 cases, so the test does bite on the change; restored afterwards.

Not run: the Vulkan part. I have an RTX 4080 SUPER (NVIDIA 620.73.04, so --wave64-emulate on 32-wide subgroups) and a gfx1036 RADV iGPU (Mesa 26.3.1, native wave64), but the PR adds no fixture and names no --filter, so I cannot tell which vk_compute_test shaders produced the AMD results. If you name the fixtures/commands, I can run them on both GPUs.

AI-assisted.

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

Two real defects remain.

  1. A valid wave32 vcc_hi bitwise mask is still treated as data. tools/rdna2spirv.py:5579-5580 _mask_b32_dst_half returns a mask destination only for exec_lo, vcc_lo, exec and vcc in wave32; vcc_hi is missing, so sop2_b32_srcs (:5620-5624) falls back to raw src_u and _store_b32_mask_dst (:5604-5611) stores the raw constant word instead of a per-lane 0/~0 mask. tools/lane_masks.py:233-251 likewise has only a wave64 dst_t == "vcc_hi" branch (:247), so wave32 drops vcc_hi from the mask state. With vcc_lo = 0x00100000 (lane 20) and s_and_b32 vcc_hi, vcc_lo, 0xFFFF, hardware gives a zero mask, but the raw 0xFFFF makes mask_src (:5991-5994, _scalar_word_lane_bit) inspect bit 20 & 31 = 4 and enable lane 20. v_cndmask_b32_e64, s_bcnt1_i32_b32 and v_mbcnt_lo_u32_b32 then read the wrong mask. Include vcc_hi in the wave32 mask destination and have lane_masks.step put MASK for it.

Test gap: tests/test_lane_masks.py:341-350 lists the wave32 producers but no s_and_b32/s_or_b32/s_cselect_b32 into vcc_hi; tests/semantic/test_vcmp_dst_wave32_vcchi.py:273-320 has no bitwise producer and its vcc_lo is lane 7 only, hiding the high-lane raw-word bug. Add a s_and_b32 vcc_hi, vcc_lo, 0xFFFF case with a lane ≥ 16 (or a unit assertion that vcc_hi is MASK).

  1. exec_hi compare SDSTs are accepted by ordinary compares but rejected by cmp_class_f64. Gen.mask_dst now accepts wave64 exec_hi via exec_half_write (:6098-6101), but the only validator Gen.is_mask_dst (:6087-6096) excludes exec_hi and is used only by cmp_class_f64 (:4367). write_compare_result (:1852), cmp_class f32/f16 (:4348) and the 64-bit ordered/equality paths (:8244, :9033) call mask_dst without it, so v_cmp_lt_f32/f64, v_cmp_eq_u64 and v_cmp_class_f32 with exec_hi translate, while v_cmp_class_f64 raises. The negative test only covers class_f64 (tests/semantic/test_vcmp_dst_wave32_vcchi.py:471-486, line 480). The docs (docs/design.md:497) list null, exec_lo/exec and wave32 vcc_hi, not exec_hi; if exec_hi is invalid, the ordinary paths are wrong; if valid, the class_f64 test is wrong. Make one rule apply to all compare/class families and test the ordinary ones; v_cmp_class_f32/f16 are untested.

Synthetic only; no game files. AI-assisted (OpenCode).

@N4use4tic

Copy link
Copy Markdown

Tested 47494e7 on Windows 11, Python 3.14.4, no GPU or LLVM: pass.
From tests/semantic: test_vcmp_dst_wave32_vcchi (7 tests), test_wave32_bfm64_data (6) and test_wave64_subgroup_ops (6) OK; tests/test_lane_masks.py ok.
test_image_atomics_guard and test_image_store_d16 are still red, as on main (#7284), not caused by this PR.
Note: this PR conflicts with #8264 (1 conflict; found with git merge-tree).
Code not reviewed beyond the test run.

@Marukooh

Copy link
Copy Markdown
Contributor

Local integration test of #8448 at 47494e7 together with #6446 at fb40ed3, on top of the same #7529 library extraction. The two semantic fixtures passed (7 cases each). Across the full library, all 2,492 translated modules passed spirv-val, up from 1,773. The combined result covers 492 of 524 distinct compute lookups missing in the original boot run, up from 429.

On the same Wine 11.22 runtime and RTX 5070 Ti (NVIDIA 620.73.04), comparing the first 1,000 successful PresentX calls, distinct FSPX compute misses dropped from 36 to 8. There were still 4 CreatePipelineState failures and the presenter remained hidden. The counts describe the combined integration, so they cannot be attributed to either PR individually.

AI-assisted verification. No game files, shaders, identifiers or traces attached.

@hah346

hah346 commented Nov 23, 2026

Copy link
Copy Markdown

Independent check of the exact translator changes from 47494e7 (applied on top of e5658e4) on Windows build 26300, RTX 2060 driver 616.64, SPIRV-Tools 2026.4.

All seven new semantic tests and the lane_masks suite passed. I also dispatched three synthetic compute modules on Vulkan with validation enabled: wave32 vcc_hi compare/consume while keeping vcc_lo distinct and discarding a null compare (32/32 expected lane results), wave32 exec_lo compare (32/32, lanes after 12 untouched), and emulated wave64 exec compare (64/64, lanes after 32 untouched). The unmodified base refused all three at v_cmp destination. No validation errors in the GPU runs.

I retested the 2,128 graphics-library programs rejected by the baseline VS/PS offline pass, same disassembly and flags. None translated after this change. At aggregate level the former 161 v_cmp destination and 83 mask destination refusals are now 244 mask destination refusals. All four output parts were empty; the merge guard correctly declined to publish an empty index. This was a targeted retry of previous failures, so it gives no regression count for previously successful modules or boot coverage. AI-assisted. Counts and synthetic cases only.

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.

9 participants