Ios 金属有后缓冲吗?

Ios 金属有后缓冲吗?,ios,metal,Ios,Metal,我目前正在追踪我的Metal应用程序中的一些视觉弹出,相信这是因为我直接绘制到帧缓冲区,而不是后缓冲区 // this is when I've finished passing commands to the render buffer and issue the draw command. I believe this sends all the images directly to the framebuffer instead of using a backbuffer [re

我目前正在追踪我的Metal应用程序中的一些视觉弹出,相信这是因为我直接绘制到帧缓冲区,而不是后缓冲区

  // this is when I've finished passing commands to the render buffer and issue the draw command.  I believe this sends all the images directly to the framebuffer instead of using a backbuffer
  [renderEncoder endEncoding];
  [mtlCommandBuffer presentDrawable:frameDrawable];
  [mtlCommandBuffer commit];
  [mtlCommandBuffer release];
  //[frameDrawable present];   // This line isn't needed (and I believe is performed by presentDrawable
几次谷歌搜索之后,我还没有发现任何关于金属后缓冲器的文档。我知道我可以自己滚,但我不敢相信金属不支持后缓冲

下面是我如何设置CametLayer对象的代码片段

+ (id)layerClass
{
    return [CAMetalLayer class];
}

- (void)initCommon
{
    self.opaque          = YES;
    self.backgroundColor = nil;
    ...
}

-(id <CAMetalDrawable>)getMetalLayer
{
    id <CAMetalDrawable> frameDrawable;
    while (!frameDrawable && !frameDrawable.texture)
    {
        frameDrawable = [self->_metalLayer nextDrawable];
    }
    return frameDrawable;
}
+(id)层类
{
返回[CametLayer类];
}
-(无效)普通
{
self.不透明=是;
self.backgroundColor=nil;
...
}
-(id)getMetalLayer
{
id可框架绘制;
而(!frameDrawable&!frameDrawable.texture)
{
frameDrawable=[self->_metalayernextDrawable];
}
返回帧可绘制;
}
我可以在我的CametLayer对象上启用backbuffer吗,或者我需要自己滚动吗?

我假设“后缓冲区”是指在显示相应的前缓冲区时渲染到的renderbuffer

在Metal中,这个概念是由您从
CametLayer
中提取的Drawable提供的。
CametLayer
实例维护一个小的Drawable池(通常为3个),每次调用
nextDrawable
时从池中检索其中一个,并在调用
presentDrawable
后以及渲染完成后将其返回到池中(这可能需要一段时间,因为GPU从CPU异步运行)

实际上,在每个帧循环中,通过调用
nextDrawable
获取一个后缓冲区,并通过调用
presentDrawable:
并提交
MTLCommandBuffer
使其有资格成为前缓冲区

由于池中只有3个可绘制文件,关键是您必须自己管理此生命周期,方法是在调用
nextDrawable
时添加适当的CPU资源同步,并在渲染完成后的回调中添加相应的CPU资源同步(根据
MTLCommandBuffer addCompletedHandler:
回调设置)

通常,您使用
dispatch\u信号量\u t
进行以下操作:

_resource_semaphore = dispatch_semaphore_create(3);
然后在调用
nextDrawable
之前放置以下内容:

dispatch_semaphore_wait(_resource_semaphore, DISPATCH_TIME_FOREVER);
在您的
addCompletedHandler:
回调处理程序中:

dispatch_semaphore_signal(_resource_semaphore);
看看苹果公司的一些简单的金属样本应用程序,看看它的实际应用。苹果公司在这方面的文档并不多