Skip to content

rdna2spirv: the permlane FI=1 value and FI=0 activity shuffles run in every lane on MoltenVK - #6249

Open
sovljanskii wants to merge 1 commit into
ItsNotRexed:mainfrom
sovljanskii:permlane-eager-shuffles
Open

sovljanskii wants to merge 1 commit into
ItsNotRexed:mainfrom
sovljanskii:permlane-eager-shuffles

Conversation

@sovljanskii

@sovljanskii sovljanskii commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Follow-up to #6322 (BUILD-1895 translator half; claim: #5934 (comment)). Rebased onto main f6c6d11e and cut down to what #6322 leaves.

@autowert66's #6322 fixed cs_w32_permlane_fi (#5895): the FI=0 value now goes through bitwise masks. Two shuffles are still read where SPIRV-Cross (MoltenVK) inlines them into a ternary or a short-circuit. Here is the MSL MoltenVK 1.4.2 dumps (MVK_CONFIG_SHADER_DUMP_DIR) for the fixture on main:

_98[12u] = _275 ? spvSubgroupShuffle(_98[2u], ...) : _98[12u];                          // FI=1, permlane16
uint _298 = (_292 && (spvSubgroupShuffle(uint(_275), _293) != 0u)) ? 4294967295u : 0u;  // FI=0 activity

That is 8 of the fixture's 14 shuffles in a conditional position:

  • FI=1 value (2 shuffles): it is read only by dst()'s select, active ? shuffle : old. The lanes off in EXEC skip the shuffle, and they are exactly the lanes FI=1 reads from. A shuffle from a lane that doesn't run it is undefined. The M4 returns the right words anyway, so this passes on luck.
  • FI=0 activity bit (6 shuffles): it sits on the right of present && (act != 0). In a full wave present is always true, so this fixture can't show it. In a workgroup smaller than the wave, a lane whose own source is absent skips the shuffle, though it can still be another lane's source.

