Macos -OSX 10.11 Beta 2上的[CametLayer nextDrawable]问题

Macos -OSX 10.11 Beta 2上的[CametLayer nextDrawable]问题,macos,beta,metal,Macos,Beta,Metal,每当我将CAMetalLayer添加到NSView时,[CAMetalLayer nextDrawable]方法将在3次成功id后通过nil 我尝试了两种不同的方法来配置设置。第一,我使用了MTKView并使用了它的CametLayer,它不起作用。其次,使用了NSView并创建了新的CametLayer。那也没用。我有一些奇怪的问题 我想知道还有谁有这个问题,如果有人知道解决这个问题的方法 附加说明: 我不想通过重写MTKView draw系统的方法(还没有)来使用它。另外,这在iOS 8上不

每当我将
CAMetalLayer
添加到
NSView
时,
[CAMetalLayer nextDrawable]
方法将在3次成功
id
后通过
nil

我尝试了两种不同的方法来配置设置。第一,我使用了MTKView并使用了它的
CametLayer
,它不起作用。其次,使用了
NSView
并创建了新的
CametLayer
。那也没用。我有一些奇怪的问题

我想知道还有谁有这个问题,如果有人知道解决这个问题的方法

附加说明:
我不想通过重写MTKView draw系统的方法(还没有)来使用它。另外,这在iOS 8上不是问题,我也没有在iOS 9的beta版上尝试过我的代码(还没有)

更新


我重新路由我的drawable调用以使用
MTKViewDelegate
委托。通过
drawInView
delegate方法,我能够检索到一致的可绘制帧但是,我仍然希望直接从
CametLayer
使用
nextDrawable
方法。希望这对其他人有所帮助。

我也遇到了同样的问题,并询问了WWDC 15的开发人员

MTKView的工作原理
MTKView
MTKView
的可绘制内容数量有限(可能有3个),因此在编码帧时,可以绘制的可绘制内容很少

您正在做的事情:您的场景可能非常简单,因此您可以非常快速地对帧进行编码。所以看起来,当CPU比GPU快4帧时,您要求下一个可绘制的,因为所有(3)个可绘制的都在使用中,所以失败了

解决方案:当没有空闲线程时,您需要使用语义库等待drawable

下面是要使用的代码:

let inflightSemaphore = dispatch_semaphore_create(3)

func drawInView(view: MTKView) {

        // use semaphore to encode 3 frames ahead
        dispatch_semaphore_wait(inflightSemaphore, DISPATCH_TIME_FOREVER)

        self.update()

        let commandBuffer = commandQueue.commandBuffer()
        let renderEncoder = commandBuffer.renderCommandEncoderWithDescriptor(view.currentRenderPassDescriptor!)
        renderEncoder.drawPrimitives()


        // use completion handler to signal the semaphore when this frame is completed allowing the encoding of the next frame to proceed
        commandBuffer.addCompletedHandler{ [weak self] commandBuffer in
            if let strongSelf = self {
                dispatch_semaphore_signal(strongSelf.inflightSemaphore)
            }
            return
        }

        commandBuffer.presentDrawable(view.currentDrawable!)
        commandBuffer.commit()
    }
这在任何地方都没有记录唯一的书面提及是在
GameViewController
的iOS项目模板(文件->新建->项目->游戏->拾取金属)中

我已经对此进行了调查(还没有回应),如果你也这样做,我将不胜感激


此外,您可能会发现我的github回购协议非常有用,因为我忘了回到这里


这是用OSX Beta 4解决的
nextDrawable
方法工作正常,并传回可用的
CAMetalDrawable
对象。我想我应该等到发布版本出来后再发布这个。我只是想在beta版首次发布时让其他人知道这个问题

使用
@autoreleasepool
进行可绘制的渲染


您遇到的问题,您是通过调用
nextDrawable
来谈论
camertallayer
,还是说您提交雷达的
MTKView
drawable方法?@NateHat MTKView drawable我的痛苦是关于
camertallayer
而不是
MTKView
。您可能可以使用
MTKView
CAMetalLayer
,但需要考虑的是从
CAMetalLayer
类、新实例或
MTKView
使用
nextDrawable
方法。不过,你指出的信息很好。谢谢你。