Swift Package Manager plug-in to compile Metal files that can be debugged in Xcode Metal Debugger.

Overview

MetalCompilerPlugin

Swift Package Manager plug-in to compile Metal files that can be debugged in Xcode Metal Debugger.

Description

Swift Package Manager now1 seems to compile all Metal files within a target into a default.metallib. Alas, this file cannot be debugged in Xcode Metal Debugger.

Unable to create shader debug session

Source is unavailable

Under the target's Build Settings, ensure the Metal Compiler Build Options produces debugging information and includes source code.

If building with the 'metal' command line tool, include the options '-gline-tables-only' and '-frecord-sources'.

(Screenshot).

This plug-in provides an alternative way to compile Metal files into a metallib that can be debugged.

This project also shows how to create a "Pure-Metal target" that can be used to contain your Metal source code and header files.

Usage

In your Package.swift file, add MetalCompilerPlugin as a dependency. And add the MetalCompilerPlugin to your target's plugins array.

For example:

    dependencies: [
        .package(url: "https://github.com/schwa/MetalCompilerPlugin", branch: "main"),
    ],
    targets: [
        .target(name: "MyExampleShaders", plugins: ["MetalCompilerPlugin"]),
    ]

Note the title of the output metal library file will be debug.metallib and will live side-by-side with the default.metallib file. See Limitations below.

Limitations

The output metal library file will be debug.metallib and will live side-by-side with the default.metallib file. This is because of the default.metallib file is created by the Swift Package Manager and cannot be overridden.

You will not be able to use MTLDevice.makeDefaultLibrary() to load the debug.metallib file. Instead, you will need to use MTLDevice.makeLibrary(url:) to load the debug.metallib file. See the unit tests for an example.

Pure-Metal Targets

A "Pure-Metal" target is a target that contains only Metal source code and header files. This is useful for projects that contain a lot of Metal code and want to keep it separate from the rest of the project.

This is also useful so that Metal and Swift can share types defined in common header files. For example, a Vertex or Uniforms struct defined in a header file can be used by both Metal and Swift code.

Direct sharing of Metal types with Swift prevents duplication of types and makes sure that your types have a consistent layout and packing across Metal and Swift. Simply defining the same type in both Metal and Swift manually is not enough and can lead to subtle memory alignment-related crashes or data corruption.

See the ExampleShaders target in the Package.swift file. The "Pure-Metal" target must not contain any Swift files. It should contain your Metal source code and header files (contained in an included folder). It should also contain a Module.map file that allows Swift to import the header files.

License

BSD 3-clause. See LICENSE.md.

TODO

  • File and link to feedback items for the limitations and issues above.
  • More configuration options.
  • Searching for .metallib works in Xcode Unit Tests but fails under swift test. Why?

Footnotes

  1. Prior to Swift Package Manager 5.3 it was impossible to process Metal files at all. Version 5.3 added the capability to process resources, including Metal files. Somewhere between versions 5.3 and 5.7 Swift Package Manager gained the ability to transparently compile all Metal files in a package.

You might also like...
Boids written in the Metal Shader language + Swift

MetalBoid Boids written in the Metal Shader language + Swift This is an example of a Boid simulating running in iOS using Swift+Metal. The parameters

An example app showing how to use AVCaptureSession with Metal in Swift.
An example app showing how to use AVCaptureSession with Metal in Swift.

#iOSSwiftMetalCamera Click here to see video demo. This app is a basic example showing how to use Swift to setup an AVCaptureSession session to access

VRTracerSample - Learning project in Metal Ray Tracing and Swift
VRTracerSample - Learning project in Metal Ray Tracing and Swift

VRTracer This is a personal project for learning Metal's Ray Tracing API with sw

Visualiser written in Swift, SwiftUI and Metal API
Visualiser written in Swift, SwiftUI and Metal API

ModularMTL About Visualisation of modular multiplication on a circle. Written in Swift using Metal API and SwiftUI. Images Features Keyboard controls

