Skip to content

Keep the permlane FI/BOUND_CTRL subgroup operations convergent on MoltenVK (fixes #5895) - #6322

Open
autowert66 wants to merge 1 commit into
ItsNotRexed:mainfrom
autowert66:fix-permlane-fi
Open

autowert66 wants to merge 1 commit into
ItsNotRexed:mainfrom
autowert66:fix-permlane-fi

Conversation

@autowert66

Copy link
Copy Markdown

Fixes #5895. Claim: #6089 (comment)

Problem. The FI=0 / BOUND_CTRL handling of v_permlane16_b32 / v_permlanex16_b32 (SHADER-74, 71d8f8685) applied its result with a scalar OpSelect — first ok ? value : old-or-zero, then dst()'s active ? … : old. MoltenVK's SPIRV-Cross lowers scalar selects to short-circuiting Metal ternaries, moving the ballot and both shuffles into divergent control flow; the value arm then wins, and the FI=0 lanes read the off source lane's value instead of keeping the old one (or zero). Measured on Apple M1 Max / MoltenVK 1.4.2, and on a fresh MoltenVK main build at SPIRV-Cross aa217aeb — which includes all four revisions docs/testing.md cites for the other MoltenVK fixes, among them 5c372ffb "control dependent expressions don't end up in a ternary": cs_w32_permlane_fi fails with out[0..7] = 4 4 4 1 52 52 52 49, want 1000 0 4 1 1000 0 52 49. KosmicKrisp and the CPU model pass. It is the same driver shape #932 fixed for ds_bpermute.

Change. The FI=0 path on a native subgroup now redirects absent source lanes to the calling lane (as ds_lane_read does), fetches the value and the source lane's activity bit through the redirected index, and combines with bitwise masks — ok ? value : old becomes value & mask | old & ~mask, ok ? value : 0 becomes value & mask — and the destination write uses dst()'s eager masks, so the ballot and both shuffles run before lane predication. FI=1 and --wave64-emulate are unchanged (no subgroup op reaches MSL from the emulated path; its tests pin that).

Verification, Apple M1 Max (32-core GPU), macOS 27.2.1, llvm-mc 23.1.6, SPIRV-Tools v2026.4:

run before after
cs_w32_permlane_fi, MoltenVK 1.4.2 FAIL 4 4 4 1 52 52 52 49 PASS 1000 0 4 1 1000 0 52 49
cs_w32_permlane_fi, MoltenVK main @ SPIRV-Cross aa217aeb FAIL, same words PASS, same words
cs_w32_permlane_fi, KosmicKrisp (Homebrew mesa 26.3.1) PASS PASS (unchanged)
tests/semantic/test_valu_permlane16.py, test_permlane_fi.py pass pass (16/16; the mask negative controls re-expressed: forcing the ok-mask on reproduces the MoltenVK symptom)
full tests/semantic discover pass pass — 6150 tests OK (1 suite-inherent skip, 1 expected failure)
full run_gpu_tests.py, MoltenVK 1.4.2, main 561b65a83 + this change 165/232, 8 failed 166/232, 7 failed — only the documented set remains (cs_fma_fused, ps_ssharp, the five ps_vcmp*); no other test changed
full run_gpu_tests.py, KosmicKrisp 166/232, 4 failed (the #3125 NaN family) 166/232, the same 4 (cs_bvh, cs_bvh32, ps_cndmask_sign_mods, ps_valu16_mad_sel) — unchanged
crosslane_fuzz.py, seed 1, 50 programs, wave32 native, MoltenVK 1.4.2, standard model 36 match / 10 hypothesis-only / 4 mismatch 43 match / 3 hypothesis-only / 4 mismatch — the seven newly matching programs are the FI=0 permlane ones; the four mismatches are the same non-permlane programs before and after. With --permlane-fetch-inactive (which models the off-lane fetch as FI=1) the fixed GPU now correctly diverges from that model

AI-assisted (OpenCode / DeepSeek V4.1 Flash + GLM-5.3): the agents wrote the change, ran the suites and fuzzers sandboxed on the hardware above, and wrote this PR.

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.

cs_w32_permlane_fi fails on MoltenVK 1.4.2: the FI=0 / BOUND_CTRL lanes read the source lane's value instead of keeping the old value

1 participant