EmitCx::arena_slot remembered the slot where it was first asked for.
dispatch::emit_entry asks in the entry hooks, after the floor's tail
guard (push::emit_tail_guard) closed a construct, and the memo keeps an
entry only where it was made in the entry block, the block the hooks
end in or the open block's spine: a later hook construct leaves the
slot behind, and every block that reaches the arena derives it again
(24 instructions each). Lane ksizeread counted 2,965 such derivations
in the 780M library's 628,489-weight kernel.
- The slot is now made in the function's first block wherever it is
first asked for (FunctionBuilder::in_entry_block, remembered at
entry): its operands are the pushed arena address load_push_fields
loads there, the invocation's built-ins and constants.
- The entry block is recorded before the hooks run (begin_hooks), so a
hook after the tail guard's construct recalls the push fields the
first block loaded instead of loading them again.
- The tail guard reads the tail field from that same load where the
function reads the field from its member (EmitCx::derives names the
fields a function derives elsewhere); the tail word, and a derived
field, are still loaded by the guard.
Test: tests/engine_device_arena.rs, an owned kernel whose 7176-word
arena is reached in four blocks. On every identity profile, with the
default inputs and with partial_threadgroups, the slot is derived once
and each push member is loaded once. Without this change, on the same
kernel at 0429ff1bd4 (m3-max-64752), one member was loaded twice by
default and one three times with partial threadgroups; the slot was
derived once there, so the kernel does not reproduce the re-derivation
the 628,489 kernel shows.
A reader of a Managed buffer's device copy took, as it was encoded, the copy back of any texture
over it that any command buffer had written, submitted or not, and cleared the flag the write's
submission reads. On one queue Metal runs command buffers in commit order, whichever was encoded
first, so:
- W (writes the texture) encoded before R (reads the buffer), R committed first: R copied the
image back before W ran and cancelled W's copy back; a reader after both completed read the
old bytes.
- R encoded before W, W committed first: R took nothing as it was encoded and nothing took the
copy back at R's submission; R read the old bytes. The same held for R on another queue
committed once the guest saw W complete, or ordered behind W by an event.
Now a reader takes as it is encoded only the copies back owed by earlier writes of its own
command buffer (each segment's written textures carry whether their copy back is still owed).
Those owed by other command buffers' writes, set at the write's submission, are taken by the
upload that leads the reader's submission, as take_into and the capture's copy-in already do:
on the device's one VkQueue that is where the order is known. A segment that reaches a Managed
buffer a texture over which an earlier segment of its held group wrote, its copy back owed,
leads its own group, so the write is submitted first (the capture fix's split). Entry.fresh
goes. No copy is added; the same copies back move to where their order is known.
Tests: three arms of one device test (tests/managed.rs): W encoded first and R committed first;
R encoded first and W committed first; R on another queue encoded first and committed once W
completed. Before this change all three were red on the RTX 5080 where run (64770: arms one and
two; the third arm was added with the fix).
Two device tests on one queue: W copies a pattern into a texture over a Managed buffer in an image
of its own, R copies the whole buffer out; the one encoded later is committed first, then L reads
the buffer once both completed. R reads what the commit order leaves (the buffer's bytes where R
went first, W's pattern where W did) and L reads W's pattern. The line prints the form and the
copies R recorded as it was encoded.
Development's 2260 is the kept routines of repeated regions (9356f81e51), which landed first. The signed
remainder's own bump (64d9946757 on its branch, 2259 to 2260) is not replayed; this commit takes the next
number instead. A cached lowering made under 2260 may hold OpSRem or OpSMod, or the six-instruction funnel
shift, where this tree emits the defined remainder and the two-shift rotate.
The case signed-remainders was recorded without times, so the conformance suite's
times::every_case_is_timed::every_case_carries_its_timing failed on it (job m3-max-64669).
`conformance times --runs 8 --write signed-remainders` on the M3 Max (job m3-max-64714) took
Metal's per-call figures into the case's recording: seven calls (buffer, zeroed_buffer, library,
compute_pipeline, dispatch_threads, wait, read_buffer) over 8 rounds. The recorded answers are
unchanged; only the recording's times list is added.
llvm.fshl, llvm.fshr and air.rotate whose amount operand is an integer constant (const_int at
selection) take ArithStrategy::IntFnBy, with k = the amount modulo the width taken at
translation. math::funnel_by emits a (b for fshr) for k = 0, else (a << k) | (b >> (N - k)) left
and (a << (N - k)) | (b >> k) right (a rotate's b is a): three instructions, both shifts in
1..N-1, where the run-time form takes six (OpUMod of the amount, the shift by one, the OpISub
of N - 1 - s, two shifts and the or) so that no shift reaches the width, which SPIR-V leaves
undefined. A run-time amount keeps that form; a vector amount is not a constant here and keeps
it too. The strategy is named arith.int_fn.by_constant.
Why: ksizeread's count found every llvm.fshl in the heavy kernels to be a 32-bit scalar rotate
by a constant amount (8,546 in k7, 8,560 and 8,569 in the two heaviest, 4,273-8,569 in the other
780M kernels), and no llvm.fshr. Each loses three instructions and two constants' worth of work.
Tests: lower::arith::tests::funnel_shifts_by_a_constant_answer_their_definition runs
math::funnel_by for rotate, fshl and fshr at 8, 16, 32 and 64 bits for every amount in 0..2N
against int_ref (the run-time form's reference), over the width's edges and random values.
tests::engine_arith::a_funnel_shift_by_a_constant_shifts_by_constants compiles fshl(a, a, 13),
fshr(a, b, 37) and fshl(a, b, 32) on moltenvk-m3, runtime-floor and amd-rdna3-radv: no OpUMod
and no OpISub in the module (the run-time form holds both), and LLVM's answer on the
interpreter.
Under SEMANTICS_VERSION 2260 with the signed remainder: the same pin, no version of its own.
The case signed-remainders runs the owned fixture kernel_signed_remainders: each of 238 threads
reads a 64-bit dividend and divisor (17 dividends by 14 divisors: both signs, the most negative
long and int, low words that are the most negative short and char, values past 32 bits) and
writes eight words: the remainder of the low words as int, short and char, the 64-bit remainder's
two words, the exclusive-or of an int2 remainder's lanes, and the low word's remainders by 3 and
-8. Apple's compiler writes srem i32, i16, i64 and <2 x i32> by run-time divisors and srem i32 by
the constants 3 and 8 (x % -8 is x % 8). A remainder MSL leaves undefined (by zero, or of the
most negative value by -1) is never taken: the fixture writes 0xdeadbeef there. Every column
compares exactly.
It holds every device to Metal's answer where the translator's signed remainder (the commit
before last) replaced OpSRem, which Vulkan makes poison for a negative operand without
maintenance8.
Recorded on the M3 Max, macOS 27.0.1 (job m3-max-64656, which also compiled the fixture's
companions with scripts/regen-air-fixtures under Apple metal 32023.922 and LLVM 21; TOOLCHAIN
records the fixture's line). Metal's 1,904 recorded words equal C's truncating remainder for
every operand pair (checked from the recording against a reference written apart from the
fixture). docs/CONFORMANCE-COVERAGE.md regenerated (scripts/conformance-coverage/coverage.py).
The counter of folded results in signed_remainder_kernels was named k, which shadowed the file's
fn k(name, body, want) at the call that builds each kernel (E0618 in job m3-max-64645's clippy).
It is now folds.
Vulkan makes OpSRem and OpSMod poison when either operand is negative unless the device enables
maintenance8 (the Vulkan spec, "Precision and Operation of SPIR-V Instructions"; maintenance8 is
optional, and the UHD 630's Windows driver does not list it). LLVM's srem and Metal's % are
defined for every sign but a zero divisor and the most negative value by -1, so a negative
operand gave a guest an undefined answer on such a device.
One form on every device, with no query: FunctionBuilder::signed_remainder takes the operands'
magnitudes (negated where negative, read unsigned, so the most negative value's is 2^(w-1)),
their OpUMod, negated where the dividend is negative; RemainderSign::Divisor then adds the
divisor where the remainder is not zero and the signs differ (OpSMod's sign). A scalar constant
operand's magnitude and sign are computed at translation. Scalars and vectors of every width;
a signed-typed operand is bitcast to the unsigned type for OpUMod and back. The IR's BinOp has
no SRem or SMod any more, so no lowering can emit either: arith's srem (lower/arith/ops.rs) and
the bicubic emulation's repeat and mirror wraps (lower/sampler/bicubic.rs) take the helper; the
wide (two-word) 64-bit path already divided magnitudes. The interpreter's SRem and SMod go with
the variants.
Size, before building (job m3-max-64604, a probe counting sites in every serialized module, no
GPU): every site in the app's two libraries is a 32-bit scalar srem, none an smod. k7 (436,848
function-body instructions) holds 54 and gains about 414 instructions (0.095%); the heaviest
kernels gain 0.07-0.12%. The only rows past 1% are modules of 257 to 787 instructions with one
to four sites.
Tests: tests::engine_arith::no_module_holds_a_signed_remainder_opcode (fails before this
change: every kernel's module holds OpSRem) over srem of i8, i16, i32, i64, <2 x i32> and
<2 x i64> by run-time and constant divisors of both signs, the most negative value among them,
on moltenvk-m3, runtime-floor and amd-rdna3-radv; the same kernels compute LLVM's srem on the
CPU interpreter in arith_kernels_validate_and_compute_on_every_profile. engine_bicubic's
reference test now requires no OpSMod or OpSRem in its modules. The serializer's family test
validates the form on each integer type with both signs; the interpreter's integer test reads
-7 rem 2 = -1 and -7 mod 2 = 1 through the helper.
SEMANTICS_VERSION 2259: srem and the bicubic wraps emit different words.
What: DeviceOptions::stage_memory_ceiling (bytes, default 0) is the memory ceiling the consumer
gives its stage helper. Device::record_stage_breach keeps it after a StageBreach::Memory entry's
byte (the entry grows from 58 to 66 bytes); at a make, a memory breach kept under a ceiling below
the device's is a miss, removed like any miss, so the make answers Error::StageUnfilled with its
request and the consumer's next fill (or a breach kept under the new ceiling) takes the entry's
place. At the breach's ceiling or below it refuses (Gap::StageSize) as before. A memory breach of
its byte alone reads as kept under 0. Time, Compile and CompileRequired breaches keep their one
byte and refuse under every ceiling; data entries are unchanged.
Why: a breach kept under the consumer's lower helper cap kept refusing the pipeline after the
consumer raised the cap, until the driver's version changed, so a host that gains memory stayed
refused for good. The ceiling is a fact about the consumer's helper that rt only stores with a
memory breach and compares at a make; no other path reads it. The entry form changes by a length
rule, with no version: WIRE_VERSION is in every stage key, and bumping it would drop every filled
entry.
Tests: a_memory_breach_holds_to_its_ceiling_and_is_a_miss_above_it (host): a memory breach kept at
A holds at 0, A-1 and A and is a removed miss at A+1; a fill replaces a breach of its key; a breach
of the byte alone holds at 0 and is a miss at 1 and at A; the other three breaches stay 58 bytes
and hold at 0, A and u64::MAX; data reads back at u64::MAX. The foreign-entry test adds a time
breach followed by a ceiling and a memory breach followed by half of one, each a removed miss. The
device test adds: the breach kept at ceiling 0 is StageUnfilled with the same request on a device
given ceiling 1, and a breach kept there refuses there (runs only where the driver writes a
pipeline cache header, so not on lavapipe).
What: over_write_before_a_capture reads, once R is scheduled and while the busy work still holds
the GPU, whether a submission went since W's commit, prints it on the path line, and asserts it
went exactly where W is in the group held and the device keeps two copies.
Why: AGENTS.md asks evidence that a device-shaped path ran, not only that the run passed. With two
copies, R takes the copy-in over the buffer W's texture lies over, so it leads its own group
(Captured::names_written) and W's group is submitted as R comes, before the busy work ends; held
for room, or with one copy (no Managed device copy, no split), nothing is submitted before then.
How verified: the compile job and the lavapipe rt suite, and the 5080 and XTX runs of this commit,
are in the lane's report by job id.
What: the test of eighty equal regions asserts that the first search's set holds all eighty, then
that the outlined module is valid and writes what the regions wrote; it no longer asserts that the
whole pass makes exactly one routine called eighty times.
Why: once the eighty regions are calls, the calls are equal items themselves; with the test's
regions of about 44 instructions and a smallest region of 1, a later search can write runs of 16
or more calls as a routine of their own (calls are CONST_OK operands, as roll's varying_ok says),
so "one routine, eighty calls in the entry" depended on that second search failing. The set the
first search takes is the property the fix (f0a204d6a0) gives: the search as it was took at most
65 of them.
Verified: not yet run; it runs in the next compile job with the rest of spirv::outline.
What: cache::SEMANTICS_VERSION 2259 to 2260.
Why: the outline pass (a repeated region of 500 or more instructions written once, as a kept
routine) changes the words of any module that holds such a region under an unchanged key. Its
first commit bumped 2258 to 2259; development reached 2259 for the device-address leaf
(d97bf60431) before it landed, so the rebase took that line as already equal and the pass's own
bump is this one.
Verified: the golden table and the old render key are re-blessed at the pin, as for every bump;
the compile job of this branch's tip reports them.
What: find_in compares an extent against every repeat of its seed window in the function (ranges
of keys by prefix hashes), not only the first 64 repeats it extends against, so one search makes
one routine for every occurrence of a region. The context keeps, by layout position, whether a
loop holds it, and the set of loops' continue blocks; apply drops the gone regions' first blocks
from the switches-at-use list once. The bounded-growth test's chain draws each group's two
operations from four by a hash of the group's index.
Why: the compile job of 08455481c5 (m3-max-64636) failed
engine_bounded_growth::compile_cost_grows_linearly_with_the_block_count: doubling its chain of
equal groups multiplied total compile allocation by 3.43 (49,119,827 to 168,331,419 bytes), 26,005
to 83,028 words. A set held at most 65 occurrences and its saving was counted over them, so a
function of N repeats was searched about N/64 times, each search linear in the function: the
quadratic term. Two scans per occurrence over every loop of the module (in_loop, the continue
check) and a retain over switches-at-use per region were the same shape. The test's chain is all
one group repeated, which the pass rightly writes as one routine, so its module stops growing with
the chain ("the generated graph was folded away"); its groups now differ, so the graph it
measures survives whole.
Verified: not yet run; the new test
a_region_repeated_past_the_repeats_tried_is_one_routine_called_at_every_repeat (80 equal regions
are one routine with 80 calls; the search as it was makes two) and the bounded-growth test run in
the next compile job.
What: a new pass, spirv::outline, runs on every module after rolling and hoisting. It finds a set
of regions of one function that are the same code (one sequence of the function's spine, loop
bodies included; entered only at the start and left only at the end), each of at least 500
instructions with a call of a kept routine counting one, writes the first as a new kept routine
(Function::kept, declared DontInline, the form ModuleBuilder::kept_routine makes) and replaces
every region with a call of it, then looks again, at most 64 times. Values from before a region
are parameters (one per distinct set of the regions' values; a constant that differs only where
any value may stand); a pointer parameter is a Function, Private, Workgroup or UniformConstant
variable itself or a PhysicalStorageBuffer pointer; values read after a region are the routine's
results (several in a struct). A Function variable only its region uses becomes the routine's
own where the region is in no loop or its first use stores the whole variable in a block the
region always runs; otherwise it is passed. Anything else that differs keeps the regions in line.
Candidates come from the spine's keys (16-item windows hashed, extended both ways); a set whose
exact comparison fails at an operand or result is compared again without that item. The spine
(roll::spine) takes a flag to walk loop bodies as sequences; rolling passes false and is
unchanged. SEMANTICS_VERSION 2259. API.md and ARCHITECTURE.md say the routines exist.
Why: NVIDIA's driver compiles a DontInline routine once and Mesa's drivers inline it either way.
On the RTX 3090 (620.70.06, job m3-max-64453) a generated kernel calling a 1,984-instruction
function from 50 places was created in 21.5 s inlined and 52 ms as a kept routine (51.8 s and
75 ms with 64 values live across every call); its dispatch GPU time was the same with few values
live and 20.6% lower as a routine with 64 live. A 497-instruction function: 0.1% and 19.7% lower.
500 is the smallest size measured within 3%. RADV and ANV (Mesa 26.2.6) compiled identical code
for the call, DontInline and inlined forms (jobs m3-max-64357, m3-max-64379).
How verified: spirv::outline::tests build kernels with three equal regions (a variable, a
selection's phi, a counting loop), a chain where each region reads the previous one's result, a
middle region that differs, and two regions in a loop whose accumulator is read before it is
written; each checks the routine and call counts, the module through the verifier and spirv-val,
and the words the interpreter writes against the unrewritten module's and the expected ones.
The named pin carries memleaf (d97bf60431, fffff6e96b: a device-address leaf of whole words is one access, and
under the identity domains a wide pointer is its device address), which bumped SEMANTICS 2258 to 2259.
- golden_hashes.tsv: 1,980 rows re-blessed on the M3 (m3-max-64644 at db5fefc2ce, GOLDEN=0), header semantics 2259.
- authored-compile.tsv: artifact hashes only; no case changed status (2,378 rows, 0 status changes; 64644).
- the_old_render_descriptor_key_keeps_its_value: b3da28b0..., the value the suite at db5fefc2ce printed
(m3-max-64624); the key hashes the translation's semantics, which moved.
Under the resident-table domains a pointer loaded through a wide pointer is
two whole words reached through PsbMem, which now reads them as one
PhysicalStorageBuffer access (Aligned 4) instead of two word loads. The
test counted two volatile loads; it now counts one and still checks the
value the chased pointer reaches.
Verified: the suite job m3-max-64513 at 428ff0fedd failed this assertion
(left 1, right 2) on moltenvk-m3 robust=true; rerun below.
A wide pointer under the identity domains was u64vec4(0, a, 0, 0): three
zero fields carried through every GEP (four extracts and a construct around
the 64-bit index arithmetic), phi and select, and extracted at every access.
It is now the address alone, a u64 (DemoteTy::Address): a GEP is the
address's own arithmetic, an access reads no field, a parameter is its slot's
address, a loaded or converted pointer is the loaded word, and the null wide
pointer is 0. Off the identity domains the root-table form keeps its fields.
dynamic::fields gives an identity pointer's fields as constants, and add64
folds the zero host.
Rides SEMANTICS_VERSION 2259 with the whole-word access (both change
device-address modules).
A load or store of a Path::Vec4, Vec2 or Aligned leaf through a device
address (psb::PsbMem: static slots, wide pointers, the vertex fetch's
sources) moved each 32-bit word with its own address arithmetic, place and
access: a float4 at an unproven 16-byte offset was four loads and about 38
instructions. It is now one PhysicalStorageBuffer access per 16 bytes at the
device address of its first word: the leaf's own type where its register
value is its words' bits in 32-bit lanes (float, int and their vectors), else
a u32 or uvecN converted as the words were. The Aligned operand is what the
offset is proven to be (16 or 8 from a slot's own address, else 4), which
VUID-StandaloneSpirv-PhysicalStorageBuffer64-06314 allows for every type the
form uses. The words read and written are the word path's, at the word
holding the leaf's first byte, so Metal's placement holds. A store ending
inside a word keeps the word path. Descriptor views keep theirs. The
device-address uvec2/uvec4 units this replaces are deleted, and the word
below an access is one mask (psb::split_word) instead of a mask and a
subtract.
SEMANTICS_VERSION 2258 -> 2259: device-address modules change.
Each shape is two kernels, one access and two, everything else equal: the
second's entry weight less the first's is one access's instructions, and its
device-address loads and stores less the first's the SPIR-V accesses it
makes. Shapes: wide float, int, float2, float4 loads and a float4 store; a
pointer loaded at a run-time offset of an align-1 constant buffer and a float
through it; a float4 load and store at a uint offset (alignment 4 proven);
a float4 load at a float4 offset (16 proven). On every identity profile each
access of a leaf of whole words must be one device-address access, within
its bound. It fails on the word-by-word form this branch replaces.
floor::MAINTENANCE8, floor::Maintenance8Features (with its maintenance8 member and its chain
impls), floor::Features::maintenance8 and floor::Capabilities::texel_offset_operand are new, and
OPTIONAL_EXTENSIONS's value ends with MAINTENANCE8. For a consumer: a struct literal of
floor::Features or floor::Capabilities that names every field no longer compiles (both take the
new field); nothing else moves.
The device-cfg floor test creates each device with the floor's features and destructures them;
the new field broke its build under --cfg m2v_gpu and m2v_cpu_icd (job m3-max-64512).
The owner allowed a ninth query-chosen form (Telegram 2465): "I allow the ninth query. Use it
where you can". This answers the texel-offset question inside his compile-time order ("Multi
minute compiles are unacceptable").
What: the floor reads VK_KHR_maintenance8 and its feature maintenance8 where the device lists the
extension (one of OPTIONAL_EXTENSIONS, and one of the OPTIONAL features, each of which chooses one
of two forms; VkPhysicalDeviceMaintenance8FeaturesKHR is bound by hand, as ash 0.38 lacks it, its
layout checked as the crate compiles). Device creation enables both, Capabilities answers
texel_offset_operand, and the translator's description is told of Maintenance8 and
KhrMaintenance8 (shader_enables). The translator already takes a run-time offset on a sample as
the Offset operand where its profile has maintenance8 (lower::sampler::select::dynamic_offset).
Until now the runtime never enabled the feature, so with_enabled dropped it, and every run-time
offset that reached lowering became a switch of up to 256 ConstOffset arms. NVIDIA's compiler
takes minutes to create that switch (lane stagesize: 255 arms 193 s on an RTX 3090, the operand
80 ms). Canonicalization's unroll of a proven small nest is unchanged on every device.
A device without the feature keeps the branch: Intel's Windows driver for the UHD 630 (101.2145)
lists no VK_KHR_maintenance8 (vulkaninfo, job 64024). The runtime README records the branch's
compile time as a known gap of pipeline states, and its floor tables gain the extension and the
optional feature. AGENTS.md rule 2 changes in this commit: "for eight only" becomes "for nine
only", and the list gains run-time texel offsets.
Spec (1.4.366): VUID-RuntimeSpirv-Offset-10213 is the only gate on Offset outside a gather. The
value is OpBitFieldSExtract(v, 0, 4), in [-8, 7], inside the required minTexelOffset <= -8 and
maxTexelOffset >= 7 (VUID-RuntimeSpirv-OpImageSample-06435/06436). Gathers already took Offset
through shaderImageGatherExtended, which the floor requires. Enabling maintenance8 changes no
other path the runtime takes: its blits stay within one 3D image, it names no queue family
ownership transfer flag, and it merges no pipeline caches.
Caches: the translator is unchanged, so SEMANTICS_VERSION stays. The translator's profile
fingerprint (DeviceProfile::fingerprint, over every profile field, ImageCaps::dynamic_sample_offset
among them) moves on a device that has the feature, and with it every FunctionCompileKey and render
record name in the cache directory. A lowering made without the feature is not taken by a device
with it (tests::filter_nest's every_device_keeps_the_operand_s_and_the_switch_s_lowerings_apart).
Tests: tests::floor's a_run_time_texel_offset_is_the_sample_s_operand_where_maintenance8_is_reported
fails without the change (no Maintenance8 among the enables); the_optional_features_decide_the_
capabilities takes the eighth case. tests::filter_nest (device cfgs): the unrolled kernel, the
operand and the switch (a translator told of no maintenance8 on the same device, test-only) write
the same 64 sums; the module needs maintenance8 and holds no OpSwitch where creation enabled it,
and holds a switch otherwise.
every_device_writes_its_lowerings_off_the_creating_thread_and_drops_them_past_its_queue hung on
lavapipe after 7a9458f983 (capover's check m3-max-64386: SLOW past 300 s; it passed at 8bef47758f
in m3-max-64358). The stall made the reaper pop a file and then spin in write_kept, so the queue
could be empty when the test set its bound to the bytes waiting. Since 7a9458f983 an empty queue
takes a file of any size, so the second kernel's lowering was kept, not dropped; the assertion
failed with the writes still stalled, and the device's teardown waited forever on a reaper spinning
in write_kept.
Now the stall is taken where the reaper takes a write: next_write answers none while stalled, the
queue keeps every file handed over, and the test pokes the reaper when it lets them go. The
product path is unchanged (the stall is test-only).
The room rule's paragraph said a run not yet known passes the 16 ms test. It does not:
an unknown run counts as u64::MAX (submit::room, and a group's run saturates), so a queue
whose command buffers have not yet retired with their GPU times has room for two
submissions only, and its third command buffer waits for one seen complete. That is what
the Iris A/B's frame_5cb_from_idle (+4.0%, about 6 us, m3-max-64375) reads as the room
rule's price from idle.
Verified: docs only; the check is fmt, Rustdoc and the API reference.
What: a didModifyRange: capture's copy-in no longer records the copies back owed to the textures
over its ranges in images of their own at the commit. The submission that takes the copy-in takes
them (CopyIn::backs, by the existing rule for submitted writes, ManagedOvers::backs_before) into the
upload that leads it, ahead of the copy-in. A command buffer that would take a copy-in over a
Managed buffer, a texture over which a command buffer of its queue's group held wrote, leads its
own group (Captured::names_written), so the write is submitted, and owes its copy back, first. The
split fires only then: a group held that holds a write of a texture over a Managed buffer's device
copy, and a later command buffer joining it that takes a copy-in captured after the group's last
lead over that same buffer.
Why: Metal's device copy keeps a GPU write outside a didModifyRange:'s range, and a command buffer
committed after the capture reads that write and the range's new bytes (MTLBuffer.h). The copy-in
copies the texture's whole range from the device copy into its image, so a write that runs before
it must be copied back first. Taken at the commit, only writes already submitted were copied back:
a write committed before the capture and still held (in its queue's group held, or held for room)
ran before the copy-in and was overwritten. Which writes run before the copy-in is known only as the
submission that takes it goes: a write of another queue not yet submitted runs after it, and taking
its copy back at the commit (the commit-time form) would copy an image never filled over the device
copy and drop the write's own copy back.
How verified: before, at d910296ac6 on the RTX 5080 (job m3-max-64324), both forms of
over_write_before_a_capture failed: R read the buffer's old bytes outside the named row, the new
bytes in it, with two copies, an image of its own, its buffer's entry owing it, and W not yet
submitted as R's commit took the capture. A third arm,
every_device_keeps_a_managed_texture_over_s_write_held_behind_a_passing_capture, runs the copy-in
ahead of the write (B1 passing A's group held with A3 the writer) and checks B1's read, A4's and the
buffer's after. The after-runs are in the lane's report by job id. The capture tests now read W's
submission state before R's commit, which takes the capture: W's group may now go as R is staged.
What: over_write_before_a_capture, in two forms. Behind the busy gate, W copies a pattern into a
texture over a Managed buffer in an image of its own and is held (in the queue's group held, or held
for room behind UNSEEN_JOINS joins); then the consumer writes and names the texture's last row and
R, committed after on the same queue, takes the capture and reads the whole texture. R must read
W's pattern outside the named row and, with two copies, the consumer's bytes in it. The test prints
the path: two copies, an image of its own, owed by its buffer's entry, W held for room, the
queue's submissions in flight and group held as R commits, and W not yet submitted as R's commit
took the capture.
Why: Metal's device copy keeps a GPU write outside a didModifyRange:'s range, and the range's new
bytes reach a command buffer committed after it (MTLBuffer.h). Read from the code: the capture's
copy-in takes only the copies back of submitted writes (ManagedOvers::backs_before), then copies the
texture's whole range from the device copy into its image, so a write committed before the capture
and not yet submitted is overwritten once it runs.
How verified: its run on the RTX 5080 at this commit is in the lane's report, by job id.
What: section 10's Draws entry on a filled primitive past a viewport edge that crosses a pixel. It
said a Vulkan device covers such a pixel where its sample lies in the clipped primitive; it now says
what was measured: RADV (RX 7900 XTX, two Radeon 780Ms, RX 550) and NVIDIA's driver (RTX 3090,
RTX 2080, RTX 5080) cover every pixel the viewport overlaps, as Metal on the M3 Max does; lavapipe
covers such a pixel only where its sample lies in the clipped primitive; the Iris Xe (ANV) covers
every pixel the near edges cross and none the far edges cross, the accepted difference where that
pixel's sample is outside or on the edge and a driver bug (the runtime README's known gap) where it
is inside.
Why: the entry claimed more than was measured; seven GPUs show no difference at all.
How verified: replays of fractional-viewport-coverage through the runtime, each differing pixel
printed against Metal's recording: m3-max-64279 (XTX), 64288 (780M 1002:15bf), 64280 (780M
1002:1900), 64323 (RX 550), 64286 (3090), 64287 (2080), 64282 (5080): 0 differing pixels;
m3-max-64281 (Iris Xe): 120 pixels, all far columns and rows; lavapipe's 344 elements from its
ledger row. The entry's bold lead-in (the allowance slug) is unchanged.
What: the reaper's write queue (cache::Pending) refused any lowering that would take it past
PENDING_BYTES (8 MiB), even when it was empty, so a single lowering larger than 8 MiB was never
written to the cache directory and every later device lowered it again. An empty queue now takes a
file of any size; one larger than the bound waits alone, and the next is dropped until it is taken.
Why: the consumer's cold launch of a modelling app (Radeon 780M) remade its pipelines after the
fills and translated again for exactly the three heaviest kernels (661, 934 and 1114 ms, weights
742,949, 628,489 and 489,281), while the five lighter ones hit in 12 to 30 ms. A cache that drops
its heaviest entries drops the ones that cost the most to make again. Memory stays bounded: the
queue holds 8 MiB of lowerings or one larger lowering, bytes already in memory before the push.
Verified: the queue's unit test gains an empty-queue push of a file past the bound (kept), a push
behind it (dropped) and room again after the pop; it fails without the change by construction (the
old check refused any push past the bound). Docs: the module doc, PENDING_BYTES, keep_translation,
Metrics::cache_writes_dropped and the README's cache paragraph say the same.
What: one row of known-gaps-rt.tsv, fractional-viewport-coverage on the Iris Xe at case/drawn/texels
(480 elements differ (F32), the largest difference 12), and docs/CONFORMANCE-COVERAGE.md re-derived
(the ledger's row count and the case's gap list).
Why: the case postdates the last round's replays, so no GPU venue had replayed it, and the next round
holds every GPU venue to the ledger. The Iris site mixes two causes, so the one row splits them by pixel:
- 240 elements, 60 pixels (the far column and row of the arms ending 0.7 into a pixel): each centre lies
inside the viewport and is undrawn, ANV's truncated scissor far edge (Mesa update_scissors), a driver
bug, the runtime README's known gap of render encoders; not an accepted difference.
- 240 elements, 60 pixels (the far column and row of the arms ending 0.25 into a pixel and on a pixel
centre): each centre lies outside the viewport or on its far edge, the accepted difference of
docs/API.md section 10 (Draws).
The Iris draws every arm's near partial column and row, as Metal does.
How verified: both cases replayed through the runtime on each GPU venue the round replays, with a probe
(never landed) that printed every differing pixel against Metal's recording, built at 8dc5ebbe9f
(development 0b73ac76e5 plus the probe bin), m3-max-64275:
- Iris Xe (ms01) m3-max-64281: fractional divergent as above; lines-fill-past-the-viewport announced
(equal to Metal under its notice).
- RX 7900 XTX m3-max-64279, 780M HawkPoint m3-max-64280, 780M Phoenix m3-max-64288, RX 550
m3-max-64323, RTX 3090 m3-max-64286, RTX 2080 m3-max-64287, RTX 5080 m3-max-64282: both cases
announced, 0 differing pixels; no row.
With held work going only by room (3f2be1ea4d), the test that a parked completed handler
let IN_FLIGHT + 2 later command buffers all submit asserted the removed busy flag's
behaviour: past the room, the later ones now wait for the handler to return, which
every_device_holds_work_for_room_while_a_completed_handler_runs asserts. The test now
commits two later command buffers, each once the one before it went, and asserts each is
submitted while the handler is parked (a queue with fewer than two in flight has room),
none completes before it returns, and all complete in order after.
Verified: m3-max-64303 (lavapipe) failed this test at 3f2be1ea4d's tip (60 s within at
command.rs:191); the rebased tip's check follows.
The XTX sized A at 26, 28 and 44 fills in arms of one job (m3-max-64241, 64283): the three
single fills that size it ran at the clock an idle GPU starts at in some arms. A warm-up of 256
fills now runs first on the sizing queue, and the least of five fills sizes A.
Each part also times A's GPU time a command buffer, from its first's start to its last's end
over their count (a_per_cb, wait_a_per_cb): the planner's "A's whole backlog drained" check
compares it between arms.
The completion thread set Done::busy and then woke the submit thread (complete.rs, at each
round), and a pass that read busy held nothing: every held group and every command buffer held
for room went to the VkQueue at once. The wake that announces a completion is sent right after
busy is set, so whether room held was a race between a round's length and a thread wake: on the
3090 it mostly held, on the Iris and on the XTX's short arm the backlog flooded past room (A/B
jobs m3-max-64198, 64241: B's p90 two to three of A's command buffers).
The planner's ruling (A): busy goes. Done::busy, its two stores, the read in pass and the
parameter through next_ready, waits_for_room, hold's callers, step, Fifo::goes and unheld are
deleted; held work goes when a completion leaves room, at teardown, or on a send-through (a host
wait, send_now, a fence's updater). `completed` is still raised before the submit thread's mark
is read, so a completion is never missed. While a round runs it sees no completion, so held work
waits for the round's end: a completed handler or listener longer than the work in flight
leaves the GPU idle for the rest, where Metal would go on. The README records that known gap
beside the scheduled-handler one and drops "a slow completed handler holds no later
submission".
Test: every_device_holds_work_for_room_while_a_completed_handler_runs parks the completion
thread in a completed handler, commits three on a queue with room for two, and finds the third
held in a group, two submissions sent, once a later commit on another queue is scheduled. With
busy it went at once (3 in flight). The waits for !busy in the two_queues and behind_busy
helpers and the upload test's trace are gone with it.
A's GPU idle before each of its command buffers was the gap from the end of the one before,
and B's small command buffers that ran in that gap counted as idle. With the room rule B lands
between A's (A keeps two on the VkQueue, not its whole backlog), so the gap grew by B's runs on
the new arm alone: 62-65 us against 22-26 us on the 3090, 77-131 against 23-24 on the XTX (jobs
m3-max-64240, 64241). The idle is now the gap less the parts of B's runs within it.
The signalled part had B commit every 16.7 ms a waiter on A's last committed count. Each of
those waited for A's whole backlog, so B kept about nine uncompleted and B's own queue held
its later waiters: they reached the GPU behind more of A's work, on the old arm and the new
alike (the 3090 OLD read 20 ms at p50 in two of three arms, the Iris NEW in one of three; jobs
m3-max-64199, 64198). That measured B's depth, not the signal's path.
Now, as the consumer's writer and its waiter do, A's thread commits on B, right after each of
A's command buffers (its fills, then the signal at its tail), a waiter on that signal; the main
thread only lets it run as long as the first part's frames. Both parts also time A's GPU idle
before each of its command buffers, from the end of the one before (a_gap_p50, a_gap_p90;
wait_a_gap_p50, wait_a_gap_p90): where room arrives later than the GPU needs it, that idle
grows.
The authored compile census re-blessed. Its 290 differences against the old table are the texture-buffer work
landing since the last bless: 230 cells now compile (texture-buffer cases the translator and the runtime now
make), and 60 refusals changed their requirement lists (texture_buffer dropped where the case still refuses
for another requirement, ulong_texture_atomic among them). failed 0, regressions 0.
Verified: census job m3-max-64248 on the M3 at 80b54178df (2376 cases x 10 profiles = 23760 cells; compiles
18740, compiled 17689, refused 6071, failed 0, differences 290, regressions 0). No translator, AIR or
validation source changed between 80b54178df and this commit's parent 0b73ac76e5, so the table holds here.
The texture over a buffer in an image of its own that two queues read is made over a Shared buffer
too (a pitch a texel past its row, which no device's linear image lays): the Shared rules copy it in
for each submission's own commands, so B1, passing A3's group held, reads the buffer's bytes as A3
does. The setup helper makes either kind and prints which.
What: the known gap of NVIDIA's driver's execute cost says its figures ran on one card, an RTX
3090 (620.70.06), that the harness frame's microseconds are its own draws' and not a guest
frame's, and that on a Radeon RX 7900 XTX (RADV) a guest's frame of that shape at a held camera
pose took 4.305 ms of GPU time with its executions against 4.372 ms with the same draws direct,
the executions 1.5% under, so the driver's execute cost is measured on NVIDIA's driver alone.
Why: the gap's scope, as the planner ruled it: rung 4 for the driver's share, its shares kept as
the harness's microseconds (the driver's 539.0 of the 720.9 us gap; the splits about 117 to 128
and the empty parts about 54 to 65), and no percent of a guest frame, since the harness frame's
gap is larger than a guest frame's whole gap and the two do not map one to one.
Verified: README only; the harness figures are job m3-max-64194's (unchanged); the XTX figures
are the consumer's two walks at the held pose, jobs m3-max-64076 (executions) and m3-max-64084
(direct), each a separate run. Docs check: fmt and workspace Rustdoc -D warnings (job below).
two_queues takes whether A holds a group and how many command buffers it holds for room since
0a35c20f4b; the passing pair's A holds A3 in a group and A4 and A5 for room.
A texture over a Managed buffer's device copy in an image of its own owes a copy in at its making
and after submitted device work wrote the buffer (ManagedOvers). That copy was taken as a command
buffer that reads the texture was staged into its queue's group, and the copy rode the group. A
command buffer of another queue committed later could be sent before that group (it passes a
group held), find no copy owed and read the image before the copy ran: on an RTX 5080 B1 read
zeros where the buffer held its bytes (job m3-max-64193; before rule R too, at fbaa5bb777, job
m3-max-64213). Metal's contract: a command buffer committed after the bytes were named and
committed reads them.
Now the copy is taken as a group goes (WorkState::close), for each command buffer of it with
commands that keeps the texture: the device's one VkQueue runs submissions in the order they go,
so the first submission that reads the texture makes the copy, of whichever queue, and nothing
later owes one. Where nothing passes, the one copy is made as before.
Taking the copy at the send would let a capture of a didModifyRange over the texture, committed
between a reader's staging and its send, swallow the copy that reader still needs, as it already
did for a reader held for room: the capture copies the texture in only ahead of the command
buffers numbered at or after it. So the capture no longer clears the owed copy; it records its
commit number on the entry, and a reader numbered at or after it takes none (the capture's copy
runs ahead of it), while one numbered before it takes its own. Device work's later write clears
the number with the copy it owes again.
Two device tests behind the busy gate on one queue: R reads a texture over a Managed buffer in an
image of its own whose first copy in its making owes; the consumer then writes and names the
texture's last row, and C, committed after on the same queue, takes that capture and reads the
texture. R runs before the capture's copy in and must read the buffer's bytes outside the named row
(Metal leaves the named row undefined for it); C must read the new bytes. R is either in the
queue's group held or, behind four command buffers that join that group first, held for room.
The passing pair (two_queues) now prints and asserts A's submissions in flight and group held as B1
commits, and the shared setup (the Managed buffer, its capture and the texture over it) is one
helper that asserts and prints the texture's form.
Two device tests on qroom's two-queue kit: a texture over a Managed buffer in an image of its own
(a pitch a texel past its row, which no device's linear image lays), made once the buffer's named
bytes were captured, is read by A3 (in A's group held) or A4 (held for room), the first of queue
A's to read it, and by B1 of queue B, committed after and run before it. Both must read the buffer's
bytes. On a device with two copies the texture's first copy in is owed by its buffer's entry
(ManagedOvers); each test prints the form, the run order and what each reader read.
What: the known gaps of indirect command buffers gain the RTX 3090's measured costs of an
execution over a range a buffer holds: the driver's own execute cost (a new gap), the split's
cost (about 11 us of GPU time an execution) and a part with count 0 (about 10 us a part).
Why: an execution over a GPU-written range cost more GPU time a frame than the same draws direct
on an RTX 3090. Measured apart, three quarters of that is inside the driver's
vkCmdExecuteGeneratedCommandsEXT, which no form of ours changes (the workaround ladder's rung 4);
the rest is the split around the count kernel and the parts the count leaves empty.
Verified: a probe row (never lands, steelbrain/icbperf-probe 3ad97ab2bd on fbaa5bb777, compile
job m3-max-64187) times a frame of 11 executions over ranges a buffer holds in 6 passes
(buffers of 8,162, 785 and 289 commands, 2,132 commands in range) against the same draws direct,
on an RTX 3090 (NVIDIA 620.70.06, um870, Thunderbolt 3 link, validation layer off), job
m3-max-64194: 6 arms alternating over 9 rounds, each turn at least 300 ms (204 to 334 frames),
every turn at P0 with the SM at 1950 MHz and the memory at 9751 MHz, every image matching its
reference. GPU us a frame, medians of 9 turns: direct 386.0; the runtime's form 1106.9; one
part an execution 1041.7; counts written as the command buffer records, no split 978.9; both
925.0; explicit preprocess 263.9 + executes 592.9 (1080.4 in all). Counts a frame: 11
executions, 11 count kernel dispatches, 11 splits, 17 parts (6 with count 0), 25,305,344
preprocess bytes, against 2,132 draws direct.
Scheduled handlers run on the device's one submit thread, so every queue's later submissions
wait while one runs, held groups and command buffers held for room included. A handler that
blocks outside the runtime (the runtime's own waits are refused in it) until such a command
buffer completes therefore never returns, where Metal runs it on a thread of its own. The gap
predates the room rule (any group held behind full in-flight work); signals now waiting for room
widen what can be held, which is how the event-chain test's parked handler hung at 0a35c20f4b
(job m3-max-64168). The README said "the queue's later submissions"; it is every queue's.
Docs only.
The lavapipe rt suite at 0a35c20f4b (job m3-max-64168) hung two tests that held the old rule,
a signal always staged at once:
- The shared-event chain parks the submit thread in a scheduled handler after its links are
committed; its third link on one queue, behind two links of unknown run, now waits for room
and could not go while the thread was parked. Each queue's expected run is now set to 1 ms,
so each has room for its links, and the test's own claims (every link submitted and Scheduled
before the first runs, none held for a value, the links in order) hold as before.
- The three-deep signal test asserted that a held group never keeps back a signal. It now
asserts the rule: the signal waits for room with the group, Scheduled, its waiter on another
queue Committed, nothing more submitted before the busy work ends; then all three go and the
waiter ends after the signaller, held once for its value. Renamed for what it now shows.
A segment that signals an event sends its group at once, so a command buffer that signals
went to the VkQueue whenever no group was held, or when the group held would take it: a queue
whose every command buffer signals kept all of it on the VkQueue, and another queue's later
work could not pass it. The lavapipe run of the harness's two-queue row showed it: with each of
A's command buffers signalling, 0 held for room (job m3-max-64136).
Now a head that signals in any segment waits unstaged for room (WorkState::waits_for_room):
with no group held, until its queue has room for it; behind a group held, though the group
would take it. Its signal is staged only then, and as a waiter takes a staged signal as
submitted, a wait for it waits with it: no waiter is submitted ahead of its signal. Covered:
work then a signal at the tail (one segment), a wait at the head (no split: command.rs
Building::wait splits only a segment with commands or signals), and a signal after a wait that
follows work (a later segment). A partly staged command buffer's later signal still goes at
once: one command buffer at most. The fence's held-updater scan no longer needs the other queue
to hold a group, and the completion wake stays on while a queue's head is held for room.
Tests: A's every command buffer signals at its tail (work, then the signal), or after a wait
that follows its work; B1 runs after A1 and A2 as behind unsignalled work, A3 to A5 held for
room. The two_queues helper takes whether A holds a group and how many it holds for room.
Its order of A1 to A5 then B1 held on the base before the room rule (5ccd158e6d + the tests,
job m3-max-64094), where every signal went to the VkQueue at once; there only A's held count
failed. Its doc now says so, and names the two-queue and fence tests as the ones that carry the
rule's own order, so nobody reads it as that proof.
Comment only.
What: a public RefusalBasis (MetalDocumented, MetalMeasured, Ours, Device) and Error::basis, which
answers Refused, Limit and Unsupported from the variant's own basis, BelowFloor and
NoDirectDriverLoading as Device, and None for Translation, the platform's and Vulkan's failures and
the consumer's own block, stage or quiesce. Refusal::basis, Limit::basis and Gap::basis live in
crates/metal2vulkan-runtime/src/error/basis.rs, which scripts/refusal-surface/refusal_surface.py
writes from the `Basis:` line each variant's doc comment ends with: 131 arms (Refusal 82, Limit 17,
Gap 32), one per variant in declaration order, no `_` arm. The doc comment stays the one source.
Why: a consumer's census of the refusals its guests meet could only match names, so 67 refusals
whose basis is ours counted as "Metal refuses it". A typed basis tells them apart.
How: the script enumerates the enums structurally (rt_refusal_enums), reads each variant's pattern
(`Name`, `Name(..)`, `Name { .. }`) with enum_arms, and maps the basis value to the RefusalBasis
variant it names. It fails where the enum has no such variant (metal-takes and unknown have none:
the value comes with the first variant that needs it) and where a name is too long for rustfmt to
keep its arm's pattern on one line. It writes the file as `cargo fmt` leaves it (one line per arm,
else rustfmt's block form past 100 columns), so no rustfmt run is needed. `--check` fails where
basis.rs is stale, as for docs/REFUSALS.md, and one run regenerates both. `--selftest` gains three
cases: the arms and the block form, two Basis lines give two files, a missing value fails.
Verified: refusal_surface.py --check and --selftest, signatures.py --check and cargo fmt --check
pass on this tree. The generated forms were checked against rustfmt at five name widths and three
variant shapes. The compile job and the lavapipe rt suite are named in the lane report. Without
the change, the new tests do not build: RefusalBasis is unresolved and `basis` is not found.
Queue A keeps 8 command buffers uncompleted from a thread of its own, each sized by fills of a
256 MiB Private buffer to about 20 ms on the GPU (one fill's run, the least of three on a queue
of its own); queue B commits 60, one every 16.7 ms, each one 4 KiB fill. Unrelated, B's
commit-to-completed p50, p90 and most, and A's GPU run, are its times (b_p50, b_p90, b_max,
a_run). With each of A's signalling a shared event with its count and each of B's waiting first
for A's last committed, the GPU start of B's after its signaller's GPU end at p50 and p90
(wait_p50, wait_p90). Both parts print Metrics::held_for_room's growth. Every command buffer is
to complete and each waiter to end after its signaller, or the row fails; the harness's rt test
runs it on the cfg's device.
It measures the room rule's landing rows: B's wait behind A's work in flight, and that a waiter
on a signal held for room starts no later after its signaller.