Under the identity domains a kernel that reads a grid builtin no longer declares the MultiRegion
specialization constant. It tells a region from an indirect dispatch by the region's grid
(RegionSelect::Grid in lower::dispatch):
- Every dispatch the host knows (dispatchThreads, dispatchThreadgroups, and each piece of a split
of either) pushes DispatchRegion with Metal's threads_per_grid in region[1].xyz and its piece's
first threadgroup in region[0].xyz. So the pieces of a split read Metal's whole grid, and every
compute pipeline takes the base offset.
- An indirect dispatch pushes a zero grid. Its kernel then takes the single-region form, its grid
NumWorkgroups times L, which needs its workgroup size to be Metal's threadgroup size.
- One pipeline runs every dispatch of a threadgroup size, with no constant to specialize.
A flat variant (LoweringInputs::flat_grid), bound as any other kernel, reads its grid from the same
pushed field rather than from a record at ReplayRegionAddress (plan_replay, EmitCx::push_field).
The consumer runs non-observing kernels in a fixed shape with it, and invocations past the grid
return before the body. A replay or folded variant keeps its record and stays refused under the
identity domains.
The runtime lane takes this ABI as agreed: the zero grid marks an indirect dispatch, which runs
the per-size pipeline.
SEMANTICS_VERSION 2148: modules under the identity domains change.
Tests (src/tests/engine_identity.rs), on lavapipe and moltenvk-m3:
- every_dispatch_reads_metals_grid_from_its_pushed_region. A generated kernel reads
thread_position_in_grid, threads_per_grid and threadgroups_per_grid. It declares no MultiRegion
constant and passes L3. On the CPU interpreter, with L = (4, 2, 1) over an 8x6 grid, it stores
the same answer at every position in three forms: one whole dispatch, a split into two pieces at
region base (0, 1, 0), and an indirect dispatch with a zero grid.
- a_flat_variant_reads_its_grid_from_its_pushed_region. Its flat variant reads a 7x5 grid from
the pushed region in three workgroups of 16. The 13 invocations past the grid store nothing.
- The buffer-kernel test runs once, with its region pushed.
Verified:
- m3-max-41225 (msi, check commit 7fe9bc780c: this tree's metal2vulkan files, which equal those
here on 1bb5fe5bf8): clippy -p metal2vulkan --all-targets --all-features, rustdoc -D warnings,
and nextest -p metal2vulkan --all-features, exit 0 (every test passed; the count's log was
lost to the scratch path two of the lane's jobs shared, since fixed).
- m3-max-41226 (msi, 7fe9bc780c): clippy under --cfg m2v_gpu and --cfg m2v_cpu_icd.