MTLDevice
The main Metal interface to a GPU that apps use to draw graphics and run computations in parallel.
Declaration
protocol MTLDevice : NSObjectProtocol, SendableMentioned in
- Understanding the Metal 4 core API
- Finding multiple GPUs on an Intel-based Mac
- Confirming which counters and counter sets a GPU supports
- Converting GPU timestamps into CPU time
- Creating an indirect command buffer
- Creating binary archives from device-built pipeline state objects
- Creating sparse heaps and sparse textures
- Detecting GPU features and Metal software versions
- Developing Metal apps that run in Simulator
- Getting the default GPU
- Improving CPU performance by using argument buffers
- Improving rendering performance with vertex amplification
- Improving your game’s graphics performance and settings
- Minimizing the binary size of a shader library
- Sampling GPU data into counter sample buffers
- Simplifying GPU resource management with residency sets
- Synchronizing passes with a fence
- Using the Metal 4 compilation API
Overview
You can get the default MTLDevice at runtime by calling MTLCreateSystemDefaultDevice() (see Getting the default GPU). Each Metal device instance represents a GPU and is the main starting point for your app’s interaction with it. With a Metal device instance, you can inspect a GPU’s features and capabilities (see Device inspection) and create subsidiary type instances with its factory methods.
Buffers, textures, and other resources store, synchronize, and pass data between the GPU and CPU (see Resource fundamentals).
Input/Output command queues efficiently load resources from the file system (see Resource loading).
Command queues create command encoders and schedule work for the GPU, including rendering and compute commands (see Render passes and Compute passes).
Pipeline states store render or compute pipeline configurations — which can be expensive to create — so that you can reuse them, potentially many times.
If your app uses more than one GPU (see Multi-GPU systems), ensure that instances of these types only interact with others from the same device. For example, your app can pass a texture to a command encoder that comes from the same Metal device, but not to another device.
Topics
Working with GPU devices
Device inspectionWork submissionPipeline state creationResource creationShader library and archive creation
Instance Properties
Instance Methods
functionHandle(function:)functionHandle(function:)makeArchive(url:)makeArgumentTable(descriptor:)makeBuffer(length:options:placementSparsePageSize:)makeCommandAllocator()makeCommandAllocator(descriptor:)makeCommandBuffer()makeCommandQueue(descriptor:)makeCompiler(descriptor:)makeCounterHeap(descriptor:)makeLogState(descriptor:)makeMTL4CommandQueue()makeMTL4CommandQueue(descriptor:)makePipelineDataSetSerializer(descriptor:)makeTensor(descriptor:)makeTextureViewPool(descriptor:)queryTimestampFrequency()size(ofCounterHeapEntry:)tensorSizeAndAlign(descriptor:)