Commit Graph
284 Commits
Author SHA1 Message Date
Anees Iqbal ec9706e6e3 Survive the loss of the VkDevice: the device is a line of generations
Metal's MTLDevice survives a GPU recovery; the runtime's device refused every
call with DeviceLost from the first loss on, and the consumer ends its VM at
the first refusal. Now a device the runtime made is a line of generations
(device/line.rs), each a DeviceShared over its own VkDevice, and the first call
that needs the device after a loss makes a new VkDevice of the same physical
device, options, queue families and extensions.

- Two kinds of handle. The program's device (and its clones) is a root handle:
  it holds the line, pins no generation, and every public Device call goes to
  the generation that serves (each public method forwards to its *_now body).
  Objects hold generation handles, so their Vulkan calls, drops included, reach
  their own VkDevice alone. A generation handle's check is one relaxed load of
  the line's generation (Device::generation_serves).
- A draw pays nothing for it. A command buffer takes its generation once, as
  it is made (CommandBuffer::generation); its encoders' per-draw reaches (work
  counts, fresh-unwritten and alias records, sampler-slot changes, attachment
  read notices) read it there, not through a device handle's kind. A bind's
  device check is one compare of the cells the two handles hold, inlined, its
  refusal (Device::foreign) out of line.
- The state machine (Live, Lost, Failed): the claiming call recovers, every
  other call waits (a notice past 10 s, waiting on); threads command buffers'
  completion depends on never wait. Recovery: the lost generation's command
  buffers in flight fail through its completion path, its queues drain under
  their locks, create_on makes the next VkDevice, the queues are retired.
- Command-buffer answers, as a real loss is one more hang: the oldest
  incomplete batch's command buffer fails GpuHang (exact on one VkQueue; on two
  or more the queue whose oldest incomplete batch was submitted first, said so
  in the notice), counted against its queue so the second revokes it
  (AccessRevoked); the others GpuRecoveryVictim; one committed on the hang's
  queue before the recovery runs nothing and completes with no error; one made
  before and committed after fails GpuRecoveryVictim. One loss names one hang:
  a batch that went to the driver just before the loss and reached the lost
  device's completion after the loss took the pending batches fails with it,
  as a victim (its own wait need not fail: the test hook's VkDevice runs it),
  and no later failure of the lost device names a second hang.
- Command queues survive: a queue is a root handle and a cell of its place on
  one generation (VkQueue, slots, pools, hangs), which a recovery retires and
  the next command buffer re-makes; label and GPU-error count go on.
- Objects made before a recovery are refused where they meet the new VkDevice
  or need their lost one: RuntimeGap::MadeBeforeRecovery, at the 38 lost-device
  checks (Device::lost_refusal) and at every foreign-object check of one line
  (Device::foreign). DeviceLost stays for a device the consumer made.
- Carried across generations: the address space, resource IDs and the passing
  holds a making waits out before it takes one, unique identifiers, counters
  and the announced notice kinds.
- A device handle is an enum of the two kinds (24 bytes, was 16): the shadow
  merge's copy-back dispatch, which holds handles, is boxed (clippy's
  large_enum_variant).
- Device::recover_for_test (public, documented) runs the whole path with no
  GPU fault; RuntimeGap::AdoptedDeviceRecovery on an adopted device.
- Degradation::DeviceRecovered (device-recovered), announced at each recovery
  with the culprit and its time. WorkCounts::vk_devices_live, vk_devices_made,
  device_recoveries: two VkDevices while objects of the lost one live, one
  after.

Docs: docs/API.md catalogue entry, the runtime README's device-loss section,
FAST-PATHS known gap (a make whose own submission first meets the loss is
refused DeviceLost), docs/REFUSALS.md regenerated (refusal_surface.py names a
forwarded body's sites by its public method), api_signatures blessed.

Tests: runtime_lane::device_recovery (hang and victims, command buffers on
their way to the driver at a recovery, MadeBeforeRecovery and the VkDevice
bound, revocation at the second hang, a command buffer made before fails as
victim, all under the validation layer; a recovery that finds nothing of the
queue scheduled names no hang, its command buffers victims),
tests::device_recovery (the hold of the hang's queue between a loss and the
recovery), detach_lost and the MoltenVK lost-device lanes updated to the
recovery's answers.

Verified:
- lavapipe: runtime suite and touched validation tests 1850/1850, surface
  19/19 (m3-max-5695, gem10, before the rebase onto 7e039f062a); on
  7e039f062a, before the one-hang fix, 1853/1853, surface 19/19, clippy clean
  (m3-max-6150, ms01). This tree: clippy clean (m3-max-6278, msi).
- RADV RX 7900 XTX: 81/81 touched device tests (m3-max-5709). Iris Xe (ANV):
  80/81 (m3-max-5766), the 81st kept_images, which fails so at development
  too and the last of these three commits fixes; the recovery tests alone 3
  rounds of 3 (m3-max-5852). RTX 5080 Laptop GPU: 80/81 (b5080 entry
  devloss-devloss-tip1-nine-163410), the 81st the test's own 20 s bound on
  the recovery, which took 39.5 s beside another entry; the test now prints
  the recovery beside the device's first making and bounds neither.
- MoltenVK on the M3 Max: the device_recovery tests 8 rounds of 8
  (m3-max-6135); with the one-hang fix 12 of 12 (m3-max-6242), where without
  it 3 rounds of about 20 failed with a command buffer Completed after the
  hang (m3-max-6219, m3-max-6233). The RTX 5080 failed the second-hang test
  so in 2 runs of 3 (devloss-devloss-rec-alone-170457).
- Recovery time, alone, under the validation layer: llvmpipe 29.9 ms, RX 7900
  XTX 20.4 ms, Iris Xe 15 to 21 ms (its first making 30 to 41 ms), M3 Max
  (MoltenVK) 35 to 40 ms (42 to 50 ms), RTX 5080 530 to 559 ms (602 to 635
  ms). VK_EXT_device_fault listed: llvmpipe 0, XTX 1, Iris 0, 5080 1.
- Per draw (draw_costs, release, --heap, M3 Max, base 7e039f062a and the tip
  alternating, 4 rounds, m3-max-6121): instructions a draw ws +0.03%, many
  -0.05%, 10k -0.31%; draw_primitives +10, +8 and -26 of 17,172, 11,245 and
  7,736 a call; each set_* call +3 to +4 (of 425 to 860); a command buffer's
  creation +170 to +370, an encoder's end +120 to +390.

(cherry picked from commit 3d7758c074fc9895d5d6c9766604c6c4eae9166d)
2026-11-07 18:38:26 -08:00
Anees Iqbal 78e58c370f Guest RAM: listed chunks stop at 512 MiB, not 256
On a device whose held imports add to the cost of every submission (RADV), a guest RAM's chunks
now run up to 512 MiB. reims's 16 GiB guest on the Radeon 780M (their job 5584, two boots of each
setting) had less of QEMU's RAM resident with 512 MiB chunks than with 256 MiB ones: 0.45 GiB more
than without the source at its desktop against 0.94 GiB, and 0.15 against 0.25 GiB at the end of
its run, with at most 11 to 12 chunks live against 15 to 18. The probe's per-submission cost falls
too: an 8 GiB RAM's submission median was 32 to 33 us in 32 chunks of 256 MiB and 24 us in 16 of
512 MiB (job 5411).

LONGEST_LISTED_CHUNK, the module and use_host_ram docs, HOWTO, the FAST-PATHS row and the
chunk-length probe (now up to 512 MiB) say 512 MiB.

(cherry picked from commit 003382bdc921fa8e7901fa00c7896f29439d7907)
2026-11-07 16:40:58 -08:00
Anees Iqbal 406b379515 FAST-PATHS: the copied-rebind gap is where the check did not pass fresh pages, which it now checks on RADV too
The known gap said RADV's check gave fresh pages no verdict, so a rebind under a texture in place
at another pitch than RADV's linear image's was refused there. The check now makes its fresh-pages
buffer wherever the device takes such pages: on the Radeon 780M (RADV, 5640 and 5667) every Fresh
verdict passed, where the control left them Unchecked. The gap stays where the check failed fresh
pages or the device takes none, and the entry says so.

Verified: 5640/5667 on um790's 780M (1002:15bf) and lavapipe; see the branch's earlier commits.
(cherry picked from commit 756b83b22c97cc13b822cba31752d0906adb93c9)
2026-11-07 16:25:24 -08:00
Anees Iqbal 54647162d4 Record the copied rebind a texture in place is still refused for in FAST-PATHS' known gaps
Where the device's in-place check gave fresh pages no verdict (RADV: no new buffer lies in them
under the import tax) and the driver's own linear image lies at another pitch than the texels',
a gate-refused or moved rebind under a texture in place is refused (NotImplemented
(RebindTextures)), which Metal accepts. Recorded where a user reads it until the fresh-pages
check runs wherever fresh_page_buffer works.

(cherry picked from commit 9de4ad66cde6d12a58d35eed359a9246d170e31c)
2026-11-07 15:36:07 -08:00
Anees Iqbal 801f35bf19 Name the interlocked race's causes, record the split's cost, and count the memoryless lane per pass
DriverFact::InterlockedDrawsRaceUnderLoad's doc now names its causes.
- MoltenVK 1.4.2 turns render pass barriers off for every Apple GPU family
  (its device setup: Apple's GPUs do not support them). The by-region
  memory barrier between_storage_draws records therefore encodes no Metal
  barrier and orders nothing. The measurements agree: 16 of 20,790 passes
  lost with the barrier, 6 of 7,560 without it, the same rate.
- MoltenVK's shaders of the lanes' fetches, dumped with
  MVK_CONFIG_SHADER_DUMP_DIR (m3-max-5436), declare every interlocked
  storage image access::read_write, memory_coherence_device and
  raster_order_group(0), and read and write it there alone. Metal's raster
  order groups are what failed to order the draws under load, not a form
  the translator emits.
So no translator-side fix applies, and the split stands.

The measurement now holds both A/B runs. m3-max-5349 and m3-max-5414 ran
six processes at once, the builds in turn: 16 of 20,790 passes failed
with the barrier and 0 of 20,790 with the split.

docs/FAST-PATHS.md: the barrier row names the MoltenVK split, and a known
gap records its cost on the M3 Max (m3-max-5414, tile_path_costs,
release, four runs each). The other tile path cases kept their instances
and times.
- wide blended in the function: 11.5 to 12.9 ms a frame against 1.8 ms,
  243 instances a frame against 9.
- extended range: 11.8 to 12.4 ms against 2.5 to 2.6 ms, 234 instances
  against 9.
- extended range, wide attached: 10.7 to 12.4 ms against 2.5 to 2.7 ms.

a_memoryless_attachment_fetched_after_a_plain_inline_draw_starts_from_zero
now counts each pass apart. Each pass records inline, splits before a
write of the memoryless color through inputs, splits 3 times before draws
after interlocked writes where the device does so (none elsewhere), and
records at least its first split's instance inline. On the M3 Max the
first pass's later instances recorded in secondaries and the second's
inline (1 and 4, m3-max-5436), which the inline rule decides; the test
does not hold it.

Verified: cargo fmt. The lanes run next.
(cherry picked from commit f47897d1a80cf2e959211a883707df169011104c)
2026-11-07 15:16:42 -08:00
Anees Iqbal f9bc470d7c Move a shadow made before its pages' in-place verdict in place once it passes
A texture over host pages made before its class's in-place verdicts were
known is a shadow (CheckPending): an unknown, not a lack. Under the owner's
11-07 ruling a shadow is only for accesses that cannot be done in place, so
such a shadow must not stay one for life because it was made early.

Each such shadow now waits for its class's verdicts (StorageForms::moves).
The check's thread, at each verdict, decides from facts stored with the
wait (class, usage, texel bytes) and takes no handle of a program's
texture. Where the verdicts take an image in place, the texture waits for
the storage-form switch. At the commit of the device's only uncommitted
command buffer, the switch makes the image in place exactly as the
texture's making makes it: the declared plan, with feedback loop and
storage usage where the device makes them so, and noted for a rebind and
its first move. Where every encoder ran, the texture presents it from then
on (TextureShared::moved; every storage read goes through
Texture::storage). It is counted in host_textures_in_place and in the new
WorkCounts::host_textures_moved_in_place, and its slots are written again.

No texel is copied: between encoders the shadow holds nothing the buffer
lacks, and the image in place is the buffer's bytes, whose uses hazard
tracking orders after earlier copies back and merges. A view made before
the move keeps the shadow. A shadow with a usage or render shadow, over
detached or copied bytes, or whose image the device refuses stays a
shadow. The shadow's image is kept with the texture until it goes.

Test: runtime_lane::in_place_textures::a_texture_made_before_its_verdict_moves_in_place_once_it_passes
(under the validation layer). Docs: storage_form.rs and in_place.rs module
docs, FAST-PATHS in-place row, HOWTO, API.md.

(cherry picked from commit 605d0444de1ad1a9b93e02649db7e1b2fda18e93)
2026-11-07 15:14:38 -08:00
Anees Iqbal be1f1c141b Take the storage form for a private target whose self-read splits for want of STORAGE
A draw that reads its pass's color attachment at its own pixels after a render-target barrier
takes the snapshot only where no later fetch could render the attachment through a stand-in
(`keeps_own_attachment`: the image has STORAGE). A private texture whose device lays an image
out otherwise with STORAGE (with_free_usage leaves it off: the Iris Xe's optimal BGRA8Unorm,
as the orchestrator relayed from the 4845 A/B, 12-15 ms a frame of 30 splits for the private
selfread target) split at every such read, every frame, for good.

The fallback now notes the texture for its storage form (texture/storage_form.rs), the switch a
fetching pass's scratch already takes: at a later commit its image is made again with STORAGE
and its texels copied in once, announced as fetched-target-storage, and its later passes'
readers take the snapshot. A texture noted already returns before its plan is asked again, as
a reader that splits notes it at each such draw.

Test: tests/self_read_storage.rs (device test), with a test-only switch that makes STORAGE
cost every image (DeviceShared::storage_costs_forced, read in Device::if_free): a private
BGRA8Unorm target's first pass splits and takes the form at its commit, its later passes'
readers take the snapshot, each pass's texels Metal's; where the device does not take the path,
every reader splits and nothing swaps. Docs: the fetched-target-storage declaration and its
API.md entry, the FAST-PATHS attachment-read row.

(cherry picked from commit e0444b4029c9372197faf8c5bab3d967cb9bb543)
2026-11-07 15:14:06 -08:00
Anees Iqbal c34d5ad97a Record the chunk-length probe's numbers where the listed chunks' cap is described
The lane probe submit_per_ram_chunk_length ran on the Radeon 780M (RADV, Mesa 26.2.6, Linux
7.3.1) before the cap, two rounds, over an 8 GiB memfd RAM in 2 MiB pages with one 2 MiB object
in each chunk (job m3-max-5411 on the test copy a20f678c2e of e0e069f6bf).

Submission p50, round 1 / round 2:
- no RAM: 14.7 / 14.0 us
- 128 chunks of 64 MiB: 91.1 / 59.5 us
- 64 chunks of 128 MiB: 50.3 / 36.1 us
- 32 chunks of 256 MiB: 31.8 / 32.8 us
- 16 chunks of 512 MiB: 23.9 / 23.5 us
- 8 chunks of 1 GiB: 18.6 / 19.3 us

That is 0.34 to 0.66 us per live chunk. At every length the first submission that listed the
chunks took 52 to 56 ms, and the RAM was resident whole: 8192 of 8192 MiB, its objects over 16
to 256 MiB.

The FAST-PATHS entry and the host_ram module docs now carry these numbers. The paragraphs
touched are reflowed to 100 columns.

(cherry picked from commit 9aafb46d7b86f5834c821a25bc6ad1ec1b9b935e)
2026-11-07 15:03:11 -08:00
Anees Iqbal 6aff9aaa3c Stop a listed guest RAM's chunks at 256 MiB: a chunk's import pins every page of it
Where each listed import costs every submission (RADV with a source of dma-bufs), a guest RAM
was imported in chunks as long as the source's dma-bufs and the device's limits took: about
2.5 GiB on a consumer's 16 GiB guest on the Radeon 780M. A chunk's import pins every page of the
chunk, and udmabuf allocates the pages of the memfd the guest never touched, which stay
allocated once the chunk is freed. So each chunk an object lies in made all its bytes resident:
the consumer measured QEMU's Pss_Shmem at 7.86 GiB without the source and 12.31 GiB with it.

listed_chunk_bytes now stops at LONGEST_LISTED_CHUNK, 256 MiB, on every device and kernel. It
is a structural bound, not tied to udmabuf's size_limit_mb, which stays an upper bound through
HostRam::with_largest_dma_buf. The trade is speed against memory, with no accuracy change and
so no switch. Each live chunk costs every submission about half a microsecond (an 8 GiB RAM on
the 780M: 128 chunks of 64 MiB took a submission's median from 14 us to 60-88 us; 3 chunks of
2730 MiB, to 16 us). At 256 MiB, a 16 GiB RAM lists at most 64 chunks.

The kept-chunk rule (releases_idle_chunks) is unchanged, so the first-gather win of kept chunks
stays. The docs (the host_ram module, Device::use_host_ram, HOWTO section 6, and the FAST-PATHS
"Idle dma-buf imports are released" entry, edited in place) say where the chunks stop and why.
The lane probe submit_per_ram_chunk_length now measures only the lengths the plan can make (64,
128 and 256 MiB). Its run before the cap measured 64 MiB to 1 GiB.

Verified: the unit test listed_chunks_are_as_long_as_every_limit_takes_in_whole_64_mib fails
without the cap (a 2.5 GiB source gave 2560 MiB chunks) and passes with it (job ids in the tip).

(cherry picked from commit 9a158941e94173b4e0dc53b89f3b15c9b59f60c2)
2026-11-07 15:03:11 -08:00
Anees Iqbal 442dcd08c9 Copied host memory: a copy that drops the GPU's writes takes its guest RAM's log, and a draw that only reads through loaded addresses leaves unnamed copies uncompared
A copy of memory of Metal's private option bit 24 (on a system that maps no read-only view of
the pages) skipped the routing of its guest RAM runs, so it kept no log: every commit compared
every byte of it, and every completion of a command buffer with a root table compared every
copy. In consumer boots that is about 29.5 MiB per commit and per completion over 37-44 objects.

