3
내가 MetalKit
에 새로운 오전 OSX
응용 프로그램을 다시 playground
에서 this tutorial을 변환하려고 :MetalKit - Drawable.texture 주장 오류
command_encoder.setTexture(drawable.texture, atIndex: 0)
: 나는 라인에 오류가있어import MetalKit public class MetalView: MTKView { var queue: MTLCommandQueue! = nil var cps: MTLComputePipelineState! = nil required public init(coder: NSCoder) { super.init(coder: coder) device = MTLCreateSystemDefaultDevice() registerShaders() } override public func drawRect(dirtyRect: NSRect) { super.drawRect(dirtyRect) if let drawable = currentDrawable { let command_buffer = queue.commandBuffer() let command_encoder = command_buffer.computeCommandEncoder() command_encoder.setComputePipelineState(cps) command_encoder.setTexture(drawable.texture, atIndex: 0) let threadGroupCount = MTLSizeMake(8, 8, 1) let threadGroups = MTLSizeMake(drawable.texture.width/threadGroupCount.width, drawable.texture.height/threadGroupCount.height, 1) command_encoder.dispatchThreadgroups(threadGroups, threadsPerThreadgroup: threadGroupCount) command_encoder.endEncoding() command_buffer.presentDrawable(drawable) command_buffer.commit() } } func registerShaders() { queue = device!.newCommandQueue() do { let library = device!.newDefaultLibrary()! let kernel = library.newFunctionWithName("compute")! cps = try device!.newComputePipelineStateWithFunction(kernel) } catch let e { Swift.print("\(e)") } } }
assertion 'frameBufferOnly 텍스처가 계산에 지원되지 않습니다.'
어떻게 해결할 수 있습니까?
어디에서 설정해야합니까? MetalView 클래스 안에 있습니까? – sooon
좋아, 알았다. 'self.frameBufferOnly = false'를 설정하면 작동합니다. – sooon
놀랍습니다. 놀이터에서 코드를 실행하면이 행을 설정할 필요가 없습니다. 코드를 앱에 적용하면이 코드를 추가해야합니다. – XueYu