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)") } } }
アサーションに失敗しました `frameBufferOnly textureは計算でサポートされていません。 '
どうすれば解決できますか?
ここでこれを設定する必要がありますか? 'MetalView'クラスの中で? – sooon
OK、私はそれを得た。私は 'self.frameBufferOnly = false'をセットして動作します。 – sooon
これは奇妙なことですが、私がプレイグラウンドでコードを実行すると、私はこの行を設定する必要はありませんでしたが、私はアプリケーションにコードを採用する場合、これを追加する必要があります。 – XueYu