如何保留 CAMetalLayer 的支持?

How to retain backing of a CAMetalLayer?

我无法找到一种方法来保留 CAMetalLayer 的支持,因为 nextDrawable 每次都从池中提供不同的 MTLTexture。即使我在渲染过程描述符上设置了适当的 loadAction 和 storeAction,也不会发生支持。内容随着 nextDrawable 调用交换纹理而闪烁。

我想要与 OpenGL ES 中的 kEAGLDrawablePropertyRetainedBacking 类似的行为。

有人想出这个吗?

nextDrawable 将始终为您提供未定义状态的纹理,据我所知,没有像 kEAGLDrawablePropertyRetainedBacking 这样的简单选项可以改变这种行为。

但是,显然可以通过将旧的可绘制对象保留一段时间并手动执行从前一个纹理到下一个纹理的 GPU 复制来实现复制。 https://devforums.apple.com/message/1060027#1060027

但是,您必须将 CAMetalLayer.framebufferOnly 设置为 NO,根据文档 (https://developer.apple.com/library/ios/documentation/Animation/Reference/CAMetalLayer_Ref/#//apple_ref/occ/instp/CAMetalLayer/framebufferOnly)

,这是 'at a cost to performance'