Runtime: an indirect offset off 4 is Metal's documented refusal; arguments past the end are ours

Refusal::IndirectOffset covered two cases under one `ours` basis. Metal's headers document
the first: "indirectBufferOffset must be a multiple of 4" (MTLComputeCommandEncoder.h for
dispatchThreadgroupsWithIndirectBuffer:indirectBufferOffset:threadsPerThreadgroup:,
MTLRenderCommandEncoder.h for the indirect drawPrimitives and drawIndexedPrimitives; Apple's
page for the indirect drawPatches sends its offset to the feature set tables, whose minimum
constant buffer offset alignment is 4 bytes). The headers state no rule for the second,
arguments that run past the buffer's end, which is the runtime's own check because Vulkan's
indirect commands read inside the buffer (VUID-vkCmdDispatchIndirect-offset-00407,
VUID-vkCmdDrawIndirect-drawCount-00487, VUID-vkCmdDrawIndexedIndirect-drawCount-00539).

- IndirectOffset { offset, length } is now the offset-off-4 case alone, Basis:
  metal-documented.
- New IndirectArgumentsPastEnd { offset, length, needed }, Basis: ours, for arguments at a
  multiple of 4 with fewer than `needed` bytes (12 dispatch, 16 draw, 20 indexed draw) after
  the offset, or an end that overflows.