- Commit (copy in): a no-copy buffer, heap or rebind whose GPU writes are dropped has its runs
  asked as a writable one's are (routes_runs), so its copy takes the RAM's log and copies in only
  the pages the log reports written. It is still never bound in the RAM's chunk: the in-chunk
  binding is filtered on drops_writes. macOS keeps its read-only view and asks no runs.
- Completion (merge back): State::writes_unnamed narrows reaches_unnamed to commands whose
  functions may write memory. A draw's root table writes only where the vertex or fragment
  function may store or update memory (GraphicsState::vertex_writes_memory,
  fragment_writes_memory) or the pipeline has another stage; kernels, tile functions, replay
  tables and records resolved by host steps stay as they were (every copy compared). The compare
  itself stays: in a dropping copy it is what restores the dropped bytes, so later command
  buffers read the pages' bytes.

Tests: host_ram_copy_device a_private_bit_copy_over_the_pages_copies_in_only_the_pages_the_log_reports
(one page written: length - page bytes not compared, the GPU's fill dropped) and copied_device
a_merge_back_skips_a_copy_when_a_draw_only_reads_through_loaded_addresses (root table noted,
merge back compared 0). Docs: copied.rs, FAST-PATHS known gap, HOWTO section on copies.

(cherry picked from commit 61a9a4f4603a4c080ba5a4f2e204668ae621cf41)
2026-11-07 14:28:18 -08:00
Anees Iqbal c6e1d5a9fd Make a BC1 or BC4 texture over a surface's plane at an offset or pitch off 16
The runtime refused a BC texture over a plane of a surface with planes
whose offset or bytesPerRow is off 16 bytes, as
NotImplemented(SurfacePlaneShape). The M3 Max answers nil for every BC
texture over a surface, so the x86 Macs are the reference (job
m3-max-4779 on macbook-pro-2019: an AMD Radeon Pro 5300M and an Intel
UHD 630 under macOS 26.7.1, surface_texture_envelope.m's bgraat8.bc1 at
offset 8 and bgrarow264.bc1 at 264 bytes a row). Both GPUs' blits and
samples take block row j at the plane's offset + j x bytesPerRow, with
no rounding to 16.

linear_plan::blocks_off_sixteen makes a BC texture of 8-byte blocks
(BC1, BC4) at an offset and bytesPerRow that 8 divides, at least 16
bytes a row. Every BC plane now lies at the CPU's layout on the GPU too
(plan_iosurface_plane's blocks flag): at multiples of 16 the two were
already equal. The CPU calls take the plane's own offset, as the
5300M's getBytes does, while the UHD 630's getBytes and replaceRegion
take a plane at offset 8 from byte 0. That difference is recorded in
docs/API.md's accepted differences. BC4 was not measured off 16; it
takes BC1's 8-byte block rows. BC textures of 16-byte blocks (BC2,
BC3, BC5, BC6H, BC7) off 16, and 8-byte ones off 8 or under 16 bytes a
row, stay refused. SurfacePlaneShape's doc names them, and so does its
reach mark in REFUSALS.md.

Tests: tests::linear_plan makes bgraat8.bc1, bgrarow264.bc1, BC4 at
(8, 264) and BC1 at offset 40, with the GPU layout equal to the CPU's.
It refuses BC3, BC5 and BC7 off 16, BC1 at offset 4 and at 260 bytes a
row, and BC4 at 8 bytes a row. tests::surface_shapes (a device test)
gains bgraat8.bc1, bgrarow264.bc1 and bgraat8.bc4 on every path.

docs: linear_plan.rs's Block-compressed surfaces, the plane call,
SurfacePlaneShape, BufferRefusal::PlaneShape, the FAST-PATHS known gaps
and the API.md accepted differences. Regenerating REFUSALS.md changes
only the reach mark. CONFORMANCE-COVERAGE.md and the API signatures are
unchanged.

(cherry picked from commit ff454bd8b269fff6abf590da85cd050862d539a9)
2026-11-07 14:23:18 -08:00
Anees Iqbal 0c621da77a Make a texture over a surface's plane whose rows are wider than its pitch
Metal makes a 2D texture over a plane of a surface with planes whose
rows are wider than the plane's bytesPerRow, and a 1D texture wider than
one row; the runtime refused both as NotImplemented(SurfacePlaneShape).
On the M3 Max every path reads row y whole from the plane's offset plus
y times bytesPerRow (surface_texture_envelope.m's bgra1x2.65x64,
bgra1x2.128x32, 420v.p0.65x64, 420v.p1.33x32 and bgra1x2.1d.128), so
the texels lie in one place and the 2D texture's rows overlap, on the
GPU and the CPU alike.

linear_plan::wide_rows makes such a texture of a colour format over a
plane whose offset and bytesPerRow are multiples of 16, its GPU layout
its CPU one. A 1D texture is one row from the offset. A 2D texture's
overlapping rows are held as the rows of a pitch off 16 are: a shadow
whose copies reproduce the sharing, refused where a render pass stores
into it, blits into it refused (NotImplemented(OverlappingSurfaceRows)),
announced as CollidingSurfaceRowWrites. What is new is that the shared
head can be wider than the pitch (a byte shared by three rows or more),
so plane_copy_regions copies it in in pieces no wider than the pitch,
and copies row 0's head back as one row. plane_rows_share_bytes asks the
GPU layout alone, as a wide plane's CPU rows share bytes too. Other
formats, and planes off 16, stay refused: nothing measured them.

The write orders come from overlapping_plane_row_writes.m, extended in
the previous commit and run on the M3 Max (macOS 27.0.1, job
m3-max-5088, three processes a case), and recorded in its header. The
GPU gives the shared bytes the answers it gives the rows of the same GPU
pitch and row at a pitch off 16: no one order for blits, and for a
kernel the earlier row's within the first threadgroup's rows. Where
three rows share a byte, the kernel at 8 x 4 keeps the earliest row's.
replaceRegion writes the rows in order, so the latest row's bytes stand,
in every shape and process. So the runtime's copy back, which keeps the
earliest row's bytes, is one of Metal's kernel answers. Its CPU writes
go row by row, as Metal's do. The notice's cost now says "the earliest
row's" in place of "the earlier row's", and docs/API.md's catalogue says
the same.

Tests:
- tests::linear_plan: the probe's wide shapes are made, with their
  layouts. Wide rows off 16, of a depth format or of a 1D texture off
  16 are refused. A render target over wide rows is OverlappingRows.
- A new sweep: 2232 wide planes, 1302 of them sharing more than a
  pitch, over five texel sizes, pitches of 16 to 64 and 2 to 4 rows.
  It holds plane_copy_regions to what Vulkan allows and to the
  earliest-row rule (hold_the_copies, which now allows the head's
  pieces and a bufferRowLength of 0).
- tests::buffer_texture: its sweep now holds that only a wide plane's
  CPU rows share bytes, its CPU layout its GPU one.
- tests::surface_shapes (a device test): the probe's five wide shapes
  read as Metal reads them on every path, with a blit into the 2D ones
  refused.

docs: linear_plan.rs's Beyond the plane's rows and Rows that overlap;
SurfacePlaneShape, the plane call and BufferRefusal::PlaneShape; the
CollidingSurfaceRowWrites declaration and its API.md entry; and the
FAST-PATHS known gaps. REFUSALS.md, CONFORMANCE-COVERAGE.md and the API
signatures are unchanged when regenerated.

Checks: job ids are in the tip's report.
(cherry picked from commit 344cd110f8f612907f26dd9a30b0871e299ddb27)
2026-11-07 14:23:18 -08:00
Anees Iqbal 6b6a7f522b Make mipmapped, 3D, multisample and sliced textures over a surface's plane
What. Buffer::new_texture_with_iosurface_plane over a plane of a surface
with planes makes three shapes it answered
NotImplemented(SurfacePlaneShape) for:
- a 2D texture of more than one level, a 3D texture and a 2D multisample
  one, of a colour format (linear_plan::apart_from_plane: is_linear and
  tail_held): a texture of the device's own memory
  (Device::surface_texture_apart), zero when made in every storage mode,
  a Private one's too (texture.rs's new Fresh::Zero start, which skips
  Metal's fresh pattern and the uncounted held start), announced by the
  new Degradation::SurfaceTexelsApart ("surface-texels-apart",
  precision). A Memoryless one stays MemorylessSurfacePlane.
- a 2D array of more than one slice, of a colour format, over a plane
  whose offset and bytesPerRow are multiples of 16
  (linear_plan::slices_apart): its first slice over the plane as a 2D
  texture's rows, its others in a tail of the texture's own. The planner
  lays the slices one image apart and gives Placed::kept, the second
  slice's first byte (or the buffer's length where that comes first);
  Texels::kept cuts the tail there instead of at the buffer's length
  (with_tail, past, staging), so the shadow's copies, blits and CPU
  calls take slice 0 from the plane and the rest from the tail.
  Announced by SurfaceTexelsTail, whose doc and cost now name both
  cases.

Why. Metal makes these, and on the M3 Max under macOS 27.0.1
(probes/surface_texture_envelope.m, job m3-max-4776) it lays them out in
no one place: bgra1x2.mips2/mips7, 420v.p0.mips2, bgra1x2.3d.d2,
420v.p0.3d.d2 and bgra1x2.2dms4.private read level 0 or slice 0 by blit
and kernel from other bytes than its blits, replaceRegion and getBytes
put there; bgra1x2.2darray.a2 and .a2.64x64 keep slice 0 over the plane
on every path while slice 1 is read at the plane's offset by blits and
getBytes, one image on by kernels, and written at the plane's offset.
By the rule of 9ee7323e76 what lies in one place stays in place and the
rest goes in memory of the texture's own, announced (the orchestrator's
option A). The x86 Macs under macOS 26.7.1 keep level 0 and slice 0 of
the first shapes over the plane; API.md's accepted differences records
that the runtime does not.