📷 A composable image editor using Core Image and Metal.
📷 A composable image editor using Core Image and Metal.

Brightroom - Composable image editor - building your own UI Classic Image Editor PhotosCrop Face detection Masking component 🎉 v2.0.0-alpha now open!

📷 A composable image editor using Core Image and Metal.
📷 A composable image editor using Core Image and Metal.

Brightroom - Composable image editor - building your own UI Classic Image Editor PhotosCrop Face detection Masking component 🎉 v2.0.0-alpha now open!

A python library to run metal compute kernels on MacOS 12

metalcompute for Python A python library to run metal compute kernels on MacOS Usage Example execution from M1-based Mac running MacOS 12.0: ./build

A GPU accelerated image and video processing framework built on Metal.
A GPU accelerated image and video processing framework built on Metal.

MetalPetal An image processing framework based on Metal. Design Overview Goals Core Components MTIContext MTIImage MTIFilter MTIKernel Optimizations C

1D, 2D, and 3D variations of Fast Fourier Transforms for a Metal S4TF backend

MetalFFT MetalFFT is an experiment in adding GPU acceleration for 1D, 2D, and 3D variations of Fast Fourier Transforms. This framework's original purp

Owner
Jonathan Wight
No.
Jonathan Wight
Compile-time-checked URLs

SafeURL Tool for avoiding using the URL(string:) initializer with optional result, instead introducing a compile time URL validity check. Note, this d

Jhonatan A. 133 Oct 25, 2022
Extract Metal functions from .metallib files.

Metal Library Archive MetalLibraryArchive is a product of reverse-engineering Apple's metallib file format. You can use MetalLibraryArchive to get the

Yu Ao 55 Nov 22, 2022
BeatboxiOS - A sample implementation for merging multiple video files and/or image files using AVFoundation

MergeVideos This is a sample implementation for merging multiple video files and

null 3 Oct 24, 2022
Swift Package Manager command plugin for Swift-DocC

Swift-DocC Plugin The Swift-DocC plugin is a Swift Package Manager command plugin that supports building documentation for SwiftPM libraries and execu

Apple 216 Nov 12, 2022
Xcode-streamdeck-plugin - A Stream Deck plugin for Xcode

Stream Deck Xcode Plugin This repository contains a Stream Deck plugin to add so

Daniel Kennett 74 Nov 11, 2022
Xcode plugin that brings ⇧⌘T from AppCode over to Xcode

Aviator An Xcode Plugin that brings ⇧⌘T over to Xcode This minimal plugin allows you to use the key combo ⇧⌘T to toggle between source and test files.

Mark Sands 29 Aug 18, 2018
NavigationCoordinator acts as a coordinator for NavigationView in SwiftUI. You can use pushView, popView, popToView, popToRootView as you can in traditional UIKit

NavigationCoordinator NavigationCoordinator acts as a coordinator for NavigationView. You can use pushView, popView, popToView, popToRootView in Swift

Shahriar Nasim Nafi 3 Aug 3, 2022
GPUImage 3 is a BSD-licensed Swift framework for GPU-accelerated video and image processing using Metal.

GPUImage 3 Janie Clayton http://redqueengraphics.com @RedQueenCoder Brad Larson http://www.sunsetlakesoftware.com @bradlarson [email protected]

Brad Larson 2.4k Nov 22, 2022
GPU-based media processing library using Metal written in Swift

GPU-based media processing library using Metal written in Swift. Overview MetalAcc is a GPU-Based media processing library that lets you apply GPU-acc

Jiawei Wang 258 Oct 20, 2022
A simple mesh viewer for MacOS based on Swift and Metal and using Assimp for loading meshes

Metal Mesh Viewer A simple triangle mesh viewer for MacOS This application is a simple (triangle) mesh viewer that should be capable of rendering even

J. Andreas Bærentzen 0 Dec 13, 2021