Commit Graph
46 Commits
Author SHA1 Message Date
Anees Iqbal 83ecf464ec Make a long new host-visible buffer in fresh pages imported by pointer, with nothing written
Content: the tree of `development` at 12606c508c, unchanged.
2026-10-26 13:19:04 +02:00
Anees Iqbal 33e89bd482 Fit mesh, compute and tile pipelines to ANV's compiler word bound
On ANV a pipeline whose largest stage module passes 400,000 words under the exact forms is
retranslated with those forms dropped until it fits; render pipelines already were, and now mesh,
compute and tile pipelines are too, announced as exact-forms-over-compiler-limit with the kind of
pipeline state named. New Device::fit_mesh_variant, fit_compute_pipeline and fit_tile_pipeline for
pipelines linked from stages compiled ahead. The known gap is gone from docs/FAST-PATHS.md.
Verified: the fit tests for every kind, 188 translator and runtime tests and the device notice tests
on ANV, and 7 of 7 on RADV.

Folds in:
- Fit mesh, compute and tile pipelines to ANV's compiler word bound
2026-10-19 00:16:00 +03:00
Anees Iqbal e320a1f475 Drop design-record, work-package and evidence codes from comments, and retire vk12-bare from the corpus
Comments, fixture notes and docs lose their design-record numbers, work-package codes and evidence
codes; lines that earlier commits of this series added carry their cleaned text there, so this
commit holds the cleanup of lines that predate the series, the retired vk12-bare profile's corpus
rows (a rationale and two observation rows), and docs/FAST-PATHS.md's measurements stated as they
stand. Thirteen hash-keyed files keep their citations, because their bytes are case or record
identities: eight case-keyed .ll fixtures and five parity sources.
Verified: the CPU suites (4997 of 4997 and 1328 of 1328), clippy, rustdoc and doctests.

Folds in:
- Drop evidence codes, design-record numbers and work-package codes from comments and fixture notes
- Drop the retired vk12-bare profile from the corpus
- Say the fast-path ledger's measurements as they stand, without commits, rounds or host incidents
- Keep the case-keyed .ll fixtures byte for byte
- Keep the parity lanes' fingerprinted sources byte for byte
2026-10-19 00:16:00 +03:00
Anees Iqbal affd8a5eb7 Split an interlocked pass at the fetch on every GPU, and delete the whole-pass reroute
The UHD 770's cost fact said an interlocked pass ran faster kept whole; measured again, splitting at
the fetch wins on every measured GPU (UHD 770, Iris Xe, Radeon 780M, RTX 3090, RTX 5080 Laptop) on
the window server's passes, so the UHD 770 carries InterlockedPassSplitNoSlower like the rest. With
no device keeping a pass whole, the whole-pass reroute is deleted:
DriverFact::InterlockedPassWholeFaster, RenderCommandEncoder::reroute()'s whole branch and
interlocked_colors(). The extended-range half shadow's draw keeping stays.
Verified: the framebuffer_fetch, extended_range and multisample lanes on all seven GPUs, 271 of 271
each.

Folds in:
- Run an interlocked pass split on the UHD 770 as on every GPU measured, by the corrected cost fact
- Delete the whole-pass reroute, which no device reaches since the UHD 770's fact was corrected
2026-10-19 00:16:00 +03:00
Anees Iqbal 6898b52edf Hold freed memory for the program's own with_vk_queue submissions, and tear the device down on its own thread
On drivers that park freed memory (MoltenVK among them), memory freed while the program's own
with_vk_queue submissions may still use it now waits for them, by a mark each use signals. The watch
of those marks and the release of freed memory hold only the device parts they use, never the
device, and teardown closes the parking first and waits for the handler threads: the program's last
drop tears the device down on its own thread before it returns, as Metal's last release does
(vkDestroyDevice needs external synchronization and every child object destroyed first).
freed_memory.rs is listed among the modules that may keep the device's functions, with that reason.
Verified: the freed-memory and teardown tests on ANV, lavapipe and the M3 through MoltenVK (14 of 14
each), the two teardown tests fail without the fix, and the presenting test that crashed in the
batch passed 20 of 20 on the M3.

Folds in:
- Hold MoltenVK's freed memory for the program's own with_vk_queue submissions, by a mark each use
  signals
- Hold nothing of the device in the watch of the program's marks and the releases of freed memory
- List freed_memory.rs among the modules that keep the device's functions
2026-10-19 00:16:00 +03:00
Anees Iqbal 7bc5866f45 Draw a multisampled 32-bit float depth copy, announced, where the driver's fragment depth is unmeasured
On a driver whose fragment depth is unmeasured, a multisampled Depth32Float copy is drawn and
announced rather than refused.

Folds in:
- Draw a multisampled 32-bit float depth copy, announced, on a driver whose fragment depth is
  unmeasured

Verified by each folded change's own checks; the tree this series ends on is the one verified
at the tip on six GPUs, the CPU suites and lint (see the tables commit).
2026-10-19 00:16:00 +03:00
Anees Iqbal 5783db2459 Keep a fetched merge's texels in an image copy of its shadow, the kept images held per queue
A fetched merge keeps its texels in an image copy of its shadow where the copy in takes no keep, and
kept images are held per queue and taken by any later keep of the same shape once its encoder ended,
so merges stop making a new image each time.

Folds in:
- Keep a fetched merge's texels in an image copy of its shadow where the copy in takes no keep
- Keep merges' kept images per queue, taken by any later keep of the shape once its encoder ended

Verified by each folded change's own checks; the tree this series ends on is the one verified
at the tip on six GPUs, the CPU suites and lint (see the tables commit).
2026-10-19 00:16:00 +03:00
Anees Iqbal e841dd6b4a Read the Radeon 780M of Hawk Point as the measured Phoenix 780M, with its own device profile
The Radeon 780M of Hawk Point (PCI device 0x1900) takes the driver facts measured on the Phoenix
780M (0x15bf), the same GPU, and gets its own committed device profile.

Folds in:
- Read the Radeon 780M of Hawk Point (0x1900) as the measured Phoenix 780M (0x15bf)

Verified by each folded change's own checks; the tree this series ends on is the one verified
at the tip on six GPUs, the CPU suites and lint (see the tables commit).
2026-10-19 00:16:00 +03:00
Anees Iqbal d77bd86377 Compute half + - * and fma in 16 bits under the 16-bit float controls
On a device whose half roundings take the 16-bit float controls (RoundingModeRTE, DenormPreserve
and SignedZeroInfNanPreserve for 16 bits with shaderFloat16: ANV and RADV among the committed
profiles), a half + - * is now the device's 16-bit OpFAdd, OpFSub or Fma(a, b, -0.0), kept apart,
between exact conversions (ops::f16_binary, the form the measured MoltenVK fact already takes).
Where shaderFmaFloat16 is enabled too, a half fused multiply-add is OpFmaKHR on 16 bits (new
fma::Route::F16Khr), under either policy. Elsewhere the f32 operation and its rounding pair, the
round-to-odd routine and native device maths' Fma stay as they were.

Exact: Vulkan's precision table lists OpFAdd, OpFSub and OpFMul for half precision, and OpFmaKHR,
as correctly rounded, to nearest even under RoundingModeRTE, with denormals kept under
DenormPreserve and zero signs under SignedZeroInfNanPreserve, the modes the entry declares where it
computes in 16 bits (narrow::computes_in_16_bits). That is Metal's half arithmetic and Metal's
half fma, which the round-to-odd routine emulated. A NaN's bits are the device's, as the
controlled rounding's already are; Metal's NaN is selected around the instruction where the
profile asks for it. The half fma under native device maths no longer records NativeFma there.

Why: the device's compiler spent most of a large half fragment function's making on the f32 ->
f16 -> f32 rounding pairs, most of which follow a + - * or a fused multiply-add. On ANV a
consumer's largest fragment library made in about 4 s, and about 2.2 s without its rounding pairs.

New: VkFeature::ShaderFmaFloat16 (the Khronos table, enables, the ash and runtime feature chains,
derivation, the codec), OpFmaKHR's feature by its operands' width, the builder's OpFmaKHR on 16-bit
floats, and the owned fixture engine/hfb_filter_bank (a 32-case switch of runtime-sampler tap
loops and half arithmetic chains) with its engine inventory rows. The validation engine's enable
list enables shaderFmaFloat16 from VkPhysicalDeviceShaderFmaFeaturesKHR beside shaderFmaFloat32,
and the opened-chains pin records it for the profiles that list it. Docs: docs/FAST-PATHS.md's half
rounding row, and the NativeFma notice in artifact.rs and docs/API.md.

Verified, as the commits state:
- On the UHD 770 (ANV, Mesa 26.2.4) the fixture's fragment library made in 1.74-1.89 s against
  4.64-5.26 s before (3 alternating rounds, no driver caches), SIMD8 instructions 25,902 ->
  18,736, translation 0.17 s release; driver_deviations::half_arithmetic_answers_as_metal passes
  there.
- On the UHD 770 in the release m2v_gpu build, the groups that failed before the engine enabled
  the feature pass: candidate engine runs, platform enables and device, engine_render,
  engine_compute, engine_textures, acceptance_pipelines, the runtime lanes kernel_textures,
  sparse_textures, renders, argument_buffers and runtime_probe, and the half and fma driver
  deviations.
- Debug translator tests: engine_arith, lower::arith, the fma, derivation, device, ash_interop,
  cache and fast_paths tests, and the engine inventory's llvm_as parts; engine_native_half
  (counting the 16-bit operations and their exact conversions) and engine_spirv_cross_forms (no
  NativeFma where the half fma route is F16Khr), with fused and engine_arith, 213 passed.
- clippy of metal2vulkan.
2026-10-19 00:16:00 +03:00
Anees Iqbal b6addb96c0 Read storage without a format by its format's bit under VK_KHR_format_feature_flags2 or Vulkan 1.3
Vulkan enables the SPIR-V capabilities StorageImageReadWithoutFormat and
StorageImageWriteWithoutFormat by shaderStorageImage{Read,Write}WithoutFormat, by Vulkan 1.3, or
by VK_KHR_format_feature_flags2; under the last two each format's own
STORAGE_{READ,WRITE}_WITHOUT_FORMAT bit (VkFormatProperties3) says whether it may be accessed so.
Intel's ANV and SwiftShader lack shaderStorageImageReadWithoutFormat, and the translator took the
feature as the only route, so a storage read the shader cannot declare with a SPIR-V format was
refused there even where the format's own bit grants it. Metal accepts such reads: an A8Unorm
storage texture read, and a fetch of an A8Unorm color attachment through the pixel interlock.

Now:
- VkExtension::KhrFormatFeatureFlags2 joins the Khronos name table, the cache codec, the
  runtime's and the validation platform's extension tables and the enable facts (core in 1.3, no
  feature member). The runtime enables it below Vulkan 1.3 where the device lists it.
- A module's Requirements list the two capabilities without their feature
  (device::requirements::WITHOUT_FORMAT_CAPABILITIES), and DeviceProfile::check and
  DeviceDescription::required_enables resolve them on the device: the feature where the device has
  it, else nothing at Vulkan 1.3, else the extension. A device with none is refused naming the
  feature, as before.