Docs: API.md's catalogue (the new kind, SurfaceTexelsTail rewritten) and
two accepted differences (sliced arrays; mipmapped/3D/multisample);
FAST-PATHS.md's known gap; SurfacePlaneShape's, PlaneShape's and the
plane call's docs; REFUSALS.md regenerated; api_signatures.tsv blessed.

Tests: tests::buffer_tail_device::an_array_over_a_plane_keeps_its_second_slice_in_its_tail
(64x32x2 RGBA8 over a 32768-byte plane: slice 0 the plane's bytes and
slice 1 zero on get_bytes, blit and a kernel through 2D views; kernel,
CPU writes read back on every path; the plane past slice 0 and the
buffers around unchanged; one notice) and
a_plane_s_texture_metal_lays_in_no_one_place_lies_apart (2 levels, 3D of
depth 2, 4-sample Private; level 0 zero, levels and slices written and
read back, no byte of the surface changes, one notice);
validation lane a_mipmapped_plane_lies_apart_and_is_announced, listed in
degrade_notices; linear_plan table rows for apart and sliced shapes,
their kept cut, and the off-16 and depth arrays still refused.

Verified by potluck jobs at this commit (clippy plain and m2v_cpu_icd,
runtime unit tests, lavapipe runtime and validation lanes, a negative
control at the runtime sources before it); results in the tip's report.

(cherry picked from commit 463cd6b9ecccc9e0b4263d8ac2452190f0287241)
2026-11-07 14:23:17 -08:00
Anees Iqbal 32b8a9dfa1 FAST-PATHS: the guest RAM chunk's first-submission stall as the 780M A/B measured it
The row kept the 231 to 275 ms a /proc stack sampler saw (gem10 job 4750). The A/B of the probe
runtime_lane::submit_per_import::submit_per_ram_chunk on the Radeon 780M (gem10 job m3-max-5090,
--exclusive, an 8 GiB memfd RAM with its udmabuf source and with_largest_dma_buf at the host's
limit, 3 chunks of up to 3.94 GiB, two rounds each) measured more:

- the first gather after the idle window, its chunk released and imported again (the plan before
  this branch): 475.7 and 480.1 ms from commit to completion, 453 and 462 ms of it submitting;
  with the chunks kept: 2.76 and 2.58 ms (0.49 and 0.32 ms submitting), no import made;
- a gather at each 64 MiB: 240.7 and 185.3 ms released, 4.6 and 5.9 ms kept;
- steady submission p50 4 s after the objects went: 14.7 and 15.3 us with no chunk live, 16.8
  and 16.2 us with 3 kept.

The row now gives 231 to 462 ms and both gathers' times, and 14 to 15 us with no chunk.

(cherry picked from commit 52f46a21948eee752d2702b42ec171309bd3ab55)
2026-11-07 14:11:16 -08:00
Anees Iqbal 78a98addc1 Guest RAM: a listed chunk stays imported where the whole RAM fits the memory its imports count against
On RADV the first kernel submission that lists a guest-RAM chunk just imported waits while
amdgpu writes the chunk's page tables, one entry per host page, through SDMA jobs that wait
for room in the IB suballocator (amdgpu_cs_ioctl > amdgpu_vm_bo_update > amdgpu_vm_sdma_update
> drm_suballoc). It holds the VM's reservation lock throughout, so every other submission of
the device waits too, and so did the guest-RAM thread's next PRIME_FD_TO_HANDLE (218 ms in
amdgpu_gem_object_open). Seen with a root /proc stack sampler on the Radeon 780M (gem10 job
4750): 231 to 275 ms of a gather's submission per 3.94 GiB chunk imported again. Every
re-import after the idle release paid it again.

A listed chunk, once imported, now stays imported while the device uses the RAM, where the
whole RAM fits in half the device's memory heaps with unified memory (RADV reports an APU's
GTT and carve-out together, split across two heaps), else in three quarters of the heaps that
are not device-local (a discrete GPU's GTT). Chunks kept past their objects must fit in the
kernel's GTT: RADV lists every import in every submission, which fails once they pass it.
Where the RAM does not fit, chunks are released while idle as before. Each kept chunk costs
every submission about half a microsecond (3 chunks for 8 GiB: 16 us against 14 us).

Plan::releases says which; Device::count_host_ram_imports_against is the device tests' seam
(cfg(test)): the release test makes the RAM too long, and a new test sees chunks kept past
their objects and the idle window, with the next objects bound in them and no import made.
The lane probe's gathers say how many chunks are live and were released. FAST-PATHS and
HOWTO say what is true now.

(cherry picked from commit 75f17258ddd0dc03e2f89a85819091cfa22c345a)
2026-11-07 14:11:16 -08:00
Anees Iqbal 2fff78740e Record that a sparse slice past the texture's costs its other levels and tail what it costs inside
UnitGrid::clipped_region charges a mapping update whose slice is past
the texture's own what the same region inside the texture costs: the
region clipped to the level's tiles, a page per tile, the slice's whole
tail at firstMipmapInTail, and nothing inside the tail past it. That
was measured on level 0 alone, and mapping.rs called every other level
and the tail unmeasured.

sparse_slice_past_levels_usedsize.m (landed with rows2's fixes) ran on
the M3 Max (macOS 27.0.1, job m3-max-4446): eighteen shapes, each in its
own process and run twice. It used the direct selector, the indirect one
and the direct one through a view, over a 2-slice 256x256 nine-level
R32Float texture. Every reading is the rule's, and so is every
control's on an in-bounds slice:
- a tile of level 1 or of level 2 costs one page;
- 8x8 tiles on a level holding 2x2 cost four;
- a tile of level 3, the first tail level, costs the slice's tail (one
  page here);
- level 5, inside the tail, costs nothing;
- an unmap gives the page back.
The three forms and the two runs read alike. No behavior changes.

- tests::sparse gains the readings row by row, each with its control.
- mapping.rs states the rule as measured on those levels and the tail.
- The probe's header records what it read.
- FAST-PATHS's known gap said the runtime counts none of these pages.
  It counts the pages Metal's heap counts (sparse/bind.rs charges them
  through SparseState::charged), as docs/API.md's accepted difference
  already said, so the known gap now says the same.

(cherry picked from commit c4a47fc17d634f750b9c62b6489c95d3d4d5d966)
2026-11-07 14:00:19 -08:00
Anees Iqbal 3312a0ad84 Make a texture over host pages before its verdict without waiting for the in-place check
A texture over host pages made while its class's in-place verdict was pending started the check
and waited for that verdict as it was made, up to in_place::VERDICT_WAIT (5 s). The check's
rounds take seconds on some devices and builds: on um870's Radeon 780M (RADV, Mesa 26.2.6), in a
debug build, the first of the consumer's odd-width surfaces (3662x16, rows of 14656 bytes,
ShaderRead | RenderTarget) took 1.75 s and 1.86 s to make (job m3-max-5168), past the ~2 s the
consumer's guest waits for the COMPLETE of its next message. reims-vgpu's
on_vulkan_a_presented_surface_at_an_odd_width_reads_row_for_row failed there ("a COMPLETE") from
the wait's landing on; every command buffer of the same shape completed in under 2 ms.

A texture made before its verdict is a shadow again (ShadowCause::CheckPending, counted in
host_texture_shadows_check_pending), and its making starts the check and waits for none of it.
A program that makes such textures as it starts, and wants them in place on a driver's first
run, starts the check earlier with Device::settle_in_place_checks and a zero timeout; a device
whose record holds the verdicts knows them as it is made, as before. VERDICT_WAIT,
InPlaceChecks::wait_for and WorkCounts::in_place_verdicts_waited go (api_signatures.tsv).

Test: tests::first_host_texture, the consumer's shape: six surfaces over no-copy buffers at widths
3662, 1831 and 1001 (rows padded to 64 bytes), ShaderRead | RenderTarget then ShaderRead, each
copied out by a blit and read at its own pixels by a draw. The first is a shadow made before its
verdict; before this change it waited and was counted 0 there (m3-max-5168), so the assertion
fails without the fix. fresh_pages's in-place test settles the check before its texture, as a
texture made before its verdict is a shadow now. The waiter's unit test goes with wait_for.

Docs: in_place.rs, docs/API.md, docs/HOWTO.md, the FAST-PATHS in-place row.
(cherry picked from commit eca12ad708a8f1ad53521c967d4340a9b2635a22)
2026-11-07 13:48:35 -08:00
Anees Iqbal eb6c13f52b Give a render target in place over host pages the storage usage its snapshot reads fetch through
On the Iris Xe (m3-max-4845, the self_reads lane, a 3662x2039 BGRA8 surface over host pages, 30
pairs of a 600x400 draw, a render-target barrier and a draw reading the target at its own
pixel), a surface in place (557d9f0905) split every reading draw: 30 splits a frame, 30 copies
of the whole surface into the reader's copy (224M texels copied in), 22.4 and 27.2 ms of GPU a
frame, where its shadow took the snapshot (cut A, 60b9a69d39): 30 snapshotted draws, no split,
4.7 and 4.3 ms. The in-place image took the feedback loop usage (aliases 1) but not the storage
usage, which a snapshot's fetch of the attachment in the pixel interlock reads through
(RenderLowering::keeps_own_attachment), so snapshot_wanted fell back to the split: the image
was the texture's declared plan's, where a shadow takes undeclared usages (with_undeclared_usage).

