Commit Graph
286 Commits
Author SHA1 Message Date
Anees Iqbal 45ebbdaa5e RUNTIME 2484: Copies between a texture's region and a surface's runs of guest RAM
A consumer that keeps an IOSurface's GPU copy as one optimal texture, on a host whose surface
path copies by runs of guest RAM (copies_guest_ram: no view of the pages is made), needs the
texture forms of the run copies, or its fill, upload and download go back through a view per
block or a staging buffer.

What: BlitCommandEncoder::copy_texture_from_host_ram(ram, runs, offset, bytes_per_row, size,
texture, slice, level, origin) and copy_texture_to_host_ram(texture, slice, level, origin, size,
ram, runs, offset, bytes_per_row), runtime extensions (Metal has none). `runs` is the surface's
bytes in order (the shape the consumer's run copies pass today); offset and bytes_per_row are
Metal's copyFromBuffer layout over those bytes. Each row's texels within a run and a chunk are
one vkCmdCopyBufferToImage / vkCmdCopyImageToBuffer region straight on the chunk's import
(bufferRowLength and bufferImageHeight 0; bufferOffset a multiple of the texel,
VUID-vkCmdCopyImageToBuffer-srcImage-07975; the subresource bounds 07971/07972), with no staging
buffer. A first-touch or CPU-only chunk goes through the existing StagedGather / StagedScatter,
which now take a buffer or an image target. Hazard tracking, dirty-page reports, imports held to
completion and the bytes outside the texels are as the buffer forms keep them. Refused as the
buffer forms are, and with Invalid / Problem::HostRam for the texture's own cases (its doc
extended); no new RuntimeGap, Degradation kind or WorkCounts field: the direct form shows in
host_ram_copy_regions with no staged copy. replay.rs logs the call (HostRamTextureCopy);
blit_texture.rs and blit_plan.rs helpers are shared (pub(super)). Runtime README and HOWTO
document it; the signature table blessed (+2 methods); REFUSALS regenerated. RUNTIME_VERSION 2484.

Verified: msi job m3-max-37991 (lavapipe, --cfg m2v_cpu_icd): clippy -p metal2vulkan-runtime
--all-targets --all-features -D warnings 0; nextest host_ram_texture_device + host_ram_copy_device
39 passed. m3-max-37997: "HOST-RAM-TEXTURE llvmpipe: fill regions 250, dispatches 0, staged 0" (a
300x200 BGRA8 Private texture, rows at 1280 bytes from byte 48, one row across a chunk end); the
staged test saw exactly one staged gather and one staged scatter. Plain and --cfg m2v_gpu clippy,
rustdoc and the 780M and Iris runs follow on development.
2026-11-16 14:53:52 -08:00
Anees Iqbal 3619e37540 RUNTIME 2482: Texture::view_placement answers what a view would be, by the decision its making takes
The consumer will make an IOSurface plane's device cache one optimal Private texture, every
texture over the plane a view of it, and needs to know before it makes a view whether the
runtime would make it a Vulkan view of the image or a view shadow (which it sends to its own
fallback instead).

What: `Texture::view_placement(pixel_format)` answers `ViewPlacement` (`Image`,
`ImageThroughSwizzle`, `Shadow(ViewShadowReason)`, `OverBytes`), or the error
`new_texture_view` would refuse the view with. The decision is factored, not copied:
`Texture::checked_view` holds the checks `view_as` ran inline (Metal's rules, rotation, X32,
buffer slices, decoded twins), `Texture::view_hold` decides the storage (shared, through a
swizzle, the viewed image, a shadow and why, storage over the bytes), and
`Device::view_shadow_plan` / `shadow_plan` hold the shadow's refusals `image_shadow` checked
while making. `view_as` and the query call the same three. `image_plan::views_missed` replaces
`takes_views_of` and names why an image takes no view (another compatibility class, or not in
its list); `Device::view_apart` replaces `image_takes_view` and puts the device's missing
reinterpretation first; the `shadowed-texture-view` notice's reason now follows that reason
(it chose by the texture's PixelFormatView usage before).

Tests: `view_placement_device` (runtime, device cfgs) sweeps 10 texture formats x 5 usages x
24 view formats, checks the query moves no count and matches the view made (by
`view_shadows`, `views_through_swizzle` and the handed-out image), and names the consumer's
cases. `plane_device_cache` (validation lane): a 300x200 BGRA8Unorm Private texture round-trips
between no-copy buffers at offset 48 and pitch 1232 with every other byte kept; a clear through
its sRGB view then a copy through its own-format view in the next encoder, tracked and
untracked with a fence, read the clear with no hazard under synchronization validation, and the
unordered control is reported as a read after write.

Documented in the runtime README; the signature table blessed (10 rows); REFUSALS regenerated.
RUNTIME_VERSION 2482.

Verified: msi job m3-max-37961 at c2f0c96d3c: clippy -p metal2vulkan-runtime -p
metal2vulkan-validation --all-targets --all-features --cfg m2v_cpu_icd -D warnings 0; the lavapipe
tests, plain and --cfg m2v_gpu clippy and rustdoc follow on development. The hazard tracker keys a
view's uses on its image (texture.rs view_as shares the Arc<Image>; bound_use/image_use key on
image.identity.key), so the order across views needed no fix.
2026-11-16 14:48:17 -08:00
Anees Iqbal df87983bb7 RUNTIME 2463: Render draws: the restarted list and the error and notice makers out of line, cold
What: draw_resident's restarted-list arm (the index rewrite and gather requests, 205 source lines)
is its own #[cold] #[inline(never)] method, restarted_list; Device::degrade, degrade_copied_pages,
degrade_host_step, degrade_where and tell, and error.rs's vulkan, invalid, nil and internal are
#[cold]. Same commands, barriers and answers; only where the code lies changes (draw_resident 130.7
-> 127.4 KB of machine code). Also folded: draw_costs gains a guest shape of a few render encoders
with set_bytes and each thread's CPU a draw (17126bfe04), the encoding thread's own CPU apart from
unnamed threads (afa24f4074), and --calls counting each call's cycles and cache misses (7249f6930b).

