Metal is used for rendering graphics and performing parallel computations like image processing. But,
there are many boiler plates to use Metal normally.
- Creating Metal device
- Creating command queue
- Creating library, taking caring for which bundle includes it.
- PipelineState, CommandBuffer, Threadgroup ......... 😱
This library simplifies these steps.
| Thundershower | Fourier Series |
|---|---|
![]() |
![]() |
| Reference | Concept |
- Reference: http://glslsandbox.com/
| Edge Detection | Color Conversion |
|---|---|
![]() |
![]() |
| Prewitt | Monochrome |
| Before | After | Difference |
|---|---|---|
![]() |
![]() |
![]() |
- Bold font was changed to regular font.
- The last
processors.word was removed. - The border disappeared.
#include <metal_stdlib>
using namespace metal;
kernel void monochrome(texture2d<half, access::read_write> dest [[ texture(0) ]],
texture2d<half, access::read_write> source [[ texture(1) ]],
uint2 gid [[ thread_position_in_grid ]]) {
half3 color = source.read(gid).rgb;
half max_color = fmax3(color.r, color.g, color.b);
dest.write(half4(half3(max_color), 1), gid);
}import GPUOperator
final class Monochrome: Kernel {
static let functionName: String = "monochrome"
}let gpuOperator = try? GPUOperator()
try? gpuOperator?.install(kernel: Monochrome())let renderingView = RenderingView(frame: .zero)
renderingView.gpuOperator = gpuOperator
renderingView.run()The run() function just starts displaylink process inside RenderingView.
If you want to use MTLView (Metal Standard class), following example would be helpful.
import MetalKit
extension ViewController: MTKViewDelegate {
func mtkView(_ view: MTKView, drawableSizeWillChange size: CGSize) {}
func draw(in view: MTKView) {
autoreleasepool {
guard let drawable = view.currentDrawable else { return }
gpuOperator?.commit(drawable: drawable)
}
}
}- Swift 5.0
- iOS 12.0+
- Any simulators are unsupported.
pod 'GPUOperator'github "horita-yuya/GPUOperator"GPUOperator is available under the MIT license.






