Metal sample code library
Explore the complete set of Metal samples.
Overview
Browse the topics below to find samples relevant to a concept you want to learn more about, starting with the basic computation and render workflows. The samples in the lighting and multiple technique sections demonstrate how to take advantage of the unique GPU architecture of Apple silicon.
Topics
Compute workflows
Performing calculations on a GPUSelecting device objects for compute processingCustomizing a TensorFlow operationCustomizing a PyTorch operation
Machine learning workflows
Running a machine learning model on the GPU timelineTraining a neural network to render irradiance in real timeRunning inline ML operations in a shader with Metal 4
Render workflows
Using Metal to draw a view’s contentsDrawing a triangle with Metal 4Selecting device objects for graphics renderingCustomizing render pass setupCreating a custom Metal viewCalculating primitive visibility using depth testingEncoding indirect command buffers on the CPUImplementing order-independent transparency with image blocksLoading textures and models using Metal fast resource loadingAdjusting the level of detail using Metal mesh shadersCreating a 3D application with hydra renderingCulling occluded geometry using the visibility result bufferImproving edge-rendering quality with multisample antialiasing (MSAA)Achieving smooth frame rates with a Metal display link
Textures
Combining blit and compute operations in a single passReading pixel data from a drawable textureCreating and sampling texturesStreaming large images with Metal sparse textures
Argument buffers
Managing groups of resources with argument buffersUsing argument buffers with resource heapsEncoding argument buffers on the GPURendering terrain dynamically with argument buffers
Shaders
Synchronization
Synchronizing CPU and GPU workImplementing a multistage image filter using heaps and eventsImplementing a multistage image filter using heaps and fences
Lighting techniques
Rendering a scene with forward plus lighting using tile shadersRendering a scene with deferred lighting in Objective-CRendering a scene with deferred lighting in SwiftRendering a scene with deferred lighting in C++Rendering reflections with fewer render passes
Multiple techniques
Ray tracing
Rendering reflections in real time using ray tracingAccelerating ray tracing using MetalControl the ray tracing process using intersection queriesAccelerating ray tracing and motion blur using MetalRendering a curve primitive in a ray tracing scene