Commit Graph
585 Commits
Author SHA1 Message Date
Anees Iqbal b6131002df A compute pipeline's making names itself and dumps its module before the driver's call
With METAL2VULKAN_LOG_PIPELINES on, a compute VkPipeline's making now logs a line as it starts,
before vkCreateComputePipelines: the kernel, its SPIR-V hash and words and its specialization.
With METAL2VULKAN_DUMP_PIPELINES set, its module is written then, not after. A making that never
returns (a driver compile that runs for tens of minutes) is the start line without its made
line, and its module is on disk, where before neither the line nor the module appeared until the
driver returned. Default-off diagnostics; no product path changes.

The made line no longer writes the module (the start did). The compute log test checks that the
start line, with the same module hash, comes before the made line.
2026-11-13 00:21:49 -08:00
Anees Iqbal 03c587b9ee A large kernel's whole grids run on its partial-threadgroups variant
A kernel that observes its threadgroup partition runs its ragged dispatchThreads grids on its
partial-threadgroups variant, one VkPipeline of the call's threadgroup size (MultiRegion 1),
while its whole grids took the plain pipeline (MultiRegion 0): two driver compiles of the same
module. On a guest's run on an RX 7900 XTX the plain one, for a kernel of 2,415,531 words, was
26.9 s of a 39.8 s warm pass.

Now a kernel whose base module holds compile_memory::COUNTED_WORDS (65,536) SPIR-V words or more
runs every direct dispatch of a threadgroup size on that variant, every thread live, where its
ragged grids of the same form run there (it observes its partition, and for a one-row grid in
one-row threadgroups otherwise than through its simdgroups alone, whose such grids run flat).
Where the variant is refused it falls back to the plain pipeline as before. Smaller kernels keep
the plain pipeline. Both forms give the same answers, so there is no switch and no FAST-PATHS
row.

- Binder: on a partial-threadgroups plan, a whole Threads grid takes the same L-sized regions
  per group-count chunk, unflagged (no NONUNIFORM), and a Threadgroups dispatch's regions have
  MultiRegion 1, so one specialization of a threadgroup size runs all of them.
- Translator API: CompiledFunction::observes_threadgroup_partition and
  observes_partition_through_simdgroups_alone state the two partition facts the compile already
  decides, so the runtime can decide at creation which form a kernel's ragged grids take.
- Runtime: compute::partial_direct takes whole grids and dispatchThreadgroups of such a kernel
  (ComputePipelineState::whole_on_partial). WorkCounts::whole_dispatches_on_partial_variants
  counts each such dispatch. A creation's predicted region is not made for such a kernel's
  predicted dispatch, which would run on the variant, not the base.
- GPU cost, measured once on the XTX (RADV) with the probe on steelbrain/uniform-partial-probe:
  1,048,576 threads in 64, partial/plain 0.997 to 1.020 over four straight-line kernels, words
  equal. Stated at partial_direct and in docs/API.md's dispatch-regions paragraph.

Tests: engine_partial_threadgroups's whole_grids_run_on_the_partial_plan_with_every_thread_live
(whole Threads and Threadgroups dispatches on the partial plan give the split's and Metal's
words, and every grid of a threadgroup size takes one specialization, on the CPU interpreter);
the runtime's a_large_kernel_s_whole_grids_run_on_its_partial_variant (a large kernel makes one
VkPipeline over whole grids of both forms and a ragged one, counting 3 whole dispatches, with the
plain pipeline's words; a small kernel makes the plain pipeline's and the variant's, counting 0).
heap_trimmed makes its two large makings at two threadgroup sizes, since its whole and ragged
grids now share one.
2026-11-13 00:18:06 -08:00
Anees Iqbal 9f3dc79994 A Managed buffer's named range is copied in by the GPU as the submission runs, by default
What: DevicePolicy gains managed_copy_in (ManagedCopyInPolicy, a runtime
choice no profile carries). Under the default, AtSubmission, a commit that
takes a did_modify_range's range has the GPU copy it from the host copy (the
import of the caller's pages, or the runtime's own host-cached memory) into the
device copy as the submission runs (Buffer::upload), with no CPU copy and no
staging. Pages no import maps are still staged by the CPU at the commit. Under
AtCommit, which exact_answers() selects, the commit copies the range on the
CPU as the host copy holds it then (the RV2145 snapshot, Buffer::upload_now,
now upload_at_commit). Staging buffers of both directions are now Shared in
the default CPU cache mode, host-cached system memory, never the device-local
(BAR) memory a write-combined buffer prefers without unified memory, and of
power-of-two lengths (64 KiB at least), so a like-sized later copy takes a
buffer the recycler parked rather than new memory.

The ledger gets its row (the bound: a CPU write after the commit, before the
GPU runs the command buffer, may be read), and managed.rs, managed_copy.rs,
API.md's accepted difference, the runtime README, FAST-PATHS' costs bullet and
the conformance crate's Policy::Exact say so. tests::fast_paths names the
choice and checks it keys no profile and that exact_answers() takes AtCommit.
The named-rounds race tests take the policy: by default each round reads, in
each byte, its own byte or one the CPU wrote to its buffer after its commit
(0xee, a later round's), never an earlier round's; under AtCommit only its
own; three AtCommit tests join the three default ones. The lane test's step 4
reads either oracle's answer by default and the 5300M's under AtCommit
(exact_answers_take_a_did_modify_range_at_the_commit).

Why: a compute benchmark's commits spent most of their time in this copy on a
discrete GPU (a CPU memcpy into write-combined staging in BAR across an eGPU
link, fresh 32 MiB chunks each time). The oracles differ on the bytes after
the commit (5300M A,B,B,A,B; UHD 630 A,B,B,B,B), so the cheaper answer is the
default and the snapshot stays behind the switch (AGENTS.md rule 1).

Verified: jobs in the report (lint both cfgs, the translator's fast_paths, the
runtime suite on lavapipe, managed_copy_device and the lane test on the RTX
3090 and the RX 7900 XTX, and the copy-in bench there before and after).
2026-11-12 23:57:16 -08:00
Anees Iqbal 7b77851a95 Runtime attachment images start at zero where an unstored DontCare load stays DONT_CARE
What: Device::new_planned_texture, which makes the runtime's own images (the
scratch image of separate depth and stencil textures, stand-ins, backings,
colour twins), starts an image with color or depth/stencil attachment usage
that a clear writes at zero (Start::ZeroUnpatterned) on a device whose
unstored DontCare loads stay the driver's DONT_CARE
(clear_reach::UnstoredLoads::DontCare: UnstoredDontCarePolicy::Driver on a
driver without DriverFact::UnstoredClearNoSlower). Elsewhere it starts as its
memory lies, as before. FAST-PATHS' unstored DontCare row and API.md say so.

Why: such a load reads what the image holds (a depth or stencil test, a
blend, a fetch). A Private runtime image started as its memory lay, and a
recycled one may hold a released texture's texels, of another process of a
consumer whose processes share the device. Devices that clear such loads read
nothing of it, so they pay no clear.

Verified: tests::unwritten_parts on lavapipe and Iris Xe (jobs in the
report).
2026-11-12 23:41:01 -08:00
Anees Iqbal ae413fd7e9 Half sqrt at 16 bits: its bound belongs to NativeTranscendentals, which it records
On a device whose float functions are not Metal's, a half sqrt is the
device's instruction for Metal's function and records
NativeTranscendentals (function_notes), not DeviceArithmetic. The 16-bit
Sqrt's bound moves to that note's doc and its catalogue entry; the
division test asserts NativeDivision and NativeTranscendentals, as the
Iris Xe profile records (job 24519: [NativeTranscendentals,
NativeDivision, NativeNanEncoding]).
2026-11-12 23:20:51 -08:00
Anees Iqbal ab56a1c88e Half division and square root at 16 bits under the 16-bit float controls
Rule 1: where the module computes half in 16 bits under the 16-bit float
controls (QuantizeForm::Controlled), the device's native form of a half
division and square root is its 16-bit OpFDiv and Sqrt, so those are the
only form there; elsewhere the float instruction rounded to half stays.

- divide::native: a half quotient under the controls narrows its operands
  (exact, they are halves), scales a divisor past 2^14 by 2^-2 and a
  denormal one by 2^10 into Vulkan's range for the 16-bit OpFDiv
  ([2^-14, 2^14], 2.5 half ulp), divides at 16 bits and widens. The
  scaling is exact but where the quotient rounds to zero or overflows
  anyway.
- math::float_fn: a half sqrt under the controls is the 16-bit Sqrt
  between exact conversions (Vulkan: inherited from 1 / InverseSqrt).
- narrow::computes_in_16_bits counts 16-bit FDiv and Sqrt, so the entry
  declares the controls (denormals kept, IEEE zeros, infinities, NaNs).
- ops: float_ty and f16_splat, shared with f16_binary.
- NativeDivision and DeviceArithmetic state the 16-bit bounds; docs/API.md,
  docs/FAST-PATHS.md, the narrow and half_hold module docs follow.
- Test: engine_half_hold's half_division_and_sqrt_are_16_bit_under_the_
  float_controls (Iris Xe and RADV: 16-bit FDiv x2 and Sqrt, none at 32,
  no exact narrowing, the exact answers on the interpreter, L3, the notes;
  lavapipe: the float forms, the same answers).

Verification: in the following potluck runs (FConvert count on hnq,
the half engine tests, spirv-val, clippy, the suite).
2026-11-12 23:20:51 -08:00
Anees Iqbal bbf86acd0e The encoder trail names each execution's GPU form, and its line reads the form's scratch while pending
The 3090 hang's rerun (its trail line, read in place) named a pass whose two executions of
indirect commands, both through ranges a buffer holds, carried no host-step note: commit recorded
them for good in their merged GPU form (render/executions/gpu.rs), where the trail noted nothing,
so the line could not tell what the GPU read.

