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

问题描述:

每当我添加CAMetalLayerNSView,该[CAMetalLayer nextDrawable]方法将后3分成功id<CAMetalDrawable>通过nil- [CAMetalLayer nextDrawable]问题上OSX 10.11 Beta 2的

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

我想知道其他人有这个问题,如果有人知道解决方案来解决这个问题。

其他注意事项:
我不想通过覆盖它的方法来使用MTKView绘制系统(还没有)。此外,这不是在iOS 8上的问题,我没有尝试我的代码与iOS 9的测试版(尚未)。

更新

我重新路由我绘制调用使用​​委托。从drawInView委托方法,我能够检索一致的可绘制框架。 但是,我仍然想直接从CAMetalLayer使用nextDrawable方法。希望这可以帮助其他人。

我忘了回来这将不胜感激。

这是fixedOSX Beta 4nextDrawable方法正常工作并传回可用的CAMetalDrawable对象。我想我应该等到发布版发布后再发布。当测试版首次发布时,我只想让其他人知道这个问题。

我有同样的问题,问金属开发者在WWDC 。

如何MTKView工作MTKView限制了可绘制的数量(大概3),所以当你在编码帧有你可以借鉴到一些可绘制。

你在做什么:你的场景可能很简单,所以你CPU可以很快的编码帧。所以看起来好像,当CPU比GPU早4帧时,你会要求下一个drawable,并且因为所有(3)drawable都在使用中,所以它会失败。

解决方案:您需要使用semapthore等待绘制时,有没有免费的。

这里的代码使用方法:

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项目模板(文件 - >新建 - >项目 - >游戏 - >挑金属)。

我已经填补了雷达对这个(没有反应还),如果你做同样的https://bugreport.apple.com

你也可能发现有用我的github回购https://github.com/haawa799/RamOnMetal

+0

你有问题,你是通过调用'nextDrawable'谈论'CAMetalLayer'或者是你谈论你提交雷达对抗'MTKView'绘制方法? –

+0

@NateHat MTKView可绘制 – haawa

+0

我的考验是关于'CAMetalLayer'而不是'MTKView'。您可能可以使用'MTKView'的'CAMetalLayer',但担心的是使用'CAMetalLayer'类中的'nextDrawable'方法,从新实例或'MTKView'中。这是你指出的很好的信息。感谢那。 –

使用@autoreleasepool来渲染绘制。

https://forums.developer.apple.com/thread/15102