Skip to content

Commit 1e40295

Browse files
committed
vk: fix leaking swapchains again (#9410)
- Adjust order of destroy call in both headless and platform swapchains. We need to be careful of the order due to assumptions made by the base class's destroy(). - remove `=0` since VulkanPlatformSwapChainBase::destroy() has an implementation. Fixes #9403
1 parent be71499 commit 1e40295

2 files changed

Lines changed: 7 additions & 4 deletions

File tree

filament/backend/src/vulkan/platform/VulkanPlatformSwapChainImpl.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,6 @@ VkResult VulkanPlatformSurfaceSwapChain::recreate() {
408408
}
409409

410410
void VulkanPlatformSurfaceSwapChain::destroy() {
411-
VulkanPlatformSwapChainBase::destroy();
412411
// The next part is not ideal. We don't have a good signal on when it's ok to destroy
413412
// a swapchain. This is a spec oversight and mentioned as much:
414413
// https://github.com/KhronosGroup/Vulkan-Docs/issues/1678
@@ -425,6 +424,8 @@ void VulkanPlatformSurfaceSwapChain::destroy() {
425424
// phone). If necessary, we can revisit and implement the workaround [1].
426425
vkQueueWaitIdle(mQueue);
427426

427+
VulkanPlatformSwapChainBase::destroy();
428+
428429
for (uint32_t i = 0; i < IMAGE_READY_SEMAPHORE_COUNT; ++i) {
429430
if (mImageReady[i] != VK_NULL_HANDLE) {
430431
vkDestroySemaphore(mDevice, mImageReady[i], VKALLOC);
@@ -475,7 +476,6 @@ VkResult VulkanPlatformHeadlessSwapChain::acquire(VulkanPlatform::ImageSyncData*
475476
}
476477

477478
void VulkanPlatformHeadlessSwapChain::destroy() {
478-
VulkanPlatformSwapChainBase::destroy();
479479
// This is only ever called from the destructor since headless does not recreate.
480480
for (auto image: mSwapChainBundle.colors) {
481481
vkDestroyImage(mDevice, image, VKALLOC);
@@ -485,7 +485,10 @@ void VulkanPlatformHeadlessSwapChain::destroy() {
485485
}
486486
}
487487
mSwapChainBundle.colors.clear();
488-
// No need to manually call through to the super because the super's destructor will be called
488+
489+
// Still need to call through to free the depth image. But must do it after releasing the color
490+
// images.
491+
VulkanPlatformSwapChainBase::destroy();
489492
}
490493

491494
}// namespace filament::backend

filament/backend/src/vulkan/platform/VulkanPlatformSwapChainImpl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ struct VulkanPlatformSwapChainBase : public Platform::SwapChain {
6262
virtual bool queryFrameTimestamps(uint64_t frameId, FrameTimestamps* outFrameTimestamps) const;
6363

6464
protected:
65-
virtual void destroy() = 0;
65+
virtual void destroy();
6666

6767
VkImage createImage(VkExtent2D extent, VkFormat format, bool isProtected);
6868

0 commit comments

Comments
 (0)