Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save MasDennis/e9fb5ad11739389be9d9279fc2cc1d2b to your computer and use it in GitHub Desktop.
Save MasDennis/e9fb5ad11739389be9d9279fc2cc1d2b to your computer and use it in GitHub Desktop.
private func setupComputePipeline(targetTexture: MTLTexture) {
guard let device = MTLCreateSystemDefaultDevice(),
let library = device.makeDefaultLibrary(),
let postProcessingKernel = library.makeFunction(name: "inverseColorKernel"),
let pipelineState = try? device.makeComputePipelineState(function: postProcessingKernel)
else {
assertionFailure()
return
}
computePipelineState = pipelineState
threadsPerThreadgroup = MTLSize(width: pipelineState.threadExecutionWidth,
height: pipelineState.maxTotalThreadsPerThreadgroup / pipelineState.threadExecutionWidth,
depth: 1)
threadgroupsPerGrid = MTLSize(width: (targetTexture.width + threadsPerThreadgroup.width - 1) / threadsPerThreadgroup.width,
height: (targetTexture.height + threadsPerThreadgroup.height - 1) / threadsPerThreadgroup.height,
depth: 1)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment