Commit Graph
466 Commits
Author SHA1 Message Date
Anees Iqbal 9a67d986e6 Separate depth and stencil textures: an unstored DontCare aspect follows UnstoredDontCarePolicy in the scratch image
A pass whose depth and stencil attachments are two textures renders through a scratch image of
the combined format (depth_stencil_scratch.rs), and clear_reach::dont_care_loads skipped it: an
aspect loaded DontCare and not stored took the scratch's DONT_CARE load under every policy, with
no notice. So under exact_answers() its draws read what the new scratch image held (on MoltenVK
a stencil of 0 and a depth of 1.0, Metal's defaults for a load that names no clear value), where
Metal's read the pass's clear value: measured on the M3 Max under macOS 27.0.1 by the lane's
passes through Metal itself (job m3-max-16522), each aspect apart, whether the other aspect is so
loaded or loaded and stored.

Now such an aspect takes the answer of any attachment so loaded, each aspect apart: in a pass
whose draws reach a tile, the scratch's Clear to the aspect's clear value under
UnstoredDontCarePolicy::Cleared and on a driver with DriverFact::UnstoredClearNoSlower (the
scratch image is a combined depth/stencil attachment, the shape the fact measured), else its
DONT_CARE, announced dont-care-unstored-load naming the aspect. Nothing is copied into the
aspect before the pass (only Load aspects are), so no earlier bytes reach it. An aspect the pass
stores keeps the scratch's DONT_CARE load as before.

Docs: clear_reach.rs records Metal's answer for separate textures and the rule; the scratch
module, the notice's rustdoc and catalogue entry, UnstoredDontCarePolicy's rustdoc, API.md's
section and the FAST-PATHS row name separate textures; the known gap is removed.
2026-11-11 10:35:17 -08:00
Anees Iqbal 56c25f8b7a Runtime: a host step's recording keeps the takes of the one it replaces; a dropped command buffer gives its takes back
A tiled texture's copy taken at use was lost in two places where nothing ran it:

- Work the commit recorded and a host step records again (an execution of indirect commands the
  CPU wrote since the commit): the step's cores decided by the mark, which the commit's recording
  had cleared, so the recording that runs took no copy and the texture read stale levels. Now the
  step hands the replaced recording's takes to the cores it records into (State::step_takes, read
  by EncoderCore::segment_raw, under the step's turn): ShadowSync::over follows each decision
  that recording made, keeping its take and number, and decides a use it never met by the mark.
  As the step's recording replaces the commit's, a take of the commit's it never met is given
  back (Takes::give_back_unheld). TakeBy::Mark carries the replaced decisions; a core with none
  decides as before.
- A command buffer dropped without a commit kept its encoders' takes. Its drop now gives back
  every take of its ended encoders and of its segments' recordings while its status is still
  NotEnqueued.

Unit test tests::shadow::a_recording_in_place_of_another_keeps_its_takes covers the follow, the
by-mark decision of an unmet use, the give-back of an unmet take and of none kept, and a kept
no-take after did_modify_data. The device legs are in the previous commit. docs/API.md's tiled
texture paragraph says both.
2026-11-11 10:02:16 -08:00
Anees Iqbal 35c68796d3 Unstored DontCare loads: a DevicePolicy switch, cleared by default where the driver clears no slower
The fix before this cleared every attachment a pass loads `DontCare` and does not store, Metal's
answer (lane dont_care_unstored). Measured, that clear is no cost on some drivers and a cost on
others, so by rule 1 it is now a speed-for-accuracy choice with both forms kept:

- DevicePolicy::unstored_dont_care_loads: UnstoredDontCarePolicy::Driver (the default) clears
  such an attachment on a driver with DriverFact::UnstoredClearNoSlower and leaves it DONT_CARE
  elsewhere, announced `dont-care-unstored-load` (a new precision notice); ::Cleared, which
  exact_answers() selects, clears it everywhere. The runtime's choice alone: no profile carries it.
- DriverFact::UnstoredClearNoSlower, a cost fact, one row per GPU measured no slower with CLEAR
  than DONT_CARE (a probe of eight 3648x2038 passes a frame, an RG16Float colour and a
  Depth32Float_Stencil8 loaded by the form and stored DontCare, GPU time per pass, medians of 15
  frames in two rounds): RADV, Mesa 26.2.6, on the Radeon 780M (861 and 865 us against 1147 and
  988, job m3-max-16320) and MoltenVK 1.4.2 on the M3 Max (218 and 218 against 224 and 217,
  within one form's spread, m3-max-16341). Measured slower, so no row: lavapipe (10480 and 10744
  against 7280 and 7259, m3-max-16321) and ANV, Mesa 26.2.6, on the Iris Xe (1936 and 1936
  against 1907 and 1151, m3-max-16343).
- The lane dont_care_unstored expects Metal's answer under exact_answers() and on a driver with
  the fact, lavapipe's earlier texels under the default there, and the notice exactly where the
  load is left to the driver.
- dont-care-store's text names the new answer after such a pass: where the pass loads the
  attachment DontCare and clears it, a tile no draw touches holds zero or the clear value.
- docs/FAST-PATHS.md: the switch's row with the per-driver numbers, and a known gap: separate
  depth and stencil textures (the scratch path) still load DONT_CARE under every policy.

NVIDIA is not measured yet; its row follows with the measurement.
2026-11-11 09:59:04 -08:00
Anees Iqbal f3f6696eb9 An unstored DontCare load in a pass that draws clears, as Metal's draws read it
Metal (an M3 Max, macOS 27.0.1, lane dont_care_unstored): an attachment a pass loads `DontCare`
and does not store reads zero (a color) or the pass's clear value (a stencil) wherever the pass's
draws read it, never its earlier texels. The runtime left such an attachment `DONT_CARE`
(clear_reach::dont_care_loads skipped every attachment the pass does not store): the first
instance's DONT_CARE load read 0 for the stencil (MoltenVK names no clear value there), later
instances of a split pass LOAD what the first left, so the tiles it did not reach read the
earlier texels, and a color the only instance leaves out (fetched through the pixel interlock)
read its earlier texels everywhere.

Now such an attachment (not memoryless, not separate depth and stencil textures) takes `Clear`
in a pass whose draws reach a tile: zero for a color (dont_care_clear), the attachment's clear
value for depth and stencil, by the first instance's load operation over the render area, and a
color that instance leaves out is cleared before the pass by the existing path for cleared
storage colors (cleared_ahead, or the reach pass over the render area). It is not tile-bounded
and not announced: no fragment reads a tile no draw touches, so the answer is Metal's wherever it
is read. `dont-care-load-tiles`' text, rustdoc and catalogue entry are scoped to stored
attachments; clear_reach.rs records Metal's measured answer and the rule.
2026-11-11 09:59:04 -08:00
Anees Iqbal 2fc317f6e3 Translator: OpenCL-mode image arguments reflect as the textures bound, of no data type
What: AIR names an OpenCL C image's component `unknown` (`texture1d<unknown, read>`), which the
reflection's type grammar did not parse, so a pipeline of OpenCL mode with an image argument had
no reflection (Unsupported, Feature::Reflection, naming the type). Now:
- reflection/types.rs: a texture whose component AIR names `unknown` reflects data type
  DataType::None;
- canon::opencl::entry, the entry as a pipeline of OpenCL mode binds it: a 1D image's texture is
  the 2D one Metal's OpenCL binds (`texture1d<..>` -> `texture2d<..>`, `texture1d_array<..>` ->
  `texture2d_array<..>`, bound_texture), as canon::opencl_1d already reads it, so its binding
  reflects TextureType::Type2D / Type2DArray.
Only the reflection reads an argument's type name; lowering and binding are unchanged.

Why: Metal states exactly that. The probe opencl_image_reflection on the M3 Max (macOS 27.0.1,
job m3-max-16390) reflects every image of an OpenCL-mode pipeline as MTLDataTypeNone, whether
read as float, int, uint or half, written, only queried or unused; image1d_t as 2D and
image1d_array_t as 2DArray (as the clmode-images probe found on the M3 Max and a Radeon Pro
5300M). The data type is not the element type a kernel reads: Metal answers None for every one.

Tests: engine_opencl_mode::an_opencl_mode_pipeline_reflects_its_images_as_the_textures_bound_of_no_data_type
reflects an owned fixture (image1d_t arguments read as float, int, uint and half, an
image1d_array_t, a write-only image1d_t, a buffer) and holds each texture binding to the M3 Max's
answer (type, None, access, not depth, length 1) and the buffers to theirs; before this commit
its reflection is refused. reflection::tests::the_type_grammar_names_textures parses the
`unknown` component.

Docs: canon::opencl's module docs and docs/API.md's OpenCL-mode images.

