Commit Graph
76 Commits
Author SHA1 Message Date
Anees Iqbal 1156d66df8 Runtime: a command buffer whose submission is a Managed copy-in counts no stage
A command buffer with nothing for the GPU that takes a Managed buffer's copy-in has the copy-in as
its submission and completes after it. Its retirement gives it one GPU time, at its queue's last end
or its kernel end, whichever is later, as Metal reports a command buffer with nothing for the GPU,
and it fed those same times to the runtime's stage metric. So the copy's whole GPU run was counted
in gpu_end_to_handler, with its steps and tail, the figure the round and the plays read as
completion latency. The perf audit found it on the gb-3090-r3 play on the RX 7900 XTX: 52 command
buffers over 16 ms. One copy-in it dumped was 274 MB and 38.8 ms of GPU time, about 7 GB/s (jobs
m3-max-86564, m3-max-86566). The copy itself is Metal's didModifyRange: point on a discrete GPU;
only its attribution was wrong.

The submit thread now marks such a command buffer as its group goes. For each copy-in that
Captured::take hands to a lead, the finished member with that lead's number gets
Gpu::copy_in_only, if it has nothing for the GPU. An empty command buffer has one segment, so it is
always among the finished. Retirement leaves a marked command buffer out of scheduled_to_gpu_start,
gpu_run and gpu_end_to_handler, and out of the behind, steps and tail sums that go with them. Its
commit_to_scheduled still counts. What the guest sees does not change: gpu_start_time and
gpu_end_time are still one time, computed as before. A command buffer with nothing for the GPU that
took no copy-in counts as before.

Why leave it out rather than count the copy-in's own timestamps as its run:
- runtime_command_buffer_gpu_nanos already counts the copy-in's run as the runtime's own, and its
  doc says that is no Metal command buffer's gpu_run.
- A member of a group sent member by member retires before the copy-ins of its submission, so its
  retirement could not read their timestamps without moving the copy-ins' retirement.
- gpu_run would then differ from the command buffer's own gpu_end_time - gpu_start_time, which
  stays Metal's answer.

Test: empty_commit_takes_named_ranges (tests/managed.rs) now asserts the stage counts the command
buffer added: [1, 0, 0, 0] where its one submission was the copy-in, [1, 1, 1, 1] otherwise. Its
existing assertions show the path ran: 256 bytes captured, one submission, one runtime command
buffer.

Red: at 6f6e322f16 (scratch; development plus the test alone), on lavapipe (llvmpipe, LLVM 23.1.1;
job m3-max-86583), the declared-buffer and no-effects-dispatch tests fail in the two-copy view, each
counting [1, 1, 1, 1]. 39 of the 41 selected tests passed and 2 failed.
Green: at e6bdfe999a (scratch; this tree on development), on lavapipe (job m3-max-86581), the
runtime's Managed, gpu_span and stage-histogram tests passed: 41 passed, 986 skipped (filtered).

Docs: the doc of Metrics::scheduled_to_gpu_start and the runtime README now name this exclusion.
runtime-sources.sha256 does not change, because no input of its fingerprint changed (pin-compute.py
reads 3b7da9e9).
2026-12-04 11:09:57 -08:00
Anees Iqbal 07ec04e0d4 Runtime: memory both the waited uploads' part and the group's first part use stays acquired between them
The own part for uploads the host waits for (a6dda529a6) released all it
used at its end and the group's first part acquired all it used again:
where both use one block, one more release and acquire than the single
part before. On the RX 7900 XTX (RADV) that pair put the group's GPU end
97 us later in the scratch probe (a 256 MiB fill touching the export the
waited zero fill is in; group GPU end from the resume, median of 8
alternated runs: 799 us red, 896 us green, run ranges apart; job
m3-max-84216), while the Iris Xe (84176, 1.001) and the RTX 3090 (84191,
0.976) showed none.

parts() now takes what each part acquires and what it releases as two
lists. Where the uploads go as a part of their own, submit() gives that
part an acquire of all they use and a release only of what the group's
first part does not use; that part acquires only what they did not and
releases all it uses. A block both use is so acquired once and released
once, as in one part; one the uploads alone use is still the other API's
again when the host's wait returns, and the uploads' value is signalled
at their last upload where they release nothing. Handed::is is now
pub(crate) for the difference. Every other part's two lists are the same
list, as before.

Docs (Work::flush, submit's, parts', the counters' external_acquires,
external_releases and restoring_makes_shared, Keep::Restore, RestoreFence,
Block and Surface wait_until_ready, the runtime README) say so. The
plane_parts test gains the shape of both lists.

Verified: jobs to follow.
2026-12-03 11:37:20 -08:00
Anees Iqbal e14ee65c7b Runtime: uploads the host waits for that use shared memory go as a part of their own
An awaited flush (Work::flush and the other flush_awaited callers: a
restoring make, Texture::get_bytes of a texture without named bytes, a
ready wait of an exported block or surface whose making is not yet
submitted, and a call's wait for room in the uploads or the staging
ring) whose uploads go with a group signal the value below the group's
in a batch of their own. Where those uploads used memory another API
shares (a new buffer's zero fill in an exported block, a surface
plane's image an upload holds, a block a copy into a texture's image
reads), they signalled nothing: the wait ended at the release after the
group's first part, so it waited for that part's command buffers, for
as long as they ran.

