From 6f168f0ca24f4cf059a0235c8339ea9d102004d5 Mon Sep 17 00:00:00 2001 From: Attila Kocsis Date: Mon, 10 Feb 2020 20:19:03 +0100 Subject: [PATCH] Metal: Fixed msaa capture --- src/renderer_mtl.mm | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/src/renderer_mtl.mm b/src/renderer_mtl.mm index ea822b853..b48232580 100644 --- a/src/renderer_mtl.mm +++ b/src/renderer_mtl.mm @@ -540,6 +540,12 @@ namespace bgfx { namespace mtl || BX_ENABLED(BX_PLATFORM_OSX) || (BX_ENABLED(BX_PLATFORM_IOS) && iOSVersionEqualOrGreater("9.0.0") ) ; + + m_hasStoreActionStoreAndMultisampleResolve = false + || (BX_ENABLED(BX_PLATFORM_OSX) && macOSVersionEqualOrGreater(10,12,0)) + || (BX_ENABLED(BX_PLATFORM_IOS) && iOSVersionEqualOrGreater("10.0.0") ) + ; + m_macOS11Runtime = true && BX_ENABLED(BX_PLATFORM_OSX) && macOSVersionEqualOrGreater(10,11,0) @@ -1333,6 +1339,9 @@ namespace bgfx { namespace mtl if (NULL != desc.texture) { desc.loadAction = MTLLoadActionLoad; + desc.storeAction = desc.resolveTexture == nil ? + MTLStoreActionStore : + MTLStoreActionMultisampleResolve; } } @@ -1340,14 +1349,18 @@ namespace bgfx { namespace mtl if (NULL != depthAttachment.texture) { depthAttachment.loadAction = MTLLoadActionLoad; - depthAttachment.storeAction = MTLStoreActionStore; + depthAttachment.storeAction = depthAttachment.resolveTexture == nil ? + MTLStoreActionStore : + MTLStoreActionMultisampleResolve; } RenderPassStencilAttachmentDescriptor stencilAttachment = renderPassDescriptor.stencilAttachment; if (NULL != stencilAttachment.texture) { stencilAttachment.loadAction = MTLLoadActionLoad; - stencilAttachment.storeAction = MTLStoreActionStore; + stencilAttachment.storeAction = stencilAttachment.resolveTexture == nil ? + MTLStoreActionStore : + MTLStoreActionMultisampleResolve; } m_renderCommandEncoder = m_commandBuffer.renderCommandEncoderWithDescriptor(renderPassDescriptor); @@ -2292,6 +2305,7 @@ namespace bgfx { namespace mtl bool m_iOS9Runtime; bool m_macOS11Runtime; bool m_hasPixelFormatDepth32Float_Stencil8; + bool m_hasStoreActionStoreAndMultisampleResolve; Buffer m_uniformBuffer; Buffer m_uniformBuffers[MTL_MAX_FRAMES_IN_FLIGHT]; @@ -3891,7 +3905,17 @@ namespace bgfx { namespace mtl desc.loadAction = MTLLoadActionLoad; } - desc.storeAction = desc.texture.sampleCount > 1 ? MTLStoreActionMultisampleResolve : MTLStoreActionStore; + if ( NULL != m_capture && + !isValid(fbh) && + m_hasStoreActionStoreAndMultisampleResolve) + { + desc.storeAction = desc.texture.sampleCount > 1 ? MTLStoreActionStoreAndMultisampleResolve : MTLStoreActionStore; + + } + else + { + desc.storeAction = desc.texture.sampleCount > 1 ? MTLStoreActionMultisampleResolve : MTLStoreActionStore; + } } }