我刚刚开始在 Swift 中使用 Metal 来尝试在 GPU 上进行一些并行计算,但我在使用 newComputePipelineStateWithFunction 时遇到了一些问题。我查看了多个网站,例如 Apple's Documentation for Data-Parallel Compute Processing但我也遇到了错误。
这是我目前遇到的错误:
Incorrect argument label in call (have '_:error:', expected '_:completionHandler:')
我尝试用完成处理程序替换“错误”,但在那里也遇到了困难。提前致谢。这是我的代码:
import UIKit
import Metal
class ViewController: UIViewController {
var device: MTLDevice! = nil
var defaultLibrary: MTLLibrary! = nil
var thefunc: MTLFunction! = nil
var pipelineState: MTLComputePipelineState!
var commandQueue: MTLCommandQueue! = nil
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
setupMetal()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func setupMetal()
{
// Our default MTLDevice
device = MTLCreateSystemDefaultDevice()
defaultLibrary = device.newDefaultLibrary()
commandQueue = device.newCommandQueue()
// Define the kernel function
let kernelFunction: MTLFunction = defaultLibrary.newFunctionWithName("particleRendererShader")!
// Define the pipeline state
let pipelineState: MTLComputePipelineState = device.newComputePipelineStateWithFunction(kernelFunction, error: nil)
// Define the command buffer
let commandBuffer: MTLCommandBuffer = commandQueue.commandBuffer()
// Define the command encoder
let commandEncoder: MTLComputeCommandEncoder = commandBuffer.computeCommandEncoder()
commandEncoder.setComputePipelineState(pipelineState)
// thefunc = library.newFunctionWithName("filter_main");
// filterState = device.newComputePipelineStateWithFunction(thefunc, error: nil);
// let kernelFunction = library.newFunctionWithName("filter_main")
// pipelineState = device.newComputePipelineStateWithFunction(kernelFunction!, error: nil)
// do {
// try pipelineState = device.newComputePipelineStateWithDescriptor(pipelineStateDescriptor)
// } catch _ {
// print("Failed to create pipeline state, error")
// }
}
}
Best Answer-推荐答案 strong>
我认为你需要:
device.newComputePipelineStateWithFunction(function) { (state:MTLComputePipelineState?, error:NSError?) in
}
关于iOS Metal Swift newComputePipelineStateWithFunction 不工作错误,我们在Stack Overflow上找到一个类似的问题:
https://stackoverflow.com/questions/37605155/
|