Skip to main content

Device

Struct Device 

Source
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

Source

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)

Source

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)

Source

pub fn are_barycentric_coords_supported(&self) -> bool

Check if barycentric coordinates are supported.

C++ equivalent: bool areBarycentricCoordsSupported() const

Source

pub fn are_programmable_sample_positions_supported(&self) -> bool

Check if programmable sample positions are supported.

C++ equivalent: bool areProgrammableSamplePositionsSupported() const

Source

pub fn are_raster_order_groups_supported(&self) -> bool

Check if raster order groups are supported.

C++ equivalent: bool areRasterOrderGroupsSupported() const

Source

pub fn supports_32bit_float_filtering(&self) -> bool

Check if 32-bit float filtering is supported.

C++ equivalent: bool supports32BitFloatFiltering() const

Source

pub fn supports_32bit_msaa(&self) -> bool

Check if 32-bit MSAA is supported.

C++ equivalent: bool supports32BitMSAA() const

Source

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)

Source

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)

Source

pub fn supports_query_texture_lod(&self) -> bool

Check if query texture LOD is supported.

C++ equivalent: bool supportsQueryTextureLOD() const

Source

pub fn supports_pull_model_interpolation(&self) -> bool

Check if pull model interpolation is supported.

C++ equivalent: bool supportsPullModelInterpolation() const

Source

pub fn supports_shader_barycentric_coordinates(&self) -> bool

Check if shader barycentric coordinates are supported.

C++ equivalent: bool supportsShaderBarycentricCoordinates() const

Source

pub fn supports_bc_texture_compression(&self) -> bool

Check if BC texture compression is supported.

C++ equivalent: bool supportsBCTextureCompression() const

Source

pub fn is_depth24_stencil8_pixel_format_supported(&self) -> bool

Check if depth24 stencil8 pixel format is supported.

C++ equivalent: bool isDepth24Stencil8PixelFormatSupported() const

Source

pub fn supports_raytracing(&self) -> bool

Check if ray tracing is supported.

C++ equivalent: bool supportsRaytracing() const

Source

pub fn supports_raytracing_from_render(&self) -> bool

Check if ray tracing from render is supported.

C++ equivalent: bool supportsRaytracingFromRender() const

Source

pub fn supports_primitive_motion_blur(&self) -> bool

Check if primitive motion blur is supported.

C++ equivalent: bool supportsPrimitiveMotionBlur() const

Source

pub fn supports_function_pointers(&self) -> bool

Check if function pointers are supported.

C++ equivalent: bool supportsFunctionPointers() const

Source

pub fn supports_function_pointers_from_render(&self) -> bool

Check if function pointers from render are supported.

C++ equivalent: bool supportsFunctionPointersFromRender() const

Source

pub fn supports_dynamic_libraries(&self) -> bool

Check if dynamic libraries are supported.

C++ equivalent: bool supportsDynamicLibraries() const

Source

pub fn supports_render_dynamic_libraries(&self) -> bool

Check if render dynamic libraries are supported.

C++ equivalent: bool supportsRenderDynamicLibraries() const

Source

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)

Source

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

Source

pub fn max_threads_per_threadgroup(&self) -> Size

Get the maximum threads per threadgroup.

C++ equivalent: Size maxThreadsPerThreadgroup() const

Source

pub fn max_threadgroup_memory_length(&self) -> UInteger

Get the maximum threadgroup memory length in bytes.

C++ equivalent: NS::UInteger maxThreadgroupMemoryLength() const

Source

pub fn max_buffer_length(&self) -> UInteger

Get the maximum buffer length in bytes.

C++ equivalent: NS::UInteger maxBufferLength() const

Source

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

Source

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)

Source

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)

Source

pub fn sparse_tile_size_in_bytes(&self) -> UInteger

Get the sparse tile size in bytes.

C++ equivalent: NS::UInteger sparseTileSizeInBytes() const

Source

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)

Source

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)

Source

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)

Source

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(...)

Source

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(...)

Source

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)

Source

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.

Source

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)

Source

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

Source

pub fn name(&self) -> &str

Get the device name.

C++ equivalent: NS::String* name() const

§Example
let device = device::system_default().unwrap();
println!("GPU: {}", device.name());
Source

pub fn architecture(&self) -> Option<Architecture>

Get the device architecture.

C++ equivalent: Architecture* architecture() const

Source

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

Source

pub fn location(&self) -> DeviceLocation

Get the device location.

C++ equivalent: DeviceLocation location() const

