Commit Graph
594 Commits
Author SHA1 Message Date
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 39639ef473 Follow struct members in the narrow analysis: mixed-select merges and a read's noted bits
What. Two analyses in lower/arith/narrow.rs looked only at whole values, so a value carried
inside a composite slipped past both:

- `merges_mixed_selects` (now `narrow::merges`) decides whether a module merges a select of a
  widened `half` against a value it does not hold widened with another widened value. Metal's
  compiler answers 2045 of the 2046 `half` NaNs of that merge `0x7E00` (measured on the M3 Max,
  2026-11-03), so a module that does it stays outside `DriverDeviation::MetalNanMoves`. It
  checked only scalar selects at phis and stores, and missed the same merge when a struct (a
  texel read's `{T, i8}`), an array or a vector carried the select and the other value. The new
  module records how each value is made (construct, insert, extract, copy, select, phi) and asks
  member by member, by a path of literal indices, whether a merged value holds a mixed select
  where another merged value holds a widened one. Walks are bounded (256 steps per question, 256
  members per type; past a bound the answer is the conservative one), and the records are charged
  to the meter.
- `known_bits` reused a `half`'s read bits only when the stored value was the read itself. A
  store of the read's value pulled back out of a struct (`{T, i8}` built from the read, then
  `OpCompositeExtract`) encoded the `half` again, which is the device's narrowing and loses a NaN's
  bits. The builder now records each struct construct, insert and extract it emits
  (`ModuleBuilder::structs`, counted in its footprint), and `FunctionBuilder::member_source`
  walks an extract back to the value that supplies the member wholly. A later insert into part
  of the path, a struct the builder did not make, a load or a phi gives no source. `known_bits`
  follows it before looking up noted bits.

Both decide from IR structure only (types, composite paths, operands), never from names.

Why. The coordinator's bug: `narrow::merges_mixed_selects` misses struct-wrapped merges, and a
store of a read's value does not see noted bits through the `{T, i8}` extract.

Docs: driver_facts.rs (the MetalNanMoves measurement) and docs/API.md's native-nan-encoding
entry now say the merge is followed member by member, and that a `half` moved unchanged from its
read keeps its bits through a struct's member too. The member-by-member reading is not measured
through a composite; the code and the docs say so.

SEMANTICS_VERSION 1968 -> 1969: translations change. The golden table moves 30 cells, all
`engine/rfs_imageblock_cover{.ll,.air.ll} | cover_two_word`, on every one of the 15 profiles.
That kernel's `as_type<half>` result is now stored from its noted bits through the struct
member instead of being encoded again. The table is re-blessed on development, not here.

Verified on the M3 Max (potluck, debug):
- New tests:
  - `lower::arith::tests::narrow::narrow_members_move_as_bits_through_structs`: every
    pattern of every narrow form, through a construct, inserts, a nested struct, and a
    replaced member, compared exactly.
  - `lower::arith::tests::narrow::a_merge_of_a_select_is_followed_through_struct_members`:
    builder-made `OpPhi`s of a plain select and of structs carrying it by construct, insert
    and extract are merges; a struct holding the select apart from the other value's member,
    and a merge with a constant, are not.
  - `tests::engine_arith::half_moves_are_metals_only_where_the_device_folds_them` gains
    kernel `member_kept`: a `half` read, inserted into `{half, i8}` and extracted keeps its
    bits (0xFE01) and widens nothing.
  All three, plus engine_cross_class and engine_float_call_notes, pass: 15/15, job
  m3-max-1192.
- Negative controls, with the translator sources of fd1029d6c9 under these tests (job
  m3-max-1195): all three fail.
  - The merge test fails at `Struct` (false, want true).
  - The members test fails "Form { held: Float(Half), lanes: 1 } through a struct
    (construct): 2045 of 65536 cases differ".
  - `member_kept` widens on lavapipe (true, want false).
- Note sets: a census of every public fixture's entries (2914 rows per stem) on moltenvk-m3 and
  lavapipe. It recorded each row's precision notes and whether it requires MetalNanMoves, before
  (fd1029d6c9's sources) and after. The two files are byte-identical (job m3-max-1195), so no
  fixture gains or loses a note on either device.
- Full metal2vulkan suite at an earlier stage of this change: 3335 passed. The 2 failures were a
  since-corrected test expectation and the golden table above (job m3-max-1190).

(cherry picked from commit a4c235fb867a6a32098b77e39387c43a97a28862)
2026-11-05 07:39:33 -08:00
Anees Iqbal be34c40f1d Bound a packed blend by the code its sample was stored at
The multisampled word lane compares each blended sample of a format the
device renders itself with Metal's within one code. The blend reads the
sample the device's fill stored, which the lane already accepts a code from
Metal's (the device's conversion, `device-color-conversion`), and the device
blends over that code by its own arithmetic, so the two native differences add.
On lavapipe (Mesa 26.2.4, LLVM 23.1.1) `A1BGR5Unorm` at 4 samples, pixel 12:
the fill stored 0x9ea1 where Metal stored 0x9e61 (green 26 against 25), and
source-over at alpha 0.102 stored 0x9ea5 against Metal's 0x9e23 (green 26
against 24, blue 18 against 17); the exact blend over the device's own sample
is green 25.31, blue 17.44, so the device's blend is itself within a code.

The lane now allows a blended sample one code more for each code its stored
sample lies from Metal's (none on the word path, whose fill is exact).
`PrecisionNote::DeviceColorConversion`, `Degradation::DeviceColorConversion`
and docs/API.md's catalogue record the measured lavapipe bound: within 2
codes over a sample stored a code from Metal's.

Verified on msi-laptop, lavapipe (Mesa 26.2.4), `--cfg m2v_cpu_icd`: at
b23d78eb50 `multisampled_word_formats_store_read_resolve_and_blend_as_metal`
fails on that one sample (word 0x9ea5 against Metal's 0x9e23), every other
blended sample within one code; the words above came from a scratch
diagnostic run (not committed).

(cherry picked from commit 5a4a8ca8fc297b03f19b39cf675eee1ada29742c)
2026-11-05 07:39:32 -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 751135f389 State a gathered 32-bit float denormal, flushed to a zero, in device-texel-conversion's bound
runtime_lane::half_read_nans::half_float_reads_hand_back_metals_nans on the RTX 5080 Laptop GPU
(NVIDIA 615.71.09, at 961b1ff319): with the gathered NaNs taken (eb9a8db1ac), 24 lanes still
differed, every one a gathered 32-bit float denormal (0x00000001, 0x80000001 in R32Float,
RG32Float and RGBA32Float) handed back as a zero of its sign, where Metal hands back the texel's
bits; the device's reads and samples of the same texels hand them back as stored. The gather is
the device's texture unit's, which DeviceTexelConversion records off Apple GPUs; its bound named
the gathered NaN, not the denormal. An under-stated bound.

What: DeviceTexelConversion's bound (pipeline/artifact.rs) and docs/API.md's catalogue state a
32-bit float texel's denormal in a gather as flushed to a zero of its sign; the lane takes such a
lane for Metal's where the device's texture unit is not Metal's. The note's condition is
unchanged, so no translation, note set or classification moves.

Verified: the 24 differing lanes of the 5080's run are each a flushed gathered denormal (the lane's
HALF-READ-DIFFERS lines); the lane reruns in the next proof run.

(cherry picked from commit ec73c51148a57302b1c6cc8f421c4b02692036e5)
2026-11-05 05:10:59 -08:00
Anees Iqbal c6901502d2 Prove max_buffer_length's heap bound in the lane: a buffer one byte past it is nil, one of it is made
The lane's a_buffer_past_max_buffer_length_is_nil prints the device's
max_buffer_length (MAX-BUFFER-LENGTH) and refuses a Shared and a Private
buffer one byte longer as Nil(new_buffer, BufferLength), as plain Metal
answers nil past maxBufferLength. The ignored
a_buffer_of_max_buffer_length_is_made_where_the_heap_bounds_it makes a
Private buffer of exactly max_buffer_length where the heap bound is below the
compile layer's answer (the RTX 5080 Laptop GPU's) and refuses one byte more;
it takes three quarters of the device's memory, so it runs only by name.

docs/API.md's accepted differences name the proxy: the largest DEVICE_LOCAL
heap stands for Metal's recommendedMaxWorkingSetSize, which Vulkan does not
report.

Verified: not yet built (potluck build queued).
(cherry picked from commit 77fc830057352d11837826a8bb181ebb9a6bac5b)
2026-11-05 05:10:58 -08:00
Anees Iqbal 12497a0aad State a gathered 32-bit float NaN in device-texel-conversion's bound
half_read_nans failed on the RTX 5080 Laptop GPU (NVIDIA 615.71.09): a gather of R32Float,
RG32Float and RGBA32Float hands back 0x7fffffff for every NaN texel (64 lanes each), where Metal
hands back the stored words; the same texels read and sampled come back as stored. The gather
records PrecisionNote::DeviceTexelConversion off Apple's GPUs, whose bound said every class but a
half-float or small-float NaN is Metal's value.

What: the bound (the note's rustdoc and API.md's catalogue) states a 32-bit float texel's NaN in a
gather as the device's encoding, with the 5080's answer; half_read_nans takes a gathered 32-bit
float NaN for Metal's where the device's texture unit is not Metal's, as it takes a half-float
texel's NaN. No note is recorded differently, so no version moves.

Verified: compile and the 5080 and M3 runs follow in the lane proof run.
(cherry picked from commit 8e537ae9c2c3ad814c0973841b2454fa15d66120)
2026-11-05 05:10:58 -08:00
Anees Iqbal fc79fdd4e9 Announce every NVIDIA RTX 5080 Laptop clear and plain fill off a whole code: its clears take either nearest code
runtime_lane::color_fills::plain_color_fills_are_the_device_s_clear (vkCmdClearColorImage of 762
colours into each of 70 formats) on the RTX 5080 Laptop GPU at 0b556ddfd6: 352 fills stored 382
normalized channels a code from Metal's, each one of the two codes nearest the scaled value,
unannounced where the value was not near a midpoint. Vulkan allows it ("returns one of the two
unsigned binary integer values with exactly b bits which are closest to the floating-point value
r. Implementations should round to nearest"). The 8- and 16-bit unorm and snorm channels went
toward zero (R16Unorm's 0.001, 65.535 codes, stored 65; R8Snorm's -0.5 stored -63), packed and
10-bit channels and an sRGB format's alpha at times to the code above the nearest. An under-note.

What:
- DriverFact::ColorClearTakesEitherCode, on the RTX 5080 Laptop GPU (NVIDIA), with its
  measurement in its doc.
- clear_value::rounds_apart takes the fact: on such a driver a normalized channel's clear is in
  question wherever its scaled value is off a whole code, not only near a midpoint; the clear and
  the plain colour fill (blit_fill, fill_value, render_pass) announce device-color-conversion then.
- docs/API.md's catalogue entry for the clear conversion names the fact.
- Tests: driver_facts' table test; a fill_value unit test of the rule on the measured cases with
  and without the fact; api_signatures for the new variant.

Verified: in the lane proof runs on the 5080 and the M3 (counts in the series' last commit). The
M3's and lavapipe's facts are unchanged, so their notices are.

(cherry picked from commit f2da9346bb51ed034f0d5f8bf076c8d55c57f277)
2026-11-05 05:10:38 -08:00
Anees Iqbal f1def3dffe Count a texel's half rounding as the measured conversion on MetalHalfConversion profiles
Re-applies 384734851d (reverted in the stack by 5dbf6f3be3) on top of the previous commit, which
merges a heap half read's class arms as the texel's half bits.

What: narrow::round_texel rounds through round_measured, so in QuantizeForm::Converted the
conversion pair's narrowing is recorded as measured. On a profile that takes
DriverDeviation::MetalHalfConversion (MoltenVK on the Apple M3 Max's macOS 27 identity) a texel's
half rounding records no PrecisionNote::NativeHalfConversion, and the module requires
VkProperty::MetalHalfConversion instead: a texel the module decodes itself
(extended_range::decode), a merge of texels (a heap read's phi of its fetched texel and its decode
routine's) and an image instruction's. The note stays for roundings by narrow::round: half
operations and functions computed in float, filter sums, packs and the rest. Other profiles never
read the measured set, so they are unchanged by construction, and round_measured emits the same
pair, so the SPIR-V is unchanged. SEMANTICS_VERSION 1967: recorded notes change on moltenvk-m3.

Why: reims-vgpu's strict Mac tests die on native-half-conversion at a kernel that reads an
argument buffer's texture as half (their ycbcr_probe.metal read_held, over BGRA8Unorm). Every heap
half read carries the decode routine of the seven extended-range/padded/bfloat forms, and its
merge, so it recorded the note whatever the texture. MetalHalfConversion measured the device's
conversion as Metal's half(float) for loaded and computed floats; where Metal's half texel is not
the nearest even half of the texel's value, the access's own note states it: HalfTexelConversion
(outright for a heap element, by the bound class at a slot) or DevicePackConversion (a decoded
texel). The stack 28 gate's cross-class lane failure that reverted it came from the heap read's
merge of widened halves, not from a rounding: an integer texel's bits read as half go through no
rounding, and the previous commit merges them as integers, so they keep their bits without a note.

Kept from 384734851d: the core tests heap_half_texels_round_by_the_measured_conversion and
decoded_half_texels_round_by_the_measured_conversion, the M3 lane
heap_extended_reads::heap_half_reads_of_every_code_round_their_float (half_conversions::half_of
made pub(super) for it), and the docs: the PrecisionNote, DriverDeviation and VkProperty rustdoc,
API.md's native-half-conversion exemption, the driver-facts record (which now also says the
argument buffer's cross-class half read rounds nothing and names its lane), narrow's docs.
runtime-sources.sha256 moves for the doc edits in driver_facts.rs and requirements.rs, which change
no behaviour of a run.

Verified: pending in this commit; the next jobs run the core and M3 lane checks on it.
(cherry picked from commit 1757bd7866aa87c4e38ab83f0b4c4d83e68c75bb)
2026-11-05 04:28:29 -08:00
Anees Iqbal 5dbf6f3be3 Revert counting a texel's half rounding as measured on MetalHalfConversion profiles
This reverts the stack's pick of 384734851d ("Count a texel's half rounding as the measured
conversion on MetalHalfConversion profiles"); SEMANTICS_VERSION goes to 1965, since the recorded
notes change back.

The stack 28 gate's M3 lane run failed
runtime_lane::cross_class_reads::argument_buffer_cross_class_reads_are_the_native_words: an
argument buffer's half read of an integer texture (R8Sint, RGBA8Sint, RG16Sint, RGBA16Sint,
RGBA32Sint, RGBA16Uint, RGBA32Uint; 66 of 2170 lanes) answers the device's quiet NaN 0x7e00 where
the slot's read of the same texel keeps its bits (0xfff5 and the like). The heap read rounds its
texel through float, and that rounding's narrowing no longer recorded NativeHalfConversion on
moltenvk-m3, so the stage carried no note that leaves a half NaN's bits to the device (the notes
were SetPastLayoutSupport, DeviceNanEncoding and HalfTexelConversion). The commit's measurement
covered the extended-range forms' codes, not an integer texel's bits read as half. Until a fix
keeps those bits or notes them, the note stays as it was before the change.

The doc conflict in driver_facts.rs (a later pick's measurement paragraph for the reverted rule)
takes the text from before the change.

Verified: not yet; the gate reruns the core suite and the M3 lanes on this tree.
2026-11-05 02:46:28 -08:00
Anees Iqbal 4f32162f99 Regenerate the conformance coverage document for stack 28's cases and recordings
The coverage document is generated from the suite's sources and recordings; the stack's picks
each regenerated it on their own base, so it is derived again here once over all of them.
Verified: python3 -I scripts/conformance-coverage/coverage.py --check reports it as derived.
2026-11-05 02:09:58 -08:00
Anees Iqbal 95859dac16 Regenerate the conformance coverage document for the composited row
python3 scripts/conformance-coverage/coverage.py over the tree with
pass-start-barrier-private-composited's recording: one more recording, case and Metal-run answer,
and the Metal items the row reaches counted once more.

(cherry picked from commit 0147b3a386081175dfaffa7c72513efac6def034)
2026-11-05 02:08:34 -08:00
Anees Iqbal bc1d0ab837 Say in render-pass-split's trigger that a read of the clear alone takes a cleared copy instead
The declaration in degradation.rs and docs/API.md's catalogue entry both said a draw that reads a
color attachment's texture after a memory barrier splits the pass. A read of the clear alone
before any draw of the pass now reads its copy cleared to the clear in the pass's one instance
where the copy can be (WorkCounts::attachment_read_clears), so both name that exception.

Docs only; unverified beyond cargo fmt.

(cherry picked from commit 1bcf89e89571bc7f65694c10ea34bdde6c3af6b0)
2026-11-05 02:08:33 -08:00
Anees Iqbal de64560175 Name the pass-start read's cleared copy in the API guide's accepted difference
docs/API.md: a draw that reads the clear after a render-target barrier before
any draw of its pass reads its copy cleared to the clear in the pass's first
instance where the copy can be so (WorkCounts::attachment_read_clears), else an
instance after one of the clear alone.

Unverified: documentation of 4259b7f41c, whose runs are pending.
(cherry picked from commit cc9312dcc9a97d5c663efbfea3f0f25374581249)
2026-11-05 02:08:33 -08:00
Anees Iqbal d3f2bf185a HostRam: test a run-bound buffer against copies of its pages; copies' take wording
On gate/stack27b the HostRam copies (copy_from_host_ram,
copy_to_host_ram) and the run imports compose: a copy reads and writes
a chunk's pages through the chunk's import, and an object over a chunk
not imported yet is bound in an import of its own run, two imports of
the same pages ordered only by their host bytes (host_aliases.rs).

New device test
a_run_bound_buffer_and_a_copy_of_its_pages_order_by_their_host_bytes:
four pages over a chunk not imported are bound in their run's import,
and then, both ways:
- a fill through the buffer before a gather of its second page;
- a scatter into that page before a copy out of the buffer.
Each way runs in one blit encoder (a barrier recorded between them),
in two encoders of one command buffer, and across two queues in commit
order (the writer behind 2 GiB of private fills). The six copies import
nothing, and the run's import stays live. On a device with
RuntimeDriverDefect::AliasedImportBlitsUnordered (MoltenVK) the test
asserts the fallback: no run import, the buffer imports the chunk and
lies in the copies' import.

Docs: copy.rs's module docs and HOWTO said a copy takes a chunk "as an
object does", importing it or waiting for its import; objects no longer
wait, so both now say that a copy makes no run import of its own and
waits. host_ram.rs and HOWTO add the copies to what a run-bound
object's uses order against, and the test module's docs add the
composition.

Verification is pending in this commit: M3 and RTX 5080 device runs.

(cherry picked from commit be6d43fbf2c0a5921a2468038740ef3604a2da9f)
2026-11-05 02:08:32 -08:00
Anees Iqbal c074aa490e Document the HostRam window's direction, the runs' imports and their fallback
docs/HOWTO.md's "One run inside one chunk" bullet now says what the
branch's runtime does: the window opens in the takes' direction, up or
down the RAM; an object over a chunk not imported yet is bound in an
import of its own run (run_bound_buffers_made, run_imports_live) and
never waits for the chunk's fault-in; the price is up to one more
allocation and pin per such object; and where the object falls back to
the chunk's import (thread stopped, chunk failed or given back,
allocations within the margin, a whole-chunk run, or
RuntimeDriverDefect::AliasedImportBlitsUnordered on MoltenVK).

It adds the measured result from tests/host_ram_window_bench.rs on the
RTX 5080 laptop (NVIDIA 615.71.09), at 2b2419c67c: 256 2 MiB heaps
upward, downward and scattered had no making of 5 ms or more (slowest
1.4, 1.5, 3.7 ms), against 2, 8 and 15 makings importing a chunk
(slowest 8.2 to 8.7 ms) without the change; 128, about 76 and 20 heaps
were bound in their own runs' imports.

Docs only; verified by reading the text against host_ram.rs's
for_object and after_take.

(cherry picked from commit 25572e5af997da7009960fa31bf94c5d478e2370)
2026-11-05 02:08:32 -08:00
Anees Iqbal 749daae1d9 Say a texture's image of any storage mode may overflow past device-local memory
Every texture's image is placed in Private memory (image_plan.rs), so a
Shared or Managed texture's image overflows as a Private one does; the
notice's declaration, the catalogue entry, the runtime README and the
lane's site note now say so.

Verified: nothing (docs and comments only).
(cherry picked from commit ec5b5a70fdea000eb9a7d5ab84e5aaad02fffed4)
2026-11-05 02:08:31 -08:00
Anees Iqbal 8ccb2934c9 Place resources past a full device-local heap in system memory
Placement refused a resource once device-local memory was full: memory.rs
gives the Private class only DEVICE_LOCAL types, every texture's image is
Private, and a Managed buffer's own bytes on a device without unified memory
are Private, so place() returned OutOfMemory(Device). On the RTX 5080, 96 of
5090 1-MiB Managed GPU copies were refused at about 5 GB held, where Metal
on a 4 GiB Radeon Pro 5300M made, used and read back 12 GiB of Managed
buffers, six 1 GiB Private buffers and a 17 GB Private heap.

- memory.rs: overflow_candidates, the types a Private or Memoryless
  resource overflows into where none of its own has room (allowed,
  allocatable, neither device-local nor lazily allocated; those the host
  does not map first). place() tries them after the class's own types;
  such a placement is marked (Placement::overflowed) and counted
  (Memory::overflows, WorkCounts::device_memory_overflows). Metal's own
  refusals (max_buffer_length, texture limits) stay where they are.
- Driver paging first: VK_EXT_pageable_device_local_memory with
  VK_EXT_memory_priority, enabled where the device lists both and has
  pageableDeviceLocalMemory (enables.rs, create.rs); the spec lets such a
  driver page memory out rather than fail an allocation. Every allocation
  keeps the default priority.
- Degradation::DeviceMemoryOverflow (performance), announced once for a
  program's buffer or heap (degrade_system_memory, which now names the
  storage mode) and texture (Texture::overflowed) that overflowed.
- Tests: tests::memory::device_local_classes_overflow_into_system_memory,
  tests::device::pageable_device_local_memory_is_enabled_where_the_device_has_it,
  and the device test tests::device_memory_overflow (a GPU hazard, under
  m2v_gpu_hazards on a GPU, in the shape of 7b57d9a87a; check-cfg added),
  which fills device-local memory where it can overflow and makes, uses
  and reads back Private buffers, a Private heap with a buffer and a
  texture, Private textures and Managed buffers past it. The lane names
  the kind's site as the runtime's test (degrade_notices OVERFLOWED).
- Docs: API.md (runtime-own extensions, catalogue entry), runtime README
  memory model.

Verified: nothing yet (cargo fmt only); builds and runs follow as potluck
jobs.

(cherry picked from commit 586f2d0b5c6708016d9a255c0934f9727569125c)
2026-11-05 02:08:30 -08:00
Anees Iqbal 504d01b759 Present the Mac class the consumer declares, by default its GPU's, as the fresh-texture key
The fresh-texture key (DeviceProperties::lossless_compression) was
has_unified_memory. That is wrong for every integrated GPU that is not
Apple's. The consumer's oracle shows an Intel UHD 630 Mac reports unified
memory and reads zero or a released texture's texels from a new Private
texture, as the AMD 5300M does, and never Apple's pattern. The owner's
choice (option B): the consumer declares the Mac class the device presents,
and the default follows the GPU family.

What:
- MacClass { AppleSilicon, IntelOrAmd } (public, capabilities.rs), with
  MacClass::of_vendor: an Apple GPU (vendorID 0x106b, MoltenVK on Apple
  silicon) is AppleSilicon, every other GPU IntelOrAmd.
- DeviceOptions::mac_class and RawDevice::mac_class (Option, None by default:
  the GPU's class) feed presents_lossless_compression, still the one place
  the key is decided. lossless_compression is class == AppleSilicon. The
  options' equality and Debug list the field.
- A new Private texture under IntelOrAmd on a GPU that is not Apple's holds
  what its memory held, as before (private_textures_unfilled). On an Apple
  GPU, whose own image of such a texture is compressed and reads Apple's
  pattern, it is filled with zeros as it is made, which is what such a Mac
  reads where its memory held nothing. Counted by the new
  WorkCounts::private_textures_zero_filled. The pattern path now runs only
  where the device presents compression.
- AppleSilicon keeps the runtime's pattern and zeros on any GPU. The device's
  own contents are not Metal's pattern on the M3: in the negative control
  (m3-max-88) leaving Private textures unfilled failed 16 of the 28 lanes.
  No PrecisionNote: the fill is capability (the declared Mac's contract),
  not arithmetic. An Apple-class pattern that no clear or copy writes
  exactly still announces fresh-pattern-zeroed.
- Defaults change only where unified memory and GPU family disagree: Intel
  and AMD integrated GPUs and lavapipe now present no compression (their new
  Private textures are unfilled). The M3 (Apple) and the discrete GPUs
  answer as before.
- Docs: docs/API.md (the accepted difference and the fresh-pattern-zeroed
  entry), the runtime README, the degradation declaration, the work-count
  docs. api_signatures blessed. REFUSALS.md regenerated with no change. No
  FAST-PATHS row: no speed-for-accuracy choice.

Tests:
- tests::capabilities::lossless_compression_is_the_presented_mac_class
  (no device): every vendor kind (Apple, Intel, AMD integrated and
  discrete, NVIDIA, Mesa CPU) under no declaration and both declarations.
- tests::mac_class (device, both settings):
  the_default_class_is_the_gpu_s and
  a_declared_class_other_than_the_gpu_s_is_presented. Each reads a new
  Private RGBA8Unorm target and checks the counters: AppleSilicon reads
  Metal's magenta pattern; IntelOrAmd on an Apple GPU reads zero
  (zero_filled +1); IntelOrAmd elsewhere is unfilled (+1).

Verified: cargo fmt --all. Build, clippy and tests run as potluck jobs
after this commit (results in the next commit or report).

(cherry picked from commit f3d6f24ca447fbcadc8df56e63e598cbc92e09b7)
2026-11-05 02:08:30 -08:00
Anees Iqbal 9fe1b0175f Key the compressed shape's clear route in the extended-range and bfloat clear checks
A clear takes Metal's straight route only where nan_clear::keeps_nan_sign holds (render.rs),
which the fresh-texture key now makes false on a device that presents a Mac keeping no texture
compressed: there a 16 x 16 plain target is not compressed, so it clears through half, as
Metal's uncompressed targets do (expected, not measured on such a Mac). Three checks still
expected the straight route there and failed on the RTX 5080 Laptop at fd34a10316:

- conformance xr-clear-routes-{bgra10xr,bgra10xr-srgb,bgr10xr,bgr10xr-srgb}: divergent at
  case/plain-16/texels/0..3 alone (15 sites), unlisted, in the replay of job m3-max-120; the
  baseline replay at 0b556ddfd6 (job m3-max-141) held none of them (its other 908 unlisted gap
  sites are the same in both runs). ClearRoutes now declares
  replay::without_compression("plain-16").
- validation runtime_lane::extended_range_targets::clears_take_metal_s_route (15 clears
  differ, all the 16 x 16 draws-false shape) and runtime_lane::bfloat_targets::
  bfloat_clears_take_metal_s_route (11, all that shape), suite job m3-max-124: each now expects
  ClearRoute::Straight for that shape only where DeviceProperties::lossless_compression holds,
  else ThroughHalf.

docs/API.md's accepted difference says the clear route too, and keeps_nan_sign's doc says it
decides the route.

Verified on the M3 Max, no device: nextest metal2vulkan-conformance 1011/1011; cargo clippy -D
warnings on validation and conformance with --cfg m2v_gpu (all targets, all features);
docs/CONFORMANCE-COVERAGE.md re-derives unchanged. UNVERIFIED: none of the three has run with
this commit on the 5080 or the M3.

(cherry picked from commit 1c042263e5fee942b79fbd30042c2dc9f222b61b)
2026-11-05 02:08:30 -08:00
Anees Iqbal 64bea51c0c Put the fresh-texture key behind one presented fact, and give every lane and case its arm
The key that decides whether the Mac a device presents keeps textures losslessly compressed is
now one public fact, DeviceProperties::lossless_compression, decided in one private function,
capabilities.rs presents_lossless_compression. Today it is has_unified_memory, as the approved
proposal said; the owner's open question (unified memory, a consumer-declared Mac class, or a
family split) changes that one function. Everything that differs because Apple silicon
compresses reads only that field: Device::metal_compresses_textures() (a new Private texture's
fill, compressed_blit::compressed(), nan_clear::keeps_nan_sign), the validation lanes
(fresh_contents::unfilled, patterns_of) and the conformance venue (Venue::lossless_compression;
the Metal side answers supportsFamily(MTLGPUFamily::Apple1)).

This finishes what the parked commit before it listed as open:

- docs/API.md: a new accepted-differences group, "The Mac a device presents", whose entry
  (slug a-device-that-presents-a-mac-without-texture-compression-answers-as-that-mac) gives
  reims's measured AMD 5300M and Intel UHD 630 rows for fresh Private contents and marks the
  blit encodings, fills and NaN clear sign as expected, and states the Intel-iGPU limit. The
  fresh-pattern-zeroed catalogue entry and its rustdoc say the key; so does the runtime README's
  "New resources" bullet.
- Conformance: Justification::WithoutUnifiedMemory became WithoutCompression (and
  Unjustified::VenueCompresses, Offered::lossless_compression, replay::without_compression /
  WITHOUT_COMPRESSION). The fresh family's Private rows declare it at their fresh site; the
  compressed-blits-* rows of the BGRA10_XR formats (the only ones whose canonical encoding the
  runtime writes) declare it at the seven sites a blit reaches through the compressed texture.
  The fresh test now asserts the new shape (renamed
  a_row_loosens_the_notices_site_and_a_private_texture_s_fresh_site); the compressed-blits test
  asserts the venue declarations site by site.
- Lane arms on an unfilled device: fresh_costs (the counter moves by count x runs per Private
  shape; no readback), fresh_writes (patterns_of in both controls and the scratch test; the
  forced single-sample note only where the device fills), parallel_encodes (no expected
  pattern), depth_denormals (no draw/store check of unwritten texels, no sign, no zeroed note),
  compressed_blits (the notes and the Canonical rewrite only where the device compresses).
  degrade_notices needs none (FRESH_PATTERNS is only its catalogue list); the tile-store lanes
  (rotated_textures, snorm_tile_store, padded_loads, extended_range_blends) read draw notes,
  which are not keyed.
- api_signatures.tsv blessed for DeviceProperties.lossless_compression and
  WorkCounts.private_textures_unfilled. docs/CONFORMANCE-COVERAGE.md regenerated (the Metal leg
  now calls supportsFamily:, and WithoutCompression is a justification it names).

No RUNTIME_VERSION or runtime-sources pin change here: left to the orchestrator.

Verified on the M3 Max, no device: cargo clippy -D warnings over the runtime, validation and
conformance (all targets, all features) plain and with --cfg m2v_gpu; nextest
metal2vulkan-conformance 1011/1011, metal2vulkan-runtime 1234/1234 (2 skipped),
metal2vulkan api_signatures + api_surface 15/15; the refusal-surface and metal-coverage checks
pass. UNVERIFIED: no device run yet (the lanes, the nan_signs test and the conformance replays,
on the M3 and the 5080), and no negative control yet.

(cherry picked from commit fd34a1031602645e87e4cb192d1044790f79a88f)
2026-11-05 02:08:29 -08:00
Anees Iqbal 61e6e1f9ac Announce device-pack-conversion where a heap set holds a texture by its raw texels
A heap holds a texture of a form ExtendedRange::HEAP_READ names
(BGR10_XR, BGRA10_XR, R10Unorm_X6, RG10Unorm_X12 and the bfloat
formats) by its raw texels alone, its raw view in the unsigned integer
class. A function's float read, sample or gather of it through an
argument buffer decodes the raw texels itself, by the device's
arithmetic, within the bounds PrecisionNote::DevicePackConversion
states. That is the same conversion a slot's read records statically,
but nothing announced it for a heap read: the stage cannot know which
textures an argument buffer names, and recording the note on every heap
float read would announce it for argument buffers that never hold such
a texture.

Scope it through the run-time mechanism a decoded twin already uses.
heap_sets now notes, per set, the textures whose raw view a set's
unsigned integer array holds (SetEntry.raws, detected in texture_info
by the class and bind::heap_raw_form). It announces
Degradation::DevicePackConversion, naming the texture ("BGRA10XR
texture at resource ID n"), at the first command that binds a set
holding one, and once (degrade_once) as one is placed in a set a
pending command buffer may read through. This matches TwinRead's
twin_read and twin_placed. A command whose sets hold no such texture
announces nothing. A command that binds a set holding one announces it
whether or not its function reads that texture, because the runtime
does not see which textures an argument buffer names. The twin
bookkeeping shares the new noted and pending_read helpers.

The runtime's DevicePackConversion doc, docs/API.md's
device-pack-conversion entry and heap_sets' module docs say so.

New lane test
runtime_lane::heap_extended_reads::a_heap_set_holding_a_raw_texture_announces_its_decode.
It dispatches a heap float-read kernel with only an RGBA8Unorm texture
live (no device-pack-conversion announced), then with a BGRA10XR
texture made (the notice names that texture's resource ID). It prints
the stage's own notes beside the notices.

No RUNTIME_VERSION bump (not asked for on this branch).

Verification: the branch's next CPU job (clippy, runtime suites) and
GPU job (the heap_extended_reads lane on MoltenVK on the M3).

(cherry picked from commit f5c2127ebee39d3fcf221e1930e287d26c7f9e68)
2026-11-05 02:08:28 -08:00
Anees Iqbal 75228b052b Record no device-nan-encoding for a color output that only ever returns NaN-free constants
A fragment function's color output to a half-float attachment recorded
PrecisionNote::DeviceNanEncoding wherever the device's conversion stores
a NaN otherwise than Metal, even when every value the function returns
there is a constant with no NaN lane, which stores no NaN. Texture
writes already skip the note for such a constant texel
(texture::holds_no_nan); color outputs now apply the same structural
rule. stage_io::returns_no_nan follows each `ret` of the function to the
output's member (through insertvalue chains and aggregate constants),
and color_write::plan, called from the output-variable path and from
the storage-form path, leaves the note out when every return holds such
a constant. Any computed, undef, argument or partly unknown member
keeps the note.

Per-site audit of the device-nan-encoding notes on MoltenVK on the M3
(the reims strict Mac tests), with the translator CLI over each site's
stages:
- (a) undefined tests x3 (xr_constant_fragment and the other
  constant-colour fragments): their outputs are NaN-free constants, so
  the note was wrong there. Fixed here.
- (c) encode_render x2 (sweep_fragment, sweep_half_fragment): computed
  outputs that sweep through NaN values. The device stores its own NaN
  encoding, so the note stays.
- (c) rgbx x3 (rgbx_write_half, store_half, read_write_half, and the
  NaN clears and half NaN writes): deliberate NaN texel writes. The
  note stays.
- (c) slice_write_repro x1 (slice_write, slice_write_l0): computed
  texel writes. The note stays.

New public fixture ncw_constant_colors (our own MSL, compiled by
scripts/regen-air-fixtures). It covers a half and a float constant
colour, a constant NaN colour, a computed colour, and a two-member
struct whose member 0 is a constant and member 1 computed. The new test
engine_link::constant_colors_without_a_nan_record_no_nan_encoding
checks, on the lavapipe and moltenvk-m3 profiles, that the note is
recorded exactly for the NaN constant, the computed colour and the
pair's computed member, and that each stage links and validates.

docs/API.md's device-nan-encoding entry states the rule. SEMANTICS_VERSION
goes to 1963 because the recorded notes change. The golden tables
need the new fixture's rows, re-blessed on development.

Verification: the new test and the touched suites run in the branch's
next CPU job.

(cherry picked from commit 2d436ebc2963f1aac1854b850ff1808e654c61f3)
2026-11-05 02:08:28 -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 6e63f015b5 Count a texel's half rounding as the measured conversion on MetalHalfConversion profiles
What: narrow::round_texel rounds through round_measured, so in QuantizeForm::Converted the
conversion pair's narrowing is recorded as measured. On a profile that takes
DriverDeviation::MetalHalfConversion (MoltenVK on the Apple M3 Max's macOS 27 identity) a texel's
half rounding no longer records PrecisionNote::NativeHalfConversion. That covers a texel the module
decodes itself (extended_range::decode) and a merge of texels (a heap read's phi of its fetched
texel and its decode routine's), as well as an image instruction's. The module requires
VkProperty::MetalHalfConversion instead. The note stays for roundings by narrow::round: half
operations and functions computed in float, filter sums, packs and the rest. Other profiles never
read the measured set, so they are unchanged by construction. The SPIR-V is unchanged too:
round_measured emits the same pair.

Why: reims-vgpu's strict Mac tests die on native-half-conversion at a kernel that reads an
argument buffer's texture as half (their ycbcr_probe.metal read_held). Every heap half read
carries the decode routine of the seven extended-range/padded/bfloat forms, and its merge, so it
recorded the note even for a BGRA8Unorm texture. The note states that the device's conversion may
differ from Metal's half(float), and MetalHalfConversion measured that conversion as Metal's
half(float) for loaded and computed floats. Where Metal's half texel is not the nearest even half
of the texel's value, the access's own note states it: HalfTexelConversion (outright for a heap
element, by the bound class at a slot) or DevicePackConversion (a decoded texel).

Verified:
- New core tests heap_half_texels_round_by_the_measured_conversion (heap half read, nearest sample
  and gather on moltenvk-m3: no note and the property with the deviation, the note without it,
  HalfTexelConversion kept; a linear sample's filter sum keeps the note on both) and
  decoded_half_texels_round_by_the_measured_conversion (a slot's half read of each extended-range
  form: the same, DevicePackConversion kept). Both fail with round_texel's old rounding and pass
  with the change; half_conversions_are_metals_where_measured still passes.
- Notes of every public fixture subject on moltenvk-m3, lavapipe and nvidia-rtx5080-laptop before
  and after (a temporary dump over the golden-hash subjects, 2,915 per profile): 7 change, all on
  moltenvk-m3, each losing NativeHalfConversion alone and keeping HalfTexelConversion
  (a8r_buffer_read_half, hlf_half_buffer, selected_member_texture and
  kernel_texture_variant_leftovers, the .ll and .air.ll forms).
- reims's ycbcr_probe read_held on moltenvk-m3 through the CLI: [DeviceNanEncoding,
  HalfTexelConversion, NativeHalfConversion] before.
- Pending: the M3 lane heap_half_reads_of_every_code_round_their_float (new) and the lanes that
  read the note (alpha_in_red now requires a8r_buffer_read_half to be Metal's there).

Docs: the PrecisionNote, DriverDeviation and VkProperty rustdoc, API.md's native-half-conversion
exemption, the driver-facts record, narrow's docs.

(cherry picked from commit 384734851de7b2f1a3106355a6c941080f097be4)
2026-11-05 02:08:27 -08:00
Anees Iqbal 493178c82e Keep a draw's heap part while what it is made of holds
A replayed page's host step costs about 400 ns per replayed draw per
resident texture (reims: 14 s a frame). Each draw works its heap part
out again for every texture its encoder made resident, though the
residency did not change and the command rebinds only a buffer:
- the handle tables, at every heap member (bind::heap::member_id,
  table_bytes);
- where the heap writes go (heap_elements, member_id again);
- each heap entry's view check (bound_view, view_reading,
  binding_view, Image::view);
- for every member, a neutral image descriptor in each heap image
  array whose class it does not fit (neutral_view, border_texel,
  BicubicTexels::with_border). heap_sets::bind then dropped every one
  of those.

Now:
- The translator splits the heap part from the rest of a draw's
  commands:
  - BindingPlan::instantiate_draw_apart_into writes every command but
    the heap tables;
  - heap_tables_into writes the heap tables alone (handle tables,
    sampler tables, function-table directories);
  - heap_slots names the texture slots they read besides the used
    resources.
  instantiate_draw_into is unchanged. A consumer breaks nowhere: all
  three are additions. docs/API.md says when the tables may be kept.
- The runtime keeps each draw's heap part in its encoder's LiveBind
  (render/heap_part.rs): the heap tables, where the heap writes go
  (Arc<HeapElements>), and the writes past the heap's entries
  (binding::PastHeap). The first draw that checks every entry's view
  lists those writes, and meets no notice the device announces at each
  occurrence (EachWatch) while it does.
- What a part is made of:
  - the plan, by address;
  - the variant's heap capacity;
  - the residency's generation;
  - the argument samplers: the count of sampler-ID slot changes they
    were listed at, else compared state by state;
  - the function tables, compared;
  - what the plan's heap slots bind, compared;
  - the heap placement and the token order.
- Parts are kept for the last 8 plans, so pipeline states drawn in
  turn and the plans a draw's primitive type picks each keep their
  own. They go as the encoder ends.
- Builds with debug assertions check every kept part against one
  worked out whole, and every listing of writes past the heap against
  one listed again.
- bind_into writes no heap image element at all, whatever the plan
  reads: the device's heap set holds each one. One predicate,
  heap_sets::holds_element, now says this for bind_into and
  heap_sets::bind.
- WorkCounts::draw_heap_parts_made counts the parts worked out. The
  replayed-frames lanes print it, and the resident uses' walk counters.

Builds with debug assertions check a kept listing against the writes
listed again in place, allocating nothing.

Measured, release, the replayed textured page
(runtime_lane::replayed_textured, 3 frames, interleaved with the
commit before over two rounds):
- Apple M3 Max, MoltenVK 1.4.2:
  - host_step_ms 10363-10491 a frame before, 1489-1621 after;
  - test time 31.7-32.5 s before, 5.1-5.3 s after;
  - pixels e3306dc52a1c9e86 in both;
  - peak RSS 306-317 MiB in both.
- RTX 5080 Laptop (b5080 entry resident-x-heap-part-004402, kind t):
  - host_step_ms 8800-8931 before, 1309-1359 after;
  - pixels 8e977e2bb4582473 in both.
- After, in both: draw_heap_parts_made 2 a frame (the point draws'
  plan and the other draws'). resident_uses_made stays 10,009,006 a
  frame; the next commit addresses it.

The 5080 binaries came from build-only commits. Their release code
equals this tree's but for the Deferred Send and Sync below this
commit and the lane's extra counter print.

Verified:
- On the M3 (potluck), clippy, plain and --cfg m2v_gpu, all targets,
  of the translator, the runtime and the validation crate; Rustdoc
  -D warnings; scripts/api-docs.
- The translator's heap, binder, instantiate and api tests, 143 of
  143. Among them, graphics tests check that instantiate_draw_apart_into
  plus heap_tables_into equals instantiate_draw_into wherever the
  latter succeeds.
- The runtime's suite, debug, --cfg m2v_gpu, hazard filter: 1626 of
  1627. The one failure, exit_guard's
  only_the_listed_modules_keep_the_device_s_functions, fails on the
  base too: a547d0ce33's command_buffer Parts shares a name with the
  device's Parts.
- The validation lanes over residency, draws and notices, debug,
  --cfg m2v_gpu, hazard filter: 246 of 247. The one failure is
  runtime_lane::frame_costs::a_frame_s_draws_and_pass_ends_allocate_
  within_their_bounds: 21.50 allocations a draw on the M3 against
  DRAW_ALLOCATIONS_DEBUG, 20. Whether that comes from this change or
  from its base is not yet measured. The release bound
  (DRAW_ALLOCATIONS) was not run.
- Negative control: with the kept part never kept, the new test fails
  at draw 1 (heap_parts 1, expected 0).

(cherry picked from commit 12f8301c62ffbbc149c04792007895649b8fe9ed)
2026-11-05 02:08:26 -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 5b451a6508 Hold a commit's refused recording of a write-resident ICB's records for the host step
A commit that recorded an execution from the CPU's records and found a record it refuses failed
there, though a route met after the commit may still write those records before the work runs:
another queue's command buffer that the work waits for through a shared event, encoded and
committed after this commit. Metal runs what that route wrote (the new probe
crates/metal2vulkan-conformance/probes/icb_cross_queue_writes.m, M3 Max, macOS 27.0.1, validation
off: `written` completes both command buffers with the kernel's green triangle; `unwritten`
completes too, drawing the CPU's mismatched-format command as garbage). Dying there where Metal
runs breaks the owner's rule 2.

Now, where the commit's recording of a render pass's executions, or of a compute execution, is
refused and the command buffer made one of the executed buffers resident for writing
(Residency::writable_indirect_command_buffers), the segment is held for its host step
(Prepared::held sets Segment::host), prepared as a step's: settled variants and made-ahead
pipelines, its footprint bound. The step waits for the work before it, records from the records
as they stand then, and fails the command buffer at that batch's submission only where they are
still refused. A refusal of another buffer's records, and every valid recording, keep the
commit-time path. Counted: WorkCounts::commit_refusals_held (api_signatures row).

The lane test write_routes::a_refused_command_another_queue_writes_again_runs_what_it_wrote runs
the probe's `written` shape: both command buffers complete, the centre is green, and the counter
moved once. docs/API.md states the held refusal.

Verified: clippy -D warnings, all features, plain and --cfg m2v_gpu, for the runtime and
validation crates; api_signatures/api_surface 15/15. The lane test is not run on a device yet.

(cherry picked from commit 83a1365119f1563ce45f97941a335ea119bc9efc)
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 cc4c44bd7e Make the GPU hazard tests opt-in under --cfg m2v_gpu_hazards
Owner's rule (11-05): tests that fault a real GPU, hold one for long, or
allocate toward its limits never run in sweeps, lanes, stress loops or
gates; they run only when that feature is tested, on request. On the M3
Max a GPU fault's recovery fails other processes' command buffers in
flight (.config/nextest.toml has the measurement). #[ignore] is not
enough, since lanes run --run-ignored all, so the gate is a cfg: on a
real GPU a hazard compiles only under --cfg m2v_gpu --cfg
m2v_gpu_hazards. Under --cfg m2v_cpu_icd it compiles and runs as
before, so lavapipe CI keeps them.

Gated (each doc comment now says which hazard it is):
- runtime_lane::host_memory::a_gpu_fault_fails_its_command_buffer_and_the_queue_runs_on
  and ::a_lost_device_s_command_buffers_let_go_of_their_pools_after_the_driver_s_completion:
  GPU writes into read-only host pages, real page faults (2 and 3).
- host_memory::a_no_copy_buffer_s_pages_are_imported_when_it_is_made:
  no-copy buffers of 1 to 16 GiB.
- vertex_strides::vertex_fetches_past_4_gib_of_a_buffer_are_refused and
  stage_in_strides::stage_in_fetches_past_4_gib_of_a_buffer_are_refused
  (and their `Large` helper): 4 GiB + 4 KiB buffers.
- heaps::the_largest_heap_lies_in_one_allocation: a heap of the device's
  largest allocation, up to 4 GiB.
- cross_queue_shadows: the three tests whose spin holds one command
  buffer for 1.5 s.
- framebuffer_fetch::storage_forms::a_steady_stream_takes_the_storage_form_at_its_first_lone_commit:
  a single-dispatch spin of up to 1 s that only its cap ends on Apple GPUs.
- detach::table_3_a_detach_waits_for_running_work_then_refuses: single
  dispatches calibrated to 500 ms (up to 2 s loaded), the cap alone ending
  them on the M3 Max, where Metal ended some 0.5 s dispatches as hung.
- runtime tests::detach_lost: one dispatch of 2^25 loads (about 4.5 s on
  the M3 Max) whose word the GPU does not see raised.

Made safe instead of gated:
- mesh_draws::object_grids_run_as_metal_runs_them: on a GPU without the
  hazards cfg, grids past 2^20 object threadgroups are skipped (printed),
  as a CPU ICD already skips them; the 70k to 262k grids and the
  past-the-watchdog discards still run. The 4.6M grid took 12 s in one
  command buffer on the RTX 5080 Laptop GPU.
- detach::a_resident_buffer_no_command_reaches_fails_its_submission_once_detached
  takes the spin kernel without calibrating a cap (`spin_kernel`): its
  word is raised, so the cap never mattered, and the calibration's
  unraised runs are bounded only at 16 x 50 ms.
- cross_queue_shadows::an_encoder_after_a_signal_reads_what_another_queue_wrote_after_it
  no longer calibrates a spin it never ran.

The cfg is declared for unexpected_cfgs in the runtime, validation and
conformance manifests. docs/VALIDATION.md says what a hazard is and how
to run one; CONTRIBUTING.md and .config/nextest.toml mention the cfg.
The device lane is unaffected: its builds set RUSTFLAGS to --cfg
m2v_gpu alone. No product code changed (no RUNTIME_VERSION bump; the
runtime-sources pin skips test modules).

Verified on this Mac (no test run on any GPU): cargo fmt --all; cargo
clippy --workspace --all-targets --all-features -D warnings clean plain,
under --cfg m2v_gpu, --cfg m2v_gpu --cfg m2v_gpu_hazards and --cfg
m2v_cpu_icd. cargo nextest list -p metal2vulkan-runtime -p
metal2vulkan-validation --all-features --run-ignored all: under --cfg
m2v_gpu 5022 tests, under --cfg m2v_gpu --cfg m2v_gpu_hazards 5034, and
the difference is exactly the 12 gated tests; all 12 are listed under
--cfg m2v_cpu_icd (5000 tests).

(cherry picked from commit 7b57d9a87a3dd8275a2ece547fc0bd9b9cb6808c)
2026-11-05 00:43:51 -08:00
Anees Iqbal a0bebe78f1 runtime: copy runs of a guest RAM to and from a buffer on the GPU, from the chunk imports
`BlitCommandEncoder::copy_from_host_ram(ram, runs, destination, destination_offset)` gathers runs
of a `HostRam` the device uses into consecutive bytes of a buffer, and
`copy_to_host_ram(source, source_offset, ram, runs)` scatters them back (a runtime extension:
Metal has none). A surface that is a scatter of guest pages is copied straight from the RAM's
64 MiB chunk imports, with no view mapped per surface (one mmap per run) and no import made per
surface.

How: adjacent ascending runs merge, descending neighbours stay apart; runs are cut at chunk ends;
the 4 KiB pages become a table in the command buffer's upload arena, and each chunk the runs touch
takes one dispatch of the new `bind::pages_copy_module` (more only past the storage-buffer range
or the workgroup count). A chunk not imported yet is imported, or its pending import waited for,
as an object over it does.

Ordering: each chunk a copy uses gets a resource key placed over the chunk's host bytes in the
host-alias placements, the way no-copy buffers and heaps are placed, so the copy's chunk uses
(joined to at most 16 ranges per chunk) order against other copies and against every no-copy
object over the RAM's own addresses, in one encoder and across encoders; the buffer side is
tracked like any blit. A scatter's writes reach the RAM's dirty log as the GPU's in place, so a
copied backing over those pages takes them in at its next commit. Objects made over another
mapping of the pages (a view resolved through `with_runs`) are not ordered against the copies.

Refused with `Problem::HostRam`: an empty run, one off 4 KiB, one outside the RAM, a RAM the
device does not use, buffer bytes off a 4-byte word; no host import is `Unsupported`; bytes past
the buffer are `RangeOutOfBounds`. Replayed at rebinds (`BlitCall::HostRamCopy`). New counters
`host_ram_copies`, `host_ram_copy_bytes`, `host_ram_copy_dispatches`. README, HOWTO, the
API signature rows and docs/REFUSALS.md updated.

Verified:
- On this M3 Max (MoltenVK), --cfg m2v_gpu under nextest: the five new device tests
  (`tests::host_ram_copy_device`: round trips byte for byte over ascending, descending, adjacent,
  repeated and chunk-crossing runs into Shared and Private buffers; CPU writes before the commit
  gathered and a scatter's bytes in the pages after completion; the two hazard cases in one
  encoder and across encoders; a copied backing over the pages taking a scatter at the next
  commit; the refusals) and the ten `tests::host_ram_device` tests: 15 passed.
- Negative controls, each a saved build: merging descending neighbours fails
  `adjacent_ascending_runs_merge_and_descending_ones_stay_apart` and
  `a_gather_and_a_scatter_move_every_runs_bytes_in_order` ("the gathered bytes"); not placing the
  chunk keys over the host bytes fails
  `copies_are_ordered_against_a_no_copy_buffer_over_the_same_pages` ("a later reader sees the
  scatter"). The first control found the test pattern repeating every 1 KiB, so a page swap
  went unseen; the pattern now differs per page.
- The `host_ram::copy` unit tests (merge, refusals, chunk cuts, the plan, the joined uses) and
  `consumer_auto_traits`; clippy --workspace --all-targets --all-features -D warnings, plain and
  --cfg m2v_gpu; rustdoc -D warnings; `signatures.py --check` after the bless; the refusal
  surface `--check`.
- The ignored release bench `tests::host_ram_copy_bench` on the M3, a 3840x2054 BGRA8 surface
  (31,549,440 bytes, 31,551,488 in whole pages) scattered over 1 GiB of shared RAM: 7703 4 KiB
  runs (5490 descending neighbours, 7279 runs after the merge) take 16 dispatches, 0.35 ms of CPU in the call, 0.59 ms of GPU and 0.64 ms from commit to completion
  for a gather (scatter 0.37 / 0.58 / 0.64). The view path at the host's 16 KiB page (1926 runs:
  a view mapped run by run, a buffer `with_runs`, a buffer-to-buffer copy, the release) takes
  1.58 ms to map, 2.36 ms to make the buffer, 0.99 ms commit to completion and 0.78 ms to
  release; the gather of the same 1926 runs takes 0.14 ms CPU and 0.60 ms commit to completion.
Ported onto gate/stack27, where the device's thread imports a window of chunks ahead of the
objects (paced, with the memory lock released, short of maxMemoryAllocationCount and giving back
what no object took). The conflict was `RamOnDevice`'s fields alone: the copies' `ChunkKeys` sit
beside the window and its wake, and the old cursor is gone. The copy still takes each chunk
through `RamOnDevice::chunk(.., By::Object)`, the objects' own path, which now moves the window
past it, wakes the thread and clears the chunk's untaken mark; there is no second import path. The
copy module docs and HOWTO say so. The ignored release bench waited for every chunk imported
ahead, which the window never does; its warm-up copy now imports the chunks the runs touch.

The verification above was on the old base; this tree's is in the commit that follows.

(cherry picked from commit 923718777c198bef526dd07f701fc71a71e07b00)
(cherry picked from commit fa00224f7b29ab0359c8305a47da9c9273fc5d37)
2026-11-05 00:43:50 -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 215a9f7583 Time the pass-start barrier family on the M3 Max, and count it in the conformance coverage
What: `conformance times --runs 8 --write` over the 13 pass-start-barrier cases keeps both
legs' figures in their recordings, and docs/CONFORMANCE-COVERAGE.md is regenerated
(scripts/conformance-coverage/coverage.py): 1141 recordings in 153 case modules, and
`MTLBarrierScopeRenderTargets` now compared.

Why: `times::every_case_carries_its_timing` holds every case to a timing record, and the
coverage doc is derived from the recordings and the suite's sources.

How verified: potluck job m3-max-37 on the Apple M3 Max, debug build, exit 0: 13 cases carry
their timing; 4 within 10x, 9 unmeasured because our leg announces render-pass-split (and the
display row two more), so its work is not Metal's. The host's load was 188 while Metal's leg
ran, so the margin is reported, not judged. coverage.py --check passes.

(cherry picked from commit 8ce6ed8262789fb7887794bb7073eb63dbed249e)
2026-11-04 21:54:22 -08:00
Anees Iqbal cee5c7eeb3 Name a draw's read behind a barrier as the cause in the render-pass-split notice
What: a split made so a draw reads a color attachment's texture after a memory barrier
(`Split::AttachedRead`, the pass-start barrier's split among them) is now counted for the
split's degrade notice (`SplitCauses::attached_reads`), whose reason says so: "draws that read
a color attachment's texture after a memory barrier read what its load actions and the draws
before the barrier stored, in a Vulkan render pass instance after theirs, ending N of them".
The `RenderPassSplit` declaration and docs/API.md's catalogue entry list the cause.

Why: such a split counted neither as a barrier split (`self.barrier` is false for a
render-target barrier before any draw, and for one between draws, which records in the
instance) nor as any other cause, so the notice fell to its last reason, "its draws keep
different attachments out of their subpass", which describes no part of this pass. The
conformance replays of the pass-start barrier family showed the split announced on every
barrier row (Apple M3 Max, lavapipe).

How verified: builds (conformance binary, debug). The lane assertion added to
`a_draw_after_a_barrier_at_the_pass_start_reads_the_clear` (the split's reason, and a notice
exactly where a pass split) is NOT yet run; the runtime-sources pin is not re-hashed (the
coordinator's).

(cherry picked from commit 30b797c61b27d4dbe34386c36a27837bb3ed8ead)
2026-11-04 21:54:21 -08:00
Anees Iqbal 34bafa410d Record the pass-start barrier family on the M3 Max (unverified on our side)
WORK IN PROGRESS, parked: recorded on Metal, not yet replayed on the runtime.

pass_start_reads.rs adds 13 conformance cases (pass-start-barrier-*), each a pass that clears a
BGRA8Unorm target and draws a read of it (owned fixture psb_reads):
- 32x32 private and over-a-buffer targets, each with: the barrier then a read at own pixels; the
  barrier then a pixel-coordinate sample; the read and the sample with no barrier; a solid draw,
  the barrier, then the read.
- display-masked-read: a 1728x1216 private target holding an earlier DontCare pass's leftovers
  (61x55, 45x45), cleared, the barrier, a read at own pixels through a 453x100 scissor beside an
  A8Unorm mask over a buffer at texture 3.
- new-texture-chain: two new 896x576 private textures, each cleared, the barrier, a read at own
  pixels through 841x521 (the second beside the first at texture 3), then a target over a buffer,
  loaded, the barrier, and a read of the second over it.
- new-texture-tile: a new 448x576 texture cleared, the barrier, a read over all of it.
Texels are recorded as runs of equal texels (fresh_contents::texel_runs, now pub(super)). Rows
with a barrier accept, beside the M3 Max's recorded answer, the Mac2 answer the case states, by
docs/API.md's accepted difference a-barrier-over-the-render-targets-orders-what-it-names-as-a-
mac2-gpu-s-does (the sentence naming these cases is added to it here). tests.rs bills the 13
cases' cost records to the next whole-set run (AFTER_THE_LAST_RUN).

Verified:
- conformance record on the M3 Max (macOS 27, 3 runs, one outcome each): every row's read
  draws the texels from before its pass, the barrier or not; Metal's validated leg stops the
  barrier ("scope (0x4) cannot contain MTLBarrierScopeRenderTargets on this device; afterStages
  (0x2) can not contain ... MTLRenderStageFragment on this device").
- cases::pass_start_reads unit tests pass (plain target), including
  metal_reads_the_texels_from_before_the_pass_on_the_small_rows against these recordings.
- clippy -p metal2vulkan-conformance --all-targets --all-features -D warnings.

Unverified / owed:
- conformance replay of these cases on the runtime (M3 MoltenVK, 5080, lavapipe): whether each
  barrier row matches the stated Mac2 answer exactly, and which notices each venue announces
  (shared-in-system-memory is declared; shadowed-texture or dont-care-stand-in may be needed).
- times::every_case_carries_its_timing fails until `conformance times --write` runs over these
  13 cases on the M3.
- docs/CONFORMANCE-COVERAGE.md not regenerated.
- new-texture-chain's recording is 1.46 MB of pretty-printed JSON (three 896x576 sites of 1042
  runs each); consider dropping the first texture's site.

(cherry picked from commit 724afbf80b78c14a8824dfb96203df3813fba9aa)
2026-11-04 21:54:20 -08:00
Anees Iqbal 60d3c512a6 Announce copied-host-pages for a buffer that lies in a live copy
What: a no-copy buffer or rebind that lies in the live copy of the same
bytes (`Device::degrade_copied_shared`) announces `copied-host-pages`, its
detail saying it lies in that copy and whether the copy drops the GPU's
writes. docs/API.md says so.

Why: such a buffer makes no copy of its own, but the GPU uses a copy for
it all the same (`Buffer::host_backing` answers `Copied`); before the join
each one was a copy and was announced. A consumer that asks for the kind at
each occurrence (`DeviceOptions::announce_each`) hears it per buffer as
before.

Verified: cargo check of the runtime (all features); the lane runs follow
on the M3.

(cherry picked from commit a4a75f118381a9f049157b1da063ba2fa4c9bff5)
2026-11-04 21:54:20 -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 3797c098eb Order a pass's clear before a draw that reads it after a barrier at the pass's start
A pass that clears a color and begins with a memory barrier over the render targets (after the
fragment stage, before it) and then samples that color's texture in a draw read the texels from
before the pass. Mac2 GPUs read the clear there (an Intel UHD 630 after the barrier, an AMD
Radeon Pro 5300M with or without it). The draw reads the texture's copy, taken ahead of the pass's
load actions (render/shadows.rs), and a barrier split the pass only where a draw of the current
instance came before it, so a barrier at the pass's start split nothing.

Such a barrier now orders the pass's load actions (`loads_ordered`): the scope form with the render
targets, or the resource form over an attachment's texture, after the fragment stage and before a
stage at or before it, recorded before any draw of the pass. A draw after it that samples the
texture of a color the pass clears (`Texture::cleared_in`) takes the existing after-barrier path:
it records into an instance after the pass's first, which runs the clear and draws nothing
(`next_instance` keeps the first instead of replacing it), so the copy before it holds the clear;
or, where the device has them, it reads through snapshots inside the first instance. The split is
counted as the after-barrier read's (`attachment_read_splits`, `instance_splits_attached_read`)
and reloads stand-ins over a buffer's bytes as one after a barrier does. A pass with such a
barrier but no such draw records as without it.

docs/API.md section 10 gets the accepted difference this ordering is: Apple GPUs do not support
the render-target scope, and the M3 Max reads the texels from before the pass after it.

The owned fixture psb_reads (regen-air-fixtures) holds the functions the lane and the coming
conformance cases draw with: a read and a pixel-coordinate sample of texture 0 at the fragment's
own pixel, channels reordered so a read is told from a skipped draw, and two-texture reads.

Verified on the M3 Max (MoltenVK, debug, --cfg m2v_gpu), runtime_lane::attachment_reads:
- a_draw_after_a_barrier_at_the_pass_start_reads_the_clear: both targets (own image, over a
  buffer), psb_read and psb_sample, the scope alone, with the textures and the resource form:
  the clear inside the scissor, one split each (attachment_read_splits 1, instance splits 1,
  2 instances begun), own-pixel copies of 308 texels (the 20x12 scissor and a pixel round).
- a_draw_after_a_clear_with_no_barrier_reads_the_texels_from_before_the_pass: no split.
- a_barrier_at_the_pass_start_costs_nothing_without_a_read_of_a_cleared_color: a loaded target
  read after the barrier, and a cleared one with a draw reading another texture: no split, as
  many instances begun and copies taken as with no barrier.
Negative control: the same tests on the tree without the runtime change fail at pixel (4, 4),
reading [0, 64, 0, 255] (the texel from before the pass, reordered) where the clear's
[120, 200, 40, 255] is due.

(cherry picked from commit 923095effcd188a93ee5134ecc4dad3fab21b3fe)
2026-11-04 18:50:30 -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 b2df1add01 Bind a storage view of a whole buffer from its space's start, so draws that move only an offset keep their set 0
What: `bind::instantiate::planned_range` gives a descriptor-form slot read
through a storage view of its `Whole` window the range from the start of
the bound buffer's space to its padded end, whatever the bind offset, and
the bind offset as its `SlotBindOffset` residual. `bind_buffers` (every
draw's and dispatch's instantiation) and `rebind_slots`
(`rebind_draw_slots_into`) take it. Every other slot keeps
`descriptor_range`'s range: uniform views (whose `RangeAtBindOffset`
specialization reads a range from the bind offset), bounded windows, and a
storage view whose range from 0 would pass the view's
`maxStorageBufferRange` (`PlannedBuffer::max_range`) or 2^32 bytes (a
32-bit residual and offset), or whose bind offset lies at or past the
padded end. The tessellation factor and index bindings keep it too.

Why: `EncoderCore::set_zero_of` was 14.3% (draws.10k) and 8.8% (WS-like)
of the encoding thread's samples: every draw allocated, wrote and bound a
set 0 of its own. A `device T *` slot's range started at the bind offset
aligned down, so each new offset wrote another descriptor and neither
`LastSetZero` nor `SetCache` could match.

Vulkan: the descriptor's offset is the space's start (256-aligned, as a
bind at offset 0 has it today) and its range ends where today's ends (the
padded end), so offset + range, and a dynamic binding's effective offset +
range (VUID-vkCmdBindDescriptorSets-pDescriptorSets-01979), are what they
were. dynamic_writes moves that same start into the dynamic offset for
every bind offset. The range is explicit, never VK_WHOLE_SIZE (06715 does
not apply). Hazard ranges are untouched: they come from the plan's use
ranges from the bind offset (`binding::bytes_use`).

Behaviour: a Metal offset m from the bind offset reads byte residual + m of
the range, the same byte as before for every access inside the window. An
access that reaches back before the bind offset (a negative index, the
32-bit offset wrapping) and lands in the buffer's space now reads and
writes the buffer's bytes there, as Metal's does; before, it lay outside
the descriptor range unless it stayed within the alignment's residue. On
a device with robustBufferAccess (or under in-shader containment against
the view's size) accesses are bounded by the larger range [space start,
padded end) instead of [bind offset aligned down, padded end): such an
access before the bind offset is in range and reaches the buffer's bytes
where it was a robust out-of-bounds access (a zero, a value from within
the buffer, or a dropped write). Accesses past the end are bounded as
before.

SEMANTICS_VERSION 1957 -> 1958: instantiated descriptor ranges and
residuals change. golden_hashes_match_the_table passed unchanged here (it
hashes compiled modules, which this does not change); the re-bless on
development decides.

Tests: planned_range's unit tests (the range from 0 and the residual at
every 4-byte offset for base alignments 16, 64 and 256, and a 2^32-byte
buffer at its last word; each fallback equal to descriptor_range's
answer). A device test, set_zero_at_offsets: 9 draws of colored_vertex
moving only two device buffers' offsets reuse 8 sets and bind 1, and draw
what 9 draws of buffers of their own draw (0 reused, 9 bound).
dynamic_multi_variable's moved-offset dispatches now reuse their
predecessor's set (7 of 8) and still answer Metal's values from each
dispatch's own offset. docs/API.md states the range.

Verified: the translator suite, 3324 of 3324 (plain). On the M3 Max
(MoltenVK 1.4.2), debug, --cfg m2v_gpu, under maclock and memcap: 96 of 96
runtime tests (fix 1's set plus set_zero_at_offsets,
dynamic_multi_variable, uniform_bind_offsets, binding_view, range,
rebind_descriptor_slip, rebind_behind_a_wait, depth_ranges, attributes),
and 220 of 220 validation lanes under the validation layer (fix 1's set
plus stage_in_regions, stage_in_strides, padded_loads, escaped_slots,
absent_reads, chosen_pointers, dispatch_*, read_through_views,
guarded_effects, index_fetches, first_vertex, vertex_strides, host_bytes,
pointer_uploads, commands_recorded, runtime_lane::tests, among them
renders::public_render_cases_match_metal and
tests::stage_in_region_cases_match_metal). Negative control:
planned_range forced to fall back fails set_zero_at_offsets ((0, 9)
against (8, 1)) and both dynamic_multi_variable moved-offset tests
((0, 0) against (7, 0)). clippy plain and with --cfg m2v_gpu clean.

Per draw on the encoding thread, release with thin LTO, 3 interleaved
rounds against the parent build, medians:
  draws.10k  11201.7 ->  9212.4 instructions (-17.8%), 616-661 -> 485-495 ns
  WS-like    23121.1 -> 21752.5 instructions (-5.9%)
One round's counts: draws.10k 0 -> 29880 sets reused, 30000 -> 120
vkCmdBindDescriptorSets, 6 -> 60000 vkCmdPushConstants (the residuals;
both stages' writes are pushed where either changes); WS-like 0 -> 3744
sets found in the command buffer's cache, binds unchanged at 4000.

(cherry picked from commit b875660ecbad7dd6f9dfa9f976ef1c2b32bded1e)
(cherry picked from commit b09293e9c22d80e4ae4c505b00ba0e07e6a8165c)
2026-11-04 18:50:27 -08:00
Anees Iqbal cc6b083fc2 Let what every write route of a command buffer may write reach every buffer it made resident for writing
What: what an indirect command buffer's records may hold (WrittenCommands, command_writes) took a
writer's writes only from the encoder that made the buffer resident for writing (Writers: the
state set then, each set after, and that encoder's executions). The routes that mark the buffer
(write_routes.rs) were already the command buffer's. Routes now keeps what all of its routes may
write (states set in any encoder, before the residency or after it, and what executed buffers'
records may name) and adds it to every buffer made resident for writing, at the call that brings
either; an encoder opens with what the ended ones met. For two encoders open together (a parallel
render encoder's) the commit adds what each did not see of the other, and the followers that
sets off are marked outside the command buffer's lock, as the commit's marks are. Writers is
gone: Routes holds a superset of what it held.

Why: Metal runs what a kernel wrote with the buffer resident for writing in any encoder of the
command buffer, before the kernel's or after it (the probe icb_routed_writes.m, M3 Max, macOS
27.0.1). The marks matched that; the summary did not, and an execution of a buffer that inherits
the encoder's state decides on the summary whether the GPU alone runs it, as draws of the one
primitive type it allows. With the residency in another encoder than the kernel's, the GPU alone
ran the kernel's point as a draw of the CPU's triangles, which drew nothing (the previous commit's
lane). The bug is older than the write routes: the summary was per encoder before them too.

What it moves: an execution of a buffer whose command buffer sets, in another encoder than the
one that made the buffer resident, a state that may write what the GPU-alone forms rule out: a
render execution takes the host step where that state may write more than draws of one primitive
type, buffers, resets and cleared barriers; a compute execution in a concurrent encoder orders its
commands where it may set a barrier, and a checked one calls its check where the records may name
a state that may encode. The lanes that made a buffer writable with a state set in an encoder of
its own (indirect_host_steps::encoding_state_set: icb_replay_encode's, which may set pipelines,
dispatch, set threadgroup lengths and barriers) showed it: with it, 6 of the 480 tests of the 40
modules changed (render_merged_executions' GPU forms into a shadowed target took the host step,
6 executions; five dispatch_executions tests saw barriers, check calls and a host step), all
others as before, resident_draws among them (its writer and residency share an encoder: no host
step on its write path, its chunks kept). Those lanes are about the GPU-written path, not about
what the state writes, so the lever now sets icb_reset_encode's state (resets alone, which no
GPU-alone form rules out).

Docs: written_commands.rs and write_routes.rs module docs, IndirectCommandBuffer::command_writes,
render/executions/gpu.rs, the runtime README and docs/API.md section 10.

How verified (debug, --cfg m2v_gpu, M3 Max under MoltenVK): runtime_lane::write_routes passes
(it failed before this commit: After and Before drew no point); the 39 ICB lane modules and
write_routes, 480 tests, pass with the reset lever; the runtime's
tests::write_routes_device::a_route_reaches_every_buffer_its_command_buffer_made_writable (new:
a later encoder's state, one set before the residency, and a parallel encoder's at the commit)
and tests::written_commands pass; clippy -D warnings with --cfg m2v_gpu is clean.

(cherry picked from commit 7d13a4dee21162a972b40fd9868e3e2f9112a677)
(cherry picked from commit 13b9646e48b767defdd189bf156a2a9130b3b857)
2026-11-04 18:50:27 -08:00
Anees Iqbal e924d293c5 Compare against Metal what an execution runs of commands a kernel wrote, by where the command buffer made the buffer resident for writing
What: a new owned fixture, icb_routed_writes, whose kernels write command 0 of an indirect command
buffer: a render command with its state taken from the argument buffer (irw_encode_draw), a
render command of a buffer that inherits the encoder's state, a point at the target's centre
beside the CPU's triangle in command 1 (irw_encode_point), and a compute command with its state
from the argument buffer (irw_encode_dispatch). A Metal probe
(crates/metal2vulkan-conformance/probes/icb_routed_writes.m) and a lane
(runtime_lane::write_routes) run the same four shapes: the buffer made resident for writing in
the kernel's encoder, only in an encoder after it, only in one before it, and nowhere; a later
encoder of the same command buffer executes the buffer.

Why: the marks of a buffer the GPU may write are the command buffer's, while what its records may
hold was gathered per encoder. The lane asks whether an execution runs what the GPU wrote, with the
right state and pixels, wherever the command buffer paired the residency with the writer.

Metal's answers (the probe, M3 Max, macOS 27.0.1, validation off, verified): in the kernel's
encoder, after it and before it, all three kinds ran the kernel's command (green, green, words
0x100 to 0x103). Nowhere: the render command and the point did not run (the CPU's records: red),
the compute command did. docs/API.md records that last difference: no encoder of the command
buffer made the buffer resident for writing, which Metal's contract asks of a function's write,
and the runtime runs the CPU's records there (APART in the lane).

How verified: the lane, debug with --cfg m2v_gpu on the M3 Max under MoltenVK, fails at this
commit, which is the bug the next commit fixes: [(Same, [true, true, true]), (After, [true, false,
true]), (Before, [true, false, true]), (Nowhere, [false, false, false])] against Metal's (with the
compute command apart), the inherited state's executions taking 2, 0, 0 and 0 host steps: with the
residency in another encoder than the kernel's, the GPU alone ran the kernel's point as a draw of
the CPU's triangles, which drew nothing. The render command and the compute command ran right in
every shape.

(cherry picked from commit 25134688d13d1abedab5e3ee5e1ff4c9db442a90)
(cherry picked from commit ba7f047a7987a63a9e1f6fd78ae7093f27326e55)
2026-11-04 18:50:27 -08:00