Commit Graph
1530 Commits
Author SHA1 Message Date
Anees Iqbal 74beed3761 Take a texture's ID only once its making cannot be refused
Four makings took the program's texture ID (Texture::made) before a last step that could
still fail:
- Device::texture_as and new_shared_texture: the decoded twin's start.
- Both sparse makings: the tile map's first bytes.
- A heap's texture: its twin's whole decode.
A failure dropped the texture, and with it the ID, so the next ID came out as Metal's. Still,
the ID was held while the step ran, where another thread's making could see it taken. The
pool was also started, so a later reservation was ignored, for a making that returned an error.

Each step now runs on the shared image before the texture is made:
- Image::start_decoded_twin and Image::decode_whole replace the Texture methods.
- Device::start_tile_map takes the image.
On a fresh image, view_shadow::truth is the image itself, so the steps do the same work in
the same order with the image's first moves.

A heap texture's decode now comes before heap.hold_texture and the multisample tile planning.
A decoded twin is never multisampled, and the decode needs neither. What still follows the ID
there fails only on the runtime's own fault (internal). The resource_ids.rs module docs state
the contract: a program's texture takes its ID as its making's last step.

Verified on this M3 Max, through maclock and memcap, with the in-place check fix (the commit
before):
- 151 device tests of the touched families passed idle, among them sparse, heap, heap_tiled,
  twin_reads, twin_flights, bc_own_image, resource_ids and the ID tests. twin_reads' ASTC_4x2
  texture lies in a carrier with a twin on every device.
- The ID tests passed under load x3.
- The runtime's static suite passed (1218 tests). Clippy -D warnings passed, plain and
  --cfg m2v_gpu. Rustdoc -D warnings and the api-signatures check passed.
Not shown: a test where one of these steps fails, since none of them fails on a working device.

(cherry picked from commit cea4dd4b0525e11babce87b899c7791614e28c08)
(cherry picked from commit 8b3fc9ec8b20ff9bc1a81405699eb67bd4224f4a)
2026-11-03 11:48:36 -08:00
Anees Iqbal de7ca47842 Make the in-place check's textures the runtime's own: they take no texture ID
The device's check of the first move in place (in_place_check.rs) runs on its own thread,
m2v-in-place-check. It made each texture through the public Buffer::new_texture at the default
placement, so each one took a plain program texture ID and held it through settle_in_place's
submit and wait. That is 3 page classes x 11 shapes x 3 rounds. The check starts when a texture
over host pages first asks for a verdict. Its verdicts are kept in the shader cache's content
store, keyed by driver, check version and RUNTIME_VERSION, so after a runtime bump the first
process runs the check again while the program goes on making textures.

A program texture made while a check texture held an ID got the next one. In the consumer's
texture_identifiers_are_metals on the M3, the check started at its texture over a surface
(ID 9). Under load its first texture landed between t7 and t8 and held 12, so t8 took 13 where
Metal gives 12, and every ID after it moved by one. The refused format-263 texture just before
t8 took no ID: descriptor.check() refuses it before any ID is taken. A check texture also
started the texture pool, so a program's reservation made after it was ignored ("reserve()
must be called before any allocation takes place").

The fix: Buffer::new_runtime_texture (pub(crate)) makes a texture over a buffer that takes no
ID (IdUse::Runtime). make_texture_over takes Whose::Program or Whose::Runtime, and the public
new_texture, new_linear_texture and surface-plane paths pass Program as before. The in-place
check makes its textures through it.

The tests (device tests, m2v_gpu):
- tests::in_place_check::the_in_place_check_takes_no_texture_id (deterministic). Settle the
  check, reserve texture ID 5, make 5 textures: Metal's IDs are [1, 2, 3, 4, 6].
- tests::in_place_check::texture_ids_keep_metals_order_while_the_in_place_check_runs (the
  race). Make and drop a texture until the check settles; every one must take ID 1.
- tests::internal_texture_ids::the_runtime_s_own_textures_take_no_texture_id (guard). Program
  textures made around a pass of separate depth and stencil textures (combined scratch) and a
  memoryless attachment's pass (kept backing) take 1 to 7 in order.

Verified on this M3 Max, through maclock and memcap:
- The test binary built before the fix, idle, failed both in-place tests:
  - [1, 2, 3, 4, 5] instead of [1, 2, 3, 4, 6].
  - 53981 textures made while the check ran, 325 of them at ID 2 ({1: 53656, 2: 325}).
  - internal_texture_ids passed.
- The same binary under 16 `yes` loops, the race test x3, failed all three: ID 2 for 829,
  868 and 2698 textures.
- The fixed tree passed all 4 in_place_check and internal_texture_ids tests under the same
  load x3. The race test saw only ID 1, for 62779, 54485 and 61885 textures. The deterministic
  test ran the check each time (no "made no texture" skip line).
- The fixed tree passed 151 device tests of the touched families idle (in_place_check,
  internal_texture_ids, resource_ids, sparse, heap, heap_tiled, twin_reads, twin_flights,
  bc_own_image, buffer_texture, in_place, freed_memory, wrapped, texture, surface_two_planes,
  rotated, ycbcr_device, texture_descriptor, kept_images, surface_depth).
- The runtime's static suite passed (1218 tests). Clippy -D warnings passed, plain and
  --cfg m2v_gpu, all targets and features. Rustdoc -D warnings passed. The api-signatures check
  passed (no public item changed).

RUNTIME_VERSION and the runtime-sources pin are not bumped here: that is the owner's step.

(cherry picked from commit bc5421fa54621bdb954cb457fd1e2cbc36b8406e)
(cherry picked from commit 9c75fb477421278b8ea20c50d77bf59d4cc7c318)
2026-11-03 11:48:36 -08:00
Anees Iqbal f7f4e11859 Lend shadow merges that need zeroed scratch too, filling it with zero before each keep
A shadow merge whose kernel reads bytes no copy writes (one not cut to rows of whole words: a
merge through a copy, as for a command that writes a texture's bytes two ways, or one over
several regions) made a new zero buffer of up to three times the texture's bytes for every
merge, held until the command buffer completed. A command buffer of many such encoders so held
one a merge, as the lent scratch of the other merges no longer does (merge_scratch.rs).

Now such a merge takes its scratch as every other does (the command buffer's pool, then the
shadow's spares, else a new one unzeroed) and fills its parts with zero before each keep
(ShadowMerge::record_zero: vkCmdFillBuffer of its parts, then Barrier::everything), on both keep
paths (record_keep and the keep from the staging buffer). The keep's tracked uses include the
fill's write of the parts. A scratch past the device's largest buffer is still a new zero buffer
a part. The shadow's spare is now taken only where the pool lends none (it was taken and
dropped when the pool lent one). WorkCounts::shadow_merge_scratches_zeroed keeps counting these
merges; shadow_merge_scratches_reused counts their loans.

Test (device, --cfg m2v_gpu): tests::merge_scratch::two_ways_merges_take_few_scratches: 64
compute encoders in one command buffer, each writing texel (0, 0) of a shadowed texture over a
Private buffer of padded rows (200 texels in rows of 1024 bytes) and 4 bytes of the same buffer
another way: every merge needs zero, the merges after the first take a lent scratch, encoding
them grows the device's memory by less than an eighth of one scratch a merge, and the bytes hold
both writes of every encoder and every other byte its first.
Passed on the M3 Max (64 zeroed, 63 reused) and on the RTX 5080 Laptop GPU (64 zeroed, 63
reused), with tests::linear_runs and the rest of tests::merge_scratch (8/8 on each). Negative
control (this test against shadow_merge.rs and shadow.rs as before, on the M3): it fails, 64
zeroed and 0 reused. clippy --all-targets --all-features -D warnings, plain and --cfg m2v_gpu.

(cherry picked from commit a543f6428de4c1d6d95a6afa181975b0a1e453ef)
(cherry picked from commit 83d6cb557ed3a464fcb2531a99a3704847ad0313)
2026-11-03 11:48:36 -08:00
Anees Iqbal d1eb2b8ccd Merge a run of passes over one linear attachment once, after its last pass
A linear attachment rendered apart (a texture over a buffer's bytes beside a depth or stencil
attachment on NVIDIA, VK_NV_linear_color_attachment's rule) copied its box into the kept image,
kept it, rendered, and merged the changed words back, every pass, each step between barriers
from every command to every command. A WebGPU frame split at every indexed draw (stencilprobe
-P: 706 passes over one surface in one command buffer) paid that 706 times.

Now consecutive passes over one attachment form a run (linear_run.rs) under a conservative rule:
the run's first pass copies in and keeps as before; each later pass whose box lies in the run's
renders over what the pass before left in the kept image, with no copy in and no keep; and each
pass leaves its merge to its batch's submission (Deferred::LinearMerge, a segment after its own
command buffers), which the next pass of the run takes over, so only the last pass's merge is
recorded, in that pass's place, between the same barriers. The merge compares the first keep
with the image the last pass left, so it writes every word one of the passes changed. Its uses
are noted as each pass ends (EncoderCore::note_left_uses), so the tracker orders later work
after a write of the bytes as before.

A run ends (its merge recorded where its last pass left it, its scratch lent on) at:
- any encoder between its passes but a render encoder (blit, compute, resource state);
- a render encoder whose commands name the surface's buffer or its host range, reach memory they
  do not name (root or handle tables, heaps, executions, a barrier inside the pass), wait for or
  update a fence, resolve, write visibility results, record later (pending draws, tile
  dispatches, later color groups), or that attaches those bytes or renders that kept image;
- an event or semaphore wait or signal, or a host step (any new batch, RunPoint);
- a pass whose box reaches past the run's (the next run then covers the whole render area);
- the command buffer's end.
A pass joins only where it is encoded once: neither its commands nor its attachments name a
buffer over host pages (which a rebind encodes again), no rasterization-rate map, no execution,
outside a predicated loop's laying. An encoder encoded again changes no run, and its linear
merges borrow no scratch from the pool, since its place may lie inside a run's span. The 1x1
attachmentless encoders of stencilprobe -P name nothing of the surface and pass a run.

LinearMerge::lend is now once only (a run's merge is lent when the run ends). Counted:
WorkCounts::linear_merges_recorded and linear_merges_taken_over (new; api_signatures blessed).

Touched pass-end and submission code (kept small): render.rs end_pass (the run decision before
the copies in, the keep skipped for a pass going on, the merge left to submission),
encoder.rs (RecordedSegment::submitted, note_left_uses, encodes_again), command_buffer/submit.rs
record_scrubs (records a run's merge, a taken-over one records nothing), deferred.rs (the
variant), command_buffer/mod.rs (State::run_point, linear_runs), tracker.rs (EncoderUses::fenced).

Tests (device, --cfg m2v_gpu):
- tests::linear_runs (runtime crate, new): one command buffer of 26 steps over a linear target
  (Shared and Private buffers, packed rows of 1024 bytes), the rule forced: passes over it beside
  a cleared depth attachment, 1x1 attachmentless encoders, passes over another texture, a pass
  binding the target's buffer, blits reading its texels mid-sequence, an event signal, and a
  pass whose box reaches past its run's. 17 passes, 7 runs: 7 merges recorded and 10 taken
  over; with a blit between every two encoders (every pass merging after itself) 17 and 0; the
  texels each blit read and those left at the end equal a private texture's under the same
  steps, both ways. Passed on the M3 Max (MoltenVK 1.4.2) and the RTX 5080 Laptop GPU.
- tests::merge_scratch (runtime crate): 240 passes over Shared and Private targets now one run
  each on both devices (1 merge recorded, 239 taken over, one scratch made); texels equal the
  private texture's. Passed on the M3 and the 5080 (8/8 with the next commit's test).
- Negative control (this tree with the run decision off, run_point always None, on the M3):
  both linear_runs tests fail (17 merges recorded, 7 expected) and the three linear
  merge_scratch cases fail (240 recorded).
- runtime_lane::linear_attachments::many_passes_* (validation): assertions moved to runs.
- clippy --all-targets --all-features -D warnings, plain and --cfg m2v_gpu (runtime and
  validation); the runtime's plain unit tests (1213 passed); api_surface and api_signatures.

Measured:
RTX 5080 Laptop GPU (msi-laptop, release, the stencilprobe -P harness: one command buffer, a
clearing pass and 706 passes loading colour and stencil beside a Depth32Float_Stencil8
attachment, a 1x1 attachmentless encoder between them, 1400 encoders; target over a Private
buffer, 1024x1024 BGRA8Unorm, rows 4096; three runs a process; SCHED_OTHER under the GPU locks),
base 896214a5b0 against this commit: commit to completion 81.9, 74.4, 71.2 ms before; 18.1,
11.2, 9.5 ms after (3 runs then 1 run a command buffer: 3 then 1 merge recorded, 703 then 705
taken over); encoding 63.0, 22.5, 21.2 ms before, 50.2, 19.5, 19.1 ms after. The M3 renders
this target in place (no rule), so it has no such passes to measure.

(cherry picked from commit 5d2b237e1a561153b3bcce58c459768e2a83e38a)
(cherry picked from commit 0bf36f1a1cad63fe37da128db30d86580fcd4528)
2026-11-03 11:48:35 -08:00
Anees Iqbal d240b99a7c tests::merge_scratch: put the padded Private rows case back, its texels laid out as the reference's
The case of a Private buffer whose rows hold bytes between them (200 texels in rows of 1024
bytes) was dropped from 6fa0708f5e as a runtime bug the base shared: after 240 passes 8800 (M3)
and 10516 (RTX 5080) of its 76800 texel bytes differed from a private texture's. The fault was
the test's: its first bytes were a pattern of each byte's place in the buffer, so a target with
bytes between its rows started with other texels than the reference, whose rows are packed;
blending at alpha 0.5 hid the difference wherever enough passes covered a texel. The pattern is
now of each texel byte's place among the texels, the same in any rows, and the bytes between
the rows hold 0xa5 again, checked unchanged after the passes.