Source

pub fn location_number(&self) -> UInteger

Get the device location number.

C++ equivalent: NS::UInteger locationNumber() const

Source

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

Source

pub fn is_headless(&self) -> bool

Check if the device is headless (has no display attached).

C++ equivalent: bool isHeadless() const

Source

pub fn is_low_power(&self) -> bool

Check if the device is low-power.

C++ equivalent: bool isLowPower() const

Source

pub fn is_removable(&self) -> bool

Check if the device is removable.

C++ equivalent: bool isRemovable() const

Source

pub fn current_allocated_size(&self) -> UInteger

Get the current allocated memory size in bytes.

C++ equivalent: NS::UInteger currentAllocatedSize() const

Source

pub fn recommended_max_working_set_size(&self) -> u64

Get the recommended maximum working set size.

C++ equivalent: uint64_t recommendedMaxWorkingSetSize() const

Source

pub fn read_write_texture_support(&self) -> ReadWriteTextureTier

Get the read-write texture tier supported by this device.

C++ equivalent: ReadWriteTextureTier readWriteTextureSupport() const

Source

pub fn argument_buffers_support(&self) -> ArgumentBuffersTier

Get the argument buffers tier supported by this device.

C++ equivalent: ArgumentBuffersTier argumentBuffersSupport() const

Source

pub fn peer_group_id(&self) -> u64

Get the peer group ID for multi-GPU configurations.

C++ equivalent: uint64_t peerGroupID() const

Source

pub fn peer_index(&self) -> u32

Get the peer index within a multi-GPU configuration.

C++ equivalent: uint32_t peerIndex() const

Source

pub fn peer_count(&self) -> u32

Get the number of peer devices.

C++ equivalent: uint32_t peerCount() const

Source

pub fn max_transfer_rate(&self) -> u64

Get the maximum data transfer rate in bytes per second.

C++ equivalent: uint64_t maxTransferRate() const

Source

pub fn should_maximize_concurrent_compilation(&self) -> bool

Get whether to maximize concurrent compilation.

C++ equivalent: bool shouldMaximizeConcurrentCompilation() const

Source

pub fn set_should_maximize_concurrent_compilation(&self, value: bool)

Set whether to maximize concurrent compilation.

C++ equivalent: void setShouldMaximizeConcurrentCompilation(bool)

Source

pub fn maximum_concurrent_compilation_task_count(&self) -> UInteger

Get the maximum number of concurrent compilation tasks.

C++ equivalent: NS::UInteger maximumConcurrentCompilationTaskCount() const

Source

pub fn query_timestamp_frequency(&self) -> u64

Get the GPU timestamp frequency in Hz.

C++ equivalent: uint64_t queryTimestampFrequency()

Source

pub fn sample_timestamps(&self) -> (u64, u64)

Sample CPU and GPU timestamps simultaneously.

C++ equivalent: void sampleTimestamps(MTL::Timestamp*, MTL::Timestamp*)

Source

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)

Source

pub fn barycentric_coords_supported(&self) -> bool

👎Deprecated: Use are_barycentric_coords_supported() instead

Check if barycentric coordinates are supported.

C++ equivalent: bool barycentricCoordsSupported() const

Source

pub fn programmable_sample_positions_supported(&self) -> bool

👎Deprecated: Use are_programmable_sample_positions_supported() instead

Check if programmable sample positions are supported.

C++ equivalent: bool programmableSamplePositionsSupported() const

Source

pub fn raster_order_groups_supported(&self) -> bool

👎Deprecated: Use are_raster_order_groups_supported() instead

Check if raster order groups are supported.

C++ equivalent: bool rasterOrderGroupsSupported() const

Source

pub fn headless(&self) -> bool

👎Deprecated: Use is_headless() instead

Check if the device is headless.

C++ equivalent: bool headless() const

Source

pub fn low_power(&self) -> bool

👎Deprecated: Use is_low_power() instead

Check if the device is low-power.

C++ equivalent: bool lowPower() const

Source

pub fn removable(&self) -> bool

👎Deprecated: Use is_removable() instead

Check if the device is removable.

C++ equivalent: bool removable() const

Source

pub fn depth24_stencil8_pixel_format_supported(&self) -> bool

👎Deprecated: Use is_depth24_stencil8_pixel_format_supported() instead

Check if depth24 stencil8 pixel format is supported.

C++ equivalent: bool depth24Stencil8PixelFormatSupported() const

Source§

impl Device

Source

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.

Source

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)

Source

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

