From 9af8ec3d23d9cb412b6fb44b4a6ab9041c41f4ff Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Wed, 15 Feb 2017 13:10:30 -1000 Subject: [PATCH] Vulkan Win32 fixes --- glslang | 2 +- lib/graphicsdev/Vulkan.cpp | 101 +++++++++++++++++++------------------ lib/win/WindowWin32.cpp | 3 +- 3 files changed, 56 insertions(+), 50 deletions(-) diff --git a/glslang b/glslang index bfaf8fe..6a0bc97 160000 --- a/glslang +++ b/glslang @@ -1 +1 @@ -Subproject commit bfaf8feb90e0727acfcc913cc64bcb14058629e1 +Subproject commit 6a0bc978795300252ed776b482770f8403a88925 diff --git a/lib/graphicsdev/Vulkan.cpp b/lib/graphicsdev/Vulkan.cpp index eddf735..6d5073f 100644 --- a/lib/graphicsdev/Vulkan.cpp +++ b/lib/graphicsdev/Vulkan.cpp @@ -101,59 +101,53 @@ static void SetImageLayout(VkCommandBuffer cmd, VkImage image, imageMemoryBarrier.subresourceRange.levelCount = mipCount; imageMemoryBarrier.subresourceRange.layerCount = layerCount; - if (old_image_layout == VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL) { + switch (old_image_layout) + { + case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL: imageMemoryBarrier.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | VK_ACCESS_COLOR_ATTACHMENT_READ_BIT; + break; + case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL: + imageMemoryBarrier.srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT; + break; + case VK_IMAGE_LAYOUT_PREINITIALIZED: + imageMemoryBarrier.srcAccessMask = VK_ACCESS_HOST_WRITE_BIT; + break; + case VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL: + imageMemoryBarrier.srcAccessMask = VK_ACCESS_TRANSFER_READ_BIT; + break; + case VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL: + imageMemoryBarrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT; + break; + case VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL: + imageMemoryBarrier.srcAccessMask = VK_ACCESS_SHADER_READ_BIT; + break; + default: break; } - if (old_image_layout == VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL) { - imageMemoryBarrier.srcAccessMask = - VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT; - } - - if (old_image_layout == VK_IMAGE_LAYOUT_PREINITIALIZED) { - imageMemoryBarrier.srcAccessMask = - VK_ACCESS_HOST_WRITE_BIT; - } - - if (old_image_layout == VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL) { - imageMemoryBarrier.srcAccessMask = - VK_ACCESS_TRANSFER_READ_BIT; - } - - if (old_image_layout == VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL) { - imageMemoryBarrier.srcAccessMask = - VK_ACCESS_TRANSFER_WRITE_BIT; - } - - if (old_image_layout == VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL) { - imageMemoryBarrier.srcAccessMask = - VK_ACCESS_SHADER_READ_BIT; - } - - if (new_image_layout == VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL) { - /* Make sure anything that was copying from this image has completed */ + switch (new_image_layout) + { + case VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL: imageMemoryBarrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT; - } - - if (new_image_layout == VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL) { - /* Make sure anything that was copying from this image has completed */ + break; + case VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL: imageMemoryBarrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT; - } - - if (new_image_layout == VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL) { - /* Make sure any Copy or CPU writes to image are flushed */ + break; + case VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL: imageMemoryBarrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT; - } - - if (new_image_layout == VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL) { + break; + case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL: imageMemoryBarrier.dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | VK_ACCESS_COLOR_ATTACHMENT_READ_BIT; - } - - if (new_image_layout == VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL) { + break; + case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL: imageMemoryBarrier.dstAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT; + break; + case VK_IMAGE_LAYOUT_PRESENT_SRC_KHR: + imageMemoryBarrier.dstAccessMask = VK_ACCESS_MEMORY_READ_BIT; + break; + default: break; } VkPipelineStageFlags src_stages = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; @@ -410,7 +404,7 @@ void VulkanContext::initDevice() void VulkanContext::initSwapChain(VulkanContext::Window& windowCtx, VkSurfaceKHR surface, VkFormat format, VkColorSpaceKHR colorspace) { - m_displayFormat = VK_FORMAT_B8G8R8A8_UNORM; + m_displayFormat = format; VkSurfaceCapabilitiesKHR surfCapabilities; ThrowIfFailed(vk::GetPhysicalDeviceSurfaceCapabilitiesKHR(m_gpus[0], surface, &surfCapabilities)); @@ -2373,7 +2367,8 @@ struct VulkanCommandQueue : IGraphicsCommandQueue { if (m_boundTarget) { - VkViewport vp = {float(rect.location[0]), float(m_boundTarget->m_height - rect.location[1] - rect.size[1]), + VkViewport vp = {float(rect.location[0]), + float(std::max(0, int(m_boundTarget->m_height) - rect.location[1] - rect.size[1])), float(rect.size[0]), float(rect.size[1]), znear, zfar}; vk::CmdSetViewport(m_cmdBufs[m_fillBuf], 0, 1, &vp); } @@ -2385,7 +2380,8 @@ struct VulkanCommandQueue : IGraphicsCommandQueue { VkRect2D vkrect = { - {int32_t(rect.location[0]), int32_t(m_boundTarget->m_height - rect.location[1] - rect.size[1])}, + {int32_t(rect.location[0]), + int32_t(std::max(0, int(m_boundTarget->m_height) - rect.location[1] - rect.size[1]))}, {uint32_t(rect.size[0]), uint32_t(rect.size[1])} }; vk::CmdSetScissor(m_cmdBufs[m_fillBuf], 0, 1, &vkrect); @@ -2820,10 +2816,8 @@ void VulkanDataFactory::destroyData(IGraphicsData* d) void VulkanDataFactory::destroyPool(IGraphicsBufferPool* p) { - std::unique_lock lk(m_committedMutex); VulkanPool* pool = static_cast(p); - m_committedPools.erase(pool); - delete pool; + pool->m_dead = true; } void VulkanDataFactory::destroyAllData() @@ -3326,6 +3320,17 @@ void VulkanCommandQueue::execute() } ++it; } + for (auto it = gfxF->m_committedPools.begin() ; it != gfxF->m_committedPools.end() ;) + { + if ((*it)->m_dead) + { + VulkanPool* p = *it; + it = gfxF->m_committedPools.erase(it); + delete p; + continue; + } + ++it; + } datalk.unlock(); /* Perform texture resizes */ diff --git a/lib/win/WindowWin32.cpp b/lib/win/WindowWin32.cpp index 4868399..3fe9bcd 100644 --- a/lib/win/WindowWin32.cpp +++ b/lib/win/WindowWin32.cpp @@ -450,7 +450,8 @@ public: if (m_vsyncRunning) { m_vsyncRunning = false; - m_vsyncThread.join(); + if (m_vsyncThread.joinable()) + m_vsyncThread.join(); } m_ctx->m_windows.erase(m_parentWindow);