Commit Graph
61 Commits
Author SHA1 Message Date
Anees Iqbal 472cfba642 Runtime: a viewport Vulkan takes in no form that covers no pixel of the render area draws nothing
set_viewport and set_viewports refused, as Gap::Draw of DrawKind::Viewport, every viewport that
VkViewport's valid usage forbids: an extent past maxViewportDimensions, a corner past
viewportBoundsRange (VUID-VkViewport-width-01771, -height-01773, -x-01774, -x-01232, -y-01775,
-y-01776, -y-01777, -y-01233), a negative width, and depths past [0, 1] (the runtime enables no
VK_EXT_depth_range_unrestricted). Metal documents no such limit. A user met the refusal four times
in one session, and a WebGL 1 page reaches it with a far gl.viewport: 32768 is the bounds range on
the 780M and Iris profiles, 65536 on NVIDIA's.

No other Vulkan viewport maps clip space as one of these does, since a viewport's transform is
fixed by its own origin and extent. But where such a viewport covers no pixel of Metal's render
area, Metal draws nothing through it, as the rt draws nothing through a viewport of no extent. So
checked() now keeps a viewport Vulkan takes as it is, makes one it does not take that covers no
pixel (viewport_pixels) a viewport of no width or height at the area's origin with its depths cut
to [0, 1], which Vulkan takes and whose draws record an empty scissor, and refuses the rest. With
the bounds Vulkan requires (at least twice the largest extent past either side of the origin) and
an area no larger than maxViewportDimensions, a viewport past the bounds within that extent covers
a pixel only where its edge lies inside the last pixel of an area of the largest size; WebGL's
integer origins never do. What stays refused: a negative width over the area (Metal mirrors it), a
depth range past [0, 1] over it, an extent past maxViewportDimensions over it, and that last-pixel
edge. DrawKind::Viewport, set_viewport and the runtime README (Render encoders, and its known gaps)
say so. docs/REFUSALS.md regenerates unchanged: the Gap::Draw row and its checked() site stay.

The refusal test's mirrored viewport now lies over the target (origin x 4, width -4); at origin 0
it covered no pixel and now draws nothing, as Metal's. The new test also sets a mirrored viewport
and one with depths past [0, 1], both off the target.

Verified:
- Red: the test commit 17aa4279b3 on lavapipe (job m3-max-78333): 0 passed, 1 failed, at
  draw.rs:501, the set_viewport of the first far viewport.
- Green, this commit's tree (fd7df2eccb), run as a scratch commit of the same tree: lavapipe (job
  m3-max-78345) 3 passed, 868 skipped: the new test, the triangle test and the refusal test, under
  the validation layer, "10 viewports past bounds [-32768, 32768] and dimensions [16384, 16384]
  drew nothing". The same three tests from one msi-built gpucfg archive under the carried
  validation layer 1.4.363.0, each 3 passed, 870 skipped: Radeon 780M, RADV, Mesa 26.2.6 (job
  m3-max-78347, bounds [-32768, 32767], dimensions 16384); Iris Xe, ANV, Mesa 26.2.6 (job
  m3-max-78348, the same limits); RTX 3090, NVIDIA 620.70.06 (job m3-max-78349, bounds
  [-65536, 65536], dimensions 32768); RX 7900 XTX, RADV, Mesa 26.2.6 (job m3-max-78350, bounds
  [-32768, 32767], dimensions 16384).
- Job m3-max-78346: clippy -D warnings on metal2vulkan-runtime, all targets and features, plain,
  --cfg m2v_gpu and --cfg m2v_cpu_icd, each exit 0; the runtime's whole suite on lavapipe, 868
  passed, 3 skipped. Job m3-max-78371: the runtime's rustdoc with warnings denied, public and with
  private items, 0 diagnostics. scripts/api-signatures/signatures.py --check and
  refusal_surface.py --check pass. cargo fmt --all.
2026-12-02 06:15:13 -08:00
Anees Iqbal 23847fe2ae Runtime: a pass that mixes a marked surface plane with another attachment renders it through a stand-in
A surface plane in place whose format's LINEAR tiling renders only through
VK_FORMAT_FEATURE_2_LINEAR_COLOR_ATTACHMENT_BIT_NV (VK_NV_linear_color_attachment: such a
format renders "as long as all the color attachments in the render pass instance have
VK_IMAGE_TILING_LINEAR tiling") was refused in any pass that set something beside it,
Gap::LinearPlanePass. A guest met it: a view of an exported 1920x1080 surface's R8 luma plane as
colour 0 beside an ordinary RG8 texture as colour 1, both loaded and stored. Red on the RTX 5080
Laptop GPU (job m3-max-78092) and the RTX 3090 (job m3-max-78106, NVIDIA 620.70.06).

The planner's ruling, form (ii): in a pass that mixes a marked plane with another attachment (a
colour attachment that is not one, a depth or stencil attachment, or a multisample attachment
resolving into it; decided by the format query's mark and the pass's attachments alone,
pass::mixes_linear), each marked colour attachment and each marked resolve target renders into
its stand-in, an optimal image of the runtime's of the plane's format and size
(TextureObject::stand_in). The pass's begin moves the stand-in from undefined and, where the
plane's Vulkan load op is LOAD, copies the render area of the plane into it; its end copies the
stand-in's render area into the plane where its store op is STORE or the pass resolves into it.
The plane stays general. A pass of marked planes alone still renders them in place; a device
whose LINEAR tiling offers the format as a colour attachment renders the plane in place in every
pass.

Counted: Metrics::plane_copies_in, plane_copy_in_bytes, plane_copies_out, plane_copy_out_bytes
(in bytes_copied too). The guest's pass pays both: its luma plane is loaded and stored, so each
run copies 2,073,600 bytes in and 2,073,600 bytes out. The stand-ins are bounded by structure,
one per (plane image, format), made at the first mixed pass and freed with the plane
(StandIns, Free::StandIn), counted in Gauges::plane_stand_ins and plane_stand_in_bytes, which
each_device checks are zero at the device's drop. A draw of such a pass that reads the plane
through a texture, or fetches it, stays refused: Gap::Draw of AttachmentRead or
FetchedAttachment (the plane holds what the pass rendered only after its end); a read of another
plane of the same surface is not.

Gap::LinearPlanePass and LinearPlanePassKind are gone: every kind (OtherColor, DepthStencil,
Resolve) renders. AGENTS.md's rule 2 grows to thirteen forms with the mixed-pass entry; the
runtime README's exported surfaces, floor and render encoder known gaps say the form and its
cost; docs/REFUSALS.md and the signatures table are regenerated.

Tests: the plane tests assert the plane copies (none in place; one out for a cleared plane
beside a colour or resolved into; one in and one out for the loaded plane beside a depth
attachment and the guest's pass), and a new test runs eight mixed passes over one plane: one
stand-in where it is marked, none elsewhere, freed when the surface drops. The unit test of
mixes_linear replaces linear_shape's. Device runs follow in the lane's report.
2026-12-02 05:39:50 -08:00
Anees Iqbal 7adf1d6603 Runtime: a command marks its Managed-over writes and takes their copies back in its own segment, after its command buffer begins
A command encoded right after encodeSignalEvent marked what it did to textures over a Managed
buffer's device copy (managed_reach, wrote_managed, wrote_texture_managed) in the segment the
signal ends, before ordered_command split the recording there. That segment goes in a submission
of its own ahead of the command's, so on a device with two copies a write's copy in was taken
before the write ran and never after it (a fill of the buffer, then every later reader of the
texture read the bytes from before the fill), and a texture write's copy back was made before the
write. And managed_reach took the copy back owed by a write earlier in the command buffer before
managed_backs began the command buffer, so a begin that failed dropped it for good.

Building::open_segment makes the current segment the command's (a new one past a signal) and
begins its command buffer, with what is owed left owed. The blit copies, fill, mipmap chain and
synchronize, and the dispatch, call it before their first mark; a render pass's begin marks its
attachments after its ordered_command instead, so whether it opens its command buffer, which
spares its first barrier, is read as before. No public change and no new form.
2026-12-02 03:20:20 -08:00
棠渚听潮 9826aa708b Submit aligned render push constant deltas
Track the last push length and record only the changed words for a draw. Keep Managed index and slot reaches on the full draw path, and leave device-wide alias and unslotted reads to the existing post-update checks.

Verified with cargo fmt and runtime Clippy, 207 runtime unit tests with the existing CRLF-sensitive stage test skipped, and the draw-offset regression on Intel Arc B390 including a Managed copy back.
2026-12-02 16:38:05 +08:00
棠渚听潮 d17046ea81 Update render buffer offsets without rebuilding push data
Reuse retained buffers for offset-only binds and track changed slots by stage. Patch indexed push fields and fixed-function bindings for eligible direct draws, and use full validation and filling when the draw cannot reuse them.

Verified with runtime clippy, the 207 lib tests in a temporary copy with LF in stage.rs, and the offset regression on Intel Arc B390.
2026-12-02 16:38:05 +08:00
Anees Iqbal 80ecfdab4a Runtime: draw a state whose colours past the pass's last attachment the pass lacks
A pipeline state that names colours past its pass's last colour attachment, its
formats up to that attachment, its depth and stencil formats and its raster sample
count all the pass's, was refused at the draw as DrawKind::AttachmentFormats. Plain
Metal draws it (pass-pipeline-color-unattached, the Apple M3 Max, job m3-max-75903):
the attachments it has hold the fragment's values, and its validation alone stops it.

set_render_pipeline_state now binds, for such a pass, the state of the descriptor
without those colours (RenderPipelineState::without_colors): a content of its own in
the device's map of contents, lowered on the calling thread where the device holds
none, its fragment function storing those colours nowhere as for any descriptor that
leaves them unset, its samplers numbered at the state's indices, and its pipeline made
by its first draw (a first-use wait). That content renders into the pass under the
exact match draws already take, so no new attachment rule enters a pipeline's make. A
state that renders into its pass takes the same path as before: one renders_into and
the lend. Each state now keeps the descriptor it was made of.

A colour the state names before the pass's last colour attachment that the pass
leaves unset stays refused: plain Metal writes the next colour's value into the
attachment after it (pass-pipeline-color-unattached-between, job m3-max-75934). So do
another format, a depth or stencil format the pass lacks and another sample count.

Test: tests/unattached_colors.rs. Verified: formatted only; the device runs follow.
2026-11-26 20:25:14 -08:00
Anees Iqbal c2fc914a3e Translator and runtime: a kernel's buffer arguments as set-0 storage buffers under robust buffer access 2
The twelfth form a Vulkan query chooses. Under the identity domains, on a device that answers
five queries (DeviceProfile::binds_kernel_buffers: pipelineRobustness enabled,
robustBufferAccess2 supported and not enabled, robustBufferAccessUpdateAfterBind,
maxPerStageDescriptorStorageBuffers >= 31, and maxStorageBufferRange holding a 2 GiB buffer with
the max(minStorageBufferOffsetAlignment, 16) - 1 bytes a descriptor starts before it), a kernel
reaches each buffer argument through its storage view, a storage buffer of set 0 bound over its
buffer, in place of its device address with each run-time-offset access checked in the shader.
The pipeline's robust buffer access 2 (VkPipelineRobustnessCreateInfo, storageBuffers) contains
the view: a load or store of a view is not checked in the shader; an atomic is, against the
view's array length (RBA2 leaves an out-of-bounds atomic's result undefined). A slot a wide
pointer, a typed atomic or the stage-in fetch reaches, and one the dispatch binds below its
argument's alignment (word_bound_buffers), keeps its device address; render stages keep theirs.

Translator: VK_EXT_pipeline_robustness and its feature, robustBufferAccess2 and
robustBufferAccessUpdateAfterBind and robustStorageBufferAccessSizeAlignment in Limits,
RuntimeFact::RobustStorageBuffers (Mechanism::PipelineState), the bound slot's
AddressAlignment fact so the runtime checks its address, DeviceProfile::buffer_base_alignment;
SEMANTICS_VERSION, ARTIFACT_FORMAT_VERSION and RUNTIME_VERSION bumped.

Runtime: the optional extension and feature in the floor; set 0's layout of 31 compute storage
buffers where the profile binds (one pipeline layout); every kernel pipeline made with the
robustness there, the stage helper's too; Interface::views and FieldValue::BindOffset; each
dispatch's descriptors (a buffer over its own bytes from its first byte rounded down to the
base alignment, a set_bytes copy over its bytes at the ring's alignment, nothing bound a null
descriptor), bound from a set the command buffer wrote last where they begin it, else from the
next set of its pools (crate::bound, mirroring the occlusion pools: 256 sets a pool, 16 kept
free); the ring's writes at the buffer base alignment; Metrics bound_dispatches,
address_dispatches, buffer_sets_written, buffer_sets_held and Gauges buffer_set_pools.

Verified: nothing yet; the first build follows on this branch.
2026-11-26 05:04:53 -08:00
Anees Iqbal 0b7d408201 Runtime and replay player: count barriers by cause, the guest's blits and buffer binds, and over-copy bytes by frame
What:
- Metrics counts every barrier in one of seven causes, whose sum Metrics::barriers now is:
  pass_start_barriers (a render pass's first), pass_home_barriers (the move of its attachments
  home at its end), blit_barriers, dispatch_hazard_barriers (a dispatch's own, at a hazard or
  paying one owed), segment_end_barriers, upload_barriers (the uploads' and Managed copy-ins'
  barriers, the over copies they carry among them) and other_barriers (inside a pass, over
  copies in a command buffer, heap moves ahead of a command or segment, releases). Metric::Barriers
  is gone: each site that records a barrier counts its cause, and the shared helpers
  (Building::barrier, alias::record, over::record_side) take the cause from their caller.
- The replay player's executed counters carry the seven, so each frame line prints them.
- The player's stream counts (the guest's, fixed by the stream) add blits, an encoder's copy,
  fill, mipmap, synchronize, reset and optimize commands, and the buffer slots the set-buffer
  calls set on render and on compute encoders, each split into buffer changes (another buffer
  than the slot held, or its first set) and offset-only changes (replay/binds.rs).
- The runtime backend's report adds an `over copies by frame` line: over-copy bytes a frame,
  mean and largest frame, by memory class (Private, Shared) and by cause (pitch, dma-buf, host
  memory, every other cause as own_image), and the number of textures in an image of their own
  the largest frame's calls named (new_runtime/over_frames.rs), from counters the runtime keeps.
