Metal sample code
View sample code to see how Metal APIs are implemented.
View sample code to see how Metal APIs are implemented.
Use Metal sparse textures to render a high-resolution image without the need to allocate memory for the entire image. This sample queries a residency and access counter buffer to stream and unload mipmaps and image tiles as needed.
macOS iOS
View sample codeFollow several chapters of an interactive tutorial that demonstrates the process of porting your game from other platforms to macOS and subsequently to iOS. This tutorial covers essential technologies for implementing games on Apple platforms, including Metal rendering, audio, input, and display APIs.
macOS iOS
Download sample codeEnhance the visual quality of your games and apps using curves with Metal ray tracing. This sample implements ray-traced rendering using GPU-based parallel processing.
macOS iOS
View sample codePace rendering with minimal input latency while providing essential information to the operating system for power-efficient rendering, thermal mitigation, and the scheduling of sustainable workloads.
macOS iOS tvOS
View sample codeLearn Metal fundamentals in this series of introductory samples. This series begins by showing how to create a window and render primitives and advances with samples showing 3D rendering and compute processing.
macOS
Download sample codeUse Metal to find GPUs and perform calculations on them. This sample shows how to obtain a Metal device, create simple buffer resources, and execute a basic compute kernel.
macOS
View sample codeCreate a MetalKit view and a render pass to draw the view’s contents. This sample shows how to configure a MetalKit view, set up Metal for rendering, and display rendered content.
macOS iOS tvOS
View sample codeDetermine which pixels are visible in a scene by using a depth texture. This sample draws geometry with varying depth values allowing Metal to remove pixels in triangles obscured by other triangles.
macOS iOS
View sample codeUtilize Metal’s multisample anti-aliasing capabilities to enhance the rendering of edges by employing custom resolve options with both immediate mode and tile-based resolve paths. This sample also demonstrates the utilization of a memoryless render target to eliminate the need to allocate a substantial multisample backing store.
macOS iOS tvOS
View sample codeUse Metal sparse textures to render a high-resolution image without the need to allocate memory for the entire image. This sample queries a residency and access counter buffer to stream and unload mipmaps and image tiles as needed.
macOS iOS
View sample codeCreate argument buffers to organize related resources. This sample shows how to set up a simple Metal argument buffer, encode textures, buffers, samplers, and constant values, and access these in a shader for rendering.
macOS iOS
View sample codeChoose and render meshes with several levels of detail using object and mesh shaders. This sample uses a mesh render pipeline to render a series of meshlets. It chooses a primitive and vertex count in the object shader depending upon a user-selected LOD for each one and renders a point, line, or triangle version in the mesh shader.
macOS iOS
View sample codeStream texture and buffer data directly from disk into Metal resources using fast resource loading. This sample streams high LOD textures and vertex data for three basic geometric objects from the disk as needed.
macOS
View sample codeReduce render workloads while increasing image detail with MetalFX. The sample shows how to improve image quality by adding jitter during rendering and creating a motion vector texture for the Metal FX temporal scaler. It also shows how to only upscale a source image using the spatial scaler effect.
macOS
View sample codeCompile a library of shaders and write it to a file as a dynamically linked library. This sample displays a rudimentary source editor to develop and compile a Metal function into a dynamic library, linking to the library and then invoking the function from a shader.
macOS iOS
View sample codeImplement ray-traced rendering using GPU-based parallel processing. This sample creates a custom raytracing pipeline with an acceleration structure and custom ray-intersection function to render a simple scene using path tracing.
macOS iOS
View sample codeEnhance the visual quality of your games and apps using curves with Metal ray tracing. This sample implements ray-traced rendering using GPU-based parallel processing.
macOS iOS
View sample codePace rendering with minimal input latency while providing essential information to the operating system for power-efficient rendering, thermal mitigation, and the scheduling of sustainable workloads.
macOS iOS tvOS
View sample codeImplement a lightweight view for Metal rendering that’s customized to your app’s needs. This sample shows how to create a custom Metal view by interacting directly with CoreAnimation to obtain drawable textures, control rendering on the main thread or secondary thread, and execute rendering in a loop in-sync with the display or in response to a system event.
macOS iOS tvOS
View sample codeReplace your app’s deprecated OpenGL code with Metal. This sample shows how shaders, renderable textures, and buffers work with Metal by comparing them with typical OpenGL and OpenGL ES rendering constructs.
macOS iOS
View sample codeDraw with Metal and OpenGL in the same view using an interoperable texture. This sample shows how to transition your application's rendering from OpenGL incrementally by setting up a shared memory buffer for textures managed by Metal and OpenGL.
macOS iOS
View sample codeInvoke Metal’s frame capture from your app, then save the resulting GPU trace to a file or view it in Xcode. This sample shows how to save a GPU trace to a file or view it in Xcode to explore the Metal commands produced by your app.
macOS
View sample codeModify Metal Apps to Run in Simulator. This sample will help you learn how to run your Metal app on the iOS simulator while using Metal features only available on iOS devices.
macOS iOS tvOS
View sample codeUse advanced Metal features such as Indirect Command Buffers, Sparse Textures, and Variable Rate Rasterization to implement modern rendering algorithms. This sample uses advanced Metal features to render a complex scene with the latest rendering techniques and effects like GPU-based mesh culling, tile-based deferred lighting, ambient occlusion, volumetric fog, and cascaded shadow maps.
macOS iOS
View sample codeCreate pipelines for different levels of detail from a common shader source. This sample uses Metal function constants to demonstrate dynamic level of detail (LOD) selection for a model without needing separate shaders for each LOD.
macOS iOS tvOS
View sample codeUse fences to synchronize access to resources allocated on a heap. This sample implements a multistage image filter that efficiently reuses memory from a Metal heap for different tasks during processing while also using fences to track data hazards.
macOS iOS tvOS
View sample codeGenerate ray-traced images with motion blur using GPU-based parallel processing. This sample uses primitive or instanced motion to blur a model by calculating colors using multiple keyframes.
macOS iOS
View sample codeImplement a post-processing pipeline using the latest features on Apple GPUs. This sample demonstrates how to apply HDR processing like bloom, exposure, and tone-mapping operators.
macOS iOS
View sample codeUse Metal to accelerate neural-network training performance of a custom Tensorflow operation.
macOS
View sample codeImplement a custom operation in PyTorch that uses Metal kernels to improve performance.
macOS
View sample codeFollow several chapters of an interactive tutorial that demonstrates the process of porting your game from other platforms to macOS and subsequently to iOS. This tutorial covers essential technologies for implementing games on Apple platforms, including Metal rendering, audio, input, and display APIs.
macOS iOS
Download sample codeConvert and utilize vertex, fragment, and compute shaders from HLSL to Metal IR. This sample also demonstrates how to implement more intricate pipelines that employ HLSL geometry and tessellation shaders using the Metal mesh shading API.
macOS
Download sample codeUtilize the Metal shader converter to transform ray tracing HLSL shaders into Metal IR, enabling the rendering of triangles and procedural spheres.
macOS
Download sample codeUtilize the Metal shader converter to convert HLSL ray query shaders into Metal IR. Employ these converted shaders to render two triangles, displaying their barycentric coordinates.
macOS
Download sample code