encoder_trail.rs:
- GpuForm: an execution's GPU form, its shape (recorded at commit or by its host step, merged or a
  draw per command, indexed, primitive type, the commands its preprocess runs over and from where,
  and the range buffer's offset), with its scratch region, layout and the command buffer's status
  words.
- Named: a part's (and a batch's) trail text with the GPU forms its executions took; the line's
  front batch is described with each form's scratch read now: the range the GPU copied, the
  merged draw's two VkDrawIndirectCommands, the commands whose arguments draw, their vertices or
  indices times instances and the most of them (its index entry where indexed), and the status
  words. The last-completed batch keeps its text alone.
- Step carries forms through a host step; commit's recording of each segment runs under a Step of
  its own (CommandBuffer::noting_forms), whose forms alone it keeps, joined to the part that holds
  the segment (State::trail_forms).

upload.rs: Upload::glimpse, volatile u32 reads of a region of the host-coherent chunk mapping,
read-only, no lock, no wait. completion.rs: the line's names are taken under the pending lock and
formatted (and the scratch read) after it. Off, nothing changes: no note is made.

Test: tests::trail_gpu_forms (device): four CPU-written triangle commands through a range buffer
of [1, 2], recorded at commit merged; after completion the form reads the range 1+2, the merged
draws [2147483646 x 0; 48 x 1 from vertex 2^31], 2 drawing arguments (7x2, 12x3), the most
command 2's, no fault.
2026-11-12 23:03:44 -08:00
Anees Iqbal 158f9788b5 Half holding: the dot and mix bounds are NativeDot's and NativeMix's, a test, the docs
A half dot or mix already records NativeDot or NativeMix on every device,
so the DeviceArithmetic scan the previous commit added in compile.rs is
removed, and those two notes' docs (artifact.rs, docs/API.md's catalogue)
and docs/FAST-PATHS.md's device-gap row now state the 16-bit form and its
bound: a 16-bit dot of n lanes within (3n - 1) * 2^-11 * sum |a_i b_i| +
(3n - 1) * 2^-25 of Metal's chain (2n - 1 correctly rounded 16-bit
roundings beside Metal's n), a 16-bit mix within 2^-8 of its two terms plus
2^-22. narrow.rs's module docs, lower/arith's dot and mix comment, and
docs/ARCHITECTURE.md (the tidy stage and the spirv/ map) name the pass.

tests::engine_half_hold: a kernel of half min, max, clamp, dot, mix, a
loop-carried half and a thread array of half; on the Iris Xe and RADV
profiles it narrows no exact half, its four input roundings are its only
narrowings and its result's its only widening, its dot, mix and bounds are
16-bit instructions, no float variable stays 32-bit, it answers 33.25 on
the interpreter, passes L3 and records NativeDot and NativeMix; on lavapipe
(Converted) nothing is held and it answers the same.

Verification: not yet run (the build and tests follow).
2026-11-12 22:47:26 -08:00
Anees Iqbal c35df96940 The memory log's lines state glibc's heap and the process's heap trims
A default-off diagnostic (METAL2VULKAN_LOG_MEMORY). Where the process's
allocator is glibc's (Linux, the GNU environment), each line of the memory
log now ends with glibc's heap at that moment, every arena's, as mallinfo2
states it (bytes in use, bytes free, what its arenas hold, what it mapped
apart) and the malloc_trim calls the process's large makings made so far
(a process-wide count beside WorkCounts::heap_trims). A resident set that
grows and stays then reads, in one run, as free heap glibc keeps, heap in
use, or memory malloc did not map. Elsewhere the lines are unchanged.

Test: the_memory_log_states_glibcs_heap_where_it_is_the_allocator.
2026-11-12 22:29:54 -08:00
Anees Iqbal 1b58b69953 A kernel's partial-threadgroups variant: a ragged dispatchThreads at the call's threadgroup size
A dispatchThreads grid that is not a whole number of threadgroups split into
its interior and an edge region per axis, each edge a VkPipeline of its
remainder's local size: a kernel dispatched at many remainders made one
pipeline per remainder (Blender's Cycles on an RX 7900 XTX: 249 s of a
265 s warm render was 11 such creations).

LoweringInputs::partial_threadgroups (VariantKey::partial_threadgroups,
RuntimeFact::PartialThreadgroups) runs such a grid as the threadgroups its
threads fill at the call's size, the region flagged NONUNIFORM, the last
threadgroup along an axis answering Metal's partial threadgroup with the
object functions' machinery: threads_per_threadgroup, positions and indices
over the threads left, invocations past them returning before the body or
walking it predicated to each barrier, every lane read balloting its live
lanes. A tile function, a stage-in region, compute derivatives, emulated
simdgroups, the flat/folded/replay forms and a vote word that does not fit
are refused (GpuEncodedIndirectCommands, NotImplemented): they keep the
split. The runtime takes the variant after the flat one (settle_partial,
refusals remembered per state); the pipeline creation log names a probed
variant's refusal declined.
2026-11-12 21:59:10 -08:00
Anees Iqbal 3a3c2fb3fd The encoder trail names each host-stepped draw's route, and the pipeline pool at a stall
For the 3090 hang, where a shadow pass's host step and a rate-mapped pass's fan-out ran in the
same second: the trail now counts, per host step, the route each draw took (plain, the fan-out
probe, fanned out, region by region) and the executions recorded in their GPU form, and its stall
line names the device's pipeline pool's makings waiting and under way, so a driver compile
running beside a hung batch shows. Default off.

Verified: encoder_trail::tests and tests::stall (the line names the pool) in the check job.
2026-11-12 21:41:04 -08:00
Anees Iqbal abacc1222e The encoder trail names what a host step drew: ranges read, draws, the largest, kept chunks
A stalled host-stepped render encoder's trail line named its states but not what its step
recorded from the records and range buffers the GPU wrote, which is where a wrong count would
come from. With the trail on, a host step now notes each range it read from a buffer (location and
length as the bytes held them, and the commands it ran), its draws, their vertices or indices
times instances summed, the draw of the most of those (primitive type, count, instances), and the
kept chunks it ran again, whose draws it did not read. Default off: nothing is read or formatted
with the trail off.

Verified: the trail unit test (encoder_trail::tests) covers the line's new part.
2026-11-12 21:41:04 -08:00
Anees Iqbal 7093ca7911 A new Private texture whose first use writes every texel first takes no zeros
What: a new zero-filled Private texture's first move is marked overwritable
(FirstMove::mark_overwritable). An encoder notes each such texture it writes
whole before any of its commands reads it, decided from its own description,
never a shader's (encoder::Overwrite, on its first part):
- a render pass that loads every aspect of it Clear (as the descriptor set
  it, before DontCare loads take clears) and stores it, rendering it itself
  (no stand-in, sample planes or separate depth and stencil scratch) over its
  whole extent, the image of one level and one layer
  (PassLayout::overwrites);
- a blit command whose box covers its whole extent in every aspect
  (BlitCommandEncoder::scrub).
At a batch's take (command_buffer/submit.rs, first_overwrites), an
overwrite counts where its part has no segment, only blit parts with no
segment that name nothing of the image come before it (any other encoder may
reach a texture through its resource ID, unnamed), and the part's own uses
read nothing of the image but its attachment's own reads (a pass) or
nothing at all (a blit). FirstMoves::take_holding then takes that move
without its zeros (unzeroed, undone if the submission is given back): the
layout move stays, and batches on other VkQueues wait for this batch as for
any first work. A part that runs nothing drops its overwrites (fail_part).
DontCare and Load first uses, and partial writes, keep the zeros. Counted:
WorkCounts::private_textures_overwritten_unfilled (new public field,
signatures re-blessed); the runtime README and docs/API.md say so.
tests::first_overwrite checks both paths (whole pass, depth pass, whole
copy, a recycled image's clear; DontCare, Load, a partial copy, a clear after
another pass) and first_overwrite_costs (ignored) prints OVERWRITE-COST,
for textures made together before the first commit (the first submission
takes every waiting first move, so only its own texture goes unzeroed) and
for textures each made just before its own command buffer (every one does).

Why: the zeros are for isolation only (main's plan for pin 64): a first use
that writes every texel before anything reads one never shows them, and
they cost the Iris Xe up to 0.22 ms a 2048² depth texture (job 24088).

Verified: before this replay onto development, at 9ab0b01426 (on a67e1e3d55):
the validation lanes touching first moves, recycling, clear reach, resolves,
blits and heaps on lavapipe (job 24205, 358 passed); on the Iris Xe (job
24218) tests::first_overwrite, memoryless_fresh and recycle (9 passed;
FIRST-OVERWRITE whole: 1 each) and OVERWRITE-COST zeroed against skipped:
made together, 8 RGBA8 1024² 2.136 against 2.100 ms median, 2 Depth32Float
2048² 1.693 against 1.487 ms, one texture a burst unzeroed. At this commit,
tests::first_overwrite and the runtime suite on lavapipe, clippy (plain and
m2v_gpu) and rustdoc, and the each-made-before cost on the Iris, reported
with this sha.
2026-11-12 21:32:27 -08:00
Anees Iqbal 5877117603 A device's recovery carries its rasterization rate maps
A rate map held its device as the generation handle it was made on. After
a recovery from the loss of the VkDevice, a render pass over a map made
before it met that handle in its descriptor's check (rate_mapped_pass.rs
check_descriptor: map.device().same(device)) and was refused,
NotImplemented(MadeBeforeRecovery), at every encoder, as Metal's map goes
on: a consumer's offscreen pass was refused every frame after a real
recovery on an RTX 3090, the pass's 938 textures carried.

