Ich habe gerade angefangen, mit Metal in Swift herumzuspielen, um etwas Parallel Computing auf der GPU laufen zu lassen, und ich habe Probleme mit der neuenComputePipelineStateWithFunction. Ich habe mehrere Seiten wie Apple's Documentation for Data-Parallel Compute Processing angeschaut, aber ich bekomme auch Fehler dort.iOS Metal Swift newComputePipelineStateWithFunction funktioniert nicht fehler
Hier ist der Fehler, den ich zur Zeit bin immer:
Incorrect argument label in call (have '_:error:', expected '_:completionHandler:')
Ich versuchte, den „Fehler“ mit einem Abschluss-Handler ersetzt wurde aber Schwierigkeiten es zu haben. Danke im Voraus. Hier ist mein Code ist:
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")
// }
}
}
Das Objective-C [ 'newComputePipelineStateWithFunction'] (https://developer.apple.com/library/ios/documentation/Metal/ Referenz/MTLDevice_Ref/index.html # // apple_ref/occ/intfm/MTLDevice/newComputePipelineStateWithFunction: Fehler :) akzeptiert ein 'Fehler'-Argument, die Swift-Version nicht. z.B; 'try pipelineState = device.newComputePipelineStateWithFunction (kernelFunction)' sollte funktionieren. – lock
Danke für den Kommentar, aber ich bekomme den Fehler "Fehler von hier geworfen werden nicht behandelt". – Jeremy
Ja, anstatt einen NSError als Eingabeargument zu akzeptieren, das Sie nach dem Aufruf der Methode überprüfen sollten, ist es eine schnellere Methode, eine Ausnahme auszulösen. Sie müssen es in ein 'do {} catch {}' umhüllen, ähnlich wie es Ihr auskommentierter Code tut. – lock