- Both raise sites (the indirect dispatch, and the indirect draws' shared check) test the
  alignment first, then the length.
- Regenerated docs/REFUSALS.md and error/basis.rs (refusal_surface.py), and
  api_signatures.tsv (one variant added). The runtime README's indirect-draw paragraph
  names both refusals.

Tests: every_device_refuses_an_indirect_dispatch_off_4_or_past_the_buffer_s_end (compute)
and every_device_refuses_an_indirect_draw_off_4_or_past_the_buffer_s_end (draw) assert each
variant and its basis(): off 4 at 2 and at an offset that is also past the end (alignment
first), past the end at a multiple of 4 and at an overflowing offset, an indexed draw's 20
bytes where a plain draw's 16 fit; then the arguments in each buffer's last bytes dispatch or
draw and their results are read back. The compute refusal test's two IndirectOffset asserts
moved into the dispatch test.

Checked here: refusal_surface.py --check and signatures.py --check pass (source only).
This commit is contained in:
Anees Iqbal committed 2026-11-21 15:33:10 -08:00
1 parent a3786dd88b
commit 325e88c276
9 files changed
+250 -53

No files matched your search

+6 -5
View File
@@ -3484,11 +3484,12 @@ cache is answered compile-required on both.
buffer does, and the command buffer keeps it until it retires; the pass's first barrier, and the
encoder's memory barrier after a draw that wrote, make earlier writes visible to the GPU's read.
The runtime never reads the arguments, so a count of 0 is recorded and draws nothing. An offset
that is not a multiple of 4 or leaves fewer than the arguments' 16 bytes in the buffer (20 for an
indexed draw) is `Refusal::IndirectOffset`, as Metal's validation stops it; arguments at a byte of
the block's allocation that is not a multiple of 4 are `Refusal::ArgumentPlace`; an indexed draw's
index offset that is not a multiple of the index size or is at or past the buffer's end is
`Refusal::IndexBufferOffset`.
that is not a multiple of 4 is `Refusal::IndirectOffset`, as Metal's headers require; one that
leaves fewer than the arguments' 16 bytes in the buffer (20 for an indexed draw) is
`Refusal::IndirectArgumentsPastEnd`, the runtime's own check, as Vulkan's indirect draws read
inside the buffer; arguments at a byte of the block's allocation that is not a multiple of 4 are
`Refusal::ArgumentPlace`; an indexed draw's index offset that is not a multiple of the index size
or is at or past the buffer's end is `Refusal::IndexBufferOffset`.
- A viewport is Vulkan's with its height negated (from `y + height`): framebuffer rows, the
fragment position and derivatives follow Metal's clip space, whose y points up, and Metal's
front-facing winding is Vulkan's front face of the same name. A viewport of no width or height,
+12 -10
View File
@@ -896,9 +896,10 @@ impl ComputeCommandEncoder {
/// the runtime never does, so a count above the device's limit is not refused (a known gap).
///
/// Err: as [`dispatch_threadgroups`](Self::dispatch_threadgroups); [`Refusal::OtherDevice`];
/// [`Refusal::IndirectOffset`] for an offset not a multiple of 4 or without 12 bytes after
/// it in the buffer; [`Refusal::ArgumentPlace`] for arguments at a byte of the buffer's
/// block's allocation that is not a multiple of 4, as a buffer placed at such a byte has.
/// [`Refusal::IndirectOffset`] for an offset not a multiple of 4;
/// [`Refusal::IndirectArgumentsPastEnd`] for one without 12 bytes after it in the buffer;
/// [`Refusal::ArgumentPlace`] for arguments at a byte of the buffer's block's allocation that
/// is not a multiple of 4, as a buffer placed at such a byte has.
pub fn dispatch_threadgroups_with_indirect_buffer(
&mut self,
buffer: &Buffer,
@@ -908,14 +909,15 @@ impl ComputeCommandEncoder {
if !buffer.is_of(self.building().device.core()) {
return Err(Error::Refused(Refusal::OtherDevice));
}
if offset % 4 != 0
|| offset
.checked_add(12)
.is_none_or(|end| end > buffer.length())
{
return Err(Error::Refused(Refusal::IndirectOffset {
let length = buffer.length();
if offset % 4 != 0 {
return Err(Error::Refused(Refusal::IndirectOffset { offset, length }));
}
if offset.checked_add(12).is_none_or(|end| end > length) {
return Err(Error::Refused(Refusal::IndirectArgumentsPastEnd {
offset,
length: buffer.length(),
length,
needed: 12,
}));
}
let place = buffer.device_range().1 + offset;
+35 -6
View File
@@ -416,18 +416,39 @@ pub enum Refusal {
/// The state's `maxTotalThreadsPerThreadgroup`.
max: u32,
},
/// An indirect dispatch's or draw's argument offset that is not a multiple of 4, or that leaves
/// fewer than the arguments' bytes in the buffer: 12 for a dispatch (three 32-bit counts), 20
/// for an indexed draw, 16 for another draw.
/// An indirect dispatch's or draw's argument offset that is not a multiple of 4, which Metal's
/// `indirectBufferOffset` must be
/// ([`ComputeCommandEncoder::dispatch_threadgroups_with_indirect_buffer`](crate::ComputeCommandEncoder::dispatch_threadgroups_with_indirect_buffer)
/// and the indirect draws of [`RenderCommandEncoder`](crate::RenderCommandEncoder)).
///
/// Basis: ours (`vkCmdDispatchIndirect`, `vkCmdDrawIndirect` and `vkCmdDrawIndexedIndirect`
/// read their 32-bit words at a 4-byte aligned offset inside the buffer).
/// Basis: metal-documented (MTLComputeCommandEncoder.h for
/// `dispatchThreadgroupsWithIndirectBuffer:indirectBufferOffset:threadsPerThreadgroup:`, and
/// MTLRenderCommandEncoder.h for the indirect `drawPrimitives` and `drawIndexedPrimitives`:
/// "indirectBufferOffset must be a multiple of 4"; Apple's page for the indirect
/// `drawPatches` sends its offset to the feature set tables, whose minimum constant buffer
/// offset alignment is 4 bytes).
IndirectOffset {
/// The offset asked for.
offset: u64,
/// The buffer's length.
length: u64,
},
/// An indirect dispatch's or draw's arguments, at an offset that is a multiple of 4, that run
/// past the buffer's end: fewer than the arguments' bytes lie after the offset, 12 for a
/// dispatch (three 32-bit counts), 20 for an indexed draw, 16 for another draw. The calls'
/// Metal headers state no such rule.
///
/// Basis: ours (`vkCmdDispatchIndirect`, `vkCmdDrawIndirect` and `vkCmdDrawIndexedIndirect`
/// read their arguments inside the buffer, `VUID-vkCmdDispatchIndirect-offset-00407`,
/// `VUID-vkCmdDrawIndirect-drawCount-00487` and `VUID-vkCmdDrawIndexedIndirect-drawCount-00539`).
IndirectArgumentsPastEnd {
/// The offset asked for.
offset: u64,
/// The buffer's length.
length: u64,
/// The arguments' bytes.
needed: u64,
},
/// A dispatch whose kernel, or a draw whose vertex or fragment function, reaches a buffer
/// bound where its address, the buffer's `gpuAddress` plus the bind offset, is not a multiple
/// of the argument's alignment (`air.arg_type_align_size`, at most 16). Plain Metal runs such a dispatch at addresses of
@@ -2334,7 +2355,15 @@ impl fmt::Display for Refusal {
),
Refusal::IndirectOffset { offset, length } => write!(
f,
"indirect arguments at offset {offset} of a {length}-byte buffer are misaligned or past its end"
"indirect arguments at offset {offset} of a {length}-byte buffer are not at a multiple of 4"
),
Refusal::IndirectArgumentsPastEnd {
offset,
length,
needed,
} => write!(
f,
"{needed} bytes of indirect arguments at offset {offset} run past a {length}-byte buffer's end"
),
Refusal::BufferOffsetAlignment {
index,
@@ -38,7 +38,8 @@ impl Refusal {
Refusal::SamplerIds { .. } => RefusalBasis::Ours,
Refusal::NoBufferAtIndex { .. } => RefusalBasis::Ours,
Refusal::ThreadgroupSize { .. } => RefusalBasis::MetalDocumented,
Refusal::IndirectOffset { .. } => RefusalBasis::Ours,
Refusal::IndirectOffset { .. } => RefusalBasis::MetalDocumented,
Refusal::IndirectArgumentsPastEnd { .. } => RefusalBasis::Ours,
Refusal::BufferOffsetAlignment { .. } => RefusalBasis::MetalDocumented,
Refusal::IndicesGranted { .. } => RefusalBasis::Ours,
Refusal::IndicesNotGranted { .. } => RefusalBasis::Ours,
@@ -2030,11 +2030,11 @@ impl RenderCommandEncoder {
/// nothing.
///
/// Err: as [`draw_primitives`](Self::draw_primitives); [`Refusal::OtherDevice`] for another
/// device's buffer; [`Refusal::IndirectOffset`] for an offset not a multiple of 4 or without
/// 16 bytes after it in the buffer; [`Refusal::ArgumentPlace`] for arguments at a byte of the
/// buffer's block's allocation that is not a multiple of 4; [`Gap::Draw`] of
/// [`DrawKind::DividedBaseInstance`] for a state whose base instance the device takes as 0
/// alone.
/// device's buffer; [`Refusal::IndirectOffset`] for an offset not a multiple of 4;
/// [`Refusal::IndirectArgumentsPastEnd`] for one without 16 bytes after it in the buffer;
/// [`Refusal::ArgumentPlace`] for arguments at a byte of the buffer's block's allocation that
/// is not a multiple of 4; [`Gap::Draw`] of [`DrawKind::DividedBaseInstance`] for a state whose
/// base instance the device takes as 0 alone.
pub fn draw_primitives_indirect(
&mut self,
primitive_type: PrimitiveType,
@@ -2221,9 +2221,16 @@ impl RenderCommandEncoder {
}
let bytes = indirect_bytes(indices.is_some());
let length = arguments.length();
if offset % 4 != 0 || offset.checked_add(bytes).is_none_or(|end| end > length) {
if offset % 4 != 0 {
return Err(Error::Refused(Refusal::IndirectOffset { offset, length }));
}
if offset.checked_add(bytes).is_none_or(|end| end > length) {
return Err(Error::Refused(Refusal::IndirectArgumentsPastEnd {
offset,
length,
needed: bytes,
}));
}
let place = arguments.device_range().1 + offset;
if !place.is_multiple_of(4) {
return Err(Error::Refused(Refusal::ArgumentPlace {
@@ -16,7 +16,7 @@ pub(crate) mod on_device {
use crate::tests::kernels;
use crate::{
Buffer, CommandBuffer, ComputeCommandEncoder, ComputePipelineState, Device, DispatchType,
Error, Gap, HeapRange, Limit, MemoryClass, Refusal,
Error, Gap, HeapRange, Limit, MemoryClass, Refusal, RefusalBasis,
};
/// Words in each test buffer: 256 bytes.
@@ -845,6 +845,80 @@ pub(crate) mod on_device {
});
}
/// An indirect dispatch's offset that is not a multiple of 4 is Metal's documented refusal,
/// `Refusal::IndirectOffset`, which is checked first: at 2, and at 246, whose 12 bytes would
/// also run past the 256-byte buffer's end. Arguments at a multiple of 4 that run past the end
/// are the runtime's own refusal, `Refusal::IndirectArgumentsPastEnd`: at 248, and at an
/// offset whose end overflows. The arguments in the buffer's last 12 bytes, at 244, dispatch.
#[test]
fn every_device_refuses_an_indirect_dispatch_off_4_or_past_the_buffer_s_end() {
each_device("compute_indirect_offset", |name, _, device| {
let mut arena = Arena::new(&device);
let (a, b, o, arguments) = (
arena.buffer(),
arena.buffer(),
arena.buffer(),
arena.buffer(),
);
write_words(&a, |index| index);
write_words(&b, |index| 1000 * index);
write_words(&arguments, |index| match index {
61 => 4,
62 | 63 => 1,
_ => 0,
});
let state = add(&device);
let queue = device.new_command_queue(4).expect("a queue");
let command_buffer = queue.command_buffer().expect("a command buffer");
let mut encoder = command_buffer
.compute_command_encoder(DispatchType::Serial)
.expect("an encoder");
encoder.set_compute_pipeline_state(&state).expect("a state");
for (slot, buffer) in [&a, &b, &o].into_iter().enumerate() {
encoder
.set_buffer(Some(buffer), 0, slot as u32)
.expect("a buffer");
}
let mut refused = |offset: u64| {
let result = encoder.dispatch_threadgroups_with_indirect_buffer(
&arguments,
offset,
[16, 1, 1],
);
match result {
Err(Error::Refused(refusal)) => (refusal, refusal.basis()),
other => panic!("{name}: arguments at {offset}: {other:?}"),
}
};
let length = 256;
for offset in [2, 246] {
let off_4 = Refusal::IndirectOffset { offset, length };
let want = (off_4, RefusalBasis::MetalDocumented);
assert_eq!(refused(offset), want, "{name}: at {offset}");
}
for offset in [248, u64::MAX - 3] {
let needed = 12;
let past = Refusal::IndirectArgumentsPastEnd {
offset,
length,
needed,
};
assert_eq!(
refused(offset),
(past, RefusalBasis::Ours),
"{name}: at {offset}"
);
}
encoder
.dispatch_threadgroups_with_indirect_buffer(&arguments, 244, [16, 1, 1])
.expect("an indirect dispatch of the buffer's last 12 bytes");
encoder.end_encoding();
run(name, &command_buffer);
let expected: Vec<u32> = (0..WORDS as u32).map(|index| 1001 * index).collect();
assert_eq!(words(&o), expected, "{name}");
});
}
/// A dispatch of a kernel that writes no memory (`Interface::has_effects` false, from the
/// translator's `PipelineInterface::writes_memory`) records nothing: given the step kernel's
/// words under such an interface, a direct and an indirect dispatch leave its buffer as it was,
@@ -1021,24 +1095,6 @@ pub(crate) mod on_device {
encoder.dispatch_threads([60, 1, 1], [16, 1, 1]),
Err(Error::Unsupported(Gap::PartialThreadgroups { .. }))
));
assert_eq!(
refused(encoder.dispatch_threadgroups_with_indirect_buffer(&buffer, 2, [1, 1, 1])),
Refusal::IndirectOffset {
offset: 2,
length: 256
}
);
assert_eq!(
refused(encoder.dispatch_threadgroups_with_indirect_buffer(
&buffer,
248,
[1, 1, 1]
)),
Refusal::IndirectOffset {
offset: 248,
length: 256
}
);
// While the encoder is open, the command buffer takes no other call.
assert!(matches!(
command_buffer.compute_command_encoder(DispatchType::Serial),
+101 -3
View File
@@ -127,9 +127,9 @@ pub(crate) mod on_device {
Block, Buffer, ColorAttachmentDescriptor, CommandBuffer, CompareFunction, CullMode,
DepthStencilDescriptor, Device, DrawKind, Error, FunctionDescriptor, Gap, IndexBuffer,
IndexClass, IndexType, Library, MemoryClass, NumberedSampler, PixelFormat, PrimitiveType,
Refusal, Region, RenderPassDescriptor, RenderPipelineDescriptor, RenderPipelineState,
ScissorRect, StageSource, StencilOperation, StorageMode, Texture, TextureDescriptor,
TextureType, TextureUsage, Viewport, VisibilityResultMode,
Refusal, RefusalBasis, Region, RenderPassDescriptor, RenderPipelineDescriptor,
RenderPipelineState, ScissorRect, StageSource, StencilOperation, StorageMode, Texture,
TextureDescriptor, TextureType, TextureUsage, Viewport, VisibilityResultMode,
};
use metal2vulkan::error::Feature;
use metal2vulkan::library::{FunctionConstantValue, FunctionConstantValues};
@@ -2572,6 +2572,104 @@ define internal void @_GLOBAL__sub_I_() section "air.static_init" {
});
}
/// An indirect draw's offset that is not a multiple of 4 is Metal's documented refusal,
/// `Refusal::IndirectOffset`, which is checked first: at 2, and at 26, whose 16 bytes would
/// also run past the 40-byte buffer's end. Arguments at a multiple of 4 that run past the end
/// are the runtime's own refusal, `Refusal::IndirectArgumentsPastEnd`: a draw's 16 bytes at
/// 28 and at an offset whose end overflows, and an indexed draw's 20 at 24, where a draw's 16
/// fit. Each kind's arguments in its buffer's last bytes then draw: the indexed draw's whole
/// blue triangle, then the draw's top half green one over it.
#[test]
fn every_device_refuses_an_indirect_draw_off_4_or_past_the_buffer_s_end() {
let Some(library) = examples() else {
return;
};
let d = descriptor(&library, "colored_fragment", PixelFormat::RGBA8Unorm);
each_device("draw_indirect_offset", |name, _, device| {
let state = state(name, &device, &d);
let mut buffers = Buffers::new(&device);
let (positions, colors) = vertices(&device, &mut buffers);
let indices = buffers.of(&device, &[3, 0, 4, 0, 5, 0]);
// 40 bytes, `last` the last words.
let arguments = |last: &[u32]| -> Vec<u8> {
let lead = [0xeeee_eeee_u32; 10];
let words = [&lead[..10 - last.len()], last].concat();
words.iter().flat_map(|w| w.to_le_bytes()).collect()
};
// The top triangle from vertex 0, and the whole one from index 0 (vertices 3 to 5).
let plain = buffers.of(&device, &arguments(&[3, 1, 0, 0]));
let indexed = buffers.of(&device, &arguments(&[3, 1, 0, 0, 0]));
let color = target(
&device,
PixelFormat::RGBA8Unorm,
TextureUsage::RENDER_TARGET,
);
let queue = device.new_command_queue(4).expect("a queue");
let command_buffer = queue.command_buffer().expect("a command buffer");
let mut encoder = (command_buffer.render_command_encoder(&pass(&color, None)))
.unwrap_or_else(|error| panic!("{name}: {error}"));
let draw = |result: Result<(), Error>| result.unwrap_or_else(|e| panic!("{name}: {e}"));
draw(encoder.set_render_pipeline_state(&state));
draw(encoder.set_vertex_buffer(Some(&positions), 0, 0));
draw(encoder.set_vertex_buffer(Some(&colors), 0, 1));
let index_buffer = IndexBuffer {
buffer: &indices,
offset: 0,
index_type: IndexType::UInt16,
};
let triangle = PrimitiveType::Triangle;
let refused = |result: Result<(), Error>, case: &str| match result {
Err(Error::Refused(refusal)) => (refusal, refusal.basis()),
other => panic!("{name}: {case}: {other:?}"),
};
let length = 40;
for offset in [2, 26] {
let got = refused(
encoder.draw_primitives_indirect(triangle, &plain, offset),
"draw",
);
let off_4 = Refusal::IndirectOffset { offset, length };
assert_eq!(
got,
(off_4, RefusalBasis::MetalDocumented),
"{name}: at {offset}"
);
}
for offset in [28, u64::MAX - 3] {
let got = refused(
encoder.draw_primitives_indirect(triangle, &plain, offset),
"draw",
);
let needed = 16;
let past = Refusal::IndirectArgumentsPastEnd {
offset,
length,
needed,
};
assert_eq!(got, (past, RefusalBasis::Ours), "{name}: at {offset}");
}
let got = refused(
encoder.draw_indexed_primitives_indirect(triangle, index_buffer, &indexed, 24),
"indexed draw",
);
let past = Refusal::IndirectArgumentsPastEnd {
offset: 24,
length,
needed: 20,
};
assert_eq!(got, (past, RefusalBasis::Ours), "{name}: indexed at 24");
draw(encoder.draw_indexed_primitives_indirect(triangle, index_buffer, &indexed, 20));
draw(encoder.draw_primitives_indirect(triangle, &plain, 24));
encoder.end_encoding();
run(name, &command_buffer);
let want = texels(|_, y| match y {
0..4 => GREEN,
_ => BLUE,
});
assert_eq!(read(&color, 4), want, "{name}: the texels");
});
}
/// A shader-read render target of `format`, `SIDE` a side and `levels` levels, at `index`.
pub(crate) fn readable(
device: &Device,
@@ -9485,6 +9485,7 @@ variant metal2vulkan-runtime::Refusal::InScheduledHandler InScheduledHandler
variant metal2vulkan-runtime::Refusal::IndexBufferOffset IndexBufferOffset { offset: u64, length: u64 }
variant metal2vulkan-runtime::Refusal::IndicesGranted IndicesGranted { class: IndexClass, index: u32 }
variant metal2vulkan-runtime::Refusal::IndicesNotGranted IndicesNotGranted { class: IndexClass, index: u32 }
variant metal2vulkan-runtime::Refusal::IndirectArgumentsPastEnd IndirectArgumentsPastEnd { offset: u64, length: u64, needed: u64 }
variant metal2vulkan-runtime::Refusal::IndirectOffset IndirectOffset { offset: u64, length: u64 }
variant metal2vulkan-runtime::Refusal::ManagedBlockPrivate ManagedBlockPrivate { block: BlockId }
variant metal2vulkan-runtime::Refusal::ManagedCopyMissing ManagedCopyMissing
Can't render this file because it is too large.
+5 -3
View File
@@ -32,7 +32,7 @@ Columns:
| Rate maps the compile layer does not compile | 5 | 5 | 0 | 0 | 4 | 1 | 0 |
| The translation deadline | 1 | 1 | 0 | 0 | 0 | 1 | 0 |
| Devices below the runtime's floor | 8 | 8 | 0 | 0 | 0 | 0 | 0 |
| The runtime's `Refusal` | 82 | 82 | 0 | 0 | 0 | 0 | 0 |
| The runtime's `Refusal` | 83 | 83 | 0 | 0 | 0 | 0 | 0 |
| The runtime's `Limit` | 17 | 17 | 0 | 0 | 0 | 0 | 0 |
| The runtime's `Gap` | 32 | 32 | 0 | 0 | 0 | 0 | 0 |
@@ -46,7 +46,7 @@ Columns:
| Rate maps the compile layer does not compile | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 5 |
| The translation deadline | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 |
| Devices below the runtime's floor | 0 | 0 | 0 | 8 | 0 | 0 | 0 | 0 |
| The runtime's `Refusal` | 22 | 25 | 0 | 0 | 35 | 0 | 0 | 0 |
| The runtime's `Refusal` | 22 | 26 | 0 | 0 | 35 | 0 | 0 | 0 |
| The runtime's `Limit` | 0 | 0 | 0 | 13 | 4 | 0 | 0 | 0 |
| The runtime's `Gap` | 0 | 0 | 0 | 3 | 29 | 0 | 0 | 0 |
@@ -284,7 +284,8 @@ Columns:
| `SamplerIds` | A consumer's answer to `Device::new_compute_pipeline_state`'s numbered samplers with another count of indices | every device (a public call's own check of its arguments) | `ours`: each numbered sampler takes one index | 1: `crates/metal2vulkan-runtime/src/pipeline.rs (number_samplers)` | `-` |
| `NoBufferAtIndex` | `setBufferOffset` at an index where no buffer is bound, or a draw whose vertex descriptor reads a vertex buffer index where none is bound | every device (a public call's own check of its arguments) | `ours`: there is no buffer whose offset to change, and none whose vertices the draw reads; Metal's validation stops such a draw | 3: `crates/metal2vulkan-runtime/src/encoder.rs (set_buffer_offset)`, `crates/metal2vulkan-runtime/src/render_encoder.rs (find)` (+1) | `-` |
| `ThreadgroupSize` | A threadgroup of no threads, or of more than Metal's `maxTotalThreadsPerThreadgroup` for the kernel (a required size's threads, where the... | every device (a public call's own check of its arguments) | `metal-documented`: a threadgroup's threads total at most the state's `maxTotalThreadsPerThreadgroup` | 2: `crates/metal2vulkan-runtime/src/encoder.rs (dispatch)`, `crates/metal2vulkan-runtime/src/encoder.rs (size_checked)` | `-` |
| `IndirectOffset` | An indirect dispatch's or draw's argument offset that is not a multiple of 4, or that leaves fewer than the arguments' bytes in the buffer | every device (a public call's own check of its arguments) | `ours`: `vkCmdDispatchIndirect`, `vkCmdDrawIndirect` and `vkCmdDrawIndexedIndirect` read their 32-bit words at a 4-byte aligned offset inside the buffer | 2: `crates/metal2vulkan-runtime/src/encoder.rs (dispatch_threadgroups_with_indirect_buffer)`, `crates/metal2vulkan-runtime/src/render_encoder.rs (indirect)` | `-` |
| `IndirectOffset` | An indirect dispatch's or draw's argument offset that is not a multiple of 4, which Metal's `indirectBufferOffset` must be... | every device (a public call's own check of its arguments) | `metal-documented`: MTLComputeCommandEncoder.h for `dispatchThreadgroupsWithIndirectBuffer:indirectBufferOffset:threadsPerThreadgroup:`, and MTLRenderCommandEncoder.h for the indirect `drawPrimitives` and `drawIndexedPrimitives`: "indirectBufferOffset must be a multiple of 4"; Apple's page for the indirect `drawPatches` sends its offset to the feature set tables, whose minimum constant buffer offset alignment is 4 bytes | 2: `crates/metal2vulkan-runtime/src/encoder.rs (dispatch_threadgroups_with_indirect_buffer)`, `crates/metal2vulkan-runtime/src/render_encoder.rs (indirect)` | `-` |
| `IndirectArgumentsPastEnd` | An indirect dispatch's or draw's arguments, at an offset that is a multiple of 4, that run past the buffer's end | every device (a public call's own check of its arguments) | `ours`: `vkCmdDispatchIndirect`, `vkCmdDrawIndirect` and `vkCmdDrawIndexedIndirect` read their arguments inside the buffer, `VUID-vkCmdDispatchIndirect-offset-00407`, `VUID-vkCmdDrawIndirect-drawCount-00487` and `VUID-vkCmdDrawIndexedIndirect-drawCount-00539` | 2: `crates/metal2vulkan-runtime/src/encoder.rs (dispatch_threadgroups_with_indirect_buffer)`, `crates/metal2vulkan-runtime/src/render_encoder.rs (indirect)` | `-` |
| `BufferOffsetAlignment` | A dispatch whose kernel, or a draw whose vertex or fragment function, reaches a buffer bound where its address, the buffer's `gpuAddress` plus the... | every device (a public call's own check of its arguments) | `metal-documented`: Metal's API validation refuses the bind offset: "must be a multiple of 4 but was set to 2" for a `uint *` argument bound at offset 2, an Apple M3 Max, macOS 27.0.1, `probes/vector_access_placement.m` in the conformance crate | 1: `crates/metal2vulkan-runtime/src/encoder.rs (check_alignment)` | `-` |
| `IndicesGranted` | A grant of an index already granted (`Device::grant_indices`) | every device (a public call's own check of its arguments) | `ours`: each index has one grant, so each resource ID names one object | 1: `crates/metal2vulkan-runtime/src/arrays.rs (grant)` | `-` |
| `IndicesNotGranted` | A texture, a sampler state or a pipeline state's constexpr sampler at an index no grant of its class holds (`Device::new_texture`,... | every device (a public call's own check of its arguments) | `ours`: an object takes an index the consumer was granted | 1: `crates/metal2vulkan-runtime/src/arrays.rs (place)` | `-` |
@@ -587,6 +588,7 @@ Each refusal's sites, with the function that builds it.
- `rt:Refusal::NoBufferAtIndex`: `crates/metal2vulkan-runtime/src/encoder.rs (set_buffer_offset)`; `crates/metal2vulkan-runtime/src/render_encoder.rs (find)`; `crates/metal2vulkan-runtime/src/render_encoder.rs (set_buffer_offset)`
- `rt:Refusal::ThreadgroupSize`: `crates/metal2vulkan-runtime/src/encoder.rs (dispatch)`; `crates/metal2vulkan-runtime/src/encoder.rs (size_checked)`
- `rt:Refusal::IndirectOffset`: `crates/metal2vulkan-runtime/src/encoder.rs (dispatch_threadgroups_with_indirect_buffer)`; `crates/metal2vulkan-runtime/src/render_encoder.rs (indirect)`
- `rt:Refusal::IndirectArgumentsPastEnd`: `crates/metal2vulkan-runtime/src/encoder.rs (dispatch_threadgroups_with_indirect_buffer)`; `crates/metal2vulkan-runtime/src/render_encoder.rs (indirect)`
- `rt:Refusal::BufferOffsetAlignment`: `crates/metal2vulkan-runtime/src/encoder.rs (check_alignment)`
- `rt:Refusal::IndicesGranted`: `crates/metal2vulkan-runtime/src/arrays.rs (grant)`
- `rt:Refusal::IndicesNotGranted`: `crates/metal2vulkan-runtime/src/arrays.rs (place)`