Commit Graph
4624 Commits
Author SHA1 Message Date
Anees Iqbal c8d8a2063d An A8Unorm texture over a buffer that only reads takes R8Unorm's linear image, read through (0, 0, 0, R)
Where the device reports A8_UNORM's linear tiling without what its optimal
tiling has for the texture's usage, and R8_UNORM's linear tiling with all of
it (vkGetPhysicalDeviceFormatProperties2's linearTilingFeatures and
optimalTilingFeatures, read through linear_plan::linear_lack), an A8Unorm
texture over a buffer's bytes that only reads (no RenderTarget, ShaderWrite,
ShaderAtomic or BlockWritesOnly usage; one level, one sample; its alpha not
read as one, not rotated) is made as an R8Unorm texture's storage over the
same bytes: the image in place over host pages, an image aliasing the
buffer's memory, or that texture's shadow where it would be one. Its record
reads the image as R8Unorm through the swizzle metal::format::swizzle_over
composes ((Zero, Zero, Zero, Red) composed with the texture's own), as an
A8Unorm view of an R8Unorm texture is read (ViewRecord::read_as): the same
byte, the same filter, the channels moved by the view's component mapping.

NVIDIA's linear A8_UNORM has no sampling, linear filtering or transfer
features (the consumer's RTX 2080 walk kept 195 glyph-sized A8Unorm textures
over Shared buffers as shadows): those are now in place where an R8Unorm
texture's image is. A texture that renders or is written keeps the A8_UNORM
route. Buffer::texture_placement answers the same route.

Counted: WorkCounts::alpha_textures_held_in_red (api_signatures.tsv
regenerated). a8_over_buffers asserts no shadow and the device's own
A8Unorm texture's reads; device runs pending.
2026-11-12 08:57:12 -08:00
Anees Iqbal a400209ed3 Device tests: an A8Unorm texture over a buffer that only reads, and the shadows a driver's row layout leaves
a8_over_buffers: an A8Unorm texture over a Shared buffer and over a no-copy
buffer's host pages, read alone, is no shadow and reads (0, 0, 0, code/255)
through a kernel's read, as the device's own A8Unorm texture of the same bytes
does. It fails today where the device's linear A8_UNORM image lacks its
optimal image's features (NVIDIA): the texture is a shadow there.

shadow_causes_device: a probe of the shadows a consumer's RADV walks counted:
an RGBA16Float IOSurface plane at rows of 192 bytes, Managed RGBA8Unorm
textures at rows of 152 in 256, a BGRA8Unorm texture whose buffer ends inside
its last row, and dma-buf planes at rows of 384 and 1920 at offsets 0, 256 and
32; each case's placement and counts, its texels checked, and the driver's
answers for linear and DRM_FORMAT_MOD_LINEAR images at those pitches.

Not yet run: the device runs follow.
2026-11-12 08:57:12 -08:00
Anees Iqbal b2fa7e7da8 SEMANTICS_VERSION 2052: a generic pointer stored in a closed thread allocation and loaded back keeps its stores' space
The commits before this one extend canon::generic (SV 2049) to generic pointers that pass through thread memory: the struct fields of macOS 27's MPS NDArray kernels, which hold generic pointers stored through addrspacecasts or null and loaded back field by field.
- Each constant byte offset of a thread alloca is one slot. A load takes its slot's stores' space, and may be null only where a null is stored there.
- The cell stays a GenericPointer(Memory) refusal in two cases:
  - its address escapes: it is stored, cast other than by bitcast, passed to any call but memset/memcpy/memmove, or reaches a phi, a select or an aggregate;
  - its bytes are not disciplined: overlapping slots, a data write over a slot, or an unknown-offset access meeting any write.
- docs/FAST-PATHS.md's known gap and the Memory variant's doc say so.

The owned fixture generic_pointers gains generic_slots (a struct read by reference) and generic_fields (a struct passed by value), and the Metal probe gains the same kernels. The companions were regenerated on the M3.

Verified:
- runtime_lane::generic_pointers on lavapipe gives the M3 Max's words for both new kernels: 100+t, 201+t, 1 for t<4 then 4, and t (m3-max-21485).
- engine_generic_pointers passes (m3-max-21507).
- The AIR suite passes 553/553 and metal2vulkan-air clippy is clean (m3-max-21475).
- Of macOS 27's 590 MPS functions in release on RDNA3, 11 of the 16 Memory rows move (m3-max-21539):
  - 3 translate and pass spirv-val;
  - 8 now stop at a linked visible function, which is a pipeline input;
  - 5 stay Memory, because the cell's address goes into an unlinked visible-function call.
  The slowest row takes 1.21 s and the largest peak is 207 MB.
2026-11-12 08:52:33 -08:00
Anees Iqbal 12119c572d GenericPointer::Memory and the FAST-PATHS gap: memory other than a closed thread allocation's slots 2026-11-12 08:52:14 -08:00
Anees Iqbal 01191726ce generic_pointers: the AIR companions regenerated for the struct kernels' device-or-null pointer (m3-max-21474; Metal answers 1 then 4) 2026-11-12 08:52:14 -08:00
Anees Iqbal a5ae812630 canon::generic: a load from a thread slot may be null only where a null may be stored there
A generic pointer loaded from a cell's slot was taken as possibly null, so each space query of
it became a comparison with null. It is now possibly null only where a store into the slot (or
into the slot an unknown-offset access joins it to) stores a pointer a null constant may reach;
a slot no store has written reads an undefined pointer. A query of a pointer no null reaches is
answered outright, as for a pointer computed in registers. A memset of the cell is a write of
other bytes like any copy.

The struct kernels' third pointer is now in + 8 or null, a device pointer: the memory planner's
cells refuse a threadgroup global's address stored into a cell (Lowering(Access)), which the
lane run on lavapipe hit at the select of the threadgroup array or null.
2026-11-12 08:52:14 -08:00
Anees Iqbal ee42213298 engine_generic_pointers: the struct kernels compile on committed profiles 2026-11-12 08:52:14 -08:00
Anees Iqbal e0b4c26774 canon tests: a slot test reads the queries' words last, after the slots' stores 2026-11-12 08:52:14 -08:00
Anees Iqbal aacf76eb20 runtime_lane::generic_pointers: generic pointers a struct holds answer as Metal
The fixture's AIR companions regenerated for generic_slots and generic_fields (Apple metal
32023.922, macOS SDK 27.2, as TOOLCHAIN records). generic_slots stores three generic pointers
into the thread's struct and a noinline function loads them back by reference; Clang passes
generic_fields's struct as its scalar fields. The lane test compares both with what the M3 Max
answered through the probe (macOS 27.0.1, job m3-max-21439): t + 100, t + 201, 3 for t < 4 and
4 after (the third pointer threadgroup or null), and t.
2026-11-12 08:52:14 -08:00
Anees Iqbal c34e0cfd19 generic_pointers: two kernels that keep generic pointers in a struct, and their Metal probe
generic_slots stores three generic pointers (a device, a thread, and a threadgroup or null
pointer) and a count into a thread struct that a noinline function reads by reference;
generic_fields passes a copy of the struct by value. Each writes four words a thread: two reads
through the pointers, the third pointer's space, and the count. The probe runs the same source on
Metal (cases slots and fields). The AIR companions are regenerated in the next commit.
2026-11-12 08:52:13 -08:00
Anees Iqbal caa8c11776 canon::generic: a generic pointer loaded from a closed thread slot is in its stores' group
A generic pointer stored into an alloca and loaded back was refused as GenericPointer(Memory).
When every use of the alloca's address is visible (loads, stores, memory intrinsics,
comparisons and address arithmetic) and only generic pointers' bytes can be read as generic
pointers (slots do not overlap, no other write overlaps a slot or lands where the translation
cannot place it), each slot is a union-find node: a generic store joins its value's group and
the slot's, a generic load the slot's. A load at an unknown offset joins every slot of its cell.
A load from a slot may read a null pointer, so a space query of it compares with null. Any
other alloca stays refused as Memory. This is the shape of MPS's array_ref fields in
_MPSNDArrays under MSL 4.1.

