diff --git a/lib/graphicsdev/Vulkan.cpp b/lib/graphicsdev/Vulkan.cpp index 648e60c..75f9774 100644 --- a/lib/graphicsdev/Vulkan.cpp +++ b/lib/graphicsdev/Vulkan.cpp @@ -702,6 +702,7 @@ struct VulkanPool : IGraphicsBufferPool { VkDeviceMemory m_bufMem = VK_NULL_HANDLE; std::unique_ptr m_buffer; + bool m_dead = false; Buffer(VkDeviceMemory mem, class VulkanGraphicsBufferD* buf) : m_bufMem(mem), m_buffer(buf) {} }; @@ -714,6 +715,21 @@ struct VulkanPool : IGraphicsBufferPool if (buf.second.m_bufMem) vk::FreeMemory(m_ctx->m_dev, buf.second.m_bufMem, nullptr); } + + void clearDeadBuffers() + { + for (auto it = m_DBufs.begin() ; it != m_DBufs.end() ;) + { + if (it->second.m_dead) + { + if (it->second.m_bufMem) + vk::FreeMemory(m_ctx->m_dev, it->second.m_bufMem, nullptr); + it = m_DBufs.erase(it); + continue; + } + ++it; + } + } }; static const VkBufferUsageFlagBits USE_TABLE[] = @@ -3264,7 +3280,9 @@ IGraphicsBufferD* VulkanDataFactory::newPoolBuffer(IGraphicsBufferPool* p, Buffe void VulkanDataFactory::deletePoolBuffer(IGraphicsBufferPool* p, IGraphicsBufferD* buf) { VulkanPool* pool = static_cast(p); - pool->m_DBufs.erase(static_cast(buf)); + auto search = pool->m_DBufs.find(static_cast(buf)); + if (search != pool->m_DBufs.end()) + search->second.m_dead = true; } GraphicsBufferPoolToken VulkanDataFactory::newBufferPool() @@ -3357,6 +3375,10 @@ void VulkanCommandQueue::execute() delete p; continue; } + else + { + (*it)->clearDeadBuffers(); + } ++it; } datalk.unlock(); diff --git a/lib/win/WindowWin32.cpp b/lib/win/WindowWin32.cpp index e1d5569..46b6a07 100644 --- a/lib/win/WindowWin32.cpp +++ b/lib/win/WindowWin32.cpp @@ -393,7 +393,7 @@ struct GraphicsContextWin32Vulkan : GraphicsContextWin32 HWND m_hwnd; VulkanContext* m_ctx; VkSurfaceKHR m_surface = VK_NULL_HANDLE; - VkFormat m_format; + VkFormat m_format = VK_FORMAT_UNDEFINED; VkColorSpaceKHR m_colorspace; uint32_t m_sampleCount; @@ -577,15 +577,23 @@ public: * supported format will be returned. */ if (formatCount >= 1) { - if (surfFormats[0].format == VK_FORMAT_UNDEFINED) - m_format = VK_FORMAT_B8G8R8A8_UNORM; - else - m_format = surfFormats[0].format; - m_colorspace = surfFormats[0].colorSpace; + for (int i=0 ; iinitSwapChain(*m_windowCtx, m_surface, m_format, m_colorspace); m_dataFactory = new class VulkanDataFactory(this, m_ctx, m_sampleCount); diff --git a/lib/x11/WindowXlib.cpp b/lib/x11/WindowXlib.cpp index 801d80e..fad2a5e 100644 --- a/lib/x11/WindowXlib.cpp +++ b/lib/x11/WindowXlib.cpp @@ -763,15 +763,23 @@ public: * supported format will be returned. */ if (formatCount >= 1) { - if (surfFormats[0].format == VK_FORMAT_UNDEFINED) - m_format = VK_FORMAT_B8G8R8A8_UNORM; - else - m_format = surfFormats[0].format; - m_colorspace = surfFormats[0].colorSpace; + for (int i=0 ; iinitSwapChain(*m_windowCtx, m_surface, m_format, m_colorspace); /* Spawn vsync thread */