Better Programming

Advice for programmers.

Follow publication

Using Metal in Swift Playgrounds 4

Eskil Gjerde Sviggum
Better Programming
Published in
4 min readApr 19, 2022
Ill: Apple Inc.

Compiling the Metal-library in Xcode

Animated image showing how to navigate to the compiled metal library.
Compiling the Metal-source in Xcode and copying the compiled library. Located at <build-folder>/Products/Debug-<Platform>.

Strengths

Limitations

Store the Metal-source as a resource

let file = #fileLiteral(resourceName: "<Name of your metal-source>")

let libraryData = try! Data(contentsOf: file)
let libraryStr = String(data: libraryData, encoding: .utf8)!
let library = try device.makeLibrary(source: libraryStr, options: nil)

Strengths

Limitations

Compiled: 641 μs. Source: 981 μs.
Comparison of time for playground to load a Metal library on an M1 Mac using the two methods.
Eskil Gjerde Sviggum
Eskil Gjerde Sviggum

Written by Eskil Gjerde Sviggum

this.is.theOnlyPlanet?(with: “Swift”)

No responses yet

Write a response