Files
metal2vulkan/docs/HOWTO.md
T
Anees Iqbal dd5a19aea1 Alias a padded texture that only reads by default, the shadow behind PaddedReadsPolicy::Shadow
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.
2026-10-14 20:17:40 +03:00

237 lines
15 KiB
Markdown

# Integrating metal2vulkan
The checklist around the library: the tools each piece needs, caching, failures, isolating a
compile, host memory a driver refuses, and checking an integration. The API itself is
[API.md](API.md); the runtime's is [its README](../crates/metal2vulkan-runtime/README.md).
## 1. Tools
The libraries read AIR bitcode (a metallib, a bitcode wrapper or a raw module) and run no external
tool. The command line (feature `cli`) runs two, both optional:
- `llvm-as` (LLVM 21 or newer) to assemble an LLVM text input (`.ll`). Not needed for a metallib
or bitcode.
- `spirv-val` (SPIRV-Tools) to check each module it writes. When it is missing the tool says so and
still writes the modules, which the library has verified itself.
Put them on `PATH`, or name each one:
```sh
export METAL2VULKAN_LLVM_AS=/path/to/llvm-as
export METAL2VULKAN_SPIRV_VAL=/path/to/spirv-val
```
The runtime opens the Vulkan loader when it makes a device (or takes the consumer's
`vkGetInstanceProcAddr` when it adopts one). Nothing links against Vulkan at build time.
## 2. Compile
From the command line, see the [README](../README.md#command-line). From Rust, [API.md](API.md)
walks the flow in the order a consumer meets it:
1. [A device](API.md#1-a-device): describe the Vulkan device as created and choose a policy.
2. [A library](API.md#2-a-library): parse a metallib or AIR bitcode.
3. [A compute pipeline](API.md#3-a-compute-pipeline) or
[a render pipeline](API.md#4-a-render-pipeline), under a `Budget`.
4. [The interface and the plan](API.md#5-the-interface-and-the-plan): the layout, what each slot
binds, what a dispatch or draw needs.
5. [At bind time](API.md#6-at-bind-time): descriptor writes and push-constant bytes from what is
bound.
Every `air.simd_*` operation keeps Metal's 32-lane simdgroup; there is no option to use the
driver's subgroup width instead.
To read AIR without translating it (list a metallib's functions, decode a module into typed IR,
read its entry points' bindings, canonicalize an entry under function-constant values), depend on
[`metal2vulkan-air`](../crates/metal2vulkan-air). Use the same version as `metal2vulkan`, which
pins it exactly; the translator's input errors are that crate's types.
## 3. Cache
The translator keeps no cache; it gives you keys and encodings to keep one
([API.md section 7](API.md#7-caching)):
- A key is a SHA-256 of the inputs, `cache::SEMANTICS_VERSION` and the device's profile
fingerprint, known before compiling.
- A decode checks the format and semantics versions, the key, the profile fingerprint and a
checksum. Every `ArtifactError` is a cache miss: compile again and replace the entry.
- The versions move independently: the crate's (the API), `SEMANTICS_VERSION` (the output; a bump
misses every cached artifact), `ARTIFACT_FORMAT_VERSION` (the encoding) and `RUNTIME_VERSION`
(what the runtime does with an unchanged artifact).
### The runtime's shader cache
The runtime keeps every shader it translates on disk, as Metal programs get from the OS, so a
second process does not translate it again. It cannot be turned off.
- **Where.** By default `~/Library/Caches/metal2vulkan` on macOS, `$XDG_CACHE_HOME/metal2vulkan`
elsewhere, or `~/.cache/metal2vulkan` when `XDG_CACHE_HOME` is unset. `ShaderCacheOptions`
(in `DeviceOptions`, or `RawDevice` for an adopted device) names another directory. Several
processes and builds may share it; each build reads only its own translations.
- **How much.** At most `capacity` bytes on disk (25 GiB by default), least recently used first;
another build's entries go after 30 days unused. In memory, at most `memory_capacity` bytes
(256 MiB by default): a pipeline state made again takes its translation from there without
reading the disk.
- **The driver's pipeline cache.** Each pipeline is made with a `VkPipelineCache` of its own,
seeded from a record named by what the making reads (its SPIR-V, layout and state, and the
driver's identity) and written back only when the making added to it. After an update of
metal2vulkan, a pipeline whose SPIR-V and state did not change is made from its record; a driver
update starts empty. On drivers that report `pipelineBinaryInternalCacheControl` (NVIDIA's), a
device the runtime makes turns the driver's own internal cache off; an adopted device keeps what
its creator chose.
- **When it fills or a write fails.** Each device says so once, through its `MessageSink` (or on
stderr) as a `Warning` whose `id_name` is `metal2vulkan-shader-cache-evicted` or
`metal2vulkan-shader-cache-write-failed`. Match on `id_name`, never on the text. Later events are
counted in `Device::shader_cache_statistics`.
- **Failures.** Making or adopting a device fails with `Error::ShaderCache` when the directory
cannot be made or written. After that, a failed read or write only costs a translation.
- **Cold runs.** To measure with nothing cached, give the device an empty directory, and turn the
driver's own shader cache off (`__GL_SHADER_DISK_CACHE=0` for NVIDIA,
`MESA_SHADER_CACHE_DISABLE=true` for Mesa). Give each test its own directory.
- **It is a cache.** Deleting the directory, or any file in it, is always safe.
## 4. Handle failures
Every failure is a typed value; match variants, never messages
([API.md section 8](API.md#8-refusals-requested-inputs-and-precision)).
- A refusal names what would change the answer: the feature the device lacks, the pipeline input
the compile needs, or a limit.
- A deadline or a cancellation (`Error::Budget`, `Error::Cancelled`) is transient: retry later.
Every other error is the answer for that input and device and may be cached as one
(`error.retry()`, `error.is_permanent_for()`).
- Never use a module from a compile that returned an error.
- The command line prints `metal2vulkan: FALLBACK (<why>)`, exits 2, and writes a repro bundle
(the input, the profile, `repro.sh`, `failure.txt`) under `$TMPDIR/metal2vulkan-repros`, or
`METAL2VULKAN_REPRO_DIR`.
## 5. Bound a compile
Every compile runs in-process under the caller's `Budget`: a wall deadline (`Budget::standard()`
is 20 seconds), a `CancelToken` any thread may trigger, a deterministic work-unit cap and a byte
ledger charged before each input-sized allocation. A panic inside a compile becomes
`Error::Internal`. That is enough for a consumer that trusts its process.
When an abort, a stack overflow or a failed allocation in the compiler must not take the consumer
down, or a hard memory ceiling must hold, compile in a child process:
1. Spawn one worker per compile in its own process group, with the input in a file and the result
written to a file. Send the library bytes, the entry and descriptor, and the device description
and policy (with feature `serde` they serialize; equal description and policy give the same
profile fingerprint and keys).
2. In the child, install a counting global allocator that refuses allocations above a budget, build
the `Device`, and compile with the same `Budget`.
3. In the parent, poll the deadline, cancellation and the process group's resident memory. On a
breach, kill the whole group and remove its scratch files. A result that arrives late is a
timeout.
4. Load the result with `PipelineArtifact::from_bytes` against the parent's own `Device`, and check
that its key is the one the parent computed (`Device::compute_pipeline_key`,
`render_pipeline_key`).
5. Classify as in-process: a typed error is the answer; a deadline, cancellation or killed child is
transient.
The validation crate's worker (`crates/metal2vulkan-validation/src/worker/`) implements this,
under 20 seconds and 500 MiB per attempt.
## 6. Host memory a driver refuses
`Device::new_buffer_with_bytes_no_copy`, `new_heap_with_bytes_no_copy` and the
`rebind_bytes_no_copy` calls import the caller's pages by their pointer
(`VK_EXT_external_memory_host`). Some drivers refuse the pointer of shared memory: RADV (AMD on
Linux) imports a pointer through amdgpu's userptr, which takes anonymous pages only, so it refuses
`MAP_SHARED` mappings of a `memfd`, a shared memory object or any file (QEMU's
`memory-backend-memfd,share=on` guest RAM among them) with `Unsupported`, `HostMemory`. NVIDIA and
lavapipe import the same memory.
A consumer whose memory is such a mapping passes `HostMemory::with_dma_buf(pointer, source)` instead
of `HostMemory::new(pointer)`. The runtime still imports the pointer first, exactly as without a
source, and calls the source only where the device refuses it: for dma-bufs of the pages the range
touches, and again once for each texture's image over its own pages in them. The rustdoc of
`HostMemory::with_dma_buf`, `DmaBufSource` and `DmaBufRequest` is the contract: when the source is
called, the chunks it answers, and what is refused. In short, answer each `DmaBufRequest` with
dma-bufs of exactly the pages asked for, in order, split only at multiples of its `granule`. Where
the granule is less than the length (64 KiB on RADV of Mesa 26.2.4, 4 KiB on 26.0.8), several
chunks are bound to one sparse buffer and must total the length rounded up to the granule: pad the
last with a scratch page of your own, repeated. A texture's request takes one chunk, of the same
file pieces the buffer's chunks hold there.
On Linux, `udmabuf` makes such a dma-buf of the file pieces behind the pages: open `/dev/udmabuf`
(the process needs read and write access to it) and issue `UDMABUF_CREATE_LIST` with one item per
run of contiguous file pages; the `memfd` must be sealed against shrinking (`F_SEAL_SHRINK`, as QEMU
seals it) and not against writing. The consumer knows the pieces behind every byte; the runtime runs
no udmabuf code. Each udmabuf takes at most `list_limit` items and `size_limit_mb` MiB (the module's
parameters under `/sys/module/udmabuf/parameters`, 1024 and 64 by default). Keep each chunk within
the host's limits as they are: read them, never assume them raised. Scattered memory needs many
items: a macOS desktop guest of 14 GiB was measured importing up to 63.3 MiB in one object, in up to
16,201 separate 4 KiB runs, with 19 to 29 of its imports past 1024 runs; at a 64 KiB granule such an
object takes 16 chunks.
A texture over such memory is an image over a dma-buf of its own pages where the device also lists
`VK_EXT_image_drm_format_modifier` and `VK_EXT_queue_family_foreign` (RADV does). RADV (Mesa 26.2.4
and 26.0.8) lays such an image's plane only at an offset in its page that is a multiple of 256
bytes, with rows a multiple of 256 bytes apart: keep a texture's offset and `bytes_per_row` so (a
4 KiB-aligned surface with 256-byte-aligned rows always is), with no byte between its rows (below).
Elsewhere the texture takes a shadow of the bytes, announced (`shadowed-texture`, naming why), and a
rebind that cannot make the image again is refused (`NotImplemented(RebindTextures)`).
`WorkCounts::dma_buf_imports`, `dma_buf_sparse_buffers`, `dma_buf_images` and
`dma_buf_image_fallbacks` count what the route did.
A texture over a buffer's bytes is an image over them where its rows lie one after another
(`bytes_per_row` is its texels' bytes, or it has one row; an array's slices likewise) and the
image holds no byte past its texels. A texture whose rows lie with bytes between them, as a guest
browser's padded surfaces' do, is one only where it only reads (no `RenderTarget`, `ShaderWrite`,
`ShaderAtomic` or block-write usage; `Unknown` usage counts as all of them), under the default
`padded_reads = PaddedReadsPolicy::Alias`; otherwise it is a shadow (`shadowed-texture`) on every
device but MoltenVK, whose image is a Metal texture over the buffer. An image at that pitch holds
the bytes between the rows in its subresource (`VkSubresourceLayout`: "size includes any extra
memory that is required based on rowPitch"), and Vulkan lets two kinds of operation write them,
where Metal leaves them as the program writes them. The image's layout transitions "may perform
read and write accesses on all memory bound to the image subresource range", and every image takes
one, its first move from the layout it is made in, before any use; the runtime's images take no
other. A render pass's load and store operations "read and write back any memory locations within
the image subresource bound for that attachment" (lavapipe writes back the bytes its 4-texel blocks
reach past a row, a signaling NaN's bits quieted). No query of the device's states otherwise. So a
texture that renders or that a shader writes is a shadow, and one that only reads keeps the bytes
between its rows as far as the driver's first move does (docs/FAST-PATHS.md's known gap, checked
per driver by the validation lane); `padded_reads = PaddedReadsPolicy::Shadow`, which
`DevicePolicy::exact_answers()` selects, makes it a shadow too. To keep a surface that renders
aliased, lay its rows packed.
Over pages imported by their pointer, such a texture aliases them where the device lays an image's
rows at the texture's `bytes_per_row`: the driver's own linear image, or, where that lays its rows
otherwise, a `DRM_FORMAT_MOD_LINEAR` image at that pitch, which the driver may refuse (and which
the runtime makes of no depth or stencil format, as it makes no image over a dma-buf of one: Vulkan
has no query of where such a format's memory plane lies). Measured
(`runtime_lane::surface_texture_costs::pitch_classes`, nine formats, four usages, rows padded by
each power of two from 16 to 4096 bytes):
- ANV (Mesa 26.2.4) packs its own rows tight and takes every pitch asked.
- NVIDIA (615.71.09) aligns its own rows to 128 bytes and takes any larger pitch for a texture it
samples or writes, in `BGRA8Unorm`, `RGBA8Unorm`, `RGB10A2Unorm`, `RGBA16Float`, `R8Unorm` and
`RG8Unorm`; not for a render target, and not in `R16Float`, `R32Float` or `RGBA32Float`, whose
`DRM_FORMAT_MOD_LINEAR` tiling it gives no sampling or transfers.
- RADV (Mesa 26.2.4) aligns its own rows to 256 bytes, refuses a pitch that is not a multiple of
256, and asks a dedicated allocation of an image at any other, so it takes no pitch but its own.
The own rows' alignments are as measured for `BGRA8Unorm`. Elsewhere the texture is a shadow
(`shadowed-texture`): a `BGRA8Unorm` surface with packed rows takes the driver's own linear image
on RADV where its texels' bytes are a multiple of 256, and on NVIDIA where they are a multiple of
128 (their own rows' alignments).
`WorkCounts::pitched_host_images` and `pitched_host_image_refusals` count the images at Metal's
pitch made and refused.
## 7. Check the integration
`spirv-val` checks structural validity, not agreement with Metal:
```sh
spirv-val --target-env vulkan1.2 output.spv
```
`device.profile().spirv_validation()` names the environments and relaxations a module compiled
for the device is valid under; the command line runs each.
For a claim about behavior, follow [VALIDATION.md](VALIDATION.md): a synthetic regression test,
the golden output hashes where output must not move, and an authored case run on Metal and Vulkan
where it should.