Skip to content

Commit

Permalink
Functors (#88)
Browse files Browse the repository at this point in the history
* add functors

* fix formatting

* update mps+functors

* replace inout with pointer
  • Loading branch information
eugenebokhan authored Jun 11, 2020
1 parent bae5270 commit c29f4eb
Show file tree
Hide file tree
Showing 72 changed files with 519 additions and 524 deletions.
8 changes: 0 additions & 8 deletions Alloy/CVPixelBuffer+MTLTexture.swift
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
//
// CVPixelFormat+MTLTexture.swift
// Alloy
//
// Created by Andrey Volodin on 20.10.17.
// Copyright © 2017 Andrey Volodin. All rights reserved.
//

import Metal
import CoreVideo.CVPixelBuffer

Expand Down
7 changes: 0 additions & 7 deletions Alloy/CodableConformance.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
//
// CodableConformance.swift
// Beautifier
//
// Created by Andrey Volodin on 28/08/2019.
//

import Metal

extension MTLCPUCacheMode: Codable {}
Expand Down
8 changes: 0 additions & 8 deletions Alloy/ComputeCommand.swift
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
//
// ComputeFunction.swift
// AlloyDemo
//
// Created by Andrey Volodin on 28.08.2018.
// Copyright © 2018 Andrey Volodin. All rights reserved.
//

import Metal

@dynamicMemberLookup
Expand Down
7 changes: 0 additions & 7 deletions Alloy/Encoders/BlockSize.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
//
// BlockSize.swift
// Alloy
//
// Created by Eugene Bokhan on 14/02/2019.
//

import Foundation

public struct BlockSize {
Expand Down
27 changes: 20 additions & 7 deletions Alloy/Encoders/EuclideanDistance.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
//
// EuclideanDistance.swift
// Alloy
//
// Created by Eugene Bokhan on 30/08/2019.
//

import Metal

final public class EuclideanDistance {
Expand All @@ -29,6 +22,26 @@ final public class EuclideanDistance {

// MARK: - Encode

public func callAsFunction(textureOne: MTLTexture,
textureTwo: MTLTexture,
resultBuffer: MTLBuffer,
in commandBuffer: MTLCommandBuffer) {
self.encode(textureOne: textureOne,
textureTwo: textureTwo,
resultBuffer: resultBuffer,
in: commandBuffer)
}

public func callAsFunction(textureOne: MTLTexture,
textureTwo: MTLTexture,
resultBuffer: MTLBuffer,
using encoder: MTLComputeCommandEncoder) {
self.encode(textureOne: textureOne,
textureTwo: textureTwo,
resultBuffer: resultBuffer,
using: encoder)
}

public func encode(textureOne: MTLTexture,
textureTwo: MTLTexture,
resultBuffer: MTLBuffer,
Expand Down
31 changes: 24 additions & 7 deletions Alloy/Encoders/LookUpTable.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
//
// LookUpTable.swift
// Alloy
//
// Created by Andrey Volodin on 29.10.2019.
//

import Metal

final public class LookUpTable {
Expand Down Expand Up @@ -33,6 +26,30 @@ final public class LookUpTable {

// MARK: - Encode

public func callAsFunction(sourceTexture: MTLTexture,
outputTexture: MTLTexture,
lut: MTLTexture,
intensity: Float,
in commandBuffer: MTLCommandBuffer) {
self.encode(sourceTexture: sourceTexture,
outputTexture: outputTexture,
lut: lut,
intensity: intensity,
in: commandBuffer)
}

public func callAsFunction(sourceTexture: MTLTexture,
outputTexture: MTLTexture,
lut: MTLTexture,
intensity: Float,
using encoder: MTLComputeCommandEncoder) {
self.encode(sourceTexture: sourceTexture,
outputTexture: outputTexture,
lut: lut,
intensity: intensity,
using: encoder)
}

public func encode(sourceTexture: MTLTexture,
outputTexture: MTLTexture,
lut: MTLTexture,
Expand Down
15 changes: 8 additions & 7 deletions Alloy/Encoders/MPSUnaryImageKernels.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
//
// MPSUnaryImageKernels.swift
// Alloy
//
// Created by Eugene Bokhan on 27.09.2019.
//

import MetalPerformanceShaders

final public class MPSUnaryImageKernels {
Expand All @@ -21,6 +14,14 @@ final public class MPSUnaryImageKernels {

// MARK: - Encode

public func callAsFunction(sourceTexture: MTLTexture,
destinationTexture: MTLTexture,
in commandBuffer: MTLCommandBuffer) {
self.encode(sourceTexture: sourceTexture,
destinationTexture: destinationTexture,
in: commandBuffer)
}

public func encode(sourceTexture: MTLTexture,
destinationTexture: MTLTexture,
in commandBuffer: MTLCommandBuffer) {
Expand Down
19 changes: 12 additions & 7 deletions Alloy/Encoders/MaskGuidedBlur.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
//
// MaskGuidedBlur.swift
// Alloy
//
// Created by Eugene Bokhan on 29/08/2019.
//

import Metal
import MetalPerformanceShaders

Expand Down Expand Up @@ -36,6 +29,18 @@ final public class MaskGuidedBlur {

// MARK: - Encode

public func callAsFunction(sourceTexture: MTLTexture,
maskTexture: MTLTexture,
destinationTexture: MTLTexture,
sigma: Float,
in commandBuffer: MTLCommandBuffer) {
self.encode(sourceTexture: sourceTexture,
maskTexture: maskTexture,
destinationTexture: destinationTexture,
sigma: sigma,
in: commandBuffer)
}

public func encode(sourceTexture: MTLTexture,
maskTexture: MTLTexture,
destinationTexture: MTLTexture,
Expand Down
31 changes: 24 additions & 7 deletions Alloy/Encoders/NormalizeKernel.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
//
// NormalizeKernel.swift
// Alloy
//
// Created by Eugene Bokhan on 08/05/2019.
//

import Metal
import simd

Expand Down Expand Up @@ -33,6 +26,30 @@ final public class NormalizeKernel {

// MARK: - Encode

public func callAsFunction(sourceTexture: MTLTexture,
destinationTexture: MTLTexture,
mean: SIMD3<Float>,
std: SIMD3<Float>,
in commandBuffer: MTLCommandBuffer) {
self.encode(sourceTexture: sourceTexture,
destinationTexture: destinationTexture,
mean: mean,
std: std,
in: commandBuffer)
}

public func callAsFunction(sourceTexture: MTLTexture,
destinationTexture: MTLTexture,
mean: SIMD3<Float>,
std: SIMD3<Float>,
using encoder: MTLComputeCommandEncoder) {
self.encode(sourceTexture: sourceTexture,
destinationTexture: destinationTexture,
mean: mean,
std: std,
using: encoder)
}

public func encode(sourceTexture: MTLTexture,
destinationTexture: MTLTexture,
mean: SIMD3<Float>,
Expand Down
27 changes: 20 additions & 7 deletions Alloy/Encoders/TextureAddConstant.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
//
// TextureAddConstant.swift
// Alloy
//
// Created by Eugene Bokhan on 03/09/2019.
//

import Metal

final public class TextureAddConstant {
Expand Down Expand Up @@ -37,6 +30,26 @@ final public class TextureAddConstant {

// MARK: - Encode

public func callAsFunction(sourceTexture: MTLTexture,
destinationTexture: MTLTexture,
constant: SIMD4<Float>,
in commandBuffer: MTLCommandBuffer) {
self.encode(sourceTexture: sourceTexture,
destinationTexture: destinationTexture,
constant: constant,
in: commandBuffer)
}

public func callAsFunction(sourceTexture: MTLTexture,
destinationTexture: MTLTexture,
constant: SIMD4<Float>,
using encoder: MTLComputeCommandEncoder) {
self.encode(sourceTexture: sourceTexture,
destinationTexture: destinationTexture,
constant: constant,
using: encoder)
}

public func encode(sourceTexture: MTLTexture,
destinationTexture: MTLTexture,
constant: SIMD4<Float>,
Expand Down
27 changes: 20 additions & 7 deletions Alloy/Encoders/TextureAffineCrop.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
//
// TextureAffineCrop.swift
// Pods
//
// Created by Andrey Volodin on 18.11.2019.
//

import Metal

final public class TextureAffineCrop {
Expand Down Expand Up @@ -33,6 +26,26 @@ final public class TextureAffineCrop {

// MARK: - Encode

public func callAsFunction(sourceTexture: MTLTexture,
destinationTexture: MTLTexture,
affineTransform: simd_float3x3,
in commandBuffer: MTLCommandBuffer) {
self.encode(sourceTexture: sourceTexture,
destinationTexture: destinationTexture,
affineTransform: affineTransform,
in: commandBuffer)
}

public func callAsFunction(sourceTexture: MTLTexture,
destinationTexture: MTLTexture,
affineTransform: simd_float3x3,
using encoder: MTLComputeCommandEncoder) {
self.encode(sourceTexture: sourceTexture,
destinationTexture: destinationTexture,
affineTransform: affineTransform,
using: encoder)
}

public func encode(sourceTexture: MTLTexture,
destinationTexture: MTLTexture,
affineTransform: simd_float3x3,
Expand Down
47 changes: 40 additions & 7 deletions Alloy/Encoders/TextureCopy.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
//
// TextureCopy.swift
// Alloy
//
// Created by Andrey Volodin on 31/01/2019.
//

import Metal

final public class TextureCopy {
Expand Down Expand Up @@ -36,6 +29,46 @@ final public class TextureCopy {

// MARK: - Encode

public func callAsFunction(sourceTexture: MTLTexture,
destinationTexture: MTLTexture,
in commandBuffer: MTLCommandBuffer) {
self.encode(sourceTexture: sourceTexture,
destinationTexture: destinationTexture,
in: commandBuffer)
}

public func callAsFunction(sourceTexture: MTLTexture,
destinationTexture: MTLTexture,
using encoder: MTLComputeCommandEncoder) {
self.encode(sourceTexture: sourceTexture,
destinationTexture: destinationTexture,
using: encoder)
}

public func callAsFunction(region sourceTexureRegion: MTLRegion,
from sourceTexture: MTLTexture,
to destinationTextureOrigin: MTLOrigin,
of destinationTexture: MTLTexture,
in commandBuffer: MTLCommandBuffer) {
self.copy(region: sourceTexureRegion,
from: sourceTexture,
to: destinationTextureOrigin,
of: destinationTexture,
in: commandBuffer)
}

public func callAsFunction(region sourceTexureRegion: MTLRegion,
from sourceTexture: MTLTexture,
to destinationTextureOrigin: MTLOrigin,
of destinationTexture: MTLTexture,
using encoder: MTLComputeCommandEncoder) {
self.copy(region: sourceTexureRegion,
from: sourceTexture,
to: destinationTextureOrigin,
of: destinationTexture,
using: encoder)
}

public func encode(sourceTexture: MTLTexture,
destinationTexture: MTLTexture,
in commandBuffer: MTLCommandBuffer) {
Expand Down
Loading

0 comments on commit c29f4eb

Please sign in to comment.