A map holds no Vulkan object, so it now holds its device as a fence or a
depth/stencil state does (LineDevice): the recovery carries the handle, a
pass's and a copy's checks match its root handle by its line, and its
reads (the zero-layer notice, a reset's registry of command buffers to
encode again) take the generation it was carried to last. Its public
device() answers that generation's handle, owned, as the other such
objects' do (it answered a borrow). The recovery also carries the
device's note that a map of layers was released, which a later map of no
layers reads.

The device test a_rasterization_rate_map_goes_on_past_a_recovery encodes
a pass over a map made before a recovery, commits it and waits for it to
complete, copies the map's parameter data into a buffer of the next
generation and resets the map; an_objects_device_keeps_meaning_its_
generation_past_a_recovery takes the map's device among the others'. The
recovery notice's, the refusal's, the README's and docs/API.md's lists of
what a recovery carries name the maps.
2026-11-12 21:25:03 -08:00
Anees Iqbal 5eb107ac89 A new Private texture reads zero on every device: never the bytes its memory held
What: new_texture_image starts a Private texture zeroed (Start::Zero) on a
device that presents an Intel or AMD Mac, as it did on an Apple GPU presenting
one: its first move clears it, or copies zeros, or takes the driver's zeros
where the block is fresh. Only a Memoryless texture starts held.
private_textures_zero_filled counts each. WorkCounts::private_textures_unfilled
goes, as nothing counts it now.
- The recycled image a new texture takes (recycle.rs) and a recovery's remade
  texture (texture/carry.rs, Remake::Own through texture_as) go through the
  same making, so both read zero.
- Tests: mac_class (an Intel or AMD Mac's new texture reads zero, counted as
  zero-filled); the parent's recycle test.
- Lanes: fresh_contents and fresh_costs expect zeros there, counted.
- Docs: API.md's accepted difference, the runtime README, MacClass::IntelOrAmd,
  conformance's without_compression.
- api_signatures re-blessed (the field goes).

Why: Start::Held matched a Mac with an Intel or AMD GPU, where a new Private
texture can read a released texture's texels. On such a Mac those texels are
the same process's. A consumer that serves several processes from one device
showed one process another's pixels that way. The 780M read a released
texture's colour through a recycled image (m3-max-23995). After a forced
recovery on the RX 7900 XTX, a guest window read other windows' pixels. Zero is
what those Macs read where their memory held nothing, and Metal leaves the
contents undefined.

Verified: the lane run reported with this sha (the recycle test of the commit
before fails on lavapipe, the 780M and the XTX; this one passes).
2026-11-12 20:36:13 -08:00
Anees Iqbal b95bd50ae6 The encoder trail's API.md paragraph: the stall probe and the watchdog count as without it
Rewrapped after the rebase onto the watchdog (b6c52f1fa9); says the trail's line comes before
the stall probe and the watchdog, which count with the trail on as without.
2026-11-12 20:33:17 -08:00
Anees Iqbal efcb6851ce The encoder trail: name the encoder a stalled GPU stopped in, and the last one that completed
A GPU hang (a CTX SWITCH TIMEOUT on an RTX 3090) left the runtime with no way to say which
encoder never completed: encoders share batches and grouped submissions, and neither
METAL2VULKAN_LOG_PASSES nor METAL2VULKAN_QUEUE_TIMES logs anything at a stall.

METAL2VULKAN_ENCODER_TRAIL (env_vars.rs), or DeviceOptions::encoder_trail for one device, is a
default-off diagnostic (encoder_trail.rs):

- Each encoder, and each part of one a host step splits off, ends its batch (Batches::alone),
  and no batch waits in a group, so each goes in a vkQueueSubmit of its own that signals its
  queue's timeline. When work goes to the driver changes; what it computes does not.
- Each encoder notes what it was: its kind, its command buffer's object ID, its place, a
  render pass's area, samples, attachments' formats and sizes, instances and rate map, its
  indirect command executions, and the label hash of each state it bound (the first 8 bytes
  of a SHA-256 of the state's label and its functions' names; no name, no shader text). A host
  step adds the states its indirect commands named, as the GPU and the CPU left the records.
- Once no work of the device advanced for 2 s with some pending, completion.rs's stall path
  logs one Info line (id name metal2vulkan-encoder-trail) for each VkQueue whose oldest batch
  is pending: that batch's encoders and the last batch the queue completed, with how long
  before; once a stall.
- A submission a host step makes and waits for itself (a rasterization-rate map's fan-out
  probe, a predicated loop's check run again) signals no timeline; once it ran 2 s, one line
  names it, the encoder whose step made it and the states its commands named.

Off, a device reads the switch once and notes nothing.

Verified on msi (lavapipe, --cfg m2v_cpu_icd), at the branch tip this commit's tree equals:
- tests::stall::the_encoder_trail_names_the_stuck_encoder_and_the_last_one_completed: a cb
  stuck on an event wait before two blit fills; the line names the stuck cb's encoder 0 (not
  its encoder 1) and the earlier completed cb's encoder 0:
  "VkQueue 0's oldest pending batch: Blit encoder 0 of command buffer 3, states []; the last
  batch it completed: Blit encoder 0 of command buffer 2, states [] (2.106823047s before)".
- tests::rate_mapped_fan_out::the_encoder_trail_fans_out_the_same_pixels: with the trail on,
  probes/flagged/fanned [1, 1, 6] as without, no texel differs from the encoder's own draws.
- The host-step families (rate_mapped_fan_out, rate_mapped_pieces,
  indirect_command_buffer_device, host_step_neutrals, ycbcr_in_place_loop) with
  METAL2VULKAN_ENCODER_TRAIL=1: 11 passed.
- encoder_trail's unit test (one state's hash pinned: a reader of the pipeline creation log
  computes it again); the runtime suite 1504 passed; api_ tests 16 passed; clippy all features
  and the runtime under m2v_gpu and m2v_cpu_icd; rustdoc of the runtime and metal2vulkan.

