rt: a dispatch that reaches a buffer bound off its argument's alignment is refused

The planner ruled that the bind-offset mask becomes a typed refusal. The binder pushed a bound
buffer's address, its gpuAddress plus the offset, rounded down to the alignment the kernel takes
it to have (FieldValue::BufferAddress's mask, from RuntimeFact::AddressAlignment), where Metal's
API validation refuses the bind offset ("must be a multiple of 4 but was set to 2" for a uint *
argument, probe vector_access_placement.m in the conformance crate). Plain Metal runs such a
dispatch at addresses of its own: an M3 Max reaches each element at its address rounded down to
the smaller of its alignment and 4. That is not the rounding the binder did for 8- and 16-byte
arguments.

The dispatch now refuses it with Refusal::BufferOffsetAlignment { index, offset, alignment }
before it records or keeps anything. check_alignment runs after the threadgroup size check and
before a kernel without effects returns, so both direct and indirect dispatches take it.
fill_parameters pushes each address as it is. A set_bytes copy sits at a multiple of 16 in the
ring, which every mask divides, so it is never refused.

Docs:
- docs/API.md: the identity-domain paragraph and the section 10 entry (renamed: "A dispatch that
  reaches a buffer bound off its argument's alignment is refused"); no case names its slug.
- RuntimeFact::AddressAlignment's doc and the mechanism comment.
- The rt README paragraph and FieldValue::BufferAddress's doc.
- docs/REFUSALS.md regenerated (44 rt refusals); api_signatures.tsv gains the variant's row.

Tests (device, under --cfg m2v_gpu or m2v_cpu_icd):
- every_device_refuses_a_bound_address_off_its_alignment (was ..._rounds_a_bound_address_down_...):
  at alignments 2, 4, 8 and 16, each of 17 binds 1 to 15 bytes past a multiple of 16 that the
  alignment does not divide is refused and leaves the buffer unchanged, and the same buffer bound
  at 48 runs. Without the check every one of the 17 dispatches returns Ok.
- an_argument_bound_off_its_alignment_is_refused (was ..._runs_at_the_address_rounded_down):
  the translated vector_word_phases kernels with one argument off its alignment are refused,
  naming the index, offset and alignment, and the command buffer completes with every buffer
  unchanged.
This commit is contained in:
Anees Iqbal committed 2026-11-18 00:14:00 -08:00
1 parent a6520161e8
commit 9bec8a977e
11 files changed
+184 -106

No files matched your search

+12 -15
View File
@@ -117,9 +117,9 @@ compile does. `DevicePolicy::default()` is `DevicePolicy::UNTRUSTED`:
address plus its 32-bit byte offset, sign-extended, which is exact as the new runtime makes no
buffer longer than 2 GiB (`MAX_BUFFER_LENGTH`), and an access of 8 or 16 bytes at an offset
proven a multiple of its size is one `uvec2` or `uvec4`. The function states
`RuntimeFact::AddressAlignment` with that alignment (at most 16), and a binder rounds a bound
address down to a multiple of it, where Metal's API validation refuses the bind offset (an
accepted difference, section 10). A
`RuntimeFact::AddressAlignment` with that alignment (at most 16), and the new 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
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
@@ -6415,18 +6415,15 @@ each item named states the rule in full.
an argument the kernel writes may read those bytes as they were before its own writes, where the
device reads read-only memory through another path (RADV reads a uniform address of it with a
scalar load). The attribute states that no other argument reaches that memory.
- **A buffer bound off its argument's alignment is reached at the address rounded down to that
alignment** (the alignment the kernel's AIR states for the argument, `air.arg_type_align_size`,
at most 16; `RuntimeFact::AddressAlignment`): the new runtime's binder rounds the bound address,
the buffer's `gpuAddress` plus the offset, before the dispatch runs. Metal's API validation
refuses such a bind offset ("must be a multiple of 4 but was set to 2" for a `uint *` argument).
Without validation an Apple M3 Max (macOS 27.0.1) reaches 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`). The two agree
for arguments of alignment 2 and 4, and for 8- and 16-byte ones bound 1 to 3 bytes off a
multiple of 4; an 8- or 16-byte argument bound at a multiple of 4 that is not a multiple of its
alignment is reached at the address rounded down to 8 or 16, where the M3 reaches it exactly
there.
- **A dispatch that reaches a buffer bound off its argument's alignment is refused** (the
alignment the kernel's AIR states for the argument, `air.arg_type_align_size`, at most 16;
`RuntimeFact::AddressAlignment`): the new runtime refuses the dispatch
(`Refusal::BufferOffsetAlignment`) where the bound address, the buffer's `gpuAddress` plus the
offset, is not a multiple of it, before anything is recorded, as Metal's API validation refuses
such a bind offset ("must be a multiple of 4 but was set to 2" for a `uint *` argument).
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`).
- **An imageblock's length rounds its cell as an M4 does**
(`ComputePipelineState::imageblock_memory_length_for_dimensions`), never less than what a
dispatch counts against the device's threadgroup memory.