Commit Graph
953 Commits
Author SHA1 Message Date
Anees Iqbal 212bba29c6 rt: Metal's constant step is a vertex-rate binding of stride 0, on every device
Under the identity domains (Device::from_queries' profile, the new runtime's), Metal's
MTLVertexStepFunctionConstant was refused as Unsupported{VertexStepRate}, needing
vertexAttributeInstanceRateDivisor and vertexAttributeInstanceRateZeroDivisor, which the floor
does not enable. The constant step needs no divisor: it is now a vertex-rate binding of stride 0,
one form, no query, every device.

Vulkan permits it. The specification's "Vertex Input Address Calculation" (28.4) gives a
vertex-rate attribute's address as bufferBindingAddress + vertexIndex * stride +
attribDesc.offset, so a stride of 0 reads the layout's first element for every vertex and every
instance, whatever the base instance: what Metal's constant step reads. A binding's stride has no
lower bound outside the portability subset: VUID-VkVertexInputBindingDescription-stride-00619
bounds it above (maxVertexInputBindingStride) and is the only other rule on it, and
VUID-vkCmdBindVertexBuffers2-pStrides-06209 names 0 among the strides a bind may set. Under the
portability subset (VUID-VkVertexInputBindingDescription-stride-04456: at least
minVertexInputBindingStrideAlignment) link refuses the stride of 0 as
Unsupported{VertexInputLayout}, as it refuses any stride the subset forbids.

Translator, under the identity domains only (lower::access::identity), so Device::new's profile
and the old runtime are unchanged:
- metal::vertex::fetch_as answers Constant with VERTEX rate, divisor 1;
- pipeline::link::vertex::binding_stride emits stride 0 for any fixed-function fetch of a
  constant-step layout, keyed on the layout's step rather than on a divisor of 0 (on Device::new's
  profile the only such fetch is the divisor-0 one, so its bindings are the same);
- link's check that an attribute the vertex function lists as alike at every vertex of a
  primitive is fetched once per instance also takes a constant step's binding, which reads one
  element at any rate.
- The per-instance refusal (rate above 1) names exactly what the profile lacks:
  vertexAttributeInstanceRateDivisor, else the maxVertexAttribDivisor the rate passes. Its old
  text, and Feature::VertexStepRate's, claimed the constant step needed the divisor; both now name
  the per-instance step alone.

Docs: docs/API.md (identity-domain vertex input), the rt README's vertex lines, REFUSALS.md
regenerated (the VertexStepRate row and its reach mark no longer name the constant step).

Tests:
- engine_identity_render from_queries_fetches_a_constant_step_at_vertex_rate_with_stride_zero:
  on lavapipe (no buffer robustness, no divisor, no supportsNonZeroFirstInstance) ima_vertex's mark
  layout at the constant step links to a VERTEX-rate binding of divisor 1 and Static(0), both
  modules L3-valid; on moltenvk-m3 (portability subset, minVertexInputBindingStrideAlignment 1) it
  is Unsupported{VertexInputLayout}. Fails without this commit (VertexStepRate on both).
- rt draw every_device_fetches_a_constant_step_attribute_for_every_vertex_and_instance: two
  instances of a triangle from vertex 1 at base instance 1, the uint mark at the constant step over
  four distinct marks: every texel holds the first mark, provoking vertex 1, and its instance (1
  above, 2 below). Points are a gap of rt's draws, so the draw is of triangles; the provoking
  vertex is vertex 1, so a vertex-rate stride other than 0 would read the second mark, and an
  instance step the second and third.
- The Device::new-path tests stay as they were: a_constant_step_links_to_a_zero_divisor_binding_of_
  zero_stride, fetch_is_fixed_function_only_when_exact,
  a_constant_step_is_a_zero_divisor_only_where_a_zero_stride_is_legal.
2026-11-18 05:41:17 -08:00
Anees Iqbal 70dffca0c2 Deep threadgroups run as one row: SpecKey::DeepThreadgroup on from_queries, rt keys it on the size
Metal allows 1024 threads along z; a device's maxComputeWorkGroupSize[2] may hold 64 (NVIDIA's),
so rt refused a kernel's threadgroup of 1x1x320 (Limit::ThreadgroupShape) and could not play a
recorded stream past its frame 216 on any NVIDIA card. One form serves every shape on every
device: a threadgroup deeper than DEEP_THREADGROUP (64) runs as one row of its threads.

Translator, on Device::from_queries' profile only (ProfileFacts::deep_threadgroups, OneRow; Device::new
keeps Axes and is byte-equal): a kernel whose workgroup is its threadgroup (LocalSizeForm::Spec,
no compute derivatives) declares the boolean SpecKey::DeepThreadgroup. Its WorkgroupSize is
(Deep ? sx*sy*sz : sx, Deep ? 1 : sy, Deep ? 1 : sz), OpSpecConstantOp selects (the WorkgroupSize
rule now takes spec-constant operations whose defaults are positive), and its position in the
threadgroup Deep ? LocalInvocationIndex unflattened over (sx, sy) : LocalInvocationId. The linear
index, workgroup and grid builtins keep their values, so group counts, regions and indirect
buffers are untouched. The binder sets it for a region deeper than 64 and checks that region as
the flattened tiers' are. MetalDeviceProperties on that profile reports the capped invocations
on every axis (1024 on every floor device) instead of the device's per-axis sizes.
SEMANTICS_VERSION 2172, ARTIFACT_FORMAT_VERSION 536.

rt: the key is a function of the variant's size (size[2] > DEEP_THREADGROUP), so it adds no
pipeline and no cache key. choose() takes no device limit: an image-only kernel's deep tile runs
whole as one row on every device (it ran whole on RADV/ANV and in tiles on NVIDIA). fits(),
ComputeLimits::max_group_size and Limit::ThreadgroupShape are deleted: every workgroup is within
the floor by construction (a const assertion). A module that neither flattens nor declares the
key is a creation gap. README: the deep form, worst-case pipeline counts, the 50-pipeline line.
REFUSALS.md regenerated; API.md; api_signatures blessed; api_surface pins DEEP_THREADGROUP.

Tests: the translator runs a barrier-exchange kernel at 1x1x320, 2x3x100, 1x4x256 (deep) and 4x4x4
on the interpreter, checks the evaluated WorkgroupSize, no key on Device::new, the binder's
setting on an NVIDIA profile, and the reported maxima; rt's choice tests drop the device limit;
the observing-kernel device test adds deep whole, ragged and indirect dispatches; the square
test adds a column 256 deep.

Verified: built and tested under the check job named in the report.
2026-11-18 04:21:18 -08:00
Anees Iqbal 0d1a32436b vertex input under the identity domains: every attribute in fixed function, no pulled form
Planner ruling 11-18 (final): fixed-function vertex input for every attribute on every device,
the form native Vulkan uses and the fastest measured on every device, one form. Nothing of the
pulled form is taken on Device::from_queries' profile. Before this, the translator's
containment rule (contain::encoding is Check::InShader without buffer robustness) moved every
[[stage_in]] attribute into the shader, a form that reads through a descriptor the identity
domains refuse, so every rt render state with a vertex descriptor was refused as
Unsupported(IdentityDomains).

Translator (metal::vertex::fetch_as, pipeline::link::vertex::resolve), under the identity domains
only (lower::access::identity), so Device::new's profile and the old runtime are unchanged:
- the containment rule no longer moves an attribute: the device bounds the fetch as it bounds
  any (no buffer robustness: a fetch outside its buffer reads what the device gives);
- an unnormalized signed-integer format (Char*, Short*, Int*) is fetched in fixed function into
  a variable declared int, VertexFetch::SignedFixedFunction (new): Vulkan's numeric-type match
  lets a SINT format feed only a signed variable, and the device sign-extends as Metal does. The
  module reads the variable's bits by OpBitcast. Elsewhere such an attribute is still pulled and
  sign-extended in the shader;
- every case that pulled is a typed refusal by what it needs, never a second fetch form.

Metal's vertex descriptor on the rt floor:
- Maps directly:
  - formats: every Metal vertex format to the Vulkan format of its layout and conversion, by the
    device's VERTEX_BUFFER format query. 8/16-bit integer formats read into float attributes go
    through USCALED/SSCALED, signed integer formats into int variables, UChar4Normalized_BGRA is
    B8G8R8A8_UNORM, the 10:10:10:2 formats are A2B10G10R10, and FloatRG11B10 is
    B10G11R11_UFLOAT_PACK32. The validation crate's profiles of RADV (780M x2, RDNA3), ANV (Iris
    Xe, UHD 770), NVIDIA (Pascal, RTX 50) and lavapipe report VERTEX_BUFFER for all of them but
    FloatRGB9E5;
  - steps: PerVertex is VERTEX rate; PerInstance at rate 1 is INSTANCE rate;
  - offsets and strides: the descriptor's, baked into the VkPipeline.
- No fixed-function equivalent on the floor, so a typed refusal:
  - PerInstance rate > 1 and Constant: Unsupported{VertexStepRate}, by query. They need
    VK_KHR_vertex_attribute_divisor's vertexAttributeInstanceRateDivisor (plus ZeroDivisor for
    Constant) and supportsNonZeroFirstInstance, which the floor does not enable, so it is
    refused on every rt device today. Its needs name the missing feature, or the
    maxVertexAttribDivisor limit;
  - a format the device does not report for VERTEX_BUFFER: Unsupported{Format} with that format
    usage, by query;
  - FloatRGB9E5: Unsupported{Format}, not implemented, by need. Of the profiles above only
    lavapipe's reports it, and its fetch answers 0 for the fourth component, where Metal and
    Vulkan give 1;
  - an offset or stride off the format's component alignment (Metal takes any byte multiple on
    Apple5+), and an offset, stride, attribute count or layout count past
    maxVertexInputAttributeOffset, maxVertexInputBindingStride, maxVertexInputAttributes or
    maxVertexInputBindings: Unsupported{VertexInputLayout}, with the limit where one is passed;
  - PerPatch and PerPatchControlPoint: Unsupported{Tessellation}, as before.

rt: RenderPipelineKind::StepRate is deleted: the translator's VertexStepRate refusal comes first
on every rt device, so no pipeline states a divisor. README: the vertex input bullets, their
refusals, and the known gap that a vertex fetch outside its buffer returns what the device gives.
docs/API.md: the identity domains' vertex input. REFUSALS.md regenerated, with reach marks for the
two new features (VertexStepRate app, VertexInputLayout rare); api_signatures blessed.

Tests:
- engine_identity_render from_queries_fetches_every_attribute_in_fixed_function (lavapipe and
  moltenvk-m3 profiles with buffer robustness and the divisor withheld): ima_vertex's float2
  and short attributes are R32G32_SFLOAT and R16_SINT, nothing pulled, L3-valid; a rate-2 layout
  is VertexStepRate needing vertexAttributeInstanceRateDivisor. It fails without this commit (the
  attributes were pulled, then refused as IdentityDomains);
- rt draw every_device_fetches_a_signed_attribute_in_fixed_function: a short of -2 reaches the
  fragment's uint output as 0xFFFFFFFE on every texel; a rate-2 layout is refused as
  VertexStepRate. The existing stage-in test (vertex buffer and set_vertex_bytes) now makes its
  pipeline.