- metal::format: a typed declaration stays preferred wherever SPIR-V names the format; the
  declarations SPIR-V cannot name (the storage choice, the fetch's storage form, the depth and
  stencil fallbacks, the slot's formatless refusal, the ulong form) go by the features or by the
  format's own bit.
- A heap stays on the features: a per-pipeline check of each member's bit is not built, and
  docs/FAST-PATHS.md's known gap says what the formats' bits leave refused on ANV.

Effect on the committed profiles, read at the runtime's Vulkan 1.2 with and without the
extension over every PixelFormat: on intel-irisxe-rplp-anv and intel-uhd770-rpls-anv an A8Unorm
storage texture read and read-write, and an A8Unorm color attachment fetch read and written,
single and multisampled, now compile (an A8_UNORM view declared without a format), and an A8Unorm
texture buffer takes the A8_UNORM view in place of R8_UNORM holding alpha in red (both Metal's
texels). On intel-irisxe-anv and swiftshader nothing lifts. Every other changed cell on the four
profiles (1280) keeps its refusal and now names the format's missing bit in place of the feature.
The engine fixture tables do not change on any profile. The validation platform's Vulkan 1.2
device contexts enable the extension where a profile lists it, and the opened-chains pin records
it (32 contexts on 16 profiles, one more extension each).

Verified, as the commits state: the unit tests device::tests::enables (the feature, the version or
the extension), metal::format (access by the format's bits with the extension),
lower::fragment::fetch (an A8Unorm attachment fetched by its own bit, the fetch tests at Vulkan 1.2
with and without the extension), spirv::requirements and spirv::serialize, and the
framebuffer-fetch compile test all pass; public_fixtures_engine parts 1-8 unchanged; the
per-profile census above, run as a temporary test; candidate::platform::enables::tests 21 of 21;
clippy. New lane runtime_lane::alpha_in_red::a8_storage_reads_without_the_feature_go_by_the_format_s_bit
(a device made without shaderStorageImageReadWithoutFormat, as ANV is, reads its own A8_UNORM by
the format's bit under the extension: Metal's (0, 0, 0, 0.6) and 178).
2026-10-19 00:16:00 +03:00
Anees Iqbal 1ef457d88b Refuse an unordered framebuffer fetch and drop interlocked draws' barrier where the driver orders them
Three changes to framebuffer fetch and the pixel interlock.

1. An unordered framebuffer fetch is refused; FramebufferFetchPolicy is deleted. Metal orders a
   fragment function's read of its color attachment after every earlier fragment of the pixel,
   within a draw and across draws. Where a device offers neither ordered form
   (rasterization-order attachment access, or the pixel interlock's storage form where the
   pipeline's state lets it be exact), the opt-in FramebufferFetchPolicy::AcceptUnordered
   compiled the read as an unordered input attachment with a precision note. An unordered read
   can return the attachment before an earlier overlapping fragment's write: a different value
   in memory, not a rounding, which the owner's rule allows neither as a default nor as a
   switch. No exact form exists on such a device, so the fetch is refused there, as the default
   already did. The runtime never ran the unordered form, so no runtime behaviour changes.
   - Removed: DevicePolicy::framebuffer_fetch, the enum FramebufferFetchPolicy and its
     re-export (and its api_surface row), ProfileFields::framebuffer_fetch,
     PrecisionNote::UnorderedFramebufferFetch, and the runtime's note kind of that name, whose
     code metal2vulkan-degrade-unordered-framebuffer-fetch is retired; the runtime's
     framebuffer_fetch::ordered check; validation's --accept-unordered-fetch on corpus-vulkan,
     corpus-moltenvk and corpus-pipeline, and the device worker's framebuffer_fetch field.
   - lower::fragment::color refuses a read no ordered form serves (Unsupported{FramebufferFetch},
     naming both forms); lower::fragment::fetch refuses a blocked storage form with its blocker.
   - The profile's fields change, so every profile fingerprint does.

2. No barrier between interlocked draws' colors on a driver measured to order them. Between two
   draws of a render pass instance where the later one reaches a color in the fetch's
   interlocked storage form (or an extended-range color's half shadow) that the earlier one
   wrote, the runtime recorded a fragment-to-fragment storage barrier on every device. Vulkan
   orders such draws by the interlock alone (ordered interlock modes follow rasterization
   order, which follows primitive order through a subpass, and the interlocked storage image is
   decorated Coherent). A new answer fact, DriverFact::InterlockOrdersDraws, measured on ANV on
   the Iris Xe of Raptor Lake-P, drops that barrier there for these colors alone. The fragment
   imageblock's storage and the depth stand-in keep their barrier everywhere, as does every
   unmeasured driver. RADV on the Radeon 780M still needs the barrier: without it one blend
   table case leaves 19 of 495 band results wrong over 5 runs. New lanes:
   runtime_lane::interlocked_draw_order (every device, with its owned fixture ido_draw_order) and
   the ignored release bench runtime_lane::tile_path_costs (a window server's composite on
   Metal's tile path, fixture tgp_composite), with their engine inventory rows. A FAST-PATHS
   bullet records the barrier and the fact.

3. A left-out interlock color's framebuffer slot holds a placeholder image. A color attachment
   the draws read and write as a storage image in the interlock is left out of their subpass,
   but its framebuffer slot held a view of the very image the draws write, which the validation
   layer reads as VUID-vkCmdDraw-None-06537 for a draw recorded inline. The slot now holds a view
   of a placeholder that nothing reads or writes (DONT_CARE load and store, GENERAL layouts): the
   device keeps one for each format and sample count, plus one for each further color of that
   shape in the same framebuffer, grown to cover a larger framebuffer and freed once no
   framebuffer holds it; none is made per frame. A color whose draws use sample planes, and the
   planes' anchor, keep their own image's view. New WorkCounts fields
   storage_placeholders_made and storage_placeholder_attachments.

Verified, as the commits state:
- The translator's fetch tests (pipeline::compile ordering, engine_fragment, engine_moved_writers,
  device profile fingerprints and serde, fast_paths) keep the refusals; the raster-order-group
  read on a device with neither ordered form expects the fetch's own refusal naming both forms.
  Validation checks every public fetch case is refused on lunarg-desktop-baseline-2023 and
  vk12-floor, and that the command-line flag is gone.
- Iris Xe (ANV) with the fact in place: interlocked_draw_order 3 runs with every texel right,
  extended_range_blend_table 17 passed (0 of 495 bands wrong), framebuffer_fetch 49 passed. A
  1080p pass of 27 interlocked draws took about 1.08 million GPU cycles with the fact against
  1.46 million with the barrier forced (about 9 to 20 us a draw).
- The placeholder lane test (two RGBA32Uint colors over four passes and sizes): placeholders and
  slots (2, 2), (2, 4), (4, 6), (4, 8) through the interlock on the RX 7900 XTX (RADV) and the
  UHD 770 (ANV), none through input attachments, no validation message. On lavapipe 122 lane
  tests and 47 runtime render unit tests passed; on the RX 7900 XTX 94 lane tests passed.
- The engine inventory and llvm_as parts pass for the new fixtures; clippy in every
  configuration and Rustdoc -D warnings.
2026-10-19 00:16:00 +03:00
Anees Iqbal e35bf78bd5 Shadow every padded texture over a buffer and every texture over host pages, keeping CPU writes
A texture over a buffer could be an image bound to the buffer's bytes: a padded texture that only
read (PaddedReadsPolicy::Alias, the default), and any 2D texture over a no-copy buffer's host
pages (a linear image, a DRM_FORMAT_MOD_LINEAR image at Metal's row pitch, or on MoltenVK a Metal
texture over the import's MTLBuffer). An image bound to imported memory starts UNDEFINED, and a
layout transition "may perform read and write accesses on all memory bound to the image
subresource range", so such an image kept Metal's bytes across its first move only through a
host keep (read the bytes, submit the move alone, wait, write back what changed), which undid a
CPU write made inside that window. Metal keeps every CPU write to bytes a command buffer does not
write: on the M3 Max, a kernel reading half a padded no-copy texture while the CPU rewrote the
bytes between its rows and its other rows kept every CPU byte in 10 of 10 rounds. Changing bytes
in memory is not a precision note, so under the owner's rules it may be neither a default nor a
switch; exact is the default, and cost chooses only among exact forms.

Now a padded texture over a buffer, and every 2D texture (or array) over a no-copy buffer's host
pages, imported by pointer or as dma-bufs, is a shadow on every device, whatever its usage: an
optimal image of the runtime's memory, copied in from the bytes before a use and merged back
after a write. Texture::vk_image answers None for such a texture.

Removed:
- DevicePolicy::padded_reads and the enum PaddedReadsPolicy (Alias, Shadow); its FAST-PATHS row,
  its tests::fast_paths choice and its api_surface row.
- The images over host pages: the linear image for host allocations, the DRM_FORMAT_MOD_LINEAR
  image over host allocations with its refusal memo, the modifier image over a buffer texture's
  own dma-buf, the Metal texture over the import's MTLBuffer on MoltenVK (VK_EXT_metal_objects is
  no longer enabled for it), and the one image shared by textures of one plan over one import.
- The first move's host keep, and its notice unrestored-first-move-bytes (Degradation
  UnrestoredFirstMoveBytes), retired.
- WorkCounts fields first_move_keeps, first_move_kept_bytes, first_move_restored_bytes,
  pitched_host_images, pitched_host_image_refusals, pitched_host_image_refusals_recalled,
  shared_alias_images and shared_alias_moves_waited.

Kept: the buffer's dma-buf import as the last resort where the pointer is refused, on any device;
the images of heap textures over host pages, including over dma-bufs (a heap resource's contents
are undefined until written, in Metal too); a linear image over a buffer of the runtime's own
memory (PREINITIALIZED), whose first move FAST-PATHS records as a one-line known gap.
ShadowedTexture (shadowed-texture) now also covers read-only padded textures.

Also: a staged shadow's copy back merges rows that lie one after another into one region (a
packed 1080p surface takes one region, not 1080), and two new counters size what a shadow kept
across a command buffer's passes could save: WorkCounts::shadow_attachment_passes and
shadow_attachment_textures.

Docs: docs/FAST-PATHS.md (the shadow bullet with its costs, the known gaps), docs/API.md
(section 1's texture paragraph, the shadowed-texture and dont-care-stand-in entries, the retired
code), docs/HOWTO.md section 6, the runtime README, linear_attachment.rs's module doc.

Cost, as measured: on the Iris Xe a frame sampling four BGRA8Unorm tiles over no-copy pages took
3.2-5.3 ms as shadows against 3.0-6.1 ms as images (textures made once) and 3.4-7.1 against
4.6-8.6 ms (made each frame). On the UHD 770 (ANV, release, alternated), one Load/Store pass into
the guest's 1080p surface took 1.89-1.97 ms as a shadow against 2.56-3.09 ms as the linear alias,
whose draws ran slowly in host memory; 12 passes 20.9-21.1 ms against 27.4-27.8 ms, at about 40 us
more CPU a pass.

Verified, as the commits state:
- runtime_lane::first_use_writes (new: another thread writes bytes of a texture over host pages
  that its first use does not read, from 2 ms before to 2 ms after the commit; every write stays)
  passes on the RTX 3090, the Radeon 780M and the UHD 770.
- runtime_lane::pitched_surfaces asserts a shadow for every surface (counted, vk_image None),
  including the CPU write beside a padded texture during its first use and the new counters;
  no_copy_textures asserts a shadow and no modifier queries; the keep, pitch-refusal and
  shared-image tests go with what they tested.
- The lanes restated for the shadows pass whole: dma_buf_imports 13, resource_ids 38,
  rotated_textures 7 and linear_attachments 20 on the RX 7900 XTX and the 780M (RADV), the UHD
  770 (ANV, with row_copies 2) and the RTX 3090.
- linear_attachments renders over a Shared buffer of the runtime's memory, so the linear
  attachment paths stay covered, each test asserting the way its passes took; 21 pass on the RTX
  3090, the 780M, the RX 7900 XTX and the UHD 770.
- Runtime and validation nextest without a device, 2306 passed; the translator's fast_paths,
  api_surface, published_crates, refusal and driver_facts tests, 34 passed; clippy in every
  configuration and Rustdoc -D warnings.
2026-10-19 00:16:00 +03:00
Anees Iqbal 1df750bbd4 Resolve multisampled color by the device's average by default, Metal's rule on ResolvePolicy::Exact
A pass that resolves a color attachment whose format has Metal's resolve rule at its sample count
drew the runtime's exact resolve after the pass on every device whose AVERAGE is not measured to
be Metal's (everything but MoltenVK): one more render pass instance per resolved attachment,
between full barriers, reading the stored samples as an input attachment. That form is exact
and costly in GPU time. By the owner's rule (fast by default, exact on request, both kept), the
device's resolve becomes the default, announced, and the exact resolve a switch.

- DevicePolicy gains resolve: ResolvePolicy { Device (default), Exact }, a runtime choice alone
  (no emitted code changes, no profile carries it). exact_answers() selects Exact.
- Under Device the attachment resolves in its pass by Vulkan's AVERAGE, announced as
  device-rounded-resolve (precision), whose reason names ResolvePolicy::Exact: no extra pass, and
  a render target needs no input attachment usage for the resolve. Under Exact everything is as
  before.
- Unchanged under both: a driver with DriverFact::ColorResolveAverageIsMetals (MoltenVK on
  Apple's GPUs) resolves in the pass with no notice, and an attachment a fetching pass's sample
  planes hold as it ends resolves from them by Metal's rule.
- device-rounded-resolve's docs and cost state the measured bound: one code for a unorm, snorm or
  packed 16-bit unorm channel, two for an sRGB channel; a float channel's last bits are counted,
  not bounded.
- Docs: a new docs/FAST-PATHS.md row for the switch; docs/API.md's policy bullet and the
  device-rounded-resolve and shader-resolve catalogue entries; color_resolve.rs, policy.rs and
  driver_facts.rs state both values. The api_surface table lists ResolvePolicy.

Why: the exact form's extra pass costs GPU time on every device but MoltenVK (a resolved pass's
command buffer 73-77 us against 51 us on the Iris Xe, 63-75 us against 45-48 us on the 780M), and
no driver measured matches Metal's rule, so none gains ColorResolveAverageIsMetals.

Measured, as the commit states (release builds, 1920x1080 frames of 97 command buffers, every
fourth pass resolving an RGBA8Unorm x4 attachment, the exact form against the device's,
alternated): GPU busy a frame on the Iris Xe (ANV) 2.52 and 2.41 ms -> 1.92 ms (the guest's
shape 3.04, 2.77 -> 2.44, 2.43 ms); on the Radeon 780M (RADV) 2.33 to 2.78 -> 2.00 to 2.13 ms; on
the RX 7900 XTX 1.38 -> 1.36 ms.

The device's average against Metal's rule: on RADV (780M and RX 7900 XTX), ANV (Iris Xe),
lavapipe and NVIDIA (RTX 5080 Laptop), unorm and snorm channels land one code below Metal's at a
tie (16-bit channels exact on NVIDIA), sRGB within one code both ways (up to two at 4 samples on
NVIDIA), packed formats within one, float channels differ in value.

Verified, as the commit states:
- The new lane runtime_lane::resolve_rounding::the_device_resolve_rounds_as_announced (default
  policy) passes on lavapipe, the RTX 5080, the 780M, the RX 7900 XTX and the Iris Xe: every
  closed format at 2 and 4 samples resolved by the device, device-rounded-resolve exactly where
  the fact is absent, and every difference against Metal's rule within the notice's bound.
- The exact form keeps its lanes: the validated options take exact_answers(), so
  resolve_rounding's other tests, degrade_notices, nan_resolves and framebuffer_fetch run under
  ResolvePolicy::Exact as before.
- tests::fast_paths (the switch, and that the choice keys no profile), the driver_facts tests,
  api_surface, the runtime's degradation and driver_defects tests; fmt, clippy in the three
  configurations, rustdoc.
2026-10-19 00:16:00 +03:00
Anees Iqbal bb4f53d209 Read a surface's own pixels through a snapshot at any area, where its image takes feedback loop usage
A draw that reads the texture its pass renders, at its own pixels after a barrier, takes a
snapshot drawn in its subpass, or splits the pass instance and reads a copy; both are exact. The
snapshot was open only to a texture of its own image, so a texture over a buffer's bytes always
split, and each split copies the bytes into the shadow before every instance after a barrier.
The consumer's guest renders its 1080p framebuffer, an IOSurface over host pages, this way.

Now:
- Device::storage_over_buffer tries the linear image that aliases a buffer's bytes with
  ATTACHMENT_FEEDBACK_LOOP_EXT usage first (it costs a linear image nothing; its memory is the
  buffer's), then makes it without where the driver refuses, and counts each image made with the
  usage in the new WorkCounts::feedback_loop_alias_images.
- Texture::snapshot_color reads such an aliasing image through a snapshot, as an image of its
  own, and a reader of a texture over bytes takes the snapshot at any area. The area rule for a
  texture of its own image is unchanged.
- Where the image lacks the usage (NVIDIA's drivers make it without), the surface's readers
  split, exactly as before.
- A pass with a depth or stencil attachment keeps every attachment reader on the split: the
  binder makes no snapshot variant for it, and a snapshot draw would write depth or stencil before
  the drawing draw. render/snapshot.rs's docs say so, and a lane case holds the behaviour.
- The attachment-read row of docs/FAST-PATHS.md states the crossover and the feedback loop
  condition.

Why: in the guest's frames the split's copies dominated (66 splits, 68.2 own-pixel reads and
16.6M texels of bounded copies a frame), while the readers' fragments touch about 1.5% of the
texels a split copies.

Verified, as the commits state:
- On the Iris Xe (release, the new ignored lane attachment_read_costs::snapshot_crossover, a 1080p
  surface over host pages, snapshot and split forced and alternated): the snapshot's GPU time per
  pass is 0.56x to 1.2x the split's; its worst case is a small scissor covered half or more,
  about 10 us a reader, and it is cheapest for sparse readers in big scissors, where the guest's
  readers sit.
- runtime_lane::snapshot_reads: readers over a surface take the snapshot where the image took
  the usage and the split elsewhere, with Metal's bytes either way. RTX 3090 and RTX 5080
  (aliased, no feedback usage) split and pass; the Iris Xe (aliased, feedback usage) takes the
  snapshot and passes; the other snapshot_reads tests pass on all three.
- The depth/stencil case (Less depth with and without writes, a stencil test that blends each
  pixel once): every reader splits and leaves Metal's texels on the Iris Xe, the RTX 3090 and
  the RTX 5080; all 7 snapshot_reads tests pass on the RTX 5080.
- clippy plain, m2v_gpu and m2v_cpu_icd.
2026-10-19 00:16:00 +03:00
Anees Iqbal 7db879f242 Release idle pointer imports on RADV 26.2.4, and say which RADV host stack loses GPU writes
On the Radeon 780M with RADV (Mesa 26.2.4), idle pointer imports are released where they follow
their address, as on the other measured drivers; docs/HOWTO.md says which RADV host stack loses GPU
writes under memory churn.

Folds in:
- Release idle pointer imports on RADV 26.2.4 on the Radeon 780M, where they follow their address
- Say which RADV host stack loses GPU writes under memory churn

Verified by each folded change's own checks; the tree this series ends on is the one verified
at the tip on six GPUs, the CPU suites and lint (see the tables commit).
2026-10-19 00:16:00 +03:00
Anees Iqbal a97f7c2757 Keep Metal's contract for host imports and shadows: no posted deallocator, no copy back over CPU bytes
Two fast paths that broke Metal's contract are gone: the posted deallocator of a released host
import and the shadow copy back over bytes the CPU may write. A released import is freed in the
call, as Metal frees it, and a shadow merges back only the bytes the GPU changed. The notice codes
of the two retired kinds are retired too, and the runtime holds the list of every notice code ever
issued so a retired code is never reused. The keep-alive lanes wait for the keep-alive that goes
with an import's free.

Folds in:
- Free a released host import on a handler thread by default (later removed)
- Copy a shadow back over bytes the CPU may write by default (later removed)
- Remove the shadow copy back over CPU-written bytes and the posted deallocator, which broke Metal's
  contract
- Wait for a keep-alive that goes with its import's posted free in the keep-alive lanes
- Retire the codes of the two removed notice kinds, and hold every code ever issued

Verified by each folded change's own checks; the tree this series ends on is the one verified
at the tip on six GPUs, the CPU suites and lint (see the tables commit).
2026-10-19 00:16:00 +03:00
Anees Iqbal f8af954378 Emulate Metal's anisotropic filter as one routine per shape, its offset the taps' Offset operand
Metal's anisotropic filter is emulated as one routine per shape, with its calls kept where the
driver keeps them (the RTX 5080), and an anisotropic sample's texel offset reaches the routine as
the taps' Offset operand.

Folds in:
- Emulate Metal's anisotropic filter as one routine per shape, its calls kept on the RTX 5080
- Pass an anisotropic sample's texel offset to its routine as the taps' Offset operand

Verified by each folded change's own checks; the tree this series ends on is the one verified
at the tip on six GPUs, the CPU suites and lint (see the tables commit).
2026-10-19 00:16:00 +03:00
Anees Iqbal c9b0d74912 Record Vulkan commands off the encoding thread through deferred command buffers the recorder replays
Encoders log their commands into deferred command buffers, and the device's recorder thread replays
them into Vulkan once the command buffer is committed, so the encoding thread no longer calls the
driver for each command. Every recorded command goes through a slot of its device's; the recorder's
queue and the scheduler's inbox are sized for a frame's commits and grow ahead of them on the
recorder's thread; a commit's end allocates nothing; a render pass instance's secondary that nothing
executes is never replayed. The replays' commands are counted by kind, and the recorder's modules
are listed among those that may keep the device's functions.

Folds in:
- Route every command the runtime records through a slot of its device's
- List recorder/mod.rs among the modules that keep the device's functions
- List recorder/thunks.rs among the modules that keep the device's functions
- Record Vulkan commands off the encoding thread: encoders log into deferred command buffers, the
  device's recorder thread replays them once committed
- Grow the recorder's queue ahead of the commits, on the recorder's thread
- Give the scheduler's inbox and the recorder's queue room for a frame's commits from their making
- Count the commands the recorder's replays call, by kind
- Give a commit's tail log its fold's room when its encoder ends
- Never replay a render pass instance's secondary that nothing will execute
- Give new replays room to end each deferred command buffer as it is made, so a commit's end
  allocates nothing

Verified by each folded change's own checks; the tree this series ends on is the one verified
at the tip on six GPUs, the CPU suites and lint (see the tables commit).
2026-10-19 00:16:00 +03:00
Anees Iqbal f29872bd92 Sample extended-range textures as Metal does across mip levels, array layers and 3D
Extended-range textures sample as Metal does at every mip level and array layer and in 3D under no
mip filter or a nearest one. The emulated sample is one routine per shape, its constant texel offset
passed as an argument; a linear sample takes its exact sum from each tap's codes, undecoded, and its
value on the grid by a multiplication by 1/255 with an exact correction. Draws whose variant takes a
two-plane extended-range texture slot are counted.

Folds in:
- Sample extended-range textures' mip levels and array layers as Metal does
- Sample extended-range 3D textures as Metal does under no mip filter or a nearest one
- Emulate an extended-range sample as one routine per shape where the driver keeps calls, its
  constant texel offset the call's argument
- Hand a linear extended-range sample's exact sum each tap's grid steps from its codes, undecoded
- Take a linear extended-range sample's value on its grid by a multiplication by 1/255 and an exact
  correction
- Count draws whose variant takes a two-plane extended-range texture slot

Verified by each folded change's own checks; the tree this series ends on is the one verified
at the tip on six GPUs, the CPU suites and lint (see the tables commit).
2026-10-19 00:16:00 +03:00
Anees Iqbal 3bb4722d9f Release idle pointer imports where they follow their address, keep deallocator timing Metal's across rebinds and detaches, and cut host-import work
No-copy buffers and host imports now cost the kernel and the encoding thread less, and their
deallocators run in the call Metal runs them in, including when a detach races a commit.

What changes:
- Idle pointer imports. A no-copy buffer's own pointer import is releasable, as its dma-buf
  import was: while only blits read it and no pending command buffer holds it, the residency
  thread releases it after its idle window (2 s, doubling at each import again up to 64 s), and the
  next blit imports it again at the same pointer. Only where the new measured fact
  DriverFact::PointerImportsFollowTheirAddress holds (ANV 26.2.4 on the Iris Xe; lavapipe 26.0.8
  to 26.2.4): there a pointer import reads the pages mapped at its address at each submission, so
  an import again reads what the kept one would. A refused re-import fails the blit's call, typed.
- Deallocator timing. A released import hands its keep-alive and deallocators to the objects a
  command buffer still holds, so they run as that memory is freed (or parked and announced, as a
  kept import's). A committed but unsubmitted command buffer holds a blit's import objects weakly,
  so a rebind or detach before its first submission runs the deallocator in its call, as Metal
  does. A detach racing a commit on another thread runs the deallocator in one of the two calls:
  a let-go mark on the pages and the commit's hold count, both sequentially consistent, make each
  side see the other, and a commit that sees the mark replays its own command buffer at once. The
  live list re-reads a buffer's pages where a detach moved them meanwhile. HostDeallocatorDelayed
  is no longer announced for these races.
- Fewer kernel queries. A no-copy buffer asks the kernel about its mappings (PROCMAP_QUERY) only
  where it makes its own import; a rebind onto a live buffer's bytes lies in that buffer's import
  and asks nothing; /proc/self/maps stays open for the queries (reopened in a forked process).
  Three blit paths that read the caller's buffer as a read apart now read it as blits, so their
  imports stay releasable.
- Fewer rewrites and lookups. A rebind or detach rewrites only the heap slots of textures over the
  bytes it moved; host-page alias lookups visit only the length classes that hold ranges and keep
  each range's overlapping ranges; a binding and a descriptor each read where a no-copy buffer lies
  once.
- Counters (WorkCounts): host_imports_used and host_imports_read_apart (with its six reasons),
  host_imports_kept_for_fds and kept imports by cause (of_heap, rebound, pointer, no_stand_in),
  heap_slots_rewritten, host_mappings_queried (Linux; 0 elsewhere), host_range_lookups,
  host_remaps_reported, host_remaps_over_imports, host_imports_remapped, host_pointer_imports_made
  and _bytes_made, no_copy_lies_read, host_imports_rebound_unlisted, host_rebind_imports_made and
  _covered.
- Docs: docs/HOWTO.md on both kinds of release, the RLIMIT_NOFILE soft limit a program raises
  itself and the new gauges; a FAST-PATHS known gap that a buffer made before a remap reads the new
  pages on drivers whose pointer imports follow their address, where Metal keeps the old ones
  (HostMemory::new's contract forbids such a remap); the rustdoc of host_range_remapped.

Why: ANV over i915 lists every VkDeviceMemory in every execbuffer, and a pointer import costs about
0.19 us an execbuffer; the consumer's guest keeps hundreds of no-copy buffers live and uses few in
a frame. Its swap thread spent 1.54 ms of kernel time a frame querying mappings of a buffer that
joined a live import. And a released import's deallocator unmapped pages under a live userptr,
losing the device.

Verified:
- Iris Xe, a guest-shaped lane of 520 pointer imports and 43 command buffers a frame, the idle
  ones released: objects per execbuffer 536 -> 51, ioctl 4.24-4.31 -> 0.85-1.09 ms a frame,
  scheduler CPU 4.96-5.05 -> 1.33-1.74 ms a frame, frame p50 5.27-5.43 -> 2.70-3.11 ms.
- The fact, probed outside the runtime on the Iris Xe and through tests::pointer_residency on it
  and lavapipe: a kept import read the pages a remap put at its address.
- The detach race on the Iris Xe and RTX 5080 under the validation layer: without the fix 3 of 3
  runs failed (deallocators late or on another thread); with it 12 of 12 runs, 15,360 races, each
  deallocator in the detach or the commit, never late.
- A second no-copy buffer over 2040 scattered mappings: 415-418 us -> 0.3-0.6 us. A rebind with
  1024 other live textures: 4766 -> 49 us. Alias lookups: a draw -5.3% instructions on host-page
  frames (RX 7900 XTX).
- Device and unit tests: freed_memory, pointer_residency, host_residency, blit_holds,
  encoder_holds, host_import_counts, host_aliases (up to 45 passed per run); lanes rebinds,
  rebind_reach, detach, detach_textures, host_memory, no_copy_heaps, dma_buf_imports, draw_work
  (74 passed on lavapipe, 30 on the Iris Xe for the deallocator fixes). clippy -D warnings (plain,
  m2v_gpu, m2v_cpu_icd) and rustdoc.
2026-10-19 00:16:00 +03:00
Anees Iqbal f514cb9a7d Cut shadowed textures' copies to what their commands touch, merge back every buffer another writer may write, and count copies by cause
A texture over a buffer's bytes or another image whose own image is a shadow now copies in, keeps,
merges and copies back only the texels its commands reach, with fewer barriers, descriptor pools
and scratch fills, and merges its writes back wherever another writer may write the bytes during
the run.

What changes:
- Which shadows merge. A shadow merges back (kept before the first command that writes through
  it, only the words its commands changed reaching the bytes) over every buffer's bytes but a
  tracked Private or Memoryless buffer the runtime made: Shared buffers and host pages as before,
  and now Managed buffers (on unified memory the CPU writes the GPU's memory, and without it a
  later upload may run on another queue) and untracked buffers another queue may write. A tracked
  Private buffer's shadow, a command replacing every texel, an image's shadow, and turned and
  two-plane textures still copy back. A merge goes in place wherever the texture's first and last
  words lie in the buffer and the bytes lie in pages; only a first byte inside a word, a staging
  buffer or a last word past the buffer still merges through a copy, a new FAST-PATHS known gap
  since that round trip can undo another writer's write between its copies.
- Correct merges. A command that replaces every texel followed by one that writes part of it is
  copied back before the keep, so the merge carries the later writes. A merge of a part leaves a
  twin stale there alone. A detached buffer's shadow binds no stand-in (the null handle while
  detached), so no merge binds a range past a 256-byte stand-in.
- Cut copies. A read inside a rectangle keeps the rest of the changed rectangle for the next read;
  an image's one-level, one-slice shadow cuts its copies in as a buffer texture's do; a keep and
  merge are cut to the rectangle the encoder's commands write in, in bands within the device's
  limits; a loaded shadowed colour's copies are cut to its draws' scissors also in passes that
  clear another attachment or take a reach clear (Vulkan's scissor test leaves coverage outside
  at 0).
- Cheaper copies. On ANV (DriverFact::ShadowCopyBackDispatchFaster, now every ANV device measured)
  a merge's keep and changed copy are the copy back's dispatch, and a cut merge reads the changed
  texels straight from the shadow's integer view (bind::shadow_merge_image_module), with no copy
  after the commands. On the UHD 770 (new DriverFact::ShadowCopyInDispatchFaster) a merged
  shadow's copy in and its keep are one dispatch (bind::shadow_copy_in_module), its 4-byte view
  R8G8B8A8_UINT because ANV drops a storage image's compression for an R32 view. The shadow
  kernels take a bind::ShadowTexelView. A cut merge's scratch is kept for the next merges and not
  zeroed. The shadow kernels and a linear attachment's merge push their descriptors where the
  device pushes set 0, so a shadowed pass makes no descriptor pool. A run of shadow copies in an
  unordered encoder shares one barrier before and one after, keeping a barrier only between copies
  that touch the same memory and one writes.
- Counters (WorkCounts): every copy in by why it is made and by what holds the texture's truth,
  first copies apart (shadow_texels_first_copied_in_*, shadow_texels_recopied_*,
  shadow_texels_copied_in_images, shadow_texels_bounded_copied_in), shadow_texels_kept,
  shadow_merge_copies_dispatched, shadow_merges_fetched, shadow_copies_in_dispatched,
  shadow_merge_scratches_reused and _zeroed, owned_descriptor_pools, how passes take shadowed
  colours (shadow_attachment_loads_*, _clears, _clears_in_part), shadows_sharing_truth, and the
  tiles a loaded colour's scissors cover against their bounds.
- Docs: shadow.rs and shadow_merge.rs module rules, API.md's shadow entries, FAST-PATHS' costs of
  matching Metal and known gaps; the snapshot rule's figure is now an upper bound.

Why: Metal writes only the texels a command writes, and another writer may write bytes no command
touches during a run. On an M3 Max under macOS 27.0.1, a fill of an untracked Private buffer from
a second queue ran inside a first queue's kernel or render pass 5 times of 6 and both texels kept
their writes, as did a CPU write to a Managed buffer; a tracked Private buffer's fill always ran
after. And in the consumer's Finder drag on the Iris Xe, whole 1080p shadow copies were most of
the composite command buffers' GPU time.

Verified:
- Iris Xe, four shadowed textures a frame over anonymous pages, commit to completion: merged passes
  that draw 11.7-11.8 ms -> 5.0-5.4 ms and scissored ones 11.3-11.4 -> 3.6-3.9 ms across the
  dispatched copies, cut keeps and fetched merges; a 1080p Load pass's GPU time 4572 -> 3484 us
  with the fetched merge.
- UHD 770: a 1080p Load/Store pass 2390 -> 1683 us GPU with the fetched merge; a 1080p Load pass
  1.64-1.67 -> 1.43 ms with the fused copy in; the kept scratch took a 1080p Load pass 4205-4755 ->
  2626-3595 us commit to completion (RX 7900 XTX 4112-4392 -> 1628-1697 us). Shared barriers saved
  about 0.65 us of GPU time per barrier removed on the Iris Xe (680 -> 120 barriers a frame).
- runtime_lane::pitched_surfaces 28 of 28 on the UHD 770, Iris Xe, Radeon 780M, RX 7900 XTX and
  lavapipe, with merges under changing scissors, split instances and two textures over one buffer
  matching a private texture's bytes; under synchronization validation with no message. The shadow
  lanes 123 to 132 of 123 to 132 on the M3 Max, lavapipe, Iris Xe and RADV; extended_range_blends,
  linear_attachments and padded_loads on the RTX 5080 with no validation message.
- Unit tests: tests::shadow (24), clear_reach, owned_pushes, shadow kernels through all four views
  on the CPU interpreter, driver_facts. clippy -D warnings (plain, m2v_gpu, m2v_cpu_icd), rustdoc.
2026-10-19 00:16:00 +03:00
Anees Iqbal ca8340b4ee Group ready batches into one kernel submission on Mesa's drivers, and order a queue's batches by their ends
On ANV over i915 every kernel submission lists every VkDeviceMemory of the device, at a cost per
object; the consumer's guest drag on the Iris Xe had 302 entries per execbuffer (260 of them host
imports) at 112 to 128 execbuffers a frame. The runtime now makes fewer kernel submissions and
fewer command buffers per frame, under two new runtime policies.

What changes:
- DevicePolicy::completion, CompletionPolicy { Grouped (default), Exact }; exact_answers()
  selects Exact. Under Grouped, on a driver whose queue merges consecutive submits (Mesa's common
  queue: ANV, RADV, lavapipe, NVK and the rest), the scheduler holds ready batches of one VkQueue
  and submits up to four in one vkQueueSubmit, only the last signalling, so Mesa merges them into
  one kernel submission:
  - a batch whose only signals are events' joins, the group's end signalling each event to the
    highest index held; a batch waiting for a signal the group holds sends the group first;
  - only a group's first member may wait for anything not yet seen complete, since Mesa gathers
    every member's waits before the first member's commands; a later waiter goes alone after the
    group in the same call. Metal never holds one command buffer back for another's wait;
  - batches that cannot join (first work, binary semaphores, fences, sparse updates, wrapped
    images, storage-form switches) submit the held group first;
  - a pass that finds nothing ready keeps the group held while two or more earlier submissions of
    its queue are not seen complete, gated on the second-to-last, so commits arriving meanwhile
    join. It goes once full, when a head waits for the GPU, or when a thread waits for one of its
    command buffers;
  - a held batch that ends its command buffer turns Scheduled, takes its kernel end time and runs
    its submission handlers as it is held, so waitUntilScheduled returns at once, as Metal
    schedules a command buffer committed behind running work within 0.2 ms;
  - submission checks run ahead for up to three batches behind a line's head, so checked command
    buffers are found ready together; a failed group restores its waits, signals its last value
    and fails each member once; the group's submission allocates nothing.
  New degradation kind grouped-completion (Precision), announced once per device: a group's
  members but the last are seen complete late, by at most three later batches' GPU time plus one
  completion turn, and intermediate event values are seen late, never wrong.
- An event-signalling batch's end goes into its work's last command buffer, as every other batch's,
  unless its signal must wait for another queue's earlier signal.
- DevicePolicy::batch_order, BatchOrderPolicy { Ends (default), Exact }; exact_answers() selects
  Exact. On ANV, RADV and NVIDIA's driver, measured to run a queue's submissions one after another,
  each batch ends with a barrier to every later command of its queue, the tracker takes an earlier
  batch of that queue as ordered (no barrier per dependency), and a batch's start timestamp with
  nothing planned before it is written at the bottom of the pipe. Other drivers and Exact keep the
  barriers per dependency.
- WorkCounts: grouped_submissions, batches_grouped, group_ends_full / _wait / _apart /
  _first_work / _drained / _checks / _held, event_waits_met, batches_with_none_pending and kin by
  pending depth, groups_kept_pending and groups_sent_for_waits; frame_costs prints them, with
  kernel submissions and ioctl time where the i915 execbuffer script is loaded, and gains guest-
  shaped legs over 260 and 520 host imports.
- Docs: FAST-PATHS rows for both policies (the grouping row with the guest's frame rates), API.md
  entries, add_submission_handler's doc, the runtime README and the scheduler modules' docs.

Why: each fewer kernel submission saves the scheduler thread an ioctl of about 80 to 130 us there,
and each barrier per dependency buys nothing on drivers that run a queue's submissions in order.
The bound of four was kept: eight measured about three fewer submissions a frame for twice the
completion lateness and no frame-time change.

Verified:
- Iris Xe, guest shape over 520 host imports, Grouped against Exact: 26.2-26.7 execbuffers a frame
  against 67.0, ioctl 2.77-2.81 against 6.89-6.96 ms, scheduler 52-53 against 122-123 us per
  command buffer, through completion 5.98 against 8.70 ms a frame.
- UHD 770, the held group at a 1 ms commit pace: 25.0 kernel submissions a frame against 58.1,
  scheduler 67-82 against 113-124 us per command buffer, the same frame time and GPU idle;
  completion seen 1.82-1.86 ms after GPU end against 0.43-0.46 ms.
- In the guest on the Iris Xe, Grouped made 24.4-27.5 kernel submissions a frame against Exact's
  42.4-43.8 and saved 0.4-1.7 ms of scheduler CPU a frame; the frame rate was alike within
  boot-to-boot noise (15.7-17.3 against 16.4-17.6 fps).
- runtime_lane::grouped_submissions (held signals on one and two queues, waiters leading, groups
  held behind running work with and without submission handlers and checks, both policies, the
  validation layer silent): 19 of 19 on ANV and lavapipe; the held-handler case fails without its
  change. commit_work, gpu_times, grouped_submissions, queue_order, events and first-use lanes 77 of
  77 on the Radeon 780M, RX 7900 XTX and RTX 5080; under synchronization validation 34 of 34 on
  the UHD 770. The runtime's device tests 1066 of 1066 on ANV; the unit suites 4534 of 4534.
- clippy -D warnings (plain, m2v_gpu, m2v_cpu_icd) and rustdoc.
2026-10-19 00:16:00 +03:00
Anees Iqbal 2b97fc1cf0 Render packed 16-bit, 8-bit sRGB and RGB9E5 attachments the device cannot render through integer views of their words
The RTX 5080 samples A1BGR5Unorm, ABGR4Unorm (and every other 16-bit packed order), R8Unorm_sRGB,
RG8Unorm_sRGB and RGB9E5Float but renders none of them, and lavapipe renders neither 8-bit sRGB
format. A render target, clear or draw of such a texture was refused as the device lacking the
format, which ends the guest of any app that renders to one. They now render through an R8_UINT,
R16_UINT or R32_UINT view of the same bits, the fragment function writing Metal's word.

What changes:
- metal::format::WordAttachment (public, with WordField): a format's fields in its word (packed
  16-bit layouts named from the least significant bit, Srgb8, Rgb9e5). WordAttachment::of holds
  where the device samples the format (or its UNORM twin), does not render it, and renders the
  word's integer format: derived from format features alone, on every driver.
- Translator: LoweringInputs::word_colors names such attachments. The fragment output to one is
  declared as a uint and each return stores Metal's word: a packed channel h(x) to nearest even,
  NaN 0, clamped to [0, 1], times the maximum code, rounded to even; an sRGB channel through
  Metal's twelve-bit table; RGB9E5 by the truncating kernel-write rule (shared with the storage
  write, lower::texture::rgb9e5_word). The cache codec carries the new fields.
- Partial write masks and blends:
  - in the pixel interlock (where the device orders fetch through it alone), a packed 16-bit or
    8-bit sRGB word's partial mask merges the kept fields from the word read first;
  - a packed 16-bit word's blend other than One/Zero decodes each code as Metal's blend reads
    it, h(c / m), blends in half as the 8-bit unorm blend does and encodes Metal's word. Metal's
    tile holds a pass's earlier result finer than the codes, so this is a near-equivalent within
    one code, recorded as PrecisionNote::DeviceColorConversion and announced; the exact form (the
    extended-range half shadow taken by word attachments) is a FAST-PATHS "not built yet" row;
  - where fetch reads rasterization-order input attachments (lavapipe), an 8-bit sRGB word's
    partial mask merges over its input attachment (new RuntimeFact::WordInputMerge), per sample in
    a multisampled pipeline.
- Runtime: the texture's image keeps its own format, sampled and blitted natively, made mutable
  with extended usage and the word view listed; the pass's attachment is the view; a pass clear
  writes the word of Metal's clear.
- New degradation kind shared-exponent-kept (Precision): Metal's tile store normalizes a loaded
  RGB9E5 word whose largest mantissa is below 256 in each tile a draw reaches, which a Vulkan pass
  keeps; announced at each such draw, with a FAST-PATHS row.
- DeviceColorConversion's rustdoc states that Metal blends a packed 16-bit attachment against its
  tile's finer values within a pass.
- Still refused, recorded as FAST-PATHS known gaps: colour inputs and resolves of word
  attachments, blended or fetched sRGB words, an output of fewer than four lanes for a blended
  packed word, RGB9E5 half outputs, blends, masks, inputs and resolves.
- New owned fixture engine/wm_samples and runtime_lane::word_samples for the multisampled merge.

Why: these formats are Metal render targets the guest uses, and the device holds and samples them;
only rendering them directly is missing.

Metal's rules, measured with plain Metal on the M3 Max under macOS 27.0.1: 65,536 float4 and half4
outputs and 4,096 clear colours per packed format, 0 texels off the rule; a One/Zero blend stores
the same bytes; the blend sweep (2,891 states, 8,192 random pixels, four packed formats, half and
float, fast and safe maths) gave Metal's code in every channel without fast maths and within one
code under it; within a pass Metal's tile holds a packed attachment finer than its codes (blends
in one pass follow the unrounded value, across two passes the stored codes); RGB9E5 draws and
clears 65,536 of each, 0 off.

Verified:
- Translator and runtime unit filters on gem10: 162 of 162 and 258 of 258 (word attachments),
  394 (partial masks in the interlock), 370 and 422 (blends, including 864 words the M3 stored
  checked on the interpreter), 538 (sRGB and RGB9E5 words), 38 and 108 (input-attachment merge).
- On lavapipe: runtime_lane::color_writes 5 passed, RG8UnormSRGB under the red mask 0 of 107,814
  channels off where it was refused before; word_samples, 64 texels of 4 samples merged, the edge
  texels keeping both greens; public_fixtures_engine with the new rows.
- clippy -D warnings (plain, m2v_gpu, m2v_cpu_icd) and rustdoc.
2026-10-19 00:15:59 +03:00
Anees Iqbal 697c55d514 Announce a loaded snorm or RGB9E5 attachment's kept codes, and store them as Metal's tile store does under TileStorePolicy::Exact
Metal's pass, once it draws, writes each 32x32 tile a draw reaches back through its texels'
values: a signed normalized channel's minimum code (-128, -32768) reads as -1.0 and is stored as
the code above it, and an RGB9E5Float word whose largest mantissa is below 256 under an exponent
above 0 is stored normalized. A Vulkan pass's load and store keep those bytes.

What changes:
- New degradation kind snorm-minimum-kept (Precision), announced at every draw and indirect
  execution in a pass that loads a single-sampled R8, RG8, RGBA8, R16, RG16 or RGBA16 Snorm colour
  attachment and keeps it, naming each such attachment. It joins shared-exponent-kept for RGB9E5.
- New DevicePolicy::tile_store, TileStorePolicy { Device (default), Exact }; exact_answers()
  selects Exact. It is the runtime's choice alone and keys no profile. Under Exact the load pass
  that already rewrites extended-range, padded and bfloat attachments also takes a single-sampled
  snorm or RGB9E5Float attachment in the tiles the pass's draws reach, with two new
  bind::unused_bits_module rules (SnormMinimum, SharedExponent; the module is keyed by
  PixelFormat), and nothing is announced. An attachment the load pass cannot take keeps the
  device's load and store, announced.
- New answer fact DriverFact::TileStoreIsMetals for MoltenVK 1.4.1 on Apple's GPUs: its render
  pass is a Metal render pass, so its tile store is Metal's for both kinds. There neither value
  adds a load pass or a notice.
- Docs: one FAST-PATHS row for the switch, its cost the load pass's measured GPU time; a known gap
  for lavapipe, which states no blend for any snorm format, so a blending snorm pipeline is
  refused there; API.md's policy bullet and catalogue entries; the unreached-tiles-rewritten text.

Why: a code no Metal write leaves, but uploaded or copied bytes may hold, reads back differently
after a drawing pass. The exact form costs a copy of the render area through a dispatch before
every such pass, so the device's store stays the default, announced, and Metal's store is a
switch away.

Verified:
- Metal's behaviour probed on an M3 Max under macOS 27.0.1 (70x40 targets of five snorm formats):
  a pass that draws nothing moves no code; a tiny triangle moves every minimum code of its first
  32x32 tile and none elsewhere; a blended full-target draw moves all of them; a blit there and
  back moves none. The guest's sweep showed the same on R8Snorm and RG8Snorm.
- Unit tests: unused_bits (both rules against CPU models over every code, the M3's example
  RGB9E5 word, the masked-tile rewrite), fast_paths (the row, no profile key), driver_facts,
  api_surface, owned_divisions: 38 passed on gem10.
- runtime_lane::snorm_tile_store under Device and Exact for both kinds, asserting load-pass
  counts, bytes and notices: on lavapipe with padded_loads, extended_range_blends and the notice
  site check, 15 passed (Exact took the load pass, Device announced); on the M3 Max under
  MoltenVK 1.4.1, 4 passed through the fact (no load pass, no notice) and 11 more beside them.
- The load pass's cost (FAST-PATHS): on the Radeon 780M, a 1080p pass per frame of BGRA10_XR
  1958.8 us against RGBA16Float's 135.3 us; the snorm and RGB9E5 cases take the same pass, not
  timed alone.
- clippy -D warnings (plain, m2v_gpu, m2v_cpu_icd) and rustdoc.
2026-10-19 00:15:59 +03:00
Anees Iqbal 25e4162cf6 Write, sample and resolve 8-bit sRGB and RGB9E5 textures through UNORM or integer views with Metal's codes
Where a device cannot store, sample or render an 8-bit sRGB or shared-exponent format directly,
the texture now goes through a view of a format the device does handle, and the shader applies
Metal's own encode or decode. Before, these textures were refused or read wrong values with no
notice.

What changes:
- Storage. An R8Unorm_sRGB or RG8Unorm_sRGB storage texture on a device without sRGB storage (the
  RTX 5080) writes through its R8_UNORM or R8G8_UNORM view with Metal's sRGB encode, and a
  read_write read decodes through Metal's table, as RGBA8Unorm_sRGB already did. The sRGB format
  stays the image's own wherever the device holds it, so the texture keeps its render-target
  usage; the UNORM twin is the image's format only where the device holds no sRGB image at all.
  A BGRA8Unorm_sRGB storage texture whose twin needs storage access without a format (ARL,
  Pascal, ANV on the Iris Xe for read_write) falls back to an Rgba8 view that encodes, then swaps
  red and blue (StorageImageClass::SrgbEncodeBgra).
- Shared exponent. An RGB9E5Float storage slot takes a new class, SharedExponentBits, on every
  device: an R32_UINT view whose word the shader computes in integer arithmetic with Metal's
  truncating encode, since Vulkan's conversion rounds each mantissa up where Metal truncates.
- Sampling. A device that samples an sRGB format's UNORM twin but not the format (the RTX 5080
  with RG8Unorm_sRGB) samples the twin, and the function decodes with Metal's table (a new
  srgb_twins variant set), announced SrgbTexelDecode. A swizzle that moves alpha into a colour
  channel, or a colour into alpha, decodes before swizzling. A float gather decodes by Metal's
  table on every device without Metal's own sampler unit. Under SamplingPolicy::Exact a runtime
  sampler's one-texel sample reads the slot's raw view and decodes its code through Metal's table.
  Device::pixel_format_capabilities answers Filter for such a texture by the twin's filter.
