Conformance: reconvergence holds only constructs Metal defines; rc_return and rc_continue dropped

The suite compares only what Metal defines: where MSL leaves a
derivative undefined, Metal's answer is no contract, and a recorded
match would make a device's luck a contract. The class rule says a
derivative is undefined after an early return inside a selection, after
a break or continue to a construct around the innermost one, and inside
a construct a quad entered diverged. Draw by draw:

Kept (defined):
- rc_if: after an if/else that closed; every lane of the quad arrives.
- rc_loop: after a loop of the pixel's own trip count, exited through
  the loop's own merge.
- rc_break: after a break to the loop's own merge.
- rc_switch: after a switch of one label per case that closed.
- rc_discard: after a discard, which Metal runs as a demote, so the
  discarded lane stays a helper for the quad's derivatives.
- rc_grid: inside selections and a loop uniform over 8x8 blocks, so
  every quad runs them together.
- rc_continue_quad: the continue goes to the loop's own continue target,
  not to an enclosing construct; the sample is in the next iteration,
  which every lane enters together after the loop's back edge.
- rc_latches: after an if/else whose two arms both end the iteration;
  the sample is in the next iteration, as above.
- rc_select, rc_select_quad, rc_pick, rc_pick_cells: inside a selection
  uniform over 8x8 blocks; only the texture chosen differs per pixel or
  per 4x4 block, and MSL's default allows a non-uniform choice.

Dropped (undefined):
- rc_return: after a callee's early return inside a selection.
- rc_continue: after a continue from inside a switch to the loop around
  it, which is a continue to an enclosing construct.
Both matched Metal on every card the lane ran; that stays lane evidence.
rc_return_entry and rc_diverged were already left out for the same rule.

The earlier count of 15 counted the cases where the Metal-defined bar
applied as the lane first reported them. Under the class rule the suite
holds 12 draws: 8 constructs and 4 handle choices.

reconverge_sample drops the two entries and the callee rc_return used,
recompiled by scripts/regen-air-fixtures; its four inventory rows go too.
reconvergence-constructs' recording is removed here, and a new recording
comes in the next commit. reconvergence-handle-choices' inputs did not
change, so its recording stays.
This commit is contained in:
Anees Iqbal committed 2026-11-23 13:59:31 -08:00
1 parent 5216a5cde1
commit 03b0e094f4
7 files changed
+384 -2262

No files matched your search

