Move the four refusals plain Metal takes out of Error::Invalid

The steps this packet landed as, in order:
- Hold the off-four execution range to an offset inside its buffer

Content: the tree of `development` at 15b0982f8c, unchanged.
This commit is contained in:
Anees Iqbal committed 2026-10-26 13:19:17 +02:00
1 parent 089cc0a9e0
commit 7561e7bc4e
18 files changed
+389 -229

No files matched your search

@@ -260,6 +260,7 @@ fn refusal_error(call: &'static str, refusal: BufferRefusal) -> Error {
Error::NotImplemented(RuntimeGap::TexelsPastBufferLength)
}
BufferRefusal::OverlappingRows => Error::NotImplemented(RuntimeGap::OverlappingSurfaceRows),
BufferRefusal::MemorylessPlane => Error::NotImplemented(RuntimeGap::MemorylessSurfacePlane),
}
}
@@ -362,13 +363,14 @@ impl Buffer {
/// ([`AppleOnly::SurfaceClientDirection`](super::AppleOnly::SurfaceClientDirection)); what
/// Metal stops (`Invalid`, with a [`TextureProblem`](super::TextureProblem) or a
/// [`BufferTextureProblem`](super::BufferTextureProblem): a type other than 2D, more than one
/// level, `Memoryless` storage (whose measurement is
/// [`BufferTextureProblem::Options`](super::BufferTextureProblem::Options)'s), a pitch below
/// the row, a surface without planes at
/// another pitch or offset, a plane past the buffer); rows that overlap on Metal's GPU, of more
/// than 16 bytes at a `bytes_per_row` whose multiple of 16 below it is shorter than the row,
/// where Metal's writes depend on their order (`NotImplemented(OverlappingSurfaceRows)`); GPU
/// texels past the buffer, which Metal's surface holds in its pages
/// level, a pitch below the row, a surface without planes at another pitch or offset, or one
/// whose rows end past it, which plain Metal asserts on); `Memoryless` storage, which plain
/// Metal makes and serves on the CPU while its GPU uses fail the command buffer
/// (`NotImplemented(MemorylessSurfacePlane)`, which carries the measurement); rows that
/// overlap on Metal's GPU, of more than 16 bytes at a `bytes_per_row` whose multiple of 16
/// below it is shorter than the row, where Metal's writes depend on their order
/// (`NotImplemented(OverlappingSurfaceRows)`); a plane's own rows or its GPU texels past the
/// buffer, which Metal's surface holds in its pages
/// (`NotImplemented(TexelsPastBufferLength)`); and as [`new_texture`](Self::new_texture)
/// refuses a format or an image.
///
+9 -5
View File
@@ -1348,10 +1348,14 @@ impl ComputeCommandEncoder {
/// announces once (`Degradation::HostReplayedIndirectCommands`; the encoder copies the range
/// where it is encoded, behind a barrier from everything before).
///
/// Refused, changing nothing (`Invalid`): a buffer of another device, a range Metal's reading
/// of is not defined (an offset that is not a multiple of 4 bytes, or 8 bytes that run past
/// `range_buffer`: `IndirectCommandBufferProblem::RangeBuffer`), and no pipeline state set
/// where `icb` inherits it. A buffer of render command types is refused as
/// A range plain Metal takes and the runtime has no exact answer for is its own gap, not
/// misuse: 8 bytes that run past `range_buffer`, which Metal reads from whatever follows it
/// (`NotImplemented(ExecutionRangePastBuffer)`), and an `offset` that is not a multiple of 4
/// bytes, which Metal's GPU faults the command buffer over where the range read there runs a
/// command (`NotImplemented(ExecutionRangeOffFour)`; both carry the measurement).
///
/// Refused, changing nothing (`Invalid`): a buffer of another device, and no pipeline state
/// set where `icb` inherits it. A buffer of render command types is refused as
/// [`execute_commands_in_buffer`](Self::execute_commands_in_buffer) refuses it. A buffer of
/// no command types runs nothing, its range unread, as plain Metal's. What a command's dispatch
/// would be refused fails the command buffer.
@@ -1401,7 +1405,7 @@ impl ComputeCommandEncoder {
if icb.is_render() {
return Err(Error::NotImplemented(RuntimeGap::IndirectRenderCommands));
}
indirect_execute::check_range_buffer(CALL, range_buffer.length(), offset)?;
indirect_execute::check_range_buffer(range_buffer.length(), offset)?;
let pipeline = this.inherited_pipeline(CALL, icb)?;
// A buffer of no command types runs nothing, as plain Metal's; its range is not
// read.
+91 -8
View File
@@ -404,6 +404,11 @@ impl Nil {
/// [`Problem::UnwrittenFragmentInputsUnproven`], a device's [`Problem::HostReleaseUnmeasured`], and
/// [`Problem::IndirectCommandsDirectArgumentUndecided`].
///
/// What is unproven is Metal's *answer*, not what the call then does: a call measured to return,
/// whose effect Metal leaves undefined, is not one of these. Metal's answer there is known, and
/// having no exact form for the effect is the runtime's own gap
/// ([`Error::NotImplemented`]).
///
/// The first refusal in Metal's order decides, proven or not: an unproven answer stops the call's
/// checks even where a later one would be a proven refusal. A fragment function's unproven direct
/// argument hides the vertex function's proven one, and the indirect command buffers' unproven
@@ -651,7 +656,8 @@ pub enum Problem {
Copy(CopyProblem),
/// A `generate_mipmaps` Metal stops.
Mipmap(MipmapProblem),
/// A texture over a buffer Metal stops.
/// A texture over a buffer plain Metal itself refuses: [`BufferTextureProblem`] says
/// which, and whether Metal asserts or answers nil.
BufferTexture(BufferTextureProblem),
/// A render pass descriptor, or a render encoder's late store action, Metal stops.
RenderPass(RenderPassProblem),
@@ -718,7 +724,8 @@ pub enum Problem {
/// A visible-function table call, or a table or buffer binding a dispatch reads as the other,
/// Metal stops.
FunctionTable(FunctionTableProblem),
/// An indirect command buffer call Metal stops or ends the process for.
/// An indirect command buffer call plain Metal itself refuses, ending its process or
/// failing the call: [`IndirectCommandBufferProblem`] says which.
IndirectCommandBuffer(IndirectCommandBufferProblem),
/// A rasterization-rate map's descriptor Metal stops (`new_rasterization_rate_map`).
RateMap(RateMapProblem),
@@ -1124,8 +1131,11 @@ pub enum ArchivedPipeline {
Tile,
}
/// A runtime piece a later build step adds. Each is refused typed until then: Metal itself takes
/// these inputs.
/// A runtime piece a later build step adds, or a use whose effect on Metal is not defined and the
/// runtime holds nothing exact for. Each is refused typed: Metal itself takes these inputs, so
/// none of them is misuse ([`Error::Invalid`]), and none is unmeasured
/// ([`Error::Unproven`]) — what Metal does with the input is known, and is either not built here
/// yet or not a thing to build.
#[non_exhaustive]
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum RuntimeGap {
@@ -1219,10 +1229,12 @@ pub enum RuntimeGap {
ExtensionEnable(VkExtension),
/// Render pipelines, passes and draws.
Render,
/// A 2D array over a buffer whose texels run past the buffer's length, which Metal makes
/// over bytes its buffer's allocation has past the length, or a two-plane YCbCr texture over
/// a surface's plane whose luma codes run past the buffer, which Metal reads as zeros there:
/// the runtime's buffers have no bytes there.
/// A texture over a buffer whose texels run past the buffer's length, which Metal makes over
/// bytes its buffer's allocation has past the length (a 2D texture, a texture buffer and a 2D
/// array alike, up to the allocation, past which Metal answers nil:
/// [`Problem::BufferTexture`]'s `PastAllocation`), or a texture over a plane of a surface
/// with planes whose rows or GPU texels run past the buffer standing for the surface, which
/// Metal reads as zeros there: the runtime's buffers have no bytes there.
TexelsPastBufferLength,
/// A texture of an IOSurface plane (`Buffer::new_texture_with_iosurface_plane`, the stand-in
/// for `newTextureWithDescriptor:iosurface:plane:`) whose rows overlap on Metal's GPU: more
@@ -1231,6 +1243,77 @@ pub enum RuntimeGap {
/// rows' writes meet, which one wins depends on the order of its writes (a blit's and a
/// kernel's differ).
OverlappingSurfaceRows,
/// A texture of an IOSurface plane (`Buffer::new_texture_with_iosurface_plane`, the stand-in
/// for `newTextureWithDescriptor:iosurface:plane:`) whose descriptor asks for `Memoryless`
/// storage. Metal's API validation layer asserts on it ("IOSurface textures must use
/// MTLStorageModeManaged or MTLStorageModeShared"); plain Metal makes the texture, the layer
/// off, and answers `Memoryless` with the descriptor's usage, CPU cache and hazard tracking
/// modes, over a flat surface and over a planar one's plane alike. Its CPU reaches the plane's
/// bytes as a `Shared` one's does (`getBytes` reads them, `replaceRegion` writes them); every
/// GPU use measured fails the command buffer instead (status `Error`,
/// `MTLCommandBufferErrorInvalidResource`: a kernel's `write()`, a kernel's `read()` and a
/// blit out of the texture, the plane's bytes left as they were and the read-back zero); and a
/// render pass that clears and draws into it completes and stores nothing, where a `Shared` or
/// a `Private` texture over the same plane stores its texels (an M3 Max under macOS 27.0.1).
/// The runtime holds no form that makes the object, serves its CPU exactly and fails the
/// command buffer of every GPU use, and the GPU uses beyond those three are unmeasured. A
/// texture made through `newTextureWithDescriptor:offset:bytesPerRow:` takes the buffer's
/// options whatever its descriptor names, and a plane its descriptor's other modes.
MemorylessSurfacePlane,
/// A command of an indirect command buffer at or past its size
/// (`indirectComputeCommandAtIndex:`, `indirectRenderCommandAtIndex:`). Plain Metal checks no
/// bound there, the API validation layer off: it gives a command for any index, every setter
/// of it returns, and the write lands where that index's record would be, past the buffer's
/// records. What it lands on is not defined and turns on the index: on a buffer of 4 commands,
/// writing index 4 left command 0 dispatching nothing, while writing index 100 left command 0
/// dispatching as before, and index 2^40 returned from its setters too (an M3 Max under macOS
/// 27.0.1, a buffer of `ConcurrentDispatch` and one of `Draw` alike). The runtime holds no
/// bytes there and will not guess what Metal overwrote, so there is nothing exact to build and
/// nothing to measure further: the call is refused.
IndirectCommandPastSize {
/// The command's index.
index: u64,
/// The buffer's size, in commands.
size: u64,
},
/// An `MTLIndirectCommandBufferExecutionRange` whose 8 bytes run past the buffer it is read
/// from (`execute_commands_in_buffer_indirect`, a compute encoder's and a render encoder's).
/// Metal's API validation layer stops it and plain Metal takes it: the call returns, and its
/// GPU reads whatever bytes follow the buffer, inside its allocation and past it alike, and
/// runs what they say (the pair written at offset 8 of a 12-byte buffer ran both of its
/// commands, and offset 4092 of a 4096-byte buffer, whose `allocatedSize` is its length, read
/// a pair written across its end; offsets 12 and 16 of the 12-byte buffer, and 16400 of a
/// 16384-byte one, read zeros and ran nothing; an M3 Max under macOS 27.0.1, the layer off).
/// The runtime's buffer has no bytes there and will not guess Metal's, so the call is
/// refused. An offset that is not a multiple of 4 is
/// [`ExecutionRangeOffFour`](Self::ExecutionRangeOffFour).
ExecutionRangePastBuffer {
/// The range's offset in the buffer.
offset: u64,
/// The buffer's length, in bytes.
length: u64,
},
/// An `MTLIndirectCommandBufferExecutionRange` read at an offset that is not a multiple of 4
/// bytes (`execute_commands_in_buffer_indirect`, a compute encoder's and a render encoder's).
/// Metal's API validation layer stops it and plain Metal takes it: the call returns, and what
/// its GPU does turns on the range read there. With a length of 0 the command buffer
/// completes, running nothing, as it does for an aligned range of no commands; with any other
/// length its GPU faults the command buffer, which completes with status `Error` and
/// `MTLCommandBufferErrorPageFault` ("Caused GPU Address Fault Error
/// (0000000b:kIOGPUCommandBufferCallbackErrorPageFault)") and runs nothing, for a location
/// inside the buffer's commands and one past them alike — where an aligned range whose
/// location is past them completes and reports `ReplayFaults::RANGE`
/// (offsets 1, 2, 3 and 6 of a 16-byte buffer and 2 and 1002 of a 4096-byte one, with `{0, 2}`,
/// `{1, 1}` and `{5, 2}` there, against `{0, 0}` at the same offsets and every pair at offsets
/// 0, 4, 8 and 1000; an M3 Max under macOS 27.0.1, the layer off).
///
/// The runtime reads the range at its host step, once the work before it completed, and
/// failing the command buffer from there is not built: the exact answer is the encoder faulted
/// then, and only where the range read runs a command.
ExecutionRangeOffFour {
/// The range's offset in the buffer.
offset: u64,
},
/// A render pass whose custom sample positions Vulkan takes only through what the runtime
/// does not build: a depth/stencil attachment of a caller's image not made with
/// `VK_IMAGE_CREATE_SAMPLE_LOCATIONS_COMPATIBLE_DEPTH_BIT_EXT`, of a format the device does
@@ -388,8 +388,11 @@ impl IndirectCommandBufferDescriptor {
}
}
/// What an indirect command buffer call did wrong (`Problem::IndirectCommandBuffer`): each is
/// what Metal's API validation stops, or what ends Metal's process.
/// What an indirect command buffer call did wrong (`Problem::IndirectCommandBuffer`): misuse
/// plain Metal itself refuses, ending its process or failing the call ([`Error::Invalid`]'s own
/// doc). What only Metal's API validation layer stops is not here: plain Metal takes it, so the
/// runtime takes it too, or, where no exact answer is built, names its own gap
/// ([`RuntimeGap`](crate::RuntimeGap)).
#[non_exhaustive]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum IndirectCommandBufferProblem {
@@ -410,21 +413,6 @@ pub enum IndirectCommandBufferProblem {
/// The most the runtime binds.
limit: u32,
},
/// A command at or past the buffer's size. Plain Metal checks no bound there, the API
/// validation layer off: `indirectComputeCommandAtIndex:` and `indirectRenderCommandAtIndex:`
/// give a command for any index, every setter of it returns, and the write lands where that
/// index's record would be, past the buffer's records. What it lands on is not defined and
/// turns on the index: on a buffer of 4 commands, writing index 4 left command 0 dispatching
/// nothing, while writing index 100 left command 0 dispatching as before, and index 2^40
/// returned from its setters too (an M3 Max under macOS 27.0.1, a buffer of
/// `ConcurrentDispatch` and one of `Draw` alike). The runtime holds no bytes there and will
/// not guess what Metal overwrote, so it refuses the call.
CommandIndex {
/// The command's index.
index: u64,
/// The buffer's size, in commands.
size: u64,
},
/// A range of commands not inside the buffer: for `reset_with_range`, one that starts at or
/// past its size (an empty one too, but the empty one at the size) or ends past it; for the
/// read-back, one that ends past it.
@@ -452,16 +440,6 @@ pub enum IndirectCommandBufferProblem {
/// not enabled on this indirect command buffer"), but plain Metal runs one their records hold,
/// as the runtime does.
CommandType(IndirectCommandType),
/// An execution range read from a buffer (`execute_commands_in_buffer_indirect`) at an
/// `offset` that is not a multiple of 4 bytes, or whose 8 bytes run past the buffer's
/// `length`. Metal's validation stops neither, but what it reads is not defined: its GPU
/// faulted the command buffer at an offset of 2.
RangeBuffer {
/// The range's offset in the buffer.
offset: u64,
/// The buffer's length.
length: u64,
},
/// A compute command of a buffer whose commands are render ones, or a setter plain Metal does
/// not ignore on a render command of a buffer whose commands are dispatches. Plain Metal ends
/// its process at each, the API validation layer off: `indirectComputeCommandAtIndex:` on a
@@ -1557,12 +1535,13 @@ impl IndirectCommandBuffer {
lock(&self.device().shared().addresses).holds_records_slot(self.0.id.held)
}
/// `indirectComputeCommandAtIndex:`: command `index`'s setters. Refused (`Invalid`): an index
/// at or past the size, which plain Metal takes and writes past its records
/// (`CommandIndex`); a buffer of render command types
/// (`CommandKind`), which ends Metal's process. A `Private` buffer's commands are encoded
/// here too, as plain Metal encodes, reads back and runs them where its validation stops the
/// call (an M3 Max and an M4).
/// `indirectComputeCommandAtIndex:`: command `index`'s setters. Refused (`Invalid`): a buffer
/// of render command types (`CommandKind`), which ends Metal's process. An index at or past
/// the size, which plain Metal takes and writes past its records, is
/// `NotImplemented(IndirectCommandPastSize)`: the runtime holds no bytes there, and what
/// Metal's write lands on is not defined. A `Private` buffer's commands are encoded here too,
/// as plain Metal encodes, reads back and runs them where its validation stops the call (an M3
/// Max and an M4).
pub fn indirect_compute_command_at(&self, index: u64) -> Result<IndirectComputeCommand, Error> {
const CALL: &str = "indirect_compute_command_at";
let index = self.command_at(CALL, index, false)?;
@@ -1588,20 +1567,18 @@ impl IndirectCommandBuffer {
/// Command `index` for `call`, of a buffer whose commands are render ones where `render`:
/// refused (`Invalid`) for a buffer of the other kind's commands (but a render command of a
/// buffer of dispatches alone), a buffer of no command types, and an index at or past the
/// size. A `Private` buffer's commands are the CPU's as a `Shared` one's are, as plain Metal
/// encodes, reads back and runs them.
/// buffer of dispatches alone) and a buffer of no command types, and
/// `NotImplemented(IndirectCommandPastSize)` for an index at or past the size. A `Private`
/// buffer's commands are the CPU's as a `Shared` one's are, as plain Metal encodes, reads back
/// and runs them.
fn command_at(&self, call: &'static str, index: u64, render: bool) -> Result<u32, Error> {
self.check_command_types(call)?;
self.check_kind(call, render)?;
if index >= u64::from(self.0.size) {
return Err(problem(
call,
IndirectCommandBufferProblem::CommandIndex {
index,
size: self.size(),
},
));
return Err(Error::NotImplemented(RuntimeGap::IndirectCommandPastSize {
index,
size: self.size(),
}));
}
Ok(index as u32)
}
@@ -87,7 +87,7 @@ use super::compute::{
use super::degradation::Degradation;
use super::device::lock;
use super::encoder::{EncoderCore, RecordedSegment};
use super::error::{internal, invalid, Error, Problem};
use super::error::{internal, invalid, Error, Problem, RuntimeGap};
use super::executed_commands::{ExecutedCommand, RecordsRead};
use super::indirect_command_buffer::{
IndirectCommandBuffer, IndirectCommandBufferProblem, IndirectCommandCheck,
@@ -116,28 +116,27 @@ pub(super) const CALL_INDIRECT: &str = "execute_commands_in_buffer_indirect";
/// The bytes of an `MTLIndirectCommandBufferExecutionRange`: `location`, then `length`.
pub(super) const RANGE_BYTES: u64 = 8;
/// Refuse the execution range at `offset` of a buffer of `length` bytes where Metal's reading of
/// it is not defined (`execute_commands_in_buffer_indirect`; where API
/// validation stops neither): an offset that is not a multiple of 4 bytes, at which Metal's GPU
/// faulted the command buffer, and a range whose 8 bytes run past the buffer, which Metal reads
/// from whatever follows it.
pub(super) fn check_range_buffer(
call: &'static str,
length: u64,
offset: u64,
) -> Result<(), Error> {
/// Refuse the execution range at `offset` of a buffer of `length` bytes where the runtime has no
/// exact answer (`execute_commands_in_buffer_indirect`). Metal's API validation layer stops
/// neither rule below and plain Metal refuses neither: the call always returns (an M3 Max under
/// macOS 27.0.1 with the layer off, `rangebuf.m`, `rangebuf2.m` and `rangebuf3.m`, one case per
/// process, on a compute encoder's dispatches and a render encoder's draws alike). Both are the
/// runtime's own gaps ([`RuntimeGap::ExecutionRangePastBuffer`],
/// [`RuntimeGap::ExecutionRangeOffFour`], which carry the measurements).
pub(super) fn check_range_buffer(length: u64, offset: u64) -> Result<(), Error> {
let past = offset
.checked_add(RANGE_BYTES)
.is_none_or(|end| end > length);
if !offset.is_multiple_of(4) || past {
return Err(invalid(
call,
Problem::IndirectCommandBuffer(IndirectCommandBufferProblem::RangeBuffer {
offset,
length,
}),
if past {
return Err(Error::NotImplemented(
RuntimeGap::ExecutionRangePastBuffer { offset, length },
));
}
if !offset.is_multiple_of(4) {
return Err(Error::NotImplemented(RuntimeGap::ExecutionRangeOffFour {
offset,
}));
}
Ok(())
}
+58 -53
View File
@@ -4,8 +4,8 @@
//!
//! **Metal's rules** (probes 9 to 9f, on an Apple M3 Max, macOS 26.7, and an M4, macOS 27.0.1,
//! which agree; each case run plain and under API validation). The runtime refuses as `Invalid`
//! what Metal asserts on in either run and what its validation alone stops, and as `Nil` what
//! plain Metal answers nil for:
//! what Metal asserts on in a plain run, and as `Nil` what plain Metal answers nil for; what only
//! its API validation layer stops is no refusal, since plain Metal takes it:
//!
//! - **Formats.** `minimumLinearTextureAlignmentForPixelFormat:` and
//! `minimumTextureBufferAlignmentForPixelFormat:` are both 16 bytes for every format a buffer
@@ -34,13 +34,19 @@
//! each slice starts `bytesPerRow` × `height`, rounded up to 128, after the one before. Metal's
//! validation alone asserts that it is a multiple of 128; a plain run makes the array at any (16,
//! 32, 64, 80 and 192 measured, probe 9b), so the runtime does too.
//! - **Length.** Validation counts `offset + bytesPerRow × (height × slices − 1) + the packed row`
//! against the buffer's length: for an array, as if its slices were not rounded. Where an
//! array's last slice still runs past the length, Metal answers nil when the buffer is at least
//! 16 KiB and its rounded slices end past the length rounded up to 16 KiB (its
//! `allocatedSize`), and otherwise makes the texture over bytes past the length. The runtime's
//! buffers have no bytes there, so it refuses that texture as not implemented
//! ([`BufferRefusal::TexelsPastLength`]).
//! - **Length.** Metal's validation counts `offset + bytesPerRow × (height × slices − 1) + the
//! packed row` against the buffer's length, for an array as if its slices were not rounded, and
//! stops a texture whose count runs past it; plain Metal reads the buffer's `allocatedSize`
//! alone. It answers nil where the buffer is at least 16 KiB and the texture's rounded slices
//! end past the length rounded up to 16 KiB (its `allocatedSize`), and otherwise makes the
//! texture over bytes past the length, however far past (an M3 Max under macOS 27.0.1, the
//! layer off: a 2D texture and a texture buffer over a 4096-byte buffer whose rows end 128 and
//! 12288 bytes past it are made, as is one over a 20000-byte buffer, `allocatedSize` 32768,
//! from offset 20000; the same ending past 32768 is nil, and so is one over a 16384-byte
//! buffer, `allocatedSize` 16384, ending at 16640, where one ending at 16384 is made). The
//! runtime's buffers have no bytes past the length, so it refuses that texture as not
//! implemented ([`BufferRefusal::TexelsPastLength`]) and the nil one as Metal's nil
//! ([`BufferTextureProblem::PastAllocation`]).
//!
//! **IOSurface planes** (`Buffer::new_texture_with_iosurface_plane`, the stand-in for
//! `newTextureWithDescriptor:iosurface:plane:` over the caller's memory). Measured on the M3 Max
@@ -64,8 +70,10 @@
//! write the surface's bytes as a `Shared` one's do, so the runtime makes it too. A plain run
//! makes a `Memoryless` one too, whose CPU reaches the plane's bytes while its GPU uses fail the
//! command buffer and a render pass into it stores nothing; the runtime holds no form that
//! answers all three, so it refuses that texture
//! ([`BufferTextureProblem::Options`], which carries the measurement).
//! answers all three, so it refuses that texture as not implemented
//! ([`BufferRefusal::MemorylessPlane`],
//! [`RuntimeGap::MemorylessSurfacePlane`](crate::RuntimeGap::MemorylessSurfacePlane), which
//! carries the measurement).
//! - **The CPU** (`getBytes`, `replaceRegion`) reads and writes the plane where the surface lays it
//! out: from its offset, rows `bytesPerRow` apart.
//! - **The GPU** (a blit's reads and writes, a copy to or from another texture, a kernel's
@@ -115,8 +123,9 @@
//! The runtime holds both layouts: the GPU's ([`Placed::gpu`]) is the texture's texels for every
//! command, the copies of its shadow, an aliasing image and their hazards; the CPU's
//! ([`Placed::cpu`]) is `replace_region`'s and `get_bytes`'s. Both lie in the buffer, else the
//! texture is refused: a plane past the buffer `Invalid` (`PastBuffer`), GPU texels past it
//! `NotImplemented` (`TexelsPastBufferLength`; Metal's lie in the surface's pages past the plane).
//! texture is refused: a plane past the buffer `NotImplemented` (`TexelsPastBufferLength`;
//! Metal's lie in the surface's pages past the plane, where it reads zeros), and over a surface
//! without planes, which plain Metal holds the rows to, `Invalid` (`PastBuffer`).
//! A surface without planes starts at a multiple of 16 in the buffer, as a surface's base does
//! (`OffsetAlignment` otherwise).
//!
@@ -157,7 +166,9 @@ pub(super) const ARRAY_ALIGNMENT: u64 = 128;
/// rounded up to it (a shorter buffer's is its length).
pub(super) const METAL_PAGE: u64 = 16384;
/// A texture over a buffer Metal stops.
/// A texture over a buffer plain Metal itself refuses: it asserts, or answers nil
/// ([`PastAllocation`](Self::PastAllocation)). What only Metal's API validation layer stops is
/// not here (the module's rules).
#[non_exhaustive]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum BufferTextureProblem {
@@ -176,22 +187,6 @@ pub enum BufferTextureProblem {
/// The descriptor's level count.
count: u32,
},
/// An IOSurface plane's `Memoryless` storage. Metal's API validation layer asserts on it
/// ("IOSurface textures must use MTLStorageModeManaged or MTLStorageModeShared"); plain Metal
/// makes the texture, the layer off, and answers `Memoryless` with the descriptor's usage, CPU
/// cache and hazard tracking modes, over a flat surface and over a planar one's plane alike.
/// Its CPU reaches the plane's bytes as a `Shared` one's does (`getBytes` reads them,
/// `replaceRegion` writes them); every GPU use measured fails the command buffer instead
/// (status `Error`, `MTLCommandBufferErrorInvalidResource`: a kernel's `write()`, a kernel's
/// `read()` and a blit out of the texture, the plane's bytes left as they were and the
/// read-back zero); and a render pass that clears and draws into it completes and stores
/// nothing, where a `Shared` or a `Private` texture over the same plane stores its texels (an
/// M3 Max under macOS 27.0.1). The runtime refuses the texture: it holds no form that makes
/// the object, serves its CPU exactly and fails the command buffer of every GPU use, and the
/// GPU uses beyond those three are unmeasured. A texture made through
/// `newTextureWithDescriptor:offset:bytesPerRow:` takes the buffer's options whatever its
/// descriptor names, and a plane its descriptor's other modes.
Options,
/// A `bytesPerRow` that does not cover the packed row of `row_bytes`.
RowPitch {
/// The `bytesPerRow` given.
@@ -215,9 +210,20 @@ pub enum BufferTextureProblem {
/// The alignment it needs, in bytes.
alignment: u64,
},
/// Validation's count of the texture's bytes, `counted`, past the buffer's `length`.
/// A texture over a surface without planes whose rows end past the surface's bytes,
/// `counted` of the `length` the buffer standing for it holds: a descriptor taller than the
/// surface, which plain Metal asserts on, the API validation layer off (`-[IOGPUMetalTexture
/// initWithDevice:descriptor:iosurface:plane:field:args:argsSize:]`, "Descriptor
/// height*arrayLength > IOSurface height": a 16 by 8 and a 16 by 64 descriptor over a 16 by 4
/// `BGRA` surface, on an M3 Max under macOS 27.0.1, where the 16 by 4 one is made).
///
/// A *plane* of a surface with planes is not held to it: Metal makes a texture taller than
/// the plane and reads zeros past it, which the runtime's buffer has no bytes for
/// ([`RuntimeGap::TexelsPastBufferLength`](crate::RuntimeGap::TexelsPastBufferLength)), and a
/// texture over a buffer past its bytes Metal makes or answers nil for by the buffer's
/// allocation alone (the module's **Length**).
PastBuffer {
/// The bytes validation counts.
/// The bytes the rows end at, from the buffer's start.
counted: u64,
/// The buffer's length.
length: u64,
@@ -384,6 +390,10 @@ pub(super) enum BufferRefusal {
/// An IOSurface plane whose rows overlap on Metal's GPU, where a write's bytes depend on the
/// order it writes rows in (`NotImplemented`; the module's rules).
OverlappingRows,
/// An IOSurface plane whose descriptor asks for `Memoryless` storage, which plain Metal makes
/// and serves on the CPU while every GPU use fails the command buffer (`NotImplemented`; the
/// module's rules).
MemorylessPlane,
}
impl From<BufferTextureProblem> for BufferRefusal {
@@ -431,7 +441,7 @@ pub(super) fn plan_buffer_texture(
.into());
}
if surface && texture.storage == StorageMode::Memoryless {
return Err(P::Options.into());
return Err(BufferRefusal::MemorylessPlane);
}
let [width, height, _] = layout.extent.map(u64::from);
let (offset, bytes_per_row) = (texture.offset, texture.bytes_per_row);
@@ -455,12 +465,7 @@ pub(super) fn plan_buffer_texture(
rows: height,
slices: 1,
};
return match plan_iosurface_plane(cpu, planar, buffer.length) {
Err(BufferRefusal::Metal(P::PastBuffer { .. })) if ycbcr => {
Err(BufferRefusal::TexelsPastLength)
}
planned => planned,
};
return plan_iosurface_plane(cpu, planar, buffer.length);
}
let array = texture_type == T::Type2DArray;
let alignment = if array {
@@ -497,15 +502,9 @@ pub(super) fn plan_buffer_texture(
slices,
};
let length = buffer.length;
// Validation's count: the slices' rows as if contiguous.
let counted = BufferLayout {
slice_pitch: image,
..placed
}
.end();
if counted > length {
return Err(P::PastBuffer { counted, length }.into());
}
// Metal's validation counts the slices' rows as if contiguous against the length and stops
// the texture there; plain Metal reads the buffer's allocation alone (the module's
// **Length**), so the runtime does too.
if placed.end() > length {
let end = offset.saturating_add(slice_pitch.saturating_mul(slices));
if length >= METAL_PAGE {
@@ -545,12 +544,18 @@ fn plan_iosurface_plane(
}
.into());
}
// A surface without planes holds the texture's rows: plain Metal asserts on a descriptor
// taller than it (`P::PastBuffer`). Over a plane Metal makes such a texture and reads zeros
// past the plane, which the runtime's buffer has no bytes for.
if cpu.end() > length {
return Err(P::PastBuffer {
counted: cpu.end(),
length,
}
.into());
return Err(match planar {
true => BufferRefusal::TexelsPastLength,
false => P::PastBuffer {
counted: cpu.end(),
length,
}
.into(),
});
}
let gpu = iosurface_gpu_layout(&cpu)?;
if gpu.end() > length {
@@ -247,10 +247,12 @@
//! a buffer whose location lies past the size, or that passes `2^32 - 1`, runs nothing (`RANGE`):
//! Metal's GPU faults the command buffer.
//! - **What is refused.** At the call (`Invalid`): a buffer of another device, a range past the
//! size, an inherited pipeline state that is unset or made without
//! `supportIndirectCommandBuffers` (Metal's validation stops each), and a range read from a
//! buffer at an offset that is not a multiple of 4 bytes or whose 8 bytes run past the buffer
//! (`RangeBuffer`, as a compute encoder's). A buffer of compute commands, and a range read
//! size, and an inherited pipeline state that is unset or made without
//! `supportIndirectCommandBuffers` (Metal's validation stops each). A range read from a buffer
//! at an offset that is not a multiple of 4 bytes, and one whose 8 bytes run past the buffer,
//! are the runtime's own gaps, as a compute encoder's are
//! (`NotImplemented(ExecutionRangeOffFour)` and `NotImplemented(ExecutionRangePastBuffer)`).
//! A buffer of compute commands, and a range read
//! from a buffer that a draw of the encoder before the call may write, are
//! `NotImplemented(IndirectRenderCommands)`. What a command's draw refuses (a pipeline of
//! other formats than the pass's, among others) is refused so: it either refuses the commit,
@@ -460,7 +462,7 @@ impl RenderLowering {
if !icb.is_render() {
return Err(Error::NotImplemented(RuntimeGap::IndirectRenderCommands));
}
indirect_execute::check_range_buffer(CALL_INDIRECT, range_buffer.length(), offset)?;
indirect_execute::check_range_buffer(range_buffer.length(), offset)?;
// Not in a pass of several color groups (`render/color_groups.rs`).
self.check_group_execution()?;
let pipeline = match self.inherited_pipeline(CALL_INDIRECT, icb)? {
@@ -843,12 +845,15 @@ impl RenderCommandEncoder {
/// encoder wrote is read; a host step records the pass once the work before it completed, which
/// the device announces once (`Degradation::HostReplayedIndirectCommands`).
///
/// A range plain Metal takes and the runtime has no exact answer for is its own gap, not
/// misuse: 8 bytes that run past `range_buffer`, which Metal reads from whatever follows it
/// (`NotImplemented(ExecutionRangePastBuffer)`), and an `offset` that is not a multiple of 4
/// bytes, which Metal's GPU faults the command buffer over where the range read there runs a
/// command (`NotImplemented(ExecutionRangeOffFour)`; both carry the measurement).
///
/// Refused, changing nothing: what
/// [`execute_commands_in_buffer`](Self::execute_commands_in_buffer) refuses but a range (an
/// unset inherited state whatever the range); a range buffer of another device, and a range
/// Metal's reading of is not defined (`Invalid`, `IndirectCommandBufferProblem::RangeBuffer`):
/// an offset that is not a multiple of 4 bytes, at which Metal's GPU faulted, or 8 bytes that
/// run past `range_buffer`, which Metal reads from whatever follows it. A range a draw of the
/// unset inherited state whatever the range), and a range buffer of another device. A range a draw of the
/// encoder before the call may write is `NotImplemented(IndirectRenderCommands)`: Metal's
/// execution reads that draw's write, where the runtime's copy, made before the pass, would
/// not; as for the index bounds pass, an untracked buffer's writes are not seen. Under an
@@ -1,6 +1,7 @@
//! `Error::Invalid` is what Metal's validation stops, ending the process, and `Error::Nil` what
//! plain Metal answers nil for. These tests walk the runtime's own sources: every refusal its docs
//! label `Invalid`, and every problem a call refuses `Invalid`, checking that none is one Metal is
//! `Error::Invalid` is misuse plain Metal itself refuses, and `Error::Nil` what plain Metal
//! answers nil for; Metal's API validation layer is not Metal, so a rule only the layer stops is
//! no refusal at all. These tests walk the runtime's own sources: every refusal its docs label
//! `Invalid`, and every problem a call refuses `Invalid`, checking that none is one Metal is
//! documented to answer nil for.
use std::collections::BTreeSet;
@@ -138,3 +138,42 @@ fn a_buffer_answers_metal_s_allocated_size() {
assert_eq!(metal_allocated_size(&descriptor, 0), 16384, "types {types}");
}
}
/// An execution range read from a buffer, as measured on an Apple M3 Max under macOS 27.0.1 with
/// the API validation layer off (`rangebuf.m`, `rangebuf2.m`, `rangebuf3.m`, one case per process,
/// on a compute encoder's dispatches and a render encoder's draws alike): plain Metal refuses
/// neither of the two rules below, so neither is misuse. Both are the runtime's own gaps.
#[test]
fn an_execution_range_metal_takes_is_the_runtime_s_gap() {
use crate::error::{Error, RuntimeGap};
use crate::indirect_execute::check_range_buffer;
// Aligned and inside the buffer: taken, as Metal takes it.
for offset in [0, 4, 8, 1000, 4088] {
check_range_buffer(4096, offset).unwrap();
}
// An offset that is not a multiple of 4: Metal's GPU faults the command buffer where the
// range read there runs a command, and completes where it runs none.
for offset in [1, 2, 3, 6, 1002] {
assert_eq!(
check_range_buffer(4096, offset).unwrap_err(),
Error::NotImplemented(RuntimeGap::ExecutionRangeOffFour { offset }),
"offset {offset}"
);
}
// 8 bytes that run past the buffer: Metal reads whatever bytes follow it.
for (length, offset) in [(12, 8), (12, 12), (12, 16), (16384, 16400), (4096, 4092)] {
assert_eq!(
check_range_buffer(length, offset).unwrap_err(),
Error::NotImplemented(RuntimeGap::ExecutionRangePastBuffer { offset, length }),
"{offset} of {length}"
);
}
// An offset whose 8 bytes overflow is past the buffer, not off four.
assert_eq!(
check_range_buffer(16, u64::MAX - 3).unwrap_err(),
Error::NotImplemented(RuntimeGap::ExecutionRangePastBuffer {
offset: u64::MAX - 3,
length: 16,
})
);
}
@@ -384,21 +384,17 @@ fn two_dimensional_textures_and_texture_buffers_follow_metal() {
),
// The length: the last row's packed bytes may end on the buffer's end.
(texture(8, 4, 3872, 64, 4096), made(3872, 64, 4, 32)),
// Plain Metal makes a texture whose rows end past the length of a buffer under 16 KiB,
// whose `allocatedSize` is its length; the runtime has no bytes there (`past.m`).
(
texture(8, 4, 3888, 64, 4096),
refused(Pr::PastBuffer {
counted: 4112,
length: 4096,
}),
Err(BufferRefusal::TexelsPastLength),
),
(texture(8, 4, 3856, 64, 4096), made(3856, 64, 4, 32)),
(texture(8, 4, 3920, 48, 4096), made(3920, 48, 4, 32)),
(
texture(4, 1, 4096, 16, 4096),
refused(Pr::PastBuffer {
counted: 4112,
length: 4096,
}),
Err(BufferRefusal::TexelsPastLength),
),
// Offsets and pitches are multiples of 16.
(
@@ -506,17 +502,11 @@ fn two_dimensional_textures_and_texture_buffers_follow_metal() {
),
(
texture_buffer(64, 3856, 256, 4096),
refused(Pr::PastBuffer {
counted: 4112,
length: 4096,
}),
Err(BufferRefusal::TexelsPastLength),
),
(
texture_buffer(1024, 16, 4096, 4096),
refused(Pr::PastBuffer {
counted: 4112,
length: 4096,
}),
Err(BufferRefusal::TexelsPastLength),
),
// Through the SPI, a 2D texture keeps the 2D rules.
(
@@ -531,10 +521,7 @@ fn two_dimensional_textures_and_texture_buffers_follow_metal() {
call: BufferTextureCall::Linear,
..texture(4, 4, 0, 32, 111)
},
refused(Pr::PastBuffer {
counted: 112,
length: 111,
}),
Err(BufferRefusal::TexelsPastLength),
),
(
Case {
@@ -571,7 +558,7 @@ fn only_a_memoryless_plane_is_refused_its_storage_mode() {
};
let surface = matches!(call, BufferTextureCall::IoSurfacePlane { .. });
let want = if surface && storage == Memoryless {
Err(BufferRefusal::Metal(BufferTextureProblem::Options))
Err(BufferRefusal::MemorylessPlane)
} else {
Ok(())
};
@@ -642,15 +629,14 @@ fn an_arrays_slices_start_at_metals_own_stride() {
);
}
/// Where an array may end (probes 9b, 9c, 9e and 9f): validation counts its rows as if its
/// slices were not rounded; Metal answers nil where a buffer of at least 16 KiB has the rounded
/// slices end past its `allocatedSize`; elsewhere it makes an array whose last slice runs past
/// the length, which the runtime refuses as not implemented.
/// Where an array may end (probes 9b, 9c, 9e and 9f): Metal answers nil where a buffer of at
/// least 16 KiB has the rounded slices end past its `allocatedSize`; elsewhere it makes an array
/// whose last slice runs past the length, which the runtime refuses as not implemented. Its
/// validation's own count, the rows as if the slices were not rounded, is no refusal: every case
/// marked so below is one the count stops and plain Metal makes.
#[test]
fn an_array_ends_where_metal_lets_it() {
use BufferTextureProblem as Pr;
let past =
|counted, length| Err::<(), _>(BufferRefusal::Metal(Pr::PastBuffer { counted, length }));
let nil = |end, allocation| {
Err::<(), _>(BufferRefusal::Metal(Pr::PastAllocation { end, allocation }))
};
@@ -658,7 +644,7 @@ fn an_array_ends_where_metal_lets_it() {
let ok = |case: Case| plan(case).map(|_| ());
let cases = [
// Two 4x4 slices at bytesPerRow 16 from 16128 (a 64-byte image, a 128-byte stride).
(array((4, 4, 2), 16128, 16, 16255), past(16256, 16255)),
(array((4, 4, 2), 16128, 16, 16255), gap), // counted past
(array((4, 4, 2), 16128, 16, 16256), gap),
(array((4, 4, 2), 16128, 16, 16319), gap),
(array((4, 4, 2), 16128, 16, 16320), Ok(())),
@@ -667,22 +653,22 @@ fn an_array_ends_where_metal_lets_it() {
(array((4, 4, 2), 16256, 16, 16384), nil(16512, 16384)),
(array((4, 4, 2), 16256, 16, 16385), gap),
(array((4, 4, 2), 16256, 16, 16512), Ok(())),
(array((4, 4, 2), 16384, 16, 16385), past(16512, 16385)),
(array((4, 4, 2), 16384, 16, 16385), gap), // counted past
(array((4, 4, 2), 32640, 16, 32768), nil(32896, 32768)),
// Small buffers: made past the length whatever the rounded slices' end.
(array((4, 4, 2), 0, 16, 64), past(128, 64)),
(array((4, 4, 2), 0, 16, 127), past(128, 127)),
(array((4, 4, 2), 0, 16, 64), gap), // counted past
(array((4, 4, 2), 0, 16, 127), gap), // counted past
(array((4, 4, 2), 0, 16, 128), gap),
(array((4, 4, 2), 0, 16, 191), gap),
(array((4, 4, 2), 0, 16, 192), Ok(())),
(array((4, 4, 3), 0, 16, 300), gap),
(array((4, 4, 64), 0, 16, 4096), gap),
(array((4, 4, 128), 0, 16, 4096), past(8192, 4096)),
(array((4, 4, 129), 0, 16, 4096), past(8256, 4096)),
(array((4, 4, 128), 0, 16, 4096), gap), // counted past
(array((4, 4, 129), 0, 16, 4096), gap), // counted past
// bytesPerRow above the packed row: validation counts the last row's packed bytes.
(array((4, 4, 2), 0, 32, 239), past(240, 239)),
(array((4, 4, 2), 0, 32, 239), gap), // counted past
(array((4, 4, 2), 0, 32, 240), Ok(())),
(array((4, 3, 3), 0, 48, 399), past(400, 399)),
(array((4, 3, 3), 0, 48, 399), gap), // counted past
(array((4, 3, 3), 0, 48, 400), gap),
(array((4, 3, 3), 0, 48, 432), gap),
];
@@ -691,6 +677,41 @@ fn an_array_ends_where_metal_lets_it() {
}
}
/// A 2D texture's and a texture buffer's own end, measured on an Apple M3 Max under macOS 27.0.1
/// with the API validation layer off (`past.m`, one case per process): plain Metal makes the
/// texture whenever its rows end inside the buffer's `allocatedSize`, however far past the
/// `length` they run, and answers nil only past the allocation. Metal's validation counts those
/// rows against the `length` and stops every case here but the two made ones; that count is the
/// layer's alone, so the runtime does not refuse by it.
#[test]
fn a_texture_over_a_buffer_ends_where_metals_allocation_does() {
use BufferTextureProblem as Pr;
let gap = Err::<(), _>(BufferRefusal::TexelsPastLength);
let nil = |end, allocation| {
Err::<(), _>(BufferRefusal::Metal(Pr::PastAllocation { end, allocation }))
};
let ok = |case: Case| plan(case).map(|_| ());
// Each row is `texture(width, height, offset, bytes_per_row, length)` as the probe ran it, in
// RGBA8Unorm: 64 texels are a 256-byte row.
let cases = [
// A 4096-byte buffer, whose `allocatedSize` is its length: made 128 and 12288 bytes past.
(texture_buffer(64, 3968, 256, 4096), gap),
(texture(64, 1, 3968, 256, 4096), gap),
(texture(64, 64, 0, 256, 4096), gap),
// A 20000-byte buffer, `allocatedSize` 32768: made inside the allocation, nil past it.
(texture(64, 4, 19200, 256, 20000), gap),
(texture_buffer(64, 20000, 256, 20000), gap),
(texture(64, 4, 32000, 256, 20000), nil(33024, 32768)),
(texture_buffer(64, 32700, 256, 20000), nil(32956, 32768)),
// A 16384-byte buffer, whose `allocatedSize` is its length: the last row may end on it.
(texture(64, 4, 15616, 256, 16384), nil(16640, 16384)),
(texture(64, 4, 15360, 256, 16384), Ok(())),
];
for (case, want) in cases {
assert_eq!(ok(case), want, "{case:?}");
}
}
/// A linear image aliases a texture's place in its buffer only where every one of its reports
/// is Metal's layout's, and its subresources hold no byte but the texture's texels.
#[test]
@@ -1413,11 +1434,19 @@ fn iosurface_planes_lie_where_metal_puts_them() {
row_bytes: 4,
}),
),
// A plane of a surface with planes whose rows end past the buffer: plain Metal makes such
// a texture and reads zeros past the plane, which the runtime has no bytes for. Over a
// surface without planes plain Metal asserts on it ("Descriptor height*arrayLength >
// IOSurface height"), so the runtime refuses the same shape `Invalid` there (`past.m`).
(
plane(r8, (4, 4), (0, 4), true, 15),
Err(BufferRefusal::TexelsPastLength),
),
(
plane(r8, (4, 4), (0, 16), false, 48),
refused(Pr::PastBuffer {
counted: 16,
length: 15,
counted: 52,
length: 48,
}),
),
(
@@ -1505,7 +1534,7 @@ fn a_planar_surface_s_depth_or_stencil_texture_is_laid_out_as_a_colour_one() {
};
assert_eq!(
placed(memoryless).map(|_| ()),
Err(BufferRefusal::Metal(BufferTextureProblem::Options)),
Err(BufferRefusal::MemorylessPlane),
"{pf:?}"
);
}
@@ -1703,11 +1703,8 @@ fn iosurface_planes_take_their_descriptors_options() {
held.buffer
.new_texture_with_iosurface_plane(&d, OPTIONS_PLANE)
.err(),
Some(Error::Invalid(Invalid::new(
"new_texture_with_iosurface_plane",
Problem::BufferTexture(BufferTextureProblem::Options),
))),
"{kind:?}: a memoryless plane"
Some(Error::NotImplemented(RuntimeGap::MemorylessSurfacePlane)),
"{kind:?}: a memoryless plane, which plain Metal makes"
);
}
});
@@ -91,15 +91,12 @@ fn textures_over_buffers_are_made_or_refused_as_metal_makes_them() {
}
)
);
// A texture buffer whose row ends past the buffer's length, which Metal's validation
// counts and stops: plain Metal makes it over bytes past the length, which the runtime's
// buffer does not have (`past.m`, an M3 Max under macOS 27.0.1).
assert_eq!(
refused(&d, 3968, 256),
invalid(
CALL,
BufferTextureProblem::PastBuffer {
counted: 4224,
length: 4096
}
)
Error::NotImplemented(RuntimeGap::TexelsPastBufferLength)
);
// A plain run takes the buffer's options whatever the descriptor names.
let mut private = d;
@@ -923,10 +923,7 @@ fn setters_refuse_what_metal_refuses() {
let made = icb(device, &compute_descriptor(), 2);
assert_eq!(
made.indirect_compute_command_at(2).unwrap_err(),
icb_problem(
"indirect_compute_command_at",
IndirectCommandBufferProblem::CommandIndex { index: 2, size: 2 }
)
Error::NotImplemented(RuntimeGap::IndirectCommandPastSize { index: 2, size: 2 })
);
// A `Private` buffer's commands are the CPU's, as plain Metal encodes and reads them back.
let private = device
@@ -2313,10 +2310,7 @@ fn render_setters_refuse_what_metal_refuses() {
mixed.indirect_compute_command_at(0).unwrap();
assert_eq!(
made.indirect_render_command_at(2).unwrap_err(),
icb_problem(
"indirect_render_command_at",
IndirectCommandBufferProblem::CommandIndex { index: 2, size: 2 }
)
Error::NotImplemented(RuntimeGap::IndirectCommandPastSize { index: 2, size: 2 })
);
let first = made.indirect_render_command_at(0).unwrap();
assert_eq!(
@@ -1066,18 +1066,26 @@ fn an_execution_reads_its_range_as_it_runs() {
let range = range_buffer(device, 1, 2);
let command_buffer = queue.command_buffer().unwrap();
let mut encoder = command_buffer.compute_command_encoder().unwrap();
for (offset, length) in [(2, 16), (12, 16), (u64::MAX - 3, 16)] {
// Plain Metal takes both, so neither is misuse: the runtime's own gaps.
for offset in [2, 6] {
assert_eq!(
encoder
.execute_commands_in_buffer_indirect(&setup.icb, &range, offset)
.err(),
Some(Error::Invalid(Invalid::new(
"execute_commands_in_buffer_indirect",
Problem::IndirectCommandBuffer(IndirectCommandBufferProblem::RangeBuffer {
offset,
length,
})
))),
Some(Error::NotImplemented(RuntimeGap::ExecutionRangeOffFour {
offset
})),
"offset {offset}"
);
}
for (offset, length) in [(12, 16), (u64::MAX - 3, 16)] {
assert_eq!(
encoder
.execute_commands_in_buffer_indirect(&setup.icb, &range, offset)
.err(),
Some(Error::NotImplemented(
RuntimeGap::ExecutionRangePastBuffer { offset, length }
)),
"offset {offset}"
);
}
@@ -1771,11 +1771,12 @@ fn a_render_execution_reads_its_range_from_a_buffer_as_metal_s_does() {
});
}
/// Refused at the call, recording nothing (a probe, an M3 Max and an M4): a range at an offset that
/// is not a multiple of 4 bytes (Metal's GPU faulted the command buffer) or whose 8 bytes run past
/// its buffer (Metal reads whatever follows it; here it ran nothing), a buffer of compute commands,
/// and a range a draw of the encoder before the call wrote, which Metal's execution reads and the
/// runtime's copy before the pass would not.
/// Refused at the call, recording nothing (a probe, an M3 Max and an M4): a range at an offset
/// that is not a multiple of 4 bytes, which Metal's GPU faults the command buffer over where the
/// range read there runs a command, or whose 8 bytes run past its buffer, which Metal reads from
/// whatever follows it — plain Metal takes both calls, so both are the runtime's own gaps, not
/// misuse; a buffer of compute commands; and a range a draw of the encoder before the call wrote,
/// which Metal's execution reads and the runtime's copy before the pass would not.
#[test]
fn a_render_execution_s_range_is_refused_where_metal_s_read_is_not_the_copy_s() {
on_device(|device, _| {
@@ -1788,18 +1789,25 @@ fn a_render_execution_s_range_is_refused_where_metal_s_read_is_not_the_copy_s()
let queue = device.new_command_queue().unwrap();
let command_buffer = queue.command_buffer().unwrap();
let mut encoder = command_buffer.render_command_encoder(&pass()).unwrap();
for (offset, length) in [(2, 16), (12, 16), (u64::MAX - 3, 16)] {
for offset in [2, 6] {
assert_eq!(
encoder
.execute_commands_in_buffer_indirect(&icb, &range, offset)
.err(),
Some(Error::Invalid(Invalid::new(
"execute_commands_in_buffer_indirect",
Problem::IndirectCommandBuffer(IndirectCommandBufferProblem::RangeBuffer {
offset,
length,
})
))),
Some(Error::NotImplemented(RuntimeGap::ExecutionRangeOffFour {
offset
})),
"offset {offset}"
);
}
for (offset, length) in [(12, 16), (u64::MAX - 3, 16)] {
assert_eq!(
encoder
.execute_commands_in_buffer_indirect(&icb, &range, offset)
.err(),
Some(Error::NotImplemented(
RuntimeGap::ExecutionRangePastBuffer { offset, length }
)),
"offset {offset}"
);
}
+1 -1
View File
@@ -93,7 +93,7 @@ pub const ARTIFACT_FORMAT_VERSION: u32 = 449;
/// changes no behaviour, and then updates that hash alone with the commit saying why, or changes
/// behaviour and also bumps this version. The commit that bumps it says what changed; this comment
/// keeps no history.
pub const RUNTIME_VERSION: u32 = 1580;
pub const RUNTIME_VERSION: u32 = 1582;
/// The digest of the sources this build of the crate was compiled from: SHA-256, as lowercase hex,
/// of the manifest, the build script, and exactly the files the crate roots' module tree compiles
+10 -2
View File
@@ -19,7 +19,7 @@ Columns:
| Kind | Variants | With a site | Reach system | Reach app | Reach rare | Reach none | Unassessed |
|---|---|---|---|---|---|---|---|
| Translator and front-end refusals | 126 | 126 | 6 | 33 | 70 | 17 | 0 |
| Runtime gaps | 64 | 64 | 1 | 8 | 41 | 14 | 0 |
| Runtime gaps | 68 | 68 | 1 | 8 | 44 | 15 | 0 |
| Apple-only calls | 5 | 5 | 0 | 0 | 0 | 5 | 0 |
| Binder refusals at a device limit | 9 | 9 | 0 | 1 | 7 | 1 | 0 |
| Translation caps | 14 | 14 | 0 | 0 | 7 | 7 | 0 |
@@ -178,8 +178,12 @@ Columns:
| `FeatureEnable` | A feature a created device would enable that the runtime's feature chain has no member for, or whose structure no enabled extension exposes | devices without the feature or extension it names | 1: `crates/metal2vulkan-runtime/src/enables.rs (of)` | `none`: device creation with a feature the runtime's chain lacks |
| `ExtensionEnable` | An extension a created device would enable that the device lists under none of the names the runtime knows for it | devices without the feature or extension it names | 1: `crates/metal2vulkan-runtime/src/enables.rs (of)` | `none`: device creation with an extension under an unknown name |
| `Render` | Render pipelines, passes and draws | every device (runtime piece not built) | 23: `crates/metal2vulkan-runtime/src/attachment_stand_in.rs (check_copies)`, `crates/metal2vulkan-runtime/src/attachment_stand_in.rs (stand_in_as, 2 sites)` (+17) | `system`: render pass, resolve and attachment forms not built (20 sites: see the appendix) |
| `TexelsPastBufferLength` | A 2D array over a buffer whose texels run past the buffer's length, which Metal makes over bytes its buffer's allocation has past the length, or a... | every device (runtime piece not built) | 2: `crates/metal2vulkan-runtime/src/buffer_texture.rs (refusal_error)`, `crates/metal2vulkan-runtime/src/texture/surface_depth.rs (surface_depth_twin)` | `rare`: a 2D array over a buffer past its length |
| `TexelsPastBufferLength` | A texture over a buffer whose texels run past the buffer's length, which Metal makes over bytes its buffer's allocation has past the length (a 2D... | every device (runtime piece not built) | 2: `crates/metal2vulkan-runtime/src/buffer_texture.rs (refusal_error)`, `crates/metal2vulkan-runtime/src/texture/surface_depth.rs (surface_depth_twin)` | `rare`: a texture over a buffer past its length |
| `OverlappingSurfaceRows` | A texture of an IOSurface plane (`Buffer::new_texture_with_iosurface_plane`, the stand-in for `newTextureWithDescriptor:iosurface:plane:`) whose... | every device (runtime piece not built) | 1: `crates/metal2vulkan-runtime/src/buffer_texture.rs (refusal_error)` | `rare`: an IOSurface plane whose rows overlap |
| `MemorylessSurfacePlane` | A texture of an IOSurface plane (`Buffer::new_texture_with_iosurface_plane`, the stand-in for `newTextureWithDescriptor:iosurface:plane:`) whose... | every device (runtime piece not built) | 1: `crates/metal2vulkan-runtime/src/buffer_texture.rs (refusal_error)` | `rare`: a memoryless texture over an IOSurface plane |
| `IndirectCommandPastSize` | A command of an indirect command buffer at or past its size (`indirectComputeCommandAtIndex:`, `indirectRenderCommandAtIndex:`) | every device (runtime piece not built) | 1: `crates/metal2vulkan-runtime/src/indirect_command_buffer.rs (command_at)` | `none`: an indirect command at or past the buffer's size |
| `ExecutionRangePastBuffer` | An `MTLIndirectCommandBufferExecutionRange` whose 8 bytes run past the buffer it is read from (`execute_commands_in_buffer_indirect`, a compute... | every device (runtime piece not built) | 1: `crates/metal2vulkan-runtime/src/indirect_execute.rs (check_range_buffer)` | `rare`: an execution range whose 8 bytes run past its buffer |
| `ExecutionRangeOffFour` | An `MTLIndirectCommandBufferExecutionRange` read at an offset that is not a multiple of 4 bytes (`execute_commands_in_buffer_indirect`, a compute... | every device (runtime piece not built) | 1: `crates/metal2vulkan-runtime/src/indirect_execute.rs (check_range_buffer)` | `rare`: an execution range at an offset off 4 bytes |
| `SamplePositionsAtBegin` | A render pass whose custom sample positions Vulkan takes only through what the runtime does not build | every device (runtime piece not built) | 3: `crates/metal2vulkan-runtime/src/depth_stencil_scratch.rs (stencil_scratch)`, `crates/metal2vulkan-runtime/src/render_pass.rs (positioned_stand_in)` (+1) | `rare`: custom sample positions Vulkan takes only at begin |
| `SharedEventAcrossDevices` | A shared event handle opened on a device other than its event's | every device (runtime piece not built) | 1: `crates/metal2vulkan-runtime/src/event.rs (new_shared_event_with_handle)` | `rare`: a shared event opened on another device |
| `ViewportDepthRange` | A viewport depth range past `[0, 1]`, which Metal takes, on a device without the features to take it natively or by the vertex stage's... | every device (runtime piece not built) | 7: `crates/metal2vulkan-runtime/src/render/draw_shape.rs (settings)`, `crates/metal2vulkan-runtime/src/render_state.rs` (+5) | `rare`: viewport depth outside [0, 1] without the device features |
@@ -434,6 +438,10 @@ Each refusal's sites, with the function that builds it.
- `gap::Render`: `crates/metal2vulkan-runtime/src/attachment_stand_in.rs (check_copies)`; `crates/metal2vulkan-runtime/src/attachment_stand_in.rs (stand_in_as, 2 sites)`; `crates/metal2vulkan-runtime/src/buffer_texture.rs (attachment_twin)`; `crates/metal2vulkan-runtime/src/depth_stencil_scratch.rs (check_sizes)`; `crates/metal2vulkan-runtime/src/kept_bytes.rs (settle)`; `crates/metal2vulkan-runtime/src/linear_attachment.rs (settle)`; `crates/metal2vulkan-runtime/src/nan_clear.rs (plan)`; `crates/metal2vulkan-runtime/src/pipeline/render.rs (imageblock_sample_length)`; `crates/metal2vulkan-runtime/src/render.rs (check_pipeline)`; `crates/metal2vulkan-runtime/src/render.rs (draw_resident)`; `crates/metal2vulkan-runtime/src/render.rs (next_instance)`; `crates/metal2vulkan-runtime/src/render/tile_dispatch.rs (scratch)`; `crates/metal2vulkan-runtime/src/render_pass.rs (attachment_format)`; `crates/metal2vulkan-runtime/src/render_pass.rs (depth_stencil)`; `crates/metal2vulkan-runtime/src/render_pass.rs (layout)`; `crates/metal2vulkan-runtime/src/render_pass.rs (target, 2 sites)`; `crates/metal2vulkan-runtime/src/resolve.rs (attach)`; `crates/metal2vulkan-runtime/src/resolve.rs (color_copy)`; `crates/metal2vulkan-runtime/src/resolve.rs (destination, 3 sites)`
- `gap::TexelsPastBufferLength`: `crates/metal2vulkan-runtime/src/buffer_texture.rs (refusal_error)`; `crates/metal2vulkan-runtime/src/texture/surface_depth.rs (surface_depth_twin)`
- `gap::OverlappingSurfaceRows`: `crates/metal2vulkan-runtime/src/buffer_texture.rs (refusal_error)`
- `gap::MemorylessSurfacePlane`: `crates/metal2vulkan-runtime/src/buffer_texture.rs (refusal_error)`
- `gap::IndirectCommandPastSize`: `crates/metal2vulkan-runtime/src/indirect_command_buffer.rs (command_at)`
- `gap::ExecutionRangePastBuffer`: `crates/metal2vulkan-runtime/src/indirect_execute.rs (check_range_buffer)`
- `gap::ExecutionRangeOffFour`: `crates/metal2vulkan-runtime/src/indirect_execute.rs (check_range_buffer)`
- `gap::SamplePositionsAtBegin`: `crates/metal2vulkan-runtime/src/depth_stencil_scratch.rs (stencil_scratch)`; `crates/metal2vulkan-runtime/src/render_pass.rs (positioned_stand_in)`; `crates/metal2vulkan-runtime/src/sample_positions.rs (refusal_error)`
- `gap::SharedEventAcrossDevices`: `crates/metal2vulkan-runtime/src/event.rs (new_shared_event_with_handle)`
- `gap::ViewportDepthRange`: `crates/metal2vulkan-runtime/src/render/draw_shape.rs (settings)`; `crates/metal2vulkan-runtime/src/render_state.rs`; `crates/metal2vulkan-runtime/src/render_state.rs (bias_holds)`; `crates/metal2vulkan-runtime/src/render_state.rs (collapses)`; `crates/metal2vulkan-runtime/src/render_state.rs (compensation)`; `crates/metal2vulkan-runtime/src/render_state.rs (depth_range)`; `crates/metal2vulkan-runtime/src/render_state.rs (depth_ranges_refused)`
+5 -1
View File
@@ -142,8 +142,12 @@ gap AccelerationStructures rare ray tracing (out of scope by ruling)
gap FeatureEnable none device creation with a feature the runtime's chain lacks
gap ExtensionEnable none device creation with an extension under an unknown name
gap Render system render pass, resolve and attachment forms not built (20 sites: see the appendix)
gap TexelsPastBufferLength rare a 2D array over a buffer past its length
gap TexelsPastBufferLength rare a texture over a buffer past its length
gap OverlappingSurfaceRows rare an IOSurface plane whose rows overlap
gap MemorylessSurfacePlane rare a memoryless texture over an IOSurface plane
gap IndirectCommandPastSize none an indirect command at or past the buffer's size
gap ExecutionRangePastBuffer rare an execution range whose 8 bytes run past its buffer
gap ExecutionRangeOffFour rare an execution range at an offset off 4 bytes
gap SamplePositionsAtBegin rare custom sample positions Vulkan takes only at begin
gap SharedEventAcrossDevices rare a shared event opened on another device
gap ViewportDepthRange rare viewport depth outside [0, 1] without the device features
Can't render this file because it contains an unexpected character in line 126 and column 96.