No-copy buffers and host imports now cost the kernel and the encoding thread less, and their
deallocators run in the call Metal runs them in, including when a detach races a commit.
What changes:
- Idle pointer imports. A no-copy buffer's own pointer import is releasable, as its dma-buf
import was: while only blits read it and no pending command buffer holds it, the residency
thread releases it after its idle window (2 s, doubling at each import again up to 64 s), and the
next blit imports it again at the same pointer. Only where the new measured fact
DriverFact::PointerImportsFollowTheirAddress holds (ANV 26.2.4 on the Iris Xe; lavapipe 26.0.8
to 26.2.4): there a pointer import reads the pages mapped at its address at each submission, so
an import again reads what the kept one would. A refused re-import fails the blit's call, typed.
- Deallocator timing. A released import hands its keep-alive and deallocators to the objects a
command buffer still holds, so they run as that memory is freed (or parked and announced, as a
kept import's). A committed but unsubmitted command buffer holds a blit's import objects weakly,
so a rebind or detach before its first submission runs the deallocator in its call, as Metal
does. A detach racing a commit on another thread runs the deallocator in one of the two calls:
a let-go mark on the pages and the commit's hold count, both sequentially consistent, make each
side see the other, and a commit that sees the mark replays its own command buffer at once. The
live list re-reads a buffer's pages where a detach moved them meanwhile. HostDeallocatorDelayed
is no longer announced for these races.
- Fewer kernel queries. A no-copy buffer asks the kernel about its mappings (PROCMAP_QUERY) only
where it makes its own import; a rebind onto a live buffer's bytes lies in that buffer's import
and asks nothing; /proc/self/maps stays open for the queries (reopened in a forked process).
Three blit paths that read the caller's buffer as a read apart now read it as blits, so their
imports stay releasable.
- Fewer rewrites and lookups. A rebind or detach rewrites only the heap slots of textures over the
bytes it moved; host-page alias lookups visit only the length classes that hold ranges and keep
each range's overlapping ranges; a binding and a descriptor each read where a no-copy buffer lies
once.
- Counters (WorkCounts): host_imports_used and host_imports_read_apart (with its six reasons),
host_imports_kept_for_fds and kept imports by cause (of_heap, rebound, pointer, no_stand_in),
heap_slots_rewritten, host_mappings_queried (Linux; 0 elsewhere), host_range_lookups,
host_remaps_reported, host_remaps_over_imports, host_imports_remapped, host_pointer_imports_made
and _bytes_made, no_copy_lies_read, host_imports_rebound_unlisted, host_rebind_imports_made and
_covered.
- Docs: docs/HOWTO.md on both kinds of release, the RLIMIT_NOFILE soft limit a program raises
itself and the new gauges; a FAST-PATHS known gap that a buffer made before a remap reads the new
pages on drivers whose pointer imports follow their address, where Metal keeps the old ones
(HostMemory::new's contract forbids such a remap); the rustdoc of host_range_remapped.
Why: ANV over i915 lists every VkDeviceMemory in every execbuffer, and a pointer import costs about
0.19 us an execbuffer; the consumer's guest keeps hundreds of no-copy buffers live and uses few in
a frame. Its swap thread spent 1.54 ms of kernel time a frame querying mappings of a buffer that
joined a live import. And a released import's deallocator unmapped pages under a live userptr,
losing the device.
Verified:
- Iris Xe, a guest-shaped lane of 520 pointer imports and 43 command buffers a frame, the idle
ones released: objects per execbuffer 536 -> 51, ioctl 4.24-4.31 -> 0.85-1.09 ms a frame,
scheduler CPU 4.96-5.05 -> 1.33-1.74 ms a frame, frame p50 5.27-5.43 -> 2.70-3.11 ms.
- The fact, probed outside the runtime on the Iris Xe and through tests::pointer_residency on it
and lavapipe: a kept import read the pages a remap put at its address.
- The detach race on the Iris Xe and RTX 5080 under the validation layer: without the fix 3 of 3
runs failed (deallocators late or on another thread); with it 12 of 12 runs, 15,360 races, each
deallocator in the detach or the commit, never late.
- A second no-copy buffer over 2040 scattered mappings: 415-418 us -> 0.3-0.6 us. A rebind with
1024 other live textures: 4766 -> 49 us. Alias lookups: a draw -5.3% instructions on host-page
frames (RX 7900 XTX).
- Device and unit tests: freed_memory, pointer_residency, host_residency, blit_holds,
encoder_holds, host_import_counts, host_aliases (up to 45 passed per run); lanes rebinds,
rebind_reach, detach, detach_textures, host_memory, no_copy_heaps, dma_buf_imports, draw_work
(74 passed on lavapipe, 30 on the Iris Xe for the deallocator fixes). clippy -D warnings (plain,
m2v_gpu, m2v_cpu_icd) and rustdoc.
A command buffer's encoding, commit and property reads now make no call that waits for a
powered-down GPU or for the scheduler's submission, as Metal's return at once.
What changes:
- Upload arenas (argument, handle and root tables, constant blobs, neutral buffers, status words)
take host-cached, host-coherent system memory (MemoryClass::Shared) instead of write-combined
memory, which preferred device-local memory on a discrete GPU. Unified-memory devices are
unchanged; a device with no host-cached coherent memory keeps its device-local type. No flush is
needed: Vulkan defines coherent memory as needing none, and a submission orders the host's
earlier writes. New WorkCounts::upload_chunks_in_device_memory.
- The calibration pair that places GPU times on the host clock (vkGetCalibratedTimestampsKHR) is
read by the completion turn, not at commit. The placement and its pair cache are unchanged;
UncalibratedGpuTimes now says the calibration failed as the command buffer completed.
- A completed command buffer's settled spare pool begins one primary ahead on the completing
thread, with the spares' lock released and only where no thread waits on the command buffer's
gate, so the next command buffer's first encoder records into it instead of beginning one. The
pool passes between threads under the spares' lock, which is all vkBeginCommandBuffer's
external synchronization asks. WorkCounts primaries_begun_ahead and
encoder_primaries_begun_ahead.
- A timed command buffer's timestamp slot is reset on the host (vkResetQueryPool, a Vulkan 1.2
required feature the runtime enables) as it takes the slot, so no command buffer the GPU runs
resets a query; an adopted device keeps the command resets. WorkCounts
timestamp_slots_reset_on_host.
- kernelStartTime and kernelEndTime are two atomics beside the command buffer's state, and status
and error an atomic and a once-set error published at each transition, so a read waits for no
replay or submission and a commit takes no new lock. An Error status always finds its error.
- WorkCounts counts the command buffers begun by what they were begun for (encoders, segments,
continuations, secondaries, batch work and barriers, kept barriers, internal), printed by
frame_costs.
- docs/HOWTO.md notes NVIDIA's runtime D3 wake (about 1 s after about 15 s idle) and how a host
that wants none keeps the GPU powered; never required.
Why: on an RTX 5080 laptop GPU in runtime D3, the first write into device-local host-visible
memory after 20 s idle waited 977 ms for the wake, and so did the commit's timestamp read (a
commit took 973-977 ms; Metal's returns at once). On ANV a begin clears the command state, 8 to 20
us each, 0.80 ms of the Iris guest's 17 ms frame. And the scheduler holds the state lock through a
batch's replay and submission, so a status or kernel-time read waited 60-65 ms behind 131,072
fills.
Verified:
- RX 7900 XTX, release A/B: encoding-thread CPU 5.27 -> 4.79 ms a frame with cached uploads, the
vertex-heavy GPU time unchanged (28.18 -> 28.19 ms); draws_setting_bytes_write_no_device_local_memory
fails without the change on the XTX, RTX 3090 and RTX 5080.
- RTX 5080 laptop: a frame's commit after 20 s idle 973-977 ms -> 0.02-0.03 ms; the wake is now in
the wait, as Metal's commit-and-wait shows it. gpu_times and degrade_notices 27 passed on it and
on lavapipe. Host-reset slots saved about 1-2 us of GPU time a command buffer there; neutral on
the Iris Xe.
- Iris Xe: encoding-thread CPU 4.96 -> 4.62 ms a frame and a pass open 5.71 -> 2.77 us with
primaries begun ahead; 95.85 of 97 encoders a frame took one.
- runtime_lane::property_reads on the RX 7900 XTX and Radeon 780M fails without the change (reads
of 60.3-65.1 ms) and passes with it (longest read 0.022-0.097 ms); on the M3 Max under MoltenVK
it passed with 0 slow reads and the commit allocation bound held at 4.00. A new test checks
status reads Completed in the completed handler, after the wait and in a deallocator.
- Unit tests: spares, gate, exit_guard, gpu_time, completion, command_buffer (up to 218 passed
per run); clippy -D warnings (plain, m2v_gpu, m2v_cpu_icd) and rustdoc.
On Intel's ANV, CoreAnimation's A2Xghfc fragment shader (313k words) took
about 14 s to make cold, for each of three states. The consumer's x86 macOS
guest stalled with "no completion in 10 s" on its first boot. Native Metal
makes it in 0.48-0.56 s on the M3. brw (Mesa's Intel backend) spends that
time in its register allocator. Its interference build is quadratic in
instruction count, it spills, and it retries several scheduling modes. Most
of its input was our half arithmetic. Two cuts, each the cheaper form, are
taken on ANV and RADV.
1. A half result computed in float rounds through the device's conversion
pair under the float controls (QuantizeForm::Controlled). It replaces
OpQuantizeToF16 plus a denormal arm, about 11 NIR operations per lane.
- The form: an OpFConvert to 16 bits and back, each decorated
NoContraction, in an entry that declares RoundingModeRTE,
DenormPreserve and SignedZeroInfNanPreserve for 16 bits, plus the
modes the device's independence ties to them (ANV: RTE for 32 and 64
bits; RADV: RTE and DenormPreserve for 64 bits). The modes are
declared post-lowering (new ExecMode kinds), and the requirements
carry the FloatControl properties.
- Exact by the Vulkan spec under either HalfRoundingPolicy: conversions
are correctly rounded, and NoContraction forbids folding the pair. No
fact, no note.
- A new DriverWorkaround, HalfConversionPairFolded, keyed on NVIDIA's
proprietary driver, keeps NVIDIA on its previous forms. NVIDIA
615.71.09 on the RTX 3090 folds the pair even under NoContraction and
every mode combination, and the PackHalf2x16 and u16-bitcast forms
fold the same way: 2,231,288,832 of 2^32 narrowings unrounded. A
plain-Vulkan repro gives 16,775,680 of 2^24 unrounded on the 3090 and
0 on ANV.
2. A half read from its bits (a load, a reinterpretation, a texel's bits) is
the device's widening under NanMinMaxPolicy::Native, the default: each
u32 lane is bitcast to f16x2 and converted to 32 bits, in place of a
12-op integer decode. A half texel takes that conversion's NaN (no keep).
- Every non-NaN half is exact by the spec: DenormPreserve covers
"values obtained via unpacking an integer into a vector of values
with smaller bit width".
- A NaN's bits are the device's, recorded as NativeNanEncoding
(native-nan-encoding), now also announced on ANV and RADV pipelines
that decode halves. A half stored back unchanged keeps its bits.
- NanMinMaxPolicy::Exact keeps the integer decode and the keep. There,
every half widened to float answers Metal's 0x7fc00000 for a NaN, as
the M3 does over every pattern from memory, constant memory, selects
and texels.
Where brw's time went, measured on A2X (a2x-s96): after cut 1, 49.6k NIR
operations, of which the rounding pairs were about 10.7k, half decodes from
memory 8.6k and texel NaN keeps 2.6k. The rest was below 5% each.
Exactness probes:
- Cut 1 (candidate half(x) over all 2^32 f32, and half + - * over every
pair): 0 non-NaN mismatches on ANV Iris Xe (Mesa 26.2.4), RADV 780M
(Mesa 26.2.4), and the 780M and RX 7900 XTX (Mesa 26.0.8).
- Cut 2 (every half pattern): 0 non-NaN differences on ANV and RADV.
- The M3 confirms Metal equals the integer reference everywhere.
Cold making (A2X, base against each cut):
- ANV Iris Xe: 13.6-14.3 s, then 5.75-6.16 s, then 4.06-4.36 s. Peak RSS
1.28 GB, then 0.50, then 0.35. GPU time per draw 4.62 -> 4.48 ms.
- RADV 780M: 0.80-0.84 s, then 0.53-0.55 s, then 0.38-0.47 s. GPU time per
draw 4.05 -> 3.43 ms after cut 1, then within its clock states' spread.
In the consumer's cold boots on ms01 (Iris Xe), A2X went from 14 s per
state, plus two 38 s remakes, to 4.0-4.3 s. The suite's pipeline making went
from 126 s to 16.7 s, with no stall. Repeat boots show metalwin unaffected:
its frame rate follows other GPU work at session start, not this change.
Tests:
- engine_native_half: the controlled conversion, and a half read from memory
under both NaN settings, NaNs stored back.
- device::tests::profile::nvidia_carries_the_folded_half_conversion_pair.
- lower::arith::tests: narrow, round_texel, half_texel, texel_round.
- spirv::requirements; spirv::builder::ops.
- Updated expectations: engine_arith half rounding, engine_spirv_cross_forms
fma, engine_metal_routines frexp (the device's NaN under the default,
Metal's under Exact).
- The validation lanes driver_deviations and native_maths expect the
controlled form.
Docs: the FAST-PATHS half-rounding row (scope) and a new row for the
widening; the NativeHalfConversion and NativeNanEncoding entries in API.md and
their rustdoc; HalfRoundingPolicy and NanMinMaxPolicy rustdoc; HOWTO's driver
note; REFUSALS regenerated. A known gap is added to the texel-NaN row: on
ANV a 16-bit float NaN texel kept as half reads back 0xFE00 from ANV's image
decode, even under Exact (announced as device-nan-encoding). SEMANTICS_VERSION
1759, runtime pin recomputed, RUNTIME_VERSION unchanged.
Tables: the golden hashes, 274-389 cells on each ANV and RADV column across
both cuts, and NVIDIA's profile fingerprints, whose words are unchanged. The
authored compile census: artifact hashes on the 780M and RPL-P ANV columns,
with no status change. No MoltenVK, lavapipe or floor cell moves.
Verified on development-fast (batches f18-f24): every lane green on the RTX
3090, ANV Iris Xe, RX 7900 XTX, both 780Ms, lavapipe and the M3 Max, plus the
CPU suites, case qualification, clippy in every configuration, docs and
packaging. Not run on the RTX 5080 Laptop (host offline; whether its driver
keeps the pair is unmeasured).
One commit of the 247 on development-fast (720ef1ce9a..9f46fdf80d), squashed at the user's request.
Translator:
- Tessellation on a device without tessellationShader: Metal's tessellator emitted as SPIR-V, a
one-workgroup scan placing each patch's triangles in Metal's order, and the post-tessellation
function as a plain vertex stage (EmulatedTessellationDraws; SEMANTICS 1739, ARTIFACT_FORMAT 419).
- [[primitive_id]] on a device without geometry or tessellation shaders, as a flat varying the
vertex function writes; indexed lists, lines and points drawn de-indexed (RuntimeGap::PrimitiveIdIndices).
- Fragment functions of more colors than the device draws at once, compiled in color groups
(PrecisionNote::ColorAttachmentGroups).
- Object functions' threadgroup memory from the render encoder; a kernel's mesh draws from an
indirect command buffer; mesh payload sizing.
- The Vulkan 1.2 floor profile (vk12-floor) and the gates it needs; Metal 27.0.1 answers as the M3 Max.
- Overflow tests in the runtime-built modules by the product's high word (NVIDIA's compiler fails
the division form), guarded crate-wide by tests::owned_divisions.
Runtime:
- Color-group passes replayed per group over twin depth/stencil; snapshot and copy-back cost cuts.
- Command buffers finish on the queue waiter that saw them; the waiter holds no device handle, so
a program's drop after its wait is the device's last.
- Every object an encoder was handed held until its command buffer completes; deallocator order
and announcements.
- Driver defects recorded and announced: ANV counts a visibility sample once per color output
(visibility-count-per-color); MoltenVK fails pending work when memory that held a device-address
buffer is freed, so freed memory waits for the work in flight (host-deallocator-delayed).
- RenderCommandEncoder::set_object_threadgroup_memory_length; Visibility::counting().
Validation: mesh tooling (object, mesh and ICB-mesh cases on both executors), the authoring
census closed, the queue storm judged in Metal's unit, load-robust exits and indirect-census
bounds, and the golden hashes, printouts, fixture inventory and authored compile census blessed.
Docs: FAST-PATHS.md trimmed to a ledger of what is true now; API.md's catalogue and accepted
differences, REFUSALS.md and METAL-COVERAGE.md current.
Verified on development-fast before the squash: the full suites on the RTX 5080, RTX 3090,
RX 7900 XTX, Radeon 780M, Iris Xe, lavapipe and the M3 (MoltenVK and the Metal oracle), lint in
every configuration, rustdoc, doc tests, packaging and public case qualification; the timing and
teardown lanes x5 on every venue; the authoring-capability census 16656/16656 with 0 unresolved,
the vk12-floor translation census at 6139 translated with the slowest row 794 ms and peak 126 MiB.
The tree is development-fast's at 9f46fdf80d.
The padded-reads work packet (the owner's choice): a padded texture that is only read aliases the
buffer by default, under the same documented first-move gap as tight aliases, checked per driver;
the exact shadow stays behind PaddedReadsPolicy::Shadow, which exact_answers() selects.
What: a 2D texture (or array) over a buffer whose rows or slices lie with bytes between them, and
whose usage as Metal reports it holds no RenderTarget, ShaderWrite, ShaderAtomic or block writes
(Unknown reads as 0x17, so it stays a shadow; a swizzled texture reports ShaderRead |
PixelFormatView and reads), is now an image over the buffer's bytes at Metal's row pitch, as a
texture of packed rows is: the device's own linear image (PREINITIALIZED over ordinary memory, for
host allocations over a no-copy buffer), a DRM_FORMAT_MOD_LINEAR image at that pitch, or one over
a dma-buf of the pages. Its subresources may hold the bytes between its rows and its last row's
padding (to row_pitch x rows); a driver whose image reaches past that is refused as for packed rows
(lavapipe's height rounded up to 4). A render target or a texture a shader writes stays a shadow.
The rebind remakes the image under the same rule (AliasKind::Linear keeps it).
The switch: DevicePolicy.padded_reads, PaddedReadsPolicy::{Alias (default), Shadow};
DevicePolicy::exact_answers() selects Shadow, the runtime's shadow copied in before each use. It
is the runtime's alone: no ProfileFields carries it, so no profile fingerprint moves
(tests::fast_paths::the_runtime_s_padded_reads_choice_keys_no_profile) and SEMANTICS_VERSION
stays. The owner's ruling (relayed by reims-vgpu-orchestrator, 2026-10-14 15:55): "I'll take 1 &
2", (2) being this, "exact to the same standard as tight aliases", under 30c8b4bff8's first-move
known gap extended to the padding bytes, checked by the same per-driver lane check.
Why it is the same standard: the first move is the only layout transition a runtime image takes.
- Every image memory barrier the runtime records is a first move (texture/first_move.rs
FirstMove::barrier), a new image's own (storage_form.rs, host_copy.rs; never an alias), or a
caller-wrapped image's Transition (submit.rs via texture/wrapped.rs).
- The tracker's barriers are VkMemoryBarriers (tracker.rs Barrier::record), which transition no
layout.
- Blits into a texture copy in GENERAL: blit_texture.rs's vkCmdCopyBufferToImage and
vkCmdCopyImage. VUID-vkCmdCopyBufferToImage-dstImageLayout-01396 and
VUID-vkCmdCopyImage-dstImageLayout-01395 allow GENERAL; GENERAL "supports all types of device
access".
- "Each source region specified by pRegions is copied from the source buffer to the destination
region of the destination image". The Memory Model: "A memory operation must not affect memory
at a memory location not within its set of memory locations".
- Every descriptor names GENERAL (binding.rs, heap_sets.rs).
- A texture over a buffer has one level (linear_plan's MipmapLevelCount), so generate_mipmaps
leaves it, and optimize_contents_for_gpu_access records nothing.
- A texture without RenderTarget usage has no COLOR_ATTACHMENT usage. A pass renders it through a
stand-in, copied in GENERAL, so no load or store operation reaches its image.
How:
- linear_plan's padding() becomes holding(layout, usage, policy) -> Result<Holds, String>, with
Holds::{Texels, Padding}, Holds::fits (texels_alone, or the new padded_alone) and only_reads.
- aliases() takes the Holds. So do alias_image, dma_buf_alias_image (DmaBufTexels.alone),
host_alias_unbound, host_pitched_image, and the pointer and dma-buf rebinds.
- storage_over_buffer decides it once, from texture_usage (the effective usage), so the shadow's
reason no longer reads the raw descriptor's RenderTarget bit. The reason of a read-only texture
shadowed under the switch names PaddedReadsPolicy::Shadow.
- RUNTIME_VERSION 1211 (renumbered at compose); the runtime-sources pin is recomputed at this tree.
Docs:
- FAST-PATHS.md: a fast-defaults row (padded_reads = PaddedReadsPolicy::Alias/Shadow, ANV's 0.63
ms copy in per tile use and 135 vs 41 us making).
- FAST-PATHS.md: the padded-row shadow row now covers textures that render or that a shader
writes.
- FAST-PATHS.md: the first-move gap row now covers the bytes between rows, with the GENERAL anchors
in prose and the M3 Max probe's point (Metal never writes padding, even under concurrent CPU
writes).
- API.md's shadowed-texture entry, ShadowedTexture's rustdoc, HOWTO.md, interop.rs and dma_buf.rs.
- The refusal surface is unchanged (refusal_surface.py --check).
Verified so far:
- clippy -D warnings, all targets, all features, --cfg m2v_cpu_icd: clean (um780, Rust 1.98.1).
- cargo fmt --check: clean.
The unit and lane runs follow with the lane checks' commit.
Check per driver that a padded texture that only reads keeps every byte of its pages:
What: three lane tests in runtime_lane::pitched_surfaces, under PaddedReadsPolicy::Alias (the lane's
own devices take exact_answers, so Shadow), each over no-copy buffers of anonymous pages:
- a_texture_that_only_reads_keeps_every_byte_of_its_pages: a ShaderRead texture over each of the
11 layouts. Its first use is a fragment function's read through its image, before anything else
touches the pages: it must read the pages' texels, and every byte of the pages, the bytes between
the rows among them, must be unchanged. That is the image's first move, the known gap 30c8b4bff8
records, now over padding.
Then: a nearest and a linear sample, get_bytes and a blit out. The caller rewrites the texels and
the bytes between the rows; a sample and a read must give the new texels. Blits Metal makes into
any texture: a buffer's box at an odd origin, replace_region of a box, a private texture's box.
After each step every byte of the pages is compared (the blit-into-alias check the peer asked
for: a driver whose copy writes past its region fails, naming the bytes).
Prints PITCHED-READS, how many padded layouts aliased. Off MoltenVK at least one must, or no
first move over padded rows was checked.
- a_padded_texture_that_only_reads_copies_no_shadow_by_default: each padded layout under Alias and
under Shadow. Three nearest samples and a blit out read the texels. An aliased texture copies no
shadow (WorkCounts::shadow_copies unchanged), a shadow copies one in (more than 0). Under Shadow
it is never aliased off MoltenVK. Off MoltenVK at least one layout aliases under Alias.
- a_padded_texture_that_renders_or_writes_is_a_shadow_under_either_policy: the browser's tile with
RenderTarget | ShaderRead, ShaderRead | ShaderWrite and Unknown usage, under both policies, over
a no-copy buffer (shadow off MoltenVK) and an ordinary buffer (shadow everywhere).
surface() takes whether the device may alias the texture's padded rows; the existing callers pass
false and keep their assertion.
Why: the owner's standard for the read-only padded alias is the tight aliases', checked per driver
by the same first-use lane check. A driver that fails it gets a structural driver-defect entry
that keeps the shadow there.
Lane filter for the round: runtime_lane::pitched_surfaces.
Verified: clippy -D warnings with --cfg m2v_cpu_icd (um780). The device runs follow.
Check a padded texture that only reads over an ordinary buffer's rows too:
What: runtime_lane::pitched_surfaces::a_padded_texture_that_only_reads_over_an_ordinary_buffer_keeps_its_bytes,
over each padded layout of LAYOUTS in a Shared buffer (not host pages), under both policies.
- Under PaddedReadsPolicy::Alias the texture is the device's own linear image over the buffer's
memory (made PREINITIALIZED, linear_image), where the device lays one at the rows' pitch.
- Its first use, a fragment function's read through it, must read the buffer's texels and leave
every byte of the buffer as it was, the bytes between the rows included.
- A nearest sample must read the texels too; an aliased texture copies no shadow over the two.
- Under Shadow it is never aliased.
- It prints each layout's form (PITCHED-READS).
Why: the read-only padded alias also takes the runtime's own PREINITIALIZED linear image, a path the
no-copy lanes do not reach. Its first move keeps the contents by the spec (the old layout is the
current one); the move's reach over the padding is the same known gap, now checked here per driver.
Verified: to follow, with the GPU runs (lavapipe, ANV, RADV x2, NVIDIA x2).
Name the drivers whose first move keeps a padded texture's bytes:
docs/FAST-PATHS.md's first-move known gap now lists the drivers whose run showed the bytes kept.
That covers the bytes between the rows of each padded layout the driver aliases, and the ordinary
buffer's check joins the cited tests.
Verified: runtime_lane::pitched_surfaces passed 19 of 19 at 6d4508a65d's tree on each:
- lavapipe and ANV (Iris Xe RPL-P), Mesa 26.2.4;
- RADV: the Radeon 780M on Mesa 26.2.4, the RX 7900 XTX on 26.0.8;
- NVIDIA 615.71.09: RTX 3090 and RTX 5080 Laptop GPU.
Padded layouts that only read and were aliased by default: 8, 8, 2, 2, 4 and 4 of 8. None changed
a byte of the pages. MoltenVK was not run.
Name the padded-reads alias among the default's choices in the API guide and the runtime's guide:
What: docs/API.md's list of what DevicePolicy::UNTRUSTED holds gains the image over a padded
texture that only reads (PaddedReadsPolicy::Alias), its structural test (no RenderTarget,
ShaderWrite, ShaderAtomic or block writes in the usage), its known gap (the bytes between the
rows are kept as far as the driver's first move keeps them) and the switch exact_answers()
selects. The runtime README's sentence on textures over buffers now says when the runtime keeps
a copy: where linear images cannot hold Metal's layout, and over padded rows when the texture
renders or a shader writes it, or only reads under PaddedReadsPolicy::Shadow.
Why: both guides described the default without the runtime's new choice; the README's sentence
already missed the padded render-target shadow.
Verified: docs only. The degrade-catalogue tests read API.md's catalogue, which this does not
touch; no degrade code is named. The runtime-sources pin covers src/ alone, so it is unchanged.
Time a compositor's frame over padded textures that only read, under each PaddedReadsPolicy:
What: surface_texture_costs gains read_only_padded_costs, an ignored release-mode measurement
(SURFTEX-READS). Each frame makes, for each padded layout of LAYOUTS, a no-copy buffer over its
surface's anonymous pages and a ShaderRead-only texture over it, samples each into a private
target of the browser tile in one pass, commits and waits. It runs under PaddedReadsPolicy::Alias
and ::Shadow, a device each, interleaved over three rounds, and prints per policy and round the
textures' forms, the medians and 90th percentiles of a texture's making, the frame's encoding,
commit to completion and process CPU, and the shadow copies a frame. pitched_surfaces' reading
pipeline and sampler helpers become pub(super) for it.
Why: FAST-PATHS' padded-reads row quotes ANV's copy-in cost per use; this measures what the
default saves per frame against the exact switch on any device, with the forms shown so a device
that shadows anyway is not counted as a saving.
Verified: validation-only and ignored by default; it changes no product source, so the runtime
pin and versions are unchanged. Its build and clippy under --cfg m2v_gpu are checked on um780,
and its run is on ms01's ANV.
Print why a padded texture that only reads over an ordinary buffer is a shadow:
What: a_padded_texture_that_only_reads_over_an_ordinary_buffer_keeps_its_bytes appends the
shadowed-texture notice's reason to its PITCHED-READS line, as the pages' tests already do in
their PITCHED-SURFACE lines, instead of taking the notices unread.
Why: on ANV (Mesa 26.2.4, ms01) none of the 8 padded layouts aliased over an ordinary buffer
under PaddedReadsPolicy::Alias, while all 8 alias over no-copy pages; the run showed the form but
not the reason, so the cause could only be guessed. The print names it per device.
Verified: test-only; the run on ms01's ANV prints the reasons (in the follow-up timing window).
Clippy under --cfg m2v_gpu on um780.
Quote ANV's measured frame cost of the padded-reads shadow in its ledger row:
What: FAST-PATHS.md's padded_reads row now quotes what read_only_padded_costs measured on ms01's
ANV (Iris Xe, Mesa 26.2.4). A frame sampling four BGRA8Unorm tiles over no-copy pages
(1307x512 at 5248 and 5376-byte rows, 300x200 at 1216, 1913x96 at 7680) in one pass completes
about 0.36 ms later as shadows: the median of 15 interleaved Alias/Shadow pairs, 0.08 to 0.60 ms,
all 15 positive. It also takes about 56 us more encoding and 91 us more process CPU. A texture's
making costs the same either way, about 45 us.
Why: the row quoted a 0.63 ms copy in per use and 135 vs 41 us making. Those were relayed
figures, not this case's measurement. Here making costs the same, and sampling the linear image
over host pages gives back part of the copy's saving, so the frame saves less than the copies'
sum.
Verified: 5 runs of read_only_padded_costs (3 interleaved rounds of 100 frames after 10 warm,
each) on ms01, release, --cfg m2v_gpu --cfg m2v_system_alloc, under both ANV locks, taskset
0-11, load under 1, forms "aaaa" under Alias and "ssss" under Shadow, 4.00 shadow copies a frame.
A first run of 3 more pairs, taken right after another workload, swung from -2.2 to +0.57 ms,
and is not counted. tests::fast_paths passes with the edited row (5/5, um780).
Versions: RUNTIME_VERSION 1204 -> 1205. RUNTIME_VERSION moves: read-only padded textures alias by
default. crates/metal2vulkan-validation/runtime-sources.sha256 holds
edc97e709c2605eaa13ac8696ea119fb9b727243a276a679d0b3288ed5b760b3, the hash of this tree's runtime
inputs (runtime-pin.py, which reproduces build.rs's). Version numbers quoted above are the values
the work's branch built with. Each part's Verified lines name the tree it ran at.
The padded-texture work packet. A texture over a buffer whose image would hold bytes that are not
its texels is drawn through a shadow image with exact copies, since a render pass or a layout
transition may write those bytes. Then the shadow's cost is cut, exactly: no copies for a pass that
reaches no tile, a copy back bounded by the draws' scissors, and cost lines that show each part.
Shadow a texture over a buffer whose image would hold bytes that are not its texels:
A texture over a buffer is a linear (or DRM_FORMAT_MOD_LINEAR) image over the buffer's bytes only
where every byte of the image's subresources is one of its texels: its rows lie one after another
(or it has one), its slices likewise, and its last subresource ends at its texels' last byte or
before. Anything else is the shadow, whose copies address the buffer's texels alone. The Metal
texture over an MTLBuffer (MoltenVK) is exempt: every write through it is Metal's own.
Why: Vulkan lets a render pass's load and store operations "read and write back any memory
locations within the image subresource bound for that attachment" (renderpass.adoc, Load and
Store Operations), and VkSubresourceLayout's size "includes any extra memory that is required
based on rowPitch", so the bytes between padded rows lie inside the subresource. Metal leaves them
as the program writes them. No query promises otherwise, so no image may alias padded rows.
Bytes past every subresource stay allowed: Memory Aliasing bounds the bytes a write through an
image affects to "those overlapped by the image subresources that were written". Measured on
lavapipe (Mesa 26.2.4 llvmpipe, gem10) at the round's base: pitched_surfaces' 657x128/5312
RGBA16Float tile took lavapipe's own linear image (its pitch 660 texels rounded to 64 bytes is
the lane's 5312), and a clear-blend-store pass rewrote 13 padding bytes in 13 rows (row 3 byte
5265 0x7c -> 0x7e: texels 657..659 of its 4-texel blocks read and written back, signaling NaNs
quieted). The reliance predates 1cf79a9617 (own linear images whose pitch equals bytesPerRow,
the dma-buf explicit planes); 1cf79a9617 made it every padded surface on ANV and NVIDIA's wider
pitches.
How: linear_plan's padding() and texels_alone(), used by alias_image (before any image is made),
aliases() (now given the subresource's size), host_alias_unbound (the own linear image's fit and
the pitched image's), the dma-buf alias (before the pages' source is asked, counted as a
fallback; its plane's size checked for textures over buffers, not heaps') and the rebind (the
alias kind keeps the texels' layout). Importer::makes_modifier_images, a duplicate of
makes_dma_buf_images, is folded into it. RUNTIME_VERSION 1188.
Tests: the aliases unit test covers padded rows, slices apart, a one-row pitch, a subresource
past the texels and a whole-array report. pitched_surfaces checks the pages after every step
(now naming the changed bytes outside the texels), asserts padded rows are never aliased off
MoltenVK, adds a load-blend-DontCare step, packed layouts of 510 and 126 rows and of 200, and a
fragment function's writes over six layouts (shader read/write usage). no_copy_textures asserts
padded rows shadow off MoltenVK (it asserted ANV's pitched image); dma_buf_imports' 60-texel case
now shadows. Docs: API.md (the extension paragraph and the shadowed-texture entry),
ShadowedTexture's rustdoc, HOWTO.md section 6, Texture::vk_image, dma_buf.rs, and a known-gap
entry in FAST-PATHS.md with ANV's cost (making the browser tile ~135 us as a shadow vs ~41 us
as a pitched image, 1cf79a9617's numbers).
Verified on lavapipe (gem10, release, --cfg m2v_cpu_icd, LP_NUM_THREADS=1): runtime_lane's
pitched_surfaces, no_copy_textures, buffer_texture_blits, dma_buf_imports, linear_attachments,
buffer_textures, buffer_texture_order, buffer_texture_renders, dont_care_stores,
kept_buffer_bytes, rotated_textures, and tests::linear_plan / degradation: 137 of 140 passed;
a_half_float_tile passes (it failed at the base), every padded layout is shadowed, 300x200/1200
is a pitched image. The three failures: the runtime-sources pin (written here), and the two
packed odd-height layouts, 658x126/5264 (rows 126..127 past the texture rewritten) and
1308x510/5232 (SIGSEGV, rows 510..511 written past the mapping): a lavapipe defect of explicit
DRM_FORMAT_MOD_LINEAR planes, handled in the next part. GPU lanes (ANV, RADV, NVIDIA,
MoltenVK) not run yet.
Make no explicit-plane modifier image of an odd height where lavapipe renders rows past it:
RuntimeDriverDefect::ExplicitPlaneRowsPastHeight: a DRM_FORMAT_MOD_LINEAR image whose one plane
the caller lays out (VkImageDrmFormatModifierExplicitCreateInfoEXT) is rendered in blocks of 4
rows, its rows past its height up to a multiple of 4 written past its subresource and past its
memory requirements. On a driver with the defect (lavapipe, MESA_LLVMPIPE, every release until a
probe finds one clean) neither host_pitched_image nor the dma-buf image (textures over buffers
and heaps' textures alike) is made of a height that is no multiple of 4: the texture takes its
shadow, announced as shadowed-texture with the defect named. The trigger is structural (the
image's height); the driver's own linear images are untouched, as they report the rounded rows
in their subresource (the previous part's texels_alone then shadows them).
Why: a write past an image's own memory is a spec violation no query reveals. Measured on lavapipe
(Mesa 26.2.4, llvmpipe LLVM 23.1.1 256 bits, gem10, release, LP_NUM_THREADS=1) at the previous
commit, pitched_surfaces' packed odd-height layouts, each a pitched image (pitched host images 1):
658x126/5264 RGBA16Float, a load-blend-store pass rewrote 21 bytes of rows 126..127 past the
texture (signaling NaNs quieted); 1308x510/5232 BGRA8Unorm, the same pass wrote rows 510..511 past
the no-copy buffer's mapping and the process took SIGSEGV. lavapipe 26.0.8 is unprobed.
How: Device::explicit_plane_rows (dma_buf.rs), asked by host_pitched_image and
dma_buf_image_unbound after their format checks. The registry entry and its test, the variant's
rustdoc, ShadowedTexture's rustdoc and API.md's shadowed-texture entry. No refusal is added, so
docs/REFUSALS.md has no row for it (refusal_surface.py --check passes); the api_surface table
names the enum, not its variants. RUNTIME_VERSION 1189.
Verified: see the landing run (lavapipe, the pitched_surfaces odd-height layouts shadowed and
passing).
Record that an image over host-pointer pages keeps its bytes past its first move only by drivers:
A known gap in docs/FAST-PATHS.md, and a lane check that turns a driver that drops the bytes into
a visible failure. No behaviour changes (no RUNTIME_VERSION bump): whether every texture over
pointer-imported pages becomes a shadow is the owner's call.
The gap: an image of host allocations must start UNDEFINED (VUID-VkImageCreateInfo-pNext-01443),
and a transition from UNDEFINED "will cause the contents of the image's memory to be undefined"
(resources.adoc, VkImageLayout). Memory imported from a host pointer "shares ownership of the
memory between the host and the Vulkan implementation", with host access synchronized as for any
memory (memory.adoc, VkImportMemoryHostPointerInfoEXT), so the external-memory acquire from
VK_QUEUE_FAMILY_EXTERNAL/FOREIGN is not blessed for it. sync2's ignored-layout barrier keeps
contents but leaves the image UNDEFINED, invalid to use as GENERAL. Paths that rely on the drivers:
host_linear_image, host_pitched_image, and metal_alias_image (VkImportMetalTextureInfoEXT says
nothing of contents). Spec-backed: dma-buf images, acquired from VK_QUEUE_FAMILY_FOREIGN_EXT in
GENERAL (the external memory chapter's ownership transfer and its note that the UNDEFINED initial
layout is a placeholder), and the runtime's own linear images, made PREINITIALIZED.
The check: pitched_surfaces::a_texture_s_first_use_reads_the_bytes_it_was_made_over makes a
texture over each layout and reads it first through its image (a fragment function's read)
before anything else touches the pages: the read must be the pages' texels and the pages
unchanged.
Verified: see the landing run (lavapipe).
Expect a shadow wherever no linear image holds a texture's texels alone:
The runtime aliases a texture over an ordinary buffer with a linear image only
where the image's subresource holds the texture's texels and nothing else
(linear_plan::texels_alone): no padding between rows, the driver's row pitch
Metal's, and no subresource bytes past the last texel. The lanes' expectation
helper, buffer_texture_blits::linear_rows_differ, compared only the driver's
row pitch, so on lavapipe, whose linear 64x2 RGBA8Uint at a 256-byte pitch
reports a 1024-byte subresource (its height rounded up to 4 rows) while the
texels end at 512, resource_ids expected no shadow and failed with "announced
past []: [ShadowedTexture, UnnamedShadowedTexture]".
The helper now applies the same rule: rows with bytes between them, a
subresource offset other than 0, a row pitch other than the buffer's, or a
subresource size past (height - 1) * row + width * texel. It takes the texel
size, which every caller knows. The callers' expectations move the same way:
resource_ids' 64-texel rows (the size rule), buffer_texture_blits' 4x4
textures at 32-byte rows and the IOSurface planes at 9, 20 and 40 bytes, and
view_reinterpretation's rows 16 bytes past their texels (the padding rule,
which shadows them on every device).
Verified on gem10's lavapipe (Mesa 26.2.4, --cfg m2v_cpu_icd,
LP_NUM_THREADS=1, release): the focused filter over pitched_surfaces,
no_copy_textures, buffer_texture_blits, dma_buf_imports, linear_attachments,
buffer_textures, buffer_texture_order, buffer_texture_renders,
dont_care_stores, kept_buffer_bytes, rotated_textures, resource_ids,
view_reinterpretation and the runtime's linear_plan, degradation and
driver_defects tests: 186 of 187 pass, resource_ids'
a_buffer_under_a_texture_goes_at_its_release_whatever_keeps_the_image among
them; the one failure is the runtime-sources pin, which moves with this work (below).
Test-only: no runtime source changes.
Name the layout transitions as what may write a padded texture's padding:
A texture over a buffer whose rows (or slices) lie with bytes between them
is a shadow off MoltenVK, since an image over those rows would hold the
bytes between them in its subresource. The shadowed-texture notice gave one
reason for every such texture: Vulkan lets a render pass's load and store
operations write those bytes back. That cannot apply to a texture without
RenderTarget usage, which never becomes an attachment, and ms01's A/B saw
read-only padded textures shadowed under that reason.
For such a texture the basis is the layout-transition rule (the
Synchronization chapter's Image Layout Transitions): "Image layout
transitions may perform read and write accesses on all memory bound to the
image subresource range", and "If the old layout is
VK_IMAGE_LAYOUT_UNDEFINED, the contents of that range may be discarded".
Every image takes one transition before any use: its first move into
GENERAL, from UNDEFINED for imports (VUID-VkImageCreateInfo-pNext-01443)
or PREINITIALIZED for ordinary buffers. No descriptor or copy takes an image
in either layout, and host image copy's transition is a transition too. So
no transition-free path exists for a read-only linear image, and the shadow
stays. After the first move every runtime image rests in GENERAL, so no
later barrier transitions it; copies and shader accesses touch texels alone
(the Memory Model: "A memory operation must not affect memory at a memory
location not within its set of memory locations").
linear_plan::padding now takes whether the texture renders (RenderTarget
usage). Its reason names the layout transitions, its first move among them,
and for a render target also the render pass's load and store operations.
The doc comment quotes both texts. The ShadowedTexture rustdoc, docs/API.md's
catalogue entry, docs/HOWTO.md, docs/FAST-PATHS.md's known gap, and the
dma_buf.rs and linear_plan.rs module docs say the same.
Tests:
- tests::linear_plan::a_padded_texture_s_shadow_names_what_may_write_its_padding
checks both reasons' exact text.
- The lane test pitched_surfaces::a_padded_texture_s_shadow_names_what_may_write_its_padding
makes the browser's 1307x512/5248 tile over an ordinary buffer, which
shadows on every device, MoltenVK included. It runs a fresh device per
usage (ShaderRead; RenderTarget | ShaderRead) and checks the
shadowed-texture notice's reason.
RUNTIME_VERSION 1190 (fleet/round's 1189 + 1). The runtime-sources pin is
recomputed at this tree.
Verified on gem10's lavapipe (Mesa 26.2.4, llvmpipe LLVM 23.1.1,
--cfg m2v_cpu_icd, LP_NUM_THREADS=1, release). The focused filter
(pitched_surfaces, no_copy_textures, buffer_texture_blits, dma_buf_imports,
linear_attachments, buffer_textures, buffer_texture_order,
buffer_texture_renders, dont_care_stores, kept_buffer_bytes,
rotated_textures, resource_ids, view_reinterpretation, and the runtime's
linear_plan, degradation and driver_defects tests) ran 189 tests. 188
passed, both new tests among them, printing:
- ShaderRead: "its rows lie 5248 bytes apart, 5228 bytes of texels each: an
image over them holds the bytes between them, which Vulkan lets its layout
transitions read and write, its first move from the layout it is made in
among them"
- RenderTarget: "... which Vulkan lets its layout transitions read and
write, and a render pass's load and store operations write back"
The one failure was the runtime-sources pin before this commit set it
(860ca881...). Clippy with all features (no cfg) is clean.
Take the surface texture cost frame apart, per part and per texture:
surface_texture_costs measures a browser-like frame: five surface textures
over new no-copy buffers, each loaded and stored by a pass that draws
nothing, then each blitted into a private texture. On ANV, ms01 measured
commit-to-completion rising by about 2.8 ms a frame where four of them
became shadows. That number alone cannot say where the time goes: the
shadows' copies in and back, their making and release, or work beside them.
It also cannot say why the packed 1024x512/4096 tile, which stays the
driver's own linear image in both forms, took longer to make.
The new ignored measurement surface_texture_cost_parts (run by name, release,
as the others) runs the frame over anonymous pages in parts:
- Empty: the textures made and released around an empty command buffer.
- PassesStored: Load/Store passes, i.e. a shadow's copy in and copy back.
- PassesNotStored: Load/DontCare passes, a copy in only.
- PassesDrawn: Load passes that blend a rectangle and store, as a browser's
passes draw.
- Blits: the blits alone, which read a texture over a buffer as its bytes.
- Both: the original frame.
It runs over every layout, then over the packed layouts alone, so no shadow
is made beside them. Per set and part it prints (SURFTEX-PART): the forms;
each texture's making median and p90; the frame's release, encoding,
commit-to-completion and process CPU time; and the per-frame work counts.
frame() takes the part, and surface_texture_costs passes Part::Both, so its
own output is unchanged.
Test-only. It compiles at fleet/base as well (it names nothing newer), so the
same measurement runs on the earlier form. Checked with clippy --cfg m2v_gpu,
all targets and features, -D warnings, on gem10.
Copy no shadow in or back for an attachment a pass that reaches no tile loads:
A texture over a buffer whose image would hold bytes that are not its texels
is a shadow: an image of its own that encoders copy the texels into before
use and back after a write. A render pass copied its shadowed color
attachment in before the pass and back after it whenever it loaded and
stored it, even where the pass reached no tile: no draw call, or draw calls
that draw nothing (clear_reach::PassReach::Nothing). Such a pass changes no
texel:
- Metal loads and stores only the tiles a draw reaches (PassReach's EVs).
- Vulkan's load and store write back what they read: "Load operations only
update values within the defined render area", and store operations
alike.
So the copies moved a texture's every texel twice for nothing. On ANV,
surface_texture_costs' frame (whose passes draw nothing) paid that for four
padded surfaces since they became shadows.
attachment_shadows now takes no use of such an attachment: a color
attachment of a pass that reaches no tile, that loads it (Load, also a
DontCare load the pass loads), stores it Store or DontCare, resolves
nothing, and has no stand-in or planes, where the shadow is a plain image of
a buffer's bytes (ShadowTarget::Image, writes kept). No copy in, nothing
dirty, no copy back. Rotated, converted and image shadows keep their copies.
The pass still renders into the shadow image, whose attachment uses order it
as before. Every later use copies in again, since the shadow was never marked
current.
New public counter WorkCounts::shadow_copies: copies between a shadowed
texture's truth and its shadow that encoders planned (in, back, keep and
merge). It is counted where EncoderCore plans them and at each of the three
end-of-encoder finishes.
Lane test pitched_surfaces::a_pass_that_draws_nothing_copies_no_shadow: the
browser's 1307x512/5248 tile over an ordinary buffer (a shadow on every
device). Load/Store and Load/DontCare passes that draw nothing plan 0 copies
and leave every byte of the buffer. A pass that blends a rectangle plans 2
(in and back). Without this change, the expected counts for the two empty
passes are 2 and 1.
This shrinks surface_texture_costs' frame, whose passes draw nothing, not a
browser's, whose passes draw. surface_texture_cost_parts' PassesDrawn part
measures that apart.
RUNTIME_VERSION and the runtime-sources pin move with this work (below).
Verified on gem10's lavapipe (Mesa 26.2.4, --cfg m2v_cpu_icd,
LP_NUM_THREADS=1, release): the earlier focused filter plus the runtime's
shadow tests ran 200 tests, 199 passed, the new test among them. The one
failure was the pin. clippy -D warnings, all targets and features, is clean
with no cfg and with --cfg m2v_gpu.
Copy back only the texels inside a pass's draws' scissors:
A shadowed texture's copy back after a render pass moved every texel from
the shadow image to the buffer. On ANV that write-back is the shadow's cost:
ms01's surface_texture_cost_parts put a stored shadow at about 0.8 ms of
commit-to-completion a frame (1307x512 BGRA8). A pass that loads a color
attachment changes no texel outside its draws' scissors:
- "Samples with coordinates outside the scissor rectangle at the
corresponding ViewportIndex will have their coverage set to 0" (the
Fragment Operations chapter's Scissor Test).
- "Load operations only update values within the defined render area" and
"Store operations only update values within the defined render area" (the
Render Pass chapter), writing back what they read.
- Each Vulkan scissor is Metal's rectangle clipped to the pixels its viewport
overlaps (render_state.rs's implicit scissor), so Metal's draw writes no
pixel past it either.
The image's other texels are what the last copy in left, which the buffer
still holds, and a write of the bytes another way leaves the image stale, so
they need no copy back.
How:
- ShadowUse gains an area: where a command writes through the texture, where
it bounds that. render.rs passes the bounds of the pass's DrawnArea (its
draws' Vulkan scissors) for a pass whose draws reach tiles, unless a reach
clear runs before the pass, together with which color attachments the
encoder set to Load, read before the DontCare loads and reach clears change
any. attachment_shadows gives that area to a loaded color attachment with
no resolve, stand-in or planes that is the whole of a one-level, one-slice
texture.
- join and ShadowSync::after keep the rectangle bounding the writes since
the last copy back, or none where one does not bound them. copy_back puts
it on the ShadowCopy.
- record() cuts the one region of a ShadowTarget::Image without staging to
it, by part_of: the buffer offset moved to the rectangle's first texel at
the region's row length, clamped to the image. ShadowTarget::Image now
carries its texel size (none for a heap's depth or stencil shadow, which
takes no area).
- Copies in still move every texel.
New public counter WorkCounts::shadow_texels_copied_back: the texels copies
back of buffers' textures' images move.
Tests:
- tests::shadow::a_copy_back_covers_only_where_the_commands_wrote: areas
through ShadowSync and join.
- tests::shadow::a_part_of_a_region_starts_at_its_first_texel: the region
arithmetic, clamping, empty parts and tight rows.
- Lane pitched_surfaces::a_pass_copies_back_only_the_texels_its_scissors_reach:
the browser's 1307x512/5248 tile over an ordinary buffer (a shadow on every
device), blended under a 300x200 scissor, moves 60000 texels back. The
buffer then holds a private texture's blend inside the scissor and every
other byte as it was. Unscissored, the pass moves all 669184.
docs/FAST-PATHS.md's known gaps record the race the bound leaves: Metal
stores only the 32x32 tiles a primitive touches (reims-vgpu's padding probe,
M3 Max, macOS 27.0.1). A concurrent CPU write to an undrawn texel in an
untouched tile inside the scissors can be undone here, where Metal keeps it.
No copy reaches the bytes between rows.
The batch's version commit moves RUNTIME_VERSION; the runtime-sources pin follows it.
Verified on gem10's lavapipe (Mesa 26.2.4, --cfg m2v_cpu_icd,
LP_NUM_THREADS=1, release). The shadow lanes (the previous part's list,
plus scissors and capture_reach where they exist) and the runtime's shadow,
shadow_stencil, linear_plan, degradation and driver_defects tests ran 319
tests, and 318 passed, the three new ones among them. The one failure was
the runtime-sources pin. clippy -D warnings, all targets and features,
--cfg m2v_gpu, is clean.
Measure a scissored drawn pass and a shadow's copies alone:
Two additions to the surface texture cost measurements, both ignored and
run by name in release builds.
surface_texture_cost_parts gains PassesScissored: the drawn pass (Load, a
rectangle blended over the left half, Store) under a scissor of the left
half, as a browser's pass redrawing a damaged part of a tile draws. With the
previous part, its shadows copy back only the scissored half.
PassesDrawn's default scissor covers the whole tile, so its copy back moves
every texel.
shadow_copy_costs times each copy alone in its own command buffer, committed
and waited for, on the browser's 1307x512 BGRA8 tile at 5248-byte rows:
- a private texture made as a shadow is (render target and shader read) into
a no-copy buffer over anonymous pages: a copy back's way;
- the pages into the texture: a copy in's way;
- the texture into a private buffer and into a Shared buffer;
- a private buffer into the pages, and back.
It prints SURFTEX-COPY lines with commit-to-completion medians and p90s.
These tell the image's tiling (detiling) from the pages' memory (writes into
imported host memory) as the cause of ANV's copy back.
Test-only. clippy -D warnings with --cfg m2v_gpu, all targets and features,
is clean on gem10.
Print a frame's shadow copies and the texels its copies back move in the surface cost lines:
What: the surface texture cost lines' per-frame work counts (SURFTEX-COST, SURFTEX-PART) now
end with the shadow copies the encoders planned and the texels their copies back moved, both
per frame.
Why: a change to how a shadow's image is made or copied must leave the copies and the texels
they move as they were; the cost lines then show it beside the times, in the same run.
Verified: test-only; built and run with the measurements on Linux hosts in the next steps
(no build on the Mac).
Wrap the surface texture costs' SURFTEX-QUERY sentence at 100 columns:
The commit that added a frame's shadow copies to the cost lines left the module doc's
SURFTEX-QUERY sentence on one 154-column line; the tree wraps doc comments at 100. Doc only.
Verified: awk finds no line of the file over 100 columns but the ignored-tests sentence (110),
which predates that commit; cargo fmt --all leaves the tree unchanged.
Versions: RUNTIME_VERSION 1202 -> 1203. RUNTIME_VERSION moves: padded textures over buffers are
drawn through shadows, and the shadows' copies change.
crates/metal2vulkan-validation/runtime-sources.sha256 holds
52d6ce1648b67055d046e043e6d1cd126e0a8315d04a922261df93ad0a25f734, the hash of this tree's runtime
inputs (runtime-pin.py, which reproduces build.rs's). Version numbers quoted above are the values
the work's branch built with. Each part's Verified lines name the tree it ran at.
The Linux gate's work packet: CI's Linux steps now run in the gate's own container, and the failures
that run found are fixed: depth and stencil formats over a DRM_FORMAT_MOD_LINEAR image, test IR that
LLVM 21 rejects, and a frame-cost check that allocated.
Run every Linux step of ci.yml in the Linux gate's container:
What: scripts/linux-gate-ci gains the three steps ci.yml's Linux job runs and it did not:
"Clippy under each feature alone" (metal2vulkan with no feature and with serde, ash and cli each
alone; metal2vulkan-runtime; metal2vulkan-air with no feature and with serde), "Build the new
API's consumer reference" (scripts/api-docs) and "Package the published crates". Its "Test
metal2vulkan" step now tests the packages ci.yml's does (metal2vulkan, -air, -runtime and
-devtools), where it tested metal2vulkan alone. The steps run in ci.yml's order, each with the
container's build share.
Why: the script's header says every Linux run: step of ci.yml has one step here, and
docs/VALIDATION.md presents the container as ci.yml's Linux job; a change that broke only a
feature-alone build, the reference, packaging, or the AIR front end's, runtime's or dev tools'
tests passed the container and failed CI.
Verified: bash -n; the steps compared one by one with ci.yml at fd22785008. A full container run
of the script follows on msi-laptop.
Make no DRM_FORMAT_MOD_LINEAR image of a depth or stencil format:
What: Device::modifier_image_checks, which every DRM_FORMAT_MOD_LINEAR image the runtime makes
passes (host_pitched_image's at Metal's row pitch over host pages since 1cf79a9617, and
dma_buf_image's and dma_buf_natural_layout's over dma-buf pages since 11715e2a3f), refuses a
format with a depth or stencil component (FormatBlock::depth / ::stencil of the image's format).
Such a texture takes the shadow (`shadowed-texture`, naming why), as it already did on every driver
that lists no linear modifier for the format. RUNTIME_VERSION 1187; the runtime-sources pin moves
with it. docs/API.md (the dma-buf paragraph and the shadowed-texture notice), docs/HOWTO.md and
Degradation::ShadowedTexture's rustdoc say so.
Why: the runtime asks the layout of every such image of memory plane 0, and Vulkan has no valid
such query of a depth or stencil format. Vulkan 1.4.357's validusage.json: of a DRM format
modifier's tiling the aspect "must be VK_IMAGE_ASPECT_MEMORY_PLANE_i_BIT_EXT"
(VUID-vkGetImageSubresourceLayout-tiling-09433), of a format with a depth component it "must
contain VK_IMAGE_ASPECT_DEPTH_BIT" (-format-04462; stencil, -format-04463), and it "must only have
a single bit set" (-aspectMask-00997). lavapipe (Mesa 26.2.4) lists the linear modifier for
D16_UNORM, D32_SFLOAT and D32_SFLOAT_S8_UINT, so since 1cf79a9617 a depth or stencil texture over a
no-copy buffer's surface plane was made at Metal's row pitch and the validation layer reported
-format-04462/-04463, failing CI's CPU-ICD step:
runtime_lane::buffer_texture_blits::a_planar_surface_s_depth_or_stencil_texture_reads_and_stores_the_plane
and ..._s_passes_write_metal_s_elements_alone. The dma-buf paths had the same gap, reached only
where a driver refuses the host pointer and lists the modifier for such a format.
Test: runtime_lane::buffer_texture_blits::no_depth_or_stencil_texture_over_a_buffer_asks_for_a_modifier_image
makes each depth or stencil format's texture over a surface plane (ordinary and no-copy buffers,
read and render usage, rows 64 and 256 bytes apart) and checks that WorkCounts'
pitched_host_images, pitched_host_image_refusals and dma_buf_images do not move (each layout query
follows such an image), and that the validation layer reports nothing.
Verified on msi-laptop, lavapipe (llvmpipe, LLVM 23.1.1, 256 bits; Mesa 26.2.4, validation layer
1.4.357), --cfg m2v_cpu_icd, LP_NUM_THREADS=1, VK_DRIVER_FILES=lvp_icd.json: without the
modifier_image_checks change the new test fails ("NoCopy Depth16Unorm MTLTextureUsageShaderRead,
rows 64 bytes apart": (1, 0, 0) against (0, 0, 0)) beside the old one; with it, every test of
runtime_lane::{buffer_texture_blits, no_copy_textures, dma_buf_imports, surface_texture_costs,
pitched_surfaces} passes (47 of 49 selected) except
pitched_surfaces::a_half_float_tile_reads_writes_and_renders_as_metal, the known-open lavapipe
padding-bytes failure 1cf79a9617 names (fleet/fix-pitched owns it), and the runtime-sources pin,
which printed the hash written here.
Write the handle tests' sample coordinates as floats LLVM 21 reads:
What: tests::engine_handles' sampled-handle kernels (the 2D and 3D sample calls of
heap_gathers_and_nearest_samples_fetch_by_the_handle_s_class, heap_half_texels_convert_by_the_handle_s_class
and heap_linear_samples_are_emulated_by_the_handle_s_class) state their coordinates as the hex
of the floats they meant, 0x3FD3333340000000, 0x3FE3333340000000 and 0x3FDCCCCCC0000000, in place
of the decimals 0.3, 0.6 and 0.45.
Why: LLVM 21's llvm-as, which CI's Linux job (Ubuntu 26.04) assembles with, refuses a float
decimal that is not exactly a float ("floating point constant invalid for type"), so the three
tests failed there; LLVM 23 rounds it to the nearest float, which is the value the hex states
(checked on msi-laptop: `ret float 0.3` under llvm-as 23 and `ret float 0x3FD3333340000000` under
llvm-as 21 disassemble alike), so the modules are unchanged where they assembled before. These
were the only float or half decimals in crates/ that a float does not hold exactly (a scan of
every .rs and .ll).
Verified on msi-laptop with /opt/llvm-21.1.8 first on PATH and
METAL2VULKAN_TEST_REQUIRE_PINNED_LLVM=1, as CI runs: the three tests failed at fd22785008 and pass
here.
Check a stage table brought in place slot by slot, allocating nothing:
What: the debug builds' check in ArgumentTable::refresh_reading, that the table it brought in
place is the table the stage's function reads whole, is ArgumentTable::check_reading. It compares
slot by slot, with no table read whole made and nothing printed unless a slot differs: every
kept buffer, texture and sampler slot against the binding stage_table_reading would derive for it
(and the sampler as the address maps bind it), every slot that reading has against the kept
table, and the kept threadgroup lengths and acceleration structures against none. A sampler is
compared as it prints (same_as_printed: every field by `==`, the LOD clamps as bits or both NaN,
since `{:?}` tells -0.0 from 0.0 and prints every NaN alike). A slot that differs is named in the
panic. Builds without debug assertions compile none of it: their behaviour is unchanged, so
RUNTIME_VERSION stays; the runtime-sources pin moves.
Why: the check read the whole table again and compared the two as format!("{:?}") strings at
every draw, so a debug build's draw made several times the allocations of a release build's, and
CI's CPU-ICD step (a debug build) failed
runtime_lane::frame_costs::a_frame_s_draws_and_pass_ends_allocate_within_their_bounds at every
sha since its bound came: 86.60 allocations a draw on lavapipe against the bound's 27, where the
same build with CARGO_PROFILE_DEV_DEBUG_ASSERTIONS=false makes 24.62. With this, a debug build's
draw makes 35.93; the rest of the difference is LiveBind::shape's checks, which build whole bind
shapes and stay exact (the next part bounds a debug draw with them).
Tests: tests::argument_table::samplers_compare_as_they_print holds same_as_printed equal to
comparing the printed forms (opposite zero signs, NaNs of other sign and payload, a NaN against a
number, f32::MAX against infinity, and other fields); the_check_compares_every_field fails when
StageTable, BoundSampler or SamplerDescriptor gains a field, until the check compares it.
Verified on msi-laptop (Linux, debug, LLVM 21): clippy --workspace --all-targets --all-features
-D warnings clean; the two unit tests pass; on lavapipe (--cfg m2v_cpu_icd), the frame_costs
draws count 35.93 (86.60 before) and runtime_lane::{render_state, function_tables,
buffer_texture_blits}, whose draws run the check, pass (32 tests); the runtime-sources pin test
passes with the hash written here.
Bound a debug build's draw allocations by what its shape checks add:
What: runtime_lane::frame_costs::a_frame_s_draws_and_pass_ends_allocate_within_their_bounds holds
a build with debug assertions' draws to DRAW_ALLOCATIONS_DEBUG (38) and other builds' to
DRAW_ALLOCATIONS (27, unchanged). The new bound states what it holds: the draw path's
allocations and those of LiveBind::shape's two debug_assert!s, which build the state's whole bind
shape at each draw to compare the kept or the found one with it; measured 35.93 on lavapipe
(llvmpipe, LLVM 23.1.1, Mesa 26.2.4), where a build without debug assertions makes 24.62. The pass
end, pass open and commit bounds hold unchanged in both builds.
Why: CI's tests are debug builds, and its CPU-ICD step failed this test at every sha since the
bound came (86.60 allocations a draw; 35.93 since the previous part made the stage table's check
allocation-free). The shape checks stay exact: making them allocation-free would compare through
BindState::has_shape, the function the found-shape check exists to cross-check, and a reusable
shape would need new public API in the published crate. With a debug bound the CPU-ICD step keeps
holding the draw path in CI: a new allocation in it moves both counts alike, and the bound keeps
the release bound's slack (about 2.4 allocations).
Verified on msi-laptop, lavapipe, --cfg m2v_cpu_icd, debug, LP_NUM_THREADS=1, twice: the four
a_frame_s_ bound tests pass (draws 35.93 of 38, pass ends 38.63 of 40, opens 13.00 of 14, commits
5.00 of 6 and 17.08 / 17.24 of 20 on the other threads); the same tests with
CARGO_PROFILE_DEV_DEBUG_ASSERTIONS=false at fd22785008 gave 24.62, 38.63, 13.00 and 4.99; clippy
--workspace --all-targets --all-features under --cfg m2v_gpu is clean.
Versions: RUNTIME_VERSION 1186 -> 1195. RUNTIME_VERSION moves: a depth or stencil texture over a
buffer no longer gets a linear image. crates/metal2vulkan-validation/runtime-sources.sha256 holds
4a161b14058fa3e4c4b039726845c4bb221965a409dae3153e6232d213f22330, the hash of this tree's runtime
inputs (runtime-pin.py, which reproduces build.rs's). Version numbers quoted above are the values
the work's branch built with. Each part's Verified lines name the tree it ran at.
A shadow of a texture over a buffer starts as the buffer's memory lies, instead of zeros that the
copy-in then overwrites, and a format's linear-modifier features are asked of the driver once. A
no-copy texture is laid at Metal's row pitch as a linear image over the buffer wherever the driver
takes that explicit pitch, and a driver's refusal is remembered per exact image (up to 256). The
lanes check textures at a browser's padded row pitches and say which pitches each driver takes.
RUNTIME_VERSION 1186.
Gain: a surface texture's shadow on ANV 1048 -> 135 us, RADV 484 -> 90 us. With the pitched images,
every padded surface aliases on ANV with no shadow: a tile 1048 -> 41 us.
Verified on the original branches: the runtime lanes on RADV, ANV and NVIDIA. Known open:
pitched_surfaces::a_half_float_tile_reads_writes_and_renders_as_metal fails on lavapipe (a
clear-blend-store pass writes a few padding bytes past the row), as it did on the original branch.
This squashed commit was not re-tested on its own.
RADV imports host pointers through amdgpu userptr with ANONONLY, so it
refuses MAP_SHARED memfd pages (QEMU's memory-backend-memfd guest RAM and
views of it): every no-copy buffer, heap and rebind over them was refused,
and a macOS guest could not boot on AMD. NVIDIA imports the same pages.
What:
- The five no-copy entry points (new_buffer_with_bytes_no_copy, both
new_heap_with_bytes_no_copy calls, Buffer and Heap rebind_bytes_no_copy)
take a HostMemory; HostMemory::with_dma_buf adds a retained DmaBufSource.
- Where the pointer import is refused, and only there, on any device that
lists VK_KHR_external_memory_fd and VK_EXT_external_memory_dma_buf, the
runtime asks the source for dma-bufs of the window's pages (chunks cut at
the device's sparse granule, sized by the caller within udmabuf's default
limits) and binds one buffer over them: plain for one chunk, sparse for
several (vkQueueBindSparse signalling queue 0's timeline; later work waits
on it, no host wait). Every path that imported before is unchanged.
- Textures over such pages get a dedicated DRM_FORMAT_MOD_LINEAR image import
of their own pages where the driver takes the plane offset and row pitch
(multiples of 256 on RADV), with 64-bit modifier features; elsewhere, or on
a source error, the existing shadow path.
- The extensions are enabled outside the compile profile: no device's enable
set, fingerprint or ARTIFACT_FORMAT_VERSION changes. The translator crate is
unchanged.
- Imports free inside exit-guard sections; the source is never called with a
runtime lock held. WorkCounts gains dma_buf_imports, dma_buf_sparse_buffers,
dma_buf_images and dma_buf_image_fallbacks.
Verified:
- Product suites 4553/4553, validation suite 1289/1289, clippy in every
configuration, rustdoc -D warnings, scripts/api-docs.
- runtime_lane::dma_buf_imports and rebinds on RADV Mesa 26.2.4 (validation
layer clean), the RTX 3090 and lavapipe (pointer imported, source never
called), and dma_buf_imports on RADV Mesa 26.0.8.
- reims-vgpu on the Radeon 780M (RADV 26.0.8, udmabuf at its defaults): a
macOS 26 guest cold-boots to the desktop and runs Safari; 5,119 dma-buf
requests, none refused.
- 64 MiB on RADV 26.2.4, release: pointer import 187 us; one chunk 665 us;
16 chunks 16.9 ms, about half of it the refused pointer attempt. The old
host-fence bind waited 1.26 s behind queue-0 work on RADV 26.0.8.
Rolls up everything since 43c46ac8 into a single commit. Its tree is
identical to the tree of private master at
b3c77f2d2b20a432be10591a2129547c10b1c24b.
- A Cargo workspace of five crates under crates/: metal2vulkan (the
translator and the metal2vulkan command), metal2vulkan-runtime (the
Metal API on Vulkan), metal2vulkan-air (the AIR front end),
metal2vulkan-validation and metal2vulkan-devtools.
- Dual license: GPL-2.0-or-later OR LGPL-3.0-or-later.
- docs/: API, architecture, fast paths, how-to, Metal coverage,
refusals, runtime porting and validation guides.
Private-Commit: b3c77f2d2b20a432be10591a2129547c10b1c24b
Rolls up everything since 9e0e99a4 into a single commit:
- src/native, src/passes, src/reflect, src/meta: AIR intrinsic lowering,
access-chain and pointer handling, constant/composite dedup, storage
and descriptor-slot fixes, function-constant folding.
- validation/: Metal and MoltenVK oracles, triage, observation contract,
and the case runner.
- validation/corpus and fixtures: new authored cases and re-recorded
candidate observations at the shipping fingerprint.
- tests/: module-level oracles for reflection, NonWritable, gated
varyings/system values/descriptor slots, loop budget, and fallback.
Squash 147 commits (2026-08-20 through 2026-08-31) into one change on top
of the exact-kernel-grid work. Covers native lowering and pointer/layout
construction, AIR intrinsic and funnel-shift coverage, BDA address
preservation across aggregate calls, CFG structurization, function-constant
and visible-function specialization, the 30-second translation ceiling, the
authored-case corpus and linkage validation suite, and refreshed byte-exact
MoltenVK evidence.
The kernel-grid lowering in this tree supersedes the 324-line variant in
the parent commit; that file is reduced to its current 139-line form here.
Resulting tree is identical to 7174c7b. Prior history remains reachable at
tag pre-squash-backup and branch backup/pre-squash-7174c7b.
Claude-Session: https://claude.ai/code/session_01D1u4vU7Mr5QNWrnnRHC8iS
Model kernel dispatch geometry as a typed contract shared by lowering, reflection, validation, and the CLI. Cull surplus dispatchThreads invocations using fixed or reflected push-constant grid bounds, make that safe dynamic-grid path the default, and require an explicit whole-workgroup assertion to omit it.
Reject unsafe source-barrier kernels before every product emission facade by following the selected AIR entry graph, including quoted LLVM symbols. Exercise the same default contract in authored candidate validation and document the host ABI.
Keep corpus audit parent concurrency bounded by feeding isolated translation workers from scratch-backed stdin files instead of creating one feeder thread per row. This removes the scoped-thread exhaustion that aborted late full censuses while retaining child decoding inside the time and memory watchdog.
Verified with format checking, warnings-denied workspace clippy and Rustdoc, validation tests at concurrency 16, the unchanged downstream repro, a forced 88,819-row audit completing in one invocation at jobs 16, failure retries, and a zero-read warm pass.
Distinguish image descriptors from texel buffers, scope synthesized binding occupancy by descriptor set, and decouple the Metal texture source limit from configurable descriptor ranges. Centralize retry finalization and runtime sampler projection so layout and specialization contracts cannot drift across paths. Refresh consumer documentation and add adversarial descriptor tests.
Thread a versioned, validated descriptor layout through emission, reflection, synthesized resources, retry-created address tables, and Vulkan validation. Preserve the existing ABI as the explicit default and cover cross-stage separation, static samplers, embedded textures, raw aliases, invalid ranges, and default byte identity.
Route writable argument-buffer textures, including fixed descriptor arrays, through the runtime storage-image format and capability contract. Reflect their applied state by synthetic resource index and teach authored validation to resolve structural owner/offset identities through reflection before candidate translation. Bump reflection and executor fingerprints so stale outputs are not reused.\n\nVerified with cargo fmt, warnings-denied workspace clippy and Rustdoc, 1364 serial product tests, and 144 serial validation tests.
Accept runtime storage surface formats and host feature facts by Metal texture index, specialize image types before interface creation, and reflect the exact explicit or formatless contract. Track runtime origins through arrays and image aliases so every read, write, imageblock write, emulated fetch, and atomic operation checks the required capability or refuses honestly.\n\nWire authored validation resources into the same product options, bump the reflection and candidate executor contracts, document consumer use, and cover type splitting, dependent loads, exact formatless capabilities, atomics, incompatibility, missing bindings, imageblock writes, and pixel-gather storage reads.\n\nVerified with workspace clippy -D warnings, warnings-denied all-features Rustdoc, serial product and validation suites, both packaged AIR reproductions plus spirv-val Vulkan 1.3, and release measurements under 0.5 seconds / 23 MiB RSS.
Propagate exact sampler state through bounded sampler-typed SSA aliases and mark mixed joins ambiguous. Refuse pointer-selected runtime samplers instead of silently substituting the default sampler and returning to native sampling.\n\nAdd a selected-sampler regression and clarify the consumer contract.
Overhaul the validation workflow around sharded authored cases, dependency-exact observations, incremental indexed corpus audits, bounded parallel translation, and native Metal/Vulkan comparison.\n\nExpand native AIR lowering, reflection, linked-function specialization, resource and stage-interface support, and structural CFG/pointer repair across the harvested macOS 26 corpus. Add exact intrinsic inventory, distributed 16x16x16 matrix lowering, explicit opaque tensor linkage, and regression coverage for the newly supported feature classes.\n\nThe final corpus verification accounts for all 88,819 indexed AIR modules under the current product fingerprint: 65,355 translate and validate directly, 23,464 require exact authored linkage, and zero fail or remain unresolved.