- docs/REPLAY-STREAM.md and the runtime README name them; the signatures table blessed (7 fields).

Why: the planner's reading of round d9b644bae7's plays: whether pass-boundary and blit barriers
are half or more of a frame's barriers (the two pass forms), and whether over copies of Private
buffers reach 1 MB or 5% of a frame's copied bytes (the third form), needs the barrier split and
the over-copy split a frame, beside what the guest asked for; the guest's buffer binds per draw
and per dispatch size the descriptor work.

Tests: every_barrier_rt_records_is_counted adds a pass over a texture whose home is shader-read
and checks each cause's count against the barrier commands recorded (pass start 1, pass home 1,
blit 2, dispatch hazard 0, segment end 1, upload 6 or more, other 0);
every_device_places_barriers_at_hazards_only checks the dispatch-hazard and segment-end counts on
dependent, independent and concurrent encoders;
every_device_reads_its_attachment_through_a_texture_after_a_memory_barrier checks the causes on
the feedback-loop and the copy path; the player's
the_stream_fixes_its_calls_commits_encoders_draws_dispatches_blits_and_binds checks blits and
every bind count; over_copies_by_frame_give_the_mean_and_the_largest_frame checks the line.
2026-11-25 23:55:46 -08:00
Anees Iqbal 8c3bffc079 Runtime: count over-copy bytes by the buffer's memory class, and the renderings an encoder ends and begins again
What: two counters, so reach is counted rather than guessed.
- Metrics::over_copy_bytes_private and Metrics::over_copy_bytes_shared split over_copy_bytes by
  the memory class the bytes shaders reach are in (MemoryClass of the buffer's block; a Managed
  buffer's device copy counts in neither). OverCopy carries the class; Counters::over_copied
  takes it.
- Metrics::rendering_interrupts counts each vkCmdEndRendering and new vkCmdBeginRendering inside
  one render encoder (RenderCommandEncoder::interrupt, its one site): barriers, copies a draw or
  a visibility result mode needs first, feedback and heap moves, an execution's count kernel.
  The passes counter counts encoders and cannot show these.
- The replay player's executed counters carry the three, so every play's frame lines print them;
  docs/REPLAY-STREAM.md and the runtime README name them; the signatures table blessed (3 fields).

Why: the per-frame counts of round d9b644bae7's plays put over-copy bytes at 4.87 MB a frame on
the desktop stream (5080) and 34.5% of bytes copied on the 780M recording (Iris), with no way to
tell how much lies over Private buffers, whose bytes no host write reaches; and no counter shows
how often a render encoder's rendering is cut.

Tests: each_memory_class_counts_its_copies_bytes_alone (device-free); the device test
every_device_counts_each_textures_copies_under_its_cause checks the class split for each copy
and adds a texture over a Private buffer (pitch cause on lavapipe);
every_device_reads_its_attachment_through_a_texture_after_a_memory_barrier holds the count at 2
on both the feedback-loop and the copy path.
2026-11-25 23:24:36 -08:00
Anees Iqbal 412bce0bd5 Runtime: a coherent device's command buffers carry one None pointer of coherence, boxed
The planner's form A after the XTX budget job 74002 read burst_2000 as a loss (+139 user-space
instructions a command buffer at 3363435164). A device whose Shared type is host-coherent now
moves 8 bytes of coherence state with each command buffer and each batch instead of 40 and 48,
and three further items are development's own code again.

What a coherent device's command buffer did that development's does not, before this commit
(at 3363435164), with its cost and what this commit does:
- command.rs:300 `Gpu::coherence: Option<coherence::Recorded>`, 40 bytes (atom 8, the Writes
  Vec 24, reach 8), inside `Building` too. With one compute encoder a command buffer moves it
  by value about 14 times: into its Arc at the make (command.rs:413), open_encoder's take into
  the encoder (command.rs:470, encoder.rs:476), the encoder's take at its end (encoder.rs:1053),
  close_encoder (command.rs:484), the commit's take (command.rs:690), `Pending { gpu }`
  (command.rs:719), `Work::commit` into its entry (submit.rs:1604), `group.finished`
  (submit.rs:1999), the completion's `Retiree { Item::Command { gpu } }` (complete.rs:340) and
  its pop, and `retire(gpu)` (command.rs:1782). That is about 2-4 instructions a move for 40 more
  bytes. NOW `Option<Box<Recorded>>` (command.rs:301), one pointer, `None`; the box is made at
  the make on a device that is not coherent (command.rs:410, `Coherence::recording`). It is made
  at the make, not at the first write: a lazy box would need each recording site to read the
  device's coherence through its core, or an atom kept outside the box, and the commit still
  finds a reach from kept buffers with no write.
- submit.rs:546 `Batch::flushes: Option<Flushes>`, 48 bytes (two Vecs), moved with each batch.
  NOW `Option<Box<Flushes>>` (submit.rs:548), one pointer, `None`, boxed at the batch's first
  reach or copy-in (submit.rs:1924, 2068).
- counters.rs:661 the five coherence counters sat after `submit_infos`, moving every later
  counter 40 bytes from its place in development, including the submit thread's
  `submit_call_nanos` and the lock-wait counters (a layout change, no instruction). NOW they
  follow every other counter (counters.rs:892), so every development counter keeps its offset.