Change

  • The native FI=1 path redirects an absent source lane to the calling lane, the same ballot / present / safe_src as FI=0, and stores the shuffled value with Gen.eager (SHADER-529).
  • The FI=0 activity shuffle is stored with eager(). The FI=0 value already goes through masks after Keep the permlane FI/BOUND_CTRL subgroup operations convergent on MoltenVK (fixes #5895) #6322 and doesn't change.
  • tests/semantic/test_permlane_fi.py: test_no_permlane_shuffle_is_conditional checks the fixture with test_dpp_eager_subgroup's conditional_subgroup_ops, a model of SPIRV-Cross's forwarding. On main's translator it fails with these 8.
  • docs/design.md, SHADER-74 row: one sentence on why.

Tested

On an Apple M4, macOS 27.2.1, MoltenVK 1.4.2, LLVM 23.1.6, Python 3.15.2, at main f6c6d11e with a fresh runtime build:

The two NVIDIA reports below (@thehollowedone, @CharlyRien) tested the earlier head 55d2fab2, before this rebase.

For #4233: its gate goes after the shuffle in the same lowering, so whichever lands second rebases. Its test_subgroup_writeback_gate already fails on main + #4233 (3 != 2, SHADER-74's activity shuffle).

AI-assisted.

@thehollowedone

Copy link
Copy Markdown

Independent Windows check of 55d2fab2 on 561b65a8. Windows x64, RTX 3080 Ti, MSVC 19.44, LLVM MC 23.1.6, Vulkan SDK 1.4.363.0.

The stock wave32 cs_w32_permlane_fi fixture passed spirv-val and returned all eight expected words on the GPU. A direct rerun matched, with zero Vulkan core or synchronization validation errors.

All 18 tests in test_permlane_fi.py and test_valu_permlane16.py passed, including the 20- and 40-lane partial-wave cases. This adds Windows NVIDIA coverage for the wave32 fixture. Synthetic inputs only. AI-assisted.

@CharlyRien

Copy link
Copy Markdown

Tested 55d2fab (merged on main 561b65a) on RTX 3090 (NVIDIA 616.56, Windows 11 23H2; 32-wide subgroups, so the non-emulated v_permlane16/x16 path is the one this PR changes): pass. AI-assisted.

  • run_gpu_tests: cs_w32_permlane_fi (1000 0 4 1 1000 0 52 49), cs_w32_permute and cs_bpermute32 pass. 183/232 passed, 48 skipped, the same as main.
  • Full ctest gives the same results as main on this host.

… every lane on MoltenVK

ItsNotRexed#6322 fixed cs_w32_permlane_fi on MoltenVK: the FI=0 value now goes through bitwise masks, not a
scalar select. Two shuffles are still read in a position SPIRV-Cross turns into a ternary or a
short-circuit, so in the dumped MSL 8 of the fixture's 14 shuffles are conditional:

- The FI=1 value is read only by dst()'s select, which becomes
  `active ? spvSubgroupShuffle(...) : old`. The lanes off in EXEC skip that shuffle, and they are
  exactly the lanes FI=1 reads from. A shuffle from a lane that does not run it is undefined. An
  Apple M4 happens to return the right words.
- The FI=0 activity bit is read only on the right of `present && (act != 0)`. A lane whose own
  source is absent (a workgroup smaller than the wave) skips it, though it can still be another
  lane's source.

What changes:
- The native FI=1 path redirects an absent source lane to the calling lane, as FI=0 already does,
  and stores the value with Gen.eager (SHADER-529).
- The FI=0 activity shuffle is stored with eager().
- test_permlane_fi checks with test_dpp_eager_subgroup's conditional_subgroup_ops that no permlane
  shuffle is conditional. The check fails on main's translator.
- The design.md SHADER-74 row says why.

On an Apple M4 (MoltenVK 1.4.2), at main f6c6d11:
- The dumped MSL for cs_w32_permlane_fi goes from 8 conditional shuffles to 0.
- The full GPU suite gives 169/235 passed and 59 skipped, identical per test to main.
- The semantic suite gives 5,805 tests OK.

AI-assisted.
@sovljanskii
sovljanskii force-pushed the permlane-eager-shuffles branch from 55d2fab to fd13d5a Compare November 23, 2026 14:35
@sovljanskii sovljanskii changed the title rdna2spirv: v_permlane16/x16 shuffles run in every lane on MoltenVK (BUILD-1895) rdna2spirv: the permlane FI=1 value and FI=0 activity shuffles run in every lane on MoltenVK Nov 23, 2026
@sovljanskii

Copy link
Copy Markdown
Contributor Author

#6322 landed first with a fix for #5895, so I rebased this onto main f6c6d11e and cut it down to what #6322 leaves.

The MSL that MoltenVK dumps for cs_w32_permlane_fi on main still has 8 of the fixture's 14 shuffles in a ?: or &&:

  • the FI=1 value inside active ? shuffle : old, so the off lanes FI=1 reads from never run it;
  • the FI=0 activity bit on the right of present &&.

This head stores both and redirects the FI=1 source, as FI=0 does. That takes the count from 8 to 0. The GPU suite is identical per test to main on the M4, and the semantic suite gives 5,805 OK. The description has the details.

@thehollowedone and @CharlyRien, thanks for the runs. They cover the old head 55d2fab2.

AI-assisted.

@bobcatchris

Copy link
Copy Markdown
Contributor

Tested fd13d5a on Apple M2 with MoltenVK 1.4.2 (macOS 26.4, subgroup 4..32, device Vulkan 1.4.357): cs_w32_permlane_fi passes; full suite 169/235 passed, 59 skipped, 7 failed vs the PR's real merge-base f6c6d11 169/235, 59 skipped, 7 failed A/B; no regression.

  • cs_w32_permlane_fi: PASS — 1000 0 4 1 1000 0 52 49. The FI shuffles kept out of the ternary/short-circuit still give the right words on this driver.
  • pytest -q tests/semantic/test_permlane_fi.py: 2 passed, 8 subtests passed, 0 failed (llvm-mc 21.1.8, Python 3.13.18).
  • Full suite with one shared harness: head and merge-base f6c6d11 are identical per test (0 status differences, no new or removed fixtures), both with the seven known MoltenVK failures.

Rebase note: GitHub reports the PR's base as 1cc6e3c12, but the head was built on f6c6d11e, which is 59 commits behind it. Comparing against that newer base instead shows five extra failures (ps_vcmp_f16, ps_vcmp_f16_e64, ps_vcmp_f32_nan, ps_vcmpx_f16, ps_vcmpx_f16_e64) that the base passes — those come from #6251's v_cmp(x)_lg fix, which the head lacks, not from this change. A rebase onto current main would remove that confusion.

No code changes of my own; synthetic fixtures and counts only.

AI-assisted.

tedin7 added a commit to tedin7/Leonida that referenced this pull request Nov 23, 2026
… the subgroup write gate (NVIDIA 580.65.06)

On the RTX 5080 (Linux 580.65.06), select(lane == 0, shuffle(v4, 7), v6) gave the shuffle to every
lane: a v_readlane_b32 result written by v_writelane_b32 v6, s13, 0 reached all of v6
(crosslane_fuzz --dpp --ext --no-maskdata, seed 2031, cs_xl32_203106417). The lane test now goes
through gate_after_subgroup, like the EXEC gate of a permlane/swizzle write.

GPU fixture cs_w32_readlane_writelane fails on the 5080 without the change and passes with it.
The CPU gate test follows a value through an eager() copy, so it also holds with ItsNotRexed#6249's eager
permlane shuffles. The DPP writes are left to ItsNotRexed#6270 (SHADER-1035).
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.

4 participants