- Resolves. The exact shader resolve of an 8-bit sRGB attachment reads its samples and writes its
  result through views in the UNORM twin, so codes move as an 8-bit unorm channel's do, with no
  midpoint or linear-value table. The stored codes are unchanged.
- Docs: the FAST-PATHS native sRGB row covers the twin's filtered sample (exact for one texel and
  adjacent codes, up to 0.286 off between codes 0 and 255); known gaps scope a runtime sampler's
  nearest sample under native sampling.

Why: the consumer's guest on the RTX 5080 refused kernel writes to these formats and pipelines
sampling them, and an in-guest comparison under exact sampling showed BC sRGB cells off.

Metal's rules, probed on the M3 Max under macOS 27.0.1: an sRGB write clamps to [0, 1], scales by
4095 to nearest even and stores the largest code whose table step is at most that index, alpha
x255 to nearest even; a read is step / 4095. An RGB9E5 write clamps each channel to [0, 65408],
takes the exponent of the largest and truncates each mantissa; 0 of 65,536 float and 65,536 half
texels off, and every read exact.

Verified:
- New lane runtime_lane::shared_exponent_storage, and srgb_storage widened to R8 and RG8 and to a
  device without storage access without a format (lavapipe), against Metal's bytes.
- On the Iris Xe (ANV): runtime_lane::resolve_rounding 5 passed, 0 channels off Metal's rule for
  every closed format at 2 and 4 samples, sRGB included; the runtime's own BGRA8UnormSRGB 4x
  resolve at 1080p went from about 2.2x an RGBA8Unorm resolve's GPU time to about the same
  (2138 -> 1635 us for the write side alone, edge-dense 4193 -> 2638 us).
- Translator unit filters on gem10: 42 of 42 (shared exponent, image plans, storage choices), 58
  of 58 (sRGB raw, fast paths, the sRGB filter), 251 (sRGB, linear and sampler, the raw one-texel
  sample tests among them, which fail without the change), bind::color_resolve 25 passed; runtime
  image_plan 31 of 31.
- clippy -D warnings (plain, m2v_gpu, m2v_cpu_icd) and rustdoc.
2026-10-19 00:15:59 +03:00
Anees Iqbal 930d746df7 Read ASTC, ETC2/EAC, PVRTC and 4:2:2 textures the device lacks through twins of Metal's decode
On a device without a texture's compressed or chroma format, the runtime now makes the texture and
reads it as Metal does. Before, such a texture was refused at its making (ASTC, ETC2/EAC) or at its
first read (PVRTC, 4:2:2, held for copies alone). The consumer's guest on the RTX 5080 stopped at
ASTC_8x8_LDR, PVRTC_RGB_2BPP and EAC_R11Unorm. NVIDIA, RADV and lavapipe have none of these formats,
and Vulkan's 4:2:2 formats need a sampler Y'CbCr conversion whose chroma reconstruction is the
implementation's.

What changes:
- The store. The blocks lie in a carrier image of the same block bytes and shape (a compressed
  format the device copies: BC1, BC4, BC7, BC3, BC2, BC5, ETC2, EAC or ASTC 4x4; R8G8 for 4:2:2).
  replace_region, get_bytes, blits, fills and texture copies move Metal's blocks unchanged.
- The twin. Reads go to a decoded twin holding Metal's decode, kept in step on the GPU as a BC
  texture's twin is: a decode pass after a blit, a texture copy or a submitted CPU copy, and a CPU
  decode on the device's decode thread after a host write. No write costs a GPU-to-CPU round trip.
  A write's decode covers whole levels for PVRTC and whole rows for 4:2:2, whose texels read their
  neighbours. A new texture's twin starts at the decode of zero blocks (magenta for ASTC's error
  block), not at zeros.
- The decoders, our own, written from the Khronos ASTC specification, the Khronos Data Format
  Specification's ETC2 and EAC chapters, and Metal's measured answers for PVRTC1 and 4:2:2:
  bind::AstcDecode, EtcDecode, PvrtcDecode and ChromaDecode, with their GPU kernels
  astc_decode_module, etc_decode_module, pvrtc_decode_module and chroma_decode_module on the block
  decode's bindings (new api_surface rows, with AstcTexels, EtcTexels and DecodedTexelsPolicy).
- Metal's decode, matched: an ASTC LDR channel is (C >> 4) / 4095 of the 16-bit interpolated C;
  an 8-bit ETC2/EAC channel c / 255, an 11-bit one c / 2047 (signed c / 1023); PVRTC upscales
  colours A and B from the four block centres around a texel and blends them by its index; a 4:2:2
  texel takes its own green, and red and blue (3c + n + 2) >> 2 of its pair and the pair beside it.
- sRGB forms. The ASTC, PVRTC and ETC2/EAC sRGB formats read their twin's codes raw through an
  R8G8B8A8_UNORM view and decode them through Metal's table, as the 8-bit and BC sRGB formats do:
  reads, nearest samples and gathers exact, with no precision notice. Linear samples keep the
  device's sRGB filter (the exact sum under SamplingPolicy::Exact). A device that has the ASTC
  block keeps its own sRGB decode. The linear PVRTC and 8-bit linear ETC2/EAC formats take BC1 to
  BC3's Argb8 texel class, so under TexelConversionPolicy::Exact their reads are Metal's c / 255.
- The switch: DevicePolicy::decoded_texels, DecodedTexelsPolicy { Compact (default), Exact };
  exact_answers() selects Exact. Compact holds an ASTC LDR twin in 8-bit codes nearest Metal's
  12-bit value (at most 1/510 off) and an EAC 11-bit twin in the nearest 16-bit codes, announced
  decoded-texel-precision. Exact holds their floats. PVRTC, the 8-bit ETC2/EAC formats, the ASTC
  sRGB formats and 4:2:2 are exact under both. Tested by fast_paths; a FAST-PATHS row.
- Views in the other colour space. An ASTC texture viewed in its other colour space reads a second
  twin, made at the first such view: Metal reads that view exactly as a texture of the view's
  format over the same blocks, and the two forms widen endpoints apart, so one twin cannot serve
  both. Its decodes are queued on the device and recorded by the next batch with work. Counted by
  WorkCounts::second_twins, second_twin_checks and second_twin_decodes. PVRTC and 8-bit ETC2/EAC
  views of the other colour space share the one twin.
- Copies between a compressed texture and an uncompressed one whose texel is the block's bytes
  (BC1 or ETC2 with RG32Uint, BC7 or ASTC with RGBA32Uint) run with Metal's rule: every coordinate
  in the destination's texels, a block per texel. They were refused as formats of different units.
- Notices: carried-decoded-twin (Performance) on every twinned texture; decoded-texel-precision
  (Precision) only for an ASTC LDR or EAC 11-bit twin under Compact.
- Typed refusals: RuntimeGap::DecodedHeapTexture (a heap's ASTC texture, a sparse heap's carried
  texture; the heap size query refuses alike); views of the ASTC HDR form, of another footprint or
  PVRTC block, and of an EAC 11-bit format as its other signedness (Unsupported(TextureView));
  copies between PVRTC and an uncompressed format, between two compressed formats of one block size
  and different extents, and level or slice copies between compressed and uncompressed formats
  (NotImplemented(Format)). A device with the native format keeps the direct path.
- Docs: the API.md catalogue entries, the FAST-PATHS decoded_texels row and known gaps, and the
  module docs of astc.rs, etc.rs, pvrtc.rs, chroma_pairs.rs and decoded_twin.rs.

Why: Metal makes, reads and samples these textures on Apple GPUs, and the consumer's guest uses
them; the desktop Vulkan drivers have no such formats.

Verified:
- Metal's answers, probed on an M3 Max under macOS 27.0.1: ASTC (seeded random blocks, all 14
  footprints, linear and sRGB, read as float and half) bit for bit, digests pinned by
  seeded_blocks_read_as_metal_read_them; ETC2/EAC (4096 random blocks of each of the ten formats)
  digests equal; PVRTC (all eight formats) every digest equal; 4:2:2 every read, sample and gather
  bit for bit what an RGBA8Unorm texture of the decoded codes answers; the copy rule on every listed
  pair both ways.
- On the CPU SPIR-V interpreter each GPU kernel writes the CPU decode on every texel: ASTC on every
  footprint, linear and sRGB, Float and Unorm8, with blocks covering all 16 endpoint modes, every
  partition count, dual plane and void extent; ETC on every decode and both texel forms; PVRTC on
  every format. The kernels are valid on every committed profile.