- encoder.rs:1223 and render_encoder.rs:2466, the dispatch's and the draw's facts: two tests
  (the encoder's recording, then its coherence) where development tested nothing. NOW
  development's `facts.host` is tested first (encoder.rs:1225, render_encoder.rs:2468), so a
  kernel or draw that writes no memory the host reads takes that one test.
- command.rs:1806 the retire: one test of the `None`, then its drop glue at the destructure, a
  second test. NOW the field moves out once (command.rs:1813) and the one `if let` takes it, so
  a `None` is tested once; `Gpu::is_empty`'s body is `nothing_for_the_gpu` over the segments, so
  the retire reads them past that move.

Left on a coherent device, each development's code behind one test of a `None` pointer: the
make (command.rs:410), the commit (command.rs:671), each command site (blit.rs:250, 495, 623,
745, 902, 1118; render_encoder.rs:901, 1618, 2041; encoder.rs:880; and the facts sites above),
the segment join (submit.rs:1923), each copy-in (submit.rs:2067), the submission
(submit.rs:2713), the retire (command.rs:1813) and each completion wake with listeners
(complete.rs:766); about 2-3 instructions each. The 8-byte pointer in `Gpu` (and so in
`Building`) and in `Batch` moves with them. Not per command buffer: each event's `settled`
field and a staged span's memory and size.

On a device that is not coherent the calls and ranges are as before; each command buffer
allocates its box at its make, and each batch at its first reach or copy-in.

Verified: cargo fmt. Not built when committed; the build job and the device and budget jobs
that follow name it.
2026-11-25 14:24:29 -08:00
Anees Iqbal 300747079a Runtime: a coherent device's command buffers hold no coherence state, behind one test each
On a device whose Shared type is host-coherent, the per-command-buffer path is development's
own code behind one test of an Option; nothing is built for the absent state.

Built per command buffer before, on a coherent device:
- an empty `coherence::Writes` and an `Option<Arc<Ranges>>` of `None` in its `Gpu`, built at its
  creation, carried to its retirement and dropped there;
- at every command that names a Shared write (each blit, render pass attachments, a render
  encoder's Shared buffer store, a dispatch's or a draw's facts, `use_resource`), a read of the
  device's `nonCoherentAtomSize` through the device's core; in both `use_resource`s a range
  slot in the declaration's tuple, filled through `Option::and_then`, and a call that tested it
  and returned;
- in each submission group and empty batch, two empty lists (the ranges of the command buffers
  reached and those of the copy-ins), destructured at submission, the first dropped there;
- on the completion thread, a tuple of two tests at each wake that fires listeners;
- in a shared event's `signaledValue` and wait, development's code restructured: the lock
  taken and dropped before the counter's read, and a call that tested the device's Option.

Left on a coherent device:
- the `Gpu` holds one `Option<coherence::Recorded>`, `None`, from one test of the device's
  coherence at the command buffer's creation; each command site tests it once
  (`Building::coherence`, a field of the recording), each `use_resource` keeps development's
  tuple and tests it once after the access;
- the commit, each segment that joins a group and the retirement test it once; a batch holds
  one `Option<Flushes>`, `None`, tested once at submission; each copy-in tests the device's
  coherence once;
- the completion thread tests the device's coherence once per wake that fires listeners;
- `signaledValue` and the wait are development's code behind one test of the device's
  coherence (`let`-`else`, `match`); each event keeps an 8-byte `settled` field, 0 and never
  read;
- not per command buffer: a staged copy's span carries its allocation's memory and size, and
  `replace_region`, `upload_region` and `get_bytes` test the device's coherence once each; the
  zero source's make takes one flag.

A device whose type is not host-coherent records into `coherence::Recorded` what the two
fields held, and a batch builds its `Flushes` only where one of its command buffers or copy-ins
reaches Shared memory; the calls and their ranges are as before.

Test: the device test of each device's coherence state now asserts that a new command buffer
holds the state exactly where its device does.

Verified: cargo fmt. Not built when committed: no build runs on this host; the build job and
the device jobs that follow name it.
2026-11-25 14:24:29 -08:00
Anees Iqbal 31ca7f6779 Runtime: Shared coherence only where the Shared type is not host-coherent, decided at the make
What: Device::new reads the HOST_COHERENT flag of the memory type floor::choose took for Shared
once, at the make (Coherence::of). Core::coherence is now an Option<Coherence>, built only where
that type lacks the flag. A device whose Shared type is coherent keeps no ranges and makes no
flush or invalidate: every site of the flush form asks the Option first (Building::atom now
answers Option<u64>), so a commit finds no Ranges, a retirement, a submission, a shared event's
signal seen, replace_region, upload_region, get_bytes and the zero source's make each make no
call, and the encoders name no write. flush and settle are now methods of Coherence, so only a
device that holds one can make them. The type rule stays sharedflush's: the first host-visible,
host-cached type, a coherent one first. Where the type is not coherent the form is unchanged.

The flush and invalidate on a coherent type are legal (vkspec 1.4.366, "Host Access to Device
Memory Objects"): "If the memory object was created with the VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
set, vkFlushMappedMemoryRanges and vkInvalidateMappedMemoryRanges are unnecessary and may have a
performance cost." The VkMappedMemoryRange VUIDs name no type flag: memory-00684, size-00685,
size-00686, offset-00687, size-01389 and size-01390 (offset and size at multiples of
nonCoherentAtomSize or the allocation's end, inside the mapped range). So the device suite can
run the form on memory that is coherent in fact, through the test-only memory view.

tests::coherence: every device holds a coherence state exactly where its Shared type is not
coherent, and its work's calls follow (zero calls where it holds none); every GPU read through
the refused device's view (crate::tests::cached_types_incoherent) holds it and makes sharedflush's
counted calls. README, the Metrics docs, floor::SHARED_MEMORY and MemoryClass::Shared say the
calls happen only where the type is not coherent; the known gaps say no lab device can show a
missed flush, only a device whose Shared type is cached and not coherent can.

Why: sharedflush's form, with its calls on every device, cost 1.038 to 1.047 of the runtime's
instructions on four harness rows on the 780M (m3-max-73790). This is A-narrow, offered to the
owner beside B: an eleventh form, so it does not land without his word.

Verified: not yet run (cargo fmt only).
2026-11-25 14:24:29 -08:00
Anees Iqbal 2c4680acea Runtime: Shared storage takes a host-cached type, flushed and invalidated on every device
What: the floor's Shared item becomes host-visible and host-cached; Shared storage takes the
first such type a buffer can use, a host-coherent one first (floor::choose). A new module,
coherence, makes the flushes and invalidates Vulkan asks of a type without
VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, on every device, never reading the type's flags:

- before each submission, a flush over the Shared memory its command buffers keep (buffers,
  textures over buffers, heap blocks) and the ranges its Managed copy-ins read;
- before the host can see GPU progress, a flush then an invalidate over what a command buffer
  may write: as it retires (before its status, waits and completed handlers), and over every
  command buffer in flight before a shared event's GPU-raised value reaches a listener,
  signaledValue or a wait. What it may write: blit destinations, written bindings of the
  function's interface, use_resource with a write, render attachments, the visibility buffer,
  synchronize targets, every used heap's Shared block, textures over Shared buffers in images
  of their own;
- the runtime's own accesses: replace_region's staging span flushed after the rows are
  written, get_bytes's span settled before it is read, the zero source flushed at its make.

Ranges are widened to nonCoherentAtomSize inside the whole-mapped pool blocks. Imports are
unchanged (their type is host-coherent; Vulkan maps none of them). Exported blocks and surfaces
take the Private type and have no host mapping (export.rs, surface.rs), so they are never
flushed. Metrics gains shared_flushes, shared_flushed_bytes, shared_invalidates,
shared_invalidated_bytes and shared_coherence_failures.

Why: a Meteor Lake device on Mesa's Intel driver with the i915 kernel driver lists
[DL|HV|HC, DL|HV|HCached] and has no host-visible, host-coherent, host-cached type, so the
floor refused it at device creation. The lab's lists all have an HV|HC|HCached type, which
choose() still takes first: their index is unchanged.

Verified: not yet run (cargo fmt only). Still to come in later commits: README, the generated
refusal surface and signatures table, a device test of the counters, and the device legs. The
flush's effect on that device is unaudited until the user boots it.
2026-11-25 14:24:28 -08:00
Anees Iqbal 5a722b5c3f Stencil output: a device without VK_EXT_shader_stencil_export draws it by bits, the owner's tenth form
A fragment function's [[stencil]] output is the reference of both faces' stencil test for its
fragment (MSL Table 5.7, 5.2.3.5). On a device without VK_EXT_shader_stencil_export it was refused
at creation (StencilExport). Under the owner's grant (rule 2's tenth form, chosen by that
extension's query alone), such a device now draws it by bits; a device with the extension is
unchanged (FragStencilRefEXT, no fact, no note, the draw issued once).

Translator: the function stores no reference; each return kills the fragment where the draw's new
push field PushField::StencilBit k is below 8 and bit k of the output's low 8 is 0, and keeps
every fragment at 8 or more (one module, no specialization). The function states
RuntimeFact::StencilBitDraws (Mechanism::PushConstant) and its fragment stage the static note
PrecisionNote::StencilOutputOverlap. Refused there, naming the extension (Unsupported
StencilExport): a function that also writes a colour (the colour would be written by every
repeat) or memory, one whose returns cannot kill (an interlocked body, a loop over its covered
samples), a mesh pipeline, and a render pipeline made for indirect command buffers. Where the
device also lacks the pixel interlock, a function writing memory in a raster order group meets
that refusal first (RasterOrderGroups). SEMANTICS_VERSION 2301 -> 2302, ARTIFACT_FORMAT_VERSION
595 -> 596 (new codec members).

Runtime (depth_stencil::BitDraws, render_encoder::draw): with w the low 8 bits of the write masks
of the faces having a Replace operation, a draw whose stencil test is on and w is not 0 is drawn
once with every fragment kept under the reference 0 (Replace zeroes w's bits, every other
operation runs once), then once per bit k of w keeping the fragments whose output holds bit k,
under the reference 255, write mask (1 << k) & mask, Replace kept and every other operation Keep,
and no depth write; where the state writes depth under a compare other than Always and Never, the
first draw writes none and a last draw writes it with stencil write masks of 0. Each draw records
only the dynamic state that differs from the last; the encoder's tests and reference are recorded
again at the next draw. Counted in Metrics::stencil_bit_draws (the draws beyond the first).
Refused at a draw, Gap::Draw of DrawKind::StencilOutput: a face compare other than Always or Never
(the output decides that test), and, where w is not 0, a draw inside a Counting visibility
segment (every draw would add its samples). A Boolean segment is drawn. Vulkan Appendix I: the
repeats change stencil reference, operations and write masks between draws of one pipeline,
which Rule 2 lists as required (write masks) and strongly suggested (stencil parameters) to be
invariant; the note records the one difference the repeats make.

The note (rule 1): fragments of one draw that overlap leave the OR of their values. Where two
fragments of one draw reach one sample under Replace, the sample stores the OR of their outputs'
low 8 bits within the write mask, where Metal stores the later fragment's value; under a depth
test that writes, each fragment's stencil operation is chosen against the depth from before the
draw. Measured on an RTX 3090 (NVIDIA 620.70.06) under the validation layer 1.4.363.0, job
m3-max-73635: two triangles of one draw outputting 0x35 then 0x4a store 0x7f on the 32 texels both
reach, where Metal stores 0x4a, and 0x35 on the 32 one reaches, in 8 bit draws; the 780M (RADV)
and the Iris Xe (ANV), which list the extension, store 0x4a with 0 bit draws.

AGENTS.md rule 2: "for nine only" becomes "for ten only", the list ending with fragment stencil
output (the planner's text, relayed by main, word for word).

Tests: the translator's engine_stencil (every committed profile: the extension or the draws by
bits, L3 both ways; refusals for colour, memory, mesh and indirect command buffers); rt's host test
of BitDraws::of; rt's device cells (stencil_export.rs): the stencil alone and the stencil with the
depth under Always and Less over a quad, exact, texels of stencil 0 among them; the overlap row;
the refusals; the route of a 4-sample Depth32Float_Stencil8 source read at sample 0 into a
single-sample target under Always/Replace 0xff and depth Always with write, beside colour 0
RGBA8 of write mask none; the codec round trip; the mechanism table.

Docs: docs/API.md (the stencil output passage and the catalogue entry
metal2vulkan-degrade-stencil-output-overlap), rt README known gap and floor row,
docs/REFUSALS.md regenerated, api_signatures blessed. The conformance degradation and the
validation allowance (unbounded) of the note. known-gaps-rt.tsv: stencil-output and
stencil-output-loaded on NVIDIA, refused at renderCommandEncoder (draw 3's back face Equal against
the output) and divergent at case/stencil as a result. runtime-sources.sha256: the guard's inputs
changed only by mechanism.rs gaining the new fact's arm, which no existing artifact states, so no
run of an existing artifact changes.

Golden rows and the engine inventory (22 cells) are re-blessed on development: 20 move from the
StencilExport refusal to a module (stx_stencil_by_pixel, stx_stencil_discard,
stx_stencil_with_depth, stx_stencil_ms_by_sample, fragment_depth_stencil on nvidia-pascal-linux,
nvidia-rtx50-linux, nvidia-rtx5080-laptop and runtime-floor), and the 2 cells
stx_stencil_in_order and stx_stencil_ms_in_order on runtime-floor move from StencilExport to
RasterOrderGroups, still refused. Why: the memory-write refusal now runs on the emitted module
(pipeline/compile.rs), after the body's own refusals, so on a profile without the pixel interlock
the raster order group these functions write memory in is refused first; at the base the plan's
entry refused every [[stencil]] output on such a device before any body was lowered.

Verified (this tree, or the rt archive of d6bd77d203 where named; the rt and translator sources
there differ from this tree in the translator's test and a doc comment alone):
- msi check, job m3-max-73648 (this tree): fmt, signatures, refusals, clippy -D warnings with all
  features plain, --cfg m2v_gpu and --cfg m2v_cpu_icd, Rustdoc, the rt nextest archive and the
  conformance binary built; rt's whole suite on lavapipe under the validation layer 1.4.363.0,
  738 tests run: 738 passed, 3 skipped; the lavapipe leg, 7 tests run: 7 passed: export enabled,
  the overlap row storing {4a}, bit draws 0 on every cell.
- RTX 3090 (NVIDIA 620.70.06, layer 1.4.363.0), job m3-max-73635 (d6bd77d203): 7 passed; the
  overlap row above, bit draws 8; the stencil alone and with depth under Always and Less, 64
  texels exact, bit draws [8, 8, 9]; the route exact, bit draws 8; refused a colour beside the
  stencil (StencilExport), Equal and a Counting segment (DrawKind::StencilOutput), a Boolean
  segment drawn. Conformance stencil-output and stencil-output-loaded: refused at
  renderCommandEncoder and divergent at case/stencil (4 elements, largest difference 80), the
  four known-gaps rows.
- RTX 5080 Laptop GPU (NVIDIA 615.71.09, layer 1.4.363.0), job m3-max-73652 (this tree): 7
  passed; overlap {7f} where both reach, {35} where one, bit draws 8; cells exact, bit draws
  [8, 8, 9]; the route exact, bit draws 8; the same refusals; conformance replay with this tree's
  binary matched the four NVIDIA rows (exit 0).
- Radeon 780M (RADV, Mesa 26.2.6), job m3-max-73636 (d6bd77d203), and Iris Xe (ANV, Mesa
  26.2.6), job m3-max-73650 (this tree): 7 passed each, export enabled, overlap {4a}, bit draws 0.
- States-only plays of recorded streams, base 0c9db49765 against d6bd77d203, every play in
  states-only mode, made and refused equal, refused 0: lavapipe, jobs m3-max-73632 and
  m3-max-73631 (two streams: render 10643 and 9014, compute 15299 and 221); the RTX 3090 with
  --device-type gpu, job m3-max-73638 (two streams: render 9834 and 10643, compute 214 and
  15299); the RTX 5080, job m3-max-73652 (two streams: render 9014 and 9645, compute 221 and
  250). Those two carry a library holding a [[stencil]] function that no recorded pipeline state
  uses; no stream on either NVIDIA node makes a [[stencil]] pipeline (job m3-max-73646 and
  m3-max-73652's scan).
- Owed: the translator and validation suites of this tree (the suites of d6bd77d203, job
  m3-max-73627, failed in the memory refusal's test on runtime-floor, the runtime guard's hash
  and the golden and inventory cells above; this tree fixes the first two).
2026-11-25 10:38:03 -08:00
Anees Iqbal 3c52ee1cf1 Render pass: a colour attachment renders one depth plane of a 3D texture's level
What: RenderPassColorAttachmentDescriptor takes `depth_plane` (Metal's `depthPlane`). A 3D
texture of RenderTarget usage is made 2D-array-compatible (VK_IMAGE_CREATE_2D_ARRAY_COMPATIBLE_BIT,
in its image format query too: Plan::flags, from the image's type and its colour attachment usage,
no query). attachment_view then takes the plane of a 3D texture's level as a 2D view of that one
layer (base layer = depthPlane, at the level), checked against the level's depth
(Refusal::AttachmentPlace past it). Every barrier on a 3D texture's image (its attachment's, its
copies' and its moves', texture::barrier_layers) names the image's layers as 0 and
VK_REMAINING_ARRAY_LAYERS, so each moves every plane of the level it names. Before, every such pass
was Gap::RenderPass of RenderPassKind::TextureType.

Still TextureType: a 3D texture in a layered pass (renderTargetArrayLength 2 or more), a depth or
stencil attachment of a 3D texture, a 3D resolve texture, and a resolve's depth plane but 0. A draw
that reads, through a shadow (a device without the attachment feedback loop), a 3D texture whose
plane its pass renders is Gap::Draw of DrawKind::AttachmentRead: a shadow's copies are of layers.
The floor asks a device that lists VK_KHR_portability_subset for imageView2DOn3DImage too
(VUID-VkImageCreateInfo-imageView2DOn3DImage-04459), as it asks multisampleArrayImage.

Why: a guest route meets the refusal. A browser's GL layer clears every 3D texture of an RGB-family
format (RGB8, RGB16F) at creation through a pass on each plane, to set the alpha it emulates; it
also renders into a plane for framebufferTextureLayer(TEXTURE_3D, k) then a clear or a draw, for a
level sampled before a full upload, and for copyTexSubImage3D. The consumer's route showed the key
at 205c8d2398 ("a render pass with TextureType is not built", colour 0 RGBA8Unorm Type3D 32x32x4,
usage 0x7, Managed), and every route that renders into a 3D texture read 0.

Metal (MTLRenderPass.h): `depthPlane` is "The depth plane of the texture to be used for rendering.
Default is zero."; Apple's page for the property, as fetched: "If the texture isn't a 3D texture,
then Metal ignores this property." Every Mac renders into a 3D texture's plane, with nothing to ask,
so it is built.

Vulkan (1.4.366): VK_IMAGE_CREATE_2D_ARRAY_COMPATIBLE_BIT "specifies that the image can be used to
create a VkImageView of type VK_IMAGE_VIEW_TYPE_2D or VK_IMAGE_VIEW_TYPE_2D_ARRAY" (core since 1.1);
the image is 3D (VUID-VkImageCreateInfo-flags-00950) and not sparse (-09403); the format query takes
the same flags (Image Creation Limits). The view is 2D, one level
(VUID-VkImageViewCreateInfo-image-04970), its base layer below the level's depth (-02724, -02725),
of an image made with the flag (-06728).
Such a view "can be used as a framebuffer attachment that refers only to the specified range of
slices of the selected mip level" (VkImageSubresourceRange). Dynamic rendering refuses only a 3D
view type (VUID-VkRenderingAttachmentInfo-imageView-12470). The runtime does not enable
maintenance9, so a barrier on the image moves the whole level
(VUID-VkImageMemoryBarrier2-subresourceRange-01488); with maintenance9 its layers would name depth
slices (-maintenance9-10798), and the layer count that names the whole level either way is
VK_REMAINING_ARRAY_LAYERS, which the validation layer asks for on such an image
(WARNING-VkImageSubresourceRange-layerCount-compatibility, met on lavapipe with layerCount 1, job
m3-max-73446). Load and store "only update values within the defined render area" of the view's
plane. The view is bound to no descriptor
(VUID-VkDescriptorImageInfo-descriptorType-06713).

Portability: KosmicKrisp, Mesa 26.3.1's source (src/kosmickrisp/vulkan), names no portability
subset, so the M3 device is not asked: a source read, unaudited at run time. MoltenVK reports
imageView2DOn3DImage (profiles/moltenvk-m3.json) and is below the floor anyway.

Conformance: the suite's `layered-attachment-places` crosses `depthPlane` over a 3D target of three
planes, recorded on Metal. Its runtime side now sets a colour attachment's `depth_plane` (a depth or
stencil attachment's plane stays Unavailable), and its twelve known-gaps-rt.tsv rows go.
docs/REFUSALS.md, docs/METAL-COVERAGE.md (depthPlane implemented), docs/CONFORMANCE-COVERAGE.md and
api_signatures.tsv are regenerated.

Tests:
- tests::depth_planes (device cfgs): RGBA8Unorm and RGBA16Float, ShaderRead | ShaderWrite |
  RenderTarget, Managed, an 8 x 8 x 4 texture of two levels (the second 4 x 4 x 2) and an 8 x 8 x 1
  one, every plane written first by replace_region. One command buffer: level 0's plane 2 cleared
  and drawn, level 1's plane 1 cleared and drawn, level 0's plane 0 loaded and drawn, level 0's
  plane 1 cleared alone, the one-deep texture cleared and drawn; every plane of both levels copied
  out and sampled at each texel's centre through a nearest sampler state (level 1 through a 3D view
  of it). A plane past level 1's depth is AttachmentPlace, a pass of two layers TextureType.
  tests::layouts records each rendering's colour attachment's view type and range and its image's
  type and create flags, which the cell asserts and prints.
- tests::floor: the portability features asked and enabled include imageView2DOn3DImage.
- The validation layer, which every device test runs under and which fails a test on any warning,
  holds the barriers: without barrier_layers the cell drew
  WARNING-VkImageSubresourceRange-layerCount-compatibility on lavapipe (job m3-max-73446).

Verified (tree of this commit, run as f748e9e8d2 on development 6047a2d8b6):
- msi, lavapipe (Mesa 26.2.4), job m3-max-73464: fmt, clippy (no cfg, m2v_gpu, m2v_cpu_icd),
  rustdoc, the refusal, signature, Metal-coverage and conformance-coverage checks all exit 0; the
  runtime's suite under the validation layer 734 passed, 3 skipped (the cell among them); the
  conformance crate's suite 1037 passed; `conformance replay --cpu` exit 0, the ledger exact,
  layered-attachment-places "announced" (the native-nan-encoding degrade notice alone).
- One leg a vendor, a nextest archive and the conformance command built on msi (job
  m3-max-73466), under the Khronos validation layer 1.4.363.0: the cell (its form printed: a 2D
  view, base layer the plane, at the level, of a 3D image made with 2D_ARRAY_COMPATIBLE, 0x28 for
  RGBA8Unorm with MUTABLE_FORMAT, 0x20 for RGBA16Float; every plane of both levels and of the
  one-deep texture exact, copied out and sampled), the blit, floor, layouts, layered, no
  attachment, over, pass, render, resolve, shadow, texture, view and depth/stencil route and copy
  families (123 tests), and `conformance replay --gpu` (exit 0, the ledger exact,
  layered-attachment-places "announced" as on lavapipe):
  - Intel Iris Xe (ANV, Mesa 26.2.6), job m3-max-73476: cell passed, 123 passed, replay exit 0.
  - AMD Radeon 780M (RADV PHOENIX, Mesa 26.2.6), job m3-max-73477: cell passed, 123 passed,
    replay exit 0. (The XTX's node was held by another job for 47 more minutes.)
  - NVIDIA RTX 3090 (620.70.06), job m3-max-73478: cell passed, 123 passed, replay exit 0.
2026-11-24 01:35:19 -08:00
Anees Iqbal 6047a2d8b6 Runtime: whether a declaration covers a held attachment is settled as declarations and moves are made, and a draw tests it alone
What: Declarations::held answers whether a read declaration of the encoder covers an attachment
or resolve its pass holds out of its home layout (Pass::held). use_resource sets it for a read
of a held attachment's hazard id (the texture, a view of its image, or the buffer it lies over
in place), use_heap for a new heap a held attachment lies in, and the feedback moves for a
newly held attachment an earlier declaration covers. A draw counts in
Metrics::unslotted_attachment_reads where the answer is set and it may read beyond its slots
(its pipeline reads unbound, or an indirect command buffer's execution), testing the flag first,
in place of the walk of the pass's attachments against the declarations that every draw ran.
The answer only grows within an encoder: declarations are never withdrawn (a re-declaration
merges accesses), an attachment's layout leaves home only through the feedback moves and returns
only at the encoder's end, and a new pass is a new encoder with no declarations, so it equals
the walk's at every draw. The README's encoder-call contract says so.

Why: 78998777a2 moved the check into every draw and cost draw_2000 11.0 user-space instructions
a draw on the encoding thread, though no draw of it reads beyond its slots. Measured with a
probe harness (not landed) that counts the harness thread's instructions over each draw call
alone, 20 runs x 2 rounds per arm, order reversed in the second, RTX 5080 Laptop (NVIDIA
615.71.09, no layer), job m3-max-73399: ec9e2771d0 1,002.8 a draw (runs 1,002.8-1,003.0),
2c95b330e5 1,001.9 (3b76e461a2 alone does not build), 78998777a2 1,012.8, 205c8d2398 1,012.8,
205c8d2398 with 78998777a2 reverted 1,001.9; bind_2000 2,123.2 / 2,131.2 the same way. A
pipeline that reads beyond its slots paid the whole walk on every draw.

Budget: the test every_device_walks_no_attachment_at_a_draw_after_no_change counts the walks of
the pass's attachments (pass::TARGET_WALKS, test builds only) over 64 draws after the first since
a change: none for a pipeline that reads nothing beyond its slots, before and after the target is
declared read, and none for the argument-buffer pipeline, whose 65 draws each count one
unslotted attachment read. Without the change the last 64 draws walk 64 times.

How verified: the job ids of the check, the 5080 instruction arms and the AMD held_loop_reads leg
are in the lane's report to the lander.
2026-11-24 01:16:11 -08:00
Anees Iqbal 78998777a2 Runtime: every draw that may read beyond its slots checks for a held attachment it declared, not only draws that look at their reaches again
aab995f44d ran the check in draw_reaches, which a draw enters only where it reads
an attachment through a slot, reaches Managed memory or textures over buffers. A
draw through an argument buffer alone never entered it, and the held-loop-reads
test read 0 where it wants 1 (lavapipe job m3-max-73034, RADV 780M job
m3-max-73035). The check now runs in the draw itself, after the draw's own
feedback moves are recorded, so it sees the layout the draw reads in.
2026-11-23 21:54:23 -08:00
Anees Iqbal 2c95b330e5 Runtime: the unslotted-attachment-read check reads the heap block's own id and lets go of the pass before the draw is recorded
ae4dfd67b9 did not build: memory::Block keeps its id under its memory, and the
pass borrowed for the check was held by the resolves iterator past the draw's
mutable borrows. The check now runs in its own block. Verified by the clippy,
lavapipe and RADV 780M jobs named with this branch's report.
2026-11-23 21:54:23 -08:00
Anees Iqbal 3b76e461a2 rt: count draws that may read their own pass's attachment beyond their slots; the known gap in the README
What: Metrics::unslotted_attachment_reads counts a draw whose functions may read beyond their slots
(Draws::reads_unbound, or an indirect command buffer's execution) while a use_resource read or a
use_heap of the encoder covers a texture that is an attachment of the pass (a target or, in a
resolving pass, a resolve) out of its home layout. The check walks at most the pass's attachments
and the encoder's declarations, allocates nothing, and runs only for such draws; use_heap now
records its blocks, and a texture answers the block of the heap its image lies in. The replay's
counts line carries the counter. The README's known gaps of render encoders say that such a read
names a descriptor whose layout differs from the image's, which Vulkan leaves undefined
(VUID-vkCmdDraw-imageLayout-00344), that the counter counts it, and that the image is back home once
the pass ends. The held-loop-reads test asserts one in each pass that reads the attachment through
its argument buffer (after a slot's read moved it to the feedback layout, and alone, in the
attachment layout) and none for the control, whose entry names a texture that is no attachment.

Why: the ruling is rung 4 of the workaround ladder. A home in the feedback layout for every colour
render target turns compression off on RADV (radv_layout_dcc_compressed and its HTILE and FMASK
counterparts), a loss on every AMD render target; VK_KHR_unified_image_layouts would be a
query-chosen tenth form. The validation layer cannot see the mismatch: core validation checks only
statically accessed elements, and GPU-assisted validation's descriptor layout check is off in the
layer's source. So the gap is recorded and the counter tells whether a guest meets it.

How verified: the job ids of fmt, clippy (plain, m2v_gpu, m2v_cpu_icd), lavapipe and the 780M's
device suite under RADV are reported to the lander.
2026-11-23 21:54:23 -08:00
Anees Iqbal 849dfe67d7 Tests: a depth-tested draw's unchanged state and bias are checked as nothing to record, not by its cost
every_device_counts_a_depth_tested_draw_s_instructions held a draw whose
depth-stencil state and bias are set again unchanged to within a quarter of a
draw under a test set once. That bound held only while the validation layer's
per-call cost sat in the draw's base. On lavapipe without the layer
(METAL2VULKAN_TEST_UNVALIDATED=1, dotscheck's job m3-max-72849) the setters'
own ~850 instructions came to 4092 against 3220 and the test failed, though
nothing was recorded. A device suite run without the layer would fail the same
way.

The claim is now checked as the encoder states it. After a draw, the same
state and bias set again leave the encoder's marked dynamic states, the bits
its next draw records from (record_state), at none. The changed state and
bias leave them non-zero, which shows the check can see a change. It runs on
every device, before the instruction counter, so hosts without the counter
check it too. The instruction counts stay printed, held to no bound. The
accessor (RenderCommandEncoder::unrecorded) is test-only, beside pushed().
2026-11-23 20:47:10 -08:00
Anees Iqbal 22ca6271eb rt: every render pipeline takes the feedback loop's colour flag; the loop's dynamic state goes
The attachment feedback loop needed two extensions: VK_EXT_attachment_feedback_loop_layout and
VK_EXT_attachment_feedback_loop_dynamic_state. A device that lists the layout extension without
the dynamic state (AMD's open Linux driver on the Radeon 780M) read every attachment through the
counted copy into the image's shadow.

Now the loop needs the layout extension and its feature alone. Every render pipeline is made with
VK_PIPELINE_CREATE_COLOR_ATTACHMENT_FEEDBACK_LOOP_BIT_EXT where the device reads attachments
through the loop. A render state is made before any draw binds its textures, so the flag goes on
every pipeline, and a draw that reads no attachment is valid with it (the flag says a pipeline may
be used with a feedback loop; no VUID ties it to a read). The encoder no longer sets the loop's
enable at its first draw and where it changes (its LOOP dirty bit is gone), and device creation no
longer enables the dynamic-state extension or its feature. The copy stays for devices without the
layout extension. RADV and ANV read only the depth/stencil bit of the flags; a colour image's
compression follows the feedback layout, which is unchanged.

Breaking change of metal2vulkan-runtime: floor::Features loses its public field
feedback_loop_dynamic, and floor::ATTACHMENT_READ_EXTENSIONS lists the layout extension alone
(api_signatures.tsv blessed). The consumer's checkout at 9f0bfa296 has zero hits for
feedback_loop_dynamic and ATTACHMENT_READ_EXTENSIONS (grep over the tree); it reads
Capabilities::feedback_loop only. docs/REFUSALS.md regenerated with no change; no refusal or
translator name moved, so api_surface.rs is unchanged.

The floor test the_attachment_reads_take_the_feedback_loop_where_reported_and_a_copy_elsewhere
now takes a device listing the layout extension alone to the loop, and enables no dynamic state
where the device lists it too.

Verified: nothing yet; this commit's compile, test and timing jobs follow.
2026-11-23 13:06:26 -08:00
Anees Iqbal c553ebbfcb rt: a device with no heap placement of links looks at none, and a command buffer keeps no alias state until it touches one
The instruction bench (job m3-max-71736, lavapipe burst_2000, 2,000 one-dispatch command buffers a
run, A acda405b30 against B 867e059aaf alternated A B B A A B) read own_per_run 50,646,700 against
51,286,684, +1.26%, about 320 instructions a commit: each dispatch walked its slots for placements,
and Building and Segment carried the marks and the part inline. Now the heap ids count the
placements with links (HeapIds::any_linked), and a dispatch, a pass's begin, a draw and a blit
look at their resources' placements only while one has links; Building's marks and a segment's part
are boxed, made at the first touch.
2026-11-23 10:53:22 -08:00
Anees Iqbal ec6fe47a06 rt: the alias wiring names its object traits where two apply 2026-11-23 10:43:30 -08:00
Anees Iqbal 07be8848ea rt: the resources' heap placements are read through placement(), apart from TextureObject::place 2026-11-23 10:43:30 -08:00
Anees Iqbal 9d2eb08985 rt: a draw's heap moves leave its pass's own attachments, which stay in the layout the pass renders them in
An attachment of the pass the draw is in is in the pass's layout, not its home: a move from
undefined to home in the pass's interruption would leave it there. Its write at the pass's begin
already took its move where one was owed.
2026-11-23 10:43:30 -08:00
Anees Iqbal 20ddd2daad rt: a heap texture moves from undefined before its next write after an alias's write
Vulkan's memory aliasing asks that an image over bytes another resource wrote move from
VK_IMAGE_LAYOUT_UNDEFINED before it is used. rt moved a heap texture only once, at its making, so a
device that keeps a compression state beside an image's bytes read the alias's state: on the Iris
Xe (ANV, Mesa 26.2.6) a 512x512 RGBA16Float array written through a 2D view after eight aliased
arrays read 8152 of 262144 texels wrong (job m3-max-71690, the test c26698712c).

The form (crate::alias):
- Each heap texture and heap buffer is a Place, linked at placement with the placements of its heap
  whose bytes meet its, both ways and weakly; a release drops its links. A placement with no links
  pays one test at each use.
- A write of a placement makes its links stale. A stale texture's next write moves its whole image
  from undefined to home, in one barrier from every command's writes to every command's reads and
  writes. Reads move nothing; a buffer is never moved. A declared write counts as a write.
- Inside a command buffer, encode order is run order: Building's marks keep each touched
  placement's state (fresh, stale, untouched) and the segment its commands last read it in. A write
  of a stale one moves in place: before a dispatch, a pass's begin or a blit; inside a rendering,
  through the pass's interruption.
- A write of an untouched one adds a check at its segment's head; where the segment read one of its
  links before, the segment ends first. The submit thread resolves a segment's checks as it stages
  it, in the order the device's one queue runs segments (so a command buffer committed out of its
  encode order, or held by an enqueue, is decided where it runs), recording the moves owed into a
  command buffer of the cb's recorder staged just ahead of the segment's, in its submit info and so
  its vkQueueSubmit2; then it applies the segment's writes. A failed record loses the device as a
  failed submission does.
- A texture placed over another's bytes is stale from its making, and its making move waits for
  every earlier write (ALL_COMMANDS / MEMORY_WRITE in place of NONE).
- Metrics::heap_moves counts the moves, in place and leading.

No upload piece: a heap texture sits on a Private block and Metal gives a heap's textures the
heap's storage mode, so no Metal-valid replaceRegion reaches one (TextureBytesPrivate).

The README's gap line now says what remains: a read of a stale texture, writes rt cannot name, a
declared write taken whole, the making move's effect on a live alias's bytes, the move's whole
image, and a draw's check at the head of its pass's segment.

Tests: src/tests/alias.rs holds the state machine on every device of the cfg (commit order against
encode order, the segment ended before a check behind an alias's read, moves in place, a draw's
write through the pass, apart placements with no check or move); the red test is
heap_alias.rs's array test. Gate and device runs follow in the next commits.
2026-11-23 10:43:30 -08:00
Anees Iqbal cc4763d5d3 rt: Metrics::level_field_commands counts the dispatches and draws that push a texture's level fields
A run-time-level write or read, or get_num_mip_levels of a storage texture, under the identity
domains pushes the texture's level count (TextureLevels) and, for a write or read, the first of
its level elements (TextureLevelBase). Nothing showed that path ran: a case that matches on
a device could match without it. The new metric counts each recorded dispatch or draw whose push
carries either field. A dispatch or draw takes the fact from the scan its checks already make
once per change (DispatchFacts / Facts::find). No Metal counterpart.

Evidence lines: the conformance replay prints "level fields: CASE on DEVICE: N ..." per case.
The validation runtime executor prints "level fields: CASE: N ..." to stderr. The replay
player's metric list carries level_field_commands.

Tests: storage_levels gains every_device_counts_the_dispatches_that_push_level_fields. One
level-write dispatch counts 1, and one get_num_mip_levels dispatch counts 1 more and stores 4.
The fragment test's three draws count 3. Signature table blessed. REFUSALS.md is unchanged (the
script does not cover Metrics). Before commit: cargo fmt only. The device tests run in the
lane's gate jobs.
2026-11-23 09:04:39 -08:00
Anees Iqbal ed4b0ecd76 rt: storage textures written or read at a run-time level, through runs of set 1's level elements
What: under the identity domains a storage slot written, read or size-queried at a level other
than the constant 0 indexes a run of set 1's storage-image array instead of being refused as
Unsupported{IdentityDomains} ("an encoder value the function reads as TextureLevels(S)"). The
translator pushes the bound texture's level count (PushField::TextureLevels) and the run's first
element (the new PushField::TextureLevelBase, beside it), states no StorageTextureLevels or
StorageTextureLevelViews fact, and an access at level l takes element
first + min(l, max(n, 1) - 1) of the array, NonUniform, inside l < n. A texture of one level
pushes its own index, nil 0 with count 0.

The runtime's binding 1 grows by 65,536 level elements past its 65,536 textures, 4,096 runs of 16
(floor::LEVEL_ELEMENTS, floor::LEVEL_RUN). The first dispatch or draw that binds a texture of more
than one level to such a slot (the encoder's checks, compute and render stages alike) gives it a
run: a single-level storage view of each level, of its storage element's type (a cube's level as
the 2D array of its faces, a view's from its own first level), written at the run's elements. A
later bind takes the texture's lock and pushes the same two words: no Vulkan call. The run goes
back through the pool and reaper once the texture is released and its work retired: elements null,
views destroyed (Gauges::level_elements). Every run held, or a texture of more than 16 levels, is
the new Limit::LevelElements { max: 4096 }, and the dispatch or draw does not run. The floor's
storage-image limits and both totals rise by 65,536: storage 196,608, per-stage resources 327,688,
pools 351,680; every lab device's profile is far above (llvmpipe 1,015,808 storage, the least).

SEMANTICS_VERSION and ARTIFACT_FORMAT_VERSION bump in the branch's last commit (a new PushField).

Why: 17 guest kernels in 6 libraries were refused at state creation by this form.

Docs: REFUSALS.md and the signatures table regenerated, RESOURCE-ID.md (binding 1 past 65,536),
API.md (storage levels under identity), the runtime README (Set 1, the floor table, the known-gap
line replaced by the Limit), the runtime-floor profile's limits, and the conformance ledger's
level-sizes-storage row removed.

Checked by: engine_texture_levels' identity test and the runtime's storage_levels device tests
(red at 6ad1c33124: jobs m3-max-70886 and m3-max-70892 on lavapipe), engine_identity's
a_storage_slot_written_at_a_run_time_level_is_an_element_of_its_run; the lane's jobs report the
runs per card.
2026-11-23 09:04:38 -08:00
Anees Iqbal f3bb94275b rt: a bind of a texture reached through its views alone to a texture slot is TextureWithoutIndex
A texture made with no index although its usage reaches shaders (Device::new_texture_for_views,
Device::new_heap_texture_for_views, a surface's or a Direct3D 11 surface's plane made with no
index) is reached through its views, each with an index of its own. Bound directly to a
function's texture slot, a dispatch or draw pushed its resource id, index 0, set 1's null
descriptor, so every read answered zero with no refusal (the consumer saw a D3D11 luma plane read
0.0 for every texel this way). ComputeCommandEncoder::set_texture and RenderCommandEncoder's
set_vertex_texture and set_fragment_texture (the runtime's only texture-slot binds) now refuse it,
binding nothing: Refusal::TextureWithoutIndex { index }, the slot's index. The check reads the
texture's own stored facts at the bind (no index, and its descriptor's usage reaching shaders by
the creation rule); nothing is looked up and nothing runs per draw or dispatch.

A texture no shader reaches (a depth or stencil target whose usage asks neither shader reads nor
writes) also has no index, and still binds: Metal binds it, its usage asks no shader read, and a
read of it answers the null descriptor. The previous commit's test expected that case refused;
it now expects it bound, so a guest's bind of such a texture to a slot its function does not read
meets no refusal.

Texture::gpu_resource_id says what an index-free texture's id is (index 0) and that a shader
reading it from bytes (an argument buffer) reads the null descriptor; nothing refuses that, as
the call returns a ResourceId. ResourceId's encoding is unchanged. The runtime has no argument
encoder, no texture-slot range call and no indirect-command texture bind, so the binds are the
whole Result-returning surface; an attachment read of an index-free texture is already
Gap::Draw (FetchedAttachment).

REFUSALS.md and basis.rs regenerated; the runtime README's texture and compute-encoder entries
updated.
2026-11-23 02:54:00 -08:00
Anees Iqbal f17e07ad07 rt: StorageElement names its case and backing; PartialThreadgroups and ThreadgroupMemory name their site and static bytes
A refusal's sentence stays as it was (the known-gaps ledger keys on it); the new facts are typed
fields.

- Gap::StorageElement gains `case` (StorageElementCase: Absent, WriteWithoutFormat,
  ReadWithoutFormat) and `backing` (TextureBacking: Texture, Buffer, SurfacePlane, D3d11,
  Drawable; a view answers its parent's). TextureObject::storage_gap computes both at the four
  sites, and use_resource keeps it for a declared write. SurfaceImage's `general` flag, which only
  a Direct3D 11 import set, is named `d3d11`, and a surface plane's image keeps it.
- Gap::PartialThreadgroups gains `site` (PartialThreadgroupsSite): VoteWord { static_length, max }
  where the translator refused the variant for its vote word, Translator for its other refusals,
  SimdGroups { width } where the threadgroup is not whole SIMD groups of the variant. The cache
  directory keeps why with the refusal (m2v-refused-vote beside m2v-refused), so a warm boot names
  the site too.
- Limit::ThreadgroupMemory gains `static_length`, the state's staticThreadgroupMemoryLength.
- The translator's vote-word refusal is built through Unsupported::needs_any_of, so the refusal
  table derives its basis.

docs/REFUSALS.md and the api_signatures table are regenerated. Tests: the scan test's shape (i)
at 32,768 reads Limit::ThreadgroupMemory with static_length 0 and the limit; shape (ii) reads
PartialThreadgroups at the VoteWord site with its 32,768 static bytes against the limit; the
vote-word test reads the static length; storage_element, texture_buffers and read_write_tier read
the case and backing. Not yet run.
2026-11-23 02:31:24 -08:00
Anees Iqbal 3c86a2a45f Translator: a vertex function's slice and viewport index are stored as it writes them
Metal requires the same [[render_target_array_index]] and [[viewport_array_index]] at every
vertex of a primitive ("If values differ, the behavior and value passed to the fragment function
are undefined.", the Metal Shading Language specification), and Vulkan asks the same of Layer and
ViewportIndex (VUID-VkPipelineShaderStageCreateInfo-stage-02596 and -02597). The translator stored
an index only where the function's structure showed it the same among a primitive's vertices
(uniform_varyings over the raw index varyings) and refused every other one,
NotImplemented(LayeredRendering), on every device. A program that keeps Metal's rule keeps
Vulkan's with the index stored as written, and one that breaks it has no Metal answer to match,
so plan::index_store now stores the index to its builtin wherever the device stores it from a
vertex function (shaderOutputLayer, shaderOutputViewportIndex, both in the floor), whatever the
structure shows; a device without the output is refused needing it, as before. The store keeps
index < count ? index : 0 against the pushed length and viewport count, and an index never written
is still stored as 0. uniform_varyings now lists user varyings alone (the raw index keys decided
nothing else), and uniform_index is gone.

Where a program breaks Metal's rule the layer or viewport is the device's choice: the runtime
README's layered line and docs/API.md (section 4 and section 10's accepted differences) say so in
one sentence, the viewport paragraph and set_viewports no longer name a geometry stage, and
docs/REFUSALS.md is regenerated (LayeredRendering is now a device refusal alone). The runtime's
layered device test draws rt6_per_primitive's three triangles into slices 1, 1 and 2 through
viewports 0, 1 and 1 of a 2D array, checking every texel, in place of the refusal it asserted.

SEMANTICS_VERSION 2283: modules for such functions instead of the refusal, and uniform outputs
without the raw index keys.
2026-11-23 00:13:45 -08:00
Anees Iqbal 29e54794ca Runtime: a sampler state bound with LOD clamps of its own samples with them
A bind's LOD clamps (setSamplerState:lodMinClamp:lodMaxClamp:atIndex:, its
vertex and fragment forms and the range forms) that read otherwise than the
state's own were Gap::LodClamps. Metal takes the call; on the M3 Max
(conformance cases sampler-bind-lod-clamps-kernel and -fragment) the pair
replaces the state's clamps, a lower bound above the upper reads at the upper's
level, and a plain bind afterwards reads the state's own clamps again.

How: such a bind takes the state's variant of the pair, the state's descriptor
with the pair as its clamps, its device samplers from the shared sampler table,
placed at a variant element of set 1's sampler arrays. The three sampler arrays
grow from 4,000 to 8,000 elements in the runtime's layout; elements 4,000 to
7,999 are the variants'. Shaders declare the heap arrays unsized, so the
translator is unchanged: a slot's sampler index is the runtime's push, and an
argument buffer's sampler index of 4,000 or more still reads element 0, so no
program-written ID reaches a variant. A state keeps its 16 most recently bound
variants; a new one past them takes the place of the least recently bound one
no command buffer holds, and where work holds all 16 the new one is held by its
command buffer alone. Past 4,000 live variants a bind is
Limit::LodClampVariants { max: 4000 }. The lod_clamp_variants gauge counts the
live variants. A NaN bound, which Metal documents no answer for, binds the
state as it is.

The floor's sampler limits rise to 24,000 (maxPerStage and maxDescriptorSet
UpdateAfterBindSamplers) and 286,144 (maxUpdateAfterBindDescriptorsInAllPools);
the lab's least are 500,000 (MoltenVK on the M3 Max) and 1,048,576 (Intel UHD
Graphics 630 on Windows), and Vulkan requires 500,000 of each with
descriptorIndexing.

Gap::LodClamps goes; REFUSALS.md, basis.rs, the signature table, the Metal and
conformance coverage pages regenerate. The validation replay plays clamped
binds (no skipped_clamped_samplers). The ledger drops three rows the clamped
binds now answer (compute-plural-texture-and-sampler-binding steps 11 and 14,
render-state-unread-slots). The compute single clamp form's coverage row named
set_sampler_state; it names set_sampler_state_with_lod_clamps.

Tests: a kernel samples through the binds as Metal reads them; a state's 16
kept variants filled past that; the 4,000 variant elements filled past their
capacity; the gauge flat across a bind and retire loop and zero at device
drop. Verified: see the lane's report (jobs named there).
2026-11-23 00:11:19 -08:00
Anees Iqbal e23ac486be Runtime: an indexed draw's command buffer keeps its index buffer until it retires
The draw path kept an indirect draw's arguments' buffer (and an execution's
range buffer) with Building::keep, but never the index buffer of
draw_indexed_primitives or draw_indexed_primitives_indirect, though both docs
say the command buffer keeps it until it retires, as Metal's command buffer
retains what its draws use. A buffer is a view of a block that holds the block
(buffer.rs), so where the buffer was its block's last holder (the consumer's
plain buffers: it drops its block handle once the buffer is made), dropping it
after encoding gave the block back at once (memory.rs Pool::give_back): its
range was a free range of its allocation, a later take could land there and
overwrite the indices before the GPU read them, and with nothing in flight the
allocation itself could go once idle. The index buffer is now kept beside the
arguments' buffer, after the draw's checks and only for a draw that records.

Test: every_device_keeps_index_buffers_dropped_before_the_commit_until_their_draws_retire
(tests/draw.rs): a direct indexed draw and an indexed indirect draw, each index
buffer the one holder of a Shared block, both dropped after encoding and before
the commit, two blocks of the same length then taken and filled with other
indices; the target reads back exact (each half its own draw's colour), neither
block is back in the pool before the retirement, and both are after it.
2026-11-22 19:36:05 -08:00
Anees Iqbal e3a3f5c7dc Runtime: the queue cut comes off again
Reverts, in one commit, the nineteen commits of c38852d665..c2088436aa
that carry the queue cut and its order fixes (newest first): 333adf36cf
8828e8ad6c daaccb7bb0 4f683ad891 7cd99ae0b1 5f93a64342 6523e2b65c
76f369dbbf 2bcac43a53 c5e98be51d 635da9d820 1f7f77e4cc 4b1cdaf505
9e8baebc48 b1b375b8e1 40a9982a94 02923fb2ae ec24ba8439 69754cb203.
piece.rs and its tests go, and the README rows on the pieces' cost.

Kept: 6adfe028d8 (a half vector joined from read lanes keeps its bits),
7d8aabed34 and c2088436aa (the 780M import-cost rows). Against
c38852d665 the tree differs only by those three commits' paths and
changes. The cut bumped no version, so none moves here.

Why: the fallback for the Iris Xe regression under the planner's 18:00
PST box. The guest's image step reads take-to-show p90 17.16 ms cold and
24.66 ms warm (Iris Xe, the consumer's walks, job 67930) against 4.34 and
4.42 ms before. The cut, with no green fix tip by the box, comes off with
the one-module move that caused it; the cut continues on its own branch.
2026-11-22 16:25:58 -08:00
Anees Iqbal 69754cb203 Runtime: the queue cut comes back, as it stood at f0b6fff640, for its fixes to build on
This reverts e3d30c5101. With it, the runtime crate, its README, its tests and api_signatures.tsv
equal f0b6fff640 again: the queue cut, its fixes 1 and 2, the cycle fix, the rate inputs of the
tests, and the README's cross-queue rule with its known-gap line.

This branch carries the cut until it re-lands on development as one series. It re-lands when the
spin fix is green in all four forms, and the XTX compute benchmark is within 3% in an alternated
pair or the owner rules on the trade. It also waits for the wait-split sharer fix, if that is the
cut's regression.

Verified: the tree equals f0b6fff640's (git diff f0b6fff640 HEAD is empty).
2026-11-22 14:51:16 -08:00
Anees Iqbal e3d30c5101 Runtime: the queue cut comes off development until its gates pass; the runtime is f979769faf's with stage input
What: the runtime crate goes back to f979769faf's, plus stage input. Its sources, its tests and
api_signatures.tsv now equal those of f979769faf with a916e61185, f21db0934c, 59e0a3f7ca and
58e9267b6c applied, file for file.

This one new commit takes out the queue cut and everything built on it:
56cdcb7075, 929718d58f, 9adc440ec6, f997dfa7d3, 544f21b48f, c9c53b85cf, 75773059e7, 855eb86147,
62183f55af, 2ec8680181, eaba828dcd, 600b38fda7, f268d3ca07, 59481e60bd, e74f1480ed, 5686863157
and f0b6fff640. That covers piece.rs, tests/pieces.rs, the rate inputs of the barrier, heap and
event tests, and the README's sections on pieces and the device's room.

It also removes the parts of 41b5038342 that state the cut's cross-queue rule. Those are the
README's "goes after it only once that one is submitted" sentence and its known-gap line on commit
order between queues. Without the cut, a command buffer never goes ahead of an earlier-committed
one it shares a tracked resource or a fence with, and the README says so again.

Kept:
- stage input, from a916e61185 and f21db0934c;
- its NaN rows for the XTX, the Iris Xe and the RTX 3090, from 59e0a3f7ca and 58e9267b6c;
- the replay player's host wait for its own surface fill, from 41b5038342: the player, its test
  and docs/REPLAY-STREAM.md;
- the README's import-cost paragraph, from f53ddc5917.

Why:
- development carries a confirmed stall. A cut command buffer waiting for room, with an empty or
  present-only command buffer behind it on its queue, spins the submit thread with the work lock
  held. Lavapipe, m3-max-68758.
- It carries a candidate benchmark regression: the compute benchmark on the RX 7900 XTX scored
  5.09% lower in the consumer's first pair (m3-max-68746 against m3-max-68738). Its second pair
  is still being read.
- Stage input is a refusal a guest met. The consumer pins only exact commits on development, so
  stage input reaches it only through a development commit without the cut.
The cut and its fixes go to steelbrain/cut, as this commit's revert plus the fixes. They come back
to development as one series when the spin fix is green in all four forms, the XTX benchmark is
within 3% in an alternated pair or the owner rules on the trade, and the wait-split sharer fix is
in, if that turns out to be the cut's regression.

Verified:
- The runtime crate's tree and api_signatures.tsv equal steelbrain/pin-stagein (ce10a0d627).
- The diff to it is the README's import-cost paragraph, the replay player's two files and
  docs/REPLAY-STREAM.md.
- fmt, the refusal surface, the signatures table, the conformance coverage and the Metal coverage
  all check as current.
- The quick check and the suites at this commit are named where it lands.
2026-11-22 13:55:40 -08:00
Anees Iqbal 56cdcb7075 Runtime: a command buffer's compute work goes in pieces of 4 ms, and the device's room goes to the queue that waited longest
What: each command buffer's compute work is cut into pieces before a dispatch that would take
the piece's expected GPU run past GROUP_RUN (now 4 ms, was 16 ms), and where a compute or blit
encoder opens after a full piece; never inside or before a render pass. A dispatch's expected
run is its kernel's rate (picoseconds per threadgroup, on the kernel's compiled content, shared
by its states) times its threadgroups; a kernel with no rate yet goes in a piece of its own, and
an indirect dispatch counts as one threadgroup and feeds no rate. Each piece is timed by its own
pair of timestamps, from its first dispatch to its end, and that run alone feeds the rates
(never the command buffer's span, which holds the runs of what passed between its pieces). Each
piece is a submission of its own and waits for room. Room is the device's: room() over the
device's submissions not seen complete, and among the queues that want room the one that last
submitted earliest takes it, so a passed piece goes before the passer's queue's next. A command
buffer of another queue committed after a cut one passes its pieces unless it holds a buffer or
texture the cut one holds (by tracked id), waits on a fence it updates, or either reaches memory
outside its resources: then it is held behind every piece. A cut command buffer whose later
pieces wait for no event is scheduled as its first piece is staged.

The rate is scheduling data of the same kind as a queue's measured expected run
(QueueInner::expected_run, next_run): it bounds where a piece ends and never chooses between two
forms of the work (rule 4's "no calibration").

Why: on the Iris Xe the guest's screen-frame writers waited behind a background service's
running command buffer: 96.2 of 112.3 ms of each late writer's wait. The Mac runs a second
queue's command buffer beside a running one (Radeon Pro 5300M at any priority, job
m3-max-68137; UHD 630 where the number is lower, m3-max-68129).

Verified: compile job pending (this commit carries no tests yet).
2026-11-22 11:11:23 -08:00
Anees Iqbal bda5ed08e9 rt: a resolve into a texture in place over a buffer whose linear image cannot render goes through a resolve image
For the consumer: a pass that resolves into a texture in place over a buffer of the runtime's
own memory, whose linear image takes no colour attachment usage, is no longer refused with
Gap::RenderPass{ResolveUsage}. It resolves into the texture's resolve image, and the pass's end
copies the render area into the buffer at the texture's pitch. This is the guest's 600 x 600
BGRA8Unorm_sRGB ShaderRead texture over a Managed buffer, on every NVIDIA host and on KosmicKrisp:
their linear tiling features hold COLOR_ATTACHMENT for no format (count jobs m3-max-67031 and
m3-max-67032), and a pitch of the row rounded up to the alignment answer (128 and 16) lies in place.
It also covers a texture whose subresource reaches past its own rows or its buffer (the render-reach
rule), on every device. Additive public items: Metrics::resolve_copies and resolve_copy_bytes (in
bytes_copied too), Gauges::resolve_images and resolve_image_bytes. Still refused: a texture in place
over a dma-buf's import (an imported surface's memory) and a view of a texture in place.

Why this form: owner's rule 3 allows "where a format query offers no linear image for the format and
usage, a counted copy", the sentence OverCause::LinearFeatures and RenderReach already rest on for a
render target over a buffer. This is the smallest such copy: one per resolve, of the render area
only, and nothing on later uses. The texture stays in place, so shaders keep reading the buffer's
bytes through its linear image. The planner chose it over moving the texture to the copy form at
its first resolve (2,880,000 bytes per resolving pass, then a copy in every submission that uses
it).

How:
- texture.rs: the in-place texture's Image keeps a Resolving where it lies in the runtime's own
  memory (Laid::Own), its linear image took no attachment usage, and its plan's optimal image does
  (Plan::resolves, the image format query that already made it with COLOR_ATTACHMENT). The first
  resolve makes the resolve image from the texture's plan (Plan::resolved, Bind::Pooled) and a 2D
  identity view of it. Every later resolve reuses them, and they are freed with the texture
  (Free::Resolved, the resolve images gauges). resolve_attachment returns the attachment and, for a
  resolve image, a ResolveCopy: the VkBuffer of the bytes shaders reach and the region at the
  texture's pitch. That is Named::region, the region copied_over already built, now shared. A level,
  slice or layer count past the texture's one is Refusal::AttachmentPlace, as attachment_view
  refuses it.
- pass.rs: Resolve carries the copy. Its image's home is TRANSFER_SRC_OPTIMAL and it renders in
  ATTACHMENT_OPTIMAL. Resolve::from moves it away from UNDEFINED: the pass resolves every texel of
  its render area and copies only those, so nothing it held earlier is kept.
- render_encoder.rs: after the pass's back barrier (which moves the image to TRANSFER_SRC_OPTIMAL),
  end() records vkCmdCopyImageToBuffer of the render area (Pass::reach) into the buffer at the
  texture's pitch. It counts the copy and owes the pass's barrier, so the next command, or the
  segment's end, orders the copy before later work. bufferOffset is a whole number of texels, which
  check_over already requires (VUID-vkCmdCopyImageToBuffer-srcImage-07975; the multiple-of-4 rule,
  07978, is depth and stencil only). The block's buffer has TRANSFER_DST.

Readable through the linear image: the copy writes the buffer, and a later pass reads the same
memory through the texture's linear image. Vulkan 12.11 Memory Aliasing says "If two aliases are
both host-accessible, then they interpret the contents of the memory in consistent ways, and data
written to one alias can be read by the other alias". Buffers, and linear image subresources in
GENERAL or PREINITIALIZED, are host-accessible. The in-place form already rests on that sentence:
its linear image starts preinitialized and stays GENERAL through every use, copies included
(Image::copy_layout, "so that it and the buffer are aliases that interpret their bytes alike
(Vulkan's memory aliasing)"). The order between the copy and the read is the owed barrier, a memory
barrier from every command to every command.

Docs: RenderPassKind::ResolveUsage, the resolve texture's doc, resolve_attachment's and resolve()'s
docs, and the pass module say what resolves through the resolve image and what is still refused.
The runtime README's two Render encoders paragraphs and its counters list are updated, the card
names under "measured on". docs/REFUSALS.md is regenerated (two more AttachmentPlace sites, in
resolve_attachment), and so is the signatures table (the four new fields).

Test: every_device_resolves_a_loaded_pass_into_a_shader_read_texture_over_a_buffer runs the
guest's shape over a Managed and over a Shared buffer, at 2,400, at the row rounded to the alignment
answer, and at 2,560. On an in-place row whose linear image took no attachment usage, it asserts:
- the first resolve makes exactly one image;
- one resolve copy of 1,440,000 bytes, and bytes_copied equal to it;
- the buffer reads the clear within one code, with 0 bytes past the texels changed;
- a pass after it in the same command buffer reads the texture at each pixel (own_pixel_fragment
  into a 600 x 600 target), its centre texel (299, 300) the clear within one code;
- a second resolve, in a command buffer of its own, makes no image and no allocation
  (image_creates, consumer_allocations), and the resolve images gauge does not grow.
The other rows are unchanged: in place with the usage, 0 copies; copied, counted copies. Every
gauge is zero at device drop (each_device). Without this change, the RTX 3090's in-place row at
2,432 is refused with ResolveUsage (job m3-max-67081 on the resolve fix's tree).
2026-11-22 04:02:28 -08:00
Anees Iqbal be1b2cfe46 rt: an exported block's textures owe their copy for an address write only once its address went out
bef2ec1df4 copies a texture over a buffer in an exported block in once per change of its bytes.
One change it counted was a write through an address: a submission that held one command of a
pipeline that writes outside its bound slots (writes_unbound) made every such texture owe its
copy (over::ExportedOvers::wrote read Leans::unbound). On the RX 550, whose dma-buf surfaces take
the copy form, a guest step that decoded nothing still made 2,702 copies (31.31 GiB, job m3-max-66531) of the 4K
P010 planes of a stale picture.

An address can reach an exported block's memory only once a public call has handed that address
out. So the bound: each exported block carries one flag (memory::Block::addressed, an
Arc<AtomicBool> that only exported blocks get). Every call below sets it, and the first counts in
the new Metrics::exported_blocks_addressed. ExportedOvers keeps a clone of the flag beside each
texture's weak handle, and wrote() reads it at the submission, where it read Leans::unbound:
`leans.unbound && addressed`. Metal does not define an address taken after the commit and written
for that command buffer to read, so reading the flag at the submission covers every address the
work can use.

Why one flag per block, not one per span: an address reaches its buffer's whole length, and an
exported block's one buffer spans the block. The consumer's facts: an exported block holds one
buffer, made by the host (video decode and encode buffers, probe buffers, surfaces' exported
memory), and no guest buffer lies in one. A copy-form surface's buffer also spans its block. A
per-span flag would therefore always equal the block's.

Why an Arc: the entry keeps its texture weakly, and holding the block would change when its
memory is freed.

The routes that set the flag (the contract):
- Buffer::gpu_address of any buffer whose bytes shaders reach in the block. This includes a
  Managed buffer whose device copy the consumer placed in an exported block, which
  new_managed_buffer allows ("a Private block the consumer holds"); the flag goes on the block
  whose address is answered (BufferObject::address_out).
- Device::new_exported_block. Its Block derefs to BlockInfo, whose pub gpu_address states the
  block's address, so the public make marks and counts its block. The copy form of
  Device::new_exported_surface calls the crate's exported_block(), which does not.
- A texture buffer's storage element at an index over the block's bytes. Its index reaches the
  bytes outside every bound slot, so its make marks the block.

What is not a route:
- A copy-form surface's block. The surface keeps its handle, so its address goes out only through
  Surface::buffer() and then gpu_address.
- The planes' resource IDs: they reach the textures' own images, not the block.
- An indirect command buffer's gpuResourceID: the address of its own records block.
- use_resource: tracked as a declared write.
- BlockMappings: neither hook runs for an exported block.
- The runtime's own bound-slot address pushes. The three internal reads on a &Buffer
  (tessellation factors, and the indirect execution's range buffer twice) now go through
  BufferObject::gpu_address, which marks nothing.

Kept apart: a command recorded while no texture over a buffer in an image of its own lived is
untracked. Today it sets Overs::unbound through after([], true), and it must still make every
texture owe. Overs and Leans now carry it as `untracked` (Overs::untracked), which wrote() still
reads as every texture. Bound slots, declared resources, copies back, acquires and fills are
unchanged. Inside a segment the Shared rules stand as they are; only the "every texture" clause
of the leading copy narrows.

Test (tests/exported_overs.rs, extended): new_exported_block's make counts 1 in
exported_blocks_addressed. Then an opaque-handle surface at a pitch multiple of 4096, which no
driver's pitch of a 256-byte row meets (the copy form, SurfaceCopy::Pitch). Its buffer is filled,
then four submissions each copy the plane out and then dispatch an owned synthetic kernel
(store_through, asserted writes_unbound) that writes through an address into another Shared
buffer, every word checked. Copies in are [1, 0, 0, 0] and the count reads 0. Once the surface
buffer's gpu_address is read, the count reads 1 and three more such submissions copy [0, 1, 1]:
the first owes nothing, because the submission before it went while no address of the block was
out. Every read finds the filled bytes. Without the bound, every submission after the first
copies (expected from the code: wrote() owed on Leans::unbound alone).

Verified at 67a05d9f57 (this tree, on a probe branch):
- compile job m3-max-66670: signatures check, refusal-surface check, fmt, clippy plain /
  --cfg m2v_gpu / --cfg m2v_cpu_icd, workspace Rustdoc -D warnings, api-docs, all exit 0. The rt
  suite on lavapipe: 642 passed, 3 skipped. The extended test on lavapipe printed "1 1 1 0" and
  "[1, 0, 0, 0], then out: [0, 1, 1]; blocks addressed 0, then 1".
- From the m2v_gpu archive m3-max-66672, the extended test printed "1 1 1 0" and
  "Copy(Pitch { plane: 0 }) ... [1, 0, 0, 0], then out: [0, 1, 1]; blocks addressed 0, then 1"
  on the RX 550 (RADV POLARIS12, Mesa 26.2.6, job m3-max-66678; that leg's rt suite: 644 passed,
  3 skipped), the Iris Xe (RPL-P, Mesa 26.2.6, job m3-max-66679) and the RTX 3090 (NVIDIA
  620.70.06, job m3-max-66680).

README: the exported block's rule names the routes and the count; the counters line gains
exported_blocks_addressed; the address contract says an exported block's address is one the
consumer read from rt before the commit.
2026-11-22 01:26:14 -08:00
Anees Iqbal 325e88c276 Runtime: an indirect offset off 4 is Metal's documented refusal; arguments past the end are ours
Refusal::IndirectOffset covered two cases under one `ours` basis. Metal's headers document
the first: "indirectBufferOffset must be a multiple of 4" (MTLComputeCommandEncoder.h for
dispatchThreadgroupsWithIndirectBuffer:indirectBufferOffset:threadsPerThreadgroup:,
MTLRenderCommandEncoder.h for the indirect drawPrimitives and drawIndexedPrimitives; Apple's
page for the indirect drawPatches sends its offset to the feature set tables, whose minimum
constant buffer offset alignment is 4 bytes). The headers state no rule for the second,
arguments that run past the buffer's end, which is the runtime's own check because Vulkan's
indirect commands read inside the buffer (VUID-vkCmdDispatchIndirect-offset-00407,
VUID-vkCmdDrawIndirect-drawCount-00487, VUID-vkCmdDrawIndexedIndirect-drawCount-00539).

- IndirectOffset { offset, length } is now the offset-off-4 case alone, Basis:
  metal-documented.
- New IndirectArgumentsPastEnd { offset, length, needed }, Basis: ours, for arguments at a
  multiple of 4 with fewer than `needed` bytes (12 dispatch, 16 draw, 20 indexed draw) after
  the offset, or an end that overflows.
- Both raise sites (the indirect dispatch, and the indirect draws' shared check) test the
  alignment first, then the length.
- Regenerated docs/REFUSALS.md and error/basis.rs (refusal_surface.py), and
  api_signatures.tsv (one variant added). The runtime README's indirect-draw paragraph
  names both refusals.

Tests: every_device_refuses_an_indirect_dispatch_off_4_or_past_the_buffer_s_end (compute)
and every_device_refuses_an_indirect_draw_off_4_or_past_the_buffer_s_end (draw) assert each
variant and its basis(): off 4 at 2 and at an offset that is also past the end (alignment
first), past the end at a multiple of 4 and at an overflowing offset, an indexed draw's 20
bytes where a plain draw's 16 fit; then the arguments in each buffer's last bytes dispatch or
draw and their results are read back. The compute refusal test's two IndirectOffset asserts
moved into the dispatch test.

Checked here: refusal_surface.py --check and signatures.py --check pass (source only).
2026-11-21 15:33:10 -08:00
Anees Iqbal 65cd6f18f9 Runtime: a texture over a Managed buffer's copy back is taken where its order with the reader is known
A reader of a Managed buffer's device copy took, as it was encoded, the copy back of any texture
over it that any command buffer had written, submitted or not, and cleared the flag the write's
submission reads. On one queue Metal runs command buffers in commit order, whichever was encoded
first, so:
- W (writes the texture) encoded before R (reads the buffer), R committed first: R copied the
  image back before W ran and cancelled W's copy back; a reader after both completed read the
  old bytes.
- R encoded before W, W committed first: R took nothing as it was encoded and nothing took the
  copy back at R's submission; R read the old bytes. The same held for R on another queue
  committed once the guest saw W complete, or ordered behind W by an event.

Now a reader takes as it is encoded only the copies back owed by earlier writes of its own
command buffer (each segment's written textures carry whether their copy back is still owed).
Those owed by other command buffers' writes, set at the write's submission, are taken by the
upload that leads the reader's submission, as take_into and the capture's copy-in already do:
on the device's one VkQueue that is where the order is known. A segment that reaches a Managed
buffer a texture over which an earlier segment of its held group wrote, its copy back owed,
leads its own group, so the write is submitted first (the capture fix's split). Entry.fresh
goes. No copy is added; the same copies back move to where their order is known.

Tests: three arms of one device test (tests/managed.rs): W encoded first and R committed first;
R encoded first and W committed first; R on another queue encoded first and committed once W
completed. Before this change all three were red on the RTX 5080 where run (64770: arms one and
two; the third arm was added with the fix).
2026-11-21 12:59:55 -08:00
Anees Iqbal 139d9ff4f6 Texture atomics declared with their format take no formatless bit: the interface says which slots are declared without one
A slot a texture atomic updates is declared R32ui or R32i (atomic_format), so its accesses need
none of VK_FORMAT_FEATURE_2_STORAGE_{READ,WRITE}_WITHOUT_FORMAT_BIT (VUID-vkCmdDispatch-
OpTypeImage-07027 to -07030 ask them only of an access declared without a format). The runtime
asked them of every storage slot: TextureSlot folds an atomic into read and write, so pipeline.rs
counted the atomic as a formatless read, and a texture buffer had a storage element only where its
format's buffer features hold the formatless write bit. On the Windows UHD 630 (driver 101.2145,
job m3-max-64024: R32_UINT's buffer features hold STORAGE_TEXEL_BUFFER and its atomic, and no
format's hold either formatless bit) the texture-buffer atomic test was Gap::StorageElement at
slot 0 (jobs m3-max-63951, m3-max-64074) though the device runs it. The image side has the same
count in code: an R32Uint texture's atomic was refused wherever R32_UINT's optimal tiling lacks
the formatless read bit, which Vulkan leaves to a device without
shaderStorageImageReadWithoutFormat (no device in the cluster lacks it).

- TextureSlot::declared_format: the slot's storage image is declared with a format (from its
  declaration). ARTIFACT_FORMAT_VERSION 590 for the codec field; no SPIR-V changes.
- The runtime checks a format's formatless bits only at slots declared without a format
  (Interface/Draws `formatless`), for compute and render alike. A written texture buffer's
  storage element is made wherever its format holds the storage texel buffer, and a formatless
  write of one whose format lacks the write bit is refused (unwritten()), at its slot and after a
  use_resource write declaration.
- Tests: DeviceOptions gains a device-test hook, `described`, an edit of the translator's
  description before Device::from_queries (the Vulkan device is the same). The texture-buffer
  atomic test runs on each device's own answers and as a device with no formatless texel-buffer
  bit (the UHD's answer); a new 1D R32Uint texture atomic test runs on its own answers and as a
  device without shaderStorageImageReadWithoutFormat and without R32_UINT's optimal read bit.
  Both edited runs refuse before the fix.
- Gap::StorageElement's doc and the runtime README say what holds now: a texture buffer at an
  atomic's slot runs on the UHD 630; an undeclared resource-ID write to a texture buffer whose
  format lacks the formatless write bit is outside Vulkan's valid usage, as such a read already was.
2026-11-21 09:22:15 -08:00
Anees Iqbal 70dfe08320 rt: every compute pipeline a command buffer binds goes through one bind that binds set 1 first
What: `Building::bind_compute` binds a compute pipeline where another or none is bound, and set 1
at the compute bind point before the command buffer's first compute pipeline. Both compute bind
sites use it: a dispatch's (encoder.rs `record_dispatch`) and the count kernel's of an execution
over a range a buffer holds (render_encoder.rs `execution_counts`). `Building::unbound` and
`Building::bind` go.

Why: the count kernel bound its pipeline through `Building::bind`, which marked the compute bind
point bound without binding set 1, and `record_dispatch` binds set 1 only before the command
buffer's first compute pipeline. Where a held-range execution came before a command buffer's
first dispatch, every dispatch after it in that command buffer ran with set 1 unbound, its
texture and sampler reads through a descriptor pointer the driver never set. The consumer's walks
of its rendering sample's ICB variant at the pin 5a04298008 lost the device on an RTX 3090 (an MMU
fault in warps on every GPC, a read at 0x4d000) and a 7900 XTX (a scalar data read, client SQC,
in no live range). With one bind for both sites no compute pipeline is bound without set 1.

Verified: the previous commit's test (a dispatch reading a texture through set 1 after held
executions in one command buffer) fails before this fix on lavapipe by a CRASH, not by value: job
m3-max-63866 ran it alone at that commit (then 6b0126de8a, on 583684ebeb) and the test process
died with SIGSEGV (signal 11) in 1.6 s, lavapipe reading the unbound set's descriptors; the
validation layer's VUID-vkCmdDispatch-None-08600 is recorded at the dispatch, but the crash ends
the process before the test's guard reads the layer's log. The compile and lavapipe jobs on this
commit, and one 3090 and one XTX leg, are reported with the sha.
2026-11-21 08:16:46 -08:00
Anees Iqbal 0f2067150f rt: a draw of lines carries DeviceLineRasterization on every device; the raster test holds the diamond-exit rule's cells
What:
- RenderCommandEncoder::LINE_NOTE (PrecisionNote::DeviceLineRasterization)
  is the static note of a draw of lines or a line strip, and of a draw of
  triangles under the Lines fill mode, on every device.
- A render pipeline state no longer carries the note; it carried it only
  under alpha to coverage or alpha to one.
- The note's text (artifact.rs, docs/API.md's catalogue, its items list
  and the accepted difference on a line's tie-break, the runtime's README)
  names its grounds, and keeps what it said of a state with alpha to
  coverage or alpha to one: there the device's default line rule draws,
  not Bresenham's mode. One note, both facts.
- The conformance side announces LINE_NOTE for each line draw and each
  Lines fill mode set. The note is among replay's NATIVE_NOTES, so it
  loosens the notices site alone.
- known-gaps-rt.tsv: the 12 primitive-type-restart-indices rows (NVIDIA,
  RX 550, Iris Xe) cite the note. Their lines run through the boundary
  point (3.5, 1.0).
- api_signatures.tsv gains the const's two rows
  (scripts/api-signatures/signatures.py --check passes).
- Tests:
  - raster.rs's Lines pass draws the triangle (-0.65, -0.675), (3, -0.675),
    (-0.65, 3) through the target's own viewport. Its edges at x 1.4 and
    y 6.7 lie inside the target with a pixel on each side, and strictly
    inside the clip volume and the viewport.
  - The pass holds the diamond-exit rule's cells exactly, column 1 and
    row 6, on every device. A device that draws another cell fails with
    the target drawn. It does not read the corner where the two lines'
    ends meet.
  - draw.rs's alpha-to-coverage test now holds that no state carries the
    note, and that LINE_NOTE is it.

Why the note: a card draws a line pixel that differs from Metal's. The 12
ledgered rows are lines through the boundary point (3.5, 1.0): Metal on an
Apple M3 Max covers the lower pixel there, NVIDIA's driver the upper. The
runtime draws lines with VK_LINE_RASTERIZATION_MODE_BRESENHAM. Its diamond
is open, so no Vulkan control decides that pixel. The Vulkan
specification's section "Bresenham Line Segment Rasterization" also lets an
implementation's fragments "not deviate by more than one unit in either x or
y framebuffer coordinates from a corresponding fragment produced by the
diamond-exit rule", with a fragment count within one. Rule 1: a line's pixels
are the device's answer, so the operation carries a static note.

Why the test changed: the old Lines pass put its bottom edge at y 7.7 through
a viewport of y -0.3 and height 8. The Iris Xe drew none of row 7 there
(m3-max-63429 at ce998742d7, m3-max-63507 at 7c1baad228). With both edges
strictly inside the clip volume and the viewport, the Iris Xe draws the
diamond-exit rule's cells, as the other cards do. The fractional viewport's
cut row is a separate item, not a line rule.

Verified, column 1 and row 6 at the test's geometry:
- Iris Xe: m3-max-63735
- RTX 2080: m3-max-63736
- lavapipe: m3-max-63737
- RX 7900 XTX: m3-max-63707, at the same edges
The exact-cell form's legs are named with its sha.

Not a regression: the Lines pass came with a5fac6fa9b (11-20 22:51), and its
viewport moved at 2a36291a80 (23:32). No Iris run of the old pass passed.
2026-11-21 08:02:39 -08:00
Anees Iqbal dd1f8acc46 rt: an execution of an indirect command buffer does not check the encoder's own buffer bindings
What: RenderCommandEncoder::draw checks each bound buffer's address against the state's argument
alignment (Refusal::BufferOffsetAlignment) except for an execution of an indirect command buffer,
whose commands bind their own slots; the facts stay unheld after an execution, so the next draw
checks the encoder's bindings.

Why: the conformance row indirect-range-written-by-an-earlier-draw (job m3-max-63647, d362164e47,
lavapipe) was refused: the earlier draw left the range buffer at offset 8 bound at vertex slot 1,
and the execution checked it against the commands' state's slot-1 argument (a float4, 16-byte
alignment), which reads no encoder binding. Plain Metal and Metal's API validation ran the row.

Verified: the row on the next check job's lavapipe replay.
2026-11-21 07:21:51 -08:00
Anees Iqbal 5a04298008 rt: the count kernel's shape call takes the state's compiled content; the refusal beside Accumulate; as_chunks in the new word readers
What: RenderCommandEncoder::execution_part passes the compiled content by reference
(&**compiled), as Indirect::shape takes it; the tuple built before the call took no coercion. The
runtime README's known gaps of render encoders name the execution over a held range refused while
a visibility query counts (VisibilityResultInterrupt) beside Accumulate's refusal: both need a
count carried across two queries with the parts added; the visibility section lists it among the
commands that end the rendering. The count kernel's interpreter test and the runtime's visibility
cell read their words with as_chunks, which the dated nightly's clippy asks for.

Why: job m3-max-63533 on d245bab9d1 failed clippy plain and --cfg m2v_gpu with E0308 at
render_encoder.rs:2801 (expected &RenderCompiled, found &Arc<RenderCompiled>).

Verified: by this commit's compile job (named in the lane's report).
2026-11-21 06:53:05 -08:00
Anees Iqbal d245bab9d1 rt: an execution over a range the GPU writes counts its parts with a kernel; parts bounded at 2 MiB of preprocess bytes
What: an execution of an indirect command buffer runs in parts of the most commands whose
preprocess bytes, as vkGetGeneratedCommandsMemoryRequirementsEXT answers with the inherited
pipeline, stay at or under 2 MiB (indirect::PART_BYTES), one rule on every device, in place of
parts of 64 commands. The device is asked from one command up, doubling while the answer stays at
or under the bound, then again at fewer in proportion to the last answer until it is, so no answer
at far more commands than a part takes is trusted (lavapipe's grows with the square of the count
and wraps at 32 bits). An execution over a range a buffer holds (executeCommandsInBuffer:
indirectBuffer:indirectBufferOffset:), location 0 included, ends the rendering, runs the
translator's new count kernel (pipeline::own_kernel(OwnKernel::ExecutionCounts), one workgroup a
part, its parameter block pipeline::ExecutionCounts in the ring), one global barrier, and begins
the rendering again; each part's vkCmdExecuteGeneratedCommandsEXT reads its count at
sequenceCountAddress: its commands through the range's last, none past it or wholly before its
location. A CPU-given range runs no kernel. While a visibility result's query counts the draws,
the execution is refused (Gap::Draw VisibilityResultInterrupt, counted), as the rendering cannot
end inside the query. The runtime makes its own kernels once a device, at first use, through the
pipeline cache and layout (runtime src/own.rs), and destroys them with the device. The idle
preprocess pool's bound goes from 128 to 64 MiB: one frame of the sample now takes about 27 MB of
commands' bytes plus at most one part an execution.

Why: an execution over a GPU range ran the buffer's whole capacity, every command past the range
costing its vertex work. Parts of 64 commands cost 61 times one execution's GPU time on the 2080.
RADV fails past about 4 MiB of generated commands in one execution (draws nothing on a 7900 XTX,
loses the device on a 780M): it chains by sequence count, not bytes. The 2 MiB bound is half that.

Verified: on the probe branch (d59701c670), jobs 63460 and 63481 measured the frame of Apple's
rendering sample: at the 2 MiB bound 931.8 us of GPU time on the 2080 (920.0 at whole capacity)
and 588.5 on the XTX. This commit: compile job and the lavapipe rt suite, reported with the sha.
Tests: the count kernel against a brute-force count on the interpreter and valid on every
committed profile; held ranges at 0, past a part, past the commands, and a CPU range across
parts; a held range in a Boolean visibility mode before and after its first draw; the widest
layout's part at or under the bound on every device.
2026-11-21 06:47:06 -08:00
Anees Iqbal b5ac9fd07b rt: visibility results, one precise occlusion query per mode, copied into the buffer at the pass's end
What: `setVisibilityResultMode:offset:` builds `Boolean` and `Counting`. Each such mode set is one
segment counted by one precise occlusion query (`VK_QUERY_CONTROL_PRECISE_BIT`), begun in the
pass's rendering before the segment's first draw and ended there at the next mode set or the
encoder's end; a segment with no draw begins and ends its query as it ends, so its word is 0.
After `vkCmdEndRendering` the pass copies the counts (`vkCmdCopyQueryPoolResults`, 64-bit, WAIT)
straight into the visibility result buffer's `VkBuffer` at place+offset, one copy for each run of
consecutive offsets in one pool, before the pass's second barrier (recorded or owed), which orders
them before every later command; a Shared buffer's segment end barrier reaches the host, and a
Managed buffer's write and a texture over the buffer in an image of its own are kept as a blit's
write is. `Boolean` writes the count too, nonzero exactly where a sample passed (Metal documents a
nonzero word; the M3 Max writes 1): an accepted difference in docs/API.md section 10, and the
conformance cases compare a `Boolean` word as nonzero alone.

A command buffer takes its queries from occlusion pools of 256 the device lends it
(`crate::visibility`), each query reset on the host (`hostQueryReset`) as the command buffer
retires or drops uncommitted; the device keeps at most 16 pools free and destroys the rest
(`Gauges::occlusion_pools`). `occlusionQueryPrecise` joins the floor's required features (every
venue's profile reports it; Roadmap 2022 requires it), with the README floor table, the
runtime-floor profile's `m2v_runtime_floor` block and the regeneration script's list.

Refusals: Metal's own, each where the mode is set, the encoder's mode unchanged:
`Refusal::NoVisibilityResultBuffer`, `Refusal::VisibilityResultOffset` (not a multiple of 8, or
past the buffer), `Refusal::VisibilityResultOffsetTaken` (Apple documents each offset as set once
per pass; Metal's validation stops it), and `Refusal::ArgumentPlace` at alignment 8 for an offset
at an allocation byte off a multiple of 8 (VUID-vkCmdCopyQueryPoolResults-flags-00823). Gaps, each
counted and a README known gap: `DrawKind::AccumulatedVisibilityResults` (a mode in an
`Accumulate` pass; `Metrics::accumulated_visibility_refused`) and
`DrawKind::VisibilityResultInterrupt` (a command that would end the rendering while a query counts:
a memory barrier after a writing draw, a draw that moves an attachment to the feedback layout, pays
an owed barrier before an attachment read or copies into a shadow, and, bounded, a draw that looks
at textures over a buffer in an image of their own or reaches a Managed buffer with textures over
its device copy; `Metrics::visibility_interrupts_refused`). Every refusal is checked before the
encoder changes state; a segment's first draw may still end the rendering, before its query
begins. `DrawKind::VisibilityResults` is gone. `RenderPassDescriptor::visibility_result_type`
(`VisibilityResultType`, Metal's `visibilityResultType`) is a field now.

Translator: `PrecisionNote::DeviceOcclusionCount`, the static note of a `Boolean` or `Counting`
result (`RenderCommandEncoder::VISIBILITY_NOTE`), quoting Vulkan's "Occlusion Queries" (precise
counts differ between implementations: fragments killed before rasterization, counts multiplied
per colour output) and "Fragment Operations" (`earlyFragmentMultisampleCoverageAfterSampleCounting`);
its codec tag, ARTIFACT_FORMAT_VERSION 588, validation's allowance (unbounded, no tolerance), the
conformance degradation `device-occlusion-count` among the native notes, and docs/API.md's
catalogue. The dead `Feature::CountingVisibility` (no construction site) is removed with its reach
row. The old runtime's `Device::new` is untouched; the runtime-floor test profile now states
`occlusionQueryPrecise`, which re-keys that profile's fingerprint.

Why: the visibility-cut ruling. A guest that sets a mode got a refusal; it now gets its results,
or a typed, counted refusal where the cut does not build the shape (continuations and a combine
are not built).

Verified: cargo fmt; scripts/api-signatures --bless/--check, refusal_surface (0 without reach or
basis), metal-coverage and conformance-coverage regenerated, check_device_profiles (0 findings).
The compile job (fmt, signatures, clippy plain / --cfg m2v_gpu / --cfg m2v_cpu_icd, workspace
Rustdoc -D warnings) and the lavapipe rt suite, with tests/visibility.rs (Boolean and Counting
against the CPU's counts, pool reuse and the 16-pool bound past 17, Metal's refusals, Accumulate,
the barrier and attachment-read interrupts), are named in the lane's report.
2026-11-21 06:16:57 -08:00
Anees Iqbal 22ae7df766 rt: indirect command buffers of indexed draws on VK_EXT_device_generated_commands
What: the first cut of Metal indirect command buffers, the runtime's half, in one commit: the
device's extension, the buffer object, the executions, the reset and the pool depend on each
other, and any part alone would be dead code.

- The device enables VK_EXT_device_generated_commands with VK_KHR_maintenance5 together where
  both are reported (floor::INDIRECT_COMMANDS), and nothing else chooses a form. maintenance5 has
  one form here: rt takes nothing of it but the BufferUsageFlags2 a preprocess buffer needs, and
  its A8 format stays untaken. dgc.rs declares the extension's structures by hand, each size and
  offset checked at compile time against the spec's layout; it goes once ash binds the extension.
- IndirectCommandBuffer, IndirectCommandBufferDescriptor and IndirectCommandType
  (Device::new_indirect_command_buffer): indexed draws that inherit the pipeline state and bind
  their own buffers, at most 31 a stage; records in a Private block, reset from the device's
  template at the next commit. gpuResourceID is the records' device address.
- RenderCommandEncoder::execute_commands_in_buffer (a CPU range) and
  execute_commands_in_buffer_with_range (a range read from a buffer, executed at full capacity
  with the SEQUENCE_INDEX token): one PUSH_CONSTANT token a run of slot words, the index buffer
  token and the indexed draw, through the inherited pipeline; the push constants and the index
  buffer are pushed again after an execution. Every execution runs as one
  vkCmdExecuteGeneratedCommandsEXT a part of CHUNK = 64 commands, in order, on every device (the
  planner's ruling: one execution of more drew wrong on the XTX past ~4 MiB of generated commands
  and out of order on the 2080 past 64 sequences); each later part pushes its first command
  (PushField::IndirectBase) and takes its own preprocess offset in the execution's one region. A slot a command binds is pushed the widest bounds,
  unchecked, as a loaded pointer's access is (README, SlotBounds).
- BlitCommandEncoder::reset_commands_in_buffer (copies from the template in regions) and
  optimize_indirect_command_buffer (no work); useResource of an indirect command buffer in the
  compute and render encoders, and RenderCommandEncoder::use_heap.
- Preprocess memory: sized from vkGetGeneratedCommandsMemoryRequirementsEXT with the inherited
  pipeline per (content, raster state, record layout) at a part's 64 commands in a cache of
  SHAPES = 256; layouts LAYOUTS = 64;
  templates TEMPLATES = 16, each at most 64 KiB. Each a fill-past-capacity test. A new pool of
  regions (its own VkBuffer and VkDeviceMemory each, usage2 PREPROCESS | SHADER_DEVICE_ADDRESS, a
  memory type from the requirements' bits, device-local first, rounded to 64 KiB): one taken at
  record time per execution (an idle one at most twice its need, else one made), given back when
  its command buffer retires, the oldest idle ones freed past IDLE_BYTES = 128 MiB. At rest it
  holds idle regions up to 128 MiB, freed at device drop. No execution waits or is refused for
  the pool's sake. Not the block mechanism: blocks are made with the floor's one usage on every
  device, and adding the preprocess bit on DGC devices alone would be a second form; the memory
  types come from the driver's per-layout requirements. Gauges of the used and idle bytes: flat
  between iterations 100 and 200, zero at device drop (tested).
- Typed refusals by name (Gap::IndirectCommandBuffers with IndirectCommandsKind): no extension,
  other command types, per-command pipelines (everywhere), inherited buffers, bind counts past
  31, capacity, an unflagged state, a draw input the commands cannot carry, more tokens than the
  device takes; Refusal::CommandRange for ranges past the commands.
- README: indirect command buffers and their known gaps (b1's two costs, the preprocess cost,
  lavapipe's preprocess size defect verbatim, the Iris, UHD 630 and Mac host lines, the parts
  and their measured cost), the
  extension rows; METAL-COVERAGE and REFUSALS regenerated; api_signatures blessed.

GetDeviceProcAddr audit (verified by grep of the runtime's loads): every device function rt
loads belongs to an extension enabled at the load. calibrated_timestamps is a floor extension;
feedback_loop_dynamic_state loads only under the feedback loop; device_fault loads only where
device creation enabled it; external_memory_fd,
external_memory_win32 and external_memory_host load only where enabled(); Dgc::load runs only
where INDIRECT_COMMANDS is enabled.

Verified: see the lane's report (compile gate, lavapipe and GPU device tests).
2026-11-21 01:53:50 -08:00
Anees Iqbal 99e5d42deb rt: several viewports and scissor rectangles, and the viewport index, through the with-count dynamic states
setViewports:count: and setScissorRects:count: refused any count but 1 (DrawKind::Viewports). They
now take 1 to 16 each, and every draw records them with their count (vkCmdSetViewportWithCount,
vkCmdSetScissorWithCount, core in Vulkan 1.3). VIEWPORT_WITH_COUNT and SCISSOR_WITH_COUNT replace
VIEWPORT and SCISSOR in every pipeline's dynamic states, whose viewport state counts become 0, so
no pipeline is made for a count. Vulkan takes as many scissors as viewports. Each viewport's
scissor follows the deleted runtime's rule (render_state.rs's vk_scissors at 5d725aeec7^): the
rectangle of its index, the one rectangle where one is set, and none past the rectangles set where
several are, each cut to the pixels its viewport covers. A draw's attachment-read area is the
union of what it covers through the viewports it reaches: every viewport set for a vertex function
that writes [[viewport_array_index]] (GraphicsState::writes_viewport_index, now Draws::
selects_viewport), and viewport 0 for any other.

A vertex function's [[viewport_array_index]] is the translator's one form at the floor: its
ViewportIndex output, written 0 at or past the encoder's count (RuntimeFact::ViewportCount), which
the draw now pushes (PushField::ViewportCount -> FieldValue::ViewportCount, refilled when the count
changes). Its fragment function reads the index as written. An index that is not one value across
a primitive stays the translator's refusal at creation, needing geometryShader, which device
creation does not enable. Out of range: none or more than 16 is DrawKind::Viewports.

Floor: multiViewport and shaderOutputViewportIndex join REQUIRED, and the translator is told.
The venue dumps report both true on every venue: m3-max-48727, 48728, 48729, 48730, 48731, 48736,
48737 and 61508. shaderOutputViewportIndex is also true in the probes 61359 to 61362 and 61366.
tests/floor.rs, the README floor table, RUNTIME_FLOOR and profiles/runtime-floor.json add them.

The translator's tests that read runtime-floor as a device without the viewport index now take it
below the floor: engine_selected_indices (the raw index alone without multiViewport; the zero
indices without shaderOutputLayer and shaderOutputViewportIndex) and engine_stage_io_tail (the
floor declares Layer and ViewportIndex; the zero index below it). runtime-floor joins the stems
whose fragment ViewportIndex needs MultiViewport.

Also, missed in a5fac6fa9b: the README's pipeline bullet names the depth clip and triangle fill
modes among what a VkPipeline bakes.

Conformance: render-state-boxes leaves known-gaps-rt.tsv; CONFORMANCE-COVERAGE.md regenerated.
Docs: README (encoder bullets, floor table, refusal list), REFUSALS.md (Viewports' doc), the
encoder's built list.

Tests: tests/viewports.rs. rt6_select draws through the viewport of its instance, two viewports
(the halves) and two scissors (the whole target and its top half). Instance 0 fills the left half,
instance 1 the right half's top, and instance 2, past the count, draws through viewport 0, its
fragment reading 2. No pipeline is made, and none or 17 viewports or rectangles are Viewports.
draw.rs drops its two-viewport refusal. floor.rs adds the two missing cases, and the translator
sees shaderOutputViewportIndex.
2026-11-21 00:34:20 -08:00