Canon tests: a device pointer through one slot and through the first of two slots of different
spaces keeps its space; an unknown-offset load joining two spaces is TwoSpaces; a slot
overwritten by a float and an alloca whose address escapes to ptrtoint stay Memory.
2026-11-12 08:52:13 -08:00
Anees Iqbal 13e0a9b60b Golden re-bless at pin 54's candidate, 61e4df0491
The engine inventory, golden hashes and air_input printouts were re-blessed on the M3 at development 61e4df0491 (job m3-max-21541). The inventory, golden and printout steps each exited 0.

The only change is the icb_merged_attributes fixture, which SV 2051 edited: it has a new ima_strips kernel, and its source hashes changed. Its rows in golden_hashes.tsv and public_fixture_expectations_engine.tsv, and its printout, are replaced. No other fixture's row moved.

The merged check at the same sha passed (m3-max-21540).
2026-11-12 08:43:18 -08:00
Anees Iqbal d39be13ad5 Re-pin the runtime sources at the landing tip
The landed packet changed a runtime-sources input, so the committed digest no

longer described the sources and `the_runtime_sources_are_the_committed_ones`

would fail. Recomputed over the same inputs and committed by land-pkt.sh.
2026-11-12 08:42:24 -08:00
Anees Iqbal 095a0b8e9a RUNTIME_VERSION 2125: the tracker takes each batch as writing what its command buffer made resident for writing
The commits before this one fix a race in RV 2109's narrow host-step gate (522d56bb6c). A host step that runs an indirect command buffer's records waited only for the batches the tracker had last seen write them. A kernel can write those records from an encoder that never names the buffer, when another encoder of the same command buffer made it resident for writing (useResource WRITE in an empty compute encoder). In Metal, residency is the command buffer's. The tracker saw no write from the writer's batch, so the step could read the records before the GPU's writes landed. It then ran the CPU's records and drew the wrong pixels. runtime_lane::write_routes failed on that, at random: the race was exposed by 605b768750's pool take order.

Now the tracker takes each batch as writing every resource its command buffer made resident for writing. So the step's gate covers the writer's batch. Resources resident for reading stay narrow.

Verified on lavapipe (m3-max-21472):
- write_routes::a_slow_writer_s_batch_holds_the_execution_s_host_step drew red, the CPU's records, without the fix (at 44e3a43a85). It passes with the fix, and write_routes passes 4/4.
- depth_executions still narrows: "steps 2, gates narrowed 2".
- The lane set passes 113/113: frame_costs, render_merged_indexed, indirect_host_steps, render_executions, render_gpu_executions, kept and depth executions, argument_buffers.
- The runtime's tracker, residency, kept and host_step tests pass 150/150.

The earlier-command-buffer form (a_slow_writer_in_an_earlier_command_buffer_holds_the_execution_s_host_step) passed without the fix too. It guards the shape, but it does not prove the cross-command-buffer half.
2026-11-12 08:41:21 -08:00
Anees Iqbal 952755253f The tracker takes each batch as writing what its command buffer made resident for writing
Fixes a race behind runtime_lane::write_routes failing in the Before and After shapes since RV
2109 narrowed the host-step gate.

Cause:
- A host step's gate is the batches the tracker last saw write what the step reads
  (Tracker::last_writes over CommandBufferShared::step_reads): here, an indirect command buffer's
  records.
- Residency is the command buffer's (the 2026-10-07 ruling). So a kernel in an encoder that never
  names the buffer may write its records, once another encoder of the command buffer made it
  resident for writing.
