New device tests (tests/device_recovery_carry.rs, under the CPU-ICD and GPU cfgs): - One recovery carries a Private buffer (same address, zero after) and a buffer in fresh pages. The fresh-page buffer keeps its contents pointer and bytes, and the host's writes through that pointer after the recovery reach the GPU's copy. It also carries a shared event: its value, its listener's notification and a GPU signal after the recovery. - A pooled Shared buffer stays refused, and the notice counts it. It keeps the lost VkDevice, which then holds no empty block and less memory than before the loss. Dropping it takes the line back to one live VkDevice. - Seven recoveries with a carried buffer and event in use between them end with one live VkDevice, and eight made. The device_recovery helpers are shared with the new file. Docs: RuntimeGap::MadeBeforeRecovery, the DeviceRecovered catalogue entry and its consequence (runtime and API.md), the runtime README's lost-device section, line.rs's module and recover_for_test docs, in_place.rs, the validation lane's docs and the refusal surface's reach mark now say what is carried and what stays refused. REFUSALS.md is regenerated in the next commit. Not yet built. (cherry picked from commit 68d68cdfbdbbac979e5097a8ad286416450790bf)
2615 lines
154 KiB
Rust
2615 lines
154 KiB
Rust
//! The runtime's typed errors.
|
|
//!
|
|
//! Where Metal raises, aborts, or answers nil, the runtime returns one of these, and a failed
|
|
//! command records nothing. Execution status words are not errors: they are reported on the command
|
|
//! buffer ([`CommandBuffer::execution_report`](super::CommandBuffer::execution_report)).
|
|
//!
|
|
//! **A misuse ends Metal's process, or Metal answers nil**. Two kinds tell a program's misuses
|
|
//! apart by what plain Metal does with them, and both name the call and its [`Problem`]:
|
|
//!
|
|
//! - [`Error::Invalid`]: plain Metal itself refuses the call: it ends its process, raises, or
|
|
//! fails the creation with an `NSError`. A program that would run on Metal never meets one.
|
|
//! Metal's API validation layer is not Metal: that the layer stops a call justifies nothing
|
|
//! here, and each [`Problem`] names what plain Metal does with it. Where plain Metal takes
|
|
//! something the layer stops, the runtime takes it too.
|
|
//! - [`Error::Nil`]: plain Metal answers nil (no object, no error), and the process goes on;
|
|
//! its API validation layer may stop the call too. A program may meet one and carry on, as on
|
|
//! Metal.
|
|
//!
|
|
//! The same problem can be either, by the call and the descriptor: a 2D multisample texture of a
|
|
//! two-plane YCbCr format ends the process, and the 2D one answers nil, both
|
|
//! [`TextureProblem`]s. Where Metal answers nil through a kind of its own the runtime keeps that
|
|
//! kind: no memory ([`Error::OutOfMemory`], an automatic heap without room among it), a pinned
|
|
//! address that cannot be honoured ([`Error::PlacementConflict`]), no device
|
|
//! ([`Error::NoDevice`]), a library or pipeline Metal answers nil with an `NSError` for
|
|
//! ([`Error::Compile`]).
|
|
|
|
use super::address::PlacementConflict;
|
|
use super::address_map::{AddressModeMap, MappedSampling};
|
|
use super::apple_only::AppleOnly;
|
|
use super::argument_encoder::ArgumentEncoderProblem;
|
|
use super::copy_plan::CopyProblem;
|
|
use super::function_table::FunctionTableProblem;
|
|
use super::heap::HeapProblem;
|
|
use super::indirect_command_buffer::IndirectCommandBufferProblem;
|
|
use super::interop::SemaphoreProblem;
|
|
use super::linear_plan::BufferTextureProblem;
|
|
use super::mipmap_plan::MipmapProblem;
|
|
use super::pipeline::{BinaryFunctionProblem, RequiredThreadsProblem};
|
|
use super::rate_map::RateMapProblem;
|
|
use super::rate_mapped_pass::RegionRefusal;
|
|
use super::rebind::RebindProblem;
|
|
use super::render::DrawProblem;
|
|
use super::render_pass::{Attachment, RenderPassProblem};
|
|
use super::render_state::RenderStateProblem;
|
|
use super::sparse::SparseProblem;
|
|
use super::texture::WrappedImageProblem;
|
|
use super::texture_descriptor::TextureProblem;
|
|
use super::view_plan::ViewProblem;
|
|
use super::visibility::VisibilityProblem;
|
|
use super::wrapped_buffer::WrappedBufferProblem;
|
|
use metal2vulkan::bind::UnpinnedCompile;
|
|
use metal2vulkan::device::{ApiVersion, VkExtension, VkFeature};
|
|
use metal2vulkan::error::{BindError, Error as CompileError, Unsupported};
|
|
use metal2vulkan::metal::PixelFormat;
|
|
use metal2vulkan::pipeline::Stage;
|
|
use metal2vulkan::reflection::LinkedUseGap;
|
|
use std::fmt;
|
|
use std::path::PathBuf;
|
|
|
|
/// Why a runtime call failed: where Metal raises, ends the process, answers nil or an `NSError`,
|
|
/// the runtime returns one of these.
|
|
#[non_exhaustive]
|
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
|
pub enum Error {
|
|
/// Misuse plain Metal itself refuses, ending its process or failing the call: the call and
|
|
/// the problem (the module's docs).
|
|
Invalid(Invalid),
|
|
/// A device or translator gap, naming what is missing.
|
|
Unsupported(Unsupported),
|
|
/// The planner refused the encoder's bind state for this command.
|
|
Bind(BindError),
|
|
/// Library or pipeline creation failed: refused, over budget, or cancelled.
|
|
Compile(CompileError),
|
|
/// A runtime piece a later build step adds: the command needs it, so it is refused rather than
|
|
/// run without it.
|
|
NotImplemented(RuntimeGap),
|
|
/// A pinned GPU address the device's Metal address space cannot honour (a runtime extension):
|
|
/// its range meets bytes another resource holds, or leaves the space. Metal answers nil for
|
|
/// both, and aliases nothing.
|
|
PlacementConflict(PlacementConflict),
|
|
/// The device ran out of memory of this kind.
|
|
OutOfMemory(MemoryKind),
|
|
/// The Vulkan device was lost.
|
|
DeviceLost,
|
|
/// Any other Vulkan failure, raw.
|
|
Vulkan(VkResultCode),
|
|
/// No Vulkan device the runtime can use: the instance found no driver, or no physical device
|
|
/// qualified (`MTLCreateSystemDefaultDevice` answering nil). A Vulkan loader that did not
|
|
/// open is [`Error::LoaderNotFound`].
|
|
NoDevice,
|
|
/// An Apple-only call off Metal's default that the runtime refuses, never a misuse:
|
|
/// [`AppleOnly::gap`](crate::AppleOnly::gap) says why, whether Metal's answer is not measured
|
|
/// or the runtime has not built it. Each is the runtime's own gap, not a device's.
|
|
AppleOnly(AppleOnly),
|
|
/// The shader cache directory cannot be used: only device creation and adoption fail so; later,
|
|
/// a failed read or write is a counted miss.
|
|
ShaderCache(ShaderCacheError),
|
|
/// A binary archive that cannot be loaded or serialized (`MTLBinaryArchiveError`).
|
|
BinaryArchive(BinaryArchiveError),
|
|
/// A creation under `PipelineOption::FAIL_ON_BINARY_ARCHIVE_MISS` whose pipeline no listed
|
|
/// binary archive holds.
|
|
BinaryArchiveMiss(BinaryArchiveMiss),
|
|
/// A rasterization-rate map Metal's API validation takes that the compile layer does not
|
|
/// compile: this crate's bound, where Apple's compile is unmeasured or crashes.
|
|
RateMap(UnpinnedCompile),
|
|
/// A command buffer wait that would deadlock (`waitUntilCompleted`, `waitUntilScheduled`, or
|
|
/// `commandBuffer` on a queue whose command buffers are all held): the runtime refuses it at
|
|
/// once rather than hang. The cause says which of Metal's answers the refusal stands for: where
|
|
/// Metal never returns ([`DeadlockCause::OwnQueue`]), where it would hang too
|
|
/// ([`DeadlockCause::Cycle`]), where Metal's handler threads run out and it hangs
|
|
/// ([`DeadlockCause::HandlerThreadCap`]), once the process is exiting
|
|
/// ([`DeadlockCause::Exiting`]), and from a submission handler, which Metal has not
|
|
/// ([`DeadlockCause::SubmissionHandler`]).
|
|
WaitWouldDeadlock(DeadlockCause),
|
|
/// An instance API version device creation cannot request
|
|
/// (`DeviceOptions::instance_api_version`): below Vulkan 1.2, the runtime's floor, or above
|
|
/// the version the Vulkan loader reports.
|
|
InstanceApiVersion(InstanceApiVersion),
|
|
/// A Vulkan sampler the device cannot make: `maxSamplerAllocationCount` of the runtime's are
|
|
/// live (its sampler states' samplers, one per use, LOD clamps and view mapping; its
|
|
/// pipelines' immutable samplers; its neutral ones). A device's lack: the command that needs
|
|
/// another is refused rather than recorded with a sampler Vulkan does not allow.
|
|
SamplerLimit(SamplerLimit),
|
|
/// A dynamic library's file that cannot be loaded or written (`MTLDynamicLibraryError`).
|
|
DynamicLibrary(DynamicLibraryError),
|
|
/// The Vulkan loader library opened from none of the places tried (no Metal counterpart:
|
|
/// Metal has no loader). The GPU may be there: install the Vulkan loader, or name it with
|
|
/// [`DeviceOptions::loader`](crate::DeviceOptions::loader).
|
|
LoaderNotFound(LoaderNotFound),
|
|
/// A driver setting the runtime cannot run under, read from the device when it is made or
|
|
/// adopted: the device is refused, naming the setting ([`DriverSetting`]). Turn it back on.
|
|
DriverSetting(DriverSetting),
|
|
/// What plain Metal answers nil for, the process going on: the call and the problem (the
|
|
/// module's docs).
|
|
Nil(Nil),
|
|
/// What plain Metal answers nil for with an `NSError`, the process going on: the call, the
|
|
/// problem, and Metal's error ([`MetalError`]), which a consumer answering as Metal does can
|
|
/// hand on as it is.
|
|
MetalError(MetalError),
|
|
/// What the runtime cannot prove plain Metal's answer for: the call and the problem
|
|
/// ([`Unproven`]). Metal may make the object, or refuse it; the runtime does neither, so a
|
|
/// consumer answering its guest as Metal does stops, naming the problem, rather than guess.
|
|
Unproven(Unproven),
|
|
/// A device extension the options list (`DeviceOptions::device_extensions`) whose feature
|
|
/// structure the runtime knows, on a device that lacks one of its features: device creation
|
|
/// refuses it rather than enable the extension without the feature (no Metal counterpart).
|
|
ExtensionFeature(ExtensionFeature),
|
|
/// A device extension the options list (`DeviceOptions::device_extensions`) whose registry
|
|
/// dependency names an instance extension the instance would not enable: the options are
|
|
/// refused before the instance is made, where a driver need not refuse the device (no Metal
|
|
/// counterpart).
|
|
InstanceExtensionRequired(InstanceExtensionRequired),
|
|
/// A render encoder's call whose lowering, after the call returned, met a degradation the
|
|
/// device's options refuse there (`DeviceOptions::lowering_refuses`): its notice, which was
|
|
/// not announced. The call fails its command buffer (`CommandBufferError::CallRefused`), and
|
|
/// this is its refusal (`CommandBuffer::refusal`). No Metal counterpart.
|
|
Degraded(Box<crate::degradation::DegradeNotice>),
|
|
}
|
|
|
|
impl fmt::Display for Error {
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
match self {
|
|
Error::Invalid(invalid) => {
|
|
write!(f, "invalid use of {}: {:?}", invalid.call, invalid.problem)
|
|
}
|
|
Error::Unsupported(unsupported) => write!(f, "unsupported: {unsupported:?}"),
|
|
Error::Bind(error) => write!(f, "the bind state was refused: {error:?}"),
|
|
Error::Compile(error) => write!(f, "compile failed: {error:?}"),
|
|
Error::NotImplemented(gap) => write!(f, "not implemented in the runtime yet: {gap:?}"),
|
|
Error::PlacementConflict(conflict) => {
|
|
write!(f, "the pinned address cannot be honoured: {conflict:?}")
|
|
}
|
|
Error::OutOfMemory(kind) => write!(f, "out of {kind:?} memory"),
|
|
Error::DeviceLost => f.write_str("the Vulkan device was lost"),
|
|
Error::Vulkan(code) => write!(f, "Vulkan failure {}", code.0),
|
|
Error::NoDevice => f.write_str("no Vulkan device the runtime can use"),
|
|
Error::AppleOnly(feature) => {
|
|
write!(
|
|
f,
|
|
"an Apple-only feature the runtime refuses ({:?}): {feature:?}",
|
|
feature.gap()
|
|
)
|
|
}
|
|
Error::ShaderCache(error) => write!(f, "{error}"),
|
|
Error::BinaryArchive(error) => write!(f, "{error}"),
|
|
Error::BinaryArchiveMiss(miss) => write!(f, "{miss}"),
|
|
Error::RateMap(reason) => write!(f, "the rate map is not compiled: {reason}"),
|
|
Error::WaitWouldDeadlock(cause) => {
|
|
write!(f, "a command buffer wait would deadlock: {cause}")
|
|
}
|
|
Error::InstanceApiVersion(refused) => {
|
|
write!(
|
|
f,
|
|
"the instance API version cannot be requested: {refused:?}"
|
|
)
|
|
}
|
|
Error::SamplerLimit(SamplerLimit { limit }) => write!(
|
|
f,
|
|
"the device's {limit} Vulkan samplers (maxSamplerAllocationCount) are live"
|
|
),
|
|
Error::DynamicLibrary(error) => write!(f, "{error}"),
|
|
Error::LoaderNotFound(missing) => write!(f, "{missing}"),
|
|
Error::DriverSetting(setting) => write!(f, "{setting}"),
|
|
Error::Nil(nil) => {
|
|
write!(f, "Metal answers nil for {}: {:?}", nil.call, nil.problem)
|
|
}
|
|
Error::MetalError(error) => write!(
|
|
f,
|
|
"Metal answers nil for {} with error {} {} \"{}\": {:?}",
|
|
error.call, error.domain, error.code, error.localized_description, error.problem
|
|
),
|
|
Error::Unproven(unproven) => write!(
|
|
f,
|
|
"Metal's answer to {} is unmeasured: {:?}",
|
|
unproven.call, unproven.problem
|
|
),
|
|
Error::ExtensionFeature(missing) => write!(
|
|
f,
|
|
"the device lists {} but lacks its feature {}",
|
|
missing.extension, missing.feature
|
|
),
|
|
Error::InstanceExtensionRequired(missing) => write!(
|
|
f,
|
|
"the device extension {} requires the instance extension {}, which the instance \
|
|
does not enable",
|
|
missing.extension, missing.instance_extension
|
|
),
|
|
Error::Degraded(notice) => write!(
|
|
f,
|
|
"{}: {}, refused as the device's options ask ({})",
|
|
notice.object,
|
|
notice.reason,
|
|
notice.degradation.code()
|
|
),
|
|
}
|
|
}
|
|
}
|
|
|
|
/// A listed device extension's feature the device lacks ([`Error::ExtensionFeature`]).
|
|
#[non_exhaustive]
|
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
|
pub struct ExtensionFeature {
|
|
/// The extension, as the options name it (`VK_EXT_swapchain_maintenance1`).
|
|
pub extension: &'static str,
|
|
/// The feature, as the registry names its member (`swapchainMaintenance1`).
|
|
pub feature: &'static str,
|
|
}
|
|
|
|
/// A listed device extension's instance extension the instance would not enable
|
|
/// ([`Error::InstanceExtensionRequired`]).
|
|
#[non_exhaustive]
|
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
|
pub struct InstanceExtensionRequired {
|
|
/// The device extension, as the options name it (`VK_KHR_swapchain`).
|
|
pub extension: &'static str,
|
|
/// The instance extension it requires (`VK_KHR_surface`).
|
|
pub instance_extension: &'static str,
|
|
}
|
|
|
|
/// Why a command buffer wait would deadlock ([`Error::WaitWouldDeadlock`]). Metal has no such
|
|
/// error: where the runtime refuses, Metal's wait hangs, or would hang, or (past the runtime's
|
|
/// cap) runs. A consumer that copies Metal's behaviour hangs the thread on
|
|
/// [`OwnQueue`](Self::OwnQueue), and decides the others itself.
|
|
#[non_exhaustive]
|
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
|
pub enum DeadlockCause {
|
|
/// From one of the device's handler threads (a scheduled or completed handler, or a
|
|
/// deallocator run as a command buffer releases what it retained), a wait for a transition
|
|
/// of the handler's own queue still to come: its own command buffer's, or a later one's; or
|
|
/// a new command buffer of that queue while it holds all of its `maxCommandBufferCount`.
|
|
/// Metal never returns from that wait (measured on an M4, macOS 27.0.1).
|
|
OwnQueue,
|
|
/// From a handler thread, a wait for another queue whose handlers wait, through the queues
|
|
/// they wait for, for this one: a cycle of handlers' waits, across every device. Metal would
|
|
/// hang too (not measured).
|
|
Cycle,
|
|
/// From a handler thread, a wait for another queue that would leave the device's handler
|
|
/// threads with none that is not blocked in such a wait (or a marked wait off those threads,
|
|
/// which none can count): the 512th. Metal ran 511 such waits at once, which returned once
|
|
/// the command buffers they waited for completed; with 512 its process's dispatch threads ran
|
|
/// out, and no handler ran nor command buffer completed after: it hangs (the M3 Max under
|
|
/// macOS 27.0.1). Metal's threads are the process's, the runtime's each device's.
|
|
HandlerThreadCap,
|
|
/// From any thread, once the process is exiting ([`process_exiting`](crate::process_exiting)):
|
|
/// the runtime's threads that schedule and finish command buffers have ended, and it makes no
|
|
/// Vulkan call, so a command buffer not yet scheduled or finished never will be. A wait
|
|
/// already blocked answers within 50 ms.
|
|
Exiting,
|
|
/// From a submission handler ([`CommandBuffer::add_submission_handler`](crate::CommandBuffer::add_submission_handler),
|
|
/// a runtime extension Metal has no counterpart of), a wait for what has not happened yet: a
|
|
/// command buffer's scheduling or completion, or a slot of a full queue that no uncommitted
|
|
/// command buffer holds. The handler runs on the thread that submits command buffers, and its
|
|
/// own command buffer's scheduling, with every later transition of its queue, waits for it.
|
|
SubmissionHandler,
|
|
/// From a completion-seen handler
|
|
/// ([`CommandBuffer::add_completion_seen_handler`](crate::CommandBuffer::add_completion_seen_handler),
|
|
/// a runtime extension Metal has no counterpart of), a wait for what has not happened yet: a
|
|
/// command buffer's scheduling or completion, or a slot of a full queue that no uncommitted
|
|
/// command buffer holds. The handler may run on the thread that sees command buffers
|
|
/// complete, and its own command buffer's completion, with every later transition of its
|
|
/// queue, waits for it.
|
|
CompletionSeenHandler,
|
|
}
|
|
|
|
impl fmt::Display for DeadlockCause {
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
f.write_str(match self {
|
|
DeadlockCause::OwnQueue => "it waits for a later transition of the handler's own queue",
|
|
DeadlockCause::Cycle => "it would close a cycle of handlers' waits",
|
|
DeadlockCause::HandlerThreadCap => "it would leave the device no free handler thread",
|
|
DeadlockCause::Exiting => "the process is exiting",
|
|
DeadlockCause::SubmissionHandler => {
|
|
"it waits in a submission handler, which scheduling waits for"
|
|
}
|
|
DeadlockCause::CompletionSeenHandler => {
|
|
"it waits in a completion-seen handler, which completion waits for"
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
impl From<DeadlockCause> for Error {
|
|
fn from(cause: DeadlockCause) -> Error {
|
|
Error::WaitWouldDeadlock(cause)
|
|
}
|
|
}
|
|
|
|
/// The Vulkan loader libraries that did not open, in the order the runtime tried them
|
|
/// ([`Error::LoaderNotFound`]).
|
|
#[non_exhaustive]
|
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
|
pub struct LoaderNotFound {
|
|
/// Each library tried: [`DeviceOptions::loader`](crate::DeviceOptions::loader) where the
|
|
/// options name one, else the platform's own by name (a bare name, which the dynamic linker
|
|
/// searches for) and then, on macOS, the install directories no default search path holds.
|
|
pub tried: Vec<PathBuf>,
|
|
}
|
|
|
|
impl fmt::Display for LoaderNotFound {
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
f.write_str("the Vulkan loader did not open from any of")?;
|
|
for (i, path) in self.tried.iter().enumerate() {
|
|
let separator = if i == 0 { " " } else { ", " };
|
|
write!(f, "{separator}{}", path.display())?;
|
|
}
|
|
Ok(())
|
|
}
|
|
}
|
|
|
|
/// A driver setting a device is refused under ([`Error::DriverSetting`]).
|
|
#[non_exhaustive]
|
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
|
pub enum DriverSetting {
|
|
/// MoltenVK's `MVK_CONFIG_USE_METAL_ARGUMENT_BUFFERS` is off (an environment variable, a
|
|
/// layer setting of the consumer's, or the consumer's own instance): Metal always binds
|
|
/// through argument buffers, and without them MoltenVK passes every resource as a discrete
|
|
/// Metal argument, whose form Metal's compiler crashes on for large fragment functions, and
|
|
/// its bind limits fall to the per-stage ones. An instance the runtime creates asks for them.
|
|
MoltenVkArgumentBuffersOff,
|
|
}
|
|
|
|
impl fmt::Display for DriverSetting {
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
f.write_str(match self {
|
|
DriverSetting::MoltenVkArgumentBuffersOff => {
|
|
"MoltenVK runs with MVK_CONFIG_USE_METAL_ARGUMENT_BUFFERS off: Metal always binds \
|
|
through argument buffers, and without them Metal's compiler crashes on large \
|
|
fragment functions and the bind limits shrink; turn the setting back on"
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
impl std::error::Error for Error {}
|
|
|
|
/// A call plain Metal itself refuses, ending its process or failing the creation (the module's
|
|
/// docs). One plain Metal answers nil for is a [`Nil`].
|
|
#[non_exhaustive]
|
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
|
pub struct Invalid {
|
|
/// The method, by its Metal selector's snake_case name.
|
|
pub call: &'static str,
|
|
/// What it did wrong.
|
|
pub problem: Problem,
|
|
}
|
|
|
|
impl Invalid {
|
|
/// `problem` in `call`.
|
|
pub fn new(call: &'static str, problem: Problem) -> Invalid {
|
|
Invalid { call, problem }
|
|
}
|
|
}
|
|
|
|
/// A call plain Metal answers nil for, the process going on (the module's docs): its API
|
|
/// validation layer may stop it too. One plain Metal itself refuses is an [`Invalid`].
|
|
#[non_exhaustive]
|
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
|
pub struct Nil {
|
|
/// The method, by its Metal selector's snake_case name.
|
|
pub call: &'static str,
|
|
/// Why Metal answers nil.
|
|
pub problem: Problem,
|
|
}
|
|
|
|
impl Nil {
|
|
/// `problem` in `call`.
|
|
pub fn new(call: &'static str, problem: Problem) -> Nil {
|
|
Nil { call, problem }
|
|
}
|
|
}
|
|
|
|
/// A call whose answer on plain Metal the runtime cannot prove ([`Error::Unproven`]): Metal may
|
|
/// make what it asks for, or refuse it. Every problem the runtime answers so:
|
|
/// [`Problem::IndirectCommandsDirectArgumentUnproven`],
|
|
/// [`Problem::UnwrittenFragmentInputsUnproven`], 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
|
|
/// answer comes before a proven [`Problem::UnwrittenFragmentInputs`]. There Metal answers nil,
|
|
/// while the runtime answers `Unproven`, since the `NSError` text Metal would give is uncertain.
|
|
#[non_exhaustive]
|
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
|
pub struct Unproven {
|
|
/// The method, by its Metal selector's snake_case name.
|
|
pub call: &'static str,
|
|
/// What Metal's answer is unmeasured for.
|
|
pub problem: Problem,
|
|
}
|
|
|
|
impl Unproven {
|
|
/// `problem` in `call`.
|
|
pub fn new(call: &'static str, problem: Problem) -> Unproven {
|
|
Unproven { call, problem }
|
|
}
|
|
}
|
|
|
|
/// A call plain Metal answers nil for with an `NSError`, the process going on: the call, the
|
|
/// problem, and Metal's error as measured ([`Error::MetalError`]). A consumer that answers its
|
|
/// guest as Metal does makes the `NSError` of `domain`, `code` and a `userInfo` holding
|
|
/// `NSLocalizedDescription` = `localized_description`, its only key where Metal's holds no
|
|
/// other (every refusal the runtime answers so: [`Problem::IndirectCommandsDirectArgument`],
|
|
/// [`Problem::UnrasterizedVertexReturn`], [`Problem::RasterizedVoidVertex`],
|
|
/// [`Problem::DepthWrittenWithoutAttachment`],
|
|
/// [`Problem::UnwrittenFragmentInputs`], [`Problem::RasterSampleCount`], and
|
|
/// [`Problem::BinaryFunctions`] with [`BinaryFunctionProblem::NotPrecompiled`]).
|
|
#[non_exhaustive]
|
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
|
pub struct MetalError {
|
|
/// The method, by its Metal selector's snake_case name.
|
|
pub call: &'static str,
|
|
/// Why Metal refuses.
|
|
pub problem: Problem,
|
|
/// `NSError.domain`. Where Metal's is its GPU driver's class, it follows the device: the
|
|
/// runtime answers the M3 Max's under macOS 26.7 (each problem's docs name the devices
|
|
/// measured), and a consumer may substitute its own device's.
|
|
pub domain: &'static str,
|
|
/// `NSError.code`.
|
|
pub code: i64,
|
|
/// `NSError.localizedDescription`: `userInfo`'s `NSLocalizedDescription` (from `&'static str`:
|
|
/// Metal's text may name the program's own identifiers; a refusal is rare, so its text is
|
|
/// allocated).
|
|
pub localized_description: Box<str>,
|
|
}
|
|
|
|
impl MetalError {
|
|
/// `problem` in `call`, Metal's error of `domain`, `code` and `localized_description`.
|
|
pub fn new(
|
|
call: &'static str,
|
|
problem: Problem,
|
|
domain: &'static str,
|
|
code: i64,
|
|
localized_description: &'static str,
|
|
) -> MetalError {
|
|
MetalError {
|
|
call,
|
|
problem,
|
|
domain,
|
|
code,
|
|
localized_description: localized_description.into(),
|
|
}
|
|
}
|
|
|
|
/// [`new`](Self::new), of a `localized_description` made for the call.
|
|
pub fn with_description(
|
|
call: &'static str,
|
|
problem: Problem,
|
|
domain: &'static str,
|
|
code: i64,
|
|
localized_description: String,
|
|
) -> MetalError {
|
|
MetalError {
|
|
call,
|
|
problem,
|
|
domain,
|
|
code,
|
|
localized_description: localized_description.into_boxed_str(),
|
|
}
|
|
}
|
|
}
|
|
|
|
/// What a call did wrong.
|
|
#[non_exhaustive]
|
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
|
pub enum Problem {
|
|
/// An encoder of this command buffer is open: one encoder at a time. Plain Metal asserts too
|
|
/// ("A command encoder is already encoding to this command buffer", "commit command buffer with
|
|
/// uncommitted encoder", "encodeSignalEvent:value: with uncommitted encoder"; an M4).
|
|
///
|
|
/// Basis: metal-measured (an M4: plain Metal asserts "A command encoder is already encoding to
|
|
/// this command buffer").
|
|
EncoderOpen,
|
|
/// A compute or render encoder made, or a blit encoder's first command (`call` names the
|
|
/// blit encoder), under protection options 1, 3 or 7 (`CommandBuffer::set_protection_options`),
|
|
/// where Metal's process ends (SIGABRT, measured by a consumer on an M3 Max, macOS 26.7).
|
|
///
|
|
/// Basis: metal-measured (an M3 Max, macOS 26.7: Metal's process ends, SIGABRT, as the consumer
|
|
/// measured).
|
|
ProtectedEncoder {
|
|
/// The protection options set.
|
|
options: u64,
|
|
},
|
|
/// An encoder of this command buffer was dropped without `end_encoding`: its commands are
|
|
/// lost, so the command buffer can never be committed. Plain Metal asserts as the encoder
|
|
/// goes ("Command encoder released without endEncoding").
|
|
///
|
|
/// Basis: metal-documented (Metal asserts "Command encoder released without endEncoding").
|
|
EncoderAbandoned,
|
|
/// The command buffer was already committed. Plain Metal asserts too ("commit an already
|
|
/// committed command buffer", and a new encoder's `_status <
|
|
/// MTLCommandBufferStatusCommitted`).
|
|
///
|
|
/// Basis: metal-documented (Metal asserts "commit an already committed command buffer").
|
|
AlreadyCommitted,
|
|
/// A scheduled signal encoded once the command buffer completed, or failed (status `Error`)
|
|
/// (`CommandBuffer::encode_signal_event_scheduled`): Metal's process ends there (a
|
|
/// segmentation fault, as the consumer measured; in 10 of 15 runs on an M3 Max under macOS
|
|
/// 27.0.1, the others setting nothing). Encoded after the commit and before the completion,
|
|
/// it does nothing, as Metal's.
|
|
///
|
|
/// Basis: metal-measured (an M3 Max, macOS 27.0.1: a segmentation fault in 10 of 15 runs, as
|
|
/// the consumer measured).
|
|
ScheduledSignalAfterCompletion,
|
|
/// An object made by another device.
|
|
///
|
|
/// Basis: unknown (Metal's answer for an object another device made is unmeasured).
|
|
ForeignObject,
|
|
/// Dma-bufs a `DmaBufSource` returned (a runtime extension: Metal has none,
|
|
/// `HostMemory::with_dma_buf`) that break its contract: chunks that do not cover the pages
|
|
/// asked for, split off the granule, or of lengths off the host page, and a descriptor that
|
|
/// is no dma-buf or holds fewer bytes than its chunk.
|
|
///
|
|
/// Basis: ours (a runtime extension's own contract: Metal imports no dma-buf).
|
|
DmaBuf,
|
|
/// Guest RAM, or a run resolver's answer, that breaks its runtime extension's contract
|
|
/// (`HostRam::new`, `Device::use_host_ram`, `HostMemory::with_runs`,
|
|
/// `BlitCommandEncoder::copy_from_host_ram`, `copy_to_host_ram`, `copy_runs_from_host_ram`
|
|
/// and `copy_runs_to_host_ram`; Metal has none). For the RAM: no range, or a range that is
|
|
/// empty, starts or ends off the host page, runs past the address space's end or overlaps
|
|
/// another (of the same RAM, or of another RAM the device uses). For an answer: runs that are
|
|
/// not whole host pages or do not cover exactly the pages asked for. For a copy: a RAM the
|
|
/// device does not use, a run that is empty, starts off a 4-byte word or lies outside the
|
|
/// RAM's ranges, of runs one after another bytes of the buffer that start off a 4-byte word
|
|
/// of its memory, or, of a copy by regions, a buffer over host pages the copy's bytes
|
|
/// overlap.
|
|
///
|
|
/// Basis: ours (a runtime extension's own contract: Metal imports no guest RAM).
|
|
HostRam,
|
|
/// An image the caller made that cannot be wrapped as a texture of the descriptor
|
|
/// (`new_texture_with_vk_image`).
|
|
///
|
|
/// Basis: ours (a runtime extension: Metal wraps no Vulkan image).
|
|
WrappedImage(WrappedImageProblem),
|
|
/// A handle of a texture that is not shareable, for which Metal answers nil, an [`Error::Nil`].
|
|
///
|
|
/// Basis: unknown (Metal's nil for a texture that is not shareable is unmeasured).
|
|
NotShareable,
|
|
/// A semaphore that cannot be one of the caller's binary semaphores.
|
|
///
|
|
/// Basis: ours (a runtime extension: Metal has no binary semaphores).
|
|
Semaphore(SemaphoreProblem),
|
|
/// The memory of a buffer, or the semaphore of a shared event, not made exportable as asked
|
|
/// (`Buffer::export_memory_fd` of a buffer not made exportable as an opaque file descriptor,
|
|
/// `Buffer::export_memory_dma_buf` of one not made exportable as a dma-buf,
|
|
/// `Buffer::external_write_done` of one made exportable as neither, and
|
|
/// `SharedEvent::export_semaphore_fd` of an event `Device::new_exportable_shared_event` did
|
|
/// not make): no other API imports it so.
|
|
///
|
|
/// Basis: ours (a runtime extension: Metal exports no buffer's memory and no event's
|
|
/// semaphore).
|
|
NotExportable,
|
|
/// No pipeline state is set (plain Metal faults at a compute dispatch without one).
|
|
///
|
|
/// Basis: unknown (plain Metal is held to fault at a dispatch with no pipeline state, on no
|
|
/// measurement recorded here).
|
|
NoPipelineState,
|
|
/// An argument-table index past Metal's table (plain Metal writes past its own table: a
|
|
/// compute texture at index 128 faulted the dispatch on an M4).
|
|
///
|
|
/// Basis: metal-measured (an M4: a compute texture at index 128 faulted the dispatch).
|
|
IndexOutOfRange {
|
|
/// The index given.
|
|
index: u32,
|
|
/// The table's entries: indices below it are taken.
|
|
limit: u32,
|
|
},
|
|
/// An offset past the end of the buffer: at the bind in a render stage's table, and at a
|
|
/// compute dispatch whose kernel reads a slot bound so, where Metal's read is past the buffer.
|
|
///
|
|
/// Basis: metal-takes (an Apple M3 Max, macOS 27.0.1: setVertexBuffer at offset 512 of a buffer
|
|
/// of 256 bytes returns, the encoder ends and the pass completes; Metal's API validation alone
|
|
/// refuses it).
|
|
OffsetOutOfRange {
|
|
/// The offset given.
|
|
offset: u64,
|
|
/// The buffer's length.
|
|
length: u64,
|
|
},
|
|
/// `set_bytes` (or a stage's form) of more bytes than Metal's limit for inline bytes.
|
|
///
|
|
/// Basis: metal-takes (an Apple M3 Max, macOS 27.0.1: setBytes:length:8192 returns and the
|
|
/// kernel reads all 8192 bytes; Metal's API validation alone says "length(8192) must be <=
|
|
/// 4096").
|
|
InlineBytesLength {
|
|
/// The bytes given.
|
|
length: u64,
|
|
/// The most bytes one call takes.
|
|
limit: u64,
|
|
},
|
|
/// An imageblock size of more than 1024 cells over more than one row and column, or with a
|
|
/// side past 65536, at a compute encoder's `set_imageblock_size` (plain Metal runs 1024 by
|
|
/// 1 there with its cells reading 0, or is unmeasured); and a width or height that is not a
|
|
/// power of two, or more than 1024 cells, at an indirect command's execution (as Metal's API
|
|
/// validation refuses it).
|
|
///
|
|
/// Basis: unknown (plain Metal is held to run the compute form, and the indirect form rests on
|
|
/// Metal's API validation; neither measured on a named device).
|
|
ImageblockSize {
|
|
/// The width given, in pixels.
|
|
width: u64,
|
|
/// The height given, in pixels.
|
|
height: u64,
|
|
},
|
|
/// A tile dispatch's threadgroup with no threads along an axis (a compute dispatch of one
|
|
/// runs nothing, as plain Metal's).
|
|
///
|
|
/// Basis: unknown (Metal's answer for a tile dispatch of no threads along an axis is
|
|
/// unmeasured).
|
|
EmptyThreadgroup,
|
|
/// A size past what the call can state: a tile dispatch's or mesh draw's axis past 32 bits
|
|
/// (compute sizes and per-bind attribute strides past 32 bits are taken modulo `2^32`, as
|
|
/// plain Metal takes them).
|
|
///
|
|
/// Basis: unknown (Metal's answer for a tile dispatch's or mesh draw's axis past 32 bits is
|
|
/// unmeasured).
|
|
SizeOutOfRange,
|
|
/// A buffer of no bytes, or more than the device can hold in one: plain Metal answers nil
|
|
/// (`Nil`), from the device, with bytes or over the caller's, and from either type of heap.
|
|
///
|
|
/// Basis: metal-measured (an Apple M3 Max: newBufferWithLength:0 answers nil).
|
|
BufferLength {
|
|
/// The length asked for, in bytes.
|
|
length: u64,
|
|
},
|
|
/// A raw value Metal does not define for this type.
|
|
///
|
|
/// Basis: metal-takes (an Apple M3 Max: setPurgeableState:99, a value MTLPurgeableState does
|
|
/// not define, answers 2, and neither plain Metal nor its API validation refuses it).
|
|
UndefinedValue {
|
|
/// The Metal type's name (`MTLPurgeableState`, for one).
|
|
ty: &'static str,
|
|
/// The raw value given.
|
|
raw: u64,
|
|
},
|
|
/// A storage mode this call does not take (`Memoryless` for a buffer, for one): Metal stops
|
|
/// it (`Invalid`), but a shared texture's other than `Private`, which plain Metal answers nil
|
|
/// for (`Nil`).
|
|
///
|
|
/// Basis: metal-measured (an Apple M3 Max: a buffer of the Memoryless mode asserts "Invalid
|
|
/// storageMode", the API validation layer off).
|
|
StorageMode,
|
|
/// A handler added after the command buffer was committed. Plain Metal asserts too
|
|
/// ("Completed handler provided after commit call").
|
|
///
|
|
/// Basis: metal-documented (Metal asserts "Completed handler provided after commit call").
|
|
HandlerAfterCommit,
|
|
/// The given slices' lengths differ.
|
|
///
|
|
/// Basis: ours (this crate's paired slices: Metal's calls take a count).
|
|
LengthMismatch,
|
|
/// A buffer descriptor that declares the bytes between a texture's rows unobserved
|
|
/// (`BufferDescriptor::padding_unobserved`) with `NoCopy` contents: the declaration is for a
|
|
/// buffer of the runtime's own memory, whose every reader the caller owns, never the caller's
|
|
/// pages, which others may read.
|
|
///
|
|
/// Basis: ours (a runtime extension: Metal has no such declaration).
|
|
PaddingUnobservedNoCopy,
|
|
/// A buffer descriptor that lays a byte of the buffer on a multiple of 256 bytes of its memory
|
|
/// (`BufferDescriptor::aligned_byte`) with `NoCopy` contents: the placement is of the runtime's
|
|
/// own memory, never the caller's pages, whose first byte is where the caller put it.
|
|
///
|
|
/// Basis: ours (a runtime extension: Metal places no buffer's byte).
|
|
AlignedByteNoCopy,
|
|
/// A buffer descriptor that makes the buffer's memory exportable
|
|
/// (`BufferDescriptor::exported_as`) with `NoCopy` contents: the export is of the runtime's own
|
|
/// memory, never the caller's pages, which the caller can hand to another API itself.
|
|
///
|
|
/// Basis: ours (a runtime extension: Metal exports no buffer's memory).
|
|
ExportedNoCopy,
|
|
/// A texture buffer's fill given a pattern of more than 32752 bytes
|
|
/// (`fillTexture:...:bytes:length:`): Metal's process ends in the call, in the blit's
|
|
/// dispatch, whatever the region, of no texels or past the buffer too (an Apple M3 Max under
|
|
/// macOS 27.0.1: `R8Uint`, `R32Uint` and `RGBA32Uint` texture buffers; 32752 bytes are
|
|
/// filled). A fill of any other texture takes a pattern of any length, of which it reads 16
|
|
/// bytes at most.
|
|
///
|
|
/// Basis: metal-measured (an Apple M3 Max, macOS 27.0.1: Metal's process ends in the call).
|
|
LongTextureBufferFillPattern {
|
|
/// The pattern's bytes.
|
|
length: u64,
|
|
},
|
|
/// `offset..offset + size` runs past a resource of `length` bytes: Metal stops it
|
|
/// (`Invalid`). A resource placed past its heap's end is [`HeapProblem::PastEnd`].
|
|
///
|
|
/// Basis: metal-takes (an Apple M3 Max, macOS 27.0.1: didModifyRange of 0+512 and of 240+64 on
|
|
/// a buffer of 256 bytes both return; Metal's API validation alone refuses them).
|
|
RangeOutOfBounds {
|
|
/// The range's first byte.
|
|
offset: u64,
|
|
/// The range's bytes.
|
|
size: u64,
|
|
/// The resource's length, in bytes.
|
|
length: u64,
|
|
},
|
|
/// A shader cache capacity, on disk or in memory, of zero: neither cache can be turned
|
|
/// off.
|
|
///
|
|
/// Basis: ours (this crate's shader caches: Metal exposes no capacity).
|
|
ShaderCacheCapacity,
|
|
/// A command queue's `maxCommandBufferCount` of zero: Metal's command queue creation
|
|
/// validation stops it, with or without API validation.
|
|
///
|
|
/// Basis: metal-measured (an Apple M3 Max: Metal's command queue creation asserts "invalid
|
|
/// descriptor.maxCommandBufferCount value 0", with and without API validation).
|
|
MaxCommandBufferCount,
|
|
/// A texture descriptor Metal stops (`Invalid`), or plain Metal answers nil for (`Nil`):
|
|
/// [`TextureProblem`] says which.
|
|
///
|
|
/// Basis: delegated(TextureProblem).
|
|
Texture(TextureProblem),
|
|
/// A texture view Metal stops, or a use of a texture its usage does not allow.
|
|
///
|
|
/// Basis: delegated(ViewProblem).
|
|
TextureView(ViewProblem),
|
|
/// A texture copy Metal stops: `replace_region`, `get_bytes`, and the blit encoder's.
|
|
///
|
|
/// Basis: delegated(CopyProblem).
|
|
Copy(CopyProblem),
|
|
/// A `generate_mipmaps` Metal stops.
|
|
///
|
|
/// Basis: delegated(MipmapProblem).
|
|
Mipmap(MipmapProblem),
|
|
/// A texture over a buffer plain Metal itself refuses: [`BufferTextureProblem`] says
|
|
/// which, and whether Metal asserts or answers nil.
|
|
///
|
|
/// Basis: delegated(BufferTextureProblem).
|
|
BufferTexture(BufferTextureProblem),
|
|
/// A render pass descriptor, or a render encoder's late store action, Metal stops.
|
|
///
|
|
/// Basis: delegated(RenderPassProblem).
|
|
RenderPass(RenderPassProblem),
|
|
/// A draw, or render encoder state, Metal stops.
|
|
///
|
|
/// Basis: delegated(DrawProblem).
|
|
Draw(DrawProblem),
|
|
/// `new_render_pipeline_state`: the vertex function writes `[[point_size]]` and the input
|
|
/// primitive topology class is line or triangle. Metal's pipeline creation answers an error
|
|
/// here, with or without API validation ("Vertex shader writes point size but
|
|
/// inputPrimitiveTopology is ..."; measured on an M3 Max and an M4).
|
|
///
|
|
/// Basis: metal-measured (an M3 Max and an M4: Metal's pipeline creation answers an error, with
|
|
/// and without API validation).
|
|
PointSizeTopology,
|
|
/// `new_render_pipeline_state`: a tessellation pipeline made with
|
|
/// `supportIndirectCommandBuffers` whose factor scale is enabled. Plain Metal ends its process
|
|
/// over it, the API validation layer off: `-[_MTLRenderPipelineState
|
|
/// initWithDevice:pipelineStateDescriptor:]` asserts "Render Pipeline Descriptor Validation /
|
|
/// pipelines with tessellationFactorScaleEnabled = YES are not compatible with indirect
|
|
/// command buffers", where the same pipeline with either one alone is made and draws its
|
|
/// patches (an M3 Max under macOS 27.0.1). Metal reads its flat
|
|
/// `tessellationFactorScaleEnabled` alone, and asserts for a pipeline of no tessellation state
|
|
/// too; the runtime's descriptor keeps that flag inside its `tessellation`, so a caller cannot
|
|
/// ask for that pair.
|
|
///
|
|
/// Basis: metal-measured (an M3 Max, macOS 27.0.1: plain Metal ends its process, the API
|
|
/// validation layer off).
|
|
IndirectScaledTessellation,
|
|
/// `new_compute_pipeline_state`: a kernel the compile layer already compiled
|
|
/// (`StageSource::Compiled`). Metal's descriptor takes a function, and a state compiles its
|
|
/// kernel again for each variant a dispatch needs.
|
|
///
|
|
/// Basis: ours (this crate's already-compiled stage: Metal's descriptor takes a function).
|
|
CompiledKernel,
|
|
/// `new_compute_pipeline_state`, `new_render_pipeline_state`, `new_tile_render_pipeline_state`
|
|
/// and `new_mesh_render_pipeline_state`: a stage function made by `newFunctionWithName:`, not
|
|
/// specialized (`FunctionDescriptor::specialized`), whose function declares function constants
|
|
/// (its `functionConstantsDictionary` is not empty), whether each is required, or optional and
|
|
/// read only where `is_function_constant_defined` says, or only gates an argument. Plain Metal's
|
|
/// creation ends its process at its descriptor validation ("Compute Pipeline Descriptor
|
|
/// Validation / function ko cannot be used to build a pipeline state. Use
|
|
/// newFunctionWithName:constantValues:... to get the specialized function"; a render or mesh
|
|
/// state's names `vertexFunction`, `fragmentFunction`, `objectFunction` or `meshFunction`, and
|
|
/// a tile state's says "without setting constant values first"). The function made with
|
|
/// constant values, none among them too, or by `newFunctionWithDescriptor:`, is made
|
|
/// (`pipeline/unspecialized.rs`).
|
|
///
|
|
/// Basis: metal-measured (an M3 Max, macOS 27.0.1: plain Metal ends its process at a compute,
|
|
/// render, tile and mesh state of each stage, `MTL_DEBUG_LAYER` unset).
|
|
UnspecializedFunction {
|
|
/// The function's stage: `Kernel` for a compute or tile state's.
|
|
stage: Stage,
|
|
/// The function's name.
|
|
name: String,
|
|
},
|
|
/// `new_compute_pipeline_state`: the kernel's linked `functions` list this name twice, one
|
|
/// function twice or two functions of the name: plain Metal's creation fails ("error:
|
|
/// duplicated symbol: add_one", code 3), and its API validation stops it ("All linked
|
|
/// functions must have unique names"). A name `binary_functions` lists twice, or both
|
|
/// `functions` and `binary_functions` hold, is made, as plain Metal makes it where its API
|
|
/// validation stops it (`pipeline/additions.rs`).
|
|
///
|
|
/// Basis: metal-measured (an M3 Max, macOS 27.0.1: plain Metal's creation fails with code 3,
|
|
/// `binary_function_linking.m`).
|
|
DuplicateLinkedFunction {
|
|
/// The function's name.
|
|
name: String,
|
|
},
|
|
/// A viewport, scissor rectangle or other render encoder state Metal stops at its setter.
|
|
///
|
|
/// Basis: delegated(RenderStateProblem).
|
|
RenderState(RenderStateProblem),
|
|
/// A `set_visibility_result_mode` Metal stops.
|
|
///
|
|
/// Basis: delegated(VisibilityProblem).
|
|
Visibility(VisibilityProblem),
|
|
/// A heap, or a resource placed in one, Metal stops (`new_heap` and the heap's calls).
|
|
///
|
|
/// Basis: delegated(HeapProblem).
|
|
Heap(HeapProblem),
|
|
/// A resource ID, placed or reserved, of `limit` or more: Metal ends the process for one
|
|
/// (`resource_ids.rs`). A pipeline state's is its placement's low 32 bits, which Metal keeps.
|
|
///
|
|
/// Basis: metal-measured (an M4 and an M3 Max, macOS 27.0.1: the IDs at which Metal ends the
|
|
/// process, recorded in `resource_ids.rs`).
|
|
ResourceId {
|
|
/// The resource ID asked for.
|
|
id: u64,
|
|
/// The first ID past the kind's range.
|
|
limit: u64,
|
|
},
|
|
/// An indirect command buffer ID of `limit` (2^31) to 2^32 - 1 in a reservation
|
|
/// (`Device::reserve_resource_ids`): Metal's call never returns there, its pool spinning
|
|
/// (an M3 Max, macOS 27.0.1), so nothing is reserved. A caller matching Metal treats this as
|
|
/// that hang, not as an invalid argument.
|
|
///
|
|
/// Basis: metal-measured (an M3 Max, macOS 27.0.1: Metal's call never returns, its pool
|
|
/// spinning).
|
|
ReservationHangs {
|
|
/// The first such ID in the call.
|
|
id: u64,
|
|
/// The first ID at which Metal's reservation hangs.
|
|
limit: u64,
|
|
},
|
|
/// [`IdPlacement::Outside`](crate::IdPlacement::Outside) for anything but a texture
|
|
/// `Device::new_texture` or `Device::new_texture_with_vk_image` makes: a sampler state, a
|
|
/// pipeline state, an indirect command buffer, a view, or a heap's, a buffer's or a shared
|
|
/// texture. A runtime extension's misuse: Metal has no such placement.
|
|
///
|
|
/// Basis: ours (a runtime extension's misuse: Metal has no such placement).
|
|
OutsidePlacement,
|
|
/// A visible-function table call, or a table or buffer binding a dispatch reads as the other,
|
|
/// Metal stops.
|
|
///
|
|
/// Basis: delegated(FunctionTableProblem).
|
|
FunctionTable(FunctionTableProblem),
|
|
/// An indirect command buffer call plain Metal itself refuses, ending its process or
|
|
/// failing the call: [`IndirectCommandBufferProblem`] says which.
|
|
///
|
|
/// Basis: delegated(IndirectCommandBufferProblem).
|
|
IndirectCommandBuffer(IndirectCommandBufferProblem),
|
|
/// A rasterization-rate map's descriptor Metal stops (`new_rasterization_rate_map`).
|
|
///
|
|
/// Basis: delegated(RateMapProblem).
|
|
RateMap(RateMapProblem),
|
|
/// An argument encoder call Metal stops, raises for, or answers nil for.
|
|
///
|
|
/// Basis: delegated(ArgumentEncoderProblem).
|
|
ArgumentEncoder(ArgumentEncoderProblem),
|
|
/// An indirect dispatch's `bytes` of arguments at `offset` that run past the bytes the runtime
|
|
/// holds at Metal's address in its buffer of `length` bytes (`Buffer::copy_reach`: a no-copy
|
|
/// buffer's host pages to the end of its `VkBuffer`, else the length). An offset that is not a
|
|
/// multiple of 4 is read at the multiple below, as plain Metal reads it, and checked from
|
|
/// there. The same for a stage-in region read from a buffer
|
|
/// (`set_stage_in_region_indirect`), whose arguments Metal reads the same way.
|
|
///
|
|
/// Arguments past the buffer's `length` but inside its allocation are **taken**, and run: that
|
|
/// is where plain Metal reads them, and the runtime reads the same bytes there. Measured on an
|
|
/// Apple M3 Max under macOS 27.0.1 with the API validation layer off: a no-copy buffer of
|
|
/// length 8 over a 16 KiB page holding group counts `(7, 1, 1)` ran its
|
|
/// `dispatchThreadgroupsWithIndirectBuffer:` and the kernel counted 7 threadgroups, so Metal
|
|
/// read the third `u32` at byte 8, past the length; a 256-byte buffer of `(3, 1, 1)` counted
|
|
/// 3, so the counts are read from the buffer. Metal's API validation layer reports such a
|
|
/// range ("(indirectBufferOffset +
|
|
/// sizeof(MTLDispatchThreadgroupsIndirectArguments))(12) must be <= \[indirectBuffer
|
|
/// length\](8)") and plain Metal runs the dispatch anyway, as measured; a program running with
|
|
/// the layer and `MTL_DEBUG_LAYER_ERROR_MODE=assert` ends there instead, so taking the range
|
|
/// matches plain Metal and not a validated run.
|
|
///
|
|
/// Past the reach the runtime holds none of the bytes Metal reads, and refuses, as a blit's
|
|
/// read past a buffer's reach is refused.
|
|
///
|
|
/// Basis: metal-takes (an Apple M3 Max under macOS 27.0.1: an indirect dispatch whose 12 bytes
|
|
/// of arguments run past its buffer of 8 bytes runs and counts right; Metal's API validation
|
|
/// alone refuses it. Arguments inside the buffer's allocation are taken now, so what the
|
|
/// refusal still reaches past Metal for is the slice past the bytes the runtime holds there).
|
|
IndirectDispatchRange {
|
|
/// The offset the arguments are read at: the offset given, rounded down to a multiple
|
|
/// of 4.
|
|
offset: u64,
|
|
/// The arguments' bytes.
|
|
bytes: u64,
|
|
/// The buffer's length.
|
|
length: u64,
|
|
},
|
|
/// A sparse heap's or texture's call Metal stops, or answers nil for.
|
|
///
|
|
/// Basis: delegated(SparseProblem).
|
|
Sparse(SparseProblem),
|
|
/// A buffer the caller made that cannot be wrapped as a Metal buffer of the length and
|
|
/// storage (`new_buffer_with_vk_buffer`).
|
|
///
|
|
/// Basis: ours (a runtime extension: Metal wraps no Vulkan buffer).
|
|
WrappedBuffer(WrappedBufferProblem),
|
|
/// A pipeline's `requiredThreadsPerThreadgroup` that Metal refuses at creation. A dispatch
|
|
/// whose threadgroup size is not it runs at the size it gives, as plain Metal runs it (API
|
|
/// validation stops it).
|
|
///
|
|
/// Basis: delegated(RequiredThreadsProblem).
|
|
RequiredThreads(RequiredThreadsProblem),
|
|
/// A pipeline's binary functions that Metal refuses: not precompiled (plain Metal's error,
|
|
/// [`Error::MetalError`]), in a mesh pipeline's object or mesh stage, or added to a stage of a
|
|
/// state that cannot take them.
|
|
///
|
|
/// Basis: delegated(BinaryFunctionProblem).
|
|
BinaryFunctions(BinaryFunctionProblem),
|
|
/// A function made by name from a dynamic library (`newFunctionWithName:` and its forms):
|
|
/// Metal stops at an assertion ("type is not a valid MTLFunctionType") for every name, a
|
|
/// kernel the library holds among them (a probe, an M3 Max and an M4, plain and under API
|
|
/// validation).
|
|
///
|
|
/// Basis: metal-measured (an M3 Max and an M4, plain and under API validation: Metal asserts
|
|
/// "type is not a valid MTLFunctionType").
|
|
DynamicLibraryFunction,
|
|
/// `rebind_bytes_no_copy` of a buffer or heap the runtime cannot rebind as asked (a runtime
|
|
/// extension; `rebind.rs`).
|
|
///
|
|
/// Basis: ours (a runtime extension: Metal rebinds no bytes under a buffer).
|
|
Rebind(RebindProblem),
|
|
/// `new_render_pipeline_state`, `new_mesh_render_pipeline_state` or
|
|
/// `new_compute_pipeline_state` of a descriptor with `supportIndirectCommandBuffers` whose
|
|
/// `stage` function uses a direct texture or sampler argument (`[[texture(n)]]`,
|
|
/// `[[sampler(n)]]`; its reflection's used bindings of those types): plain Metal answers nil
|
|
/// with an `NSError` ([`Error::MetalError`]), on an M3 Max under macOS 26.7 and an M4 under
|
|
/// 27.0.1 alike. Unused ones, an argument buffer's textures and samplers, and constexpr
|
|
/// samplers are made. Metal names the fragment function first, then
|
|
/// the vertex, mesh and object functions. Its error: code 3, `localizedDescription` "Vertex
|
|
/// shader cannot be used with indirect command buffers" (and "Fragment shader", "Mesh
|
|
/// shader", "Object shader", "Compute function" alike), `userInfo` holding that alone, and
|
|
/// the domain of Metal's GPU driver class, which follows the device: `AGXMetalG15X_M1` on the
|
|
/// M3 Max, which the runtime answers, and `AGXMetalG16G_B0` on the M4.
|
|
///
|
|
/// Basis: metal-measured (an M3 Max under macOS 26.7 and an M4 under 27.0.1: plain Metal
|
|
/// answers nil with an NSError).
|
|
IndirectCommandsDirectArgument {
|
|
/// The function's stage: `Vertex`, `Fragment`, `Mesh`, `Object`, or `Kernel` (a compute
|
|
/// state's).
|
|
stage: Stage,
|
|
},
|
|
/// `new_render_pipeline_state` of a descriptor with rasterization disabled whose vertex
|
|
/// function's return type is not `void`: plain Metal answers nil with an `NSError`
|
|
/// ([`Error::MetalError`]) with or without `supportIndirectCommandBuffers`, before the
|
|
/// indirect command buffers' refusal (on an M4 under macOS 27.0.1), a post-tessellation vertex
|
|
/// function's too. Its error: code 3, `localizedDescription` "RasterizationEnabled is false but
|
|
/// the vertex shader's return type is not void", `userInfo` holding that alone, and the domain
|
|
/// of Metal's GPU driver class, as [`Problem::IndirectCommandsDirectArgument`]'s.
|
|
///
|
|
/// Basis: metal-measured (an M4, macOS 27.0.1: plain Metal answers nil with an NSError).
|
|
UnrasterizedVertexReturn,
|
|
/// `new_render_pipeline_state` of a descriptor with rasterization enabled whose vertex
|
|
/// function's return type is `void`, with or without a fragment function, outside OpenGL mode
|
|
/// (`PrivateRenderState::open_gl_mode_enabled`, with which Metal makes it, rasterizing
|
|
/// nothing): plain Metal answers nil with an `NSError` ([`Error::MetalError`]) (on an M3 Max
|
|
/// under macOS 27.0.1). Its error: code 3, `localizedDescription` "RasterizationEnabled is
|
|
/// true but the vertex shader's return type is void", `userInfo` holding that alone, and the
|
|
/// domain of Metal's GPU driver class, as [`Problem::IndirectCommandsDirectArgument`]'s.
|
|
///
|
|
/// Basis: metal-measured (an M3 Max, macOS 27.0.1: plain Metal answers nil with an NSError).
|
|
RasterizedVoidVertex,
|
|
/// `new_render_pipeline_state` (a render or mesh state) of a descriptor with
|
|
/// `supportIndirectCommandBuffers` whose function of `stage`, the first in the order Metal
|
|
/// names them that uses a direct texture or sampler once linked, uses one only by a rule the
|
|
/// runtime keeps beyond Metal where Metal's answer is unmeasured, `reason`
|
|
/// ([`Error::Unproven`]). Metal may make the state, or refuse it as
|
|
/// [`Problem::IndirectCommandsDirectArgument`]; every use a measured rule keeps is that problem
|
|
/// instead.
|
|
///
|
|
/// Basis: unknown (Metal's answer for a use only this rule keeps is unmeasured, so the state is
|
|
/// refused as unproven).
|
|
IndirectCommandsDirectArgumentUnproven {
|
|
/// The function's stage: `Vertex`, `Mesh` or `Fragment`.
|
|
stage: Stage,
|
|
/// The rule that keeps the use.
|
|
reason: LinkedUseGap,
|
|
},
|
|
/// `new_render_pipeline_state`, `new_mesh_render_pipeline_state` or
|
|
/// `new_compute_pipeline_state` of a descriptor with `supportIndirectCommandBuffers` where the
|
|
/// compile layer refuses to say whether its functions use a direct texture or sampler
|
|
/// argument, `refusal` ([`Error::Unproven`]): a stage the compile layer already compiled that
|
|
/// kept no reflection (`Unsupported` with `Feature::Reflection`), or the decode's or
|
|
/// specialization's own refusal (The use is decided from the arguments' roles, so an argument
|
|
/// whose reflection Metal's answer has not been measured for no longer refuses it). Metal may
|
|
/// make the state, or refuse it as [`Problem::IndirectCommandsDirectArgument`]; the runtime
|
|
/// makes no state it cannot decide that for.
|
|
///
|
|
/// Basis: ours (the compile layer will not say whether the functions use one, so no state is
|
|
/// made).
|
|
IndirectCommandsDirectArgumentUndecided {
|
|
/// The compile layer's refusal.
|
|
refusal: Box<CompileError>,
|
|
},
|
|
/// `new_render_pipeline_state` of a descriptor without a depth attachment whose fragment
|
|
/// function writes depth (a `[[depth(...)]]` output), outside OpenGL mode
|
|
/// (`PrivateRenderState::open_gl_mode_enabled`, with which Metal makes it, the depth going
|
|
/// nowhere; on an M3 Max under macOS 27.0.1): plain Metal answers nil with an
|
|
/// `NSError` ([`Error::MetalError`]) with or without rasterization, a color attachment or
|
|
/// `supportIndirectCommandBuffers`, before the indirect command buffers' refusal (on an M4
|
|
/// under macOS 27.0.1); `new_mesh_render_pipeline_state` alike, first. Its error: code 3,
|
|
/// `localizedDescription` "depthAttachmentPixelFormat is not valid and shader writes to depth",
|
|
/// and the domain of Metal's GPU driver class, as
|
|
/// [`Problem::IndirectCommandsDirectArgument`]'s.
|
|
///
|
|
/// Basis: metal-measured (an M4, macOS 27.0.1: plain Metal answers nil with an NSError).
|
|
DepthWrittenWithoutAttachment,
|
|
/// `new_render_pipeline_state` of a descriptor whose fragment function's stage inputs
|
|
/// `inputs` (their MSL member names, in declaration order), which its linking keeps, are
|
|
/// written by no vertex output, with or without rasterization: plain Metal answers nil with an
|
|
/// `NSError` ([`Error::MetalError`]), after the indirect command buffers' refusal (on an M4
|
|
/// under macOS 27.0.1). Its error: code 3, `localizedDescription` "Fragment input(s) `c,d`
|
|
/// mismatching vertex shader output type(s) or not written by vertex shader" with `inputs`
|
|
/// joined by commas, and the domain of Metal's GPU driver class. A post-tessellation vertex
|
|
/// function's alike, and `new_mesh_render_pipeline_state`'s where the mesh function writes no
|
|
/// per-vertex or per-primitive data of them, its text naming the "mesh shader".
|
|
///
|
|
/// Basis: metal-measured (an M4, macOS 27.0.1: plain Metal answers nil with an NSError).
|
|
UnwrittenFragmentInputs {
|
|
/// The inputs' names.
|
|
inputs: Box<[String]>,
|
|
},
|
|
/// [`Problem::UnwrittenFragmentInputs`] where only a rule kept beyond Metal keeps such an
|
|
/// input (`reason`): Metal may make the state ([`Error::Unproven`]).
|
|
///
|
|
/// Basis: unknown (Metal may make the state; the input is kept by a rule beyond Metal).
|
|
UnwrittenFragmentInputsUnproven {
|
|
/// The inputs' names, as every rule keeps them.
|
|
inputs: Box<[String]>,
|
|
/// The rule that keeps one.
|
|
reason: LinkedUseGap,
|
|
},
|
|
/// `new_render_pipeline_state` or `new_mesh_render_pipeline_state` of a descriptor whose
|
|
/// `attachment` is in a pixel format (`format`) Metal describes none of
|
|
/// ([`Device::pixel_format_info`](crate::Device::pixel_format_info) answers
|
|
/// [`PixelFormatInfo::INVALID`](crate::PixelFormatInfo::INVALID)): the three-channel ones, the
|
|
/// values from 630 to 650 (an Apple M4 describes 630 to 645, an M3 Max none of them), and
|
|
/// `Depth24Unorm_Stencil8` and `X24_Stencil8` (an Apple GPU has neither).
|
|
/// Plain Metal's descriptor validation stops it ("pixelFormat, for color render target(0), is
|
|
/// not a valid MTLPixelFormat", "depthAttachmentPixelFormat is not a valid MTLPixelFormat";
|
|
/// on an Apple M4 under 27.0.1, the consumer's run on an M3 Max under 26.7),
|
|
/// blended or not, before anything else; the first such attachment is named (the colors by
|
|
/// index, then depth, then stencil).
|
|
///
|
|
/// Basis: metal-measured (an Apple M4 under macOS 27.0.1, and the consumer's run on an M3 Max
|
|
/// under 26.7: Metal's descriptor validation stops it).
|
|
AttachmentNotAFormat {
|
|
/// The attachment.
|
|
attachment: Attachment,
|
|
/// Its pixel format.
|
|
format: PixelFormat,
|
|
},
|
|
/// `new_render_pipeline_state` or `new_mesh_render_pipeline_state` of a `rasterSampleCount`
|
|
/// other than 1, 2 and 4, and `new_tile_render_pipeline_state` of 0, on every device: plain
|
|
/// Metal answers nil with an `NSError` (code 2, "rasterSampleCount (8) is not supported by
|
|
/// device."; on an Apple M4 under 27.0.1, with and without API validation), an
|
|
/// [`Error::MetalError`]. A device whose Vulkan driver rasterizes more
|
|
/// samples makes no such state either.
|
|
///
|
|
/// Basis: metal-measured (an Apple M4, macOS 27.0.1: plain Metal answers nil with an NSError,
|
|
/// with and without API validation).
|
|
RasterSampleCount {
|
|
/// The `rasterSampleCount` given.
|
|
count: u32,
|
|
},
|
|
}
|
|
|
|
/// Why `DeviceOptions::instance_api_version` cannot be requested. The runtime never clamps a
|
|
/// request to what it can make.
|
|
#[non_exhaustive]
|
|
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
|
pub enum InstanceApiVersion {
|
|
/// Below Vulkan 1.2, the runtime's floor.
|
|
BelowFloor {
|
|
/// The version requested.
|
|
requested: ApiVersion,
|
|
},
|
|
/// Above the version the Vulkan loader reports (`vkEnumerateInstanceVersion`; 1.0 where the
|
|
/// loader has no such command).
|
|
AboveLoader {
|
|
/// The version requested.
|
|
requested: ApiVersion,
|
|
/// The version the loader reports.
|
|
loader: ApiVersion,
|
|
},
|
|
}
|
|
|
|
/// The device's sampler count at its limit (`Error::SamplerLimit`).
|
|
#[non_exhaustive]
|
|
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
|
pub struct SamplerLimit {
|
|
/// The device's `maxSamplerAllocationCount`.
|
|
pub limit: u32,
|
|
}
|
|
|
|
/// Why a shader cache directory cannot be used.
|
|
#[non_exhaustive]
|
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
|
pub struct ShaderCacheError {
|
|
/// The directory, or `None` when there is no default one (no home directory).
|
|
pub path: Option<PathBuf>,
|
|
/// The I/O error's kind.
|
|
pub kind: std::io::ErrorKind,
|
|
/// The I/O error's text.
|
|
pub message: String,
|
|
}
|
|
|
|
impl ShaderCacheError {
|
|
/// The failure `kind` (`message`) of `path`.
|
|
pub fn new(path: Option<PathBuf>, kind: std::io::ErrorKind, message: &str) -> ShaderCacheError {
|
|
ShaderCacheError {
|
|
path,
|
|
kind,
|
|
message: message.to_string(),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl fmt::Display for ShaderCacheError {
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
match &self.path {
|
|
Some(path) => write!(
|
|
f,
|
|
"the shader cache directory {} cannot be used: {}",
|
|
path.display(),
|
|
self.message
|
|
),
|
|
None => write!(f, "no shader cache directory: {}", self.message),
|
|
}
|
|
}
|
|
}
|
|
|
|
/// Why a binary archive cannot be loaded or serialized (`MTLBinaryArchiveError`).
|
|
#[non_exhaustive]
|
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
|
pub enum BinaryArchiveError {
|
|
/// `MTLBinaryArchiveErrorInvalidFile`: the file to load is missing or not an archive, or
|
|
/// the directory to serialize into is missing, as Metal answers (measured on an M3 Max and
|
|
/// an M4).
|
|
InvalidFile {
|
|
/// The file or directory.
|
|
path: PathBuf,
|
|
},
|
|
/// `MTLBinaryArchiveErrorCompilationFailure`, "Nothing to serialize": nothing was added to
|
|
/// the archive or loaded into it.
|
|
NothingToSerialize,
|
|
/// The file cannot be written, where Metal answers the file system's error (a directory at
|
|
/// the path, for one): the path, and the I/O error's kind and text.
|
|
Write {
|
|
/// The file.
|
|
path: PathBuf,
|
|
/// The I/O error's kind.
|
|
kind: std::io::ErrorKind,
|
|
/// The I/O error's text.
|
|
message: String,
|
|
},
|
|
}
|
|
|
|
impl fmt::Display for BinaryArchiveError {
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
match self {
|
|
BinaryArchiveError::InvalidFile { path } => {
|
|
write!(f, "{} is not a binary archive", path.display())
|
|
}
|
|
BinaryArchiveError::NothingToSerialize => f.write_str("Nothing to serialize"),
|
|
BinaryArchiveError::Write { path, message, .. } => {
|
|
write!(
|
|
f,
|
|
"the binary archive {} cannot be written: {message}",
|
|
path.display()
|
|
)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// Why a dynamic library's file cannot be loaded or written (`MTLDynamicLibraryError`).
|
|
#[non_exhaustive]
|
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
|
pub enum DynamicLibraryError {
|
|
/// `MTLDynamicLibraryErrorInvalidFile`: the file to load holds no library ("its AIR slice is
|
|
/// missing"), or the directory to serialize into is missing ("Invalid URL"), as Metal
|
|
/// answers (a probe, an M3 Max and an M4).
|
|
InvalidFile {
|
|
/// The file.
|
|
path: PathBuf,
|
|
},
|
|
/// The file to load cannot be read, where Metal answers the file system's error (a missing
|
|
/// file is `NSCocoaErrorDomain` 260): the path, and the I/O error's kind and text.
|
|
Read {
|
|
/// The file.
|
|
path: PathBuf,
|
|
/// The I/O error's kind.
|
|
kind: std::io::ErrorKind,
|
|
/// The I/O error's text.
|
|
message: String,
|
|
},
|
|
/// The file cannot be written, where Metal answers the file system's error (a directory at
|
|
/// the path, for one): the path, and the I/O error's kind and text.
|
|
Write {
|
|
/// The file.
|
|
path: PathBuf,
|
|
/// The I/O error's kind.
|
|
kind: std::io::ErrorKind,
|
|
/// The I/O error's text.
|
|
message: String,
|
|
},
|
|
}
|
|
|
|
impl fmt::Display for DynamicLibraryError {
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
match self {
|
|
DynamicLibraryError::InvalidFile { path } => {
|
|
write!(f, "{} is not a dynamic library's file", path.display())
|
|
}
|
|
DynamicLibraryError::Read { path, message, .. } => {
|
|
write!(
|
|
f,
|
|
"the dynamic library {} cannot be read: {message}",
|
|
path.display()
|
|
)
|
|
}
|
|
DynamicLibraryError::Write { path, message, .. } => {
|
|
write!(
|
|
f,
|
|
"the dynamic library {} cannot be written: {message}",
|
|
path.display()
|
|
)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// The pipeline a creation under `PipelineOption::FAIL_ON_BINARY_ARCHIVE_MISS` found in no
|
|
/// listed binary archive. Metal answers its creation nil with an error of code 3 for each kind
|
|
/// of pipeline, compute, render and tile alike (the consumer's measurement, an M3 Max under
|
|
/// macOS 26.7), whose text [`Display`](fmt::Display) gives.
|
|
#[non_exhaustive]
|
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
|
pub struct BinaryArchiveMiss {
|
|
/// The function Metal names: a compute pipeline's kernel; a tile pipeline's tile function;
|
|
/// a render pipeline's first stage whose archive key no listed archive holds, its fragment
|
|
/// function before its vertex function (the fragment function for a color change; the vertex
|
|
/// function where the fragment's key is held, as for a topology change, or where the pipeline
|
|
/// has no fragment function).
|
|
pub function: String,
|
|
/// The kind of pipeline.
|
|
pub pipeline: ArchivedPipeline,
|
|
}
|
|
|
|
impl BinaryArchiveMiss {
|
|
/// `pipeline`, of `function`, found in no archive.
|
|
pub fn new(function: &str, pipeline: ArchivedPipeline) -> BinaryArchiveMiss {
|
|
BinaryArchiveMiss {
|
|
function: function.to_string(),
|
|
pipeline,
|
|
}
|
|
}
|
|
}
|
|
|
|
impl fmt::Display for BinaryArchiveMiss {
|
|
/// Metal's text (measured on an M3 Max and an M4): `Unable to find function "<function>"
|
|
/// (compute pipeline) in binary archives.`, with `render pipeline` or `tile pipeline` for
|
|
/// those kinds.
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
let pipeline = match self.pipeline {
|
|
ArchivedPipeline::Compute => "compute",
|
|
ArchivedPipeline::Render => "render",
|
|
ArchivedPipeline::Tile => "tile",
|
|
};
|
|
write!(
|
|
f,
|
|
"Unable to find function \"{}\" ({pipeline} pipeline) in binary archives.",
|
|
self.function
|
|
)
|
|
}
|
|
}
|
|
|
|
/// A kind of pipeline a binary archive holds.
|
|
#[non_exhaustive]
|
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
|
pub enum ArchivedPipeline {
|
|
/// A compute pipeline (`newComputePipelineStateWithDescriptor:...`).
|
|
Compute,
|
|
/// A render pipeline (`newRenderPipelineStateWithDescriptor:...`).
|
|
Render,
|
|
/// A tile render pipeline (`Device::new_tile_render_pipeline_state`).
|
|
Tile,
|
|
}
|
|
|
|
/// 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 {
|
|
/// Textures and texture buffers.
|
|
Textures,
|
|
/// The resource-ID heap, descriptor set 1.
|
|
ResourceHeap,
|
|
/// Sparse heaps and their textures.
|
|
SparseHeaps,
|
|
/// What the runtime's emulation of sparse textures does not build yet: a tile map of a cube or
|
|
/// multisampled sparse texture, which the tile-map format has no layout for; a sparse texture
|
|
/// whose unmapped texels the runtime cannot zero (a single-sampled one of a format the device
|
|
/// copies nothing into, a multisampled one of a format it does not clear and render); and a
|
|
/// sparse heap or texture on a device that binds no sparse memory (`sparseBinding`, or the
|
|
/// queue family's bit) where functions read the image's own residency (it enables
|
|
/// `shaderResourceResidency`), whose exact path is the tile-map arm.
|
|
SparseTileMaps,
|
|
/// A heap larger than the device's `maxBufferSize`, which the device can allocate: the
|
|
/// runtime places a heap's buffers in one `VkBuffer` over the whole heap, which no `VkBuffer`
|
|
/// that size can be. Windows of `VkBuffer`s over the one allocation are the exact path.
|
|
HeapPastMaxBufferSize {
|
|
/// The heap's size, in bytes.
|
|
size: u64,
|
|
/// The device's `maxBufferSize`.
|
|
max_buffer_size: u64,
|
|
},
|
|
/// A heap texture an image of binds into the heap's own memory whose image needs an alignment
|
|
/// past that memory's base alignment (256 KiB): no offset in the heap is sure to meet it. The
|
|
/// base is the largest image alignment measured (an RX 7900 XTX's multisample images under
|
|
/// RADV). A texture whose every image lies in memory of its own instead binds nothing there
|
|
/// and is not refused with it, whatever alignment it answers.
|
|
HeapTextureAlignment {
|
|
/// The alignment the image needs, in bytes.
|
|
alignment: u64,
|
|
},
|
|
/// A heap texture whose image the heap's memory type does not take: an optimal image whose
|
|
/// memory types (a depth format's, which Vulkan lets differ from a color image's) leave out
|
|
/// the heap's. Memory of its own would lose the heap's aliasing. (A texture whose linear image
|
|
/// needs extended usage is checked format by format, not refused with it.) In a heap over host
|
|
/// pages, also a texture no linear image over the pages serves and no shadow of the heap's
|
|
/// bytes holds. A multisample texture there is made in memory of its own.
|
|
HeapTextureMemory,
|
|
/// A visible-function table of more entries than one buffer of the device's
|
|
/// `max_buffer_length` holds words for, or than its size word holds: the runtime keeps a
|
|
/// table's words in one buffer. Metal makes such a table on an M3 Max and ends the process on
|
|
/// an M4.
|
|
FunctionTablePastMaxBufferLength {
|
|
/// The table's entries.
|
|
count: u64,
|
|
/// The device's `max_buffer_length`.
|
|
max_buffer_length: u64,
|
|
},
|
|
/// An indirect command buffer of more commands than one buffer of the device's
|
|
/// `max_buffer_length` holds the records of: the runtime keeps them in one buffer.
|
|
IndirectCommandBufferPastMaxBufferLength {
|
|
/// The buffer's commands.
|
|
count: u64,
|
|
/// The device's `max_buffer_length`.
|
|
max_buffer_length: u64,
|
|
},
|
|
/// What indirect command buffers lack of their render commands: a command whose mesh draw's
|
|
/// object function has threadgroup memory arguments, whose lengths (the command's
|
|
/// `setObjectThreadgroupMemoryLength:atIndex:` or the encoder's) are not measured; an
|
|
/// execution of a range a draw of the encoder before
|
|
/// it may write, or of commands that need a render pass instance of their own (a fetched
|
|
/// attachment, the shader-side stencil, views, a fragment imageblock, a texture whose shadow
|
|
/// the pass does not hold, or a memoryless attachment the pass backs and reads past its
|
|
/// instances); an execution of render commands by a compute encoder, or of compute commands by
|
|
/// a render encoder; a command whose functions statically use a texture slot of the encoder
|
|
/// that holds a memoryless texture, at which Metal's answer is not measured (an encoder's own
|
|
/// draw fails the command buffer, [`CommandBufferError::InvalidResource`]); and, on a device
|
|
/// that claims Apple10, a depth/stencil state's ID, which names the state such a command sets.
|
|
IndirectRenderCommands,
|
|
/// An indirect compute command's imageblock side past 65535, which Metal keeps: the record
|
|
/// holds 16 bits a side, as a kernel's `set_imageblock_size` writes it, and no dispatch runs
|
|
/// an imageblock of more than 1024 cells.
|
|
IndirectImageblockSize {
|
|
/// The imageblock's width.
|
|
width: u64,
|
|
/// The imageblock's height.
|
|
height: u64,
|
|
},
|
|
/// The device replay of indirect command buffers; and an executed compute command of a buffer
|
|
/// that inherits the encoder's buffers whose kernel statically uses a texture slot of the
|
|
/// encoder that holds a memoryless texture, at which Metal's answer is not measured (an
|
|
/// encoder's own dispatch fails the command buffer, [`CommandBufferError::InvalidResource`]).
|
|
CommandReplay,
|
|
/// Render attachments and their binding forms.
|
|
RenderAttachments,
|
|
/// Acceleration structures.
|
|
AccelerationStructures,
|
|
/// A feature a created device would enable that the runtime's feature chain has no member
|
|
/// for, or whose structure no enabled extension exposes.
|
|
FeatureEnable(VkFeature),
|
|
/// An extension a created device would enable that the device lists under none of the names
|
|
/// the runtime knows for it.
|
|
ExtensionEnable(VkExtension),
|
|
/// Render pipelines, passes and draws.
|
|
Render,
|
|
/// 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 makes, of a shape whose texels another form
|
|
/// holds than a shadow's copies of its rows: a two-plane YCbCr texture's codes, a two-plane
|
|
/// extended-range one's, a 4:2:2 one's pairs, a depth or stencil plane's elements, a BC
|
|
/// texture's blocks, and a rotated texture's stored frame. A colour plane is made, its
|
|
/// texels past the surface in a tail of its own
|
|
/// ([`Buffer::new_texture_with_iosurface_plane`](crate::Buffer::new_texture_with_iosurface_plane),
|
|
/// announced as `Degradation::SurfaceTexelsTail`), as a 2D texture, an array or a texture
|
|
/// buffer over a buffer is made past its length
|
|
/// ([`Buffer::new_texture`](crate::Buffer::new_texture)). Metal lays a plane's in no one place
|
|
/// (`metal2vulkan-conformance/probes/surface_texture_envelope.m`, an Apple M3 Max under macOS
|
|
/// 27.0.1): its blits read zeros past the surface, its kernels zeros and, 32 KiB on, the
|
|
/// surface's first bytes again, its `getBytes` other memory, and its blits and
|
|
/// `replaceRegion` write the surface's bytes alone. The x86 Macs' are not measured, as a read
|
|
/// past a surface can fault their GPUs.
|
|
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
|
|
/// than one row of more than 16 bytes, at a `bytesPerRow` whose multiple of 16 below it is
|
|
/// shorter than the row. Metal makes it; its GPU reads the rows that far apart, and where two
|
|
/// 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 texture over a plane of an IOSurface with planes (`Buffer::new_texture_with_iosurface_plane`,
|
|
/// the stand-in for `newTextureWithDescriptor:iosurface:plane:`) that Metal makes, whose
|
|
/// texels it lays out no one way, and that the runtime holds in no form: a 2D texture whose
|
|
/// rows are wider than the plane's `bytesPerRow`, or a 1D texture wider than the row, of a
|
|
/// format but a colour one or over a plane at an offset or `bytesPerRow` off 16 bytes; a 2D
|
|
/// texture of more than one mip level, a 3D or a 2D multisample texture of a format but a
|
|
/// colour one; a 2D array of more than one slice of a format but a colour one, or over a
|
|
/// plane at an offset or `bytesPerRow` off 16 bytes; any other type but 2D, 3D, 2D
|
|
/// multisample, 2D array, texture buffer and 1D; and a BC texture of another type than 2D,
|
|
/// wider than the plane's rows, of 16-byte blocks (BC2, BC3, BC5, BC6H, BC7) over a plane at
|
|
/// an offset or `bytesPerRow` off 16 bytes, or of 8-byte blocks (BC1, BC4) at an offset or
|
|
/// `bytesPerRow` off 8 bytes or under 16 bytes a row. A BC1 or BC4 texture at an offset or
|
|
/// `bytesPerRow` off 16 that 8 divides is made at the plane's own offset and pitch on every
|
|
/// path, as the x86 Macs' blits and samples take it (the M3 Max answers nil). A
|
|
/// colour 2D texture whose rows are wider than the plane's `bytesPerRow` and a colour 1D
|
|
/// texture wider than the row, over a plane at multiples of 16, are made with their rows
|
|
/// `bytesPerRow` apart on every path, as the M3 Max lays them out, a 2D texture's rows
|
|
/// overlapping (announced as `Degradation::CollidingSurfaceRowWrites`). A colour 2D texture
|
|
/// of several levels, a 3D and a 2D multisample one are made in memory of their own, their
|
|
/// texels in no one place on the M3 Max, their first level and slice among them (announced
|
|
/// as `Degradation::SurfaceTexelsApart`); and a colour 2D array of more than one slice keeps
|
|
/// its first slice over the plane and its others in a tail of its own (announced as
|
|
/// `Degradation::SurfaceTexelsTail`). A cube or cube array there is
|
|
/// Metal's own refusal (`Invalid`: plain Metal asserts "carriesComplexTexture || numFaces ==
|
|
/// 1", the API validation layer off), and a texture buffer at an offset or `bytesPerRow` off
|
|
/// 16 is made, its functions reading from the offset rounded down to 16 and its CPU calls
|
|
/// from the offset, as the M3 Max's do.
|
|
///
|
|
/// Measured (`metal2vulkan-conformance/probes/surface_texture_envelope.m`, each texel's bytes
|
|
/// tagged, read by blit, kernel and `getBytes` and written by blit and `replaceRegion`, on an
|
|
/// AMD Radeon Pro 5300M and an Intel UHD 630 under macOS 26.7.1 and an Apple M3 Max under
|
|
/// 27.0.1; every one of these made on all three, but the M3's cube and cube array, at which
|
|
/// its own assertion ends the process, and its BC textures, for which it answers nil): no
|
|
/// layout holds them. Rows wider than the pitch overlap the next row on the M3's GPU and CPU
|
|
/// alike (the runtime's layout, over a plane at multiples of 16), while the UHD 630's GPU
|
|
/// keeps no texel past the pitch and the 5300M's blit into the texture changes no byte of the
|
|
/// surface and its kernels read the rows at another pitch. Levels past 0 lie at the plane's
|
|
/// base on the M3's CPU and elsewhere on its GPU, and in no byte of the surface on the two
|
|
/// x86 GPUs (zeros, or other memory), while their CPU lays them after level 0 or reads zeros.
|
|
/// A second slice of a 2D array or 3D texture lies one image on for the UHD 630 inside the
|
|
/// plane and nowhere past it, at the plane's base for the 5300M's and the M3's blits and CPU,
|
|
/// and in zeros or one image on for their kernels. A 1D texture wider than the row: the 5300M's blit writes its first row's
|
|
/// worth alone, and the UHD 630's writes the rest 8 KiB on. A multisample one reaches past
|
|
/// the plane's bytes and is not measured on the x86 GPUs. The offsets off 16 are not measured
|
|
/// for those formats, nor for a BC texture of 16-byte blocks: only BC1 was, at offset 8 and at
|
|
/// 264 bytes a row (`bgraat8.bc1`, `bgrarow264.bc1`).
|
|
SurfacePlaneShape,
|
|
/// 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
|
|
/// not copy both ways, as a stand-in made with it is copied, a stencil-only one (`S8_UINT`,
|
|
/// which Vulkan does not let take it) on a device none of whose combined formats renders
|
|
/// through a scratch image made with it, or a device without `variableSampleLocations`, which
|
|
/// takes them only at the pass's begin (`VkRenderPassSampleLocationsBeginInfoEXT`)
|
|
/// (`sample_positions.rs`).
|
|
SamplePositionsAtBegin,
|
|
/// A draw at custom sample positions (`setSamplePositions:count:`) through a pipeline whose
|
|
/// fragment function reads an `interpolant` at a sample it names (`interpolate_at_sample`,
|
|
/// [`GraphicsState::interpolates_at_sample`](metal2vulkan::pipeline::GraphicsState::interpolates_at_sample)):
|
|
/// Vulkan takes no `InterpolateAtSample` in a pipeline made with custom sample locations
|
|
/// (`VUID-VkGraphicsPipelineCreateInfo-sampleLocationsEnable-01524`), and where Metal reads
|
|
/// such a sample at custom positions is not measured. The same draw at the device's own
|
|
/// positions runs.
|
|
InterpolateAtSampleWithPositions,
|
|
/// A buffer whose memory another API imports (`Device::new_exportable_buffer`, a runtime
|
|
/// extension: Metal has none) on a device that does not enable `VK_KHR_external_memory_fd`
|
|
/// (the runtime enables it wherever the device lists it; an adopted device's consumer
|
|
/// enables it or not), or that exports no buffer's memory as an opaque file descriptor
|
|
/// (`vkGetPhysicalDeviceExternalBufferProperties` answers
|
|
/// `VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT` not exportable for the runtime's buffer
|
|
/// usage). Every other buffer is made as before.
|
|
ExportableMemory,
|
|
/// A buffer whose memory another API imports as a dma-buf (`MemoryExport::DmaBuf`, a runtime
|
|
/// extension: Metal has none) on a device that does not enable `VK_KHR_external_memory_fd`,
|
|
/// `VK_EXT_external_memory_dma_buf` and `VK_EXT_queue_family_foreign`, whose queue family the
|
|
/// acquire of the other API's writes names (the runtime enables them wherever the device lists
|
|
/// them; an adopted device's consumer enables them or not), or that exports no buffer's memory
|
|
/// as a dma-buf (`vkGetPhysicalDeviceExternalBufferProperties` answers
|
|
/// `VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT` not exportable for the runtime's buffer
|
|
/// usage). Every other buffer is made as before.
|
|
DmaBufExport,
|
|
/// A shared event whose timeline semaphore another API imports
|
|
/// (`Device::new_exportable_shared_event`, a runtime extension: Metal has none) on a device
|
|
/// that does not enable `VK_KHR_external_semaphore_fd` (the runtime enables it wherever the
|
|
/// device lists it; an adopted device's consumer enables it or not), or that exports no
|
|
/// timeline semaphore as an opaque file descriptor
|
|
/// (`vkGetPhysicalDeviceExternalSemaphoreProperties` answers
|
|
/// `VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT` not exportable for a timeline
|
|
/// semaphore). Every other event is made as before.
|
|
ExportableSemaphore,
|
|
/// A shared event handle opened on a device other than its event's: another physical
|
|
/// device's, or one made with other options or adopted (equal options make one device, as
|
|
/// Metal's calls do). Vulkan semaphores do not cross devices unless exported, which the runtime
|
|
/// does not do (no venue has two GPUs in one process).
|
|
SharedEventAcrossDevices,
|
|
/// A copy, fill or mipmap generation of a texture over a plane of the caller's multi-planar
|
|
/// `VkImage` (`Device::new_texture_with_vk_image_plane`), a render pass that renders it, and a
|
|
/// view or binding that would hold its texels apart in an image of the runtime's (a shadow):
|
|
/// each copies the plane, which Vulkan names by its plane aspect where the runtime's copies
|
|
/// name the color aspect. Its views, which sampling and shader reads and writes bind, are the
|
|
/// exact path and run.
|
|
VkImagePlaneCopy,
|
|
/// 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 compensation (a driver that draws the
|
|
/// compensated depths inexactly refuses it `Unsupported`, `Feature::ViewportDepthRange`), or
|
|
/// in depth clamp mode where its one clamp differs between the draw's viewports, or holds one
|
|
/// depth that a fragment function reading its position's depth would read, that lies past
|
|
/// `[0, 1]` without `VK_EXT_depth_range_unrestricted`, or that bias factors move Metal's depth
|
|
/// off where the vertex stage does not clamp each vertex's depth or the device holds no
|
|
/// Vulkan range past 1. Or for a draw whose fragment function runs its depth test itself, where
|
|
/// a compensated depth replaces the draw's range, its viewports have different ranges (the
|
|
/// function reads one range), or in depth clamp mode the depth bias or a clamp of one depth
|
|
/// moves the draw's range off the encoder's, which Metal clamps to.
|
|
ViewportDepthRange,
|
|
/// NaN or infinite depth bias factors whose effect differs between flat and sloped triangles,
|
|
/// or a draw whose bias adds a clamp that moves a viewport's depth range past `[0, 1]` or that
|
|
/// depth clamp mode bounds, where the vertex stage's compensation cannot add it after Metal's
|
|
/// clamp of each vertex's depth: Metal takes them, and no static Vulkan state gives its answer.
|
|
NonFiniteDepthBias,
|
|
/// A draw under a depth compare of `Never` in a pass without a depth attachment, which fails
|
|
/// every fragment, whose fragment function writes color attachments as storage images (a
|
|
/// framebuffer fetch in the pixel interlock) or reaches the pass's imageblock: those writes
|
|
/// are in the function's body, which Metal runs, and no write mask stops them. Also, under
|
|
/// `[[early_fragment_tests]]`, a stencil face whose operation depends on the stored value, of a
|
|
/// function that writes memory or such attachments, which Metal never runs. Every other such
|
|
/// draw is drawn.
|
|
DepthNeverWithoutAttachment,
|
|
/// A draw whose depth/stencil state uses depth or the stencil that the pass lacks, which
|
|
/// plain Metal tests against a hidden `float` depth of 1.0 and stencil of 0 (Metal's
|
|
/// validation stops it), where the encoder gives the pass no hidden depth and stencil: a pass
|
|
/// with a depth or a stencil attachment that lacks the other aspect (its texture is the
|
|
/// pass's), a pass without attachments or over a rasterization-rate map, and a device that
|
|
/// clears no `Depth32Float_Stencil8` image by a transfer. An indirect command buffer's
|
|
/// command draws as the encoder's own draw at its execution's call would, and is refused so
|
|
/// where that draw would be.
|
|
HiddenDepthStencil,
|
|
/// An indirect draw whose arguments the binding plan asks to read on the CPU
|
|
/// (`DrawCommands::indirect_needs_arguments`): an indexed draw whose index fetch nothing
|
|
/// bounds (no `robustBufferAccess2`, or an index buffer offset at or past its length), whose
|
|
/// exact path is a GPU pass that writes the indices the draw fetches into a scratch, zero past
|
|
/// the Metal buffer, before the draw; or a device that emulates base vertex and instance, draws
|
|
/// multiview, or lacks `drawIndirectFirstInstance`, whose path is a prepass that writes what
|
|
/// the draw needs. The runtime never reads arguments an earlier command may write. An index
|
|
/// bounds pass whose arguments or indices a draw of the encoder wrote since its last memory
|
|
/// barrier, which Metal does not order before the draw's fetch, is refused too. So is an
|
|
/// indirect patch draw whose post-tessellation function reads `[[base_instance]]` through the
|
|
/// device's tessellation stages, which take it from push constants; on a device without
|
|
/// `tessellationShader` the draw's tessellation scan reads it on the GPU, and none is refused.
|
|
IndirectDrawArguments,
|
|
/// A depth/stencil resolve no Vulkan resolve mode of the device states: a filter or pair of
|
|
/// filters the device's `supportedDepthResolveModes`, `supportedStencilResolveModes` or
|
|
/// `independentResolve` lack, depth and stencil resolved into different textures, or the
|
|
/// stencil filter `DepthResolvedSample` after the depth filter `Min` or `Max` of an
|
|
/// attachment whose image is not sampled (the runtime draws it from the samples otherwise). A
|
|
/// resolve draw is the exact path.
|
|
DepthStencilResolve,
|
|
/// The tile memory of a render pass of a sample count Apple's GPUs lack (theirs are 1, 2
|
|
/// and 4), which a Vulkan device may have: a pass that sets its tile size, imageblock sample
|
|
/// length or threadgroup memory length, or an encoder's tile size asked, where Metal's
|
|
/// answers are unmeasured (`tile_pass.rs`).
|
|
TileAtSampleCount,
|
|
/// A draw or tile dispatch whose imageblock is of another size than the pass's, or a draw
|
|
/// whose fragment function's layouts are of another alignment than the pass's earlier
|
|
/// draws': Metal places the explicit imageblock at an offset its alignment sets, and what a
|
|
/// layout of another size leaves in the bytes past it is read only for a draw over every
|
|
/// pixel (`fragment_imageblock.rs`). Views of another master of the same size and alignment are
|
|
/// drawn.
|
|
ImageblockMasters,
|
|
/// A render pass that reaches its imageblock storage, from a draw whose fragment function
|
|
/// declares an explicit imageblock or a tile dispatch whose function's explicit imageblock
|
|
/// stands alone, and dispatches a tile function whose explicit imageblock is aliased onto its
|
|
/// implicit one past the bytes the attachments pack to: the runtime keeps the aliased layout
|
|
/// in threadgroup memory of its dispatch, staged from and to the attachments, where Metal's
|
|
/// reaches the explicit imageblock after them (`fragment_imageblock.rs`). A layout within the
|
|
/// attachments' bytes is dispatched.
|
|
TileAndFragmentImageblocks,
|
|
// The pieces the GPU-family audit names as blocking rows of Apple's feature set tables
|
|
// (`runtime::families`). Each says the step that builds it, or that none is scheduled.
|
|
/// Metal 4's API (`MTL4CommandQueue`, `MTL4CommandBuffer`, `MTL4ArgumentTable`,
|
|
/// `MTL4Compiler` and the rest), with the features only its programming model offers: the
|
|
/// Metal4 family's one row. Not scheduled.
|
|
Metal4Api,
|
|
/// Counter sample buffers (`MTLCounterSampleBuffer`) and the commands that sample into them.
|
|
/// Not scheduled: a command buffer's GPU times are built.
|
|
CounterSampleBuffers,
|
|
/// Residency sets (`MTLResidencySet`). Not scheduled.
|
|
ResidencySets,
|
|
/// A sparse texture's access counters (`getTextureAccessCounters:...` and
|
|
/// `resetTextureAccessCounters:...` of a blit encoder). Not scheduled (orchestrator,
|
|
/// 2026-10-06): Metal's counts are its texture hardware's units, not a count of accesses,
|
|
/// nondeterministic for large dispatches and different on an M3 Max and an M4 (a Metal sparse
|
|
/// probe on both), so no exact answer exists, and Vulkan counts nothing of the kind.
|
|
TextureAccessCounters,
|
|
/// Fast resource loading: `MTLIOCommandQueue`, its command buffers and file handles. Not
|
|
/// scheduled.
|
|
IoCommandQueues,
|
|
/// Texture view pools (`MTLTextureViewPool`). Not scheduled.
|
|
TextureViewPools,
|
|
/// Color attachment mapping (`MTLLogicalToPhysicalColorAttachmentMap`). Not scheduled.
|
|
ColorAttachmentMapping,
|
|
/// Lossy texture compression (`MTLTextureCompressionTypeLossy`). Not scheduled.
|
|
LossyTextureCompression,
|
|
/// Per-pipeline shader validation (`MTLShaderValidation`). Not scheduled.
|
|
ShaderValidation,
|
|
/// Shader logging (`MTLLogState`, a shader's `os_log`). Not scheduled.
|
|
ShaderLogging,
|
|
/// Device notifications (`MTLCopyAllDevicesWithObserver`). Not scheduled.
|
|
DeviceNotifications,
|
|
/// A draw in a rate-mapped pass that the region path does not draw, for the compile layer's
|
|
/// reason (`rate_mapped_pass.rs`).
|
|
RateMapRegions(RegionRefusal),
|
|
/// A layered render pass (`renderTargetArrayLength` 2 or more) that needs a step of one
|
|
/// layer: a color resolve from the sample planes (`color_resolve.rs`). Resolves, separate
|
|
/// depth and stencil textures (copied by draws once per layer) and stand-ins take every layer.
|
|
LayeredPass,
|
|
/// A blit copy between overlapping regions of one texture's texels (`copyFromTexture:...` with
|
|
/// the source's region meeting the destination's, through the texture or views of it), other
|
|
/// than a region copied onto itself, which keeps its texels. Not scheduled: no exact answer
|
|
/// exists. Metal's copy races: small regions read as `memmove` would, but larger ones read
|
|
/// texels another part of the copy has already written, differently from run to run, on an
|
|
/// M3 Max and an M4, with and without API validation (probes).
|
|
OverlappingTextureCopies,
|
|
/// A texture fill given no pattern bytes (`fillTexture:level:slice:region:bytes:length:` of
|
|
/// length 0, [`BlitCommandEncoder::fill_texture`](crate::BlitCommandEncoder::fill_texture)).
|
|
/// Metal's API validation layer stops it ("buffer length for format ... must be at least" a
|
|
/// unit's bytes); plain Metal takes the fill, the layer off, and writes the region all the
|
|
/// same, the call returning and the command buffer completing (an Apple M3 Max under macOS
|
|
/// 27.0.1: a 2D texture over a buffer, one of its own memory, a texture buffer and a 4-sample
|
|
/// one). What it writes is bytes the call never gave, and which bytes turns on the texture: an
|
|
/// ordinary texture's texels take a unit read from the pattern's address, byte for byte what a
|
|
/// pattern of a unit's length writes there, while a texture buffer's region takes the fill's
|
|
/// leftover bytes instead, Metal's own and not the caller's (the module docs'
|
|
/// `texture-buffer-fill-leftover`; zeros but for one word in the probe). The runtime holds
|
|
/// neither: a caller's slice of no bytes is all it is given, reading past it is unsound, and
|
|
/// Metal's leftovers are not the runtime's, so there is nothing exact to write and the call is
|
|
/// refused.
|
|
EmptyFillPattern,
|
|
/// `Buffer::rebind_bytes_no_copy` of a no-copy buffer whose GPU writes are dropped (Metal's
|
|
/// private option bit 24) with a live texture over its bytes, given memory at another offset
|
|
/// in its page than the old, on macOS: the texture's copies and texel views are planned at the
|
|
/// bytes' offset in their `VkBuffer` (`rebind.rs`), and such a buffer imports a read-only view
|
|
/// of its pages there, never a copy laid out there, as any other buffer's moved bytes are
|
|
/// (elsewhere such a buffer is a copy, laid out there). Also a rebind of a no-copy buffer or heap with a
|
|
/// texture whose image is bound to its bytes, where the device makes no such image over the
|
|
/// new memory: over memory it imports by its pointer, one that takes the import's type and
|
|
/// lies where the texture's texels do, its rows (and slices) as far apart as the old image's,
|
|
/// and never for a heap's texture whose image lay over dma-bufs, whose rows the driver's
|
|
/// `DRM_FORMAT_MOD_LINEAR` layout spaces; over a copy of the memory (the caller's gate refused
|
|
/// its import, it failed, or its bytes moved in their page), a linear image of the copy's
|
|
/// memory at the texels' place, which for an image in place over a buffer the driver must lay
|
|
/// out at the texels' pitches; over memory it imports as dma-bufs
|
|
/// (`HostMemory::with_dma_buf`), an image of `DRM_FORMAT_MOD_LINEAR` over a dma-buf of the
|
|
/// texture's own new pages, which needs `VK_EXT_image_drm_format_modifier` and
|
|
/// `VK_EXT_queue_family_foreign`, a layout the driver takes and the source's dma-buf.
|
|
RebindTextures,
|
|
/// A PVRTC texture's blocks in a Metal block order the runtime does not lay out:
|
|
/// `replaceRegion` and `getBytes` of a region other than a whole level, which Metal's API
|
|
/// validation stops and plain Metal places by no rule the runtime has found, and of a whole
|
|
/// level at a `bytesPerRow` other than 0 and the level's row, unmeasured. A whole level's take
|
|
/// its blocks in Z order with the y bit lowest. A blit's copy at a nonzero `bytesPerRow` moves
|
|
/// the blocks row by row, and one at 0 lays them out in the region's Morton order, a region off
|
|
/// its blocks that of the blocks it is rounded to, with `MTLBlitOptionRowLinearPVRTC` or
|
|
/// without it, as plain Metal's does (its API validation stops all but the first with the
|
|
/// option).
|
|
PvrtcBlockOrder,
|
|
/// A heap's or a sparse heap's texture of an ASTC format on a device without that ASTC format
|
|
/// (`astc.rs`), or a sparse heap's texture of an ETC2 or EAC format on a device without them
|
|
/// (`etc.rs`) or of a 4:2:2 format (`chroma_pairs.rs`), which Metal makes: an ASTC texture's
|
|
/// blocks would lie in the heap's bytes, which its decoded twin would decode as the texture is
|
|
/// placed, and a sparse heap's tiles are mapped by GPU commands. A heap's size query answers
|
|
/// an ASTC one Metal's model, which no image of the device decides. A texture of its own takes
|
|
/// them
|
|
/// (`Degradation::CarriedDecodedTwin`), and so does an ETC2, EAC or 4:2:2 texture of a heap.
|
|
DecodedHeapTexture,
|
|
/// A draw (`drawPrimitives:` and its forms, or an indirect command buffer's command) that
|
|
/// may read a vertex attribute the pipeline fetches in its vertex function past `2^32` bytes
|
|
/// of its buffer's bind offset, in a buffer that runs past them: Metal reads the attribute at
|
|
/// `element · stride + offset` in 64 bits, where the fetch's displacement wraps at `2^32`
|
|
/// (`render/vertex_reach.rs`). An indexed draw of 32-bit indices, or an indirect draw, may
|
|
/// read any element its indices or arguments name. A draw past a buffer of at most `2^32`
|
|
/// bytes past its bind offset is drawn, as Metal reads outside the buffer there.
|
|
VertexFetchPast4GiB {
|
|
/// The Metal vertex buffer index (`setVertexBuffer:offset:atIndex:`'s index).
|
|
buffer_index: u32,
|
|
/// The furthest byte past the bind offset the draw may read, saturating.
|
|
reach: u64,
|
|
},
|
|
/// A dispatch (`dispatchThreads:threadsPerThreadgroup:` and its forms, or an indirect
|
|
/// command buffer's command) whose kernel may read a `[[stage_in]]` attribute past `2^32`
|
|
/// bytes of its buffer's bind offset, in a buffer that runs past them: Metal fetches it at
|
|
/// `element · stride + offset` in 64 bits, where the fetch's displacement wraps at `2^32`
|
|
/// (`fetch_reach.rs`). The furthest element is the stage-in region's origin plus the grid's
|
|
/// last thread position over the step rate, clamped to the region's last element; an
|
|
/// indexed step may read its index type's largest index, and a dispatch whose grid GPU
|
|
/// memory states any 32-bit position. A dispatch past a buffer of at most `2^32` bytes past
|
|
/// its bind offset runs, as Metal reads outside the buffer there.
|
|
StageInFetchPast4GiB {
|
|
/// The Metal buffer index (`setBuffer:offset:atIndex:`'s index) of the attribute's
|
|
/// layout.
|
|
buffer_index: u32,
|
|
/// The furthest byte past the bind offset the dispatch may read, saturating.
|
|
reach: u64,
|
|
},
|
|
/// A command that would sample a texture of an address-mode map
|
|
/// (`TextureDescriptor::address_mode_map`) where the runtime cannot map it at bind
|
|
/// (`address_map.rs`): through a constexpr sampler whose modes the map changes, through a
|
|
/// sampler slot whose textures in one stage map it to different modes, or by a function
|
|
/// sampling handles that can reach it.
|
|
MappedTextureSampling {
|
|
/// The texture's map.
|
|
map: AddressModeMap,
|
|
/// How it would be sampled.
|
|
through: MappedSampling,
|
|
},
|
|
/// A library compiled from Metal Shading Language source. `newLibraryWithSource:options:error:`
|
|
/// and its completion-handler form ([`Device::new_library_with_source`]) are refused: the
|
|
/// runtime takes compiled shaders only, a metallib ([`Device::new_library_with_data`]) or AIR
|
|
/// through the translator, and builds no MSL compiler. Precompile the source with Apple's
|
|
/// `metal` tool and load the metallib.
|
|
///
|
|
/// [`Device::new_library_with_source`]: crate::Device::new_library_with_source
|
|
/// [`Device::new_library_with_data`]: crate::Device::new_library_with_data
|
|
LibrarySource,
|
|
/// An indexed strip after `set_primitive_restart_enabled` with an index Vulkan does not
|
|
/// restart at, which the runtime draws as a list an index rewrite pass writes
|
|
/// (`index_rewrite.rs`), where the pass cannot run as Metal draws: a direct draw whose list
|
|
/// is past what one storage range binds or a `u32` counts, or whose base instance the
|
|
/// device's indirect draws cannot carry (without `drawIndirectFirstInstance`); a draw whose
|
|
/// indices or arguments a draw or tile dispatch of the encoder wrote since its last memory
|
|
/// barrier, which Metal does not order before the draw's fetch, read in place; and an
|
|
/// argument or index range the binding layer cannot bind.
|
|
RestartedStrip,
|
|
/// A draw of one of Metal's private primitive types (`DrawPrimitiveType`: a line loop, a
|
|
/// triangle fan, quads, a quad strip), which the runtime draws as the list Metal draws, where
|
|
/// that list cannot be drawn as Metal draws: a direct draw without indices whose list a `u32`
|
|
/// cannot count; a draw over indices or from indirect arguments the index rewrite pass cannot
|
|
/// draw, as for `RestartedStrip`; and a draw in the private list form (a vertex function that
|
|
/// writes memory or computes `[[primitive_id]]` into a varying, or a direct draw whose last
|
|
/// vertex ID passes `i32::MAX`) whose list has no device address.
|
|
PrivatePrimitives,
|
|
/// A draw under Apple's last provoking vertex (`setProvokingVertexMode:` 1) on a device
|
|
/// without `VK_EXT_provoking_vertex`'s last vertex, which the runtime draws as the list of its
|
|
/// primitives led by their last vertices (`render/provoking.rs`), where that list cannot be
|
|
/// drawn as Metal draws, as for `PrivatePrimitives`: a direct draw without indices whose list
|
|
/// a `u32` cannot count, or whose last vertex ID passes `i32::MAX` (drawn in the private list
|
|
/// form) where its list has no device address; and a draw over indices or from indirect
|
|
/// arguments the index rewrite pass cannot draw, as for `RestartedStrip`.
|
|
ProvokingVertex,
|
|
/// A line or triangle strip at a width other than 1 (Apple's `setLineWidth:`), the triangle
|
|
/// strip in fill mode `Lines`, drawn as the band variant (`render/line_width.rs`), which draws
|
|
/// the list of its primitives, where that list cannot be drawn as Metal draws, as for
|
|
/// `ProvokingVertex`. Every other draw of lines or edges the band does not draw runs the
|
|
/// device's own lines at the width nearest Metal's they draw, announced
|
|
/// (`Degradation::LinesAtNearestWidth`).
|
|
WideLines,
|
|
/// An indexed draw (`drawIndexedPrimitives:`) of a pipeline whose fragment function reads
|
|
/// `[[primitive_id]]` on a device whose fragment stage cannot declare it (neither
|
|
/// `geometryShader` nor `tessellationShader`), which draws its indices as vertices from 0 in
|
|
/// the de-indexed form, its vertex function reading the indices in place at their device
|
|
/// address (`VariantKey::primitive_id_indices`): indices a draw of the encoder wrote since
|
|
/// its last memory barrier, which Metal does not order before the draw's fetch and the draw
|
|
/// would read as a copy, and indices without a device address.
|
|
PrimitiveIdIndices,
|
|
/// A rotated texture (`TextureDescriptor::rotation`) where the runtime does not build what
|
|
/// Metal does: CPU access or a blit of a quarter-turned one whose rows, as those uses address
|
|
/// them (the texture's `height` rows of `width` texels at the plane's `bytesPerRow`), run
|
|
/// past its buffer, whose bytes Metal reads past the stored frame; a blit between such a
|
|
/// texture whose rows overlap and a texture of an image; a view of a rotated texture other
|
|
/// than the whole texture as one 8-bit RGBA format of another (`Texture::new_texture_view`); a
|
|
/// binding beyond its usage; a plane whose offset or `bytesPerRow` is off 16 bytes, or a format
|
|
/// of a texel size other than 1, 2, 4, 8 or 16 bytes, whose rotation is not measured; a store
|
|
/// past the device's largest storage buffer range or dispatch grid; and a command that writes a
|
|
/// rotated texture's bytes both through a render pass and another way, which no merge serves.
|
|
RotatedTexture,
|
|
/// A texture over a no-copy buffer's or heap's bytes (a heap's texture, or a texture over
|
|
/// the buffer or over one of the heap's buffers) that no stand-in of zero bytes presents
|
|
/// exactly while they are detached (a texture of a multi-planar format, a two-plane YCbCr
|
|
/// texture's converted texels, a multisample texture):
|
|
/// `detach_backing` of the bytes, and its making over them while they are detached. Also made
|
|
/// over detached bytes: a rotated texture, and one over a surface's two planes. And
|
|
/// `detach_backing` while a texture is being made over the bytes, or `rebind_bytes_no_copy` of
|
|
/// detached bytes while one is.
|
|
DetachTextures,
|
|
/// A texture buffer of more than one level (`TextureDescriptor::mipmap_level_count`, up to
|
|
/// its width's full chain) from the device's, a heap's or the shared creator. Metal makes it
|
|
/// (an M4 under macOS 27.0.1 and an M3 Max under 26.7), its levels separate with no buffer
|
|
/// behind it (`buffer` nil), each replaced, read and viewed on its own (the M4); the
|
|
/// runtime's texture buffers are one level over a buffer. A buffer's creator stops it, as Metal's does,
|
|
/// and the heap size query answers Metal's size, its first level's.
|
|
TextureBufferLevels,
|
|
/// A texture of `TextureDescriptor::write_swizzle_enabled` whose swizzle is not the default,
|
|
/// with `ShaderWrite` or `RenderTarget` usage, from the device's, a heap's or a buffer's
|
|
/// creator. Metal makes it (an M4 under macOS 27.0.1 and an M3 Max under 26.7), and its
|
|
/// writes go through the swizzle (the M4); the runtime's swizzles are its sampled views'
|
|
/// alone. The heap size query answers
|
|
/// its size.
|
|
WriteSwizzle,
|
|
/// `Texture::replace_region` or `get_bytes` of a texture whose bytes (a no-copy buffer's or
|
|
/// heap's) are detached (`detach_backing`). Metal's CPU access reaches the pages the texture
|
|
/// took as it was made (a heap's texture, the pages the heap was made over), measured on an
|
|
/// M4 under macOS 27.0.1; the runtime keeps no pages of detached bytes. A tiled texture of more
|
|
/// than one level (`Buffer::new_tiled_texture`) keeps its own image meanwhile: only a
|
|
/// `replace_region` of its first level is refused, whose `get_bytes` reads the bytes' last
|
|
/// texels, which the detach loaded into the image, and its other levels are read and written
|
|
/// there.
|
|
DetachedTexelAccess,
|
|
/// A use of a texture of a depth or stencil format (`Depth16Unorm`, `Depth32Float`,
|
|
/// `Depth32Float_Stencil8`, `Stencil8`, `X32_Stencil8`) over a plane of a surface with planes
|
|
/// (`Buffer::new_texture_with_iosurface_plane` with `IoSurfacePlane::planar`) that the
|
|
/// runtime does not make as Metal does: a blit of the stencil of a `Depth32Float_Stencil8` one
|
|
/// or of its `X32_Stencil8` view (that stencil is not in the plane; unmeasured), a render pass
|
|
/// on an `X32_Stencil8` one's view as `Depth32Float_Stencil8` (unmeasured), and a pass on a
|
|
/// device its tiled copies do not fit. The texture, its reads, samples, blits and CPU access,
|
|
/// its passes at any extent, its views' passes and a pass loading its stencil are made (an
|
|
/// M4 under macOS 27.0.1).
|
|
SurfaceDepthStencil {
|
|
/// The descriptor's pixel format.
|
|
pixel_format: PixelFormat,
|
|
},
|
|
/// A blit copy between a buffer and a multisampled texture (`copyFromBuffer:...toTexture:`
|
|
/// into, or `copyFromTexture:...toBuffer:` out of, a texture of more than one sample).
|
|
/// Vulkan copies no multisampled image to or from a buffer (its `vkCmdCopyBufferToImage` and
|
|
/// `vkCmdCopyImageToBuffer` require a sample count of one,
|
|
/// VUID-vkCmdCopyBufferToImage-dstImage-07973), so the single-sample buffer-image path cannot
|
|
/// take it. Plain Metal copies it per sample, the pixel's samples consecutive in the buffer:
|
|
/// texel `(x, y)` sample `s` of an `n`-sample texture of `bpp`-byte samples lies at
|
|
/// `offset + y * bytesPerRow + (x * n + s) * bpp`, whole or into a sub-region, where the
|
|
/// offset and `bytesPerRow` are multiples of the pixel's `n * bpp` bytes, rows overlapping
|
|
/// into the texture where `bytesPerRow` is below a row; at others it rounds the first row's
|
|
/// offset and the pitch down (measured on an Apple M3 Max under macOS 27.0.1, for 1- to
|
|
/// 16-byte colour, depth and stencil samples at 2 and 4 samples; its API validation refuses an
|
|
/// offset off the pixel). The runtime places the rows as Metal does, through a staging buffer
|
|
/// where a row's offset in the `VkBuffer` is off a sample (`staged-texture-copy`), but for the
|
|
/// layouts of `MultisampledBufferLayout`. The runtime runs that copy exactly
|
|
/// (`sample_interleave.rs`) through a single-sample wide image and a multisampled uint scratch,
|
|
/// by a compute split and a sample-rate merge draw. This is the refusal where the device cannot
|
|
/// run that: no `sampleRateShading`, no integer multisample color attachment at the count, no
|
|
/// storage of the copy format, or a texture without the transfer usage the copy needs. A depth
|
|
/// or stencil texture's samples cross the same images in the unsigned format of the aspect's
|
|
/// bits and move into or out of the aspect as the multisampled blit copies between
|
|
/// depth/stencil and colour move them (maintenance8's copies, or sample-rate draws); this is
|
|
/// also the refusal where that move refuses: on a device whose maintenance8 copies are missing
|
|
/// or wrong, a 16-bit depth on a driver whose codes the fragment-depth draw is not measured to
|
|
/// keep (`DriverFact::FragmentDepthKeepsDepth16Codes`), or a depth or stencil texture the
|
|
/// draws cannot sample or render to (a 32-bit float depth on a driver whose fragment depth is
|
|
/// not measured is drawn, announced as `drawn-depth-copy`; a 16-bit depth where its codes are
|
|
/// kept crosses as its codes, exact). Nothing is recorded, where previously the runtime
|
|
/// recorded invalid Vulkan and some drivers hung instead of failing (the consumer's NVIDIA
|
|
/// Xid 32 stall).
|
|
MultisampledBufferCopy,
|
|
/// A blit copy between a buffer and a multisampled texture (as for `MultisampledBufferCopy`)
|
|
/// in one of two buffer layouts that plain Metal copies by rules not yet reduced, and that
|
|
/// Metal's API validation rejects (`bytesPerRow` must be at least a row and a multiple of the
|
|
/// pixel, a texel's samples' bytes): a `bytesPerRow` of 0 from an offset that is a multiple of
|
|
/// 16 bytes (but for a single row from offset 0), where plain Metal copies the texture's
|
|
/// samples in a block order of its own; and, for a pixel of 32 bytes or more, a
|
|
/// `bytesPerRow` below a row, or off the pixel for more than one row, where plain Metal places
|
|
/// the rows by the offset's and the pitch's bits together (measured on an Apple M3 Max under
|
|
/// macOS 27.0.1). The runtime copies every other layout as plain Metal does.
|
|
MultisampledBufferLayout,
|
|
/// What a render pass the device draws in color groups does not build: a pass of more color
|
|
/// attachments with a texture than the lesser of the device's `maxColorAttachments` and
|
|
/// `maxFragmentOutputAttachments` (four on a device at Vulkan's floor), or of one at an index
|
|
/// at or past it, where Metal takes eight, draws each group's colors in a pass of its own
|
|
/// (`render/color_groups.rs`). Refused there: a render pipeline state whose colors with a
|
|
/// pixel format are not the pass's colors with a texture (or one the device draws in groups
|
|
/// in a pass it draws in one), a tile pipeline's state, an execution of render commands in a
|
|
/// pass of several groups, a depth or stencil the pass loads from a texture without the
|
|
/// transfer usage its later groups' copy needs, and in a pass of several groups a draw that
|
|
/// reads what another group writes (a color of another group, its own group's colors or the
|
|
/// depth and stencil where it draws in a later group too, a resolve texture, the visibility
|
|
/// result buffer, memory it reaches through a handle table, or a texture over a buffer's
|
|
/// bytes it may reach through a root table), and a resolve target set on a texture a draw of
|
|
/// the pass read.
|
|
ColorAttachmentGroups,
|
|
/// An object made before its device's recovery from the loss of its `VkDevice` that the
|
|
/// recovery did not carry to the new one (the runtime made a new `VkDevice` behind the device,
|
|
/// announced as `Degradation::DeviceRecovered`; `Device::recover_for_test` runs the same
|
|
/// recovery). The recovery carries the events, the `Private` buffers (their contents lost:
|
|
/// they read zero) and the buffers in the runtime's fresh pages (their contents and
|
|
/// `contents` pointer kept); every other object's Vulkan objects are the lost `VkDevice`'s,
|
|
/// which serves nothing more: a pooled `Shared` or `Managed` buffer, whose `contents` pointer
|
|
/// is its lost memory's mapping, a no-copy buffer, a heap and its resources, a texture, a
|
|
/// pipeline state, a library, a sampler state, an indirect command buffer, a buffer over the
|
|
/// caller's `VkBuffer` or exportable memory, and an event made exportable. A call that meets
|
|
/// such an object with the new generation (an encoder's bind, a pipeline's making from its
|
|
/// functions, a buffer or texture placed in its heap) or that needs its own lost `VkDevice`
|
|
/// (its placements, its imports again, its event signals) is refused, where Metal's object
|
|
/// goes on; the recovery's notice counts the buffers and events it left. The same object made
|
|
/// again on the device serves; a command buffer made before the recovery fails as its victim
|
|
/// (`GpuRecoveryVictim`).
|
|
MadeBeforeRecovery,
|
|
/// `Device::recover_for_test` on a device the consumer made (`Device::from_raw`): the runtime
|
|
/// cannot make a new `VkDevice` of the consumer's, so it recovers none, and the device is
|
|
/// left as it was. A real loss of such a device answers as a lost device does.
|
|
AdoptedDeviceRecovery,
|
|
}
|
|
|
|
/// The kind of memory that ran out.
|
|
#[non_exhaustive]
|
|
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
|
pub enum MemoryKind {
|
|
/// Host memory (`VK_ERROR_OUT_OF_HOST_MEMORY`).
|
|
Host,
|
|
/// Device memory (`VK_ERROR_OUT_OF_DEVICE_MEMORY`), or no free range of the runtime's Metal
|
|
/// address space.
|
|
Device,
|
|
/// An automatic heap with no free range the resource fits, for which Metal answers nil.
|
|
Heap,
|
|
}
|
|
|
|
/// A raw `VkResult` of a failed call.
|
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
|
pub struct VkResultCode(pub i32);
|
|
|
|
/// Why a command buffer failed on the device (`MTLCommandBufferError`).
|
|
#[non_exhaustive]
|
|
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
|
pub enum CommandBufferError {
|
|
/// The device was lost while the command buffer ran.
|
|
DeviceLost,
|
|
/// The device ran out of memory for the submission.
|
|
OutOfMemory,
|
|
/// Any other Vulkan failure of the submission, raw.
|
|
Internal(VkResultCode),
|
|
/// An indexed indirect draw's index bounds or index rewrite pass found the rest of the
|
|
/// command buffer's index pool too small for the draw's indices, and drew nothing of the draw.
|
|
/// Metal draws it; the pool (a sixty-fourth of the device's largest device-local heap) is bound
|
|
/// before the GPU reads the draw's count, so nothing is drawn short silently.
|
|
IndexPoolOverflow,
|
|
/// A function the command buffer ran sampled, gathered, or queried a texture through a
|
|
/// sampler state an argument buffer named whose min or mag filter is `Cubic`
|
|
/// (`MTLSamplerMinMagFilterCubic`). Metal filters through it bicubically; the runtime does not
|
|
/// emulate that filter through an argument buffer, so the operation's result is not Metal's and
|
|
/// the command buffer fails (`NotImplemented(SamplerBicubicFilter)`'s reach, decided where the
|
|
/// function ran). A command buffer whose functions never reach such a sampler runs as Metal's.
|
|
CubicArgumentSampler,
|
|
/// An emulated mesh draw's records, or an emulated indirect draw's object slots (one per object
|
|
/// threadgroup, the grid and payload its object function writes), did not fit the rest of the
|
|
/// command buffer's mesh records pool, or its vertices passed a `u32`: such draws drew nothing. Metal draws them; the
|
|
/// runtime's pool is the device's budget, so nothing is drawn short silently. The first such
|
|
/// draw, as its scan saw it.
|
|
MeshRecordsOverflow(MeshRecordsOverflow),
|
|
/// An emulated tessellation draw's records (an indirect patch draw's, on a device without
|
|
/// `tessellationShader`) did not fit the rest of the command buffer's records pool, the one
|
|
/// emulated mesh draws share: such draws drew nothing. Metal draws them; the runtime's pool is
|
|
/// the device's budget, so nothing is drawn short silently. The first records fault of the
|
|
/// command buffer, where it is a tessellation draw's, as its scan saw it.
|
|
TessellationRecordsOverflow(TessellationRecordsOverflow),
|
|
/// The device cannot launch a mesh draw's grid that Metal draws, and such draws drew
|
|
/// nothing: on a device that does not fold object grids (without device addresses,
|
|
/// `shaderInt64`, `multiDrawIndirect` or `drawIndirectCount`), an indirect draw's object grid,
|
|
/// as the GPU wrote it, past the task stage's limits (`maxTaskWorkGroupCount`,
|
|
/// `maxTaskWorkGroupTotalCount`), or a mesh grid past the mesh stage's; on one that folds them,
|
|
/// a grid of more pieces than `MeshArguments::OBJECT_PIECES` (only under task limits below
|
|
/// Vulkan's required least); on a device without `VK_EXT_mesh_shader` (the emulation), an
|
|
/// indirect draw's object grid past the device's `maxComputeWorkGroupCount`. Nothing is drawn
|
|
/// short silently. A direct draw of such a grid on
|
|
/// a device that does not fold is refused as it is encoded (`Unsupported{MeshShading}` naming
|
|
/// the limit). Not Metal's failure: an object grid Metal's GPU discards is
|
|
/// [`GpuRecoveryVictim`](Self::GpuRecoveryVictim).
|
|
MeshGridPastLimits,
|
|
/// A host step refused a command it recorded from an indirect command buffer's records
|
|
/// (`Degradation::HostReplayedIndirectCommands`): what `commit` refuses where the CPU wrote
|
|
/// the records, such as a command's pipeline state of other color formats than the pass's.
|
|
/// The batch the step recorded for, and those after it, did not run.
|
|
/// [`CommandBuffer::refusal`](crate::CommandBuffer::refusal) gives the refusal, typed as
|
|
/// `commit`'s would be.
|
|
Refused,
|
|
/// The program committed the command buffer as failed, with this `MTLCommandBufferError`
|
|
/// code ([`CommandBuffer::commit_failed`](crate::CommandBuffer::commit_failed)). Of Metal's
|
|
/// codes of a page fault (3) and a hang (2), it counts against its queue as the error it
|
|
/// stands for does ([`AccessRevoked`](Self::AccessRevoked)), and its completion is the GPU's
|
|
/// recovery from it, which ends a predicated loop running on the device (as a victim after a
|
|
/// fault, with no error after a hang); of any other code, neither.
|
|
Injected(u64),
|
|
/// The command buffer encoded a render pass without attachments whose
|
|
/// `renderTargetWidth` or `renderTargetHeight` is past 16384, which Metal's encoder takes:
|
|
/// Metal fails the command buffer from that pass on with `MTLCommandBufferErrorInternal`
|
|
/// ("Internal Error (0000010d:Internal Error)" on an M4, `0000010c` on the M3 Max), the
|
|
/// encoders before it run and the event signals encoded before it fire, while the pass,
|
|
/// every encoder after it and the signals after it do not (with and without API validation,
|
|
/// which lets the pass through). The queue runs on.
|
|
RenderTargetSize,
|
|
/// Metal's GPU faulted an encoder, which ran nothing, not even a render pass's load, clear or
|
|
/// store actions: a render encoder's execution of an indirect command buffer that inherits
|
|
/// its pipeline state, under the encoder's state made without
|
|
/// `supportIndirectCommandBuffers` (a range of commands that runs, or any range read from a
|
|
/// buffer, `{0, 0}` included), or an indexed draw of primitive type 9
|
|
/// ([`DrawPrimitiveType::Nine`](crate::DrawPrimitiveType::Nine)), of any index count, of no
|
|
/// index or instance too. Metal completes the command buffer with
|
|
/// `MTLCommandBufferErrorPageFault` ("Caused GPU Address Fault Error
|
|
/// (0000000b:kIOGPUCommandBufferCallbackErrorPageFault)" on an M4); the encoders before the
|
|
/// faulted one run, every event signal fires, and the queue runs on. On the M3 Max (macOS
|
|
/// 27.0.1; 120 command buffers of type-9 draws, this error's and
|
|
/// [`GpuRecoveryVictim`](Self::GpuRecoveryVictim)'s, and 44 of such executions) it completed
|
|
/// 6.86 to 10.3 ms after it read `Scheduled`, and the encoders after the faulted one were
|
|
/// lost to the GPU's recovery where the GPU ran just before (127 of 142), ran where it was
|
|
/// idle before (the first fault after 3 s idle), and in some shapes ran in part (an encoder
|
|
/// after an event signal, a command buffer committed right after). The runtime answers the
|
|
/// steady state: the faulted encoder and every one after it run nothing, and the command
|
|
/// buffer completes no sooner than 6.86 ms after it read `Scheduled` and the work before the
|
|
/// encoder ran, its queue's command buffers committed meanwhile reading `Scheduled` as they
|
|
/// are committed, and running (`command_buffer/hang.rs`).
|
|
///
|
|
/// Such a fault, as the runtime makes it, counts against the command buffer's queue, as a
|
|
/// [`GpuHang`](Self::GpuHang) does: from the completion of the queue's second, its later
|
|
/// command buffers fail with [`AccessRevoked`](Self::AccessRevoked). A relayed one is the
|
|
/// driver's queue's.
|
|
///
|
|
/// Also a page fault Metal answers for the command buffer's work under MoltenVK, which the
|
|
/// runtime relays (`CommandBufferError::Execution`).
|
|
PageFault,
|
|
/// Metal's GPU hung at a direct draw of primitive type 9 of 3 vertices or more
|
|
/// ([`DrawPrimitiveType::Nine`](crate::DrawPrimitiveType::Nine)) and failed the command buffer
|
|
/// with `MTLCommandBufferErrorTimeout` (2, "Caused GPU Hang Error
|
|
/// (00000003:kIOGPUCommandBufferCallbackErrorHang)"). On the M3 Max (macOS 27.0.1, 33 hangs)
|
|
/// it read `Scheduled` 0.68 to 13.2 ms after its commit and failed 28.3 to 46.2 ms after it,
|
|
/// mostly 27.5 to 28.9 ms after `Scheduled`: the encoders before the draw's ran; its render
|
|
/// encoder, not even its pass's load, clear or store actions, and every encoder after it ran
|
|
/// nothing; its event signals fired. Every command buffer of its queue scheduled while it was
|
|
/// in flight completed with no error together with it, committed at once, after it read
|
|
/// `Scheduled`, or 20 ms on, and with an event wait met during the hang, by the host or
|
|
/// another queue's command buffer; their work ran or not by a race (mostly ran where the hang
|
|
/// read `Scheduled` within 2 ms, mostly not where later). One whose event wait was met only
|
|
/// after it completed, one of another queue and one committed later ran. The runtime's hang
|
|
/// reads `Scheduled` 5.06 ms after its commit (later where the work before the draw is
|
|
/// submitted later), completes no sooner than 27.5 ms after it read `Scheduled` and the work
|
|
/// before the draw ran, and runs nothing of its queue's others: the outcome of Metal's
|
|
/// slower submission (`command_buffer/hang.rs`). It counts against its queue as a
|
|
/// [`PageFault`](Self::PageFault) does.
|
|
///
|
|
/// Metal's GPU also hangs at a render pass of no draw call over a `Mutable`
|
|
/// rasterization-rate map where no command buffer with a draw call (one of nothing too) over
|
|
/// such a map was committed on the device before its own (the M3 Max under macOS 27.0.1, our
|
|
/// probe `rs`: maps of layers and of none, reset or not; a pass with only a pipeline state
|
|
/// set; one after a drawn pass in the same command buffer), failing it with the same error.
|
|
/// The runtime fails it from that pass on as at the draw.
|
|
GpuHang,
|
|
/// Metal failed the command buffer as a victim of its GPU's recovery, at an indirect draw of
|
|
/// primitive type 9, indexed or not, whatever its arguments
|
|
/// ([`DrawPrimitiveType::Nine`](crate::DrawPrimitiveType::Nine)), with
|
|
/// `MTLCommandBufferErrorInternal` (1, "Discarded (victim of GPU error/recovery)
|
|
/// (00000005:kIOGPUCommandBufferCallbackErrorInnocentVictim)", its `GPUStartTime` 0), 16.9 to
|
|
/// 30.0 ms after its commit (the M3 Max, macOS 27.0.1, 5 draws): its render encoder ran
|
|
/// nothing, every event signal fired, and the queue ran on. The encoders after it, its
|
|
/// completion and the runtime's answer are a [`PageFault`](Self::PageFault)'s. It does not
|
|
/// count against its queue.
|
|
///
|
|
/// Also an object grid of more than 2^29 threadgroups (`bind::METAL_OBJECT_GRID_TOTAL`), past
|
|
/// what Metal's GPU runs within its watchdog's 5 seconds (2^29 of an object function that does
|
|
/// next to nothing ran in 4.98 s on the M3 Max, 2^30 did not), which Metal fails with the same
|
|
/// error 5 seconds on: nothing of the command buffer ran from the draw's encoder on (its clear,
|
|
/// its draws before the grid's, the encoders after it), and a command buffer of the queue
|
|
/// committed while it ran failed too. The runtime fails a direct draw's command buffer from
|
|
/// its encoder on as its work completes, and an indirect draw's as its arguments pass reports
|
|
/// it, the rest of its work running; it runs the queue's other command buffers (docs/API.md,
|
|
/// "Accepted differences").
|
|
GpuRecoveryVictim,
|
|
/// Metal ignored the command buffer, committed on a queue whose second command buffer with a
|
|
/// GPU error it caused ([`PageFault`](Self::PageFault), [`GpuHang`](Self::GpuHang), or
|
|
/// [`Injected`](Self::Injected) of Metal's code of either; not a
|
|
/// [`GpuRecoveryVictim`](Self::GpuRecoveryVictim)) had completed:
|
|
/// `MTLCommandBufferErrorAccessRevoked` (4, "Ignored (for causing prior/excessive GPU errors)
|
|
/// (00000004:kIOGPUCommandBufferCallbackErrorSubmissionsIgnored)" on the M3 Max, macOS
|
|
/// 27.0.1). It reads `Scheduled` and completes at its commit, nothing of it runs and none of
|
|
/// its event signals fires; so does every later one of the queue, while the device's other
|
|
/// queues, new ones too, run on (`command_buffer/revocation.rs`).
|
|
AccessRevoked,
|
|
/// Metal failed the command buffer's work with this `MTLCommandBufferError` code, which the
|
|
/// driver relayed: MoltenVK, which runs each batch as a Metal command buffer, reports a
|
|
/// failed one, and the runtime gives its code to the command buffer whose batch it was
|
|
/// (`device/relay.rs`), the device kept, as Metal keeps it. Measured: a GPU write into
|
|
/// read-only host pages fails with `Internal` (1, "Discarded (victim of GPU error/recovery)")
|
|
/// on an M4 with macOS 27.0.1, as does a command buffer the GPU ran beside it, and with
|
|
/// `PageFault` on an M3 Max with 26.7 (the consumer's). Code 3 is
|
|
/// [`CommandBufferError::PageFault`], and 11 [`CommandBufferError::DeviceLost`].
|
|
Execution(u64),
|
|
/// The driver did not make the `VkPipeline` of a dispatch the command buffer recorded (a
|
|
/// compute encoder's, or a render encoder's tile dispatch), which its submission waited
|
|
/// for: the runtime makes a dispatch's pipeline while the dispatch goes on and the command
|
|
/// buffer's batch waits for it, so the failure surfaces here, not at the dispatch. The batch
|
|
/// that records the dispatch, and those after it, did not run.
|
|
/// [`CommandBuffer::failed_pipeline`](crate::CommandBuffer::failed_pipeline) names the
|
|
/// state and gives the driver's error. A draw's such failure drops the draw alone, the
|
|
/// command buffer running on
|
|
/// ([`CommandBuffer::dropped_draw`](crate::CommandBuffer::dropped_draw)). Metal makes a
|
|
/// state's pipelines as it makes the state, and has no such failure.
|
|
PipelineCreation(PipelineCreationCause),
|
|
/// A command of the command buffer named a buffer over the caller's host pages (a no-copy
|
|
/// buffer, a heap over the caller's memory, or a resource placed in one) that was rebound
|
|
/// (`rebind_bytes_no_copy`) after the command was encoded and before the command buffer's
|
|
/// first batch was submitted: a binding, a blit's operand, an attachment, a vertex, index or
|
|
/// indirect buffer, a texture over the pages, an indirect command's resolved buffer. Metal
|
|
/// resolves such a use as it submits the command buffer, to the pages the buffer lies in
|
|
/// then; the runtime resolved it as the command was encoded. The rebind encodes the command
|
|
/// buffer's compute, blit and render encoders that named it again, from their calls, so they
|
|
/// reach the new pages as Metal's do (a resource state encoder takes no pages: an indirect
|
|
/// mapping update reads its buffer as it runs; a call refused at its encoding is refused
|
|
/// again, and the calls after it run); this fails only an encoder that cannot be encoded
|
|
/// again: one of a command buffer that used command predication; a render pass recorded later
|
|
/// (an indirect command buffer's execution). Each
|
|
/// of Metal's submissions holding such an encoder ran nothing (the command buffer's split),
|
|
/// every other ran, the event signals fired and the handlers ran. What the command buffer's
|
|
/// encoders made resident (`use_resource`, `use_heap`) and what its commands reach unnamed
|
|
/// follow the rebind as Metal's do. The device announces the first
|
|
/// (`Degradation::EncodedUseRebound`). A command buffer submitted before the rebind keeps the
|
|
/// old pages, as Metal's does.
|
|
EncodedUseRebound,
|
|
/// A command of the command buffer used a buffer over the caller's host pages (a no-copy
|
|
/// buffer, a heap over the caller's memory, or a buffer placed in one) that was detached
|
|
/// (`Buffer::detach_backing`, `Heap::detach_backing`) when the command buffer's submission
|
|
/// holding the command was submitted (each event group's as its first batch goes): named (a
|
|
/// binding, a blit's operand, a vertex, index or indirect buffer) or made resident
|
|
/// (`use_resource`, `use_heap`, whether or not a command reaches it). Each of Metal's submissions holding such a command
|
|
/// ran nothing (the command buffer's split), every other ran, the event signals fired and the
|
|
/// handlers ran, as Metal fails a submission that uses a resource whose memory was taken away
|
|
/// (`OutOfMemory`, code 8; the consumer's rebind probe, an M3 Max under macOS 26.7). A reach of
|
|
/// the buffer by its address alone reads zero and fails nothing. An encoder that named a
|
|
/// detached buffer recorded nothing from that command on, so it fails alike where the buffer
|
|
/// was given pages again before the submission, with [`CommandBufferError::EncodedUseRebound`].
|
|
DetachedBacking,
|
|
/// An encoder of the command buffer was made under protection options other than 0
|
|
/// (`CommandBuffer::set_protection_options`; the options set, here), or options from 0x10 up
|
|
/// were set: as Metal's GPU fails it (measured by a consumer on an M3 Max, macOS 26.7), the
|
|
/// first such encoder ran nothing, nor did any after it (with none, every encoder ran), and
|
|
/// none of its event signals fired. Metal's code is 16 ("Protection Violation") below 0x10, 1
|
|
/// ("Invalid Input") from 0x10 up.
|
|
ProtectedEncoder(u64),
|
|
/// A unit of command predication (`ComputeCommandEncoder::encode_start_if` and the others)
|
|
/// ended with a block open that no misused record killed, where the unit's commands skipped
|
|
/// as the GPU reached its end (a failed If or While, a held If's Else, a block inside one that
|
|
/// skipped): Metal's GPU recovery fails the command buffer, `MTLCommandBufferErrorInternal`
|
|
/// ("Discarded (victim of GPU error/recovery)
|
|
/// (00000005:kIOGPUCommandBufferCallbackErrorInnocentVictim)", which
|
|
/// [`CommandBuffer::error_description`](crate::CommandBuffer::error_description) gives), on
|
|
/// an M3 Max under macOS 27.0.1, `PageFault` in some runs. The runtime reads
|
|
/// the unit's skip counter where it ends, on the GPU, and fails the command buffer as it
|
|
/// completes, before its completed handlers run, and only so; a block whose commands ran there
|
|
/// is harmless, as on Metal. The rest of the command buffer runs: how much of it Metal's
|
|
/// recovery runs varies run to run.
|
|
PredicationOpenAtUnitEnd {
|
|
/// The index of the call that opened the outermost block left open in the first unit
|
|
/// that failed so, among the command buffer's command-predication calls that returned
|
|
/// `Ok` (`encode_start_if` and the other six), counting from 0. Metal's error names no
|
|
/// record.
|
|
record: u32,
|
|
},
|
|
/// The command buffer encoded a render pass without attachments whose
|
|
/// `defaultRasterSampleCount`'s low 8 bits are 16 to 127, which Metal's encoder takes: Metal
|
|
/// fails the command buffer with `MTLCommandBufferErrorInternal` ("Internal Error
|
|
/// (0000010c:Internal Error)" on the M3 Max under macOS 26.7, the consumer's run of our probe,
|
|
/// and `0000010d` on an M4 under macOS 27.0.1, plain Metal; its API
|
|
/// validation stops the pass). The runtime fails it from that pass on, as for
|
|
/// [`RenderTargetSize`](Self::RenderTargetSize), on every device,
|
|
/// whatever samples its driver rasterizes; which encoders and signals Metal runs was
|
|
/// measured for that size alone.
|
|
DefaultRasterSampleCount,
|
|
/// A command of the command buffer used a memoryless texture's memory, which it has none of:
|
|
/// a draw or dispatch whose function statically uses a texture slot that holds one (a texture
|
|
/// the function reads only behind a branch that is never taken, and a draw or dispatch that
|
|
/// runs nothing, included), a tile dispatch alike, a `use_resource` that names one, and a
|
|
/// blit that copies from or into one or makes its mipmaps of more than one level (a copy of
|
|
/// no texels too). Metal
|
|
/// takes every such call and fails the command buffer with
|
|
/// `MTLCommandBufferErrorInvalidResource` (9, "Invalid Resource
|
|
/// (00000009:kIOGPUCommandBufferCallbackErrorInvalidResource)"): the submission that holds
|
|
/// the command, as Metal splits the command buffer (a render pass alone, a run of blit or of
|
|
/// compute encoders with no event command between them), runs nothing, not even a render
|
|
/// pass's load or clear, nor does any submission after it, and no event signal encoded from
|
|
/// that submission on fires; the submissions before it run and their signals fire; the queue
|
|
/// runs on (an M3 Max under macOS 27.0.1, plain Metal; Metal's API validation stops the
|
|
/// binding instead). A binding the function does not use, rebound before the draw or never
|
|
/// drawn with, a memory barrier that names one, a copy of no slices or levels, the mipmaps
|
|
/// of one level, and a blit's `optimize_contents_*` and `synchronize_resource` fail nothing.
|
|
InvalidResource,
|
|
/// A render encoder's call that the runtime refused as it lowered the call, after the call
|
|
/// returned (`RenderLoweringPolicy::Worker`): a refusal the call's own checks of its
|
|
/// arguments and the encoder's state could not find, such as the binder's, or a failure to
|
|
/// make what the lowering needs. The call, by its Metal selector and its place among the
|
|
/// encoder's calls ([`EncoderCall`]); [`CommandBuffer::refusal`](crate::CommandBuffer::refusal)
|
|
/// gives the error the call would have returned under `RenderLoweringPolicy::AtCall`. The
|
|
/// encoder and every encoder after it run nothing, and the event signals encoded from it on do
|
|
/// not fire. Metal's validation stops the process at such a call instead. A commit whose own
|
|
/// work refused it after `commit` returned is named `commit`
|
|
/// ([`CommandBuffer::commit`](crate::CommandBuffer::commit)): none of the encoders runs.
|
|
CallRefused(EncoderCall),
|
|
}
|
|
|
|
/// One call of a render encoder, as a refusal found after it returned names it
|
|
/// ([`CommandBufferError::CallRefused`]), and as a notice announced while the runtime lowered it
|
|
/// does (`DegradeNotice::call`). No Metal counterpart.
|
|
#[non_exhaustive]
|
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
|
pub struct EncoderCall {
|
|
/// The Metal selector of the encoder's method called (`"drawPrimitives:vertexStart:vertexCount:"`
|
|
/// and its kin name their full form, as the method's documentation does).
|
|
pub selector: &'static str,
|
|
/// The call's place among the encoder's calls, from 0: every call of the encoder's methods
|
|
/// counts, `end_encoding` and the queries (`tile_width`, `tile_height`) but none. The end of an
|
|
/// encoder that logged its calls names its notices `endEncoding`, at the place after its last
|
|
/// call. A commit whose own work, run after it returned, refused it is `commit` at 0
|
|
/// (`CommandBuffer::commit`).
|
|
pub index: u32,
|
|
}
|
|
|
|
impl EncoderCall {
|
|
/// Call `index` of its encoder, to the method of Metal's `selector`.
|
|
pub(crate) fn new(selector: &'static str, index: u32) -> EncoderCall {
|
|
EncoderCall { selector, index }
|
|
}
|
|
}
|
|
|
|
/// Whose failure a command buffer's error is ([`CommandBufferError::origin`]).
|
|
#[non_exhaustive]
|
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
|
pub enum FailureOrigin {
|
|
/// Metal fails such work too, with the code [`CommandBufferError::metal_code`] gives: a
|
|
/// failure Metal relayed through the driver ([`CommandBufferError::Execution`],
|
|
/// [`CommandBufferError::PageFault`]), a lost device (Metal's `DeviceRemoved`, where Metal may
|
|
/// report a hang or a fault of the work and keep the device), the device's memory, a failure
|
|
/// measured on Metal ([`CommandBufferError::RenderTargetSize`],
|
|
/// [`CommandBufferError::DetachedBacking`], [`CommandBufferError::DefaultRasterSampleCount`],
|
|
/// [`CommandBufferError::InvalidResource`]), or the code the program committed the command
|
|
/// buffer as failed with ([`CommandBufferError::Injected`]).
|
|
Metal,
|
|
/// The runtime's own: Metal runs the work and fails no command buffer so, where the runtime
|
|
/// failed it rather than run it short or wrong (a fixed pool's overflow, a pipeline made at
|
|
/// the draw, a read or sampler the runtime does not emulate there, a host step's refusal), or
|
|
/// Vulkan failed the submission in a way Metal has no counterpart of
|
|
/// ([`CommandBufferError::Internal`]). Its [`CommandBufferError::metal_code`] is the nearest of
|
|
/// Metal's codes, not Metal's answer.
|
|
Runtime,
|
|
}
|
|
|
|
/// Why the driver did not make a draw's `VkPipeline` ([`CommandBufferError::PipelineCreation`]).
|
|
#[non_exhaustive]
|
|
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
|
pub enum PipelineCreationCause {
|
|
/// The device ran out of memory of this kind.
|
|
OutOfMemory(MemoryKind),
|
|
/// The Vulkan device was lost.
|
|
DeviceLost,
|
|
/// Any other Vulkan failure, raw.
|
|
Vulkan(VkResultCode),
|
|
/// The runtime's own broken invariant (`Error::Compile` of an internal error).
|
|
Internal,
|
|
}
|
|
|
|
impl PipelineCreationCause {
|
|
/// The cause of `error`, a pipeline's making's.
|
|
pub(super) fn of(error: &Error) -> PipelineCreationCause {
|
|
match error {
|
|
Error::OutOfMemory(kind) => PipelineCreationCause::OutOfMemory(*kind),
|
|
Error::DeviceLost => PipelineCreationCause::DeviceLost,
|
|
Error::Vulkan(code) => PipelineCreationCause::Vulkan(*code),
|
|
_ => PipelineCreationCause::Internal,
|
|
}
|
|
}
|
|
}
|
|
|
|
/// A draw's or a dispatch's `VkPipeline` the driver did not make (a dispatch's failing its
|
|
/// command buffer, [`CommandBufferError::PipelineCreation`]; a draw's dropping the draw,
|
|
/// [`CommandBuffer::dropped_draw`](crate::CommandBuffer::dropped_draw)): the command, by its
|
|
/// encoder and its order there;
|
|
/// the pipeline state it ran, and the variant of that state and the specialization its pipeline
|
|
/// took; and the error the making returned, which the command returned where the runtime made
|
|
/// the pipeline at the command. A command buffer keeps the first, in encoding order, as Metal
|
|
/// reports one error per command buffer.
|
|
#[non_exhaustive]
|
|
#[derive(Clone, Debug)]
|
|
pub struct FailedPipeline {
|
|
/// The command's render or compute encoder, by its place among the command buffer's ended
|
|
/// encoders, in the order they ended, from 0: the index of
|
|
/// [`CommandBuffer::ended_encoders`](crate::CommandBuffer::ended_encoders), as
|
|
/// [`CommitFailure::encoders`](crate::CommitFailure::encoders) numbers them.
|
|
pub encoder: usize,
|
|
/// The command, by its order among its encoder's commands of its kind that returned `Ok`,
|
|
/// from 0: a render encoder's draw calls (every `draw_*` call: of primitives, indexed,
|
|
/// indirect, patches and meshes) or tile dispatch calls (every `dispatch_threads_per_tile*`
|
|
/// call), a compute encoder's dispatch calls (every `dispatch_*` call, direct and indirect).
|
|
pub draw: usize,
|
|
/// The state the command ran.
|
|
pub state: FailedState,
|
|
/// The variant of the state the draw's bind shape asked for: the storage textures' formats, the
|
|
/// buffers fetched in the shader, sRGB textures read raw, and the other choices the compile
|
|
/// takes from what the draw binds.
|
|
pub variant: metal2vulkan::cache::VariantKey,
|
|
/// The value of each specialization constant of the draw's `VkPipeline`, by its meaning, in
|
|
/// id order, each as its low bytes: among them the word of each bound sampler
|
|
/// (`SpecKey::SamplerState`). The format class of each bound texture is not among them: its
|
|
/// functions read it from a push field, and one `VkPipeline` serves every bound format.
|
|
pub specialization: Vec<(metal2vulkan::pipeline::SpecKey, u64)>,
|
|
/// The error the driver's creation returned.
|
|
pub error: Error,
|
|
}
|
|
|
|
/// The pipeline state of a command whose `VkPipeline` the driver did not make
|
|
/// ([`FailedPipeline::state`]).
|
|
#[non_exhaustive]
|
|
#[derive(Clone, Debug)]
|
|
pub enum FailedState {
|
|
/// A draw's render pipeline state, or a tile dispatch's tile render pipeline state.
|
|
Render(crate::RenderPipelineState),
|
|
/// A dispatch's compute pipeline state.
|
|
Compute(crate::ComputePipelineState),
|
|
}
|
|
|
|
/// The first emulated mesh draw of a command buffer whose records did not fit
|
|
/// ([`CommandBufferError::MeshRecordsOverflow`]).
|
|
#[non_exhaustive]
|
|
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
|
pub struct MeshRecordsOverflow {
|
|
/// The draw's order among the command buffer's emulated mesh and tessellation draws, from 0.
|
|
pub draw: u32,
|
|
/// Its object threadgroups (1 for a pipeline without an object function).
|
|
pub object_threadgroups: u32,
|
|
/// The mesh threadgroups it launched, saturated at `u32::MAX`; 0 where its object slots did
|
|
/// not fit, before any launched.
|
|
pub mesh_threadgroups: u32,
|
|
/// The bytes of the command buffer's records pool, the device's budget.
|
|
pub budget: u64,
|
|
}
|
|
|
|
/// The first emulated tessellation draw of a command buffer whose records did not fit
|
|
/// ([`CommandBufferError::TessellationRecordsOverflow`]).
|
|
#[non_exhaustive]
|
|
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
|
pub struct TessellationRecordsOverflow {
|
|
/// The draw's order among the command buffer's emulated mesh and tessellation draws, from 0.
|
|
pub draw: u32,
|
|
/// Its records, `patchCount · instanceCount`, saturated at `u32::MAX`.
|
|
pub records: u32,
|
|
/// The bytes of the command buffer's records pool, the device's budget.
|
|
pub budget: u64,
|
|
}
|
|
|
|
impl CommandBufferError {
|
|
/// Metal's `MTLCommandBufferError` code for this error: `MTLCommandBufferErrorDeviceRemoved`
|
|
/// (11) for a lost device, `OutOfMemory` (8) for the device's memory, the index pool's and the
|
|
/// records pool's (mesh and tessellation), and a detached buffer's, `AccessRevoked` (4) for a
|
|
/// revoked queue's, `PageFault` (3), `InvalidResource` (9) for a memoryless texture's use,
|
|
/// and `Internal` (1), also for the runtime's refusals (a cubic argument sampler's reach among
|
|
/// them, a sampler state left out of an argument-sampler listing, a host step's object nothing
|
|
/// made, a named use rebound before the submission, a predicated loop past its copies, and a
|
|
/// mesh grid past the device's limits); a
|
|
/// command buffer committed as failed, the code the program chose; a pipeline's failed making,
|
|
/// its cause's; a failure the driver relayed, Metal's.
|
|
///
|
|
/// The code is Metal's answer only where [`origin`](Self::origin) is
|
|
/// [`FailureOrigin::Metal`]. A [`FailureOrigin::Runtime`] error's code is the nearest of
|
|
/// Metal's codes, for a caller that must report one, where Metal fails no command buffer.
|
|
pub fn metal_code(self) -> u64 {
|
|
match self {
|
|
CommandBufferError::Injected(code) => code,
|
|
CommandBufferError::DeviceLost => 11,
|
|
CommandBufferError::OutOfMemory
|
|
| CommandBufferError::IndexPoolOverflow
|
|
| CommandBufferError::MeshRecordsOverflow(_)
|
|
| CommandBufferError::TessellationRecordsOverflow(_)
|
|
| CommandBufferError::DetachedBacking => 8,
|
|
CommandBufferError::Internal(_)
|
|
| CommandBufferError::MeshGridPastLimits
|
|
| CommandBufferError::Refused
|
|
| CommandBufferError::RenderTargetSize
|
|
| CommandBufferError::CubicArgumentSampler
|
|
| CommandBufferError::EncodedUseRebound
|
|
| CommandBufferError::PredicationOpenAtUnitEnd { .. }
|
|
| CommandBufferError::DefaultRasterSampleCount
|
|
| CommandBufferError::CallRefused(_) => 1,
|
|
CommandBufferError::PageFault => 3,
|
|
CommandBufferError::InvalidResource => 9,
|
|
CommandBufferError::GpuHang => 2,
|
|
CommandBufferError::GpuRecoveryVictim => 1,
|
|
CommandBufferError::AccessRevoked => 4,
|
|
CommandBufferError::PipelineCreation(cause) => match cause {
|
|
PipelineCreationCause::OutOfMemory(_) => 8,
|
|
PipelineCreationCause::DeviceLost => 11,
|
|
PipelineCreationCause::Vulkan(_) | PipelineCreationCause::Internal => 1,
|
|
},
|
|
CommandBufferError::Execution(code) => code,
|
|
CommandBufferError::ProtectedEncoder(options) => match options >= 0x10 {
|
|
true => 1,
|
|
false => 16,
|
|
},
|
|
}
|
|
}
|
|
|
|
/// Whose failure this is: [`FailureOrigin::Metal`] where Metal fails such work too, with the
|
|
/// code [`metal_code`](Self::metal_code) gives, and [`FailureOrigin::Runtime`] where Metal
|
|
/// runs the work and fails no command buffer, or Vulkan failed it in a way Metal has no
|
|
/// counterpart of. A caller answering as Metal does hands on a `Metal` failure as Metal's, and
|
|
/// tells a `Runtime` one apart.
|
|
pub fn origin(self) -> FailureOrigin {
|
|
match self {
|
|
CommandBufferError::Injected(_)
|
|
| CommandBufferError::DeviceLost
|
|
| CommandBufferError::OutOfMemory
|
|
| CommandBufferError::PageFault
|
|
| CommandBufferError::GpuHang
|
|
| CommandBufferError::GpuRecoveryVictim
|
|
| CommandBufferError::AccessRevoked
|
|
| CommandBufferError::Execution(_)
|
|
| CommandBufferError::RenderTargetSize
|
|
| CommandBufferError::DetachedBacking
|
|
| CommandBufferError::PredicationOpenAtUnitEnd { .. }
|
|
| CommandBufferError::ProtectedEncoder(_)
|
|
| CommandBufferError::DefaultRasterSampleCount
|
|
| CommandBufferError::InvalidResource => FailureOrigin::Metal,
|
|
CommandBufferError::Internal(_)
|
|
| CommandBufferError::IndexPoolOverflow
|
|
| CommandBufferError::CubicArgumentSampler
|
|
| CommandBufferError::MeshRecordsOverflow(_)
|
|
| CommandBufferError::TessellationRecordsOverflow(_)
|
|
| CommandBufferError::MeshGridPastLimits
|
|
| CommandBufferError::Refused
|
|
| CommandBufferError::PipelineCreation(_)
|
|
| CommandBufferError::EncodedUseRebound
|
|
| CommandBufferError::CallRefused(_) => FailureOrigin::Runtime,
|
|
}
|
|
}
|
|
|
|
/// Metal's `localizedDescription` of [`CommandBufferError::PredicationOpenAtUnitEnd`] (an M3
|
|
/// Max under macOS 27.0.1).
|
|
pub(crate) const PREDICATION_OPEN_AT_UNIT_END_DESCRIPTION: &'static str =
|
|
"Discarded (victim of GPU error/recovery) \
|
|
(00000005:kIOGPUCommandBufferCallbackErrorInnocentVictim)";
|
|
|
|
/// The error of Metal's `MTLCommandBufferError` code `code` (not 0), as the driver relayed it
|
|
/// (`device/relay.rs`): `PageFault` for 3, `DeviceLost` for 11, else `Execution`.
|
|
pub(crate) fn of_metal_code(code: u64) -> CommandBufferError {
|
|
match code {
|
|
3 => CommandBufferError::PageFault,
|
|
11 => CommandBufferError::DeviceLost,
|
|
code => CommandBufferError::Execution(code),
|
|
}
|
|
}
|
|
}
|
|
|
|
/// A bounded wait ended before the awaited state. No Metal counterpart: the runtime's bounded
|
|
/// forms of Metal's unbounded waits.
|
|
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
|
pub struct TimedOut;
|
|
|
|
/// The error of a failed Vulkan call: out-of-memory and device loss are typed, the rest raw.
|
|
pub(super) fn vulkan(result: ash::vk::Result) -> Error {
|
|
use ash::vk::Result as R;
|
|
match result {
|
|
R::ERROR_OUT_OF_HOST_MEMORY => Error::OutOfMemory(MemoryKind::Host),
|
|
R::ERROR_OUT_OF_DEVICE_MEMORY => Error::OutOfMemory(MemoryKind::Device),
|
|
R::ERROR_DEVICE_LOST => Error::DeviceLost,
|
|
other => Error::Vulkan(VkResultCode(other.as_raw())),
|
|
}
|
|
}
|
|
|
|
/// A Metal validation error of `call`.
|
|
pub(super) fn invalid(call: &'static str, problem: Problem) -> Error {
|
|
Error::Invalid(Invalid::new(call, problem))
|
|
}
|
|
|
|
/// `problem` in `call`, for which plain Metal answers nil.
|
|
pub(super) fn nil(call: &'static str, problem: Problem) -> Error {
|
|
Error::Nil(Nil::new(call, problem))
|
|
}
|
|
|
|
/// An internal error: the compile layer's output broke a contract the runtime relies on.
|
|
pub(super) fn internal(detail: &str) -> Error {
|
|
Error::Compile(metal2vulkan::error::Error::Internal(
|
|
metal2vulkan::error::InternalError::new(
|
|
metal2vulkan::error::InternalKind::Invariant,
|
|
detail,
|
|
),
|
|
))
|
|
}
|