SEMANTICS_VERSION 2033: a reflection the translator refused it now answers.
2026-11-11 09:54:16 -08:00
Anees Iqbal 49175d0a24 Runtime: a copy made after a failed import of no-copy pages names the failure in its notice
What: the copied-host-pages announcement of a no-copy buffer, heap or rebind made a copy because
the import the device and the gate admitted failed (WorkCounts::copied_host_buffers_degraded)
said only "their import failed". It now names the failure (FailedImport::cause in
buffer_descriptor.rs): for pages the runtime kept from a driver whose failed import of
unpinnable pages breaks it (RuntimeDriverDefect::UnpinnablePagesBreakHostMemory, NVIDIA's), that
the kernel cannot pin some of them (a dma-buf's mapping, VM_PFNMAP, or one it could not ask
about), and whether a source of their dma-bufs was asked (none given or the device imports no
dma-buf; or the caller's source made none, or the device refused them); for an out-of-memory or
other Vulkan failure, whose import failed (the pointer's, or the caller's dma-bufs' after the
pointer's refusal) and the error. The copy path carries the failure and whether the source was
asked (CopiedFor::Failed(FailedImport), the rebind's Err(Some(FailedImport))); copied_pages
borrows the error. Nothing else changes: the counts, the copies and every refusal are as before.

Why: on the RTX 5080 the consumer's no-copy buffer over a view mapped through two udmabufs was
copied (copied_host_buffers_degraded 1) with no notice line saying why, and finding the cause took
a round trip.

Docs: the CopiedHostPages declaration and docs/API.md's catalogue entry say the reason names the
cause.

Tests: tests::host_memory::a_copy_after_a_failed_import_names_the_failure (no device) holds the
four causes' words. tests::host_ram_device::pages_refused_before_the_driver_with_no_source_are_copied
now announces each copied-host-pages (DeviceOptions::announce_each) and, on a driver with the
defect, asserts each of the buffer's, heap's and rebind's three reasons names the unpinnable
pages, the defect and that no source was asked, printing each (HOST-RAM-COPIED). Before this
commit each reason was "their import failed", which names none of them.
2026-11-11 09:54:03 -08:00
Anees Iqbal 9d024acefe Runtime: a tiled texture's take whose encoder runs nothing is given back
A tiled texture of more than one level over a buffer takes its copy of the
bytes at the first use encoded after its making or a did_modify_data,
which clears its mark. Where that encoder runs nothing because its command
buffer failed before it ran (committed as failed, an encoder a failure
names, a protection fault, a submission that fails EncodedUseRebound or
DetachedBacking, a hang's discard or recovery, a predication record that
drops it), the copy was never taken but the mark stayed cleared, so every
later use read zeros or an older copy until the next did_modify_data.

The take is now given back where the runtime knows its recording will not
run: State::fail_part, the one point every such failure releases a part
through. The mark is an AtomicU64 whose low bit is the mark and whose
upper bits count the takes; LevelsCopy::take returns the take's number,
and give_back(number) sets the mark again only where that take is still
the latest and nothing set the mark since (a later take holds its own
copy; a did_modify_data since already asks for one), so giving back twice,
or after a later take, changes nothing. shadow::Takes now holds each take's
number and a weak hold of the texture's copies; every ended encoder's
record keeps its takes (not only one whose log is kept), and a recorded
segment carries its own core's takes, both given back by fail_part.
ShadowSync::forget gives its takes back by number too.

An encoder split into parts at a host step gives back every take of its
own where any of its parts runs nothing, so a take that ran in an earlier
part is taken again at the next use when only a later batch fails; that
gap is in docs/FAST-PATHS.md's known gaps. docs/API.md and shadow.rs state
the rule.

Tests: tests::shadow gains a unit test of the give-back's rules (latest
take, a later take, a mark set since, twice, forget). The device tests of
the previous commit fail without this change; the runs of both commits are
in the report.
2026-11-11 09:41:44 -08:00
Anees Iqbal a0de370951 Runtime: the pipeline creation log names each compute VkPipeline and its precision notes
METAL2VULKAN_LOG_PIPELINES logged render VkPipelines only, so a consumer reading the log for a
compute state's notes (an OpenCL-mode kernel's native-nan-encoding) found nothing. A compute
variant now keeps its kernel stage while the log is on (VariantObjects::logged, None while it is
off), and each compute VkPipeline it makes logs one line through the device's sink (id name
metal2vulkan-pipeline-creation, Info): the kernel's entry, its SPIR-V (hash and words), each
specialization constant (id, meaning, value), the precision notes the stage holds under that
specialization, and the creation's wall time. No numbering, diff or split: a compute state's
pipelines differ by their specialization alone, which each line prints whole. Nothing is kept
or measured while the log is off.

Docs: creation_log's module docs, env_vars' METAL2VULKAN_LOG_PIPELINES, docs/API.md.
2026-11-11 09:37:09 -08:00
Anees Iqbal e8418615f1 Translator: a storage slot its function only queries binds a swizzled texture unswizzled
A guest's OpenCL kernel that only queries a write-only image Apple's OpenCL binds as a swizzled
view (CL_BGRA over an RGBA8Unorm view, and on an M3 Max every CL_UNORM_INT8 order but RGBA and
RGBx) failed: the plan joins a storage slot to the swizzled-storage variant only where its
function reads or writes texels, so a query-only slot kept the texture's swizzle on its storage
view, which Vulkan cannot swizzle, and the runtime refused the binding
(NotImplemented(TextureSwizzle)). The guest then read zeros.

A query reads no texel, and what it answers (the view's size, levels and layers; an OpenCL
image's order and data type, which the third hidden buffer holds) no swizzle reaches. Measured
on an M3 Max, macOS 27.0.1 (probe opencl_swizzled_images, job m3-max-16336): plain Metal's
get_width/get_height of a swizzled view at an access::write slot answer the view's size, and
OpenCL mode's width, height, order and data-type queries answer the size and the hidden words,
on every swizzle measured. So the plan now binds such a slot's storage view with no swizzle
(ImageViewDesc::shader_swizzle, under no variant): exact.

The same probe confirms the rest of the contract the crate already builds, in plain Metal and
OpenCL mode alike: reads (read(), read_write, sample, read_imagef with and without a sampler)
answer the swizzled texel, and writes (access::write, read_write, write_imagef) store it with
the swizzle undone. The channel order table and the swizzle never both apply: the table answers
queries only, the swizzle moves texels only.

Docs: ImageViewDesc::shader_swizzle, the runtime's binding_view and view_plan, docs/API.md's
OpenCL-mode images. REFUSALS.md regenerated, unchanged.

SEMANTICS_VERSION 2033.
2026-11-11 09:37:09 -08:00
Anees Iqbal eddd9112aa Runtime: an encoder encoded again takes a tiled texture's copy where its first encoding took it
A tiled texture of more than one level over a buffer is a copy of the bytes
taken at use: the first use encoded after its making, a did_modify_data or
a level-0 replace_region clears the texture's mark and records the copy in
and the later levels. A rebind of a no-copy buffer (or heap) the encoder
also named, before its command buffer's first submission, encodes the
encoder again and puts that recording in place of the first, which is never
submitted. The encoding again found the mark already cleared, recorded no
copy, and the texture's levels kept zeros or an older copy for good; a
did_modify_data made after the commit was cleared by the encoding again
instead of the next use.

The decision now belongs to the encoding. ShadowSync notes, in order, what
each first use of a copy taken at use decided (shadow::Takes); the ended
encoder's record keeps that with its log, and the core an encoding again
records into (EncoderCore::replaying, fed by reencode.rs through
State::replaying_takes) takes each copy where the use in its place took it,
never touching the mark. Its forget gives nothing back to the mark either.

Other per-encoding state checked for the same shape: the shadow carry (an
encoding again starts with none and copies the truth in, which earlier
encoders copied back to as they ended; drops-writes shadows are never
carried), gated copy-ins and standings (decided at batch submission, which
sees the recording put in place), heap tiled and multisample sample moves
(planned per recording, no mark), and segments recorded again on the GPU
alone or at a host step (their shadow copies were planned by the encoder,
not decided again). None consumes a mark at encoding.

Verified at the parent (66b00df138), lavapipe, jobs m3-max-16324/16333:
all four tiled_texture_reencode tests fail (levels read zero through the
encoding again; the next use after a did_modify_data took nothing). The
new CPU unit test in tests/shadow.rs covers the decisions directly. Runs
of this commit follow in the report.
2026-11-11 09:11:38 -08:00
Anees Iqbal daf963ab80 Docs: on NVIDIA, a device kept to the exit can fault in the driver's own exit handler
What: FAST-PATHS's known gap of NVIDIA exits now names the cause and the measured rates, and
HOWTO (section 8), the runtime README (at the process's exit) and API.md's accepted differences
tell consumers to drop the runtime's devices before the process exits on that driver.
exit_guard.rs and tests/exit_guard.rs, comments only, say that the 5080's fault in
libnvidia-glvkspirv.so also comes with no making in progress.

Why: reims-vgpu's test an_adopted_device_starts_its_in_place_check (device kept in a static,
check waited for to its end, then the test process exits) died with SIGSEGV after "ok" on the
RTX 3090. Reproduced with the runtime alone (a scratch example: device made on a named thread with
an empty shader cache of its own, in-place check started and waited for, device kept, main
returns). Every core shows the same thing: a worker thread of NVIDIA's driver, started from the
thread that made the device and so carrying its name, faulting at libnvidia-glvkspirv.so+0x363a8
(`mov 0x18,%rax; ud2`, a null dereference trap) while the main thread runs libEGL_nvidia.so's exit
handler inside exit(). No runtime thread was in a section or in the driver. reims's two cores
on that node (pids 106291, 170154) faulted on a thread named after the test thread, which libtest
joins before printing "ok", so a thread the driver started.

How verified (RTX 3090, NVIDIA 620.70.06, 8 processes at once, 80 exits each):
- exit right after the check ended, device kept: 6/80 SIGSEGV (potluck m3-max-16257)
- exit 3 s after the check ended: 0/80 (m3-max-16279)
- device dropped before the exit: 0/80 (m3-max-16280)
- no check, exit right after creation / 6 s after: 0/80 each (m3-max-16278, m3-max-16277)
- lavapipe (Mesa 26.2.6), exit right after the check: 0/20 (m3-max-16283)
Vulkan has no call that waits for the driver's worker, and a dropped device leaves none, so
the remedy is the consumer's drop, documented; no runtime behaviour changes.
2026-11-11 09:04:14 -08:00
Anees Iqbal 395e5c3305 Runtime: a tiled texture's take makes every format's later levels, and its first level is the bytes to the CPU
A tiled texture of more than one level (Buffer::new_tiled_texture) is a copy of the buffer's
bytes taken at use. Two leftovers from that change against what two x86 Macs answer:

1. Its take made the later levels only by the device's blit chain. A format generate_mipmaps
   makes by the compute filter (an extended-range one, an 8-bit sRGB one held as its UNORM twin,
   one without blits or linear filtering) or by the integer picks kept zeros past its first level,
   where Metal makes every level. Now the making keeps generate_mipmaps' own plan of the format
   (shadow::LaterLevels: the blit chain, the compute filter or the picks, announced as that call
   announces them; Kept for a format it leaves or refuses, or a scratch past the device's
   limits). The encoder makes a take's filter or picks run as it plans the copy
   (EncoderCore::later_runs, beside sample_moves: the scratch, the kernels and sets), held by the
   command buffer, and the copy in records it after its copy into the first level, behind a
   barrier, as it records the blit chain: transfers of the image and dispatches over the scratch
   alone, outside any render pass, before the first command that uses the texture. A filter take
   counts in WorkCounts::mipmaps_filtered. mipmap_filter.rs and mipmap_pick.rs split their
   recording into FilterRun and PickRun, which generate_mipmaps and the take share; what
   generate_mipmaps records is unchanged. A run that cannot be made (no room for the scratch)
   fails the command buffer, as a heap texture's sample moves do.

2. Its CPU calls reached every level in the image. On the Macs, getBytes and replaceRegion of
   level 0 address the buffer's bytes, and a replaceRegion there makes the next use take the copy
   again, as didModifyData does. Now level 0 reads and writes the bytes (Texture::level_in_image),
   a write there marks the copy stale, and while the bytes are detached level 0 is refused
   (NotImplemented(DetachedTexelAccess)) as a one-level texture's is. Levels 1 and up stay in the
   image (the GPU reads a replace_region there until the next take), where the Macs' GPU never
   sees such a write: an accepted difference in docs/API.md and the rustdoc. Blits are unchanged.

Tests (tests/tiled_texture_device.rs), each failing before its fix: RGBA8Uint's later levels are
plain Metal's picks exactly after a blit first use, and after a pass into level 1 as the first use
(level 1 cleared over the picks, the rest picked); BGR10XR's later levels are within the compute
filter's bound of the level above, the take counted once in mipmaps_filtered; level 0's get_bytes
reads the bytes before the first use, after a GPU write into level 0 (which the GPU reads) and
after a CPU write of them (which no level sees); a level-0 replace_region writes the bytes (the
rows' padding kept) and the next use takes the copy again, every level made from it. The detached
test now holds level 0 refused while detached and reads the new pages' bytes after a rebind.

Docs: new_tiled_texture's, replace_region's, get_bytes's and did_modify_data's rustdoc,
DetachedTexelAccess, WorkCounts::mipmaps_filtered, shadow.rs's Copies taken at use, the filter and
pick modules, docs/API.md (the tiled texture and an accepted difference), docs/RUNTIME-PORTING.md,
docs/FAST-PATHS.md's known gap narrowed to formats generate_mipmaps leaves or refuses, and
docs/REFUSALS.md regenerated (the MipmapGeneration sites moved). RUNTIME_VERSION and the
runtime-sources pin are left to the landing.

Checked here: cargo fmt. Clippy in three configurations, rustdoc and the device tests run as
cluster jobs on this commit.
2026-11-11 08:37:22 -08:00
Anees Iqbal 08fcc2375b Docs: the small-heap blocks' and the least queue plan's measured numbers on an RTX 2080 and an RTX 3090
What: the runtime README, the degrade-notice catalogue, FAST-PATHS' memory-blocks bullet and the
rustdoc of pooled_block_bytes, made_within_resources, DeviceRefused and LeastQueuePlan now state
what the after runs measured, and no longer name the BAR as what the driver lacked when it refused
a device: in these runs it was not (BAR1 stayed under 30 of 256 MiB), and the kernel logged a
channel instance-block allocation failure.

Evidence (potluck, NVIDIA 620.70.06, at cad545d601, --cfg m2v_gpu --cfg m2v_gpu_hazards):
- RTX 2080, 256 MiB BAR1 (m3-max-16089, um790):
  - one process, devices kept live: BAR1 5 -> 8, 10, 13, 15, 18, 20, 23 MiB for devices 1-7
    (before, at 239d729627: 5 -> 72, 138, 205, then +2-3 each); pools at open Buffers@1,
    Buffers@4, Images@1 of 64 MiB, none of the BAR type (before: Buffers@5 64 MiB too). The 8th
    device refused with 17 VkQueues and then with the least plan's 2 (DeviceRefused, two attempts).
    Kernel: kchannelAllocMem_GM107 "Instance block allocation ... failed", "Could not create
    Channel", NV_ERR_NO_MEMORY.
  - 16 processes 3 s apart, one device each: p1-p7 made with 16+1 VkQueues (BAR1 5 -> 26),
    p8 and p9 made with the least plan (vk_queues=1, BAR1 -> 28, 29), p10-p16 refused with both
    plans at BAR1 29 of 256 MiB. Before (m3-max-16046): 7 made, p8-p16 refused at BAR1 218.
  - touched device tests 11/11 (small_heap, least_queue_plan both branches' made path,
    queue_limits, the block-size rule); LEAST-QUEUE-PLAN: took 1 + 0 of the plan's 14 + 2.
- RTX 3090 control (m3-max-16085, gem10): one process BAR1 3 -> 6, 8, 11, 13, 16, 18, 21 for
  devices 1-7 (before: 3 -> 70, 136, 203), the 8th refused with both plans; touched tests 11/11.
2026-11-11 08:31:42 -08:00
Anees Iqbal 21a01a4d7b Device creation: a device the driver refuses for want of resources takes its least queue plan once, else Error::DeviceRefused
What: create_on makes the device through made_within_resources. Where vkCreateDevice answers
VK_ERROR_INITIALIZATION_FAILED or VK_ERROR_OUT_OF_DEVICE_MEMORY for the queue plan's VkQueues and
the least plan (LEAST_QUEUE_LIMITS: a round robin of one VkQueue, none reserved for presenting;
the reserved, extra and staging queues kept, as DeviceOptions::queue_limits of one and none
places them) takes fewer, it asks once more with the least plan's. A device made so announces the
new Performance degradation least-queue-plan (Degradation::LeastQueuePlan, naming both plans'
VkQueues and the driver's answer), sends none of the queue limits' informational messages (the
limits are the runtime's, not the caller's), and its presenting queue's shared-present-queue
notice says why it reserved none. A second refusal, or one where the least plan takes no fewer
(RADV's and lavapipe's one graphics queue), is the new typed Error::DeviceRefused(DeviceRefused
{ device, attempts }), naming each attempt's VkQueues and answer; before, it was Error::Vulkan(-3)
or Error::OutOfMemory(Device). Any other failure is the driver's as before. A recovery's new
VkDevice is made the same way.

Why: on an RTX 2080 (NVIDIA 620.70.06) devices of the plan's 17 VkQueues were refused from the
eighth live one, in one process and across processes alike (tests::many_devices at 655ed906fb:
seven made, p8 to p16 refused with VK_ERROR_INITIALIZATION_FAILED while BAR1 had 38 MiB free),
where a consumer measured the GPU's channel heap holding about 160 to 180 channels, raw 16-queue
devices refused from the 11th and 1-queue devices made 24 of 24.

Public surface (api_signatures.tsv blessed): Error::DeviceRefused and DeviceRefused are new, and
Degradation::LeastQueuePlan. A consumer that matched Error::Vulkan or Error::OutOfMemory from
Device::system_default* for a refused device now gets Error::DeviceRefused.

Tests: tests::queue_limits::a_device_refused_for_want_of_resources_is_asked_for_once_with_its_least_plan
(no device: NVIDIA's family shape with a reserved and an extra queue, 18 VkQueues then 4; made at
once, made with the least plan after either refusal, refused naming both attempts, any other
failure the driver's, and one attempt where the least plan takes no fewer). tests::least_queue_plan
(device tests, refuse_next_devices stands in for the driver's refusal on the creating thread):
refused once, a device whose plan takes more than one VkQueue is made with 1 + 0 and announces
least-queue-plan once, its presenting queue's shared-present-queue naming it; refused twice, it is
Error::DeviceRefused with an attempt per plan. Verified on lavapipe (ms01, job m3-max-16047): both
pass on the refused branch (llvmpipe's plan is one VkQueue: "ERROR_INITIALIZATION_FAILED with 1
VkQueue(s)"); the made branch runs on NVIDIA next. scripts/refusal-surface --check passes
(REFUSALS.md does not list top-level Error variants).

Docs: docs/API.md's catalogue entry for least-queue-plan; the runtime README's device opening
(the fallback) and error table (DeviceRefused). RUNTIME_VERSION is the orchestrator's to bump at
landing.
2026-11-11 08:31:42 -08:00
Anees Iqbal e8ce0d2186 Translator: OpenCL mode clamps an integer conversion with .sat
In a compute pipeline of OpenCL mode both measured oracles clamp an
integer converted to an integer with .sat to the destination's range
(probe jobs m3-max-15651 on a Radeon Pro 5300M and m3-max-15652 on a UHD
Graphics 630, macOS 26.7.1, OpenCL C of our own, one work-item per
operand): int and uint to char, uchar, short, ushort, int and uint; long
and ulong to int and uint; ulong to long, long to ulong, int to ulong;
char to uint, uchar to int; and convert_uchar_sat_rte(int). The
translator wrapped (convert_uchar_sat(300) was 44 where both answer
255). Outside OpenCL mode it still wraps, as the 5300M and the 630
answer there (docs/API.md).

ConvertKind::Int carries the destination's signedness where `.sat` is
honored (arith::honored); the conversion first clamps the held source to
the destination's range (math::saturation_bounds: a bound the source's
own range keeps is skipped), by the source's signedness, on native
integers and on the wide pairs, then converts as before.

Tests: every source of 8..64 bits (signed and unsigned) into every
destination of 8..64 bits (signed and unsigned) around each width's
bounds, native (convert_suffix.rs) and wide (wide.rs), on the
interpreter against exact references; the measured int-to-int forms join
tests::engine_convert_rounding's table (OpenCL mode answers both
oracles' words, outside it the wrapped plain answer).
2026-11-11 07:16:27 -08:00
Anees Iqbal 9e6a8b8a96 Translator: OpenCL mode honors air.convert's directed roundings
In a compute pipeline of OpenCL mode (LowerInputs::open_cl_mode, set
from ComputePipelineDescriptor::open_cl_mode_enabled) Metal honors the
rounding Apple's OpenCL compiler spells after a conversion's types.
Measured over OpenCL C of our own, one work-item per operand, probe jobs
m3-max-15651 (Radeon Pro 5300M) and m3-max-15652 (UHD Graphics 630),
macOS 26.7.1: both round an integer of 8 to 64 bits to float by rtz,
rtp and rtn, and a float to an integer of 8 to 64 bits by rte, rtp and
rtn (then saturate), exactly; neither creates an OpenCL-mode pipeline
for a conversion with a half side. Outside OpenCL mode the Macs answer
most of these as the plain conversion (docs/API.md), so honoring there
would leave every Mac's answer: the translator keeps the plain
conversion outside OpenCL mode.

The device has no directed conversion, so each is built exactly:
- float to integer: RoundEven, Ceil or Floor before the existing
  clamp-and-truncate (the NaN test still reads the operand);
- integer to f32 by rtz/rtp/rtn: the device's conversion (correctly
  rounded in a direction of its own), converted back exactly and
  compared with the integer (2^k told by a float compare), then moved
  one unit in the last place in the bits where it lies on the wrong side.
Both on native integers and on the wide pairs (no shaderInt64).
`arith::honored` decides per form; a half side, rte to float and rtz to
an integer stay the plain conversion.

SEMANTICS_VERSION 2030: an OpenCL-mode module holding such a conversion
changes. The function compile key already appends open_cl_mode; its
coverage test now asserts it.

Tests:
- arith/tests/convert_suffix.rs and wide.rs: every directed rounding of
  i16/i32/i64 (and wide i40/i64) to f32, signed and unsigned, and every
  integral rounding of f32 to 8..64-bit integers (both NaN tests), on
  the interpreter against exact references, around 2^24, 2^25, 2^31,
  2^32, 2^63, 2^64 and ties; the brief's oracle words; selection per
  mode (only_a_pipeline_of_opencl_mode_honors_a_suffix).
- tests::engine_convert_rounding: each measured form, compiled in
  OpenCL mode on lavapipe and moltenvk-m3 without shaderInt64, passes L3
  and answers the 5300M's and the 630's words on the interpreter, and
  the same kernel outside OpenCL mode answers the plain conversion.
2026-11-11 07:16:27 -08:00
Anees Iqbal 24b460971e shadowed-texture: state a tiled texture's copy in its cost
The notice's cost said every shadowed texture is copied in before each use and back after each
write. A tiled texture of more than one level is copied in only at its first use and the first
after each did_modify_data, and never back, so its notice stated a cost it does not pay. The cost
string and docs/API.md's catalogue entry now name that form.

Verified: tests::degradation_catalogue (the catalogue states the announced cost) runs in the
lavapipe job of this tip.
2026-11-11 07:11:38 -08:00
Anees Iqbal 8f4a534b01 Runtime: a tiled texture of more than one level is a copy of its bytes taken at use
A mipmapped tiled texture over a buffer (Buffer::new_tiled_texture, more than one level)
read zeros past its first level: its first level was a shadow of the bytes kept in step at
command boundaries and the later levels were never written, so a minified sample of such a
texture drew black. Two x86 Macs (an AMD Radeon Pro 5300M and an Intel UHD Graphics 630 under
macOS 26.7.1, measured by the consumer on both SPI forms, Shared and Managed descriptors,
RGBA8Unorm and BGRA8Unorm) take a copy of the bytes at the texture's first GPU use, every
level generated from the first; again at the first use after didModifyData; between those no
CPU write reaches a level, and a GPU write to a level never reaches the bytes or the other
levels.

The texture stays one image of every level (Storage::Shadow), its shadow now a copy taken at
use (ShadowCopies::levels, a LevelsCopy): a stale flag set at the making and by the new
Texture::did_modify_data (Metal's private -[MTLTexture didModifyData]) is taken by the first
command of an encoder that uses any of its levels (its shadow range is every level now), which
records before it the copy of every texel of the first level and the device's blit chain over
the later levels (mipmap_plan's plan, record_blit), as generate_mipmaps makes them, announced
device-filtered-mipmaps. Every other use copies nothing in; nothing is copied back, kept or
merged; a change of the truth never makes it stale; a take whose encoding is left out is given
back. get_bytes and replace_region reach every level in the image; a detach no longer loads
the first level (keep_first_level, keep_first_levels, Writes and TexturesOver::keeping go), as
the image is its own copy. A format the device's blits do not filter has its first level copied
and its later levels left as they are: a FAST-PATHS known gap. The one-level form is unchanged.

Tests (tests/tiled_texture_device.rs, rewritten for the contract): the first use takes bytes
written after the making into every level (a uniform grey, the compositor's shapes and the
probe's 256x256 of 9 levels in both formats); every later level is the 2x2 box of the one
above (a gradient); a first kernel sample at LOD 1 reads the made level (zeros before); a CPU
write after the first use reaches no level and copies nothing; did_modify_data takes the copy
at the next use, not the call (the probe's steps); a blit into level 0 reaches neither the
bytes nor the later levels; a pass into level 1 takes the copy first; detached and rebound
bytes leave every level as taken until did_modify_data.

Docs: new_tiled_texture's and did_modify_data's rustdoc, shadow.rs's Copies taken at use,
docs/API.md, docs/RUNTIME-PORTING.md, docs/FAST-PATHS.md known gaps; the API signature table
blessed (+ Texture::did_modify_data). RUNTIME_VERSION and the runtime-sources pin are left to
the landing.

Checked here: cargo fmt. The device tests, clippy in three configurations and rustdoc run as
cluster jobs on this commit.
2026-11-11 07:11:37 -08:00
Anees Iqbal a4f6080b18 vstorea_half3: record the 5300M's write of the fourth half
The 5300M's vstorea_half3 writes the fourth half of each four (the half
after the three vloada_half3 read); the M3 Max and the UHD 630 leave it,
as the expansion does (probe job m3-max-15648 beside m3-max-15630). The
5300M and the 630 also read and write uchar3 and short2 at odd elements
as the M3 does. Docs only: canon::vector_data, tests::opencl_data,
docs/API.md.
2026-11-11 07:04:32 -08:00
Anees Iqbal 7f837c636d OpenCL C's native_/half_ functions and vector data loads and stores
Apple's OpenCL compiler spells OpenCL C's native_<fn> and half_<fn> of float
types air.native_<stem>.<type> and air.half_<stem>.<type>, and vload<n>,
vstore<n>, vload_half[<n>], vloada_half<n>, vstore_half[<n>][_<rnd>] and
vstorea_half<n>[_<rnd>] air.vload[a][_half].<space>.<type> and
air.vstore[a][_half].<space>[.<rnd>].<type>. None decoded, so pipelines of
real OpenCL workloads were refused as UnknownIntrinsic
(air.native_powr.v4f32, air.vload.global.v3i32,
air.vstore_half.global.rtz.f32).

- The math family reads native_ and half_ of the twelve stems Apple spells
  (cos, exp, exp10, exp2, log, log10, log2, powr, rsqrt, sin, sqrt, tan),
  f32 scalar and every vector width, as the function at Precision::Fast.
  Metal's devices answer native_powr apart (powr(100, 0.5): 0x1.400002p+3
  on the M3 Max, 0x1.4p+3 on the 5300M), so it is the device's fast form.
- A new family, AirIntrinsic::VectorData (VectorData, VectorDataOp,
  HalfRounding), decodes every address space and element type the
  compiler spells. canon::vector_data makes each call its element
  accesses before SCCP: lane i at element offset * stride + i, at the
  element's own alignment (stride 4 for vloada_half3 / vstorea_half3), a
  half widened by fpext or narrowed by fptrunc.
- vstore_half's rounding suffixes store as the device converts (nearest
  even): the 5300M and the UHD 630 store every suffix as _rte, word for
  word over 32 values, where the M3 Max honours them; agreed with main.
  docs/API.md records the row beside the convert entry.

Measured with an OpenCL-mode probe (owned kernels): vload3(i, g + 1) of
uint reads the 3 words that follow on the M3 Max, the 5300M and the 630;
vloada_half3 / vstorea_half3 step 4 halves, vload_half3 3, on the M3.

Public surface (api_signatures.tsv blessed): AirIntrinsic gains
VectorData; Query gains ChannelOrder and ChannelDataType (previous
commit); new types VectorData, VectorDataOp, HalfRounding. An exhaustive
match over AirIntrinsic or Query in a consumer breaks.

Tests: intrinsics decode tests for both grammars (and their refusals),
observed declarations, canon::tests::vector_data (element accesses at
folded indices), runtime device tests in OpenCL mode (tests::opencl_data:
vload3 past an unaligned pointer, uchar3/short2 at odd elements, half3
strides, vstore_half's suffixes, native_powr). SEMANTICS_VERSION stays
2030 (this branch's bump).
2026-11-11 07:04:32 -08:00
Anees Iqbal 27b9cedd7a Pipeline creation log: a state's first line names its descriptor; METAL2VULKAN_DUMP_PIPELINES writes each pipeline's SPIR-V
A live pipeline the log names could not be made again from its library: the line names the
state's functions and its key, not the constant values the functions were made with, nor the
blend and write masks, nor which library's bitcode. A state's first line now names the descriptor
(`StateDescriptor::logged`): each function's name, the SHA-256 of its bitcode
(`FunctionInfo::air_hash`; a precompiled function's key) and its constant values by index and by
name as type and bytes, each color attachment's format, blend and write mask (the notices' words,
`blend_text`, which `draw_at` now shares), the depth and stencil formats and the raster samples.

METAL2VULKAN_DUMP_PIPELINES names a directory (made where missing) each device writes every render
pipeline's SPIR-V modules into, one file per module, `<hash>.spv`, the hash the line names it by,
each written once; a failed write is named in the line. Setting it turns the log on too. Both are
default-off diagnostics: no pipeline, key or path changes with them.

Test: tests::pipeline_dump (device test) runs a child process that makes one state with a
constant and a blended color: with the dump directory set and the log variable unset, the first
line names each function's bitcode hash, the constant's type and bytes, the color's format, blend
and mask, and every module a line names is in the directory as SPIR-V of the words the line
counts; with the dump variable empty and the log unset, no line and no file.
2026-11-11 06:14:20 -08:00
Anees Iqbal 7a2221ccf7 NativeMinMax: state fast::median3's two-NaN answer in the recorded bound
What: the recorded bound of PrecisionNote::NativeMinMax (artifact.rs,
docs/API.md's catalogue, lower::arith's docs) now names the answer it left
out. A fast::median3 whose first two operands are NaNs and whose third is a
number answers the number. Metal's fast form answers the second operand, a
NaN. New test lower::arith::tests::specials::
median3_of_two_nans_beside_a_number_answers_the_number.

Why: the 780M venue re-record of nan-model-min-max-of-nan-operands-under-fast-math
(27f7c2fd) differed from the M3 Max in 50 of 1024 words under NativeMinMax.
42 fall inside the stated ties (two NaNs, signed zeros, a denormal). The 8
outside are median3 of two NaN operands beside +0: the device answers 0x0
where Metal answers the second NaN ([486] 0x0/0xffeaaaaa, [494]
0x0/0x7fc00001, ...). The 0 comes from the lowering's composition
min(max(c, min(a, b)), max(a, b)) of NMin and NMax, introduced by 9afdb1e150
(rule 1: the device's min and max). NMin and NMax answer the number beside a
NaN, so any composition of them answers c here; answering b would take a select
that emulates Metal's NaN pick, which rule 1 forbids. The answer is no
translator fold: it is precise median3's own answer on Metal (the twin
55bca0fd answers 0 at the same eight lanes), and MSL leaves a NaN operand
under fast math undefined (section 8.1), so Metal's fast NaN is one reading of
an undefined answer. The bound said "the one Metal answers but at three ties",
which these lanes broke. It now states the fourth difference.

Verified: the new test runs both forms on the interpreter over the four
two-NaN rows of MEDIAN3 and the case's eight lanes. Each answers the number,
which is precise Metal's answer. The table's fast answers are the second
operand in exactly the ten rows whose first two operands are NaNs.
2026-11-11 05:45:58 -08:00
Anees Iqbal 1e1a17581d FragmentSimdgroupGrouping: a discarding function's helper ballots over a quad, where Apple's GPU splits quads
What: a fragment function that discards, asks quad_is_helper_thread or
simd_is_helper_thread, and runs a group operation over other lanes now records
PrecisionNote::FragmentSimdgroupGrouping on every profile that does not take
DriverDeviation::MetalFragmentSimdgroups (lower::simd::finish,
discarding_quads_observed). The note's text (artifact.rs, docs/API.md, the
runtime's reason, C3's deferred bound, the comparison table, the deviation's
docs) now covers this case. SEMANTICS_VERSION 2028: these functions' artifacts
record the note.

Why: the 780M venue re-record (RADV PHOENIX, Mesa 26.2.6) differed from the M3
Max's Metal rows on four public cases with no note to explain it:
helper-threads-after-a-discard-over-full-quads (18/256 words),
-over-cut-quads (10/140), helper-threads-asked-before-a-discard (14/140) and
helper-threads-after-a-terminating-discard (10/140). The translation is right:
MSL 2.3+ and the MSL 2.2 discard followed by a quad operation demote, the query
is OpIsHelperInvocationEXT, and the entry declares RequireFullQuadsKHR
(engine_helper_threads pins the forms). The difference is in Metal's rows. On
the M3 Max (macOS 26.7 and 27.0.1 alike, and MoltenVK there word for word),
a function that discards has some 2x2 quads shaded as several partial quads
from the function's start, each run holding the quad's other covered pixels as
helpers. So a live pixel's quad_ballot of the helper query names covered
pixels as helpers: 3 of 16 quads at 8x8, 2 of 12 at 7x5 after the discard,
4 of 12 when asked before it. The same function without the discard
(helper-threads-in-a-fragment-function-*) runs every quad whole on Metal and
matches on the 780M. RADV shades a primitive's covered pixels of a quad as
one quad. Metal permits a partly occupied quad and does not fix which quads
it splits, so the device's answer is one Metal allows. Nothing in Vulkan pins
Apple's split, so no exact path exists. The note's existing family is
FragmentSimdgroupGrouping: which pixels Apple's rasterizer packs together,
gated by MetalFragmentSimdgroups, and deferred in C3. Its text claimed "a quad
is the same 2x2 pixels on every device", which these rows disprove for
discarding functions. A helper computes what its covered pixel would, so only
a helper query tells the runs apart. The predicate therefore needs the
discard, the query, and an operation over other lanes.

Verified: tests::engine_helper_threads::
a_discarding_function_s_helper_ballots_record_the_grouping_where_the_driver_is_not_metal_s
(the 780M's profile records it for all three discarding functions, MoltenVK's
for none; the no-discard function and the discard-with-query-but-no-quad-op
function record none anywhere).
2026-11-11 05:45:58 -08:00
Anees Iqbal ac0fcfa7fd Docs: a texture over dma-buf pages bound at its texels' offset, where the driver answers another plane offset
What: HOWTO's dma-buf section and API.md's in-place and shadow-cause paragraphs say when a texture
over dma-buf pages takes an image of a plane at offset 0 bound at the texels' offset (a driver
that lays the explicit plane out at another offset, Honeykrisp's answer; an image that requires
no dedicated allocation, which RADV requires, and whose alignment divides the offset), counted in
WorkCounts::dma_buf_images_at_offset; WorkCounts::dma_buf_image_memories_live says such an import
is no dedicated one.

Verified: tests::dma_buf_plane_offset on RADV PHOENIX (requires a dedicated allocation: the
forced route is refused, the texture a shadow that reads its texels) and on lavapipe (Mesa
26.2.6: the forced route binds at offset 2048, in place, and reads its texels and the CPU's later
bytes).
2026-11-11 05:10:15 -08:00
Anees Iqbal 26440eaa22 Push set 0 on MoltenVK for a fragment stage that writes a set-0 storage buffer in its interlock
MoltenVK, binding through Metal argument buffers (the state device/argument_buffers.rs reads
from the limits; a device without them is refused at open), makes a bound set 0 one Metal
argument buffer, and marks each storage buffer a fragment stage reaches inside its interlock as a
member in raster_order_group(0). Metal leaves such a member unordered where the function also
reads another buffer member of the same argument buffer. A pushed set is discrete in either of
MoltenVK's modes, and Metal orders a discrete [[buffer(n), raster_order_group(0)]].

RuntimeDriverDefect::InterlockedBoundBuffersUnordered names it, on every MoltenVK GPU (keyed on
the driver, as the push holds however the device binds). There a render variant whose fragment
stage writes a storage buffer of set 0 inside its interlock pushes set 0, read from its words
(pipeline/interlocked_writes.rs: an interlock execution mode, a StorageBuffer variable of set 0
not decorated NonWritable). PushedBufferSizesUnset stays: such a variant pushes only where no
stage reads a buffer's length (OpArrayLength, OpUntypedArrayLengthKHR) and no binding of set 0
lists a stage the pipeline adds; otherwise it binds set 0 as before and announces the new
Degradation::InterlockedBufferOrder (`interlocked-buffer-order`, precision), as it does on a
device without the push command or with a set 0 no push layout takes. Nothing is refused.

Every other path is unchanged: the device now loads the push command on MoltenVK too (and primes
it), but pushes_set_zero there admits only those variants; runtime kernels stay bound
(OwnedKernel::pushed requires pushed sets that hold their sizes); every other driver decides as
before. No new DriverFact or WorkCounts field: the lane reads draws_pushing_set_zero.

Tests:
- tests::interlocked_writes: the translator's own modules of ipo_primitive_order for the
  committed MoltenVK profile (only ipo_rog_buffer's fragment stage interlocks with a writable
  set-0 buffer; no stage reads a length), and synthetic words for each fact.
- runtime_lane::interlocked_primitive_order: a RogBuffer draw must push set 0 where the device
  pushes it (draws_pushing_set_zero), and on a driver whose pushed sets lose their sizes no other
  draw may push; a_bound_set_of_interlocked_buffers_is_announced_once, the bound form with
  VK_KHR_push_descriptor withheld, the degrade site BOUND_INTERLOCKS.
- tests::driver_defects lists the defect for the MoltenVK profile; api_signatures.tsv blessed
  (two rows); docs/REFUSALS.md regenerated: unchanged. docs/API.md: section 5's pushed set 0 and
  the catalogue entry.

Evidence so far, Apple M3 Max, macOS 27.0.1, MoltenVK 1.4.2: Metal itself, our own MSL, 96 passes
each: a raster order group buffer member beside a buffer member the function reads lost writes in
96 of 96, with the width read elsewhere 0 of 96, a texture member 0 of 96, the member alone 0 of
96; MoltenVK's own Metal for the lane's stage 48 of 48, the same with the buffer discrete 0 of 48.
Through the runtime at 83d2d86519 (set 0 bound) the lane's RogBuffer lost writes in 96 of 96
passes (m3-max-14866); with every set 0 pushed (a probe arm) 0 of 96 (m3-max-14930). The fix's
own lane run is reported with the tip.
2026-11-11 04:57:58 -08:00
Anees Iqbal 1f7b2a67cf No-copy memory with no dma-buf source is a copy on a device without VK_EXT_external_memory_host
On a device that imports no host pointer but imports dma-bufs (Honeykrisp
on Asahi lists no VK_EXT_external_memory_host), a no-copy buffer or heap
over memory with no source of dma-bufs was refused, naming the extension.
Metal makes such a buffer, and in place is impossible there, so it now
takes the copy a refused pointer with no source takes on RADV
(CopiedFor::DeviceRefused): announced as copied-host-pages, counted in
copied_host_buffers_device_refused, with every copy's coherence.

How: host_window marks such pages pointerless (the device imports no
pointer, the memory is not dma-buf-only). buffer_over_host_parts no
longer takes the no-route refusal for them, so they reach
import_by_pointer, whose not_importable answer is the device's refusal;
a source that fails counts as the device's refusal there too, as on
RADV. Rebinds to such memory, a guest RAM with no source, and every
no-copy object on a device with neither route stay refused, naming the
extension. The in-place check no longer makes its pointer-class buffer
on a device that imports no pointer (it would be an announced copy now);
its verdict there stays lasting, as before.

Docs: the copied-host-pages detail, CopiedFor, CopiedBecause and the
counter, copied.rs, host_memory.rs, the no-copy buffer and heap calls,
imports_shared_host_pointers, host_ram/copy.rs, the runtime README, the
API catalogue and HOWTO section 6. docs/REFUSALS.md regenerated:
unchanged, as the extension's refusal sites all remain.

Verified by the device test in the previous commit (lavapipe and the
780M, see the hand-off).
2026-11-11 04:09:01 -08:00
Anees Iqbal aba3c0969c A render pass instance's first fetch between draws records after its load operations
On RADV on the RX 550 (Polaris, neither ordered fetch form of its own; job m3-max-14807) the first
fetch of a render pass instance read a load-cleared RGBA32Uint attachment as 0: the lane's three
exf_fetch_count draws stored (k + 1) * 13 for c * 27 + (k + 1) * 13, and
fetched_attachments_clear_as_the_load_action_does counted 7, 200, 13, 255 beside the tag for
10, 206, 22, 267. Each read after a barrier between draws was right. Vulkan orders the load
operations before every access of the instance through the attachment, but this driver did not
make the clear visible to the input attachment read; the barrier between draws, inside the
subpass's own dependency, does. So an instance begins with InterlockedStorage::BEGUN, the
fetch-after-writes kind alone set: the first draw that reads input attachments ordered between
draws alone records the barrier too. No draw of another device reaches that kind, so nothing else
changes.

The lane test now counts one more barrier in each pass (4, 3, 1) and states what a first read of
0 leaves. API.md, the runtime's framebuffer_fetch and InterlockedStorage docs and
WorkCounts::fetch_draw_barriers say the load operations are among the writes a fetch records
after. To be verified on the RX 550.
2026-11-11 04:01:36 -08:00
Anees Iqbal 1326854199 between_draws: the note is announced where the fetching pipeline is made
On llvmpipe with both ordered forms withheld (job m3-max-14744) the draws in order read 0.25 at
every texel with three barriers, and the test then found no unordered-fetch-within-draw notice:
the runtime announces a stage's precision notes where its pipeline is made (degrade_stages), as
it does every such note, and the test had taken the notices after making the pipelines and
dropped them. The test now asserts the note once at the first fetching pipeline's making and none
after the draws; the runtime's framebuffer_fetch docs, API.md's catalogue entry and the test's
module docs said it was announced at the first draw that binds the pipeline, and now say so no
more.
2026-11-11 04:01:36 -08:00
Anees Iqbal 3d18018dad A raster order group on a color read takes no interlock where fetch is ordered between draws alone
On a device with neither rasterization-order color attachment access nor the pixel interlock, a
color input reads its input attachment ordered between draws by the runtime's barriers. A raster
order group on that input (fragment_fetch's fetch_ordered), or on a color output of an attachment
the function reads, asks for the order of that read, which is the read's own form there; it no
longer interlocks the function, so such a function is no longer refused RasterOrderGroups after the
fetch itself stopped being refused. Its overlapping fragments of one draw stay unordered,
PrecisionNote::UnorderedFetchWithinDraw, which the read records. A group on a buffer, texture or
imageblock member still needs the interlock. Devices with an ordered fetch form keep their path
(rog::declared is unchanged where fetch::fetch_unordered is false).

The conformance cases that fetch (fetch_ordered, srgb_fetch: one fullscreen triangle a draw, so
every byte still compares exactly) name unordered-fetch-within-draw among their notice allowances,
so a venue with neither form (RADV on the RX 550) replays them against the M3's recordings.

Tests: the compile test draws fetch_ordered on lavapipe's description without either ordered form
(input attachment, neither feature required, noted) and with the interlock (interlocked, as
before); engine_dead_reads' live dfr_output on vk12-floor now compiles without an interlock,
noted (before, refused RasterOrderGroups). Docs: API.md's fetch paragraph and catalogue entry,
rog.rs's module docs, the note's doc.
2026-11-11 04:01:36 -08:00
Anees Iqbal 22a96f62d4 Docs: framebuffer fetch between draws, its note, REFUSALS and the API signatures
docs/API.md's framebuffer-fetch paragraph says what a device with neither
ordered form does, and the degrade-notice catalogue gains
unordered-fetch-within-draw. docs/FAST-PATHS.md's device-gap table gains its
row. docs/REFUSALS.md regenerated (FramebufferFetch loses the
unsupported_features and family-row sites). api_signatures.tsv blessed: the
PrecisionNote and Degradation variants and WorkCounts::fetch_draw_barriers.

Verified: refusal_surface.py (0 without reach mark or basis), signatures.py
--bless (3 added).
2026-11-11 04:01:35 -08:00
Anees Iqbal b39d22516f Four runtime messages are said once per device and kind, each later one counted
What: metal2vulkan-heap-texture-refused (Info, a placement heap's texture not
made at an offset inside it), metal2vulkan-twin-decode-failed (Error, a decoded
twin's failed CPU decode), metal2vulkan-late-reservation (Warning, an ignored
late reserve_resource_ids call) and metal2vulkan-queue-limits-reached (Info,
each placement or queue-sharing read the queue limits changed, at device
creation, per queue made and per report) were said at every occurrence. They
now go through the degradations' once-per-device record: Announced keeps a
bit per kind of a closed vocabulary of messages that are no degradation
(degradation::Told), and Device::tell says a kind's first message on the device
(through its sink, else stderr) and counts each later one, without making its
text, in the kind's new WorkCounts field: heap_texture_refused_withheld,
twin_decode_failed_withheld, late_reservation_withheld,
queue_limits_reached_withheld. Device::inform_once is the informational form.
Every refusal and answer is as before; only the messages' rate changes.

Why: the owner's rule (11-11): a degradation, fallback or refusal message is
logged once per kind and device, later occurrences counted, never logged per
call. reims's sweep at ef7af82fe4 found these four firing per occurrence.

Tests: tests::told_once (each kind said once and its later one counted on
one device, said again on another; a second late reservation counted, not
said); tests::heap_refused_notice (the second refusal on a device counted, not
named; another device names its own first); tests::queue_limits_device (the
first case met is sent, every later one counted; a second read of the sharing
counts one more). api_signatures.tsv takes the four fields; the docs of the
four messages (texture.rs, resource_ids.rs, DeviceOptions::queue_limits, the
runtime README, docs/API.md) say the rate.

Verified: see the branch's report.
2026-11-11 02:45:22 -08:00
Anees Iqbal 3811e1c184 air.convert's rounding and .sat suffixes: the conversion the types name, as x86 Metal answers
The exact emulation of the directed roundings, the integer .sat clamp, float-to-int pre-rounding,
the RoundingModeRTE plan and PrecisionNote::NativeConversionRounding are removed; they stay in
history at 540011dd49. The parser accepts the suffix and the lowering is the plain conversion:
Metal's compilers disagree on the suffixes, and the owner's 11-07 rule takes the cheapest answer
inside the envelope where real Macs disagree.

Measured per form, 64 threads of the fixture's edge values, one kernel per intrinsic (probes
m3-max-14380 Radeon Pro 5300M and m3-max-14381 UHD Graphics 630, macOS 26.7.1; m3-max-14382 M3
Max, macOS 27.0.1):

  form                         M3 Max                 5300M            630            now
  float->int .rte              nearest even           truncates        no pipeline    truncates
  float->half .rtz/.rtp/.rtn   .rtz as named,         nearest even     as named       nearest even
                               no pipeline rtp/rtn
  float->int .sat              unsigned keeps a       8-bit not        no pipeline    clamps
                               negative's wrap, long  clamped, long
                               of inf is 0            clamped to int
  int->float/half any mode     .rte nearest even,     nearest even     nearest even   nearest even
                               no pipeline directed
  int->int .sat                no pipeline            wraps            wraps          wraps
  float->int .rtp/.rtn         no pipeline            truncates        no pipeline    truncates

The last three rows are no difference: every Mac that creates the pipeline answers the plain
conversion. OpenCL on all three GPUs (not Metal) answers the exact IEEE roundings. The M3's
compiler service exits (XPC_ERROR_CONNECTION_INTERRUPTED) on the forms it does not compile.

- metal2vulkan-air: Convert::parse takes `.<rte|rtz|rtp|rtn>` and then `.sat` (to an integer
  only), between numbers; the module doc carries the measurement. Test: every suffix parses to
  its plain form.
- Engine test: 24 forms with every rounding (and .sat to an integer) compile on lavapipe and on
  moltenvk-m3 without shaderInt64 to the plain conversion's module words and notes, and pass L3.
- Fixture: kernel_convert_rounding_apple_gpu now calls only the forms the M3 compiles and
  answers plainly, for a case qualified there.
- docs/API.md accepted differences: the table above.
- SEMANTICS_VERSION 2024 (development is at 2023); ARTIFACT_FORMAT_VERSION back to 500, with no
  codec change.

Verified: not yet run (dispatched next).
2026-11-11 02:42:04 -08:00
Anees Iqbal 2bc702f4b4 air.convert roundings: drop the double paths AIR cannot name; fix the tests' first run
air.convert names no double (the AIR element types stop at f32), so the directed double
narrowings, the double results and the 64-bit RTE width were unreachable: removed. The nearest-even
plan is now a flag for a float result, and narrow::rte_modes decides 32 bits and the widths the
device's independence ties to it. The engine test reads the interpreter's buffers directly, pins
the RTE widths of the venue profiles (lavapipe and RADV 32, ANV 16/32/64, MoltenVK and the floor
none) and the parse test names a float narrowing instead of a double one.

Verified: the first test job (m3-max-14044, homelab-ms01-1) failed on the double case in the parse
test and a compile error in the engine test; both fixed here, rerun next.
2026-11-11 02:41:51 -08:00
Anees Iqbal 9f4590f124 air.convert with a rounding suffix: parse it and lower each form
Apple's OpenCL compiler spells every convert_* it emits as an air.convert with a
rounding after the types (.rte, .rtz, .rtp, .rtn) and, to an integer, .sat after it
(convert_float4_rte(uchar4) is air.convert.f.v4f32.u.v4i8.rte, convert_int_sat(float)
is air.convert.s.i32.f.f32.rtz.sat; the forms are read from the OpenCL runtime library
the macOS 27.2 Metal toolchain ships). Convert::parse took exactly four tokens, so each
such name was an unknown intrinsic and the pipeline was refused.

- metal2vulkan-air: Convert gains `rounding: Option<ConvertRounding>` and `saturate`;
  a rounding is accepted between numbers only (no bool, no 8-bit float) and .sat only
  after one, to an integer. Static folding leaves the saturating and the directed forms
  alone.
- Lowering (lower/arith/rounding.rs):
  - float to integer: RoundEven / Ceil / Floor first (rte / rtp / rtn; rtz is the
    conversion's own truncation), then the saturating conversion every air.convert to an
    integer takes; the NaN test reads the operand itself. Denormal notes as rint / ceil /
    floor take them.
  - integer to integer: plain; .sat clamps to the range both types share (SClamp/SMax/SMin
    of the sign extension, masked, or UMin; pairs on the wide path).
  - integer to float and float to narrower float, nearest even: the plain conversion. Where
    it can round to f32/f64 the entry declares RoundingModeRTE for the width and the widths
    the device's independence ties to it (narrow::rte_modes); a device that cannot declare
    them records the new PrecisionNote::NativeConversionRounding.
  - toward zero or an infinity: no Vulkan conversion rounds so per instruction, so the
    result is computed exactly by integer arithmetic: the magnitude's dropped bits with an
    increment where the lane rounds away (f32, f64 from 64-bit, the wide path through its
    sticky 32-bit fold), f32 to half on the bits (normal, overflow, subnormal, inf, NaN),
    double to float by stepping the device's faithful conversion, double to half through
    the round-to-odd f32. A conversion that cannot round is the plain one.
- PrecisionNote::NativeConversionRounding (native-conversion-rounding): codec, runtime
  Degradation, comparison table (unbounded), fast_paths ledger class, docs/API.md.
- SEMANTICS_VERSION 2021, ARTIFACT_FORMAT_VERSION 501 (the codec gains the note);
  api_signatures and the air api_surface blessed.
- Fixture kernel_convert_rounding_modes (owned MSL, air-rename to 64 suffixed intrinsics).

Unverified at this commit: build and tests follow in potluck jobs.
2026-11-11 02:41:50 -08:00
Anees Iqbal 1032d39bd6 Pass log: a pass a frame repeats with other counts prints no line again
The pass log told its lines apart by their whole text, its draw-call and resident counts
included, so a pass a frame repeats with one draw more printed again and the 256-line bound
could fill before the pass that matters ran. A line is now keyed by the pass without those
counts; the line still prints them.

Verified: cargo fmt; tests::pass_log runs on potluck after this commit.
2026-11-11 01:49:25 -08:00
Anees Iqbal 5a21f6d3f3 METAL2VULKAN_LOG_PASSES: a default-off log of the render passes that name a watched texture
A diagnostic to find which pass draws the white at a widget's glass edges in the 27.0.1 guest:
the runtime sees every pass's attachments, which the consumer's own logs cannot name.

The switch's value is the textures to watch, a comma-separated list of FORMAT:WIDTHxHEIGHT
(the format as the notices print it or as Metal names it, `*` for any format or size). At the end
of each render encoder that renders into a watched texture, binds one to its fragment stage or
makes one resident, the device logs one line (id name metal2vulkan-passes, Info): the render area,
its Vulkan render pass instances and draw calls, each attachment (format, size, object ID, label,
whether it took its storage form, level, slice, load and store actions as the pass ends, its
stand-in and cause), the depth/stencil aspects' actions, the pipeline states its draws drew with,
the textures bound to the fragment stage at a draw, the watched resident textures with their
stages, and what it watched. A line the same as one printed before is not printed again; a process
prints at most 256. Off (unset, empty or 0, or a value it cannot read, said once on stderr), an
encoder notes nothing; no behaviour reads it.

- crates/metal2vulkan/src/env_vars.rs: the registry row and `log_passes()`, the raw value.
- crates/metal2vulkan-runtime/src/pass_log.rs: the filter, the notes, the line and its bound.
- render.rs: an encoder's notes, made where the log is on, noted at each draw call, logged at
  the pass's end once its store actions are settled.
- texture.rs: `Texture::took_storage_form`, which the line names.
- docs/API.md and the artifact test's list of the runtime's variables name it.

Verified: cargo fmt; the build, clippy and the tests run on potluck after this commit
(tests::pass_log: the filter's parse and refusals, an entry's match, the once-and-bound rule).
2026-11-11 01:49:25 -08:00
Anees Iqbal 7aefa49b7f A float write through an argument buffer notes the half-float and small-float NaN only where the heap can name such a texture
What: lower::texture::stored_where gave a heap element one clause of no test, so a
`float` texel's write through an argument buffer recorded DeviceNanEncoding (and,
off MetalHalfStorageWrites, DeviceColorConversion) unconditionally, whatever the
command made resident. It now gives the clause the family the caller asks about:
may_store_half the 16-bit float family (bind::heap::NAN_SIXTEEN), small_float_storage
the packed small float one (NAN_SMALL), tested on SpecKey::HeapNanFamilies, which
the runtime reads at each draw or dispatch, as a `half` write's heap note already
does (half_write_nans). SEMANTICS_VERSION 2021: the notes change under unchanged
keys on every profile without MetalHalfStorageNans.

Why: with lavapipe's MetalSmallFloatNans row, runtime_lane::half_storage_writes::
every_nan_a_kernel_writes_to_a_small_float_texture_is_metal_s_where_measured failed
on lavapipe (gem10, Mesa 26.2.6, LLVM 23.1.4) in its argument-buffer form alone:
every one of 98,298 NaN fields was Metal's, yet the dispatch, whose only resident
texture is RG11B10Float, announced device-nan-encoding for the half-float family
the heap might have held. The same over-note as the reported one, through the
argument buffer's float write.

Test that fails without it: tests::engine_handles::a_heap_texel_write_is_the_devices_write
now requires a float texel's DeviceNanEncoding to hold only under HeapNanFamilies
clauses of NAN_SIXTEEN (profile without MetalHalfStorageNans) and NAN_SMALL (without
MetalSmallFloatNans); and the lane above on lavapipe.
2026-11-11 01:30:36 -08:00
Anees Iqbal 08ff006256 lavapipe stores small-float NaNs as Metal does: its MetalSmallFloatNans row, and the lanes that gate it
What: driver_facts::DEVIATIONS gains MetalSmallFloatNans for MESA_LLVMPIPE (every
CPU). A half or float texel's write that may reach an RG11B10Float storage image
on lavapipe then records no DeviceNanEncoding for it and requires
VkProperty::MetalSmallFloatNans, as on MoltenVK's Apple9 identity. Two lane tests
measure the deviation on every venue and gate it where a driver is listed:
half_storage_writes::every_nan_a_kernel_writes_to_a_small_float_texture_is_metal_s_where_measured
(32,766 float NaNs: every top-13 payload pattern, low bits clear and set, both
signs; write, read_write, texture buffer and argument buffer forms) and
half_write_nans::every_half_nan_written_to_a_small_float_texture_is_metal_s_where_measured
(all 2,046 half NaNs; write, read_write, held). Each requires every NaN field
Metal's canonical one and no device-nan-encoding where the profile takes the
deviation, and device-nan-encoding where any field differs elsewhere. half_write_nans'
stored() takes its texels. The existing half_write_nans lane's measured branch
no longer requires native-nan-encoding absent where the device's widening is
unmeasured (no MetalNanMoves): that note is the kernel making's, for its widening of
the half whatever texture it writes, and a 32-bit float store shows it.

Why: lavapipe announced device-nan-encoding on every RG11B10Float half write of
runtime_lane::half_write_nans (write, read_write and held) with 0 of 25 lanes
differing from Metal's (msi, Mesa 26.2.4, LLVM 23.1.1, at 7d7085f9d0), and the
conformance case half-write-nans-rg11b10f differed only in its notices. The note
fires because the profile lacked the deviation, not because the store differs:
llvmpipe packs a small float in its shader code and writes every NaN as the
field's quiet NaN with its sign dropped, which is Metal's. RADV and NVIDIA keep
payload bits, so they stay unlisted. No SEMANTICS_VERSION bump: the deviation is
an enabled property the profile fingerprint hashes, so lavapipe's keys change
(golden_hashes' lavapipe cells re-key; re-blessed on development).

Test that fails without it: device::tests::driver_facts::
the_profile_takes_the_deviations_its_driver_is_measured_with now expects
MetalSmallFloatNans on lavapipe, gate-lavapipe and gate-lavapipe-x86_64.
Verified: the lavapipe, PHOENIX and M3 runs in the branch's report.
2026-11-11 01:30:29 -08:00
Anees Iqbal 04bf17db16 Fence each optnone call only helper invocations may make before a storage write with an identity simdgroup shuffle
What: on a driver whose compiler loses a simdgroup's texture writes after an `optnone` call that
only its helper invocations make (DriverWorkaround::DiscardDropsSimdgroupStores: MoltenVK on an
Apple GPU), a call the helper guard cannot keep the helpers away from exactly (an arm with a
derivative or subgroup operation, a loop the helpers repeat alone) and that no tangled
instruction reading its result follows was left as it was, with
PrecisionNote::HelperBranchDropsSimdgroupStores recorded. Now spirv::helper_branches fences each
such call: an OpGroupNonUniformShuffle of its result at SubgroupLocalInvocationId (a
MulExtended's structure member by member, put together again) follows it, and every use reads
the shuffled value. Each invocation, a helper too, reads its own lane, so no answer changes and
no lane reads another's; the shuffle is the simdgroup operation after the call, reading what it
computes, that the M4 probe found keeps the writes. The fences are placed once every analysis of
the module has run (compile.rs, before the verifier): those analyses would read a shuffle as a
move between lanes.
- guard_for returns the Fences beside Guarded (Guarded::fences counts them); plan lists every
  bare call (Facts::bare, which any_bare was) and no longer stops at the first function with one.
- The census names the fences `fragment.helper-fence`; the runtime's pipeline creation log
  prints `helper-fence <stage>`.
- The note stays where no shuffle can follow: no fragment-stage subgroup shuffle on the profile,
  or a 64-bit or bool lane, or an 8- or 16-bit one without shaderSubgroupExtendedTypes.

Why: the weather widget's glass edges in the 27.0.1 guest on the M3 draw white 8x4-pixel blocks
along the primitive's edges (solid strips in some boots, a comb in others, at every pin since 30),
and the guest's run announces helper-branch-drops-simdgroup-stores for a fragment function.

Tests: engine_fragment's helper guard tests (rch_helper_branch_loop and rch_helper_tangle's
`before` and `unread` functions fenced, census and shuffles counted, no note, L3), a new test that
the note stays with the fragment shuffle taken out of the profile, and the runtime lane
helper_tangle, which now requires the fence and no lost write where the fragment stage shuffles.
SEMANTICS_VERSION 2021.

Verified: cargo fmt; the build, the touched tests and the M3 lane follow.
2026-11-11 01:12:17 -08:00
Anees Iqbal 131be007fa A half write through an argument buffer notes its NaN only where the heap can name a family the device stores its own way
What: a `half` texel's write to a heap element recorded `PrecisionNote::DeviceNanEncoding`
unconditionally ("a heap element may be any format"), so on MoltenVK on the M3 Max a write
through an argument buffer into an RGBA32Float or RG11B10Float texture announced the note
though the store is Metal's there (0 of 25 lanes differ, job 13458's lanes128.log). A new key,
`SpecKey::HeapNanFamilies(Stage)`, gives from the command's heap members the families whose
texels may hold a NaN a `half` write stores (`lower::texture::nan_family`, the same classes
the slot path tests of a bound format: 1 a 16-bit float format, 2 a 32-bit one, 4 a packed
small float one, 8 a float format of none of those; normalized, sRGB, extended-range,
integer and stencil formats none). `half_write_nans` now records the heap write's note under
one clause per family whose deviation the profile lacks (`MetalHalfTexelWrites`,
`MetalNanMoves`, `MetalSmallFloatNans`) and the no-family bit, requiring the property of each
family it takes, as a slot's write does.

Measured, before the change (`runtime_lane::half_write_nans`, argument-buffer writes):
- M3 Max, MoltenVK (job 13458): 16-bit float formats 15 of 25 lanes differ (signalling NaNs
  stored 0x7e00); 32-bit float and RG11B10Float 0 differ. The note now holds there only where
  the heap can name a 16-bit float texture (or one of no family).
- lavapipe (job 13553): 16-bit 8 differ, 32-bit 15 differ, RG11B10Float 0 differ. lavapipe
  takes none of the three deviations, so its note keeps every family's clause.

Runtime: `degrade_bound_values` reads the clause at each draw or dispatch (generic; no
runtime code changed). The lane `half_write_nans` now holds argument-buffer writes to the
measured rule as it holds slot writes: on a device with the family's property, 0 lanes differ
and nothing is announced.

Public API: `SpecKey` gains `HeapNanFamilies(Stage)` (a `#[non_exhaustive]` enum; no
consumer breaks); api_signatures.tsv blessed.

Tests: heap::a_heap_half_write_s_nan_note_follows_the_families_its_command_can_name (the
clauses and required properties on every committed profile with a heap; plan values 1/2/4/0
for R16Float, RGBA32Float, RG11B10Float, RGBA8Unorm and R32Uint residents and the note held
under them).

SEMANTICS_VERSION 2019, ARTIFACT_FORMAT_VERSION 500 (a SpecKey tag; both renumbered at
landing).

(cherry picked from commit 8f6f24055459c9143f3473da8ab60e6532b30676)
2026-11-10 06:13:23 -08:00
Anees Iqbal 199f9a99a2 A half sample of a 32-bit float texel records no half-texel note where the device's half is Metal's
What: half_texels' clause for a sample of a 32-bit float texel (Bound & BicubicTexels::LINEAR,
'Metal rounds toward zero, saturating') is no longer added on a profile that takes
DriverDeviation::MetalHalfConversion; the module then requires VkProperty::MetalHalfConversion
(TexturePlan::storage_properties), as half_texel_nans' NaN clauses do since 782da3582b. Elsewhere
the clause stays. The unmeasured-class and 16-bit normalized clauses are unchanged.

Why: on MoltenVK over the M3 Max a half sample of RGBX32Float through a runtime sampler (the
consumer's rgbx_sample_half) announced half-texel-conversion ('where it binds texture 0 bound as
RGBX32Float') while every value was Metal's. The deviation's measurement covers the half result
of a read, sample and gather of every float word of RGBA32Float (half-texel-nans-rgba32f,
m3-max-13447: every value Metal's), and RGBX32Float is held in that twin.

Test: runtime_lane::rgbx_textures::rgbx_half_samples_are_metals (the previous commit): nearest and
linear runtime samplers, edge and border, shared and private, RGBX32Float and RGBA32Float; on a
profile of MetalSampler and MetalHalfConversion no half-texel-conversion may be announced.
Docs: the note's rustdoc and API.md's catalogue entry. SEMANTICS_VERSION 2019.

Verified: the M3 run of the control and of this commit follows.
(cherry picked from commit bb5662fd6d9bb512bc8d185c85a5d7098b1f2d9d)
2026-11-10 05:50:50 -08:00
Anees Iqbal 83e5e06789 DescriptorError::ColorAttachment carries Metal's answer: nil with an NSError, or the process ends
A layer that answers as Metal does needs to know, per refused pipeline, whether Metal returns nil
with an NSError or its descriptor validation asserts and ends the process. ColorAttachment now
carries `metal: MetalAnswer` (NilWithError | EndsProcess), set at each of its 17 sites from plain
Metal's answer on an Apple M3 Max under macOS 27.0.1 (probes/color_attachment_answers.m, no
MTL_DEBUG_LAYER, job m3-max-13738):

- EndsProcess (SIGABRT, "Render Pipeline Descriptor Validation"): blending on a bfloat attachment,
  with a function, a fetching function or none ("... MTLPixelFormatRGBA16Bfloat for this render
  target is not blendable."); alpha to coverage over an integer attachment 0, rasterizing or not
  ("... alphaToCoverageEnabled requires a float/unorm pixel format ..."). The link's doc said the
  second was unmeasured with rasterization off; it is measured now.
- NilWithError (code 3, domain AGXMetalG15X_M1): an output of another numeric class (half4, float4
  and int4 into RGBA8Uint; uint4 into RGBA8Unorm and RGBA8Sint; a fetching uint4 of RGBA8Unorm);
  a color input of another class (uint4 of RGBA8Unorm, BGR10_XR, A8Unorm); fewer output components
  than channels (with and without fetch); a blend of the second source without the second output,
  or without the first (with and without fetch); a color input without an attachment; a tile
  function's imageblock member without a format ("Invalid pixel format for render target 1").
- A `Compiled` tile function compiled under another format than the descriptor's has no Metal
  counterpart (Metal compiles the function for its pipeline) and answers EndsProcess, the answer
  of an unmeasured case; under no format it answers Metal's NilWithError.

Public API: the new `error::MetalAnswer` and the changed variant are in api_signatures.tsv and the
api_surface table. Refusals are not serialized in any cache, and translation output is unchanged,
so neither ARTIFACT_FORMAT_VERSION nor SEMANTICS_VERSION moves. docs/REFUSALS.md regenerates
unchanged (descriptor errors are not in it). docs/API.md states the two answers.

Tests: each existing test of a ColorAttachment refusal now names its answer (bfloat blends,
alpha to coverage, a tile function compiled for other formats: EndsProcess; output class and
components, the second source, unattached inputs, unformatted tile members: NilWithError), and a
new unit test holds the storage form's class refusal to NilWithError for reads and writes.

(cherry picked from commit cd17476e5a4ae2b9fbf8118453ad089691adaba2)
2026-11-10 05:40:38 -08:00
Anees Iqbal f0b1976e58 Queue sharing: a command buffer whose VkQueue waits on the GPU for another's work counts that wait in its long mark
The Adaptive long mark read a command buffer's own GPU timestamps alone. A batch that waits on the
GPU for another VkQueue's work (an MTLEvent's signal pending there, the tracker's wait for another
VkQueue's writes, new resources' first work there) writes its start timestamp only once that wait
is met, so a queue of short command buffers, each waiting for another queue's 30 ms one, never went
long: it kept sharing its VkQueue, and every command buffer the queues sharing it committed behind
each wait waited for the other queue's whole long command buffer.

Now submit_batch notes, at the first batch whose VkQueue it hands such a wait (an event wait whose
signal is pending on another VkQueue or is the caller's, EventTimeline::waits_across; a tracker or
first-work wait on another VkQueue), the host time its submission was called (Times::waited_across).
place_gpu_times marks the queue long also where more than LONG_HEAD ran from then to the command
buffer's GPU end, placed in the host's time. A command buffer with no such wait is timed as before,
by its own timestamps, so the host-view false marks the module docs describe stay out.

The device test a_compositor_beside_a_queue_waiting_on_the_gpu_for_long_work_keeps_its_latency now
also asserts that the waiting queue goes long (WorkCounts::queues_gone_long >= 2). The QueueSharing
notice's cost, docs/API.md's catalogue entry and the FAST-PATHS row name the wait.

Verified: cargo fmt; unit test a_wait_crosses_queues_where_its_signal_is_pending_on_another; the
build, clippy and the 5080 device run are dispatched.

(cherry picked from commit 6391625634472fb158b6477dfad36340956ae2dd)
2026-11-10 05:16:05 -08:00
Anees Iqbal ff45556bcc An argument buffer's sample filter note holds only where its heap can name a filtered raw texture
What: a heap sample the function emulates (`sampler::heap_raw`) recorded
`PrecisionNote::BicubicFilterArithmetic` whatever the command's heap held: unconditionally
through a constexpr linear sampler, and under the bound sampler's word through a runtime
slot. A command whose heap holds no raw texture samples through the device's own sampler,
and a bfloat form's sample reads the nearest texel, so neither filters by the device's
arithmetic. `SpecKey::HeapRawTextures`' value now carries two bits, which the plan gives
from the command's heap members (`slots::heap_raw`): `heap_raw::HELD` (1, a raw-held
texture: the decode's `DevicePackConversion`, unchanged) and `heap_raw::FILTERED` (2, a
raw-held texture of a form the function filters: not a bfloat one). The filter note's
clauses each test `FILTERED` (beside the bound word's test through a runtime slot).

Runtime: `degrade_bound_values` reads the clause at each draw or dispatch, so a command
whose heap holds only RGBA8Unorm or RGBA16Bfloat textures no longer announces
bicubic-filter-arithmetic for a linear heap sample; one holding a BGRA10XR texture still
does. No runtime code changed (the path is generic).

Tests: heap::a_heap_sample_s_filter_note_follows_the_raw_texture_and_the_bound_sampler_word
(artifact clauses on every committed profile), heap::a_heap_sample_s_filter_note_holds_where_its_command_can_name_a_filtered_raw_texture
(plan values 3/1/0 and the notes bound under them), the decode-note plan test's values
(3 for BGRA10XR, 1 for RGBA16Bfloat), engine_sampler's argument-buffer stage check, and the
lane heap_extended_reads::a_heap_sample_s_filter_note_is_announced_where_its_command_can_name_a_filtered_raw_texture.
Docs: SpecKey::HeapRawTextures, the note's rustdoc, API.md.

SEMANTICS_VERSION 2018 (renumbered at landing).

(cherry picked from commit dbc8a2781ef6170f797d5b7a7a83b46264c5e4e2)
2026-11-10 04:45:12 -08:00
Anees Iqbal 445d410eda An extended-range sample's filter note through a runtime sampler follows the bound word
What: a sample of an extended-range or padded texture that the module filters itself
(`sampler::extended`, through the slot's variant, and `sampler::heap_raw`, through an
argument buffer's raw element) recorded `PrecisionNote::BicubicFilterArithmetic`
unconditionally through a runtime sampler slot. It is now specialized on the word of the
sampler bound at that slot (`NoteOn::BoundSampler`, `SpecKey::BoundSamplerWord`), with the
two tests `linear::filtering_word` gives, as the YCbCr filter note does: a linear
minification or magnification filter, anisotropy or a cubic filter (any of those bits), or
a linear mip filter. The level blend of a word-stated mip filter holds on the linear mip
test alone. A constexpr sampler keeps its rule (linear: unconditional; nearest: none).

Runtime: the clauses test a bound value, so `Device::degrade_bound_values` reads them at
each draw or dispatch of the variant (no runtime code changes: the path is generic, and
`slots::record_noted` already records the word for a noted key). A nearest runtime sampler
over such a texture no longer announces bicubic-filter-arithmetic; a filtering one still
does.

Why: a nearest sample is the decoded texel at Metal's position (no filter arithmetic), yet
it announced the note, so the conformance suite's nearest cases
(`rgb10a2-srgb-samples-nearest-*`, the eight `xr-two-plane-samples-*-n*-*`) declared it.

Tests: engine_extended_range::samples::a_runtime_sampler_s_filter_note_holds_only_where_the_bound_word_filters
(every form, half and float, runtime / constexpr linear / constexpr nearest, on lavapipe,
moltenvk-m3 and the RTX 5080 profile: clauses hold for linear, linear min, linear mag,
linear mip, anisotropic and cubic words, not for nearest or nearest-mip ones; bfloat forms
record none) and heap::a_heap_sample_s_filter_note_follows_the_bound_sampler_word. The
rgb10a2_srgb lane now checks its nearest samples announce no filter note. The conformance
allowances of the rgb10a2 sRGB and two-plane sample cases name the note for the linear
cases only. Docs: the note's rustdoc and API.md's catalogue entry.

SEMANTICS_VERSION 2016: an artifact's notes change.

(cherry picked from commit fd5212bee216b823ba18d3c5ba5e5a74a4b12073)
2026-11-10 03:17:33 -08:00
Anees Iqbal 6be4be9791 Keep the predicted plain half arm in a key's general form: a creation makes one pipeline, not two
What: on a device that samples through Metal's own texture unit (MoltenVK), a texture slot a
function converts to `half` declares SpecKey::PlainHalfTexels and SpecKey::UnmeasuredTexels.
The general form (render/residual.rs) zeroed both, so a state's creation made its predicted
key's general form (the class routine's arm, PlainHalfTexels 0) and handed the predicted key
itself (the plain arm, 1, as an unbound slot takes) to the pool right after. Every draw of a
plain class takes the predicted key, so the general form served a draw only while the
predicted key was still being made; the conformance cases render-then-sample-magnified-nearest
and -linear made it and no draw took it (cost.rs named it an open bug). PlainHalfTexels is no
longer a constant of the general form: a key keeps the plain arm its binding gives it. The
predicted key is now its own general form, and the creation makes that one pipeline.

What still takes a general form: a draw binding a class whose `half` conversion is not
measured (BC4 to BC7, the linear ASTC formats) keys UnmeasuredTexels 1, which no instruction
reads; its general form is the predicted key, made at creation, so it draws at once and runs
its own key's instructions while its own is made on the pool, as before. A draw binding a
YCbCr field on the grid 8192 (PlainHalfTexels 0) makes its own key at its draw, as any key the
creation did not predict; on a device whose memory is the host's such a slot reads its planes
in place in a variant of its own (VariantKey::ycbcr_in_place), which no creation predicts
either.

Tests: tests::general_form now expects the plain arm kept ([1,1,1,5,3] -> [0,1,0,5,3], an
unmeasured plain class's key -> the predicted key, a YCbCr class keeps the routine's arm); the
made_at_creation lane expects one making at creation on every device (it expected two on
Metal-sampler devices) and the unmeasured-class draw to take the predicted key as its general
form; ycbcr_textures' and runtime_lane's comments follow. Docs: residual.rs, predicted.rs,
WorkCounts::residual_form_draws, API.md's general-form bullet, and cost.rs's open-bug
paragraph (the recordings read 3 made until the rows' next measurement; WASTED_BY_CLASS's
draws ceiling can then drop by 2).

Verified on the M3 Max (MoltenVK 1.4.2), the same diff at 3e0db77c6f over 6f7bb169d2:
- conformance cost --runs 8 --show, each case, in order and alone (jobs m3-max-13511,
  13518): render-then-sample-magnified-nearest and -linear read creation_pipelines_made 2,
  creation_render_pipelines_made 2, variant_pipelines_made 2 (the record holds 3 of each),
  creation_pipelines_drawn 2 (the record's 2): the pipeline no draw took is gone, every
  pipeline made is drawn.
- conformance replay, the whole set (70 s): exit 0, "the 391 row(s) above are exactly the
  open gaps known-gaps.tsv expects on this venue": no case's answers moved.
- 77 touched tests under --cfg m2v_gpu passed: made_at_creation, ycbcr_textures' creation-made
  slot, pipeline_creation's pool draws, draw_work, general_form, uniform_bind_offsets,
  draw_again, draw_shape_notices.

(cherry picked from commit 56ddedfc3498c9376384a3ad4b57e7607d78594a)
2026-11-10 03:07:56 -08:00
Anees Iqbal 782da3582b A half read of a 32-bit or small float texel records no NaN note where the device's half is Metal's
On MoltenVK on the M3 Max (m3-max-13447, default policy) half-texel-nans-r32f, -rgba32f,
-rg11b10f and -rgb9e5f answered every value as Metal does and still announced
device-nan-encoding; runtime_lane::half_texel_nans read 0 differing half lanes. The profile takes
DriverDeviation::MetalHalfConversion, whose measurement covers the half result of a read, sample
and gather of every float word of RGBA32Float (NaNs among them) and 16,384 random words each of
RG11B10Float and RGB9E5Float.

half_texel_nans now records DeviceNanEncoding on such a profile only where the bound class is a
half-float one (packed field 0) or of no family, and requires VkProperty::MetalHalfConversion;
elsewhere it keeps the one clause of TexelFormat::NAN_FREE. The 16-bit float formats keep the
note: no deviation records their NaN payloads as measured.

Test: engine_texture's half-read test checks both forms per committed profile (clauses, formats
that hold, the property) and that a profile of the deviation ran. Docs: the note's rustdoc,
API.md's exemptions, the storage_properties doc. Under the branch's SEMANTICS_VERSION (2015).

(cherry picked from commit b03555f8c9f05e382f744593cfaa01f2dc3bbb20)
2026-11-10 02:59:43 -08:00
Anees Iqbal 85b896a7e1 Mesh pipelines: a required object size answers as Metal's first compile, as the mesh stage's does
Metal's answers here depend on what its compiler compiled before, which it keeps across processes
keyed on the function's AIR. With the probe's salt now in the AIR (d49370d732), an M3 Max under
macOS 27.0.1 answered, twice over, each sequence one fresh salt (m3-max-13430):

- required-object-32-max-64: refused on a first compile ("Kernel specified max total threads per
  threadgroup (32) must match compute pipeline specified max total threads per threadgroup (64)"),
  refused again, and again after required-object-32x2 or plain; made only after
  required-object-64-max-64. required-mesh-32-max-64 the same, made only after
  required-mesh-64-max-64. The object stage was made here because an earlier compile let it be.
- A required size gives its stage its threads on a first compile: required-object-32x2 answers an
  object maximum of 64 (we answered 1024), required-mesh-16x2 a mesh maximum of 32, and a
  required 32 beside a function's [[max_total_threads_per_threadgroup(64)]] 32 in either stage.

So the object stage now refuses a required size of other threads than its maximum
(MaxThreadsDiffer { stage: Object }), as the mesh stage already did, and each stage's thread
limit is the least of the descriptor's maximum, the function's, the required size's threads and
1024. RUNTIME behaviour: new_mesh_render_pipeline_state refuses an object maximum beside a
required object size of other threads, and maxTotalThreadsPer{Object,Mesh}Threadgroup answer a
required size's threads. The translator's mesh answers change, under the branch's
SEMANTICS_VERSION bump (2015).

Tests: engine_mesh's refusal test adds the object cases (32 and 16x2 under 64) and makes 64
under 64; its answers test checks a required size alone in each stage and below a function's
maximum; the runtime lane's mesh test does the same on a device. docs/API.md's accepted
difference, the error's and the getters' docs and the probe's measurements say the first-compile
rule and what later compiles answer.

(cherry picked from commit 3b05b274aec46c172fd0a38276c5ca45a1ade4ca)
2026-11-10 02:59:31 -08:00
Anees Iqbal 5bb3d04838 A float ldexp records no NativeNanEncoding: its lowering answers Metal's NaN itself
The 11-02 carve-out run flagged ldexp as possibly over-noted. A float
ldexp is lowered on the bits (math::ldexp_bits): an infinity or a NaN
operand is selected as the result bit for bit, which is Metal's answer
(NanAnswer::Operand: ldexp returns a NaN operand itself). No NaN of the
device's reaches the result on any device, yet float_call left the
answer to the device and recorded NativeNanEncoding everywhere,
MoltenVK included.

FloatFn::metal_nans now includes ldexp on float lanes, so the call
leaves no NaN answer and records no NaN note. A half ldexp multiplies by
2^k, so its NaN is still the device's product's where Metal answers the
canonical half NaN, and stays noted where the device does not answer
that. PrecisionNote::NativeNanEncoding's docs and docs/API.md's
catalogue say so.

Verified: lower::arith::tests::float_ldexp_answers_metals_nan_itself
(fails without the metal_nans change: call.nan is Some(Operand) and
NativeNanEncoding is recorded). SEMANTICS_VERSION 2014: a module
calling float ldexp records one note fewer.

(cherry picked from commit c4b748c1e63cee2a32400145a3665387a8ca72cf)
2026-11-10 02:59:23 -08:00
Anees Iqbal af1dd85b66 Blend-source notes state their bound and the device compiler's regrouping; padded rows on the 5080 and the Iris Xe
ExtendedRangeBlendSource and ExtendedRangeFloatBlendSource (their docs, the API
catalogue entries and the FAST-PATHS device-gap row) now say what the suite
measured: the device's compiler may contract and regroup the in-shader blend
(MoltenVK on the M3 Max and NVIDIA's driver on the RTX 5080 compute
S·F + D·(1 - F) as D + F·(S - D)); a stored channel lands within two codes of
Metal's on a linear format and within six near zero on an sRGB twin; and where
the compiler regroups a padded format's blend, an infinite second source stores
an end code where Metal's sum is NaN, stored as 0. The FAST-PATHS row names the
padded formats, which it lacked, and no longer says 'not measured'.

known-gaps.tsv: the 168 extended-range rows (xr-blend, xr-gamut, xr-gradient,
xr-masked) whose Open item was the blend notes' documentation are closed (Open:
nothing, the recorded bound covering the difference); every one is within the
bound (survey of the rows' largest differences). The padded-blend rows are
regenerated for five venues: the M3 Max, RADV PHOENIX and llvmpipe as before,
and the RTX 5080 (b5080 entry xrblend2-padded-replay-5080) and the Iris Xe
(job m3-max-13386), 17 each. The 5080's second-source cases differ by the whole
code range as the M3's do, and its counts are exactly a model of
D + a·(S - D) over an unnarrowed float destination (971 on R10Unorm_X6, 1850 on
RG10Unorm_X12); the Iris's are exactly the sum as written over the half
destination (844, 1607), as RADV's; llvmpipe's the sum as written over a float
destination (962, 1831). No venue's largest difference exceeds the M3's, the
780M's or llvmpipe's.

engine_padded_blends: a fetch of a padded attachment makes the whole pipeline
on every committed profile that orders fetch (storage form or input
attachment) and names the device gap elsewhere; a bfloat fetch stays
NotImplemented(Format), the negative control. Not yet run.

(cherry picked from commit c923b6d49c36c8354f375f6dababfd5f81f1ffbc)
(cherry picked from commit e3a2b226d7f5938811d1d251172088baf05c15cb)
(cherry picked from commit 85a2473cc6ea6a2c9165e2614d1e87ca77c1627e)
2026-11-10 02:59:18 -08:00