- The tracker never saw that write, so the gate left the writer's batch out. The step could read
  the records before the kernel's write landed and run the CPU's records instead.
- 605b768750 changed timing enough to expose it. Metal's probe runs the kernel's command in both
  shapes.

Fix:
- At commit, State::resident_writes gathers every resource any ended encoder made resident for
  writing: a write of the whole resource in every stage (Residency::written_uses), read from the
  encoders' own residencies so no join is paid, with the host-memory aliases an encoder's tracked
  uses take.
- Each batch with a part plans those writes with its first part (submit.rs), and its footprint
  holds them (CommandBufferShared::footprint).
- They are joined as Summary::of_no_stage, which widens none of the stages the part's fence
  updates cover.
- The tracker then holds every batch of such a command buffer as their last writer. The gate
  covers the writer whether it is an earlier batch of the step's own command buffer or a batch of
  an earlier command buffer on any queue, and is_behind orders other queues' later batches that
  share the resource.
- Resources made resident for reading alone stay as they were.

Cost:
- Nothing for a command buffer that makes nothing resident for writing.
- Otherwise, per batch, one clone of the first part's summary with those uses joined.
- Under the exact batch order (lavapipe, MoltenVK): a barrier before the first part against an
  earlier batch's access of such a resource, and one before a later part of the batch that names
  it. Batches ordered by their ends (ANV, RADV, NVIDIA) need none across batches.
- A later batch of another queue that shares such a resource waits for the batch, as it waits for
  a named write.

Tests:
- tests::tracker::writes_of_no_stage_widen_no_fence_and_name_their_batch_the_writer.
- write_routes' two slow-writer lane tests from the commit before this one.

Verified: see the landing report for the runs.
2026-11-12 08:40:59 -08:00
Anees Iqbal 14c0b28928 write_routes: a slow writer's batch holds the execution's host step
Two lane tests for the narrow host-step gate's race (RV 2109).

- In the Before and After shapes, the only encoder that makes the indirect command buffer
  resident for writing has no command, and the kernel that writes the render command never names
  the buffer.
- Slow work goes first: 16 dispatches of irw_mark over 2^23 threads into a buffer of its own
  (Scene::slow). It keeps the writer's batch running while the execution's host step could read
  the records.
- a_slow_writer_s_batch_holds_the_execution_s_host_step: the writer is in the executing command
  buffer.
- a_slow_writer_in_an_earlier_command_buffer_holds_the_execution_s_host_step: the writer is in an
  earlier command buffer of the same queue, committed first.
- Both expect the kernel's green triangle, as Metal's probe runs the one-command-buffer shapes.
  The earlier-command-buffer shape is unprobed; its expectation comes from Metal's hazard
  tracking of the buffer.

Scene::render takes the slow work's placement; the existing test passes None.

Verified: the runs come with the runtime fix that follows this commit. Without that fix, both
tests are expected to fail with red, the CPU's records.
2026-11-12 08:40:58 -08:00
Anees Iqbal 61e4df0491 Re-pin the runtime sources at the landing tip
The landed packet changed a runtime-sources input, so the committed digest no

longer described the sources and `the_runtime_sources_are_the_committed_ones`

would fail. Recomputed over the same inputs and committed by land-pkt.sh.
2026-11-12 08:39:01 -08:00
Anees Iqbal 5766d29051 SEMANTICS_VERSION 2051, RUNTIME_VERSION 2124: executed draws whose states fetch stage_in attributes run on the GPU alone
The commits before this one. Running an indirect command buffer's draws on the GPU (the replay variant, and the merged form of SV 2045) refused any render state that fetches [[stage_in]] attributes. lower::access::plan_replay refused every vertex fetch under replay_bindings. So each such execution took the host step (HostStepCause::Refused), one round trip per execution. That is every GPU-driven renderer whose vertex function takes stage_in, reims's forward-rendering sample included.

Now:
- A draw replay pulls every fixed-function layout through the pulled-vertex-buffer variant (draw_replay_vertex_layouts: the layouts a replay pulls, and the rule that keeps a layout on the host step).
- The binder needs no bound encoder buffer for a pulled layout. Today's base plan fails with UnboundVertexBuffer when the encoder binds none, which is the usual case for GPU-driven rendering.
- plan_replay lets a drawn vertex function's pulled sources through.
- A pulled layout's own buffer is read through the command's slot table: a Psb slot read through its root entry, like every other buffer in a replay. Before this, it got a storage view that the replay never binds, and drew zeros.
- In the merged form, the pulled fetch reads the merged command's vertex, instance and base instance.
- A layout whose stride each bind sets (per-command strides) keeps the host step, because a command's stride lives only in its record.
- docs/FAST-PATHS.md says which attributes a replayed draw pulls.

