Skip to content

Commit

Permalink
Merge pull request #1885 from billhollings/fix-mtl-valid-err-depth-sw…
Browse files Browse the repository at this point in the history
…izzle

Avoid Metal validation warning when depth component swizzled away
  • Loading branch information
billhollings authored May 4, 2023
2 parents d2f57fc + 789d432 commit 53a4eb2
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions MoltenVK/MoltenVK/GPUObjects/MVKRenderPass.mm
Original file line number Diff line number Diff line change
Expand Up @@ -705,23 +705,29 @@
bool storeOverride) {
// 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,
// 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();
MVKPixelFormats* pixFmts = _renderPass->getPixelFormats();
bool isDepthFormat = pixFmts->isDepthFormat(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 isMemorylessAttachment = false;
#if MVK_APPLE_SILICON
isMemorylessAttachment = attachment->getMTLTexture().storageMode == MTLStorageModeMemoryless;
#endif
MTLStoreAction storeAction = getMTLStoreAction(subpass, isRenderingEntireAttachment, isMemorylessAttachment, hasResolveAttachment, canResolveFormat, isStencil, storeOverride);

MTLStoreAction storeAction = getMTLStoreAction(subpass, isRenderingEntireAttachment, isMemorylessAttachment,
hasResolveAttachment, canResolveFormat, isStencil, storeOverride);
if (isColorFormat) {
[cmdEncoder->_mtlRenderEncoder setColorStoreAction: storeAction atIndex: caIdx];
} else if (isDepthFormat && !isStencil) {
[cmdEncoder->_mtlRenderEncoder setDepthStoreAction: storeAction];
[cmdEncoder->_mtlRenderEncoder setDepthStoreAction: (isDepthSwizzled ? MTLStoreActionDontCare : storeAction)];
} else if (isStencilFormat && isStencil) {
[cmdEncoder->_mtlRenderEncoder setStencilStoreAction: storeAction];
}
Expand Down

0 comments on commit 53a4eb2

Please sign in to comment.