gpu

GPUOperator

Simplifies Metal setup. Can be used for graphics shader, realtime video processing and image processing, like computation of two image difference.

Showing:

Popularity

Downloads/wk

0

GitHub Stars

104

Maintenance

Last Commit

2yrs ago

Contributors

1

Package

Dependencies

0

License

MIT

Categories

Readme

GPUOperator

Swift Version Carthage License Platform

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.

Examples

Graphics Shader

Implementation

ThundershowerFourier Series
thundershowerFourier
ReferenceConcept

Realtime Video Processing

Implementation

Edge DetectionColor Conversion
cameramonochrome
PrewittMonochrome

Image Processing: Two Images Difference

Implementation

BeforeAfterDifference

This infers

  • Bold font was changed to regular font.
  • The last processors. word was removed.
  • The border disappeared.

Getting Started

1. Define kernel function and kernel class

#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"
}

2. Setup GPUOperator instance

let gpuOperator = try? GPUOperator()
try? gpuOperator?.install(kernel: Monochrome())

3. Configure Rendering Process

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)
        }
    }
}

Requirements

  • Swift 5.0
  • iOS 12.0+
  • Any simulators are unsupported.

Installation

Cocoapods

pod 'GPUOperator'

Carthage

github "horita-yuya/GPUOperator"

License

GPUOperator is available under the MIT license.

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100