A proxy for MetalPerformanceShaders (and dependents) which takes to a stub on a simulator and to the real implementation on a device. It works both for Swift and Objective-C.
It's usually a problem not to be able to compile for a simulator target when using Metal shaders. By using this proxy, you are being able to compile and to run on simulators. Note that trying to run the Metal shaders on a simulator will fail. Nevertheless, it allows a project that implements Metal shaders to:
If you use Metal, you probably use
QuartzCore. But they are not available when targetting the simulator. To make them available, just do:
This pod will add no stub to devices (no footprint!), as the proxy uses preprocessor macros to decide which implementation to use.
Note that if a stub method is called, a exception will be thrown.
currentDrawable property of
MTKView is of type
CAMetalDrawable in the device but of type
MTLDrawable in the simulator. So you need to cast it in your code to use it properly. E.g., if you have
let texture = view.currentDrawable.texture
change it to
let texture = (view.currentDrawable as? CAMetalDrawable)?.texture
This is the best workaround we came up with. If you happen to have a better idea, please open an issue.
If for some reason you want to control when to use the stub, you can import the stub like:
#if condition import MetalPerformanceShadersStub #endif
See CREATION for an explanation.
To use with previous Xcode versions, see previous releases.
In particular, if you find a missing Metal-dependent framework, open an issue or better submit a pull request 😄
Before contribute check the CONTRIBUTING file for more info.
If you use MetalPerformanceShadersProxy in your app, we would love to hear about it! Drop us a line on Twitter.
Follow these 3 steps to run Example project: clone MetalPerformanceShadersProxy repository, open MetalPerformanceShadersProxy workspace and run the Example project.
As a real example, you can check out the Bender library.
CocoaPods is a dependency manager for Cocoa projects.
To install MetalPerformanceShadersProxy, simply add the following line to your Podfile:
pod 'MetalPerformanceShadersProxy', '~> 0.3'
If you just want the stub:
pod 'MetalPerformanceShadersProxy/Stub', '~> 0.3'
Carthage is a simple, decentralized dependency manager for Cocoa.
To install MetalPerformanceShadersProxy, simply add the following line to your Cartfile:
github "xmartlabs/MetalPerformanceShadersProxy" ~> 0.2
It can be found in the CHANGELOG file.