Commit Graph
253 Commits
Author SHA1 Message Date
Anees Iqbal 231a7d86f7 Put a DontCare colour's kept texels behind DontCareColorPolicy::Kept
The owner's rule 1 keeps the fast form of every speed-for-accuracy choice the
default. A colour attachment of a texture's own image stored DontCare now
stores as the driver stores it by default (DONT_CARE where the driver is
measured to keep one of Metal's answers or to store as Metal's own, else
STORE), announced dont-care-store, and renders through the pooled backing
that keeps its earlier texels only under the new opt-in switch
DevicePolicy::dont_care_colors = DontCareColorPolicy::Kept, which
DevicePolicy::exact_answers() selects.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

(cherry picked from commit 2ce15a20927a8f7a44c1bc7ee70869977a88d702)
2026-11-05 11:25:47 -08:00
Anees Iqbal e56b684d54 Record the packed word's blend refused on lavapipe among the known gaps
A blend or a partial write mask of a packed 16-bit attachment the device renders through its
word view (`A1BGR5Unorm`, `ABGR4Unorm`) is built only where the device orders fragment fetch
through the pixel interlock alone (`color_writes::stored_word`, `fetch::interlock_orders`). The
known-gap line named the device without the interlock as where it is refused; lavapipe has the
interlock but orders fetch through rasterization-order input attachments, and there the function
neither blends the word nor merges its fields over the input attachment (`merges_over_input`
leaves packed words out), so it is refused as the device lacking the format too. That is ours,
not the device's: lavapipe orders the fetch an in-shader blend needs, as the extended-range blend
over its input attachment uses. 98d65ecad3 made the multisampled word lane accept the refusal
there; the ledger now says so.

Docs only. Checked against the code paths named above and lavapipe's committed profiles
(`profiles/lavapipe.json`, `gate-lavapipe-x86_64.json`: `fragmentShaderPixelInterlock` and
`rasterizationOrderColorAttachmentAccess` both true).

(cherry picked from commit 25b55132654d8b4c6554e9a0bc0a030820db22f9)
2026-11-05 11:25:47 -08:00
Anees Iqbal d261d6ed46 Announce device-subpixel-snap where the band draws on a driver not measured to snap a half step as Metal
line_widths' wide_lines_draw_metal_s_parallelograms (and its exact-answers
twin) failed on the RTX 5080 Laptop GPU (NVIDIA 615.71.09, b5080 entries
nvlane-lane2-a2f and nvlane-lane3-a2f at a2f4c50f94) and on lavapipe
(llvmpipe, LLVM 23.1.1, Mesa 26.2.4, nvlane-lvplines-a2f) at "rows
offset by (r - 32) / 512 width 0": both drew the map's rows 18 to 49
where Metal draws 17 to 48. Before a5e1d20bd9 the 5080 failed earlier in
that test, at "LANE strip 1", so this case had not run there.

The case draws lines at y = r + 0.5 + (r - 32) / 512, which the band
draws at width 1/16 (half width 16/512). band.rs leaves the corners'
snap to 1/256 pixel to the device's rasterizer, where Metal snaps the
endpoints first, a half step rounded up, and offsets them after; the two
agree on the grid, and for odd r the endpoint lies half a step off it.
Half steps rounded down give the device's map exactly: odd r covers its
row for r in 19..49 and even r for 18..48, against Metal's 17..48 (round
to even gives the same rows here). The band's arithmetic is exact at
these values (side 64, every conversion a power of two), so the rounding
is the rasterizer's, which Vulkan leaves to the implementation: the
device's own answer, so it is announced, not emulated.

- DriverFact::SubpixelSnapIsMetals (appended): the driver's rasterizer
  snaps a vertex half a step off its 1/256-pixel grid as Metal snaps a
  line's endpoint, up. Row: MoltenVK on the M3 Max (APPLE9), where this
  lane's maps pass (a2f4c50f94, m3-max-994: 1847 of 1847). NVIDIA and
  lavapipe drew otherwise, so neither takes it; every other driver is
  unmeasured.
- Degradation::DeviceSubpixelSnap ("device-subpixel-snap", precision):
  announced by line_route at each draw the band draws on a driver
  without the fact. Its catalogue entry in docs/API.md, a FAST-PATHS
  known gap, and the conformance suite's NATIVE_NOTES (the device's own
  answer) take it. band.rs's and line_width.rs's docs say where the two
  snaps differ.
- The lane announces it per draw; a band case with a vertex an odd
  multiple of 1/512 pixel off (in framebuffer pixels) is left unchecked
  where it is announced, and every other band case is still compared
  with Metal's map. Held to the fact: never announced where the driver
  has it, and some case unchecked where it does not and the device
  tessellates. degrade_notices lists SUBPIXEL_SNAP as its site.
- driver_facts' profile test expects the fact on moltenvk-m3.

Note sets: MoltenVK on the M3 Max takes the fact, so it announces
nothing new. NVIDIA, lavapipe, RADV and ANV now announce
device-subpixel-snap at band draws. api_signatures.tsv gains the three
items (blessed); docs/REFUSALS.md regenerates unchanged. driver_facts.rs,
degradation.rs and line_width.rs are runtime pin inputs, so
RUNTIME_VERSION and the pin are the orchestrator's to move.

Verified: cargo fmt; scripts/api-signatures --check after --bless;
refusal_surface.py. Builds, clippy, the unit tests and the 5080, M3 and
lavapipe lane reruns are in the next jobs.

(cherry picked from commit 2574f4bb084656035feae4ef714bac96f720f497)
2026-11-05 05:11:14 -08:00
Anees Iqbal 792822226e Take lavapipe out of LineTiesAreMetals: it leaves out the line lane's strip's first pixel
a5e1d20bd9 gave lavapipe the fact on the conformance case's evidence
(llvmpipe draws primitive-type-restart-indices' line through (3.5, 1.0)
as Metal does). The line lane on lavapipe says otherwise: at 3785e99d8e,
under --cfg m2v_cpu_icd on msi-laptop's lavapipe (llvmpipe, LLVM 23.1.1,
Mesa 26.2.4, m3-max-949), wide_lines_draw_metal_s_parallelograms and its
exact-answers twin fail at "LANE strip 1": the strip starts at (3.5, 1.0),
a vertex the diamonds of rows 0 and 1 share, and lavapipe leaves out row
0 column 3, which Metal covers; every other pixel of the map is Metal's.
With the fact the lane held lavapipe to exactness there, and it failed.

The fact's rows are now MoltenVK on the M3 Max alone, so lavapipe
announces device-line-ties at its width-1 line draws as NVIDIA does: a
notice lavapipe did not announce before, for a difference it drew
silently before. driver_facts' profile test no longer expects the fact
on the three lavapipe profiles; the fact's docs, the catalogue entry,
FAST-PATHS' known gap and the lane's docs say what lavapipe draws.

Verified: cargo fmt. The lavapipe rerun of the line lane is in the next
msi job.

(cherry picked from commit a13ef6b9c4aeb5bac7448bd1a16526352458169d)
2026-11-05 05:11:14 -08:00
Anees Iqbal d9e3324d4e Announce device-line-ties where a driver breaks a width-1 line's diamond-vertex tie unmeasured
line_widths' wide_lines_draw_metal_s_parallelograms (and its exact-answers
twin) failed on the RTX 5080 Laptop GPU at "LANE strip 1": the
three-vertex strip at width 1, drawn in Bresenham's mode, put its
diagonal a row higher than Metal's (row 9 columns 3-4 where Metal draws
row 9 column 3 and row 10 columns 4-5, and so on, its last pixel at row
14 left out). The diagonal runs through vertices two pixels' diamonds
share; Metal covers the lower pixel, and Vulkan's diamond is open, so
the tie is the driver's with no Vulkan control over it. FAST-PATHS'
known gap "One line texel at a diamond vertex on the RTX 5080" already
said so for the conformance case primitive-type-restart-indices, but
the runtime announced nothing: a near-equivalent drawn silently.

- DriverFact::LineTiesAreMetals (appended): the driver's width-1 lines,
  as the runtime draws them, cover Metal's pixel at such a tie. Rows:
  MoltenVK on the M3 Max (APPLE9; its lines are Metal's own, the lane's
  maps pass there) and lavapipe (the conformance case: no texel differs
  on llvmpipe, LLVM 23.1.1, Mesa 26.2.4). Every other driver is
  unmeasured, so NVIDIA, RADV and ANV announce.
