【发布时间】:2020-11-27 16:04:14
【问题描述】:
这发生在我尝试使用 CAMetalLayer 渲染金属时,以及我下载的许多 'Metal By Example' 示例代码中。问题出在 'texture' 我猜,这里有一些代码,我不能提供全部,但我会尽量提供最相关的部分。它不接受纹理描述符,将其打印到控制台中。
断言失败 `MTLTextureDescriptor: Depth、Stencil、DepthStencil 和 Multisample 纹理必须使用 MTLStorageModePrivate 或 MTLStorageModeMemoryless 存储模式分配。'
- (void)buildDepthTexture
{
CGSize drawableSize = self.layer.drawableSize;
MTLTextureDescriptor *descriptor = [MTLTextureDescriptor texture2DDescriptorWithPixelFormat:MTLPixelFormatDepth32Float
width:drawableSize.width
height:drawableSize.height
mipmapped:NO];
self.depthTexture = [self.device newTextureWithDescriptor:descriptor]; // Thread 1: signal SIGABRT
[self.depthTexture setLabel:@"Depth Texture"];
}
同样,这是示例代码,可能有效,但不再有效。所以我很喜欢,让我们用私有存储模式或一些垃圾来分配它。 descriptor.storageMode = MTLStorageModePrivate;
但是当我这样做时,无法在draw 中创建渲染通道描述符。
断言失败`Texture at depthAttachment has usage (0x01) which doesn't specify MTLTextureUsageRenderTarget (0x04)'
MTLRenderPassDescriptor *renderPass = [self newRenderPassWithColorAttachmentTexture:[drawable texture]];
id<MTLCommandBuffer> commandBuffer = [self.commandQueue commandBuffer];
id<MTLRenderCommandEncoder> commandEncoder = [commandBuffer renderCommandEncoderWithDescriptor:renderPass]; //Thread 1: signal SIGABRT
这是newRenderPassWithColorAttachmentTexture 的代码。
- (MTLRenderPassDescriptor *)newRenderPassWithColorAttachmentTexture:(id<MTLTexture>)texture
{
MTLRenderPassDescriptor *renderPass = [MTLRenderPassDescriptor new];
renderPass.colorAttachments[0].texture = texture;
renderPass.colorAttachments[0].loadAction = MTLLoadActionClear;
renderPass.colorAttachments[0].storeAction = MTLStoreActionStore;
renderPass.colorAttachments[0].clearColor = MBEClearColor;
renderPass.depthAttachment.texture = self.depthTexture;
renderPass.depthAttachment.loadAction = MTLLoadActionClear;
renderPass.depthAttachment.storeAction = MTLStoreActionStore;
renderPass.depthAttachment.clearDepth = 1.0;
return renderPass;
}
所以基本上,似乎两个不同的渲染阶段需要两个不同的互斥条件。如果一个工作,另一个不工作,反之亦然。看起来不可能,说真的,我该怎么办?什么给了?
【问题讨论】:
标签: objective-c metal