rt: a buffer bound off its argument's alignment runs at the address rounded down to it
The binder (ComputeCommandEncoder::fill_parameters) pushes each bound buffer's address, its gpuAddress plus the bind offset, rounded down to a multiple of the alignment the kernel takes it to have (FieldValue::BufferAddress's mask, from RuntimeFact::AddressAlignment: the argument's air.arg_type_align_size, at most 16), for every slot. Refusal::MisalignedBuffer and the dispatch it skipped are deleted, so fill_parameters cannot fail. Why: Metal's API validation refuses such a bind offset, and 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. The probe that measured it is committed as crates/metal2vulkan-conformance/probes/misaligned_buffer_binds.m. The two agree at alignments 2 and 4 and for 8- and 16-byte arguments 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 rounded address where the M3 reaches it exactly there, a bind Metal's validation rejects. docs/API.md section 10 lists that as an accepted difference. Tests: rt's every_device_rounds_a_bound_address_down_to_its_alignment steps a buffer bound off each alignment (2, 4, 8 and 16; 15 binds) through the step kernel with the mask set, and checks the words stepped start at the rounded address; at the 8- and 16-byte binds 4, 8 or 12 bytes off, an unrounded bind would step other words on any device. an_argument_bound_off_its_alignment_runs_at_the_address_rounded_down binds vector_word_phases' vwp_words 1 and 3 bytes and vwp_vec16 4 and 12 bytes off their alignment and expects Metal's words for the rounded binds. They replace an_argument_bound_off_its_alignment_is_refused and a_misaligned_dispatch_refused_leaves_its_encoder_and_command_buffer_usable. Docs: REFUSALS.md and api_signatures.tsv regenerated (the variant's row goes), the rt README's compute encoders say what the binder pushes, the translator's RuntimeFact::AddressAlignment doc and the mechanism comment say the binder rounds.
This commit is contained in:
1 parent
ee7c4a5173
commit
4732ce6cd7
12 files changed
+370
-182
No files matched your search
+15
-2
@@ -117,8 +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 refuses a binding
|
||||
whose address is not a multiple of it, as Metal's API validation refuses the bind offset. A
|
||||
`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
|
||||
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
|
||||
@@ -6403,6 +6404,18 @@ 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.
|
||||
- **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.
|
||||
|
||||
Reference in new issue
Block a user