- Runtime unit filters 63 passed and translator unit filters 183 passed (ETC2/EAC); the runtime's
  unit suite 952 of 953 (the one failure the recorder's module-list test, fixed with the recorder).
- On lavapipe: chroma_pairs, pvrtc_textures, the mipmap, fill, buffer-texture and degrade-notice
  lanes, 45 passed; format_copies, the whole module. A lavapipe batch caught PVRTC codes read one
  ulp high under exact answers, fixed by the Argb8 class.
- clippy -D warnings (plain, m2v_gpu, m2v_cpu_icd) and rustdoc on ms01 and gem10.
2026-10-19 00:15:59 +03:00
Anees Iqbal 6b322fb50f Cut the cold making of half-heavy shaders on ANV and RADV: controlled half rounding and the device's half widening
On Intel's ANV, CoreAnimation's A2Xghfc fragment shader (313k words) took
about 14 s to make cold, for each of three states. The consumer's x86 macOS
guest stalled with "no completion in 10 s" on its first boot. Native Metal
makes it in 0.48-0.56 s on the M3. brw (Mesa's Intel backend) spends that
time in its register allocator. Its interference build is quadratic in
instruction count, it spills, and it retries several scheduling modes. Most
of its input was our half arithmetic. Two cuts, each the cheaper form, are
taken on ANV and RADV.

1. A half result computed in float rounds through the device's conversion
   pair under the float controls (QuantizeForm::Controlled). It replaces
   OpQuantizeToF16 plus a denormal arm, about 11 NIR operations per lane.
   - The form: an OpFConvert to 16 bits and back, each decorated
     NoContraction, in an entry that declares RoundingModeRTE,
     DenormPreserve and SignedZeroInfNanPreserve for 16 bits, plus the
     modes the device's independence ties to them (ANV: RTE for 32 and 64
     bits; RADV: RTE and DenormPreserve for 64 bits). The modes are
     declared post-lowering (new ExecMode kinds), and the requirements
     carry the FloatControl properties.
   - Exact by the Vulkan spec under either HalfRoundingPolicy: conversions
     are correctly rounded, and NoContraction forbids folding the pair. No
     fact, no note.
   - A new DriverWorkaround, HalfConversionPairFolded, keyed on NVIDIA's
     proprietary driver, keeps NVIDIA on its previous forms. NVIDIA
     615.71.09 on the RTX 3090 folds the pair even under NoContraction and
     every mode combination, and the PackHalf2x16 and u16-bitcast forms
     fold the same way: 2,231,288,832 of 2^32 narrowings unrounded. A
     plain-Vulkan repro gives 16,775,680 of 2^24 unrounded on the 3090 and
     0 on ANV.
2. A half read from its bits (a load, a reinterpretation, a texel's bits) is
   the device's widening under NanMinMaxPolicy::Native, the default: each
   u32 lane is bitcast to f16x2 and converted to 32 bits, in place of a
   12-op integer decode. A half texel takes that conversion's NaN (no keep).
   - Every non-NaN half is exact by the spec: DenormPreserve covers
     "values obtained via unpacking an integer into a vector of values
     with smaller bit width".
   - A NaN's bits are the device's, recorded as NativeNanEncoding
     (native-nan-encoding), now also announced on ANV and RADV pipelines
     that decode halves. A half stored back unchanged keeps its bits.
   - NanMinMaxPolicy::Exact keeps the integer decode and the keep. There,
     every half widened to float answers Metal's 0x7fc00000 for a NaN, as
     the M3 does over every pattern from memory, constant memory, selects
     and texels.

Where brw's time went, measured on A2X (a2x-s96): after cut 1, 49.6k NIR
operations, of which the rounding pairs were about 10.7k, half decodes from
memory 8.6k and texel NaN keeps 2.6k. The rest was below 5% each.

Exactness probes:
- Cut 1 (candidate half(x) over all 2^32 f32, and half + - * over every
  pair): 0 non-NaN mismatches on ANV Iris Xe (Mesa 26.2.4), RADV 780M
  (Mesa 26.2.4), and the 780M and RX 7900 XTX (Mesa 26.0.8).
- Cut 2 (every half pattern): 0 non-NaN differences on ANV and RADV.
- The M3 confirms Metal equals the integer reference everywhere.

Cold making (A2X, base against each cut):
- ANV Iris Xe: 13.6-14.3 s, then 5.75-6.16 s, then 4.06-4.36 s. Peak RSS
  1.28 GB, then 0.50, then 0.35. GPU time per draw 4.62 -> 4.48 ms.
- RADV 780M: 0.80-0.84 s, then 0.53-0.55 s, then 0.38-0.47 s. GPU time per
  draw 4.05 -> 3.43 ms after cut 1, then within its clock states' spread.
In the consumer's cold boots on ms01 (Iris Xe), A2X went from 14 s per
state, plus two 38 s remakes, to 4.0-4.3 s. The suite's pipeline making went
from 126 s to 16.7 s, with no stall. Repeat boots show metalwin unaffected:
its frame rate follows other GPU work at session start, not this change.

Tests:
- engine_native_half: the controlled conversion, and a half read from memory
  under both NaN settings, NaNs stored back.
- device::tests::profile::nvidia_carries_the_folded_half_conversion_pair.
- lower::arith::tests: narrow, round_texel, half_texel, texel_round.
- spirv::requirements; spirv::builder::ops.
- Updated expectations: engine_arith half rounding, engine_spirv_cross_forms
  fma, engine_metal_routines frexp (the device's NaN under the default,
  Metal's under Exact).
- The validation lanes driver_deviations and native_maths expect the
  controlled form.

Docs: the FAST-PATHS half-rounding row (scope) and a new row for the
widening; the NativeHalfConversion and NativeNanEncoding entries in API.md and
their rustdoc; HalfRoundingPolicy and NanMinMaxPolicy rustdoc; HOWTO's driver
note; REFUSALS regenerated. A known gap is added to the texel-NaN row: on
ANV a 16-bit float NaN texel kept as half reads back 0xFE00 from ANV's image
decode, even under Exact (announced as device-nan-encoding). SEMANTICS_VERSION
1759, runtime pin recomputed, RUNTIME_VERSION unchanged.

Tables: the golden hashes, 274-389 cells on each ANV and RADV column across
both cuts, and NVIDIA's profile fingerprints, whose words are unchanged. The
authored compile census: artifact hashes on the 780M and RPL-P ANV columns,
with no status change. No MoltenVK, lavapipe or floor cell moves.

Verified on development-fast (batches f18-f24): every lane green on the RTX
3090, ANV Iris Xe, RX 7900 XTX, both 780Ms, lavapipe and the M3 Max, plus the
CPU suites, case qualification, clippy in every configuration, docs and
packaging. Not run on the RTX 5080 Laptop (host offline; whether its driver
keeps the pair is unmeasured).
2026-10-17 11:14:51 +03:00
Anees Iqbal b7da00074a Filter a two-plane YCbCr texture with the device's sampler by default, Metal's filter behind YCbCrFilterPolicy::Exact
A draw that bound a two-plane YCbCr texture (YCBCR8_420_2P and its kin) at a
linearly sampled slot made a second VkPipeline at the draw. The slot's YCbCr
variant (RuntimeFact::YCbCrTexture) emulated Metal's filter of the format, and
the state's creation never predicts it, since the predicted key binds no
texture. On ANV, CoreAnimation's A2Xghfc paid 37.8 s for that second making,
inside a command buffer, past the x86 guest's 10 s watchdog.

Under the owner's rule (fast by default, exact on request, both kept, the
difference logged), the default is now the device's own filter. A new
DevicePolicy field, ycbcr_filter, selects the form:

- YCbCrFilterPolicy::Device, the default.
  - On a device that samples natively (ANV, RADV, NVIDIA, lavapipe),
    ProfileFields::ycbcr_variant is false. The slot records no fact and is
    filtered by the device like any other, and a draw takes the pipeline its
    state's creation made. The module's PrecisionNote::DeviceSampling
    (device-sampling) states the bound.
  - On MoltenVK, Metal's own sampler filters the slot's converted view
    (RGBA16Float on the 1/2048 grid, RGBA32Float on 1/8192).
    lower::sampler::linear::metal_filtered_ycbcr records the
    HalfSampleFilter/FloatSampleFilter note under the bound format alone
    (SpecKey::BoundTexelFormat). The runtime's degrade_bound_formats
    announces it as ycbcr-filter-not-exact, naming the slot and the format.
    A one-texel half sample on the 8192 grid records HalfTexelConversion
    under that format and is announced at the draw.
- YCbCrFilterPolicy::Exact keeps the variant: Metal's filter, through one
  pipeline made at the first draw binding such a texture.
  DevicePolicy::exact_answers() sets it. On MoltenVK, SamplingPolicy::Exact
  takes the variant too. Over a compiler limit, the native-sampling fallback
  (ReducedForms) drops it with sampling and reports it.

Bound of the default, in codes of 1/255. Each figure is the largest
difference of any channel over five surfaces (420v/420f; BT.601, BT.709,
BT.2020), 65,536 random coordinates and 960 on the 1/256 grid, float and half
results. Measured against Metal's sum (checked equal to metal_step):
- NVIDIA RTX 3090 (615.71.09): 1.183
- ANV Iris Xe RPL-P (Mesa 26.2.4): 1.058
- RADV 780M and RX 7900 XTX (Mesa 26.0.8): 0.877
- lavapipe (Mesa 26.2.4): 0.872
- MoltenVK against Metal's own YCbCr filter (M3 Max, macOS 27.0.1, plain
  Metal): 0.1245 for RGBA16Float and half results; 0.0157 for RGBA32Float
  float results.

Reproducer (corpus-draw-ab on ANV, cold, a2x-s96 with
RGBA8Unorm:linear@3=YCBCR8_420_2P): before, two pipelines (13.9 s at
creation, 37.8 s at the draw), 52.3 s wall, 3.23 GB. After, one pipeline
(13.9 s), 14.3 s wall, 1.30 GB.

Tests of both settings:
- a_device_takes_the_ycbcr_variant_only_under_the_exact_filter (lavapipe and
  MoltenVK).
- The runtime lane's default tests on native-sampling devices and on
  MoltenVK: no pipeline at the YCbCr draw, bit for bit the RGBA16Float twin's
  draw, the expected announcements once. The exact twins expect the variant.
- fingerprint_covers_every_policy_field.
- metal_s_own_answers_key_the_same_under_either_choice.
- The notes test helper (engine_linear_half::notes_bound) now gives
  BoundTexelFormat the bound texture's class, as the runtime does.

Docs: the FAST-PATHS row and its MoltenVK bound, the API.md
ycbcr-filter-not-exact, device-sampling and half-texel-conversion entries,
the policy, profile-field, fact, lowering and runtime-kind rustdoc, and
REFUSALS regenerated. SEMANTICS_VERSION 1757, RUNTIME_VERSION 1314, runtime
pin recomputed.

Tables: the golden hashes (38 cells per natively sampling column, both tables;
every profile's fingerprint for the new policy field, MoltenVK's again for its
default) and the authored compile census (187 cases on 10 native-sampling
columns, 193 on moltenvk-m3). All are artifact hashes, with no status change.

Verified on development-fast (batches f15-f19, f24): every lane green on the
RTX 3090, ANV Iris Xe, RX 7900 XTX, both 780Ms, lavapipe and the M3 Max
(MoltenVK), plus the CPU suites, case qualification, clippy in every
configuration, docs and packaging. Not run on the RTX 5080 Laptop (host
offline). The consumer measured YCbCrFilterPolicy::Exact on MoltenVK as byte
for byte the previous variant (80 of 80 tests on the M3).
2026-10-17 11:14:19 +03:00
Anees Iqbal 01841476dd Compute Metal's 8-bit unorm blend of a fetched attachment for every factor, mask and blend color
Through the pixel interlock (RADV, ANV, NVIDIA, MoltenVK) a fetched attachment is a storage image,
so the shader computes Metal's blend. For R8Unorm, RG8Unorm, RGBA8Unorm and BGRA8Unorm only
premultiplied source-over with every channel written was built; every other blend, any write mask
that keeps a channel, and the blend color stayed FramebufferFetch / NotImplemented at the color.

What: Blend::unorm8 now plans every factor and operation but the second source's, under any write
mask, with the blend color, through the 16-bit planner's forms as Metal's compiler builds them for
an 8-bit unorm attachment (Family::Unorm8, measured, below):
- an inner sum adds the destination's atoms before the source's (Order::Destination);
- a lerp takes y from the destination's product first; alpha takes no lerp of the destination
  alpha beside itself or held by both products;
- of an added pair, the destination's product is rounded first where unorm8_rank(fs) >= rank(fd)
  (tables per half/float arithmetic and color/alpha);
- alpha shares the one minus the blend alpha, source alpha and destination alpha (SourceAlpha-
  Saturated's too) that stored color lanes compute; with no color channel stored, the one minus
  an alpha the color channels' destination factor is; a min or max computes no factor. A shared
  one minus blocks a lerp of the blend or destination alpha and stays whole where added from the
  destination's product;
- a write mask of one color channel plans that channel as a scalar (Order::Scalar: Da, D, Sa,
  S): no splat rules, but a one minus an alpha that its destination factor is, or that alpha's
  factors compute (alpha stored or not), stays whole and takes no lerp.
blend_unorm8 reads the blend color from PushField::HalfBlendColor's f32 words: NaN to 0, clamped
to [0, 1], rounded to half in half arithmetic; OneMinusBlendColor reads h(1 - h(c)) (f(1 - c) in
float) under either math. fetch.rs pushes the field where the blend reads it and merges the
channels the mask leaves out after the blend, as the 16-bit form does. Because Metal's forms depend
on the mask, compiled_write_mask splits a blended RGBA8Unorm/BGRA8Unorm attachment's partial-mask
class in three (alpha alone, one color channel with or without alpha, two or more color channels);
other formats keep one partial class. Without that split a one-channel mask compiled under the
two-channel class and missed Metal's code in 64 of 4096 texels on the 3090 and the 780M. Without fast math every
state takes the rounded forms. Refused, NotImplemented(FramebufferFetch): a second-source factor;
under fast math a lerp, common factor or contracted pair into R8Unorm or RG8Unorm (Metal sums
those in forms of their own, EV FB8-r8-m3); every other format, now named in FAST-PATHS' known
gap with the source-over survey's result (10-bit unorm and RGBA8Snorm fit the 8-bit model with
their clamps; the 16-bit norms and RGBA32Float blend in float even for half4; their factor sets
are not measured). No PrecisionNote or DevicePolicy kind is added: every built blend is exact.

Metal's arithmetic, plain Metal on the M3 Max (macOS 27.0.1), our own MSL, 512 x 512 targets: every
destination code against every source alpha code (two blocks) plus random blocks with sources out
of range, infinite or NaN; half4 and float4, fast and safe; BGRA8Unorm unless named:
- EV FB8-sw2-m3 (seed 388824, blend color 0.3/0.6/0.9/0.45): every factor/operation pair for color
  beside source-over alpha (676), the reverse (676), and the same pair for both (677).
- EV FB8-rnd1-m3 (seed 424242, color 0.7/0.15/0.55/0.8): 600 random state pairs.
- EV FB8-mk1-m3 (seeds 1000 + mask): masks 1 to 14, 300 random states each.
- EV FB8-bc1-m3 (seeds 2001-2003): blend colors past both ends of every channel.
- EV FB8-sc1-m3 (seed 7): one color channel: all 153 color keys with a lerp or common-factor
  candidate beside 13 alpha keys (none, OMSA, OMDA, OMBA, OMSC, OMDC, OMBC, mixes), masks B and B+A.
- EV FB8-ao1-m3 (seed 9): alpha alone: all 432 alpha keys with a lerp, common or contracted form
  beside 8 color keys.
- EV FB8-mk3-m3 (seeds 1000 + mask): masks 1, 2, 3, 4, 5, 8, 9 under two random sets of 300.
- EV FB8-mm1-m3: a min or max beside one-minus factors, full mask, one channel and alpha alone.
- EV FB8-r8-m3 (seed 3001): R8Unorm and RG8Unorm, same/color/random400: safe math exact in every
  state; fast-math misses only lerp, common and contracted forms; single, fused, zero and min/max
  forms exact in every state.
The model fits every state of each EV (0 mismatched channels), and the Rust planner's plans equal
the model's on 240,480 states (each sweep state under ten masks with and without alpha, plus the
explorer states, half/float x fast/safe), compared through a scratch dump.

Tests: arith::tests::blend8 adds the interpreter over a state of each rule (source alpha over,
the blend color's lerps with a color past both ends, blue alone, alpha alone; half and float, fast
and safe) against hand-written Metal arithmetic, and the no-alpha refusals; tests::engine_fetch_blend8
compiles eight other blends and masks (blend color pushes HalfBlendColor, nothing announced) on
every interlock committed profile and keeps second-source factors refused; engine_fragment's
interlock test now expects RGBA8Unorm's blend computed. runtime_lane::framebuffer_fetch::blend8
adds other_blends_masks_and_the_blend_color_store_metals_blend: the four states into BGRA8Unorm
through each fixture's half4 and float4 loads on the device, every texel against the model.

Verified on gem10 at the content of this commit (WIP a395835, plus REFUSALS regenerated):
- cargo fmt --check; clippy --workspace --all-targets --all-features -D warnings in plain,
  --cfg m2v_gpu and --cfg m2v_cpu_icd; rustdoc -D warnings.
- metal2vulkan nextest -E 'test(/eight_bit|blend8|blend16|fetch/)': 90 of 90 passed.
- metal2vulkan-validation -E 'test(/eight_bit|framebuffer_fetch/)' (release, m2v_gpu) on the RTX
  3090: 56 of 56. Every draw went through the pixel interlock with Metal's 4096/4096 texels and
  nothing announced: the 24 source-over draws and the 16 new ones (four states x two fixtures x
  half4/float4). On lavapipe (m2v_cpu_icd): 56 of 56; the device blends through input attachments
  and announces HalfOutputFastMathBlend and DeviceColorConversion.
- The 780M was held by reims-vgpu at the final run. One run earlier, before the mask-class split,
  it agreed texel for texel with the 3090, including the one-channel miss the split fixes.

