More Vulkan fixes

This commit is contained in:
Jack Andersen 2017-02-15 18:47:31 -10:00
parent 3197142d1f
commit 71593afe50
3 changed files with 50 additions and 12 deletions

View File

@ -702,6 +702,7 @@ struct VulkanPool : IGraphicsBufferPool
{ {
VkDeviceMemory m_bufMem = VK_NULL_HANDLE; VkDeviceMemory m_bufMem = VK_NULL_HANDLE;
std::unique_ptr<class VulkanGraphicsBufferD> m_buffer; std::unique_ptr<class VulkanGraphicsBufferD> m_buffer;
bool m_dead = false;
Buffer(VkDeviceMemory mem, class VulkanGraphicsBufferD* buf) Buffer(VkDeviceMemory mem, class VulkanGraphicsBufferD* buf)
: m_bufMem(mem), m_buffer(buf) {} : m_bufMem(mem), m_buffer(buf) {}
}; };
@ -714,6 +715,21 @@ struct VulkanPool : IGraphicsBufferPool
if (buf.second.m_bufMem) if (buf.second.m_bufMem)
vk::FreeMemory(m_ctx->m_dev, buf.second.m_bufMem, nullptr); 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[] = static const VkBufferUsageFlagBits USE_TABLE[] =
@ -3264,7 +3280,9 @@ IGraphicsBufferD* VulkanDataFactory::newPoolBuffer(IGraphicsBufferPool* p, Buffe
void VulkanDataFactory::deletePoolBuffer(IGraphicsBufferPool* p, IGraphicsBufferD* buf) void VulkanDataFactory::deletePoolBuffer(IGraphicsBufferPool* p, IGraphicsBufferD* buf)
{ {
VulkanPool* pool = static_cast<VulkanPool*>(p); VulkanPool* pool = static_cast<VulkanPool*>(p);
pool->m_DBufs.erase(static_cast<VulkanGraphicsBufferD*>(buf)); auto search = pool->m_DBufs.find(static_cast<VulkanGraphicsBufferD*>(buf));
if (search != pool->m_DBufs.end())
search->second.m_dead = true;
} }
GraphicsBufferPoolToken VulkanDataFactory::newBufferPool() GraphicsBufferPoolToken VulkanDataFactory::newBufferPool()
@ -3357,6 +3375,10 @@ void VulkanCommandQueue::execute()
delete p; delete p;
continue; continue;
} }
else
{
(*it)->clearDeadBuffers();
}
++it; ++it;
} }
datalk.unlock(); datalk.unlock();

View File

@ -393,7 +393,7 @@ struct GraphicsContextWin32Vulkan : GraphicsContextWin32
HWND m_hwnd; HWND m_hwnd;
VulkanContext* m_ctx; VulkanContext* m_ctx;
VkSurfaceKHR m_surface = VK_NULL_HANDLE; VkSurfaceKHR m_surface = VK_NULL_HANDLE;
VkFormat m_format; VkFormat m_format = VK_FORMAT_UNDEFINED;
VkColorSpaceKHR m_colorspace; VkColorSpaceKHR m_colorspace;
uint32_t m_sampleCount; uint32_t m_sampleCount;
@ -577,15 +577,23 @@ public:
* supported format will be returned. */ * supported format will be returned. */
if (formatCount >= 1) if (formatCount >= 1)
{ {
if (surfFormats[0].format == VK_FORMAT_UNDEFINED) for (int i=0 ; i<formatCount ; ++i)
m_format = VK_FORMAT_B8G8R8A8_UNORM; {
else if (surfFormats[i].format == VK_FORMAT_B8G8R8A8_UNORM ||
m_format = surfFormats[0].format; surfFormats[i].format == VK_FORMAT_R8G8B8A8_UNORM)
m_colorspace = surfFormats[0].colorSpace; {
m_format = surfFormats[i].format;
m_colorspace = surfFormats[i].colorSpace;
}
break;
}
} }
else else
Log.report(logvisor::Fatal, "no surface formats available for Vulkan swapchain"); Log.report(logvisor::Fatal, "no surface formats available for Vulkan swapchain");
if (m_format == VK_FORMAT_UNDEFINED)
Log.report(logvisor::Fatal, "no UNORM formats available for Vulkan swapchain");
m_ctx->initSwapChain(*m_windowCtx, m_surface, m_format, m_colorspace); m_ctx->initSwapChain(*m_windowCtx, m_surface, m_format, m_colorspace);
m_dataFactory = new class VulkanDataFactory(this, m_ctx, m_sampleCount); m_dataFactory = new class VulkanDataFactory(this, m_ctx, m_sampleCount);

View File

@ -763,15 +763,23 @@ public:
* supported format will be returned. */ * supported format will be returned. */
if (formatCount >= 1) if (formatCount >= 1)
{ {
if (surfFormats[0].format == VK_FORMAT_UNDEFINED) for (int i=0 ; i<formatCount ; ++i)
m_format = VK_FORMAT_B8G8R8A8_UNORM; {
else if (surfFormats[i].format == VK_FORMAT_B8G8R8A8_UNORM ||
m_format = surfFormats[0].format; surfFormats[i].format == VK_FORMAT_R8G8B8A8_UNORM)
m_colorspace = surfFormats[0].colorSpace; {
m_format = surfFormats[i].format;
m_colorspace = surfFormats[i].colorSpace;
}
break;
}
} }
else else
Log.report(logvisor::Fatal, "no surface formats available for Vulkan swapchain"); Log.report(logvisor::Fatal, "no surface formats available for Vulkan swapchain");
if (m_format == VK_FORMAT_UNDEFINED)
Log.report(logvisor::Fatal, "no UNORM formats available for Vulkan swapchain");
m_ctx->initSwapChain(*m_windowCtx, m_surface, m_format, m_colorspace); m_ctx->initSwapChain(*m_windowCtx, m_surface, m_format, m_colorspace);
/* Spawn vsync thread */ /* Spawn vsync thread */