Files
metal2vulkan/docs
Anees Iqbal 1b9ea536f6 Translator: a threadgroup barrier, and a kernel's group operation in uniform control flow, state the reconvergence mode only in a re-entered loop
A program's threadgroup barrier, and a kernel's tangled instruction in a block the workgroup
uniformity proves every thread of the threadgroup runs together, now count as fragreconv counts a
fragment's derivatives: an entry whose tangled instructions are all such (or a fragment's
derivatives) states no MaximallyReconvergesKHR (or SubgroupUniformControlFlowKHR), records
Reconvergence::Guaranteed and no DeviceReconvergence, except where its emitted module holds a
tangled instruction, itself or through a call, in the construct of a loop whose continue target
two or more blocks of the construct branch to; there it takes the profile's mode and note as
before. An entry whose every group operation stands in a block the pass proves uniform for the
threadgroup, with no re-entered loop around it, states no mode and records Guaranteed. An entry
with any other tangled instruction keeps the mode; a kernel compiled for partial threadgroups
proves no block uniform, and the emulated tier keeps its own rule.

Why: without a mode SPIR-V reconverges invocations at the merge of a construct they entered
together and all leave by it (2.2.5, Uniform Control Flow), and an OpControlBarrier of Workgroup
execution scope is defined where every invocation executes the same dynamic instance of it,
which invocations resume only under those conditions (2.2.5, Dynamic Instance). Metal requires
every thread of the threadgroup to reach a threadgroup barrier, and a group operation in a block
every thread runs together sees every lane, so both are Metal's wherever SPIR-V reconverges,
which is everywhere but a continue target entered from several blocks. On the 780M under AMDVLK
the mode with the group operations of one kernel family costs 9.4-11.4x RADV on its own command
buffers, and 2.8-3.0x without the mode (m3-max-72248, m3-max-72261).

How: BarrierPlan::threadgroup records every threadgroup barrier; simd::finish defers an entry
whose tangled instructions are all a fragment's derivatives, threadgroup barriers or a kernel's
instructions in workgroup-uniform blocks (simd::together: partly_live's uniformity, or the same
analysis where it computed none) to SimdPlan::reentry; lower::simd::reentry (quad_loop, renamed)
settles it on the emitted module, its re-entered-loop test now over every tangled instruction
(derivatives, implicit-LOD samples, LOD queries, control barriers, group operations). The emulated
tier clears the deferral where it clears the mode. The simd module doc, the PrecisionNote and
Reconvergence docs and docs/API.md's Precision sentence and catalogue entry say the same.
SEMANTICS_VERSION 2300.

Tests (src/tests/engine_reconvergence_together.rs): a threadgroup barrier alone states no mode on
every committed profile; one in a loop two latches inside a selection re-enter keeps the mode;
a shuffle in a counted loop states no mode; a shuffle after a merge inside a per-thread branch,
and one in a loop with a per-thread exit, keep it.
2026-11-23 17:10:25 -08:00
..