File diff suppressed because it is too large. Load diff
@@ -3,13 +3,12 @@
//!
//! Two owned fixtures, one case each:
//!
//! - `reconvergence-constructs` (`reconverge_sample`) draws ten fragment functions, each after or
//! - `reconvergence-constructs` (`reconverge_sample`) draws eight fragment functions, each after or
//! inside one construct: an if/else on data, a loop of the pixel's own trip count, a break to
//! the loop's own merge, a switch of one label per case, a discard, a call that returned early
//! inside a selection, a continue from inside a switch to the loop around it, selections and a
//! loop uniform over 8 by 8 blocks (`rc_grid`), and a uniform loop's second iteration after one
//! pixel of each quad ended the first early, by a continue (`rc_continue_quad`) or by an if/else
//! at the body's end (`rc_latches`).
//! the loop's own merge, a switch of one label per case, a discard, selections and a loop
//! uniform over 8 by 8 blocks (`rc_grid`), and a uniform loop's second iteration after one pixel
//! of each quad ended the first early, by a continue to the loop's own continue target
//! (`rc_continue_quad`) or by an if/else at the body's end (`rc_latches`).
//! - `reconvergence-handle-choices` (`reconverge_select`) samples inside a selection uniform over
//! 8 by 8 blocks through a texture a ternary on two handles chooses: per pixel (`rc_select`), per
//! 4 by 4 block (`rc_select_quad`), and by a constant the whole draw shares (`rc_pick`), the last
@@ -21,11 +20,17 @@
//! source), at a coordinate whose scale is 2^q texels a pixel for a q uniform over each quad, so
//! the implicit level of detail is exactly q and the sample reads level q's value. The pair is the
//! fine derivative of the lane's own value v, and the trilinear sample is at a level of detail of
//! q + log2(1.5). Each reads the quad's other lanes, which Metal keeps running as helpers after the
//! construct. MSL does not say a derivative is defined after a callee's early return
//! (`rc_return`), after a continue from a switch to the loop around it (`rc_continue`), or in the
//! loop iterations `rc_continue_quad` and `rc_latches` sample in; the case holds Metal's answer
//! there as everywhere else.
//! q + log2(1.5). Each reads the quad's other lanes.
//!
//! Metal defines every value these draws observe. Each is taken where every lane of the quad
//! arrives together: after a construct that closed (an if/else, a loop of the pixel's own trip
//! count, a break to the loop's own merge, a switch, a discard, which Metal runs as a demote so
//! the discarded lane stays a helper), in the iteration after a loop's own back edge (the
//! continue to the loop's own continue target, and the if/else whose arms both end the
//! iteration), or inside control flow uniform over the quad. A construct after which MSL leaves a
//! derivative undefined (an early return inside a selection, a break or a continue to a
//! construct around the innermost one, a construct a quad entered diverged) is not here, because
//! Metal's answer there would be a device's luck rather than a contract.
//!
//! Each draw covers a 64 by 64 `RGBA16Float` target cleared to -1, read back through a blit. A
//! draw's row holds two sites over its texels, each a column of the channels, packed so that the
@@ -113,14 +118,12 @@ impl Draw {
}
/// `reconverge_sample`'s draws, in order.
const CONSTRUCTS: [Draw; 10] = [
const CONSTRUCTS: [Draw; 8] = [
Draw::covering("rc_cover", "rc_if"),
Draw::covering("rc_cover", "rc_loop"),
Draw::covering("rc_cover", "rc_break"),
Draw::covering("rc_cover", "rc_switch"),
Draw::covering("rc_cover", "rc_discard"),
Draw::covering("rc_cover", "rc_return"),
Draw::covering("rc_cover", "rc_continue"),
Draw::covering("rc_cover", "rc_grid"),
Draw::covering("rc_cover", "rc_continue_quad"),
Draw::covering("rc_cover", "rc_latches"),
@@ -58,7 +58,7 @@ threadgroup's threads); an authored case that executes a loop declares it
| `fragment_discard_hoist` | `discard_hoist_full`, `hoisted_known`, `counted_dependent`, `hoisted_const`, `hoisted_device_read`, `hoisted_written_read`, `hoisted_sample`, `hoisted_texture_read`, `hoisted_loop`, `hoisted_call`, `counted_call_use`, `hoisted_nested`, `counted_store`, `counted_atomic` | a `simd_sum` before a discard of whole quads (MSL 2.3), in the thirteen shapes measured for where Metal places it: past an `if (c) discard_fragment();` whose condition reads a constant, a device buffer, one the function writes later, a texture sample or read, a loop's or a call's result, or nested in a further branch (`hoisted_*`); ahead of it where the condition reads the sum, or a call using it, a device store, or an atomic lies between (`counted_*`). Bit `(y / 2) * 4 + x / 2` of `kept_quads` keeps a quad of the 8x4 target; a kept thread writes `(before > after, after - kept, (before - after) & 3, before < after)`, values that hold whatever the simdgroup's packing | Apple M4 and M3 Max write `(0, 0, 0, 0)` for every `hoisted_*` and `(1, 0, 0, 0)` for every `counted_*` with `kept_quads` 1 and 165 (measured on the M3 Max); canonicalization moves the sum of each `hoisted_*` but `hoisted_nested` past the discard (`tests::engine_fragment`), the runtime lane `discard_hoist` draws them on every device, and two authored cases hold `hoisted_known` and `counted_atomic` |
| `fragment_discard_msl22` | `discard_terminate`, `discard_derivative`, `discard_loop`, `discard_simd` | MSL 2.2's discard (compiled `-std=macos-metal2.2`, see `// metal-std:`), which Metal runs as MSL 2.3's: a terminator when nothing tangled follows, else demote/predication as at MSL 2.3, before a derivative, a loop or a simdgroup reduction | as `fragment_discard`; `discard_simd` predicated is the MSL 2.3 device gap (`shaderDemoteToHelperInvocation`) |
| `fragment_fetch` | `fetch_blend`, `fetch_scalar`, `fetch_ordered` | framebuffer fetch through input attachments (float, `uint`, and `half` color inputs, a scalar one); `fetch_ordered` reads in a raster order group (inside the interlock where the device has pixel interlock) | `fetch_blend`: `color = dst · factor + (extra.xy, x, 0.25)`, `ids = ids + (1, 2, 3, 4)`; ordered only where the device has rasterization-order color attachment access |
| `reconverge_sample` | `rc_cover`, `rc_if`, `rc_loop`, `rc_break`, `rc_switch`, `rc_discard`, `rc_return`, `rc_continue`, `rc_grid`, `rc_continue_quad`, `rc_latches` | an 11-level `r16_float` source (level n holds n + 1) sampled at the implicit level of detail, nearest and trilinear, and a fine `dfdx`/`dfdy` pair, after an if/else on data, a loop of the pixel's own trip count, a break to the loop's merge, a switch, a discard, a call that returned early inside a selection, a continue from a switch; inside selections and a loop uniform over 8 by 8 blocks (`rc_grid`), and in a uniform loop's second iteration after one pixel per quad ended the first early, by a continue (`rc_continue_quad`) or an if/else at the body's end (`rc_latches`); `rc_cover` draws one triangle over the target | each case writes (nearest sample, `dfdx(v)`, `dfdy(v)`, trilinear sample) of its lane's value v; the conformance family `reconvergence` compares each with Metal's |
| `reconverge_sample` | `rc_cover`, `rc_if`, `rc_loop`, `rc_break`, `rc_switch`, `rc_discard`, `rc_grid`, `rc_continue_quad`, `rc_latches` | an 11-level `r16_float` source (level n holds n + 1) sampled at the implicit level of detail, nearest and trilinear, and a fine `dfdx`/`dfdy` pair, after an if/else on data, a loop of the pixel's own trip count, a break to the loop's merge, a switch, a discard; inside selections and a loop uniform over 8 by 8 blocks (`rc_grid`), and in a uniform loop's second iteration after one pixel per quad ended the first early, by a continue (`rc_continue_quad`) or an if/else at the body's end (`rc_latches`); `rc_cover` draws one triangle over the target | each case writes (nearest sample, `dfdx(v)`, `dfdy(v)`, trilinear sample) of its lane's value v; the conformance family `reconvergence` compares each with Metal's |
| `reconverge_select` | `rs_cover`, `rs_cells`, `rc_select`, `rc_select_quad`, `rc_pick` | reconverge_sample's tail through a texture chosen by a ternary on two texture handles (11-level `r16_float` sources, level n holding n + 1 and 21 + n), inside a selection uniform over 8 by 8 blocks: per pixel (`rc_select`), per 4 by 4 block (`rc_select_quad`), or by a value the whole draw shares (`rc_pick`); `rs_cover` draws one triangle over the target, `rs_cells` a small triangle in each 8 by 8 cell | each written pixel holds (nearest sample, `dfdx(v)`, `dfdy(v)`, trilinear sample) of the chosen texture; the conformance family `reconvergence` compares each with Metal's |
| `handles` | `select_read`, `phi_read`, `select_null_write`, `array_read`, `sampler_select`, `fragment_select_sample`, `fragment_select_lod`, `argument_buffer_read`, `argument_buffer_array_write`, `argument_buffer_struct_array`, `argument_buffer_depth_read`, `argument_buffer_sample`, `argument_buffer_sample_int`, `argument_buffer_fragment_sample`, `argument_buffer_runtime_sampler`, `argument_buffer_sample_compare`, `argument_buffer_sample_border` | texture and sampler handles as values: selected, phi'd, null, and arrayed textures and samplers dispatched by a switch at the use; implicit-LOD fragment samples through a selected texture with hoisted gradients; an LOD query through one, every candidate queried before the switch; argument-buffer textures (the heap): one read, an element of a texture-array member written, an element of an array of argument buffers tested for null and read, and a depth texture read through the float class and written to a storage texture; heap textures sampled through constexpr samplers (a separate heap sampler): a linear and a pixel (fetch) sample copied to a storage texture, an integer texture's nearest sample, a fragment's implicit-LOD samples of a cube, a 2D, a depth, and a dynamically picked texture-array element, and an opaque-black border sample; a heap depth texture compared through the depth-comparison class; a heap texture sampled through a runtime sampler, which the binder writes with the bound sampler | structural and L3 only; the switch's values are future authored cases (`select_read`: the texel of `a` or `b` by `(gid & 1) == pick`, plus its width, height, and 0 for `is_null`) |
| `fragment_rog` | `rog_buffer`, `rog_texture`, `rog_output`, `rog_discard`, `rog_loop`, `rog_sample`, `discard_then_simd` | raster order groups on a device buffer, a read_write texture, a color output, and a buffer read after a discard; a loop in a group (its forced exit returns to the interlocked entry); a sample-rate group (sample interlock only where the module runs per sample); `discard_then_simd` is a demote-semantics discard before a simdgroup reduction (refused under predication) | every group entry runs its body inside `PixelInterlockOrderedEXT` where the device has pixel interlock, else is refused; ordering is a future authored case |
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
@@ -122,51 +122,6 @@ fragment float4 rc_discard(float4 position [[position]], texture2d<float> source
return rc_tail(source, position.xy, rc_hash(p >> 1u) % 8u, v);
}
// A callee with an early return inside a selection.
__attribute__((noinline)) static float rc_pick(device const uint *data, uint h) {
uint d = data[h & 255u];
if ((d & 3u) == 0u) {
return float(d & 63u);
}
float w = float(data[(h >> 8) & 255u] & 127u);
if ((d & 4u) != 0u) {
w += float(data[(h >> 16) & 255u] & 63u);
}
return 128.0f + w;
}
// After a call that returned early inside a selection.
fragment float4 rc_return(float4 position [[position]], texture2d<float> source [[texture(0)]],
device const uint *data [[buffer(0)]]) {
uint2 p = uint2(position.xy);
float v = rc_pick(data, rc_hash(p));
return rc_tail(source, position.xy, rc_hash(p >> 1u) % 8u, v);
}
// After a loop whose iterations a continue from inside a switch ends early.
fragment float4 rc_continue(float4 position [[position]], texture2d<float> source [[texture(0)]],
device const uint *data [[buffer(0)]]) {
uint2 p = uint2(position.xy);
uint h = rc_hash(p);
uint n = 4u + data[254] % 3u;
float v = 0.0f;
for (uint i = 0u; i < n; ++i) {
switch (data[(h + 29u * i) & 255u] % 3u) {
case 0u:
v += 1.0f;
continue;
case 1u:
v += float(data[((h >> 8) ^ i) & 255u] & 15u);
break;
default:
v += 2.0f;
break;
}
v += float(data[(h + i) & 255u] & 7u);
}
return rc_tail(source, position.xy, rc_hash(p >> 1u) % 8u, v);
}
// Inside selections and a loop whose conditions hold for whole 8 by 8 blocks, so every quad runs
// them together.
fragment float4 rc_grid(float4 position [[position]], texture2d<float> source [[texture(0)]],
@@ -2398,8 +2398,6 @@ engine/reconverge_sample.air.ll rc_loop ok ok ok ok ok ok ok ok ok ok ok ok ok o
engine/reconverge_sample.air.ll rc_break ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok
engine/reconverge_sample.air.ll rc_switch ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok
engine/reconverge_sample.air.ll rc_discard ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok
engine/reconverge_sample.air.ll rc_return ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok
engine/reconverge_sample.air.ll rc_continue ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok
engine/reconverge_sample.air.ll rc_grid ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok
engine/reconverge_sample.air.ll rc_continue_quad ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok
engine/reconverge_sample.air.ll rc_latches ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok
@@ -2409,8 +2407,6 @@ engine/reconverge_sample.ll rc_loop ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok
engine/reconverge_sample.ll rc_break ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok
engine/reconverge_sample.ll rc_switch ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok
engine/reconverge_sample.ll rc_discard ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok
engine/reconverge_sample.ll rc_return ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok
engine/reconverge_sample.ll rc_continue ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok
engine/reconverge_sample.ll rc_grid ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok
engine/reconverge_sample.ll rc_continue_quad ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok
engine/reconverge_sample.ll rc_latches ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok
Can't render this file because it is too large.