Source

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

Source

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)

Source

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)

Source

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.

Source

pub unsafe fn new_buffer_with_bytes_no_copy<F>( &self, pointer: *mut c_void, length: UInteger, options: ResourceOptions, deallocator: F, ) -> Option<Buffer>
where F: Fn(*mut c_void, usize) + Send + 'static,

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

Source

pub fn new_command_queue(&self) -> Option<CommandQueue>

Create a new command queue.

C++ equivalent: CommandQueue* newCommandQueue()

Source

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)

Source

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

Source

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*)

Source

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

Source

pub fn new_event(&self) -> Option<Event>

Create a new event.

C++ equivalent: Event* newEvent()

Source

pub fn new_shared_event(&self) -> Option<SharedEvent>

Create a new shared event.

C++ equivalent: SharedEvent* newSharedEvent()

Source

pub fn new_shared_event_with_handle( &self, handle: &SharedEventHandle, ) -> Option<SharedEvent>

Create a shared event from a handle.

C++ equivalent: SharedEvent* newSharedEvent(const SharedEventHandle*)

Source

pub fn new_fence(&self) -> Option<Fence>

Create a new fence.

C++ equivalent: Fence* newFence()

Source§

impl Device

Source

pub fn new_heap(&self, descriptor: &HeapDescriptor) -> Option<Heap>

Create a new heap with the specified descriptor.

C++ equivalent: Heap* newHeap(const HeapDescriptor*)

Source

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

pub unsafe fn new_heap_with_ptr( &self, descriptor: *const c_void, ) -> Option<Heap>

Create a new heap with a raw descriptor pointer.

C++ equivalent: Heap* newHeap(const HeapDescriptor*)

§Safety

The descriptor pointer must be valid.

Source§

impl Device

Source

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)

Source

pub fn new_rasterization_rate_map( &self, descriptor: &RasterizationRateMapDescriptor, ) -> Option<RasterizationRateMap>

Create a new rasterization rate map.

C++ equivalent: RasterizationRateMap* newRasterizationRateMap(const RasterizationRateMapDescriptor*)

Source

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**)

Source

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

Source

pub fn counter_set_count(&self) -> UInteger

Get the number of counter sets available.

Source

pub fn counter_set_at_index(&self, index: UInteger) -> Option<CounterSet>

Get a counter set at the specified index.

Source

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.

Source

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*)

Source

pub fn new_log_state( &self, descriptor: &LogStateDescriptor, ) -> Result<LogState, Error>

Create a new log state.

C++ equivalent: LogState* newLogState(const LogStateDescriptor*, NS::Error**)

Source

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**)

Source

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

Source

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**)

Source

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**)

Source

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**)

Source

pub fn new_io_handle(&self, url: &Url) -> Result<IOFileHandle, Error>

👎Deprecated: Use new_io_file_handle instead

Create a new IO handle (deprecated, use new_io_file_handle).

C++ equivalent: IOFileHandle* newIOHandle(const NS::URL*, NS::Error**)

Source

pub fn new_io_handle_with_compression( &self, url: &Url, compression_method: IOCompressionMethod, ) -> Result<IOFileHandle, Error>

👎Deprecated: Use new_io_file_handle_with_compression instead

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

Source

pub fn new_default_library(&self) -> Option<Library>

Create the default library from the app’s main bundle.

C++ equivalent: Library* newDefaultLibrary()

Source

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.

Source

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)

Source

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.

Source

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.

Source

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.

Source

pub fn new_library_with_source_async<F>( &self, source: &str, options: Option<&CompileOptions>, completion_handler: F, )
where F: Fn(Option<Library>, Option<Error>) + Send + 'static,

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.

Source

pub unsafe fn new_library_with_stitched_descriptor_async<F>( &self, descriptor: *const c_void, completion_handler: F, )
where F: Fn(Option<Library>, Option<Error>) + Send + 'static,

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

Source

pub fn new_command_allocator(&self) -> Option<CommandAllocator>

Create a new MTL4 command allocator with default settings.

C++ equivalent: MTL4::CommandAllocator* newCommandAllocator()

Source

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**)

Source

pub fn new_mtl4_command_queue(&self) -> Option<CommandQueue>

Create a new MTL4 command queue with default settings.

C++ equivalent: MTL4::CommandQueue* newMTL4CommandQueue()

Source

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**)

Source

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**)

Source

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**)

Source

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**)

Source

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)

Source

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*)

Source

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.

Source