- Degradation::DeviceLineTies ("device-line-ties", precision): announced
  by line_route at each draw the device's lines draw at width 1 (a
  plain-width draw of lines or edges, or the nearest width where that
  is 1) on a driver without the fact. Its catalogue entry in docs/API.md,
  FAST-PATHS' known gap (now "announced"), and the conformance suite's
  NATIVE_NOTES (the device's own answer) take it.
- The lane announces it per draw, leaves such a case unchecked as it
  does the other announced routes, and holds it to the fact: never
  announced where the driver has it, announced in some case where it
  does not. degrade_notices lists LINE_TIES as its site.
- driver_facts' profile test now expects the fact on the three lavapipe
  profiles and moltenvk-m3.

Note sets: MoltenVK on the M3 Max and lavapipe take the fact, so neither
announces anything new. api_signatures.tsv gains the three items
(blessed); docs/REFUSALS.md regenerates unchanged. Not covered (left as
it was): a pipeline whose multisample state keeps Bresenham's mode off
(alpha to coverage, alpha to one, sample shading) draws the device's
default mode, which the fact does not measure. The runtime's notice and
line_width.rs are runtime pin inputs, so RUNTIME_VERSION and the pin are
the orchestrator's to move.

Verified: cargo fmt; scripts/api-signatures --check after --bless;
refusal_surface.py. Build, clippy, the unit tests and the 5080 and M3
lane runs are pending (the lane fixes batch).

(cherry picked from commit 75bb1413eacbf5ef3e1a3abed7ec97eff4b1c42d)
2026-11-05 05:11:13 -08:00
Anees Iqbal 639e505b11 State NVIDIA's BC decode bound as the RTX 5080 measures it: 4/255 for BC1 to BC3, 7.4/255 for BC4 and BC5
compressed_decode's bc1_to_bc5_texels_read_the_device_s_decode failed on
the RTX 5080 Laptop GPU (identically at d19da8bfce and 961b1ff319: the
lane's blocks are seeded) with channels past compressed-texel-decode's
stated bound. Its BCDECODE lines, per channel:

  BC2RGBASRGB  codes [2, 4, 2, 0]            18 past the note
  BC3RGBA      [2.0, 4.0, 2.0, 6.0]/255       7 past
  BC3RGBASRGB  codes [2, 4, 2, 0], alpha 6    12 past
  BC4RUnorm    7.327/255                      6 past
  BC5RGSnorm   16.329/255 (0.064035)          4 past

The others are within it (BC1RGBA [1, 3, 2, 0]/255, BC4RSnorm 0.0595,
BC5RGUnorm [7.163, 5.593]/255). The decode is the device's own (rule 1),
announced; the bound understated it: a BC1 to BC3 channel (the 6-bit
green) up to 4/255 where it said 3/255, a BC4 or BC5 channel up to
7.4/255 (signed 0.065) where it said 7.3/255 (signed 0.064).

The notice's cost (degradation.rs), docs/API.md's catalogue entry,
docs/FAST-PATHS.md's row and the two DriverFact docs now state the 5080's
measured bounds for NVIDIA, lavapipe's 3/255 kept apart, and the lane's
noted_bound copies them (4/255, 7.4/255, signed 0.065), so a run past them
still fails. No decode, note condition or announcement changes.

degradation.rs and driver_facts.rs are runtime pin inputs: the
runtime-sources pin needs its re-hash.

Verified: cargo fmt. The 5080 rerun is pending (the lane fixes batch).
(cherry picked from commit 164575080bf6132dc621a7e542af6a6f133c3a3f)
2026-11-05 05:11:13 -08:00
Anees Iqbal 6eb2a66d6e Gather a two-plane YCbCr texture's planes in place
A function that samples a YCBCR8_420_2P or YCBCR10_420_2P texture and also
gathers it (a probe asking each lane for a sample or a gather of red or
blue) lost the in-place form for the whole slot: `in_place_sample` built no
gather, so the gather set `in_place.blocked`, the slot bound the converted
image, and on MoltenVK its linear samples went through Metal's sampler of
RGBA16F-like texels: `ycbcr-filter-not-exact` (Half/FloatSampleFilter), and
through a pixel sampler `pixel-sampler-scaling`. Those notes killed three
of a consumer's strict Mac tests.

What: the in-place form now builds a 2D gather of a component without
comparison, constant offset or none, through a constexpr sampler (either
filter: a gather follows none) or a runtime one. The gather is the
extended-range emulation's `gathered` over `Decode::InPlace` taps: the four
taps of the linear footprint, each the texel Metal reads there (the border
texel past a border axis), in Vulkan's order, a runtime sampler's word
mapped as a 4:2:0 texture addresses. A gathered slot stays off the device's
own Y'CbCr conversion (`device: false`):
VUID-RuntimeSpirv-OpTypeSampledImage-12206 admits only samples through it.
No Quad routine for a gather. SEMANTICS_VERSION 1962 (facts and modules of
gathered slots change).

Tests (engine_ycbcr_in_place): every gather of each component of random
8- and 10-bit planes under three conversions, constexpr and runtime
samplers, float and half, on the lavapipe and moltenvk-m3 profiles, equals
Metal's model taps on the interpreter; a gather states the in-place fact
with `device: false`; a function that samples and gathers through one
runtime sampler notes FloatSampleFilter/HalfSampleFilter on its image
compile and states the fact, and its in-place compile builds both forms and
notes neither those nor PixelSamplerScaling. Device evidence against
Metal's rows follows with the fixture and conformance cases.

Docs: API.md and FAST-PATHS (in-place reads and the planes-image row),
RuntimeFact::YCbCrInPlace, InPlaceReads, the runtime README.
(cherry picked from commit b95b95a355f9a8ff4c1bfacbf329a728c4896db9)
2026-11-05 02:08:27 -08:00
Anees Iqbal 2e2c1ec056 Leave fneg, fabs, floor and ceil unnoted where the M3's Metal keeps their denormals
MoltenVK on the Apple M3 Max runs a SPIR-V `OpFNegate`, `FAbs`, `Floor` and
`Ceil` through Metal's own compiler, which keeps a denormal operand of
negation and absolute value and reads it as the zero of its sign in floor
and ceil, as plain Metal does. The translator noted `DeviceDenormals` on
every such operation, so a strict consumer died on a kernel that negates a
float though the answer is Metal's.

What: a new APPLE9-only `DriverDeviation::MetalUnaryDenormals` (and its
`VkProperty`) on the moltenvk-m3 profile. A function whose float negation,
fabs, floor or ceil the deviation covers records no `DeviceDenormals` for
them and requires the property instead; fabs keeps its Metal-own exemption
on every other profile, and trunc, round, rint, fract, sign and the rest
stay noted (the lane does not check them). `ARTIFACT_FORMAT_VERSION` 486
(the property's tag), `SEMANTICS_VERSION` 1961 (notes and requirements
change).

Evidence: the committed MoltenVK M3 observations of the four denormal
cases (nan_denormals, nan_denormals_fast, dfl, dfl_fast) hash equal to
Metal's on the same M3. The float_denormals gate lane now checks probe rows
-a, 0-a, -(a*b), fabs(a), floor and ceil where the deviation is taken, and
asserts the module requires the property exactly then; the
arith unit test covers each op under each fast and unary setting. Device
runs follow on the GPU job for this stack.

Docs: FAST-PATHS row on device denormals, API.md degrade catalogue,
driver_facts' measurement paragraph, api_signatures.tsv; refusal surface
and signatures checks pass.

(cherry picked from commit f3f65903a395b46b3a8001c4259bb1e4bb7bc203)
2026-11-05 02:08:27 -08:00
Anees Iqbal a139f39c89 Note a texel centre's denormal only under an address mode that parts texel -1 from texel 0
What: a nearest pixel-coordinate sample at its texel's centre, floor(x) + 0.5, records
DeviceDenormals for that floor: Metal's sampler reads a negative subnormal x as texel -1, where a
floor that flushes it (MoltenVK's) makes texel 0. Clamp to edge, mirror clamp to edge and mirrored
repeat read texel -1 as texel 0, so the note now holds only where the s or t mode is repeat, clamp
to zero or clamp to the border:
- a constexpr sampler decides it from its (mapped) s and t modes at compile (centre_parts);
- a runtime sampler slot's clauses add, per axis, a test of the bound sampler's word that the
  axis's mode is none of the three. The word is read through a new note-only key,
  SpecKey::BoundSamplerWord(slot): no constant declares it and no pipeline's key carries it, so
  the mode adds no VkPipeline variant (the alternative, the ADDRESS bits in SamplerState's fields,
  would split every runtime pixel sampler slot's pipelines by mode on every device). The plan
  records its value beside the pushed specialized values (slots::record_noted, given by
  BindingPlan::specialized_value), SpecClause::tests_bound_values counts it, and the runtime's
  degrade_bound_values announces such a clause at each draw or dispatch, as it does for a pushed
  format class. The runtime's notice reads "under the formats and samplers it binds".
- NoteOn::BoundSampler is the lowering's name for the key.

Why: reims-vgpu's strict Mac tests died on device-denormals from a nearest clamp-to-edge pixel
sampler, under which the device's texel is Metal's.

Tests: tests::engine_sample_coordinates::a_texel_centre_notes_denormals_only_where_its_mode_
parts_texel_minus_one (constexpr array samples per mode on every committed profile; the runtime
slot's clauses evaluated over every s/t mode pair, and never under a normalized state);
cache::tests::the_version_485_member_round_trips;
runtime_lane::pixel_samplers::a_texel_centre_s_denormals_wait_for_a_mode_that_parts_texel_minus_one
(device: nothing at making, nor under clamp to edge and mirror clamp to edge, once under clamp to
zero). Conformance: four cases pixel-samplers-subnormal-{edge,zero,border,mirror}, the RGBA8Unorm
texture through a nearest filter at sixteen coordinates of subnormals, zeros and -2^-126 on each
axis, recorded on Metal in a following commit.

Versions: ARTIFACT_FORMAT_VERSION 485 (the SpecKey variant), SEMANTICS_VERSION 1960 (the clauses).
api_signatures gains the variant. Docs: API.md and FAST-PATHS.md (device-denormals), the
DeviceDenormals, SpecKey, SpecClause and plan rustdoc.

(cherry picked from commit 624008697abfab1dbb3039a926902373b84e1268)
2026-11-05 02:08:27 -08:00
Anees Iqbal 8fcff2117f Put a host step's copy of a chunk's records off where they changed at two steps in a row
On the 5080, a page whose GPU-written records change at every frame (replayed_frames at K=0,
5000 records, CHANGE_EACH) paid about 0.9 ms more a host step than the baseline: base 19.15 ms,
the tip 20.05, means of 3 interleaved runs of 22 warm frames each (b5080 entry icb-p-010218).
The same tip with the host step's keeping cut off (no comparison, no copy) ran 19.31. perf of
the steps thread put the difference in memmove: each step copied every chunk's records, 11 MB,
into the copy the next step compares with, 575 KB a chunk, past the caches (h 501 Mcycles of
memmove against 416 with no keeping). The comparison itself is a few hundred microseconds less
than that and the single read (ff4610cd46) already left one read a record.

A host step that records inline now copies a chunk's records only where it needs them
(kept_commands::StepCopy, held in each chunk's state beside the bytes it last read):

- where the records hold the bytes the last step read, it records from those bytes and copies
  nothing (ReadFrom::Held);
- where they changed since, it copies them again, as before;
- where they changed at the step before too, it reads them in place, record by record, as an
  execution that keeps nothing does (ReadFrom::InPlace, RecordSource::Storage), and copies them
  at one step in eight only (COPY_EVERY), each chunk at a step of its own among the eight, until
  a comparison finds them as the step before read them. A CPU write to the chunk, or a recording
  of it kept or forgotten, starts it over.

So records that change at each step are copied for an eighth of their chunks a step, and a chunk
whose records stop changing is copied again within eight steps and compared at the next. What a
step keeps is unchanged: a chunk is kept only where its records compared equal, byte for byte.
WorkCounts::host_step_chunk_copies_put_off counts the chunks read in place.

Tests: kept_commands::tests::records_that_change_at_each_step_are_copied_at_one_step_in_eight_a_chunk
(the schedule: chunk 0 copied at steps 0, 1, 10, 18, 26, chunk 7 at 0, 1, 3, 11, 19, 27, one
chunk in eight a step from step 3, a held comparison and a write start it over). The kept-steps
lane's changing case asserts each chunk's copy put off from the records' second change on, each
record still read once (indirect_record_bytes_copied), the pixels a fresh page's, and that once
the records hold again a step within ten records apart and keeps every chunk, the next running
them kept. replayed_frames' split prints host_step_chunk_copies_put_off and
indirect_record_bytes_copied.

Verified: nothing yet; the M3 clippy, units and lanes, the negative control (always copy) and the
5080 timings follow.

(cherry picked from commit cd7b2a7e74f2a6aeef4e8080689bb4bab50c0a2f)
2026-11-05 02:08:25 -08:00
Anees Iqbal 3ab5303945 Have a host step that records inline read its records once, into the copy it keeps
A step whose records change at each frame copied every chunk's records for the next step's
comparison (written_bytes_into) and then read each record again to decode it (record_now):
11 MB copied twice a frame on a page of 5000 commands. On the 5080, three interleaved runs at
K=0 with records changing every frame stepped 19.6 ms on average against 19.0 ms at
04115e977f, with libc's copy at 13.4% of the steps thread's cycles against 11.2%.

steady now hands such a step StepReads, what it reads its records into, chunk by chunk:
the bytes the last step read where it has them, else a fresh copy, and a chunk whose kept
recording's records hold reads those. The inline recording decodes its records from those
copies (IndirectCommandBuffer::written_records_in), and keeps them for the next comparison
once it recorded. keeping answers Keeps: kept, or inline with or without reads.

WorkCounts::indirect_record_bytes_copied counts the bytes copied out of a buffer's record
storage. The kept_steps lane's changing frames now expect each record copied once (DRAWS x
COMMAND_BYTES); copying them again besides fails it.

Not built or run yet.

(cherry picked from commit ff4610cd4660b94835af7841e24114d6ee89fae2)
2026-11-05 02:08:25 -08:00
Anees Iqbal 347b9870c4 Keep a host step's chunks only where two steps read the records alike, and copy the residency once an execution
A host step that compared a kept chunk's records and found them changed recorded every chunk
apart again, each into a secondary of its own, to keep: on the replayed-frames page at 5000
resident pairs on the M3 that cost 23.3 ms a step where the records changed at each frame,
against 18.3 ms recorded inline (one binary, keeping switched off by a temporary patch). Phase
timers put the difference in a copy of the residency per chunk and its drop (2.9 ms over 20
chunks), a fresh 11 MB copy of the records (about 1.1 ms more read), resolutions and contexts.

Two changes:

- RenderExecution::steady decides before recording. A step keeps chunks only where the records
  hold, chunk by chunk, the bytes a kept recording was made from or else those the last step
  read, compared whole. Else the execution records inline, as before keeping, and each chunk's
  records are copied into the bytes the last step read (IndirectCommandBuffer::
  written_bytes_into, no new pages after the first), for the next step's comparison; a recording
  whose records changed is forgotten and counted recorded again. So records that change at each
  step cost the step one copy of them beside today's inline recording, and a step records apart
  and keeps only what two steps read alike. The chunk store keeps those bytes per chunk
  (KeptChunks::look_up_step, read); a chunk recorded apart keeps them as its recording's bytes,
  copying nothing again.
- The chunks an execution records apart carry the encoder's residency from one to the next with
  the bind state (replay_encoder takes it owned), so an execution copies the command buffer's
  residency once, as one recorded inline does.

The kept-steps lane now counts chunks recorded apart to keep (WorkCounts::kept_contexts_made):
the first frame records inline, the second apart, the third runs kept; a records change records
inline, then apart, then kept; another input's change records apart at once; and records that
change at each step record inline each frame, keeping nothing, each frame drawing what a fresh
page draws.

Verified: clippy, plain and under --cfg m2v_gpu, on this Mac. The lanes and the page's timings
on the M3 follow.

(cherry picked from commit b9b1c0aab9728e57e517cb6f0abdfc1df44e9b03)
2026-11-05 02:08:23 -08:00
Anees Iqbal 042ec0a481 Keep a host step's recordings of GPU-written render commands, compared with the records
A host step of a render execution whose records the GPU may write recorded every command at
every step: about 12 to 17 ms for the replayed-frames page's 5000 indexed draws on the M3, every
frame, though the page's records are the same bytes each frame. The step now keeps its chunks as
commit keeps the CPU's (render/executions/kept.rs, kept_commands.rs): from a chunk's second step
on it records the chunk apart into a context of its own and keeps it with a copy of the bytes of
its records; a later step runs the kept recording where the records hold those bytes now,
compared whole, and its key is equal, and records it again otherwise. No write forgets such a
chunk: the comparison decides.

The key is everything the recording reads beside the records: the RenderKey commit's chunks use
(inherited pipeline state, pass shape and layout, encoder state, scissors, amplification,
attachments among the resident resources, the resident set compared whole once a list), plus the
inherited tables' buffers by key with offsets and attribute strides (new: commit's chunks need
tables that bind nothing), plus KeptChunk::runs_again's checks (each address named resolves as it
did, no no-copy buffer moved, nothing detached, everything held alive). The step keeps only where
the commands inherit the pipeline state and the inherited tables bind buffers alone; a record
barrier makes its chunk not plain instead of ruling the execution out. Its chunks draw in the
large-buffer form, as the step's other draws do. The step's round trip stays: the records are
known only once the work before them completed.

Counters: WorkCounts::host_step_chunks_kept, host_step_chunks_recorded_again,
host_step_records_compared and host_step_compare_nanos (api_signatures rows added). The
replayed_frames lane prints them and a hash of the target's pixels per frame (a blit copies the
target out); the new kept_steps lane changes one input at a time (the records the GPU wrote, the
inherited buffer and its offset, the inherited state, the scissor, the resident set, the buffer
an index address names at the same address, the inherited no-copy buffer's pages) and checks a
re-record, the pixels of a page that kept nothing, and keeping again after. FAST-PATHS' entry on
kept recordings states the host step's.

Verified: cargo check and clippy -D warnings, all features, plain and --cfg m2v_gpu, for the
runtime and validation crates; api_signatures/api_surface 15/15; fast_paths 19/19; the runtime's
kept and indirect-command unit tests 32/32. The device tests (kept_steps, replayed_frames,
the ICB lane modules) are not run yet.

(cherry picked from commit 9b3d13a6d22fba484cce4923fd87ad503f7bc060)
2026-11-05 02:08:23 -08:00
Anees Iqbal 03d4e53238 Record the copy beside another storage mode's import as a GPU-to-GPU gap
What: copied.rs's GPU-to-GPU note and docs/FAST-PATHS.md's known gap now
also name a copy beside a live import of the same bytes for the other
storage mode (a Managed buffer's import, then a Shared buffer over the
same bytes whose import the gate refused): two memories that agree only
through the pages, as overlapping copies do.

Why: a buffer lies in a live import of its own memory class, else in a
live copy of either class; a copy made while only the other class's import
lives is a second memory. Lying in the other class's import instead was
left out: it would change which memory type the buffer's import takes.

Verified: docs only (cargo fmt).
(cherry picked from commit 9f473f8f10f82e59864fd5abb74615b65c3b2e14)
2026-11-04 22:15:56 -08:00
Anees Iqbal 6c4b409fb0 Lay a no-copy buffer over a live copied host buffer's bytes in its copy
What: a copied host buffer (the caller's gate refused the import, or an
admitted import failed) now joins its memory and is placed as an import is
(`HostAliases::join` with `Kind::Copy`, `HostAliases::place`). A later
no-copy buffer over exactly the same first byte and length, of either
storage mode, finds it (`HostAliases::import`: an import of its class,
else the live copy), lies in it through `Device::buffer_in_import`, is
named to it (`copied_as`) and joins its key, with the gate not asked. A
rebind onto such bytes lies in the copy too where its textures were
planned at the copy's offset (its first byte) and no image in place rides
on it; an import keeps the old `!moved` rule. A heap's own copy is placed
but joins nothing; a buffer whose writes are dropped keeps its read-only
view. New counter `WorkCounts::copied_host_buffers_shared`.

Why: two copies of one memory agreed only through the pages (merge back
at the writer's completion, copy in at the reader's commit). reims-vgpu
measured on the M3 (MoltenVK) two textures over one 64x64 BGRA8 surface,
each over its own refused no-copy buffer: a blit write then a blit read in
one command buffer, and a reader committed first on a second queue waiting
on the writer's event, both read all 16384 bytes stale, where Metal and
the runtime in place read the write. The consumer also made a full copy of
the surface per texture per present.

The remaining GPU-to-GPU gap, between a copy and another copy or import of
overlapping but different bytes, is recorded in copied.rs, docs/API.md,
docs/HOWTO.md and docs/FAST-PATHS.md's known gaps.

Verified: cargo check of the runtime with tests; the lane in the next
commit, run on the M3 (see its message).

(cherry picked from commit 69feb791dc6ec3bc2405dbf5b6ae5d0b27d936aa)
2026-11-04 21:54:19 -08:00
Anees Iqbal 1a541744e1 Destroy an event's semaphore where its release goes again, and record NVIDIA's event costs
What: an event's release destroys its timeline semaphore on the releasing thread again, as at
4bbafa667d (event.rs is that commit's again); the device's free thread frees blocks alone. The
semaphore posting goes with its counter (WorkCounts::semaphore_destroys_posted; the API table
blessed: the field removed), its runtime test and its lane rows. docs/FAST-PATHS.md's known gaps
record what making and releasing an event costs on NVIDIA, and why the release is not posted.

Why: NVIDIA's driver runs a vkCreateSemaphore behind a vkDestroySemaphore another thread runs,
so a posted destroy moves its cost onto the program's next event and adds to it. Measured on the
RTX 5080 Laptop GPU with the bench's event modes (each row 1000 events unless said; before and
after interleaved within each hold; CPU package 83-103 C), p50 unless said:

  burst, 1000 made then released     inline: make 143-262 us, release 495-579 us
                                       (0.47-0.57 s a 1000 released)
                                     posted, bound 4096: release 0.2-0.5 us, but the makes
                                       while the destroys drained 1048-1676 us (1.10-1.66 s
                                       a 1000)
                                     posted, bound 64: release 0.5-1.2 us, p99 1.5-2.2 ms,
                                       0.51-0.66 s a 1000; makes unchanged
  steady, make one and release the   inline 203-238 us a pair; posted (64) 390-507 us
  one before, back to back
  steady, 2 ms apart (500)           inline 488-490 us a pair (event), 663-677 us (shared);
                                     posted 260-263 us and 417-421 us
  the driver's own cost              grows with the semaphores live: 98-119 us a make and a
                                     release with one or two live, against the burst's
                                       143-262 and 495-579 us with 1000 live

On the M3 Max (MoltenVK 1.4.2) a pair costs 2.6-2.8 us inline and 5.3-5.9 us posted back to
back, about 45 us either way 2 ms apart; Metal's own newEvent and newSharedEvent take 0.8-1.9
us there. The consumer's guests made no event in a boot of theirs, and their host makes a few a
second, so no shape of use has the posted destroy ahead, and the burst at a program's close,
which posting was for, gains nothing: the device's teardown drains what was posted.

Verified on the M3 Max (debug, --cfg m2v_gpu, under maclock and memcap): 90 runtime tests
(posted_frees, freed_memory, teardown_threads, memory, allocations, event, cpu_copy_layouts)
and 27 lane tests (posted_frees, shared_event, events, pool_churn, staging_batches) pass;
api_signatures and api_surface pass; clippy (plain and --cfg m2v_gpu, workspace, all targets,
all features) and the release check of the runtime's tests are clean. The inline rows above
are the RTX 5080's at 4bbafa667d's event path, which this restores.

(cherry picked from commit 1659544703425cd461106fba2cff7cfe73a02a8a)
2026-11-04 18:50:29 -08:00
Anees Iqbal 289af45922 Give the shadow runs' RTX 5080 Laptop times again, measured with the in-place first pass
The previous commit removed the RTX 5080 Laptop numbers from docs/FAST-PATHS.md because they
described the earlier form of the runs. They are measured again here, with the in-place first
pass and the second keep.

Verified on msi-laptop (RTX 5080 Laptop GPU, NVIDIA 615.71.09), under an exclusive GPU hold with
no VM running. Release builds of the 700-pass probe were made at 36c3063e16 (tip) and at
2bc0f1eac6 (fix), and run interleaved, three processes each. The times are commit to completion
of the second to fourth command buffers of each process:

- passes back to back: fix 6.5-9.1 ms, tip 6.3-9.0 ms;
- with an empty 1x1 encoder between every two passes: fix 9.3-12.2 ms, tip 9.1-12.7 ms.

The fix took 5 shadow copies and kept 2,097,152 texels in every run; the tip took 3 and kept
1,048,576. The figures for the build without runs (40.6-43.0 ms and 44.5-47.1 ms) are the ones
the row already gave.

(cherry picked from commit fa2b1b354d818fd4a373fb5af7ba1c5dd44ce21c)
(cherry picked from commit 8674db962402c9c425765fe0c8430f1383edd6ff)
2026-11-03 15:58:55 -08:00
Anees Iqbal 4bfeb66cd9 Merge a shadowed texture's pass in place until a second pass goes on from it
A shadowed texture's pass that opened a run left its merge to its batch's submission
(`Deferred::RunMerge`). That splits its encoder's commands into a continuation VkCommandBuffer and
records a segment of batch work at the submission. A pass that no later pass goes on from paid for
this and saved nothing. The conformance cases rotated-planes-load-0-64x16 and -32x32, one such pass
each, measured alone on the M3 Max: command_buffers_begun 3 -> 6, command_buffers_submitted 2 -> 5,
submit_infos 1 -> 2, end_command_buffer 3 -> 6, encoder_command_buffers_begun 2 -> 3, batch work
1 -> 2, and one batch barrier and one continuation that the recordings do not have. Reverting the
shadow runs alone restored the recorded counts; reverting the twin-shadow fix changed nothing.

Now the pass that would open a run merges in place as its encoder ends, as a pass alone does, and
only marks where a run may start (`PassRuns::placed`). The pass after it opens the run
(`Joined::Placed`): its image is carried, with no copy in, and it keeps the texture again.

The second keep is required. A run's merge compares its keep with the image its last pass left,
byte by byte, and a byte equal in both keeps the buffer's byte. A first attempt went on over the
in-place pass's keep instead. Bytes that the later passes changed and changed back then kept the
in-place merge's value, and the byte comparisons failed:
- tests::shadow_runs::runs_over_host_pages: 1,176 bytes;
- tests::merge_scratch's passes over host pages;
- the validation lane's many_passes_over_host_pages tests.
So a run of k >= 2 passes costs two keeps, two merges and k - 1 continuations, and a lone pass
costs nothing extra.

Verified on the M3 Max (MoltenVK 1.4.2, --cfg m2v_gpu):
- `conformance cost --runs 8 --alone --show` for both rotated-planes cases: every count that rose
  equals the recording again. The four counts that differ alone from the whole-set measurement
  (command_buffers_deferred, cmd_push_constants, device_memory_allocated,
  queues_sharing_a_vk_queue) also differ with the shadow runs reverted.
- New test tests::shadow_runs::a_pass_alone_merges_in_place. A pass alone: 0 continuations,
  3 shadow copies. Three passes: 2 continuations, 5 copies. The bytes equal a private texture's.
  Negative controls:
  - with the in-place path disabled, it fails at (1, 1, 3);
  - with the pass after a marker opening the run without a keep (`Joined::Opens`), it fails at
    (3, 0, 7).
- tests::shadow_runs and tests::merge_scratch, 10 of 10, with updated counts:
  - runs_over_host_pages: 32 copies, 14,680,064 texels kept;
  - the scissored passes keep at [0, 1, 2];
  - the rebind encodes 4 passes again.
- The runtime's shadow, merge, linear, rebind, re-encode and replay tests: 155 of 155.
- The validation lane's shadow, padded, linear, rotated and surface tests: 145 of 145.
- The 700-pass probe now takes 5 shadow copies and keeps 2,097,152 texels (3 and 1,048,576
  before). Release builds of this tree and of its parent, interleaved, three processes each, the
  second to fourth command buffers: commit to completion was 32.7-35.6 ms against the parent's
  31.6-36.1 ms, and with an empty encoder between every two passes, 61.5-67.2 ms against
  60.4-67.0 ms.

docs/FAST-PATHS.md gives the new counts and the M3 times. The RTX 5080 Laptop numbers are removed:
they described the previous form, and that host was running VMs, so they were not measured again.

(cherry picked from commit 2bc0f1eac676dcc86dadfbd37a81313977515d45)
(cherry picked from commit 55c7f307a92c67125d31b08c33b3f91c7d14a67b)
2026-11-03 15:58:54 -08:00
Anees Iqbal 241ee2c0d1 Keep and merge a run of passes over one shadowed texture once, not once a pass
What: a render pass whose color is a shadowed texture merged back (its truth a buffer's bytes
another writer may write, such as a no-copy buffer's host pages or a Shared buffer's), loaded and
stored, now joins a run of passes (pass_runs.rs) where it may. The run's first pass copies in (or
takes the carried image) and keeps, as before. Each later pass goes on over the image the pass
before it left (ShadowSync::go_on) and keeps nothing. Each pass leaves its merge to its batch's
submission (Deferred::RunMerge, RunWork::Shadow), and the run's next pass takes it over, so the
merge recorded is the last pass's, compared against the first keep. The run holds the keep's
scratch or kept image (RunHeld::Shadow, its MergeLease) until it ends or the command buffer
commits.

Why: consecutive render passes over one merged-back shadowed texture each copied in, kept and
merged the whole texture. 700 one-rectangle passes over a 1024x1024 BGRA8Unorm texture over host
pages took 1,401 shadow copies and 700 merges.

The rule, structural, with no names: a run ends wherever something other than its own passes
could observe or change the bytes, as in the linear runs' list:
- any encoder between its passes that is not a render encoder;
- a render encoder that names the bytes' buffer or its host range, reaches memory it does not
  name, fences, resolves, writes visibility results, records later or renders over a rate map;
- a render encoder with an attachment over those bytes, or whose draws or attachments take a
  shadowed texture over them (the run's own texture bound to a draw included);
- a signal, a wait or a host step (a new batch), and the command buffer's end;
- for a shadow, the encoder no longer carrying the image (the carry dropped).
A shadowed color joins only when it is loaded and stored, has no stand-in and no planes, belongs
to a pass of one render pass instance that is not inline and not inside a predicated laying, is
laid out as one image's texels at level 0 and slice 0, and merges back.

Encoded again: unlike a linear attachment's run, a shadowed texture's run may hold passes over
host pages, which a rebind before the first submission encodes again. Such a pass leaves its run
(RunMerge::leave). The merge it took over records after all (given back), and the pass copies in,
keeps and merges for itself. Where a later pass took its merge over, it keeps the run's scratch
again after its own merge (RunMerge::keep_after), so that later pass's run merges what the passes
after it change. Run segments now record again (Segment::records_again) and splice. An encoder
encoded again takes no pooled scratch or kept image (ShadowMerge::new's `lent`). A run's merge is
resolved at its calls (Deferred::resolved_at_its_calls), so it holds no host pages past commit;
before this, a rebind of such a run was refused with Rebind(EncodedUses).

Two more changes. A run's keep that a later pass writes outside merges and keeps every texel next,
and a run's pass that needs texels the copy-in did not hold copies every texel in. A merge in whole
blocks stays in blocks where the keep holds the pass's area (stores_blocks), under the same
read-to-store window that shadow.rs's Stored attachments already state.

Counted with the existing counters: shadow_copies, shadow_texels_kept and
shadow_merge_dispatches_planned fall from one per pass to one per run. docs/FAST-PATHS.md records
the run and its costs.

Verified on the M3 Max (MoltenVK 1.4.2), --cfg m2v_gpu, under maclock and memcap:
- tests::shadow_runs (new, all pass):
  - runs_over_host_pages_keep_and_merge_once: 1024x1024 BGRA8Unorm over host pages, rows of 15360
    bytes, with blits, foreign render encoders, reads, CPU byte writes, a signal and an aliasing
    view between runs. Mid-sequence and final reads match a private texture byte for byte, and
    the padding is untouched. Joined: 22 copies, 9 merges. Apart: 112 copies, 54 merges.
  - rebound_passes_leave_their_runs: 3 encoders encoded again, 0 refused, bytes equal.
  - scissored_runs_keep_again_once_and_merge_in_blocks: keeps at passes [0, 1], all in blocks.
- Runtime suites (shadow, merge_scratch, linear_runs): 69 of 69 passed.
- Validation runtime_lane (shadow, padded, linear): 91 of 91 passed.
- Negative controls, each a sabotaged build, source restored and touched after; each fails:
  - go_on off: every pass keeps;
  - follows across encoders: keeps [D0, D8, D9, D10, A11, D12];
  - leave off: 961,469 bytes differ;
  - stores_blocks reverted: every scissored pass keeps.
- Release probe, 700 passes in one command buffer, base a543f6428d against this commit: shadow
  copies 3 against 1,401, texels kept 1,048,576 against 734,003,200, merges planned 1 against 700.
  Commit to completion, runs 1-3: 31.6-35.3 ms against 69.3-99.9 ms. With a 1x1 render encoder
  between every two: 61.6-65.0 ms against 107.4-118.6 ms.
On the RTX 5080 Laptop GPU (NVIDIA 615.71.09), the same probe, runs 1-3: 6.6-10.0 ms against
40.6-43.0 ms, and 9.7-12.3 ms against 44.5-47.1 ms. The same 11 shadow, merge and linear device
tests passed there.
clippy --all-targets --all-features -D warnings passed plain and with --cfg m2v_gpu, and cargo fmt
was run.

(cherry picked from commit bf783428131f46c7289518a50b8505e809ecc8e5)
(cherry picked from commit 99949a4cd08cd042e448484e0b1d2f5da1898db5)
2026-11-03 15:58:53 -08:00
Anees Iqbal 385a2ed40f Record host steps on up to eight threads, so one queue's long step holds back no other queue's
What: scheduler/steps.rs had one thread per device record every host step of every queue, in
hand-over order. It now hands each step to a free thread of a pool, or starts one for it below
THREADS (8); past the cap a step waits for the first thread free, in hand-over order. The first
thread stays until the scheduler stops, as the one thread did; each later one ends after 2 s with
no step. All start at the user-interactive class, each step is still a section of the exit guard,
and where the host cannot start the first thread the scheduler's thread records the step itself,
as before.

Why: the consumer (one device for every guest process) saw WindowServer's present wait 13.6 s in
the host after the page's context had closed. A page's render-bundle ICB execution was recording
a seconds-long host step, and any command buffer whose draw or dispatch has a pipeline still
being made takes a host step too (deferred.rs: RenderPass with making(), Pending), which queued
behind the page's on the one thread. A dead context's step keeps recording, as its command buffer
holds what it uses.

Order is still the scheduler's: only a line's head is handed over, marked stepping until its step
ends, so a logical queue's steps are recorded one at a time in its order, and a head that waits
for an event value, or is behind an earlier commit's conflicting batch (order.rs), is not gated
or handed over (gate_heads takes `behind`).

Audit of what assumed one step at a time device-wide:
- kept chunks (kept_commands.rs): no host step uses them (render executions keep only when
  !step, compute executions only when states.is_none());
- upload and descriptor arenas: per command buffer (State::uploads, State::descriptors); their
  spares are the device's, under a lock; the command pool is per command buffer, recorded under
  its `reencoding` turn, which host_step takes;
- pipeline making: the pool, the budget's turns and the making maps already serve concurrent
  encoders; the in_host_step()-gated branches (Urgency::HostStep, keep_room skipped, kept
  variants not taken back, takes_multi_variable_dynamic, make_at_creation skipped, sampler-set
  count) read a thread-local, so they hold per thread; kept.rs StepNumbers is thread-local and
  per command buffer, whose steps stay sequential, `made` handed on through end_step and the
  scheduler's locks;
- residency: a command buffer's own value, its address index made per residency;
- the scheduler's wake and hand-over: record() marks the inbox under its lock and wakes, as a
  committing thread does; begin_step/end_step are the command buffer's atomics; post pushes
  under the steps' lock;
- the exit guard: sections are counted per thread and in atomics, HOST_STEPS is thread-local,
  called() is atomic; many sections at once were already normal;
- interior mutability used by the steps thread alone: none besides the steps' own state (every
  shared object is Sync and shared with committing threads already);
- notices: every-occurrence notices announced inside steps (each_in_order) of two queues may now
  interleave; Metal orders nothing between such queues.

Docs: the scheduler's "Host steps" section, left.rs, WorkCounts' host-step counters, kept.rs,
RecordsRead::HostStep and FAST-PATHS.md's pipeline-wait row say steps' threads. The
host-replayed-indirect-commands notice already says only resources the execution may reach hold
later batches back, so it is unchanged.

Verified on the M3 Max (MoltenVK, --cfg m2v_gpu, maclock+memcap), with the next commit's lane
test runtime_lane::steps_apart::another_queue_goes_on_while_a_host_step_records: before, queue
B's own stepped command buffer did not complete within 10 s while queue A's step was held (A's
objects kept, and released); after, 18.6 / 18.9 ms in debug. Its ordered checks (a step after
an event A signals, and a pass into A's target) begin only after A's step ends, before and after.
Negative control: THREADS = 1 fails the test again (Stepped, kept and released); restored and
touched. Release, A a real 5000-draw step (2.7 to 5.0 s), B's stepped kind went from 3580 ms
(released: 3359) to p50 1.49 / max 15.6 ms (released: 1.65 / 40.4); idle 1.32 ms p50.
Runtime tests::(scheduler|inbox|host_step|waiter_submits|commit_and_submit|completion_order|
unsubmitted|pipeline_wait_order|blit_order): 50 passed. Lane cases (indirect, kept,
*executions, *host_steps, submi*, steps_apart, resident_draws, event_round_trips,
command_queues): 272 passed. clippy --workspace --all-targets --all-features -D warnings, plain
and with --cfg m2v_gpu: clean.

(cherry picked from commit e15fd6752fe4f714b73dab0ee72d15fce686f3d7)
(cherry picked from commit 229f407b2abe2de5b85bf3d98b2080d0a0667e9d)
2026-11-03 13:34:03 -08:00
Anees Iqbal f6692d84e5 Keep an ICB execution's chunks where its check can see nothing among its commands
Before, any execution given a check (execute_commands_in_buffer_checked) recorded every command at
every commit and kept no chunk, even when the check's needs ruled out everything the buffer's
records may hold. In that case commit never calls the check: RenderExecution::check_sees and
Execute::check_sees answer from the needs and IndirectCommandBuffer::command_writes. A consumer
that hands every execution of own-state commands a check for draws of points, and draws
triangles, never had its unchanged commands run from kept recordings.

Now RenderExecution::keeping declines where `self.check_sees_now()` holds, and Execute::keeping
where `self.check_sees()` holds. The decision is the structural one commit makes for the check,
the check's needs against what the records may hold. When a later write makes the records hold
something the check looks for, it forgets the chunks it reaches. At the next execution
check_sees is true, so keeping declines and the execution records inline, calling the check with
every command.

Docs: the "Which executions" lists in render/executions/kept.rs and indirect_execute/kept.rs, and
docs/FAST-PATHS.md's kept-recordings row.

Tests (runtime_lane::kept_commands), counting records read, chunks and commands kept and
contexts made (WorkCounts::indirect_chunks_kept and kept_contexts_made show the kept path ran),
and the commands the check was called with:
- a_checked_execution_keeps_where_its_check_sees_nothing (render). With needs for states that
  may encode indirect commands, which the inherited state can't, the check sees nothing:
  [N, 0, 0, 0], then [N, 0, 0, 3], then [0, 3, N, 0], and the check is called 0 times. With
  needs for draws of points, which the records hold, the check sees: [N, 0, 0, 0] three times,
  and the check is called with all 3N commands.
- a_checked_compute_execution_keeps_where_its_check_sees_nothing: a compute execution checked for
  every kind. Its records hold no draw and no state that may encode, so it keeps as above, and
  the check is called 0 times. No fixture kernel encodes indirect commands, so compute has no
  "check sees" leg.

Verified on the M3 Max, debug (--cfg m2v_gpu), on lane 7583fe5d99 with the first-execution ruling
cherry-picked beneath it:
- nextest -j 8 over every runtime_lane module that executes an indirect command buffer: 39
  modules, 473 tests, all pass.
- Negative control: keep only with no check at all (the condition before). Both new tests fail
  at "the second records three chunks to keep" ([600, 0, 0, 0] where [600, 0, 0, 3] is expected).
- Negative control: keep whatever the check (render). The render test fails at "a check that sees
  keeps nothing" ([0, 3, 600, 0] where [600, 0, 0, 0] is expected).
- fmt --check, clippy -D warnings (runtime and validation, all targets and features, m2v_gpu),
  metal2vulkan tests::fast_paths 19/19.

Needs a RUNTIME_VERSION bump. No SEMANTICS_VERSION: no translated module changes.

(cherry picked from commit d75cb04ac8ed9d4616b10aa13d26af869a32d405)
(cherry picked from commit efafed587dd062f7d87bd9c9868ccb035e9ddc26)
2026-11-03 13:34:03 -08:00
Anees Iqbal 24dc3f20bb Keep an ICB range's chunks from their second execution, and forget a written chunk in one store
A range's first execution no longer pays for keeping. Before, every execution of CPU-encoded
commands recorded each 256-command chunk apart, in a KeptContext of its own (a command pool, a
descriptor arena and uploads), so it could run that recording again later, even when no later
execution came. Now a chunk is recorded to keep only from its second execution with no write
reaching it since. The first execution since a write records inline, as before 922caf3199, and
keeps nothing. A consumer that re-encodes every command each frame now pays nothing for keeping.

- kept_commands.rs: KeptChunks notes which chunks an execution that may keep its commands ran
  since a write last reached them. look_up answers each chunk of a range as Kept::Recording (a
  kept recording), Kept::Again (run before, nothing kept) or Kept::First, and notes each as run.
  IndirectCommandBuffer::kept_chunks answers None, so the execution records inline, when every
  chunk is First. When some chunks are kept and others are not, a First chunk records apart from
  its command buffer's own pool and arenas, with no KeptContext, and is not kept. An Again chunk
  records apart in a KeptContext and is kept.
- KeptChunks is dense: one ChunkState per chunk (kept recording, stepped, seen) up to the
  furthest chunk looked up, plus a flag for whether any chunk holds a state. KeptChunks::wrote
  costs one store per chunk the written range covers, whatever the number of kept chunks, and
  returns at once while no chunk holds a state. Before, it ran BTreeMap/BTreeSet::retain over
  every kept and stepped chunk on each setter call.
- WorkCounts::kept_contexts_made counts the KeptContexts made (api_signatures.tsv).
- Docs: kept_commands.rs, render/executions/kept.rs, indirect_execute/kept.rs and
  docs/FAST-PATHS.md (the kept-recordings row).
- examples/icb_setters.rs --kept now executes three times before each repetition: the first
  keeps nothing, the second records every chunk to keep, and the third runs all of them from
  those recordings.

Tests:
- runtime_lane::kept_commands asserts kept_contexts_made beside the records read and the chunks
  and commands kept.
  - A once-executed range makes no context: [N, 0, 0, 0].
  - Its second execution keeps every chunk: [N, 0, 0, 3].
  - Its third runs them: [0, 3, N, 0].
  - After a write, the written chunk records inline again and the next execution keeps it.
- kept_commands::tests::a_write_costs_the_chunks_it_covers asserts the count of chunk states
  wrote() looks at.

Verified on the M3 Max:
- Debug device lanes (--cfg m2v_gpu, nextest), with the live compute flags fix from stack22
  applied locally (not part of this commit): every runtime_lane module that executes an indirect
  command buffer (39 modules, 471 tests) pass.
- Negative control for the ruling (each chunk keeps from its first execution), debug:
  3 of the 5 kept_commands tests fail, a first execution making 3 contexts where 0 are expected
  and a written chunk making 2.
- Negative control for wrote() (it walks every chunk state): a_write_costs_the_chunks_it_covers
  fails, looking at 1000 states where 1 is expected.
- Unit tests: kept_commands::tests 2/2 and metal2vulkan tests::fast_paths 19/19.
- cargo fmt --check and clippy -D warnings (runtime and validation, all targets and features,
  --cfg m2v_gpu) are clean.
- icb_setters compute --kept (release, instructions per command, median of 30, two runs each):

  | | before (2c542021bf) | after |
  |---|---|---|
  | compute command, nothing kept | 2528.7 / 2529.1 | 2428.1 / 2427.7 |
  | compute command, 64 chunks kept | 5947.8 / 5945.5 | 2586.5 / 2583.9 |
  | set_kernel_buffer, 64 chunks kept | 1129.6 / 1129.6 | 456.9 / 456.3 |

  With three executions, the third runs all 64 chunks from kept recordings (the
  bench prints [64]), at 2583.9 and 456.3 instructions.
- conformance cost --alone indirect-render-commands-inherited-state reads arena_pools_made 1,
  argument_objects_retained 2 and argument_tables_retained 1, the recorded bounds. With a first
  execution's KeptContext these read 3, 6 and 3 (the cost run that held its record back).
- execution_costs (release) on a loaded host: wall times are dominated by host load. An earlier
  pair of runs read the first execution as slower (render n=1024 all re-encoded commit 2.88 to
  6.55 ms), but the parent then read 6.55 ms itself under the same load. Time Profiler, test
  thread CPU, same case and count, this change on 2b55ab415e against its parent:
  - render n=1024 one re-encoded, 300 executions: 611 to 610 ms;
  - compute n=1024 all re-encoded, 80 executions: 336 to 333 ms;
  - render n=1024 all re-encoded, 120 executions: 782 to 859 ms. This is the inline path's
    whole-range read: RenderExecution::commands collects the range into a second
    Vec<Option<Command>> (memmove 0 to 25 ms in RenderExecution::record), and render_records
    reallocates as it grows. The same profile has IndirectCommandBuffer::edit, whose code is
    the same in both builds, up 31 to 40 ms, so part of the difference is load.
  A later run of this commit's tree read render n=1024 all re-encoded at 2.37 ms commit, one re-encoded
  at 0.61 ms, and compute n=1024 all re-encoded at 3.49 ms.

Needs a RUNTIME_VERSION bump. No SEMANTICS_VERSION: no translated module changes.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Now:

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

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

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

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

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

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

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

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

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

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

Needs a RUNTIME_VERSION bump and a runtime-sources pin.

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

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

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

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

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

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

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

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

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

(cherry picked from commit 409aafaca513c03f6bad3378de1f0d8af6fdc5f0)
(cherry picked from commit 2b5f0731c54fa66350e88c82fceaed9909dc442a)
2026-11-03 07:56:21 -08:00
Anees Iqbal 7996b9a164 Mark a queue long by its command buffer's own GPU time, not the host's view of its head's age
What: a command queue is now marked long where one of its command buffers' own timestamps (its
first batch's start to its last's end) span over LONG_HEAD (2 ms), in the completion turn that
read them (CommandBufferShared::place_gpu_times), before the turn finishes it. The waiter's
host-age check in command_buffer/completion.rs (HeadWatch, Device::head_watch) is removed, and
went_long returns at once unless the device shares. A device whose command buffers write no
timestamps the host reads (gpu_times_from_host, a driver whose timestamps wait for every queue's,
or no calibrated timestamps) no longer shares: queue_switch_check::timed() gates the check, and
recall settles Unchecked and counts the new WorkCounts::queue_sharing_untimed where the device has
two VkQueues of one family to share. Two runtime extensions, doc-hidden, for the lanes and the
probe: CommandQueue::vk_queue_sharing() (its VkQueue and long mark) and Device::shares_vk_queues().

Why: the host's view of a batch's age as its VkQueue's oldest also holds its wait for the GPU to
start it and the waiter's lateness to see it complete, so short command buffers marked their
queues long for good. On the RTX 5080 Laptop GPU, 2x3 runs in a slow stretch had each thread's
queue marked long mid-run (at 20 ms to 1,238 ms) and settled apart, the PerQueue placement, at
PerQueue's rates. Measured cause, with a diagnostic build printing each host-age mark beside the
command buffer's own GPU span: beside another process's 30 ms command buffers, draws of 11 and
16 us of GPU time were seen 2.0 and 2.3 ms after they became their VkQueue's oldest, 1.8 and 2.1
ms of that before they started; that run's thread queue settled apart and ran at PerQueue's
4.1k. In the runs without contention, every true mark had a GPU span within 1.2 ms of its host
age (the 30 ms command buffers and the probe's 2.7 ms sizing one); under contention the sizing
command buffer's host age exceeded its span by 4.2 ms. Neither suggested alternative fits: the false
marks came mid-run, not only in a queue's first command buffers, and decaying the mark after short
heads would let the trap and alternating shapes' long queues rejoin and stall the compositor again.

Tests: tests::queue_share_device gains a_device_that_answers_gpu_times_from_the_host_does_not_
share_and_counts_it (expected, not run, to fail without the gate on the 5080: there it printed
"Unchecked ... could share: true", so the recorded Idles verdict would make it share), and
asserts queue_sharing_untimed == 0 elsewhere; its isolation runs print each queue's VkQueue and
mark over the run. The queues lane's a_queue_joining_another_s_busy_vk_queue_is_announced_once
now makes its device under QueueSharingPolicy::Adaptive (over the lane's exact_answers()), lets
the busy queue's fills be submitted first, and asserts queue_joins > 0 exactly where the device
shares, saying why where it does not. cross_queue_shadows gains the signal-in-between and the
waiting-writer cases on one VkQueue: no spin, Adaptive, the check settled, queue 2 joining queue
1's busy VkQueue; they assert the join, neither queue long, the hold still withheld while the
waiting writer has not completed, and the bytes.

Docs: QueueSharingPolicy::Adaptive, the FAST-PATHS row (the rule, the untimed exclusion, the new
ranges), docs/API.md (the policy section and the notice), the queue-sharing notice's cost text,
queue.rs and queue_share.rs; api_signatures blessed (additions only).

Verified on the RTX 5080 Laptop GPU (NVIDIA 615.71.09, msi, under gpu-locks, no VM), release
probe:
- 2 threads x 3 in flight, 10 runs each in turn: Adaptive 48.3, 28.0, 50.7, 52.9, 28.1, 53.7,
  48.6, 29.9, 31.5, 53.0k against PerQueue 21.4, 24.9, 27.8, 28.0, 27.6, 27.4, 27.1, 23.3, 26.9,
  27.3k, Adaptive above PerQueue in each pair; no thread's queue marked long in any run (gone long
  1 each: the probe's sizing queue). The 28-31k runs keep the shared placement, with waiter parks
  0.23 against 0.02-0.05 per command buffer in the fast ones: a host-side mode, not a move.
- Beside another process's 30 ms command buffers, 3 runs each: the old rule 4.1k (a thread's
  queue marked long by its host age), 5.2k, 6.6k; this rule 6.7k, 5.4k, 5.1k (no mark); PerQueue
  4.1k, 4.1k, 4.0k. There, draws' own spans reached 1.16 to 1.52 ms (timesliced), under the bound.
- Isolation, 3 runs each: trap and slow-alternating 64 completions over 10 ms under Adaptive (the
  one first-long stall, at most 26.4 to 30.1 ms) against none under PerQueue (at most 5.6 to
  9.7 ms); alternating none under Adaptive (at most 5.7 to 9.8 ms) against 7, 0, 0 under PerQueue.
  Unchanged from the host-age rule's runs.
- 8 threads: 3 in flight 53.4k, 54.4k against 27.8k, 27.4k; 1 in flight 50.1k, 49.3k against
  14.0k, 13.9k.
- Device tests (debug, --cfg m2v_gpu): tests::queue_share_device 8/8, the joining lane test and
  cross_queue_shadows 7/7 (the one-VkQueue cases: X's and Y's queues both on VkQueue 1, neither
  long, holds withheld 2, gated copies in 2). The compositor isolation test, old rule and new in
  turn, 3 each: p99 2.66-2.94 ms against 2.16-2.83 ms, 0 stalls, the same placement (the
  compositor alone on VkQueue 1, the application long on VkQueue 0, gone long 1). Its one earlier
  failure under this rule (p99 7.93 ms, 20 stalls, 5,579 of ~9,600 commits made) ran right after a
  74 s compile inside the hold, with the same placement and gone long 1: host load, not the rule.
On the M3 Max (MoltenVK, no sharing), tests::queue_share*, command_queues, cross_queue_shadows,
gpu_time and host_memory: 90/90. clippy -D warnings plain and --cfg m2v_gpu; RUSTDOCFLAGS=-D
warnings cargo doc; fast_paths, degradation*, api_signatures, api_surface, work_counts pass.
No RUNTIME_VERSION bump or pin here.

(cherry picked from commit 4fd88b7564cd9cd3651543bb3f8cd529b021709e, two claims corrected to what was run)
(cherry picked from commit eb0153e9d0fe6d272f2411c65f0a1ecda2c78bc2)
2026-11-03 06:50:11 -08:00
Anees Iqbal aa9b38e6fd State the padded sRGB twins' code and decode bounds as measured
DevicePackConversion's documented bound for the extended-range and
padded conversions said "a code within one" of Metal's. For
R10Unorm_X6_sRGB and RGB10A2Unorm_sRGB that is wrong. Metal's write of
these formats rounds the value clamped to [0, 1] to 2^-13 (nearest even)
and then looks it up in its encode table (R10X6_SRGB_ENCODE_FIRST). The
device writes the MSL transfer by its own maths, times 1023, RoundEven.
In the transfer's linear segment, one 2^-13 step spans 1.6 codes, so the
two can land two codes apart.

Measured: for each 2^-13 step over [0, 1], the f32s at and next to both
edges, where Metal's code is constant within a step and the device's
code rises with the value. The device's code (exact transfer) lies at
most two from Metal's table. It reaches two only below 0.0031308: at
1.5/8192, just above 6.5/8192, and at 24.5/8192. Everywhere else it is
within one, beyond the Pow's bound. Metal's recorded writes and stores
of RGB10A2Unorm_sRGB on the M3 Max under macOS 27.0.1
(rgb10a2-srgb-writes, -stores-f, -stores-h) show exactly that: three
words each, at k/16384 for k = 3 and 49, and at the 1.5/8192 special.

Metal's decode of RGB10A2Unorm_sRGB's colour (the rgb10a2-srgb-reads
recording, every code) lies up to 1.637 steps of 2^-13 from the exact
transfer (code 952: Metal 0.84912109, exact 0.84932096). That is the
1.64 the docs gave for R10Unorm_X6_sRGB only.

So artifact.rs's DevicePackConversion, the FAST-PATHS air.pack row and
API.md's catalogue entry now give, for those two formats only: a colour
code within two below 0.0031308, and a decoded colour within 1.64
steps. Doc text only: the device's conversion is unchanged (rule 1),
and so is behaviour. No version bump.

(cherry picked from commit 8bfaab43bd6c6368c41d58caa7e9c91fe64820d5)
(cherry picked from commit e728f0fa394c46c528d2f99df89a33751f5691d7)
2026-11-03 04:10:31 -08:00
Anees Iqbal e94d068b3b State the queue sharing row's measured rates over the 5080's spread
What: docs/FAST-PATHS.md's queue sharing row now gives each shape's measured range with its
run count, in place of the first three-run set's.

Why: two more sets on the RTX 5080 Laptop GPU (NVIDIA 615.71.09, release, one-draw command
buffers, each thread its own queue) widened the ranges:
- 2 threads with 3 in flight: Adaptive 27.0k to 46.5k a second in 13 runs after a hold's first.
  It fell within one hold, from 42.5k to 27.0k, while PerQueue stayed at 25.6k to 27.5k. Two
  more runs gave 15.4k and 17.7k; in both, one of the two queues was marked long as it began
  (gone long 2 or more, against 1 in every fast run). PerQueue: 25.2k to 27.7k in 14.
- 2 threads with 1 in flight: 16.9k to 20.7k against 10.1k to 11.5k (5 each).
- One thread over 16 queues in turn: 21.7k to 43.3k against 10.2k to 11.1k. Over 2,048:
  20.0k to 39.2k against 10.2k to 11.2k (4 each).
The 8-thread shapes keep their three-run ranges. One third of one hold, where both policies
fell to 8.1k to 13.0k, is left out. Under PerQueue the pair of VkQueues made no difference:
2 x 3 with the second queue 1, 7 or 13 places after the first ran 25.6k to 27.5k.

Verified: tests::fast_paths (19 passed).
(cherry picked from commit adb362078504cca24358e8d9c331eb1b831a2b57)
(cherry picked from commit 27999318cbb31bc8a46f24a28c40a6b80c7e2f4d)
2026-11-03 03:36:43 -08:00