What the runtime does there (the RTX 5080, a scratch experiment against a private texture,
pattern by texel): the texture is a shadow on every device (an image over the rows would hold
the bytes between them), copied back rather than merged (a tracked Private buffer's bytes have
no other writer): 19200 texels copied in once, 19200 copied back each pass; with 1, 2, 3 and
240 passes, with and without a depth attachment, in one command buffer or one each, over a
Private buffer or a Shared one (merged back there): 0 texel bytes differ, 0 bytes between the
rows change. The copies move the texels' rows alone, never the bytes between them.

Verified: tests::merge_scratch (--cfg m2v_gpu) on the RTX 5080, 5 of 5, the padded case among
them; clippy -p metal2vulkan-runtime --all-targets --all-features -D warnings with
--cfg m2v_gpu.

(cherry picked from commit 896214a5b05a652cbf9ae49fae1c2f44f2b0dc3b)
(cherry picked from commit f296b0eef66b3663f1901d09a0f4fb72f87ed282)
2026-11-03 11:48:35 -08:00
Anees Iqbal f73718882a Re-bless the conformance cost records on the M3 Max at 13a5607aff, with timing for the four Accumulate cases
Measured on the M3 Max (macOS 27.0.1, MoltenVK 1.4.2), with a debug build of 13a5607aff's tree,
under one maclock hold:
- cost --runs 8 --write over the whole set: 1127 cases, 1118 measured, and the same 9 the venue
  cannot measure, each stopping where its committed record says.
- cost --runs 8 --alone --write over the 331 cases newly covered, newly bounded or moved. Most of
  them moved only in counts the race rule names (scheduler_*, object_churn.*, wakes_*).
- times --runs 8 --write over visibility-counting-accumulate,
  visibility-counting-accumulate-one-command-buffer, visibility-counting-accumulate-revisit and
  visibility-boolean-accumulate. On time, visibility-boolean-accumulate is unmeasured: our leg
  announces metal2vulkan-degrade-device-boolean-visibility.

Against 13a5607aff's records, by cost::drift on the M3 venue: 38 differences over 15 cases,
plus 4 cases newly covered (the four Accumulate cases).
- 18 gated bounds: 16 fell, 2 rose.
- 14 counts the gate gives up.
- 6 counts it takes on.
- No ceiling or per-state ratio moved.

The gated bounds:
- Fell, 34e44e3a12 (Boolean results without the resolve): visibility-boolean-indirect-no-instances,
  -occluded, -offsets, -revisit-after-covering and -revisit-after-nothing, and
  visibility-counting-offsets. Their cmd_bind_pipeline and cmd_bind_descriptor_sets fall
  (offsets 4 -> 2, the others by 1). In the two revisit cases, cmd_dispatch 2 -> 1 and
  owned_descriptor_pools 2 -> 1.
- Rose, required by 9f47ebcf00: host-page-writes-visibility-read-only and -writable,
  replay_log_bytes 1488 -> 1496. A kept render log counts size_of::<RenderPassDescriptor>()
  (render/replay.rs, RenderLog::bytes), and the descriptor gained visibility_result_type, a
  one-byte enum padded to one more 8-byte word. Each case keeps one render log. No other commit
  in 2b55ab415e..13a5607aff touches render_pass.rs.

The three mesh cases withheld at 2b55ab415e, indirect-mesh-commands-object-threadgroup-lengths,
mesh-commands-unordered-draws and mesh-commands-own-state, are written here. With
2a23d1882c, their gated counts read as their committed records do, from before 922caf3199. The
counts the gate takes on are theirs (heap_tables_worked_out, resident_resources_joined).

Withheld: indirect-render-commands-inherited-state keeps its committed file whole. Its rise is
922caf3199's chunk contexts (arena_pools_made 1 -> 3, argument_objects_retained 2 -> 6,
argument_tables_retained 1 -> 3), and stays visible until that execution records apart only
from its second unchanged run.

cost --runs 8 --check over the whole set on these files exits 1. Its 3 gated differences are
exactly inherited-state's three, and nothing else is load-bearing. The reach is 4 counts given up
and 2 taken on: inherited-state's two new counters, and four racy counts dropped from gating at an
equal value (visibility-counting-accumulate batches_submitted_by_waiters,
detach-in-a-completed-handler memory_frees.blocks and .host_import, fresh-pattern-70
gate_waits_slept).

(cherry picked from commit 3b60c7e185156f42471fe6e1fb30910ebe9f8c5b)
2026-11-03 11:08:03 -08:00
Anees Iqbal 64b07293af Pin the runtime sources after visibility results, mesh chunks, cross-queue completion and the step-2 fix
SEMANTICS 1957 and RUNTIME 1756 say what changed. Hash from the pin derivation over the listed
runtime and translator sources.

(cherry picked from commit 13a5607affadf1c83a6562ae619faeb1e041ce72)
2026-11-03 11:08:03 -08:00
Anees Iqbal e346a8f7f5 Bump SEMANTICS_VERSION to 1957 and RUNTIME_VERSION to 1756: visibility results, mesh chunks, cross-queue completion
- SEMANTICS 1957: the binder's visibility combine module's words change (Boolean results are the
  device's nonzero query result with no resolve; Accumulate takes the buffer's words in, Counting
  in their low 32 bits as the M3 does), and the Boolean result is a new precision notice.
- RUNTIME 1756: visibilityResultType is built; a buffer of mesh or patch draws alone keeps no
  chunk; a command buffer that waited on another queue's GPU signal completes after that queue's
  command buffer.

Stacking note: the cross-queue measurement commit met checks at commit's --checked flag in the
submit_path example (its usage line and imports); both are kept. The draw path's step-2 fix is
pin-only.

(cherry picked from commit 9e1ccf432beacdea484c8797a530d0707fb78e62)
2026-11-03 11:08:03 -08:00
Anees Iqbal 0b7aba796c Measure cross-queue completion order and latency in submit_path
What: submit_path gains a `cross` mode. Command buffer A on one queue signals an event at its end
and command buffer B on a second queue waits for it on the GPU. The mode prints A's commit to
A's handler and to B's handler (p50, p90, p99), and how many of 2000 rounds ran B's handler
before A's. It covers shared and plain events, completed or completion-seen handlers
(`--seen`), and gaps of 0 and 2000 us between rounds.

Why: it measures the completion order the previous commit fixes, and its cost, on any device
the example runs on.

Verified on the M3 under MoltenVK 1.4.2: it ran before and after the fix, two pairs each.
Before, 3/2000 rounds ran B's handler first (plain events, 2 ms gap); after, 0. The latencies
are in the previous commit's message.

(cherry picked from commit 521479bb0bf6324131f4fcf0fe9519b84d011160)
(cherry picked from commit 85c5343c65375ef437ff17bb5328bda381cc1438)
2026-11-03 11:08:03 -08:00
Anees Iqbal 30deedf1d1 Complete a command buffer after the other queue's one whose GPU signal it waited for
What: a command buffer B whose work waits on the GPU, through an event, for a signal that
command buffer A of another queue keeps at its end now never completes ahead of A. Its status,
its completion-seen handlers and its completed handlers come after A's, as Metal's completion
follows the GPU's.

Why: on the M3 under MoltenVK, reims saw B's completion handler run before A's in 20 of 20 runs
(Metal: A first, 8 of 8). There were three causes, the first by far the most frequent:
- A's and B's transitions were posted to two handler-pool threads, so B's could finish first.
- B's transition ran on the waiter while A's was still posted.
- The completion turns took B's batch before A's: the takes ran in queue-index order, or B's
  waiter turned first.

How:
- Take order (completion.rs): a batch lists the other queues' batches whose kept GPU signals met
  its waits and were unfinished when it was submitted (`Submitted::after`, through
  `EventTimeline::signallers`). The completion turns take it only after those. The test is per
  front batch, O(1) where nothing is listed. Counter: `batches_held_for_another_queue`.
- Transition order (follow.rs, contexts/lines.rs): A carries a `Follow` that the events hold beside
  its kept signals. Where A's transition leads its context (it was posted and nothing there runs
  before it), B's transition is posted behind a gate in its own context, keeping its place. The
  gate opens once A's transition has its status final and has run its completion-seen handlers,
  which never block. While waiting, B holds no thread. Where A's transition is behind any other
  item, B goes on: a blocked handler of A's queue does not hold back another queue, as with Metal.
  Counter: `command_buffers_completed_after_another_queue`.
- A `Follow` names its command buffer by address alone, so the waiter never holds A's last
  reference, nor the device's.
- No new lock on the completion path: the gate check takes the context lock only for a command
  buffer that waited for another queue's kept signal.

Verified on the M3 (MoltenVK 1.4.2):
- New device test `completion_order` (50 rounds per shape, over shared and plain events, both
  queue orders and five handler shapes). It asserts that A is Completed when B's handlers run and
  when B's wait returns, and that A's handlers come first. A second test checks that a blocked
  handler on A's queue holds back A and not B.
- Fixed tree: 12 of 12 runs passed both tests. Counters per run: held 0 to 3, completed after
  1 to 10.
- Negative controls, 2 runs each:
  - the gate off: failed with status and seen-order breaks;
  - the take order off: failed with status breaks;
  - both off: failed.
- Device-free: runtime and conformance suites 2225/2225; api_signatures, fast_paths and
  api_surface pass. clippy is clean (plain and --cfg m2v_gpu). The private rustdoc count stays at
  its ceiling of 70.
- Latency, submit_path on the M3, two base/fixed pairs: single-queue commit-to-handler p50 at
  gap 0 is 205-239 us before and 245 us after (completed), 199-206 before and 235-239 after
  (seen); the pairs overlap and swap at gap 2000 (607/605 before, 628/564 after).