pub fn function_handle(&self, function: &Function) -> Option<FunctionHandle>

Get a function handle from a compiled function.

C++ equivalent: FunctionHandle* functionHandle(const MTL::Function*)

Source

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

Source

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.

Source

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 */ }
}
Source

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.

Source

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**)

Source

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.

Source

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 */ }
}
Source

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.

Source

pub fn new_render_pipeline_state_async<F>( &self, descriptor: &RenderPipelineDescriptor, completion_handler: F, )
where F: Fn(Option<RenderPipelineState>, Option<Error>) + Send + 'static,

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.

Source

pub fn new_render_pipeline_state_with_reflection_async<F>( &self, descriptor: &RenderPipelineDescriptor, options: PipelineOption, completion_handler: F, )

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.

Source

pub fn new_tile_render_pipeline_state_with_reflection_async<F>( &self, descriptor: &TileRenderPipelineDescriptor, options: PipelineOption, completion_handler: F, )

Create a tile render pipeline state with reflection asynchronously.

C++ equivalent: void newRenderPipelineState(const TileRenderPipelineDescriptor*, PipelineOption, NewRenderPipelineStateWithReflectionCompletionHandler)

Source

pub fn new_mesh_render_pipeline_state_with_reflection_async<F>( &self, descriptor: &MeshRenderPipelineDescriptor, options: PipelineOption, completion_handler: F, )

Create a mesh render pipeline state with reflection asynchronously.

C++ equivalent: void newRenderPipelineState(const MeshRenderPipelineDescriptor*, PipelineOption, NewRenderPipelineStateWithReflectionCompletionHandler)

Source

pub fn new_compute_pipeline_state_with_function_async<F>( &self, function: &Function, completion_handler: F, )
where F: Fn(Option<ComputePipelineState>, Option<Error>) + Send + 'static,

Create a compute pipeline state from a function asynchronously.

C++ equivalent: void newComputePipelineState(const Function*, NewComputePipelineStateCompletionHandler)

Source

pub fn new_compute_pipeline_state_with_function_and_reflection_async<F>( &self, function: &Function, options: PipelineOption, completion_handler: F, )

Create a compute pipeline state with reflection asynchronously.

C++ equivalent: void newComputePipelineState(const Function*, PipelineOption, NewComputePipelineStateWithReflectionCompletionHandler)

Source

pub fn new_compute_pipeline_state_with_descriptor_async<F>( &self, descriptor: &ComputePipelineDescriptor, options: PipelineOption, completion_handler: F, )

Create a compute pipeline state from a descriptor asynchronously.

C++ equivalent: void newComputePipelineState(const ComputePipelineDescriptor*, PipelineOption, NewComputePipelineStateWithReflectionCompletionHandler)

Source§

impl Device

Source

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

Source

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*)

Source

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 */ }
}
Source

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

Source

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.

Source

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 */ }
}
Source

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.

Source

pub unsafe fn new_shared_texture_with_handle( &self, handle: *const c_void, ) -> Option<Texture>

Create a shared texture with another device.

C++ equivalent: Texture* newSharedTexture(const SharedTextureHandle*)

§Safety

The handle pointer must be valid.

Source

pub unsafe fn new_shared_texture_with_descriptor( &self, descriptor: *const c_void, ) -> Option<Texture>

Create a shared texture with the specified descriptor.

C++ equivalent: Texture* newSharedTexture(const TextureDescriptor*)

§Safety

The descriptor pointer must be valid.

Source§

impl Device

Source

pub unsafe fn from_raw(ptr: *mut c_void) -> Option<Self>

Create a Device from a raw pointer.

§Safety

The pointer must be a valid Metal device object.

Source

pub fn as_raw(&self) -> *mut c_void

Get the raw pointer to the device.

Trait Implementations§

Source§

impl Clone for Device

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Device

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for Device

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Referencing for Device

Source§

fn as_ptr(&self) -> *const c_void

Get the raw pointer to the Objective-C object.
Source§

fn as_mut_ptr(&self) -> *mut c_void

Get the raw mutable pointer to the Objective-C object.
Source§

fn retain(&self) -> Self
where Self: Clone,

Retain the object, incrementing its reference count. Read more
Source§

fn release(&self)

Release the object, decrementing its reference count. Read more
Source§

fn autorelease(&self) -> Self
where Self: Clone,

Autorelease the object. Read more
Source§

fn retain_count(&self) -> usize

Get the retain count of the object. Read more
Source§

impl Send for Device

Source§

impl Sync for Device

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.