This repo contains code with examples on how to use Apple's Metal GPU APIs. Some sample code has been created entirely by me, while others have been picked from Github. The latter ones are in this repo because they have been heavily modified, not only to support the latest version of Swift, but also to add support to iOS or macOS (when applicable). Links to the source Github repos or websites are provided.
Projects
-
Basic Tessellation.
This sample shows how to tessellate a triangle or quad patch with adjustable per-patch tessellation factors.
-
Command-Line apps.
GPU Inspector.
Prints on
stdout
a brief description of all your available GPUs. For example:Intel(R) HD Graphics 530 Built-in GPU (low power) Unified memory (shared with CPU) max recommended working set: 1.61 GB Feature set support family: common 1, common 2, common 3, mac 1, mac 2 sets: 1v1, 1v2, 1v3, 1v4, 2v1 General Purpose Computing max threadgroup memory: 66 KB max threads per threadgroup: [1024, 1024, 1024] threads execution width: 32 AMD Radeon Pro 460 Built-in GPU Discrete memory max recommended working set: 4.29 GB Feature set support family: common 1, common 2, common 3, mac 1, mac 2 sets: 1v1, 1v2, 1v3, 1v4, 2v1 General Purpose Computing max threadgroup memory: 66 KB max threads per threadgroup: [1024, 1024, 1024] threads execution width: 64
Gray converter.
Based on Safx' Gray converter compute sample, this small command-line utility transforms a picture into its gray-scale version and place it on the user's desktop.
The command-line app expects one argument with the location of the image to transform (e.g.
$(PROJECT_DIR)/Sources/GrayScale/Assets/Sample.jpg
). If you run the program through Xcode, there is a default argument defined on the Xcode Scheme. -
Metal by Example.
Warren Moore wrote this book in 2015. It was and it remains one of the best introductions to Metal I have found. I've migrated most chapters to the latest Swift and I've added support to macOS. -
Shader Exam.
Leon Denise wrote a tweet with a typical shader exam he gives to his students on SupInfo.com.
Command-Line Apps
You can run Command-Line projects from Xcode and see the result in Xcode console; however, you can also build those projects on your terminal and execute them outside.
-
Clone the project.
git clone https://github.com/dehesa/Metal
-
Navigate to the Command-Line source folder.
cd "commands"
-
Build the project you are interested in.
xcodebuild -project "$PROJECT_NAME.xcodeproj"
-
Execute the Command-Line tool from the
build/Release
folder.cd build/Release ./$TOOL_NAME