Verified on lavapipe:
- runtime_lane::render_merged_attributes, for an ICB of draws and of indexed draws, with pulled and fixed-function layouts at step rates 1 and 2: before, (merged, gpu_form, records_read) was (0, 0, 4), the host step (m3-max-21242). After, it is (4, 4, 0) merged and (0, 4, 0) for strips, each equal pixel for pixel to a forced host step. The replay filter passes 195/195 (m3-max-21494).
- The metal2vulkan suite passes 3480/3486. The six failures are golden rows of new fixtures, re-blessed at the next pin (m3-max-21495).
- Validation's variants and draw_replay tests pass 10/10.
- clippy (default, --cfg m2v_gpu, --cfg m2v_cpu_icd) and fmt are clean (m3-max-21496).
2026-11-12 08:38:04 -08:00
Anees Iqbal 4c4a6d9e83 A replay variant reads a pulled layout's own buffer through its root entry
A source buffer no body access shares got its own storage view unless a BufferRangeLimit
variant named it, so under replay_bindings the fetch read a view the replay never binds
(zero positions: the lane's merged pulled draws drew nothing, m3-max-21283) while every other
slot read the command's slot table. Under replay it is now a device-address slot read through
its root entry. The replay compile test checks every buffer slot of the pulled replay variant
is Psb.
2026-11-12 08:37:43 -08:00
Anees Iqbal 039f6e5fbc FAST-PATHS: a replayed draw's attributes are among those the shader pulls
The GPU form of an execution's draws now pulls every attribute, so a normalized one there is
the module's product, as the vertex conversion row states for the other pulled attributes.
2026-11-12 08:37:43 -08:00
Anees Iqbal 515e8a1507 Tests: the replay compile test builds its shape in one initializer; the lane's per-bind flag no longer shadows strided()
Clippy (field_reassign_with_default) refused the compile test's shape, and the lane test's
local bool named strided hid the strided() helper (E0618). Found by m3-max-21257 and
m3-max-21259.
2026-11-12 08:37:43 -08:00
Anees Iqbal 5d598b85d2 A drawn vertex function's pulled sources pass the replay variant's check; the strided lane case asks for per-command strides
- lower::access's plan_replay refused any stage-input source (`sources`, which for a vertex
  function are its pulled attributes' buffers) besides a fixed-function fetch: the replay
  variant of a state whose layouts the replay pulls still failed with
  Unsupported(GpuEncodedIndirectCommands, NotImplemented)
  (pipeline::compile::tests::a_replayed_draw_reads_its_buffers_through_the_slot_table, job
  m3-max-21243). A drawn vertex function's sources are read through its slot table, so they pass;
  a kernel's stage-in fetch is still refused.
- runtime_lane::render_merged_attributes: the per-bind case's buffer sets
  supportDynamicAttributeStride, without which its commands' strides are a record the decode
  refuses (a replay fault in the host step, m3-max-21242).
2026-11-12 08:37:43 -08:00
Anees Iqbal 7cd885ea5b runtime_lane::render_merged_attributes: stage_in states' executions run on the GPU alone
The lane test of executions whose inherited state's vertex function reads [[stage_in]]
attributes now states the GPU form, against the host step's pixels (a barrier the CPU set and
cleared), for a kernel-written ICB of triangle draws and indexed draws (merged) and triangle
strips (one draw per command), each command binding its own positions and per-instance marks at
its own offsets, first/base vertex and base instance:

