From a8e7f381508c7602bf9f281f0e5171e29abf4cfe Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Fri, 19 Apr 2019 23:56:54 +0200 Subject: [PATCH] - minor code cleanup --- .../vulkan/system/vk_framebuffer.cpp | 25 +++++++++---------- src/rendering/vulkan/system/vk_framebuffer.h | 9 ++++--- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/rendering/vulkan/system/vk_framebuffer.cpp b/src/rendering/vulkan/system/vk_framebuffer.cpp index 66d644301..cff8a446a 100644 --- a/src/rendering/vulkan/system/vk_framebuffer.cpp +++ b/src/rendering/vulkan/system/vk_framebuffer.cpp @@ -87,6 +87,9 @@ VulkanFrameBuffer::VulkanFrameBuffer(void *hMonitor, bool fullscreen, VulkanDevi for (auto &fence : mSubmitFence) fence.reset(new VulkanFence(device)); + for (int i = 0; i < maxConcurrentSubmitCount; i++) + mSubmitWaitFences[i] = mSubmitFence[i]->fence; + InitPalette(); } @@ -192,9 +195,9 @@ void VulkanFrameBuffer::DeleteFrameObjects() void VulkanFrameBuffer::FlushCommands(VulkanCommandBuffer **commands, size_t count, bool finish) { - int currentIndex = nextSubmitQueue % submitQueueSize; + int currentIndex = mNextSubmit % maxConcurrentSubmitCount; - if (nextSubmitQueue >= submitQueueSize) + if (mNextSubmit >= maxConcurrentSubmitCount) { vkWaitForFences(device->device, 1, &mSubmitFence[currentIndex]->fence, VK_TRUE, std::numeric_limits::max()); vkResetFences(device->device, 1, &mSubmitFence[currentIndex]->fence); @@ -205,8 +208,8 @@ void VulkanFrameBuffer::FlushCommands(VulkanCommandBuffer **commands, size_t cou for (size_t i = 0; i < count; i++) submit.addCommandBuffer(commands[i]); - if (nextSubmitQueue > 0) - submit.addWait(VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, mSubmitSemaphore[(nextSubmitQueue - 1) % submitQueueSize].get()); + if (mNextSubmit > 0) + submit.addWait(VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, mSubmitSemaphore[(mNextSubmit - 1) % maxConcurrentSubmitCount].get()); if (finish && presentImageIndex != 0xffffffff) { @@ -216,7 +219,7 @@ void VulkanFrameBuffer::FlushCommands(VulkanCommandBuffer **commands, size_t cou submit.addSignal(mSubmitSemaphore[currentIndex].get()); submit.execute(device, device->graphicsQueue, mSubmitFence[currentIndex].get()); - nextSubmitQueue++; + mNextSubmit++; } void VulkanFrameBuffer::FlushCommands(bool finish) @@ -268,16 +271,12 @@ void VulkanFrameBuffer::WaitForCommands(bool finish) swapChain->QueuePresent(presentImageIndex, mRenderFinishedSemaphore.get()); } - VkFence waitFences[submitQueueSize]; - for (int i = 0; i < submitQueueSize; i++) - waitFences[i] = mSubmitFence[i]->fence; - - int numWaitFences = MIN(nextSubmitQueue, (int)submitQueueSize); - vkWaitForFences(device->device, numWaitFences, waitFences, VK_TRUE, std::numeric_limits::max()); - vkResetFences(device->device, numWaitFences, waitFences); + int numWaitFences = MIN(mNextSubmit, (int)maxConcurrentSubmitCount); + vkWaitForFences(device->device, numWaitFences, mSubmitWaitFences, VK_TRUE, std::numeric_limits::max()); + vkResetFences(device->device, numWaitFences, mSubmitWaitFences); DeleteFrameObjects(); - nextSubmitQueue = 0; + mNextSubmit = 0; if (finish) { diff --git a/src/rendering/vulkan/system/vk_framebuffer.h b/src/rendering/vulkan/system/vk_framebuffer.h index 9c5623471..5bdbc820d 100644 --- a/src/rendering/vulkan/system/vk_framebuffer.h +++ b/src/rendering/vulkan/system/vk_framebuffer.h @@ -125,10 +125,11 @@ private: std::unique_ptr mDrawCommands; - enum { submitQueueSize = 8}; - std::unique_ptr mSubmitSemaphore[submitQueueSize]; - std::unique_ptr mSubmitFence[submitQueueSize]; - int nextSubmitQueue = 0; + enum { maxConcurrentSubmitCount = 8}; + std::unique_ptr mSubmitSemaphore[maxConcurrentSubmitCount]; + std::unique_ptr mSubmitFence[maxConcurrentSubmitCount]; + VkFence mSubmitWaitFences[maxConcurrentSubmitCount]; + int mNextSubmit = 0; std::unique_ptr mSwapChainImageAvailableSemaphore; std::unique_ptr mRenderFinishedSemaphore;