The runtime-sources pin moves (not re-pinned here).
2026-11-12 20:33:17 -08:00
Anees Iqbal d4ab197556 Metal's command-buffer watchdog: a front batch 20.2 s without its timeline advancing fails as Metal's timeout
reims's 3090 boot after an Xid 109 (CTX SWITCH TIMEOUT) had its graphics queue's batch never
complete while the copy engine ran on: the staging probe completed 23 times in under a
millisecond, so the stall rule found the GPU running and nothing failed. The probe stays; beside
it each queue's front batch now has its own clock (stall::Clock::front_held), which runs while
its waiter's waits run out with it pending and stops whenever its queue's timeline advances,
whatever the probe answers. Past stall::WATCHDOG (20.2 s, the x86 AMD Mac's measured bound and the
largest of Metal's) the front fails as Metal's timed-out command buffer (GpuHang, code 2, named
exactly: its queue is known, no inference), the rest in flight as GpuRecoveryVictim, and the
generation is marked stopped (Stop::Watchdog), parked and recovered from as a wedge; the notice
says the watchdog stopped it. Counted: WorkCounts::watchdog_timeouts (wedges_declared keeps the
unanswered probe's stops).

Measured on the M3 Max (macOS 27.0.1, a Swift probe): a command buffer waiting for an event no one
signalled, shared or plain, failed with MTLCommandBufferErrorTimeout ('Caused GPU Timeout Error
(00000002:kIOGPUCommandBufferCallbackErrorTimeout)') 5.00 s after its commit, nothing of it run;
two such on one queue revoked it (the next fill failed AccessRevoked 0.24 ms after its commit,
a new queue ran). So the clock counts event waits, as Metal's does, and the watchdog's GpuHang
counts against its queue as any timeout (revocation.rs says so; the count is QueueCommon's and
carries over a recovery, as Metal's queue keeps it).

Tests (tests::stall): the stuck front with an answered probe fails at the hooks' 1 s bound, no
sooner, as GpuHang, parks the generation and runs the next command buffer; the answered leg
whose front advances within the hooks' 3 s fails nothing. Docs: stall.rs, revocation.rs,
docs/FAST-PATHS.md known gap, docs/API.md, the runtime README, WorkCounts, api_signatures.
2026-11-12 20:29:01 -08:00
Anees Iqbal c7362776d0 Let carried textures' and pipeline states' parts go at the lost generation's rest
What: a recovery's carried textures and pipeline states let go of their
parts on the lost generation once it comes to rest, as buffers already
did, so the lost VkDevice goes while they live.

- device/carry.rs: LetGo<T>, the let-go cell MadeOn was (MadeOn is now
  LetGo<Device>), and PartsCalls/CallHold, one guard generalised from the
  buffer's calls and HeldParts: a call outside command buffers' work counts
  itself, and a release at rest waits for the last call to end. Buffers
  use it unchanged in behaviour (Buffer::held_parts, LostBuffer,
  LostPlaced, LostHost).
- Pipeline states: StateShared.program and ProgramLink.program are LetGo
  cells. The carry hands the lost generation a LostProgram, which drops
  the state's program there in place at rest (its variants' objects,
  plans, makings and its Device). reached() skips programs let go of. The
  state keeps its own copy of its label, so label()'s borrow outlives the
  program. Holds: the public state methods that reach the program,
  program(), Debug, and the argument encoder's and indirect commands' set
  paths.
- Textures: TextureShared's per-generation parts (storage, moved,
  pending_move, usage_shadow(_making), faces, snapshot, kept_backings,
  render_shadow, facts, planes_in_place) move into Parts in a LetGo cell,
  read through Deref. The carry hands the lost generation a LostTexture.
  At rest it leaves the texture's slot in the lost generation's table and
  heap sets, hands the caller's range token to the parts on the next
  generation, and drops the parts in place. Parts with a handed-out VkImage
  (Texture::vk_image) stay until the texture goes. Texture::s() skips parts
  let go of. Holds: the public texture methods that reach parts, and
  vk_image; a view's hold holds its root texture too. slot_keeper names a
  texture buffer's generation by its texel views, not by the buffer's
  serving generation.
- WorkCounts::lost_programs_released and lost_textures_released, counted
  on the line.
- Public signatures: ComputePipelineState::device,
  RenderPipelineState::device, FunctionHandle::device and
  VisibleFunctionTable::device now answer an owned Device. The last two
  also borrowed from the state's program. Command-buffer paths use the
  crate-private borrowing generation(). api_signatures is blessed.
- Docs: the carry module docs (device, pipeline, texture), docs/API.md's
  recovery entry, the runtime README's recovery paragraph, vk_image's doc.
- Tests: the four recovery tests in 99dbc69666 also assert the counters.

Why: a carried texture kept its images on the lost generation, and a
carried state its program there, until the object went, so the lost
VkDevice lived as long as any of them. A long-lived program kept it for
good.

Verified: cargo check of the workspace, all targets and features, under
no cfg, m2v_gpu and m2v_cpu_icd, clean but for one validation call site
fixed here (jobs m3-max-23824, 23852). The lavapipe lane (the tests of
99dbc69666 before and after), the suite, lint and the 780M run follow.
2026-11-12 19:32:06 -08:00
Anees Iqbal 41337099f5 Time a rate-mapped pass's pieces on a device asked for host-clock GPU times
A device made with DeviceOptions::gpu_times_from_host wrote no timestamps
at all, so a pass recorded in pieces read no piece time there
(rate_map_pieces_timed 0): a guest frame on an RTX 3090 cut into 126
pieces gave no hint which piece or draw was long. The option only spares
command buffers' own two timestamps; the piece timer and the host step's
probe now write theirs on such a device. They still skip where the driver's
timestamps wait for every queue's (FromHost::Driver, MoltenVK), since there
a timestamp would serialize the device's queues.

The option's docs, the gpu_time module's, the degrade notice's, the API
catalogue's and the work counts' say so.

Verified: the new runtime test
a_device_answering_gpu_times_from_the_host_times_its_pieces passes on
lavapipe (12 pieces past the first, 13 timed) and on an RTX 3090 (NVIDIA
620.70.06, the same counts), built at the branch's earlier commit with the
same runtime source.
2026-11-12 18:54:27 -08:00
Anees Iqbal 64982ac827 A GPU that stops with no loss from the driver fails its work and is parked
On NVIDIA after an Xid 109 the device's queues stopped: no batch completed and
every completion wait answered VK_TIMEOUT, never VK_ERROR_DEVICE_LOST, so the
program's command buffers waited without end.

The completion's waiters now keep a device-wide stall clock
(command_buffer/stall.rs): it runs while a wait ran out with its front batch
pending and stops whenever any queue's timeline advances. Past 10 s one waiter
probes the staging queue (NVIDIA's copy engine) with a submission of nothing
that waits for nothing, and for up to 2 s reads the probe's answer and the
stuck front's fence (a wait of no time) and timeline
(vkGetSemaphoreCounterValue); a loss either read answers takes the failed
wait's path at once. One informational message, metal2vulkan-stall-probe,
names the stall, the probe's answer and each read's last VkResult. A probe
answered, or a front that advanced, fails nothing and restarts the clock, so a
device that still makes progress is never failed whatever its work's length.
A probe unanswered in 2 s stops the generation: Device::mark_wedged marks it
stopped and lost, the wait fails as a lost device's (the oldest command buffer
as GpuHang, the rest GpuRecoveryVictim), and the line recovers; the
DeviceRecovered notice says the VkDevice stopped and was parked.

Parked: release.rs's door leaves every object of a parked VkDevice, the device
itself included; DeviceShared::queues_idle waits for none of its queues, and
its teardown returns before vkDeviceWaitIdle, keeping the instance. New public
query Device::is_parked(vk::Device) -> bool (no Metal counterpart), for a
consumer that holds the stopped generation's handles. Counters:
WorkCounts::stall_probes_sent, wedges_declared, longest_stall_nanos. A device
without a staging queue sends no probe (FAST-PATHS known gap, with the leak and
Metal's bounds: about 5 s on the M3 Max, 20.2 s and 16.1 s on x86 Macs' AMD and
Intel GPUs).

Tests (tests::stall, through the line's hooks: the clock's bound 200 ms, and
no probe seen answered): a command buffer waiting on its VkQueue for a reserved
event signal is pending; with the probe answered nothing fails and it
completes once the host signals; with none answered it fails as GpuHang, the
old VkDevice is parked, the new one is not, and a command buffer runs after.
Verification follows on this commit.
2026-11-12 18:50:18 -08:00
Anees Iqbal a52c30aff2 A recovery carries no-copy heaps and the textures placed in heaps
What: a heap over the caller's memory (new_heap_with_bytes_no_copy) is
carried as a no-copy buffer is: its own buffer made again over the same
pages (Buffer::carry_no_copy, now for a heap's own buffer too, kept among
no program resources; its pages keep what they were made of, a heap's own
included), its identity kept, the buffers placed in it carried at their
offsets (Buffer::carry_placed), their bytes as they are. The textures
placed in a carried heap, Private or no-copy, are made again there after
the heaps (Remake::Heap, Device::heap_texture_again): as the runtime's own
texture over the same range of the heap's bytes, through the making that
placed them (a texture buffer's buffer carried with carry_placed), sharing
the range's makeAliasable flag (HeapPlace::aliasable is an Arc), the range
handed to the newest image (HeapPlace::again, hand_range_to), so it is
given back once. A Private heap's texture reads as a new one, a no-copy
heap's reads the pages. The heap keeps its textures numbered as they were
(no forget_held); one the recovery leaves is forgotten (Numbered::forget,
Heap::forget_texture). A texture over a carried heap buffer is made again
over it, as over any carried buffer. Heap::carry answers what its bytes'
carry did with their contents and None where it was carried already, so
the notice counts no-copy heaps apart (", and N no-copy heaps with the M
buffers placed in them, over the same pages") and textures placed in
no-copy heaps apart ("N textures placed in the no-copy heaps carried"),
a Private heap's textures by storage mode. Docs: heap.rs, texture/carry.rs,
device/carry.rs, MadeBeforeRecovery, the device-recovered cost (degradation.rs,
API.md), the runtime README, and FAST-PATHS's known gap on lost texture
contents, which now names a Private heap's textures.

Why: reims's forced recoveries (3090 m3-max-23482, XTX m3-max-23547) left
44 no-copy heaps and 929 heaps' textures refused: 3424 refused texture
binds in one compositor's command buffers, 82 placements in those heaps
refused, the desktop mostly black after. Metal keeps a heap and what is
placed in it. The owner's call: a Private heap's textures are carried with
their contents lost, as new_texture's are.

Verified: a check of the runtime's lib and tests under plain and
m2v_cpu_icd was clean (m3-max-23688, on a probe commit of this change);
the lane that follows runs the tests.
2026-11-12 18:31:39 -08:00
Anees Iqbal 257b77bc21 Fan a host step's rate-mapped draws out to the regions in one draw
A rate-mapped pass drew every draw once per region of the map's plan: an executed command's
triangles ran their vertex function 2074 times on a 3648 by 1734 screen's plan, and the command
buffer of a guest frame's shape took 514 ms of an Iris Xe's GPU and 462 ms of a Radeon 780M's.

At a host step, where the default `RateMapRegionPolicy::FanOut` holds and the device enables
`geometryShader`, `shaderClipDistance` and `vertexPipelineStoresAndAtomics`, the pass is now
probed first: each execution's commands, read once, are replayed in probe mode into a segment of
their own (one middle render pass per instance, the fan-out variant's geometry stage writing a
flag and a copy count per command and emitting nothing), submitted and waited for. A command
whose flag is clear (no triangle crosses w = 0 or touches more regions than the copies) is drawn
once through the fan-out variant over the whole target, its geometry stage emitting a copy per
region it touches; a flagged command, and every command after a barrier, after a draw that writes
memory or at a mesh or patch draw, is drawn region by region as before. A fan-out variant the
compile refuses falls back to region by region at the settle.

`RateMapRegionPolicy::Exact` (`DevicePolicy::exact_answers()`) keeps every draw region by
region. The FAST-PATHS row, the API.md bullet and a known gap (the encoder's own draws and the
draws commit records stay region by region) describe it; `WorkCounts` counts the probes, the
flagged and fanned-out draws and the probes' GPU time. `CommandBuffer::submit_waited` is the
loop check's waited submission, shared with the probe.

Verified (release, `--cfg m2v_gpu`, e55e6ebd01 before the rebase onto aacde9f2ad, which applied
cleanly): the runtime's `rate_mapped` tests pass on an Iris Xe and a Radeon 780M (Mesa 26.2.6) and
on lavapipe, the fan-out test counting one probe, one flagged draw and six fanned out with pixels
equal to the region-by-region draw's; the pieces lane's host-step frame takes 111 ms of the Iris
Xe's GPU fanned out against 514 ms under Exact, 125 ms against 462 ms on the 780M, the probe 1.1
ms and 0.5 ms. Clippy, rustdoc, the API reference check, the surface and signature tests and the
fast-paths tests pass; the golden table's changed cells are development's drift, re-blessed there.
2026-11-12 18:28:19 -08:00
Anees Iqbal e6124818d9 A recovery carries Private exportable buffers over their own memory
What: Buffer::carry takes a Private buffer in exportable memory (no host
copy) to the new generation over its block's payload imported again
(Device::buffer_in_carried_export, memory::place_carried_export): the lost
block is exported once from the lost VkDevice (memory::carried_payload,
vkGetMemoryFdKHR, which the spec lets a lost device answer) and that
descriptor is kept on the block (Block::payload); the new VkDevice imports
a clone of it (Handed) once for every buffer carried from the block, as
memory of the block's own type and allocation size with the device-address
flag of the device's blocks, dedicated to the buffer where the lost block
was a dma-buf's dedicated allocation, and binds each buffer at its offset.
The buffer is not cleared: another API's import (VA-API) reaches the same
memory and may be writing it, so it keeps whatever the memory holds, counted
among the buffers carried with their contents. Its exports after the
recovery answer a clone of the kept descriptor, and so does the dma-buf a
texture's image over it imports (ExportedTexels::payload), so textures over
it carry as over any carried buffer. Left refused: Shared and Managed
exportable buffers (their contents pointer is the lost mapping), and an
opaque descriptor's dedicated allocation, a new kind in the notice
(Left::DedicatedOpaqueFd: VUID-VkMemoryDedicatedAllocateInfo-buffer-01879
names a buffer identical to the payload's, which Vulkan does not define
across devices). Docs: exported_memory.rs, device/carry.rs, buffer.rs,
MadeBeforeRecovery, the device-recovered cost (degradation.rs, API.md) and
the runtime README, with the exception to the Private-reads-zero rule.

Why: reims's NV12/P010 device caches are Private exportable buffers
(STORAGE_PRIVATE in surface_cache.rs and vaapi.rs, read-only check) that
VA-API decodes into; a recovery left them refused, failing a video
session's frames, where Metal keeps the buffer.

Verified: the lane that follows runs the test before and after on lavapipe;
REFUSALS.md regenerated (no change).
2026-11-12 18:02:50 -08:00
Anees Iqbal 30ba489080 A recovery carries sampler states
What: a sampler state's device is a LineDevice the state's own carry links
(LineDevice::unkept, link_unkept). The recovery takes the generation's live
sampler states (Carry::sampler_state, Taken::samplers) and, first after the
handles, carries each (SamplerState::carry) where both generations compile
alike: its handle linked to the new generation's under its cache's lock, the
VkSamplers it kept forgotten, the state kept in the new generation's map of
live states (an equal request gets it) and placed in its heap sets and
sampler tables, then kept there for a later recovery. Its placement on the
lost generation is taken out at that generation's rest (LostPlacement).
SamplerState::vk_sampler takes the generation the bind writes for and makes
the sampler there, cached for the state's latest generation alone; for any
other generation it answers None, and the heap set, slot and argument-buffer
writes take the neutral sampler. The recovery's notice counts the states
carried (and any left, where the generations compile otherwise).
Docs: MadeBeforeRecovery, the device-recovered cost (degradation.rs and
API.md), the runtime README, device/carry.rs and sampler.rs. As main asked,
Device::recover_for_test's doc and line.rs's module doc now point at
device/carry.rs for the kinds carried instead of a stale list.

Why: a sampler state kept its lost generation, so every bind of it after a
recovery was refused (MadeBeforeRecovery) where Metal's goes on; and the
argument buffers' listing of live states is line-wide, so a draw or
dispatch of the new VkDevice made the listed state's VkSampler on the lost
VkDevice and wrote it into a descriptor set of the new one, a handle of
another device, which Vulkan does not allow.

Verified: the lane that follows runs the test before and after on
lavapipe; REFUSALS.md regenerated (no change).
2026-11-12 17:38:31 -08:00
Anees Iqbal 56a8aa5283 did_modify_range: a commit takes the ranges of the buffers its command buffer uses, copied in on its queue
What: Modified::take_at_commit takes, at a commit, only the noted ranges of the buffers the
command buffer may use (CommandBuffer::may_use: its encoders' uses name the buffer or made it
resident, a command may reach memory no use names, its last encoder's end is still with the
lowering thread, or nothing owns the buffer's key); the rest stay noted, in their order, for a
commit that uses them (managed.rs's Noted). Their copies in, and every other upload into a
buffer the program may have read (Buffer::upload, copy_in_from), register as uploads
(FirstMoves::register_upload, FirstFill::reached_only): a batch takes one only where its
commands may reach the buffer, on a device with a fill queue or without one, never because it
takes every other fill; an internal submission takes it too, and a batch that needs no GPU work
leaves it waiting. FillTake::Owned carries the batch's reach for that. So the copy lands on the
user's queue, after the command buffers before it there, before the commands of the first that
uses it: Metal's shape. Docs: managed.rs, managed_copy.rs (the 'as on Metal' line now says what
holds: only two queues' unordered uses of the buffer race the copy), first_move.rs, API.md, the
runtime README and FAST-PATHS.md's managed row.

Why: any queue's commit took every noted range, and any queue's next submission took its copy in
(before f62966f4f0 the call registered it, with the same take), so a range a thread named after
committing a command buffer that reads the buffer could land, on another queue's submission,
before that command buffer ran: on an RTX 3090 round 0 of a buffer read round 2's bytes, a silent
wrong result on every discrete GPU.

Tests: managed.rs's take rule (a_commit_takes_the_noted_ranges_of_the_buffers_its_command_buffer_uses)
and first_move.rs's (an_upload_goes_only_with_a_batch_that_reaches_its_buffer), on every device;
the parent's named rounds on two queues and on one, on the RTX 3090 before and after (job ids in
the report). RUNTIME_VERSION wants a bump at landing.
2026-11-12 17:18:01 -08:00
Anees Iqbal 6b79a77730 A recovery carries drawing and mesh pipeline states
What: a drawing state (a mesh one, and a twin of a color group, a single-sample or a factor-scaling
state among them) keeps a chain of programs per generation as a compute state does
(pipeline/carry.rs): its StateShared Deref reaches the program of the generation whose command
buffer's work the thread does, else the last; its ID, uniqueIdentifier, label and sampler numbers
stay. Each state is kept by its generation's carry registry (GraphicsState::kept at the end of a
render or mesh creation, with its color groups' twins); the recovery carries them after the compute
states (pipeline/render/carry.rs): its base variant, and its large-buffer form's, made again from
the pipelines its creation compiled or the live variants of them the new generation holds, no
translation; then, under the new generation's reach (NoticesFor::of_generation), its neutrals, its
predicted first draw's VkPipeline handed to the pool with nothing waiting for it
(make_at_creation(false)), and its depth stand-in copies. Its descriptors, keys, label and twins are
kept; its other variants, plans, settles and routings are made as its draws need them. A failed
making is counted and refused where bound (RemadeAfterRecoveryFailed) through
RenderPipelineState::bound_device, at set_render_pipeline_state (encoder, call checks, indirect
command buffer) and an argument encoder's render word; a tile state's bind now answers its kernel's
failed making the same way. A state is made again only where both generations compile alike
(compiles_alike, the profile fingerprint the memo carry checked already); else its making is refused
as failed. Docs: device/carry.rs, pipeline/carry.rs, MadeBeforeRecovery (render states no longer
listed refused) and RemadeAfterRecoveryFailed, the DeviceRecovered cost (degradation.rs and API.md,
equal), API.md's recovery entry, the runtime README; REFUSALS.md regenerated.

Why: drawing states made before a recovery were refused where bound after it; Metal's go on.

Verified: see the lane run reported with this sha (the test commit before it fails, this one
passes), with the recovery's wall time for 0, 200 compute and 200 drawing states.
2026-11-12 17:13:53 -08:00
Anees Iqbal 98db2b33e6 A recovery carries compute and tile pipeline states
What: a compute state (and so a tile state's kernel) keeps a chain of programs, one per
generation (pipeline/carry.rs): the state object, its ID, uniqueIdentifier, label and sampler
numbers stay, and its Deref reaches the program of the generation whose command buffer's work the
thread does, else the last. Each state is kept by its generation's carry registry; the recovery,
after the textures, makes its program again on the new generation: the base variant's objects
from the pipeline its creation compiled (Variant::of with the compiled pipeline, or the live
variant the new memo already holds), no translation, and the VkPipeline its creation predicted
queued on the making pool with no wait (make_predicted with waited false). The lost generation's
memo of compiled functions and pipelines is carried first where both generations' profile
fingerprints match (PipelineMemo::carry_from), so later variants and creations translate nothing
again. A state whose making there fails stays the lost generation's, is counted by the notice and
refused where bound with the new RuntimeGap::RemadeAfterRecoveryFailed (compute encoder,
argument encoder and indirect command buffer checks, through ComputePipelineState::bound_device).
The notice says how many states were made again and how many failed. An indirect command
buffer's depth/stencil check now matches the state by its line too, as the encoders' do since the
regression fix. Docs: carry.rs, MadeBeforeRecovery, the new gap, the DeviceRecovered cost
(degradation.rs and docs/API.md, equal), the runtime README; REFUSALS.md, reach.tsv and the API
signature table regenerated.

Why: compute and tile states made before a recovery were refused where bound after it; Metal's
go on.

Verified: see the lane run reported with this sha (the test commit before it fails, this one
passes), with the recovery's wall time for 0 and 200 live states.
2026-11-12 16:45:38 -08:00
Anees Iqbal 85847d3941 A binary archive and a dynamic library go on past their device's recovery
What: a binary archive and a dynamic library hold their device as a LineDevice
(device/carry.rs), as a fence or a library does: device() answers the generation handle of the
generation they were made on, else of the one a recovery carried them to last, and the lost
generation's handle goes at its rest. A creation's archive check matches an archive by its
device's line (its root handle), so a creation of any generation lists an archive made before a
recovery; each add makes its state on the generation that serves (Device::at_serving through the
root handle), its used artifacts taken afresh for each run. Docs: both modules, carry.rs,
MadeBeforeRecovery, the DeviceRecovered cost (degradation.rs and docs/API.md, equal), the runtime
README. REFUSALS.md regenerated: unchanged.

Why: an archive made before a recovery refused its adds there (its creation ran on the lost
generation) and every creation that listed it (MadeBeforeRecovery), and both kinds held the lost
VkDevice while they lived; Metal's go on.

Verified: see the lane run reported with this sha (the test commit before it fails, this one
passes).
2026-11-12 16:35:28 -08:00
Anees Iqbal fb41ed11d9 Name the simdgroup kernels' one-row flat dispatch in the split-dispatch notice's entry 2026-11-12 16:29:20 -08:00
Anees Iqbal 9b308145e9 A texture buffer goes on over its carried texels; the notice counts lost textures by storage mode
What: Texture::carry makes a texture buffer of new_texture again over its texels' buffer where the
recovery carried that buffer (texture_buffer_over, the runtime's own ID use), so a Shared one
reads the bytes the buffer carry kept; where the buffer was left it is made new as before.
Remade splits the textures whose contents were lost by storage mode (Shared, Managed, Private or
memoryless), and the recovery's notice says those three counts. carry.rs says how kept bytes are
read: Vulkan makes the content of external memory imported to a lost device undefined (vkspec
5.2.3), read as the hung work's writes possibly landing in part; once the lost import goes, the
pages are only our or the caller's memory. Docs: texture/carry.rs, carry.rs, the
DeviceRecovered cost (degradation.rs, docs/API.md, equal), the runtime README, and a known gap in
docs/FAST-PATHS.md: a recovery loses the contents of textures whose only copy is device memory
(new_texture of any storage mode), textures over carried pages keeping what their buffer keeps.

Why: the consumer asked for Shared textures' contents kept across a reset. A texture of
new_texture of any storage mode has no copy outside its image in the lost VkDevice's memory, so
keeping it would need a CPU copy at a cost to every frame; decided against for now, and recorded
as the known gap. Textures over carried pages already keep their bytes; texture buffers did not.

Verified: see the lane run reported with this sha (the test commit before it fails, this one
passes).
2026-11-12 16:27:36 -08:00
Anees Iqbal b564fb7a91 A recovery carries textures, their views and those over carried buffers
What: a device's recovery now carries the program's textures made by a call it can make
again (texture/carry.rs). That covers a texture of `Device::new_texture`, a texture over a
buffer the recovery carried (`Buffer::new_texture` and its kin), and a view of either.

- The call is made again on the new generation as the runtime's own texture, which takes no
  ID. That texture holds the program texture's parts there: `TextureShared::next`, with a
  `carried` flag.
- `Texture::s` picks the parts the work at hand reaches. Inside a command buffer's work it
  answers that generation's parts (`NoticesFor::generation`); elsewhere, those of the
  generation the texture was carried to last. The buffer carry picks its parts the same way.
- Every read of a per-generation field goes through it: `storage()` (the hub), facts, faces,
  usage shadows, storage forms, render shadows, snapshots, memoryless backings and planes in
  place.
- The texture object keeps its `ObjectId`, resource ID, label, parent and handles, and its
  purgeable state is copied across. Its ID's slot in the new generation's texture table and
  heap sets names its parts there (`heap_sets::place`), and leaving the slot walks every
  generation's parts.
- Each program texture is kept by its generation's carry registry as it is made
  (`Carry::texture`). The call that made it sets how to make it again (`Remake`) and carries
  it itself where the take came first (`Device::kept_texture`, `Carry::late_texture`).
- The carry runs inside a `NoticesFor::of_generation` scope for the new generation, so the
  buffer it remakes a texture over and a view's parent answer their parts there.
- Left refused, and counted by kind in the notice: a heap's texture or one over a heap's
  buffer, a texture over the caller's `VkImage`, a sparse or shareable texture, a texture over
  a buffer left, and their views.
- The notice adds ", and N textures whose contents were lost too (they read as new ones), M
  textures over the buffers carried and V texture views".

Known gap, documented in API.md, the README and device/carry.rs: a carried texture's images
on the lost generation, and so the lost `VkDevice`, stay until the texture goes. Letting them
go at the lost generation's rest needs a hold of the parts by each call outside command
buffers' work, as `Buffer::held_parts` does for buffers.

Why: render targets and display textures made before a recovery were refused
(`MadeBeforeRecovery`) where they met the new `VkDevice`, while Metal's go on.

Tests: device_recovery_carry's main test now leaves a `Shared` heap instead of a texture as the
object that keeps the lost `VkDevice`. Its held-parts test now expects the texture made by a
call that completed on the lost generation to be carried by its maker. Docs updated:
`MadeBeforeRecovery`, the device-recovered cost (degradation.rs and docs/API.md, kept equal),
the runtime README and the heap docs. docs/REFUSALS.md regenerated (`view` became `view_as`).

Verified: the lane run of the test commit before and this one after is reported with its sha.
2026-11-12 16:27:35 -08:00
Anees Iqbal b1d963289e The resident-set search is its loop alone, without 16 unrolled steps
Each resolve of a loaded pointer emitted 16 unrolled binary-search steps before the loop that
finished sets of more than 2^16 entries. RADV inlines every call of the search, so a module with
many loaded pointers paid the 16 steps at every site: on a curve-shading kernel with 1,065
searches, its creation on the 780M took 92.9 s and 8.4 GiB of compile memory.

The search now starts the loop from all N entries. A step halves the candidates whatever its
compare gives, so the trip count, ceil(log2 N), depends on N alone: every invocation that
searches one table takes the same branches, and a set below 2^16 entries does fewer entry loads
than the 16 steps did (they kept loading after one candidate was left). search_step is the loop's
step; search_rest is now bisect, from (0, N). SEARCH_STEPS is gone, SEARCH_WORDS charges one step
plus the loop, and the docs (roots.rs, API.md) and the tests that named the unrolled reach say
what is true now. The handle-table search keeps its own unrolled steps. Answers are unchanged.

Measured on the 780M (RADV PHOENIX), before (1125fb62d2) and after, one job (m3-max-23016), one
run each:

The curve-shading kernel's creation (pipeline cache off, RADV_DEBUG=shaderstats):
  time in the driver   92.9 s -> 62.6 s
  peak RSS             8,462 -> 5,846 MiB
  ACO instructions     1,741,690 -> 1,000,747
  spilled VGPRs        179,037 -> 105,970
  spilled SGPRs        95,824 -> 46,562

GPU time of a dispatch whose 262,144 threads each resolve 64 loaded pointers, over M buffers made
resident, every lane's address the same (uniform) or its own (divergent); median of 15 commits,
every thread's sum checked (0 wrong in every row):
  M        form       before      after
  16       uniform    5.56 ms     4.02 ms   -28%
  16       divergent  4.61 ms     4.03 ms   -13%
  1,024    uniform    5.58 ms     6.52 ms   +17%
  1,024    divergent  8.37 ms     7.84 ms    -6%
  66,048   uniform    7.86 ms     9.04 ms   +15%
  66,048   divergent  92.4 ms     95.8 ms    +4% (ranges overlap)
Uniform addresses over sets of 1,024 entries or more cost 15-17% more GPU time: the loop's exit
test and back branch at each step cost more there than the unrolled chain's extra steps.
2026-11-12 16:12:29 -08:00
Anees Iqbal a610b58b8a A replayed draw whose making outlasts the commit's bound leaves its pass to the host step
The last draw dropped for its making's time: a draw of an execution's replay at commit (render
commands the CPU writes) whose pipeline the replay began itself and that was still being made at
the command buffer's bound recorded nothing. Metal cannot encode a draw before its pipeline
exists, so every encoded draw runs.

Now the replay at commit stops there, keeps the making on the command buffer
(CommandBuffer::leave_unmade), and the pass takes it into the makings its host step waits for
(DeferredPass::left_for_makings): the commit leaves the pass to the host step with its
pipelines pending, as it already did for a pass whose settled makings were still being made, and
the step records it from the records as they stand then once the making lands. A replay inside
a host step waits for its making until made, on the step's thread. record_on_gpu declines to
the host step the same way. The commit still returns at its bound at most.

Removed: DrawDroppedStillMaking, WorkCounts::draws_dropped_still_making,
CommandBuffer::drop_late_draw, RenderLowering::drop_late_replayed_draw, the execution's encoder
place that only named the dropped draw, and the open-gap text in FAST-PATHS row 43, API.md (the
bullet and the catalogue entry), the runtime README and the PipelineWaitPolicy docs
(api_signatures.tsv -2). The IndirectCommandCheck and executed-commands docs name the new case
in which an execution read at commit is read and checked again in its host step.

The gap's test flips: a_replayed_draw_whose_pipeline_is_still_being_made_at_its_bound_renders_once_made
(commit returns after the bound and before the 10 s watchdog; the command buffer is not complete
a second past its bound while another queue completes; once the hold goes it completes with the
rectangle drawn and nothing dropped). Checked by the lint and lavapipe jobs reported with it.
2026-11-12 16:01:25 -08:00
Anees Iqbal b4eaf4caa7 Keep the replayed draw's test as the open gap's, and name the gap by the replay's own wait
The lavapipe run (m3-max-23046) showed a draw of a commit-time replay of
CPU-written records dropped at the bound: the replay waits for that
making itself, which the settle did not leave to the host step. That is
the open gap this change keeps; its test asserts the drop, and the docs
name the gap by the replay's own wait.
2026-11-12 15:41:59 -08:00
Anees Iqbal 91dbc91bbc Hold a command buffer for its draws' and dispatches' makings instead of dropping them
A dispatch whose pipeline was still being made 4.5 s after its command
buffer's commit recorded nothing, and so did such a draw. Metal makes a
state's pipelines inside its creation, so every draw and dispatch it
encodes runs: a dropped dispatch leaves wrong results (a guest's path
tracer dropped 45 dispatches behind a 116 s compile on the RX 7900 XTX),
and a dropped draw leaves content drawn once (a cached shadow map, a
glyph atlas) without it. The owner's rule: no switch may break Metal's
contract, so the dropping form is removed, not kept behind a switch.

A batch's host step now waits for every making its segments record,
past the bound too (Segment::steps_after_pipelines; the scheduler's
StepWaits loses its `until`, and Segment::holds goes): the batch stays
in its queue's line on the scheduler's thread, which no call waits for,
and records the draws and dispatches once made. Held batches still give
way to other queues' later commits that share no fence. `commit` waits
for no making but a pass that executes render commands the CPU writes,
until its bound, and leaves that pass to the host step past it. The
pending dispatch, tile dispatch and pending draw recordings wait until
made. DispatchDroppedStillMaking, its counter and catalogue entry, and
CommandBuffer::drop_late_dispatch are removed.

One drop remains, an open gap named in FAST-PATHS and the notice: a draw
of an execution's replay whose pipeline the replay itself began making,
of a key the commit's settle did not foresee, still being made at the
bound (DrawDroppedStillMaking, now that case alone). That case is the
next change.

Tests (device, rewritten): a draw, a replayed draw and a dispatch whose
makings are held past the bound each complete once the making lands,
drawn or written, nothing dropped, while another queue's command buffer
completes meanwhile and the held one is still not complete a second past
its bound.
2026-11-12 15:41:59 -08:00
Anees Iqbal 3c88a7df60 An address pool goes on past its device's recovery
What: `AddressPool` holds a root handle of its device (`Device::root`) and the device's
address space, instead of a handle of the generation it was reserved on. A buffer placed in
one of its slots after a recovery passes the same-device check (`Device::same` answers a root
and any generation of its line alike), and the pool's drop gives its span back to the address
space, which every generation shares, without reaching a generation.

Why: a consumer found that after a recovery every new buffer in a slot of a pool reserved
before it was refused (`MadeBeforeRecovery`), which refused all of its buffers under 16 KiB.
A pool holds no Vulkan object and no memory: it is a span of the line's address space
(`AddressSpace::reserve_pool`), and a buffer in a slot takes its own memory as any buffer
does, only its Metal address from the slot. Holding a generation handle also kept the lost
`VkDevice` alive while the pool lived.

Docs: the recovery lists in `MadeBeforeRecovery`, the device-recovered cost (degradation.rs
and docs/API.md), the runtime README and device/carry.rs name address pools; the pool's own
docs say it goes on. docs/REFUSALS.md regenerated with no change.

Verified: the lane run of the test commit before and this one after is reported with its sha.
2026-11-12 15:33:06 -08:00
Anees Iqbal 62923811dc A library and its functions go on past their device's recovery
What: a library holds a root handle of its device (Device::root) rather than the generation
it was made on, and its functions take that handle, as a fence does. A library is the
compile layer's parsed library and a function the compile layer's function with its
constants, no Vulkan object; their sampler-ID holds are the line's resource IDs, which every
generation shares. So a pipeline made from them on any generation passes its device check
(same matches a root handle by its line), and they no longer keep the lost VkDevice alive.
Docs: library.rs, carry.rs, MadeBeforeRecovery (libraries leave the refused list), the
device-recovered cost (degradation.rs and docs/API.md), the runtime README. REFUSALS.md
regenerated: unchanged.

Why: after a recovery a pipeline made from a library or function made before it was refused
NotImplemented(MadeBeforeRecovery); Metal's library goes on.

Verified: see the lane run reported with this sha (the test commit before it fails, this
one passes).
2026-11-12 15:11:30 -08:00
Anees Iqbal fb7eaa8cbc A depth/stencil state goes on past its device's recovery
What: a depth/stencil state holds a root handle of its device (Device::root) rather than
the generation it was made on, as a fence does. The state is its descriptor and the compile
layer's Vulkan depth/stencil state, no Vulkan object, so a render encoder of any generation
accepts it (check_device matches a root handle by its line), and it no longer keeps the lost
VkDevice alive. gpu_resource_id asks supports_family, which goes to the serving generation,
instead of the "now" form a root handle has no generation for. Docs: depth_stencil.rs,
carry.rs, MadeBeforeRecovery, the device-recovered cost (degradation.rs and docs/API.md),
the runtime README. REFUSALS.md regenerated: unchanged.

Why: after a recovery a state made before it was refused NotImplemented(MadeBeforeRecovery)
at set_depth_stencil_state; Metal's state goes on.

Verified: see the lane run reported with this sha (the test commit before it fails, this
one passes).
2026-11-12 15:11:29 -08:00
Anees Iqbal e05beb832d A fence goes on past its device's recovery
What: a fence holds a root handle of its device (Device::root) rather than the generation
it was made on. A fence has no Vulkan object, only the key the tracker orders on, so
update_fence and wait_for_fence of any generation's encoder now accept a fence made before
a recovery (check_device matches a root handle by its line); an update made on a lost
generation went with that generation's work, so a wait on the next one finds none, as for a
fence never updated there. The fence no longer keeps the lost VkDevice alive. Docs: fence.rs
module and item docs, carry.rs, MadeBeforeRecovery, the device-recovered cost (degradation.rs
and docs/API.md), the runtime README. REFUSALS.md regenerated: unchanged.

Why: after a 780M gfx ring timeout and a recovery, a guest's waitForFence: calls were
refused NotImplemented(MadeBeforeRecovery) about 2,000 times; Metal's fence goes on.

Verified: see the lane run reported with this sha (the test commit before it fails, this
one passes).
2026-11-12 15:02:41 -08:00
Anees Iqbal b10839e2b2 A recovery carries Private heaps with the buffers placed in them
What: a device's recovery now carries each live heap to the new VkDevice (Heap::carry,
called from Device::carry_to after the buffers, or by a heap's maker where the recovery
took the generation first). A Private heap's own buffer is made again in new memory placed
where the heap's textures can lie (place_heap_buffer), zeroed as a carried Private buffer
is, keeping its ObjectId, hazard key, Metal address and range, range token, label and
purgeable state; the heap is registered by its key there and kept in the new generation's
registry for a later recovery. Each live buffer placed in it gets a new link on the new
generation (Buffer::carry_placed) at the same offset of the carried bytes, with the same
ObjectId, address, label and a shared aliasable flag; its old link lets go of its live-list
entry and device handle at the lost generation's rest (LostPlaced). A placed buffer's drop
gives an automatic heap's range back only from the link carried to last, so a carried
buffer frees its range once. A buffer placed while the heap is being carried carries itself
under the heap's placed lock. The heap's textures made before stay the lost generation's
(no recovery carries a texture); the heap forgets them (keeping their numbering), so a
use_heap on the new generation never makes an old image resident. Shared heaps (their bytes
are pooled host-visible memory, never the runtime's own pages), no-copy heaps and sparse
heaps stay left, with their buffers.

The recovery notice now counts carried heaps ("N `Private` heaps (B bytes) with the M
buffers placed in them") and left heaps by kind, and splits the old "buffers over the
caller's or exportable memory" into "buffers over the caller's `VkBuffer`" and "buffers in
exportable memory" (Left::Caller / Left::Exported). Docs: carry.rs module docs, the
Buffer::carry docs, heap.rs, MadeBeforeRecovery, the device-recovered cost (degradation.rs
and docs/API.md), the runtime README. REFUSALS.md regenerated: unchanged.

Why: after a GPU recovery a guest's MTLHeap newBufferWithLength:options:offset: was refused
NotImplemented(MadeBeforeRecovery) and the guest got nil; Metal's heap goes on.

Verified: see the lane run reported with this sha (the test commit before it fails, this
one passes).
2026-11-12 14:59:22 -08:00
Anees Iqbal da3cea7633 A heap texture's chosen constexpr samplers are one sampler array, not a switch
A heap texture sampled through one of several constexpr samplers that a
sampler handle names at run time (a table of constexpr samplers read at a
computed index) was a switch-at-use with one arm per candidate: each arm
its own heap sampling and raw-texel emulation. On large kernels that
multiplies the sampling code by the candidate count.

Where every candidate is a constexpr sampler, their handles are
consecutive, each candidate's sampling is the same but for its sampler
and the state its raw emulation follows, the use is not tangled, and the
device indexes a sampler array non-uniformly
(shaderSampledImageArrayNonUniformIndexing, which heap textures already
need), the sampling is now one sampling through a set-0 array of the
candidates' samplers (ResourceKind::SamplerArray,
BindingSource::SamplerArray): element handle - first, NonUniform, its
immutable samplers each made as the heap sampler of that candidate alone
would be (DescriptorBinding::immutable_samplers, listed per stage in
StageInterface::sampler_arrays). A handle outside the array reads zero,
as the switch's null arm. The raw emulation reads the element's sampler
word from a constant table at the same index (heap_raw::State::Table),
through the runtime-word path. Elsewhere the switch stays.

The runtime bakes one sampler per element into the set layout, pushes
each element's own sampler where set 0 is pushed, and keys the set-0
shape on them.

Tests: the array form on every profile with the sampled heap (one
sampled image, L3), the switch kept for non-consecutive handles, each
element equal to the immutable sampler of the candidate sampled alone and
never written by the plan, and a device test (lavapipe under
m2v_cpu_icd) that each lane reads what its sampler alone reads and what
the address modes define.

Docs: API.md section 5, the sampler module doc, api_signatures,
api_surface, REFUSALS regenerated.
2026-11-12 14:55:47 -08:00
Anees Iqbal bcfec16960 A rate-mapped draw skips the regions its viewport and render area leave no pixel
Each draw of a rate-mapped pass was recorded once per region of the map's plan, even where the
region's scissor, cut to the pixels whose centres lie in the guest's viewport and to the render
area, held no pixel. Such a recording shades nothing (the scissor test discards every fragment),
and its vertex function repeats nothing observable (a plan of several regions refuses a vertex
function that writes memory), so it is now left out. Where the cut leaves no region a pixel, the
first region alone is still recorded through its empty scissor, so the vertex function runs as
Metal's does. A draw whose viewport covers part of the screen now records only the regions it
reaches; one over the whole screen records what it did.

The new lane test draws the case's fullscreen triangle over a 256-pixel map at the falling
quality with a viewport over the screen's left quarter: fewer regions than the whole screen's,
from an indirect buffer region by region, and the direct (batched) draw shades bit for bit the
same pixels, inside the left half of the physical columns.
2026-11-12 14:37:06 -08:00
Anees Iqbal 1b1ebfd055 GPU times from the host start at the first submission that carried the work
A command buffer whose work went as several submissions (a wait for an
event the host signals, an execution its host step records) answered,
on a device made with gpu_times_from_host or a driver whose timestamps
wait for every queue's, the call of its LAST submission (its
kernelEndTime) as its GPUStartTime: its window missed the work of its
earlier submissions. Metal's GPUStartTime and GPUEndTime span the whole
command buffer's GPU work. A consumer that answers GPU times from the
host read windows of 0 to 240 ms on an Iris Xe for command buffers whose
kernel start to end spanned 2 to 8 s, each GPU start at the kernel end.

KernelTimes keeps the call of the first driver's submission that carried
a batch of the command buffer (the batch's own vkQueueSubmit, or its
group's), and the host-clock start is that call where it came before
the kernel end, else the kernel end as before, or the queue's latest GPU
end where later. A command buffer whose work went as one submission
answers as before. Devices that write timestamps already started at the
first batch's timestamp (lavapipe, job 22670: GPU start 173 ms before
the signal its second batch waited for).

Docs: gpu_time.rs (the host-clock bullet, rule 2), gpu_start_time,
DeviceOptions::gpu_times_from_host, the GpuTimesFromHost notice's cost
and its API.md entry.

Verified: pending lavapipe before and after, the 780M, lint.
2026-11-12 14:35:01 -08:00
Anees Iqbal 6014ad370d Faces: a logged pass turns, and an encoding again meets the faces as first met
While the device has a buffer over host pages, every render pass logs its calls for a rebind,
and a pass with a log, or with an earlier encoder of its command buffer keeping one, turned no
texture (Unturned::Pass): under a consumer that keeps host-page buffers alive, no attached read
ever took the turn and every one copied in.

A logged pass now turns as any other. A rebind's encoding again of the command buffer's encoders
meets the faces as their first encodings met them: the encoding again runs with a thread-local
context of the command buffer and the encoder's parts (with_faces_as_of); a texture a later pass
of the command buffer turned presents the face from before that turn to it (Faces::face), and
the turning pass encoded again takes its turn again (Texture::retake_turn: the shadow of the face
from before the turn held current, no copy in). Any other pass encoded again turns nothing.
TurnPoint drops logs_kept; SwapRecord keeps the face it turned from.

The shadow log (METAL2VULKAN_LOG_SHADOWS) also names, once per shadowed texture, at the first
draw that binds it after its shadow was made: the slot, whether the function fetches, samples or
writes it, and each sampler's min, mag and mip filters (a sampler state's by Metal's names, a
constexpr sampler's as the layout bakes it).

Tests: the runtime's attached_read_faces gains a lane with a host-page buffer alive (a logged
pass turns; a blit and a turning pass behind a shared-event wait, encoded again by a rebind, read
the texels from before the turn), against the same lane beside an open command buffer (the copy
route); the validation crate's runtime_lane::logged_face_turns runs the same under the layer.
Not yet run: dispatched next.
2026-11-12 14:03:30 -08:00
Anees Iqbal f62966f4f0 did_modify_range's bytes are taken at the next commit, as Metal takes them
What: did_modify_range (and a CPU write through a texture over a buffer) notes the range on the
device (managed.rs Modified); every commit, at its start and before it returns, copies each
noted range of a buffer with a host copy on the CPU into staging buffers as the host copy holds
it then (Buffer::upload_now, CallerCopy::copy_in_now, managed_copy::stage_in), which the next
submission copies into the device copy before any of its commands. A range the staging buffers
find no memory for falls back to the copy from the host copy as the submission runs.

Why: the copy in read the host copy (the caller's pages through their import, or the runtime's
own host copy) when the GPU ran it, so a CPU write made after the commit, before the GPU reached
the command buffer, was what the command buffer read. Metal on a Radeon Pro 5300M (macOS
26.7.1, reims's oracle) takes the bytes at the commit after didModifyRange: a write before the
commit (after the call, or with the command buffer encoded before it) is read, one made 30 ms
after the commit while the GPU spun is not. Capturing at the call would be wrong (steps 2 and
3 read the later write there). An RX 7900 XTX computed frame 0 of a benchmark on frame 1's
input this way.

Docs: managed.rs and managed_copy.rs state the rule and its cost (a CPU copy of the range's
bytes at the commit); API.md, the runtime README and FAST-PATHS.md's managed row follow.
managed_bytes_copied_in counts a caller copy's copies alone, as before.

Verified: the lane test of the parent commit on an RTX 3090 (job ids in the report).
2026-11-12 13:47:32 -08:00
Anees Iqbal a7ba65dd66 synchronize_texture copies a Managed texture's bytes over a two-copy buffer out
What: on a device without unified memory, BlitCommandEncoder::synchronize_texture
now copies a Managed texture's bytes over a buffer from the buffer's device copy to
its host copy (the caller's pages, or the runtime's own host copy), as
synchronize_resource of the texture already did. A level that lies in the image
alone (a tiled texture's past its first) copies nothing; a texture of an image
alone still records nothing, its CPU access reading its image. The copy is shared
code: synchronize_resource's buffer and texture arms now call synchronize_bytes and
synchronize_texels.

Why: synchronize_texture recorded nothing on every device, its doc saying Managed
memory behaves as shared memory. Without unified memory a Managed buffer is two
copies (managed.rs, managed_copy.rs), and a texture over one serves get_bytes, and
the buffer its contents, from the host copy (buffer_texture.rs Texels::read). So a
program that synchronized with synchronizeTexture:slice:level: read the CPU copy as
of its last didModifyRange: stale texels. Found reading the read-back paths for a
benchmark that fails validation on an RX 7900 XTX.

Docs: the stale doc is replaced; API.md and FAST-PATHS.md name synchronize_texture
beside synchronize_resource for the copy out; the managed counters' docs count it.

Verified: the lane test runtime_lane::device_copies::
a_synchronize_texture_copies_the_texels_out (a blit into rows of a Managed texture
over pages and over a runtime-made Managed buffer, then synchronize_texture: the
contents and get_bytes hold the rows; the copy out counted for the pages with two
copies) is run on a discrete NVIDIA GPU with this change and once without the
runtime fix (negative control); job ids in the report.
2026-11-12 13:27:01 -08:00
Anees Iqbal df9ae6b02d Snapshot reads with no barrier: API.md's accepted difference covers writers
docs/API.md's accepted difference for a draw that reads its own pass's color at its own pixels
with no barrier now covers a draw that writes the color too: it reads what the draws before it
wrote where the runtime takes no copy for it (in place, or through a snapshot where the device
takes that route and the snapshot costs no more than the copy: a surface's reader always, a
private texture's by the area rule), else the copy, the M3 Max's texels. Its lead-in is the slug
the pass-start-barrier read rows name. FAST-PATHS.md's row and texture/attached_reads.rs say the
same, each naming both answers.

Verified: docs only; the conformance unit test that the slug exists runs in the 780M job.
2026-11-12 12:52:10 -08:00
Anees Iqbal 090930eebf Queue times: a default-off diagnostic notes when a command buffer became its queue's head and when its submission returned
What: with METAL2VULKAN_QUEUE_TIMES set, each command buffer notes two host times beside its kernel
times (gpu_time::KernelTimes), read through two hidden runtime-extension methods:
- CommandBuffer::queue_head_time: its first batch became the first of its queue's batches the
  scheduler had not taken. Noted as the scheduler takes it in onto an empty line, or as the batch
  before it on its line is taken for submission (Order::next, in the scheduler's passes and a
  committing thread's).
- CommandBuffer::submit_returned_time: the vkQueueSubmit that carried its last batch returned
  (submit.rs for a batch submitted now, group.rs for a group's members). kernelEndTime is that
  call's start, so the two bracket the driver's time in the call.
Unset, nothing is noted and no line is looked up: a relaxed load of the device's flag (read once
from the environment into gpu_time::Timing) per take and per submission.

Why: walkprof5 (m3-max-22376) put commit -> submission start at 37.0 ms p50, while kernel start to
kernel end was 0.008 ms, which does not bracket the vkQueueSubmit cost (the call starts at the
kernel end). The consumer's trace needs to split commit -> submission into time behind the
queue's earlier work and time held at its head, and to see each call's own length.

Docs: env_vars.rs's registry entry and accessor, docs/API.md's diagnostics paragraph, the
validation artifact note's list of variables the runtime reads; api_signatures.tsv blessed (two
hidden methods).

Tests: tests::kernel_end_device::queue_times_are_noted_in_the_order_of_a_queue_s_submissions_and_only_where_asked
(three command buffers on one queue, committed back to back): unasked, both read 0; asked
(Timing::note_queue_times, test-only), head <= kernel start <= kernel end <= returned for each,
heads in commit order, and each submission returned before the next one's kernel start.
2026-11-12 12:45:56 -08:00
Anees Iqbal 8274894e15 API.md: a rate-mapped pass draws several regions in one multi-draw where the device allows it
The accepted difference "A rate-mapped pass draws region by region" now says where the device
enables multiDraw, multiViewport, shaderOutputViewportIndex and shaderDrawParameters, a direct
draw of a vertex pipeline records up to the least of maxViewports and one below
maxMultiDrawCount regions in one vkCmdDrawMulti[Indexed]EXT, its vertex variant storing
ViewportIndex as DrawIndex, with the same pixels.

Docs only; the behaviour landed in the previous commits.
2026-11-12 12:37:46 -08:00