Why: on a Zen 4 host a one-draw render pass ran at IPC 0.79 against 1.7 inside a long pass, the
same on RADV and lavapipe (gem10, m3-max-36911/36975). The misses are instruction fetches: per pass
about 8.3k L2 instruction misses against 1.2k data, over 806 distinct 4 KiB code pages (more than
the L2 iTLB's 512), no function above 7.5% of them (m3-max-37017, -37041). This change is
measured neutral (m3-max-37061, lavapipe, release: pass1 instructions 112,257 -> 112,123, L2
misses 10,590 -> 10,577; cycles within the node's noise) and kept as correct and neutral; the
lever left is the layout of the path's code across pages, a build setting of the program.

Verified: see the landing's check jobs.
2026-11-16 09:43:35 -08:00
Anees Iqbal 3de483d86f RUNTIME 2459: Joined completions: a command buffer marked to join the next groups under Exact
CommandBuffer::set_completion_joins_next marks a command buffer, before its
commit, as one whose completion may be seen with the next one's. Under
CompletionPolicy::Exact, on a device whose merge check holds and whose
queues are not relayed, a marked command buffer's batches wait in the
scheduler's group as every batch does under Grouped. The first batch of the
VkQueue behind them that is not marked goes last in that group, which then
goes at once (GroupEnd::Closed, WorkCounts::group_ends_closed), so it is
seen complete at its own end and never held back. Its submission check runs
with the marked ones' (check_heads), so they are found ready together. No
group is kept past its pass under Exact (Alone::Unkept,
WorkCounts::batches_held_alone_unkept): a kept group can reach the GPU after
the work ahead of it ended, which would delay the unmarked one behind it.
Everywhere else (Grouped, no merge, relayed queues, the encoder trail,
batches that never group) the mark changes nothing.

Why: on the Iris Xe, ANV on i915 lists every VkDeviceMemory in each
execbuffer, about 170-190 us of driver time a vkQueueSubmit at the
consumer's import count, and the consumer cuts each guest command buffer
into about 12 parts committed under Exact, one kernel submission each.
In its walk the GPU sat idle about 1.5 ms per waited guest buffer between
parts already committed, behind a backlog of those calls. The consumer will
mark every part but the last of a cut whose completion nothing observes.

Grouped-completion's notice, docs/API.md's catalogue, FAST-PATHS row 38, the
runtime README, CompletionPolicy::Exact's doc, api_signatures and REFUSALS
say so. Tests: runtime_lane::joined_completions (marked parts group and a
group is closed by the last; checked parts too; a no-op where the device's
own check finds no merge; unmarked parts go alone; an unmarked command
buffer is seen complete while the long one behind it still runs, the marked
one before it complete by then), on lavapipe with the merge assumed.

Joined completions: the cost table's length, and the order test's first work done before

The conformance cost table's SHARED list holds 36 rows with
batches_held_alone_unkept. In the order test the marked command buffer took
the new buffers' first work, which no batch in a group takes, so it went
alone and nothing grouped: the buffers' first work now runs before it.

Verified: clippy and lavapipe lane job m3-max-36769 showed the failure
(grouped 0 with grouping true); the rerun is the next job.

Verified at 8e6c37c263: m3-max-36784 (msi) clippy --workspace --all-targets --all-features 0; m3-max-36785 (msi, lavapipe, --cfg m2v_cpu_icd) joined_completions + grouped_submissions + alone_batches 21/21 (marked parts under Exact with the merge: 7 command buffers in 2 submissions; unmarked: 7 submissions, 0 grouped; lavapipe's own merge check, not Holds: 0 grouped; an unmarked buffer is seen complete at its own end). The Iris merge check answers Holds (m3-max-36725: 9.6 us in one call of 4 against 26.4 us apart). Release-mode lavapipe, clippy --cfg m2v_gpu and m2v_cpu_icd and rustdoc run after the merge.
2026-11-16 08:18:12 -08:00
Anees Iqbal 8d617591f8 RUNTIME 2409: In-place textures over dma-buf pages: the image bound in the buffer's own import
A texture in place over a no-copy buffer's dma-buf pages no longer always asks the pages'
source for a new dma-buf and a dedicated import of its own. Where the pages lie in one import
dedicated to nothing (no sparse buffer over several imports, no import the driver made
dedicated to the buffer), its DRM_FORMAT_MOD_LINEAR image whose plane lies at offset 0 at the
texels' pitches is bound in that import at the texels' offset, beside the buffer
(vkBindImageMemory's memoryOffset): no udmabuf, no import, no new GPU mapping. Every fact is
asked of the driver: the image requires no dedicated allocation (VUID-vkBindImageMemory-
image-01445), the format query takes dma-bufs for it outside one (not DEDICATED_ONLY), its
alignment divides the offset (-None-10735), its size fits the pages' placement (-None-10737)
and its memory types take the import's. An import dedicated to the buffer binds no image
(-memory-10926): DmaBufPages now notes that.

A new check class, PagesClass::DmaBufInImport (CHECK_VERSION 20), measures that image; the
check's textures of each dma-buf class take that class's image alone (a thread-local of the
class the check runs). texture/route.rs takes the new class where its verdicts take the
texture, else DmaBuf's; a shadow waits on DmaBuf's verdict while both pend. Where the making
refuses the image in the import, it falls back to today's image where DmaBuf's verdicts take
it. A pending move re-routes the same way. Binding in the import reads it apart: it is kept
imported for good, as an image in a pointer import's is. A rebind remakes such an image in the
new pages' import by the same order. RADV requires a dedicated allocation of every such image,
so its check leaves the new class unchecked and it never takes the route.

New WorkCounts field: dma_buf_images_in_import. No new Degradation kind.

The route-(b) device tests (parked images, plane offset, import cycles, a texture's residency)
fail the new class's verdicts first, so they keep measuring today's image on any device. A new
device test (tests/dma_buf_in_import.rs) counts the route and its negative control.

Also: 4c3cbe2f1d and 37d2a750ce (the probe, dma_buf_linear_bind: a linear and a modifier image for
dma-bufs bound in the pages' existing import, the dedicated answers, a re-import arm), 5a40c2ef7b
(docs: API.md, HOWTO.md, FAST-PATHS.md, host_residency.rs module docs).

Why: the owner asked how to remove the per-texture dma-buf. Probe answers (Mesa 26.2.6): RADV on
the Radeon 780M refuses LINEAR images for dma-bufs (NOT_SUPPORTED x15) and requires a dedicated
allocation of every DRM_FORMAT_MOD_LINEAR image (m3-max-34443), so there it never fires. ANV on the
Iris Xe takes both images outside a dedicated allocation, bound in the existing import byte-exact;
first use of an 84 MiB texture 1.37 -> 0.21 ms (m3-max-34453).

Verified in the lane (m3-max-34571, gem10, at 5d5dee7901): clippy -D warnings -p metal2vulkan-runtime
--all-targets --all-features, plain and m2v_cpu_icd. Still running when landed: the lavapipe
in-place and dma-buf suites with the new count test (m3-max-34593), clippy m2v_gpu, PHOENIX, and the
Iris count test with its negative control.

API: adds the field WorkCounts::dma_buf_images_in_import (additive; api_signatures blessed in the lane).
2026-11-15 18:55:56 -08:00
Anees Iqbal aa5511f61e SEMANTICS 2130 / RUNTIME 2406: 16x16x16 simdgroup matrix products: refused as their own feature, Metal's rule below Apple10
What: `air.simdgroup_matrix_16x16x16_[widening_]multiply_accumulate` is now refused in every stage
as `Unsupported{SimdgroupMatrix16x16x16, NotImplemented}` (a new `Feature`), ahead of the 8x8
lowering's kernel-only check. The runtime's `compile_error` answers it as Metal does:
`Needs::MetalGpuFamily(1010)` on a device that does not claim Apple10, `NotImplemented` on one
that does (as `IndirectRenderState`). The owned fixture engine/simd_matrix16 shrinks to one form
per class (float, half, widening signed int8), each with the four transpose-flag pairs, 12
kernels; the probe carries the M3's answer in its header.

Why: Metal itself refuses these products below Apple10. The M3 Max (macOS 27.0.1) refused every
pipeline of the fixture at creation, AGXMetalG15X_M1 code 3, "simdgroup_matrix<T,16,16x16>
operations are supported by GPUFamily10 and later" (job m3-max-34410). No device the runtime
presents claims Apple10: the family lists the "SIMD-scoped matrix multiply operations" row (from
Apple7), refused NotImplemented(SimdgroupMatrix) on every device, and the lod-bias row, a gap. So
the refusal is Metal's own answer, not a device gap: no FAST-PATHS known gap.

Tests: engine_simd_matrix::products_of_16x16x16_are_refused_as_their_own_feature (every
committed profile, the fixture's 12 kernels); runtime_lane::simd_matrix16 (the device's compute
pipeline creation answers MetalGpuFamily of Apple10). REFUSALS.md regenerated, api_signatures
blessed, reach mark added. The engine fixture expectation table and golden hashes take the
fixture's rows on development.

Also: f639b74288 adds the owned fixture (MSL we wrote, compiled by scripts/regen-air-fixtures) and
its Metal probe; 5dbfa3d3d5 imports AirLibrary in the runtime-lane test.

Verified in the lane: m3-max-34499 (msi, at 38d4694b12) clippy -D warnings for metal2vulkan, runtime
and validation (all targets and features) and 45/45 tests, incl. the new engine_simd_matrix test (12
kernels on every committed profile), the error tests, refusal_surface, api_signatures, api_surface;
m3-max-34514 (gem10, at 5dbfa3d3d5) clippy m2v_cpu_icd and runtime_lane::simd_matrix16 on lavapipe
(Needs::MetalGpuFamily(1010) for all 12). Clippy m2v_gpu (34516) still running when landed.

API: adds Feature::SimdgroupMatrix16x16x16 (additive; api_signatures blessed in the lane).
2026-11-15 18:32:00 -08:00
Anees Iqbal c2206c14b0 RUNTIME 2389: Device::import_shared_dma_buf imports a shared dma-buf ahead and keeps it while a handle lives
A runtime extension (Metal has none). A guest's buffers over pieces of one shared file of guest RAM
were each imported as their own dma-buf import and freed with the buffer, so a compute loop that
made and dropped no-copy buffers paid an import and a free per command buffer, and on RADV each
import maps its pages at once (the next submission's CS waits for the page-table job).
Device::import_shared_dma_buf(file, options) (unix) imports the whole dma-buf on the caller's
thread, or joins the device's live import of it, and returns a SharedDmaBufImport; while a handle
lives, the file's entry in the device's map keeps the import, so buffers over its pieces join it
instead of importing again, and it is freed once its last buffer, heap and handle have gone (one
kept import per file a live handle names, per generation). The class comes from `options` as a
no-copy buffer's (Private, Memoryless and undefined options refused, Invalid StorageMode); the
import takes the type a no-copy buffer of that class would get first, so pieces join it.
Refusals use the existing kinds (Unsupported HostMemory, OutOfMemory). A device's recovery lets go
of the lost generation's kept holds and seeds the new one's map, whose first buffer imports the
file again; nothing is imported on the recovering thread. A device without a dma-buf importer
keeps nothing (Debug: imported false). The handle imports whether or not the device's buffers over
those pages take the dma-buf route: on a device that takes the pages' pointer it is one listed
dma-buf a submission for nothing. WorkCounts::dma_buf_shared_imports_kept gauges the kept imports;
the handle's import counts in dma_buf_imports. Docs: rustdoc, dma_buf.rs Shared files, HOWTO
dma-buf section, the runtime README extensions and unix-only lists. REFUSALS.md: the StorageMode
site moved to host_class, which the no-copy call and this one share.

Public surface: Device::import_shared_dma_buf, SharedDmaBufImport (Send + Sync, consumer_auto_traits)
and WorkCounts::dma_buf_shared_imports_kept, blessed in api_signatures.tsv.

Verified: m3-max-33745 at the lane tip 856a1fabae: clippy plain, m2v_gpu, m2v_cpu_icd 0; rustdoc 0;
lavapipe runtime suite 2836 passed. Device tests (lavapipe): three buffers made and dropped in turn
take imports 1 / joined 3 with the handle, imports 3 / joined 0 without; a handle keeps a live
buffer's import; recovery imports nothing and the next buffer's import stays kept; Private refused.
Churn bench, PHOENIX (RADV 780M, release, interleaved, 450 command buffers an arm, a8f297bf11, the
same code but the count): no handle 1 import + 1 free a command buffer, call median 820-907 us, GPU
start median 3026-3037 us; handle kept 0 imports, 0 frees, 1 join, call median 25-69 us, GPU start
median 104-145 us.
2026-11-15 14:48:09 -08:00
Anees Iqbal ab139e4b6e RUNTIME 2366: Runtime FALLBACK repro bundle at a creation refusal (default-off diagnostic)
What: metal2vulkan-runtime writes the FALLBACK repro bundle the command line
writes for its own failures when it refuses a library or pipeline creation,
where METAL2VULKAN_REPRO_DIR names a directory (unset, nothing is written).

- The CLI's bundle writer moves into the library as the hidden crate-root
  module metal2vulkan::repro (feature serde), shared by the binary and the
  runtime. A bundle's directory is named by its content
  (metal2vulkan-repro-<16 hex>), written under a temporary name and renamed,
  so an identical failure is written once, across threads, processes and
  runs. The CLI's own bundles keep their files (input, profile.json, the
  descriptor files, repro.sh, repro-command.txt, failure.txt); only the
  directory's name changed, so a bundle written before still replays.
- The CLI takes --device FILE in place of --profile: the JSON of a
  DeviceDescription and DevicePolicy (ReproDevice), which builds the
  runtime's own compile device.
- The runtime hooks each creation where its refusal returns: a library of a
  metallib, a function's lookup, every compute and tile state
  (ComputePipelineState/TileState::create_adding: creations, added binary
  functions, archive adds) and every render state
  (GraphicsState::create_reflecting). It bundles Unsupported, NotImplemented
  and Compile refusals but a cancelled compile and a name the library lacks
  (Metal's own nil); never Invalid/Nil/MetalError. The bundle holds the
  library's bytes, device.json, the request as the CLI's options and
  descriptor files, and failure.txt with the call, the refusal and what the
  command does not replay. That list comes from a full destructuring of the
  compute, tile and render descriptors (and the stage functions): a new
  descriptor field fails to compile in repro.rs until it is replayed or
  listed.
- Bounded: at most 32 bundles and 256 MiB per process; past either nothing
  more is written and one line says so. Written on the refusing thread; the
  call returns the same refusal; a write failure is said once. Each bundle
  is named in one line through the device's message sink (id name
  metal2vulkan-repro). The runtime's metal2vulkan dependency gains serde.
- Not bundled: mesh states (no CLI mesh path), a dispatch's or draw's later
  variant, driver VkPipeline makings, Metal-source libraries.

Docs: env_vars registry, README CLI, docs/HOWTO.md section 4, the runtime
README's Errors section, the CLI help.

Tests: runtime CPU tests of the bounds (a tally with the seam's limits);
a lavapipe/GPU device test (ob3_stage_input with no stage-input descriptor:
one bundle with the expected parts and command, device.json rebuilding the
runtime's compile device by profile fingerprint and answering the same
refusal, none for a second identical refusal or a missing name, none
without a directory); CLI tests replaying library-written runtime bundles
(compute, and render with a vertex descriptor) through repro.sh to the same
FALLBACK, and --device compiling what --profile does.

Verified at ae56b195e9 (msi, m3-max-32986): metal2vulkan cli,
api_surface and api_signatures 25 passed; runtime repro tests 9 passed;
clippy -p metal2vulkan -p metal2vulkan-runtime all targets, all features
0. Lavapipe (m3-max-32978): repro_device writes one bundle that the
CLI replays to the same refusal; a second identical refusal writes
nothing.
2026-11-15 10:14:52 -08:00
Anees Iqbal 5ba7afd9d4 RUNTIME 2360: Shader cache: no default directory makes a memory-only device, never a failed one
With no caller directory and no home (USERPROFILE on Windows, HOME elsewhere),
default_directory answered Err and CacheSetup::of turned it, and any failure to
open the default path, into Error::ShaderCache, so every device creation and
adoption failed. Metal never fails device creation over its shader cache, and
the default is the runtime's choice, not the caller's (owner rule 2).

- The Windows default is %LOCALAPPDATA%\metal2vulkan (the local application
  data folder, read from the environment; no new dependency). XDG_CACHE_HOME and
  USERPROFILE are no longer read there.
- default_directory takes its environment as a closure (CacheSetup::of_in), so
  a test feeds its own without touching the process's.
- Where the caller names no directory and the default does not exist or cannot
  be made or written, the device keeps its cache in memory alone: the Store has
  no directory, every lookup is absent, every write is refused with no
  filesystem call, the scans do nothing, and writers ask has_directory first so
  nothing is encoded for it (a translated function still is: its encoded length
  weighs it in the memo). The device says so once as it is made, as the existing
  degrade notice ShaderCacheEntryNotWritten naming why; each entry it does not
  write counts in write_failures. The driver's pipeline cache data is not read
  back, and the device checks' verdicts are not encoded.
- A directory the caller names that cannot be used is still Error::ShaderCache.
- Device::shader_cache_directory answers Option<&Path>: None for such a device.

Docs: the shader_cache module docs, ShaderCacheOptions::directory,
write_failures, Error::ShaderCache, the degradation's declaration and its
docs/API.md entry, the runtime README (Windows default, error table), HOWTO,
create.rs's list of environment variables. api_signatures re-blessed;
docs/REFUSALS.md regenerated (a refusal's site function renamed).

Tests: tests::shader_cache's default-directory and no-directory-store unit
tests (plain gate), and the lavapipe/GPU device test
shader_cache_no_directory: a device made with an empty environment and no
caller directory is made, has no directory, makes four render states with two
functions translated once, writes nothing, and its notice is heard once.

Verified (msi): m3-max-32796 clippy plain 0, 67/67 shader_cache and
degradation tests, api_signatures 0, clippy x86_64-pc-windows-gnullvm 0;
m3-max-32797 (lavapipe) clippy m2v_cpu_icd 0, 61/61 shader_cache and
in_place_check, including the no-directory device test.
2026-11-15 09:10:25 -08:00
Anees Iqbal 0ca24685d7 RUNTIME 2351: Textures over buffers: Metal's allocation bound counts the last texel, a heap's size and a no-copy buffer's pages
A texture over a buffer whose texels run past the length was answered nil
where its rows' padding ended past the length rounded up to 16 KiB. The
M3 Max (macOS 27.0.1, the consumer's limits runs, every buffer kind and
length bisected) makes more:

- A 2D texture and a texture buffer count to their last texel, not the
  last row's padding: a 2D R32Uint 64x64 from 256, rows 512 apart, over
  20000 bytes is made with its last texel at 32768 (rows' end 33024); a
  texture buffer of 32768 R8Uint texels at a bytesPerRow of 36864 over
  20000 bytes is made. Arrays keep their rounded slices' end.
- A heap's buffer is bounded by the heap's size, counted from the
  buffer's start, whatever its length or place in the heap (4 MiB heap:
  made to 4194304, nil at 4194305).
- A no-copy buffer is bounded by its pages: its pointer's offset in its
  16 KiB page plus its length, rounded up to 16 KiB, from its start
  (16384 bytes starting 4096 short of a page's end: made to 32768).

BufferFacts now carries the buffer's allocation (own, a heap's size, a
no-copy buffer's page offset), filled from Buffer::heap, host_backing and
contents; BufferFacts::allocation_end gives the bound. Buffers under
16 KiB keep no bound (the M3 Max answers nil past 128 KiB there, the x86
Macs make every end measured), and an array whose last texel lies inside
the length is still made: no new refusal.

Such a texture stays a copy, as before at the old bounds: a 2D texture or
array is a shadow image whose copies in and back go through its tail
(texture/route.rs Route::Past -> TextureShadowReason::PastLength,
announced shadowed-texture), a texture buffer's functions view its tail
(into_texture_buffer, staged-texture-buffer). The texels past the length
live in the tail, zero when made; the caller's bytes past a no-copy buffer
and a heap's other bytes are never read or written.

Tests: tests::linear_plan::a_texture_ends_where_metal_s_allocation_of_its_buffer_does
(each kind's and form's M3 boundary, made at it and nil one past; the
made rows past the old bound fail before this change); device tests in
buffer_tail_device (a heap's buffer to its 64 KiB heap's size, a no-copy
buffer at page offset 12288 to 32768, a padded 2D texture to its last
texel): made, every path reads and writes right, the buffer's CPU write
inside the length is read through the texture, shadow copies counted,
no other memory touched, one row more Metal's nil. docs/API.md's
accepted difference, REFUSALS.md regenerated.

Evidence (lane jobs, msi): m3-max-32369: clippy -p metal2vulkan-runtime --all-targets --all-features -D warnings 0;
linear_plan|buffer_texture 34/34 incl. tests::linear_plan::a_texture_ends_where_metal_s_allocation_of_its_buffer_does (the
M3's boundaries per kind and form, made at E, nil at E+1). m3-max-32370 (lavapipe): 13/13 buffer_tail_device + allocation
tests incl. a heap's buffer to its heap's size, a no-copy buffer to its pages, a 2D texture whose last texel ends at the
allocation: every path (get_bytes, blit, kernel) reads as made, writes coherent with the buffer's bytes inside the length
(shadow copies counted: such textures are shadows / staged texture buffers through their tail), neighbours untouched, one
row more Nil(PastAllocation). Negative control and the PHOENIX run follow in the lane.

Lane commit: 263219d515.
2026-11-15 07:15:50 -08:00
Anees Iqbal f851c07e52 SEMANTICS 2123 / RUNTIME 2349: Texture buffers past maxTexelBufferElements bound through views of their parts
Metal makes texture buffers of up to 2^28 texels on every Mac; one texel
buffer view holds at most the device's maxTexelBufferElements (2^27 on ANV
and lavapipe, 2^26 on MoltenVK), and the binding of a wider one was refused
(BindError::TexelBufferTooLarge).

The consumer now states with a texture buffer's binding the views its texels
take (BoundTexture::Buffer::parts, bind::texel_buffer_parts: 1 within the
limit), which its shape carries. A slot whose function only reads, writes,
updates by an atomic or asks the width of the texture buffer, on a device that
indexes texel buffer arrays NonUniform, states RuntimeFact::TexelBufferParts;
where the shape binds more than one part there, the plan asks for the parts
variant (VariantKey::texel_buffer_parts). Under it the slot is an array of
the parts' texel buffers: texel i is texel i - k*P of part
k = min(i / P, parts - 1), P the device's limit rounded down to its texel
buffer offset alignment (bind::part_texels), and the width (parts - 1) * P
plus the last part's. texel_ranges writes one range per part at its array
element (DescriptorRange::element), and the runtime views each.

Each part is the device's own view in the format one view takes, so a read
converts its texel as the one view does: no precision note. A texture buffer
one view holds keeps one view, no variant and its key. The families row
TextureBufferWidth is exact where the parts reach 2^28.

Still refused (TexelBufferTooLarge): a slot read through a sampler or used beyond read/write/atomic/width; a device
without NonUniform indexing of that kind of texel buffer array; formats with several texels a block. Argument-buffer
texture buffers past the limit stay the heap neutral (unnamed-texture-unviewable). New: WorkCounts::texel_buffer_parts_bound,
RuntimeFact::TexelBufferParts (appended), bind::part_texels / texel_buffer_parts, BoundTexture::Buffer.parts,
TextureShape::Buffer.parts (serde default 1), VariantKey/LoweringInputs.texel_buffer_parts (hashed only when non-empty),
DescriptorRange.element. SEMANTICS_VERSION bumped: input once refused now translates.

Evidence (lane jobs, msi): m3-max-32343 at 628264de17: clippy --workspace --all-features --all-targets -D warnings 0;
41 metal2vulkan tests incl. golden_hashes_match_the_table (every fixture's SPIR-V unchanged on every profile: one part is
byte-identical), the binder test (an under-limit slot: no parts entry, empty variant, layout counts 1), the interpreter
parts test (robust and unrobust), api_surface / api_signatures / refusal_surface; families::states_follow_their_sources;
lavapipe texture_buffer_width_device (R32Uint limit+64 texels: both sides of the limit and the last texel read and written,
past the end reads 0 and writes dropped, texel_buffer_parts_bound +3) and buffer_tail_device. Without the fix the device
test fails at bind: TexelBufferTooLarge{elements 134217792, limit 134217728} (m3-max-32140). ANV (2^27) is down; the XTX
(2^29) never parts.

Lane commits: 9fbf7d3c14, 7f7f3ad95e, 9a745ffb3c, 740e9e43dd, 628264de17.
2026-11-15 07:10:59 -08:00
Anees Iqbal b7053280de RUNTIME 2346: 4:2:2 textures over IOSurface planes: an image of their texels, decoded from the pairs in place
A GBGR422 or BGRG422 texture made over a buffer's bytes (Buffer::new_texture_with_iosurface_plane,
a CoreVideo 2vuy or yuvs plane, over a Shared buffer or a no-copy buffer's host pages) had no
decoded twin: twins are attached only to textures whose image is their own for good, so every
dispatch or draw that read or sampled it was refused, with a "needs R8G8B8A8_UNORM SampledImage"
line naming a format every device samples.

Such a texture is now an R8G8B8A8_UNORM image of its texels, the converted shadow a two-plane
YCbCr texture over planes already is (ShadowSource::Converted, its conversion now an enum of the
planes' and the pairs'): its copy in, before the first command of a command buffer that reads it
and after a command wrote the bytes, is one dispatch of the new bind::chroma_convert_module that
reads the pairs where they lie, at any byte of their VkBuffer, through one storage-buffer binding,
and writes Metal's texels (ChromaDecode, exact) through the image's R32_UINT view. Copies, blits
and CPU calls keep moving the plane's bytes. Where the device converts the pairs' format with
Metal's reconstruction (MoltenVK), the copy in is that conversion instead: the plane's rows copied
into the pairs' image, sampled through the conversion (chroma_sample_module) into a scratch,
copied into the image; announced decoded-texel-precision at the copy in's planning. The set binds
the buffer's VkBuffer, so the planning makes it again after a rebind gave the buffer another one,
and each command buffer holds the set it took. The placement query answers OtherShape. A plane
the window cannot take (past maxStorageBufferRange, a last word past the buffer, rows that share
bytes, texels past the buffer; with the device's conversion, a first byte or rows off 4 bytes)
keeps the carrier, its reads refused; FAST-PATHS records it as a known gap.

Per frame, per texture (w x h texels): before, no read ran at all; the texture was an R8G8_UNORM
carrier of the plane, 2 bytes a texel. Now no byte is copied: one dispatch reads the w*h*2 bytes
of pairs in place and writes w*h*4 bytes of texels (1920x1080: 4147200 read, 8294400 written).
Memory: one R8G8B8A8_UNORM image, w*h*4 bytes (1920x1080: 8294400), in the carrier's place; with
the device's conversion also the pairs' image (w*h*2) and the scratch (w*h*4), and per copy in a
w*h*2 copy in and a w*h*4 copy out. Announced carried-decoded-twin (an existing kind) with that
cost. No new Degradation kind, no new WorkCounts field.

A carrier's binding without a twin is now refused NotImplemented(Format) naming the texture's
format (pvrtc::holds_for_copies), not a need of the twin's view format.

Public surface: metal2vulkan::bind::{chroma_convert_module, ChromaConvertModule} added
(api_signatures.tsv blessed, api_surface table); docs/REFUSALS.md regenerated (one more
binding_view site of Format).

Tests: the in-place kernel against ChromaDecode's decode under the interpreter (both orders, first
bytes off a word, odd sizes, rows apart); a carrier's binding refusal (binding_view unit test);
a device test of both formats over a Shared buffer and over host pages reading Metal's measured
bar values (an Apple M3 Max, macOS 27.0.1) and Metal's decode of a random frame written on the
CPU before the next command buffer, OtherShape from the placement query, and the device's
conversion counted and announced where it converts. Verification jobs follow in the lane report.

Evidence (lane jobs): msi m3-max-32240 at 94f603bf35, --cfg m2v_cpu_icd on llvmpipe: 130/130 touched tests, clippy -D warnings 0;
the device test fails without the fix (placement not OtherShape, the read's dispatch refused). PHOENIX gem10 m3-max-32260
(archive m3-max-32241): all 4 cases (GBGR422/BGRG422 over a Shared buffer and over host pages) "Metal's texels, exact"
for the M3's measured bars and a random CPU-written frame; ycbcr_device, ycbcr_refresh, twin_reads 7/7. MoltenVK (device form)
run on the M3 follows.

Lane commits: 735234d5f4, d59f44baa6, 94f603bf35.
2026-11-15 06:48:09 -08:00
Anees Iqbal 43bb61c60e RUNTIME 2344: Runtime: a command queue on the copy engine, and buffer copies merged into runs
Device::new_command_queue_for_copies() answers a CommandQueue whose command
buffers submit to the device's copy engine (the staging queue's family of
transfers alone), or None where the device has none to give (MoltenVK,
lavapipe, RADV by default, a copy engine of one queue, an adopted device).
Its VkQueue is the copy engine's third queue where it has one, else the fill
queue's, whose submissions then take that QueueSlot's lock: NVIDIA's copy
engine has two queues, staging's and fill's, and staging must wait for no work
in flight. The slot is the last of the device's VkQueues, after presenting's;
its family stays out of image sharing (buffers already share it as the staging
queue's family, so no ownership transfer is recorded).

Its command buffers take blit encoders alone, and of their commands buffer
copies, fills and fences: other encoders and blit commands are refused
(Invalid, Problem::CopyQueue(CopyQueueProblem::Encoder | Command)), as is a
caller's VkBuffer not concurrent with the copy family (Buffer). A copy batch
takes buffers' fills alone from first work. Barriers on its VkQueue name the
copy family's reads (Barrier::record_reading), not the primary family's, which
a family of transfers alone may not name beside ALL_COMMANDS
(VUID-vkCmdPipelineBarrier-dstAccessMask-02816).

A blit encoder's consecutive copy_from_buffer_to_buffer calls between the same
two VkBuffers that its order needs no barrier between are recorded as one
vkCmdCopyBuffer of many regions (copy_run.rs), on every queue; counted as
WorkCounts::buffer_copies_merged. Batches on the copy slot are counted as
WorkCounts::copy_queue_batches.

Verified: not yet built (first build job follows).

Also in this landing:
- Copy queue: docs, and the device test's None answer checked against the device
- Copy queue: keep the copy queue's place alive while the families are counted

Evidence: lavapipe 425/425 (m3-max-32049), clippy m2v_cpu_icd and m2v_gpu -D warnings (32049, 32053); XTX m3-max-32073: default RADV answers None; RADV_PERFTEST=transfer_queue: 1 batch on the copy engine, 63 of 64 row copies merged, sync file signalled, bytes right, refusals typed, validation layer silent.
The derived API table and docs/REFUSALS.md were re-derived on the merged tree (winport's #[cfg(unix)] gates landed beside copyq).
2026-11-15 06:09:09 -08:00
Anees Iqbal ec0be064d0 RUNTIME 2342, SEMANTICS 2122: Texture buffers read through argument buffers sit in texel-buffer heap classes
A pipeline whose argument buffers hold texture buffers was refused with
ArgumentBufferTextures (NotImplemented, no location): the translator's heap layout
(lower/texture/slot.rs declare_heap) had no set-1 class for a texture_buffer member, so
SPIRV-Cross-shaped tier-2 argument buffers (descriptor sets as [[buffer(n)]] structs with
texture_buffer, texture2d and sampler members) could not be made, on any device.

- Set 1 gains texel-buffer heap classes: UNIFORM_TEXEL_BUFFER for read, formatless
  STORAGE_TEXEL_BUFFER for read_write and write. The class follows the facts' texture type.
- DescriptorCaps gains update_after_bind_uniform_texel_buffer and
  update_after_bind_storage_texel_buffer; where a device lacks them a typed needs_any_of names
  the missing features. Non-uniform texel-buffer indexing and the without-format read/write
  needs are checked as for images; link counts STORAGE_TEXEL_BUFFER with the images against
  the update-after-bind limits.
- New public bind::heap::HeapElement::TexelBuffer(vk::Format).
- The runtime writes each live texture buffer's texel view at its resource ID, with a neutral
  texel view at element 0; a gone texture buffer's Texels stay alive until its tickets clear.
  A texture buffer whose bytes cannot be viewed in place (staged, tail-viewed, offset off
  minTexelBufferOffsetAlignment, past maxTexelBufferElements, swizzled, or a non-direct format)
  reads the neutral and is announced through the existing UnnamedTextureUnviewable. No new
  Degradation kind.
- docs/REFUSALS.md and api_signatures.tsv regenerated.

Test: runtime_lane::argument_texel_buffers::a_texture_buffer_in_an_argument_buffer_is_read_in_both_stages
(an owned fixture in SPIRV-Cross's shape): vertex and fragment read a texture_buffer member of a
set-0 argument buffer, the fragment also samples a set-1 texture2d through the sampler beside it;
every pixel must equal texel[1] + texel[4]*tint + albedo.

Verified: lavapipe with the validation layer, m3-max-31658 at 6626eeaff3: pass. Control
m3-max-31636 (the fixture and test at the base, without the fix): fails with exactly the
ArgumentBufferTextures NotImplemented refusal.
2026-11-14 23:33:03 -08:00
Anees Iqbal 057b794f5b SEMANTICS 2115 / RUNTIME 2315: rate-mapped region copies record a box of regions per multi-draw
What: a draw through its region-copy variant recorded its regions 16 at a time (the device's
viewports). Each recording set 16 scissors, pushed its first region and stored DrawIndex as
ViewportIndex. On a guest frame the host step made about 4.7k such recordings a frame (Iris and
RTX 3090), while the GPU sat idle waiting for the step.

The variant's four clip distances already keep each copy to its region's pixels, as a fanned-out
copy's are kept; the per-region scissor only culled. Now:
- The vertex function draws region first + (DrawIndex / c)*nx + DrawIndex mod c from a pushed
  box (PushField::RegionBox, renamed from RegionFirst, now [first, columns]).
- It stores 0 as ViewportIndex, the recording's one viewport, so it writes every output the base
  variant wrote.
- The recording sets one viewport and its box's union scissor.
- A direct draw records a box as many regions at a time as one vkCmdDrawMultiEXT takes
  (maxMultiDrawCount - 1), its rows in order. A run records one recording per box its bounds
  reach; any other draw records the whole table in one or a few.
- Indirect draws keep one region a recording, under that region's scissor.
- The variant still needs shaderOutputViewportIndex and shaderDrawParameters; it no longer
  needs multiViewport.

Exactness: a border between two regions of a recording holds no pixel centre and no sample at
Vulkan's standard sample locations (at least 1/16 px inside a pixel, up to 8 samples), while each
copy's clip distance there is zero up to rounding. A box is recorded one column (row) at a time:
- in a pass whose custom sample positions put a sample on a pixel's left (top) edge;
- on a device without standardSampleLocations;
- in a 16-sample pass.
See render/fan_out.rs, folds.

A box's recording and the recordings of each of its regions alone run one pipeline that writes
the same outputs. They differ only in their dynamic viewport and scissor values and the integer
region each draw selects (Vulkan's Invariance appendix, Rules 2 and 4). The agreement between the
encoder's region-copy vertex function and the host step's fan-out geometry stage stays the
existing FAST-PATHS known gap, checked by running: no new near-equivalent, no new accepted
difference.

SEMANTICS_VERSION 2115 (the variant's module and push layout); ARTIFACT_FORMAT_VERSION 523 (the
PushField tag); RUNTIME_VERSION 2315 (what a region-copy draw records). Docs: rate_mapped_pass.rs,
render/fan_out.rs, bind/fan_out.rs, the translator's region-copy plan and store, docs/API.md, and
the FAST-PATHS fan-out row and known gap. docs/REFUSALS.md regenerated unchanged; api_signatures
blessed. No new Degradation kind, no WorkCounts field.

Tests:
- render/fan_out/tests.rs: run boxes, box recordings, box scissors, the fold rule.
- tests::rate_mapped_region_boxes (device test): the same two passes drawn directly (boxes) and
  indirectly (one region a recording, its own scissor), additively blended into RGBA16Float with
  a ground plane, border-crossing slivers and off-screen and w-straddling triangles, then an
  Equal pass, compared bit for bit, with the recordings counted.

Verified (lane ratemap2):
- msi m3-max-30288 at 9240cc0ea6: clippy -D warnings, all targets and features, plain, cpu_icd
  and m2v_gpu, exit 0; rustdoc -D warnings exit 0; translator touched tests 226/226; runtime
  33/33; lavapipe 13/13.
  - rate_mapped_depth_equal: 0 failing pixels in every pairing under Exact and FanOut. Without
    the ViewportIndex store, FanOut's mixed-route pairings had 2853 of 89483 (m3-max-30235).
  - rate_mapped_region_boxes: direct 3 draws in 3 recordings against indirect 3 in 624, 0 texels
    differ, Equal-pass mismatches [0, 0].
- Negative control (each clip distance widened by one pixel): rate_mapped_region_boxes fails,
  25464 texels differ, Equal-pass mismatches [11019, 0].
- The Iris GPU-time A/B (ms01, m3-max-30315, exclusive) is running; the consumer's renderer run
  at the next pin is the workload proof (rate_map_piece_gpu_nanos a frame on Iris).

Landing note: docs/API.md merged by hand with RUNTIME 2314's probe-parts sentence (both rewrote one
paragraph), and rate_mapped_pass.rs's Fan-out now says the probe runs in parts (RUNTIME 2314).
2026-11-14 14:32:33 -08:00
Anees Iqbal 2960070096 SEMANTICS 2114 / RUNTIME 2307: write() through an argument buffer to a two-plane YCbCr texture stores or drops as the slot write does
An argument buffer's texture2d<float|half, write> of a two-plane YCbCr
texture died at dispatch (its storage heap member was refused). Metal
stores through a handle exactly what it stores through a slot (the M3
Max under macOS 27.0.1, measured by the consumer): nothing of
YCBCR8_420_2P, both planes of the unpacked 4:4:4 formats byte for byte
the slot's.

- bind::heap: a storage class holds a texture whose writes Metal drops
  (metal::format::writes_dropped) as its neutral (Fit::Dropped), and a
  4:4:4 texture whose writes Metal stores (ycbcr_writes_stored) through
  the R32G32B32A32_SFLOAT view of its write shadow; its table entry
  carries FLAG_YCBCR_WRITES (bit 15). A stage that reads the storage
  class (new RuntimeFact::HeapStorageReads, a PlanTimeCheck) refuses
  either texture it reaches there, Format / NotImplemented, as a slot
  that reads one is refused.
- memory::handles: the search carries the flag into handle bit 29
  (HANDLE_YCBCR_WRITES) under the stage's new SpecKey::HeapYCbCrWrites,
  a u32 constant the plan gives from the command's members (1 where a
  member it names is such a texture, usage writing). At 0 the carry
  mask, the element mask and the write's test are spec-constant
  folds, so a command naming no such texture runs the pipeline it ran
  before (the predicted bindings name none).
- lower::texture: a float/half 4-lane 2D heap write selects
  (rgb, 1.0) where the handle carries the flag: the mark the write-back
  kernel reads (nonzero), in place of any member conversion.
- runtime: the write shadow's image is MUTABLE_FORMAT with an
  R32G32B32A32_SFLOAT view where the device stores that format; the
  heap's float storage element is that view; a command making such a
  texture resident for writing names the shadow in its uses (its copies
  clear the marks and encode the marked texels into the planes), and
  the texture's own image only where it reads it too.

Tests: src/tests/engine_heap_ycbcr_writes.rs (interpreter run at the
constant's 0 and 1, plan values and one variant for every command
naming no shadowed texture, the storage-read refusal);
runtime_lane::ycbcr_argument_writes (500/503/507/523/527/542/545
through an argument buffer against the slot's bytes, and the pipeline
count). REFUSALS.md regenerated; api_signatures blessed: two new
variants of #[non_exhaustive] enums, nothing breaks for a consumer.

Metal (M3 Max, macOS 27.0.1, m3-max-29643): argument-buffer writes are byte-identical to slot writes
for 500/503/507/523/527.

Verified (msi lavapipe, --cfg m2v_cpu_icd): m3-max-29859 clippy translator/runtime/validation 0,
runtime 243/243, lavapipe lanes 75/75, translator 246/247 (a word bound the mark raised, fixed in
ce01da189e); m3-max-29865 at ce01da189e clippy 0, translator 4/4, lavapipe 2/2: argument-buffer
writes byte-equal to slot writes for all 7 formats (alpha-0 writes, so an unmarked write stores
nothing); pipelines 1 after RGBA8/RGBA16Float/500 commands, 2 after the first 503 and still 2
after a second.
2026-11-14 10:46:27 -08:00
Anees Iqbal 9fa1fe4a7a SEMANTICS 2113 / RUNTIME 2305: write() and render into the _sRGB two-plane 4:4:4 twins (523, 527) store what Metal stores
write() (kernel and fragment) into YCBCR8_444_2P_sRGB (523) and YCBCR10_444_2P_sRGB (527) over a
surface plane, and such a texture as a render attachment, were refused (the encoding unknown).
Metal's bytes, measured on an M3 Max (macOS 27.0.1; 8 colours, kernel write, fragment write and
Clear+Store over 444v/x444 surfaces), fit one reading exactly: each channel is sRGB-encoded first,
then converted as the non-sRGB twins 503/507 convert (here BT.601 video range). Metal's own paths
differ by one code on one 10-bit luma (kernel 696, pass 697).

- metal::format: ycbcr_writes_stored and ycbcr_renders take 523/527; the 4:2:0 and 4:2:2 sRGB
  twins stay refused (unmeasured).
- bind::ycbcr_write: one shape word, SRGB: per channel the pass's half (pass only), then
  lower::arith::pack::srgb_encode (the device's Pow), then the existing grid step and rows. The
  device's float curve is the conversion we implement (no sRGB view can store a matrix
  combination of encoded channels); no PrecisionNote: any difference is within Metal's own
  one-code spread.
- A pass that Loads a twin is refused at its start, and a pipeline that blends into one at its
  attachment, both NotImplemented(Format) (Metal's load and blend of the twins unmeasured).
  REFUSALS.md regenerated (Format sites 124 -> 125).
- CPU references ycbcr_write/ycbcr_store encode the twins by the same f32 steps.

Verified (msi, lavapipe, m3-max-29687 at db17bcce16): clippy (metal2vulkan, runtime, validation,
--cfg m2v_cpu_icd) 0; translator tests 13/13 (reference and interpreter give Metal's eight
colours for 523/527); lavapipe 14/14 (lane ycbcr_srgb_twins: both planes against Metal's table
for kernel, fragment and Clear+Store, one code allowed on the 10-bit luma only; load and blend
refusals; the 503/507/542/545 tests unchanged). Negative control (SRGB word forced to 0,
m3-max-29701): the CPU test and the kernel, fragment and pass tests fail on grey,
(0.2,0.6,0.9) and (0.9,0.3,0.1).
2026-11-14 09:51:17 -08:00
Anees Iqbal be62103f73 One state lock per encoder open and one per end
A compute encoder opened after another took its command buffer's state lock
7 times as it opened and 3 times as it ended (a debug count on lavapipe):
the protection check, settle_end's three takes, the open itself,
enter_predication and inherited_residency; end_predication,
note_scheduled_work and the end itself. About 17 ns each under perf, 118 ns
of a folded dispatch's open and 55 of its end on msi.

- EncoderCore::open checks the protection options (compute and render),
  settles the last render encoder's end where one waits (CommandBuffer::
  settled: the three takes only where something is there, else the lock it
  holds), and runs the kind's own state work as a closure under its lock:
  compute's enter_predication and State::inheriting, blit's protection
  options.
- end_with_replay notes the scheduled work and, for a compute encoder whose
  command buffer has no predication record, its unit's work under its own
  lock. Captures::unpredicated tracks that: false at open where the command
  buffer has a record, cleared by the encoder's own record, false for an
  encoding again, so those keep end_predication's lock.

Tests: tests::encoder_state_locks (debug, device): a compute encoder and a
blit encoder opened after a compute encoder lock once at open and once at
end.

No behaviour changes (what a run answers, records and submits is the same), so RUNTIME_VERSION
stays 2304 and the runtime-sources pin alone moves.

Verified (msi, lavapipe): tests::encoder_state_locks 1 lock at open and 1 at end for compute and
blit (negative control with the base sources: compute 7/3, blit 5/2); touched runtime suites
156/156 (render_fold 13, encoder_fold 22, ...); validation predication and protection_options
18/18; clippy plain, m2v_gpu and m2v_cpu_icd 0; rustdoc 0. Release A/B (base 0c3c24ec0e vs
tip, own target dirs, medians of 4 interleaved): host time per dispatch within the run's noise
(about 200 ns): long folded encode 4246 -> 4303, short folded 4122 -> 4018. Kept as a
correct, neutral change.
2026-11-14 09:39:37 -08:00
Anees Iqbal 76855fc0ba SEMANTICS_VERSION 2106, ARTIFACT_FORMAT_VERSION 522, RUNTIME_VERSION 2256: GPU-written indirect command buffers that inherit the encoder's buffers run on the GPU; write routes reach the indirect command buffers of their own command kind
A GPU-encoded indirect command buffer whose records inherit the encoder's buffers took the host
step: the render GPU form refused inherit_buffers (DrawReplayRule::InheritedBuffers) and the compute
GPU form had no inherited-bytes path, so every frame read the records back and replayed them on the
host (gameload's icb: 8,192 indexed draws, ~44 ms of host step a frame on the Iris against 0.29 ms
natively).

- Render (da75a4602f..f3745fd69c): a draw replay's variant takes the encoder's vertex and fragment
  buffers by index as its parent buffers, resolved to device addresses past the parent's record;
  inline bytes (set*Bytes) are planned at their slots; an unaddressed inherited buffer keeps the
  host step with its cause named (parent_entries refuses it rather than writing a zero entry). The
  executor's draw preprocess binds the encoder's vertex buffers.
- Compute (7c148c3995..0a68ac5f15): a GPU-written buffer of dispatches that inherits the encoder's
  kernel buffers runs on the GPU the same way; the new fixture icb_inherited_dispatches (our MSL) and
  its golden.
- Route kinds (2d9f4ac597..2e206952c2): every route of a command buffer joined every indirect command
  buffer it made resident for writing, so a compute ICB's writer (DISPATCH|RESET) refused the render
  ICB's GPU form in the same command buffer (DrawReplayRule::Operations): gameload -b's render ICB
  host-stepped although nothing refused its own shape. A write route now reaches only the ICBs of its
  command kind (render or compute); CommandWrites carries the kinds (ARTIFACT_FORMAT 522).
- host-replayed-indirect-commands is announced once per cause instead of once per device
  (a660b2fe8d), naming the rule that keeps a pass from the GPU form, as copied-host-pages announces
  per reason; no new Degradation kind or WorkCounts field.

Verified on the branch (steelbrain/icbinherit2 at a660b2fe8d): clippy plain, m2v_gpu and
m2v_cpu_icd and rustdoc exit 0 (27886); runtime suite 1538/1539, the one failure the catalogue text
RUNTIME 2253 already fixed on development (27884); lavapipe ICB and notice lanes 214/219 with
render_inherited_buffers, compute_inherited_buffers, write_routes, written_commands and the
beside test (inherited and own buffers: cold (8,8,0), warm (8,8,0,0), pixels as alone) passing, the
5 failures failing the same at the branch's base (27926, 27927); before route kinds the beside
test fails as designed, (0,0,8) against (8,8,0) (27764); XTX 90/101 at 60c85035e3 (27853), the 11
failures fixture paths under msi's compile-time path only, all 11 passing on lavapipe (27807).
2026-11-13 20:11:00 -08:00
Anees Iqbal 1cf0e1910d RUNTIME 2255: cubes and BC rows over an IOSurface plane are made where the x86 Macs make them
reims's oracle_surftex found the Radeon Pro 5300M and the UHD 630 making three IOSurface-plane
shapes that the runtime refused:
- a Cube and a CubeArray over a plane of a surface with planes (cases 119, 188-191). These were
  refused as Metal's own Invalid; the M3 Max asserts "carriesComplexTexture || numFaces == 1", the
  arm64 envelope.
- BC1 64x64 over a 420v luma plane, whose rows of blocks are wider than the plane's row (case 187).
  This was refused as NotImplemented(SurfacePlaneShape); the M3 answers nil.
An x86 guest was answered "made" while the host held no object for it. The x86 envelope is the x86
Macs', and they agree, so the runtime now makes them as those Macs lay them out. Measured with
surface_texture_envelope on both x86 GPUs (m3-max-27621, -27622).

Cubes: face k lies at the plane's offset + k x rows x bytesPerRow, rows bytesPerRow apart. The
planner (linear_plan.rs, faces_at_pitch) lays a colour cube or cube array over a plane, at an offset
and bytesPerRow that are multiples of 16, as a 2D array of its faces at that pitch, for the GPU
and the CPU alike. Faces past the buffer go in the texture's tail, announced as SurfaceTexelsTail,
as a 2D array's texels past it do. The image is cube-compatible, as every cube's is. Every other
cube over such a plane (another format, off 16, several levels, rows wider than the plane's) is
NotImplemented(SurfacePlaneShape) instead of Invalid. Over a surface without planes it stays
BufferTextureProblem::TextureType. The CPUs differ: the 5300M's getBytes and replaceRegion take
every face at the first's bytes, and the 630's take them one image on from the surface's byte 0.
The runtime's CPU calls take the GPUs' layout.

BC rows of 8-byte blocks wider than the plane's row keep to it, as the x86 Macs' blits do: the
blocks in the plane's row lie in place; the blocks past it read zero and their writes are dropped.
There is no tail storage: the shadow zeroes them at its first move, and blits, replace_region and
get_bytes clip to the kept columns. InPlaceRefusal::Rows's doc now also covers rows that hold fewer
of a BC texture's blocks than its row. No Degradation kind and no public item were added. docs/API.md
records two accepted differences: the CPU calls follow the GPUs' layout, and a cube's faces past
the plane's rows lie at the plane's pitch. linear_plan.rs, the RuntimeGap and BufferTextureProblem
docs, FAST-PATHS known gaps and REFUSALS.md (regenerated) are updated.

Verified (planerows, 97de630b9f on 4e694366cc, msi):
- lavapipe (m3-max-27711): 27/27, SURFACE_SHAPES_LVP_EXIT=0. Every surface shape, over Shared and
  over host pages, reads 0 wrong: 119/188/189/190/191, the four probe cube shapes, 187
  (420v.p0.fmt.bc1) and 420v.p0.bc1.32x64. The validation layer reported nothing.
- Planner unit tests (27659): 26/26.
- clippy m2v_gpu 0 (27721), m2v_cpu_icd 0 (27722), plain 0 (27724); runtime rustdoc 0.
- Owed: the XTX leg (27731, queued).

RUNTIME_VERSION 2254 -> 2255.
2026-11-13 19:19:09 -08:00
Anees Iqbal 2bd067d6c7 RUNTIME 2254: a command buffer's completion exports as a SYNC_FD sync file
A consumer that composites one GPU's frames on another vendor's GPU has to order the second
device's work after a runtime command buffer. The only semaphore export was
SharedEvent::export_semaphore_fd: a timeline semaphore as OPAQUE_FD, which Vulkan imports only on a
device with the same deviceUUID and driverUUID, so it cannot cross from NVIDIA to RADV. The consumer
waited on the CPU instead, about 3.5 ms a present on its window thread. A cross-driver handle needs
SYNC_FD, which only binary semaphores export.

New (unix only, no Metal counterpart):
- CommandBuffer::add_completion_sync_file(), before the commit: the command buffer's last batch
  also signals a binary semaphore exportable as SYNC_FD, after its to-host barrier. That batch never
  joins a submission group. A command buffer with no GPU work submits the signal alone, after its
  queue's earlier work.
- CommandBuffer::export_completion_sync_file() -> Result<Option<OwnedFd>, Error>, after the
  commit. It blocks only until the signalling batch's vkQueueSubmit has returned, never on the GPU.
  None means the work already ended, or the driver answered -1; the importer imports -1 or skips
  the wait.
- Spec: the export follows the signal's submission (VUID-03254), with copy transference. One export
  per command buffer. Event::reserve_vk_signal's doc carries the contract for a reserved signal
  that the batch waits on.
- The semaphore goes back to an idle pool of up to 8 per device once the command buffer completes
  with its fd exported, and is released otherwise.

Where the host writes the caller's pages after the GPU work (a copied host buffer's merge back, or a
managed two-copy buffer's copy-out), no GPU signal can come after those writes. There the export
waits for completion and answers None, announced by a NEW Degradation: SyncFileAfterHostCopies
(sync-file-after-host-copies, performance). Also new: WorkCounts::sync_files_exported and
sync_files_after_host_copies; RuntimeGap::SyncFileExport, for a device without
VK_KHR_external_semaphore_fd or without binary SYNC_FD export (MoltenVK, an adopted device without
the extension); Problem::SyncFile(SyncFileProblem { Committed, NotCommitted, Exported }).
docs/API.md (catalogue entry), the runtime README, REFUSALS.md (regenerated), the reach table and
api_signatures are updated.

Verified (syncfile, 8f9caba0ae on d72dc03519, msi):
- Runtime suite: 1538 passed, 6 skipped (27758).
- tests::sync_file on lavapipe (27733). llvmpipe exports and imports SYNC_FD. The no-copy buffer
  was imported by pointer. A second VkDevice imported the fd and read every byte filled. The export
  came while the status was Scheduled.
- The lane test a_sync_file_after_host_copies_waits_for_them_announced (27759): the export over a
  copied buffer's merge back waited, the pages held the fill, and the kind was announced once and
  counted.
- clippy plain, m2v_cpu_icd and m2v_gpu 0 (27709, 27737, 27760); rustdoc 0 (27730).
- Owed: the cross-vendor run on um790, the 2080 writing and an XTX VkDevice importing (27739,
  queued).

RUNTIME_VERSION 2253 -> 2254.
2026-11-13 19:06:19 -08:00
Anees Iqbal 7e827c1b5e RUNTIME 2251: a two-plane YCbCr texture over IOSurface rows of codes that overlap is made, as Metal makes it
A two-plane YCbCr texture can sit over a plane of a surface with planes whose rows of codes are
wider than the planes' bytesPerRow (a texture wider than its plane, or a 10-bit format over 8-bit
rows). Metal makes it. The runtime refused it at creation: linear_plan's overlap_held answered
NotImplemented(OverlappingSurfaceRows), and the guest got nil. An arm64 guest's oracle run met
one: YCBCR8_420_2P 66x64 over plane 0 of a 64x64 '420v' (luma rows of 64 bytes).

Such a texture's texels are its conversion of the planes' bytes (ycbcr.rs), which reads every code
at the planes' rows, so rows that share bytes need no row rule. The refusal was written for a
plain plane's two-region shadow copies, which a converted texture never uses. overlap_held now
holds a two-plane YCbCr texture over a plane of a surface with planes, whatever its usage.

Still refused, now at use and with the precise gap NotImplemented(OverlappingSurfaceRows) (was
NotImplemented(Format)):
- a blit from a buffer into such a texture: Metal leaves no single row's bytes there (the
  earlier row's at every shared byte of the 8-bit shape; 2047, then 1919, of 4032 for the 10-bit
  one);
- a 4:4:4 texture's stored writes;
- a render pass whose rows of codes overlap (unmeasured).

Over a surface without planes it stays refused at creation (unmeasured). docs/FAST-PATHS.md's
known gaps, the RuntimeGap doc and REFUSALS.md (regenerated) say so. No Degradation kind, no public
item.

Metal's answer (probes/ycbcr_wide_code_rows.m, m3-max-27270, macOS 27.0.1, two processes a shape),
for the 66x64 8-bit shape and a 64x64 10-bit one:
- read() and the nearest sample of every texel equal the same texture over the same bytes laid
  apart, bit for bit (0 of 4224 and 0 of 4096 texels differ);
- getBytes reads the luma rows at the pitch;
- replaceRegion writes them in order, the later row standing.

Verified (planerows, 5fdbf147d5 on 90ced1544a):
- lavapipe lane (27310): 6/6, including the new
  ycbcr_textures_whose_rows_of_codes_overlap_read_what_metal_reads.
- runtime tests::linear_plan (27319): 25/25, including the new
  a_two_plane_ycbcr_texture_whose_rows_of_codes_overlap_is_held_over_a_plane.
- clippy plain 0 (27348), m2v_cpu_icd 0 (27382, after the type_complexity fix); rustdoc 0 (27349).
- The XTX lane run and clippy m2v_gpu are queued (27440/27441/27472).

RUNTIME_VERSION 2250 -> 2251.
2026-11-13 17:31:50 -08:00
Anees Iqbal 977c9da12f RUNTIME 2246: setTriangleFillMode: 2 (MTLTriangleFillModePoints, Apple-private) draws a triangle's vertices as points
Apple's GL renderer sends setTriangleFillMode:2 for glPolygonMode(GL_POINT) under its Intel and
Apple-silicon caps tables. The value is not in the public headers. Our TriangleFillMode had only
Fill and Lines, so the consumer's raw-value conversion failed and its host died. Measured on
Metal: an M3 Max and an Intel UHD 630 draw only a triangle's 3 vertex pixels (a Radeon Pro 5300M
fills it); our own probe on the M3 (m3-max-26811) draws 1-px points whether point_size is 4, 1 or
unwritten, culls them with CullMode Front, and draws them with Back.

Now TriangleFillMode::Points (2) exists. The generator (scripts/regen-metal-enums) takes a
PRIVATE line for it, with its evidence, and a PRIVATE_DOCS doc comment (metal_enum! accepts
variant attributes); generated.rs stays generated and `--check` passes. The runtime draws it as
VK_POLYGON_MODE_POINT. It needs fillModeNonSolid (refused otherwise:
Feature::TriangleFillPoints) and, on a portability-subset device, pointPolygons
(VkFeature::PointPolygons; MoltenVK withholds it, so it refuses Points). New degradation
TrianglePointSize ("triangle-point-size"): Vulkan sizes the points by the PointSize the vertex
function writes, where Metal draws 1 px. An ICB command still refuses set_triangle_fill_mode, as
before. New lane module runtime_lane::triangle_points.

Verified (fillpoints, 6b9927c402 on 25be73dddf):
- lavapipe lane 30/30: points light {(3,3),(3,12),(12,3)} (Metal's 3 vertex pixels); culled
  front none, back the same 3; fill 45 px (the M3 lit 45); lines 27; fill/lines unchanged.
- msi: clippy plain, m2v_gpu and m2v_cpu_icd 0; rustdoc 0; touched tests 102/102.
- Owed: the XTX leg (m3-max-26943).

ARTIFACT_FORMAT_VERSION 519 -> 520 (VkFeature appended to the codec), RUNTIME_VERSION 2245 -> 2246.
2026-11-13 15:26:44 -08:00
Anees Iqbal b741f93b9e SEMANTICS 2098 / RUNTIME 2244: a rate-mapped pass's region-by-region draws copy each region in the vertex function, scissored, so Equal depth matches the fanned-out route
Under RateMapRegionPolicy::FanOut a draw was drawn two ways: fanned out (a geometry stage's copy
of each triangle per region, window position a*x + b*w through one viewport), or region by region
(each region through its own Vulkan viewport). The two rounded a vertex's window position
differently, so a pass testing depth Equal against depth the other route stored failed along whole
surfaces: the consumer's black blotches on lit surfaces in Apple's Modern Rendering sample on the
RTX 3090. The depth-Equal repro left 44,666 of 89,483 pixels red on lavapipe whenever the prepass
and the Equal pass took different routes; 0 under Exact or on one route.

Now on a fanning device the region-by-region draws take a region-copy variant
(RegionFanOut::RegionCopies), with no geometry stage. Its vertex function computes region
RegionFirst + DrawIndex of the table, stores its position through the region's line and four clip
distances by the one emitter the fan-out stage's copies use (pipeline::link::fan_out::region_copy:
NoContraction arithmetic, Position and ClipDistance Invariant), and its draw index as
ViewportIndex. Each recording sets as many viewports as one multi-draw takes, every one the
fan-out's over the render area, with each region's scissor at its index (bind::fan_out::scissors),
so off-region triangles are scissored, not clipped. The settle keys the pipeline with the same
viewport count (fan_out::copy_viewports). The variant replaces the regions variant, so no pipeline
is added per state. A device without multiViewport, shaderOutputViewportIndex and
shaderDrawParameters keeps the per-region-viewport route (FAST-PATHS known gap). Exact is
untouched. New: bind::fan_out::scissors, WorkCounts::rate_map_region_copy_draws and
rate_map_region_copy_recordings, PushField::RegionFirst; cache codec variants (artifact format).

Verified (blotch, steelbrain/blotch 1fd68a45c0..16d5c2404f):
- lavapipe at 16d5c2404f: rate_mapped_depth_equal + rate_mapped_fan_out 4/4, 0 red in all 10
  depth-Equal lines (mixed pairs included), 0 pipelines made at the host step; clippy CPUICD,
  GPU and plain 0; rustdoc 0. Translator suite at 8ad673ffba 3562/3563, the one failure
  golden_hashes (re-blessed on development).
- 780M and XTX at 8ad673ffba (differs from the tip by the settle fix only): 0 red in all 10
  lines. E->E GPU cold/warm: 780M 4.99/4.97 ms against Exact 1.68/1.65; XTX 1.14 ms/650 us
  against 569/265 us. Creation (shader cache off): 780M 1.32 ms/state (Exact 0.92), XTX 1.30
  (Exact 0.68).
- Owed: the same numbers at development's tip without this change (the GS fan-out), the
  clip-distance probe, and the 780M/XTX runs at 16d5c2404f.

SEMANTICS_VERSION 2097 -> 2098, ARTIFACT_FORMAT_VERSION 518 -> 519, RUNTIME_VERSION 2243 -> 2244.
2026-11-13 14:52:26 -08:00
Anees Iqbal 20d04dbd5e RUNTIME 2242: an ICB's setters write through one batch, mostly without the lock; set_render_command and set_compute_command
An indirect command buffer's CPU setters, after RUNTIME 2238's dense table and one hold: every
setter write now goes through one per-command batch (one storage pointer, one count of the writes
made without the lock), written into in place rather than handing back a ~180-byte plan (which
made a first form slower than before). The written flag (SEMANTICS 2097) is set in the one write
helper, write_field, by the rule unchanged: every setter write sets it, a write of the reset
record clears it. A draw, a dispatch, a set barrier and a cleared barrier the edits' summary
already holds, like a buffer slot before, take no lock where the GPU may not have written the
buffer, checked against an atomic mirror of the summary set under the lock; a pipeline state the
command already names is set again with no lock and no CallHold (an atomic (id, serial, kind)
mirror per command; a recovery's carry forgets it, so the next set redoes every check). New
public calls IndirectCommandBuffer::set_render_command / set_compute_command (an index and a list
of sets, no handle and no Arc clone; index and kind refusals at place 0) and the handle's
set_each; borrowed RenderAt/ComputeAt views. docs/API.md says which setter writes take no lock;
the carry docs say a write made without the lock does not wait for a carry (as buffer slots'
did; a set racing a device recovery may write through the old mapping).

Verified (icbset, f403b6e922 on 33de04117d), ns a command, median, 16384 commands, msi lavapipe
(26658, two passes), development e93b3f192e -> tip: full render slot 142.6/147.6 -> 100.7/100.1;
compute slot 119.3/123.0 -> 77.5/77.5; three fields 77.1/78.8 -> 71.8/71.9; draw only 43.5/43.9 ->
34.0/34.0; set_render_command 94.7, set_compute_command 78.9. 780M (26754, 256 commands): full
slot 154.3/167.7 -> 111.0/117.0, compute 123.3/122.7 -> 93.1/87.8. lavapipe ICB set 154/154,
including a test of which way each write went and set_each/set_render_command against one setter
at a time; negative control (a whole-record read-modify-write in write_field) fails the
strengthened two-thread test (26658). 780M: the 6 ICB device tests and set_states pass. clippy
plain / --cfg m2v_gpu / --cfg m2v_cpu_icd and rustdoc 0 (26682, 26756).

RUNTIME_VERSION 2241 -> 2242.
2026-11-13 14:24:31 -08:00
Anees Iqbal 4383b55aed SEMANTICS 2096: ANV: a stage heavier than the largest measured to compile in host-sized memory is refused, or keeps the widest pin
ANV's compiler takes memory that grows faster than the stage it compiles, inside the process that
creates the pipeline, well below the 2^20-object bound the serialized stage already keeps under.
Measured on the Iris Xe of RPL-P (Mesa 26.2.6), compute modules created cold through
vkCreateComputePipelines, the resident set sampled every second (job m3-max-26147): entry weights
73,814, 75,886 and 99,109 were created in 45 s, 47 s and 132 s at peaks of 1.76, 2.24 and
3.65 GiB; a module of entry weight 532,213 passed 16 GiB at 358 s without finishing. Job
m3-max-26086: a module of entry weight 796,525, its heap raw-texture arms dead, passed 20 GiB in
under two minutes. Both under the old bound (786,432) would have been handed to the driver: one
pipeline creation that can take a host's memory.

- DriverWorkaround::CompilerMemoryGrowsWithStageSize, keyed on ANV whatever its GPU and release
  (device::derive), documented with those points.
- stage_bound: StageBounds holds both bounds (SERIALIZED_STAGE_WEIGHT 786,432;
  COMPILED_STAGE_WEIGHT 99,109, the largest measured to compile, no margin below it as nothing
  above it is measured to compile). emit keeps a module under every bound its profile's defects
  set, with the same widest-pin retry; a refusal (StageSize, DriverDefect) names the serialized
  stage's defect past 786,432 and the compiler's memory below it. The bound rises when a larger
  compile is measured within host-sized memory.
- The test hooks (compile_bitcode_bounded, compile_stage_bounded) take StageBounds.

Docs: stage_bound's module docs and FAST-PATHS' known-gaps entry state both bounds with the
measured points only (weights, never names), and restate the serialized bound's figures in
entry_weight's units: the faulting stage 1,603,989 (0.683 objects per unit, was 1,565,083 and
0.70 by a count 2.4% lower), the other 21 stages' ratios as counted by that count, which ran 1.9
to 2.7% below entry_weight on the five modules both counted; the shader-object figure likewise
1,603,989. Feature::StageSize's docs and its reach line cover the memory bound; REFUSALS.md
regenerated. api_signatures.tsv blessed with the new variant (the bless also moves
scheduler_slice_rescues to the script's own order).

For a consumer on ANV: a module of entry weight past 99,109 and up to 786,432 that was handed to
the driver is now refused (Unsupported, Feature::StageSize,
Needs::DriverDefect(CompilerMemoryGrowsWithStageSize)) unless its pinned plan fits. Other drivers
are unchanged.

Tests:
- engine_simd_lockstep::a_kernel_past_the_stage_bound_keeps_the_widest_pin_or_is_refused covers
  both defects: for each, under a bound the emulated module passes the kernel is planned again
  pinned (exact at 32 lanes), under one its pinned module passes too it is refused naming that
  defect, and past both the serialized stage's defect is named; RADV emits under every bound.
- engine_simd_lockstep::a_kernel_past_the_stage_bound_gets_one_answer_through_either_path on the
  serialized bound through StageBounds.
- device::tests::profile::large_module_defects_are_keyed_on_anv includes the new workaround.

Verified, on msi, read from inside each job:
- m3-max-26184 (this change on 86d362e2aa): cargo fmt --check 0; clippy --workspace
  --all-targets --all-features -D warnings 0; clippy -p metal2vulkan --no-default-features 0;
  clippy with --cfg m2v_gpu (all features) 0; nextest over device::tests, engine_simd_lockstep,
  fast_paths and the refusal_surface, api_signatures, api_surface and feature_vocabulary
  binaries: 189 run, 189 passed.
- m3-max-26212: the stage-bound test with its output shown passed with no SKIPPED line; the
  negative control, the compiled bound's cap set past every module, fails it ("left: Emulated,
  right: Direct" for CompilerMemoryGrowsWithStageSize).

SEMANTICS_VERSION 2095 -> 2096: on ANV a module of entry weight above 99,109 (and up to 786,432) is now
refused or re-planned with the widest pin kept, where it was handed to the driver.
2026-11-13 11:45:50 -08:00
Anees Iqbal a2ac4433ca SEMANTICS 2094: One input, one answer: a compile past the stage bound is charged once, by either path
A kernel planned again past the stage bound (stage_bound::emit, WidestPin::Kept) ran plan_one a
second time: decode, specialization, lockstep order, lowering inputs and memory analysis, all
charged to the meter again. And Device::compile_function_from_entries charged nothing for an entry
a creation had already specialized (StageEntries handed out an uncharged copy). So one input got
two answers under one budget: compiled alone, a large kernel past the bound on the Iris Xe was
refused LimitExceeded(WorkUnits); compiled from a creation's entries, Unsupported(StageSize).

- stage_bound::emit analyzes the entry once (analyze_one, the part of plan_one before selection,
  kept as Analyzed) and only selects, emits and rolls again. What the dropped plan and module hold
  of the ledger is released, measured from before the selection.
- Meter::measured runs work and states what it charged (Spent: work units, its ledger peak above
  where it began, the bytes it still holds); Meter::spend charges that to another meter, work units
  first, then the peak, keeping the held bytes.
- StageEntries keeps each entry's, decode's and plain answer's Spent and charges it to every ask
  that finds them, so a found entry costs what making it cost. The object spares time, never
  budget: compile_function_from_entries charges what compile_function charges, unit for unit.

For a consumer: Spent, Meter::measured and Meter::spend are new public items of
metal2vulkan-air's budget module (api_signatures.tsv blessed); nothing was removed. A creation
that shares a StageEntries is now charged its found entries' work units against each compile's
budget, as a compile that shares nothing always was.

Tests:
- budget: spent_work_charges_another_meter_as_the_work_did (work, ledger and peak equal to the
  work itself; refused alike one unit under either cap).
- engine_simd_lockstep: a_kernel_past_the_stage_bound_gets_one_answer_through_either_path. The
  pressured kernel under a bound its emulated module passes (planned again, Direct) and under one
  its pinned module passes too (StageSize): alone, from entries that make the entry and from
  entries that find it, the same answer and the same work units W; at exactly W both paths answer
  the bound's way, at W - 1 both are refused WorkUnits; the negative control, a meter also charged
  one more plan of the entry (what the plan made again used to charge), is refused WorkUnits at W.
- library_entries_decode_once, stage_input_siblings: the work units through a shared decode or
  entry now equal the unshared compile's (they asserted fewer before); the decode counts still
  show the sharing.

Also in this commit: crates/metal2vulkan-air/tests/api_surface.txt gains the four rate-map items
b31ce16c85 made public and left out of it (canon::rate_map_data BOUNDARY_MASK, GRANULE_SHIFT,
shader_physical_to_screen_integer, shader_screen_to_physical_integer): the_table_matches_the_source
failed on development without them, the same four lines at d5620581d5 (job m3-max-26042).

Verified, on msi, read from inside each job:
- m3-max-25972 (21ff252584, this change on d5620581d5 before the surface lines): cargo clippy
  --workspace --all-targets --all-features -D warnings exit 0; cargo nextest -p metal2vulkan
  -p metal2vulkan-air -p metal2vulkan-runtime --all-features: 5,645 run, 5,643 passed, 2 failed:
  metal2vulkan-air::api_surface (the four rate-map lines above, failing alike at the base) and
  golden_hashes_match_the_table.
- m3-max-26018: golden_hashes_match_the_table lists 360 changed cells at this change and 360 at
  d5620581d5, the same cells line for line, 180 in each of the nvidia-rtx50-linux and
  nvidia-rtx5080-laptop columns: development's own pending re-bless, none of this change's.
- m3-max-26001: budget::tests::spent_work_charges_another_meter_as_the_work_did passed.

Not landed beside it: the handle-table search as a loop (memory::handles::define_lookup), measured
and dropped. On the RX 7900 XTX (RADV, release, shader cache off), a synthetic kernel of 1,408
heap handle loads: the loop cut cold creation from 224.6 ms to 129.4 ms and the driver's code from
24,512 instructions (118,512 bytes, 28 spilled SGPRs) to 15,441 (78,004 bytes, 11), but a kernel
of 64 handle loads a thread over 2^20 threads took 33 to 38% more GPU time (median of 20 runs,
two rounds: 0.604 and 0.625 ms against 0.829 and 0.832 at 65 resident textures; 0.666 and 0.644
against 0.883 and 0.866 at 4,097). Creation is paid once and cached; the GPU time on every
lookup-heavy dispatch. The unrolled search stays.

Correction to c53ea4164e's message: its "reproduced ... with a synthetic 360k-FMA chain" was wrong.
That chain faults on another ANV defect, through a pipeline and through a shader object alike
(job m3-max-25842), so it is no reproduction of the serialized-index wrap.

SEMANTICS_VERSION 2093 -> 2094: an input near the work budget past the stage bound now gets the
bound's answer where it was refused at the work cap, so cached LimitExceeded(WorkUnits) refusals
must be recomputed. Landed before its own check (m3-max-26047) reported.
2026-11-13 10:36:44 -08:00
Anees Iqbal c53ea4164e SEMANTICS 2091: on ANV, a stage past the serialized-object bound keeps the widest pin or is refused
Mesa's common pipeline runtime (vk_pipeline.c) serializes every compute stage into a precompiled
shader and reads it back before compiling it. nir_serialize names each object by a 20-bit index
(MAX_OBJECT_IDS 1<<20) checked only by an assert, so a release build wraps past 2^20 objects and
the driver faults inside vkCreateComputePipelines. On Intel Iris this took a consumer's host
process down on a large compute kernel (its translated stage: idx_table_len 1,096,128).

DriverWorkaround::SerializedStageWrapsLargeModules (keyed on ANV) bounds the stage's weight at
SERIALIZED_STAGE_WEIGHT = 786,432 instructions, every call counted as its callee's body. A module
over the bound is never handed to the driver: a kernel that emulated its simdgroups only in place
of the widest mode's pin compiles pinned to 32 lanes again (lower::simd::WidestPin::Kept), and any
other is refused as Unsupported::driver_defect(Feature::StageSize, ..), where Metal compiles it.
The gap is recorded in docs/FAST-PATHS.md's known gaps; REFUSALS regenerated, reach.tsv marks
StageSize rare, api_signatures carries the two new variants.

The bound's basis: 22 stages measured at 0.14-0.99 serialized objects per weight unit; 786,432 is
3/4 of 2^20 at the worst measured ratio of about 1.

Verified: the crash reproduced live on ms01's Iris (job 25723) with both the consumer kernel and a
synthetic 360k-FMA chain; test
a_kernel_past_the_stage_bound_keeps_the_widest_pin_or_is_refused; checks job 25736 (msi): clippy
on the workspace, rustdoc, the full metal2vulkan suite, green. Not yet verified: the consumer's
Iris run at the next pin.

SEMANTICS_VERSION 2090 -> 2091: translator output and refusals change on ANV.
2026-11-13 09:05:44 -08:00
Anees Iqbal b31ce16c85 The uint2 rasterization-rate map overloads compile to Metal's decoder
A fragment shader's map_screen_to_physical_coordinates and
map_physical_to_screen_coordinates with uint2 arguments were refused
(Unsupported{RasterizationRateMap, NotImplemented} at the lowering of
Fragment::MapCoordinates). Canon now expands them beside the float2
overloads, reusing the float2 decoder:

- screen to physical: the float2 decoder at the pixel's centre (c + 1/2),
  converted to uint saturating (a NaN to 0), the conversion the float2
  index path already uses;
- physical to screen: the bits of the float (0 - offset) * reciprocal of
  the entry of granule c >> 5 on the axis's to-screen table; the
  coordinate's value within the granule is not read.

Both are Metal's answers as our probe rate_map_integer_overloads measured
them on an Apple M3 Max under macOS 27.0.1: 20,114 coordinates over four
maps (one of two layers), at each map's layers and two past them, every
one equal to these formulas. The arithmetic is float and the device's own
(owner rule 1); where a device's denormals differ from Metal's flushed
ones the existing PrecisionNote::DeviceDenormals reading applies, as for
the float2 decoder. The boundary byte of a table entry is compared on its
low seven bits, as Metal's decoder does (the probe's maps hit an entry
with the high bit set).

The decoder's Rust models gain shader_screen_to_physical_integer and
shader_physical_to_screen_integer. Lowering's MapCoordinates arm is now an
invariant error: canon compiles every overload before lowering.

Tests:
- bind::rate_map::apple_tests::metals_integer_answers: 1,561 of the M3's
  answers (apple_integer_vectors.txt: Metal's answers to our probe on our
  maps, no Apple binary) against the Rust models, each map's bytes
  checked by sha-256;
- tests::engine_rate_map::integer: the fixture rate_map_integer (kernel
  and fragment) compiles on every tested profile, robust and not, passes
  L3 with no RasterizationRateMap note; the interpreter's answers equal
  the decoder's arithmetic at every layer and two past, and Metal's on a
  map's own layers; and the translated kernel's answers equal the M3's
  recorded ones at all 587 recorded points of the maps' own layers, bit
  for bit;
- the fixture's four expectation rows go from the refusal to ok on all
  profiles; integer_rasterization_rate_maps_are_refused is removed.

docs/REFUSALS.md regenerated: the fragment select site leaves the
RasterizationRateMap sites.
2026-11-13 08:31:52 -08:00
Anees Iqbal 76f5b1b53f SEMANTICS_VERSION 2088: a loop's AIR unroll request reaches its OpLoopMerge
The two commits before this one carry a loop's llvm.loop unroll metadata from the AIR latch to
its SPIR-V OpLoopMerge: unroll.full and unroll.enable ask Unroll (clang's enable: fully where the
trip count is known, partly otherwise, SPIR-V's "to the degree possible"), unroll.count N asks
PartialCount N (SPIRV_VERSION 1.5 has it, held by a const assertion), unroll.disable asks
DontUnroll, and a count of 0 or no request asks nothing. Metal's compiler honours the same
requests; until now every OpLoopMerge carried None. It changes no answer, so it is not a
speed-for-accuracy choice. Translator output changes (SEMANTICS). docs/REFUSALS.md follows a
renamed site (structure_loops).

Verified by imgleak's runs: engine_loop_unrolling, one test per form (5/5 at ba2b803e57, 25358);
negative control with e7ea80f1bb's lower/view.rs, so no request is read: the four form tests fail
(unroll_count [[0]] where [[256, 4]] is expected), the no-request test passes (25376). Before the
rebase, clippy -p metal2vulkan all targets and features clean and 585/586 touched tests, the one
failure golden_hashes on kernel_threadgroup_float_bbox_atomics (unroll(disable)) and
engine/hnq_half_layer_composite (#pragma unroll), re-blessed at the next pin (25343).
Cold creation (driver caches off) and GPU time of the SR conv kernel 199ed, read in place on
um790, base b4a3e4e91c -> nuw e7ea80f1bb -> unroll (25521-25523): RTX 2080 creation 0.076 ->
0.083 -> 0.448 s, GPU 119.8 -> 120.3 -> 6.46 ms a dispatch (binary 23936 -> 106368 B); RX 7900
XTX 0.021 -> 0.116 -> 0.044 s, 12.7 -> 0.72 -> 0.71 ms; Radeon 780M 0.019 -> 0.043 -> 0.042 s,
over 6 s -> 6.08 -> 6.04 ms. On the 2080 the hint costs 0.37 s of cold creation once and saves
113 ms a dispatch; on the AMD devices it keeps nuw's creation and cuts code 15404 -> 12448 B.
Authored fixtures on all three: creation within run-to-run noise.
2026-11-13 08:09:54 -08:00
Anees Iqbal 10f2539a71 8-bit floats widen through the device's own type where it has one
Owner rule 1: where a device has a native 8-bit float type, its conversion is the only form.
VK_EXT_shader_float8's shaderFloat8 (the SPIR-V capability Float8EXT, SPV_EXT_float8) is now a
VkFeature the device enables and the profile reads (leaf.float8); the SPIR-V IR has
Type::Float8 { encoding } (OpTypeFloat 8 with its FPEncoding, from the regenerated grammar items),
and the interpreter reads OCP's E4M3 and E5M2.

The shared decode, narrow::fp8_to_f32, widens through the device's type where the layout names
one (Fp8Layout::on): each u32 lane bitcast to four 8-bit floats, the low byte's widened by
OpFConvert, so no 8-bit integer type is needed. f8e4m3fn and a tensor's e4m3 take Float8E4M3EXT,
f8e5m2 and a tensor's e5m2 Float8E5M2EXT; the IEEE-like f8e4m3 has no device encoding and keeps
the integer decode. Every site takes it: air.convert's 8-bit float sources, simdgroup-matrix fp8
cells, and matmul2d, whose expansion now widens each element by an air.convert of the tensor's
format (Fp8::TensorE4M3, Fp8::TensorE5M2: Metal's reading, qualified on the M3 Max, e4m3 with no
specials, e5m2's NaNs 0x7FC00000; never parsed from a name, built by Out::air_call). A device
without shaderFloat8 decodes with integers, as before.

Where a tensor's element widens natively the stage records PrecisionNote::NativeFloat8
(native-float8): the device's e4m3 reads 0x7F and 0xFF as NaN where Metal reads 480 and -480,
and an e5m2 NaN's bits are the device's. Validation classes it Unbounded; the conformance suite
lists it among the native notes; FAST-PATHS.md has its device-gap row and API.md its catalogue
entry. The other formats record none: Metal on Apple M3 does not compile them.

The refusal of a matmul2d of 8-bit floats on such a device (Entry::float8_products, the select
check) goes. REFUSALS.md and api_signatures.tsv regenerated.

Tests: matmul2d's fp8 fused sums on the RTX 50 profile (Float8EXT declared, the note recorded,
e4m3 NaN sums) beside MoltenVK, RADV and lavapipe (neither); air.convert widenings on the RTX 50
profile and lavapipe; simdgroup-matrix fp8 cells on the RTX 50 profile too. Not yet built here:
the build and these tests run next on the cluster.
2026-11-13 01:11:22 -08:00
Anees Iqbal 1ace4b5c46 The pre-import placement test counts the asking thread's images; signatures and refusals
What: tests/host_pages_placement.rs reads ObjectChurn::vk_images_made_this_thread (the
WorkCounts field it named does not exist); api_signatures.tsv blessed for
Device::host_pages_texture_placement and Problem::HostPagesBacking; docs/REFUSALS.md
regenerated.

Why: the test did not compile (m3-max-24729); the public surface changed.

Verified: pending the lavapipe run.
2026-11-13 00:43:10 -08:00
Anees Iqbal 9689f5934b matmul2d of 8-bit floats: refused where the device has its own 8-bit float type
Owner rule 1: where a device has a native 8-bit float type, its conversion is the only
form. VK_EXT_shader_float8 (whose shaderFloat8, the SPIR-V capability Float8EXT, Vulkan
requires of every device that lists it) is the vocabulary's ExtShaderFloat8, enabled where
the device lists it. The matmul2d expansion records whether a lowered run reads 8-bit float
elements (Entry::float8_products, from the run's operand types), and selection refuses such
an entry, Unsupported{Tensors, NotImplemented}, where the extension is enabled: the
conversion through the device's type is not built yet. Elsewhere the integer decode stays
the form. Of the committed profiles, nvidia-rtx50-linux and nvidia-rtx5080-laptop list it;
their 8 opened validation contexts each enable it (opened_chains.txt blessed). REFUSALS.md
and api_signatures.tsv regenerated.

Verified on msi (m3-max-24411, m3-max-24435): 261 of 261 touched tests (matmul2d, tensor
ops, the device vocabulary and enables, requirements, the codec, ash interop, the signature
table) pass, among them fp8_products_are_refused_where_the_device_has_its_own_8_bit_floats
(both RTX 50 profiles refuse e4m3 and e5m2; RADV and lavapipe translate and validate) and
the fused-sum tests on MoltenVK, RADV and lavapipe.
2026-11-12 22:57:49 -08:00
Anees Iqbal 5523293ab8 Partial threadgroups: the runtime's tests, the round-trip fields, the surface tables
The runtime's partial_threadgroups test dispatches five ragged grids of a
kernel with a threadgroup barrier (with and without a simdgroup sum) on the
variant and on the same kernel made to split (split_ragged_grids, test-only),
comparing both with Metal's model and counting VkPipelines; under m2v_gpu a
heavy kernel times the creations. flat_simdgroups' two-row grid and barrier
kernel now take the variant's one VkPipeline. api_signatures.tsv and
REFUSALS.md regenerated.
2026-11-12 21:59:10 -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 11d87dec93 Make the region table a public submodule of bind, and pin the fan-out surface
bind::fan_out moves out of the rate map's module so the surface scan reads it;
the surface table, the signatures and docs/REFUSALS.md name the fan-out's
items and refusals.
2026-11-12 16:53:03 -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 1fefc3d956 SEMANTICS_VERSION 2065, ARTIFACT_FORMAT_VERSION 510, RUNTIME_VERSION 2167: a one-row ragged dispatch of a simdgroup-only kernel runs flat in the call's threadgroups
The four commits before this one. A ragged dispatch of a kernel that uses simdgroups was split into a body and an edge
variant, a second full compile of the same kernel (Blender's Cycles kernels on RADV: concurrent ~11 GiB compiles).
The kernel partition now has three classes, decided from structure alone (barrier execution scope, fence and atomic
scope, simd_/quad_ functions, is_uniform, the simdgroup size, the lane builtins): Oblivious, Simdgroups and Observed;
air.all/any of a bool vector now counts as the thread's own (a BoolReduce false positive). New:
KernelFacts::partition_simdgroups, LoweringInputs and VariantKey::call_threadgroups, RuntimeFact::CallThreadgroups
(Variant mechanism, fact id 97). Under flat_grid + call_threadgroups invocations count by subgroup lane order in the
flattened tiers, so workgroup w is Metal's threadgroup w with its simdgroups; the lane builtins are derived; lanes past
the grid return before the body. The compile refuses the bit without flat_grid, with replay_bindings, or for a module
that would hold a workgroup barrier. The runtime's flat_direct tries the plain flat variant first and, for a one-row
grid in one-row threadgroups, then the call variant (its own refusal flag; None, unremembered, when the threadgroup
size asks for emulated simdgroups). Indirect and replay paths still need an oblivious kernel; a kernel with a
threadgroup barrier keeps the split.

Verified (on the branch): m3-max-23184 (gem10, at 4c5d46f8d9) workspace clippy all features, clippy m2v_gpu on runtime
and validation, rustdoc, 136/137 translator tests (the one a test's use of flat_rmw, fixed after), lavapipe 7/7
(FLAT-SIMDGROUPS VkPipelines [1, 2, 2, 2]; lavapipe's 8-lane subgroups emulate the sum, so it splits); m3-max-23193
(8a46347092) 10/10, a_flat_grid_of_the_call_s_threadgroups_admits_a_kernel_of_simdgroups over every committed
profile; 780M RADV (m3-max-23200) 4/4, VkPipelines [1, 2, 2, 1]: the simdgroup barrier + simd_sum kernel runs flat in
one VkPipeline, every thread's word matching Metal's partition, the partial last simdgroup's sum included;
m3-max-23202 workspace and m2v_gpu runtime clippy clean. No guest kernel was dispatched through this path.
2026-11-12 16:29:57 -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 7926fa6e66 SEMANTICS_VERSION 2062: the predicated walk's size estimate charges what the walk emits
The commit before this one. The emulated-simdgroup variant (a dispatch whose threadgroup leaves a partial
simdgroup) took its size forecast from divergent::extra_words: 512 words per AIR block and 12 per operand use, about
15M words on a large kernel, so two kernels of a guest's path tracer (4.0M and 4.5M words emitted) were refused
LimitExceeded(SpirvWords) before emission, where Metal makes them. The estimate now charges each construct the walk
emits beyond the plain walk, from the structured tree (guards per segment, syncs and their guarded stores, reloads
of demoted uses, flag and vote words per walked loop, arm sequencing per walked branch); each constant names the
emitter code it bounds. Translation results change: modules that were refused now translate.

Verified (on the branch): nextest -p metal2vulkan --all-features (m3-max-22642) 3500/3501, the one failure
golden_hashes from SEMANTICS_VERSION 2061's pending re-bless (blessed since at pin 59; this commit changes no
emitted word); the shared test helpers assert estimate >= emitted on every Emulated-tier or walked module the
engine suites build; a_large_predicated_body_compiles_under_a_cap_it_fits (old forecast ~20x emitted). Lint
m3-max-22643. Release translation, amd-780m-radv profile (m3-max-22644): the two kernels' emulated variants at
1.64 s / 256.6 MiB and 1.99 s / 287.4 MiB, within 20 s / 500 MiB. Census over the 3,781 simd/quad/barrier rows
on vk12-floor (m3-max-22649) pending.
2026-11-12 13:57:58 -08:00
Anees Iqbal 62568021fd Region viewports: name the three features in the refusal; bless the API table and REFUSALS.md
The refusal under LoweringInputs::region_viewports lists its features literally, so the
refusal surface names them (devices without shaderOutputViewportIndex, shaderDrawParameters
or multiViewport). api_signatures.tsv takes the new fields and variants; REFUSALS.md the new
sites.

Verified: signatures.py --bless and refusal_surface.py ran locally (source-only).
2026-11-12 12:37:46 -08:00
Anees Iqbal 15866645a8 A generic pointer of no one space is refused as GenericPointer, naming how and where
canon::generic refused every generic pointer it could not give one address space as AddressSpace(8), with no location, so a caller could not tell a pointer of two spaces from one loaded from memory. Feature::GenericPointer (both crates) now names how the pointer gets a space only the run knows (TwoSpaces, Memory, Aggregate, Call, Integer) and the refusal locates the instruction where it does. AddressSpace's doc now lists 8 as defined; the planner treats a generic pointer that survived canonicalization as an invariant breach. FAST-PATHS records the gap, REFUSALS and the API signature table are regenerated, ARCHITECTURE names the pass. runtime_lane::generic_pointers compares generic_spaces and generic_null with the M3 Max's answers (run next on lavapipe).
2026-11-12 07:40:47 -08:00
Anees Iqbal fbb1f7c6bb docs/REFUSALS.md: regenerated after the heap texture beside a selected sampler compiles (one ArgumentBufferTextures site fewer) 2026-11-12 06:21:36 -08:00
Anees Iqbal 131887a2e1 Merged draw replays take indexed draws, and each fragment its own command's slot table
A render execution whose records a kernel writes ran on the host step wherever the buffer's
command types held DRAW_INDEXED, and the merged form refused any fragment function that reads
buffers, since one merged draw had one fragment slot table. Now both stay on the GPU.

- Indexed draws (DrawReplay::indexed, from draw_replay_indexed over the decided writes). The
  preprocess holds an indexed record where the policy and the INDEXED flag allow it: its
  arguments are [index count, instances, base vertex, base instance], and it writes a 16-byte
  index entry per command (the device address of the first index, its offset rounded down to the
  index size; the whole indices to the buffer's end; the size, 2, 4 or 0 for a draw without
  indices). An index buffer of address 0 or a bad index type is a RECORD fault; an address no
  resident range holds draws nothing and counts a resident miss; a position past the buffer reads
  index 0, as the encoder's indexed draw reads it. The merged vertex reads its vertex as the index
  at its position plus the base vertex, a u16 from its aligned word. An indexed replay that does
  not merge is refused (ReplayRefusal::IndexedApart): the runtime host-steps it
  (HostStepCause::Rule).
- Per-command fragment tables. The merged vertex writes its command to a flat uint varying
  (IoRole::MergedCommand, VaryingKey::merged_command). A merged fragment that reads buffers takes
  it as an input and MergedDrawAddress as its push field, and reads its RootTableAddress as the
  header's tables plus command times the stride plus the fragment table's offset
  (bind::merged_fragment_table). The header grows two words (H_INDICES_AT 48, H_FRAGMENT_TABLE
  52; MERGED_HEADER_BYTES 56). A fragment that reads [[primitive_id]] keeps the merged variant
  refused, so its executions host-step, as before.
- Runtime (render/executions/gpu.rs): indexed executions take the merged form alone, no
  per-command fallback; one whose type does not merge host-steps with the rule named. The
  host-replayed-indirect-commands notice text names indexed draws that do not merge.
- The fixture icb_merged_indexed (ours: kernels writing indexed draws of 16-bit and 32-bit
  indices with per-command vertex marks and fragment tints), its AIR companions compiled by
  scripts/regen-air-fixtures on the M3, and its AIR input golden.

Verified:
- metal2vulkan's draw replay, merge, stage IO, varyings, link and API tests, among them the new
  interpreter test of seven indexed records (u16 and u32 offsets, base vertex -1 over two
  instances, indices past the buffer, a residency miss, a bad type, a null buffer): 354/354
  (potluck m3-max-20787, msi).
- Clippy in every configuration (all features, each feature alone, the runtime, --cfg m2v_gpu)
  (m3-max-20812, msi); Rustdoc of both crates and 379/379 tests of the replay, AIR goldens, stage
  IO, API tables, refusals and catalogue (m3-max-20824, msi).
- The new lane test merged_indexed_draws_draw_what_the_host_step_draws (16-bit and 32-bit: six
  commands merged on the GPU with no record read, each fragment its own command's tint, the
  same pixels as the host step's) with the other merged and range-read lanes: lavapipe 12/12
  (m3-max-20811, msi), RADV Radeon 780M 10/10 (m3-max-20814, um790).
- The golden icb_merged_indexed.txt was blessed under the pinned llvm-as (m3-max-20792); no other
  golden moved.

The semantics and artifact format bumps, the golden re-bless and the census stay with the
landing.
2026-11-12 05:39:20 -08:00
Anees Iqbal 6d9bc9f096 RuntimeGap::IndirectRenderCommands names the rule that refused it (IndirectRule)
One gap stood for a dozen rules: an execution of the other encoder kind's commands, a range a
draw of the encoder may write, a command's memoryless texture slot, a color in another format,
the shader-side depth test, a shadowed texture the call did not gather, residency past the call
meeting a shadow's truth, an emulated mesh command's ordering, a memoryless attachment read past
the pass, and on an Apple10 device the render states the commands set themselves. A consumer's log
said "IndirectRenderCommands" for all of them, so a report could not say which one a program met
(a public GPU-culling sample's host step on an RX 550 did not).

The variant now carries IndirectRule (public, non-exhaustive, Copy), one value per site, and the
error's text prints it: "not implemented in the runtime yet: IndirectRenderCommands(UngatheredShadow)".
A family row of indirect render commands names FamilyRow, the summary of the others. No
behavior changes: every site refuses where it did, typed as before.

Tests that expected the gap now expect its rule: the other encoder kind (render_executions,
indirect_command_buffers), a range a draw wrote (render_executions), residency past the call
(buffer_texture_renders), mesh ordering (mesh_commands) and the Apple10 states (state_ids,
command_render_states, families). docs/REFUSALS.md and api_signatures.tsv regenerated.

A consumer that names RuntimeGap::IndirectRenderCommands names a rule now, or matches
IndirectRenderCommands(_).
2026-11-12 04:10:12 -08:00
Anees Iqbal 236340a171 A heap texture's observed residency is resident; a sparse member under it is refused at plan
A function that observes the residency of a read, sample or gather of a texture it reaches
through an argument buffer (sparse_sample, then sparse_color::resident()) was refused at
pipeline creation: lower::texture::residency answered Lowering(Texture), NotImplemented, for a
heap element's status word. A forward renderer that streams its material textures compiles
exactly that, so its pipeline never made and it drew nothing.

Metal reports a texture that is not sparse resident everywhere, which is the word 0 the module
already builds for a heap element's access (emit::with_word). So residency() now answers a heap
element's observed residency with no residency form, the word 0, and the stage states the new
RuntimeFact::HeapResidency { stage } (PlanTimeCheck). The planner (bind::heap::HeapPlanner::new)
refuses a sparse texture (TextureFacts::sparse) that such a stage's handle tables reach,
Unsupported { ArgumentBufferTextures, NotImplemented }: answering one would need the member's
tile map or sparse image per handle-table entry, which is not built. docs/FAST-PATHS.md records
it as a known gap; a slot's sparse texture stays answered (RuntimeFact::SparseTexture).

SEMANTICS_VERSION 2041 (refusals become modules); ARTIFACT_FORMAT_VERSION 504 (a RuntimeFact
variant). docs/REFUSALS.md and the API surface table regenerated.

Test: tests::engine_heap_residency over the new tail_argument_sparse_samples fixture: both
fragments compile behind its vertex function on every committed profile with what they use
(moltenvk-m3, lavapipe and amd-780m-radv named), state the fact and pass L3; their plan holds
a texture that is not sparse and refuses a sparse one. Before the change the base CLI refused
argument_sparse_fragment with Lowering(Texture), NotImplemented, at block 0 instruction 2, the
sparse sample (job m3-max-20327, gem10).
2026-11-12 03:35:36 -08:00
Anees Iqbal 0d144ec0de Pooled memory: no bound on a texture's bytes; ShadowCause::LinearCost is gone
The owner, through reims: zero copy, in place where possible, shadow copies a fallback and never
a first option. A tracked texture over a Private buffer of the runtime's pooled memory whose rows
the device's own linear image lays out otherwise was a shadow past 48 KiB to its pitch
(TextureShadowReason::LinearCost), a speed choice measured on an Iris Xe alone that shadowed 1001
of an RTX 2080 guest boot's 1366 textures. It now takes its DRM_FORMAT_MOD_LINEAR image at Metal's
pitch at any size, wherever the device makes one and its check of the pooled memory passed, as a
texture over a Shared buffer already did; it is a shadow only where the device makes no such
image (its format, usage, pitch or limits), its policy is HostPageTexturePolicy::Shadow, or the
check failed or is pending (a pending one still moves in place once it passes).

Removed with the bound: in_place::POOLED_PITCHED_BYTES, ShadowCause::LinearCost and the public
TextureShadowReason::LinearCost (a breaking change of metal2vulkan-runtime's surface:
api_signatures.tsv loses its variant), texture_spans.rs (the runs of bytes textures were made
over, which only the bound read) and the moves it fed (MoveAfter::Aliases, LoneShadow, the
buffer's note and wait), Texels::only_commands_write (the bound's alone), the bench behind the
bound (runtime_lane::pooled_draw_costs, its crossover additions included) and
aliased_surfaces' cost bench. aliased_surfaces' first check now asserts every texture over one
surface's bytes takes the image at Metal's pitch, the first included, and a read copies nothing;
its one-after-another check, about the first texture's shadow, is gone. storage_over_buffer is
one function again (REFUSALS.md regenerated for the name). API.md, HOWTO.md, FAST-PATHS.md (the
in-place row) say "at any size".

RUNTIME_VERSION is not bumped here: the landing bumps it and re-pins the runtime sources.
2026-11-12 01:50:58 -08:00
Anees Iqbal 9ec681c85c REFUSALS: regenerated for the pooled bound's moved refusal sites 2026-11-11 21:00:30 -08:00
Anees Iqbal cb8f4a0988 A compute state's required size past its kernel's own maximum is refused
A compute creation whose descriptor requires a threadgroup size of more threads than its
kernel's own [[max_total_threads_per_threadgroup(n)]] is now refused,
RequiredThreadsProblem::OverKernelMax, as Metal's first compile of the kernel refuses it. The
runtime made such a state and answered the kernel's maximum.

Measured on the M3 Max under macOS 27.0.1, compute_pipeline_limits.m with a salt
(m3-max-17580), each case a first compile and the same again in its salt:
required-128-attribute-64 is refused both times, code 3, "requested required threads per
threadgroup 128,1,1 but 'count64' expects max threads per threadgroup 64";
required-32-attribute-64 is made answering 32. After a compile of the kernel with no size,
Metal makes the 128 state and answers 64. The runtime answers as the first compile, every time,
as it already does for the other history-dependent answers (docs/API.md, accepted differences).

How: the check runs after the compile (additions::check_kernel_maximum, called from
of_kernel), not in the translator's compile: the required size is no part of the compiled
pipeline's key, so a pipeline of the kernel found in the memo, an archive or the disk cache
would skip a check there. It reads the kernel's maximum through a new public accessor,
CompiledFunction::max_total_threads_attribute. A tile function's own maximum beside a
required size is unmeasured and not checked.

Also: the probe header records the salted answers and the descriptor-validation stops of
m3-max-17549; docs/API.md's accepted difference and the additions.rs module docs name the
refusal; docs/REFUSALS.md regenerated; api_signatures.tsv blessed (two additions: the variant
and the accessor).

Test: runtime_lane::compute_threadgroups::
a_required_size_past_the_kernels_own_maximum_is_refused_every_time refuses 128x1x1 and 16x8x1
beside 64 before and after a state of the kernel is made (the second finds the pipeline
compiled), makes 32x1x1 (32) and 8x8x1 (64), and makes 128x1x1 for the kernel without a
maximum.

Verified: nothing yet; the lavapipe run of the test and the lint follow.
2026-11-11 15:17:08 -08:00
Anees Iqbal 78835b832a Docs: REFUSALS and the API table for the function's logic operation; the probe's findings
docs/REFUSALS.md regenerated: PrivateRenderState's reach names the three features of the
operation's refusal on a device that orders fetch in neither form. The signature table gains
LoweringInputs::logic_operation and RuntimeInput::LogicOperation. The probe's header states
what it measured on the M3 Max.
2026-11-11 14:18:19 -08:00