Verified: the next lint job and the device legs on every device.
2026-11-18 03:13:48 -08:00
Anees Iqbal 9bec8a977e rt: a dispatch that reaches a buffer bound off its argument's alignment is refused
The planner ruled that the bind-offset mask becomes a typed refusal. The binder pushed a bound
buffer's address, its gpuAddress plus the offset, rounded down to the alignment the kernel takes
it to have (FieldValue::BufferAddress's mask, from RuntimeFact::AddressAlignment), where Metal's
API validation refuses the bind offset ("must be a multiple of 4 but was set to 2" for a uint *
argument, probe vector_access_placement.m in the conformance crate). Plain Metal runs such a
dispatch at addresses of its own: an M3 Max reaches each element at its address rounded down to
the smaller of its alignment and 4. That is not the rounding the binder did for 8- and 16-byte
arguments.

The dispatch now refuses it with Refusal::BufferOffsetAlignment { index, offset, alignment }
before it records or keeps anything. check_alignment runs after the threadgroup size check and
before a kernel without effects returns, so both direct and indirect dispatches take it.
fill_parameters pushes each address as it is. A set_bytes copy sits at a multiple of 16 in the
ring, which every mask divides, so it is never refused.

Docs:
- docs/API.md: the identity-domain paragraph and the section 10 entry (renamed: "A dispatch that
  reaches a buffer bound off its argument's alignment is refused"); no case names its slug.
- RuntimeFact::AddressAlignment's doc and the mechanism comment.
- The rt README paragraph and FieldValue::BufferAddress's doc.
- docs/REFUSALS.md regenerated (44 rt refusals); api_signatures.tsv gains the variant's row.

Tests (device, under --cfg m2v_gpu or m2v_cpu_icd):
- every_device_refuses_a_bound_address_off_its_alignment (was ..._rounds_a_bound_address_down_...):
  at alignments 2, 4, 8 and 16, each of 17 binds 1 to 15 bytes past a multiple of 16 that the
  alignment does not divide is refused and leaves the buffer unchanged, and the same buffer bound
  at 48 runs. Without the check every one of the 17 dispatches returns Ok.
- an_argument_bound_off_its_alignment_is_refused (was ..._runs_at_the_address_rounded_down):
  the translated vector_word_phases kernels with one argument off its alignment are refused,
  naming the index, offset and alignment, and the command buffer completes with every buffer
  unchanged.
2026-11-18 00:14:00 -08:00
Anees Iqbal b0e68fd826 Delete the folded-tile pipeline: a kernel that is not image-only runs every grid in the remap's tiles
The planner's ruling makes the rule two lines. An image-only kernel that does not observe its
threadgroup partition is declared: 16x16x1 on a grid one deep, the grid's tile (grid_tile) on a
deeper one, at MultiRegion 0 with the extent test. Every other such kernel runs today's remap:
256-lane workgroups, each one tile the region carries. The fold no longer serves buffer-touching
kernels. Image-only kernels used it only where the grid's tile is past the device's
maxComputeWorkGroupSize, and that class is too small to keep a form for, so those dispatches take
the remap too.

The census (replay's job m3-max-44582, both recorded streams): image-only non-observer
dispatches whose tile is past a depth of 64 (NVIDIA's, the floor's limit) are 6 dispatches,
1,760 threads in each stream, one (spec, tile) pair of tile 1x1x256. That is 0.0004% of the
image-only non-observer threads in one stream and 0.0033% in the other. No tile is past a side of
1,024.

Deleted: SpecKey::FoldedTile and the select that took it in place of the region's tile
(lower::dispatch), its binder entry, codec tag, signature row and API guide sentence; rt's
Variant::fold, Constant::FoldedTile, Choice::fold and Last::fold. The cache versions stay at this
branch's single bump (SEMANTICS_VERSION 2171, ARTIFACT_FORMAT_VERSION 535, now for
KernelFacts::image_only and the edge test under MultiRegion 0 alone). An image-only kernel's
pipeline per tile stays: its workgroup is the tile, so a deeper grid's first dispatch at a tile
makes it, and waits once, as the square device test's two-deep dispatch checks.

Verified: cargo fmt; docs/REFUSALS.md regenerated (unchanged). The dispatch-choice tests pin a
tiling kernel's grids of every depth in the remap's tiles, and a 1,024-deep column in them past
a depth of 64. The translator's engine test runs the edge kernel at MultiRegion 0 in 16x16x1
workgroups and at the grid's tile.
2026-11-17 23:13:20 -08:00
Anees Iqbal 45b27a7623 WIP square workgroups: docs, refusal surface, device test 2026-11-17 23:13:19 -08:00
Anees Iqbal f1c73d60bc A dispatch of a kernel that writes no memory records nothing
The translator states on a pipeline's interface whether some stage writes memory another
invocation or a later command can read (PipelineInterface::writes_memory, the union of the
stages' StageInterface::writes_memory: a store to a buffer or through a device address, a
texture write or an atomic update, in the entry or any function it calls; the
ExecutionStatus words are the product's and do not count). The cache's artifact format and
semantics versions move with the new field.

rt reads it into the compute state's interface. A dispatch of a kernel without it, direct
or indirect, is checked as Metal checks it and then records nothing: no bind, no push, no
vkCmdDispatch, and the indirect buffer is not kept or read. Metrics gains
dispatches_without_effects, which counts them. Such a kernel has no effect a program can
observe, so the only difference is less GPU and encode time than Metal's.

Tests: the translator's a_compute_pipeline_states_whether_its_kernel_writes_memory (a kernel
that returns at once, one that only reads, one that writes only its own thread's array: no;
a store behind a branch, a noinline callee's store: yes, on the function and the linked
pipeline, each validated), and rt's
every_device_records_nothing_for_a_dispatch_of_a_kernel_without_effects (a direct, an
indirect and an unbound dispatch of a kernel the interface says writes nothing leave the
buffer unchanged and count three).
2026-11-17 20:35:35 -08:00
Anees Iqbal 8fc4064da5 rt: Managed textures, an image and the consumer's named bytes, uploaded by a device copy
A Managed texture is a Private image plus a range the consumer names, on every
device. Device::new_managed_texture takes a Shared buffer and, per level and
slice, a BytesPlace (offset, bytes per row, bytes per image) laid out as the
consumer chooses; rt never picks the layout. Places that a buffer-to-image copy
cannot read in place (rows not whole texel blocks apart, images not whole rows
apart, a first byte off the block's bytes or off 4 for depth/stencil, a level
leaving the buffer, a wrong count, a buffer the host does not reach) are
refused with Refusal::ManagedTextureBytes.

Texture::upload_region(region, level, slice) records one vkCmdCopyBufferToImage
from the named place into the image in the upload, ahead of every command
buffer committed after the call on every queue, as did_modify_range copies a
Managed buffer: no CPU copy, no staging. On such a texture replace_region
writes the named bytes (Metal's CPU copy) and uploads them; get_bytes reads the
named bytes with no submission. The texture copy's record() now takes a buffer
and region, so staging and named copies share it.

README, the API.md accepted difference (the copy reads the bytes when the GPU
reaches it), REFUSALS.md and the signatures table updated.

Test: tests::managed::every_device_copies_a_managed_texture_s_named_regions
(whole-level uploads, a sub-region upload with an unmarked change outside it,
get_bytes reading the named bytes, replace_region writing them, six refusals).
2026-11-17 18:26:07 -08:00
Anees Iqbal 4732ce6cd7 rt: a buffer bound off its argument's alignment runs at the address rounded down to it
The binder (ComputeCommandEncoder::fill_parameters) pushes each bound buffer's address,
its gpuAddress plus the bind offset, rounded down to a multiple of the alignment the
kernel takes it to have (FieldValue::BufferAddress's mask, from
RuntimeFact::AddressAlignment: the argument's air.arg_type_align_size, at most 16), for
every slot. Refusal::MisalignedBuffer and the dispatch it skipped are deleted, so
fill_parameters cannot fail.

Why: Metal's API validation refuses such a bind offset, and without validation an Apple
M3 Max (macOS 27.0.1) reaches each element at its address rounded down to the smaller of
the element's alignment and 4, for loads, stores and pointers stored in a buffer alike.
The probe that measured it is committed as
crates/metal2vulkan-conformance/probes/misaligned_buffer_binds.m. The two agree at
alignments 2 and 4 and for 8- and 16-byte arguments bound 1 to 3 bytes off a multiple of
4; an 8- or 16-byte argument bound at a multiple of 4 that is not a multiple of its
alignment is reached at the rounded address where the M3 reaches it exactly there, a bind
Metal's validation rejects. docs/API.md section 10 lists that as an accepted difference.

Tests: rt's every_device_rounds_a_bound_address_down_to_its_alignment steps a buffer bound
off each alignment (2, 4, 8 and 16; 15 binds) through the step kernel with the mask set,
and checks the words stepped start at the rounded address; at the 8- and 16-byte binds 4,
8 or 12 bytes off, an unrounded bind would step other words on any device.
an_argument_bound_off_its_alignment_runs_at_the_address_rounded_down binds
vector_word_phases' vwp_words 1 and 3 bytes and vwp_vec16 4 and 12 bytes off their
alignment and expects Metal's words for the rounded binds. They replace
an_argument_bound_off_its_alignment_is_refused and
a_misaligned_dispatch_refused_leaves_its_encoder_and_command_buffer_usable.

Docs: REFUSALS.md and api_signatures.tsv regenerated (the variant's row goes), the rt
README's compute encoders say what the binder pushes, the translator's
RuntimeFact::AddressAlignment doc and the mechanism comment say the binder rounds.
2026-11-17 18:07:45 -08:00
Anees Iqbal ee7c4a5173 rt: Managed buffers, a device copy where Shared memory is not device-local
newBufferWithLength:options: and newBufferWithBytes:length:options: with Managed storage over a
range of a Shared block the consumer names: Device::new_managed_buffer(block, offset, length,
copied). The device's memory-type query picks the form. Where the Shared type is device-local the
buffer is its bytes, as a Shared buffer is, and didModifyRange does nothing. Elsewhere shaders
reach a device copy in Private memory, as Metal keeps one on a Mac with a discrete GPU.

The device copy is a place in a copy block: a Private block of the pool, or a dedicated one past
BLOCK_LEN, in a set apart from the texture blocks, so no buffer lies beside an optimal image. Its
first `copied` bytes are copied from the consumer's and the rest zero-filled, in the upload.
Buffer::did_modify_range(start, length) marks a range changed: the upload, which goes ahead of
every command buffer committed after the call on every queue, copies it from the consumer's bytes
into the device copy as it is submitted, one vkCmdCopyBuffer per buffer with its ranges merged
where they overlap or touch, after a counted barrier that puts the upload's earlier fills first.
No CPU copy, no staging, nothing sized by the call. Each change is one of the upload's 4,096 calls,
so changes past them submit it and wait. The copy reads the bytes when the GPU reaches it, which
docs/API.md records as an accepted difference.

A command buffer keeps each device copy it uses, and an upload each one it copies into, until it
retires; the copy's place is freed then. An indirect dispatch reads its arguments from the device
copy. Places take a core and give a block back once it empties where it is dedicated or another
pooled block of the set is empty; Core::take_memory chooses a pooled or dedicated block for both
take_block and the places.

Refusals: ManagedBlockNotShared (a Private block) and ModifiedRange (a range past the buffer),
both ours; docs/REFUSALS.md and the signatures table regenerated.

Tests: changed ranges merge where they overlap or touch; on every device, in the form its query
picks, the device copy holds the first bytes and zeros, a changed range reaches it at the next
submission and an unmarked change does not, changes past the upload's calls submit it (none
without a copy), both refusals, and every gauge zero after teardown.
2026-11-17 18:00:53 -08:00
Anees Iqbal f3c0008bac translator: a slot held to its narrow unit is reached from its address as it is
Under the identity domains a buffer argument whose alignment is below 4 (a uchar or ushort
buffer, air.arg_type_align_size 1 or 2) took the word form: each access rounded its 64-bit
address down to the word below it. Where every access of the slot is one narrow unit no wider
than its alignment (an i8 access of a uchar buffer, an i16 one of a ushort buffer, on a profile
with that width's storage access), the unit lies at its own address, so the slot now takes the
direct form, as a slot held to 4 does.

AccessPlan::reach records the granularity each slot's static-root accesses reach: a OneWord
leaf of a narrow unit the profile has, its size; any other leaf, a copy's endpoint and an
atomic, 4. A slot is reached from its address as it is where its alignment is at least that
(capped at 4). address_alignment now answers 1 for an argument with no alignment or one of 1;
the AddressAlignment fact is still stated only from 2 up.

engine_narrow_direct checks buffer_end_byte_load, buffer_end_byte_store and
buffer_end_half_load on every identity profile: no 64-bit and (the word form's rounding) where
the profile has the unit, the word form where it does not, L3 passes, and the narrow access
claims its unit's alignment. SEMANTICS_VERSION 2167.
2026-11-17 16:52:34 -08:00
Anees Iqbal 4232d4ed9b translator: every slot held to 4 is reached from its address as it is
Under the identity domains a device-address slot whose argument's alignment is at least 4 now
takes the direct form whatever its window: each access is the slot's address plus its 32-bit
byte offset from the bind address, sign-extended. The runtime makes no buffer longer than 2 GiB
(MAX_BUFFER_LENGTH), so every byte of a buffer lies within 2^31 bytes of each bind address in it
and the sign extension is exact. The window no longer picks the form, and the offset is taken
from the bind address rather than the window's start, so the start's 64-bit add and 32-bit
subtract go and the start need not be a multiple of 16 (the alignment proofs are from the bind
address). DIRECT_WINDOW and direct_window are deleted, and so is the test of accesses past
2 GiB, which the 2 GiB cap puts outside every buffer; the interpreter test of accesses up to
2 GiB stays. Slots held to less than 4 keep the word form.

The word-phase alignment test now expects one uvec4 in every slot held to 16, its Whole window
included. SEMANTICS_VERSION 2166: identity-domain modules change.
2026-11-17 16:50:10 -08:00
Anees Iqbal 0a82834fd2 rt: a kernel that does not observe its threadgroup partition runs its grid in fitted tiles, with no division
A kernel that does not observe its threadgroup partition reads only thread_position_in_grid and
threads_per_grid, so only the set of positions matters. Its partial-threadgroups variant used to
answer Metal's partial threadgroups in rt's tiles (256x1, or the grid's width rounded down to a
power of two): each thread rebuilt its position by UDiv/UMod of its index by the threads left, and
tiles fitted only by width launched 1.68x to 4x the grid's threads on 3D grids of 8x8
threadgroups. On the RX 550 such rows ran up to 3.67x the old runtime's time.

On Device::from_queries' profile under the identity domains (ProfileFacts' new ObliviousEdge,
Grid there, Partial on Device::new's, whose modules stay byte-equal), such a variant states
RuntimeFact::GridTiles and runs its grid in tiles:
- Under MultiRegion 1 its workgroup of GRID_TILE_THREADS (256) is one tile whose power-of-two
  sides the region's nominal size gives. Its position is ((base + WorkgroupId) << s) +
  (idx & m.x, (idx >> s.x) & m.y, idx >> (s.x + s.y)), with m = L - 1, s = bitCount(m), and idx =
  LocalInvocationIndex: masks and shifts of uniform values, no division, nothing new pushed.
- Where the region is flagged NONUNIFORM, an invocation past the grid returns before the body.
  On the RX 550 the driver folds the flag into the exit's exec mask, so the three compares issue
  on every wave; the prologue to that exit is 10 VALU (7 for the position, 3 compares) and 18
  SALU, where the old runtime's is 14 VALU. One pipeline and one form: no second pipeline for
  whole grids.
- Under MultiRegion 0 (an indirect dispatch) it runs at its pipeline's size, as a plain kernel:
  the specialization folds the tile and the exit away.

pipeline::grid_tile(threads) picks the tile from the grid's extents alone, with no device input:
sides 2^a, 2^b, 2^c with a + b + c = 8, the first in one total order over those 45 tiles:
1. the fewest threads launched;
2. then the fewest tiles partly past the grid;
3. then the shallowest (z side 1 first);
4. then, where the grid has two rows or more, the height nearest 2 (|b - 1| smallest);
5. then the widest.
A one-row grid takes 256x1 by its waste. Why this order: among tiles of equal waste the shape
measured within 3% of the best everywhere is 128x2. On the UHD 630, the slowest GPU, 256x1 was
first on every image row and 64x4 cost 5% to 10%; 128x2 stayed within 3% of 256x1 on every such
row. On the 780M avoiding wide tiles helped (sampling 1.028 of the old runtime), and on the RX 550
having more than one row did (texture_write 1.024). The measured rows are its budgets: the RX 550's
21 rows of 3D grids of 8x8 threadgroups, waves, sample_down and sample_up, and the texture
rows on the 780M, 3090 and RX 550.

grid_tile's paths:
- Where the powers of two that divide the extents reach 256 it takes the first tile that
  divides the grid.
- Where one tile holds the grid it takes the first tile that holds it.
- Otherwise it tries the 45 tiles in the order, computing each tile's counts as it goes. It
  passes over a depth 2^c whose bound, ceil(z / 2^c) * ceil(x*y / 2^(8 - c)), exceeds the fewest
  tiles found so far.
24x24x252 and 8x8x360 take 8x8x4 with no waste, 8x8x22 8x8x4 (1.09x), 304x304 16x16,
1024x1024 128x2, 5600x4200 32x8, a row 256x1 and a column 1x256.

rt runs every direct dispatch of such a kernel on one VkPipeline (256x1x1, MultiRegion 1, made
with the state), each region carrying its tile. The indirect pipeline is made at the state's
first indirect dispatch, a first-use wait, and is counted in the pipeline gauge. The
translator's binder plans a GridTiles kernel's Threads and Threadgroups dispatches the same way,
and a ThreadgroupRange at its own size with MultiRegion 0.

Tests:
- lower::dispatch: the rule's table (whole and ragged square, wide, tall, deep, one-row and
  one-tile grids, each with its tile), and grid_tile against the order taken over every tile on
  12,850 grids.
- engine_identity: on the interpreter, ragged-in-3D, whole, z-ragged, row and column grids store
  each of Metal's positions once and nothing past the grid; an indirect dispatch runs at its own
  size; from_queries' module divides by no run-time value, Device::new's still does.
- rt translate: the narrow threadgroup dispatch now shares the tiles' pipeline. The tiles test's
  indirect dispatch makes one more pipeline by one first-use wait, and every gauge, pipelines
  included, is zero at the device's drop.

SEMANTICS_VERSION 2166; ARTIFACT_FORMAT_VERSION 533 (the new fact).
2026-11-17 16:30:42 -08:00
Anees Iqbal 0f854aef98 translator: the direct form adds the sign-extended offset in 64-bit integers, with no pointer bitcast
A bounded slot's access was a byte array's element at its 32-bit offset, the
element pointer bitcast to a pointer to the unit's one-member Block. The
UHD 630's Windows driver (Vulkan 1.3.215) ends the process in that shape
(exit 139, every kind), and passes the integer address with OpConvertUToPtr
to the same Block. Each access is now the slot's address plus its offset
sign-extended (OpSConvert), then one OpConvertUToPtr: the integer form of the
access chain's signed index, which RADV lowers alike (iadd of an i2i64), with
no zero-extended offset for GFX11 to split into a scalar base and a vector
offset. The window is at most 2 GiB (direct_window, tested at 2^31 and one
byte past), so the sign extension is exact.

The byte array and its element place (device_byte_place, device_element)
have no other user and are deleted, and the identity domains no longer need
storageBuffer8BitAccess.
2026-11-17 15:30:39 -08:00
Anees Iqbal 28f9b1db27 translator: identity slots aligned by their argument are reached from their address as it is
Under the identity domains every buffer slot access rounded its address down to a word
(64-bit add, and 3, sub, subb per access) and moved 8- and 16-byte values as words. On the
RX 550's one-wave dispatches that rounding is about 20 scalar instructions per wave.

Metal's API validation refuses a buffer bound at an offset that is not a multiple of its
argument type's alignment (air.arg_type_align_size): measured on an Apple M3 Max by the
conformance crate's vector_access_placement probe, "must be a multiple of 4 but was set to 2"
for a uint * argument (constant too, and a struct of two uints), "of 16 but was set to 8" (and
4) for a float4 *, "of 2 but was set to 1" for a ushort *; a uint * at 4, a ushort * at 2 and a
uchar * at 1 pass. So each plain buffer argument with an alignment of 2 or more states
RuntimeFact::AddressAlignment { slot, align } (at most 16), for a binder to refuse what Metal
refuses. Where that alignment is at least 4 and the slot's window starts at a multiple of 16,
the slot's address is a word memory's base as it is: each access is the 32-bit byte offset
m - start from address + start, through a PhysicalStorageBuffer byte array whose element
pointer is bitcast to a pointer to a one-member Block of the unit (NonWritable for an unwritten
slot's load), then member 0; nothing is rounded, and an 8- or 16-byte access at an offset proven
a multiple of its size is one uvec2 or uvec4. OpBitcast between PhysicalStorageBuffer pointers
is valid SPIR-V (SPV_KHR_physical_storage_buffer). Every other identity slot (no alignment, 1
or 2, a buffer-table element, an argument buffer) keeps the word below each access, as before.
Atomics take their word place the same way. The default policy, so Device::new and the old
runtime, is unchanged.

The identity domains now need storageBuffer8BitAccess (in the new runtime's floor).
SEMANTICS_VERSION and ARTIFACT_FORMAT_VERSION are bumped for the new output and fact.

Measured before this change on the scratch forms (the same SPIR-V shape, the byte view at the
pushed address, no rounding, no anchor):
- the constant-reads probe's 13 columns, against the identity form before it (geomean / worst
  column): RX 7900 XTX -4.3% / +0.5%, RX 550 -6.6% / +0.1%, RTX 3090 -54.2% / 0.0%. The
  64-bit add without rounding failed the XTX by 8.9%;
- short-wave rows on the RX 550 (ladder job 42427, emulated module, against the old runtime):
  k130 2.567x -> 2.295x, k106 1.656x -> 1.537x, k109 1.377x -> 1.233x, k171 1.342x -> 1.315x,
  waves 2.461x -> 2.377x.
2026-11-17 15:30:38 -08:00
Anees Iqbal 66a5a2c9ab translator: on from_queries' profile a kernel reads its region's base on every dispatch and its size by MultiRegion
Under the identity domains a kernel that reads a grid builtin decoded its
dispatch region on every dispatch: the base and Metal's threadgroup size
were selected by a test of the region's grid (region[1].xyz != 0), and the
size was unpacked from region[0].w. On the RX 550 that decode is 19 scalar
instructions per wave on k130 against the old runtime's 1, and making the
region constants saved 5.65 ms of k130's 2.57.

A new profile fact, IdentityRegion, gives the form. Device::new keeps
Grid, today's form, so its modules are byte-equal. Device::from_queries
takes Sized:
- the base is region[0].xyz on every dispatch: 0 where the dispatch is not
  split, and for an indirect one, which pushes a zero region;
- the kernel declares MultiRegion (default 0): at 0, L is the pipeline's
  WorkgroupSize, a constant the driver folds; at 1, L is the region's
  packed nominal size. This is the form for a region whose workgroup size
  is not Metal's, as the binder's edge regions are;
- the grid builtins' single-region form for an indirect dispatch is still
  chosen by the region's grid.

The binder is public and runs on any device's plan, a from_queries one
included, and it sets MultiRegion 1 on every region whose workgroup size
or base is not the dispatch's. So the constant stays rather than the
decoded path being dropped.

The new runtime pushes the pipeline's own size on every launch, so it
leaves MultiRegion at its default: its constant mapping skips the key.

SEMANTICS_VERSION 2163.

Docs: API.md (the identity domains' region) and the runtime README.

Test: engine_identity's
from_queries_reads_every_regions_base_and_its_size_by_multi_region. On
from_queries' profile the grid kernel declares MultiRegion with default
0. On the CPU interpreter, the whole, split (base [0,1,0]) and indirect
dispatches at 0 store Metal's answers, and so does a ragged 7x6 grid
split as the binder splits it: a region of 4x2 at 0, and an edge of 3x2
at base [1,0,0] at 1.
2026-11-17 14:35:03 -08:00
Anees Iqbal b78f8163f9 translator: a half fma is the device's 16-bit Fma on from_queries' profile under the 16-bit float controls
On every device the new runtime makes, Metal's fma on half was the device's float Fma on the
operands held in float, rounded to half by the controlled conversion pair (two OpFConvert
decorated NoContraction). On a chain of 1,024 dependent half4 fmas over 2^19 threads, the
device's 16-bit Fma took 437.5 against 1,818-1,832 us on an RTX 3090, 284 against 377-389 us on an
RX 7900 XTX, and 22.0 against 114.2 ms on a UHD 630 (probe jobs 42069, 42068, 42070).

The translator: a new profile fact, HalfFma. Device::new keeps Measured, the routes it took (the
measured 16-bit Fma on MoltenVK, OpFmaKHR on 16 bits under the controls where shaderFmaFloat16 is
enabled, else the float Fma rounded), which ROWS renders as nothing, so every Device::new
fingerprint and module is unchanged. Device::from_queries takes Native: a half fma is
fma::Route::F16Native, the device's GLSL.std.450 Fma on 16-bit floats, wherever the profile
computes half under the 16-bit float controls (shaderFloat16, with 16-bit RoundingModeRTE,
DenormPreserve and SignedZeroInfNanPreserve); spirv::half_hold then removes its exact conversions,
so the kernel carries no NoContraction pair for it. Elsewhere today's float Fma rounded to half
stays: on the RX 550, without shaderFloat16, and on lavapipe, which does not preserve 16-bit
denormals. OpFmaKHR is not taken on that profile: shaderFmaFloat16 is not one of the queries that
may choose a second form, and the new runtime does not enable VK_KHR_shader_fma.

The note is PrecisionNote::NativeFma, the float fma's. It is per operation, not per width: it
already covers both formats with a bound for each, and Vulkan gives the 16-bit Fma the precision
of the 32-bit one (a multiply and an add, each rounded), so its float bound holds in half. A half
twin would add a Degradation kind to the frozen old runtime and a row to the conformance suite's
native notes for the same statement. Every half fma on from_queries' profile records it, on
either route, and none requires VkProperty::MetalHalfFma.

RADV (Mesa 26.2.6, RX 7900 XTX) does not round the 16-bit Fma once: 1,622,016 lanes of that
chain ended up to 9 half ulp from Metal's (42068). NVIDIA's driver on an RTX 3090 and Intel's
Windows driver on a UHD 630 matched Metal in every lane (42069, 42070). The new runtime's README
lists it among the known gaps of pipeline states.

Tests: engine_arith's a_half_fused_multiply_add_is_the_devices_16_bit_fma_on_from_queries
compiles a half fma through Device::from_queries on five captures: on RADV's, ANV's and NVIDIA's
it is one 16-bit Fma with no NoContraction decoration, no MetalHalfFma requirement and NativeFma
recorded, rounding once on the interpreter; on lavapipe's and vk12-floor's it is the float Fma
rounded, NativeFma recorded, rounding twice. The profile facts test covers HalfFma and its
fingerprint; the fused emit test takes the new route. docs/API.md's native-fma entry and
PrecisionNote::NativeFma's doc state the 16-bit form and its bound.
2026-11-17 13:27:41 -08:00
Anees Iqbal 100b92d608 identity: constexpr samplers by a pushed index into set 1's sampler arrays
Under the identity domains a texture slot sampled through a constexpr sampler takes the sampler
from the set-1 sampler array of its use (binding 2 plain, 3 compare, 4 integer texture) at an
index the consumer pushes: PushField::ConstexprSampler(CombinedSampler), one u32. The consumer
makes the device sampler that the new public CombinedSampler::constexpr_sampler(profile)
describes, places it at an index of that array, and pushes the index. The index is a push word,
not a specialization constant: an index allocated at run time would key the driver's and the
pipeline cache's entries. Link's immutable sampler for the default domains now goes through the
same method, with the same result.

Under the identity domains every device sampler is normalized: a constexpr pixel sampler's
coordinate is scaled in the shader, as a runtime sampler's is, never handed to the device's
unnormalized sampler. A linear sample or gather through it records
PrecisionNote::PixelSamplerScaling, which is static. No address-mode-map variant applies there
(no binder picks a variant), so the sampler keeps its own modes and the slot records no
ConstexprSampled fact.

Still refused as Unsupported{IdentityDomains}: an argument buffer's sampler, arrays of samplers,
bicubic and anisotropy emulation. The refusal test now uses engine/a2_bicubic_weights.

Translation output changes only under the identity domains (Device::from_queries). Device::new
output is unchanged: golden_hashes_match_the_table passes at this tip (job m3-max-42192), with no
"changed under an unchanged key" and no "profile changed:" line.

Public surface: PushField::ConstexprSampler and CombinedSampler::constexpr_sampler are added
(api_signatures blessed); nothing is removed or changed.

SEMANTICS_VERSION 2162: identity-domain modules of constexpr-sampling kernels change.
ARTIFACT_FORMAT_VERSION 531: PushField gains a variant.

Verified:
- m3-max-42097 (msi), this change on cd5a76a757: clippy -p metal2vulkan --all-targets
  --all-features and rustdoc -D warnings green; nextest all() of metal2vulkan, 3,689 of 3,693
  passed. The four failures were development's own (the new pad_simd_shape and
  vector_word_phases fixtures had no table rows), re-blessed at 74669c0552.
- m3-max-42098 (msi): clippy --cfg m2v_gpu and --cfg m2v_cpu_icd green.
- m3-max-42192 (msi), this tip on the samplers landing on 58891b9ce5: golden_hashes_match_the_table,
  public_fixtures_engine inventory and llvm_as part 8, and air_input's engine golden printouts
  pass.
- engine_identity a_constexpr_sampler_is_the_set_1_element_its_pushed_index_names: sample_up and
  the same kernel through a linear pixel sampler link and pass L3 on every profile and on
  moltenvk-m3 without robustImageAccess2. Their push fields are the two texture IDs and
  ConstexprSampler(c) of the normalized use, with no spec constant but LocalSize, no immutable
  sampler and no ConstexprSampled fact; set 1 bindings 0, 1 and 2 are used; constexpr_sampler
  gives a normalized device sampler. PixelSamplerScaling is recorded for the pixel kernel under
  identity, and under the default domains, which hand that kernel the unnormalized sampler, it is
  not.
2026-11-17 12:46:53 -08:00
Anees Iqbal 445b720f78 identity: texture slots sampled through runtime sampler slots from set 1's sampler arrays
Under the identity domains a kernel samples a texture slot through a runtime sampler slot. The
texture is its class's set-1 element at the index of its pushed gpuResourceID, as a read's is.
The sampler is the element of a set-1 sampler array at the index of the sampler slot's pushed
gpuResourceID (SlotGuestBase of the sampler slot), joined to the texture by OpSampledImage. The
array is picked by the use: binding 2 for a plain sample, 3 for a depth comparison, 4 for a
texture of an integer format; 4,000 SAMPLER descriptors each, PARTIALLY_BOUND |
UPDATE_AFTER_BIND | UPDATE_UNUSED_WHILE_PENDING, every stage, the same set 1 for every pipeline.
The sampler's word (pixel coordinates, a nearest pixel sampler) is read from the ID's high word,
so no specialization constant and no SamplerReduction, SamplerCoordinates, CubicSampler or
ConstantLanes fact remains; every precision note is static. An integer write to a storage slot
without a format saturates to the channel widths the consumer pushes
(PushField::TextureIntegerChannels, a u32), with no fact.

Still refused as Unsupported{IdentityDomains}: constexpr samplers (next change: a pushed index),
an argument buffer's sampler, arrays of samplers, bicubic and anisotropy emulation, a slot's
minimum level.

Translation output changes only under the identity domains (Device::from_queries). Device::new
output is unchanged: golden_hashes_match_the_table passes at this tip (job m3-max-42189), with no
"changed under an unchanged key" and no "profile changed:" line.

For the runtime's side (the planner's three facts):
a. The runtime must dedupe device samplers by create info across the three arrays' uses.
   Exhausting maxSamplerAllocationCount (4,000 on the 2080, 3090 and UHD 630; 32,768 on
   lavapipe; 65,536 on the others) must be a typed refusal, with a fill-past-capacity test.
b. The update-after-bind limits for 65,536 sampled images, 4,096 storage images and 12,000
   samplers hold on all nine profiles (the smallest is lavapipe's 1,015,808); the floor must
   check them by query.
c. The count of cubic sampler descriptors is asked of the replay lane; if any exist it goes back
   to the planner before step 5 closes.

SEMANTICS_VERSION 2161: identity-domain modules of sampling kernels and integer writes change.

Verified:
- m3-max-42094 (msi), this change on cd5a76a757: clippy -p metal2vulkan --all-targets
  --all-features and rustdoc -D warnings green; nextest all() of metal2vulkan and metal2vulkan-rt,
  3,719 of 3,723 passed. The four failures were development's own (the new pad_simd_shape and
  vector_word_phases fixtures had no table rows), re-blessed at 74669c0552.
- m3-max-42096 (msi): clippy --cfg m2v_gpu and --cfg m2v_cpu_icd green.
- m3-max-42189 (msi), this tip on 58891b9ce5: golden_hashes_match_the_table,
  public_fixtures_engine inventory and llvm_as part 8, and air_input's engine golden printouts
  pass.
- engine_identity: sample_down links and passes L3 on every profile and on moltenvk-m3 without
  robustImageAccess2, with set 1 bindings 0, 1 and 2 used, no spec constant but LocalSize, and no
  sampler fact; an integer write of (300, 70000, 5, 2^31) stores (255, 255, 5, 255) under the
  RGBA8Uint word and the raw lanes under word 0, on the CPU interpreter.
2026-11-17 12:46:10 -08:00
Anees Iqbal da5fd7da0b push window: 256 bytes on from_queries' profile, the new runtime's floor
A kernel's push window held 128 bytes, what Vulkan guarantees: a dispatch region and 12 buffer
addresses. A kernel of more buffers put the rest in a parameter block that the new runtime writes
into its ring on every dispatch, and whose address the window holds.

The translator: a new profile fact, PushWindow. Device::new keeps Guaranteed (a 128-byte kernel
window, the value ROWS renders as nothing, so every Device::new fingerprint and module is
unchanged); Device::from_queries takes Floor, a 256-byte kernel window: a dispatch region and 28
buffer addresses. lower::push::{window, place, spills} take it; the render windows are the same on
both. The push range is still the function's own need, and a module whose block passes 128 bytes
requires maxPushConstantsSize to cover it, as before.

The new runtime: the floor requires maxPushConstantsSize >= 256 (every captured device reports
256), a typed refusal below it; its pipeline layout declares 256 bytes, and a dispatch pushes the
kernel's own bytes. A new metric, Metrics::ring_writes, counts each parameter block and each
set_bytes copy written into the ring. README: the floor's limit row and the parameters paragraph.

The harness gains wide_bindings: 256 small dispatches of a kernel that binds 24 buffers.

Tests: push.rs places a region and 28 addresses in the floor window and spills a 29th, with the
first 12 placed as the guaranteed window places them; engine_identity's many-buffer kernel on
from_queries pushes all 21 addresses with no block, and one of 33 slots spills 2, both answering
on the interpreter; the floor tests move to 256; the profile facts test covers the new fact; an rt
device test dispatches a 24-buffer kernel with no ring write and a 30-buffer one with one a
dispatch. The signatures table gains Metrics::ring_writes.
2026-11-17 12:09:37 -08:00
Anees Iqbal c1b123813f docs: under the identity domains unwritten and constant arguments are read-only memory 2026-11-17 11:31:25 -08:00
Anees Iqbal 8ec8cbbc20 old-runtime regression fix: a half color output is 16-bit again under Device::new
6f5bd20321 removed the 16-bit `half` color output form on every device. That moved Device::new's
output, which the old runtime builds on: 111 golden cells on each RADV, ANV and MoltenVK profile
(5c47b9c867 -> bfe63b5097). The form comes back for Device::new alone, as a profile fact:
ProfileFacts::half_outputs is HalfOutputs::Sixteen in Device::new's facts (ROWS) and
HalfOutputs::Widened in Device::from_queries' (EVERY). Under Sixteen a `half` color output is
declared with 16-bit `float` lanes where the profile enables storageInputOutput16 and
shaderFloat16, as before 6f5bd20321. storageInputOutput16 is not one of the queries rule 2 lets
choose a second form, so the new runtime keeps one 32-bit form for every stage output. The fact
renders into no ROWS fingerprint, so Device::new's profile keys do not move.

- lower::stage_io: plan::half_variable (now reading the fact and the enabled feature),
  IoObject::User::half, the 16-bit store and io_elem's width are back. StageIo::half_outputs and
  the link contract's 16-bit lanes are back.
- The HalfOutputPrecision and HalfOutputFastMathBlend note texts, docs/API.md's degrade
  catalogue, docs/FAST-PATHS.md and the half-output-blends case say what they said for the old
  path, each scoped to Device::new, with Device::from_queries handing every device the `float`.
- known-gaps.tsv: the 52 MoltenVK rows for the M3 Max's half-output-blends-r16f, -rg16f and
  -rgba16f go, as before 6f5bd20321: with the 16-bit output MoltenVK stored Metal's codes there.
  docs/CONFORMANCE-COVERAGE.md is regenerated (3,783 -> 3,731 ledger rows).
- The Iris Xe's 62 half-output rows (6769c2eaaf) were measured with the 32-bit form on ANV, which
  gets the 16-bit form again under Device:🆕 they are owed a re-run with it.
- SEMANTICS_VERSION 2157 (the 111 cells per profile change under unchanged keys) and
  ARTIFACT_FORMAT_VERSION 530 (the artifact codec has StageIo::half_outputs again).
- The engine_stage_io test is back. It also checks that the profile from Device::from_queries is
  HalfOutputs::Widened and keeps the output 32-bit on MoltenVK, RADV and lavapipe, with no
  StorageInputOutput16.

Verified at 8e0e199a12 on 00ca405504, whose tree is this commit's but for SEMANTICS_VERSION (2156
there; development took it meanwhile) and development's later commits (03a3741772 and the
harness's), which touch none of this commit's files:
- msi 41897: golden_hashes_match_the_table with every difference listed, compared with the
  tables at 5c47b9c867 and bfe63b5097. All 504 stage-io cells on the .ll rows that Linux compares
  (56 on each of the 4 RADV, 4 ANV and MoltenVK profiles) are back at their 5c47b9c867 values,
  none elsewhere. On ANV and MoltenVK those are the only cells that moved (280, under unchanged
  keys). The RADV and NVIDIA columns are stale under profile fingerprints that development's
  e0f567a8bc moved back before this commit (12,705 cells, the table not yet blessed for it); in
  them only the stage-io cells above and 185 cells on each of nvidia-rtx50-linux and
  nvidia-rtx5080-laptop (e0f567a8bc's NVIDIA restore) moved. No ROWS fingerprint moved with
  this commit. The 55 stage-io cells per profile on .air.ll rows need metal-as and wait for the
  M3 bless.
- msi 41813: clippy -p metal2vulkan --all-targets --all-features -D warnings, rustdoc
  -D warnings, nextest -p metal2vulkan -p metal2vulkan-conformance in full: 4,719 of 4,722 pass.
  The failures: golden_hashes_match_the_table, for the bless above;
  the_public_signatures_are_the_committed_table, development's degradations! row, fixed since by
  489bc24c4e; the_authored_4096_step_kernel_compiles_inside_the_budget, which passed alone on
  the same build (41862) and is not in this commit's scope.
- msi 41814: clippy under --cfg m2v_gpu and --cfg m2v_cpu_icd.
2026-11-17 11:30:29 -08:00
Anees Iqbal aa8d6ac6f5 old-runtime regression fix: a stage's reconvergence note only on from_queries' profile; the old runtime's extra kind goes
6e08f5aaef made every stage of implementation-defined reconvergence
record PrecisionNote::DeviceReconvergence on the shared translator
path. The old runtime (Device::new) then announced a second kind,
Degradation::DeviceReconvergence ("device-reconvergence"), for a
tangled stage on a device without maximal reconvergence. Before that
commit it announced ImplementationDefinedReconvergence alone, from the
stage's reconvergence field.

Route (a) of the planner's two: the note is a third profile fact.
- ProfileFacts gains reconvergence_note: ReconvergenceNote::Field for
  Device::new (ROWS), ReconvergenceNote::Noted for
  Device::from_queries (EVERY).
- pipeline::compile records the note only where the profile notes it.
- A Device::new stage again carries the field alone, its notes as
  before 6e08f5aaef.
- The fingerprint renders the facts only off ROWS, so no Device::new
  fingerprint moves.

The old runtime's Degradation::DeviceReconvergence kind is deleted: no
Device::new stage records the note. Its catalogue entry in API.md and
its API-table row go with it. from_precision_note maps the note, which
none of its stages hold, onto ImplementationDefinedReconvergence, as the
closed match requires. The note stays in the translator's vocabulary,
codec and validation allowance for metal2vulkan-rt, which forwards it
through ComputePipelineState::precision_notes.

Tests:
- engine_simd's reconvergence_follows_the_profile and
  uniform_control_flow_mode_without_maximal_reconvergence assert the
  field alone through Device::new and the note through
  Device::from_queries; the guaranteed stage records none.
- the_profiles_facts_follow_its_constructor covers the third fact.

SEMANTICS_VERSION 2155.
2026-11-17 10:57:34 -08:00
Anees Iqbal e0f567a8bc old-runtime regression fix: the two half rows return to Device::new; from_queries' profile notes every controlled pair
07e62aa306 deleted DriverWorkaround::HalfConversionPairFolded (NVIDIA)
and HalfConversionFusedWithArithmetic (RADV) on the shared translator
path. That changed the old runtime's modules:
- NVIDIA's moved from the Converted form to the Controlled one: 333
  golden cells each on nvidia-rtx50-linux and nvidia-rtx5080-laptop,
  bless 7fa6662170.
- The NVIDIA and RADV fingerprints moved (six profiles).
- Every controlled module gained NativeHalfConversion.

Restored for Device::new, as before 07e62aa306: both identity rows,
narrow::quantize_form's fold check (NVIDIA takes Converted),
narrow::rounds_arithmetic, and the note on a controlled pair only where
RADV's row fuses f32 arithmetic into the narrowing. The validation lanes
(half_conversions, native_maths) and the translator's tests go back to
their text before 07e62aa306.

rt keeps what landed, carried with no switch. The note's form is a
second profile fact beside the stage bound:
- device::profile::ProfileFacts holds { stage_bound, half_pair_note }.
- Device::new builds ProfileFacts::ROWS (Defects, Fused).
- Device::from_queries builds ProfileFacts::EVERY (Every, Every).
- pipeline::compile reads half_pair_note: Every records the note on
  every module that keeps a controlled pair. Fused is the old rule.
- from_queries profiles name neither row, so quantize_form gives them
  Controlled on every device with the controls, NVIDIA's included.
- The fingerprint renders the facts only when they differ from ROWS, so
  Device::new's NVIDIA and RADV fingerprints return to their values
  before 07e62aa306.

Tests:
- The identity tests are back.
- New from_queries_half_rounding_follows_the_queries_alone and
  from_queries_notes_every_controlled_pair.
- The facts test covers both facts.

Docs: PrecisionNote::NativeHalfConversion, API.md's degrade catalogue
and HOWTO.md name both paths; the API table regains the two variants.

SEMANTICS_VERSION 2154.
2026-11-17 10:57:34 -08:00
Anees Iqbal d5a475f1a0 old-runtime regression fix: the stage bounds return to Device::new's ANV rows; the bound on every device is a fact of from_queries' profile
576a7348bc put one stage bound on every device on the shared translator
path, so the old runtime (Device::new) newly refused what it compiled
before: on the UHD 630 and on every committed profile without maximal
reconvergence, 6 corpus modules (12 rows) went from compiled (emulated
simdgroups, entry weights 104,424 to 188,554) to Needs::StageBound.
Measured on gem10 through Device::new at 9cb90de8cc (job m3-max-41747).

Restored for Device::new, as before 576a7348bc:
DriverWorkaround::SerializedStageWrapsLargeModules and
CompilerMemoryGrowsWithStageSize on ANV's identity row, their bounds
(786,432 and 99,109), the re-plan keeping the widest pin, and the
refusal as Needs::DriverDefect naming the defect; no bound elsewhere.
The old runtime's heap-trim test, warm-refusal kinds and their tests go
back to their text before 576a7348bc.

rt keeps what landed, carried with no switch. The bound is a fact of
the profile (device::profile::StageBound): Device::new builds
StageBound::Defects (the bounds of its rows), Device::from_queries
builds StageBound::Every (99,109 on every device, refused as
Needs::StageBound). stage_bound::emit reads that one field. The
fingerprint renders the fact only when it is Every, so every
Device::new fingerprint is byte-identical to before 576a7348bc. Every
from_queries fingerprint moves, so an rt profile is never one of the
old path's.

Tests:
- The pre-576a7348bc ANV tests are back (both defects' bounds, and the
  same profile without them emitting under every bound).
- New every_stage_from_queries_keeps_the_widest_pin_or_is_refused:
  re-planned, then StageBound; the serialized bound is none there; RADV
  through Device::new is unbounded.
- the_stage_bound_fixture_keeps_the_pin_or_is_refused covers both
  paths. Iris pinned through both. Without maximal reconvergence:
  StageBound through from_queries, DriverDefect on ANV through
  Device::new, and emitted emulated through Device::new under Intel's
  Windows driver (the UHD 630's case).
- New the_stage_bound_is_a_fact_of_the_profile checks every committed
  profile.

Docs:
- FAST-PATHS' known gap is ANV's again.
- The rt README's known gaps gain the every-device bound.
- API.md and the Needs::StageBound and Feature::StageSize docs name
  both paths.
- REFUSALS.md regenerated; the API table regains the two variants.

SEMANTICS_VERSION 2153.
2026-11-17 10:57:34 -08:00
Anees Iqbal 75b422338a identity: argument-buffer textures are the set-1 elements their resource IDs name
Under the identity domains an argument buffer's texture handle is the gpuResourceID its member
holds: the handle is the ID's index, the element of the class's set-1 array (0 is nil, the null
descriptor), with no handle table, no search and no descriptor. Where the shader checks a read
itself (no robustImageAccess2) the handle carries the word's missing-alpha bit (word bit 12) at
HANDLE_ALPHA_ONE, so the handle form is Lookup::Element or Lookup::Flagged{alpha} only.

The handle tables' variant forms are off under these domains (`texture::tabled`): reads of a
member of another numeric class, raw-texel decodes, storage conversions (red-blue, sRGB alias),
A8 alpha-in-red, unreadable-storage nulls, YCbCr write marks, and the HeapCrossClassNeutral,
HeapStorageReads and HeapResidency facts. A slot and a member of one class index one array, so
the class's volatility now merges the slots' uses with the groups'. The admission takes heap
groups whose declaration is their identity class with no plain, raw or cross classes; anything
else stays Unsupported{IdentityDomains}.

Translation output changes only under the identity domains: the default domains plan and emit
as before (no golden re-bless needed). SEMANTICS_VERSION 2153.

The test kernel `tex` gains an argument-buffer form (`texture_kernel(true)`), checked on
lavapipe, moltenvk-m3 and moltenvk-m3 without robustImageAccess2: same answers at the same
elements, set 0 empty, and the handle form Element or Flagged{alpha} as the profile checks reads.

Verified (this commit's tree, as 657e2245c2 on 2872c419e0):
- msi 41756: clippy -p metal2vulkan --all-targets --all-features -D warnings, rustdoc
  -D warnings, nextest -p metal2vulkan -p metal2vulkan-rt in full: 3,701 of 3,702 pass; the one
  failure is golden_hashes_match_the_table, stale under development's own profile change.
- msi 41800: that golden test with every difference listed: 7,260 cells under a changed profile
  fingerprint (development's at 2872c419e0; this commit changes no profile field), no cell whose
  value moved, no cell changed under an unchanged key. Fixtures that need metal-as (macOS) are
  not compared there.
- msi 41757: clippy under --cfg m2v_gpu and --cfg m2v_cpu_icd.
- msi 41712, 41713 and 41752: the same at 160a3c5bae on 9cb90de8cc (SEMANTICS 2152 there), the
  golden test matching 1,815 rows x 19 profiles.
2026-11-17 10:56:25 -08:00
Anees Iqbal 576a7348bc translator: one stage bound on every device; the two stage-size workarounds go
A module whose entry weighs more than COMPILED_STAGE_WEIGHT (99,109, the
heaviest stage measured to compile within host-sized memory, on ANV) is
now handed to no driver, whatever its identity. A kernel that emulated
its simdgroups only in place of the widest mode's pin (the subgroup size
range decides it) is planned again keeping the pin, as before; every
other module past the bound is refused with Feature::StageSize and a new
Needs::StageBound, its symbol naming the weight and the bound. The
refusal is permanent for the input on the device (its plan decides the
weight), so it is not NotImplemented; validation reads it as the
translator's own gap.

DriverWorkaround::SerializedStageWrapsLargeModules and
CompilerMemoryGrowsWithStageSize go, with ANV's identity entries for
them and the serialized bound (786,432), which the single bound sits
far below. Why: the workaround ladder takes one form for every device,
the slowest compiler's; a device whose compiler would take a heavier
stage is refused it, recorded in FAST-PATHS' known gaps.

Measured before this change, with a scratch build that applied the
bounds and the re-plan to every profile: the corpus on the Iris Xe's
description without its identity refused nothing (largest planned
module 91,399, job m3-max-41496), and RADV and NVIDIA nothing either;
without maximal reconvergence 12 rows were refused, 6 distinct
simdgroup-matrix modules of 198 to 285 products whose lockstep pairs
force emulated simdgroups (jobs m3-max-41474, m3-max-41523).

The owned fixture stage_bound/stage_bound_matrix (512 simdgroup matrix
products beside a lockstep pair in divergent flow, our own MSL) has
their structure: on the Iris Xe its emulated module weighs 123,307 and
its pinned one 37,646; without maximal reconvergence it is refused at
123,308 (scratch weighing, job m3-max-41602). The new test
the_stage_bound_fixture_keeps_the_pin_or_is_refused asserts both paths
and that the re-planned kernel is under the bound.

The old runtime's heap-trim test loses its long chain, now refused on
every device; it asks for a trim where the making left more than the
floor free (NVIDIA's compile never does under the bound, 189 MB at
most measured). SEMANTICS_VERSION 2150; REFUSALS.md regenerated; the
API table loses the two variants and gains Needs::StageBound.
2026-11-17 10:24:59 -08:00
Anees Iqbal fa52012831 identity: texture slots are the set-1 elements their pushed resource IDs name
Under the identity domains a kernel's texture slots now lower. A slot's
gpuResourceID is pushed as its PushField::SlotGuestBase (the index in the
low word, the word in the high one). Its texture is the element at that
index of one of set 1's two fixed arrays: binding 0, SAMPLED_IMAGE x
65,536, and binding 1, STORAGE_IMAGE x 4,096. Each is partially bound,
updated after binding and while unused elements are pending, and seen by
every stage, with the same layout for every pipeline
(BindingSource::IdentityArray). Each image class the kernel declares
(shape, numeric type and depth comparison, sampled, or storage without a
format) is a variable of its descriptor type's binding. The slot binds no
descriptor and declares no specialization constant:
- is_null_texture answers whether the index is 0. Nil needs nothing
  else in the shader, since element 0 of each array is a null descriptor
  (the device test of ba4454b05b).
- A read the shader checks itself takes Metal's out-of-bounds alpha of 1
  from bit 12 of the word (TextureWord::OUT_OF_BOUNDS_ALPHA_ONE).
- The ResourcePresence and OutOfBoundsAlpha facts are not stated there.

No binder chooses a variant under identity, so a slot reads whatever
texture its ID names through the plain form:
- the variant facts (cross-class reads, planes read in place, texel rows,
  texture-buffer parts) are not stated;
- a float or half read takes the device's sRGB decode with
  PrecisionNote::SrgbTexelDecode (VkProperty::MetalSampler on MoltenVK),
  as a heap element's does, with no SrgbTexture twin;
- no texture is sparse (the consumer refuses one): no write-dropping
  SparseTexture constant and no ConstantLanes;
- a storage slot is formatless with no StorageTextureFormat fact. Where
  the device cannot access it without a format, the slot is refused as
  Unsupported{IdentityDomains} instead of asking for an input no consumer
  gives there.

Admission stays typed. Under identity, a function is refused as
Unsupported{IdentityDomains}, not implemented, if it:
- samples (any sampler plan; Metal's own sampler as a requirement is
  allowed);
- reaches textures through argument buffers (any heap group);
- declares a slot with no identity class: texture buffers, level views,
  cube-as-array, planes, extended range, RGBX, ulong, or a storage
  image with a format;
- uses a slot whose state comes from anything but its ID: border texels,
  sparse residency arms, a half conversion by the bound format, swizzles,
  offset bases;
- carries a fact naming such state (identity_unsourced).
That keeps the arm64-only forms (two-plane, extended range, sRGB twins)
out of the identity domains, as the x86 scope wants. The old binder
refuses an identity array as an internal error, since the consumer
writes those arrays.

SEMANTICS_VERSION 2150 (identity output changes), ARTIFACT_FORMAT_VERSION
529 (BindingSource gains IdentityArray). docs/RESOURCE-ID.md says what the
arrays are and what the shader reads of an ID. docs/API.md says what the
identity domains lower. The refusal surface and the API signatures are
regenerated. The blessed table also gains
metal2vulkan-rt::PrecisionNote::CappedLodBias, a variant development's
table lacked.

Verified, on development cfa389aa9b (check commit 564d131163, same tree):
- msi, job m3-max-41519: clippy -p metal2vulkan --all-targets
  --all-features -D warnings, rustdoc -D warnings, and nextest of
  metal2vulkan's whole suite: 3672 tests run, 3672 passed, 20 skipped.
- msi, job m3-max-41520: clippy of metal2vulkan under --cfg m2v_gpu and
  --cfg m2v_cpu_icd, both clean.
- The new test, texture_slots_are_the_set_1_elements_their_pushed_resource_ids_name,
  runs on lavapipe, moltenvk-m3, and moltenvk-m3 without
  robustImageAccess2. Its words come from tests/resource_words.tsv rows
  70 and 10, checked against TextureWord::of. It checks the fixed set-1
  layout and that the pushed fields are exactly the buffer, the three
  texture IDs and the region. On the interpreter, with the source at
  sampled element 3 and the destination at storage element 2, it checks
  the reads, the writes, the width and is_null_texture both ways (index
  0 and index 1). On moltenvk-m3 without robustImageAccess2, where the
  shader checks the read, the source image traps any access outside it
  and the out-of-bounds alpha comes from bit 12 of the word: 1.0 for
  R8Unorm, 0.0 for RGBA8Unorm. On the other two profiles the device's
  robust texel answers.
- The same change on the earlier base 9a3b6587b2 (jobs m3-max-41478 and
  41479): 3670 of 3670, clippy clean in all three configurations.
2026-11-17 09:51:53 -08:00
Anees Iqbal 07e62aa306 translator: a controlled half pair is noted on every device; the two half workarounds go
What: a half rounded through the device's conversion and its widening under the 16-bit float
controls (QuantizeForm::Controlled) now records PrecisionNote::NativeHalfConversion on every
device, as a static note of the operation. Every profile with shaderFloat16 and those controls
takes that form, NVIDIA's included. DriverWorkaround::HalfConversionPairFolded (NVIDIA, identity)
and DriverWorkaround::HalfConversionFusedWithArithmetic (RADV, identity) are deleted, with
narrow::rounds_arithmetic, which only the second read.

Why: rule 2 of the owner's rules (one path for every device, no identity-keyed branch) and the
planner's ruling on these two rows of the workaround ladder. The pair is Metal's half(float) by
the Vulkan spec, but a driver's compiler may fold it (NVIDIA's) or fuse the float operation into
the narrowing (RADV's). Recording the note statically on every device covers both drivers with no
identity check, and it never refuses. NVIDIA's modules move from the Converted form to the
Controlled one (NoContraction on the pair, the entry declaring the 16-bit modes), so its golden
cells move. ANV's and RADV's modules gain only the note, which is not hashed. SEMANTICS_VERSION
goes to 2149.

Tests: engine_native_half, device::tests::profile (half_rounding_follows_the_queries_alone replaces
the two identity tests), engine_float_call_notes, and the native_maths and half_conversions
lanes, updated to expect the note on every controlled profile. Docs: API.md's
NativeHalfConversion entry and HOWTO.md. api_signatures.tsv loses the two variants, and
REFUSALS.md is regenerated unchanged.
2026-11-17 09:45:26 -08:00
Anees Iqbal 6e08f5aaef metal2vulkan: PrecisionNote::DeviceReconvergence, a stage's implementation-defined reconvergence as a static note
A stage whose reconvergence is ImplementationDefined (a tangled instruction in
its entry on a device without maximal reconvergence) records
PrecisionNote::DeviceReconvergence, static per stage and as coarse as the field.
metal2vulkan-rt forwards it through ComputePipelineState::precision_notes and
adds none of its own; metal2vulkan-runtime announces its note kind beside its
existing ImplementationDefinedReconvergence kind. The note is in API.md's
degrade-notice catalogue, the fast-paths ledger's Elsewhere class, the cache
codec (ARTIFACT_FORMAT_VERSION 528) and validation's Unbounded allowance.

SEMANTICS_VERSION 2149: a stage's notes change on devices without maximal
reconvergence; the golden tables are re-blessed on development.

Tests: engine_simd reconvergence_follows_the_profile and the uniform-control-flow
case assert the note exactly where the field is ImplementationDefined.
2026-11-17 09:21:08 -08:00
Anees Iqbal 159154d5a9 PrecisionNote::CappedLodBias: a sampler state's capped or withheld lodBias carries a static note
Where the presented GPU adds a sampler descriptor's lodBias to every sample's level
(SamplerUse::lod_bias), vk_sampler hands the device device_lod_bias's answer: past the device's
maxSamplerLodBias it adds that limit, and a NaN, or any bias where a portability subset withholds
samplerMipLodBias, adds none. Only the old runtime said so (Degradation::CappedLodBias, announced as
it makes the state); the translator's vocabulary had no note for it, so a runtime built on the
translator alone could not report it. The lab's own reports put the limit at 15 on the 2080 and
both 3090s and 16 on the other target devices.

The translator now states it as PrecisionNote::CappedLodBias, which DeviceLodBias::note gives for
every variant but Exact. It is fixed by the state's bias and the device's limit; no pipeline stage
records it, so translation output does not change (no SEMANTICS_VERSION bump).

Classed where every note is: the artifact codec, tests::fast_paths (Elsewhere: docs/API.md section
9 states it), validation's comparison allowance (unbounded). The old runtime's degradations! macro
maps the note to its existing runtime kind CappedLodBias with one hand-written from_precision_note
arm. That change is mechanical, with no behaviour change: the kind keeps its code, category, cost
and announcement site, and its precision_note() stays None, so the site tests' rule (a kind with a
note is a stage's) still holds. docs/API.md: section 9's intro, the capped-lod-bias catalogue entry
and the accepted difference name the note. api_signatures.tsv re-blessed; refusal_surface.py
--check passes, REFUSALS unchanged.

Test: metal::sampler::tests::the_device_lod_bias_carries_its_note_where_it_is_not_the_bias, over
every committed device: no note for 0, -0 or a bias within the limit, the note past it, at the
infinities and for a NaN, and for every nonzero bias where samplerMipLodBias is withheld.

Verified: cargo fmt; signatures.py --bless; refusal_surface.py --check. Lints and tests follow as
potluck jobs.
2026-11-17 09:14:26 -08:00
Anees Iqbal 50c5bd0fe1 identity: every dispatch reads Metal's grid from its pushed region
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.
2026-11-17 08:26:40 -08:00
Anees Iqbal 227b118bd9 identity: fields past the push window go to a parameter block at a pushed address
Under the identity domains the stage's ArgumentTable is not a uniform buffer. It is a parameter
block in memory that the consumer writes for the call, and its device address is the new push
field PushField::ArgumentTableAddress, a u64.

How it works:
- The placement is the one the translator already makes. Fields fill the 128-byte window in kind
  order; the first that does not fit, and every field after it, go to the block at
  PushLoc::ArgumentTable offsets, and argument_table_size is the block's size.
- ArgumentTableAddress sorts first among the kinds. A kernel whose fields spill inserts it, so the
  window always holds it, at offset 0 under the identity domains, where RootTableAddress never
  appears.
- The function reads each spilled field through the address (table::read_block): a
  PhysicalStorageBuffer load at the field's offset, aligned to its shape.
- No descriptor is declared or counted, and maxUniformBufferRange does not bound the block.
- Selection now admits a kernel whose slot addresses or region spill, with the address in the
  window.

The variant goes at the codec's end, since tags are by name. The api_signatures table gains it,
and the kind-order and status-address placement tests name it. SEMANTICS_VERSION 2147: a refusal
under the identity domains became a module.

The new test, slot_addresses_past_the_window_are_read_from_the_pushed_parameter_block, uses a
generated kernel with 20 read buffers and an output. On lavapipe and moltenvk-m3:
- ArgumentTableAddress is at Push{0}, 15 slot addresses fill the rest of the window, and 6 go to a
  48-byte block;
- there is no descriptor;
- it passes L3;
- on the CPU interpreter, with the block and every buffer above 4 GiB, it stores the ordered fold
  of the 20 words, which a swapped address would change.

Docs: docs/API.md's identity-domain bullet names the parameter block (added after the check
runs; no code differs from what they built).

Verified:
- m3-max-41196 (msi, check commit 9c6102b5ad on step 1's tree: this commit's metal2vulkan tree, with
  the same translator files as here on 1bb5fe5bf8, where only the runtime crate's signature rows
  differ): clippy -p metal2vulkan --all-targets --all-features, rustdoc -D warnings, and nextest -p
  metal2vulkan --all-features, exit 0 (every test passed; the log of the count was lost to a
  second job on the node writing the same scratch path, since fixed).
- m3-max-41197 (msi, 9c6102b5ad): clippy under --cfg m2v_gpu and --cfg m2v_cpu_icd.
2026-11-17 08:20:24 -08:00
Anees Iqbal 46e3215e55 identity: kernels over buffers lower under the identity domains
Under PointerDomain::Identity with HandleDomain::Identity every buffer slot of a kernel is its
device address used directly. Each slot is the Psb form, its address read from its own push
field, PushField::SlotGuestBase(slot): gpuAddress plus the bind offset, which under the identity
domains is the Vulkan device address. No root table is read, and no access is contained, as Metal
contains no device-address access (psb::prepare_at). Selection admits, under the identity domains,
only the plans lowered so far (select::identity_admits): a kernel whose push fields are its slot
addresses and its dispatch region, all in the push window, with no descriptor and every slot
addressed. Anything else is still Unsupported{IdentityDomains}, not implemented, now refused there
rather than for every function at analysis. SEMANTICS_VERSION 2146: a refusal under the identity
domains became a module.

The new tests (src/tests/engine_identity.rs):
- a1_bool_from_float under the identity domains on lavapipe and moltenvk-m3 has no descriptor,
  no root table and three SlotGuestBase fields. It passes L3, and it computes the program's
  answer on the CPU interpreter, with its buffers above 4 GiB at bind offsets 32, 16 and 4. It
  writes nothing past its output, with its region pushed.
- a2_dynamic_texel_offset, which samples a texture, compiles under the default domains and is
  refused under the identity ones.

Verified:
- m3-max-41149 (msi, check commit eeecc4492b, the same tree but for the test's region bytes):
  clippy -p metal2vulkan --all-targets --all-features, rustdoc -D warnings, and nextest -p
  metal2vulkan --all-features, 3664 of 3665. The one failure was this test, which met the kernel's
  DispatchRegion field and did not fill it.
- m3-max-41195 (msi, a5dbfd408f, this tree): clippy and rustdoc; tests::engine_identity and the
  domain pair test, 3 of 3.
- m3-max-41150 (msi, eeecc4492b): clippy under --cfg m2v_gpu and --cfg m2v_cpu_icd.
2026-11-17 08:13:46 -08:00
Anees Iqbal 94071f82a2 device: the identity pointer and handle domains, taken as a pair
The new runtime's form: pointers are device addresses used directly and a texture's or sampler's
handle is its gpuResourceID (docs/RESOURCE-ID.md). The variants come beside the old domains,
which stay until the cutover; nothing lowers under them yet.

- PointerDomain::Identity and HandleDomain::Identity.
- Device::new refuses one identity domain without the other (InvalidDescriptor) and the identity
  domains on a device without bufferDeviceAddress and shaderInt64 (Unsupported{IdentityDomains},
  naming both features as one alternative).
- A compile under the identity domains is Unsupported{IdentityDomains}, not implemented, at the
  start of analysis, so no old form is ever emitted under them. Later steps lift it as the
  lowering lands.
- The profile fingerprint covers the domains (tested).
- docs/API.md's policy section names the domains; docs/REFUSALS.md and the reach table carry the
  new refusal; api_signatures regenerated.

Verified (this commit's tree, rebased with the ledger commit before it onto b216007f0a):
- msi 41071: clippy -p metal2vulkan --all-targets --all-features -D warnings, rustdoc -D warnings,
  nextest -p metal2vulkan in full, 3,663 of 3,663 (the golden table included: no cell moved; the
  new test the_identity_domains_come_as_a_pair_on_a_device_with_addresses among them).
- msi 41072: clippy under --cfg m2v_gpu and --cfg m2v_cpu_icd.
- msi 41073: the conformance crate's ledger tests, 7 of 7.
2026-11-17 07:46:08 -08:00
Anees Iqbal 6f5bd20321 stage io: one 32-bit form for every stage output
The translator declared a `half` color output with 16-bit float lanes where the device enabled
storageInputOutput16 and shaderFloat16: a second form chosen by a query that is not one of the four
the owner's rule 2 allows (the 3090, 2080, RX 550 and lavapipe lack it; MoltenVK, RADV and ANV
have it). Every interface variable is now 32-bit on every device: a `half` output is widened to
`float`, which holds every `half` exactly, and no module needs StorageInputOutput16.

- lower::stage_io: plan::half_variable, IoObject::User::half and the 16-bit store are gone, and
  io_elem takes no width. StageIo::half_outputs and the profile's input_output_16bit are gone;
  the link contract checks 32-bit float lanes only.
- SEMANTICS_VERSION 2145 and ARTIFACT_FORMAT_VERSION 527 (the artifact codec lost a field). The
  golden table needs its re-bless on development: every profile's key moved with the profile's
  lost field.
- The HalfOutputPrecision and HalfOutputFastMathBlend notes, docs/API.md's degrade catalogue,
  docs/FAST-PATHS.md and the half-output-blends conformance case say what the device receives
  now; their statements about the 16-bit form are gone.
- known-gaps.tsv: 52 rows for MoltenVK on the Apple M3 Max. With the 16-bit output MoltenVK stored
  Metal's codes at every word of half-output-blends-*; with the `float` output its blend is the
  device's own (half-output-fast-math-blend) at 17, 17 and 18 sites of the R16Float, RG16Float and
  RGBA16Float cases, largest differences 1 to 1,582 codes at the stored value (the blend-colour
  sites the largest). Its 32-bit float cases still store Metal's codes.

Verified (code at c55bc28e43, ledger rows added at 2754676210, this commit's tree):
- msi 40877: clippy -p metal2vulkan --all-targets --all-features -D warnings, rustdoc
  -D warnings, nextest -p metal2vulkan in full: 3,661 of 3,662 pass; the one failure is
  golden_hashes_match_the_table (every profile's key moved), for the re-bless on development.
- msi 40827: clippy under --cfg m2v_gpu and --cfg m2v_cpu_icd.
- XTX (RADV NAVI31) 40843: runtime_lane color_writes (every `half`, NaN and infinity included),
  half_output_blends and extended_range_blends, 16 of 16 pass; the conformance replay of the six
  half-output-blends cases exits 0 against the RADV rows, so every row's count and largest
  difference held.
- RTX 3090 (ms01) 40844: the same 16 lanes pass; the replay's 59 divergent sites are exactly the
  RTX 5080's 59 rows (the ledger holds no 3090 rows; NVIDIA never had the 16-bit form).
- M3 Max on MoltenVK: 40833 before the rows (52 new gaps, all in the 16-bit float cases), 40862
  with them (exit 0, every count held on the second run).
- msi 40875: the conformance crate's ledger tests, 7 of 7.
2026-11-17 07:01:32 -08:00
Anees Iqbal ec40b7de6d Interface: what a function reads and writes beyond its bound slots
Each stage interface, and a pipeline's together, states whether its
function may read or write a resource through anything but its bound
slots: a pointer or texture it loads from memory or makes from an
integer (an argument buffer's resources, an address stored in a buffer,
a resource ID), an indirect command buffer, ray tracing, or a call it
cannot see into. Decided from the specialized entry's memory plan: an
access whose pointer or texture handle may have a dynamic or call root.
With each slot's access, these are the two static facts the new
runtime's compute encoder needs to place a barrier only on a hazard.

SEMANTICS_VERSION 2144 (interface facts), ARTIFACT_FORMAT_VERSION 526
(two fields in StageInterface and PipelineInterface).
2026-11-17 06:14:08 -08:00
Anees Iqbal 94e3f50b3e RUNTIME 2524: name and count each reader's snapshot image
What: a reader's snapshot (render/snapshot.rs, Texture::snapshot_texels) is a storage image of
the read texture's level-0 extent beside the texture's own image, which no log line named and no
count counted as an image. Each snapshot a draw takes is now counted
(WorkCounts::reading_snapshots_taken; reading_snapshots_recycled for those whose image was the
recycler's parked one, which placed no memory) and named in the shadow log
(METAL2VULKAN_LOG_SHADOWS): the draw's call, the texture it binds (format, size, levels, usage,
object ID, the texture it is a view of), the snapshot's format and extent, and whether its image
is the recycler's or one placed for it. Image records whether the recycler handed its VkImage
back (Device::recycled_image now says so).

Why: a consumer's Iris walk (RUNTIME 2485) showed a second Private image of each image cache's
size placed about 1 ms after the cache and returned with it, 109 of them, named by nothing: the
snapshot of a draw that samples the cache's view at its own pixels while its own pass renders the
view and writes that color. RUNTIME 2508 already releases it with its command buffers; it stayed
unnamed and uncounted.

Test: tests::snapshot_goes turns the shadow log on and checks one line per snapshot taken, the
recycler's named so, each naming the view, its texture and the snapshot's extent; the second
pass takes 1 snapshot, the recycler's. On a device without the path: none taken or named, and
the reader's copy is the usage shadow the log names for the attached read.

Verified (twinplace lane, tip 2e160c176e on fe3f09f569): m3-max-39527 (msi): clippy -D warnings
plain, m2v_gpu and m2v_cpu_icd 0 for metal2vulkan-runtime and metal2vulkan, rustdoc 0, lavapipe
snapshot_goes, snapshot_reader*, snapshot_area, leading_snapshots, swapped_out_book 10/10
(the copy route: snapshots taken 0); m3-max-39554: api_signatures, api_surface, env_registry
19/19; PHOENIX (RADV) m3-max-39555: the same 10/10, snapshots taken 3, recycled 2, lines 3.
New WorkCounts fields reading_snapshots_taken and reading_snapshots_recycled; no new
Degradation kind; no route change.
2026-11-16 23:52:28 -08:00
Anees Iqbal 4114585b2a SEMANTICS 2143 / RUNTIME 2517: a selection on an own-pixel read keeps its snapshot slot
A fragment function that reads its own pixel of a colour attachment and branches on the value
was refused its snapshot read (SnapshotRefusal::Branch), so each such draw split its render pass
and copied the texture. On the consumer's desktop walks that was 614 draws/s on the XTX and the
Radeon 780M (510 render-pass splits/s, 20.8 M texels/s of split copies) and 107 draws/s on the
Iris Xe. In a pipeline dump of the 780M walk, 30 of the 33 readers refused for Branch branch
through selections whose arms hold no derivative, implicit-level sample, group op, kill or loop;
their values leave the arms through Function variables, not phis.

The rule (spirv/requirements/snapshot.rs, new snapshot/arms.rs): a branch or switch on a fetched
value keeps the slot when it is a selection whose arms leave only through its merge (no break,
continue, return, OpKill, OpTerminateInvocation or unreachable end), hold no tangled instruction
(Inst::is_tangled: a derivative, an implicit-level sample or LOD query, a subgroup or quad op),
hold no loop and no non-constant integer divisor or dynamic index, and call no function that
holds any of these. The merge's phis and the Function, Private and Output variables the arms (or
their callees) store to take the condition's reach, so a merged value that reaches a derivative
still refuses the slot (Derivative). A helper invocation may then take either arm: its stores to
Function, Private and Output memory have no effect beyond it ("Helper Invocations"), and nothing
in the arms observes its neighbours. The loop form stays Branch. demote_guard goes: the rule
covers it (demote arms are clean arms).

The facts a module states change (snapshot_textures, snapshot_refusals): SEMANTICS bump. A new
owned fixture, engine/snapshot_select.metal (scripts/regen-air-fixtures). No new Degradation
kind, WorkCounts field or public signature. Docs: SnapshotRefusal::Branch, docs/API.md (Snapshot
reads).

Tests: snapshot::tests (kept: empty arm, demote arms, Private store, callee and pointer forms;
refused for Branch: an arm with a derivative, a call to one, a kill, a loop, a non-constant
divisor, the loop exit; refused for Derivative: an arm's store or a merge phi reaching a
derivative); compile::tests::a_selection_on_the_texel_keeps_the_slot_where_a_helper_may_take_
either_arm (ss_read_selecting states no refusal on the 780M and lavapipe profiles;
ss_read_selecting_dfdx and wlk_read_branch state Branch); runtime_lane::snapshot_reads 12/12 on
lavapipe with two new lanes.

Verified (snapbranch lane): clippy -D warnings on the three crates (m3-max-39324), touched tests
6/6, lavapipe snapshot_reads 12/12 (m3-max-39334). The fixture's inventory, air_input printout
and golden hashes re-bless on development; clippy under the GPU cfgs, rustdoc, the release
translation timings and the PHOENIX lane run follow there.
2026-11-16 22:47:15 -08:00
Anees Iqbal 594c792b66 RUNTIME 2506: An upload's trailing barrier names its batch's own uses of the buffer
A batch's first work of Managed uploads alone ended with a barrier
TRANSFER/TRANSFER_WRITE -> ALL_COMMANDS/MEMORY_READ|MEMORY_WRITE. On a
device that orders its batches by their ends, where the first work
already takes no leading barrier (first_move::Earlier::Ended), its
second scope is now the union of the stages and access types the
batch's encoders' uses of those buffers name (first_move::Later::Batch,
from the parts' tracker summaries). Every later batch on the VkQueue is
ordered by the batch's end, Barrier::to_all, whose first scope includes
all earlier commands at ALL_COMMANDS/MEMORY_WRITE (the uploads among
them) and whose second includes every later command; another VkQueue's
command buffers wait for the batch's signal, whose first access scope
includes all memory access performed by the device. The barrier keeps
ALL_COMMANDS under the exact batch order, and wherever the batch's use
is unknown: a command may reach memory no use names, a heap's set is
bound, the work may write through its residency, an upload names no
key, or the batch's uses name none of a buffer.

Probe (64 B inline, GPU p50; probe-only branches, never landed): the
global barrier narrowed to COMPUTE_SHADER/SHADER_READ|SHADER_WRITE took
the RTX 2080 from 23.85 to 18.25 us (none 12.4) and the RTX 3090 from
32.25 to 25.05 us (none 21.8); a buffer-range barrier measured the same;
on the RX 7900 XTX the trailing barrier costs nothing (9.7 us either
way).

New counter WorkCounts::managed_upload_barriers_narrowed; device tests:
the WAR test counts it, a later batch reads the upload at a stage the
upload's batch never used, and the barrier's scope names both stages of
a batch whose kernel and blit both use the buffer (a test-only record of
the scopes).

The second commit (263b155a4a) prints vk flags as raw words; Later derives no Debug.

Verified: m3-max-38590 (m2v_gpu and release archives, clippy --cfg m2v_gpu) and m3-max-38591
(clippy plain and --cfg m2v_cpu_icd, rustdoc -D warnings) clean; device tests managed_inline,
host_ram_managed and managed_copy_device 49/49 on the RX 7900 XTX (m3-max-38597) and the RTX
2080 (m3-max-38600): the WAR test counts the barrier narrowed (0 under the exact order and in
its negative control), the later-batch test reads the upload at TRANSFER, and the scope test
finds COMPUTE_SHADER|TRANSFER and SHADER_READ|TRANSFER_READ. The base-vs-tip benches on the
2080 (m3-max-38610) and 3090 (m3-max-38612) follow the merge.
2026-11-16 18:33:58 -08:00
Anees Iqbal 3e39f3b9b1 RUNTIME 2502: Uploads alone after a batch's end take no barrier from the commands before
A batch whose first work is only Managed uploads (copies or inline
vkCmdUpdateBuffers into device copies) recorded, in its first-work
command buffer, an execution barrier ALL->ALL before its GPU start and a
lead barrier ALL_COMMANDS/MEMORY_WRITE -> TRANSFER before the uploads.
On a device that orders its batches by their ends (batch_order::by_ends:
RADV, NVIDIA, ANV) both are redundant: every earlier command on the
batch's VkQueue is a batch's, followed in submission order by its end
Barrier::to_all (ALL_COMMANDS/MEMORY_WRITE -> ALL_COMMANDS/
MEMORY_READ|MEMORY_WRITE), whose first synchronization scope "includes
all commands that occur earlier in submission order" and second "all
commands that occur later in submission order" (vkCmdPipelineBarrier),
the uploads among them. Earlier reads of the device copy run before them
(WAR needs only an execution dependency), earlier writes are available
and visible to their writes (WAW), and the start timestamp at the top of
the pipe is held there as a first encoder's prefix start already is. The
one other kind of submission on a batch VkQueue, an internal one
(device/submit.rs), ends with no such barrier: the batch skips both only
where no internal submission the host has not seen complete was made,
read while it holds its place in the first work's order, which an
internal submission takes before it is made. Another VkQueue's command
buffers stay ordered by the batch's semaphore waits. Under the exact
batch order (to_host ends) both barriers stay; the trailing barrier stays
everywhere.

New counter WorkCounts::managed_uploads_unbarriered. New device tests in
tests::managed_inline: an upload behind a batch whose kernel still spins
on the device copy's word lands after its reads (default order, counted
unbarriered on a by_ends device; exact order, kept), and an ignored
negative control forcing it unbarriered under the exact order. The bench
prints the counter.

The write-after-read test's buffers take their first work before its steps
(e54dbd08b3) and its doc says where it can fail (5cbadadeef).

Verified: clippy in three configurations and rustdoc passed
(m3-max-38492, m3-max-38530); the managed_inline device tests on the XTX
47/47 (m3-max-38511); the write-after-read legs on the 2080 passed
(m3-max-38527). Measured (release, inlinemanaged bench, 64 B inline):
the XTX's GPU gap over no upload fell from +5.6 us to +3.5 us
(m3-max-38521; 2.1-2.9 us across sizes); the 3090 showed no measurable
change (m3-max-38522). The 2080 rerun follows the merge.
2026-11-16 18:06:39 -08:00
Anees Iqbal f2367d8956 SEMANTICS 2142 / RUNTIME 2495: View facts from the device's own check: the runtime's view check, measured workarounds in the description
What: the two constant-window view cost facts no longer come from a GPU identity.
- metal2vulkan: DeviceDescription::measured (a set of DriverWorkaround, serde default) is a
  profile input: the profile takes those workarounds beside its identity's, so the fingerprint and
  every cache key follow it. The identity rows of UniformBufferPerLaneReadsSerialize (RTX 3090,
  RTX 2080, RTX 5080 Laptop) and ExternalUniformReadsSkipACache (ANV on the Iris Xe RPL-P) are
  gone, and NVIDIA_RTX_2080 with them (nothing else used it).
- The texel form now applies only to a slot with an indexed read (SlotPlan::indexed_read, from
  Provenance::indexed_constant_reads, marked on a profile with the texel fact): a slot read at
  constant offsets alone keeps its uniform buffer, whose ranges ANV pushes into registers (Mesa's
  brw_nir_analyze_ubo_ranges; read, not measured), as reims's Iris Geekbench pair 2 suggested.
  With both facts, view_kind gives a per-lane slot storage, an indexed-uniform slot the texel view,
  a constant-offset slot the uniform buffer: no conflict.
- bind::view_check_module (CheckView x CheckReads): the check's kernels, built and verified like
  any crate module (push-constant window mask, uvec4 reads, uniform / per-lane / fields).
- metal2vulkan-runtime: view_check.rs, a device check on its own thread, started as the device is
  made, once per driver + release + runtime, its medians kept in the shader cache's directory:
  8 kernels x 1 KiB / 4 KiB windows in device memory, and UBO / texel uniform reads over imported
  host pages; 7 interleaved rounds after a warm-up, medians of timestamps x timestampPeriod. Facts:
  per-lane where storage/UBO per-lane < 0.3 at both windows (NVIDIA 0.011-0.107, RADV 0.96-1.00);
  texel where texel/UBO uniform over imported pages < 0.7 at both (Iris 0.40-0.49). Unchecked
  (no fact) without timestamps or on any refusal. Device::settle_view_check, view_costs
  (ViewCosts, ViewVerdict), view_check_report.
- Timing: creation never waits. Device::compile_device returns the description's compile device
  until the check answers with a fact, then the one with the facts measured (made before the
  answer is published, held in the line's Invariant); a recorded answer applies from the first
  pipeline. pipeline::Sources reads the compile device once per creation or variant, so one
  compile and its link never straddle the answer. The runtime's own tests fix the facts
  (DeviceOptions::view_facts, cfg(test), default none) unless a test runs the check; it replaces
  compile_as.

Tests: device::tests::profile view_facts_come_from_the_measured_set_alone (no committed profile
nor the 3090/2080 IDs carries either fact by identity; each measured set its own fingerprint);
engine_lane_reads (the fact from the measured set on NVIDIA's and RADV's captures; NVIDIA
identities without it keep UniformWords; both facts compose: Storage / UniformTexel /
UniformWords); engine_access (the texel form for an indexed read, a constant offset keeps the
uniform buffer, nothing measured keeps it); bind::view_check validity on every committed profile;
runtime view_check::tests (facts on both sides of each bound, the measured GPUs' ratios, the record
round trip, the measured compile device and its fingerprint); view_check_device (lavapipe: settles
Measured with its medians, the compile device carries exactly its facts, a later device reads the
record); uniform_texels on indexed inline kernels under fixed facts.

Docs: API.md (DeviceDescription::measured, the texel form's indexed-read rule), runtime README
(the check, its cost, its verdicts, when translation takes them), FAST-PATHS known gap, api
signatures blessed, api_surface entries, REFUSALS regenerated (unchanged).

Verified so far: msi job m3-max-38239 at 5d493d44f7: clippy -p metal2vulkan -p
metal2vulkan-runtime --all-targets --all-features -D warnings CLIPPY=0.

With it (folded): View check: the inline kernels' module metadata llvm-as takes; the windows' descriptor alignment checked

The engine_access and uniform_texels inline kernels named llvm.module.flags and air.version with
the version tuples of air.version and air.language_version, which llvm-as rejects (msi job
m3-max-38254: engine_access's texel test panicked in assemble_text). The view check refuses a
window or out buffer whose VkBuffer offset lies off 256 bytes, the most any descriptor offset
alignment Vulkan bounds may ask, rather than write such a descriptor.

Verified: m3-max-38239 (msi) at 5d493d44f7: clippy -p metal2vulkan -p metal2vulkan-runtime --all-targets --all-features 0. m3-max-38262 at f941e38fab: clippy --cfg m2v_cpu_icd (runtime) 0; lavapipe 21/21 (uniform_texels, uniform_bind_offsets, view_check_device, view_check unit tests); lavapipe verdict Measured, no facts (per-lane storage/UBO 1.17-1.44, texel/UBO over imported pages 1.99-2.30, fields texel/UBO 1.99-2.09; the check took 267-487 ms; a second device read the record). m3-max-38254 at 46e4aaab03: translator 146/147 (engine_access's inline IR, fixed in the second commit). clippy --cfg m2v_gpu, rustdoc, the translator rerun and the device verdicts (2080, 780M, XTX, 3090, Iris) run after the merge.
2026-11-16 16:42:53 -08:00
Anees Iqbal 2911334351 RUNTIME 2491: A discrete host's small Managed ranges go to the GPU inline in the command stream
WIP: the mechanism, the counter, tests and bench; the bound and docs follow.

Measured bound (managed::INLINE_BYTES = 16 KiB; release managed_inline_bench, 200 one-dispatch command
buffers, p50 GPU us, copy against inline): RX 7900 XTX (m3-max-38126) 64 B 11.7-11.8 vs 10.2-10.3, 4 KiB
12.2-12.3 vs 11.0, 16 KiB 13.8-13.9 vs 11.0-11.1, 64 KiB 20.8-20.9 vs 11.2; RTX 2080 (m3-max-38161) 64 B
36.4-37.0 vs 31.1-31.6, 4 KiB 38.5-39.1 vs 31.7-32.3, 16 KiB 44.7-45.4 vs 39.4-39.9, 64 KiB 69.5-70.0 vs
70.5-71.0 (inline loses). Unaligned ranges keep the copy: widening them would put the host copy's bytes
over GPU writes beside the range. New WorkCounts::managed_ranges_inlined. RUNTIME_VERSION 2491.

Verified: msi m3-max-38118 at 7094cdbcd3: clippy -p metal2vulkan-runtime --all-targets --all-features -D
warnings plain 0 and --cfg m2v_gpu 0; 5f78fe489a compiled in m3-max-38132. managed_inline (bytes at 4 B,
B, B+4, 65540, unaligned ranges, a range named twice, GPU-filled neighbours kept, bound 0 the negative
control with 0 inlined) plus the Managed, host-RAM and copy suites: 61/61 on the XTX (m3-max-38126) and
61/61 on the 2080 (m3-max-38161). Lavapipe has unified memory, so it never takes this path. The 3090
bench and --cfg m2v_cpu_icd clippy and rustdoc follow.
2026-11-16 16:02:43 -08:00
Anees Iqbal 8f1e4157d8 RUNTIME 2490: Command queues sharing a VkQueue take fair turns: a queue's own work in flight there is bounded
What: a new DevicePolicy field, queue_turns. Under QueueTurnPolicy::Fair (the
default), on a VkQueue that two or more command queues hold, a batch of a queue
not made unshared goes only while less than 2 ms of its own queue's expected GPU
work is in flight there (16 ms while no other command queue took a batch there
within 50 ms); else the scheduler holds it in its place (HeldFor::QueueTurn) and
a later commit of another queue that shares nothing with it goes first.
QueueTurnPolicy::CommitOrder keeps the old behaviour: every ready batch at once,
in commit order. exact_answers() keeps Fair.

Why: on a device with one graphics VkQueue (RADV, ANV, lavapipe, Intel's Windows
driver) every ready batch went to the VkQueue at commit, so a command buffer a
second queue committed after one queue's burst (a long command buffer cut into
parts, a backlog of frames) waited for the whole burst. The unshared hold
protected only queues made unshared, and released the other queues' held
batches in commit order, so a later plain queue still waited behind the whole
burst, only paced. Metal ran a second queue's small command buffer beside a
first queue's 200 ms one (the consumer's oracles, UHD 630 and 5300M).

How: the VkQueue's flight (unshared_hold.rs) now counts each plain queue's
batches in flight and the latest two submitting queues; Flight::own_ahead
prices each of a queue's batches at its expected run now (a longer run prices
the rest of a burst at once), credits the running oldest only where it is the
queue's own, and holds a queue with no run seen to one batch. Under Fair every
batch enters the flight. The scheduler's look holds a head for its turn beside
the unshared hold (same gate and timer wake, await_room); a committing or
waiting thread's pass leaves such a head to the scheduler's thread
(LeftAtCommit::Turn). New counters: heads_held_for_queue_turns,
heads_let_go_turn_idle, scheduler_at_commit_left_turns. Unshared queues are
never held for a turn. FAST-PATHS gets the row; its known gap now says what
remains (a submitted batch runs to its end).

Tests: tests::queue_turns (the flight's turn math: two budgets, a later queue
not held by another's burst, repricing against the unshared bound, no run seen,
the oldest's credit, published completions); the existing unshared_hold unit
tests on the new flight API; queue_share_device::
a_later_queue_s_command_buffer_takes_its_turn_ahead_of_another_queue_s_burst on
a device under both values (Fair: the small one before the burst's fourth, heads
held; CommitOrder, the negative control: after the twelfth, none held);
fast_paths' ledger choice, keys-no-profile and exact_answers tests. API
signatures blessed; REFUSALS.md unchanged.

Also: the queue_share example's --turns fair|commit-order; the conformance probe
cross_queue_burst_turns.m (not yet run); the queue-sharing and unshared-hold device tests pin
CommitOrder so they keep testing their own mechanism. Public: QueueTurnPolicy::{Fair, CommitOrder},
DevicePolicy::queue_turns, WorkCounts::heads_held_for_queue_turns / heads_let_go_turn_idle /
scheduler_at_commit_left_turns. Default Fair per the owner's 11-03 decision (isolation outranks peak
rate); CommitOrder is today's behaviour. RUNTIME_VERSION 2490.

Verified: m3-max-38127 (msi, 37143cedda): clippy -p metal2vulkan -p metal2vulkan-runtime 0; fast_paths,
api_surface, api_signatures 51/51; queue_turns, unshared_hold, queue_share unit tests 32/32. At
079c3b7635: m3-max-38140 workspace clippy 0, rustdoc 0; m3-max-38142 --cfg m2v_gpu clippy 0;
m3-max-38141 (lavapipe) --cfg m2v_cpu_icd clippy 0, queue_share_device + queue_turns + unshared_hold +
scheduler_held_wakes 47/47: a_later_queue_s_command_buffer_takes_its_turn_ahead_of_another_queue_s_burst
passes under both values (Fair: the small CB starts before the burst's 4th, held > 0; CommitOrder, the
negative control: after the 12th ends, held 0). The 780M numbers for the row follow.
2026-11-16 16:01:06 -08:00
Anees Iqbal d8b39b12d1 SEMANTICS 2141 / RUNTIME 2481: Read short constant windows through uniform texel buffers on the Iris Xe
What: on a device whose profile takes the new cost fact
DriverWorkaround::ExternalUniformReadsSkipACache (ANV on the Iris Xe of
RPL-P alone), a buffer slot's uniform view whose window the translation
bounded to at most TEXEL_WINDOW_BYTES (4 KiB) is declared as a uniform texel
buffer (UniformConstant image, Dim Buffer, Sampled 1, u32 texels) and read with
OpImageFetch; the plan's form is DescriptorView::UniformTexel, its descriptor
UNIFORM_TEXEL_BUFFER, its use class Sampled, its range the uniform view's own
under minTexelBufferOffsetAlignment and maxTexelBufferElements. Every other
uniform view stays a uniform buffer exactly as before. The runtime makes an
R32G32B32A32_UINT view of the planned range for each write, with no cache,
holds it until the command buffer completed (State::retain_own, which also
keeps an indirect chunk that made one from being kept), and binds whole a draw
rebound or carried at such a slot. The zero buffer takes the uniform texel
usage, and upload regions align to the texel offset alignment too.
ARTIFACT_FORMAT_VERSION 525 (DescriptorView gains a variant); SEMANTICS_VERSION 2141, RUNTIME_VERSION 2481.

WorkCounts: uniform_texels_bound; uniform_buffers_bound_to_16k (a bound
buffer's uniform view written as a uniform buffer, window at most 16 KiB: on
the Iris the 4-16 KiB ones); uniform_buffers_bound_past_16k (longer, or not
bounded).

Why: ANV gives external memory MOCS 61 on Gen12.0, which loses the HDC L1
that uniform buffer reads go through; the sampler path keeps its cache. On the
Iris, a UBO over imported memory ran 2.0-2.5x (and 5.2-5.5x for a divergent
index) the time of device memory, a uniform texel buffer 0.98-1.04x (jobs
m3-max-37703, 37729). The window sweep (37753, 37780) set B: at 1 and 4 KiB
texel-set was no slower than ubo-set on device memory in every pattern; at
16 KiB one row was 3.1% slower; from 32 KiB per-lane patterns 2.8-4.2x.

B = 4 KiB covers the consumer's binds only where the kernel's window (its
struct size or accessed hull) is at most 4 KiB. The counting walk counted
buffer sizes, not windows, so the new counter will tell.

The cost of a view per write: vkCreateBufferView+vkDestroyBufferView 0.082 us
on the Iris (mean of 4000), vkUpdateDescriptorSets 0.007 us against a uniform
buffer's 0.024. A set 0 naming a fresh view is found again by no later
command, so such commands lose set-0 reuse.

Tests: engine_access (the texel form's module, its interpretation at
residuals 0, 4, 16 and 256, the window bound, the slot's plan), the profile
fact's carriers, and a lavapipe test whose compile device takes the Iris's
identity (cfg(test) DeviceOptions::compile_as): offsets 0, 4, 16, 256, 260,
set*Bytes data, bytes written before encoding, after it and by a blit, and a
4100-byte window kept as a uniform buffer, with the counts as evidence.

Also: the fixture uniform_texel_windows's AIR companions (job m3-max-37901); a texel form's
loop-invariant fetches move out of their loops as a uniform block's loads do (spirv::hoist, with
its test); the texel form documented (ARCHITECTURE, FAST-PATHS, view docs, runtime README); the
API signatures blessed.

Verified: msi job m3-max-37946 at 00121399e7: fmt check 0, clippy (plain, --cfg m2v_gpu,
--cfg m2v_cpu_icd; --all-targets --all-features -D warnings) 0, rustdoc -D warnings 0. Touched
suites running in the same job. Golden table and engine fixture inventory re-bless on development.
2026-11-16 14:46:29 -08:00
Anees Iqbal 8bcaf69f1d RUNTIME 2475: Compute dispatches instantiate over the commands their bind state kept
What: BindingPlan::instantiate_dispatch_into writes a dispatch's commands over a kept
DispatchCommands, every field set as instantiate_dispatch sets it, the vectors keeping their
storage: each region's specialization (spec_key_into, region_specialization_into) and push
write's bytes, the argument table's bytes, the ranges, extents, holes and uses.
instantiate_dispatch is that method over no commands. The regions a dispatch plans take no list
of each axis's pieces (`Pieces`, numbers alone). In the runtime, compute::Instantiated keeps its
commands as storage when a value they may read moves, and a direct dispatch that instantiates
writes over them where nothing else holds them (the memo entry they were taken into is replaced
first: a dispatch that instantiates settled anew); builds with debug assertions instantiate
afresh and compare. WorkCounts::dispatches_instantiated_in_place counts them.

Why: a guest's compute encoders bind their buffers at moving offsets, one dispatch an encoder,
so their kept commands never serve again (reims's Iris walk: 96.6% of dispatches instantiated
anew). Profile (msi lavapipe, dispatch_chain --host 400 --only encoders --dispatches 5 --groups
64 --states 3 --binds tex-moved, calling thread): instantiate_dispatch 5.6% of its CPU, about
600 ns a dispatch, of it translator instantiate 3.4%, regions 1.6%, region_specialization 1.1%;
about fifteen allocations each instantiation. The commands read the buffer bindings that move,
so no memo of them is exact for this shape: the cut is the work of making them.

Verified: tests::bind::dispatch's
instantiating_over_kept_commands_gives_a_fresh_instantiation (more regions, fewer, none, another
state, the key's storage kept); compute_instantiated's
encoders_of_moving_offsets_instantiate_over_the_kept_commands (five encoders of one command
buffer: 5 instantiated, 4 in place, each writing at its own offset), on lavapipe.

Checks at the lane tip d52118ce95 (msi): clippy -D warnings --all-targets --all-features for metal2vulkan and the runtime, plain (m3-max-37686), m2v_cpu_icd (37688) and m2v_gpu (37689), all 0; rustdoc -D warnings 0 (37689); the translator bind::dispatch, plan::compute and graphics tests 42/42 (37686); the runtime compute, dispatch and encoder tests on lavapipe in a debug build, so every in-place instantiation was compared with a fresh one, 244/244 (37688). gem10 lavapipe m3-max-37685: dispatches_instantiated_in_place 0.80 a dispatch on the tex-moved row, every instantiation; that run's timing was unusable (rows the change does not touch moved more than the cut); one interleaved timing run follows.

With: dispatch_chain: an encoder's dispatch binds as its command buffer's dispatch index says (aac8651f23): at development the encoders shape never moved offsets or swapped textures.
2026-11-16 13:03:25 -08:00
Anees Iqbal 3a3d31c374 RUNTIME 2470: Rebinds: a rebind before the submission of an encoder no rebind encodes again is refused
A rebind between a command buffer's commit and the submission of its last
event group, of a buffer an encoder of it named that keeps no log (a compute
encoder its unit of command predication reaches past, a loop's laying, a
render encoder opened while no buffer over host pages existed), failed that
submission EncodedUseRebound: the commit let go of its holds, and nothing
encodes the encoder again. The consumer's answer table ends the VM on that
kind. Now the rebind is refused instead (EncodedUses), and the command buffer
runs over the pages it was encoded over.

- State::keep_replays also answers whether an encoder that keeps no log
  (not one its commit fails, which runs nothing) named a buffer over host
  pages, by its own commands or by work it left for later not recorded on
  the GPU alone (State::unlogged_names_a_pin).
- Where so, the commit keeps the command buffer's holds
  (State::held_to_submission) instead of letting them go:
  Holds::hold_to_submission moves each from Entry::pending to a new
  Entry::unsubmitted under one lock of `buffers`, so no rebind falls
  between. They go as the last event group's first batch is submitted
  (State::first_submission, State::later_group), or at completion; a
  rebind after that keeps the old pages for the submitted work, as before.
- replace and the rebind's first check refuse while `unsubmitted > 0`,
  counted as their own reason: WorkCounts::rebinds_refused_unsubmitted.
- Cost: nothing new for a command buffer whose encoders a rebind encodes
  again (one pass over its ended encoders' flags at the commit, inside
  keep_replays). A host-step command buffer keeps holding to completion
  (steps_hold), unchanged.

Deadlock audit, by lock:

- Commit: hold_to_submission takes `buffers` under the command buffer's
  `state` lock: state -> buffers, the order encode_moved's Submitting and
  the commit's own clear of its holds already take.
- Submission: the holds go under the scheduler's lock and `state`, after
  the `Submitting` guard (`buffers`) was dropped; each Holds' drop takes
  `buffers` alone: scheduler -> state -> buffers, the order the
  submission's judging already takes. Never under `buffers` itself.
- Completion: moved out of `state` and dropped after its lock, with the
  submitted holds.
- Nothing waits on them: a rebind finds `unsubmitted` and is refused; no
  wait is added anywhere, so no cycle can form.

Tests (lavapipe): rebind_races gains a control (the predicated family
committed behind an unsignaled shared-event wait, rebound before the
signal: refused, completes over the old page, refused-unsubmitted 1), and
the threaded run asserts no command buffer fails EncodedUseRebound. Tests
that asserted the old outcome of such a rebind now assert the refusal and
a completion over the old pages: pending_rebind, rebind_loop_check's
rebind before the laying's submission, tile_rebind_making_wait's
unlogged tile pass, and validation's rebind_reach test of a unit's
encoder that laid its first step. The validation lane no longer has a test
that announces encoded-use-rebound (degrade_notices says so).

Docs: rebind.rs module docs (ordering rule, a predicated loop's laying),
Buffer::rebind_bytes_no_copy, RebindProblem::EncodedUses, the
encoded-use-rebound catalogue entry and its declaration, runtime README;
api_signatures blessed.

Follow-ups in the same landing: Rebinds: a state's reset takes held_to_submission fresh too; Rebinds: clippy (append, take) in the hold-to-submission moves.

Checks (lane rebindsafe2): clippy plain (runtime, validation) 0 at 5bfab2beaa in m3-max-37364; lavapipe runtime tests 356/356 at a0fc57f283 (m3-max-37354: rebind, detach, host_page, host_step, indirect, predication, pending, holds, encoder_fold, deferred_calls), the new control refused with refused-unsubmitted 1 and the threaded run asserting 0 EncodedUseRebound. Validation lavapipe (m3-max-37365), rustdoc and the cfg clippy runs follow on development.
2026-11-16 11:23:09 -08:00
Anees Iqbal 5acd27cd0d RUNTIME 2468: Rebinds: a call of an encoder the runtime cannot encode again never races a rebind
After RUNTIME 2465 a rebind racing an encoder call on another thread is
detected and the encoder encoded again; one the runtime cannot encode again
(a compute encoder its predication unit reaches past, one that left a
GPU-written indirect dispatch to its host step, a render encoder that keeps
no log) failed EncodedUseRebound at submission instead, which a consumer's
answer table treats as fatal.

The protocol: those encoders' calls are gated, so no publish overlaps one.

- Rebinds gains `calls` (gated calls under way). A gated call begins
  (`Holds::begin_call` -> `CallGate::enter`): calls += 1, then reads `open`;
  where a publish is open it backs off and waits for it to close
  (`wait_published`), before it reads anything of a buffer over host pages.
- A rebind's publish now opens before its replace (`Rebinds::quiet_calls`):
  open += 1, then reads `calls`; where a call is under way it waits for the
  calls to end (`drain`/`drained`), up to CALLS_DRAIN (2 ms), and is refused
  past it (EncodedUses, Unreplaced::Calls), never failing the encoder later.
  The four accesses are SeqCst (a store-buffering handshake: of a rebind and
  a call that meet, at least one reads the other's rise), so each gated call
  reads the buffer wholly before the publish (holding it, which refuses a
  rebind until its commit) or wholly after its close. Chosen over the
  registry lock: the call side costs two atomics and takes no lock.
- Which encoders: every compute encoder, and a render encoder that opened
  with no log. A compute encoder can become unreplayable mid-encoding (the
  call that records predication, a loop's record, an unbalanced record that
  leaves work out, a later encoder of its unit that lays a loop, a dispatch
  left to its host step), after earlier calls ran: a gate that started at
  that transition would leave those earlier calls racing. So the gate covers
  a compute encoder from its open. Blit encoders always log, and render
  encoders with a log, stay re-encodable and pay nothing new. A device with
  no buffer over host pages pays one Relaxed load per gated call (`any`).
- Nesting: a thread-local depth, so a call an encoder's call makes of its own
  public calls (a blit's unlogged calls, a loop's copies) never waits.
- WorkCounts: rebinds_refused_calls_in_flight (the retry rate),
  encoder_calls_held_by_rebind, and encoders_raced_unreplayable (raced
  encoders committed with no log: each fails EncodedUseRebound; zero now).

Deadlock audit, extending 2465's, by lock:

- `drain`: taken by a rebind waiting for the calls (no other runtime lock
  held: rebind_host_pages holds no lock across replace) and by a gated
  call's end, which holds none of the runtime's at its end. Nothing is
  taken under it.
- `buffers`: `unopen` takes it alone to lower `open` and notify `closed`
  (so a waiter between its check and its wait cannot miss it); a gated
  call's back-off waits on `closed` under it, holding at most its render
  deferral's `lowerer` lock (lowerer -> buffers is the order holds already
  take). No publish step takes `lowerer`; the rebind's `lower_all` runs
  before the publish opens.
- The rebind's wait for calls is bounded (2 ms), so a gated call under way
  that waits on a thread held at a gated begin (a render end waiting for
  its lowering) ends in a refusal, not a deadlock. A gated call waits only
  as it begins, never under way, and the publish waits for nothing an
  encoder holds (2465's audit), so every begin's wait ends when the open
  publishes close.

Docs: the Safety text of Buffer::rebind_bytes_no_copy and
Heap::rebind_bytes_no_copy, the rebind.rs **Other threads** bullet and
RebindProblem::EncodedUses state the new outcome: refused, never failed
later, for the gated kinds. api_signatures.tsv gains the three fields.

Tests (src/tests/rebind_races.rs): a pause-point control (a predicated
dispatch, Unlogged::Predicated, held at its hold while the main thread
rebinds: the rebind refused, the command buffer completes over the old
page, refused-for-calls 1); the threaded run gains a predicated family and a
host-step family (an indirect stage-in region, Unlogged::Segments), and
asserts encoders_raced_unreplayable == 0.

Follow-up in the same landing (cc0b4592a3): Rebinds: the refusal reason carries no pages (clippy: field never read).
Unreplaced::Held and Unreplaced::Calls no longer give the new pages back:
replace drops them once the registry's lock went (unopen drops the guard
first), as the caller's map_err dropped them before. Also the docs of the
encoded-use-rebound notice (degradation.rs, docs/API.md) and the runtime
README say which encoders still fail it after a race (a blit or logged
render encoder whose commit failed it, or whose encoding again a call that
answers otherwise refused) and that gated calls never race.

Verified: m3-max-37298 (msi) clippy at ec3cbb49c7 failed on exactly these
two fields; the next job checks this commit.

Checks (lane rebindsafe2): clippy plain (runtime, all targets, all features) 0 at cc0b4592a3 in m3-max-37302; lavapipe rebind/detach/host-page/host-step/indirect/predication/pending/holds suites with the gated control and the six-family threaded run in m3-max-37299 (ec3cbb49c7, same library code), the gate-off negative control, clippy GPU/CPU-ICD cfgs and rustdoc follow on development.
2026-11-16 10:59:33 -08:00
Anees Iqbal 2bafb6537a SEMANTICS 2138: Fragment simdgroup lane: run it on Cluster32 tiers, refuse it only below 32 lanes
What: a fragment function that reads [[thread_index_in_simdgroup]] on a profile
without DriverDeviation::MetalFragmentSimdgroups was refused Unsupported{SimdWidth}
on every tier but Direct. It is now refused only on Tier::PartialFragment (fragment
subgroups narrower than 32). On Tier::Cluster32 (a 64- or 128-lane fragment stage,
e.g. RADV on Polaris, wave64 only) the lane is the subgroup lane's low five bits.

Why: the guest is told an Apple GPU's width, 32 (threadExecutionWidth 32,
[[threads_per_simdgroup]] the constant 32), and its shaders are built for 32-lane
simdgroups. On Cluster32 each aligned 32 lanes of the device's subgroup is one
simdgroup. The function's simdgroup operations already ran there, and the emitter
already gave the lane as L & 31 (group::Lane::metal), the same cluster the shuffles
and ballot words use. So the device lacked nothing; the refusal was ours. The lane
is the device's grouping, which Metal allows, and records the existing
PrecisionNote::FragmentSimdgroupGrouping as before.

Tests: engine_simd's fragment-lane test also runs on wave64() (the committed RDNA3
description narrowed to 64 lanes) and requires every lane form to compile there on
Cluster32 with the note, the low-bits mask and L3. Without the fix it is refused and
the test panics. Device test fragment_simdgroup_lanes_are_metal_s accepts the
SimdWidth refusal only where the fragment stage's sizes are all below 32, so on a
wave64-only device it fails without the fix; it also prints the stage's sizes.

Docs: the note's text in docs/API.md and PrecisionNote, the doc comments in
lower::simd. SEMANTICS_VERSION 2137 -> 2138. REFUSALS.md regenerated, unchanged.

Checks (lane simd64): msi m3-max-37237 clippy plain 0, tests 88/88 (engine_simd, public_fixtures_engine, fast_paths, device::tests::subgroup); m3-max-37255 clippy GPU and CPU-ICD cfgs 0, rustdoc 0. The RX 550 run (m3-max-37259) follows on development.
2026-11-16 10:47:52 -08:00
Anees Iqbal 372cf95641 RUNTIME 2465: Rebinds: an encoder call that races a rebind on another thread is encoded again
rebind_bytes_no_copy (Buffer and Heap) may now run while other threads encode and
commit command buffers that use the buffer or heap. Before, the Safety contract
excluded that; this lifts it.

The windows found:

- W1: an encoder call reads a buffer's pages before it holds the buffer. A
  dispatch builds its bind state, a draw its tables, and a blit reads the
  VkBuffer for a copy run that records in a later call. A rebind can land
  between that read and the hold. The hold then pins the new pages while the
  commands name the old ones.
- W2: what lies over the bytes (aliasing images and their views, texel views,
  the heap sets' elements) is made over the new pages only after `replace` has
  let go of the registry's lock. A hold in that gap pins the new pages over
  half-made state.
- W3: the render lowering thread does the same reads, later.
- W4: an encoding again (`replay.rs`) can run under a concurrent rebind of
  another thread. This one is a live defect under today's contract: a commit's
  rate-map or split re-encode, and one rebind's turn racing another buffer's
  rebind.
- W5: a texture made over the bytes during the call stays excluded.

The change: detect, then encode again. Nothing waits on the encode path.

- Each rebind's publish runs from `Rebinds::replace` to a new
  `Rebinds::published`. `published` is the close, after `renew_over`. It is
  tracked by a per-device count of closed publishes (`published`), a count of
  open ones (`open`), and `Entry::publishing` / `Entry::published`.
- Every encoder call loads that count as it begins (`Holds::begin_call`: one
  Acquire load of an AtomicU64). The sites: compute and blit `logged`,
  `end_encoding`, the five predication calls, render `Lowering::logged`, the
  deferral's `at_call_unit`, the replay dispatcher and `open_render`, which
  reads the count before it reads the attachments.
- A hold or pin finds the call raced when the entry's publish is open, or
  closed after the call began. A raced Taken counts as rebound
  (`Submitting::rebound`), so the commit encodes its encoders again before the
  first submission (`State::raced_again`), as for a rate-map reset.
- `reencode` loops: when an encoding again itself raced, it waits until no
  publish is open (`Rebinds::wait_published`, a condvar on `buffers`) and
  encodes again.
- The close marks again the command buffers committed while the publish was
  open, so their raced encoders are encoded again over finished state.
- An encoder the runtime cannot encode again whose call raced fails
  EncodedUseRebound at its submission. These are the existing list: a compute
  encoder its predication unit reaches past, one that left a GPU-written
  indirect dispatch to its host step, a blit or render encoder opened while no
  buffer over host pages existed, one whose commit fails it, and one with a
  call that answers otherwise. A rebind that no encode overlaps changes
  nothing for them.
- New WorkCounts::encoders_raced_rebind counts the encoders marked stale this
  way.
- `blit_at` holds the buffer before it reads its VkBuffer, because a copy run
  records in a later call.
- `replace` refuses a second rebind of a key whose publish is open
  (EncodedUses).

What the publish window covers:

- Inside it: `live_buffers.rebound`, the alias leave/hold/place, the image
  swaps and parking, the texel views, `forget_stale` and `renew_over`.
- Moved after the close: dropping the read twins (`drop(twins)`), dropping
  the old pages (`drop(old)`, which reaches vkDestroyBuffer/vkFreeMemory and
  the deallocator), `release_held_back`, `heap_sets::retire` and the
  encodings again.
- What a later pin judges against: the old pages' twins and the stand-ins.
- Not covered: the import of the new pages and the images made again over
  them before `replace`. These are the rebind's own and are invisible to
  other threads until `replace`.

Deadlock audit, by lock:

- `rebinds.buffers`:
  - `hold` and `pin` take `buffers`, then the cell's `pages` (`lying`), and
    hold nothing across them.
  - `replace` takes `buffers` -> `waiting` (`mark_waiting`) and `buffers` ->
    `pages` (`cell.replace`).
  - `published` takes `buffers` -> `waiting`. `mark_reencode` is an atomic.
  - No thread holds `waiting` or `pages` and then takes `buffers`.
  - The existing `state` -> `buffers` order (`encode_moved`'s `submitting`)
    is unchanged. Neither publish step takes a command buffer's state lock.
- `wait_published`: its callers hold only the command buffer's `reencoding`
  turn. These are the commit (after its state and slot locks are gone) and a
  rebind's or commit's `reencode`. No publish step takes a `reencoding` lock
  or waits for one. A publish waits for nothing: these take no lock an
  encoder holds across a hold:
  - `live_buffers.inner`;
  - `aliases`;
  - the image swap and view locks (`Image::swap_in`);
  - HostPages `parked`;
  - `rebinds.stale`;
  - the texel views;
  - `heap_sets`: `passing_hold` and `heaps`, whose writes are deferred while
    `heaps.holds > 0`, with no wait.
  So every wait ends as soon as the open publishes close.
- The test pause points (`rebind::pause`, cfg test) stop at the hold, with
  no runtime lock held, and in the publish after `replace` has let go of
  `buffers`.

Docs:

- The Safety text of Buffer::rebind_bytes_no_copy and
  Heap::rebind_bytes_no_copy states the new contract and outcomes. Still
  excluded: another rebind or a detach of the same buffer or heap, a texture
  made over its bytes, and a resource placed in the heap, during the call.
- The rebind.rs module docs gain an **Other threads** bullet.
- Also updated: the EncodedUseRebound declaration and its docs/API.md
  catalogue entry (the cost text is unchanged), the `renew_over` doc and the
  runtime README.
- api_signatures.tsv gains the new field.

Tests (src/tests/rebind_races.rs, device tests):

- A pause-point control at the hold: a dispatch that read the bound buffer
  before its hold, with a second buffer keeping the old import. Expected: the
  new page's output and one raced encoder.
- A pause-point control in the publish: a dispatch reading a texture over the
  buffer.
- A threaded run: four families (a dispatch of a texture over K, a draw with
  K as a vertex buffer, a blit copy from K, and a dispatch bound a call
  before) against a rebinding thread. Each output must be wholly one page of
  those K lay in meanwhile, or EncodedUseRebound.

Hot path: one Acquire load per encoder call (begin_call) plus one compare
under the lock the hold already takes. Per-call numbers follow in the bench
commit or report.

Also folded: the threaded run reports the pages its outputs read and each wrong output's reason
(060e8219f0); and a publish's close counts as a move (buffer::host_cells_settled), so a binding read
during the publish (a texel view for one) is not kept under the post-replace count and reused
by a later encoder that did not race; debug checks (check_reading, compute check_whole,
KeptSpaces::of) hold off where a call may have raced (rebind::call_may_have_raced, debug only)
(0c7a7a5c98).

Verified (lavapipe, msi): m3-max-37154 at 0c7a7a5c98: clippy plain and --cfg m2v_cpu_icd 0;
rebind*, pending_rebind, degradation*, argument_table, live_bind 41 passed; the hold and publish
controls raced 1 and completed; the threaded run (4 threads x 25 command buffers: a dispatch over
a texture over the buffer, a draw with it as vertex buffer 1, a blit from it, a dispatch bound a
call before) read every output wholly from one page, 0 EncodedUseRebound, 63 rebinds made, 1,537
refused (EncodedUses), 5 encoders raced, 11 encoded again. Negative control m3-max-37156 with
Entry::raced forced false: the hold control fails (the dispatch read the pages the buffer left).
2026-11-16 10:16:14 -08:00