- pulled_attributes_of_executed_draws_fetch_their_commands_elements: strides 10 and 6, which the
  shader fetches anyway (merged draws read the command's vertex and instance, not the merged
  draw's corner indices);
- fixed_function_layouts_of_executed_draws_are_pulled: strides 8 and 4, marks at step rates 1
  and 2, no vertex buffer bound at the encoder;
- a_layout_of_a_stride_set_per_bind_keeps_the_host_step: a dynamic-stride position layout the
  commands bind at their own stride takes the host step, whose notice names the rule.

The fixture gains ima_strips (a triangle strip writer). docs/API.md states the attribute rule in
the indirect command buffer section and in the GPU form's list; api_signatures.tsv and
api_surface.rs list draw_replay_vertex_layouts.
2026-11-12 08:37:43 -08:00
Anees Iqbal fa36bcc433 Draw replays pull every fixed-function layout and take states that fetch attributes
An execution of GPU-written render commands whose inherited state's vertex function reads
[[stage_in]] attributes took the host step (DrawReplayRule::VertexAttributes, and the replay
variant refused any vertex fetch). Its commands bind their own vertex buffers, which
fixed-function input cannot fetch, but a pulled attribute reads its slot from the command's slot
table. So the replay now pulls every fixed-function layout through the pulled-vertex-buffer
variant and runs on the GPU, one draw per command or merged:

- Lowering: under replay_bindings a vertex function may fetch attributes all pulled
  (lower::access's plan_replay refuses only a fixed-function one). In a merged draw's vertex
  function the pulled per-vertex and per-instance steps read the corner's command's vertex and
  instance (Step::MergedVertex, Step::MergedInstance, from bind::merged_vertex), rate > 1
  dividing from the command's base instance: the merged draw's own VertexIndex and
  InstanceIndex count corners.
- Binder: a layout BindShape::far_vertex_buffers names is pulled whatever the encoder binds
  there, so it needs no bound buffer (no UnboundVertexBuffer for a GPU-driven encoder that binds
  none).
- Runtime: replay_draw_of sends a state with a layout of a stride set per bind to the host step
  (draw_replay_vertex_layouts' VertexAttributes), and far_vertex_buffers names every
  fixed-function layout in BufferForms::Replay and Merged, so the decision and the recording
  draw settle the same variant.
- Validation: compile_render_for_shape names the base's layouts in the replay forms' shape, and
  the device replay's drawn() checks the attribute rule on the variant.

Test: pipeline::compile::tests::a_replayed_draw_reads_its_buffers_through_the_slot_table now
also takes a stage_in vertex function through the base plan with its layout named and no buffer
bound, to the replay variant in both forms (no binding, the attribute pulled, L3, its plan
stating its key). The lane test follows.
2026-11-12 08:37:43 -08:00
Anees Iqbal cf082518ad draw_replay_vertex_layouts: the layouts a draw replay pulls, and the rule that keeps one
A draw replay's commands bind their own vertex buffers, which fixed-function vertex input cannot
fetch, but a pulled attribute reads its slot from the command's slot table. The new
bind::draw_replay_vertex_layouts names every fixed-function binding's layout of a state's vertex
input (the layouts the replay variant pulls, as the pulled-vertex-buffer variant does), and
DrawReplayRule::VertexAttributes now means what still keeps a state from the replay: an
attribute whose layout's stride is set per bind (a fixed-function binding's, or a pulled
attribute's that steps), which the binder writes from the encoder's bind where each command
binds its own. draw_replay_draw keeps its vertex_buffers guard.

Unit test: bind::replay::rules::tests::a_draw_replay_pulls_every_fixed_function_layout_of_a_static_stride.
Not wired yet (the binder, lowering, runtime and validation follow).
2026-11-12 08:37:43 -08:00
Anees Iqbal 22e0b39dc4 Golden re-bless at pin 53's sha, ef6ada57d5
The engine inventory, golden hashes and air_input printouts were re-blessed on the M3 at development ef6ada57d5 (job m3-max-21492). Each step exited 0.

Only new rows and files, with no existing line removed or changed:
- kernel_texture_unit_bit_test (SV 2050);
- generic_pointers (SV 2049), with its printout generic_pointers.txt;
- icb_merged_attributes (SV 2048 / RV 2119), with its printout icb_merged_attributes.txt.

They are added to golden_hashes.tsv and public_fixture_expectations_engine.tsv.

The merged check at the same sha passed (m3-max-21490: gpucfg clippy of five crates, api_signatures, api_surface, fast_paths, rustdoc).
2026-11-12 08:29:54 -08:00
Anees Iqbal ef6ada57d5 Re-pin the runtime sources at the landing tip
The landed packet changed a runtime-sources input, so the committed digest no

longer described the sources and `the_runtime_sources_are_the_committed_ones`

would fail. Recomputed over the same inputs and committed by land-pkt.sh.
2026-11-12 08:26:55 -08:00
Anees Iqbal 8f2ce49aa3 RUNTIME_VERSION 2123: one bound across every compute variant's region pipelines
The commits before this one. RV 2121 let each compute variant keep 256 region VkPipelines, and kept instances (KEPT = 256) keep what their memo held. With no bound across variants, an app with many partition-observing kernels at many widths could hold up to 65,536 pipelines: about 42 GB on lavapipe at about 650 KiB each, or at most about 33 GB of GTT on RADV.

Now pipeline/region_ledger.rs keeps one LRU of every region VkPipeline that a compute variant's memo keeps, kept instances included. It is keyed by (Instance, RegionKey) and bounded by DEVICE_REGION_PIPELINES = 512. Full, that is about 325 MiB on lavapipe and at most about 258 MiB of GTT on RADV.
- The bound is a count, because Vulkan documents no query of one pipeline's memory.
- A variant's memo reports keeps, lookups, evictions and removals to the ledger under the memo's lock. The ledger's lock is innermost.
- A live variant's evicted key leaves its memo at the next region-pipeline lookup, and is destroyed at its last release instead of being kept.
- A kept instance's evicted keys are pruned in Kept::settle, so Kept changes in program order.
- Evictions are counted in WorkCounts::region_pipelines_evicted.

Limits, in the module docs: a dispatch that reuses its encoder's planned or kept pipelines without a memo lookup doesn't refresh the LRU. An evicted pipeline lives until its last holder lets go.

Verified on lavapipe (m3-max-21473: 127/127, with clippy under --cfg m2v_cpu_icd and --cfg m2v_gpu):
- region_widths::two_kernels_past_the_device_bound_make_a_key_again_only_once_it_is_let_go, at a bound of 96, gives [made, evicted] per pass: A [64, 0], B [64, 32], B again [0, 0]. After A is released, Kept holds 32. B's widths 65 to 80 give [16, 16]. A remade gives [48, 48]. At most 96 are ever listed.
- region_widths with a single kernel still gives [128, 0].
- kept_variants, tile_rebind_making_wait, grid_widths, tests::making and the memo's watch test pass.
- Plain clippy and rustdoc are clean (m3-max-21461).
- RADV per-pipeline figures (780M, m3-max-21399, from RV 2121's measurement): about 3 us for a remake that the driver's cache serves, and at most about 516 KiB of GTT and 48 KiB of RSS for each pipeline kept.
2026-11-12 08:25:58 -08:00
Anees Iqbal e1d9acfdc3 Tests: the two kernels' test finds its store in the kernel's unindented text
The kernel's LLVM text is a string continuation, which drops each line's leading spaces: the
second kernel's text came out the same as the first's, which the test's own check caught on
lavapipe (m3-max-21459).
2026-11-12 08:25:38 -08:00
Anees Iqbal 2ff2140415 region_ledger: let go of past keys one at a time, the ledger's lock dropped before each memo's
Clippy's drain_collect refused draining the whole list into a new one; popping one key at a time
keeps the lock order (ledger's let go before a memo's is taken) without moving the list out.
The memo test's log is read by a copy and a clear for the same lint.
2026-11-12 08:25:38 -08:00
Anees Iqbal f1389d2dd0 DeviceShared: the region ledger is made before the line moves into the device
The ledger's counts were borrowed from the line's carried state after the line moved into the
struct literal (E0505). Verified by the lint job that follows.
2026-11-12 08:25:38 -08:00
Anees Iqbal 00d1b37232 One bound across every compute variant's region pipelines, kept instances included
Each kernel's variant keeps up to 256 region VkPipelines (REGION_PIPELINES), and a released
variant's kept instance kept every one its memo held, so a device's region pipelines had no
bound of their own: 256 kept instances of 256 each is 65,536 pipelines, about 650 KiB each of
resident memory on lavapipe.

The device now keeps a ledger (pipeline/region_ledger.rs) of every region pipeline a compute
variant's memo keeps, listed by the variant's instance and the region's key, the least recently
used first, at most DEVICE_REGION_PIPELINES (512: twice one variant's bound, so one kernel's full
memo leaves as many to the rest; about 325 MiB on lavapipe, at most about 258 MiB of GTT on RADV
by the figures REGION_PIPELINES's docs now carry). The bound is a count: Vulkan has no query of
one pipeline's memory (VK_EXT_memory_budget is per heap and process; the pipeline executable
statistics are optional, the driver's own, and name no memory).

- A variant's memo tells the ledger of each key kept, looked up, let go past its own bound and
  removed, under the memo's lock (memo::Watch, making::KeyWatch); the ledger's lock is the
  innermost.
- Keys past the device's bound go, counted in WorkCounts::region_pipelines_evicted. A live
  variant's is taken out of its memo at the next lookup of a region pipeline on the device
  (region_ledger::let_go, no memo lock held); a kept instance's is destroyed where the kept
  variants next settle on the program's thread (Kept::settle_let_go, at such a lookup or at a
  variant's making), so the kept variants change only in the program's order.
- A pipeline a memo or the ledger lets go is destroyed at its last release instead of kept
  (RawPipeline::doom): a kept instance holds only what its variant's memo held, each listed once.

Tests: region_widths::two_kernels_past_the_device_bound_make_a_key_again_only_once_it_is_let_go
(bound 96: the second kernel's 64 keys let the first's 32 oldest go and its second pass makes
none; the first released keeps the 32 listed, 16 more keys of the second let 16 of those go, and
the first made again takes back 16 and makes 48; the ledger never lists more than 96);
memo::a_watched_map_tells_each_keep_use_eviction_and_removal replaces the eviction-count test.
2026-11-12 08:25:38 -08:00
Anees Iqbal 7ef17497d3 Re-pin the runtime sources at the landing tip
The landed packet changed a runtime-sources input, so the committed digest no

longer described the sources and `the_runtime_sources_are_the_committed_ones`

would fail. Recomputed over the same inputs and committed by land-pkt.sh.
2026-11-12 08:02:07 -08:00
Anees Iqbal 30c2d07ae0 RUNTIME_VERSION 2122: a residency given nothing allocates nothing
The commit before this one fixes a regression from RV 2116 (c1a552215b). That change gave Residency an Arc<Held> field but kept #[derive(Default)], so every compute or render encoder open (CommandBufferShared::inherited) allocated an Arc for an empty residency. A pass open went from 4 allocations to 5, over frame_costs' bound of 4.5.

Now held is None until something is made resident. Reads see None as a static empty Held, and the first change makes its own Arc as before. kept_key answers one shared empty listing for an empty residency.

Verified on lavapipe (m3-max-21360):
- runtime_lane::frame_costs passes 2/2 at the parent of c1a552215b (m3-max-21337), fails with 5.00 allocations a pass open at c1a552215b (m3-max-21249), and passes 2/2 with this change.
- The wider lane set passes 106/107. The one failure is write_routes, a separate narrow-gate race fixed next.
- The runtime's residency, kept and host_step tests pass 76/76.
- clippy (all features, --cfg m2v_gpu, --cfg m2v_cpu_icd) and rustdoc are clean (m3-max-21384).
2026-11-12 08:01:10 -08:00
Anees Iqbal 9e3222d9f8 A residency given nothing allocates nothing: a pass open makes 4 allocations again
c1a552215b put a residency's resources behind an Arc<Held> and kept #[derive(Default)], so
every Residency::default() allocated an Arc for an empty Held. Every compute and render encoder's
open makes one (CommandBufferShared::inherited, Residency::shadows), so a frame's pass open made
5 allocations where frame_costs bounds it at 4.5 (lavapipe: 5.00, every open).

- Residency::held is Option<Arc<Held>>: None until the residency is given a resource;
  Held::changed makes its own Held at the first change, as it copied a shared one before.
- Reads go through Residency::held, which answers the static NOTHING for None.
- Nothing device-specific is shared: NOTHING's kept-key cache (the one field of Held tied to a
  device, through the views epoch it was listed at) is never written, because kept_key answers
  an empty residency with one empty listing (no resources, no keys) before it reaches the cache.
- find_shadowed borrows the field alone, so `shadowed` can change during the walk.

Verified: frame_costs' two pass-open tests on lavapipe, at the parent of c1a552215b
(m3-max-21337) and with this change, with the runtime's residency, kept and host-step tests (the
landing report names the jobs).
2026-11-12 08:00:55 -08:00
Anees Iqbal 7e0bc118f0 SEMANTICS_VERSION 2050: SCCP folds an operation over a value that is one of a few constants
The commits before this one. A fragment that GL-on-Metal emits for an omni-light shadow lookup picks its texture unit with a phi of three constants (5, 7, 8), then branches on a bit test of 416 by that unit, which every unit passes. The side that loses the test samples a cube from a texture2d_array parameter, and Metal never runs it. Our SCCP took a phi of different constants as overdefined, so it kept that dead side, and the render pipeline was refused at creation, Lowering(Texture) at air.sample_texture_cube.v4f32. This was reims's F17 #2: Unigine Valley through GL-on-Metal on the XTX, refused at every creation.

Now SCCP has a lattice level Set: one of up to 8 constants, interned.
- A phi whose entries are all literal constants merges them by union, and so does a select of two constants. Every other phi meets flat, where a Set entry counts as overdefined, so loop-carried values never become sets.
- A pure operation on Set operands folds each combination of members: at most 64 folds, metered. The result is a Set or a single constant.
- A branch on a Set is decided where every member decides it alike, and its dead way is deleted.

Also fixed forward from SV 2049: the AIR crate's api_surface rows for GenericPointer and PointerSpace, and a bitcode refusal test that used address space 8 (now decoded) uses 9.

Verified:
- The owned fixture kernel_texture_unit_bit_test.ll, with a phi-picked unit, a bit test and a cube sample on the dead side:
  - With sccp.rs as before, it is refused the same way (m3-max-21338).
  - With the change it compiles on lavapipe, amd-rdna3-radv and moltenvk-m3, with no cube sample left.
  - Its lane test on lavapipe stores the answers Metal's semantics give (m3-max-21367).
- The guest's module, linked with its vertex function offline on the M3 (release command line, RDNA3), was refused at __main block 68 inst 748 before, and passes spirv-val for Vulkan 1.2 and 1.4 after, in 0.28 s and 8.2 MB (m3-max-21344).
- Over macOS 27's 590 MPS functions, outcomes are identical and timing is unchanged (5.85 to 6.01 s in total; m3-max-21341).
- The AIR suite passes 552/552 (m3-max-21367), and clippy is clean (m3-max-21306).
2026-11-12 07:59:28 -08:00
Anees Iqbal ee323ead2f runtime_lane::texture_unit_bit_test: a texture slot is a u32
set_texture takes the slot as u32 (m3-max-21338's lane build).
2026-11-12 07:59:08 -08:00
Anees Iqbal 729912a69e ARCHITECTURE: SCCP's values of a few constants 2026-11-12 07:59:08 -08:00
Anees Iqbal 71c5b4b405 metal2vulkan-air: the generic-pointer surface rows, and a bitcode refusal test in space 9
Fix forward for SEMANTICS_VERSION 2049 (MSL 4.1 generic pointers): the AIR crate's own api_surface table lacked error::GenericPointer and intrinsics::PointerSpace, and bitcode::tests::unknown_and_unsupported_records_are_typed refused a global in address space 8, which now decodes as the generic space; it now takes 9, still outside AIR's. Both failed at 8557a75390 (m3-max-21338).
2026-11-12 07:59:07 -08:00
Anees Iqbal 3722e72ad6 engine_texture_unit_bit_test: compile first, so a refusal names itself
Without the SCCP fix the test failed on the printout's cube sample before compiling (m3-max-21305's negative control); compiling first makes the negative control show the refusal itself.
2026-11-12 07:59:07 -08:00
Anees Iqbal df3d33b569 SCCP: a PHI that meets flat takes a set entry as overdefined
random_bodies_settle_alike_under_both_meets (m3-max-21305) found a PHI whose incremental slot disagreed with the full meet: an instruction entry went from a constant to a set, the flat meet met the old constant with the set as Bottom, and the full meet over the entry's current value kept the set. Only a PHI of literal constants merges a few constants, so every other PHI now merges a set entry as Bottom, as it merges an undefined one: both meets then agree, and no set flows through a PHI an instruction feeds.
2026-11-12 07:59:07 -08:00
Anees Iqbal b0dfc39397 SCCP: a value may be one of a few constants
SCCP's lattice was flat: a PHI of three different constants was overdefined, so trunc (lshr 416, zext phi [5, 7, 8]) stayed unknown and a branch every member decides alike kept both ways. A GL fragment that emulates a cube texture as a 2D array has exactly that: the cube sample on the dead way samples a texture2d_array parameter, and the translator refused the pipeline as Lowering(Texture) at creation.

Lat::Set holds 2 to 8 constants (interned in the solver's Sets, so Lat stays 8 bytes). A PHI whose every entry is a literal constant merges as a set; a select between two constants on an unknown condition too; a pure operation over sets folds each choice of members (at most 64) and is the set of the answers, a constant where they agree. A PHI with an instruction entry still meets flat, so a loop's counter takes no more turns. A branch on a set takes every way. Canon tests constant_sets cover a decided and an undecided bit test.
2026-11-12 07:59:06 -08:00
Anees Iqbal 5eaeb5dc74 kernel_texture_unit_bit_test: a texture unit a switch picks and a bit test every picked unit passes
An owned, hand-written fixture in the shape a GL fragment's AIR takes where it emulates a cube texture as a 2D array: a switch picks a texture unit (a PHI of constants 5, 7, 8) and its texture (a PHI of three handles), and a bit test of the unit (trunc (lshr 416, zext unit)) picks a 2D-array sample or a cube sample of a texture the entry declares texture2d_array. Every unit passes the test, so the cube sample never runs. engine_texture_unit_bit_test expects the kernel to compile with no cube sample left; runtime_lane::texture_unit_bit_test expects each thread's folded texel of the texture its unit picks. Both fail until SCCP folds a value of a few constants (next commit).
2026-11-12 07:59:06 -08:00
Anees Iqbal 542b8e6759 Re-pin the runtime sources at the landing tip
The landed packet changed a runtime-sources input, so the committed digest no

longer described the sources and `the_runtime_sources_are_the_committed_ones`

would fail. Recomputed over the same inputs and committed by land-pkt.sh.
2026-11-12 07:56:54 -08:00
Anees Iqbal 1ad6fd6ad1 RUNTIME_VERSION 2121: a kernel's variant keeps 256 region pipelines
The commits before this one. A compute variant kept at most 32 VkPipelines, one per dispatch region. A partition-observing kernel dispatched at many widths (dispatchThreads(n, min(n, 64)): each width at most 64 is one region, and above that an interior plus an edge region) thrashed it.

In reims's Valley run on the XTX at a940fd546d, a GL-on-Metal index kernel that uses threadgroup memory and barriers had 190 keys. Each key was made about 6,300 times: 1.2 M VkPipeline creations in 146 s, and each such dispatch's batch waited for its making.

Now a kernel's variant keeps REGION_PIPELINES = 256 region VkPipelines. Render and tile-function variants keep PIPELINES = 32: a tile dispatch has no edges, and tile_rebind_making_wait relies on 32. The new WorkCounts::region_pipelines_evicted counts the pipelines any compute variant's memo lets go, through an Lru eviction hook.

The bound's memory cost, measured on lavapipe, is about 650 KiB a pipeline (JIT code), so about 160 MiB for a full memo there. The RADV figure is still to come. A kept kernel instance (kept.rs, KEPT = 256) keeps what its memo held.

Verified:
- tests/region_widths.rs on lavapipe, in debug. A kernel that reads thread_index_in_threadgroup, dispatched at n = 1..128 twice, checks each dispatch's words against Metal's gid % width.
  - At 8cf2089b44 it made [129, 129] pipelines and failed (m3-max-21348).
  - With the change it made [128, 0], evicted 0, and passed (m3-max-21362).
- In the same run, the Lru eviction unit test, tests::memo, grid_widths [1, 0] and the four tile_rebind_making_wait legs passed, 13/13.
- clippy (plain, --cfg m2v_cpu_icd, --cfg m2v_gpu) and rustdoc -D warnings are clean (m3-max-21373, 21374).
2026-11-12 07:55:55 -08:00
Anees Iqbal d933749703 REGION_PIPELINES: what a full memo costs on lavapipe, measured
The doc said a compute VkPipeline costs a few KiB, unmeasured. tests/region_widths.rs on lavapipe (m3-max-21362) grew the process's resident memory from 121,784 to 205,456 KiB across its 128 makings: about 650 KiB each (lavapipe JIT-compiles each pipeline), up to about 160 MiB for a full memo of 256. The RADV figure follows from a GPU run.
2026-11-12 07:55:36 -08:00
Anees Iqbal 2d8407c940 A kernel's variant keeps 256 region pipelines, counting those it lets go
What: a kernel's compute variant now keeps up to REGION_PIPELINES = 256 region VkPipelines
(was PIPELINES = 32, which render variants and tile functions' variants keep as before), and
every compute variant's memo counts the pipelines it lets go past its bound in a new
WorkCounts::region_pipelines_evicted (the memo's Lru takes an eviction hook,
Lru::counting_evictions; Making::counted_evicting).

Why: a guest's run on an RX 7900 XTX dispatched one index fix-up kernel as
dispatchThreads(n, min(n, 64)). The kernel observes its threadgroup partition, so it keeps the
exact split: a single region at each width 1..64 (MultiRegion 0) and, for ragged grids, the
interior of 64 and an edge at each remainder 1..63 (MultiRegion 1): about 128 region keys of
one variant. With 32 kept, the cyclic stream remade each key about 6,300 times in 146 s (1.2M
compute pipeline creations), each such dispatch's command buffer waiting for a pool making.
256 holds that measured working set twice over. A tile function's dispatch is one region of its
pass's threads per tile, with no edges, so its variant keeps 32 (tile_rebind_making_wait
crowds 33 keys to evict one).

Verified: tests/region_widths.rs (the stream above, twice, outputs checked against Metal's
gid % width) made [129, 129] VkPipelines at the parent on lavapipe (m3-max-21348, the control);
this commit's run follows in the report.
2026-11-12 07:55:36 -08:00
Anees Iqbal 9265667130 Tests: a partition-observing kernel dispatched at every width from 1 to 64 makes each region pipeline once
A device test of the dispatch stream a guest's index fix-up kernel made on an RX 7900 XTX: dispatchThreads of n threads in threadgroups of min(n, 64), n from 1 to 128, twice. The kernel reads thread_index_in_threadgroup, so it keeps its exact split: 128 region keys of one variant (a single region at each width 1..64, the interior of 64, an edge at each remainder 1..63). Each dispatch's words are checked against Metal's gid % width. The second pass must make no VkPipeline. It fails at this commit: the variant's memo keeps 32 VkPipelines, so the cyclic stream makes all 128 again; the next commit sizes the memo.
2026-11-12 07:55:35 -08:00
Anees Iqbal 8557a75390 SEMANTICS_VERSION 2049: MSL 4.1 generic pointers (AIR addrspace(8)) take the one space they come from
The commits before this one. The AIR that MSL 4.1 emits for unqualified pointers uses address space 8, the generic space. It reaches generic pointers through addrspacecast from the device, thread and threadgroup spaces, and answers air.is_device_pointer, air.is_thread_pointer and air.is_threadgroup_pointer. We refused all of it at decode, and so refused macOS 27's system convolution kernels on every device.

- AIR decode:
  - addrspace(8) decodes as AddrSpace::Generic;
  - the three queries decode as AirIntrinsic::PointerSpace.
- canon::generic: gives each generic pointer the one space every source of it shares.
  - A space query is answered from that space.
  - Where the pointer decides the answer structurally, the query takes that answer:
    - a variable's or global's address is not null;
    - a null constant is null;
    - `select c, var, null` makes the query `c`;
    - otherwise the query becomes `icmp ne p, null`.
  - Pointers that only the queries read are deleted.
- What we cannot give one space is refused as Feature::GenericPointer: TwoSpaces (the mixed case), Memory, Aggregate, Call or Integer. The refusal is located where the pointer takes that form. It is recorded in docs/FAST-PATHS.md's known gaps and docs/REFUSALS.md.
- A generic pointer that survives canonicalization is an invariant breach in the memory planner and in lower::select.

Verified:
- The owned fixture generic_pointers.metal, with its spaces, null and mixed cases and the Metal probe of the same kernels:
  - it compiles on lavapipe, RDNA3 and MoltenVK-M3, and the mixed case is refused as TwoSpaces (engine_generic_pointers, m3-max-21238);
  - runtime_lane::generic_pointers on lavapipe gives all 64 of the M3's words for spaces and its 32 for null (m3-max-21260, matching the M3's m3-max-20340 and 21124).
- canon generic_pointers, 4 tests (m3-max-21172).
- Clippy across the workspace with all features, rustdoc, api_signatures, api_surface, fast_paths and refusal_surface pass (m3-max-21238).
- macOS 27's AMD convolution kernels translate and pass spirv-val within 0.02 s and 10 MB, under the 26.x constants and under zeros (m3-max-21218).
- A census of macOS 27's 590 system functions that name addrspace(8): 115 translate, 124 are refused as Aggregate and 16 as Memory, and 0 hit TwoSpaces, Call or Integer.
2026-11-12 07:41:13 -08:00
Anees Iqbal 4ae5db434f runtime_lane::generic_pointers: the AIR library trait in scope
new_library_with_air is the validation crate's AirLibrary trait method (m3-max-21239).
2026-11-12 07:40:47 -08:00