• Stars
    star
    251
  • Rank 161,423 (Top 4 %)
  • Language
    Swift
  • License
    MIT License
  • Created about 7 years ago
  • Updated 5 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Examples for Apple's Metal APIs (rendering and compute).

Metal Logo & Name

Swift 5.x macOS, iOS, tvOS Metal 2.2 Xcode 12 MIT License

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

  • Apple's sample code.

    Basic Tessellation.

    This sample shows how to tessellate a triangle or quad patch with adjustable per-patch tessellation factors.

    macOS app tessellating a triangle

  • 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.

  1. Clone the project.

    git clone https://github.com/dehesa/Metal
  2. Navigate to the Command-Line source folder.

    cd "commands"
    
  3. Build the project you are interested in.

    xcodebuild -project "$PROJECT_NAME.xcodeproj"
  4. Execute the Command-Line tool from the build/Release folder.

    cd build/Release
    ./$TOOL_NAME