From 2037b6c007d9e3018a2e78b5e21f8a44f2c0ff9d Mon Sep 17 00:00:00 2001 From: Bill Hollings Date: Thu, 2 Apr 2020 12:54:57 -0400 Subject: [PATCH] Defer resetting MTLTexture in MVKSwapchainImage until request to acquire. Move call to MVKSwapchainImage::resetMetalDrawable() from immediately after presentation until request to acquire, to preserve image content for copying after presentation in cases such as an app screen capture operation. Testing indicates this deferral has little or no adverse effect on the performance of retrieving the drawable when next needed. --- MoltenVK/MoltenVK/GPUObjects/MVKImage.mm | 1 - MoltenVK/MoltenVK/GPUObjects/MVKSwapchain.mm | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/MoltenVK/MoltenVK/GPUObjects/MVKImage.mm b/MoltenVK/MoltenVK/GPUObjects/MVKImage.mm index 47208f6bd..4a226d94d 100644 --- a/MoltenVK/MoltenVK/GPUObjects/MVKImage.mm +++ b/MoltenVK/MoltenVK/GPUObjects/MVKImage.mm @@ -958,7 +958,6 @@ [mtlCmdBuff presentDrawable: getCAMetalDrawable()]; if (scName) { mvkPopDebugGroup(mtlCmdBuff); } - resetMetalDrawable(); signalPresentationSemaphore(mtlCmdBuff); retain(); // Ensure this image is not destroyed while awaiting MTLCommandBuffer completion diff --git a/MoltenVK/MoltenVK/GPUObjects/MVKSwapchain.mm b/MoltenVK/MoltenVK/GPUObjects/MVKSwapchain.mm index 9bc255f83..b93d3b94d 100644 --- a/MoltenVK/MoltenVK/GPUObjects/MVKSwapchain.mm +++ b/MoltenVK/MoltenVK/GPUObjects/MVKSwapchain.mm @@ -97,6 +97,7 @@ // Return the index of the image with the shortest wait and signal the semaphore and fence when it's available *pImageIndex = minWaitImage->_swapchainIndex; + minWaitImage->resetMetalDrawable(); minWaitImage->signalWhenAvailable((MVKSemaphore*)semaphore, (MVKFence*)fence); return getHasSurfaceSizeChanged() ? VK_ERROR_OUT_OF_DATE_KHR : VK_SUCCESS;