SEMANTICS_VERSION 1754 -> 1755: the translation of these blends and the mask classes changes.
RUNTIME_VERSION and the runtime-sources pin are unchanged. docs: the FAST-PATHS known gap (what is
built, what is refused, and the other formats' survey), the API.md degrade catalogue, and
REFUSALS.md regenerated.
2026-10-17 11:13:19 +03:00
Anees Iqbal bc90b127f1 Compute Metal's 8-bit unorm source-over blend of a fetched attachment in the shader
The x86 macOS guest refused a render pipeline on every interlock device (RADV, ANV, NVIDIA,
MoltenVK): framebuffer fetch of a BGRA8Unorm color 0 blended One / OneMinusSourceAlpha (add,
color and alpha, mask 0xf) beside an RGBA16Float color 1 of mask none was
FramebufferFetch / NotImplemented at Color(0). Through the pixel interlock the fetched attachment
is a storage image, so no Vulkan blend applies and the shader must compute Metal's blend; only
the extended-range and 16-bit float blends were built.

What: Blend::unorm8 plans premultiplied source-over into R8Unorm, RG8Unorm, RGBA8Unorm and
BGRA8Unorm storing every channel, half4 and float4 outputs, fast and safe math, through the 16-bit
float planner's forms. blend_unorm8 clamps the output to [0, 1] (NaN to 0), reads the texel's code
exactly (RoundEven(texel * 255), then the existing exact division to f32, then half for a half4
output), and blends in the output's type: fast math fuses (h(fma(d, h(1 - a), s))), safe math
rounds each step (h(s + h(d * h(1 - a))), likewise in float). fetch::unorm8_blended then rounds the
result's code by Metal's 8-bit unorm write (color_write's Unorm{8} rule). The blend takes channels
in Metal's order from read_texel and hands them to emit_return's metal_order exchange, so ANV's
RGBA twin of a BGRA8Unorm attachment takes it unchanged. Any other blend of an 8-bit unorm
attachment, a write mask that keeps one of its channels, and every other format stay refused as
before (FramebufferFetch / NotImplemented). The color write plan treats a shader-blended 8-bit
channel as rounded in the shader, so it records no device-conversion note. No PrecisionNote or
DevicePolicy kind is added: the blend is exact.

Metal's arithmetic, measured with plain Metal on the M3 Max (macOS 27.0.1), our own MSL of the
guest's shape:
- EV FB8-dec1-m3 (seed 1): a fetch of every code reads h(c / 255) as half4 and f(c / 255) as
  float4, every channel of every format. A plain write stores the code of the value clamped to
  [0, 1] (NaN to 0) times 255, the exact product rounded half up.
- EV FB8-sw1-m3 (seeds 1000 * run + (output is float), runs 0 to 3; 4096 x 961 targets): every
  half alpha in [0, 1] (15,361) against every destination code of each channel, four source draws
  per pair (aimed within four ulps of a code midpoint, 2% out of range, infinite or NaN). That is
  63 million channels per variant (BGRA8Unorm, RGBA8Unorm, RG8Unorm, R8Unorm x half4, float4 x
  fast, safe), and the model above gives Metal's code in every channel: 0 mismatches.
- EV FB8-fold1-m3 (seed 7, 2048 x 2048): nine products and sums of the output, the fetched color
  among them, half4 and float4, fast and safe. The clamp keeps all of them out of the blend, so
  fbl8_over_product is exact too (16-bit float folds it).

Tests: arith::tests::blend8 runs the interpreter over every alpha code's value against every
destination code (half and float, fast and safe, BGRA8Unorm and R8Unorm), and checks that another
blend, mask or format is refused. tests::engine_fetch_blend8 compiles the guest's shape on every
interlock committed profile (BGRA8Unorm on each, the ANV profile asserted, no skip) for four
formats and six entries, plus the whole guest pipeline. It asserts the storage form, no note,
link and validation, and that other blends stay refused at Color(0). At d188d8b771 (before this
change) a_blended_eight_bit_unorm_fetch_computes_metals_blend fails with the guest's refusal
("unsupported: FramebufferFetch; needs NotImplemented ... color attachment 0", amd-780m-radv
BGRA8Unorm). The fixtures fbl_fetch_blend8 and fbl_fetch_blend8_safe (our own MSL, regenerated
by scripts/regen-air-fixtures) feed runtime_lane::framebuffer_fetch::blend8, which draws each
entry into the four formats on the device and compares every texel with the model; their
golden printouts (tests/air_input) come from bless_engine_goldens under the pinned LLVM 21.

Verified (gem10, release where a GPU runs):
- clippy --workspace --all-targets --all-features -D warnings in plain, --cfg m2v_gpu and
  --cfg m2v_cpu_icd; rustdoc -D warnings.
- metal2vulkan nextest -E 'test(/eight_bit|blend16|fetch/)': 87 of 87 passed; -E 'test(/air_input/)'
  with METAL2VULKAN_TEST_REQUIRE_PINNED_LLVM=1: 7 of 7 passed.
- metal2vulkan-validation -E 'test(/eight_bit|framebuffer_fetch/)', 55 of 55 passed, on the RTX
  3090 (NVIDIA ICD) and on lavapipe (m2v_cpu_icd, LP_NUM_THREADS=1). On the 3090 every one of
  the 24 fixture x format draws went through the pixel interlock with Metal's 4096/4096 texels
  and nothing announced.

SEMANTICS_VERSION 1753 -> 1754 (translation of this shape changes). RUNTIME_VERSION and the
runtime-sources pin are unchanged. docs: FAST-PATHS known gaps (the interlock blend's coverage),
the API.md degrade catalogue (HalfOutputFastMathBlend), REFUSALS.md regenerated.


The blessed tables come in the same commit: golden_hashes.tsv gains 16 rows for
fbl_fetch_blend8 and fbl_fetch_blend8_safe, public_fixture_expectations_engine.tsv their 16
inventory rows in fixture order, and authored-compile.tsv only its product fingerprint (no cell
moves). Batch verification on development-fast: the fetch and blend filters green on the RX 7900
XTX, the 780M, the Iris Xe, the RTX 3090, lavapipe and the M3; the full suites at the bless green
on the Iris Xe, the XTX, the 780M and the M3 (7259 and 7274 tests). The RTX 5080 was not run.
2026-10-17 06:13:23 +03:00
Anees Iqbal fc9147534d Fetch a BGRA-order attachment through its RGBA twin without format-less reads
On a device that orders framebuffer fetch through the pixel interlock but
has no shaderStorageImageReadWithoutFormat (ANV), a fetched BGRA8Unorm or
BGR10A2Unorm color attachment was refused: SPIR-V names no image format
for B8G8R8A8_UNORM or A2R10G10B10_UNORM_PACK32, so neither the typed nor
the format-less declaration reached it. A guest pipeline of a fetched
BGRA8Unorm color 0 beside an RGBA16Float color 1 was refused on the Iris
Xe and aborted the consumer.

What changed:

- One public decision for the fetch storage view's format,
  StorageAttachmentUse::view_alias_of(format, profile) (the old
  uint_view_of took no profile). An 8-bit sRGB attachment keeps its
  unsigned-integer view. A BGRA-order format the device accesses without
  a format keeps its own format (RADV, NVIDIA, MoltenVK unchanged). One
  no declaration reaches takes its RGBA-order twin (R8G8B8A8_UNORM,
  A2B10G10R10_UNORM_PACK32) where the twin declares and stores. The
  compile layer (lower/fragment/fetch.rs) and the runtime
  (framebuffer_fetch::storage_view_format) both call it.
- The fragment reads and writes such an attachment through the twin,
  exchanging red and blue in the shared read and write helpers
  (read_texel, metal_order), so every read, written value, kept channel
  and per-sample plane sees Metal's channel order.
- The runtime makes the views: a BGRA8Unorm render target's free STORAGE
  candidate is made mutable to the twin (so ANV fetches it in place),
  and stand-ins and sample planes take the twin as their storage view.
- StorageAttachmentUse::format_usages names the view's format (the one
  the storage image is bound in), not the attachment's.
- Public rename: StorageAttachmentUse::uint_view and
  WriteSource::TileAttachment::uint_view become view_alias (serde keeps
  the old name as an alias), with StorageAttachmentUse::with_view_alias
  and view_alias_of.
- The refusal names both routes where neither reaches (a BGR10A2Unorm
  attachment without shaderStorageImageExtendedFormats).

The class, on a device without format-less storage reads: a fetch of a
16-bit packed attachment (B5G6R5Unorm, A1BGR5Unorm, ABGR4Unorm,
BGR5A1Unorm) stays a typed FramebufferFetch refusal, and a read of an
argument buffer's writable texture a typed ArgumentBufferTextures one;
both are FAST-PATHS known gaps. Kernel slots, tile passes and the depth
and stencil stand-ins already declare typed first.

SEMANTICS_VERSION 1753, RUNTIME_VERSION 1313, runtime-sources pin
recomputed. REFUSALS.md regenerated; docs/API.md says which view the
storage form binds.

Verified:

- Metal (M3 Max, macOS 27.0.1, our own MSL probe under the Mac GPU
  lock): BGRA8Unorm and RGBA8Unorm targets, 1x and 4x, masks of every
  channel and of red and alpha, one to three fetch_ordered draws: every
  byte matches the model the device test checks (c read as c/255,
  halved, written as the exact product with 255 rounded to nearest).
- ms01, Iris Xe (ANV, Mesa 26.2.4), release, --cfg m2v_gpu:
  runtime_lane::framebuffer_fetch::bgra passes with Metal's bytes in
  every case beside an RGBA16Float color 1 that keeps its clear. The
  BGRA8Unorm pipelines are made with view_alias R8G8B8A8_UNORM (4
  pipelines); single-sampled targets are fetched in place (no storage
  form switch, no fetch-through-scratch notice), 4x through sample
  planes viewed in R8G8B8A8_UNORM. The fetch lane
  (runtime_lane::framebuffer_fetch::, 47 tests) and
  tests::srgb_fetch_images pass there too: 48 of 48.
- ms01, debug: lower::fragment::fetch::tests (new: the twin on each
  of four ANV profiles for BGRA8Unorm and BGR10A2Unorm at 1x, in planes, under
  reads, writes and a red-and-blue mask; format-less profiles
  unchanged; both routes named; the refused class),
  engine_fragment::a_fetched_bgra_attachment_is_viewed_in_its_rgba_twin
  (the consumer's two-attachment shape on intel-irisxe-anv, 1x, 4x and
  a partial mask, the SPIR-V validated against the profile), with
  engine_fragment, engine_tile, cache::tests, pipeline::api_tests,
  pipeline::link::tests, fast_paths and api_surface: 217 of 217 pass.
  With the twin decision forced off, the five new translator tests
  fail, the consumer shape refused as on the Iris Xe (FramebufferFetch
  needs AnyOf([[ShaderStorageImageReadWithoutFormat]])).
- clippy --workspace --all-targets --all-features -D warnings clean
  plain, with --cfg m2v_gpu and with --cfg m2v_cpu_icd.
2026-10-17 06:13:23 +03:00
Anees Iqbal cc961dc744 Keep zero signs where an Exact answer needs them, and end a busy exit at once on Linux
One squash of development-fast d8546c940b..46649e335d (5 commits); the
tree equals 46649e335d.

- Exact float maths (FloatMathsPolicy::Exact off MoltenVK): a module whose
  checked product, checked OpFmaKHR or fma routine (Wide, Soft, HalfOdd)
  answers Metal's zero of its sign now declares SignedZeroInfNanPreserve at
  the routine's widths, or records DeviceSignedZeroInfNan where the device
  lacks the mode. A fast-math kernel declared no mode, so Vulkan let the
  device answer either zero sign: the RTX 3090 answered -0 where Metal
  answers +0. The default policy and MoltenVK are unchanged.
- Exit on Linux (glibc): an exit while the driver still runs the runtime's
  work (a section, a making, or a CPU device's work) ends at once with the
  exit's status and one line on standard error, as Metal's exit does not
  wait; the exit handlers registered before the runtime's do not run in
  that case (docs/API.md, Process exit). An idle exit is unchanged; macOS
  keeps its waits. The exit lane test expects the new ending.
- The exact golden hashes and the authored compile census re-blessed.

Verified at 46649e335d (batch f10), all green: RTX 5080 7248/7248,
RTX 3090 7248/7248, M3 7263/7263, Iris Xe, RX 7900 XTX and 780M
7248/7248 each, fuzz 8/8 on every venue; lavapipe 3823/3823, product
4824/4824, CPU validation 1331/1331; fmt, clippy (4 configurations),
Rustdoc, packaging, qualification, refusals, the API reference check and
doctests.
2026-10-16 20:54:15 +03:00
Anees Iqbal 20bd3793f3 Exact tiny products and fma, Metal's 16-bit blend zeros and new depth pattern, new notices, the ANV compiler-bound fallback, exit and barrier fixes
One squash of development-fast c66863112e..d8546c940b (27 commits); the
tree equals d8546c940b.

Exact float maths (FloatMathsPolicy::Exact only; the fast default is
unchanged):
- A tiny float product and OpFmaKHR flush to zero as Metal does; the
  native default announces the device's rounding first
  (float-tininess-after-rounding). The check is the compact form; its
  compile cost is recorded in docs/FAST-PATHS.md, and the check's own
  scaling multiply is NoContraction.

Now Metal's:
- A fetched 16-bit float blend's lone term takes Metal's zero under fast
  math (R16Float and RG16Float read alpha as 1).
- A new Private Depth32Float or Depth32Float_Stencil8 target's NaN pattern
  is switched on at the pass that loads it; where the device's test is not
  Metal's it is announced (signed-depth-test), and a clamping device
  announces fresh-pattern-zeroed.
- A render-target barrier from the fragment stage to an earlier stage
  orders the later passes' attachments.

New notices for differences that were silent: unmeasured group
speculation, an anisotropic sampler without mips (MoltenVK), a draw's
attachment read in place, a sample level the device's arithmetic chooses
(exact sampling off MoltenVK), and exact forms dropped to fit ANV's
compiler.

Crash and exit fixes:
- ANV: a render pipeline whose largest stage passes 400,000 words under
  exact forms is retranslated with them dropped until it fits
  (ExactFormsOverCompilerLimit), instead of a SIGSEGV in Mesa's register
  allocator.
- The exit hook sees a making that ends as it looks, and drains a CPU
  device's work at its first run only.

Measurements: the commit hand-off cost on the Iris Xe; the M3 under macOS
27.0.1 places heap blocks and copies compressed textures as the M4 does.

Tests fixed (heap-shadow fence, attachment-read routes, freed-memory
thread, depth pattern per device class, the new kind's lane site) and the
golden hashes, engine inventory and authored compile census blessed.

Verified at d8546c940b (batch f7): RTX 5080, M3, Iris Xe, RX 7900 XTX and
780M green; lavapipe 3822/3822, product 4821/4821, CPU validation
1331/1331, fuzz, fmt, clippy (4 configurations), Rustdoc, packaging,
qualification, refusals and the API reference check green; RTX 3090
7244/7245. Stress soaks of the runtime crate x2 clean on the 5080, XTX,
780M and Iris Xe.

Known open: on the RTX 3090 an Exact checked OpFmaKHR can answer -0 where
Metal answers +0 (the kernel's fast math declares no
SignedZeroInfNanPreserve); the fix is in progress. Not yet run: consumer
boots on this tree and the private-corpus translation census.
2026-10-16 18:45:39 +03:00
Anees Iqbal 29d3ebb22e Fix the consumer's first-move SIGBUS and deallocator fatal, restore the release door, announce the tessellator's triangle order
One commit of the 4 on development-fast (0175289314..c66863112e), squashed at the user's request:
the pin reims-vgpu tested clean.

Runtime:
- A texture's first move over host pages writes back only the bytes the move changed, and only
  where the kernel says the process may write them (mach_vm_region on macOS, the maps query on
  Linux). Before, it wrote back every kept byte: a SIGBUS on read-only pages on MoltenVK, and a
  hang under QEMU, whose handler retried the store. A changed byte over pages the host cannot
  write stays as the move left it, announced (unrestored-first-move-bytes; not observed on any
  venue). WorkCounts::first_move_restored_bytes. HostMemory::new states the Linux contract that
  imported pages stay writable.
- A no-copy buffer released while a submitted command buffer's live buffers' table lists its
  pages runs its deallocator at the release when the caller gave a keep-alive, which keeps the
  pages mapped until the import is freed. Only a release without one waits and announces
  host-deallocator-delayed. Before, the keep-alive case was announced too, which the consumer
  treats as fatal.
- Memory::free_then renamed release_then: it calls no Vulkan entry point, so the release door's
  source scan holds again.
(RUNTIME_VERSION 1303.)

Translator: PrecisionNote::TessellationTriangleOrder, recorded on a pipeline drawn through the
device's tessellation stages where the tessellator is not Apple's
(DriverWorkaround::TessellatorNotMetals): a patch's triangle order, first corners and ring joins
are the device's. The emulation without tessellationShader draws Metal's order and records none.
(SEMANTICS 1740, ARTIFACT_FORMAT 420.)

Docs: API.md's catalogue, FAST-PATHS.md's known gaps, REFUSALS.md.

Verified on development-fast:
- the runtime crate and runtime_lane x3 on the RX 7900 XTX, Radeon 780M and RTX 3090 at
  0175289314 (red only on the release-door scan, then fixed and checked);
- the tessellation note's lanes on the RTX 5080 and M3 (111/111 each);
- the keep-alive lanes on the XTX and 780M (152/152 each), the 5080 and lavapipe, its new test
  failing without the fix;
- both fixes' lanes on lavapipe 197/197, RTX 5080 195/195, Iris Xe 195/195 and M3 194/194; the
  read-only test aborts with SIGBUS on the M3 without the fix;
- reims-vgpu at this tree: cold x86-64 macOS 26 boots clean on the Iris Xe and the 780M, 2711/2711
  of its tests.
Not re-blessed here: the golden hashes' profile fingerprints and tessellation cells that the new
workaround moves; the bless is on development-fast.
The tree is development-fast's at c66863112e.
2026-10-16 13:06:03 +03:00
Anees Iqbal 0175289314 Batch the development-fast round: tessellation without tessellationShader, primitive ids, mesh tooling, color groups, the vk12 floor, runtime timing and teardown fixes
One commit of the 247 on development-fast (720ef1ce9a..9f46fdf80d), squashed at the user's request.

Translator:
- Tessellation on a device without tessellationShader: Metal's tessellator emitted as SPIR-V, a
  one-workgroup scan placing each patch's triangles in Metal's order, and the post-tessellation
  function as a plain vertex stage (EmulatedTessellationDraws; SEMANTICS 1739, ARTIFACT_FORMAT 419).
- [[primitive_id]] on a device without geometry or tessellation shaders, as a flat varying the
  vertex function writes; indexed lists, lines and points drawn de-indexed (RuntimeGap::PrimitiveIdIndices).
- Fragment functions of more colors than the device draws at once, compiled in color groups
  (PrecisionNote::ColorAttachmentGroups).
- Object functions' threadgroup memory from the render encoder; a kernel's mesh draws from an
  indirect command buffer; mesh payload sizing.
- The Vulkan 1.2 floor profile (vk12-floor) and the gates it needs; Metal 27.0.1 answers as the M3 Max.
- Overflow tests in the runtime-built modules by the product's high word (NVIDIA's compiler fails
  the division form), guarded crate-wide by tests::owned_divisions.

Runtime:
- Color-group passes replayed per group over twin depth/stencil; snapshot and copy-back cost cuts.
- Command buffers finish on the queue waiter that saw them; the waiter holds no device handle, so
  a program's drop after its wait is the device's last.
- Every object an encoder was handed held until its command buffer completes; deallocator order
  and announcements.
- Driver defects recorded and announced: ANV counts a visibility sample once per color output
  (visibility-count-per-color); MoltenVK fails pending work when memory that held a device-address
  buffer is freed, so freed memory waits for the work in flight (host-deallocator-delayed).
- RenderCommandEncoder::set_object_threadgroup_memory_length; Visibility::counting().

Validation: mesh tooling (object, mesh and ICB-mesh cases on both executors), the authoring
census closed, the queue storm judged in Metal's unit, load-robust exits and indirect-census
bounds, and the golden hashes, printouts, fixture inventory and authored compile census blessed.

Docs: FAST-PATHS.md trimmed to a ledger of what is true now; API.md's catalogue and accepted
differences, REFUSALS.md and METAL-COVERAGE.md current.

Verified on development-fast before the squash: the full suites on the RTX 5080, RTX 3090,
RX 7900 XTX, Radeon 780M, Iris Xe, lavapipe and the M3 (MoltenVK and the Metal oracle), lint in
every configuration, rustdoc, doc tests, packaging and public case qualification; the timing and
teardown lanes x5 on every venue; the authoring-capability census 16656/16656 with 0 unresolved,
the vk12-floor translation census at 6139 translated with the slowest row 794 ms and peak 126 MiB.
The tree is development-fast's at 9f46fdf80d.
2026-10-16 11:12:03 +03:00
Anees Iqbal c05c380139 Match the M3 Max under macOS 27.0.1: measurements, profile, Metal rows and MoltenVK venue
The macOS 27 work packet: the M3 Max moved to macOS 27.0.1, where MoltenVK gives it the M4's
deviceID. Its measurements, its MoltenVK profile, its Metal rows (now the C3 reference) and its
MoltenVK venue rows are taken again, and the tests follow.

Read Metal's NotMipmapped anisotropic footprint through MoltenVK at level 0:
On macOS 27 Metal's anisotropic filter reads a sampler without a mip filter
differently once its level clamp reaches 1/64: the runtime's NotMipmapped form
(nearest mip, lod [0, 0.25]) handed MoltenVK an anisotropic footprint that
was not Metal's NotMipmapped one, and the anisotropic lane failed on the M3
Max under macOS 27.0.1. Through Metal's own sampler (VkProperty::MetalSampler)
with anisotropy and equal min and mag filters the sampler now clamps to
[0, 0]: with equal filters the level has no filter left to choose, and Metal
answers that sampler as NotMipmapped bit for bit. With filters that differ no
clamp reads Metal's answer at maxAnisotropy 2 to 16; that stays a known gap in
docs/FAST-PATHS.md.

RUNTIME_VERSION moves (renumbered once for the composed batch): a run of an unchanged
artifact samples differently.

Verified: metal::sampler unit tests (24, including the new
metals_own_anisotropic_sampler_reads_not_mipmapped_at_level_zero) at a release
build; runtime_lane::anisotropic_filter::anisotropic_samples_answer_within_
their_bounds_of_metals passes on the M3 Max, macOS 27.0.1, MoltenVK 1.4.1
(it failed at the round's first composed tree and at 61a2efc7d3).

Take the M3 Max's macOS 27 measurements on MoltenVK's shared Apple identity:
MoltenVK's deviceID on an Apple GPU is the macOS release and the GPU's
highest families (MVKPhysicalDevice::getHighestGPUCapability), so under
macOS 27.0.1 the M3 Max reports 0x1B000209, the M4's identity, and takes the
M4's driver facts. The owner's rule: an answer fact holds on the shared
identity only where measured on both GPUs; a cost fact follows the M3 Max.

- MetalNormStorageWrites and DepthTestKeepsDenormals, measured on the M4:
  re-measured on the M3 Max under macOS 27.0.1 with the fact taken, every
  channel and texel Metal's; kept, the evidence in their docs.
- GraphicsCubeGradientRoute stays measured on the macOS 26.7 identity alone;
  the shared identity's graphics route stays unmeasured.
- The interlocked pass: on the M3 Max under macOS 27.0.1 split ran about a
  quarter faster than whole (wall 721-769 us against 974-1045, GPU 671-719
  against 914-964, two runs of three rounds of 30 frames at 1920x1080
  RGBA16Float), so the shared identity's row moves from
  InterlockedPassWholeFaster to InterlockedPassSplitNoSlower. The M4's own
  measurement (whole faster) is in the row's doc and in docs/FAST-PATHS.md's
  known gaps. RUNTIME_VERSION 1190 on this branch covers it.
- APPLE_M3_MAX and APPLE_M4 say what the deviceID is.

Verified: the facts and timings on the M3 Max (macOS 27.0.1, MoltenVK 1.4.1)
through runtime-lane tests at the round's first composed tree with these facts; the
device::tests::driver_facts unit tests run at the rebased tip before landing.

Hold the degrade-notice lane to the resolves the device actually makes:
passes_degrade_once_per_kind expected the exact resolve and the device's
rounded one to be announced wherever the driver's RGBA8Unorm average at 4
samples is measured as Metal's, assuming a texture of 8 samples exists. The
M3 Max (macOS 27.0.1, MoltenVK 1.4.1) makes none at 8 samples, so neither
is announced there, and the lane failed. The filter now expects those two
where the average is not measured as Metal's or where the device makes an
8-sample texture.

Verified: runtime_lane::degrade_notices::passes_degrade_once_per_kind passes
on the M3 Max (it failed at 61a2efc7d3 and the round's first composed tree).

Write the tessellation test's vertex output as Metal's compiler does:
authored_tessellation_executes_native_patch_inputs hand-writes its AIR, and
its post-tessellation output carried metadata Metal's compiler does not
write (Xcode 27, every macOS target 13 to 27 checked): air.location_index on
a vertex output. Our AIR reader refused it (Abi(UnknownKey) for
air.location_index on a vertex output), as it should for a key the compiler
never writes there. The output now carries air.vertex_output with its
user(locn0) name, its type name and its argument name, as the compiler emits
it.

Verified: metal::tests::graphics::authored_tessellation_executes_native_
patch_inputs passes on the M3 Max, macOS 27.0.1 (it failed at 61a2efc7d3 and
the round's first composed tree).

Wrap the driver-facts claims test's doc at the line width:
The interlocked-pass sentence the shared-identity commit rewrote ran past
the 100-column doc width. No other change.

Hold the unmeasured-identity test to the macOS 27 identity's split form:
an_unmeasured_identity_takes_its_drivers_defects_alone still expected the
moltenvk-m4 capture to take InterlockedPassWholeFaster, which the shared
macOS 27 identity no longer does (it takes InterlockedPassSplitNoSlower, the
M3 Max's measurement). Found by the device::tests::driver_facts run at the
rebased tip.

Name the format where the formats capture and the product's query differ:
the_formats_capture_is_the_product_queried_formats_of_the_venue_device
compared every format's masks without naming the format, so a failure on
the M3 Max showed two masks and no format. Each assert now names it.
Test-only.

Capture the M3 Max's MoltenVK profile under macOS 27.0.1:
The reference Mac runs macOS 27.0.1 (26A434) now. Its moltenvk-m3 capture
(vulkaninfo --json and corpus-vulkan --capture-formats, Homebrew MoltenVK
1.4.1, vulkan-tools 1.4.350.1) is regenerated through
scripts/regen-device-profiles. Only the identity moved: MoltenVK's deviceID
on an Apple GPU is the macOS release and the GPU family, so the M3 Max now
reports 0x1B000209 (452985353), the M4's identity, and every capability,
limit and format mask is as before. c3-venues.json declares the new
identity.

The two captures now differ only in allocation sizes, which no translation
reads, so they derive one translation key:
- candidate::platform::profiles: a run on the M4 held to the M3 Max venue
  stops on the device name alone (the venue's identity guard, not product
  behaviour), and proceeds where the venue allows the M4.
- c3::tests: the M4's capture passes check_profiles as a second device of
  the venue; the list still refuses it for naming the M3 Max's Metal
  environment.
- device::tests::driver_facts: moltenvk-m3 takes the shared identity's facts;
  the macOS 26.7 identity (APPLE_M3_MAX), measured but with no committed
  capture now, moves to MEASURED_WITHOUT_PROFILE and keeps its coverage
  through a description at that deviceID, graphics cube route included.
- tests::engine_sampler_unk: the graphics cube route's test builds the
  M3 Max under macOS 26.7 the same way.
Docs: API.md and profiles/README.md say what MoltenVK's deviceID is.

Golden hashes and expectation rows that hold moltenvk-m3's translation key
are left for the round's bless. Verified: the capture on the M3 Max
(regen_device_profiles.py --only moltenvk-m3, check_device_profiles.py);
the unit tests above run at a build of this branch before landing.

Record the Metal rows of the M3 Max under macOS 27.0.1:
The reference Mac's Metal answers, apple-m3-max-macos27.0.1 (Apple M3 Max,
40 GPU cores, macOS 27.0.1 26A434, Xcode 27A266a, Metal toolchain 32023.921,
ORACLE_ABI metal-literal-resources-v48): corpus-metal --batch over every
case the 26.7 environment holds, in three maclock holds of about 6.5
minutes, then --batch-install. 2227 cases ran: 2223 qualified, 4 reference
gaps (the simdgroup_matrix 16x16 cases, GPUFamily10, as on 26.7), no
failure. The 26.7 rows stay.

Against the 26.7 rows: no status changed and 8 outputs moved, every one a
cube-gradient case with identical AIR and inputs (a54af728, 315ca8b0,
391fac4d, 6ce71712, ae7aa91b, b3e5b4ef, dd39e2e5, 649c204a). Those 8 ran a
second time identically. Every other case answers as on 26.7.

Expect the M3 Max's and the M4's MoltenVK captures to share a fingerprint:
fingerprints_distinguish_committed_profiles listed only the two Intel
captures as sharing a fingerprint, kept apart for the Apple GPUs by the
graphics cube route measured on the M3 Max's macOS 26.7 deviceID. Under
macOS 27 MoltenVK gives the M3 Max and the M4 one deviceID, and the captures
differ only in allocation sizes, so moltenvk-m3 and moltenvk-m4 now derive
one fingerprint; the test lists the pair.

Found by device::tests at a build of this branch; device:: (104) and
tests::engine_sampler_unk (8) pass with it on the release build.

Make the M3 Max under macOS 27.0.1 the C3 reference Metal environment:
The reference Mac runs macOS 27.0.1 (26A434), and its Metal rows are
committed (apple-m3-max-macos27.0.1). The switch:
- c3-references.json: the primary is apple-m3-max-macos27.0.1 (Apple M3 Max,
  40 cores, 27.0.1, 26A434, Xcode 27A266a, Metal toolchain 32023.921).
- c3-venues.json: the MoltenVK venue's device compares with it.
- runtime_lane::METAL_ENVIRONMENT, the reference and venue tests, and
  scripts/rerecord-venue's default name it.
- The parity lines: record_metal and the sequences' record_metal on the M3
  Max under macOS 27.0.1. The four scenarios recorded 68, 240, 95 and 36
  records; the 64 sequence seeds 8534 records, 0 differences from the model
  and no Metal-side gap (seeds 32, 51 and 62 crashed Metal's driver under
  26.7; they run under 27.0.1). The 26.7 lines and rows stay.

Verified on the M3 Max (release, --cfg m2v_gpu, the validation layer on):
runtime_lane::driver_deviations::cube_gradients_through_an_anisotropic_
sampler_answer_as_metal passes against the 27 rows (MoltenVK answers Metal
27's cube gradients; it failed against the 26.7 rows); parity::tests::
committed_records_are_current and the 14 parity and sequence lanes pass (their
2 recorders are ignored); the
c3::, candidate::platform::profiles::, candidate::engine::guards:: and
parity::tests:: modules pass (98 tests).

Record the M3 Max's MoltenVK venue under macOS 27.0.1 at product 15b6df4e2bd0:
Rows and refusals recorded by one build (executor vulkan-engine-v181, product
15b6df4e2bd0cb440724ffe07ba95f1ccf6d0a5dd7fb5055598e70c877596734, semantics 1698, oracle
metal-literal-resources-v48) at this commit's product, on the Apple M3 Max under macOS 27.0.1 (MoltenVK
1.4.1, deviceID 0x1B000209). They are judged against the apple-m3-max-macos27.0.1 Metal rows and
were installed by scripts/rerecord-commit --no-commit. No later commit changes the product, so every row installed here stays current.

- apple-m3-max-moltenvk (moltenvk): 4389 rows, 56 refusals, over 2223 cases in two legs
- stated: 2168 match, 23 mismatch, 31 refused, 1 failed
- robustness-off: 2175 match, 23 mismatch, 25 refused

Against the macOS 26.7 rows, per case and leg:
- Of the earlier matches, 2965 still match, none mismatches, and 1 failed (below).
- 13 earlier mismatches and 13 earlier refusals now match; 38 mismatches and 42 refusals remain.
- 1374 runs had no 26.7 row: 1352 match, 14 refused, 8 mismatch. The 8 are the robustness-off
  leg of four linked-single radix13 and radix15 zero-write cases whose stated leg was already a
  mismatch, and both legs of the two new cases quad-broadcast-first-in-an-arm-metal-speculates
  and quad-broadcast-first-in-a-fragment-arm-metal-speculates.

The failed run is authored-four-iteration-loop (3cf0a3f024a5), stated leg. Metal's compiler
connection was interrupted while it compiled the compute pipeline (XPC_ERROR_CONNECTION_INTERRUPTED
after MoltenVK's retries), on both the first try and the --retry-failed run. Its robustness-off leg
matches, and under 26.7 it matched in both legs. Its stated slot keeps the 26.7 row, which C3 reads
as stale. Two msl-4-1 cases the venue's selection did not include also keep 26.7 rows that read
stale.

Verified:
- corpus-moltenvk --batch-report reads this_build=yes for the out directory at the recording tree and at the round's
  final tree (the table bless after this commit), which adds only tests, test tables and docs.
- corpus-status --c3 prints the same report at both trees. The MoltenVK slots (stated, then
  robustness-off) read: match 2168 and 2175, reviewed 10 and 10, mismatch 13 and 13, refused 25
  and 19, ray tracing out of scope 6 and 6, stale 3 and 1.

Versions: RUNTIME_VERSION 1205 -> 1211. RUNTIME_VERSION moves: MoltenVK's NotMipmapped anisotropic
footprint is read at level 0, and the macOS 27 Apple identity takes InterlockedPassSplitNoSlower.
crates/metal2vulkan-validation/runtime-sources.sha256 holds
e74792b15fd66114fb4efcc8e281318bfe1e16a3b8532e90d737834ea5a2add3, the hash of this tree's runtime
inputs (runtime-pin.py, which reproduces build.rs's). Version numbers quoted above are the values
the work's branch built with. Each part's Verified lines name the tree it ran at.
2026-10-14 20:17:42 +03:00
Anees Iqbal dd5a19aea1 Alias a padded texture that only reads by default, the shadow behind PaddedReadsPolicy::Shadow
The padded-reads work packet (the owner's choice): a padded texture that is only read aliases the
buffer by default, under the same documented first-move gap as tight aliases, checked per driver;
the exact shadow stays behind PaddedReadsPolicy::Shadow, which exact_answers() selects.

What: a 2D texture (or array) over a buffer whose rows or slices lie with bytes between them, and
whose usage as Metal reports it holds no RenderTarget, ShaderWrite, ShaderAtomic or block writes
(Unknown reads as 0x17, so it stays a shadow; a swizzled texture reports ShaderRead |
PixelFormatView and reads), is now an image over the buffer's bytes at Metal's row pitch, as a
texture of packed rows is: the device's own linear image (PREINITIALIZED over ordinary memory, for
host allocations over a no-copy buffer), a DRM_FORMAT_MOD_LINEAR image at that pitch, or one over
a dma-buf of the pages. Its subresources may hold the bytes between its rows and its last row's
padding (to row_pitch x rows); a driver whose image reaches past that is refused as for packed rows
(lavapipe's height rounded up to 4). A render target or a texture a shader writes stays a shadow.
The rebind remakes the image under the same rule (AliasKind::Linear keeps it).

The switch: DevicePolicy.padded_reads, PaddedReadsPolicy::{Alias (default), Shadow};
DevicePolicy::exact_answers() selects Shadow, the runtime's shadow copied in before each use. It
is the runtime's alone: no ProfileFields carries it, so no profile fingerprint moves
(tests::fast_paths::the_runtime_s_padded_reads_choice_keys_no_profile) and SEMANTICS_VERSION
stays. The owner's ruling (relayed by reims-vgpu-orchestrator, 2026-10-14 15:55): "I'll take 1 &
2", (2) being this, "exact to the same standard as tight aliases", under 30c8b4bff8's first-move
known gap extended to the padding bytes, checked by the same per-driver lane check.

Why it is the same standard: the first move is the only layout transition a runtime image takes.
- Every image memory barrier the runtime records is a first move (texture/first_move.rs
  FirstMove::barrier), a new image's own (storage_form.rs, host_copy.rs; never an alias), or a
  caller-wrapped image's Transition (submit.rs via texture/wrapped.rs).
- The tracker's barriers are VkMemoryBarriers (tracker.rs Barrier::record), which transition no
  layout.
- Blits into a texture copy in GENERAL: blit_texture.rs's vkCmdCopyBufferToImage and
  vkCmdCopyImage. VUID-vkCmdCopyBufferToImage-dstImageLayout-01396 and
  VUID-vkCmdCopyImage-dstImageLayout-01395 allow GENERAL; GENERAL "supports all types of device
  access".
- "Each source region specified by pRegions is copied from the source buffer to the destination
  region of the destination image". The Memory Model: "A memory operation must not affect memory
  at a memory location not within its set of memory locations".
- Every descriptor names GENERAL (binding.rs, heap_sets.rs).
- A texture over a buffer has one level (linear_plan's MipmapLevelCount), so generate_mipmaps
  leaves it, and optimize_contents_for_gpu_access records nothing.
- A texture without RenderTarget usage has no COLOR_ATTACHMENT usage. A pass renders it through a
  stand-in, copied in GENERAL, so no load or store operation reaches its image.

How:
- linear_plan's padding() becomes holding(layout, usage, policy) -> Result<Holds, String>, with
  Holds::{Texels, Padding}, Holds::fits (texels_alone, or the new padded_alone) and only_reads.
- aliases() takes the Holds. So do alias_image, dma_buf_alias_image (DmaBufTexels.alone),
  host_alias_unbound, host_pitched_image, and the pointer and dma-buf rebinds.
- storage_over_buffer decides it once, from texture_usage (the effective usage), so the shadow's
  reason no longer reads the raw descriptor's RenderTarget bit. The reason of a read-only texture
  shadowed under the switch names PaddedReadsPolicy::Shadow.
- RUNTIME_VERSION 1211 (renumbered at compose); the runtime-sources pin is recomputed at this tree.

Docs:
- FAST-PATHS.md: a fast-defaults row (padded_reads = PaddedReadsPolicy::Alias/Shadow, ANV's 0.63
  ms copy in per tile use and 135 vs 41 us making).
- FAST-PATHS.md: the padded-row shadow row now covers textures that render or that a shader
  writes.
- FAST-PATHS.md: the first-move gap row now covers the bytes between rows, with the GENERAL anchors
  in prose and the M3 Max probe's point (Metal never writes padding, even under concurrent CPU
  writes).
- API.md's shadowed-texture entry, ShadowedTexture's rustdoc, HOWTO.md, interop.rs and dma_buf.rs.
- The refusal surface is unchanged (refusal_surface.py --check).

Verified so far:
- clippy -D warnings, all targets, all features, --cfg m2v_cpu_icd: clean (um780, Rust 1.98.1).
- cargo fmt --check: clean.
The unit and lane runs follow with the lane checks' commit.

Check per driver that a padded texture that only reads keeps every byte of its pages:
What: three lane tests in runtime_lane::pitched_surfaces, under PaddedReadsPolicy::Alias (the lane's
own devices take exact_answers, so Shadow), each over no-copy buffers of anonymous pages:

- a_texture_that_only_reads_keeps_every_byte_of_its_pages: a ShaderRead texture over each of the
  11 layouts. Its first use is a fragment function's read through its image, before anything else
  touches the pages: it must read the pages' texels, and every byte of the pages, the bytes between
  the rows among them, must be unchanged. That is the image's first move, the known gap 30c8b4bff8
  records, now over padding.
  Then: a nearest and a linear sample, get_bytes and a blit out. The caller rewrites the texels and
  the bytes between the rows; a sample and a read must give the new texels. Blits Metal makes into
  any texture: a buffer's box at an odd origin, replace_region of a box, a private texture's box.
  After each step every byte of the pages is compared (the blit-into-alias check the peer asked
  for: a driver whose copy writes past its region fails, naming the bytes).
  Prints PITCHED-READS, how many padded layouts aliased. Off MoltenVK at least one must, or no
  first move over padded rows was checked.
- a_padded_texture_that_only_reads_copies_no_shadow_by_default: each padded layout under Alias and
  under Shadow. Three nearest samples and a blit out read the texels. An aliased texture copies no
  shadow (WorkCounts::shadow_copies unchanged), a shadow copies one in (more than 0). Under Shadow
  it is never aliased off MoltenVK. Off MoltenVK at least one layout aliases under Alias.
- a_padded_texture_that_renders_or_writes_is_a_shadow_under_either_policy: the browser's tile with
  RenderTarget | ShaderRead, ShaderRead | ShaderWrite and Unknown usage, under both policies, over
  a no-copy buffer (shadow off MoltenVK) and an ordinary buffer (shadow everywhere).

surface() takes whether the device may alias the texture's padded rows; the existing callers pass
false and keep their assertion.

Why: the owner's standard for the read-only padded alias is the tight aliases', checked per driver
by the same first-use lane check. A driver that fails it gets a structural driver-defect entry
that keeps the shadow there.

Lane filter for the round: runtime_lane::pitched_surfaces.
Verified: clippy -D warnings with --cfg m2v_cpu_icd (um780). The device runs follow.

Check a padded texture that only reads over an ordinary buffer's rows too:
What: runtime_lane::pitched_surfaces::a_padded_texture_that_only_reads_over_an_ordinary_buffer_keeps_its_bytes,
over each padded layout of LAYOUTS in a Shared buffer (not host pages), under both policies.
- Under PaddedReadsPolicy::Alias the texture is the device's own linear image over the buffer's
  memory (made PREINITIALIZED, linear_image), where the device lays one at the rows' pitch.
- Its first use, a fragment function's read through it, must read the buffer's texels and leave
  every byte of the buffer as it was, the bytes between the rows included.
- A nearest sample must read the texels too; an aliased texture copies no shadow over the two.
- Under Shadow it is never aliased.
- It prints each layout's form (PITCHED-READS).

Why: the read-only padded alias also takes the runtime's own PREINITIALIZED linear image, a path the
no-copy lanes do not reach. Its first move keeps the contents by the spec (the old layout is the
current one); the move's reach over the padding is the same known gap, now checked here per driver.

Verified: to follow, with the GPU runs (lavapipe, ANV, RADV x2, NVIDIA x2).

Name the drivers whose first move keeps a padded texture's bytes:
docs/FAST-PATHS.md's first-move known gap now lists the drivers whose run showed the bytes kept.
That covers the bytes between the rows of each padded layout the driver aliases, and the ordinary
buffer's check joins the cited tests.

Verified: runtime_lane::pitched_surfaces passed 19 of 19 at 6d4508a65d's tree on each:
- lavapipe and ANV (Iris Xe RPL-P), Mesa 26.2.4;
- RADV: the Radeon 780M on Mesa 26.2.4, the RX 7900 XTX on 26.0.8;
- NVIDIA 615.71.09: RTX 3090 and RTX 5080 Laptop GPU.
Padded layouts that only read and were aliased by default: 8, 8, 2, 2, 4 and 4 of 8. None changed
a byte of the pages. MoltenVK was not run.

Name the padded-reads alias among the default's choices in the API guide and the runtime's guide:
What: docs/API.md's list of what DevicePolicy::UNTRUSTED holds gains the image over a padded
texture that only reads (PaddedReadsPolicy::Alias), its structural test (no RenderTarget,
ShaderWrite, ShaderAtomic or block writes in the usage), its known gap (the bytes between the
rows are kept as far as the driver's first move keeps them) and the switch exact_answers()
selects. The runtime README's sentence on textures over buffers now says when the runtime keeps
a copy: where linear images cannot hold Metal's layout, and over padded rows when the texture
renders or a shader writes it, or only reads under PaddedReadsPolicy::Shadow.

Why: both guides described the default without the runtime's new choice; the README's sentence
already missed the padded render-target shadow.

Verified: docs only. The degrade-catalogue tests read API.md's catalogue, which this does not
touch; no degrade code is named. The runtime-sources pin covers src/ alone, so it is unchanged.

Time a compositor's frame over padded textures that only read, under each PaddedReadsPolicy:
What: surface_texture_costs gains read_only_padded_costs, an ignored release-mode measurement
(SURFTEX-READS). Each frame makes, for each padded layout of LAYOUTS, a no-copy buffer over its
surface's anonymous pages and a ShaderRead-only texture over it, samples each into a private
target of the browser tile in one pass, commits and waits. It runs under PaddedReadsPolicy::Alias
and ::Shadow, a device each, interleaved over three rounds, and prints per policy and round the
textures' forms, the medians and 90th percentiles of a texture's making, the frame's encoding,
commit to completion and process CPU, and the shadow copies a frame. pitched_surfaces' reading
pipeline and sampler helpers become pub(super) for it.

Why: FAST-PATHS' padded-reads row quotes ANV's copy-in cost per use; this measures what the
default saves per frame against the exact switch on any device, with the forms shown so a device
that shadows anyway is not counted as a saving.

Verified: validation-only and ignored by default; it changes no product source, so the runtime
pin and versions are unchanged. Its build and clippy under --cfg m2v_gpu are checked on um780,
and its run is on ms01's ANV.

Print why a padded texture that only reads over an ordinary buffer is a shadow:
What: a_padded_texture_that_only_reads_over_an_ordinary_buffer_keeps_its_bytes appends the
shadowed-texture notice's reason to its PITCHED-READS line, as the pages' tests already do in
their PITCHED-SURFACE lines, instead of taking the notices unread.

Why: on ANV (Mesa 26.2.4, ms01) none of the 8 padded layouts aliased over an ordinary buffer
under PaddedReadsPolicy::Alias, while all 8 alias over no-copy pages; the run showed the form but
not the reason, so the cause could only be guessed. The print names it per device.

Verified: test-only; the run on ms01's ANV prints the reasons (in the follow-up timing window).
Clippy under --cfg m2v_gpu on um780.

Quote ANV's measured frame cost of the padded-reads shadow in its ledger row:
What: FAST-PATHS.md's padded_reads row now quotes what read_only_padded_costs measured on ms01's
ANV (Iris Xe, Mesa 26.2.4). A frame sampling four BGRA8Unorm tiles over no-copy pages
(1307x512 at 5248 and 5376-byte rows, 300x200 at 1216, 1913x96 at 7680) in one pass completes
about 0.36 ms later as shadows: the median of 15 interleaved Alias/Shadow pairs, 0.08 to 0.60 ms,
all 15 positive. It also takes about 56 us more encoding and 91 us more process CPU. A texture's
making costs the same either way, about 45 us.

Why: the row quoted a 0.63 ms copy in per use and 135 vs 41 us making. Those were relayed
figures, not this case's measurement. Here making costs the same, and sampling the linear image
over host pages gives back part of the copy's saving, so the frame saves less than the copies'
sum.

Verified: 5 runs of read_only_padded_costs (3 interleaved rounds of 100 frames after 10 warm,
each) on ms01, release, --cfg m2v_gpu --cfg m2v_system_alloc, under both ANV locks, taskset
0-11, load under 1, forms "aaaa" under Alias and "ssss" under Shadow, 4.00 shadow copies a frame.
A first run of 3 more pairs, taken right after another workload, swung from -2.2 to +0.57 ms,
and is not counted. tests::fast_paths passes with the edited row (5/5, um780).

Versions: RUNTIME_VERSION 1204 -> 1205. RUNTIME_VERSION moves: read-only padded textures alias by
default. crates/metal2vulkan-validation/runtime-sources.sha256 holds
edc97e709c2605eaa13ac8696ea119fb9b727243a276a679d0b3288ed5b760b3, the hash of this tree's runtime
inputs (runtime-pin.py, which reproduces build.rs's). Version numbers quoted above are the values
the work's branch built with. Each part's Verified lines name the tree it ran at.
2026-10-14 20:17:40 +03:00
Anees Iqbal 30c8b4bff8 Shadow a padded texture over a buffer exactly, and cut the shadow's cost
The padded-texture work packet. A texture over a buffer whose image would hold bytes that are not
its texels is drawn through a shadow image with exact copies, since a render pass or a layout
transition may write those bytes. Then the shadow's cost is cut, exactly: no copies for a pass that
reaches no tile, a copy back bounded by the draws' scissors, and cost lines that show each part.

Shadow a texture over a buffer whose image would hold bytes that are not its texels:
A texture over a buffer is a linear (or DRM_FORMAT_MOD_LINEAR) image over the buffer's bytes only
where every byte of the image's subresources is one of its texels: its rows lie one after another
(or it has one), its slices likewise, and its last subresource ends at its texels' last byte or
before. Anything else is the shadow, whose copies address the buffer's texels alone. The Metal
texture over an MTLBuffer (MoltenVK) is exempt: every write through it is Metal's own.

Why: Vulkan lets a render pass's load and store operations "read and write back any memory
locations within the image subresource bound for that attachment" (renderpass.adoc, Load and
Store Operations), and VkSubresourceLayout's size "includes any extra memory that is required
based on rowPitch", so the bytes between padded rows lie inside the subresource. Metal leaves them
as the program writes them. No query promises otherwise, so no image may alias padded rows.
Bytes past every subresource stay allowed: Memory Aliasing bounds the bytes a write through an
image affects to "those overlapped by the image subresources that were written". Measured on
lavapipe (Mesa 26.2.4 llvmpipe, gem10) at the round's base: pitched_surfaces' 657x128/5312
RGBA16Float tile took lavapipe's own linear image (its pitch 660 texels rounded to 64 bytes is
the lane's 5312), and a clear-blend-store pass rewrote 13 padding bytes in 13 rows (row 3 byte
5265 0x7c -> 0x7e: texels 657..659 of its 4-texel blocks read and written back, signaling NaNs
quieted). The reliance predates 1cf79a9617 (own linear images whose pitch equals bytesPerRow,
the dma-buf explicit planes); 1cf79a9617 made it every padded surface on ANV and NVIDIA's wider
pitches.

How: linear_plan's padding() and texels_alone(), used by alias_image (before any image is made),
aliases() (now given the subresource's size), host_alias_unbound (the own linear image's fit and
the pitched image's), the dma-buf alias (before the pages' source is asked, counted as a
fallback; its plane's size checked for textures over buffers, not heaps') and the rebind (the
alias kind keeps the texels' layout). Importer::makes_modifier_images, a duplicate of
makes_dma_buf_images, is folded into it. RUNTIME_VERSION 1188.

Tests: the aliases unit test covers padded rows, slices apart, a one-row pitch, a subresource
past the texels and a whole-array report. pitched_surfaces checks the pages after every step
(now naming the changed bytes outside the texels), asserts padded rows are never aliased off
MoltenVK, adds a load-blend-DontCare step, packed layouts of 510 and 126 rows and of 200, and a
fragment function's writes over six layouts (shader read/write usage). no_copy_textures asserts
padded rows shadow off MoltenVK (it asserted ANV's pitched image); dma_buf_imports' 60-texel case
now shadows. Docs: API.md (the extension paragraph and the shadowed-texture entry),
ShadowedTexture's rustdoc, HOWTO.md section 6, Texture::vk_image, dma_buf.rs, and a known-gap
entry in FAST-PATHS.md with ANV's cost (making the browser tile ~135 us as a shadow vs ~41 us
as a pitched image, 1cf79a9617's numbers).

Verified on lavapipe (gem10, release, --cfg m2v_cpu_icd, LP_NUM_THREADS=1): runtime_lane's
pitched_surfaces, no_copy_textures, buffer_texture_blits, dma_buf_imports, linear_attachments,
buffer_textures, buffer_texture_order, buffer_texture_renders, dont_care_stores,
kept_buffer_bytes, rotated_textures, and tests::linear_plan / degradation: 137 of 140 passed;
a_half_float_tile passes (it failed at the base), every padded layout is shadowed, 300x200/1200
is a pitched image. The three failures: the runtime-sources pin (written here), and the two
packed odd-height layouts, 658x126/5264 (rows 126..127 past the texture rewritten) and
1308x510/5232 (SIGSEGV, rows 510..511 written past the mapping): a lavapipe defect of explicit
DRM_FORMAT_MOD_LINEAR planes, handled in the next part. GPU lanes (ANV, RADV, NVIDIA,
MoltenVK) not run yet.

Make no explicit-plane modifier image of an odd height where lavapipe renders rows past it:
RuntimeDriverDefect::ExplicitPlaneRowsPastHeight: a DRM_FORMAT_MOD_LINEAR image whose one plane
the caller lays out (VkImageDrmFormatModifierExplicitCreateInfoEXT) is rendered in blocks of 4
rows, its rows past its height up to a multiple of 4 written past its subresource and past its
memory requirements. On a driver with the defect (lavapipe, MESA_LLVMPIPE, every release until a
probe finds one clean) neither host_pitched_image nor the dma-buf image (textures over buffers
and heaps' textures alike) is made of a height that is no multiple of 4: the texture takes its
shadow, announced as shadowed-texture with the defect named. The trigger is structural (the
image's height); the driver's own linear images are untouched, as they report the rounded rows
in their subresource (the previous part's texels_alone then shadows them).

Why: a write past an image's own memory is a spec violation no query reveals. Measured on lavapipe
(Mesa 26.2.4, llvmpipe LLVM 23.1.1 256 bits, gem10, release, LP_NUM_THREADS=1) at the previous
commit, pitched_surfaces' packed odd-height layouts, each a pitched image (pitched host images 1):
658x126/5264 RGBA16Float, a load-blend-store pass rewrote 21 bytes of rows 126..127 past the
texture (signaling NaNs quieted); 1308x510/5232 BGRA8Unorm, the same pass wrote rows 510..511 past
the no-copy buffer's mapping and the process took SIGSEGV. lavapipe 26.0.8 is unprobed.

How: Device::explicit_plane_rows (dma_buf.rs), asked by host_pitched_image and
dma_buf_image_unbound after their format checks. The registry entry and its test, the variant's
rustdoc, ShadowedTexture's rustdoc and API.md's shadowed-texture entry. No refusal is added, so
docs/REFUSALS.md has no row for it (refusal_surface.py --check passes); the api_surface table
names the enum, not its variants. RUNTIME_VERSION 1189.

Verified: see the landing run (lavapipe, the pitched_surfaces odd-height layouts shadowed and
passing).

Record that an image over host-pointer pages keeps its bytes past its first move only by drivers:
A known gap in docs/FAST-PATHS.md, and a lane check that turns a driver that drops the bytes into
a visible failure. No behaviour changes (no RUNTIME_VERSION bump): whether every texture over
pointer-imported pages becomes a shadow is the owner's call.

The gap: an image of host allocations must start UNDEFINED (VUID-VkImageCreateInfo-pNext-01443),
and a transition from UNDEFINED "will cause the contents of the image's memory to be undefined"
(resources.adoc, VkImageLayout). Memory imported from a host pointer "shares ownership of the
memory between the host and the Vulkan implementation", with host access synchronized as for any
memory (memory.adoc, VkImportMemoryHostPointerInfoEXT), so the external-memory acquire from
VK_QUEUE_FAMILY_EXTERNAL/FOREIGN is not blessed for it. sync2's ignored-layout barrier keeps
contents but leaves the image UNDEFINED, invalid to use as GENERAL. Paths that rely on the drivers:
host_linear_image, host_pitched_image, and metal_alias_image (VkImportMetalTextureInfoEXT says
nothing of contents). Spec-backed: dma-buf images, acquired from VK_QUEUE_FAMILY_FOREIGN_EXT in
GENERAL (the external memory chapter's ownership transfer and its note that the UNDEFINED initial
layout is a placeholder), and the runtime's own linear images, made PREINITIALIZED.

The check: pitched_surfaces::a_texture_s_first_use_reads_the_bytes_it_was_made_over makes a
texture over each layout and reads it first through its image (a fragment function's read)
before anything else touches the pages: the read must be the pages' texels and the pages
unchanged.

Verified: see the landing run (lavapipe).

Expect a shadow wherever no linear image holds a texture's texels alone:
The runtime aliases a texture over an ordinary buffer with a linear image only
where the image's subresource holds the texture's texels and nothing else
(linear_plan::texels_alone): no padding between rows, the driver's row pitch
Metal's, and no subresource bytes past the last texel. The lanes' expectation
helper, buffer_texture_blits::linear_rows_differ, compared only the driver's
row pitch, so on lavapipe, whose linear 64x2 RGBA8Uint at a 256-byte pitch
reports a 1024-byte subresource (its height rounded up to 4 rows) while the
texels end at 512, resource_ids expected no shadow and failed with "announced
past []: [ShadowedTexture, UnnamedShadowedTexture]".

The helper now applies the same rule: rows with bytes between them, a
subresource offset other than 0, a row pitch other than the buffer's, or a
subresource size past (height - 1) * row + width * texel. It takes the texel
size, which every caller knows. The callers' expectations move the same way:
resource_ids' 64-texel rows (the size rule), buffer_texture_blits' 4x4
textures at 32-byte rows and the IOSurface planes at 9, 20 and 40 bytes, and
view_reinterpretation's rows 16 bytes past their texels (the padding rule,
which shadows them on every device).

Verified on gem10's lavapipe (Mesa 26.2.4, --cfg m2v_cpu_icd,
LP_NUM_THREADS=1, release): the focused filter over pitched_surfaces,
no_copy_textures, buffer_texture_blits, dma_buf_imports, linear_attachments,
buffer_textures, buffer_texture_order, buffer_texture_renders,
dont_care_stores, kept_buffer_bytes, rotated_textures, resource_ids,
view_reinterpretation and the runtime's linear_plan, degradation and
driver_defects tests: 186 of 187 pass, resource_ids'
a_buffer_under_a_texture_goes_at_its_release_whatever_keeps_the_image among
them; the one failure is the runtime-sources pin, which moves with this work (below).
Test-only: no runtime source changes.

Name the layout transitions as what may write a padded texture's padding:
A texture over a buffer whose rows (or slices) lie with bytes between them
is a shadow off MoltenVK, since an image over those rows would hold the
bytes between them in its subresource. The shadowed-texture notice gave one
reason for every such texture: Vulkan lets a render pass's load and store
operations write those bytes back. That cannot apply to a texture without
RenderTarget usage, which never becomes an attachment, and ms01's A/B saw
read-only padded textures shadowed under that reason.

For such a texture the basis is the layout-transition rule (the
Synchronization chapter's Image Layout Transitions): "Image layout
transitions may perform read and write accesses on all memory bound to the
image subresource range", and "If the old layout is
VK_IMAGE_LAYOUT_UNDEFINED, the contents of that range may be discarded".
Every image takes one transition before any use: its first move into
GENERAL, from UNDEFINED for imports (VUID-VkImageCreateInfo-pNext-01443)
or PREINITIALIZED for ordinary buffers. No descriptor or copy takes an image
in either layout, and host image copy's transition is a transition too. So
no transition-free path exists for a read-only linear image, and the shadow
stays. After the first move every runtime image rests in GENERAL, so no
later barrier transitions it; copies and shader accesses touch texels alone
(the Memory Model: "A memory operation must not affect memory at a memory
location not within its set of memory locations").

linear_plan::padding now takes whether the texture renders (RenderTarget
usage). Its reason names the layout transitions, its first move among them,
and for a render target also the render pass's load and store operations.
The doc comment quotes both texts. The ShadowedTexture rustdoc, docs/API.md's
catalogue entry, docs/HOWTO.md, docs/FAST-PATHS.md's known gap, and the
dma_buf.rs and linear_plan.rs module docs say the same.

Tests:
- tests::linear_plan::a_padded_texture_s_shadow_names_what_may_write_its_padding
  checks both reasons' exact text.
- The lane test pitched_surfaces::a_padded_texture_s_shadow_names_what_may_write_its_padding
  makes the browser's 1307x512/5248 tile over an ordinary buffer, which
  shadows on every device, MoltenVK included. It runs a fresh device per
  usage (ShaderRead; RenderTarget | ShaderRead) and checks the
  shadowed-texture notice's reason.

RUNTIME_VERSION 1190 (fleet/round's 1189 + 1). The runtime-sources pin is
recomputed at this tree.

Verified on gem10's lavapipe (Mesa 26.2.4, llvmpipe LLVM 23.1.1,
--cfg m2v_cpu_icd, LP_NUM_THREADS=1, release). The focused filter
(pitched_surfaces, no_copy_textures, buffer_texture_blits, dma_buf_imports,
linear_attachments, buffer_textures, buffer_texture_order,
buffer_texture_renders, dont_care_stores, kept_buffer_bytes,
rotated_textures, resource_ids, view_reinterpretation, and the runtime's
linear_plan, degradation and driver_defects tests) ran 189 tests. 188
passed, both new tests among them, printing:
- ShaderRead: "its rows lie 5248 bytes apart, 5228 bytes of texels each: an
  image over them holds the bytes between them, which Vulkan lets its layout
  transitions read and write, its first move from the layout it is made in
  among them"
- RenderTarget: "... which Vulkan lets its layout transitions read and
  write, and a render pass's load and store operations write back"
The one failure was the runtime-sources pin before this commit set it
(860ca881...). Clippy with all features (no cfg) is clean.

Take the surface texture cost frame apart, per part and per texture:
surface_texture_costs measures a browser-like frame: five surface textures
over new no-copy buffers, each loaded and stored by a pass that draws
nothing, then each blitted into a private texture. On ANV, ms01 measured
commit-to-completion rising by about 2.8 ms a frame where four of them
became shadows. That number alone cannot say where the time goes: the
shadows' copies in and back, their making and release, or work beside them.
It also cannot say why the packed 1024x512/4096 tile, which stays the
driver's own linear image in both forms, took longer to make.

The new ignored measurement surface_texture_cost_parts (run by name, release,
as the others) runs the frame over anonymous pages in parts:
- Empty: the textures made and released around an empty command buffer.
- PassesStored: Load/Store passes, i.e. a shadow's copy in and copy back.
- PassesNotStored: Load/DontCare passes, a copy in only.
- PassesDrawn: Load passes that blend a rectangle and store, as a browser's
  passes draw.
- Blits: the blits alone, which read a texture over a buffer as its bytes.
- Both: the original frame.

It runs over every layout, then over the packed layouts alone, so no shadow
is made beside them. Per set and part it prints (SURFTEX-PART): the forms;
each texture's making median and p90; the frame's release, encoding,
commit-to-completion and process CPU time; and the per-frame work counts.
frame() takes the part, and surface_texture_costs passes Part::Both, so its
own output is unchanged.

Test-only. It compiles at fleet/base as well (it names nothing newer), so the
same measurement runs on the earlier form. Checked with clippy --cfg m2v_gpu,
all targets and features, -D warnings, on gem10.

Copy no shadow in or back for an attachment a pass that reaches no tile loads:
A texture over a buffer whose image would hold bytes that are not its texels
is a shadow: an image of its own that encoders copy the texels into before
use and back after a write. A render pass copied its shadowed color
attachment in before the pass and back after it whenever it loaded and
stored it, even where the pass reached no tile: no draw call, or draw calls
that draw nothing (clear_reach::PassReach::Nothing). Such a pass changes no
texel:
- Metal loads and stores only the tiles a draw reaches (PassReach's EVs).
- Vulkan's load and store write back what they read: "Load operations only
  update values within the defined render area", and store operations
  alike.
So the copies moved a texture's every texel twice for nothing. On ANV,
surface_texture_costs' frame (whose passes draw nothing) paid that for four
padded surfaces since they became shadows.

attachment_shadows now takes no use of such an attachment: a color
attachment of a pass that reaches no tile, that loads it (Load, also a
DontCare load the pass loads), stores it Store or DontCare, resolves
nothing, and has no stand-in or planes, where the shadow is a plain image of
a buffer's bytes (ShadowTarget::Image, writes kept). No copy in, nothing
dirty, no copy back. Rotated, converted and image shadows keep their copies.
The pass still renders into the shadow image, whose attachment uses order it
as before. Every later use copies in again, since the shadow was never marked
current.

New public counter WorkCounts::shadow_copies: copies between a shadowed
texture's truth and its shadow that encoders planned (in, back, keep and
merge). It is counted where EncoderCore plans them and at each of the three
end-of-encoder finishes.

Lane test pitched_surfaces::a_pass_that_draws_nothing_copies_no_shadow: the
browser's 1307x512/5248 tile over an ordinary buffer (a shadow on every
device). Load/Store and Load/DontCare passes that draw nothing plan 0 copies
and leave every byte of the buffer. A pass that blends a rectangle plans 2
(in and back). Without this change, the expected counts for the two empty
passes are 2 and 1.

This shrinks surface_texture_costs' frame, whose passes draw nothing, not a
browser's, whose passes draw. surface_texture_cost_parts' PassesDrawn part
measures that apart.

RUNTIME_VERSION and the runtime-sources pin move with this work (below).

Verified on gem10's lavapipe (Mesa 26.2.4, --cfg m2v_cpu_icd,
LP_NUM_THREADS=1, release): the earlier focused filter plus the runtime's
shadow tests ran 200 tests, 199 passed, the new test among them. The one
failure was the pin. clippy -D warnings, all targets and features, is clean
with no cfg and with --cfg m2v_gpu.

Copy back only the texels inside a pass's draws' scissors:
A shadowed texture's copy back after a render pass moved every texel from
the shadow image to the buffer. On ANV that write-back is the shadow's cost:
ms01's surface_texture_cost_parts put a stored shadow at about 0.8 ms of
commit-to-completion a frame (1307x512 BGRA8). A pass that loads a color
attachment changes no texel outside its draws' scissors:
- "Samples with coordinates outside the scissor rectangle at the
  corresponding ViewportIndex will have their coverage set to 0" (the
  Fragment Operations chapter's Scissor Test).
- "Load operations only update values within the defined render area" and
  "Store operations only update values within the defined render area" (the
  Render Pass chapter), writing back what they read.
- Each Vulkan scissor is Metal's rectangle clipped to the pixels its viewport
  overlaps (render_state.rs's implicit scissor), so Metal's draw writes no
  pixel past it either.
The image's other texels are what the last copy in left, which the buffer
still holds, and a write of the bytes another way leaves the image stale, so
they need no copy back.

How:
- ShadowUse gains an area: where a command writes through the texture, where
  it bounds that. render.rs passes the bounds of the pass's DrawnArea (its
  draws' Vulkan scissors) for a pass whose draws reach tiles, unless a reach
  clear runs before the pass, together with which color attachments the
  encoder set to Load, read before the DontCare loads and reach clears change
  any. attachment_shadows gives that area to a loaded color attachment with
  no resolve, stand-in or planes that is the whole of a one-level, one-slice
  texture.
- join and ShadowSync::after keep the rectangle bounding the writes since
  the last copy back, or none where one does not bound them. copy_back puts
  it on the ShadowCopy.
- record() cuts the one region of a ShadowTarget::Image without staging to
  it, by part_of: the buffer offset moved to the rectangle's first texel at
  the region's row length, clamped to the image. ShadowTarget::Image now
  carries its texel size (none for a heap's depth or stencil shadow, which
  takes no area).
- Copies in still move every texel.

New public counter WorkCounts::shadow_texels_copied_back: the texels copies
back of buffers' textures' images move.

Tests:
- tests::shadow::a_copy_back_covers_only_where_the_commands_wrote: areas
  through ShadowSync and join.
- tests::shadow::a_part_of_a_region_starts_at_its_first_texel: the region
  arithmetic, clamping, empty parts and tight rows.
- Lane pitched_surfaces::a_pass_copies_back_only_the_texels_its_scissors_reach:
  the browser's 1307x512/5248 tile over an ordinary buffer (a shadow on every
  device), blended under a 300x200 scissor, moves 60000 texels back. The
  buffer then holds a private texture's blend inside the scissor and every
  other byte as it was. Unscissored, the pass moves all 669184.

docs/FAST-PATHS.md's known gaps record the race the bound leaves: Metal
stores only the 32x32 tiles a primitive touches (reims-vgpu's padding probe,
M3 Max, macOS 27.0.1). A concurrent CPU write to an undrawn texel in an
untouched tile inside the scissors can be undone here, where Metal keeps it.
No copy reaches the bytes between rows.

The batch's version commit moves RUNTIME_VERSION; the runtime-sources pin follows it.

Verified on gem10's lavapipe (Mesa 26.2.4, --cfg m2v_cpu_icd,
LP_NUM_THREADS=1, release). The shadow lanes (the previous part's list,
plus scissors and capture_reach where they exist) and the runtime's shadow,
shadow_stencil, linear_plan, degradation and driver_defects tests ran 319
tests, and 318 passed, the three new ones among them. The one failure was
the runtime-sources pin. clippy -D warnings, all targets and features,
--cfg m2v_gpu, is clean.

Measure a scissored drawn pass and a shadow's copies alone:
Two additions to the surface texture cost measurements, both ignored and
run by name in release builds.

surface_texture_cost_parts gains PassesScissored: the drawn pass (Load, a
rectangle blended over the left half, Store) under a scissor of the left
half, as a browser's pass redrawing a damaged part of a tile draws. With the
previous part, its shadows copy back only the scissored half.
PassesDrawn's default scissor covers the whole tile, so its copy back moves
every texel.

shadow_copy_costs times each copy alone in its own command buffer, committed
and waited for, on the browser's 1307x512 BGRA8 tile at 5248-byte rows:
- a private texture made as a shadow is (render target and shader read) into
  a no-copy buffer over anonymous pages: a copy back's way;
- the pages into the texture: a copy in's way;
- the texture into a private buffer and into a Shared buffer;
- a private buffer into the pages, and back.
It prints SURFTEX-COPY lines with commit-to-completion medians and p90s.
These tell the image's tiling (detiling) from the pages' memory (writes into
imported host memory) as the cause of ANV's copy back.

Test-only. clippy -D warnings with --cfg m2v_gpu, all targets and features,
is clean on gem10.

Print a frame's shadow copies and the texels its copies back move in the surface cost lines:
What: the surface texture cost lines' per-frame work counts (SURFTEX-COST, SURFTEX-PART) now
end with the shadow copies the encoders planned and the texels their copies back moved, both
per frame.

Why: a change to how a shadow's image is made or copied must leave the copies and the texels
they move as they were; the cost lines then show it beside the times, in the same run.

Verified: test-only; built and run with the measurements on Linux hosts in the next steps
(no build on the Mac).

Wrap the surface texture costs' SURFTEX-QUERY sentence at 100 columns:
The commit that added a frame's shadow copies to the cost lines left the module doc's
SURFTEX-QUERY sentence on one 154-column line; the tree wraps doc comments at 100. Doc only.

Verified: awk finds no line of the file over 100 columns but the ignored-tests sentence (110),
which predates that commit; cargo fmt --all leaves the tree unchanged.

Versions: RUNTIME_VERSION 1202 -> 1203. RUNTIME_VERSION moves: padded textures over buffers are
drawn through shadows, and the shadows' copies change.
crates/metal2vulkan-validation/runtime-sources.sha256 holds
52d6ce1648b67055d046e043e6d1cd126e0a8315d04a922261df93ad0a25f734, the hash of this tree's runtime
inputs (runtime-pin.py, which reproduces build.rs's). Version numbers quoted above are the values
the work's branch built with. Each part's Verified lines name the tree it ran at.
2026-10-14 20:17:38 +03:00
Anees Iqbal f25dfd8ea2 Record that a commit can wait for the driver's submission
What: a known-gap row in docs/FAST-PATHS.md. Where the scheduler is free,
commit() runs the submission pass, vkQueueSubmit included, on the
committing thread, so a submission the driver holds holds commit(), where
Metal's commit returns at once.

Why: tests::completion::a_completion_on_one_queue_is_seen_while_other_queues_are_waited_for
fails on the RTX 5080 Laptop GPU (NVIDIA 615.71.09) when it runs beside the
runtime_lane scheduler tests, about 20 processes opening devices at once.
It failed in 4 of 4 such runs, at fd22785008, 365aef412c and the round's first composed tree, and
passed 4 of 4 alone. Scratch timestamps (not committed) showed what happens.
In the slow round, the second commit took 116.6 to 177.5 ms. It was handed
off 0 times. The thread spent 3.5 to 3.8 ms on the CPU and 0 ms waiting
runnable, with 29 to 45 voluntary context switches: asleep in the driver.
The GPU ran that command buffer at 0.0 to 0.1 ms, and its vkQueueSubmit
returned 116 to 177 ms later. The first command buffer's completed handler
ran 0.1 ms after its commit, so the completion path is prompt. The test
only sees the delay because its own thread began waiting after its commits
returned. In one round the third commit took 58.8 ms (7.6 ms on CPU), and
its GPU work started only as the call returned. Across the runs the
stalls took 58 to 226 ms, in 1 or 2 of the 1,800 commits of a run.

The test split (judge completion from the completed handler, check
commit()'s own wall time apart) and the product choice (hand each commit
to the scheduler thread, or do so after a stall) are deferred: the user
ruled that known failures are recorded now and fixed after this push; the
product choice is the owner's.

Verified: docs only; tests::fast_paths run on msi-laptop (see the LAND
message for the result).

Versions: unchanged.
2026-10-14 20:17:37 +03:00
Anees Iqbal 81c82b1167 Fix the RX 7900 XTX and 780M lanes' findings, and measure the XTX's Function storage
The um780 lanes' work packet: busy GPU work a driver's watchdog lets run, a pass's replay logs going
before its holds, a linear-attachment diagnostic, and the RX 7900 XTX's Function storage
measurement.

Commit the lanes' busy GPU work as command buffers a driver's watchdog lets run:
The runtime lanes' busy work (first_use::Busy: one threadgroup spinning on a flag until the test
releases it or its cap of loads runs out, about 2 s) was one command buffer. Linux 7.0's amdgpu
ends any one job after 2 s by default (`modinfo -p amdgpu`: lockup_timeout "default: 2000", unset
on the host), resets the ring and loses the context, so on an RX 7900 XTX and a Radeon 780M (Mesa
26.0.8, kernel 7.0.0-38) every busy work that ran to its cap was killed: dmesg "ring gfx_0.0.0
timeout ... ring reset" in the test's thread, then DeviceLost.
first_use::frame_sized_textures_copy_texel_exact failed 2 of 2 alone on each GPU (its get_bytes
waits behind the work there), and frees_in_flight::frees_while_the_gpu_is_busy_fail_no_command_buffer
failed under load. No user may be asked to raise a kernel parameter, so the work fits the watchdog.

Busy::commit now commits the work as 8 command buffers on its queue, each a spin of at most
BUSY / 8 (250 ms at the kernel's measured rate, 8x under the 2 s watchdog), each with a ticket
of its own on the one flag; the last writes the end mark. A release ends every spin still to run
at its first load. It returns a BusyWork whose wait, error (the first link's), status and
scheduled cover every command buffer, so frees_in_flight checks each for an error.
dma_buf_imports' rebind-in-flight leg commits the busy work and then its copy behind it on the
queue (first submitted before the rebind, held on the GPU behind the work), where it encoded the
spin into the copy's own command buffer; Busy::encode is gone.

Verified on homelab-um780, both GPUs (release, --cfg m2v_gpu, each pinned with
MESA_VK_DEVICE_SELECT and MESA_VK_DEVICE_SELECT_FORCE_DEFAULT_DEVICE=1): every lane of the
helper's users (runtime_lane::{first_use, frees_in_flight, dma_buf_imports, compressed_decode},
29 tests) passed twice at -j 1 and once at default parallelism, with no amdgpu line in the kernel
log (3 to 4 ring timeouts per run before). The GPU stays busy as the tests claim: FRAME-COPY's
"through submissions" get_bytes returned after 2062 to 2079 ms, texel-exact; FIRST-USE "every call
returned with the busy work running"; FREE-IN-FLIGHT "still running after the changes".

Let a scheduler pass's replay logs go before its holds of their command buffers:
A scheduler pass hands what it spent to its caller to drop without the lock: the holds of the
command buffers it submitted, and the replay logs their first submissions ended, which hold
clones of the handles their encoders named. Spent's fields dropped in declaration order, holds
first, so once a command buffer had finished, the hold's drop opened its gate and its waiters
returned while its logs still held the program's buffers on the scheduler's thread. A program
that waited for a command buffer and then let go of a no-copy buffer was not letting go of its
last handle: the buffer, its pages and its deallocator went later, on the scheduler's thread.
That breaks the contract complete() keeps: what the commands used goes before the gate opens,
so a waiter returns after it. The lane
runtime_lane::rebinds::rebinds_before_the_first_submission_reach_the_pages_of_the_last caught it
under load: the deallocator had not run in the program's drop (runs 0, no delayed deallocator),
in about 1 of 150 runs with 16 at once, on an RX 7900 XTX and a Radeon 780M alike, never alone.

Spent now declares its logs before its holds, so they go first by its fields' declaration
order, and says so as its contract; it is generic, defaulting to the scheduler's types (as
HostAliases is), so tests::gate::a_pass_lets_go_of_its_logs_before_its_holds checks with a probe
that a log goes while the gate is still closed. With the fields in their old order that test
fails ("a log went after the hold opened the gate"). The lane's `ran` is #[track_caller], so a
failure names the check that failed. RUNTIME_VERSION 1188: when a program's no-copy deallocator
runs changed. The runtime-sources pin moves with it (below).

The other holds of command buffers checked for a resource-holding neighbour that outlives them:
completion's Submitted (its events go at the end of each batch's turn, its last batch's hold
only with the posted transition), Transition (a result alone), the scheduler's Committed and
Held (their events dropped, or their batches moved, before the hold goes into Spent), and its
Settled, Handlers and Steps lists (holds alone). Spent was the only one.

Verified on homelab-um780 (release, --cfg m2v_gpu): the unit test fails with the old field order
and passes with the new one.

Say which bytes differ when a linear attachment's pass misses the private one's:
runtime_lane::linear_attachments::scissored_blends_over_a_corner_render_in_place failed once on an
RX 7900 XTX under the full suite's load ("the pages differ from the private texture's pass") and
never alone (3 of 3, and 0 of 640 sixteen at once). A mismatch there is a race until shown
otherwise, and the message said nothing of where. blends_over_the_pages now names how many bytes
and rows differ and the first 32, each with its row, column and channel, the private pass's value
and the pages', and whether it lies inside the scissor, on its edge, or outside: stale or partial
rows point at a missing barrier, values a little off at the blend. Test-only: no product path.

Measure the RX 7900 XTX's Function storage: 96 KiB a thread:
What: device::function_storage's MEASURED table gains the AMD Radeon RX 7900 XTX (MESA_RADV,
0x1002, 0x744c) at 96 KiB a thread. Before, the XTX was a device not measured, so it took the 16 KiB
floor: every stage keeping private memory recorded PrecisionNote::FunctionStorageAssumed, and every
stage needing more than 16 KiB was refused (Unsupported{PrivateMemory}, or {Recursion} for a call
stack). The module doc and docs/FAST-PATHS.md's known-gaps entry name the XTX's failing size beside
the 780M's and list it among the measured devices. The 780M's row notes that the same series on
Mesa 26.0.8 answered as its 26.2.4 measurement did (its value is unchanged).

device/tests/profile.rs used 0x744c as its example of an unmeasured RADV GPU: it now checks that the
780M's description under the XTX's ID takes the XTX's 96 KiB, and under Navi 21's 0x73bf the floor.
engine_private_memory's rtx_3090() becomes captured_as(stem, id), a committed capture under another
device ID, which the 3090's test and the new XTX test share.

Measurement (homelab-um780, AMD Radeon RX 7900 XTX (RADV NAVI31), Mesa 26.0.8-1ubuntu0.3, kernel
7.0, release --cfg m2v_gpu, VK_DRIVER_FILES radeon_icd.json with MESA_VK_DEVICE_SELECT=1002:744c,
under the radeon_icd lock with the hang tripwire checked before each size):
runtime_lane::private_memory's sizes in ascending order, each alone and cut at 60 s, from a build
whose table took the XTX to hold 1 MiB (the lane cannot reach the device past the translator's
refusal otherwise; that build was never committed). 4, 8, 16, 32, 48, 64 and 96 KiB answered
correctly over 1, 64, 4096 and 262144 threads (262144 threads at 96 KiB in 59 ms); 128 KiB answered
correctly over 1 and 64 threads and wrongly over 4096 (53 of the 64 threads checked), so the series
stopped there. Repeats: 96 KiB three more times, 4, 32 and 64 KiB once, all correct; 128 KiB twice
more, wrong over 4096 both times (55 and 53 of 64). No size hung or timed out, and journalctl -k
showed no amdgpu line through either series. The same lane on the 780M (1002:15bf, same build and
Mesa) answered 4 to 96 KiB correctly over 262144 threads.

Test: tests::engine_private_memory::private_memory_on_the_rx_7900_xtx_rests_on_its_measurement takes
the committed amd-rdna3-radv capture (an RX 7800 XT, RDNA3 under RADV like the XTX) with the XTX's
device ID and checks that a 96 KiB private array (24576 words) compiles with no
FunctionStorageAssumed note and 24592 words are refused needing them against 96 KiB. On
homelab-um780 (release, --all-features), the 7 tests matching function_storage or
engine_private_memory:: pass; with the XTX row removed, this test fails ("24576 words: unsupported:
PrivateMemory; needs ... required: 98304, available: 16384") and
function_storage_is_the_measured_value_of_the_device fails (Assumed(16384) against
Measured(98304)), the other 5 pass.

Versions: no SEMANTICS_VERSION bump. DeviceProfile::fingerprint hashes every ProfileFields field,
so the XTX's function_storage moving from Assumed(16384) to Measured(98304) moves every key derived
on it. No committed profile has the XTX's device ID (amd-rdna3-radv is the 7800 XT's 0x747e), so the
golden tables and the authored compile census do not move. function_storage.rs is a runtime input
of the validation crate, so RUNTIME_VERSION and the runtime-sources pin move with it (below),
at landing.

Versions: RUNTIME_VERSION 1198 -> 1199. RUNTIME_VERSION moves: when a program's no-copy deallocator
runs, and the XTX's Function storage fact, change.
crates/metal2vulkan-validation/runtime-sources.sha256 holds
3634eb419d48a74cf21d54319d5026013dea4c3de8d747d0d976559096f07e6f, the hash of this tree's runtime
inputs (runtime-pin.py, which reproduces build.rs's). Version numbers quoted above are the values
the work's branch built with. Each part's Verified lines name the tree it ran at.
2026-10-14 20:17:36 +03:00
Anees Iqbal edfba8ac8b Decode AIR 2.5's stride-less kernel and vertex ICB buffer setters
AIR 2.5 (Metal compiler 31001.723, macOS 12's and 13's) declares an
indirect command's kernel and vertex buffer setters without the i64
attribute stride before the buffer index:

  air.set_kernel_buffer_compute_command.p{1,2}i8
  air.set_vertex_buffer_render_command.p{1,2}i8
    void (ptr addrspace(1), i32, ptr addrspace(1|2), i32)

Decode had one form for these, (cmd, i32, ptr, i64 stride, i32 index),
so such a declaration classified as DeclClass::Mismatch and its module
was refused with InvalidInput(Intrinsic(SignatureMismatch)). The
translation census over ms01's private corpus at fd22785008 refused 8
rows this way on every committed profile, all AIR 2.5 from 31001.723;
7 of them (3 vertex functions, 4 kernels) declare these setters. The
error text and position (blocks [8, 12]) are the consumer's macOS 12 and
13 Contacts refusals'; whether those are these setters is unverified.

What the stride-less form means: it is MSL's plain setter,
set_kernel_buffer(buffer, index) and set_vertex_buffer(buffer, index).
Today's compiler spells that setter with an i64 of all ones. Evidence,
run on this Mac with Apple metal version 32023.921 (metalfe-32023.921.6),
on kernels calling the plain kernel and vertex setters on a device and
a constant buffer, compiled at -std=macos-metal2.4, metal3.0, metal3.1
and metal3.2: every standard declares all four setters with the i64,

  declare void @air.set_kernel_buffer_compute_command.p1i8(
    %struct._command_buffer_t addrspace(1)* nocapture, i32,
    i8 addrspace(1)*, i64, i32)

and call each with it as -1:

  call void @air.set_kernel_buffer_compute_command.p1i8(... %3,
    i8 addrspace(1)* %7, i64 -1, i32 0)
  call void @air.set_vertex_buffer_render_command.p2i8(... %3,
    i8 addrspace(2)* %8, i64 -1, i32 1)

(4 of 4 calls at -1 at each standard.)
All ones is the stride the encoder already writes for a stride-less
buffer (Fields::Buffer { stride: None }, "as Metal's kernel-side setter
does"), the stride the runtime's CPU-side set_kernel_buffer records.

How:
- IndirectCommand::SetBuffer gains `strided`. A kernel or vertex setter
  parses as strided; alternative() offers the stride-less form, through
  AirIntrinsic::alternative(), as for the legacy texture read and the
  AIR 2.7 to 2.9 forms. The fragment, object and mesh setters keep their
  one stride-less form.
- lower/access/encode.rs takes `strided` from the operation instead of
  deriving it from the stage, so the stride-less form writes the
  all-ones stride.
- The decode golden printouts of the engine ICB fixtures spell the new
  field.

Tests:
- families_tests: the four AIR 2.5 declarations among the observed
  ones; buffer_setter_forms_are_chosen_by_the_declaration (each form
  classifies to its own operation, keeps the command handle at 0 and
  the buffer at 2; other operand lists, and a stride on a fragment,
  object or mesh setter, stay Mismatch).
- engine_indirect_commands::air_2_5_buffer_setters_write_the_plain_
  setters_records: the compute and render ICB kernels rewritten into
  the AIR 2.5 spelling (AIR 2.5, Metal 2.4) write byte-identical records
  to today's form at stride -1, on every profile with device addresses,
  over a dynamic stride set before.
- A new owned synthetic fixture, kernel_icb_encode_plain_setters_air_2_5.ll
  (two kernels, both setters, device and constant buffers), with its
  inventory rows: ok wherever kernel_icb_encode_compute_commands is,
  refused for GpuEncodedIndirectCommands where it is. It assembles with
  the pinned LLVM 21.1.8.

docs/FAST-PATHS.md: the known gap for macOS 12's and 13's declarations
now says what is true: the setters decode, and of the 7 private rows
that declare them, 1 translates and 6 meet the typed not-implemented
ArgumentBufferObjects refusal (below); one private row stays refused
with SignatureMismatch, a kernel declaring air.intersect.triangle_data
with six trailing settings where decode's form has nine (ray tracing,
out of scope). A new known gap names the CallTypeMismatch class: a
direct call whose arguments do not line up with its callee's
parameters, which no exact form exists for and which stays refused.

SEMANTICS_VERSION 1693 -> 1694: declarations that were refused now
decode, and a row that was refused now translates.
No runtime input changes (runtime-sources.sha256 unchanged). The golden
hash table is not re-blessed here.

Verified on homelab-ms01 at the round's first composed tree plus this change:
- cargo nextest, -p metal2vulkan-air -p metal2vulkan --all-features:
  tests matching indirect or families (145 pass); then, with the
  fixture, buffer_setter_forms, observed_declarations, families_tests,
  engine_indirect_commands, public_fixtures_engine (every llvm_as part
  and the inventory order; the metal_as parts skip off macOS),
  air_input and cache:: (123 tests): all pass but air_input's golden
  printout check, which failed on exactly the 14 SetBuffer lines (7
  engine fixtures under LLVM 21 and 23). With the printouts updated,
  air_input, engine_indirect_commands and the inventory order pass
  (27 tests).
- Release corpus-triage, translation audit of the 12 rows the census
  at fd22785008 refused with Intrinsic::SignatureMismatch (8) or
  Canon::CallTypeMismatch (4), on all 20 committed profiles (--hash-file,
  ms01's corpus index copy). Per profile: 1 translated (on the 15
  profiles with GPU-encoded commands; device_capability_missing on
  lunarg, roadmap, swiftshader, vk12-bare and vk12-floor, as for the
  committed ICB fixtures), 6 unsupported not_implemented
  ArgumentBufferObjects, 1 SignatureMismatch (the ray-tracing kernel),
  4 CallTypeMismatch; defects 0, budget stops 0. Slowest row 34 ms,
  peak worker RSS 20 MB, so far inside 20 s and 500 MiB.
  The 6 ArgumentBufferObjects rows are ICB inheritance functions whose
  builds by other compilers are refused the same way in the fd22785008
  census (which raise site fires is not examined here). That is a
  separate, already typed gap, not a decode fault.
- Authoring-capability census with the fix, --reclassify-all then warm:
  total 16,602 (the 2 new public rows), classified 16,602, remaining 0,
  unresolved 39 (the same 4 families as before); the warm pass read 0
  source bytes.

Versions: SEMANTICS_VERSION 1693 -> 1694. SEMANTICS_VERSION moves: input that was refused now
translates. Version numbers quoted above are the values the work's branch built with.
2026-10-14 20:17:36 +03:00
Anees Iqbal ed87db8d58 Measure the RTX 3090's Function storage: 128 KiB a thread
What: device::function_storage's MEASURED table gains the NVIDIA GeForce RTX 3090
(NVIDIA_PROPRIETARY, 0x10de, 0x2204) at 128 KiB a thread. Before, the 3090 was a device not
measured, so it took the 16 KiB floor: every stage keeping private memory recorded
PrecisionNote::FunctionStorageAssumed (which the runtime announces), and every stage needing more
than 16 KiB was refused (Unsupported{PrivateMemory}, or {Recursion} for a call stack). The module
doc names the 3090's failing size beside the others'. docs/FAST-PATHS.md's known gaps gain the
floor itself: Vulkan states no per-thread scratch limit, drivers past their capacity answer
wrongly or hang, so the amount is measured per device by runtime_lane::private_memory, never
probed at device open; the devices measured; the floor, its note and its refusal for every other
device; and the scratch's memory cost on the 3090.

Why: reims-vgpu's tests on the 3090 die on function-storage-assumed. function_storage.rs is
unchanged since the 10-11 squash, so this is not a regression: the 3090 had not been measured.

Measurement (homelab-gem10, NVIDIA 615.71.09, release --cfg m2v_gpu, VK_DRIVER_FILES
nvidia_icd.json, under gpu-nvidia-3090.lock): runtime_lane::private_memory's sizes in ascending
order, each alone and cut at 60 s, from a build whose table took the 3090 to hold 1 MiB (the
lane cannot reach the device past the translator's refusal otherwise; that build was never
committed). 4, 8, 16, 32, 48, 64, 96 and 128 KiB answered correctly over 1, 64, 4096 and 262144
threads; 192 KiB answered correctly over 1 and 64 threads and then hung over 4096 (no completion
within 50 s; dmesg: NVRM Xid 109 CTX SWITCH TIMEOUT for the test process), so the series stopped
there. 4, 32, 64, 96 KiB and three more runs of 128 KiB repeated correct. The GPU recovered by
itself (P8, 51 MiB in use after). The GPU's memory in use peaked at 1.3 GiB at 32 KiB, 2.3 GiB at
64 KiB, 3.3 GiB at 96 KiB and 4.2 GiB at 128 KiB, of 24 GiB: not a memory limit.

Test: tests::engine_private_memory::private_memory_on_the_rtx_3090_rests_on_its_measurement takes
the RTX 5080 Laptop GPU's committed capture with the 3090's device ID (as engine_link's test of
the 3090 does; no 3090 capture is committed) and checks that a 128 KiB private array (32768
words) compiles with no FunctionStorageAssumed note and 32784 words are refused needing them
against 128 KiB. Without the table entry it fails on the 3090's floor ("32768 words: unsupported:
PrivateMemory; needs ... required: 131072, available: 16384"), run at fd22785008 with the test
alone on homelab-gem10. A probe there on the 3090 itself (a validated device, a 16 KiB private
array dispatched over 64 threads) took the notice "the kernel of a compute pipeline state: its
translation records PrecisionNote::FunctionStorageAssumed
[metal2vulkan-degrade-function-storage-assumed]".

Versions: no SEMANTICS_VERSION bump. DeviceProfile::fingerprint hashes every ProfileFields field,
so the 3090's function_storage moving from Assumed(16384) to Measured(131072) moves every key
derived on it, and no output changes under an unchanged key. No committed profile has the 3090's
device ID, so the golden tables and the authored compile census do not move, and no venue of
cutover/c3-venues.json is a 3090. function_storage.rs is a runtime input of the validation
crate, so the RUNTIME_VERSION and the runtime-sources pin move with it (below).

Versions: RUNTIME_VERSION 1197 -> 1198. RUNTIME_VERSION moves: the RTX 3090's measured Function
storage changes what runs there. crates/metal2vulkan-validation/runtime-sources.sha256 holds
b5972723933c5a6c091bbb65a719d258c12ef83e35c98cb76b43bd7c54438daf, the hash of this tree's runtime
inputs (runtime-pin.py, which reproduces build.rs's). Version numbers quoted above are the values
the work's branch built with.
2026-10-14 20:17:36 +03:00
Anees Iqbal 2f3c6174f6 Keep a buffer's bytes under a texture a pass stores DontCare
A pass that does not store a color whose texture lies over a buffer now renders it into an image the
texture keeps (a Load copies the buffer's texels in first; nothing is copied back), so the buffer
keeps its bytes, as Metal does: measured on an M3 Max, every DontCare case kept the buffer's bytes,
with or without a barrier between draws. On MoltenVK a pass that Metal receives whole keeps using
Metal's own DontCare at no cost; only split or restarted passes use the kept image. New performance
notice `dont-care-stand-in`, a `kept_bytes_passes` work count, a frame-cost shape whose layers are
textures over buffers, and the cost recorded in docs/FAST-PATHS.md. RUNTIME_VERSION 1185.

Gain: correct bytes where the old form wrote rendered or cleared texels into the buffer. Cost on ANV:
a Load + DontCare pass about 10 us more; Clear + DontCare frames got cheaper (12.33 -> 11.18 ms).

Verified on the original branch: the four focused lane modules, 35 of 35 on RADV, an RTX 3090,
lavapipe and ANV, and its MoltenVK lanes on the M3 Max. This squashed commit was not re-tested on its
own.
2026-10-14 12:34:27 +03:00
Anees Iqbal 4b564766ec Sample extended-range textures through Metal's bicubic filter
A sample of a BGR10_XR, BGRA10_XR or RGB10A8_2P_XR10 texture (or an sRGB twin) through a constexpr
bicubic sampler, or through a runtime sampler whose bound word states Cubic, was refused
(NotImplemented(SamplerBicubicFilter) in the lowering, NotImplemented(Format) in the binder). It is
now Metal's bicubic filter of the decoded texels, measured on an Apple M3 Max (macOS 26.7) through
the owned fixture xr_bicubic: random codes of each of the six formats at 16x16, 7x5, 3x3, 2x6 and
1x1, 2,304 coordinates each (every texel's centre, then random ones up to 0.15 of the texture past
its edges), through 12 kernels (a runtime Cubic sampler with float and half results; constexpr
samplers under clamp to edge with float and half results, repeat, mirrored repeat, clamp to zero,
the opaque-white and opaque-black borders, pixel coordinates, and an offset under clamp to edge and
repeat): 3,317,760 lanes.

What Metal does, and what the lowering now does: the footprint, weights, addressing, a mirrored
axis and a level below four texels are the other formats' bicubic filter's, each tap the decoded
texel or the border texel through the format's channels; a level below four texels sums as the
extended-range linear filter (terms truncated); otherwise each tap's step is weighed by the
product of Metal's weights and summed exactly (no term truncated, unlike the linear filter), the
step rounded half up, clamped into the steps of the codes 0 and 1023 (a color lane's (0-384)/510
and (1023-384)/510, an sRGB twin's table steps, alpha [0, 1]), and divided by the grid exactly; a
half result rounds as the linear filter's does. The clamp is applied to the rounded result, which
equals clamping the step because each rounding is monotonic. Every lane but 4,050 matches that
model; each of the 4,050 is one step from Metal's (1/8160 a color lane, 1/8192 an sRGB color lane,
1/4080 alpha), its exact sum within 0.014 of a step of a rounding tie that Metal rounds the other
way. No model of Metal's datapath tried closes that residue, so the sample records
PrecisionNote::BicubicFilterArithmetic, and docs/FAST-PATHS.md and docs/API.md say so. A bfloat or
padded form's bicubic sample, a swizzled texture's and a gather through a bicubic sampler were not
measured and are refused.

How: select_extended takes the bicubic state of a constexpr sampler or of the slot's cubic-sampler
variant (LoweringInputs::cubic_samplers) and plans Metal's bicubic filter; the extended sampler emits
it through bicubic::filter with Texels::Extended, which fetches each tap's raw texel and decodes it,
through the exact routines alone, then clamps. The binder takes a cubic word at an extended-range
slot as the cubic-sampler variant's, and gives such a slot the neutral BicubicTexels value in the
plan of the pipeline as compiled, which binds the neutral there (it refused the format before
naming the variant: the device lane found that). SEMANTICS_VERSION 1693; RUNTIME_VERSION 1184, as
a run of an existing artifact with a cubic sampler at an extended-range slot is no longer refused;
the runtime-sources hash re-pinned.

The table: xr_bicubic.tsv (2,067 samples of the probe's, per texture and kernel the middle
texel's centre, four random coordinates, the first sample with a lane at a clamp bound and the
first with a lane at a tie), shared through metal2vulkan_devtools::xr_bicubic with the probe's
texture generator.

Verified on homelab-gem10 (debug builds):
- tests::engine_extended_range::bicubic, on the CPU interpreter on the lavapipe and MoltenVK-M3
  profiles: every lane of the table through the same 12 kernels, compiled under the six forms'
  variants (the runtime ones under the cubic-sampler word the binder plans), is Metal's bits but
  the 136 lanes the table marks, each one step away; each compile validates and its estimate
  bounds it. A padded or bfloat form's bicubic sample, a swizzled texture's and a gather are
  refused as above (a two-plane gather as Format, under any sampler); on every committed profile
  the pipeline as compiled plans the variants with the XR texture and a Cubic sampler bound, and
  the variant's pipeline plans the same key.
- runtime_lane::extended_range_bicubic (new): the 8,268 lanes on the Radeon 780M (RADV), the RTX
  3090 and lavapipe, textures written as the probe wrote them: 0 differ from Metal (136 at a tie,
  one step away), and the state announces bicubic-filter-arithmetic. The extended_range_samples,
  two_plane_samples and two_plane_copies lanes, whose helpers this shares, pass on all three.
- Release build, 12 kernels x 6 forms x 5 profiles (lavapipe, 780M, RTX 5080 Laptop, Arc ANV,
  MoltenVK-M3): 360 translations, mean 1.31 ms, slowest 1.97 ms (xrb_runtime, BGRA10_XR sRGB,
  780M), budget ledger peak at most 935 KiB, process peak RSS 15.6 MB; the linear XR kernels
  take 0.81 ms on average.
- clippy -D warnings (workspace, all features, all targets; validation also under m2v_gpu),
  rustdoc -D warnings and the doctests pass. Suites: metal2vulkan, -air, -runtime and -devtools
  4,566 of 4,567, validation 1,293 of 1,293. The one failure is tests::golden_hashes, whose 380
  stale cells are the two new fixtures' alone (smw_writers 7 and xr_bicubic 12 entries x 20
  profiles), left to be blessed on development.
2026-10-13 17:04:18 +03:00
Anees Iqbal 61a2efc7d3 Fix the GPU test failures seen on the 3090, 5080, XTX, 780M and M3
What and why, per failure (all release, --cfg m2v_gpu):

AMD RADV, Ubuntu Mesa 26.0.8 (RX 7900 XTX, Radeon 780M):
- generated_executions faulted the GPU (amdgpu gfxhub page fault, ring
  reset): RADV before 26.2 skips re-emitting a compute pipeline it thinks
  is bound, so the second execution's implicit preprocess ran our kernel.
  New RuntimeDriverDefect::ImplicitPreprocessAfterExecutionSet (RADV at
  every identity but the measured clean 780M at 26.2.4): the runtime
  preprocesses every execution of a range explicitly, then a barrier, then
  runs them preprocessed. RUNTIME_VERSION 1183.
- The validation executor's generated-commands replay had the same fault;
  it now preprocesses apart on the same defect (runtime's
  generated_commands::preprocess_apart, now public).
- float_denormals under fast math: the test checked a / b, smoothstep and
  (a / b) * c bit for bit, but without VK_KHR_shader_fma (26.0.8) the fast
  reciprocal is the device's OpFDiv(1, y), within 2.5 ulp. Those words are
  now checked at Metal's edges there, in full elsewhere.

NVIDIA 615.71.09 (RTX 3090, RTX 5080 Laptop):
- render_commands_and_render_states_run_as_the_executor_compiles_them: the
  executor used Vulkan device addresses as Metal addresses, and NVIDIA's lie
  below 2^32, where a record's address names no buffer. An addressed
  allocation's guest address is now its device address read signed (RADV's
  are sign-extended) plus 2^47 + 2^32, one translation for every allocation.
- the_runtime_probe_measures_the_test_device_consistently: two driver
  answers Vulkan does not allow (3090: a buffer read after a linear-image
  copy over the same memory in one submission reads stale bytes; both: an
  explicit linear pitch the driver does not lay out is moved, not refused)
  are listed with their evidence in the test; the runtime records neither.
- exits (5 tests): vkDestroyDevice takes ~55 ms alone and up to 2 s beside
  other processes' GPU work on the 3090, so the exit-timing tests run alone
  (.config/nextest.toml); the 1.5 s limit is unchanged.
- pipeline_records (5080): the test assumed the driver finds a pipeline only
  in byte-identical records, but NVIDIA's bytes vary per compile and the two
  formats share entry keys. It now copies a compute pipeline's record over
  the render state's records, which no driver can hit.
- compile_worker (5080, under load): a worker faster than the 1 ms sampler
  left no peak RSS. Each worker now reports its own peak (VmHWM on Linux,
  ru_maxrss on macOS) and the parent takes the larger.
- tests::completion (both, under load): slow rounds were the GPU starting
  late behind another process's ~200 ms busy kernel, or NVIDIA's
  vkQueueSubmit returning up to 64 ms late; the completion was seen within
  1 ms of the moment it could be. A command buffer is now judged from the
  later of its GPU end and its submission's return where the device
  calibrates timestamps (from the commit elsewhere, as before).
- first_use::new_resources_wait_for_no_gpu_work (both, under load): the
  busy kernel's rate came from one wall-clock run, which collapsed under
  load (3 of 28 calibrations), so the busy work lasted milliseconds. The
  rate is now the fastest of every run at every size by GPU time, for all
  four lanes that share it (gpu_times::read_kinds predicts the notice a GPU
  time read emits, for the neutrals test).

Apple M3 Max, MoltenVK 1.4.1:
- heap_textures allows the shadowed-texture route for depth on drivers that
  lay heap depth textures apart.
- The argument-buffer intersection-table test states Metal's own metadata.
- The indirect lane classifies the deferred pipeline-making failure as
  compile-failed alike and keeps only the failed pipeline's error; Apple's
  33-bit closed-form compiler crash is a known gap in docs/FAST-PATHS.md.

Docs: CONTRIBUTING.md and docs/VALIDATION.md say the golden tables and the
compile census are re-blessed on development.

ENGINE_EXECUTOR_ABI is vulkan-engine-v181 (the RADV replay and the Metal
addresses change what the executor submits): every recorded candidate row
and the authored compile census go stale and need re-recording
(scripts/rerecord-venue per venue, rerecord-commit, corpus-status --c3,
corpus-triage --audit authored-compile --bless).

Still open: M3 frees_in_flight, XTX bfloat clears, 780M half NaN blur and
the 5080's one 2 s rebind_bytes_no_copy did not reproduce; the wall-clock
busy calibrations of framebuffer_fetch/storage_forms.rs and queue_storms
remain.

Verified:
- um780 full suites at the AMD fixes (before the executor and NVIDIA
  commits): XTX 3535/3535, 780M 3535/3535, no amdgpu kernel lines.
- Each fix's focused tests before and after on its GPUs (in the agents'
  commits: e.g. generated/indirect 178/178 on XTX and 780M at 26.0.8 and
  26.2.4; candidate 229/229 on 3090, 780M and Iris Xe; the worker peak 0
  of 1440 under 24-way load on the 5080).
- The combined tip: fmt, clippy (with and without --cfg m2v_gpu) and
  rustdoc on ms01; clippy of the validation crate on macOS; a focused run
  on the 3090 was stopped at 333 of 334 passed, none failed. No full suite
  ran on the combined tip.
- The completion and first_use fixes: 3090 load set 1 of 4 runs failed
  before, 4 of 4 passed after (completion) and 12 runs with no first_use
  failure (84 calibrations, 10.19M-11.24M loads); 5080 6 of 6 and 12 of
  12. fmt and clippy (no cfg, m2v_gpu, m2v_cpu_icd) on ms01.
2026-10-13 01:15:18 +03:00
Anees Iqbal 13b279df1b Squash 11203 commits of translator, runtime, and validation work
Rolls up everything since 43c46ac8 into a single commit. Its tree is
identical to the tree of private master at
b3c77f2d2b20a432be10591a2129547c10b1c24b.

- A Cargo workspace of five crates under crates/: metal2vulkan (the
  translator and the metal2vulkan command), metal2vulkan-runtime (the
  Metal API on Vulkan), metal2vulkan-air (the AIR front end),
  metal2vulkan-validation and metal2vulkan-devtools.
- Dual license: GPL-2.0-or-later OR LGPL-3.0-or-later.
- docs/: API, architecture, fast paths, how-to, Metal coverage,
  refusals, runtime porting and validation guides.

Private-Commit: b3c77f2d2b20a432be10591a2129547c10b1c24b
2026-10-11 20:09:13 +03:00