#[cfg(feature = "deserialize")] fn deserialize_binding_map<'de, D>(deserializer: D) -> Result<BindingMap, D::Error> where
D: serde::Deserializer<'de>,
{ use serde::Deserialize;
let vec = Vec::<BindingMapSerialization>::deserialize(deserializer)?; letmut map = BindingMap::default(); for item in vec {
map.insert(item.resource_binding, item.bind_target);
}
Ok(map)
}
// Using `BTreeMap` instead of `HashMap` so that we can hash itself. pubtype BindingMap = alloc::collections::BTreeMap<crate::ResourceBinding, BindTarget>;
/// The slot of a buffer that contains an array of `u32`, /// one for the size of each bound buffer that contains a runtime array, /// in order of [`crate::GlobalVariable`] declarations. pub sizes_buffer: Option<Slot>,
}
// Note: some of these should be removed in favor of proper IR validation.
#[derive(Debug, thiserror::Error)] pubenum Error { #[error(transparent)]
Format(#[from] FmtError), #[error("bind target {0:?} is empty")]
UnimplementedBindTarget(BindTarget), #[error("composing of {0:?} is not implemented yet")]
UnsupportedCompose(Handle<crate::Type>), #[error("operation {0:?} is not implemented yet")]
UnsupportedBinaryOp(crate::BinaryOperator), #[error("standard function '{0}' is not implemented yet")]
UnsupportedCall(String), #[error("feature '{0}' is not implemented yet")]
FeatureNotImplemented(String), #[error("internal naga error: module should not have validated: {0}")]
GenericValidation(String), #[error("BuiltIn {0:?} is not supported")]
UnsupportedBuiltIn(crate::BuiltIn), #[error("capability {0:?} is not supported")]
CapabilityNotSupported(crate::valid::Capabilities), #[error("attribute '{0}' is not supported for target MSL version")]
UnsupportedAttribute(String), #[error("function '{0}' is not supported for target MSL version")]
UnsupportedFunction(String), #[error("can not use writable storage buffers in fragment stage prior to MSL 1.2")]
UnsupportedWritableStorageBuffer, #[error("can not use writable storage textures in {0:?} stage prior to MSL 1.2")]
UnsupportedWritableStorageTexture(ir::ShaderStage), #[error("can not use read-write storage textures prior to MSL 1.2")]
UnsupportedRWStorageTexture, #[error("array of '{0}' is not supported for target MSL version")]
UnsupportedArrayOf(String), #[error("array of type '{0:?}' is not supported")]
UnsupportedArrayOfType(Handle<crate::Type>), #[error("ray tracing is not supported prior to MSL 2.4")]
UnsupportedRayTracing, #[error("cooperative matrix is not supported prior to MSL 2.3")]
UnsupportedCooperativeMatrix, #[error("overrides should not be present at this stage")] Override, #[error("bitcasting to {0:?} is not supported")]
UnsupportedBitCast(crate::TypeInner), #[error(transparent)]
ResolveArraySizeError(#[from] crate::proc::ResolveArraySizeError), #[error("entry point with stage {0:?} and name '{1}' not found")]
EntryPointNotFound(ir::ShaderStage, String), #[error("Cannot use mesh shader syntax prior to MSL 3.0")]
UnsupportedMeshShader, #[error("Per vertex fragment inputs are not supported prior to MSL 4.0")]
PerVertexNotSupported,
}
#[derive(Clone, Debug, PartialEq, thiserror::Error)] #[cfg_attr(feature = "serialize", derive(serde::Serialize))] #[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] pubenum EntryPointError { #[error("global '{0}' doesn't have a binding")]
MissingBinding(String), #[error("mapping of {0:?} is missing")]
MissingBindTarget(crate::ResourceBinding), #[error("mapping for immediates is missing")]
MissingImmediateData, #[error("mapping for sizes buffer is missing")]
MissingSizesBuffer,
}
/// Points in the MSL code where we might emit a pipeline input or output. /// /// Note that, even though vertex shaders' outputs are always fragment /// shaders' inputs, we still need to distinguish `VertexOutput` and /// `FragmentInput`, since there are certain differences in the way /// [`ResolvedBinding`s] are represented on either side. /// /// [`ResolvedBinding`s]: ResolvedBinding #[derive(Clone, Copy, Debug)] enum LocationMode { /// Input to the vertex shader.
VertexInput,
/// Output from the vertex shader.
VertexOutput,
/// Input to the fragment shader.
FragmentInput,
/// Output from the fragment shader.
FragmentOutput,
/// Output from the mesh shader.
MeshOutput,
/// Compute shader input or output.
Uniform,
}
#[derive(Clone, Debug, Hash, PartialEq, Eq)] #[cfg_attr(feature = "serialize", derive(serde::Serialize))] #[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] #[cfg_attr(feature = "deserialize", serde(default))] pubstruct Options { /// (Major, Minor) target version of the Metal Shading Language. pub lang_version: (u8, u8), /// Map of entry-point resources, indexed by entry point function name, to slots. pub per_entry_point_map: EntryPointResourceMap, /// Samplers to be inlined into the code. pub inline_samplers: Vec<sampler::InlineSampler>, /// Make it possible to link different stages via SPIRV-Cross. pub spirv_cross_compatibility: bool, /// Don't panic on missing bindings, instead generate invalid MSL. pub fake_missing_bindings: bool, /// Bounds checking policies. pub bounds_check_policies: index::BoundsCheckPolicies, /// Should workgroup variables be zero initialized (by polyfilling)? pub zero_initialize_workgroup_memory: bool, /// If set, loops will have code injected into them, forcing the compiler /// to think the number of iterations is bounded. pub force_loop_bounding: bool, /// Whether and how checks in the task shader should verify the dispatched /// mesh grid size. pub task_dispatch_limits: Option<TaskDispatchLimits>, /// Whether to validate the output of a mesh shader workgroup. pub mesh_shader_primitive_indices_clamp: bool,
}
/// Corresponds to [WebGPU `GPUVertexFormat`]( /// https://gpuweb.github.io/gpuweb/#enumdef-gpuvertexformat). #[repr(u32)] #[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)] #[cfg_attr(feature = "serialize", derive(serde::Serialize))] #[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] pubenum VertexFormat { /// One unsigned byte (u8). `u32` in shaders.
Uint8 = 0, /// Two unsigned bytes (u8). `vec2<u32>` in shaders.
Uint8x2 = 1, /// Four unsigned bytes (u8). `vec4<u32>` in shaders.
Uint8x4 = 2, /// One signed byte (i8). `i32` in shaders.
Sint8 = 3, /// Two signed bytes (i8). `vec2<i32>` in shaders.
Sint8x2 = 4, /// Four signed bytes (i8). `vec4<i32>` in shaders.
Sint8x4 = 5, /// One unsigned byte (u8). [0, 255] converted to float [0, 1] `f32` in shaders.
Unorm8 = 6, /// Two unsigned bytes (u8). [0, 255] converted to float [0, 1] `vec2<f32>` in shaders.
Unorm8x2 = 7, /// Four unsigned bytes (u8). [0, 255] converted to float [0, 1] `vec4<f32>` in shaders.
Unorm8x4 = 8, /// One signed byte (i8). [-127, 127] converted to float [-1, 1] `f32` in shaders.
Snorm8 = 9, /// Two signed bytes (i8). [-127, 127] converted to float [-1, 1] `vec2<f32>` in shaders.
Snorm8x2 = 10, /// Four signed bytes (i8). [-127, 127] converted to float [-1, 1] `vec4<f32>` in shaders.
Snorm8x4 = 11, /// One unsigned short (u16). `u32` in shaders.
Uint16 = 12, /// Two unsigned shorts (u16). `vec2<u32>` in shaders.
Uint16x2 = 13, /// Four unsigned shorts (u16). `vec4<u32>` in shaders.
Uint16x4 = 14, /// One signed short (u16). `i32` in shaders.
Sint16 = 15, /// Two signed shorts (i16). `vec2<i32>` in shaders.
Sint16x2 = 16, /// Four signed shorts (i16). `vec4<i32>` in shaders.
Sint16x4 = 17, /// One unsigned short (u16). [0, 65535] converted to float [0, 1] `f32` in shaders.
Unorm16 = 18, /// Two unsigned shorts (u16). [0, 65535] converted to float [0, 1] `vec2<f32>` in shaders.
Unorm16x2 = 19, /// Four unsigned shorts (u16). [0, 65535] converted to float [0, 1] `vec4<f32>` in shaders.
Unorm16x4 = 20, /// One signed short (i16). [-32767, 32767] converted to float [-1, 1] `f32` in shaders.
Snorm16 = 21, /// Two signed shorts (i16). [-32767, 32767] converted to float [-1, 1] `vec2<f32>` in shaders.
Snorm16x2 = 22, /// Four signed shorts (i16). [-32767, 32767] converted to float [-1, 1] `vec4<f32>` in shaders.
Snorm16x4 = 23, /// One half-precision float (no Rust equiv). `f32` in shaders.
Float16 = 24, /// Two half-precision floats (no Rust equiv). `vec2<f32>` in shaders.
Float16x2 = 25, /// Four half-precision floats (no Rust equiv). `vec4<f32>` in shaders.
Float16x4 = 26, /// One single-precision float (f32). `f32` in shaders.
Float32 = 27, /// Two single-precision floats (f32). `vec2<f32>` in shaders.
Float32x2 = 28, /// Three single-precision floats (f32). `vec3<f32>` in shaders.
Float32x3 = 29, /// Four single-precision floats (f32). `vec4<f32>` in shaders.
Float32x4 = 30, /// One unsigned int (u32). `u32` in shaders.
Uint32 = 31, /// Two unsigned ints (u32). `vec2<u32>` in shaders.
Uint32x2 = 32, /// Three unsigned ints (u32). `vec3<u32>` in shaders.
Uint32x3 = 33, /// Four unsigned ints (u32). `vec4<u32>` in shaders.
Uint32x4 = 34, /// One signed int (i32). `i32` in shaders.
Sint32 = 35, /// Two signed ints (i32). `vec2<i32>` in shaders.
Sint32x2 = 36, /// Three signed ints (i32). `vec3<i32>` in shaders.
Sint32x3 = 37, /// Four signed ints (i32). `vec4<i32>` in shaders.
Sint32x4 = 38, /// Three unsigned 10-bit integers and one 2-bit integer, packed into a 32-bit integer (u32). [0, 1024] converted to float [0, 1] `vec4<f32>` in shaders. #[cfg_attr(
any(feature = "serialize", feature = "deserialize"),
serde(rename = "unorm10-10-10-2")
)]
Unorm10_10_10_2 = 43, /// Four unsigned 8-bit integers, packed into a 32-bit integer (u32). [0, 255] converted to float [0, 1] `vec4<f32>` in shaders. #[cfg_attr(
any(feature = "serialize", feature = "deserialize"),
serde(rename = "unorm8x4-bgra")
)]
Unorm8x4Bgra = 44,
}
/// Defines how to advance the data in vertex buffers. #[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serialize", derive(serde::Serialize))] #[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] pubenum VertexBufferStepMode {
Constant, #[default]
ByVertex,
ByInstance,
}
/// A mapping of vertex buffers and their attributes to shader /// locations. #[derive(Debug, Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serialize", derive(serde::Serialize))] #[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] pubstruct AttributeMapping { /// Shader location associated with this attribute pub shader_location: u32, /// Offset in bytes from start of vertex buffer structure pub offset: u32, /// Format code to help us unpack the attribute into the type /// used by the shader. Codes correspond to a 0-based index of /// <https://gpuweb.github.io/gpuweb/#enumdef-gpuvertexformat>. /// The conversion process is described by /// <https://gpuweb.github.io/gpuweb/#vertex-processing>. pub format: VertexFormat,
}
/// A description of a vertex buffer with all the information we /// need to address the attributes within it. #[derive(Debug, Default, Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serialize", derive(serde::Serialize))] #[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] pubstruct VertexBufferMapping { /// Shader location associated with this buffer pub id: u32, /// Size of the structure in bytes pub stride: u32, /// Vertex buffer step mode pub step_mode: VertexBufferStepMode, /// Vec of the attributes within the structure pub attributes: Vec<AttributeMapping>,
}
/// A subset of options that are meant to be changed per pipeline. #[derive(Debug, Default, Clone)] #[cfg_attr(feature = "serialize", derive(serde::Serialize))] #[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] #[cfg_attr(feature = "deserialize", serde(default))] pubstruct PipelineOptions { /// The entry point to write. /// /// Entry points are identified by a shader stage specification, /// and a name. /// /// If `None`, all entry points will be written. If `Some` and the entry /// point is not found, an error will be thrown while writing. pub entry_point: Option<(ir::ShaderStage, String)>,
/// Allow `BuiltIn::PointSize` and inject it if doesn't exist. /// /// Metal doesn't like this for non-point primitive topologies and requires it for /// point primitive topologies. /// /// Enable this for vertex/mesh shaders with point primitive topologies. pub allow_and_force_point_size: bool,
/// If set, when generating the Metal vertex shader, transform it /// to receive the vertex buffers, lengths, and vertex id as args, /// and bounds-check the vertex id and use the index into the /// vertex buffers to access attributes, rather than using Metal's /// [[stage-in]] assembled attribute data. This is true by default, /// but remains configurable for use by tests via deserialization /// of this struct. There is no user-facing way to set this value. pub vertex_pulling_transform: bool,
/// vertex_buffer_mappings are used during shader translation to /// support vertex pulling. pub vertex_buffer_mappings: Vec<VertexBufferMapping>,
}
/// Shorthand result used internally by the backend type BackendResult = Result<(), Error>;
const NAMESPACE: &str = "metal";
// The name of the array member of the Metal struct types we generate to // represent Naga `Array` types. See the comments in `Writer::write_type_defs` // for details. const WRAPPED_ARRAY_FIELD: &str = "inner";
/// Information about a translated module that is required /// for the use of the result. pubstruct TranslationInfo { /// Mapping of the entry point names. Each item in the array /// corresponds to an entry point index. /// ///Note: Some entry points may fail translation because of missing bindings. pub entry_point_names: Vec<Result<String, EntryPointError>>,
}
pubfn write_string(
module: &crate::Module,
info: &ModuleInfo,
options: &Options,
pipeline_options: &PipelineOptions,
) -> Result<(String, TranslationInfo), Error> { letmut w = Writer::new(String::new()); let info = w.write(module, info, options, pipeline_options)?;
Ok((w.finish(), info))
}
pubfn supported_capabilities() -> crate::valid::Capabilities { usecrate::valid::Capabilities as Caps;
Caps::IMMEDIATES // No FLOAT64
| Caps::PRIMITIVE_INDEX
| Caps::TEXTURE_AND_SAMPLER_BINDING_ARRAY // No BUFFER_BINDING_ARRAY
| Caps::STORAGE_TEXTURE_BINDING_ARRAY
| Caps::STORAGE_BUFFER_BINDING_ARRAY
| Caps::CLIP_DISTANCES // No CULL_DISTANCE
| Caps::STORAGE_TEXTURE_16BIT_NORM_FORMATS
| Caps::MULTIVIEW // No EARLY_DEPTH_TEST
| Caps::MULTISAMPLED_SHADING
| Caps::RAY_QUERY
| Caps::DUAL_SOURCE_BLENDING
| Caps::CUBE_ARRAY_TEXTURES
| Caps::SHADER_INT64
| Caps::SUBGROUP
| Caps::SUBGROUP_BARRIER // No SUBGROUP_VERTEX_STAGE
| Caps::SHADER_INT64_ATOMIC_MIN_MAX // No SHADER_INT64_ATOMIC_ALL_OPS
| Caps::SHADER_FLOAT32_ATOMIC
| Caps::TEXTURE_ATOMIC
| Caps::TEXTURE_INT64_ATOMIC // No RAY_HIT_VERTEX_POSITION
| Caps::SHADER_FLOAT16
| Caps::SHADER_INT16
| Caps::TEXTURE_EXTERNAL
| Caps::SHADER_FLOAT16_IN_FLOAT32
| Caps::SHADER_BARYCENTRICS
| Caps::MESH_SHADER
| Caps::MESH_SHADER_POINT_TOPOLOGY
| Caps::TEXTURE_AND_SAMPLER_BINDING_ARRAY_NON_UNIFORM_INDEXING // No BUFFER_BINDING_ARRAY_NON_UNIFORM_INDEXING
| Caps::STORAGE_TEXTURE_BINDING_ARRAY_NON_UNIFORM_INDEXING
| Caps::STORAGE_BUFFER_BINDING_ARRAY_NON_UNIFORM_INDEXING
| Caps::COOPERATIVE_MATRIX
| Caps::PER_VERTEX // No RAY_TRACING_PIPELINE // No DRAW_INDEX // No MEMORY_DECORATION_VOLATILE
| Caps::MEMORY_DECORATION_COHERENT
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.