Merge pull request #1885 from billhollings/fix-mtl-valid-err-depth-swizzle

Avoid Metal validation warning when depth component swizzled away
This commit is contained in:
Bill Hollings 2023-05-04 00:01:19 -04:00 committed by GitHub
commit 53a4eb26f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -705,23 +705,29 @@ void MVKAttachmentDescription::encodeStoreAction(MVKCommandEncoder* cmdEncoder,
bool storeOverride) { bool storeOverride) {
// For a combined depth-stencil format in an attachment with VK_IMAGE_ASPECT_STENCIL_BIT, // For a combined depth-stencil format in an attachment with VK_IMAGE_ASPECT_STENCIL_BIT,
// the attachment format may have been swizzled to a stencil-only format. In this case, // the attachment format may have been swizzled to a stencil-only format. In this case,
// we want to guard against an attempt to store the non-existent depth component. // we must avoid either storing, or leaving unknown, the non-existent depth component.
// We check for depth swizzling by looking at the original image format as well.
MTLPixelFormat mtlFmt = attachment->getMTLPixelFormat(); MTLPixelFormat mtlFmt = attachment->getMTLPixelFormat();
MVKPixelFormats* pixFmts = _renderPass->getPixelFormats(); MVKPixelFormats* pixFmts = _renderPass->getPixelFormats();
bool isDepthFormat = pixFmts->isDepthFormat(mtlFmt);
bool isStencilFormat = pixFmts->isStencilFormat(mtlFmt); bool isStencilFormat = pixFmts->isStencilFormat(mtlFmt);
bool isDepthFormat = pixFmts->isDepthFormat(mtlFmt);
bool isDepthSwizzled = false;
if (isStencilFormat && !isDepthFormat) {
isDepthFormat = pixFmts->isDepthFormat(attachment->getImage()->getMTLPixelFormat());
isDepthSwizzled = isDepthFormat;
}
bool isColorFormat = !(isDepthFormat || isStencilFormat); bool isColorFormat = !(isDepthFormat || isStencilFormat);
bool isMemorylessAttachment = false; bool isMemorylessAttachment = false;
#if MVK_APPLE_SILICON #if MVK_APPLE_SILICON
isMemorylessAttachment = attachment->getMTLTexture().storageMode == MTLStorageModeMemoryless; isMemorylessAttachment = attachment->getMTLTexture().storageMode == MTLStorageModeMemoryless;
#endif #endif
MTLStoreAction storeAction = getMTLStoreAction(subpass, isRenderingEntireAttachment, isMemorylessAttachment, hasResolveAttachment, canResolveFormat, isStencil, storeOverride); MTLStoreAction storeAction = getMTLStoreAction(subpass, isRenderingEntireAttachment, isMemorylessAttachment,
hasResolveAttachment, canResolveFormat, isStencil, storeOverride);
if (isColorFormat) { if (isColorFormat) {
[cmdEncoder->_mtlRenderEncoder setColorStoreAction: storeAction atIndex: caIdx]; [cmdEncoder->_mtlRenderEncoder setColorStoreAction: storeAction atIndex: caIdx];
} else if (isDepthFormat && !isStencil) { } else if (isDepthFormat && !isStencil) {
[cmdEncoder->_mtlRenderEncoder setDepthStoreAction: storeAction]; [cmdEncoder->_mtlRenderEncoder setDepthStoreAction: (isDepthSwizzled ? MTLStoreActionDontCare : storeAction)];
} else if (isStencilFormat && isStencil) { } else if (isStencilFormat && isStencil) {
[cmdEncoder->_mtlRenderEncoder setStencilStoreAction: storeAction]; [cmdEncoder->_mtlRenderEncoder setStencilStoreAction: storeAction];
} }