- Cross-queue, A's commit to B's handler p50 at gap 0: shared 405-482 us before, 506-558 after
  (A's handler itself moved alike, 212-254 to 265-295); plain 364-375 before, 346-350 after.
- B ahead of A in that probe: 3/2000 twice before (plain events, 2 ms gap), 0 after.
- Not run on NVIDIA: the 5080 had a VM running at every check.

(cherry picked from commit dc164b7608a184420aef1a4d5573218a5c4b0466)
(cherry picked from commit 53f6f039d0d8b7cefee48c800cd4b90f43c50d57)
2026-11-03 11:08:02 -08:00
Anees Iqbal 7148b9518f host_ab: draw_host, each draw's vertex buffer bound at the next 256 bytes of no-copy host chunks
The encode workload gains a variant over the buffer kind a guest's setVertexBytes: reaches the
runtime through: no-copy buffers of 64 KiB over host pages (one mapping, a buffer a chunk, 256
draws' rectangles each), each draw binding the chunk its rectangle lies in at its offset
(setVertexBuffer:offset:atIndex:), as reims-vgpu's draws.10k measurement does. The other variants
draw as before (encode_draws takes the chunks, empty for them).

Verified: clippy over host_ab, all features. Run on the RTX 5080 Laptop GPU at the lane base and at
the draw path's step 4 (one run each, 3000 and 9000 draws a pass, encode us a draw): draw_host
0.642 / 0.617 and 0.584 / 0.528, draw_offset 0.536 / 0.532 and 0.490 / 0.516.

(cherry picked from commit 691332c6c3076d78b68abed22960227d3c220e27)
(cherry picked from commit 07145d5cfde93f81acf46fe8ae84e306cd2760ae)
2026-11-03 11:08:02 -08:00
Anees Iqbal 32b1920f21 Work a buffer use's access out at its callers, with bytes_use infallible and inline
Step 2 (patching a rebound draw's buffer uses in place) moved the making of one buffer use into
binding::bytes_use, which command_uses_into calls for each buffer use of every draw that takes
every step, and which returned a Result: it worked out the use's access flags from its class
(fallibly) and checked its source index's width per use. On the 5080 the shapes that never take
the patch read slower after step 2 in two A/Bs (bind 0.848 -> 0.884 and 0.960 -> 1.014 us a draw,
compositor 1.089 -> 1.127 and 1.207 -> 1.266, medians of 6 samples each, wide ranges).

bytes_use now takes the use's reads and writes as its callers work them out and returns the use:
command_uses_into works the access out from the class as before every step did, and
patch_buffer_uses keeps the accesses of the use it patches, which its class made. The source
index's width is checked once a command, for its whole count of uses, where it was checked per
use. The uses made are the same.

Measured. M3 Max, whole-process instructions a draw (two runs of 3000 and 9000 draws a pass, 23
passes each), step 1 / step 2 / step 2 with this: bind 16601 / 16882 / 16338, compositor 19039 /
18466 / 18852, offset 12430 / 11940 / 11871: mixed signs within about 600, so no cost of step 2 on
those shapes stands out of the noise there, nor any gain of this. 5080, interleaved A/B of 6
samples in 2 exclusive holds, us a draw, median (range): bind 0.960 (0.871-1.406) / 1.014
(0.908-2.585) / 0.988 (0.909-1.790), compositor 1.207 (1.133-3.339) / 1.266 (1.190-2.271) / 1.258
(1.168-2.254), offset 0.629 / 0.616 / 0.602. The 5080's main-thread perf counts spread too far to
read (offset 11770 to 21885 instructions a draw across binaries whose encode times sit within
0.05 us). A neutral change, kept as correct and built.

Verified on the M3 Max (MoltenVK 1.4.2), --cfg m2v_gpu, with debug assertions, on step 4's tree
with this: the runtime's whole suite, 1551 of 1551; the validation crate's runtime lanes
frame_costs, draw_* and render, all passing; clippy over the workspace at --cfg m2v_gpu.

(cherry picked from commit f44082d4e309bbc18e5cdac3cb232b560c7134a6)
(cherry picked from commit a087c926bcf9f250436db564d1645ff122f9c560)
2026-11-03 11:08:02 -08:00
Anees Iqbal 12f58a227f Keep no chunk of a buffer of mesh or patch draws alone: none of their draws is plain
922caf3199 records an execution of commands the CPU encoded chunk by chunk, each chunk
apart from a KeptContext of its own (a command pool, descriptor arena and uploads), and
keeps a chunk whose draws are all plain. A mesh draw and a patch draw are never plain
(render/executions.rs clears RenderLowering::replay_plain for both), so on a buffer whose
command types hold neither DRAW nor DRAW_INDEXED every chunk recorded apart was found not
plain, noted, and its execution finished through the apart encoder. That cost a command
pool and two more primaries, each with a barrier, on the first execution, and kept
nothing. RenderExecution::keeping now admits only a buffer whose command types intersect
DRAW | DRAW_INDEXED (the test settle already makes). A buffer of mesh or patch draws
alone records as it did before 922caf3199. A buffer that mixes them with draws of
primitives keeps today's path. docs/FAST-PATHS.md's known gap lists the buffers that
still record at every commit.

Runtime behaviour: such a buffer's executions record no chunk apart. An execution of a
chunk of resets alone on one of them, which draws nothing, is no longer kept either.

The cost gate showed the redundant work as three conformance rises, now withheld in the
records, all from 922caf3199. Each case measured alone, debug, M3 Max, over 8 runs:
- indirect-mesh-commands-object-threadgroup-lengths: command_buffers_begun 11 -> 9,
  continuations 3 -> 1, submitted 8 -> 6, cmd_pipeline_barrier 14 -> 12,
  end_command_buffer 11 -> 9, encoder_command_buffers_begun 9 -> 7.
- mesh-commands-unordered-draws: 9 -> 7, 3 -> 1, 6 -> 4, 11 -> 9, 9 -> 7, 8 -> 6.
- mesh-commands-own-state: 10 -> 8, 3 -> 1, 7 -> 5, 13 -> 11, 10 -> 8, 8 -> 6.
command_pools_made fell 2 -> 1 in each. Every gated count equals its value at
c00efdc7c0, 922caf3199's parent. The remaining differences are scheduler_sleeps,
scheduler_wakes_host and submit_stalls_on_work, which the race rule names.

Test: runtime_lane::mesh_commands::a_buffer_of_mesh_draws_alone_records_no_chunk_apart
executes the CPU's own commands on a buffer of both mesh kinds twice, after another
buffer's execution. It asserts the first execution begins as many command buffers as
the second, and that both draw Metal's words. Verified on the M3 Max (--cfg m2v_gpu):
it passes with the fix, and fails without it (left 9, right 7). own_commands_draw_metals_words,
which now shares encode_own, passes. clippy -D warnings, all targets and features, with
--cfg m2v_gpu, is clean for metal2vulkan-runtime and metal2vulkan-validation.

RUNTIME_VERSION and the runtime-sources pin are left to the stack.

(cherry picked from commit 132d0aeea055b9a3819c82619a12e3c4adf32646)
(cherry picked from commit 2a23d1882ceb4cd21506af2a66f92f8258b5b2b2)
2026-11-03 11:08:02 -08:00
Anees Iqbal 61a9508e92 Build visibilityResultType: Accumulate takes a pass's results into the buffer's words
RenderPassDescriptor gains visibility_result_type (MTLVisibilityResultType: Reset, the default
and today's behaviour, and Accumulate). Under Accumulate no query result is copied over its
offset's word: every query of an offset, the first one too, is copied into the upload region the
continuations already use, and the crate-owned combine takes them into the word as the buffer
holds it. The combine already loaded the destination word as its accumulator, so Accumulate is
the first query becoming one more source. A `Boolean` word ORs the device's results in; a
`Counting` word is summed in through a new table mode of the combine, into the word's low 32 bits
alone, wrapping there, its high 32 bits kept (ContinuedResult::low_half / in_low_half). That last
part is what the M3 Max answered when recorded: 0xffff_fff8 plus 16 samples writes 8, and
0xffff_ffff_ffff_fff8 plus 16 writes 0xffff_ffff_0000_0008. A plain 64-bit sum was divergent there.
An offset set with no draw after it keeps its word, because a query with no draw adds 0. Where a
no-copy buffer's bytes start off a multiple of 8, so the results land in an upload region, the
words are now copied into that region before the combine (Landing::inward). Reset records exactly
what it did before.

Conformance: RenderPass gains visibility_type (typed()), and words() appends it only where it is
not Reset, so existing fingerprints read as before. Both sides set it. There are four new
visibility cases, recorded on the M3 Max (macOS 27.0.1): visibility-counting-accumulate (two
command buffers; words 100/5/7/0xffff_fff8/u64::MAX-7), visibility-counting-accumulate-one-command-buffer
(two passes in one command buffer, read once), visibility-counting-accumulate-revisit, and
visibility-boolean-accumulate (words 0/2/3 under covering and non-covering draws, an offset set
with no draw, then a second command buffer). The family's acts key states the type, and a joined
shape adds a command-buffer input. Cost and timing records for the new cases are not written here.

Lane tests (runtime_lane): accumulated_counts_add_to_the_words,
accumulated_booleans_or_into_the_words, and
host_bytes::accumulated_visibility_results_land_where_their_bytes_lie. Unit tests: the combine's
accumulated_counts_are_summed_into_the_low_half, its plan's table mode, and the type's raw values.

Coverage: coverage.tsv marks MTLRenderPassDescriptor.visibilityResultType implemented (its unused
"visibility" group is removed), and METAL-COVERAGE.md is regenerated. MTLVisibilityResultType joins
the enum table, so metal_enumerators.tsv and CONFORMANCE-COVERAGE.md are regenerated. The API
signatures are re-blessed. REFUSALS.md is regenerated: VisibilityResultType::from_raw is one more
UndefinedValue site. The regeneration also picks up two bind/graphics.rs sites the committed file
was missing. The degrade docs (landed results, Boolean) state Accumulate.

Verified on the M3 Max under MoltenVK 1.4.2:
- The 52 visibility-touching lane tests pass: visibility, host_bytes, depth_never, amplified_draws,
  degrade_notices and the framebuffer_fetch split pass.
- The visibility family's replay is all announced (no divergence), after the low-half change.
- Negative control with Accumulate forced to Reset: all three Accumulate lane tests fail, and all
  four new cases replay divergent.
- Negative control with no inward copy: the landing test fails at 4 bytes past a page (2 read 0,
  100 read 16).
- Before the low-half change, visibility-counting-accumulate replayed divergent at words 3 and 4.
- The combine's low-half test fails on the interpreter without the high-half select ([8, 1] for
  [8, 0]).
clippy (plain and --cfg m2v_gpu), rustdoc and scripts/api-docs are clean.

SEMANTICS_VERSION: no translated shader changes, but the owned combine module's words do
(main's call). RUNTIME_VERSION and the runtime-sources pin are not touched here.

(cherry picked from commit 1c172968ad6492cebcae2a568fc99e90565d4d11)
(cherry picked from commit 9f47ebcf006920f7561a16a77f77e422de7201c1)
2026-11-03 11:08:01 -08:00
Anees Iqbal d806c0a792 Write Boolean visibility results as the device's nonzero query result, without the resolve
Metal's Boolean visibility result is nonzero where any sample passed and 0 otherwise. The
Apple M3 Max writes 1; Metal on the AMD Radeon Pro 5300M and the Intel UHD Graphics 630
(macOS 26.7.1, the reims-vgpu team's probes) writes the samples that passed. The runtime
had a crate-owned dispatch (bind::visibility_resolve_module) after every pass with a
Boolean offset whose only job was to rewrite that word to exactly 1. Under AGENTS.md rule
1 the device's native answer is the only form: a Boolean result is now the imprecise
occlusion query's own result, which Vulkan states as "When any samples are passed,
boolean queries will return a non-zero result value, otherwise a result value of zero is
returned" (occlusionQueryPrecise). Across a split pass's render pass instances the
combine still ORs the continuations, so zero stays zero exactly where no instance passed
a sample. Counting queries stay precise.

- Runtime: the resolve's plan, uploads, sets and dispatch are gone from visibility.rs, and
  OwnedModule::VisibilityResolve from owned_kernel.rs. A pass with no continuation now
  records only vkCmdCopyQueryPoolResults. The combine's in-place words are declared as
  shader reads and writes for every combined offset (they were declared only for Boolean
  ones). A new precision degradation, DeviceBooleanVisibility
  (device-boolean-visibility), is announced where a pass's Boolean results record; its
  catalogue entry is in docs/API.md section 9 and a device-gaps row in docs/FAST-PATHS.md,
  as for the other native-answer kinds.
- Translator: bind/visibility_resolve.rs and its tests are deleted (VisibilityResolve,
  VisibilityResolveModule, visibility_resolve_module leave the public surface). Its
  shared helpers (windows, words_buffer, u32_value) move into visibility_combine.rs; the
  combine's plan tests take the two refusal cases only the resolve's tests held. No
  translation output changes.
- Conformance: a new Loosening::Nonzero, and an allowance may name one element of a byte
  region as <site>/<byte offset>. The visibility family loosens each Boolean result's word,
  and only that word, by Nonzero, justified by device-boolean-visibility, which its Boolean
  cases also declare at the notices site. Every other word still compares exactly. No
  recording changes. README and docs/CONFORMANCE-COVERAGE.md (regenerated) say so.
- Validation lane: every Boolean expectation reads the word by its contract
  (visibility::by_contract: nonzero and not the buffer's starting word reads as 1), in
  visibility, framebuffer_fetch, host_bytes, depth_never and amplified_draws; the notice
  is a new lane site (visibility::BOOLEANS) taken by
  boolean_results_announce_the_device_s_value and expected where other tests' notice sets
  are exact. boolean_results_are_copied_with_no_dispatch counts one query result copy and
  no vkCmdDispatch for a pass of two Boolean offsets.

Verified: cargo clippy --workspace --all-targets --all-features -D warnings with
--cfg m2v_gpu; the runtime's degradation catalogue and site tests, the translator's
combine, owned-division, resolve-helper users', api_surface and api_signatures tests;
the conformance suite's 1024 device-free tests. The device lane tests run on the M3 with
the next step.

(cherry picked from commit a4976cdc3734c21c1b9ed4cf603bbf6bab2523f0)
(cherry picked from commit 34e44e3a12a46e6ff4b651cc4689002690d680fc)
2026-11-03 11:08:01 -08:00
Anees Iqbal b78025a08a Pin the runtime sources after the host RAM imported ahead and the draw path's steps
RUNTIME_VERSION 1755 says the host RAM's behaviour changed; the draw path's steps change how
the runtime works out the same commands. Hash from the pin derivation over the listed runtime and
translator sources.

(cherry picked from commit e3444f32738ecd626ed6a46545ef693e18fd4117)
2026-11-03 10:11:06 -08:00
Anees Iqbal 3868162ee4 Bump RUNTIME_VERSION to 1755: a used host RAM's chunks are imported ahead
use_host_ram starts a device thread that imports every 64 MiB chunk of the RAM ahead of use, so
an object made over it no longer imports its chunk on the making thread
(WorkCounts::host_ram_chunks_imported_ahead). The draw path's steps in this stack (owned count
shards, buffer uses patched in place, push writes pointing at their own info, rebinds without the
command buffer's state lock, the lean recorder thunk) record and submit the same commands, uses
and barriers, and need only the pin.

(cherry picked from commit 89deb7f630984d8c296573c9f19ce51e57113a3a)
2026-11-03 10:11:05 -08:00
Anees Iqbal 68f095f652 Count a recorder command into the shard its thread holds, with no call in the thunk
Each recorder thunk looked its thread's shard up through a thread-local with a destructor (the
one that gives the shard back), so the lookup checked the thread-local's state and, at a
thread's first count, registered the destructor and took a shard inline. Those calls made every
thunk save the command's arguments to the stack and restore them before handing on to the
driver's command, at every command recorded (on the M3 Max: five register pairs saved and
restored, twelve moves, in vkCmdPushDescriptorSet's thunk).

The shard index now lives in a thread-local of its own with no destructor, which costs a load
to read; the destructor lives in a second thread-local, touched once, as the thread takes its
shard (shards::first_shard, out of line), and it hands the thread's later counts to the shared
shard as it gives the shard back. A thunk counts into the shard its thread holds and takes none
(shards::held): a thread's commands before its first other count (a draw's, which takes its
shard) go to the shared shard, by an atomic add. The thunk is then as short as before step 1's
owned shards, with a load and a store where it had an atomic add.

tests::recorder_shards::a_thread_holds_the_shared_shard_until_it_takes_its_own checks that a
thread that took none holds the shared shard, that holding takes none, and that a thread that
took its own holds it. The api_signatures table is blessed again for the commands! macro body.

Verified: on the M3 Max, the release thunk's disassembly (no saves, one tail call). The runtime's
shard tests, plain; clippy over the runtime, plain; signatures.py --check after the bless. On the
M3 Max, --cfg m2v_gpu, with debug assertions: the runtime's whole suite, 1551 of 1552; the one
failure, tests::draw_again::draws_after_texture_and_sampler_changes_rebind_what_every_step_binds,
counted one begin_command_buffer more in one run's window than the other's; it then passed in
each of 15 reruns of tests::draw_again's 8 tests (its cause unaudited). The
validation crate's runtime lanes frame_costs, draw_* and render: 106 of 106.

5080 (msi), interleaved A/B of 6 samples against the step before: a tie (static 0.058 against
0.054 us a draw, offset 0.458 against 0.464, bind 0.818 against 0.811, compositor 1.047 against
1.055; the medians within 8 ns, each pair's ranges overlapping).

(cherry picked from commit 2d28f3aa1fb31c60032947d978e905472aa62820)
(cherry picked from commit 6d251e5b526ba39d711f9a7c311dec2de673ea7f)
2026-11-03 10:11:05 -08:00
Anees Iqbal d6731732dd Rebind a draw's buffer slots without locking its command buffer's state
A draw rebound locked its command buffer's state (CommandBuffer::state) to rewrite set 0's
buffer descriptors, as binding::descriptor takes the state for the sources that upload bytes.
The command buffer's encoders on other threads share that lock, and the 5080 profile put about
2.6% of a rebound draw in it. The rebind rewrites only slots' descriptors: a buffer slot's
buffer, or the call's copy of a slot's bytes, neither of which uploads.

binding::slot_descriptor now makes those two descriptors from the command's planned range alone
(planned_range and in_space, shared with binding::descriptor, which takes them first), and
rebind_into takes no state: a draw rebound locks none. In builds with debug assertions,
CommandBuffer::state counts its locks on the locking thread (command_buffer::state_locks), and
tests::shared_draw_locks::draws_rebound_at_another_offset_lock_no_command_buffer_state draws a
rectangle at another offset of its vertex buffer 8 times and asserts that every draw counted
rebound (WorkCounts::draws_rebound) locked no command buffer's state.

Verified so far: clippy over the runtime, plain and --cfg m2v_gpu. Its run on the M3 Max (the
runtime's whole suite and the validation crate's runtime lanes) and its negative control (a
state lock put back into the rebind, so the new test should fail) are pending.

5080: expected faster on the rebound shapes; the interleaved A/B is pending.
(cherry picked from commit a77b2629c6e5c9a0cda65332f1cacca29c4255da)
(cherry picked from commit 49dd6820c6de412a7b3c744569c63390a1fbbbd3)
2026-11-03 10:11:05 -08:00
Anees Iqbal d21d960cb1 Point a push's raw descriptor writes at each write's own info
binding::push_set copied each pushed write's info into one of three 16-entry arrays (buffer
infos, image infos, texel views), zeroed whole first with a 16-entry array of raw writes, and
pointed each raw write at its copy: about 1.9 KB zeroed and filled at every push of set 0, of a
draw or a dispatch. write_sets did the same for each 16 writes it hands vkUpdateDescriptorSets.

A raw write now points at the info its write holds where it lies (Info::written, SetWrite::raw):
the infos are copied nowhere. The raw writes sit on the stack uninitialised past those written
(binding::fill_raw), and only those are handed over; past 16, push_set collects them on the heap
as before. Vulkan reads the infos during the call, while the writes they lie in live. The same
descriptors reach the same commands.

tests::push_raw_writes asserts it: of a buffer, an image and a texel write, each raw write is at
its binding, element and type with one descriptor, and points at its own write's info (by
address), and as many raw writes as writes are handed over.

Verified on the M3 Max (MoltenVK 1.4.2), --cfg m2v_gpu, with debug assertions: the runtime's
whole suite, 1550 of 1550; the validation crate's runtime lanes (frame_costs, render, draw_*,
compute, dispatch, tile, hazards, sync_coverage, shadows, attachments, executions,
degrade_notices, push, descriptor, argument), 343 of 343. Clippy over the runtime, plain and
--cfg m2v_gpu; signatures.py --check.

5080: expected faster at every push; the interleaved A/B is pending. Single lock holds read
0.483-0.502 us a draw on the offset shape with the steps before.

(cherry picked from commit ecb9682fd1384d7d09dfc5d7634b052ddeb4a7e8)
(cherry picked from commit 2d224ab1674e199de10900876e8257a79fa3602e)
2026-11-03 10:11:05 -08:00
Anees Iqbal 698988bdde Patch a rebound draw's buffer uses in place where only offsets moved
A draw rebound after buffer binds made its uses again whole (binding::command_uses_into): every
use of every slot, texture and resource, and the attachment checks of the texture uses
(render_target::shares_attachment). Where only buffer slots changed and each still binds the
buffer it bound (its offset may have moved), only those slots' uses can differ.

command_uses_into now records, for each use it makes, the index of the plan's or command's
resource use it was made of (CommandUses::sources). binding::patch_buffer_uses rewrites in
place the uses of the changed buffer slots, as bytes_use (factored out of the builder) makes
them for the slot's buffer and offset now. It declines, and the draw makes its uses whole as
before, where any changed slot is unbound or binds another buffer, where a use was added after
the builder (its sources no longer match), or where a texture or sampler slot changed. Every
other use is of a slot, buffer or texture no call changed, so the uses, and the keys the
resident set reaches, are those command_uses_into makes, and the tracker sees the same uses and
ranges: the same barriers.

Verified on the M3 Max (MoltenVK 1.4.2), --cfg m2v_gpu, with debug assertions, where the first
rebound draw of a kept draw and every second after it take every step and compare the uses by
digest: the runtime's whole suite, 1549 of 1549; the validation crate's runtime lanes
(frame_costs, render, draw_*, hazards, sync_coverage, shadows, attachments, executions,
degrade_notices), 292 of 292. Negative control (the patch skipping its rewrite, so the debug
check should report other uses): built, its run pending. Clippy over the workspace, plain and
--cfg m2v_gpu.

5080: expected faster on the offset shape; the interleaved A/B is pending. Single lock holds read
0.548-0.567 us a draw on the offset shape with the step before.

(cherry picked from commit 678ded926bd21c1b52ecb693b7a6f5664500e017)
(cherry picked from commit e11f9719d9bb500bf346cd5d2077788059011cc3)
2026-11-03 10:11:05 -08:00
Anees Iqbal ac42123ade Own the count shards: a thread's adds are a load and a store, no locked add
The draw and recorder counts (shards.rs) each kept 16 shards, and a thread took shard
(n mod 16) at its first count, so two threads could share one, and every add was an atomic
fetch_add: a locked read-modify-write on x86 at every count. The 5080 profile of a rebound draw
put about 6% of it in those adds (three thread-local lookups and five to seven locked adds a
draw).

A thread now owns its shard while it lives. At its first count it takes the lowest free one of
16 (a bitmask, by compare-exchange with acquire ordering) and gives it back as it ends (its
thread-local's destructor, with release ordering). Only its owner writes a shard, so the owner's
add is a plain load and store. The threads past 16, and a thread counting after its
thread-locals ended, share a 17th shard by fetch_add. The counts a thread leaves in its shard
survive its exit: the next owner adds on top of them, and a sum reads each shard's count as
stored, so a hand-over moves no count and a reader sees none lost or doubled. A draw rebound adds
all its counts into one shard lookup (Counters::draw_rebound now takes the states and writes it
pushed), and the recorder's command thunks look their shard up once.

The api_signatures table is blessed again: the body of the commands! macro, which the thunks
come from, changed. No item a consumer calls changed.

Verified on the M3 Max (MoltenVK 1.4.2), --cfg m2v_gpu, with debug assertions:
tests::recorder_shards (threads own distinct shards while they live, and a new thread takes one
again; 19 threads x 100000 adds sum exactly; a reader summing through 40 rounds of 19 threads'
hand-overs sees every sum monotone and at most the total, and the final sum exact), with
tests::draw_again, shared_draw_locks, recorder, draw_shape_notices and exit_guard, 58 of 58; the
validation crate's runtime lanes frame_costs and draw_*, 36 of 36. Negative control: with the
shared shard also added to by a plain load and store, the 19-thread sum test fails (additions
lost). Clippy
over the workspace, plain and --cfg m2v_gpu; signatures.py --check.

5080 (msi, SCHED_OTHER): expected faster than the landed shards; the interleaved A/B is pending.
Single lock holds, which the A/B is to settle, read 0.651-0.678 us a draw on the offset shape
against 0.594-0.648 for the lane tip.

(cherry picked from commit 4ae147ebb662f7ab3e76153337c6f9416c06e613)
(cherry picked from commit 0e60618737d59d3c5bf58971358c12cf38395c7e)
2026-11-03 10:11:05 -08:00
Anees Iqbal 9b60da4bee host_ram: import a used RAM's chunks ahead, on a thread of the device's
What: Device::use_host_ram now starts a thread ("m2v-host-ram", through exit_guard::spawn)
that imports the RAM's 64 MiB chunks one after another, ahead of the objects over them. It
goes on from the chunk past the one an object last took, then from the RAM's start. It
skips a chunk whose lock is held (an object is importing it) and one it failed to import
(left to the first object over it, as before). It stops once every chunk is imported, the
use ends, the device goes or is lost, or the process exits (each import inside an
exit_guard section). It holds the device and the RAM weakly between chunks. An object over
a chunk the thread has not reached imports it on its own thread, as before. One over the
chunk being imported waits for that one import. New counter:
WorkCounts::host_ram_chunks_imported_ahead.

Why: a consumer makes 2 MiB heaps over consecutive fresh guest RAM (memfd). Each 32nd heap
was the first object over a chunk. Its making waited for the chunk's import, which faults
in and pins 64 MiB of fresh pages. That took ~7.5 ms exclusive on the RTX 5080 laptop, and
0.4-4.0 s in a shared boot with compaction (compact_stall +10,889). Keeping chunks imported
for the RAM's life already held at the start of this branch (a chunk stays in its slot
while the use lasts). Measured here: a heap made again after every heap was dropped
imported 0 chunks.

The trade-off: the whole RAM is resident and pinned from soon after use_host_ram, not only
the chunks objects touch. 16 GiB of fresh THP memfd RAM took 3.47 s on the thread, with
compact_stall 1152, compact_fail 56, pgmigrate_success 935291 and allocstall_normal 54,
all off the making threads. No kernel, boot or module parameter is needed. Recorded in
docs/HOWTO.md ("One run inside one chunk").

Vulkan rules relied on (checked against the 1.4.366 spec): the import itself is
Device::import_chunk, unchanged, under VUID-VkImportMemoryHostPointerInfoEXT-pHostPointer-01749
"pHostPointer must be a pointer aligned to an integer multiple of
VkPhysicalDeviceExternalMemoryHostPropertiesEXT::minImportedHostPointerAlignment",
VUID-VkImportMemoryHostPointerInfoEXT-handleType-01750 "pHostPointer must be a pointer to
allocationSize number of bytes of host memory", VUID-VkMemoryAllocateInfo-allocationSize-01745
"allocationSize must be an integer multiple of ...minImportedHostPointerAlignment", and
VUID-VkMemoryAllocateInfo-memoryTypeIndex-01744 "the value of memoryTypeIndex must be one of
those returned by vkGetMemoryHostPointerPropertiesEXT". The spec's "Externally Synchronized
Parameters" list names no parameter of vkAllocateMemory, so the thread's imports may run
while other threads use the device. Each chunk's import is made once, under the chunk's own
lock. A chunk is freed only on the existing path (vkFreeMemory's memory parameter is
externally synchronized: one owner frees it).

Verified on the RTX 5080 laptop (NVIDIA 615.71.09), release, --cfg m2v_gpu:
- All 21 host_ram tests pass, among them the new device test
  chunks_are_imported_ahead_so_no_making_waits_for_one. It covers 4 chunks of fresh memfd
  RAM under MADV_HUGEPAGE, imported ahead in 32.5 ms. Then 40 heaps of 2 MiB over
  consecutive runs: 0 chunk imports, 0 host-pointer imports and 40 chunk-bound buffers
  during the makings, the slowest making 78 us. Heap 33 passes a CPU write -> GPU read ->
  GPU write -> CPU read round trip. A heap made again after all were dropped imports
  nothing. The other device tests hold the thread back (Device::hold_host_ram_imports,
  test-only), so they still see each chunk imported by its first object.
- Negative control: with the spawn disabled, the new test fails ("the device's thread
  imported 0 of 4 chunks").
- On the M3 Max (MoltenVK, macOS 27.0.1), release, --cfg m2v_gpu: all 19 host_ram tests
  pass (the two dma-buf tests are Linux-only). In the new test, 4 chunks were imported ahead
  in 7.2 ms; across the 40 makings the slowest took 35 us.
- Unit test the_devices_thread_goes_on_past_the_chunk_an_object_took_then_from_the_start
  covers the order, the skip of a held or failed chunk, and the end.

Heap makings, 128 heaps of 2 MiB over fresh THP memfd RAM (wall time per
new_heap_with_bytes_no_copy):

  case                                          p50       p90       max      makings > 5 ms
  before, 1 GiB RAM                             0.001 ms  0.002 ms  7.39 ms  heaps 0, 32, 64, 96
  after, made at once                           0.001 ms  0.003 ms  7.54 ms  heaps 0, 32, 64, 96
  after, made once the thread is done (122 ms)  0.001 ms  0.002 ms  0.05 ms  none
  before, 16 GiB RAM                            0.001 ms  0.002 ms  7.54 ms  heaps 0, 32, 64, 96
  after, 16 GiB, made once done (3468 ms)       0.001 ms  0.002 ms  0.03 ms  none

Made at once, the makings outran the thread: 5 chunks were imported during them, 4 of
them by the thread. Once the thread is done, no making waits for an import.

(cherry picked from commit 7baa553a75515909f2ce9701c1e1bea4c408845a)
(cherry picked from commit 97a69f70ab96d37dcdf269192a6935f8c4126749)
2026-11-03 10:11:04 -08:00
Anees Iqbal c9a2347fa6 Re-bless the conformance cost records on the M3 Max at 2b55ab415e, four ICB/mesh cases withheld
What: the M3 Max cost records of the whole case set re-measured on this tree (2b55ab415e: the
compressed-extended-range scratch fix 2b5f0731c5 and the no-copy look fix 36ec3efc81 in), debug
build, MoltenVK 1.4.2: `conformance cost --runs 8 --write` over the whole set (1123 cases, 1114
measured, 9 stopped), then `conformance cost --runs 8 --alone --write` over the 820 cases whose
record gained a bound or a record, so every new bound carries its contrast. The draws class's
ceiling in cost::the_creation_prediction rises 45 -> 47 (below), with its table re-read from these
files. AFTER_THE_LAST_RUN names no case and stays empty.

Four cases keep their committed recordings, whole files, new counters and all, because their
gated rises came with stack18's indirect-command-buffer and host-step commits and are not yet
explained: indirect-mesh-commands-object-threadgroup-lengths, mesh-commands-unordered-draws,
mesh-commands-own-state and indirect-render-commands-inherited-state. A `cost --check` on this tree
reads `over` on exactly those four until their cause is fixed or shown to be required and their
records are written in a follow-up.

Differences of this commit's records from the ones they replace, as `cost --check` counts them
(cost::drift of each committed record against this write, before the contrast): 1522 over 558
cases, 45 of them numbers the gate reads.
- 1452 counts newly gated (the counters the old records predate: heap_tables_worked_out in 551
  cases, resident_textures_looked_at 320, dispatch_shapes_made 293, host_steps_recorded 155,
  dispatch_used_resources_listed 47, and others); 25 no longer gated.
- 43 gated bounds moved: 16 fell (bound_notices_made in 14 cases, no_copy_lies_read in two) and
  27 rose. 2 pipelines-per-state ratios rose.

Each rise, bisected with each case alone (`cost --runs 8 --show`, debug builds, one selection at
every candidate commit):
- compressed-blits-bgra10xr and -srgb: command_barriers 5 -> 24, cmd_copy_buffer_to_image
  7 -> 12, cmd_copy_image_to_buffer 6 -> 11, cmd_pipeline_barrier 18 -> 37. 4b194d24af (452c17aa2c
  reads the old figures, 4b194d24af the new ones): under the suite's exact policy
  (ExtendedRangeBlitPolicy::Canonical) each blit into such an image is rewritten in Metal's
  encoding through a scratch copy out, one dispatch a region and a copy back, and each blit out
  into a buffer takes one dispatch. Required for Metal's bytes. 4b194d24af also zeroed that scratch
  in a first-work command buffer of its own (command buffers 11 -> 14, cmd_copy_buffer 2 -> 7,
  7 more barriers), which 2b5f0731c5 removed. Those counts are back at their old bounds.
- xr-draw-bgra10xr-{half,float} and -srgb-{half,float}: cmd_bind_descriptor_sets, cmd_bind_pipeline
  and cmd_push_constants 1 -> 2. xr-clear-routes-bgra10xr and -srgb: the same three 4 -> 12.
  4b194d24af: each blit out of a compressed BGRA10_XR target into a buffer takes one dispatch of
  the canonical encoding (1 and 8 of them). Required for Metal's bytes.
- host-page-writes-kernel-store-read-only: no_copy_lies_read 21 -> 23 (-visibility-read-only and
  -writable fell 18 -> 17). 442a9fd538 and 3fd1f6672b each added a look at a new no-copy buffer's
  pages, which 36ec3efc81 removed. a4546da224 adds 3 looks per dispatch that binds one, in its
  debug-build checks of the kept compute bind state (compute/live.rs, under debug_assertions):
  the case alone reads 22 on a release build of abd5f64c55 and 25 on its debug build. A debug-only
  artifact of the measurement, no product work.
- pixel-samplers-rgba8-linear-edge: pipelines per state 1/3 -> 2/3. 575ac2b103 (its parent
  6c294fe742 reads 1/3): SpecKey::NearestPixelSampler keys a nearest pixel sampler's variant apart
  from a linear one's, so the first linear case after the nearest ones makes its own. Required for
  Metal's nearest texel.
- render-then-sample-magnified-nearest: pipelines per state 2/2 -> 4/2 (alone 4/2 -> 6/2).
  d4fa99a14c (its parent 3fd1f6672b reads the old figures): the half-reading state's creation
  makes its predicted key's general form and hands the predicted key itself to the pool, and the
  draw takes the predicted key. So this case and -magnified-linear each make one general-form
  pipeline no draw takes, 2 -> 3 made and 2 taken, which is what raises the draws class's ceiling
  from 45 to 47. That waste is an open bug (not making the general form where the prediction is
  plain), not a requirement.

The 9 cases that stop do so at the same call as their committed cost records, each a refused row
in known-gaps.tsv: binary-archive-mesh-adder (program),
mesh-object-draws-partial-threadgroup-6-by-4 and -5x3-by-4x2 (drawMeshThreads),
format-footprints-plain-stragglers, -one-plane-ycbcr, -padded-wide-channels and
-two-plane-ten-bit (makes-texture), attribute-stride-inline-bytes (dispatchThreadgroups) and
argb8-targets-destination-alpha (pipeline/argb8).

Verified on the M3 Max: `conformance cost --runs 8 --check` over the whole set, run right after
the contrast and before the four files were put back, exit 0: "no gated bound and no ceiling
moved" (3 reach differences, 0 load-bearing). `cargo nextest run -p metal2vulkan-conformance
--all-features` on this commit's files: 1010 passed.

(cherry picked from commit 572e87eeb81b7bb46de6100a73b00e68c225371f)
(cherry picked from commit 02a0466c43d944a75d9089f45887de2f7e0c29b4)
2026-11-03 10:11:04 -08:00
Anees Iqbal e0b0bbb700 Pin the runtime sources after the captured core's merge leases
A type-only fix in encoder.rs (no behaviour changed, so RUNTIME_VERSION stays 1754).

(cherry picked from commit 2b55ab415e2972a1f6cff06536bd4c659193f4e2)
2026-11-03 09:25:31 -08:00
Anees Iqbal 4bfc52b6de Hold a captured core's merge leases as the encoder now does
The kept ICB recordings' Captured takes an encoder core's kept_leases, which the lent merge
scratch turned from Vec<KeptLease> into Vec<MergeLease> (and dropped KeptLease's import): each
branch built alone, the two together failed E0425 at encoder.rs. Captured now holds
Vec<MergeLease>, the same leases the core held. No behaviour changes.

Verified: cargo clippy --workspace --all-targets --all-features -D warnings passes on the stack.
(cherry picked from commit bee669c0efdb0be77539f3be2c1dd2e6aac1f694)
2026-11-03 09:25:30 -08:00
Anees Iqbal 18f064f0ff Pin the runtime sources after host steps, kept ICB recordings, replay misses and lent merge scratch
RUNTIME_VERSION 1754 says the behaviour changed. Hash from the pin derivation over the listed
runtime and translator sources.

(cherry picked from commit e9300eecd461cc17c6d9f37d22106d0bf5a0d681)
2026-11-03 09:25:30 -08:00
Anees Iqbal e748ef398b Bump RUNTIME_VERSION to 1754: host steps off the scheduler, kept ICB recordings, unbound replay misses, lent merge scratch
- Unchanged indirect commands run from kept recordings, chunk by chunk.
- A device replay leaves an address no allocation holds unbound, counts the miss and runs the
  command (it faulted and dispatched nothing).
- Host steps record on a steps thread off the scheduler's, order by what the execution reaches,
  and make only the states the CPU named.
- A command buffer lends its finished encoders' linear-merge scratch to its later merges.
- A new no-copy buffer's pages are looked at once as it is made.
Each changes what a recorded run did.

Stacking note: the host-steps commit (3831ba7e12) met checks at commit in scheduler/mod.rs.
run_work takes the scheduler's Arc (to post a step to the steps thread) and keeps the
committing-thread doc of claim_check; submit_at_commit's call passes &self.shared (a check, so it
never takes the steps branch). cargo check of the runtime passed after the resolution.

(cherry picked from commit d8c160edeba572b9500a04e228c4b79d1fd6492d)
2026-11-03 09:25:30 -08:00
Anees Iqbal 9c41c0b2a6 Lend a command buffer's merge scratch to its later encoders' merges
A linear attachment rendered apart (a texture over a buffer's bytes beside a depth or stencil
attachment on NVIDIA, VK_NV_linear_color_attachment's rule) made a scratch of twice its box
for every pass's merge (LinearMerge:🆕 Device::scratch_buffer(2 * part)), and a shadow
merged back at each encoder's end (host pages, packed rows the device's linear images do not
lay out, such as an IOSurface's 4 * width) made one of its rows for every encoder: each held
until the command buffer completed, as the shadow's spares came back only then. A WebGPU frame
split at every indexed draw (stencilMask: 706 passes over a 1200x1200 canvas) so held 4 to
5.6 GiB, and the reims-vgpu lane's endEncoding failed out of device memory on the RTX 5080.

Now each command buffer keeps a pool of the scratch its ended encoders' merges are done with
(merge_scratch.rs, CommandBufferShared::merge_scratch): a linear merge takes the smallest free
scratch of its kind that holds its box, and gives it back once its pass's merge is recorded
(LinearMerge::record_merge); a shadow merge takes one the same way (before the shadow's
spares), held by a ScratchLease beside the encoder's kept-image leases (MergeLease) and given
back as the encoder goes. The pool holds weak references, so the bytes still go when the
command buffer completes, a shadow's back to its spares once the last merge that used it goes
(Scratch's drop, in place of ShadowMerge's). A new scratch takes at least twice the largest of
its kind the command buffer made, capped at a whole attachment's merge, so growing boxes make
a few. The memory a command buffer holds for merges follows its attachments, not its passes.

Why lending needs no wait (merge_scratch.rs's Order, against the barriers as recorded):
- a linear merge's scratch is touched only by its pass's fill and keep after the copy in
  (record_keep: fill, Barrier::everything, keep, Barrier::everything), its reloads in the
  pass's steps (reload_in), and its merge (record_merge: Barrier::everything, the changed copy,
  Barrier::everything, the dispatches, Barrier::everything); a shadow merge's by its keeps and
  merges, recorded before the encoder's next command that touches the bytes another way or at
  its end, each merge ending with Barrier::everything after its dispatches (record_merge). All
  lie in the encoder's own VkCommandBuffers or the segments it leaves between them;
- a command buffer's encoders go in order (one open at a time; a render end left to the
  lowering thread is lowered before the next encoder opens) to its queue's one VkQueue, which
  the queue keeps from the command buffer's making to its completion; reruns of a laying and
  re-encodes after a rebind repeat or replace whole encoders. So two encoders' spans over one
  scratch never interleave in submission order;
- each span writes what it reads before reading it, and the earlier one ends with
  Barrier::everything (ALL_COMMANDS/MEMORY_WRITE to ALL_COMMANDS/MEMORY_READ|WRITE), whose
  scopes are every command before and after it in submission order on the queue: the later
  span's writes follow the earlier's reads and writes. A shadow's scratch is tracked besides.

Counted: WorkCounts::linear_merge_scratches_made and linear_merge_scratches_reused (new; the
api_signatures table blessed); shadow merges count the pool's loans in
shadow_merge_scratches_reused. A cfg(test) switch (DeviceShared::linear_rule_forced) makes
linear_attachment::bound answer the rule, so a device of no such rule (MoltenVK) reaches the
path in the runtime crate's own device tests.

Measured on the RTX 5080 Laptop GPU (msi-laptop, release, a scratch harness of
stencilprobe -P's sequence on the runtime: one command buffer, a clearing pass, 706 passes
loading colour and stencil beside a Depth32Float_Stencil8 attachment, a 1x1 attachmentless
encoder between them, 1400 encoders; three runs a process; peak = nvidia-smi's per-process
used memory, sampled every 50 ms), base 357a76f214 against this commit:
- texture over host pages, 1200x1200, rows 4800 (a shadow): before 3776 to 4096 MiB of device
  memory allocated while encoding, peak 4333 MiB, commit to completion 87 to 89 ms; after 0 MiB,
  peak 237 MiB, 57 to 65 ms;
- host pages, 1024x1024, rows 4096 (a shadow): before 2496 to 2816 MiB, peak 3053 MiB, 65 to
  70 ms; after 0 MiB, peak 237 MiB, 53 to 59 ms;
- a Private buffer, 1024x1024, rows 4096 (the linear attachment rendered apart, 707 passes
  through copies): before endEncoding failed, OutOfMemory(Device), peak 5485 MiB; after it
  completes, 0 MiB, peak 237 MiB, 73 to 81 ms;
- a Shared buffer, 1200x1200, rows 4800 (a shadow): before 3776 to 4096 MiB, peak 4333 MiB, 80
  to 88 ms; after 0 MiB, peak 237 MiB, 56 to 64 ms.

Measured on this Mac (M3 Max, MoltenVK 1.4.2, release, the same harness; peak = the process's
peak memory footprint, /usr/bin/time -l), base against this commit: host pages 1200x1200, rows
4800 (a shadow): before 3776 to 4096 MiB allocated while encoding, footprint 5087 MB, commit to
completion 117 to 151 ms; after 0 MiB, 795 MB, 104 to 138 ms. Host pages 1024x1024, rows 4096:
before 2496 to 2816 MiB, 3755 MB, 110 to 143 ms; after 0 MiB, 803 MB, 101 to 128 ms. The Private
and Shared cases render in place on MoltenVK (no rule, no shadow) and are unchanged (64 to 86
ms, 655 to 661 MB).

Tests (device tests, --cfg m2v_gpu):
- tests::merge_scratch (runtime crate): 240 passes beside a Depth32Float depth attachment in one
  command buffer, over a Private buffer and a Shared buffer (packed rows of 1024 bytes), packed
  rows of 1200 bytes, and host pages; the rule forced. Passed on the RTX 5080 as committed, and
  on the M3 (MoltenVK) with a fifth case since dropped (below): each linear case 240 passes
  apart, 1 scratch made and 239 reused; each shadow 239 reused; texels equal a private
  texture's. Negative control (this tree with
  MergeScratch::take lending nothing, on the M3): all four fail (240 made, 0 reused; 0 shadow
  scratches reused). The base with the test copied in (its new counters left out) fails the
  shadow cases on the 5080 too (0 reused).
- runtime_lane::linear_attachments::many_passes_* (validation crate): 706 passes over a Private
  buffer (320x240, rows 1280), host pages (rows 1280 and 1200) and a Shared buffer of rows 1200,
  colour bytes against a private texture's. Passed on the M3 and on the RTX 5080, where the
  Private case is apart by the device's own rule: 706 passes through copies, 1 scratch made and
  705 reused; each shadow 705 reused. The negative control fails the host pages case.
- clippy --all-targets --all-features -D warnings, plain and with --cfg m2v_gpu; the
  api_signatures and api_surface tests.

Not fixed here, and not in the tests: over a Private buffer whose rows have bytes between them
(200 texels in rows of 1024 bytes, a shadow copied back), the same 240 passes leave 8800 (M3)
and 10516 (RTX 5080) of the 19200 texels unequal to a private texture's, at base 357a76f214 too
(the 5080, the test copied in): no merge runs there, so it is not this change's.

(cherry picked from commit b8fdd84f5c69546d1626fb994fd7d13756c1fc96)
(cherry picked from commit 6fa0708f5ef41bf2a599616a19d2da616492f032)
2026-11-03 09:25:30 -08:00
Anees Iqbal 0e62eb1f72 host_replay_frames: HOST_REPLAY_VERTEX_OPS gives each state a vertex function of its own
With one vertex function for every state, the large-buffer form of the states' pipelines shares
its vertex module, and the driver compiles it once: on the RTX 5080 Laptop GPU (NVIDIA
615.71.09, its disk cache off) the parent's commit-time settle made 4,001 VkPipelines of 2,000
states in about 0.1 s, where a browser's states each bring their own vertex function. The knob
gives each state its own: rt6_resolve_half's triangle, its depth a chain of that many dependent
multiplies and adds on the vertex index, times zero, plus a half.

Verified: the generated vertex function translates (metal2vulkan CLI, spirv-val PASS); clippy
-D warnings with --cfg m2v_gpu for the validation crate.

Needs no version bump: a test, ignored by default.

(cherry picked from commit 7532a5fbc4ac6cad04a1b91186a8819952c7235c)
(cherry picked from commit 59ea25b2d2894f467256420518445fe902e78deb)
2026-11-03 09:25:30 -08:00
Anees Iqbal e51a3fa56d Name an ICB's per-command map CommandStates, not Commands
The kept recordings of unchanged indirect commands (four commits back) named the buffer's map of
the states the CPU set, and of its kept chunks, Commands. tests::exit_guard's
only_the_listed_modules_keep_the_device_s_functions reads the sources for copies of the device's
functions and takes Commands for the generated-commands table that holds them, so it failed at
indirect_command_buffer.rs's pipelines: Mutex<Commands>. The map holds no device function; its
name now says what it holds.

Verified: --cfg m2v_gpu, metal2vulkan-runtime's tests::exit_guard and kept_commands tests (42)
pass; the exit-guard test failed on the commit before (the M3 Max run of the runtime's lib, 1,830
of 1,831 passing).

Needs no version bump: a private rename.

(cherry picked from commit 93c48b72a7a094d6c7cee93192070f7f99e77dea)
(cherry picked from commit 831d54138016d0373b51e7c033e4c7665dbd65ce)
2026-11-03 09:25:30 -08:00
Anees Iqbal 51c7059a40 Regenerate docs/REFUSALS.md: KernelStageIn's site and the rebind_slots range refusals
python3 scripts/refusal-surface/refusal_surface.py on this tree. Two rows move:
- KernelStageIn's runtime site is indirect_execute.rs's dispatch now, where the kept recordings
  of unchanged indirect commands moved the refusal (two commits back), not record;
- BufferRange and DescriptorRangeExceeded gain bind/graphics.rs's rebind_slots, a site the base
  had added without regenerating the table.
The device replay's ReplayFaults::ADDRESS was no refusal, so its removal moves no row;
tests/api_surface.rs names ReplayFaults alone, and api_signatures.tsv dropped the constant with
it (scripts/api-signatures --check passes).

Needs no version bump: a generated document.

(cherry picked from commit 07d7e05255a3d15ba98094389a680e96440eefa0)
(cherry picked from commit 3d66d7436109ffbd80c5e6adf0ef1d92b26d70e5)
2026-11-03 09:25:30 -08:00
Anees Iqbal 2e0fb7b220 runtime_lane::host_replay_frames: what frames of GPU-writable render commands cost another queue
An ignored measurement (run by name, release, --cfg m2v_system_alloc), the shape of a browser's
render bundle under a compositor: 256 render pipeline states made with
supportIndirectCommandBuffers, each with a fragment function of its own, and an ICB of 5000
draws that sets the first 4 of them in turn, inheriting nothing. Each frame a compute encoder
makes the ICB resident for writing and dispatches a kernel that writes no command, and a render
pass executes every command; meanwhile another queue presents a clear every 8.33 ms. It prints
HOST-REPLAY lines: the first 4 frames one by one, then the median, p90 and largest of 60 frames
(the frame, its commit, first submission to last), the presenter's commit to completion and the
ticks it missed, and the device's counters over them (host steps and their time, heads held,
variant pipelines made, pipelines looked up, draws settled and dropped, records read).

HOST_REPLAY_STATES sets the live states, HOST_REPLAY_OPS gives each fragment function that many
dependent operations on the position (so the driver takes longer to compile it), and
HOST_REPLAY_DROP_MS has the program release every state but the named ones that long into the
first frame.

Verified: the previous commit's M3 Max numbers come from it (run on the parent and on that
commit's tree); clippy -D warnings with --cfg m2v_gpu for the validation crate.

Needs no version bump: a test, ignored by default.

(cherry picked from commit 42c7708b1ded77b1334812c7eb701764a5d69bd5)
(cherry picked from commit afed271c358c30dcb1a7eddfe829c1518055998a)
2026-11-03 09:25:30 -08:00
Anees Iqbal 185bbd6328 Host steps: record off the scheduler's thread, order by what the execution reaches, make only named states
A batch executing indirect commands the GPU may write waits for its gate, then its host step
records the commands from their records. Three costs fell on every other queue meanwhile:

- The step ran on the scheduler's thread, which submitted nothing while it recorded (thousands
  of draws take milliseconds).
- Its footprint was unknown (tracker::ordered's None), so every later batch of another queue that
  made a tracked use was held behind it until it was submitted.
- At commit, the render settle made a VkPipeline for every live state that supports indirect
  command buffers, times the topology class's primitive types (1,280 lookups and 513 makings for
  256 live states on the measured frame), and the step waited for all of them, up to the command
  buffer's bound.

Now:

- The scheduler hands each step to a steps' thread (scheduler/steps.rs, started at the first
  step, user-interactive like the scheduler's, recording inline where the host cannot start it),
  which records the steps in order, each a section of the exit guard, and wakes the scheduler.
  The batch is marked as stepping meanwhile (CommandBufferShared::begin_step/end_step), so it
  waits and no pass hands it over twice.
- commit bounds a step's uses where it can (Segment::bound): for a compute execution, the
  resources the command buffer made resident and the ICB's storage (and an indirect range's
  copy); for a render pass, the pass's own uses, the resident resources and each execution's
  storage. CommandBufferShared::footprint uses that bound, so only a later batch sharing one of
  those is held. An execution that inherits buffers, is gated or preprocessed, reaches tile
  memory, has shadows or lends visibility stays unbounded (None), as before.
- The render settle makes the states the CPU set on the executed commands
  (IndirectCommandBuffer::set_render_states, each state once), or the inherited one. A draw of a
  state a GPU-written record names that no settle made is begun at the step, made on its thread
  or handed to the device's pool and waited for until the command buffer's bound, as before; it
  holds no other queue's batch, and it is counted.

On the kept recordings of the commit before (item 1), set_render_states reads the states the CPU
set from the buffer's per-command map (Commands::states, a range of it), each state once.

New counters: WorkCounts::host_steps_recorded, host_step_nanos, and host_step_pipelines_made
(the VkPipelines a step began itself, made on its thread or handed to the device's pool and
waited for: counted at the variant's making on the step's thread and at pipeline_pooled).
The degrade notice host-replayed-indirect-commands states the new cost (degradation.rs and
docs/API.md, same text).

Verified on the M3 Max (MoltenVK 1.4.2), release, runtime_lane::host_replay_frames (the next
commit: 256 live states, an ICB of 5000 draws naming 4, made resident for writing by a compute
pass each frame, and a presenter clearing a texture on another queue every 8.33 ms), the parent
and this tree run alternately twice, 60 frames each after 4 cold ones, on a loaded host:
- the presenter: 80 of 244 and 73 of 192 ticks presented before (commit to completion median
  16.9 and 16.4 ms, p90 40.8 and 23.7 ms), 186 of 186 and 185 of 189 after (1.13 and 1.13 ms,
  p90 1.49 and 2.23 ms); heads held behind earlier commits 23 and 13 before, 0 after;
- the first frame's commit: 377 and 168 ms before (513 variant pipelines made, 1,284 looked
  up), 5.3 and 5.1 ms after (9 made, 24 looked up); a steady commit 2.38 and 2.33 ms before,
  0.14 ms after;
- the frame itself (commit to the last completion): median 28.7 and 24.4 ms before, 23.3 and
  24.6 ms after, within the host's noise; the host step takes about 20 ms of it
  (host_step_nanos), recording the 5000 draws.
The consumer's ICB repro (one state, 5001 draws, the ICB made resident for writing, another
queue's one-dispatch command buffers meanwhile), same runs: that queue's commit to completion at
the 99th percentile 53.5 and 24.3 ms before, 2.96 and 3.71 ms after, 140 and 119 command
buffers in 40 frames before, 2,281 and 2,062 after; the frame alike (21 to 26 ms).
Tests: runtime_lane::render_executions::
a_host_step_makes_the_pipeline_of_a_state_only_a_gpu_written_record_names (a blit-copied record
naming a state, of another variant, that the CPU set on no executed command: both commands draw,
the step's beginning of that state's VkPipeline is counted, and the step's time).

--cfg m2v_gpu under the validation layer, on this tree before the pipeline_pooled count and the
test: 234 tests of the indirect_*, kept_*, render_executions, render_gpu_executions,
render_merged_executions, mesh_commands and executions lanes; 1,644 tests of the runtime crate's lib and the
commands_recorded, dispatch_executions, generated_executions, kept_variants, device_commands,
queue_order, submission_checks and grouped_submissions lanes. clippy -D warnings, plain and
--cfg m2v_gpu; rustdoc -D warnings; scripts/api-signatures --check.

Needs a RUNTIME_VERSION bump (what a run submits, when, and its counts) and a runtime-sources
pin.

(cherry picked from commit 4b05004999403684a2bdf4f3994108b53c7dc776)
(cherry picked from commit 3831ba7e1298203779597feb0ea2943f77f9f5df)
2026-11-03 09:25:30 -08:00
Anees Iqbal 4b0222d316 Device replay: leave an address no allocation holds unbound, count the miss, and run the command
The compute device replay's preprocess (bind/replay.rs, the GPU-alone path of a GPU-writable
compute execution and the generated-commands path) faulted a command whose kernel buffer address
lay in no resident allocation (ReplayFaults::ADDRESS) and dispatched nothing. The command buffer
completed with no error and the dispatch never ran: a command naming a buffer the program released
before the execution, made resident for READ|WRITE in the executing encoder or for WRITE in an
earlier encoder, wrote nothing. Metal runs that dispatch, and the draw replay and the host's step
already leave such a slot unbound and count a resident miss.

The preprocess now does the same: the slot is unbound (it reads as a buffer never set, so it reads
zero and drops writes), the command's misses are added to the status's ResidentMisses with
StatusBits::RESIDENT_MISS, and the command runs. A faulted command reports its faults alone, as
before. ReplayFaults::ADDRESS is removed (bit 7 is no longer reported): a breaking change of the
public `metal2vulkan::bind` surface, and the validation engine's verdict drops its name.

Tests: bind::replay::tests' four ADDRESS refusal cases become
an_address_no_allocation_holds_leaves_its_slot_unbound_and_counts_a_miss (no fault, one miss,
the command's arguments and slot table, the missed slot zero, an empty command counts nothing);
runtime_lane::dispatch_executions::a_command_s_released_buffer_runs_its_slot_unbound runs one
command naming a released 16-byte and 1 MiB buffer with the ICB resident for READ (commit's
recording), for READ|WRITE, and for WRITE in an earlier encoder (both on the GPU alone), and
checks the output, one counted miss in the report, and that nothing is announced.

Verified on the M3 Max (MoltenVK 1.4.2), --cfg m2v_gpu, under the validation layer:
- before the fix (the parent with the test added), the test fails at the READ|WRITE form of the
  16-byte buffer: out stays 0xee in all 16 bytes, so the dispatch never ran;
- with it, the test passes, as do runtime_lane::dispatch_executions, indirect_host_steps and
  generated_executions (35 tests).
CPU: metal2vulkan bind::replay, bind::status, tests::engine_device_replay and the validation
candidate::engine tests pass; scripts/api-signatures/signatures.py --check passes.

Needs a RUNTIME_VERSION bump (the device replay's preprocess and its status) and a runtime-sources
pin; no SEMANTICS_VERSION or ARTIFACT_FORMAT_VERSION bump.

(cherry picked from commit 89ebae67047f940624efb76c0ab535fa3b3b56ab)
(cherry picked from commit 15da05bbb5eb5fe8814efd912b6e81b50802a7a8)
2026-11-03 09:25:29 -08:00
Anees Iqbal 565fbd9153 Run unchanged indirect commands from kept recordings, chunk by chunk
An execution of an indirect command buffer read, decoded and recorded every
command again at every commit, so an unchanged execution of 16384 draws cost
about 44 ms of commit on the M3 Max and 64 ms on the RTX 5080 laptop, where
Metal's costs 2 ms. A profile of the render case put a third of it in the
records' decode and moves and the rest in recording the draws.

Now an execution of commands the CPU encoded records them in chunks of 256
(kept_commands.rs). A render chunk records into a secondary of its own, begun
for simultaneous use against the instance's compatible pass, through an
encoder over a core of its own whose effects the pass's core takes
(EncoderCore::capture, absorb); a compute chunk records as a segment of its
own, behind a barrier from everything before. Each chunk takes its command
pool, descriptor arena and uploads from a context of its own, lent to the
command buffer while it records and held by every command buffer that runs
it. A chunk whose recording is plain (every draw passes draw_again's keep
test but for being replayed, no step outside its command buffer, nothing its
command buffer alone holds, no released state) is kept on the buffer with
what it was recorded from: the encoder's inputs (RenderKey, ComputeKey: the
inherited state, the pass's compatible pass, shape, extent and sample
positions, the encoder's state and scissors, the resident resources), each
address its commands named and what it resolved to, and the no-copy moves.
A later execution of the chunk under equal inputs, every address resolving
as before, nothing detached and every held object alive, runs the kept
command buffer and notes its uses, keys, holds and executions again
(EncoderCore::run_kept), reading no record. Every CPU write of a command
forgets its chunk under the lock the write takes; the buffer's first GPU
write forgets them all; a recording from records written meanwhile is not
kept. A chunk that is not plain records the rest of the range as before and
is noted, so later executions of it record as before until a write reaches
it. The buffer's per-command state moves to a map, so a buffer of commands
never encoded holds nothing for them.

WorkCounts::indirect_chunks_kept and indirect_commands_kept count the kept
path. docs/FAST-PATHS.md's known gaps list the executions that still record
every command at every commit.

Verified on the M3 Max (MoltenVK 1.4.2), --cfg m2v_gpu, under the
validation layer: runtime_lane::kept_commands, 5 tests: unchanged render
commands run 3 kept chunks of 600 commands reading no record, into another
target and twice in one pass; a command written again or reset records its
chunk alone; a blit's reset runs no kept chunk and its commands draw nothing;
another residency or range records again; compute commands the same, with a
command written again and a blit reset. 446 of 448 tests of the 33 lanes
that execute indirect commands pass; the two others
(extended_range_blends half outputs, padded_loads loading pass) are among
the MoltenVK reds the parent already has. clippy -D warnings, plain and
--cfg m2v_gpu, for the runtime and validation crates; the runtime's
kept_commands unit test; the translator's fast_paths, api_signatures and
api_surface tests.

Needs a RUNTIME_VERSION bump and a runtime-sources pin.

(cherry picked from commit 21b9438ec5b8cbf7a1e79c5dfbf84cdad7b43d91)
(cherry picked from commit 922caf3199378b029bafc201429f80b0d43bb048)
2026-11-03 09:25:29 -08:00
Anees Iqbal b7652d85a2 Re-qualify every authored case on Metal under ORACLE_ABI v49
ORACLE_ABI v49 (the tile oracle's own pipeline per threadgroup size) leaves every v48 row
non-current, so every committed authored case is qualified again on the M3 Max under the C3
reference identity: macOS 27.0.1 (26A434), Xcode 27B52, metal 32023.922. The cases were measured
through the indexed path (corpus-metal --batch, default jobs, under the Mac GPU lock) and
installed with corpus-metal --batch-install, the store's validated write. Each case's
apple-m3-max-macos27.0.1 row is replaced, and no other environment's row moves.

Field by field against the committed rows, leaving out only the environment identity,
oracle_abi and timing:
- 2262 equal in every field: 2258 qualified with the same output and 4 reference gaps with
  the same family and message (GPUFamily10 simdgroup_matrix 16x16);
- 0 newly qualified;
- 0 changed status.
The 2262 cases are every committed case. The 1x1 tile-order case left in the previous commit.
Every apple-m3-max-macos27.0.1 row now records metal-literal-resources-v49.

One case needed a second run. e997a71d…, a private-source compute case, timed out in the batch
under host load: "compute pipeline creation did not finish within 60s". Run alone, it
qualified in 43.7 s with its committed output.

Verified:
- the comparison above, by a script over the committed and installed shards;
- the whole metal2vulkan-validation suite with every row installed: 1363 passed, 4 skipped.

(cherry picked from commit 1a970229669e0e30c154182f453e8626220412fa)
(cherry picked from commit c00efdc7c0519d01304f174ab625780ad8412ed4)
2026-11-03 09:25:29 -08:00
Anees Iqbal b31ea18f1b Remove the 1x1 tile-order case: Metal runs no thread of a 1x1 tile threadgroup
The case tile-threads-1x1-in-a-16x16-tile-take-their-places (b879f660…) dispatched
k10ts_tile_order at one thread per tile threadgroup. It qualified only because Metal's pipeline
cache handed it a pipeline compiled for another case's larger size. Under ORACLE_ABI v49 its
pipeline is its own, and Metal refuses it. Metal gives no error text: the tile pipeline answers
maxTotalThreadsPerThreadgroup 0, and the oracle refuses the dispatch before encoding it:
"Metal tile dispatch asks for 1 threads a threadgroup ([1, 1, 1]), but the pipeline permits 0".
The 0 is Metal's real behaviour, not a value read wrongly. A from-scratch 1x1 tile pipeline
compiled for the first time on the M3 Max (macOS 27.0.1) reports 0 and runs no thread of a 1x1
dispatch, with the command buffer completed and no error. The store has no Metal-refusal row, and
a v48 row left in the slot would read as missing Metal forever, so the case goes.

The same tile function at the same tile is still covered, through the same fixture and entry, at
2x2 (e307478f…, tile-threads-2x2-in-a-16x16-tile-take-their-places, the smallest size Metal
runs), 4x4 (5e61d5c4…), 8x8 (81c239f3…) and 16x16 (0714ac91…), and in a 32x32 tile (2a0d4ff1…).

Removed: the case line (cases/shard_030), its Metal rows (2), Vulkan rows (10), MoltenVK rows
(2) and its line of the authored compile census (authored-compile.tsv, one line per committed
case). No other line of the census moves. Nothing outside the corpus names the case.

(cherry picked from commit 02006734aefb5100632cd20c6f060859074b1f48)
(cherry picked from commit e9adbb55bedd2ab953a0988a8fbba66900b02ebe)
2026-11-03 09:25:28 -08:00
Anees Iqbal 4def63989b Give each tile threadgroup size a Metal pipeline of its own: ORACLE_ABI v49
The tile oracle now sets the tile pipeline descriptor's maxTotalThreadsPerThreadgroup to the
dispatch's threads, beside the requiredThreadsPerThreadgroup it already set.

Why: Metal keeps a tile pipeline it has compiled. For a later descriptor of the same function
that differs only in requiredThreadsPerThreadgroup, it hands back that pipeline and its
maxTotalThreadsPerThreadgroup, in the same process and in later ones (measured on the M3 Max,
macOS 27.0.1, with salted from-scratch kernels). A case's outcome therefore followed whichever
case of its fixture ran first:
- In the reference re-measure, the 8x8 case of k10ts_tile_order (81c239f3…) ran after its 4x4
  case and got 16: "Metal tile dispatch asks for 64 threads a threadgroup ([8, 8, 1]), but the
  pipeline permits 16".
- The 1x1 case qualified only when a larger size's pipeline was handed back.
- Such a pipeline also runs nothing: an 8x8 state that reports 16 runs no thread of its 8x8
  dispatch.

The descriptor's own limit separates the pipelines. With it set to the size's threads, each size
reports its own limit and runs all of its threads (16, 64 and 256 for 4x4, 8x8 and 16x16), in
the same process and in a later one. A first compile of a required size reports that limit
anyway, and Metal refuses a descriptor limit above it ("must match"), so the limit adds no
constraint of its own. Metal still answers what it answers without a cache: the size's threads
rounded down to a multiple of 4.

ORACLE_ABI moves from v48 to v49: what the oracle compiles changed. Every Metal row recorded under
v48 stops being current evidence until it is re-qualified, which the commits that follow do.

Verified with the release corpus-metal of this tree, reference environment, single runs:
- e307478f… (2x2), 5e61d5c4… (4x4) and 81c239f3… (8x8) qualify, each with its committed output.
- b879f660… (1x1) is refused: "Metal tile dispatch asks for 1 threads a threadgroup ([1, 1, 1]),
  but the pipeline permits 0".

(cherry picked from commit 193875e7393810840c517a9d9d5ea127a0e317ec)
(cherry picked from commit ac29781634d83f9d1b814f0156b3d01ad320d84b)
2026-11-03 09:25:28 -08:00
Anees Iqbal 3cbc39b51c Look at a new no-copy buffer's pages once as it is made
What: making a no-copy buffer (Device::new_buffer_with_bytes_no_copy and the other callers of the
import path in buffer_descriptor.rs) looked at where the new buffer lies three times, each look
taking the pages' lock (WorkCounts::no_copy_lies_read): kept_log for the log of the pages' writes
and the copy's name, kept_with for the guest RAM runs, and the aliases' join. kept_with's
`if let (Some(runs), Some(pages)) = (runs, buffer.host_pages())` evaluated the look even when there
were no runs. The import path now looks once (HostCell::current, as the aliases' join did) and
gives those pages the caller's dirty log, the log, the copy's name, the runs and the aliases; the
two copied paths look once in kept (kept_log and kept_with merged into kept and keep_in).

Why: the whole-set conformance cost check on the M3 Max read no_copy_lies_read over its records in
host-page-writes-visibility-read-only and -writable (18 -> 19) and -kernel-store-read-only
(21 -> 25). Bisected per case alone (cost --runs 8 --show, debug builds, the three cases in one
selection, visibility / kernel store): a6c58e923f 17 / 20; 442a9fd538 18 / 21 (kept_with);
97116bb420 18 / 21; 3fd1f6672b 19 / 22 (kept_log); 842f5d14fc 19 / 22; a4546da224 19 / 25. The
comment above the dirty log's look said the pages are looked at only for memory that carries one,
which the two new looks undid. a4546da224's three are its debug-build checks of the kept compute
bind state (compute/live.rs, check_reading and check_whole under debug_assertions): a release build
of abd5f64c55 reads 22 where its debug build reads 25, so release does no such look and nothing of
it is changed here.

Test: tests::no_copy_lies::a_no_copy_buffer_is_looked_at_once_as_it_is_made (device, m2v_gpu):
making a no-copy buffer over host memory with no log and no guest RAM looks once.

Verified on the M3 Max (MoltenVK 1.4.2), --cfg m2v_gpu: the test passes; with buffer_descriptor.rs
as at abd5f64c55 it fails, 3 looks for 1. The three cases alone, debug, after the change: 17 / 17 /
23 (a6c58e923f's 17 / 17 / 20 plus the debug-build check's 3). cargo check of the runtime crate,
all features, clean. Runtime behaviour changes (counts only): RUNTIME_VERSION is left to the
stacker.

(cherry picked from commit 402c67b4e69510ee88ca0d139a5d75c487bc739b)
(cherry picked from commit 36ec3efc81ed57b94075a05188b793ed11784bf8)
2026-11-03 09:25:28 -08:00
Anees Iqbal 043018d751 Pin the runtime sources after required sizes, checks at commit and the unzeroed canonical scratch
RUNTIME_VERSION 1753 says the behaviour changed. Hash from the pin derivation over the listed
runtime and translator sources.

(cherry picked from commit abd5f64c55a37cd2df0257185c40dce7fc0c69ca)
2026-11-03 07:56:22 -08:00
Anees Iqbal 622d03bd59 Bump RUNTIME_VERSION to 1753: required sizes answer W*H*D, checks run at commit, canonical scratch unzeroed
- A pipeline state with a required threadgroup size answers W*H*D as its
  maxTotalThreadsPerThreadgroup (compute and tile), lowered only to the device's limit.
- commit_and_submit runs a ready head's submission checks on the committing thread.
- The canonical extended-range encoding makes its image scratch without a zero fill.
Each changes what a recorded run did or answered.

(cherry picked from commit 1480dbb62e83eda330debe8d098c6b0480e7aeb5)
2026-11-03 07:56:22 -08:00
Anees Iqbal f2c12aeb80 submit_path: a --checked flag, each fill with a passing submission check
What: the bench's latency, cpu and threads rows can give each fill a
submission check that answers None, as a consumer's detach check does.

Why: to measure commit to completed-handler latency for checked command
buffers before and after the committing thread runs their checks
(commit_and_submit), on the RTX 5080.

Verified: clippy -D warnings on the runtime's examples (all features).
(cherry picked from commit 1677e2c42bf862411799073c34f6e8f35552eb3b)
(cherry picked from commit bb4b6681a74eaad43cb8dd3d96d7386162d890fc)
2026-11-03 07:56:22 -08:00
Anees Iqbal 22fe806e71 scheduler_wakes: count the sleep under way as the window opens
What: wakings_and_sleeps now counts, besides the sleeps the scheduler's thread
began between the two reads, the one it may have been in as `before` was read.

Why: tests::scheduler_wakes::commits_with_idle_gaps_lose_no_wake failed 3 of 30
at 357a76f214 and 8 of 30 here, every failure exactly one waking over the
sleeps (121/120, 36/35, 42/41, 33/32, 8/7, 6/5). Each test reads `before` on
an idle device, whose thread is asleep in a sleep counted as it began, before
the read; the first commit's waking of it is counted inside the window. It
reads `after` as its last command buffer completes, when the thread may be
awake again with its next sleep not yet begun: the wakings then exceed the
sleeps begun by one with no sleep notified twice. A sleep notified twice by a
change of the wake path would show more than that over a run's 30 to 120 sleeps.

Verified on the M3 Max (--cfg m2v_gpu, maclock): both scheduler_wakes tests,
--stress-count 60: 60/60 passed; over the 120 runs the wakings never exceeded
the sleeps begun by more than one (two runs at exactly one).

(cherry picked from commit 7dfd7177e0660d95db25483c620147690cbca371)
(cherry picked from commit ee8447c8053d201f893794db4930c2a4906b1819)
2026-11-03 07:56:22 -08:00
Anees Iqbal b74a0a4866 commit_and_submit: run a head's submission checks on the committing thread
What: a thread in CommandBuffer::commit_and_submit now runs the submission
checks of the head committed first of all itself, without the scheduler's
lock, right before it submits that head, where the head is ready but for its
checks (no host step, no group, no storage-form switch, no rebind) and every
event value it waits for was reached on the device or by the host. It then
passes again under the lock (Inbox::pass_again, which takes nothing in) and
submits that head first, and so on up to PASS_SUBMISSIONS batches in all. A
head whose checks wait for a submitted GPU signal to land, or whose checks the
scheduler's thread took first, stays the scheduler thread's, as before.

Why: reims's Vulkan platform sets a check on every command buffer it commits,
so commit_and_submit never submitted at commit for them (plain_ready held out
every checked head). Metal checks a submission as it submits it, on whichever
thread submits, so running the check on the committing thread is Metal's
behaviour; the check follows the submission handler's rule there (no lock the
caller holds, no GPU wait).

How:
- Held::checks_taken marks a batch whose checks were taken, by check_heads
  (left to the scheduler's thread, replacing its Left::holds lookup) or by a
  committer (claim_check), so the two never both run them.
- claim_check looks at Order::first_mut (the head take_first would take), so
  no head is passed over: commit order holds across threads.
- The committer's handlers keep their Turns tickets: each pass under the lock
  takes its own ticket, and its handlers run before the next check.
- The check runs through run_work -> CommandBufferShared::run_checks, the
  scheduler's own path, so a code (or a panic) fails the submission exactly
  as there (fail_submission, the CB completing with Injected(code)).
- plain_ready now holds out only a checked head whose checks are still to run,
  so a head whose checks ran goes with any plain pass.
- Counted: WorkCounts::batches_checked_at_commit (new), beside
  batches_submitted_at_commit; classified as Submission by its "batches_"
  prefix in the conformance cost rules.

Verified on the M3 Max (MoltenVK, --cfg m2v_gpu, maclock, load 50-90):
- New tests in tests::commit_and_submit:
  - a_checked_command_buffer_is_checked_and_submitted_on_the_committing_thread:
    40 of 40 checked and submitted on the caller, check then handler, before the
    call returned; batches_checked_at_commit 40.
  - a_refusing_check_fails_its_submission_alike_at_commit_and_on_the_scheduler:
    two submissions split by an event signal, the second refused with code 8:
    identical status, error, completed-handler status, submissions seen, bytes
    and event value on both paths.
  - checked_command_buffers_keep_commit_order_across_commit_and_commit_and_submit:
    2 threads x 500 checked CBs, commit and commit_and_submit in turn: checks
    and submission handlers in commit order, each check once; 308 of 1000
    checks on a committing thread.
  - The five commit_and_submit tests: --stress-count 10, 10/10 passed.
- Negative controls:
  - claim_check answering None: all three new tests fail (0 checked at commit).
  - claim_check neither honouring nor setting checks_taken: the order test
    fails 4/4 (checks out of commit order, checks run twice).
- runtime_lane::submission_checks' in-flight test gains a commit_and_submit
  variant whose wait is met only by a GPU signal in flight: its check ran only
  after the signal landed and never on the caller, Event and SharedEvent.
  submission_checks, grouped_submissions and queue_order lanes: 24/24 passed.
- Runtime tests matching scheduler|check|teardown|completion|submission|inbox|
  order: 169/169 passed. Conformance cost, fast_paths and api_signatures
  tests 38/38; clippy -D warnings (runtime + validation, --cfg m2v_gpu) clean;
  public rustdoc clean. api_signatures.tsv blessed (one new field).

(cherry picked from commit 91d0ea691a95649cbdc7828d4cc9ee6762a7ae53)
(cherry picked from commit 6c5fca926e855ee7d7236bc850bb9b281f4dd9cd)
2026-11-03 07:56:21 -08:00
Anees Iqbal 0e7e09a064 Answer a required threadgroup size's threads as a state's maxTotalThreadsPerThreadgroup
A compute or tile state whose descriptor states requiredThreadsPerThreadgroup now answers that
size's threads as its maxTotalThreadsPerThreadgroup. The answer is lowered only where this device
holds fewer threads for the kernel than the size. A state that requires no size keeps today's
answer, the compiled pipeline's limit. Before this change every state answered the compiled limit
(1024 on a full device) whatever size it required. Metal answers the size.

Measured on the M3 Max under macOS 27.0.1. Each state came from a source compiled once and never
before, with an integer baked into it:
- Compute: exactly W*H*D. 1x1x1 gives 1, 3x1x1 gives 3, 3x3x1 gives 9, 7x3x1 gives 21, 8x8x2
  gives 128, 1x1x64 gives 64, 32x32x1 and 1024x1x1 give 1024. No size gives 1024.
  [[max_total_threads_per_threadgroup(128)]] with 8x8x1 gives 64.
- Tile (threadgroupSizeMatchesTileSize on or off): W*H*D rounded down to a multiple of 4.
  1x1, 2x1 and 3x1 give 0, 3x3 gives 8, 7x3 gives 20, 2x2 gives 4, 6x6 gives 36, 8x8 gives 64,
  16x16 gives 256, 32x32 gives 1024. A tile dispatch of the state's own size runs no thread
  where the threads are not a multiple of 4 (1x1, 2x1, 3x3, 7x3). The command buffer completes
  with no error.
- Metal keeps a state it compiled and hands its limit to a later state of the same function
  that differs only in the required size. For compute this was seen in the same process; for
  tile, in the same process and in a later one. A compute state with 8x8x1, and one with no
  size, answered 16 after a 4x4x1 state of the same MTLFunction. An 8x8 tile state answered 16
  after a 4x4 one, and its 8x8 dispatch ran no thread. The module doc's earlier "the state's
  maxTotalThreadsPerThreadgroup stays the kernel's own" reads like such a measurement: a
  function compiled first with no size.

Rule 1 does not cover this: it is an API value Metal reports, not arithmetic. So the runtime
answers Metal's first-compile rule and does not imitate its cache. Following the owner's
decision, a tile state also answers the size's threads where Metal rounds them down, and its
dispatch of that size runs. Metal runs no thread there, which is its own defect. docs/API.md's
accepted differences records both and Metal's cache answer.

How:
- ComputePipelineState::max_total_threads_per_threadgroup answers
  pipeline::reported_max_total_threads(required size, compiled limit). A tile state's
  RenderPipelineState answer goes through its tile function's compute state, so it follows.
- The compiled limit moves to pipeline_max_total_threads_per_threadgroup (crate-private). The
  replay and folded indirect-dispatch paths (gpu_execute, indirect_dispatch) read it, so no
  dispatch path changes.
- Docs: the additions module's measurement, the tile module's answers, the render and compute
  accessors, the translator's descriptor fields and ComputePipelineMetalInfo, and docs/API.md's
  accepted differences.

Tests:
- tests::pipeline::a_required_size_is_the_states_thread_limit (CPU): the rule, the device's
  lower limit, no size, and axes whose product overflows.
- runtime_lane::compute_threadgroups::a_compute_state_with_a_required_size_answers_its_threads
  and runtime_lane::tile_states::a_tile_state_with_a_required_size_answers_its_threads
  (--cfg m2v_gpu): states made through the runtime with and without a size.

Verified:
- cargo clippy -D warnings, plain (metal2vulkan, metal2vulkan-runtime, metal2vulkan-validation)
  and with --cfg m2v_gpu (metal2vulkan-validation);
- RUSTDOCFLAGS=-D warnings cargo doc (metal2vulkan, metal2vulkan-runtime);
- scripts/api-docs;
- the metal2vulkan-runtime and metal2vulkan-air suites: 1715 passed, 4 skipped;
- the device lanes on the M3 Max through MoltenVK (tile_states, compute_threadgroups,
  tile_threadgroups, indirect_dispatches, indirect_executions, function_tables): 124 passed.
  With the old answer put back, both new device tests fail ("left: 1024, right: 1" at 1x1x1).

No version bump and no pin here: they come at stacking.

(cherry picked from commit 94fbec600e2155fff4c05b88894155054569621e)
(cherry picked from commit 09be67cab1968bbadcc698456fb245ec6e94f20a)
2026-11-03 07:56:21 -08:00
Anees Iqbal e23bd582ca Name Feature::Constant in ConstantRecord's doc without a link
ConstantRecord lives in metal2vulkan-air and metal2vulkan re-exports it in its error module. Its
doc linked [`Feature::Constant`], which rustdoc resolves to the AIR crate's Feature. The
reference that scripts/api-docs renders does not document that Feature, so the link rendered as
bracketed text and the script failed ("links that did not resolve": error/index.html and
error/enum.ConstantRecord.html). The doc now names the variant in plain code. The constants-record
change that added the doc introduced this.

Verified: scripts/api-docs passes.
(cherry picked from commit 139b3b3d37b9eacb075189d3d7f47c72bd4e28c6)
(cherry picked from commit 24e85e53141c571acc78f402d42bbb279a253256)
2026-11-03 07:56:21 -08:00
Anees Iqbal 7e48216b37 Make the canonical encoding's image scratch without zeros
What: under ExtendedRangeBlitPolicy::Canonical, a blit into a compressed BGRA10_XR or
BGRA10_XR_sRGB image rewrites its texels through a scratch buffer: a copy out, one dispatch a
region, a copy back. The scratch was made with Device::own_buffer, which zeroes a Private buffer
in a submission's first work (a copy of the device's zeros on a device with unified memory, a fill
on a discrete one), in a command buffer of its own. The copy out writes every byte the dispatches
and the copy back read (the regions, tightly packed) and nothing reads the alignment gaps, so the
scratch is now made with Device::unzeroed_buffer (Private, tracked as before), as shadow_merge's
fully written scratch already is. Nothing the program or Metal observes changes; the work counts
do.

Why: the whole-set conformance cost check on the M3 Max read compressed-blits-bgra10xr and its
sRGB twin over their records since 4b194d24af (which added the Canonical form and which the suite's
exact policy selects). Each case alone, cost --runs 8 --show, debug build, MoltenVK 1.4.2:
- 452c17aa2c (before) -> 4b194d24af: command_barriers 5 -> 24, command buffers begun and
  submitted 11 -> 14 (batch work 2 -> 5), cmd_copy_buffer 2 -> 7, cmd_copy_buffer_to_image
  7 -> 12, cmd_copy_image_to_buffer 6 -> 11, cmd_pipeline_barrier 18 -> 44, 9 dispatches.
- 4b194d24af -> this change: command buffers begun and submitted 14 -> 11 (batch work 5 -> 2),
  cmd_copy_buffer 7 -> 2, cmd_pipeline_barrier 44 -> 37; nothing else moved. The copies out and
  back, the dispatches and the encoder's barriers around them are the rewrite itself.

Test: runtime_lane::compressed_blits::extended_range_blits_write_metal_s_encoding_under_the_canonical_policy
now asserts that a blit into each Private texture, compressed or not, records no buffer-to-buffer
copy and makes no zero fill (WorkCounts::commands_recorded.cmd_copy_buffer +
new_buffer_zero_fills), under both policies.

FAST-PATHS: the Canonical row's cost column no longer lists the zeroing command buffer, and says
its figures were taken while it ran.

Verified on the M3 Max (MoltenVK 1.4.2), --cfg m2v_gpu: the test passes; with the scratch made by
own_buffer again it fails under Canonical ("BGRA10XR optimized true, 64 high, blitted in on Apple
M3 Max under Canonical", left 1, right 0) after passing the Kept leg. Conformance suite (no cfg):
1010 passed. Runtime behaviour changes (counts only): RUNTIME_VERSION is left to the stacker.

(cherry picked from commit 409aafaca513c03f6bad3378de1f0d8af6fdc5f0)
(cherry picked from commit 2b5f0731c54fa66350e88c82fceaed9909dc442a)
2026-11-03 07:56:21 -08:00
Anees Iqbal 209b375767 Pin the runtime sources after the GPU-time long mark
The queue-share change edits the runtime's completion and placement sources; RUNTIME_VERSION 1752
says the behaviour changed. Hash from the pin derivation over the listed runtime and translator
sources.

(cherry picked from commit 715f47be94b579e6ea954c544c8403137368a96f)
2026-11-03 06:50:11 -08:00
Anees Iqbal c11497e7a3 Bump RUNTIME_VERSION to 1752: a queue is marked long by its command buffers' own GPU time
Adaptive VkQueue sharing now marks a queue long only when one of its command buffers' GPU
timestamps spans more than 2 ms, and a device without readable, calibrated timestamps does not
share (WorkCounts::queue_sharing_untimed). Placement, and so what a recorded run did, changes.

(cherry picked from commit a460f320ebb3c1ef6ce8d983adeef9e9d0af39ca)
2026-11-03 06:50:11 -08:00