From 19afba3f718897bd91fe1be99a9b4f61f6728858 Mon Sep 17 00:00:00 2001 From: saschawillems Date: Sun, 3 Jun 2018 09:38:14 +0200 Subject: [PATCH] Base class wait fences --- base/vulkanexamplebase.cpp | 14 ++++++++++++++ base/vulkanexamplebase.h | 3 +++ 2 files changed, 17 insertions(+) diff --git a/base/vulkanexamplebase.cpp b/base/vulkanexamplebase.cpp index ff41a5b8..4ae9f396 100644 --- a/base/vulkanexamplebase.cpp +++ b/base/vulkanexamplebase.cpp @@ -188,6 +188,7 @@ void VulkanExampleBase::prepare() createCommandPool(); setupSwapChain(); createCommandBuffers(); + createSynchronizationPrimitives(); setupDepthStencil(); setupRenderPass(); createPipelineCache(); @@ -798,6 +799,9 @@ VulkanExampleBase::~VulkanExampleBase() vkDestroySemaphore(device, semaphores.presentComplete, nullptr); vkDestroySemaphore(device, semaphores.renderComplete, nullptr); vkDestroySemaphore(device, semaphores.overlayComplete, nullptr); + for (auto& fence : waitFences) { + vkDestroyFence(device, fence, nullptr); + } if (UIOverlay) { delete UIOverlay; @@ -1956,6 +1960,16 @@ void VulkanExampleBase::mouseMoved(double x, double y, bool & handled) {} void VulkanExampleBase::buildCommandBuffers() {} +void VulkanExampleBase::createSynchronizationPrimitives() +{ + // Wait fences to sync command buffer access + VkFenceCreateInfo fenceCreateInfo = vks::initializers::fenceCreateInfo(VK_FENCE_CREATE_SIGNALED_BIT); + waitFences.resize(drawCmdBuffers.size()); + for (auto& fence : waitFences) { + VK_CHECK_RESULT(vkCreateFence(device, &fenceCreateInfo, nullptr, &fence)); + } +} + void VulkanExampleBase::createCommandPool() { VkCommandPoolCreateInfo cmdPoolInfo = {}; diff --git a/base/vulkanexamplebase.h b/base/vulkanexamplebase.h index faeaafc6..a2f8d154 100644 --- a/base/vulkanexamplebase.h +++ b/base/vulkanexamplebase.h @@ -131,6 +131,7 @@ protected: // UI overlay submission and execution VkSemaphore overlayComplete; } semaphores; + std::vector waitFences; public: bool prepared = false; uint32_t width = 1280; @@ -338,6 +339,8 @@ public: // all command buffers that may reference this virtual void buildCommandBuffers(); + void createSynchronizationPrimitives(); + // Creates a new (graphics) command pool object storing command buffers void createCommandPool(); // Setup default depth and stencil views