A texture over host pages that renders, in place, now takes the storage usage too
(framebuffer_fetch::storage_candidate over the feedback loop plan, with the view in another
format a fetch stores through where the device needs one: ANV's RGBA twin of a BGRA format)
where the device's check passed for a shader's writes over the pages' class and the texel is one
the check's kernel stores (4, 8 or 16 bytes): with that usage a shader writes the texels in
place, which the check's writes cover. Tried first, then the feedback loop plan, then the
declared plan: the first the device makes the image in place with. Elsewhere its readers split
as before. A rebind asks the writes verdict of an image with storage usage already.

Tests: tests::in_place_storage (new, device): a render target in place over host pages has the
storage usage only where the check passed for writes there, with the feedback loop usage and a
fetch through storage. runtime_lane::snapshot_reads::a_surfaces_readers_take_the_snapshot_at_any_area
expects a snapshot for an image in place only where it took the storage usage (Pointer writes:
Passed), as for a shadow.

Docs: in_place_image.rs (its usage), API.md (textures over host pages in place), FAST-PATHS.md
(the attachment-read row: images over host pages, and the shadow only where a texture is one).

Verified: cargo fmt; the build, clippy, lavapipe and the Iris A/B and snapshot lane follow in the
tip's evidence.

(cherry picked from commit e4d61153702293e23bd874cf0830ff22d6be307a)
2026-11-07 13:24:34 -08:00
Anees Iqbal 6276d55b25 Textures a shader writes over host pages in place, where the device's check passes for their writes
A texture over host pages whose usage writes it through a shader (`ShaderWrite` or `ShaderAtomic`)
was a shadow on every device: its texels copied in before each use and merged back after each
write. The owner's ruling of 11-07 (confirmed for discrete GPUs) has CPU-visible memory worked on
in place wherever the device can, slower or not, with a shadow only where in place is impossible,
announced and counted. This takes such a texture in place on the same terms as one that renders,
from the parked branch park/shaderwrite-in-place, onto the per-class, per-access check, with no
device-type rule: a discrete GPU takes it in place too.

- `in_place.rs`: a third access, `Access::Writes`, which a texture of `ShaderWrite` or
  `ShaderAtomic` usage takes; a texture is tried in place where its class's check passed for each
  access it takes (`Access::takes`: renders, writes, or reads where it does neither), asked in
  that order until one did not pass. A texture a shader writes of texels of 1 or 2 bytes, which
  the check's kernel stores none of, is a shadow (`ShadowCause::StoreWidth`); `ShadowCause::
  ShaderWrite` is gone. Nine verdicts a record (CHECK_VERSION 3).
- `in_place_check.rs`: the storage rounds, per class: a texture of `ShaderWrite` usage over the
  pattern, every texel stored by the crate-owned copy-in kernel through an unsigned-integer view
  (`Texture::store_in_place`, from a buffer outside the Metal address space), its first move
  first, while the writer writes the bytes between rows and after the image; every texel must read
  the kernel's bytes, every other byte the writer's or the pattern. `STORE_SHAPES`: 4, 8 and 16-byte
  texels, packed, padded at 512 bytes (widths no multiple of 4, odd heights) and at a tight 16-byte
  pitch, and 1920x1080.
- `WorkCounts`: `host_textures_in_place_written` (of `host_textures_in_place`, those a shader
  writes) and `host_texture_shadows_store_width` are new; `host_texture_shadows_shader_write` is now
  the subtotal of the shadows a shader writes, as `host_texture_shadows_render_target` is of those
  that render. The rebind of a texture in fresh pages asks every access its image's usage takes.

Tests: the decision test covers every usage, texel width and combination of the three accesses'
verdicts, and the order in which they are asked; the cause words and the record of nine verdicts.
Lanes: in_place_textures gains `written_textures_over_host_pages_take_the_path_their_checks_answered`
(64x64 `RGBA16Float` at 1024 and 512 bytes, 61x64 at 496, signaling-NaN halves beside the texels:
in place exactly where `Pointer writes` passed, a kernel's writes reaching the pages, every other
byte kept), and `textures_that_render_or_write_take_the_path_their_checks_answered` replaces the
test that counted every written texture a shadow; no_copy_textures and pitched_surfaces take a
written texture in place where its texels are 4, 8 or 16 bytes.

Docs: in_place.rs, in_place_check.rs, the policy's docs, API.md (the in-place paragraph, the
shadow paragraph, the `shadowed-texture` notice), HOWTO.md, the runtime README and FAST-PATHS.md's
in-place row and host-pages bullet.

(cherry picked from commit c3ffb08376251b87e16b7b417b39f1458e271085)
2026-11-07 13:24:33 -08:00
Anees Iqbal 24ceac6e88 Make device copies on a discrete GPU of Managed textures over host pages alone
On a discrete GPU, a texture over host pages that only samples or reads, over memory that carries a
log of its writes, was a device copy (a shadow in VRAM whose copies in take the rows the log
reports) whatever its storage mode: a speed choice, so the GPU read the surface from its own
memory instead of across the bus. The owner's ruling of 11-07 (confirmed for discrete): Shared
and IOSurface memory over guest pages is used in place over the import, never shadowed to VRAM
for speed; Managed keeps Metal's two copies on a discrete Mac. So `Texels::device_copy` now also
asks for `Managed` storage and a buffer's bytes (not an IOSurface plane's, whose memory is one copy
whatever the descriptor's storage mode): a Shared texture and an IOSurface's are in place over the
import where the device's check passed, as on every other device.

Tests: the runtime's `a_logged_device_copy_sampled_in_an_inline_pass_is_copied_in_before_the_pass`
and the device_copies lane make their buffers Managed (`over_logged_as`, `over_as`); the new lane
test `a_shared_surface_over_logged_pages_is_no_device_copy` asserts a Shared surface over logged
pages is no device copy on any device, in place exactly where the check passed for pointer pages,
and that its reads hold the pages' texels before and after a logged CPU write.

Docs: API.md, the runtime README, FAST-PATHS.md's in-place row, the WorkCounts field and the
lanes' module docs.

(cherry picked from commit fd9fc11dd372a0985fdbc921adb2bc971ff78a3d)
2026-11-07 13:24:33 -08:00
Anees Iqbal 669d756fd7 Make a texture buffer over a surface's plane at an offset or pitch off 16
What. Buffer::new_texture_with_iosurface_plane makes a TextureBuffer
over a plane of a surface with planes whose offset or bytesPerRow is
off 16 bytes, where it answered NotImplemented(SurfacePlaneShape). Its
texels are placed from the plane's CPU layout (placed.cpu) and go
through into_texture_buffer as a buffer's texture buffer does: its CPU
calls at the plane's offset, its functions from the offset rounded down
to 16. A BC texture off 16 stays refused. SurfacePlaneShape's doc, the
module's Beyond the plane's rows, BufferRefusal::PlaneShape and
FAST-PATHS.md's known gap say so.

Why. Metal makes it, in one place a path. On the M3 Max under macOS
27.0.1 (probes/surface_texture_envelope.m's bgraat8.texbuf.64,
bgraat8.texbuf.128 and bgrarow264.texbuf.128, job m3-max-4776) its
kernels read texel i from the offset rounded down to 16 plus i texels,
and getBytes and replaceRegion from the offset, at a 264-byte pitch as
at 256: the layout a texture buffer over a buffer already has in the
runtime. What Metal lays out in one place stays in place.

Tests: tests::surface_shapes::textures_over_surfaces_take_the_bytes_metal_does
gains the three probe shapes over a plane at offset 8 and at 264 bytes a
row; a kernel's reads are checked against the rows from the offset
rounded down to 16 (gpu_rows_of), the CPU's from the offset. linear_plan's
a_surface_plane_s_other_shapes_follow_the_probe places offsets 36, 8 and
pitch 264 (CPU offset kept, GPU offset rounded down); its refused row
for an off-16 texture buffer goes.

Verified (same tree content on the previous base, replay-27 9a1a8abf1d):
lavapipe on homelab-gem10-1 (m3-max-4868): runtime lane 174/174 with
surface_shapes passing; negative control, the runtime's sources at the
base with these tests: surface_shapes fails.
Re-checked on this base by the
branch's check job.

(cherry picked from commit 5da259d2aa40580e62ec41a0aa98a06664521b43)
2026-11-07 12:44:46 -08:00
Anees Iqbal b06871f199 Refuse a cube or cube array over a surface's plane as Metal's own refusal
What. Buffer::new_texture_with_iosurface_plane over a plane of a
surface with planes answers a Cube or CubeArray descriptor
Invalid(BufferTextureProblem::TextureType), where it answered
NotImplemented(SurfacePlaneShape). BufferTextureProblem::TextureType's
doc and basis name the plane's case; SurfacePlaneShape's doc, the
module's Beyond the plane's rows, FAST-PATHS.md's known gap and
REFUSALS.md (regenerated) follow.

Why. Plain Metal itself stops it on the M3 Max under macOS 27.0.1, the
release the runtime imitates: with the API validation layer off it
asserts "carriesComplexTexture || numFaces == 1" in
-[IOGPUMetalTexture initWithDevice:descriptor:iosurface:plane:field:args:argsSize:]
and ends the process, for a cube (bgra1x2.cube.16) and a cube array
(bgra1x2.cubearray.16) alike (probes/surface_texture_envelope.m, run
with --hazard so each shape runs in a child process, job m3-max-4776).
What Metal refuses is a typed Invalid, never a runtime gap.

Tests: linear_plan's a_surface_plane_s_other_shapes_follow_the_probe
expects TextureType for a 64x64 cube and a 16x16 cube array over a
planar surface; it fails without the check (both planned PlaneShape).

Verified (same tree content on the previous base, replay-27 9a1a8abf1d):
runtime unit 56/56 on msi-laptop (m3-max-4867), runtime lane 174/174 on
lavapipe on homelab-gem10-1 (m3-max-4868). Re-checked on this base by the
branch's check job.

(cherry picked from commit 7ea41c39ea9f471fcb14776f9c2c551cb4827209)
2026-11-07 12:44:46 -08:00
Anees Iqbal 88ddbf4f90 Keep a colour plane's texels past its surface in a tail of the texture's own
What. A colour texture of a plane of an IOSurface with planes
(Buffer::new_texture_with_iosurface_plane) whose GPU or CPU rows run past
the buffer standing for the surface is made. Its texels inside the surface
are the buffer's bytes, as every texture over a buffer's are; its texels
past it lie in a tail of the texture's own (Texels::past, the form
9ee7323e76 gave a 2D texture past its buffer's length): a Shared buffer,
zero when made, which its functions, blits and CPU calls read and write
alike. The new Degradation::SurfaceTexelsTail (precision,
"surface-texels-tail") announces it once. linear_plan's tail_held names
the shapes that keep no tail and stay NotImplemented(TexelsPastBufferLength):
a two-plane YCbCr, two-plane extended-range, 4:2:2, depth, stencil or BC
texture (another form than a shadow's copies of rows holds their texels),
and a rotated texture's stored frame (turned_plane), whose turned texels
past a surface are not measured.

Why. reims-vgpu's guests make such planes and Metal makes them; the
runtime refused them. On the M3 Max (macOS 27.0.1,
probes/surface_texture_envelope.m's bgra1.64x65, bgra1.64x128 and
420v.p1.32x512) Metal lays those texels out in no one place: its blits
read zeros past the surface, its kernels zeros and 32 KiB on the plane's
rows again, its getBytes zeros and other memory, and its writes there
change no byte of the surface. By the rule of 9ee7323e76, texels Metal
lays out in no one place go in a tail of the texture's own, announced;
the rows inside the surface stay in place.

Docs: API.md's degrade-notice catalogue gains the kind and its accepted
difference names the colour planes; FAST-PATHS.md's known gap and
TexelsPastBufferLength's doc name what stays refused; REFUSALS.md and
reach.tsv regenerated; api_signatures.tsv blessed for the new kind.

Tests: tests::buffer_tail_device::a_plane_past_its_surface_keeps_those_texels_in_its_tail
(64x17 over 4096 bytes and 64x16 from offset 2048: get_bytes, blit and
kernel rows inside and past the surface, a kernel write, a replace_region
past it, the buffers around unchanged, one notice); the validation lane's
a_plane_past_its_surface_is_made_and_announced (the notice beside the
forced shadow, the rows read and written past the surface, the buffer's
bytes kept), listed in degrade_notices; linear_plan's table rows for the
kept and refused shapes.

Verified (at the same tree content on the previous base, replay-27
9a1a8abf1d): lavapipe on homelab-gem10-1 (m3-max-4868) runtime lane
174/174 and validation lane 70/70, clippy --cfg m2v_cpu_icd clean;
msi-laptop (m3-max-4867) clippy plain clean, runtime unit 56/56,
conformance unit 53/53. Negative control: the runtime's sources at the
base with these tests fail a_plane_past_its_surface_keeps_those_texels_in_its_tail
(NotImplemented(TexelsPastBufferLength)). Re-checked on this base by the
branch's check job.

(cherry picked from commit 5ad2ed0b865ff4027488c398a09fc53c0a80ab2f)
2026-11-07 12:44:45 -08:00
Anees Iqbal 23ffb2f64f Name the in-place check's record by the driver and the check alone; wait for the verdict
The record of the device's in-place check was named by RUNTIME_VERSION too, which moves at almost
every pin: every reims boot after a pin move ran the check again, and the textures made before it
answered (WindowServer's framebuffers, made at its start) were shadows for that boot's life.

- in_place.rs: the record's name and body hold the check's tag, kind and version and the driver's
  identity (vendor, device, driver version, driver ID, name, info, device UUID), not the runtime
  version; the body loses its runtime field. CHECK_VERSION is the version of what decides the
  answer: the check, and the images over host pages it checks as the product makes them. Asked
  by main for the owner's 11-07 ruling.
- A texture made while its class's verdict for its access is pending starts the check and waits
  for that verdict as it is made, up to in_place::VERDICT_WAIT (5 s), instead of taking a shadow
  for its life (InPlaceChecks::wait_for, woken by each verdict set and by the settle; counted
  WorkCounts::in_place_verdicts_waited). Past the wait it is a shadow, counted check_pending.
- self_reads prints the check's time (SELF-READ-CHECK ... took).

Tests: tests::in_place pins the record name to the identity and check alone (a hash computed in
the test), drops the runtime field from the frame tests, and checks a waiter wakes on its own
verdict and on the settle.

Docs: in_place.rs, in_place_check.rs, docs/API.md, docs/HOWTO.md, docs/FAST-PATHS.md's row;
api_signatures.tsv gains WorkCounts.in_place_verdicts_waited.

Verified: build, clippy and the touched tests in the follow-up jobs named in the tip's report.
(cherry picked from commit 841a92b0020f1d43e943c9bc04245cffb7fcf503)
2026-11-07 12:33:50 -08:00
Anees Iqbal 8ab8a8c0fe Render targets over host pages in place, where the device's check passes for them
A texture over host pages whose usage renders into it (an IOSurface's render target, the guest
desktop's framebuffer) was always a shadow: in_place() refused RenderTarget usage by policy, so
every render pass instance over one copied the whole texture in, kept it and merged it back (on
the Iris Xe of RPL-P, ~3 ms an instance at 3662x2039 in reims's measurements, 90-98% of the
desktop's GPU time a composite). ANV makes the linear image such a texture needs at every pitch
probed (BGRA8 at widths 3662, 1920, 2560, 3840, 1366 and 1440, packed and padded to 16, 64, 128,
256 and 512 bytes, with color attachment and feedback loop usage, for host allocations; job
m3-max-4631), so nothing on the device kept it out.

The owner's rulings (10-27: render targets in place where the driver leaves the bytes alone;
11-07: CPU-visible memory worked on in place even where a linear image is slower) take such a
texture in place where the device's own check shows the operations Vulkan lets touch the bytes
beside the texels leave them alone. So:

- in_place.rs: the check's verdicts are per class and access (Access::Reads, Access::Renders):
  a texture that renders asks its class's render verdict; only a shader write (ShaderWrite,
  ShaderAtomic, Unknown) is refused by usage. ShadowCause::RenderTarget is gone; the pending,
  failed and unchecked causes name the access. The record holds six verdicts (CHECK_VERSION 2).
- in_place_check.rs: rounds of their own for an image that renders: the texture made with
  RenderTarget usage, the writer writing the bytes between rows and after the image alone,
  through the first move, the moves into ATTACHMENT_FEEDBACK_LOOP_OPTIMAL_EXT and back where the
  image has that usage (Texture::settle_feedback_moves, render_target::feedback_moves, recorded as
  moved_barriers records them), and a render pass of the check's own queue that clears at load
  and stores. Every texel must read zero after, every other byte the CPU's write or the pattern.
- in_place_image.rs: a texture that renders takes the feedback loop usage where the device makes
  the image with it (counted feedback_loop_alias_images), so a self-read after a render-target
  barrier reads through a snapshot rather than a split; else the declared plan's image.
- texture.rs: on a discrete GPU, the device copy (dirty-log shadow) stays for textures that only
  sample or read; one that renders works on the pages in place.
- WorkCounts::host_texture_shadows_render_target now counts, of the shadows counted by cause,
  those that render: the render targets still shadowed, whatever the cause.

Docs: in_place.rs and in_place_check.rs module docs, HostPageTexturePolicy, the runtime README,
docs/API.md, docs/FAST-PATHS.md's in-place row and host-pages bullet. Lanes: in_place_textures
(render targets in place where "Pointer renders: Passed", recalled verdicts 6),
no_copy_textures (render targets may alias; passes_blend_load_and_store_as_private_textures runs
under both policies, so in-place render targets are checked byte for byte against a private
texture with the padding untouched), pitched_surfaces (render targets may alias in the _in_place
runs), attachment_read_costs::self_reads (settles the check first, prints textures in place).

Verified: build, clippy and the touched tests in the follow-up jobs named in the tip's report.
(cherry picked from commit 557d9f090525801183aaff5958c4738c0cfabe46)
2026-11-07 12:33:49 -08:00
Anees Iqbal d33079bd05 Read a shadowed attachment through a snapshot after a barrier, not a split
A texture over host pages that renders is always a shadow (in_place.rs:
ShadowCause::RenderTarget), the consumer's guest's IOSurface framebuffer
among them, and Texture::snapshot_color took only an image of its own or a
linear image over the bytes. So every draw that read such a target at its own
pixels after a barrier over the render targets split the render pass
instance, on every device: a keep of the whole shadow for the merge, a copy
of every texel from the bytes into the copy the reader reads, and a store and
load of the attachment, at each read (the guest's selfread probe on the Iris
Xe: 30 splits, 31 whole copies in and 30 keeps a frame, 98 ms).

The shadow is the image the pass renders, so the snapshot path serves it as
it serves an image of its own:

- the shadow image takes the feedback loop usage where that costs it nothing
  (Device::if_free, as with_free_usage gives an image of its own), counted as
  WorkCounts::feedback_loop_shadow_images;
- Texture::snapshot_color takes Storage::Shadow's image;
- RenderCommandEncoder::over_bytes (the snapshot at any area) takes a texture
  that renders its bytes through a shadow too (Texture::renders_bytes), as
  the split's copy there reads the bytes into the reader's copy after a keep
  and a merge.

Every other check of render/snapshot.rs stands; the reads are the snapshot's,
exact as for an image of its own. The pass's shadow plan is unchanged: the
attachment is copied in before the instance and merged back as the encoder
ends, as before, without the keeps and copies of the splits.

Tests: runtime_lane::snapshot_reads::a_surfaces_readers_take_the_snapshot_at_any_area
now expects a snapshot for each reader of a surface over host pages wherever
the device takes the path and the image the pass renders took the usage (the
shadow's, or a linear alias's), its bytes unchanged. The self_reads lane
prints the images made with the usage. The WorkCounts field is in the
api_signatures table and host_ab's list; the FAST-PATHS row on attachment
reads names shadows.

(cherry picked from commit 60b9a69d393a097f8658af8bcb5a8d6ef3576441)
2026-11-07 12:33:49 -08:00
Anees Iqbal 76f46963b6 Driver facts: RADV on the RX 7900 XTX decodes BC1 to BC3 as Metal does
The XTX's BC1 to BC3 texels, unorm and sRGB, read as Metal's decode in
the runtime lane `compressed_decode::bc1_to_bc5_texels_read_the_device_s_decode`:
0 of 4096 channels off for each of the six formats (RADV, Mesa 26.2.6,
job m3-max-4261 on homelab-gem10's XTX, MESA_VK_DEVICE_SELECT 1002:744c!),
the 780M's reading exactly. Its BC4 and BC5 read as the 780M's do
too (BC4 snorm 10 channels up to 1.6/255, BC5 snorm 44 up to 1.726/255),
so `ChannelBlockDecodeIsMetals` stays off for both.

So `ColorBlockDecodeIsMetals` gains a RADV row on the XTX (0x744c, the
new AMD_RX_7900_XTX), and a BC1 to BC3 texture there no longer announces
`compressed-texel-decode`. The notice's doc, docs/API.md's catalogue,
docs/FAST-PATHS.md's row and the fact's measurement doc name the XTX.
The 12 RADV ledger rows of bc1/bc2/bc3-rgba-srgb now state that the block
decode is measured to be Metal's on both GPUs, so the sRGB decode is
what differs.

Test: `a_radv_gpu_no_row_names_takes_radv_s_driver_wide_fact_alone`
presented the 780M under the XTX's deviceID as a GPU no row names; it
now expects the XTX's two facts (the driver-wide zero fetch and BC1 to
BC3's decode) there and the driver-wide fact alone under 0x1114, at
another release too.

Pinned files change (driver_facts.rs, degradation.rs): the runtime pin
and RUNTIME_VERSION are the orchestrator's.

(cherry picked from commit 18101735f400ebe243e775a67b7d8da19ea2ad5a)
2026-11-07 11:10:56 -08:00
Anees Iqbal 6a31655071 Guest RAM on a listed device: no making or copy waits for a long chunk's import
On a device where each listed import costs every submission (RADV with a dma-buf source), a
guest RAM's chunks are a few long dma-bufs (2.7 GiB on the Radeon 780M and RX 7900 XTX), and
the first object over a chunk not imported imported it on its own thread: 660 to 692 ms, at
the first object over each chunk and again at a released chunk's next use. A copy over such a
chunk (copy_from_host_ram, copy_to_host_ram) did the same on the encoding thread.

Now the chunk's import is off the caller's path:
- On a listed device the device's thread (listed_chunks, in place of release_idle) imports each
  chunk an object or copy asked for (ChunkSlot::asked, RamOnDevice::next_asked), and still
  releases idle chunks. The object, and every object over the chunk until the import is done,
  is bound in an import of its own run alone (RamOnDevice::run_alone), as on a device that
  imports ahead; those after lie in the chunk.
- A buffer's (not a heap's) run import is releasable as a no-copy buffer's own import is
  (host_residency.rs, AgainFrom::RamRun): released while idle, its address never handed out,
  and at its next blit bound in the chunk's import where that is made and lays the bytes as the
  run's did, else in its run's own import again; never the chunk's import nor a wait for one.
  This holds on every device whose objects take run imports.
- A copy over a chunk not imported imports each of its ranges of that chunk alone (ranges less
  than 2 MiB apart joined, at most copy::MOST_ALONE = 16), held by its command buffer, while the
  device's thread imports the chunk (RamOnDevice::for_copy); more ranges than that, or where an
  object's run would not be imported alone, the chunk as before.

Tests: the listed device test now checks the first object's run import, the thread's import of
the asked chunk, the holders in the chunk, the runs' release while idle and the rebind in the
chunk at the next blit, the chunks' release, and a copy over a released chunk taking its run
alone. The AHEAD copy window test expects the copy past the window to import its page alone.
Unit tests: next_asked's choice, alone_ranges' joins.

Docs: host_ram.rs, host_residency.rs, host_ram/copy.rs module docs, use_host_ram,
HostMemory::with_runs, WorkCounts::run_imports_live, FAST-PATHS.md, HOWTO.md.
(cherry picked from commit f80468eb4afac1e30f14fd99e1af06b67622a1a1)
2026-11-07 11:10:07 -08:00
Anees Iqbal 48ba1d9856 Guest RAM on a device that pays per listed import: few long chunks, none ahead, idle ones released
Where the device imports dma-bufs, the RAM has a source and the device's held imports add to the
cost of every submission (RADV), each listed import costs every submission: an 8 GiB RAM as 128
dma-bufs of 64 MiB raised a submission's median from 14 us to 60-88 us on the 780M (probe
submit_per_ram_dma_buf, job 3904), as 3 of 2730 MiB to 16 us.

There (Plan::listed) a chunk is as long as one dma-buf of the source holds
(HostRam::with_largest_dma_buf, new: udmabuf's size_limit_mb) and maxMemoryAllocationSize,
maxBufferSize and maxStorageBufferRange take, in whole 64 MiB (listed_chunk_bytes). No thread
imports ahead and no run is imported alone; the device's thread instead releases a chunk only its
slot holds once it stayed so for its window (2 s, doubled per release up to 64 s, as a no-copy
buffer's idle import), counted by the new WorkCounts::host_ram_chunks_released.

Tests: listed_chunk_bytes and long chunk_spans unit tests; a device test
(where_each_listed_import_costs_a_submission_...) of one long chunk, none ahead, kept while held,
released once idle and imported again; the probe submit_per_ram_chunk (8 GiB memfd RAM, an
object over each 64 MiB). Docs: host_ram.rs, with_runs, HOWTO section 6, FAST-PATHS idle-release
row, api_signatures.

Not built yet: the next commits fix forward what the build finds.

(cherry picked from commit e313ddd4201e87a76490a36eb394281d6961dbc9)
2026-11-07 10:32:40 -08:00
Anees Iqbal 50c03d4b54 Make a mesh render pipeline of maxVertexAmplificationCount above 1, and refuse its amplified draws
Metal makes a mesh render pipeline of maxVertexAmplificationCount 2 and
answers its limits as the plain pipeline's (the
mesh-limits-amplification-2 recording, M3 Max); the translator refused
it at creation, NotImplemented(VertexAmplification). Now it is made,
without multiview (a mesh pipeline draws no amplification as a view, so
graphics_requirements asks no multiview of it), and a draw of one
amplification, Metal's default, draws as a pipeline without
amplification does. The refusal moves to the draw of more than one: the
binder refuses a mesh pipeline's multiview route and its one-at-a-time
route alike NotImplemented(VertexAmplification) (the second was
MeshShading). No exact form is built: multiview may run the task stage
once a view where Metal runs the object function once a draw, and a
draw per amplification reruns it and needs the mesh function to add a
view mapping's offsets.

Test: engine_mesh's an_amplified_mesh_pipeline_draws_one_amplification
(made on every committed profile, no multiview requirement, a draw at
count 1, both routes at count 2 refused); the creation table's amp-2
row now expects the pipeline. docs/FAST-PATHS.md's known gap and
docs/REFUSALS.md follow. Not yet run.

(cherry picked from commit fe4aa26ba199c3bc8aedff48543623d09489122a)
2026-11-07 09:37:11 -08:00
Anees Iqbal 51b8007dd9 Docs for the formats held for copies alone
docs/FAST-PATHS.md's known gap of the 26 footprint formats now says
which twenty are held for copies alone and what stays refused (reads,
writes, renders, views, texel buffers' reads, sparse textures), and why
the four RGB10A8_2P formats stay unheld: Metal lays them out in two
planes, as RGB10A8_2P_XR10, whose blits between textures move both, and
one bytes image of the texel's word would not hold the second plane.
(The previous commit's message said Metal's blits of RGB10A8_2P move
two planes; that is RGB10A8_2P_XR10's measurement, not theirs.)

docs/API.md gains the accepted difference of seven of them, whose host
copies plain Metal leaves as no-ops at 16x16 under ShaderRead (the
format-footprints-padded-wide-channels recording), where the runtime
moves the bytes, as for the padded 10-bit formats Metal keeps
compressed. docs/REFUSALS.md re-derived (the sparse refusal's new
site).

(cherry picked from commit 8b4a0783997511a3ffcda495f3887749da56ca4a)
2026-11-07 09:37:10 -08:00
Anees Iqbal 231a7d86f7 Put a DontCare colour's kept texels behind DontCareColorPolicy::Kept
The owner's rule 1 keeps the fast form of every speed-for-accuracy choice the
default. A colour attachment of a texture's own image stored DontCare now
stores as the driver stores it by default (DONT_CARE where the driver is
measured to keep one of Metal's answers or to store as Metal's own, else
STORE), announced dont-care-store, and renders through the pooled backing
that keeps its earlier texels only under the new opt-in switch
DevicePolicy::dont_care_colors = DontCareColorPolicy::Kept, which
DevicePolicy::exact_answers() selects.

- metal2vulkan: the new public field DevicePolicy::dont_care_colors and enum
  DontCareColorPolicy { Driver (default), Kept }. Its docs give each form,
  its cost and Metal's documentation ("You need to assume that GPU discarded
  the texture's contents"). The runtime alone reads it, so no profile carries
  it (tests::fast_paths checks that no fingerprint moves).
- runtime: kept_bytes::settle takes the backing only under Kept. The docs of
  kept_bytes, render_target, attachment_stand_in, degradation and
  WorkCounts::kept_texels_passes, which counts only the Kept form's passes,
  now say which policy they describe.
- docs/FAST-PATHS.md: the choice moves from "Costs of matching Metal" into the
  table, as a row with its default, its switch, its bound and its measured
  cost. docs/API.md's dont-care-store entry and the Render passes accepted
  difference name the policy.
- Tests of both settings. dont_care_stores' default-policy tests are back to
  their earlier form (each texel one of Metal's two answers, announced where
  the driver does not store as Metal's own) and assert that no pass took a
  backing. The new exact_answers_keep_a_dont_care_color_s_earlier_texels_on_
  every_driver runs under Kept: the single-sample cases, both barriers and the
  two 4x colours keep their texels exactly and are counted.
  deferred_calls's refused-end test is back to its DontCare form.
  clear_reach gains lane_with.
- conformance: the Policy::Exact doc lists queue_sharing and dont_care_colors.
  The colour case's dont-care-store comment says what each policy gives.
- The known-gaps ledger keeps the eight pass-sequence-color-actions rows
  removed. It is held against `conformance replay`, which takes the exact
  policy, as the BGRA10_XR compressed-blit rows already are.
- The API signatures are blessed and docs/CONFORMANCE-COVERAGE.md is
  re-derived (its ledger table had kept the rows that both families removed).
  REFUSALS.md does not change.

Verified: cargo fmt only. The Linux clippy, rustdoc, suites and lavapipe
replays under both policies follow as potluck jobs.

(cherry picked from commit ec3479464c0f72ab5443223a28e23e84ec23e78d)
2026-11-07 09:05:59 -08:00
Anees Iqbal 8d8db05c06 Record what a bit-24 no-copy buffer's dropping copy costs off macOS
On the RTX 5080 Laptop GPU, commit to completion, median of 300 (the
scratch example rows3_cost, b5080 entry rows3-t2 in batch m3-max-3848):
beside a live 16 MiB copy whose pages carry no log, a 256-byte fill into
a writable 16 MiB no-copy buffer took 1.5 ms (49 us beside a 64 KiB
copy), and the same fill into the copy 2.6 ms; into a 64 KiB copy 53 us.
Before the page-at-a-time restore (rows3-t1, same batch) the fill into
the 16 MiB copy took 13.1 ms. The known gap in docs/FAST-PATHS.md now
says so; one code span there is rewrapped onto one line.

(cherry picked from commit 3c595e52ada9f9088a86e8077ab6a536c43c204f)
2026-11-07 09:05:41 -08:00
Anees Iqbal 75137702ab Record what a DontCare colour's kept texels cost
Family A's change came in be0b42bc67/568dd0d59b (a DontCare colour of a
texture's own image keeps its texels through a pooled backing) and
18b42a54bc/e3b68145f3 (drop the pass-sequence-color-actions rows). Their
subjects say WIP and they have no body, so this is their body:

What: kept_bytes::settle now also renders a colour attachment of a
texture's own image stored DontCare (not memoryless, resolving nothing,
not over a buffer) through a backing its queue keeps for the
attachment's shape (attachment_stand_in::pooled_backing, which now takes
whether it copies, Cause::KeptTexels), into which a Load copies the
texels first; the backing is stored DONT_CARE and nothing is copied back.
Not where the pass hands the store to a driver whose DONT_CARE is
Metal's own (MoltenVK), nor the viewed/executes/taken passes, nor where
a format makes no stand-in. No dont-care-store is announced for it, as
the texture keeps Metal's answer; WorkCounts::kept_texels_passes counts
each such pass.

Why: Metal's documentation leaves a DontCare store's contents open ("You
need to assume that GPU discarded the texture's contents"); what the M3
Max leaves, measured by pass-sequence-color-actions over eight runs, is
the attachment's texels from before the pass. Vulkan's DONT_CARE leaves
them undefined, and llvmpipe and the RTX 5080 left the pass's clear and
draw (8 ledger rows). STORE_OP_NONE does not keep the texels of a pass
that writes, so no store op alone matches; the backing does at the cost
below.

Verified:
- lavapipe: pass-sequence-color-actions every plane equal to Metal's
  (m3-max-3621, m3-max-3768, m3-max-3807 at the rebased tip); the whole
  lavapipe set matches the ledger exactly (3768: 1156 rows; 3807: 1137);
  the touched lane tests pass under m2v_cpu_icd (48 at the tip, 3807),
  among them dont_care_stores'
  a_dont_care_color_keeps_its_earlier_texels_on_every_driver, which
  counts kept_texels_passes.
- MoltenVK on the M3 Max: the case announced, its planes exact
  (m3-max-3743, m3-max-3822); 46 lane tests pass under m2v_gpu.
- Negative control (keeps_texels forced false, steelbrain/rows3-negctl,
  m3-max-3729): the 4 llvmpipe rows come back.
- Costs (this commit, docs/FAST-PATHS.md): the scratch example
  rows3_cost on the RTX 5080 (b5080 t entries rows3-t1, rows3-t2, batch
  m3-max-3848) and lavapipe (m3-max-3765, m3-max-3782).

(cherry picked from commit b0197dcf1103f2794723a2cf520f20d698a7b2fd)
2026-11-07 09:05:41 -08:00
Anees Iqbal 3eb84d76c6 Off macOS, drop the GPU's writes to bit-24 no-copy memory through a copy
Metal drops what a shader or the blit engine writes into no-copy memory
made with its private option bit 24: the write completes with no error,
a later command of the same command buffer may read it back, and neither
a later command buffer nor the CPU sees it (probes/readonly_gpu_writes.m,
an M3 Max under macOS 27.0.1; the owner's ruling of 10-23: drop, never
refuse, on every driver). macOS imports the pages through a read-only
view of them. Elsewhere the import was of the caller's own pages, so the
GPU's writes reached the pages, the CPU and later command buffers
(host-page-writes-kernel-store-read-only and
host-page-writes-visibility-read-only diverged on llvmpipe and the RTX
5080), announced as private-resource-option. No import can keep the
writes out there: Linux drivers pin imported pages for writing, and ANV
lost the device and RADV failed every submission over read-only imported
pages.

So off macOS such a buffer, heap or rebind is made over a copy of the
pages whose GPU writes are dropped, the mechanism copied.rs already has
for pages the process maps read-only: each commit copies in what the CPU
changed, later commands of the batch read the GPU's writes, and the
batch's completion puts every byte the GPU changed back, writing nothing
to the pages. The gate is not asked (nothing is imported), the copy joins
no other buffer over the bytes, and a rebind whose bytes moved in their
page is now a copy laid out at the old offset rather than refused.

- buffer_descriptor.rs: buffer_over_host_memory makes the copy
  (CopiedFor::ReadOnly) where drops_writes and the system maps no
  read-only view; the rebind path copies the same way (read_only_copy);
  copied_buffer takes why it copies, and passes read_only to
  CopiedBuffers::add and drops_writes to the buffer's HostCell.
  no_copy_options moves here from degradation.rs and no longer
  announces private-resource-option off macOS (that notice stays for a
  heap of the runtime's memory and an indirect command buffer).
- copied.rs: add() takes read_only, which drops the copy's GPU writes
  whatever the pages' protection.
- buffer.rs: BufferParts carries drops_writes into host_lie.
- New: CopiedBecause::ReadOnly, WorkCounts::copied_read_only_memory.
- Docs: read_only_view.rs, copied.rs, capabilities.rs (the answer stays
  no off macOS), values.rs, host_backing.rs, interop.rs, host_aliases.rs,
  error.rs (RebindTextures is macOS-only now), degradation.rs, docs/API.md
  (private-resource-option, copied-host-pages), docs/HOWTO.md and the
  docs/FAST-PATHS.md known gap: off macOS a command buffer committed while
  the writer is in flight still reads its writes, and a render pass's
  store-out into the copy completes where Metal's faults.
- Tests: degrade_notices' bit-24 lane tests assert the writes are
  dropped on every driver and count the copies (3 and 1 off macOS, 0 on
  it) and the kinds (copied-host-pages off macOS, none on it);
  copied_surfaces' dropping buffer is a copy of its own off macOS.
- host-page-writes read-only rows declare copied-host-pages in place of
  private-resource-option; their 8 ledger rows are removed.
- api_signatures.tsv blessed for the new field.

Verified: see the replay and lane-test jobs named in the branch report
(lavapipe, the RTX 5080 through b5080, MoltenVK on the M3).

(cherry picked from commit 1f24b1f035d61f093ecf2c76fae4b9c2e4b541d9)
2026-11-07 09:05:40 -08:00
Anees Iqbal c36bf38d91 Scheduler: wake after a committing thread's pass only where it submitted alone a batch that may group
The wake that ends a committing thread's pass (ff870f6403) came after every such pass. Before the
alone path (4d4e103471), a commit_and_submit's batch of a VkQueue whose batches may wait in a group
was left to the scheduler's thread, which the commit woke; every other batch it submitted itself,
waking nothing. So on a driver whose check finds no merge (lavapipe) the base never woke the thread
for a commit_and_submit, and the unconditional wake added one there: on lavapipe the "seen handler
alone" shape's commit to watch went to p50 14.7-15.0 us, p90 21.9-22.6, against the base's
13.7-13.9 and 16.0-17.3, while the same binary with the wake switched off was at the base
(m3-max-3884, gem10 exclusive).

Now `submit_plain_ready` counts the batches it submitted whose `VkQueue`'s batches may wait in a
group (`Plain::alone`: for a committing thread, those `plain` lets go alone where the group would go
at once, `goes_alone_at_commit`), and a committing pass that left nothing wakes the thread
(`Woken::Commit`) only where that count is above zero: the wake the batch's hand-off to the thread
would have made. Every driver keeps the base's cadence by construction: RADV its wake per such
commit, lavapipe and any driver whose check finds no merge none. Docs: the scheduler module,
`submit_at_commit`, `Plain`, `Woken::Commit`, `CommandBuffer::commit_and_submit`,
`WorkCounts::scheduler_wakes_commit`, the runtime README's item, FAST-PATHS row 37's figures. The
scheduler_wakes test is now
`a_commit_and_submit_wakes_the_sleeping_thread_only_for_a_batch_that_may_group`: once the
submission checks answered, ten commit wakings of ten where the batches may group, none elsewhere.

Verified (m3-max-3922, gem10 exclusive, one job, this diff on 7e57099fa3; base = the three
scheduler files before 4d4e103471; two alternating rounds of both lanes on each driver):
- lavapipe (Mesa 26.2.6): the thread's counts over the lane as the base's, sleeps 4000 and
  commit wakings 4000 at both, 2000 submitted at commit; "seen handler alone" commit to watch
  p50 13.8-14.1 us, p90 16.9-17.5, against this run's base 12.9-13.2 and 15.9-16.9 (3884's base
  13.7-13.9 and 16.0-17.3), the unconditional wake's p90 21.9-22.6 gone; a checked fill's commit to
  submission handler p50 12.5-13.4 us against 12.4-13.4.
- RADV (RX 7900 XTX): sleeps 6000 at both, the commit_and_submit batches' wakes counted as a
  commit's (commit 6000, host 0) where the base counted them as a host signal's (4000 and 2000);
  the plain shapes' commit to watch p50 32.1-47.3 us against 38.9-46.7, the thread's wake p50
  4.0-4.5 against 4.1; commit_and_submit's gain kept: a checked fill's commit to submission
  handler p50 30.4-32.8 us, p99 48.8-57.8, against 36.2-55.7 and 112.1-198.5, 520 of 520
  submitted at commit; another queue's head waiting, p50 24.7-25.0 against 32.7-39.2; the shape in
  turn with the plain ones, commit to watch p50 31.9-36.1 against 39.2-50.1.
- Tests alone (commit_and_submit, deferred_calls, scheduler_wakes, each --exact on one thread):
  31 of 31 on RADV (the new test: batches grouping, 10 commit wakings of 10) and on lavapipe (not
  grouping, 0 of 10). Negative controls: on RADV with 3e9230adf2's scheduler (no wake) the new test
  fails with 0 of 10; on lavapipe with 7e57099fa3's (the wake after every pass) it fails with 10.
- Clippy (plain, m2v_gpu, m2v_cpu_icd) and rustdoc with -D warnings pass (m3-max-3923, ms01).

(cherry picked from commit 9184d15a5707ff4e89c00f32af225b66ec40875e)
2026-11-07 08:17:57 -08:00
Anees Iqbal ff870f6403 Scheduler: a committing thread's pass ends by waking the scheduler's thread, as a commit does
Since a committing thread's batch went alone on a grouping driver (4d4e103471), a
`commit_and_submit` that submitted its batch itself no longer woke the scheduler's thread;
before it, on such a driver, that batch was left to the thread, whose wake came with it. The
thread so slept across those commits, and the plain `commit`s made beside them often fell into
a slow mode: in the completion-latency lane (three shapes committed in turn 2 ms apart), the
plain shapes' p50 was slow in 4 of 6 rounds (three jobs) without the wake and in none of 10 with
it, before the alone path or after this change.

Mechanism (gem10, RX 7900 XTX, RADV, Mesa 26.2.6, exclusive; m3-max-3816, a probe build):
the thread's own counts over the lane show the wake source: before the alone path, sleeps 6000,
woken by a commit 4000 and by the host 2000 (the committed batch left to it), batches submitted
at commit 0; at 3e9230adf2, sleeps 4000, commit 4000, host 0, at commit 2000; with a wake after
the committing thread's submissions, sleeps 6000, commit 4000, host 2000, at commit 2000. The
latency followed: in 3e9230adf2's slow round, the plain shapes' thread wake p50 4.5-10.6 us
(p90 51-104) and commit to watch p50 56-104 us, `vkQueueSubmit` itself 27-62 us at the median,
on every thread, the committing one's included; with the wake, both rounds at the old figures. The system-wide
cpuidle counts (entries and residency of each state, the menu governor, amd-pstate-epp) did not
separate the legs, so the idle-depth part of the account is not shown by them.

Fix: `Scheduler::submit_at_commit` wakes the thread after its pass, for what it left
(`Woken::Host`, as before) or else for the commit itself (`Woken::Commit`), once a sleep as any
waker. The wake comes after the submissions and their submission handlers, so nothing on a
command buffer's way to its `VkQueue` waits for it. Docs: the scheduler module, `submit_at_commit`,
`Woken::Commit`, `CommandBuffer::commit_and_submit`, `WorkCounts::scheduler_wakes_commit` and
`scheduler_wakes_host`, the runtime README's item, and FAST-PATHS row 37's figures for the alone
path. New test: `tests::scheduler_wakes::a_commit_and_submit_wakes_the_sleeping_thread_as_a_commit_does`
(ten `commit_and_submit`s after idle gaps, each submitted at commit, each a commit's waking).

Verified (m3-max-3823, gem10 exclusive, release, base = the three scheduler files before
4d4e103471, dev = development's scheduler, fix = this; two alternating rounds of both lanes):
- the plain shapes back at base: commit to watch p50 31.3-37.0 us against base 29.9-39.4 (dev
  33.4-169.9), the thread's wake p50 4.1-4.5 us against 4.0-4.2 (dev 4.3-51.0);
- commit_and_submit keeps its gain: a checked fill's commit to submission handler p50 30.7-32.2
  us against base 34.2-70.0, 520 of 520 submitted at commit; the call returns at 32.0-33.5 us
  against dev's 31.8-33.8; the shape in turn with the plain ones, commit to watch p50 31.3-31.6 us
  against base 31.3-39.5 (dev 29.6-102.4).
Tests alone on RADV (each `--exact`, one thread): commit_and_submit, deferred_calls and
scheduler_wakes, 31 of 31 pass at the fix; with development's scheduler 30 of 31, the new test
failing with 0 commit wakings of 10. Clippy (plain, m2v_gpu, m2v_cpu_icd) and rustdoc with -D
warnings pass (m3-max-3824, um870).

(cherry picked from commit b80e092759fb412a0154365bfb378ee38e096f56)
2026-11-07 07:16:37 -08:00
Anees Iqbal 6126e8a237 FAST-PATHS: the Grouped row's figures for a batch a committing thread submits alone
Measured in job m3-max-3640 (homelab-gem10-1, exclusive, release test
binaries of the fix's tip and of the form before it, alternating, two
rounds each): tests::completion_latency::runtime_commit_to_submission
and runtime_completion_latency on RADV (RX 7900 XTX, Mesa 26.2.6,
whose submission check finds merges: 520 batches submitted at commit
at the tip, 1 before) and on lavapipe (whose check finds none: the two
forms alike). The plain commits interleaved with commit_and_submit ones
saw the scheduler thread wake later at the tip, in three of four rows;
the row states it.

(cherry picked from commit d94a28e714c46ca24fe764700ee5017c2041c297)
2026-11-07 06:47:43 -08:00
Anees Iqbal 4d4e103471 commit_and_submit: on a grouping driver, submit a batch alone where the group would go at once
On lavapipe (and on every Mesa driver, whose queues merge a submission that
signals nothing into the next), commit_and_submit's committing thread never
submitted anything: tests::commit_and_submit printed "0 of 40 handlers on the
caller; passes at commit 40, batches 0", and six of its tests failed (lines
126, 217, 284, 427, 535, 624), with deferred_calls.rs:1106 (the check and
handler ran on the scheduler's thread, not the lowering thread). Under the
default CompletionPolicy::Grouped there, every batch "may wait in a group"
(group::groups), and scheduler::plain refused any such batch to a thread
other than the scheduler's, so each commit went to the scheduler's thread, a
wake and a pass away: the extension did nothing on the drivers it was made
for (the runtime README states it submits the ready command buffers needing
no host step and no storage-form switch; only the method's doc said "no
group").

A pass that holds a batch in the group sends the group at its end unless two
or more earlier submissions of its VkQueue are not seen complete
(Group::keeps). So where at most one runs, a committing thread now submits
such a batch alone (CommandBufferShared::goes_alone_at_commit, read from the
queue's timeline without its lock, as keeps reads it): it reaches the GPU no
later than through the scheduler, and the wake and pass are saved. Where two
or more run, it is left to the scheduler's thread, which holds it in the
group with the commits that join it, as before. submit_batch takes `alone`,
which a thread other than the scheduler's passes, so such a batch never joins
the group. A thread about to block keeps leaving groupable batches to the
scheduler.

Docs: commit_and_submit's doc, the scheduler module doc, the runtime README
and the Grouped row of docs/FAST-PATHS.md (its switch and forms unchanged).

Verified on lavapipe (layer 1.4.363) by the commit_and_submit and
deferred_calls tests and the grouped-submission lane at this commit and with
plain()'s change reverted, in one job (see the report for the job id).

(cherry picked from commit 25a43729192f80d5fc2ca3af42ef4c14596ae1f0)
2026-11-07 06:47:43 -08:00
Anees Iqbal 718f6543b4 HostRam: chunks imported as dma-bufs where held pointer imports tax every submission
reims measured raw Vulkan on the Radeon 780M: each live host-pointer import adds about
0.75 us plus 0.33 us per MiB to every vkQueueSubmit (amdgpu gets every page of a userptr
again in each CS), each dma-buf about 0.44 us with no per-page cost. A guest RAM imported
in 64 MiB pointer chunks would cost RADV about 24 us per chunk per submission, and RADV
refuses the pointer of any shared mapping (a memfd's) anyway, so the consumer imports
13-135 region blocks and its IOSurfaces one dma-buf each there.

- `HostRam::with_dma_buf(source)` (new public method) gives the RAM a DmaBufSource. Each
  import of the RAM, a chunk or an object's run imported alone, is then one dma-buf of its
  pages where the device's submission checks found a held pointer import taxing every
  submission (the ImportTax verdict; the pointer where that import fails), and elsewhere
  the pointer first, the dma-buf where the pointer is refused. The decision reads the
  device's measured verdict or the driver's refusal, never its identity: NVIDIA, ANV and
  MoltenVK (untaxed) keep the pointer path unchanged. `use_host_ram` waits (at most 10 s)
  for the checks first when the RAM has a source.
- A buffer bound in a dma-buf chunk is made for DMA_BUF_EXT memory
  (VUID-vkBindBufferMemory-memory-02985; `host_buffer` takes the handle type). Its
  placement lends the chunk's imports, so textures over it take the dma-buf image route
  (an image over a dma-buf of their own pages from the RAM's source), asked at the RAM's
  addresses (`Placement::dma_buf_address`: the caller's view may differ from the RAM's).
  A rebind into such a chunk makes the heap's and in-place images again as a rebind onto
  the caller's dma-bufs does. `host_backing` reports such a buffer InHostRam; its
  deallocator goes at once (it frees no memory of its own); the chunk's RAM keep-alive
  goes after the chunk's dma-buf import is freed.
- Counted: WorkCounts::host_ram_dma_buf_imports (new field).

Also in this commit, for the submission checks of 363fa41176: the docs that named the
removed DriverFact rows (PointerImportsFollowTheirAddress, SubmissionsWithoutSignalsMerge)
name the device checks (FAST-PATHS grouping row and known gaps, HOWTO, fresh_pages.rs,
buffer.rs, buffer_descriptor.rs, host_memory.rs, work_counts.rs); fresh_pages.rs and
FAST-PATHS give the measured reason for the tax gate (one 64 MiB fresh-page buffer: a
commit's p50 10.7 -> 36.6 us on the 780M, 14.7 -> 164.7 us on the RX 550,
submit_per_fresh_page_buffer at 27b9b13bcd); the checks' 10 s answer wait is one constant
(submit_check::ANSWER_WAIT) shared with the in-place check; and the recall test's
failure names the record, where it lies, the cache's rejected/failed reads and both
identities (it failed on lavapipe, msi-laptop, m3-max-3160: no device recalled the record
in 60 s; the cause is not known yet).

Verified: cargo fmt only; compiled and tested in the following jobs.
(cherry picked from commit fa8c27f1549fe09d769847ef63f8e34d51f2c6af)
2026-11-07 05:45:53 -08:00
Anees Iqbal c559ed6f84 Docs: the half shadow holds at more than one sample; REFUSALS for the merge's refusals
The extended-range-blends-stored-codes notice (its declaration and the
docs/API.md catalogue entry) now says where it is not announced: a color
whose half shadow the runtime holds, in a pass of one layer on a device that
orders fetch through the pixel interlock alone, at one sample or more, from
the pass's clear or (at one sample) its load; and where the codes stay:
over lavapipe's input attachments, in a multisampled pass that loads the
color, and after a draw the shadow cannot follow. docs/FAST-PATHS.md's word
attachment row no longer says an extended-range color keeps its codes at
more than one sample. docs/REFUSALS.md regenerated
(scripts/refusal-surface/refusal_surface.py): link's second
extended_write_mask site and fetch::unordered_extended_fetch.

How verified: refusal_surface.py wrote the table with 0 variants without a
reach mark or a basis; the catalogue test runs with the runtime suite next.

(cherry picked from commit 70691da1d131573dac3a3c4ae4e6436ad48283f3)
2026-11-05 21:13:17 -08:00
Anees Iqbal 0f289cdac4 Commit the regenerated fixture companions, and record how Metal runs an amplified mesh draw
What: the .ll and .air.ll companions of mesh_partial_barrier,
compute_thread_limit and mesh_pipeline_limits, and their TOOLCHAIN lines
(regen-air-fixtures on the M3 Max, job m3-max-2677). probes/
mesh_amplification.m records its answers: under an amplification count of
2 the object function runs once (8 threads) and the mesh threadgroups it
launches run once per amplification (16 threads, ids 0 and 1, a count of
2), each into its view mapping's slice. FAST-PATHS.md's known gap for a
mesh pipeline's amplification says what an exact form must do and why
neither built draw form is one.
Why: the tests and cases read the fixtures; the gap stays open with the
measured semantics written down.
Verified: the probe ran on the M3 Max (job m3-max-2677).

(cherry picked from commit bb5a45dd26d89d5af72e755ad4ac976975007d8b)
2026-11-05 21:13:15 -08:00
Anees Iqbal 9609083aa2 Walk object and mesh functions predicated at their barriers, and partial object threadgroups from their threads
What: the divergent-barrier pass (lower::simd::divergent::barriers) now covers
object and mesh functions as it covers kernels: a workgroup barrier in a block
Uniformity does not prove uniform makes the body walk predicated, so every
invocation reaches it. Every object function now runs a drawMeshThreads
partial object threadgroup (lower::mesh::plan_partial_groups no longer
excludes a body with a barrier; RuntimeFact::PartialObjectThreadgroups). One
whose body holds any workgroup barrier is walked predicated
(Predication::partial_groups) from live = KernelDecl::live, the invocation
being one of its threadgroup's threads (dispatch::emit_entry computes it in
the entry block and hands it to the walk through
CodeEmitter::entry_live/EmitCx::entry_live), so the invocations past a
partial threadgroup's threads reach every barrier, and loop vote, as
invocations that returned at entry, and run no other instruction of the body:
no load, store or atomic of theirs is made. A body without a barrier keeps its
early return. The vote word an object function's walk takes counts in its
ObjectThreadgroupArena fact, which the binder checks with the encoder's
lengths; where the word does not fit and the barriers are uniform, the
function runs no partial threadgroup (the binder refuses such a draw as
before).

Why: an object function with a threadgroup barrier on a partial object
threadgroup was refused (NotImplemented(MeshShading), a FAST-PATHS known gap),
which kept the Metal3 mesh shading row false on every device; and an object
or mesh function's barrier after a divergent early return or under a
thread-dependent condition stood in non-uniform control flow, which Vulkan
leaves undefined (an Intel GPU hangs on it).

Docs: FAST-PATHS' known gap is gone; render/mesh.rs, bind/graphics.rs and the
fact's docs say what runs. The Metal3 mesh feature rows
(families/features.rs) lose their not_implemented(MeshShading), and the
families test now expects the mesh shading row exact where the device runs
the stages natively or as compute work.

Tests: engine_mesh_barriers (new, over the owned fixture
mesh_partial_barrier): every object function and the divergent mesh function
predicated on every committed profile, their bodies' barriers all uniform by
spirv::testing::barriers::workgroup_barriers_of (new: the check of a called
body); partial draws instantiate; and the interpreter runs each emulated
object function's partial and whole draws under BarrierRule::Vulkan giving
the predicated reading. The old
a_partial_object_threadgroup_of_a_body_with_a_barrier_is_not_implemented is
replaced by a_partial_object_threadgroup_of_a_body_with_a_barrier_draws.
SEMANTICS_VERSION 1973. Verification in the following commits' potluck runs.

(cherry picked from commit 65660d13d001484e444c0f89b268f92b847976b1)
2026-11-05 21:13:13 -08:00
Anees Iqbal 296723b362 Test a filter notice's bound format against the format the slot's binding presents
The consumer's own-format view test died on the M3 Max (MoltenVK) in strict mode at a sample of
an 8-bit 4:2:0 texture's 2D array view in its own format: `ycbcr-filter-not-exact`, "texture 0
bound as YCBCR84202P". That view is the luma view (`Texture::luma_view`): an `R8G8B8A8_UNORM`
image of the codes, read as the code-reading format `RGB8_420_2P` through a swizzle, which
Metal's own sampler filters as Metal filters that format (the lane already holds the view's
linear sample to that format's, and Metal's view to it bit for bit). The binding plan reads the
bound record's format (`ViewRecord::bound`, `RGB8_420_2P`), but the notice's bound-format test
read `Texture::pixel_format`, the view's own (`YCBCR8_420_2P`), whose class carries the 1/2048
field `FloatSampleFilter`'s clause tests. So the note was wrong: no float texels are filtered
there. The 10-bit views (`RGB10_420_2P` codes, `A2B10G10R10_UNORM_PACK32`) and the `_sRGB`
twins' views announced it alike.

`Tables::bound_format` now reads the format the texture's bindings present
(`Texture::bound_pixel_format`, `ViewRecord::bound`), the one its slot's code was specialized
for. That changes what the bound-format notices test and name for every texture that reads its
image in another format: the luma views; views in other channels of their image's bits, whose
class is their image's; and converted textures over a P3 surface, whose image is the
code-reading format's codes. A P3 texture's linear sample is no longer announced: Metal's
filter of it is not measured, now a FAST-PATHS known gap. Notices only: no pipeline, binding or
answer changes.

Docs: ycbcr.rs (views; linear filtering, with the in-place form's 4:2:0-only reach), the
YCbCrFilterNotExact declaration and its API.md entry, and the FAST-PATHS known gap.

Verified: cargo fmt. The lane check of the previous commit fails without this on the M3 Max;
device runs follow.

(cherry picked from commit 37a50861dd4e105619690a520a290c30bd3208d5)
2026-11-05 18:59:20 -08:00
Anees Iqbal 21a1cf7218 Give the commit hand-off's cost from idle too, and name commit_and_submit its inline form
docs/FAST-PATHS.md gave the scheduler thread's wake as 5 us on the RTX
5080 Laptop GPU, true for commits back to back, where the thread is
awake. From idle it is far longer: with one fill committed every 2 ms
(the completion latency lane), a commit's batch was watched 140 to 165 us
after the call at the median on that GPU, against 5 us for vkQueueSubmit,
and a parked thread's wake took 80 to 105 us at the median on that host.
The row gives both, and names CommandBuffer::commit_and_submit as the
inline form a program that needs the latency takes.

(cherry picked from commit 880ffe3b551b585a7593784165a7b4ac11bc50ec)
2026-11-05 18:58:59 -08:00
Anees Iqbal c305c66a7f Give mesh pipelines Metal's descriptor limits, state queries and refusals
The mesh descriptor gains Metal's fields, with Metal's defaults:
max_total_threads_per_{object,mesh}_threadgroup, max_total_threadgroups_per_mesh_grid,
the two threadgroup-size-is-multiple-of-width flags, payload_memory_length,
max_vertex_amplification_count (1) and required_threads_per_{object,mesh}_threadgroup. The
descriptor key reads every one.

A compiled mesh pipeline carries MeshPipelineMetalInfo (RenderPipeline::mesh_info), and the
runtime's RenderPipelineState answers Metal's five mesh queries from it, plus the two required
sizes. Each thread limit is the descriptor's maximum, else the function's
[[max_total_threads_per_threadgroup(n)]], else 1024, held to the device's own limit where that is
lower: the task and mesh stages' invocations with VK_EXT_mesh_shader, the compute stage's where
both stages run as compute work. The widths are 32. The grid limit is the descriptor's, else the
object function's [[max_total_threadgroups_per_mesh_grid(n)]], else 2^20, held to
maxMeshWorkGroupTotalCount where mesh functions run natively. Without an object function the
object stage answers 0 and 0, where the M3 Max answers 3 and 32 (an accepted difference).
DeviceProfile::emulates_mesh_shading says how a device runs the stages, so a consumer no longer
copies the compile layer's rule; with the getters, no separate per-stage query is needed.

What Metal refuses is refused as Metal's rule, DescriptorError::MeshPipeline with a
MeshPipelineProblem, measured on the M3 Max (mesh_pipeline_limits.m, plain and under
MTL_DEBUG_LAYER): a required size with an axis of 0, past 1024 threads or past its stage's
maximum, or for an object stage without an object function (process ends); a maximum past 1024,
a function maximum other than the descriptor's, a mesh stage's required size of other threads
than its maximum, and a payload past 16384 bytes (creation errors, codes 3 and 2). An
amplification count of 0 is VertexAmplificationCount, as a render pipeline's; one above 1, which
Metal makes, is NotImplemented(VertexAmplification), recorded in FAST-PATHS' known gaps.

payloadMemoryLength widens the object and mesh functions' payload arena past the declared type
(LoweringInputs::object_payload now reaches the object stage too); an object stage compiled on
its own without it is NeedsInput(ObjectPayload). SEMANTICS_VERSION 1971 and
ARTIFACT_FORMAT_VERSION 488 for that and the new artifact field; the runtime's warm record
format 4 for the descriptor's fields.

Docs: the new_mesh_render_pipeline_state doc now says how each device runs mesh stages, and
what it refuses; API.md's accepted differences gain the mesh pipeline rows. api_signatures
blessed (it also records RuntimeFact::PartialObjectThreadgroups from the partial-threadgroup
commit), api_surface lists MeshPipelineMetalInfo and MeshPipelineProblem, REFUSALS.md,
METAL-COVERAGE.md and CONFORMANCE-COVERAGE.md regenerated.

Tests: engine_mesh's a_mesh_pipeline_answers_metals_mesh_queries_within_the_device and
a_mesh_descriptor_metal_refuses_is_refused_as_its_rule over every committed mesh and
emulating profile; the validation lane's
a_mesh_state_answers_metals_queries_and_refuses_what_metal_refuses on a device. Not yet built:
the next steps are the M3, lavapipe and RTX 5080 runs.

(cherry picked from commit d6934967fad363ca2185c49935204141f253b416)
2026-11-05 17:12:37 -08:00
Anees Iqbal ead2c31249 Run a partial object threadgroup of drawMeshThreads as Metal does
What: a drawMeshThreads with an object function whose threads leave a
partial object threadgroup now draws instead of failing with
NotImplemented(MeshShading). The binder launches the object threadgroups
the threads fill, rounded up, at their whole size, under MultiRegion 1,
with Metal's threads in region[1].xyz and the new flag
lower::dispatch::NONUNIFORM in region[1].w (a folded variant's record
carries it in word 7). An object function whose body holds no workgroup
barrier (lower::mesh::plan_partial_groups, RuntimeFact::
PartialObjectThreadgroups) reads the flag: its threadgroup answers
min(L, threads - group * L) per axis as threads_per_threadgroup and in
its simdgroup counts, its thread position is lin unflattened over that
size, and its invocations past it return before the body. The emulated
wrapper's payload copy strides by the dispatched threads so those
invocations still copy. A body that holds a barrier keeps the uniform
form and its partial draws stay NotImplemented(MeshShading), since the
returned invocations would not reach the barrier (FAST-PATHS known gap).

Why: Metal (M3 Max, macOS 27.0.1) draws these: 6 threads in object
threadgroups of 4 run a threadgroup of 4 and one of 2 whose
threads_per_threadgroup is 2, as dispatchThreads runs a kernel.

Tests: lower::dispatch's partial_object_threadgroups_match_metal (each
Metal thread live once with Metal's builtins, Spec and Flat forms);
the binder's object_draws_specialize_each_stage_within_its_limits (the
flagged region, MultiRegion 1, refused without the fact); engine_mesh's
emulated and native partial draws and
a_partial_object_threadgroup_of_a_body_with_a_barrier_is_not_implemented;
the lane test object_draws_store_metals_words now requires Metal's words
for both Threads rows; the conformance ledger's two partial rows are
removed. SEMANTICS_VERSION 1970. Verification in the following commits'
potluck runs.

(cherry picked from commit 1707d3428bcd641faba462d4c35b13148df83a91)
2026-11-05 17:12:36 -08:00
Anees Iqbal 5080707c8c Document the surface shapes and BC textures the runtime makes
linear_plan.rs gains **Block-compressed surfaces** and **Beyond the
plane's rows** (the probe's measurements and what the runtime holds);
new_texture_with_iosurface_plane names the new shapes and the
SurfacePlaneShape refusal; TexelsPastBufferLength records where the M3
Max puts rows past a surface's end and that the x86 Macs' are
unmeasured; FAST-PATHS.md's known gaps record the refused shapes and
the taller-than-plane divergence on the x86 Macs, which IoSurfacePlane
cannot hold as it carries no plane height. Regenerated docs/REFUSALS.md
and api_signatures.tsv (RuntimeGap::SurfacePlaneShape).

Verified: refusal_surface.py (0 variants without reach or basis);
signatures.py --bless. Rustdoc runs in the next M3 job.

(cherry picked from commit d3bb1dfa2aab94728518529a0b2020da4a3e76aa)
2026-11-05 15:26:47 -08:00
Anees Iqbal d1b5ace93d Keep draws that read textures through the heap, at commit and at a host step
A draw that read the heap (set 1's heap set, the device's texture table or a sampler table) was
never plain (render.rs draw_resident), so no execution of such draws kept a chunk: a host step
of the replayed_textured page (5001 commands, each reading a texture of its own through an
argument buffer) read and recorded all 5001 again at every step.

Now a replayed draw that is plain but for its heap is kept where its set-1 binding is one a
kept recording may bind again (heap_sets::bind's Bound::again):
- the device has descriptorBindingUpdateUnusedWhilePending, so the heap set is the shared
  SetVersion that later writes update in place (heap_sets.rs);
- the draw writes no set elements of its own (a function table's);
- its set holds no shadowed texture, decoded twin or raw read (SetEntry::notes_nothing);
- it reads no sampler table, and its tables bind no texture its heap part reads
  (HeapPart::binds_slot_textures).
A kept chunk holds a Weak of each SetVersion its draws bound (KeptEffects::heaps). Running it
again (KeptEffects::runs_again, heap_sets::bound_again) requires each to be its layout's
current shared version with nothing noted, and pins it for the command buffer as a fresh bind
does (HeapUse::bind_again). RenderKey gains the device's sampler_slots_changed count, so a
sampler state made or released between steps records the kept chunks again. Draws that fall
out are counted by why, new public WorkCounts fields: replayed_heap_draws_unshared,
replayed_heap_draws_writing, replayed_heap_draws_noted, replayed_heap_draws_over_sampler_tables,
replayed_heap_draws_table_textures. The replayed_frames lane prints them.

Images in the heap set rest in GENERAL and its image infos name GENERAL; only an instance's own
attachments move, as for a fresh recording. A kept chunk's run notes the uses its recording
noted (EncoderCore::run_kept), so the tracker orders it after earlier writers as it orders a
fresh recording.

Verified on the M3 Max (MoltenVK 1.4.2), release, the replayed_textured page (5001 commands,
15018 resident buffers), 2 rounds of 3 frames, interleaved, b960f51b05 (this branch's base
before commit 1; it carries the code of bfcfa638ee) against this commit:
- frame 2 (the first step that runs kept chunks): host_step_ms 25.6/26.7 before, 7.4/7.3 now;
  encoding to completion 57.0/57.8 ms before, 38.8/38.3 now; host_step_chunks_kept 0 before,
  20 now (every chunk); records_read 5001 before, 0 now.
- frame 1 (the step that records the chunks apart to keep them): host_step_ms 27.4/28.7
  before, 85.9/83.3 now; encoding to completion 60.1/60.3 ms before, 117.6/116.1 now. Each of
  the 20 chunks recorded apart gathers the page's 5002 resident uses (resident_uses_gathered
  100044, against 5006 inline). It is paid once, at the step that first finds the records
  unchanged.
- frame 0: 99.4/98.5 ms before, 102.9/101.5 now.
- replayed_heap_draws_*: 0 in every frame.

New tests:
- runtime tests::kept_heap_uses (device test): the batches planned for a frame that runs both
  chunks kept hold the same tracked uses (resource, range, read and write stages and accesses)
  as those of the frame that recorded inline, the 512 textures among them
  (CommandBuffer::watch_planned, test-only).
- lane kept_textured (two chunks, validation layer): a host step keeps the heap draws (frame 1
  records apart, frame 2 runs kept, frame 0's pixels; the host then writes every texture's
  texels and frame 3, still kept, draws what a fresh page of those texels draws; where the
  device lacks the feature, every frame records inline and counts every replayed draw unshared);
  a kept draw reads what a blit in an earlier command buffer wrote, on the same queue and on
  another queue (a spinning kernel holds the blit back past the host step); a sampler state made
  between steps records the chunks again; a texture swapped at a token records them again; a
  texture made with a released texture's ID is read by the kept draws.
- replayed_textured's commit-1 test now runs on a device made without
  descriptorBindingUpdateUnusedWhilePending (DeviceOptions::withheld_features), so each command
  buffer binds a heap set of its own and its draws stay not plain: it still covers commit 1's
  hand-back, and now also asserts that no chunk is kept.

Negative controls, each fails its test on the M3:
- plain_drawn set from the old plain rule (no heap draw kept): the keeping test fails;
- run_kept noting none of the recording's uses: tests::kept_heap_uses fails (the kept frame's
  planned uses differ from the inline frame's);
- RenderKey's samplers left out of its equality: the sampler test fails;
- the resident key left out: the token-swap and gone-ID tests fail;
- commit 1's hand-back dropped: the commit-1 test fails at frame 2 (674400 bytes copied).
The pixel test a_kept_heap_draw_reads_what_an_earlier_command_buffer_wrote still passes on the
M3 under the dropped-uses control: there the copies land before the kept draws read them anyway
(expected cause: Metal under MoltenVK orders its tracked textures' writes itself; unaudited).
The structural uses test is the check that fails.

Checks run on the M3: clippy -D warnings with --cfg m2v_gpu over the runtime and validation
crates (all targets, all features); the runtime suite (1659 passed; tests::kept_heap_uses
passed on its own after its hook was keyed right); the residency, draw and notice lanes (248
passed); the kept, step and replayed lanes (62 passed; kept_textured and the commit-1 test run
again after the last test edits, 6 passed); the frame-cost lanes in debug and release (3
passed); the API signature table (blessed for the five fields).

(cherry picked from commit bc717ab533dbc4d36d47f355245857fd0d1fe773)
2026-11-05 11:25:48 -08:00
Anees Iqbal f2fc42a95d Show a command buffer's kernel start only with its end, waiting or not
`kernelStartTime` answered the host time the scheduler began submitting the first batch as soon
as it began, while `kernelEndTime` answered 0 until the last batch was submitted: a start without
an end for as long as the submission took, and for as long as a command buffer that waits for an
event after its first batch waited. Metal shows neither before both. A Swift probe on the M3 Max
under macOS 27.0.1 (a potluck job, committed nowhere) read each command buffer's pair, start
first, from its commit until it completed: 3,900 to 240,000 reads of each of six that waited for
nothing, and 4.6 to 4.7 million over 200 ms of each of eighteen that waited for an
`MTLSharedEvent` the host signalled or an `MTLEvent` another queue's command buffer signalled,
after a blit encoder, before one, or alone. None answered a start and no end. The waiting ones
answered both 0, `Committed`, until 50 to 160 us after the signal, then both; their start was
13 to 39 us after the commit, from before the wait.

`kernel_start_time` now reads `KernelTimes::shown_start`: 0 until the end is stored, the start
then (the end loaded first, acquire; the start is stored before the end on every path). The
scheduler's own reads (whether to begin, a recovery's window, the GPU times' life check) keep the
stored start, `KernelTimes::start`, so no scheduler file changes. Where the first command waits
for the event, the runtime's start is that batch's submission after the signal, where Metal's is
about the commit: recorded among docs/FAST-PATHS.md's known gaps.

The users of the old order move to Metal's semantics:
- rebind_reach's four held-buffer cases waited for `kernel_start_time() != 0` as the sign that
  the batch before the wait was submitted, which now never shows while it waits (they timed out
  at 60 s with 86701a2e00). They wait instead for the device's batches submitted to rise
  (`WorkCounts::batches_with_none_pending` and the three fields after it, which count a batch as
  it is submitted or held, at the place in `submit_batch` where the start was stored), through
  `property_reads::first_batch_submitted`; `walk`'s check that nothing was submitted before the
  event reads the same count.
- property_reads_wait_for_no_submission_and_no_busy_work counted a read inside the submission as
  one that answered a start and no end. A read inside is now one begun after the kernel start
  and returned before the kernel end, on their clock (`host_time`), judged once the end shows
  from the most recent 2^16 reads each thread keeps; and the test asserts that no read of either
  thread answered a start and then no end.
- New: property_reads' kernel_times_show_neither_while_their_command_buffer_waits_for_an_event,
  for both kinds of event: after the batch before the wait was submitted (the count), 50 ms of
  reads answer neither time and `Committed`; after the signal no read answers a start alone, and
  the start lies before the signal, the end after it.
- New: tests::gpu_time::a_kernel_start_shows_with_its_end_alone.

Tests: those above on MoltenVK (M3 Max, --cfg m2v_gpu) and lavapipe (--cfg m2v_cpu_icd); the
negative control is `kernel_start_time` reading the stored start again, under which both
property_reads tests and the unit test fail.

(cherry picked from commit 2ce15a20927a8f7a44c1bc7ee70869977a88d702)
2026-11-05 11:25:47 -08:00