2016-06-03 2 views
2

저는 Swift에서 Metal로 시작하여 GPU에서 병렬 컴퓨팅을 시도하기 시작했습니다. 특히 newComputePipelineStateWithFunction과 관련된 문제가 있습니다. Apple's Documentation for Data-Parallel Compute Processing과 같은 여러 사이트를 검토했지만 오류가 너무 많이 발생합니다.iOS 메탈 스위프트 newComputePipelineStateWithFunction이 작동하지 않습니다.

여기에 나는 현재지고있어 오류 발생 :

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") 
     // } 

    } 

} 
+0

목적-C ['newComputePipelineStateWithFunction']을 (https://developer.apple.com/library/ios/documentation/Metal/ 참조/MTLDevice_Ref/index.html # // apple_ref/occ/intfm/MTLDevice/newComputePipelineStateWithFunction : error :)는 'error' 인수를 허용하지만 Swift 버전은 그렇지 않습니다. 예 : '시도 pipelineState = device.newComputePipelineStateWithFunction (kernelFunction)'작동합니다. – lock

+0

댓글을 주셔서 감사합니다.하지만 "여기에서 던진 오류는 처리되지 않았습니다."라는 오류 메시지가 나타납니다. – Jeremy

+1

예, 메서드를 호출 한 후 확인해야하는 입력 인수로 NSError를 수락하는 대신 예외를 throw하는 것이 더 신속한 방법입니다. 주석 처리 된 코드가하는 것처럼'do {} catch {}'로 묶어야합니다. – lock

답변

0

난 당신이 필요하다고 생각 :

device.newComputePipelineStateWithFunction(function) { (state:MTLComputePipelineState?, error:NSError?) in 

    } 
+0

이것은 컴퓨팅 파이프 라인 작성 방법의 비동기 변형 중 하나입니다. 이를 사용하려면 계산 작업을 인코딩하기 전에 완료 핸들러 (여기에서 후행 클로저로 작성)가 호출 될 때까지 기다려야합니다. – warrenm

관련 문제