Runtime: a buffer bound at a multiple of 4 below its argument's alignment runs the state's variant that holds it to 4

What: a dispatch's alignment check (check_alignments) no longer refuses a buffer whose argument's
alignment is 8 or 16 (mask past 3) bound at a multiple of 4 below it: it answers the mask of those
slots, bit i slot i. A non-empty mask picks the state's variant (PipelineInner::variant, srgbwrite's
sRGB variant generalised to both masks): Compiled::of lowers the state's function with those slots
in LoweringInputs::word_bound_buffers, kept in the device's bounded map of contents under
KernelKey's new words mask (1,024 entries), held by the command buffer that dispatched it. The
dispatch then checks the variant's own alignments strictly, so a buffer a 64-bit atomic may reach,
which the variant holds to 8, is refused off a multiple of 8. A kernel the consumer compiled has no
variant: its own module's strict check refuses the bind as before. One bit per slot: a second class
(8 at a multiple of 8) would need a second mask in the key and the input.

Still refused: an address off a multiple of 4 (off 2 for an alignment of 2), a 64-bit atomic's
buffer off a multiple of 8, every draw's (render_encoder keeps the strict check_alignment: the
draw side would need the render path's variant key), and a consumer-compiled kernel's.
Refusal::BufferOffsetAlignment's doc says so; its message and `alignment` now name the alignment
the function holds the address to, as the variant's 8 for a 16-aligned argument is not the
argument's. The buffer-bind-off-alignment ledger row carries the new message;
docs/CONFORMANCE-COVERAGE.md regenerated (unchanged); REFUSALS.md regenerated (unchanged: its row
takes the doc's first words).

Why: a guest's system texture-decode kernel (library db82b13f114fbeef #0) binds buffer 0 at offset
1871700 (4 mod 16) under a 16-byte argument alignment and met the refusal 60 and 72 times in two
sessions; plain Metal runs it with each element at its own address. Only such a dispatch runs the
variant: an empty mask keeps the state's key, hash and module.

Tests (not yet run): translate.rs every_device_places_each_vector_access_at_its_own_address runs
vwp_vec16 at VEC16_AT_WORDS too, holds Metal's words, and asserts a variant lowered exactly at the
runs off a multiple of 16; every_device_keeps_a_word_bound_variant_in_the_bounded_map_of_contents
(cap 2: one variant a mask, kept, the map at its cap, a forgotten one lowered again);
an_argument_bound_off_its_alignment_is_refused binds vwp_vec16 2 and 3 bytes off (alignment 16).
compute.rs's for_test kernel still refuses all 17 binds (no variant to lower).

Docs: the runtime README's compute-encoder rule and a known gap of pipeline states (the relaxed
form, with the unconditional build's 3090 constant_* rows), docs/API.md sections 1 and 10.
This commit is contained in:
Anees Iqbal committed 2026-11-25 19:17:03 -08:00
1 parent ab18b5cdcf
commit b42ef61b9b
12 files changed
+252 -67

No files matched your search

+12 -1
View File
@@ -139,7 +139,13 @@ and so do the command line, the compile worker and every validation tool. It hol
of its size is one `uvec2` or `uvec4`. The function states `RuntimeFact::AddressAlignment` with
that alignment (at most 16), and the runtime refuses a dispatch whose bound address is not a
multiple of it, as Metal's API validation refuses the bind offset (an accepted difference,
section 10). A slot whose argument states an alignment below 4, or none, is reached the same way where each of
section 10). Plain Metal reaches each element of an argument of 8- or 16-byte alignment bound at
a multiple of 4 exactly where the program put it (an Apple M3 Max, macOS 27.0.1,
`crates/metal2vulkan-conformance/probes/misaligned_buffer_binds.m`), so a function compiled with
such a slot in `LoweringInputs::word_bound_buffers` states the argument's alignment up to what
the slot's accesses need, 4, or 8 where a 64-bit atomic may reach it (any slot, where one goes
through a pointer loaded from memory), and its accesses through the address claim no more
`Aligned` than that; the runtime's dispatch of such a bind runs that variant. A slot whose argument states an alignment below 4, or none, is reached the same way where each of
its accesses is one 1- or 2-byte unit no wider than that alignment (an `i8` access of a `uchar`
buffer, an `i16` one of a `ushort` buffer) on a device with that width's storage access. Any
other slot is reached from the word below each access, its offset sign-extended, so an access
@@ -2759,6 +2765,11 @@ named states the rule in full.
Without validation an Apple M3 Max (macOS 27.0.1) runs it, reaching each element at its address
rounded down to the smaller of the element's alignment and 4, for loads, stores and pointers
stored in a buffer alike (`crates/metal2vulkan-conformance/probes/misaligned_buffer_binds.m`).
A function kernel's argument of 8- or 16-byte alignment bound at a multiple of 4 below it is not
refused: that rule reaches each of its elements at its own address, and the dispatch runs a
variant of the kernel that reaches them there (section 1, `LoweringInputs::word_bound_buffers`),
though Metal's API validation refuses that bind offset too. Such a buffer that a 64-bit atomic
may reach off a multiple of 8, a draw's, and a consumer-compiled kernel's are still refused.
- **A recursive call past the call stack yields zero**: the stack holds what Metal's byte model
holds for the pipeline's `max_call_stack_depth`; a call that finds it full returns zero, where
Metal's answer is corrupt.