submit() now gathers what the uploads use of such memory apart from
what the group uses. Where the host waits for them and they use any,
they are a part of their own: leads gains a 0 ahead of the group's
(prepended to the member-by-member leads where the group goes apart),
handed gains their list at its head, and parts() gives that part an
acquire at its head and a release at its end that signals the value the
flush gave (close() already numbers it below the group's first part).
That part goes in the same vkQueueSubmit2 as the part after it, so no
call is added; where the group goes member by member it rides the first
member's call. The group's first part hands its own memory over after
it, acquiring again what both use. Uploads the host does not wait for
are as before. Direct3D 11 plane submissions are now counted per call
from the acquires each call holds, so the call with two parts counts
once. restoring_makes_shared keeps its condition and now counts the
makes that took the own part; its docs, restoring_make_wait_nanos',
external_acquires', external_releases' and d3d11_plane_submissions'
say so, as do Work::flush, the RestoreFence docs, Block and Surface
wait_until_ready, and the runtime README (the restore, the fence
paragraph, the exported block's hand-over, Direct3D 11 planes and the
fence's known gap).

Cost on every awaited flush that rides a group and uses shared memory:
one more acquire and release pair (two runtime command buffers, two
hand-over barriers and one global barrier) and one more VkSubmitInfo2
in the same call.

The plane_parts test gains the own part's shape, as one part and
member by member. Verified: jobs to follow (red e8dbe38dc8 against this
on lavapipe and the Iris Xe).
2026-12-03 11:37:20 -08:00
Anees Iqbal ed55748644 Docs: the runtime README, API.md, REPLAY-STREAM.md and VALIDATION.md state each measurement by its card and driver, not by our job id
The planner widened the job-id rule from the published crates' rustdoc to the four prose docs a
reader takes measurements from. Each lab job id (m3-max-NNNN, and the bare job numbers beside
them) and each commit sha comes out; the ids stay in the commit messages that already carry them.
A measurement keeps the card, driver and OS its sentence names. Where an id was the only basis a
sentence named, the sentence now says what was measured and on what:

- the runtime README's identity-domains paragraph cited five plays of recorded streams; it now
  states what the states-only plays of the 26 kept replay streams on lavapipe show: each makes
  every pipeline state its stream makes, and none of their render or compute states is refused,
  a refusal under the identity domains among them (the plays of jobs m3-max-83458, -83494, -83695,
  -83889 and -83954, each printing refused 0);
- the probe lists name the cards ("probes on the RTX 3090, the Iris Xe, lavapipe and the RX 7900
  XTX"; "probes on a Radeon Pro 5300M and a UHD Graphics 630, both macOS 26.7.1");
- sentences that compared runs by id compare them by order ("failed in one run and passed in two
  others"), and "the same job" is "the same run";
- "rt at <sha>" and "players built from <sha>" become what that build was ("a build of the runtime
  that copied a texture over any import"), or go where the card and driver already say it;
- VALIDATION.md's harness count reads "the harness on lavapipe".

Two README tables lose their Job column (the import-cost table and the guest-buffers table). The
edited paragraphs are rewrapped at 100 columns; a token diff against the parent shows only the
ids, the shas, the two columns and the rewordings above.

submit.rs's three citations of two probe commits (06860a3848 and b15b306d2f) become "measured
with a probe build of the runtime" (and, for the split probe, "that timed each command buffer");
the IN_FLIGHT and infos comments are rewrapped at 100 columns.

So it does not grow back, scripts/api-docs first fails when the four docs name a job id
(`m3-max-NNNN`, or `job NNNN`); CONTRIBUTING.md, API.md's description of the script and ci.yml's
comment on its step say so.

docs/CONFORMANCE-COVERAGE.md is unchanged: its generator has no job column. Its 1772 lines with an
id are all in its last section, The ledger, which quotes the last field of known-gaps-rt.tsv; the
ids are in the ledger's own sentences, which the ruling keeps out.

Not widened, per the ruling: the ledger, known-gaps-rt.tsv, results.py, test comments and the
unpublished crates. The OS is not added to measurements whose sentence named a card and driver
but no OS.

Verified on the CPU with no device, job m3-max-84430 at this commit's tree: cargo fmt --check 0;
the workspace's rustdoc with -D warnings 0; scripts/api-docs 0, and 1 with a job id planted in
docs/VALIDATION.md, naming the planted line (the tree clean after its restore); the refusal
surface's --check 0; the 13 tests that read these docs passed (feature_enables, the floor, the
accepted differences, the precision-note catalogue, the consumer's objects and the guide's
example). Before the commit, no line of the four docs matched the check's pattern, and rustfmt
--check passed on submit.rs.
2026-12-03 09:10:35 -08:00
Anees Iqbal b54d8d46bc Docs: the published crates' rustdoc states each measurement by its card and OS, not by our job id
What: every lab job id (m3-max-N) in a doc comment of the three
published crates' product sources is removed: 91 ids, and one list
written as a range and bare numbers, on 72 lines over 17 files. The
card, driver, OS and probe each sentence already names stay. Each
changed sentence is rewrapped at 100 columns from the id's line to its
paragraph's end. docs/REFUSALS.md is regenerated: its Basis column
carries those doc lines' evidence (14 rows).

Why: the planner's rule. Docs say the measurement (card, OS), not our
job numbers. The ids stay in the commit messages that already carry
them. A token comparison of each file against its parent shows only id
phrases removed: "(job m3-max-N)", ", job m3-max-N", "potluck job
m3-max-N", "(m3-max-N)" and id lists of the same forms. One line that
held only "(job m3-max-49358)." in submit.rs is folded into the line
above it.

Not changed here: the runtime README (217 lines with ids), docs/API.md
(20), docs/REPLAY-STREAM.md (2), docs/VALIDATION.md (1),
docs/CONFORMANCE-COVERAGE.md (1772, generated from the conformance
ledger), plain // comments (blit.rs 3, conformance cases 3, tests 5),
test modules' and unpublished crates' doc comments.

Verified: refusal_surface.py --check passes. basis.rs regenerates
unchanged. runtime-sources.sha256 is unchanged (44066e69...): none of
the files is its input. rustfmt --check passes on each file. Rustdoc,
private rustdoc and api-docs in the job the READY names.
2026-12-03 08:50:04 -08:00
Anees Iqbal 66a1665f51 Runtime: a restoring make counts its two waits, and whether its restore rode shared uploads
The consumer's walk on the Iris Xe reads one long restore span a walk (57.3 and 57.9 ms at pin S),
in a HEIC step whose VA-API decodes write rt's exported blocks, and nothing in the runtime splits
a restoring make's wait, so the walk cannot say what the span waited for. A fenced make waits
twice: for the GPU work already submitted, before the fence's before, then for the progress value
its flush gave, inside the span. That second wait holds the batch that carries the restore (every
upload of any thread not yet submitted, and a group's copies into its textures' images), the GPU
work submitted ahead of it on the one queue and, where an upload of the batch uses memory another
API shares (an exported block's zero fill, a copy from one), the group's first part, since such
uploads signal no value of their own.

Metrics counts, with nothing run beside the work:
- restoring_makes, once each make's wait returned;
- restoring_make_drain_nanos, the fenced make's first wait;
- restoring_make_wait_nanos, the wait for the restore, and restoring_make_wait_submissions, the
  submissions the completion thread had not yet seen complete as it began (more than one: work
  submitted ahead of the restore's batch);
- restoring_makes_shared and restoring_make_shared_wait_nanos, the makes whose restore went ahead
  of a group's command buffers in uploads that use memory another API shares. Each restore's
  upload carries its make's flag (Keep::Restore's, through Restoring), which submit() sets before
  the vkQueueSubmit2 where it sends awaited uploads that share memory with no signal of their own;
  the make reads it once its wait returned.

The runtime README's fence paragraph names the fields. The signature table gains them.
2026-12-03 07:47:34 -08:00
Anees Iqbal 126ee4fdf5 Runtime: a restoring make waits for its restore's batch, not for a group's command buffers
A texture made in place over host memory's import on a unified device restores the bytes under
its image inside the make, and waits for the progress value Work::flush gives: the submit thread's
next submission's. Where a group goes at that turn, the flushed uploads went ahead of the group's
command buffers in the same batch, with one signal at the batch's end, so the make waited for the
guest's command buffers too. The consumer's walk on the Iris Xe saw restoring makes take up to
63.9 ms (9 spans of one photo-decode step, 67.4 ms in all) where the runtime's own makes take
about 3.5 ms.

Now a flush the host waits for (Work::flush, the staging waits, the surface and block ready
waits) marks its uploads awaited. Where a group's submission takes them, WorkState::close gives
them the progress value below the group's first, the value the flush returned, and submit has the
last of them signal it: their batch ends there, ahead of the group's, in the same vkQueueSubmit2.
The make waits for that batch alone. The pre-wait for the work already submitted is unchanged, so
a group submitted between that wait and the flush still lands ahead of the restore on the queue,
and the make still waits for it.

Two cases keep the group's signal:
- uploads that use memory another API shares (a surface plane or an exported block, held or read
  by the uploads' copies) signal no value of their own: that memory is the other API's again only
  at the first part's release, after the part's command buffers, so the wait is for the part's
  value, as before;
- a batch signals a timeline semaphore once (Vulkan 1.4, section 7.2), so where nothing follows
  the uploads in their part, parts gives the part's value in place of theirs.

A flush nobody waits for (the half-region staging flush, the release of held bytes) adds no batch:
its uploads go with the group's command buffers as before.

Docs: submit.rs's module doc and the flush docs; texture.rs's restore comment, RestoreFence and
Buffer::new_texture; Block::wait_until_ready and Surface::wait_until_ready; the runtime README's
restore paragraph, the fence's span, the known gap's span sentence and the two ready waits.

RUNTIME_VERSION moves to the next number above development's: a restoring make, a getBytes read
and the ready waits now end at the uploads' own batch.

Tests:
- restore_batch.rs each_device_returns_from_a_restoring_make_ahead_of_a_groups_command_buffers
  (the commit before this one) passes;
- plane_parts.rs uploads_with_a_value_of_their_own_end_a_batch_that_signals_it_once: uploads that
  signal their own value end a batch of their own ahead of the group's segment, and alone in their
  part they signal the part's value once.

runtime-sources.sha256 is unchanged (a92fe0a8): it covers none of the files this edits.

Verified:
- red, submit.rs at the commit before this one: restore_batch hangs and fails after 10 s, and
  plane_parts' new test fails (the uploads' value and the part's in one batch), on lavapipe
  (llvmpipe, LLVM 23.1.1, job m3-max-83370) and on the Iris Xe (RPL-P, ANV, job m3-max-83373);
- green: restore_batch passes, the make returning with the fill's command buffer Scheduled, and
  plane_parts 4 of 4, on both; the runtime's suite on lavapipe 985 passed (4 skipped), job
  m3-max-83370, and on the Iris Xe 987 passed (4 skipped), job m3-max-83383;
- job m3-max-83370: fmt, the signatures, clippy plain, with --cfg m2v_gpu and with
  --cfg m2v_cpu_icd, rustdoc, the private rustdoc and the API reference check passed; the suites
  3738 of 3739 passed (24 skipped), the one failure the golden table, a bless due on development;
  validation 1337 passed (3 skipped); conformance 1052 passed; the doctests passed.
2026-12-03 04:41:35 -08:00
Anees Iqbal b975709ed0 Runtime tests: a restoring make whose restore goes with a group's command buffers
A texture made in place over host memory's import on a unified device restores the bytes under
its image inside the make: the make flushes the upload that saves them, moves the image home and
writes them back, and waits for the progress value the flush gives (texture.rs). That value is the
submit thread's next submission's. Where a group goes at that turn, its command buffers ride in the
same batch behind the upload, with one signal at their end, so the make waits for them too. The
consumer's walk on the Iris Xe saw restoring makes take up to 63.9 ms where the runtime's own
makes take about 3.5 ms.

This adds a device test that puts the restore and a group's command buffer in one submission and
holds the group's batch back on the GPU, and the test hooks it needs, under the device cfgs alone:
- Work::pause and Work::resume hold the submit thread between passes;
- Work::flushing says whether a flush waits for the thread to send the uploads;
- Work::hold_next has the first segment of the next submission of a group's command buffers wait
  on the GPU for a timeline semaphore the test signals.

restore_batch.rs each_device_returns_from_a_restoring_make_ahead_of_a_groups_command_buffers: on
a unified device whose texture over the import is in place, the test pauses the submit thread,
commits a fill of a buffer of its own, makes the texture on a thread of its own until its restore
is flushed, holds the fill's segment behind the test's semaphore and lets the thread pass. The make
must return while the fill's command buffer has not completed. Ten seconds after the thread passes
again, the test signals the semaphore and fails.

At this commit the test fails: the make waits for the fill's command buffer. Verified with
submit.rs at this commit under the next commit's tests:
- on lavapipe (llvmpipe, LLVM 23.1.1), job m3-max-83370: "the make did not return within 10s
  while the fill's command buffer, in the same submission as its restore, waited for the test's
  semaphore";
- on the Iris Xe (RPL-P, ANV), job m3-max-83373: the same.
2026-12-03 04:41:35 -08:00
Anees Iqbal cb09012f99 rt test: capture's lists for a commit stay bounded when Managed buffers go uncommitted
capture::Changes holds two lists that wait for a commit, both of weak entries:
- the ranges that didModifyRange named, with their index by buffer;
- the bytes of each Managed buffer made since the last commit.
Each list drops the entries of buffers that are gone once it doubles, starting from SWEEP_FLOOR
(64) entries. Nothing tested that bound. A program that makes, names and drops Managed buffers
without committing would grow the lists without limit if the sweep broke.

every_device_bounds_what_managed_buffers_gone_left_for_a_commit makes, names and drops four times
SWEEP_FLOOR Managed buffers, each with its bytes, and commits nothing. With a device copy, each
list and the index fill to the floor and never hold more. With one copy, nothing is listed. The
test reaches the lists through two accessors that exist only for the device tests
(Changes::entries, Work::changes). SWEEP_FLOOR becomes pub(crate) so the test can name it.

Verified in job m3-max-82584, at a commit with the same tree (c3ea874a68):
- with both sweeps disabled in a probe copy of capture.rs, on lavapipe in its two-copy view:
  "after 65 Managed buffers gone, [named, indexed, made] are [65, 65, 65], past 64", red;
- as committed, on lavapipe: one copy [0, 0, 0], two copies [64, 64, 64] at most, green;
- the RTX 5080 Laptop (two copies), under --cfg m2v_gpu: [64, 64, 64] at most, green;
- managed.rs's 37 tests on lavapipe, green;
- signatures, clippy plain, m2v_gpu and m2v_cpu_icd, doc and privdoc, all 0.
2026-12-03 00:13:19 -08:00
Anees Iqbal b7c59c9b9c Runtime: a Managed buffer's first bytes go at the next commit, whatever it names
The first-naming-commit rule (baf1c8a8c9) also held a new Managed buffer's
first `copied` bytes until a commit named the buffer, so a reach before then
read the device copy's old bytes. Metal's device copy holds a buffer's bytes
from its making. Those bytes now go in at the next commit whatever its encoders
name (Changes::made, taken by every commit, merged with the buffer's named
ranges where the same commit takes both); ranges did_modify_range names still
wait for a commit that names the buffer. The made entries are swept as the
named ones are.

Texture::image_bytes, a test helper, now commits a compute encoder that
declares the texture by use_resource, so its commit takes the named ranges of
the buffer the texture lies over.

Lavapipe's full runtime suite at baf1c8a8c9 (m3-max-81741: 957 passed, 2
failed, 4 skipped) failed managed::every_device_places_a_managed_buffer_s_
device_copy_where_the_consumer_says and over::every_device_holds_a_texture_
over_a_buffer_in_place on these two; this fixes both. Not yet compiled.
2026-12-02 21:46:13 -08:00
Anees Iqbal 51ac48c788 Runtime: a Managed range is taken at the first commit that names its buffer
On a device that keeps a device copy, did_modify_range named a range and the
next commit of any command buffer took every range named since. A consumer
that names a range, commits a command buffer that does not use the buffer,
writes the range again with no second name, then commits the command buffer
that binds it had the GPU read the first bytes. Metal on an AMD Radeon Pro
5300M (macOS 26.7.1, 8 rounds each, jobs 81602 and 81644) takes a named range
at the first commit whose encoders bind the buffer (a compute slot, a vertex
slot with a draw), declare it by useResource: or read it in a blit copy, with
its bytes as of that commit; an unrelated commit takes nothing; a buffer named
to no encoder and reached by address keeps its last synced bytes. The Intel
UHD Graphics 630 keeps one copy (jobs 81603 and 81645).

A commit now takes only the ranges of the buffers its command buffer keeps,
which is every way an encoder names a buffer in the runtime:
- a slot of any stage: compute set_buffer, set_vertex_buffer,
  set_fragment_buffer;
- use_resource on a compute or a render encoder (the runtime has no
  use_resources);
- an index buffer; the indirect arguments of a draw, an indexed draw or a
  dispatch; a patch draw's index and control-point buffers and an indirect
  command buffer's range buffer, kept by the same line of the draw as the
  index buffer and the arguments;
- the tessellation factor buffer and the pass's visibility result buffer;
- a blit: a copy's source or destination, a fill, a copy into or out of a
  texture, a synchronize;
- a texture over the buffer, or a view of one, wherever the command buffer
  keeps it (a slot, use_resource, an attachment, a resolve, a blit).
A heap use names none: Metal refuses a Managed heap (jobs 81602, 81603).

A pending range holds its buffer weakly. The pending list sweeps the entries
of buffers gone once it holds twice the entries its last sweep left (at least
64), so it stays bounded by the live buffers with ranges pending.

Tests (tests::managed): the consumer's six calls (red at e1fbce1486 on
lavapipe's two-copy view, m3-max-81614, and on an RTX 2080, m3-max-81606);
each way above, through compute, render and blit encoders and a texture over
the buffer, with a reach by address alone taking nothing; a buffer no encoder
names keeps the bytes taken last; a narrow named range takes its own bytes
alone (unaudited on Metal); a declaration alone takes, a commit with no
commands takes nothing. over_texture's capture commit now names its buffer.

The did_modify_range doc and the runtime README state the rule and its jobs.
Not yet compiled; the green runs follow.
2026-12-02 21:46:13 -08:00
Anees Iqbal 4b7f935a80 Runtime: a texture over host memory's import in place, its bytes saved and written back once
A texture over a buffer in host memory's import (Device::import_host_memory) used to be the counted
copy at every use. Its bytes were copied into an image of its own before each submission that used
it, and back after each write. Now it is in place: the device's linear image, made for host
memory's handle, bound in the import's own memory. The condition is that the external image query
for VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT answers the linear image importable,
compatible and not dedicated-only, and that the image passes the tests of any texture over a
buffer in place.

This is not a new copy. It is the existing last form made smaller: one copy pair in the texture's
life, in place after it, on documented behaviour only.
- Created UNDEFINED: an image bound in imported memory names the import's handle type
  (VUID-vkBindImageMemory-memory-02989), so it starts undefined
  (VUID-VkImageCreateInfo-pNext-01443).
- Saved and written back around the one transition: a move out of the undefined layout may
  discard the bytes (Vulkan 1.4, section 7.1.1).
- Host access by memory-domain operations: host memory has no other side whose release an acquire
  could match (section 11.2.6).

The image's one move home is in the upload ahead of the first command buffer submitted after the
making, from any queue, in this order:
1. a barrier from every earlier command's writes, including earlier submissions on the one
   queue, to the save;
2. a copy of the bytes bound under the image into a Private block taken at the making;
3. the move, in a barrier that waits for the save's reads;
4. the write-back, with a barrier between write-backs, since two imports of the same pages may
   meet;
5. a barrier from the write-backs to every later command and the host.
The block goes back once the upload retires. A later use copies nothing. Where the query offers no
linear image of the format and usage, the texture stays the counted copy at each use. On the Mac
driver that is every render target, since it makes no linear colour attachment.

Counts:
- the two copies count in Metrics::over_copies_host_memory (and over_copies, over_copies_imported,
  bytes_copied), each of the bytes bound under the image;
- new: Metrics::textures_in_place_over_imports counts each texture in place over an import, host
  memory's or a dma-buf's, at its making;
- the replay's frame metrics carry it.

Docs, in this commit:
- AGENTS.md rule 3's first exception gains the planner's clause verbatim;
- the runtime README's Imported blocks gives the form, and states the two VUIDs' rule in plain
  words;
- its known gap gives the pair, the window while the upload runs (a host write may be lost, and a
  host read may see the bytes undefined), and which formats and usages keep the per-use form on
  which driver, by query;
- REPLAY-STREAM.md and Buffer::new_texture's doc follow.

Tests:
- host_in_place gains two checks: a fill submitted before the making and not waited for is in the
  first read, and the texture counts once at its making;
- over_causes, import's texture test and imported_aliases now take either form, asserting in
  place on lavapipe and the copy where the query refuses.

Verified on the system lavapipe (llvmpipe, LLVM 23.1.4), job m3-max-81271, filter host_in_place,
over_causes, import's texture test, imported_aliases, import_overs and layouts: 17 tests.
- Red at the commit before: host_in_place fails at its in-place assertion; the other 16 pass.
- Green, at a tree whose code equals this commit's: 17 of 17 pass. The restore pair is 2 copies,
  512 bytes. In imported_aliases, the Half textures are in place, two pairs for two textures over
  one import. Clippy -D warnings under --cfg m2v_cpu_icd is clean for the runtime and validation.
2026-12-02 20:07:39 -08:00
Anees Iqbal 003d258843 rt docs: an exported block's textures owe a copy in at external_writes_done's host mark, not at an acquire
Since each submission part that uses shared memory hands it over (acquire at its head, release at
its end), `Block::external_writes_done` records no acquire: it marks the other API's writes on the
host side (`Work::exported_changed`, `ExportedOvers::owe`). ExportedOvers' doc still named "an
acquire" as an event that changes a texture's bytes, as did owe's and exported_changed's docs and
four places in the runtime's README (the copy form's planes "copied at each acquire and release",
"an acquire among them", "after its acquire", "the block's acquire"). They now name the mark, and
say the per-part acquire and release change no byte. Block::external_writes_done,
Surface::external_writes_done and the README's hand-over contract already said so. Wording only;
no behaviour changes.
2026-12-02 14:24:12 -08:00
Anees Iqbal 09e7277972 rt: an event's semaphore counts the event's signals, not Metal's values
rt put Metal's 64-bit event values on the event's timeline semaphore as they were. Vulkan bounds
a signal's distance from the semaphore's value and from every signal pending on it by the
device's maxTimelineSemaphoreValueDifference (VUID-VkSubmitInfo2-semaphore-03883), which a
device may report as 2,147,483,647 (two committed profiles do: nvidia-pascal-linux and
runtime-floor; the 780M under AMDVLK reports 2^32 - 1). So an event's first signal of 2^31 or
more, or a GPU signal just above a host value far above the last GPU signal, was outside valid
usage there.

One form on every device: the k-th signal of an event the submit thread stages signals its
semaphore to k (submit.rs stage), and the event keeps each pending signal as (count, Metal
value). Both rise, since a signal not above the highest value submitted or set is still left
out, so the value the host sees is the value of the signal the confirmed count reached
(EventState::value_of), and a wait for a Metal value waits for the count of the first pending
signal that reaches it (EventState::count_reaching). Every signal moves the semaphore by one, so
no signal lies further from its value than the signals pending on it. rt submits no semaphore
wait for an event, so 03884 never applied; the README's known-gap paragraph, which named it and
waits, is removed, and the event paragraph says what the semaphore holds. The completion thread
confirms and takes in counts (EventInner::take_in); reached() now takes the state its callers
hold. No Vulkan call, GPU work or copy is added: per signal one increment and a (u64, u64) pushed
where a u64 was; per host read an index into the pending signals under the lock already taken.

Metal's answer for a lower signal: the MTLEvent.h and MTLCommandBuffer.h headers say nothing of
one; the conformance case event-highest-signal, recorded on an Apple M3 Max under macOS 27.0.1,
reads 7 after 7 then 4 and after 4 then 7, so a lower signal changes nothing. rt matches: it is
left out and takes no count.

The pending signals have no bound of their own: one 16-byte entry each, which the signals the
submit thread has staged bound (256 of one command buffer were pending at once behind the gate
on the RX 7900 XTX, job m3-max-78721). The count cannot wrap: at one signal a nanosecond, 2^64
counts take about 584 years.

the_largest_value_is_kept no longer skips a device whose limit is below u64::MAX, and its
semaphore reads 1. The tests of the previous two commits failed at them on the RX 7900 XTX (jobs
m3-max-78698 and m3-max-78708: the semaphore read 7 for a 7, 2^40 for a 2^40, 9 for a 9).
2026-12-02 14:24:07 -08:00
Anees Iqbal 87081c05bb Runtime: a surface's planes and buffer are handed over together, and its making releases from the general layout
FIX A. An exported surface in place is one memory that its planes' images and its buffer
alias, and Vulkan 1.4 section 7.7.6 makes "the contents of any other resource aliasing the
transferred memory" undefined after a release or an acquire. A part that used only the planes
handed over only the planes, and a part that used only Surface::buffer only the buffer's block.
Now the surface's make gives its planes one handed::Aliases set, which the buffer joins when
Surface::buffer makes it (memory::Block::aliases, Under::Surface's aliases); Handed::keep adds
every living member with any one, so each part's one acquire and one release name the planes
and the buffer as further entries of the same barriers. No barrier is added. The set holds its
members weakly: one gone is handed over no more. The making is not expanded: the buffer has no
making of its own, and the planes' making releases only what was made.

FIX B. The making released each plane from the undefined layout, while every later acquire and
release names the general layout, and a release's layouts are its acquire's (section 7.7.6). Now
Upload::hand_over records, for a making, the planes' moves out of the undefined layout first,
within the runtime's queue family (handed::moves, Image::making_move), counted in
Metrics::upload_barriers, then the release from and to the general layout. One barrier more per
surface at its making; nothing per picture changes.

The README's making and hand-over text says both.

Tests: ad65d6a70e's two structural tests, red on lavapipe at ad65d6a70e (job m3-max-78062);
the green runs follow in the lane's report.
2026-12-02 05:39:49 -08:00
Anees Iqbal d562f130a6 Runtime: a making's wait for the work lock is a home lock wait; the ready-order test reads the semaphore
Work::create, which an exported block's or surface's make calls to owe its making to the next
submission's upload, waits for the submit side's work lock as a texture's move home does. It now
times that wait as Part::HomeLock, so Metrics::home_lock_waits counts it again; the hand-over change
moved the surface make's upload entry into Work::create and left the wait untimed, and
make_parts' every_device_times_an_exported_surfaces_make_by_part expects one home lock wait per
make. The counter's doc names the exported make.

every_device_completes_a_surface_s_making_before_its_ready_wait_returns read the device's
completed progress (Done::completed), which the completion thread raises after the progress
semaphore does; the ready wait returns on the semaphore. The test now reads the semaphore's own
value (vkGetSemaphoreCounterValue), which the ready wait's return orders after.

Failing before: both tests on lavapipe (llvmpipe), runtime suite job m3-max-77883 at 6559c48acd.
2026-12-02 05:39:48 -08:00
Anees Iqbal 2113de81cb Runtime: the hand-over's private docs name Image::making and Upload::hand_over
6559c48acd renamed Image::made to Image::making and folded Upload::make_handed into
Upload::hand_over, and four private doc links still named the old items: the private-items
rustdoc of the runtime failed on them (job m3-max-77880, the Linux node's privdoc step; its
public rustdoc, gpu clippy and the validation crate's clippy passed there).

Verified by the next privdoc run, reported with the lane's tip.
2026-12-02 05:39:48 -08:00
Anees Iqbal d0a424060a Runtime: each submission that uses memory another API shares hands it over; the release calls are gone
A consumer's video path showed green frames. Its paths call external_writes_done before each
picture and a release only in their encode fills, so every acquire of an exported block or surface
after the first had no release of the runtime's to match (VUID-vkQueueSubmit2-commandBuffer-03879),
and whether memory another API wrote was acquired, or discarded, depended on the order the
consumer's calls arrived in. f6fe21431c's test shows it: no submission released the surface.

Now one form serves every kind of memory another API shares, the form Direct3D 11 planes already
took (crate::handed): each vkQueueSubmit2 part whose command buffers or uploads use an exported
block, an exported surface's planes in place or its buffer, or a Direct3D 11 plane acquires all of
it from the other API's queue family in one barrier, in a runtime command buffer at the part's head
after a global barrier, and releases it in one barrier in another at the part's end, which takes
the part's last signals. Per such part: 3 barriers and 2 runtime command buffers; no submission,
VkSubmitInfo2 or semaphore wait is added. The uploads' copies into textures over a buffer in an
exported block go with the first part, which hands that block over too.

Exported memory is the runtime's until its making (Work::create): an exported block's buffer is
released, and an exported surface's planes in place move out of the undefined layout and are
released in the same barrier, in a runtime command buffer at the head of the submission that takes
the make's upload, ahead of any acquire. The upload owes the making by weak reference, so a surface
or block dropped first owes nothing and holds nothing. The making's submission is the ready point:
Surface::wait_until_ready waits for it in both forms (the copy form's is its block's), and the new
Block::wait_until_ready is its twin (Metal counterpart none; refuses a block that is not exported;
has the submission go at once, so it returns with no command buffer committed). One barrier at the
making, nothing per frame beyond the per-part hand-over.

external_writes_done keeps only its host-side mark: on a block (and a copy-form surface) the
textures over it take its bytes again; in place and on a Direct3D 11 import it records nothing.
Surface::buffer records nothing at its make. A block that is not exported is still refused.

Deleted, with no replacement: BlitCommandEncoder::release_to_external and
BlitCommandEncoder::release_surface_to_external, and Building::release_command, which only they
used. Consumer uses (the consumer's checkout, searched for main): release_to_external at
vaapi/fill.rs:599 and nvidia/encode/fill.rs:289, each followed by EndEncoding, commit and the
consumer's CPU wait; its wrapper trait method BlitEncoder::release_to_external
(core/platform/blit.rs:395, a cfg(unix) no-op default) and the RtPlatform impl
(rt_platform/blit.rs:992-999); doc mentions at rt_platform/export.rs:33, vaapi/fill.rs:30 and
nvidia/encode/fill.rs:18. release_surface_to_external: zero uses. The consumer drops them all in
the pin that takes this commit.

The guard the planner asked for: a plane's image in place takes its tiling from InPlaceTiling
alone, whose values are LINEAR and the DRM_FORMAT_MOD_LINEAR modifier, never OPTIMAL; the
device-free test no_plane_in_place_takes_the_optimal_tiling pins it. The order test
every_device_completes_a_surface_s_making_before_its_ready_wait_returns checks that each plane
owes its move at the make and none once the wait returns, with the device's completed progress at
or past the ready point. The export, surface and Direct3D 11 tests now count one acquire and one
release per submission and one release at the making, with no release call.

The runtime README states the contract (The hand-over contract): nothing another API writes may
be handed memory of ours before that memory's ready point; the other API's next write must not
begin before the submissions that used the memory have completed; who waits by kind and what a
reader gets where no write landed; no optimal image in memory another API writes in place
(section 12.11), the Direct3D 11 import being the documented case (section 12.10.1, Table 17).
Its known gaps carry the planner's line on host-pointer memory. docs/REFUSALS.md is regenerated
and the signature table blessed (one added, two removed).

Checked before this commit: clippy of the runtime, all targets, plain and under --cfg
m2v_cpu_icd, on this commit's code less its doc changes (job m3-max-77874). The device runs at
this commit (lavapipe, the Radeon 780M, the UHD 630) follow and are reported with the lane's tip.
The dma-buf import half is not built.
2026-12-02 05:39:47 -08:00
Anees Iqbal ad49a715ff Runtime tests: a group sent apart is read from the values its members were given, not by a clock
every_device_signals_each_member_of_a_group_sent_apart failed once on llvmpipe in the merge check
at 1da727a583 (m3-max-77710, lvp_rt: "no value between the busy work's 6 and the group's 9 before
L's end") and passed at 2f5f35ca47 (m3-max-77732) and in round 89fb420796-1202-0117. Its proof
needed a host thread polling the progress semaphore to catch A's value inside the 4-10 ms between
A's end and L's: on a loaded CPU device the thread can be off the CPU for the whole window. The
specification bounds when a timeline signal is seen only from below (a submission's signal
follows its own commands), so a device that showed the value late would also fail it.

The deterministic form the planner asked for, a wait on an event instead of the clock, has no
valid Vulkan shape here. A GPU wait on a host-set event is defunct: "Events signaled by the host
must be signaled before the command buffer waits on those events" (6.6; also
VUID-vkCmdWaitEvents2-pEvents-03840). The runtime's own shared-event wait holds L on the host
until the event is met, so L would never join A's group.

So the test now reads what the runtime gave each member as the group went: Work::assigned, a
record kept for the device tests (as Work::acquired is), of each group member's place in the
commit order and the progress value it retires at. It asserts A then L in commit order, the
busy work's last value < A's < L's = the group's last, and still one submission each. The
timings (A's handler and L's GPU end, from A's GPU end) are printed, not asserted, and so are the
values.

Verified: nothing run yet for this commit; the merge check's lvp_rt and clippy in the device
configurations run it next.
2026-12-02 02:06:32 -08:00
Anees Iqbal 74c3940054 Runtime: the Direct3D 11 tests and the sparse wait compile on Windows without warnings
Three fixes the Windows cross-build of 7c5df5a317 found (the gnullvm target under --cfg m2v_gpu,
job m3-max-76160):

- The maxExtent refusal test printed a vk::Extent3D and the first-use test compared and printed
  vk::ImageLayout values with Debug, which ash's types do not implement here: the extent prints
  as its three numbers, and the layouts compare and print as their raw values.
- Since the part builder returns the parts, the only change to them after it is the sparse bind's
  wait, made on Unix hosts alone, so `let mut parts` was an unused mut on Windows (a warning, an
  error under -D warnings). The owed wait is now read into one binding on every host, None where
  the host has no such import, and the mutation compiles everywhere.

No behaviour changes.
2026-11-26 22:59:32 -08:00
Anees Iqbal 7c5df5a317 Runtime tests: a Direct3D 11 plane's first acquire before any access names the undefined layout
A plane's image is made undefined (VUID-VkImageCreateInfo-pNext-01443), and Vulkan takes it as
general only "when they are accessed in Vulkan after external access" (section 12.5.2). Every
acquire of a plane names the general layout as its old layout, the first included, so where rt
uses a plane before any Direct3D 11 access (a transfer fill of a new target, or a command buffer
that writes the plane first), that acquire's old layout is neither the image's current layout nor
undefined (section 12.5.1: "the old layout value must either equal the current layout of the
image subresource (at the time the transition executes), or else be VK_IMAGE_LAYOUT_UNDEFINED").

This test states the rule and fails on this tree:
every_device_acquires_a_direct3d_11_plane_from_undefined_only_before_any_access (Windows, m2v_gpu).
rt writes picture 3 into a new surface's planes before any Direct3D 11 access: each plane's first
acquire must name the undefined layout, and the acquire of rt's next read, after Direct3D 11 read
picture 3 exactly, the general layout. On a surface Direct3D 11 drew first and the consumer
reported by external_writes_done, every acquire names the general layout, the first included, and
rt reads picture 1 exactly: the control, which passes here.

The acquires are read from Work::acquired, a record only the device tests compile: each plane
acquire's image and old layout as the hand-over records it, in recording order.
2026-11-26 22:57:39 -08:00
Anees Iqbal 2d6ed58921 Runtime: each vkQueueSubmit2 part hands its own Direct3D 11 planes over
A group sent member by member is one vkQueueSubmit2 a part, each with a progress value of its own,
and each command buffer retires at its own part's value. The planes' hand-over was per group: one
acquire ahead of the first part and one release at the end of the last, taking the last part's
signals. A member ahead of the last that used a plane was then seen complete before that plane's
release had run, and the consumer's precondition (rt's command buffers that use a plane have
completed before Direct3D 11 accesses it) let Direct3D 11 take the plane while rt still owned it,
its release still queued (Vulkan 1.4, section 12.10.1: "Ensure the release operation has completed
using semaphores or fences"; 7.7.6: an ownership transfer may access all memory bound to the
subresource). Found by reading; whether any run met it, and whether it made a hang on any driver,
is not known.

Now a group records which planes each part's segments use, by the part the segment is in (the
leads before it), from what each segment keeps (Segment::planes), and the part builder hands each
plane-using part's planes over in that part: the acquire at its head, after the global barrier as
before, and the release at its end, taking that part's last signals, its progress value among
them, so it adds no submit info and no submission. The uploads' planes go with the first part. A
group sent as one part is unchanged: one acquire ahead of everything, one release after
everything. Each plane-using part of a group sent apart adds one acquire and one release command
buffer, with no wait, copy or submission added.

Metrics::d3d11_plane_submissions now counts vkQueueSubmit2 calls that hand planes over: a group
sent as one counts once, a group sent apart once for each of its calls that uses a plane. The new
Metrics::d3d11_plane_parts (no Metal counterpart) counts the calls among those that are parts of a
group sent member by member: the path's evidence. The Ownership paragraph (d3d11.rs), the runtime
README, Segment::planes, external_writes_done, release_surface_to_external and the metric docs
say per vkQueueSubmit2 where it was per submission. api_signatures.tsv blessed for the new field;
docs/REFUSALS.md unchanged by its regeneration.

The test commit's plane_parts tests (no device), red on that commit (job m3-max-76147), and its
Direct3D 11 apart test state this form; the apart test now asserts d3d11_plane_parts too.
2026-11-26 22:49:51 -08:00
Anees Iqbal dbd332e087 Runtime tests: each part of a group sent apart hands its own Direct3D 11 planes over
A group sent member by member is one vkQueueSubmit2 a part, each part signalling a progress value of
its own, and each command buffer retires at its own part's value. The Direct3D 11 planes' hand-over
is still per group: one acquire ahead of the first part and one release at the end of the last, so
a member ahead of the last that used a plane is seen complete before that plane's release has run,
and the consumer's precondition (rt's command buffers that use a plane have completed) lets
Direct3D 11 take the plane while rt still owns it (Vulkan 1.4, section 12.10.1: "Ensure the release
operation has completed"). Found by reading; whether any run met it is not known.

These tests state the per-part form and fail on this tree:

- plane_parts (no device, every leg): the part builder, now its own function (`submit::parts`)
  with the per-group placement unchanged, given a group of an upload and two leads and the planes
  each part uses. Each plane-using part must acquire at its head and release at its end, the
  release taking the part's signals and progress value; a part using no plane takes neither; the
  uploads' planes go with the part ahead of the first lead. The negative control, a group sent as
  one part, hands over once ahead of everything and once after, as today, and passes here.
- every_device_hands_direct3d_11_planes_over_in_each_part_of_a_group_sent_apart (Windows,
  m2v_gpu): behind a queue's busy work, a read of the planes and a second command buffer join one
  group; a run of 1 s seen before it goes (QueueInner::ran, the state retirements set) sends it
  member by member. Two reads must hand over twice each way and make two vkQueueSubmit2 calls; a
  read and a buffer copy once each way in two calls. Sent as one part (send_now), the two reads
  hand over once: the control.

The extraction moves no command buffer: the acquire still leads the uploads and the release still
takes the last part's last signals.
2026-11-26 22:46:01 -08:00
Anees Iqbal 5cd3228dbc Runtime: Shared coherence's flushed bytes by point, and the host time inside its calls
What: six public Metrics fields, after shared_coherence_failures.
- shared_reach_flushed_bytes, shared_retire_flushed_bytes, shared_event_flushed_bytes and
  shared_staging_flushed_bytes: each flush's bytes once more, by the point that made it
  (coherence::Point: the flush before a submission; the settle as a command buffer retires; the
  settle before a GPU-raised shared event value is seen; the runtime's own host accesses:
  replace_region, upload_region, get_bytes and the zero source). A settle's flush counts at its
  settle's point.
- shared_flush_nanos and shared_invalidate_nanos: host_time() read at each
  vkFlushMappedMemoryRanges and vkInvalidateMappedMemoryRanges call and at its return (a settle
  times its two calls apart), one Relaxed add each. The zero source's flush, made outside
  Coherence, is timed the same way.

The identity: reach + retire + event + staging == shared_flushed_bytes, and
retire + event <= shared_invalidated_bytes <= retire + event + staging (the excess is get_bytes's
settles), for a read made while no call is under way and for the difference of two such reads.
A device whose Shared type is host-coherent holds no Coherence, reads no clock for these and
keeps all six at 0.

Why: issue 182's Meteor Lake session averages 67 MB a frame of flushed and settled bytes, and its
counters cannot say which point carries them, nor how long the driver's calls take. Counting and
timing only: no site narrowed, no form, switch or device check.

Tests (crates/metal2vulkan-runtime/src/tests/coherence.rs): calls() returns the four points with
the five totals and asserts the identity on every delta it reads; each site under the forced view
asserts its bytes at its own point (a fill, a blit, replace_region, get_bytes, a GPU-signalled
event seen, the texture-over-buffer, use_resource, use_heap, function-table, upload and
written-only sites through one_submission); a device with no coherence state counts nothing and
no time over its life; where calls ran the time fields are not 0. A new device test,
a_coherence_state_counts_each_call_at_its_point_and_times_it, makes a coherence state of its own
over the viewed Shared type, so it runs on lavapipe too, where the floor refuses the view: a
flush and a settle at each point count there alone.

Docs: the Metrics fields' comments, coherence.rs's module doc, the runtime README's Shared memory's
coherence and its known gap; api_signatures.tsv blessed (six field lines). refusal_surface.py
--check passes unchanged.

Verified: cargo fmt only when committed; the build and device jobs follow.
2026-11-26 18:48:55 -08:00
Anees Iqbal 0b7d408201 Runtime and replay player: count barriers by cause, the guest's blits and buffer binds, and over-copy bytes by frame
What:
- Metrics counts every barrier in one of seven causes, whose sum Metrics::barriers now is:
  pass_start_barriers (a render pass's first), pass_home_barriers (the move of its attachments
  home at its end), blit_barriers, dispatch_hazard_barriers (a dispatch's own, at a hazard or
  paying one owed), segment_end_barriers, upload_barriers (the uploads' and Managed copy-ins'
  barriers, the over copies they carry among them) and other_barriers (inside a pass, over
  copies in a command buffer, heap moves ahead of a command or segment, releases). Metric::Barriers
  is gone: each site that records a barrier counts its cause, and the shared helpers
  (Building::barrier, alias::record, over::record_side) take the cause from their caller.
- The replay player's executed counters carry the seven, so each frame line prints them.
- The player's stream counts (the guest's, fixed by the stream) add blits, an encoder's copy,
  fill, mipmap, synchronize, reset and optimize commands, and the buffer slots the set-buffer
  calls set on render and on compute encoders, each split into buffer changes (another buffer
  than the slot held, or its first set) and offset-only changes (replay/binds.rs).
- The runtime backend's report adds an `over copies by frame` line: over-copy bytes a frame,
  mean and largest frame, by memory class (Private, Shared) and by cause (pitch, dma-buf, host
  memory, every other cause as own_image), and the number of textures in an image of their own
  the largest frame's calls named (new_runtime/over_frames.rs), from counters the runtime keeps.
- docs/REPLAY-STREAM.md and the runtime README name them; the signatures table blessed (7 fields).

Why: the planner's reading of round d9b644bae7's plays: whether pass-boundary and blit barriers
are half or more of a frame's barriers (the two pass forms), and whether over copies of Private
buffers reach 1 MB or 5% of a frame's copied bytes (the third form), needs the barrier split and
the over-copy split a frame, beside what the guest asked for; the guest's buffer binds per draw
and per dispatch size the descriptor work.

Tests: every_barrier_rt_records_is_counted adds a pass over a texture whose home is shader-read
and checks each cause's count against the barrier commands recorded (pass start 1, pass home 1,
blit 2, dispatch hazard 0, segment end 1, upload 6 or more, other 0);
every_device_places_barriers_at_hazards_only checks the dispatch-hazard and segment-end counts on
dependent, independent and concurrent encoders;
every_device_reads_its_attachment_through_a_texture_after_a_memory_barrier checks the causes on
the feedback-loop and the copy path; the player's
the_stream_fixes_its_calls_commits_encoders_draws_dispatches_blits_and_binds checks blits and
every bind count; over_copies_by_frame_give_the_mean_and_the_largest_frame checks the line.
2026-11-25 23:55:46 -08:00
Anees Iqbal 6930e494d6 Tests: guards for the submit thread's wake at a group's last and the expected run's feed
Two device tests, each failing without its change:
- an early member of a group sent member by member leaves its queue's
  retirement count and expected run as they stood until the group's last
  retires: A's handler and L's see the count two apart and the run fed twice;
- while a queue holds a command buffer behind such a group and one more
  submission, the members ahead of the group's last complete without poking the
  submit thread, and the last's completion pokes it once (a count of pokes the
  device tests read).

The apart-group test's long copies and their sizing become helpers the new
test shares.
2026-11-25 15:34:17 -08:00
Anees Iqbal e42fc0cc53 Runtime: a completion wakes the submit thread only when it can leave room
Since each member of a group sent member by member signals its own progress
value, every member retires in a round of its own, and each such round woke
the submit thread while its queue held work. A member's completion cannot leave
room: a queue's submission in flight is the group's, at its last value, and
room changes only as that completes.

The flag that said a queue holds work becomes the value whose completion can
leave room: the first submission in flight of each queue that holds, the lowest
of them; 0 while the thread passes, so a completion during the pass still wakes
it, and none while nothing is held. The completion thread wakes the thread for
a round that reached it, and for a round that fired events or found the device
lost, as before.

On an RTX 3090 (job m3-max-72705, every arm at P0, base, per-member signal,
this, this, per-member signal, base at 8 s), the submit thread's timeslices per
command buffer over the base fell from +47.6% to +16.4% (2 shorts a long, 16
in flight) and from +34.8% to +6.8% (6 shorts a long), and its CPU per command
buffer from +3.94% to +3.51% and from +8.55% to +0.78%, at rates within 0.2%.
The lavapipe test, clippy in three configurations and rt's suite passed with
it (job m3-max-72695).
2026-11-25 15:34:17 -08:00
Anees Iqbal 3f3dc7fd73 Runtime: each member of a group sent apart signals its own progress value
A held group whose summed expected run passes GROUP_RUN as it goes is sent member by member,
one vkQueueSubmit2 each, and only the last call signalled the progress semaphore. A member ahead
of a long one was then seen complete (its status, its completed handlers, waitUntilCompleted)
only at the group's end, late by the GPU runs of the members after it. Metal completes each
command buffer at its own end. On an RX 7900 XTX (RADV) a guest's compute work showed it: its
8-16 ms spans from GPU end to handlers matched its 8-16 ms GPU runs one for one, with submissions
equal to commits, so those groups went member by member.

Each part of such a group now signals its own value, the last part the group's, and each member
retires at its own part's. The calls, their submit infos and the room rule are unchanged: the
queue counts the group one submission in flight, at its last value. Uploads and copy-ins retire
at the group's value as before, and the held-start gap keys on the group's value. A group sent in
one call keeps its one signal.

Verified on lavapipe, job m3-max-72649: the new device test polls the progress semaphore while
a group of a fill A and a long copy L (about 10 ms) goes member by member. In three repeats it
read A's value 59-254 us after A's GPU end, and the group's last at L's end, 9.3-10.9 ms after.
With this commit's runtime files taken back, the counter went from the busy work's value to the
group's at L's end (9.6 ms) and the test fails. rt's suite on lavapipe: 714 passed, 3 skipped.
Clippy with -D warnings plain, under --cfg m2v_gpu and under --cfg m2v_cpu_icd: clean. On
lavapipe A's handler still begins after L's end: the round before it waits in
vkGetQueryPoolResults behind the queue's execution there (jobs m3-max-72643, m3-max-72616), so
the handler times are read on a card.
2026-11-25 15:34:17 -08:00
Anees Iqbal 412bce0bd5 Runtime: a coherent device's command buffers carry one None pointer of coherence, boxed
The planner's form A after the XTX budget job 74002 read burst_2000 as a loss (+139 user-space
instructions a command buffer at 3363435164). A device whose Shared type is host-coherent now
moves 8 bytes of coherence state with each command buffer and each batch instead of 40 and 48,
and three further items are development's own code again.

What a coherent device's command buffer did that development's does not, before this commit
(at 3363435164), with its cost and what this commit does:
- command.rs:300 `Gpu::coherence: Option<coherence::Recorded>`, 40 bytes (atom 8, the Writes
  Vec 24, reach 8), inside `Building` too. With one compute encoder a command buffer moves it
  by value about 14 times: into its Arc at the make (command.rs:413), open_encoder's take into
  the encoder (command.rs:470, encoder.rs:476), the encoder's take at its end (encoder.rs:1053),
  close_encoder (command.rs:484), the commit's take (command.rs:690), `Pending { gpu }`
  (command.rs:719), `Work::commit` into its entry (submit.rs:1604), `group.finished`
  (submit.rs:1999), the completion's `Retiree { Item::Command { gpu } }` (complete.rs:340) and
  its pop, and `retire(gpu)` (command.rs:1782). That is about 2-4 instructions a move for 40 more
  bytes. NOW `Option<Box<Recorded>>` (command.rs:301), one pointer, `None`; the box is made at
  the make on a device that is not coherent (command.rs:410, `Coherence::recording`). It is made
  at the make, not at the first write: a lazy box would need each recording site to read the
  device's coherence through its core, or an atom kept outside the box, and the commit still
  finds a reach from kept buffers with no write.
- submit.rs:546 `Batch::flushes: Option<Flushes>`, 48 bytes (two Vecs), moved with each batch.
  NOW `Option<Box<Flushes>>` (submit.rs:548), one pointer, `None`, boxed at the batch's first
  reach or copy-in (submit.rs:1924, 2068).
- counters.rs:661 the five coherence counters sat after `submit_infos`, moving every later
  counter 40 bytes from its place in development, including the submit thread's
  `submit_call_nanos` and the lock-wait counters (a layout change, no instruction). NOW they
  follow every other counter (counters.rs:892), so every development counter keeps its offset.
- encoder.rs:1223 and render_encoder.rs:2466, the dispatch's and the draw's facts: two tests
  (the encoder's recording, then its coherence) where development tested nothing. NOW
  development's `facts.host` is tested first (encoder.rs:1225, render_encoder.rs:2468), so a
  kernel or draw that writes no memory the host reads takes that one test.
- command.rs:1806 the retire: one test of the `None`, then its drop glue at the destructure, a
  second test. NOW the field moves out once (command.rs:1813) and the one `if let` takes it, so
  a `None` is tested once; `Gpu::is_empty`'s body is `nothing_for_the_gpu` over the segments, so
  the retire reads them past that move.

Left on a coherent device, each development's code behind one test of a `None` pointer: the
make (command.rs:410), the commit (command.rs:671), each command site (blit.rs:250, 495, 623,
745, 902, 1118; render_encoder.rs:901, 1618, 2041; encoder.rs:880; and the facts sites above),
the segment join (submit.rs:1923), each copy-in (submit.rs:2067), the submission
(submit.rs:2713), the retire (command.rs:1813) and each completion wake with listeners
(complete.rs:766); about 2-3 instructions each. The 8-byte pointer in `Gpu` (and so in
`Building`) and in `Batch` moves with them. Not per command buffer: each event's `settled`
field and a staged span's memory and size.

On a device that is not coherent the calls and ranges are as before; each command buffer
allocates its box at its make, and each batch at its first reach or copy-in.

Verified: cargo fmt. Not built when committed; the build job and the device and budget jobs
that follow name it.
2026-11-25 14:24:29 -08:00
Anees Iqbal 300747079a Runtime: a coherent device's command buffers hold no coherence state, behind one test each
On a device whose Shared type is host-coherent, the per-command-buffer path is development's
own code behind one test of an Option; nothing is built for the absent state.

Built per command buffer before, on a coherent device:
- an empty `coherence::Writes` and an `Option<Arc<Ranges>>` of `None` in its `Gpu`, built at its
  creation, carried to its retirement and dropped there;
- at every command that names a Shared write (each blit, render pass attachments, a render
  encoder's Shared buffer store, a dispatch's or a draw's facts, `use_resource`), a read of the
  device's `nonCoherentAtomSize` through the device's core; in both `use_resource`s a range
  slot in the declaration's tuple, filled through `Option::and_then`, and a call that tested it
  and returned;
- in each submission group and empty batch, two empty lists (the ranges of the command buffers
  reached and those of the copy-ins), destructured at submission, the first dropped there;
- on the completion thread, a tuple of two tests at each wake that fires listeners;
- in a shared event's `signaledValue` and wait, development's code restructured: the lock
  taken and dropped before the counter's read, and a call that tested the device's Option.

Left on a coherent device:
- the `Gpu` holds one `Option<coherence::Recorded>`, `None`, from one test of the device's
  coherence at the command buffer's creation; each command site tests it once
  (`Building::coherence`, a field of the recording), each `use_resource` keeps development's
  tuple and tests it once after the access;
- the commit, each segment that joins a group and the retirement test it once; a batch holds
  one `Option<Flushes>`, `None`, tested once at submission; each copy-in tests the device's
  coherence once;
- the completion thread tests the device's coherence once per wake that fires listeners;
- `signaledValue` and the wait are development's code behind one test of the device's
  coherence (`let`-`else`, `match`); each event keeps an 8-byte `settled` field, 0 and never
  read;
- not per command buffer: a staged copy's span carries its allocation's memory and size, and
  `replace_region`, `upload_region` and `get_bytes` test the device's coherence once each; the
  zero source's make takes one flag.

A device whose type is not host-coherent records into `coherence::Recorded` what the two
fields held, and a batch builds its `Flushes` only where one of its command buffers or copy-ins
reaches Shared memory; the calls and their ranges are as before.

Test: the device test of each device's coherence state now asserts that a new command buffer
holds the state exactly where its device does.

Verified: cargo fmt. Not built when committed: no build runs on this host; the build job and
the device jobs that follow name it.
2026-11-25 14:24:29 -08:00
Anees Iqbal 31ca7f6779 Runtime: Shared coherence only where the Shared type is not host-coherent, decided at the make
What: Device::new reads the HOST_COHERENT flag of the memory type floor::choose took for Shared
once, at the make (Coherence::of). Core::coherence is now an Option<Coherence>, built only where
that type lacks the flag. A device whose Shared type is coherent keeps no ranges and makes no
flush or invalidate: every site of the flush form asks the Option first (Building::atom now
answers Option<u64>), so a commit finds no Ranges, a retirement, a submission, a shared event's
signal seen, replace_region, upload_region, get_bytes and the zero source's make each make no
call, and the encoders name no write. flush and settle are now methods of Coherence, so only a
device that holds one can make them. The type rule stays sharedflush's: the first host-visible,
host-cached type, a coherent one first. Where the type is not coherent the form is unchanged.

The flush and invalidate on a coherent type are legal (vkspec 1.4.366, "Host Access to Device
Memory Objects"): "If the memory object was created with the VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
set, vkFlushMappedMemoryRanges and vkInvalidateMappedMemoryRanges are unnecessary and may have a
performance cost." The VkMappedMemoryRange VUIDs name no type flag: memory-00684, size-00685,
size-00686, offset-00687, size-01389 and size-01390 (offset and size at multiples of
nonCoherentAtomSize or the allocation's end, inside the mapped range). So the device suite can
run the form on memory that is coherent in fact, through the test-only memory view.

tests::coherence: every device holds a coherence state exactly where its Shared type is not
coherent, and its work's calls follow (zero calls where it holds none); every GPU read through
the refused device's view (crate::tests::cached_types_incoherent) holds it and makes sharedflush's
counted calls. README, the Metrics docs, floor::SHARED_MEMORY and MemoryClass::Shared say the
calls happen only where the type is not coherent; the known gaps say no lab device can show a
missed flush, only a device whose Shared type is cached and not coherent can.

Why: sharedflush's form, with its calls on every device, cost 1.038 to 1.047 of the runtime's
instructions on four harness rows on the 780M (m3-max-73790). This is A-narrow, offered to the
owner beside B: an eleventh form, so it does not land without his word.

Verified: not yet run (cargo fmt only).
2026-11-25 14:24:29 -08:00
Anees Iqbal e13ed258d5 Runtime: Shared coherence's bookkeeping trimmed; a Managed buffer's device copy is its GPU reach
What:
- BufferObject::shared_range (and shared_span) answers None for a Managed buffer with a device
  copy. Its commands reach the copy, so neither a command buffer's reach at submission nor its
  writes at completion name the block of the buffer's bytes. Two calls touch that block: a
  copy-in (did_modify_range), whose submission flushes the bytes it reads
  (CopyIn::shared_ranges), and a synchronize (read_back), which now names the block's bytes
  itself (Range::of_block of the held block) as a write, so its command buffer's completion
  flushes and invalidates them. Each of the two flushes or invalidates its own bytes there,
  which is why the GPU reach can leave the block out.
- Writes holds a Vec, not a HashSet: no hashing, and no RandomState per command buffer. A range
  named again right after itself is held once, and the ranges are merged in place each time
  their count reaches a power of two from 64.
- merge() sorts and merges in place (Vec::dedup_by) in place of merged()'s second Vec.
- flush and settle build their VkMappedMemoryRange array on the stack for up to 8 ranges.
  settle builds it once for both calls and sums the bytes once.
- A submission of one command buffer and no copy-in flushes that command buffer's ranges,
  already merged at its commit, with no new Vec.
- README and module doc: the submission's reach leaves out a Managed buffer with a device copy.

Why: job m3-max-73772 (RX 7900 XTX, c030b1b4bd against 4fb7684a62, three alternated passes)
put the runtime's own instructions per timed run 4.7 to 6.7% over the before arm on the frame
and burst rows, about 1,300 to 1,600 instructions a command buffer, past the 1.03x gate. Job
m3-max-73773 (Iris Xe) put them about 1,650 to 1,700 a command buffer over. Most of that was
heap allocation and hashing per command buffer, and on a discrete GPU a Managed buffer's host
block counted as reached. Same form: every call is still made on every device, with no branch
on the type's flags.

Verified: not yet run (cargo fmt only). The alternated job is re-run on the 780M first, then
the XTX.
2026-11-25 14:24:28 -08:00
Anees Iqbal 2c4680acea Runtime: Shared storage takes a host-cached type, flushed and invalidated on every device
What: the floor's Shared item becomes host-visible and host-cached; Shared storage takes the
first such type a buffer can use, a host-coherent one first (floor::choose). A new module,
coherence, makes the flushes and invalidates Vulkan asks of a type without
VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, on every device, never reading the type's flags:

- before each submission, a flush over the Shared memory its command buffers keep (buffers,
  textures over buffers, heap blocks) and the ranges its Managed copy-ins read;
- before the host can see GPU progress, a flush then an invalidate over what a command buffer
  may write: as it retires (before its status, waits and completed handlers), and over every
  command buffer in flight before a shared event's GPU-raised value reaches a listener,
  signaledValue or a wait. What it may write: blit destinations, written bindings of the
  function's interface, use_resource with a write, render attachments, the visibility buffer,
  synchronize targets, every used heap's Shared block, textures over Shared buffers in images
  of their own;
- the runtime's own accesses: replace_region's staging span flushed after the rows are
  written, get_bytes's span settled before it is read, the zero source flushed at its make.

Ranges are widened to nonCoherentAtomSize inside the whole-mapped pool blocks. Imports are
unchanged (their type is host-coherent; Vulkan maps none of them). Exported blocks and surfaces
take the Private type and have no host mapping (export.rs, surface.rs), so they are never
flushed. Metrics gains shared_flushes, shared_flushed_bytes, shared_invalidates,
shared_invalidated_bytes and shared_coherence_failures.

Why: a Meteor Lake device on Mesa's Intel driver with the i915 kernel driver lists
[DL|HV|HC, DL|HV|HCached] and has no host-visible, host-coherent, host-cached type, so the
floor refused it at device creation. The lab's lists all have an HV|HC|HCached type, which
choose() still takes first: their index is unchanged.

Verified: not yet run (cargo fmt only). Still to come in later commits: README, the generated
refusal surface and signatures table, a device test of the counters, and the device legs. The
flush's effect on that device is unaudited until the user boots it.
2026-11-25 14:24:28 -08:00
Anees Iqbal c553ebbfcb rt: a device with no heap placement of links looks at none, and a command buffer keeps no alias state until it touches one
The instruction bench (job m3-max-71736, lavapipe burst_2000, 2,000 one-dispatch command buffers a
run, A acda405b30 against B 867e059aaf alternated A B B A A B) read own_per_run 50,646,700 against
51,286,684, +1.26%, about 320 instructions a commit: each dispatch walked its slots for placements,
and Building and Segment carried the marks and the part inline. Now the heap ids count the
placements with links (HeapIds::any_linked), and a dispatch, a pass's begin, a draw and a blit
look at their resources' placements only while one has links; Building's marks and a segment's part
are boxed, made at the first touch.
2026-11-23 10:53:22 -08:00
Anees Iqbal 20ddd2daad rt: a heap texture moves from undefined before its next write after an alias's write
Vulkan's memory aliasing asks that an image over bytes another resource wrote move from
VK_IMAGE_LAYOUT_UNDEFINED before it is used. rt moved a heap texture only once, at its making, so a
device that keeps a compression state beside an image's bytes read the alias's state: on the Iris
Xe (ANV, Mesa 26.2.6) a 512x512 RGBA16Float array written through a 2D view after eight aliased
arrays read 8152 of 262144 texels wrong (job m3-max-71690, the test c26698712c).

The form (crate::alias):
- Each heap texture and heap buffer is a Place, linked at placement with the placements of its heap
  whose bytes meet its, both ways and weakly; a release drops its links. A placement with no links
  pays one test at each use.
- A write of a placement makes its links stale. A stale texture's next write moves its whole image
  from undefined to home, in one barrier from every command's writes to every command's reads and
  writes. Reads move nothing; a buffer is never moved. A declared write counts as a write.
- Inside a command buffer, encode order is run order: Building's marks keep each touched
  placement's state (fresh, stale, untouched) and the segment its commands last read it in. A write
  of a stale one moves in place: before a dispatch, a pass's begin or a blit; inside a rendering,
  through the pass's interruption.
- A write of an untouched one adds a check at its segment's head; where the segment read one of its
  links before, the segment ends first. The submit thread resolves a segment's checks as it stages
  it, in the order the device's one queue runs segments (so a command buffer committed out of its
  encode order, or held by an enqueue, is decided where it runs), recording the moves owed into a
  command buffer of the cb's recorder staged just ahead of the segment's, in its submit info and so
  its vkQueueSubmit2; then it applies the segment's writes. A failed record loses the device as a
  failed submission does.
- A texture placed over another's bytes is stale from its making, and its making move waits for
  every earlier write (ALL_COMMANDS / MEMORY_WRITE in place of NONE).
- Metrics::heap_moves counts the moves, in place and leading.

No upload piece: a heap texture sits on a Private block and Metal gives a heap's textures the
heap's storage mode, so no Metal-valid replaceRegion reaches one (TextureBytesPrivate).

The README's gap line now says what remains: a read of a stale texture, writes rt cannot name, a
declared write taken whole, the making move's effect on a live alias's bytes, the move's whole
image, and a draw's check at the head of its pass's segment.

Tests: src/tests/alias.rs holds the state machine on every device of the cfg (commit order against
encode order, the segment ended before a check behind an alias's read, moves in place, a draw's
write through the pass, apart placements with no check or move); the red test is
heap_alias.rs's array test. Gate and device runs follow in the next commits.
2026-11-23 10:43:30 -08:00
Anees Iqbal 0a3625b07e rt: a global barrier from and to every stage before a Direct3D 11 plane's acquire
An acquire from VK_QUEUE_FAMILY_EXTERNAL ignores its srcStageMask, so its
first synchronization scope does not apply, and Vulkan 1.4 section 7.7.6
has the release before it happen-before it. Two plane-keeping submissions
in flight together on rt's one queue (two reads with no wait between) had
nothing that ordered the first's release before the second's acquire:
rt meets event waits on the CPU and adds no semaphore wait.

The head command buffer now records a global barrier, ALL_COMMANDS to
ALL_COMMANDS (record::barrier, Reach::Commands), before the acquire. Its
first scope takes the earlier release ("VK_PIPELINE_STAGE_ALL_COMMANDS_BIT
is the only valid stage to wait on or wait for these operations") and its
second the acquire after it. One more barrier per plane-keeping submission,
counted in Metrics::barriers.

Verified: cargo fmt. The test of two reads back to back and the gate and
UHD jobs follow.
2026-11-23 04:38:55 -08:00
Anees Iqbal 35243bc211 rt: each submission that uses a Direct3D 11 plane acquires it at its start and releases it at its end
A Direct3D 11 surface's planes were acquired from VK_QUEUE_FAMILY_EXTERNAL
by Surface::external_writes_done and released by
release_surface_to_external, one call each, which the consumer had to pair
around every Direct3D 11 access. The consumer never called the release
(zero hits in its checkout at 76c55a4074), so rt kept the planes from the
first acquire on while Direct3D 11 drew into them.

Each submission whose command buffers or uploads use a plane now acquires
it from VK_QUEUE_FAMILY_EXTERNAL in a command buffer of rt's own ahead of
everything (the uploads included) and releases it in another after
everything, both GENERAL to GENERAL (VUID-VkImageMemoryBarrier-
srcQueueFamilyIndex-12332, -dstQueueFamilyIndex-12331): Direct3D 11 owns
the planes' memory between rt's submissions. Planes are kept per segment
(keep_texture), so a submission of segments before an event wait, which
the submit thread meets on the CPU, acquires none of the planes the
segments after the wait use; a segment that signals passes its planes to
the next, as a texture bound after a signal is used by the command that
splits. The two command buffers are uploads, so they retire with the
submission, and the release holds the images. The release takes the
last segment's signals, so no VkSubmitInfo2 is added; nor is a submission
or a wait. Metrics::d3d11_plane_submissions counts each such submission,
and each barrier counts in external_acquires or external_releases.

Surface::external_writes_done and release_surface_to_external record
nothing for a Direct3D 11 surface now; no public item is removed. The
consumer's external_writes_done call (d3d11_surface.rs:93 at 76c55a4074)
stays valid.

Docs: d3d11.rs, the runtime README, the Metrics fields and the two calls
state the per-submission hand-over, and that no keyed mutex is used by rt
or on the textures (SHARED | SHARED_NTHANDLE, not SHARED_KEYEDMUTEX).

Tests: the import test asserts that its three submissions that keep the
planes count three, with three acquires and three releases; the drop
test's three drops now send nothing, no upload holding a plane.

Verified: cargo fmt; api signatures and the refusal surface unchanged
(signatures.py --check, refusal_surface.py --check). The device-cfg
builds, clippy, Rustdoc, lavapipe and the UHD 630 run are named in the
next commit or the landing report. AMD and NVIDIA Windows drivers are
unverified: the lab's one Windows GPU is the UHD 630.
2026-11-23 04:38:55 -08:00
Anees Iqbal e3a3f5c7dc Runtime: the queue cut comes off again
Reverts, in one commit, the nineteen commits of c38852d665..c2088436aa
that carry the queue cut and its order fixes (newest first): 333adf36cf
8828e8ad6c daaccb7bb0 4f683ad891 7cd99ae0b1 5f93a64342 6523e2b65c
76f369dbbf 2bcac43a53 c5e98be51d 635da9d820 1f7f77e4cc 4b1cdaf505
9e8baebc48 b1b375b8e1 40a9982a94 02923fb2ae ec24ba8439 69754cb203.
piece.rs and its tests go, and the README rows on the pieces' cost.

Kept: 6adfe028d8 (a half vector joined from read lanes keeps its bits),
7d8aabed34 and c2088436aa (the 780M import-cost rows). Against
c38852d665 the tree differs only by those three commits' paths and
changes. The cut bumped no version, so none moves here.

Why: the fallback for the Iris Xe regression under the planner's 18:00
PST box. The guest's image step reads take-to-show p90 17.16 ms cold and
24.66 ms warm (Iris Xe, the consumer's walks, job 67930) against 4.34 and
4.42 ms before. The cut, with no green fix tip by the box, comes off with
the one-module move that caused it; the cut continues on its own branch.
2026-11-22 16:25:58 -08:00
Anees Iqbal 333adf36cf Runtime: a head held behind an idle queue's sharer is staged into a group of its own, held
What: next_ready skips a head that sends_past holds only where it would join a group held whose
first command buffer sends_past does not hold. Otherwise it stages the head as before: into a group
of its own, or into a held group whose first is held too. Such a group waits in its queue. It has
no room and wants none, and no host wait sends it through (has_room, wants, goes), until the
earlier commit is submitted.

Why: 530842c0bc skipped every such head, so it stayed committed and unscheduled until that commit
was submitted. every_device_submits_a_write_on_an_idle_queue_before_another_queues_later_read
waits for its reader to be scheduled, held in a group for the device's room. It timed out at the
reader's status on lavapipe (m3-max-68984, 674 of 675) and on the Iris Xe (m3-max-68985, 676 of
677). A held group goes only by those three gates, so staging the head into one changes no
order. Skipping it is needed only where it would join a group that goes before the earlier commit.

Verified: not run when committed; its jobs follow.
2026-11-22 15:37:40 -08:00
Anees Iqbal 8828e8ad6c Runtime: no work goes before an earlier sharer of another queue that Metal submitted at its commit
What: one predicate in submit.rs, WorkState::sends_past(index, pending). It answers whether
`pending`, a command buffer of the FIFO at `index`, would go before an earlier commit of another
queue that Metal had submitted at its commit (Fifo::idle_first: the first command buffer not yet
submitted of a queue committed to it idle, with a part ready) and that shares a tracked resource
with it (by the hazards' ids), or where either reaches memory outside its resources. It replaces
the host-wait-only sends_past and is asked at every place that lets work go:
- next_ready: such a head is not staged, nor a head that would join a group whose first is such
  a one (the head choice);
- has_room and wants: such a FIFO has no room and wants none, so it holds no other queue back by
  rank (the FIFO choice, and the groups that go at once, which stage only with room);
- goes and waits_for_room: no host wait sends it through (the host-wait send).
A group is asked by its first command buffer (Fifo::sends); those that joined it go with it.
wants takes the FIFO's index in place of the FIFO, for the predicate.

Why: the planner's (h3) shape, a regression of the cut. C, committed to an idle queue, is held by
block_shared behind X, a cut command buffer of another queue it shares with. While held, C wants
nothing. D, a sharer of C on a third queue committed after C and sent by no host wait, then took
the room between X's pieces and copied C's buffer before C wrote it. Metal submits C at its
commit, so its hazard tracking orders D after C.

goes_before stays separate. It orders the closes of groups that all go now within one pass and
holds nothing. sends_past decides whether work goes at all. They overlap only for sharers, and
there goes_before still orders the groups that go without a room check: at teardown (stop), and a
fence updater sent through by its waiter (updater_held).

The over-hold row: the holder is still read when the work is staged or takes the room, not at
its commit, as the host-wait rule read it. That is unchanged in kind, but it now covers every send,
not only a host wait's. Two readers of one resource share it here, as in the cut rule (no read or
write mode is kept per resource), so a read waits behind an idle queue's earlier read of the same
buffer, which Metal does not order: an over-hold, now written in the README. No more is held:
an earlier commit not submitted at its commit (its queue's work ahead of it), or one whose next
part waits for an event not yet met, holds nothing, as before.

Seen, not patched (each a shape of its own): updater_held sends a fence updater through to its
waiter with no room check, so an updater held by this rule would still go.

README: the cross-queue paragraph's host-wait sentence now states the rule for every send, the
(h3) case and the over-hold.

Verified: not run when committed; its jobs follow.
2026-11-22 15:37:40 -08:00
Anees Iqbal 2bcac43a53 Runtime: what a host wait sends waits for a sharer of another queue that Metal had submitted
What: a queue sent through by a host wait (Work::send, send_now) goes through only once no command
buffer of another queue, committed before one it sends, the first not yet submitted of a queue that
has submitted nothing since a commit found it idle (Fifo::idle_first), with a part ready, and
holding a buffer or texture it holds by the ids the hazards track them by (or where either reaches
memory outside its resources), is left unsubmitted (WorkState::sends_past). Until then it waits
for the device's room, whose order sends that one first. The runtime README says so.

Why: on the cut the device's room is shared. With busy work of a third queue filling it, a command
buffer that fills, waits for an event and fills again on an idle queue is held up to its wait in a
group for room, and a later command buffer of another queue that copies what it filled and signals
the event, sent by a host wait, went past the room and ahead of it: its copy read none of the
fill. Metal submits the first at its commit and orders the copy after its fill before the wait
(the conformance case event-signaller-of-a-wait, M3 Max, job m3-max-68673). Only such a pair is
held, and only until the first's ready part is submitted; a command buffer committed behind its
own queue's work holds nothing, as on Metal (the README's M3 Max rows).

Verified: pending.
2026-11-22 14:51:17 -08:00
Anees Iqbal c5e98be51d Runtime: a queue whose work all completed takes turn 0 at its next commit, seen or not
What: WorkState::push reads the progress value the completion thread has seen complete
(Done::completed), passed in by enqueue and commit: a queue with nothing queued and nothing in
flight past it takes turn 0, as one that never submitted.

Why: the submit thread forgets a queue's completed submissions only as it next looks (settle), and
a completion with nothing held does not wake it. So a queue whose last submission had completed
kept its old turn at its next commit, and a later commit of another, idle queue ranked before it
(rank) and went first, the first's fill before its wait passed. Metal submits a command buffer
committed to a queue with nothing ahead of it at its commit (the runtime README's M3 Max rows).

Verified: pending.
2026-11-22 14:51:17 -08:00
Anees Iqbal 9e8baebc48 Runtime: behind a cut head waiting for room, what would be sent through waits in its queue's order
What: next_ready does not pick an entry that hold() would send its queue through to (ended before
it went, nothing for the GPU, or presenting: Entry::sent_through, the one condition both now
read) while the FIFO's head that waits for room is a cut command buffer. The FIFO offers nothing
until room comes; the head's pieces go at the room's pace, and the entry goes behind them in the
queue's order, scheduled as it reaches the head (or, presenting, once submitted). The runtime
README's room paragraph says so.

Why: the submit thread spun with the work lock held. Behind a cut head waiting for room
(waits_for_room's None arm), next_ready returned the first entry not held, with waits; hold()
took its early return for it (ended, empty or presenting), raising send_through and leaving it
unheld, and a cut head never goes through on send_through (waits_for_room's `through`), so
nothing next_ready reads changed: pass() continued on Staged and picked the same entry again, for
as long as the room stayed full. Completions are settled only at pass()'s top and commits wait
for the lock, so the room never came back. A cut command buffer of three or more pieces waits for
room at its third piece by room() alone, so the window opened during each such command buffer's
run. The fix holds Metal's order within the queue: the entry completes after the head and is
scheduled no earlier than it.

Verified: the four forms, each a test and a process of its own, hang without the fix and pass
with it on lavapipe; with the compile check, the pieces tests and the runtime suite on lavapipe:
see the jobs named where it is handed over.
2026-11-22 14:51:16 -08:00
Anees Iqbal 69754cb203 Runtime: the queue cut comes back, as it stood at f0b6fff640, for its fixes to build on
This reverts e3d30c5101. With it, the runtime crate, its README, its tests and api_signatures.tsv
equal f0b6fff640 again: the queue cut, its fixes 1 and 2, the cycle fix, the rate inputs of the
tests, and the README's cross-queue rule with its known-gap line.

This branch carries the cut until it re-lands on development as one series. It re-lands when the
spin fix is green in all four forms, and the XTX compute benchmark is within 3% in an alternated
pair or the owner rules on the trade. It also waits for the wait-split sharer fix, if that is the
cut's regression.

Verified: the tree equals f0b6fff640's (git diff f0b6fff640 HEAD is empty).
2026-11-22 14:51:16 -08:00
Anees Iqbal 53bf3a3f3c Runtime: of the groups that go at once, the one committed first goes first
What: before the submit thread closes a group, each other queue's group that goes now and whose
first command buffer was committed before every one it holds goes first (WorkState::goes_before,
Fifo::first_committed), and the group right after, before anything more is staged.

Why: a command buffer that fills, waits for an event and fills again, on an idle queue, is staged
up to its wait into a group that goes only at the end of the pass, as that segment holds no
signal. A command buffer of another queue committed after it, which copies what it filled and
signals the event, went at its signal, ahead of that group, so its copy read none of the fill.
Metal submits the first at its commit and its hazard tracking orders the copy after the fill
before the wait (the conformance case event-signaller-of-a-wait, M3 Max, job m3-max-68673). Both
groups go now either way; only their order changes, and nothing waits longer.

Verified: pending.
2026-11-22 14:09:06 -08:00
Anees Iqbal e3d30c5101 Runtime: the queue cut comes off development until its gates pass; the runtime is f979769faf's with stage input
What: the runtime crate goes back to f979769faf's, plus stage input. Its sources, its tests and
api_signatures.tsv now equal those of f979769faf with a916e61185, f21db0934c, 59e0a3f7ca and
58e9267b6c applied, file for file.

This one new commit takes out the queue cut and everything built on it:
56cdcb7075, 929718d58f, 9adc440ec6, f997dfa7d3, 544f21b48f, c9c53b85cf, 75773059e7, 855eb86147,
62183f55af, 2ec8680181, eaba828dcd, 600b38fda7, f268d3ca07, 59481e60bd, e74f1480ed, 5686863157
and f0b6fff640. That covers piece.rs, tests/pieces.rs, the rate inputs of the barrier, heap and
event tests, and the README's sections on pieces and the device's room.

It also removes the parts of 41b5038342 that state the cut's cross-queue rule. Those are the
README's "goes after it only once that one is submitted" sentence and its known-gap line on commit
order between queues. Without the cut, a command buffer never goes ahead of an earlier-committed
one it shares a tracked resource or a fence with, and the README says so again.

Kept:
- stage input, from a916e61185 and f21db0934c;
- its NaN rows for the XTX, the Iris Xe and the RTX 3090, from 59e0a3f7ca and 58e9267b6c;
- the replay player's host wait for its own surface fill, from 41b5038342: the player, its test
  and docs/REPLAY-STREAM.md;
- the README's import-cost paragraph, from f53ddc5917.

Why:
- development carries a confirmed stall. A cut command buffer waiting for room, with an empty or
  present-only command buffer behind it on its queue, spins the submit thread with the work lock
  held. Lavapipe, m3-max-68758.
- It carries a candidate benchmark regression: the compute benchmark on the RX 7900 XTX scored
  5.09% lower in the consumer's first pair (m3-max-68746 against m3-max-68738). Its second pair
  is still being read.
- Stage input is a refusal a guest met. The consumer pins only exact commits on development, so
  stage input reaches it only through a development commit without the cut.
The cut and its fixes go to steelbrain/cut, as this commit's revert plus the fixes. They come back
to development as one series when the spin fix is green in all four forms, the XTX benchmark is
within 3% in an alternated pair or the owner rules on the trade, and the wait-split sharer fix is
in, if that turns out to be the cut's regression.

Verified:
- The runtime crate's tree and api_signatures.tsv equal steelbrain/pin-stagein (ce10a0d627).
- The diff to it is the README's import-cost paragraph, the replay player's two files and
  docs/REPLAY-STREAM.md.
- fmt, the refusal surface, the signatures table, the conformance coverage and the Metal coverage
  all check as current.
- The quick check and the suites at this commit are named where it lands.
2026-11-22 13:55:40 -08:00
Anees Iqbal 59481e60bd Runtime: a cut command buffer whose next piece waits for an event holds no other queue
What: block_shared counts a cut command buffer at its queue's head as a holder only while its
next segment is ready (its waits met). A command buffer of another queue that shares with it is
held while that piece could go, and goes where the piece waits for an event not yet met. The
README's queue section states the one rule this and the stale-picture fix keep: "Across queues,
work goes to the device in any order, except that a command buffer never goes ahead of an
earlier-committed one it shares a tracked resource or a fence with, and an event wait holds
only its own queue." Its two sentences on the hold and Metrics::shared_holds say the rest.

Why: the hold was a cycle. A queue held behind a cut command buffer it shares a buffer with is
skipped by next_ready (submit.rs:1629) and wants nothing (:1741), and the cut command buffer's
piece after encodeWaitForEvent is not ready until that event's value is reached. Where the
value comes from the held queue, from a command buffer behind it, or from the host after a wait
on it, nothing moves again: no refusal, no loss, the command buffer never completes. Metal's
wait stops only its own queue, and runs the other queue's command buffer beside it. An update
of a fence held so is not waited for in Metal either (crate::fence, probe
cross_queue_fence_held_update.m).

Verified:
- The test every_device_runs_the_signaller_of_a_cut_command_buffers_wait_though_it_shares
  (queue A: two pieces, then a wait for E, then a fill; queue B: a copy from A's buffer, then
  the signal of E) fails without the fix on lavapipe: m3-max-68633 at f268d3ca07, 10.187 s,
  pieces.rs:304, the signaller not complete in 10 s; both completed once the host set E.
- With the fix, every piece test passes on lavapipe, that one in 0.073 s: m3-max-68643, 12 of
  12, at 4e12dfd4f6, whose code this commit carries (it adds README lines only).
- Compile check (fmt, signatures, clippy plain, m2v_gpu and m2v_cpu_icd, workspace Rustdoc):
  m3-max-68645 at 4e12dfd4f6.

Where the runtime relies on commit order across queues, and how it holds under the pieces and
the device's room:
1. Sharers of a tracked resource across queues, with no event or fence between them (a fill
   committed first, a read committed after it on another queue): the room's rank could send the
   later one first. The open hole of the stale first-use picture; fixed in step() beside
   updater_held, the queue holding the earlier sharer going through to it first, with its own
   forcing test (lane surfpic).
2. The shared hold against an event wait: this commit, and its test above.
3. Waits that submit nothing: stage() marks an event's value submitted as the signal is staged
   (submit.rs:2308), and ready() reads that mark (:2282). The signalling segment's group goes
   in the same turn of pass() that staged it (step() returns Goes, :2055-2056 and the end
   match; pass() closes and submits it before stepping again), and one thread makes every
   submission (run() :2355; submit() called only at :2450 and :2460). So a waiter made ready by
   the mark is closed, and submitted, after its signaller. Held by structure.
4. Uploads numbered for the next commit (take_uploads, :1463): an upload goes in the first
   submission whose command buffers' last was committed at or after its number. Held by
   contract: the next close takes it. A cut command buffer's later pieces take none, so a later
   commit's upload may run before them; its calls came after that command buffer's commit.
5. Captures: a Managed buffer's copy-in waits at its capturing commit's number, and the first
   submission of a command buffer committed at or after it takes it (close(), :2147). A cut
   command buffer committed before the capture takes none in its later pieces; Metal leaves the
   range undefined for command buffers committed before the didModifyRange (crate::capture).
6. Releases: a block an unsent upload holds, released, has the uploads flushed (:1124), and a
   resource released in flight is freed once its submissions complete (command.rs:1823,
   core.pool.ended() at retire). A cut command buffer keeps what it holds until it retires after
   its last piece, so a release frees no sooner than before the pieces.
7. Fences across queues: a waiter goes after each held command buffer of another queue that
   updates its fence (updater_held, :1829), and after every ready piece of a cut one that does
   (the shared hold, covering fences: command.rs:338). Where the cut one's next piece waits for
   an event, the waiter now goes before the update. Metal does not wait for an update in a
   command buffer it holds at an event wait before its work (probe
   cross_queue_fence_held_update.m, an M3 Max, jobs m3-max-52186 and m3-max-52188). An update
   after a wait in the middle of a command buffer whose earlier work runs is not measured:
   whether Metal's waiter waits for it is unaudited.
9. Readers: Gpu::shares compares the tracked ids alone (command.rs:334-339), so two readers of
   one resource share it, and a read is held behind a cut command buffer that only reads it: an
   over-hold, with no write to order. No read and write tracking is built for it.
8. The in-flight list: the device's, in submission order (pushed :2161, popped as each value
   completes, :1861). A queue's own next command buffer waits for every piece of its cut one
   (every_device_runs_a_queues_next_command_buffer_after_every_piece), so each queue completes
   in its commit order.
2026-11-22 13:04:03 -08:00
Anees Iqbal f997dfa7d3 Runtime: a queue's turn for the device's room is 0 only from a commit that finds it idle
The rank put every queue with nothing in flight at turn 0, ties by commit order. In the shape of five queues with backlogs of cut command buffers and the device holding two pieces, at least three of the five have nothing in flight at any moment and their command buffers were committed earlier, so a sixth queue's commit waited for every command buffer committed before it: first-come order. A queue now takes turn 0 only at a commit that finds it with nothing queued and nothing in flight; otherwise its turn is its last submission. The rank is (turn, commit order). A backlog whose last piece just completed keeps its last submission's turn and outranks no queue idle longer.
2026-11-22 11:11:23 -08:00
Anees Iqbal 9adc440ec6 Runtime: the dispatches of one kernel of unknown rate share its piece; room's rank holds per-queue values only
A dispatch of a kernel whose rate is unknown begins a new piece unless the piece holds dispatches of that kernel alone, so a new kernel's first command buffer is one piece whose run sets its rate. A queue's in-flight list keeps its progress values only: the room is the device's. The device tests read the order of submissions by queue and set a kernel's rate.
2026-11-22 11:11:23 -08:00
Anees Iqbal 56cdcb7075 Runtime: a command buffer's compute work goes in pieces of 4 ms, and the device's room goes to the queue that waited longest
What: each command buffer's compute work is cut into pieces before a dispatch that would take
the piece's expected GPU run past GROUP_RUN (now 4 ms, was 16 ms), and where a compute or blit
encoder opens after a full piece; never inside or before a render pass. A dispatch's expected
run is its kernel's rate (picoseconds per threadgroup, on the kernel's compiled content, shared
by its states) times its threadgroups; a kernel with no rate yet goes in a piece of its own, and
an indirect dispatch counts as one threadgroup and feeds no rate. Each piece is timed by its own
pair of timestamps, from its first dispatch to its end, and that run alone feeds the rates
(never the command buffer's span, which holds the runs of what passed between its pieces). Each
piece is a submission of its own and waits for room. Room is the device's: room() over the
device's submissions not seen complete, and among the queues that want room the one that last
submitted earliest takes it, so a passed piece goes before the passer's queue's next. A command
buffer of another queue committed after a cut one passes its pieces unless it holds a buffer or
texture the cut one holds (by tracked id), waits on a fence it updates, or either reaches memory
outside its resources: then it is held behind every piece. A cut command buffer whose later
pieces wait for no event is scheduled as its first piece is staged.

The rate is scheduling data of the same kind as a queue's measured expected run
(QueueInner::expected_run, next_run): it bounds where a piece ends and never chooses between two
forms of the work (rule 4's "no calibration").

Why: on the Iris Xe the guest's screen-frame writers waited behind a background service's
running command buffer: 96.2 of 112.3 ms of each late writer's wait. The Mac runs a second
queue's command buffer beside a running one (Radeon Pro 5300M at any priority, job
m3-max-68137; UHD 630 where the number is lower, m3-max-68129).

Verified: compile job pending (this commit carries no tests yet).
2026-11-22 11:11:23 -08:00