iOS Metal Swift newComputePipelineStateWithFunction 不工作错误
<p><p>我刚刚开始在 Swift 中使用 Metal 来尝试在 GPU 上进行一些并行计算,但我在使用 newComputePipelineStateWithFunction 时遇到了一些问题。我查看了多个网站,例如 <a href="https://developer.apple.com/library/ios/documentation/Miscellaneous/Conceptual/MetalProgrammingGuide/Compute-Ctx/Compute-Ctx.html#//apple_ref/doc/uid/TP40014221-CH6-SW6" rel="noreferrer noopener nofollow">Apple's Documentation for Data-Parallel Compute Processing</a>但我也遇到了错误。</p>
<p>这是我目前遇到的错误:</p>
<pre><code>Incorrect argument label in call (have '_:error:', expected '_:completionHandler:')
</code></pre>
<p>我尝试用完成处理程序替换“错误”,但在那里也遇到了困难。提前致谢。这是我的代码:</p>
<pre><code>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")
// }
}
}
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>我认为你需要:</p>
<pre><code>device.newComputePipelineStateWithFunction(function) { (state:MTLComputePipelineState?, error:NSError?) in
}
</code></pre></p>
<p style="font-size: 20px;">关于iOS Metal Swift newComputePipelineStateWithFunction 不工作错误,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/37605155/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/37605155/
</a>
</p>
页:
[1]