pub struct Device(/* private fields */);Expand description
A Metal device representing a GPU.
C++ equivalent: MTL::Device
The device is the central object in Metal. It is used to create all other Metal objects including command queues, buffers, textures, and pipelines.
Implementations§
Source§impl Device
impl Device
Sourcepub fn supports_family(&self, gpu_family: GPUFamily) -> bool
pub fn supports_family(&self, gpu_family: GPUFamily) -> bool
Check if the device supports a specific GPU family.
C++ equivalent: bool supportsFamily(MTL::GPUFamily gpuFamily)
Sourcepub fn supports_feature_set(&self, feature_set: FeatureSet) -> bool
pub fn supports_feature_set(&self, feature_set: FeatureSet) -> bool
Check if the device supports a specific feature set (legacy).
C++ equivalent: bool supportsFeatureSet(MTL::FeatureSet featureSet)
Sourcepub fn are_barycentric_coords_supported(&self) -> bool
pub fn are_barycentric_coords_supported(&self) -> bool
Check if barycentric coordinates are supported.
C++ equivalent: bool areBarycentricCoordsSupported() const
Sourcepub fn are_programmable_sample_positions_supported(&self) -> bool
pub fn are_programmable_sample_positions_supported(&self) -> bool
Check if programmable sample positions are supported.
C++ equivalent: bool areProgrammableSamplePositionsSupported() const
Sourcepub fn are_raster_order_groups_supported(&self) -> bool
pub fn are_raster_order_groups_supported(&self) -> bool
Check if raster order groups are supported.
C++ equivalent: bool areRasterOrderGroupsSupported() const
Sourcepub fn supports_32bit_float_filtering(&self) -> bool
pub fn supports_32bit_float_filtering(&self) -> bool
Check if 32-bit float filtering is supported.
C++ equivalent: bool supports32BitFloatFiltering() const
Sourcepub fn supports_32bit_msaa(&self) -> bool
pub fn supports_32bit_msaa(&self) -> bool
Check if 32-bit MSAA is supported.
C++ equivalent: bool supports32BitMSAA() const
Sourcepub fn supports_texture_sample_count(&self, sample_count: UInteger) -> bool
pub fn supports_texture_sample_count(&self, sample_count: UInteger) -> bool
Check if the device supports a specific texture sample count.
C++ equivalent: bool supportsTextureSampleCount(NS::UInteger sampleCount)
Sourcepub fn supports_vertex_amplification_count(&self, count: UInteger) -> bool
pub fn supports_vertex_amplification_count(&self, count: UInteger) -> bool
Check if vertex amplification is supported for a given count.
C++ equivalent: bool supportsVertexAmplificationCount(NS::UInteger count)
Sourcepub fn supports_query_texture_lod(&self) -> bool
pub fn supports_query_texture_lod(&self) -> bool
Check if query texture LOD is supported.
C++ equivalent: bool supportsQueryTextureLOD() const
Sourcepub fn supports_pull_model_interpolation(&self) -> bool
pub fn supports_pull_model_interpolation(&self) -> bool
Check if pull model interpolation is supported.
C++ equivalent: bool supportsPullModelInterpolation() const
Sourcepub fn supports_shader_barycentric_coordinates(&self) -> bool
pub fn supports_shader_barycentric_coordinates(&self) -> bool
Check if shader barycentric coordinates are supported.
C++ equivalent: bool supportsShaderBarycentricCoordinates() const
Sourcepub fn supports_bc_texture_compression(&self) -> bool
pub fn supports_bc_texture_compression(&self) -> bool
Check if BC texture compression is supported.
C++ equivalent: bool supportsBCTextureCompression() const
Sourcepub fn is_depth24_stencil8_pixel_format_supported(&self) -> bool
pub fn is_depth24_stencil8_pixel_format_supported(&self) -> bool
Check if depth24 stencil8 pixel format is supported.
C++ equivalent: bool isDepth24Stencil8PixelFormatSupported() const
Sourcepub fn supports_raytracing(&self) -> bool
pub fn supports_raytracing(&self) -> bool
Check if ray tracing is supported.
C++ equivalent: bool supportsRaytracing() const
Sourcepub fn supports_raytracing_from_render(&self) -> bool
pub fn supports_raytracing_from_render(&self) -> bool
Check if ray tracing from render is supported.
C++ equivalent: bool supportsRaytracingFromRender() const
Sourcepub fn supports_primitive_motion_blur(&self) -> bool
pub fn supports_primitive_motion_blur(&self) -> bool
Check if primitive motion blur is supported.
C++ equivalent: bool supportsPrimitiveMotionBlur() const
Sourcepub fn supports_function_pointers(&self) -> bool
pub fn supports_function_pointers(&self) -> bool
Check if function pointers are supported.
C++ equivalent: bool supportsFunctionPointers() const
Sourcepub fn supports_function_pointers_from_render(&self) -> bool
pub fn supports_function_pointers_from_render(&self) -> bool
Check if function pointers from render are supported.
C++ equivalent: bool supportsFunctionPointersFromRender() const
Sourcepub fn supports_dynamic_libraries(&self) -> bool
pub fn supports_dynamic_libraries(&self) -> bool
Check if dynamic libraries are supported.
C++ equivalent: bool supportsDynamicLibraries() const
Sourcepub fn supports_render_dynamic_libraries(&self) -> bool
pub fn supports_render_dynamic_libraries(&self) -> bool
Check if render dynamic libraries are supported.
C++ equivalent: bool supportsRenderDynamicLibraries() const
Sourcepub fn supports_rasterization_rate_map(&self, layer_count: UInteger) -> bool
pub fn supports_rasterization_rate_map(&self, layer_count: UInteger) -> bool
Check if rasterization rate maps are supported for a given layer count.
C++ equivalent: bool supportsRasterizationRateMap(NS::UInteger layerCount)
Sourcepub fn supports_counter_sampling(
&self,
sampling_point: CounterSamplingPoint,
) -> bool
pub fn supports_counter_sampling( &self, sampling_point: CounterSamplingPoint, ) -> bool
Check if counter sampling is supported at a specific sampling point.
C++ equivalent: bool supportsCounterSampling(MTL::CounterSamplingPoint samplingPoint)
Source§impl Device
impl Device
Sourcepub fn max_threads_per_threadgroup(&self) -> Size
pub fn max_threads_per_threadgroup(&self) -> Size
Get the maximum threads per threadgroup.
C++ equivalent: Size maxThreadsPerThreadgroup() const
Sourcepub fn max_threadgroup_memory_length(&self) -> UInteger
pub fn max_threadgroup_memory_length(&self) -> UInteger
Get the maximum threadgroup memory length in bytes.
C++ equivalent: NS::UInteger maxThreadgroupMemoryLength() const
Sourcepub fn max_buffer_length(&self) -> UInteger
pub fn max_buffer_length(&self) -> UInteger
Get the maximum buffer length in bytes.
C++ equivalent: NS::UInteger maxBufferLength() const
Sourcepub fn max_argument_buffer_sampler_count(&self) -> UInteger
pub fn max_argument_buffer_sampler_count(&self) -> UInteger
Get the maximum number of samplers that can be in an argument buffer.
C++ equivalent: NS::UInteger maxArgumentBufferSamplerCount() const
Sourcepub fn minimum_linear_texture_alignment_for_pixel_format(
&self,
format: PixelFormat,
) -> UInteger
pub fn minimum_linear_texture_alignment_for_pixel_format( &self, format: PixelFormat, ) -> UInteger
Get the minimum alignment for a linear texture with the given pixel format.
C++ equivalent: NS::UInteger minimumLinearTextureAlignmentForPixelFormat(MTL::PixelFormat format)
Sourcepub fn minimum_texture_buffer_alignment_for_pixel_format(
&self,
format: PixelFormat,
) -> UInteger
pub fn minimum_texture_buffer_alignment_for_pixel_format( &self, format: PixelFormat, ) -> UInteger
Get the minimum alignment for a texture buffer with the given pixel format.
C++ equivalent: NS::UInteger minimumTextureBufferAlignmentForPixelFormat(MTL::PixelFormat format)
Sourcepub fn sparse_tile_size_in_bytes(&self) -> UInteger
pub fn sparse_tile_size_in_bytes(&self) -> UInteger
Get the sparse tile size in bytes.
C++ equivalent: NS::UInteger sparseTileSizeInBytes() const
Sourcepub fn sparse_tile_size_in_bytes_for_page_size(
&self,
page_size: SparsePageSize,
) -> UInteger
pub fn sparse_tile_size_in_bytes_for_page_size( &self, page_size: SparsePageSize, ) -> UInteger
Get the sparse tile size in bytes for a specific page size.
C++ equivalent: NS::UInteger sparseTileSizeInBytes(MTL::SparsePageSize sparsePageSize)
Sourcepub fn sparse_tile_size(
&self,
texture_type: TextureType,
pixel_format: PixelFormat,
sample_count: UInteger,
) -> Size
pub fn sparse_tile_size( &self, texture_type: TextureType, pixel_format: PixelFormat, sample_count: UInteger, ) -> Size
Get the sparse tile size for a texture configuration.
C++ equivalent: Size sparseTileSize(MTL::TextureType, MTL::PixelFormat, NS::UInteger sampleCount)
Sourcepub fn sparse_tile_size_with_page_size(
&self,
texture_type: TextureType,
pixel_format: PixelFormat,
sample_count: UInteger,
page_size: SparsePageSize,
) -> Size
pub fn sparse_tile_size_with_page_size( &self, texture_type: TextureType, pixel_format: PixelFormat, sample_count: UInteger, page_size: SparsePageSize, ) -> Size
Get the sparse tile size for a texture configuration with specific page size.
C++ equivalent: Size sparseTileSize(MTL::TextureType, MTL::PixelFormat, NS::UInteger, MTL::SparsePageSize)
Sourcepub fn convert_sparse_pixel_regions(
&self,
pixel_regions: &[Region],
tile_regions: &mut [Region],
tile_size: Size,
mode: SparseTextureRegionAlignmentMode,
)
pub fn convert_sparse_pixel_regions( &self, pixel_regions: &[Region], tile_regions: &mut [Region], tile_size: Size, mode: SparseTextureRegionAlignmentMode, )
Convert pixel regions to tile regions for sparse textures.
C++ equivalent: void convertSparsePixelRegions(...)
Sourcepub fn convert_sparse_tile_regions(
&self,
tile_regions: &[Region],
pixel_regions: &mut [Region],
tile_size: Size,
)
pub fn convert_sparse_tile_regions( &self, tile_regions: &[Region], pixel_regions: &mut [Region], tile_size: Size, )
Convert tile regions to pixel regions for sparse textures.
C++ equivalent: void convertSparseTileRegions(...)
Sourcepub fn heap_buffer_size_and_align(
&self,
length: UInteger,
options: ResourceOptions,
) -> SizeAndAlign
pub fn heap_buffer_size_and_align( &self, length: UInteger, options: ResourceOptions, ) -> SizeAndAlign
Get the size and alignment for a buffer in a heap.
C++ equivalent: SizeAndAlign heapBufferSizeAndAlign(NS::UInteger length, MTL::ResourceOptions options)
Sourcepub unsafe fn heap_texture_size_and_align(
&self,
descriptor: *const c_void,
) -> SizeAndAlign
pub unsafe fn heap_texture_size_and_align( &self, descriptor: *const c_void, ) -> SizeAndAlign
Get the size and alignment for a texture in a heap.
C++ equivalent: SizeAndAlign heapTextureSizeAndAlign(const MTL::TextureDescriptor* desc)
§Safety
The descriptor pointer must be a valid MTLTextureDescriptor.
Sourcepub fn heap_acceleration_structure_size_and_align_with_size(
&self,
size: UInteger,
) -> SizeAndAlign
pub fn heap_acceleration_structure_size_and_align_with_size( &self, size: UInteger, ) -> SizeAndAlign
Get the size and alignment for an acceleration structure in a heap (by size).
C++ equivalent: SizeAndAlign heapAccelerationStructureSizeAndAlign(NS::UInteger size)
Sourcepub unsafe fn heap_acceleration_structure_size_and_align_with_descriptor(
&self,
descriptor: *const c_void,
) -> SizeAndAlign
pub unsafe fn heap_acceleration_structure_size_and_align_with_descriptor( &self, descriptor: *const c_void, ) -> SizeAndAlign
Get the size and alignment for an acceleration structure in a heap (by descriptor).
C++ equivalent: SizeAndAlign heapAccelerationStructureSizeAndAlign(const MTL::AccelerationStructureDescriptor*)
§Safety
The descriptor pointer must be a valid MTLAccelerationStructureDescriptor.
Source§impl Device
impl Device
Sourcepub fn architecture(&self) -> Option<Architecture>
pub fn architecture(&self) -> Option<Architecture>
Get the device architecture.
C++ equivalent: Architecture* architecture() const
Sourcepub fn registry_id(&self) -> u64
pub fn registry_id(&self) -> u64
Get the device registry ID.
This is a unique identifier for the device that persists across reboots.
C++ equivalent: uint64_t registryID() const
Sourcepub fn location(&self) -> DeviceLocation
pub fn location(&self) -> DeviceLocation
Get the device location.
C++ equivalent: DeviceLocation location() const
Sourcepub fn location_number(&self) -> UInteger
pub fn location_number(&self) -> UInteger
Get the device location number.
C++ equivalent: NS::UInteger locationNumber() const
Sourcepub fn has_unified_memory(&self) -> bool
pub fn has_unified_memory(&self) -> bool
Check if the device has unified memory.
Returns true if the CPU and GPU share the same memory.
C++ equivalent: bool hasUnifiedMemory() const
Sourcepub fn is_headless(&self) -> bool
pub fn is_headless(&self) -> bool
Check if the device is headless (has no display attached).
C++ equivalent: bool isHeadless() const
Sourcepub fn is_low_power(&self) -> bool
pub fn is_low_power(&self) -> bool
Check if the device is low-power.
C++ equivalent: bool isLowPower() const
Sourcepub fn is_removable(&self) -> bool
pub fn is_removable(&self) -> bool
Check if the device is removable.
C++ equivalent: bool isRemovable() const
Sourcepub fn current_allocated_size(&self) -> UInteger
pub fn current_allocated_size(&self) -> UInteger
Get the current allocated memory size in bytes.
C++ equivalent: NS::UInteger currentAllocatedSize() const
Sourcepub fn recommended_max_working_set_size(&self) -> u64
pub fn recommended_max_working_set_size(&self) -> u64
Get the recommended maximum working set size.
C++ equivalent: uint64_t recommendedMaxWorkingSetSize() const
Sourcepub fn read_write_texture_support(&self) -> ReadWriteTextureTier
pub fn read_write_texture_support(&self) -> ReadWriteTextureTier
Get the read-write texture tier supported by this device.
C++ equivalent: ReadWriteTextureTier readWriteTextureSupport() const
Sourcepub fn argument_buffers_support(&self) -> ArgumentBuffersTier
pub fn argument_buffers_support(&self) -> ArgumentBuffersTier
Get the argument buffers tier supported by this device.
C++ equivalent: ArgumentBuffersTier argumentBuffersSupport() const
Sourcepub fn peer_group_id(&self) -> u64
pub fn peer_group_id(&self) -> u64
Get the peer group ID for multi-GPU configurations.
C++ equivalent: uint64_t peerGroupID() const
Sourcepub fn peer_index(&self) -> u32
pub fn peer_index(&self) -> u32
Get the peer index within a multi-GPU configuration.
C++ equivalent: uint32_t peerIndex() const
Sourcepub fn peer_count(&self) -> u32
pub fn peer_count(&self) -> u32
Get the number of peer devices.
C++ equivalent: uint32_t peerCount() const
Sourcepub fn max_transfer_rate(&self) -> u64
pub fn max_transfer_rate(&self) -> u64
Get the maximum data transfer rate in bytes per second.
C++ equivalent: uint64_t maxTransferRate() const
Sourcepub fn should_maximize_concurrent_compilation(&self) -> bool
pub fn should_maximize_concurrent_compilation(&self) -> bool
Get whether to maximize concurrent compilation.
C++ equivalent: bool shouldMaximizeConcurrentCompilation() const
Sourcepub fn set_should_maximize_concurrent_compilation(&self, value: bool)
pub fn set_should_maximize_concurrent_compilation(&self, value: bool)
Set whether to maximize concurrent compilation.
C++ equivalent: void setShouldMaximizeConcurrentCompilation(bool)
Sourcepub fn maximum_concurrent_compilation_task_count(&self) -> UInteger
pub fn maximum_concurrent_compilation_task_count(&self) -> UInteger
Get the maximum number of concurrent compilation tasks.
C++ equivalent: NS::UInteger maximumConcurrentCompilationTaskCount() const
Sourcepub fn query_timestamp_frequency(&self) -> u64
pub fn query_timestamp_frequency(&self) -> u64
Get the GPU timestamp frequency in Hz.
C++ equivalent: uint64_t queryTimestampFrequency()
Sourcepub fn sample_timestamps(&self) -> (u64, u64)
pub fn sample_timestamps(&self) -> (u64, u64)
Sample CPU and GPU timestamps simultaneously.
C++ equivalent: void sampleTimestamps(MTL::Timestamp*, MTL::Timestamp*)
Sourcepub fn get_default_sample_positions(&self, positions: &mut [SamplePosition])
pub fn get_default_sample_positions(&self, positions: &mut [SamplePosition])
Get default sample positions for a given sample count.
C++ equivalent: void getDefaultSamplePositions(MTL::SamplePosition*, NS::UInteger)
Sourcepub fn barycentric_coords_supported(&self) -> bool
👎Deprecated: Use are_barycentric_coords_supported() instead
pub fn barycentric_coords_supported(&self) -> bool
Check if barycentric coordinates are supported.
C++ equivalent: bool barycentricCoordsSupported() const
Sourcepub fn programmable_sample_positions_supported(&self) -> bool
👎Deprecated: Use are_programmable_sample_positions_supported() instead
pub fn programmable_sample_positions_supported(&self) -> bool
Check if programmable sample positions are supported.
C++ equivalent: bool programmableSamplePositionsSupported() const
Sourcepub fn raster_order_groups_supported(&self) -> bool
👎Deprecated: Use are_raster_order_groups_supported() instead
pub fn raster_order_groups_supported(&self) -> bool
Check if raster order groups are supported.
C++ equivalent: bool rasterOrderGroupsSupported() const
Sourcepub fn headless(&self) -> bool
👎Deprecated: Use is_headless() instead
pub fn headless(&self) -> bool
Check if the device is headless.
C++ equivalent: bool headless() const
Sourcepub fn low_power(&self) -> bool
👎Deprecated: Use is_low_power() instead
pub fn low_power(&self) -> bool
Check if the device is low-power.
C++ equivalent: bool lowPower() const
Sourcepub fn removable(&self) -> bool
👎Deprecated: Use is_removable() instead
pub fn removable(&self) -> bool
Check if the device is removable.
C++ equivalent: bool removable() const
Sourcepub fn depth24_stencil8_pixel_format_supported(&self) -> bool
👎Deprecated: Use is_depth24_stencil8_pixel_format_supported() instead
pub fn depth24_stencil8_pixel_format_supported(&self) -> bool
Check if depth24 stencil8 pixel format is supported.
C++ equivalent: bool depth24Stencil8PixelFormatSupported() const
Source§impl Device
impl Device
Sourcepub unsafe fn new_acceleration_structure_with_descriptor(
&self,
descriptor: *const c_void,
) -> Option<AccelerationStructure>
pub unsafe fn new_acceleration_structure_with_descriptor( &self, descriptor: *const c_void, ) -> Option<AccelerationStructure>
Create an acceleration structure with the given descriptor.
C++ equivalent: AccelerationStructure* newAccelerationStructure(const AccelerationStructureDescriptor*)
§Safety
The descriptor pointer must be valid.
Sourcepub fn new_acceleration_structure_with_size(
&self,
size: UInteger,
) -> Option<AccelerationStructure>
pub fn new_acceleration_structure_with_size( &self, size: UInteger, ) -> Option<AccelerationStructure>
Create an acceleration structure with the given size.
C++ equivalent: AccelerationStructure* newAccelerationStructure(NS::UInteger size)
Sourcepub unsafe fn acceleration_structure_sizes_with_descriptor(
&self,
descriptor: *const c_void,
) -> AccelerationStructureSizes
pub unsafe fn acceleration_structure_sizes_with_descriptor( &self, descriptor: *const c_void, ) -> AccelerationStructureSizes
Get the sizes needed for building an acceleration structure.
C++ equivalent: AccelerationStructureSizes accelerationStructureSizes(const AccelerationStructureDescriptor*)
§Safety
The descriptor pointer must be valid.
Source§impl Device
impl Device
Sourcepub fn new_binary_archive(
&self,
descriptor: &BinaryArchiveDescriptor,
) -> Result<BinaryArchive, Error>
pub fn new_binary_archive( &self, descriptor: &BinaryArchiveDescriptor, ) -> Result<BinaryArchive, Error>
Create a new binary archive.
C++ equivalent: BinaryArchive* newBinaryArchive(const MTL::BinaryArchiveDescriptor*, NS::Error**)
Source§impl Device
impl Device
Sourcepub fn new_buffer(
&self,
length: UInteger,
options: ResourceOptions,
) -> Option<Buffer>
pub fn new_buffer( &self, length: UInteger, options: ResourceOptions, ) -> Option<Buffer>
Create a new buffer with the specified length and options.
C++ equivalent: Buffer* newBuffer(NS::UInteger length, MTL::ResourceOptions options)
Sourcepub fn new_buffer_with_bytes(
&self,
bytes: &[u8],
options: ResourceOptions,
) -> Option<Buffer>
pub fn new_buffer_with_bytes( &self, bytes: &[u8], options: ResourceOptions, ) -> Option<Buffer>
Create a new buffer initialized with the specified data.
C++ equivalent: Buffer* newBuffer(const void* pointer, NS::UInteger length, MTL::ResourceOptions options)
Sourcepub unsafe fn new_buffer_with_bytes_ptr(
&self,
pointer: *const c_void,
length: UInteger,
options: ResourceOptions,
) -> Option<Buffer>
pub unsafe fn new_buffer_with_bytes_ptr( &self, pointer: *const c_void, length: UInteger, options: ResourceOptions, ) -> Option<Buffer>
Create a new buffer initialized with the specified data (raw pointer version).
C++ equivalent: Buffer* newBuffer(const void* pointer, NS::UInteger length, MTL::ResourceOptions options)
§Safety
The pointer must be valid for length bytes.
Sourcepub unsafe fn new_buffer_with_bytes_no_copy<F>(
&self,
pointer: *mut c_void,
length: UInteger,
options: ResourceOptions,
deallocator: F,
) -> Option<Buffer>
pub unsafe fn new_buffer_with_bytes_no_copy<F>( &self, pointer: *mut c_void, length: UInteger, options: ResourceOptions, deallocator: F, ) -> Option<Buffer>
Create a new buffer that wraps existing memory without copying.
The deallocator block will be called when the buffer is deallocated.
C++ equivalent: Buffer* newBuffer(void* pointer, NS::UInteger length, MTL::ResourceOptions options, void (^)(void*, NS::UInteger))
§Safety
- The pointer must remain valid until the deallocator is called.
- The pointer must be page-aligned.
Source§impl Device
impl Device
Sourcepub fn new_command_queue(&self) -> Option<CommandQueue>
pub fn new_command_queue(&self) -> Option<CommandQueue>
Create a new command queue.
C++ equivalent: CommandQueue* newCommandQueue()
Sourcepub fn new_command_queue_with_max_command_buffer_count(
&self,
max_command_buffer_count: UInteger,
) -> Option<CommandQueue>
pub fn new_command_queue_with_max_command_buffer_count( &self, max_command_buffer_count: UInteger, ) -> Option<CommandQueue>
Create a new command queue with a maximum command buffer count.
C++ equivalent: CommandQueue* newCommandQueue(NS::UInteger maxCommandBufferCount)
Sourcepub unsafe fn new_command_queue_with_descriptor(
&self,
descriptor: *const c_void,
) -> Option<CommandQueue>
pub unsafe fn new_command_queue_with_descriptor( &self, descriptor: *const c_void, ) -> Option<CommandQueue>
Create a new command queue with a descriptor.
C++ equivalent: CommandQueue* newCommandQueue(const CommandQueueDescriptor*)
§Safety
The descriptor pointer must be valid.
Source§impl Device
impl Device
Sourcepub fn new_depth_stencil_state(
&self,
descriptor: &DepthStencilDescriptor,
) -> Option<DepthStencilState>
pub fn new_depth_stencil_state( &self, descriptor: &DepthStencilDescriptor, ) -> Option<DepthStencilState>
Create a new depth/stencil state with the specified descriptor.
C++ equivalent: DepthStencilState* newDepthStencilState(const DepthStencilDescriptor*)
Sourcepub unsafe fn new_depth_stencil_state_with_ptr(
&self,
descriptor: *const c_void,
) -> Option<DepthStencilState>
pub unsafe fn new_depth_stencil_state_with_ptr( &self, descriptor: *const c_void, ) -> Option<DepthStencilState>
Create a new depth/stencil state with a raw descriptor pointer.
C++ equivalent: DepthStencilState* newDepthStencilState(const DepthStencilDescriptor*)
§Safety
The descriptor pointer must be valid.
Source§impl Device
impl Device
Create a new shared event.
C++ equivalent: SharedEvent* newSharedEvent()
Create a shared event from a handle.
C++ equivalent: SharedEvent* newSharedEvent(const SharedEventHandle*)
Source§impl Device
impl Device
Sourcepub fn new_heap(&self, descriptor: &HeapDescriptor) -> Option<Heap>
pub fn new_heap(&self, descriptor: &HeapDescriptor) -> Option<Heap>
Create a new heap with the specified descriptor.
C++ equivalent: Heap* newHeap(const HeapDescriptor*)
Sourcepub fn new_heap_validated(
&self,
descriptor: &HeapDescriptor,
) -> Result<Heap, ValidationError>
pub fn new_heap_validated( &self, descriptor: &HeapDescriptor, ) -> Result<Heap, ValidationError>
Create a heap with validation.
This safe method validates the descriptor before calling Metal APIs:
- Ensures heap size is > 0
§Example
let desc = HeapDescriptor::new().unwrap();
desc.set_size(1024 * 1024); // 1 MB
desc.set_storage_mode(StorageMode::PRIVATE);
match device.new_heap_validated(&desc) {
Ok(heap) => { /* use heap */ }
Err(ValidationError::InvalidHeapSize) => { /* handle error */ }
Err(e) => { /* handle other errors */ }
}Source§impl Device
impl Device
Sourcepub fn new_indirect_command_buffer(
&self,
descriptor: &IndirectCommandBufferDescriptor,
max_count: UInteger,
options: ResourceOptions,
) -> Option<IndirectCommandBuffer>
pub fn new_indirect_command_buffer( &self, descriptor: &IndirectCommandBufferDescriptor, max_count: UInteger, options: ResourceOptions, ) -> Option<IndirectCommandBuffer>
Create a new indirect command buffer.
C++ equivalent: IndirectCommandBuffer* newIndirectCommandBuffer(const IndirectCommandBufferDescriptor*, NS::UInteger, ResourceOptions)
Sourcepub fn new_rasterization_rate_map(
&self,
descriptor: &RasterizationRateMapDescriptor,
) -> Option<RasterizationRateMap>
pub fn new_rasterization_rate_map( &self, descriptor: &RasterizationRateMapDescriptor, ) -> Option<RasterizationRateMap>
Create a new rasterization rate map.
C++ equivalent: RasterizationRateMap* newRasterizationRateMap(const RasterizationRateMapDescriptor*)
Sourcepub fn new_counter_sample_buffer(
&self,
descriptor: &CounterSampleBufferDescriptor,
) -> Result<CounterSampleBuffer, Error>
pub fn new_counter_sample_buffer( &self, descriptor: &CounterSampleBufferDescriptor, ) -> Result<CounterSampleBuffer, Error>
Create a new counter sample buffer.
C++ equivalent: CounterSampleBuffer* newCounterSampleBuffer(const CounterSampleBufferDescriptor*, NS::Error**)
Sourcepub fn counter_sets_raw(&self) -> *mut c_void
pub fn counter_sets_raw(&self) -> *mut c_void
Get the available counter sets for this device.
Returns a raw pointer to an NSArray of CounterSet objects.
C++ equivalent: NS::Array* counterSets() const
Sourcepub fn counter_set_count(&self) -> UInteger
pub fn counter_set_count(&self) -> UInteger
Get the number of counter sets available.
Sourcepub fn counter_set_at_index(&self, index: UInteger) -> Option<CounterSet>
pub fn counter_set_at_index(&self, index: UInteger) -> Option<CounterSet>
Get a counter set at the specified index.
Sourcepub unsafe fn new_argument_encoder_with_arguments(
&self,
arguments: *const c_void,
) -> Option<ArgumentEncoder>
pub unsafe fn new_argument_encoder_with_arguments( &self, arguments: *const c_void, ) -> Option<ArgumentEncoder>
Create a new argument encoder from an array of arguments.
C++ equivalent: ArgumentEncoder* newArgumentEncoder(const NS::Array* arguments)
§Safety
The arguments pointer must be a valid NSArray of Argument objects.
Sourcepub fn new_argument_encoder_with_buffer_binding(
&self,
buffer_binding: &BufferBinding,
) -> Option<ArgumentEncoder>
pub fn new_argument_encoder_with_buffer_binding( &self, buffer_binding: &BufferBinding, ) -> Option<ArgumentEncoder>
Create a new argument encoder from a buffer binding.
C++ equivalent: ArgumentEncoder* newArgumentEncoder(const BufferBinding*)
Sourcepub fn new_log_state(
&self,
descriptor: &LogStateDescriptor,
) -> Result<LogState, Error>
pub fn new_log_state( &self, descriptor: &LogStateDescriptor, ) -> Result<LogState, Error>
Create a new log state.
C++ equivalent: LogState* newLogState(const LogStateDescriptor*, NS::Error**)
Sourcepub fn new_texture_view_pool(
&self,
descriptor: &ResourceViewPoolDescriptor,
) -> Result<TextureViewPool, Error>
pub fn new_texture_view_pool( &self, descriptor: &ResourceViewPoolDescriptor, ) -> Result<TextureViewPool, Error>
Create a new texture view pool.
C++ equivalent: TextureViewPool* newTextureViewPool(const ResourceViewPoolDescriptor*, NS::Error**)
Sourcepub fn new_tensor(&self, descriptor: &TensorDescriptor) -> Result<Tensor, Error>
pub fn new_tensor(&self, descriptor: &TensorDescriptor) -> Result<Tensor, Error>
Create a new tensor.
C++ equivalent: Tensor* newTensor(const TensorDescriptor*, NS::Error**)
Source§impl Device
impl Device
Sourcepub fn new_io_command_queue(
&self,
descriptor: &IOCommandQueueDescriptor,
) -> Result<IOCommandQueue, Error>
pub fn new_io_command_queue( &self, descriptor: &IOCommandQueueDescriptor, ) -> Result<IOCommandQueue, Error>
Create a new IO command queue.
C++ equivalent: IOCommandQueue* newIOCommandQueue(const IOCommandQueueDescriptor*, NS::Error**)
Sourcepub fn new_io_file_handle(&self, url: &Url) -> Result<IOFileHandle, Error>
pub fn new_io_file_handle(&self, url: &Url) -> Result<IOFileHandle, Error>
Create a new IO file handle.
C++ equivalent: IOFileHandle* newIOFileHandle(const NS::URL*, NS::Error**)
Sourcepub fn new_io_file_handle_with_compression(
&self,
url: &Url,
compression_method: IOCompressionMethod,
) -> Result<IOFileHandle, Error>
pub fn new_io_file_handle_with_compression( &self, url: &Url, compression_method: IOCompressionMethod, ) -> Result<IOFileHandle, Error>
Create a new IO file handle with compression.
C++ equivalent: IOFileHandle* newIOFileHandle(const NS::URL*, IOCompressionMethod, NS::Error**)
Sourcepub fn new_io_handle(&self, url: &Url) -> Result<IOFileHandle, Error>
👎Deprecated: Use new_io_file_handle instead
pub fn new_io_handle(&self, url: &Url) -> Result<IOFileHandle, Error>
Create a new IO handle (deprecated, use new_io_file_handle).
C++ equivalent: IOFileHandle* newIOHandle(const NS::URL*, NS::Error**)
Sourcepub fn new_io_handle_with_compression(
&self,
url: &Url,
compression_method: IOCompressionMethod,
) -> Result<IOFileHandle, Error>
👎Deprecated: Use new_io_file_handle_with_compression instead
pub fn new_io_handle_with_compression( &self, url: &Url, compression_method: IOCompressionMethod, ) -> Result<IOFileHandle, Error>
Create a new IO handle with compression (deprecated, use new_io_file_handle_with_compression).
C++ equivalent: IOFileHandle* newIOHandle(const NS::URL*, IOCompressionMethod, NS::Error**)
Source§impl Device
impl Device
Sourcepub fn new_default_library(&self) -> Option<Library>
pub fn new_default_library(&self) -> Option<Library>
Create the default library from the app’s main bundle.
C++ equivalent: Library* newDefaultLibrary()
Sourcepub unsafe fn new_default_library_with_bundle(
&self,
bundle: *const c_void,
) -> Result<Library, Error>
pub unsafe fn new_default_library_with_bundle( &self, bundle: *const c_void, ) -> Result<Library, Error>
Create the default library from a bundle.
C++ equivalent: Library* newDefaultLibrary(NS::Bundle*, NS::Error**)
§Safety
The bundle pointer must be valid.
Sourcepub fn new_library_with_source(
&self,
source: &str,
options: Option<&CompileOptions>,
) -> Result<Library, Error>
pub fn new_library_with_source( &self, source: &str, options: Option<&CompileOptions>, ) -> Result<Library, Error>
Create a library from source code.
C++ equivalent: Library* newLibrary(const NS::String* source, const CompileOptions* options, NS::Error** error)
Sourcepub unsafe fn new_library_with_data(
&self,
data: *const c_void,
) -> Result<Library, Error>
pub unsafe fn new_library_with_data( &self, data: *const c_void, ) -> Result<Library, Error>
Create a library from pre-compiled binary data.
C++ equivalent: Library* newLibrary(dispatch_data_t data, NS::Error** error)
§Safety
The data pointer must be valid dispatch_data_t.
Sourcepub unsafe fn new_library_with_url(
&self,
url: *const c_void,
) -> Result<Library, Error>
pub unsafe fn new_library_with_url( &self, url: *const c_void, ) -> Result<Library, Error>
Create a library from a file URL.
C++ equivalent: Library* newLibrary(const NS::URL* url, NS::Error** error)
§Safety
The URL pointer must be valid.
Sourcepub unsafe fn new_library_with_stitched_descriptor(
&self,
descriptor: *const c_void,
) -> Result<Library, Error>
pub unsafe fn new_library_with_stitched_descriptor( &self, descriptor: *const c_void, ) -> Result<Library, Error>
Create a library from a stitched library descriptor.
C++ equivalent: Library* newLibrary(const StitchedLibraryDescriptor*, NS::Error**)
§Safety
The descriptor pointer must be valid.
Sourcepub fn new_library_with_source_async<F>(
&self,
source: &str,
options: Option<&CompileOptions>,
completion_handler: F,
)
pub fn new_library_with_source_async<F>( &self, source: &str, options: Option<&CompileOptions>, completion_handler: F, )
Create a library from source code asynchronously.
C++ equivalent: void newLibrary(const NS::String* source, const CompileOptions* options, NewLibraryCompletionHandler)
The completion handler is called with the library and any error that occurred.
Sourcepub unsafe fn new_library_with_stitched_descriptor_async<F>(
&self,
descriptor: *const c_void,
completion_handler: F,
)
pub unsafe fn new_library_with_stitched_descriptor_async<F>( &self, descriptor: *const c_void, completion_handler: F, )
Create a library from a stitched library descriptor asynchronously.
C++ equivalent: void newLibrary(const StitchedLibraryDescriptor*, NewLibraryCompletionHandler)
§Safety
The descriptor pointer must be valid.
Source§impl Device
impl Device
Sourcepub fn new_command_allocator(&self) -> Option<CommandAllocator>
pub fn new_command_allocator(&self) -> Option<CommandAllocator>
Create a new MTL4 command allocator with default settings.
C++ equivalent: MTL4::CommandAllocator* newCommandAllocator()
Sourcepub fn new_command_allocator_with_descriptor(
&self,
descriptor: &CommandAllocatorDescriptor,
) -> Result<CommandAllocator, Error>
pub fn new_command_allocator_with_descriptor( &self, descriptor: &CommandAllocatorDescriptor, ) -> Result<CommandAllocator, Error>
Create a new MTL4 command allocator with a descriptor.
C++ equivalent: MTL4::CommandAllocator* newCommandAllocator(const MTL4::CommandAllocatorDescriptor*, NS::Error**)
Sourcepub fn new_mtl4_command_queue(&self) -> Option<CommandQueue>
pub fn new_mtl4_command_queue(&self) -> Option<CommandQueue>
Create a new MTL4 command queue with default settings.
C++ equivalent: MTL4::CommandQueue* newMTL4CommandQueue()
Sourcepub fn new_mtl4_command_queue_with_descriptor(
&self,
descriptor: &CommandQueueDescriptor,
) -> Result<CommandQueue, Error>
pub fn new_mtl4_command_queue_with_descriptor( &self, descriptor: &CommandQueueDescriptor, ) -> Result<CommandQueue, Error>
Create a new MTL4 command queue with a descriptor.
C++ equivalent: MTL4::CommandQueue* newMTL4CommandQueue(const MTL4::CommandQueueDescriptor*, NS::Error**)
Sourcepub fn new_argument_table(
&self,
descriptor: &ArgumentTableDescriptor,
) -> Result<ArgumentTable, Error>
pub fn new_argument_table( &self, descriptor: &ArgumentTableDescriptor, ) -> Result<ArgumentTable, Error>
Create a new MTL4 argument table.
C++ equivalent: MTL4::ArgumentTable* newArgumentTable(const MTL4::ArgumentTableDescriptor*, NS::Error**)
Sourcepub fn new_compiler(
&self,
descriptor: &CompilerDescriptor,
) -> Result<Compiler, Error>
pub fn new_compiler( &self, descriptor: &CompilerDescriptor, ) -> Result<Compiler, Error>
Create a new MTL4 compiler.
C++ equivalent: MTL4::Compiler* newCompiler(const MTL4::CompilerDescriptor*, NS::Error**)
Sourcepub fn new_counter_heap(
&self,
descriptor: &CounterHeapDescriptor,
) -> Result<CounterHeap, Error>
pub fn new_counter_heap( &self, descriptor: &CounterHeapDescriptor, ) -> Result<CounterHeap, Error>
Create a new MTL4 counter heap.
C++ equivalent: MTL4::CounterHeap* newCounterHeap(const MTL4::CounterHeapDescriptor*, NS::Error**)
Sourcepub fn size_of_counter_heap_entry(&self, heap_type: CounterHeapType) -> UInteger
pub fn size_of_counter_heap_entry(&self, heap_type: CounterHeapType) -> UInteger
Get the size of a counter heap entry.
C++ equivalent: NS::UInteger sizeOfCounterHeapEntry(MTL4::CounterHeapType type)
Sourcepub fn new_pipeline_data_set_serializer(
&self,
descriptor: &PipelineDataSetSerializerDescriptor,
) -> Option<PipelineDataSetSerializer>
pub fn new_pipeline_data_set_serializer( &self, descriptor: &PipelineDataSetSerializerDescriptor, ) -> Option<PipelineDataSetSerializer>
Create a new MTL4 pipeline data set serializer.
C++ equivalent: MTL4::PipelineDataSetSerializer* newPipelineDataSetSerializer(const MTL4::PipelineDataSetSerializerDescriptor*)
Sourcepub unsafe fn new_archive_with_url(
&self,
url: *const c_void,
) -> Result<Archive, Error>
pub unsafe fn new_archive_with_url( &self, url: *const c_void, ) -> Result<Archive, Error>
Create a new MTL4 archive from a URL.
C++ equivalent: MTL4::Archive* newArchive(const NS::URL*, NS::Error**)
§Safety
The url pointer must be a valid NS::URL object.
Sourcepub fn function_handle(&self, function: &Function) -> Option<FunctionHandle>
pub fn function_handle(&self, function: &Function) -> Option<FunctionHandle>
Get a function handle from a compiled function.
C++ equivalent: FunctionHandle* functionHandle(const MTL::Function*)
Sourcepub fn function_handle_with_binary_function(
&self,
function: &BinaryFunction,
) -> Option<FunctionHandle>
pub fn function_handle_with_binary_function( &self, function: &BinaryFunction, ) -> Option<FunctionHandle>
Get a function handle from a binary function.
C++ equivalent: FunctionHandle* functionHandle(const MTL4::BinaryFunction*)
Source§impl Device
impl Device
Sourcepub unsafe fn new_render_pipeline_state(
&self,
descriptor: *const c_void,
) -> Result<RenderPipelineState, Error>
pub unsafe fn new_render_pipeline_state( &self, descriptor: *const c_void, ) -> Result<RenderPipelineState, Error>
Create a render pipeline state from a descriptor.
C++ equivalent: RenderPipelineState* newRenderPipelineState(const RenderPipelineDescriptor*, NS::Error**)
§Safety
The descriptor pointer must be valid.
Sourcepub fn new_render_pipeline_state_with_descriptor(
&self,
descriptor: &RenderPipelineDescriptor,
) -> Result<RenderPipelineState, ValidationError>
pub fn new_render_pipeline_state_with_descriptor( &self, descriptor: &RenderPipelineDescriptor, ) -> Result<RenderPipelineState, ValidationError>
Create a render pipeline state with validation.
This safe method validates the descriptor before calling Metal APIs:
- Ensures a vertex function is set (required)
- Validates raster sample count is supported by the device
Use this method instead of new_render_pipeline_state to avoid process
aborts from Metal’s validation layer.
§Example
let desc = RenderPipelineDescriptor::new().unwrap();
desc.set_vertex_function(Some(&vertex_fn));
desc.set_fragment_function(Some(&fragment_fn));
match device.new_render_pipeline_state_with_descriptor(&desc) {
Ok(pipeline) => { /* use pipeline */ }
Err(ValidationError::MissingVertexFunction) => { /* handle error */ }
Err(e) => { /* handle other errors */ }
}Sourcepub unsafe fn new_render_pipeline_state_with_reflection(
&self,
descriptor: *const c_void,
options: PipelineOption,
reflection: *mut *mut c_void,
) -> Result<RenderPipelineState, Error>
pub unsafe fn new_render_pipeline_state_with_reflection( &self, descriptor: *const c_void, options: PipelineOption, reflection: *mut *mut c_void, ) -> Result<RenderPipelineState, Error>
Create a render pipeline state with options.
C++ equivalent: RenderPipelineState* newRenderPipelineState(const RenderPipelineDescriptor*, PipelineOption, RenderPipelineReflection**, NS::Error**)
§Safety
The descriptor and reflection pointers must be valid.
Sourcepub fn new_compute_pipeline_state_with_function(
&self,
function: &Function,
) -> Result<ComputePipelineState, Error>
pub fn new_compute_pipeline_state_with_function( &self, function: &Function, ) -> Result<ComputePipelineState, Error>
Create a compute pipeline state from a function.
C++ equivalent: ComputePipelineState* newComputePipelineState(const Function*, NS::Error**)
Sourcepub unsafe fn new_compute_pipeline_state_with_function_and_reflection(
&self,
function: &Function,
options: PipelineOption,
reflection: *mut *mut c_void,
) -> Result<ComputePipelineState, Error>
pub unsafe fn new_compute_pipeline_state_with_function_and_reflection( &self, function: &Function, options: PipelineOption, reflection: *mut *mut c_void, ) -> Result<ComputePipelineState, Error>
Create a compute pipeline state with options.
C++ equivalent: ComputePipelineState* newComputePipelineState(const Function*, PipelineOption, ComputePipelineReflection**, NS::Error**)
§Safety
The reflection pointer must be valid if not null.
Sourcepub fn new_compute_pipeline_state_validated(
&self,
descriptor: &ComputePipelineDescriptor,
) -> Result<ComputePipelineState, ValidationError>
pub fn new_compute_pipeline_state_validated( &self, descriptor: &ComputePipelineDescriptor, ) -> Result<ComputePipelineState, ValidationError>
Create a compute pipeline state with validation.
This safe method validates the descriptor before calling Metal APIs:
- Ensures a compute function is set (required)
Use this method instead of the unsafe new_compute_pipeline_state_with_descriptor
to avoid process aborts from Metal’s validation layer.
§Example
let desc = ComputePipelineDescriptor::new().unwrap();
desc.set_compute_function(Some(&compute_fn));
match device.new_compute_pipeline_state_validated(&desc) {
Ok(pipeline) => { /* use pipeline */ }
Err(ValidationError::MissingComputeFunction) => { /* handle error */ }
Err(e) => { /* handle other errors */ }
}Sourcepub unsafe fn new_compute_pipeline_state_with_descriptor(
&self,
descriptor: *const c_void,
options: PipelineOption,
reflection: *mut *mut c_void,
) -> Result<ComputePipelineState, Error>
pub unsafe fn new_compute_pipeline_state_with_descriptor( &self, descriptor: *const c_void, options: PipelineOption, reflection: *mut *mut c_void, ) -> Result<ComputePipelineState, Error>
Create a compute pipeline state from a descriptor.
C++ equivalent: ComputePipelineState* newComputePipelineState(const ComputePipelineDescriptor*, PipelineOption, ComputePipelineReflection**, NS::Error**)
§Safety
The descriptor and reflection pointers must be valid.
Sourcepub fn new_render_pipeline_state_async<F>(
&self,
descriptor: &RenderPipelineDescriptor,
completion_handler: F,
)
pub fn new_render_pipeline_state_async<F>( &self, descriptor: &RenderPipelineDescriptor, completion_handler: F, )
Create a render pipeline state asynchronously.
C++ equivalent: void newRenderPipelineState(const RenderPipelineDescriptor*, NewRenderPipelineStateCompletionHandler)
The completion handler is called with the pipeline state and any error that occurred.
Sourcepub fn new_render_pipeline_state_with_reflection_async<F>(
&self,
descriptor: &RenderPipelineDescriptor,
options: PipelineOption,
completion_handler: F,
)where
F: Fn(Option<RenderPipelineState>, Option<RenderPipelineReflection>, Option<Error>) + Send + 'static,
pub fn new_render_pipeline_state_with_reflection_async<F>(
&self,
descriptor: &RenderPipelineDescriptor,
options: PipelineOption,
completion_handler: F,
)where
F: Fn(Option<RenderPipelineState>, Option<RenderPipelineReflection>, Option<Error>) + Send + 'static,
Create a render pipeline state with reflection asynchronously.
C++ equivalent: void newRenderPipelineState(const RenderPipelineDescriptor*, PipelineOption, NewRenderPipelineStateWithReflectionCompletionHandler)
The completion handler is called with the pipeline state, reflection data, and any error.
Sourcepub fn new_tile_render_pipeline_state_with_reflection_async<F>(
&self,
descriptor: &TileRenderPipelineDescriptor,
options: PipelineOption,
completion_handler: F,
)where
F: Fn(Option<RenderPipelineState>, Option<RenderPipelineReflection>, Option<Error>) + Send + 'static,
pub fn new_tile_render_pipeline_state_with_reflection_async<F>(
&self,
descriptor: &TileRenderPipelineDescriptor,
options: PipelineOption,
completion_handler: F,
)where
F: Fn(Option<RenderPipelineState>, Option<RenderPipelineReflection>, Option<Error>) + Send + 'static,
Create a tile render pipeline state with reflection asynchronously.
C++ equivalent: void newRenderPipelineState(const TileRenderPipelineDescriptor*, PipelineOption, NewRenderPipelineStateWithReflectionCompletionHandler)
Sourcepub fn new_mesh_render_pipeline_state_with_reflection_async<F>(
&self,
descriptor: &MeshRenderPipelineDescriptor,
options: PipelineOption,
completion_handler: F,
)where
F: Fn(Option<RenderPipelineState>, Option<RenderPipelineReflection>, Option<Error>) + Send + 'static,
pub fn new_mesh_render_pipeline_state_with_reflection_async<F>(
&self,
descriptor: &MeshRenderPipelineDescriptor,
options: PipelineOption,
completion_handler: F,
)where
F: Fn(Option<RenderPipelineState>, Option<RenderPipelineReflection>, Option<Error>) + Send + 'static,
Create a mesh render pipeline state with reflection asynchronously.
C++ equivalent: void newRenderPipelineState(const MeshRenderPipelineDescriptor*, PipelineOption, NewRenderPipelineStateWithReflectionCompletionHandler)
Sourcepub fn new_compute_pipeline_state_with_function_async<F>(
&self,
function: &Function,
completion_handler: F,
)
pub fn new_compute_pipeline_state_with_function_async<F>( &self, function: &Function, completion_handler: F, )
Create a compute pipeline state from a function asynchronously.
C++ equivalent: void newComputePipelineState(const Function*, NewComputePipelineStateCompletionHandler)
Sourcepub fn new_compute_pipeline_state_with_function_and_reflection_async<F>(
&self,
function: &Function,
options: PipelineOption,
completion_handler: F,
)where
F: Fn(Option<ComputePipelineState>, Option<ComputePipelineReflection>, Option<Error>) + Send + 'static,
pub fn new_compute_pipeline_state_with_function_and_reflection_async<F>(
&self,
function: &Function,
options: PipelineOption,
completion_handler: F,
)where
F: Fn(Option<ComputePipelineState>, Option<ComputePipelineReflection>, Option<Error>) + Send + 'static,
Create a compute pipeline state with reflection asynchronously.
C++ equivalent: void newComputePipelineState(const Function*, PipelineOption, NewComputePipelineStateWithReflectionCompletionHandler)
Sourcepub fn new_compute_pipeline_state_with_descriptor_async<F>(
&self,
descriptor: &ComputePipelineDescriptor,
options: PipelineOption,
completion_handler: F,
)where
F: Fn(Option<ComputePipelineState>, Option<ComputePipelineReflection>, Option<Error>) + Send + 'static,
pub fn new_compute_pipeline_state_with_descriptor_async<F>(
&self,
descriptor: &ComputePipelineDescriptor,
options: PipelineOption,
completion_handler: F,
)where
F: Fn(Option<ComputePipelineState>, Option<ComputePipelineReflection>, Option<Error>) + Send + 'static,
Create a compute pipeline state from a descriptor asynchronously.
C++ equivalent: void newComputePipelineState(const ComputePipelineDescriptor*, PipelineOption, NewComputePipelineStateWithReflectionCompletionHandler)
Source§impl Device
impl Device
Sourcepub fn new_residency_set(
&self,
descriptor: &ResidencySetDescriptor,
) -> Result<ResidencySet, Error>
pub fn new_residency_set( &self, descriptor: &ResidencySetDescriptor, ) -> Result<ResidencySet, Error>
Create a new residency set.
C++ equivalent: ResidencySet* newResidencySet(const MTL::ResidencySetDescriptor*, NS::Error**)
Source§impl Device
impl Device
Sourcepub fn new_sampler_state(
&self,
descriptor: &SamplerDescriptor,
) -> Option<SamplerState>
pub fn new_sampler_state( &self, descriptor: &SamplerDescriptor, ) -> Option<SamplerState>
Create a new sampler state with the specified descriptor.
C++ equivalent: SamplerState* newSamplerState(const SamplerDescriptor*)
Sourcepub fn new_sampler_state_validated(
&self,
descriptor: &SamplerDescriptor,
) -> Result<SamplerState, ValidationError>
pub fn new_sampler_state_validated( &self, descriptor: &SamplerDescriptor, ) -> Result<SamplerState, ValidationError>
Create a sampler state with validation.
This safe method validates the descriptor before calling Metal APIs:
- Ensures LOD min clamp is <= LOD max clamp
- Ensures max anisotropy is >= 1 and a power of 2
§Example
let desc = SamplerDescriptor::new().unwrap();
desc.set_min_filter(SamplerMinMagFilter::LINEAR);
desc.set_mag_filter(SamplerMinMagFilter::LINEAR);
match device.new_sampler_state_validated(&desc) {
Ok(sampler) => { /* use sampler */ }
Err(ValidationError::InvalidLodRange { .. }) => { /* handle error */ }
Err(e) => { /* handle other errors */ }
}Sourcepub unsafe fn new_sampler_state_with_ptr(
&self,
descriptor: *const c_void,
) -> Option<SamplerState>
pub unsafe fn new_sampler_state_with_ptr( &self, descriptor: *const c_void, ) -> Option<SamplerState>
Create a new sampler state with a raw descriptor pointer.
C++ equivalent: SamplerState* newSamplerState(const SamplerDescriptor*)
§Safety
The descriptor pointer must be valid.
Source§impl Device
impl Device
Sourcepub unsafe fn new_texture(&self, descriptor: *const c_void) -> Option<Texture>
pub unsafe fn new_texture(&self, descriptor: *const c_void) -> Option<Texture>
Create a new texture with the specified descriptor.
C++ equivalent: Texture* newTexture(const TextureDescriptor*)
§Safety
The descriptor pointer must be valid.
Sourcepub fn new_texture_with_descriptor(
&self,
descriptor: &TextureDescriptor,
) -> Result<Texture, ValidationError>
pub fn new_texture_with_descriptor( &self, descriptor: &TextureDescriptor, ) -> Result<Texture, ValidationError>
Create a texture with validation.
This safe method validates the descriptor before calling Metal APIs:
- Ensures width and height are > 0
- Ensures depth is > 0 for 3D textures
- Ensures array length is > 0 for array textures
- Validates mipmap count is within allowed range
- Validates sample count is supported by the device
Use this method instead of new_texture to avoid process aborts
from Metal’s validation layer.
§Example
let desc = TextureDescriptor::texture_2d_descriptor(
PixelFormat::BGRA8_UNORM, 256, 256, false
).unwrap();
match device.new_texture_with_descriptor(&desc) {
Ok(texture) => { /* use texture */ }
Err(ValidationError::InvalidTextureDimensions { .. }) => { /* handle error */ }
Err(e) => { /* handle other errors */ }
}Sourcepub unsafe fn new_texture_with_iosurface(
&self,
descriptor: *const c_void,
iosurface: *const c_void,
plane: UInteger,
) -> Option<Texture>
pub unsafe fn new_texture_with_iosurface( &self, descriptor: *const c_void, iosurface: *const c_void, plane: UInteger, ) -> Option<Texture>
Create a new texture backed by an IOSurface.
C++ equivalent: Texture* newTexture(const TextureDescriptor*, IOSurfaceRef, NS::UInteger plane)
§Safety
The descriptor and IOSurface pointers must be valid.
Create a shared texture with another device.
C++ equivalent: Texture* newSharedTexture(const SharedTextureHandle*)
§Safety
The handle pointer must be valid.
Create a shared texture with the specified descriptor.
C++ equivalent: Texture* newSharedTexture(const TextureDescriptor*)
§Safety
The descriptor pointer must be valid.