首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >MetalKit - Drawable.texture断言错误

MetalKit - Drawable.texture断言错误
EN

Stack Overflow用户
提问于 2016-08-29 12:58:20
回答 2查看 3.5K关注 0票数 10

我是MetalKit的新手,并试图将本教程playground转换回OSX应用程序:

代码语言:javascript
复制
    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)")
        }
    }
}

我在线路上有个错误:

代码语言:javascript
复制
command_encoder.setTexture(drawable.texture, atIndex: 0)

失败的断言“`frameBufferOnly纹理不支持计算”。

我怎么解决这个问题?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-08-29 18:53:36

如果您想从计算函数中写入绘图的纹理,则需要告诉MTKView,它应该将其层配置为不只是帧缓冲区:

代码语言:javascript
复制
metalView.framebufferOnly = false

如果将此值设置为false,您的可绘制将为您提供带有shaderWrite用法标志集的纹理,这是从着色器函数编写纹理时所必需的。

票数 27
EN

Stack Overflow用户

发布于 2019-09-03 07:18:01

即使我将frameBufferOnly设置为false,并在使用可绘制之前打印布尔值以进行双重检查,我也有相同的问题。

但是,当我关闭GPU frame capture时,就不会再有断言了(至少现在是这样)。还是不知道为什么。

Menu > Scheme > Edit Scheme > Run > Options > GPU Frame Capture禁用

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39206935

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档