diff --git a/src/rendering/vulkan/system/vk_framebuffer.cpp b/src/rendering/vulkan/system/vk_framebuffer.cpp index ae1e8b110b..2f4dc24d71 100644 --- a/src/rendering/vulkan/system/vk_framebuffer.cpp +++ b/src/rendering/vulkan/system/vk_framebuffer.cpp @@ -66,6 +66,7 @@ VulkanFrameBuffer::~VulkanFrameBuffer() void VulkanFrameBuffer::InitializeState() { + mUploadSemaphore.reset(new VulkanSemaphore(device)); mGraphicsCommandPool.reset(new VulkanCommandPool(device, device->graphicsFamily)); mVertexData = new FFlatVertexBuffer(GetWidth(), GetHeight()); @@ -109,21 +110,51 @@ void VulkanFrameBuffer::Update() mPresentCommands->end(); - VkSemaphore waitSemaphores[] = { device->imageAvailableSemaphore->semaphore }; - VkPipelineStageFlags waitStages[] = { VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT }; + if (mUploadCommands) + { + // Submit upload commands immediately + VkSubmitInfo submitInfo = {}; + submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; + submitInfo.commandBufferCount = 1; + submitInfo.pCommandBuffers = &mUploadCommands->buffer; + submitInfo.signalSemaphoreCount = 1; + submitInfo.pSignalSemaphores = &mUploadSemaphore->semaphore; + VkResult result = vkQueueSubmit(device->graphicsQueue, 1, &submitInfo, VK_NULL_HANDLE); + if (result != VK_SUCCESS) + I_FatalError("Failed to submit command buffer!\n"); - VkSubmitInfo submitInfo = {}; - submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; - submitInfo.waitSemaphoreCount = 1; - submitInfo.pWaitSemaphores = waitSemaphores; - submitInfo.pWaitDstStageMask = waitStages; - submitInfo.commandBufferCount = 1; - submitInfo.pCommandBuffers = &mPresentCommands->buffer; - submitInfo.signalSemaphoreCount = 1; - submitInfo.pSignalSemaphores = &device->renderFinishedSemaphore->semaphore; - VkResult result = vkQueueSubmit(device->graphicsQueue, 1, &submitInfo, device->renderFinishedFence->fence); - if (result != VK_SUCCESS) - I_FatalError("Failed to submit command buffer!\n"); + // Wait for upload commands to finish, then submit render commands + VkSemaphore waitSemaphores[] = { mUploadSemaphore->semaphore, device->imageAvailableSemaphore->semaphore }; + VkPipelineStageFlags waitStages[] = { VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT }; + submitInfo.waitSemaphoreCount = 2; + submitInfo.pWaitSemaphores = waitSemaphores; + submitInfo.pWaitDstStageMask = waitStages; + submitInfo.commandBufferCount = 1; + submitInfo.pCommandBuffers = &mPresentCommands->buffer; + submitInfo.signalSemaphoreCount = 1; + submitInfo.pSignalSemaphores = &device->renderFinishedSemaphore->semaphore; + result = vkQueueSubmit(device->graphicsQueue, 1, &submitInfo, device->renderFinishedFence->fence); + if (result != VK_SUCCESS) + I_FatalError("Failed to submit command buffer!\n"); + } + else + { + VkSemaphore waitSemaphores[] = { device->imageAvailableSemaphore->semaphore }; + VkPipelineStageFlags waitStages[] = { VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT }; + + VkSubmitInfo submitInfo = {}; + submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; + submitInfo.waitSemaphoreCount = 1; + submitInfo.pWaitSemaphores = waitSemaphores; + submitInfo.pWaitDstStageMask = waitStages; + submitInfo.commandBufferCount = 1; + submitInfo.pCommandBuffers = &mPresentCommands->buffer; + submitInfo.signalSemaphoreCount = 1; + submitInfo.pSignalSemaphores = &device->renderFinishedSemaphore->semaphore; + VkResult result = vkQueueSubmit(device->graphicsQueue, 1, &submitInfo, device->renderFinishedFence->fence); + if (result != VK_SUCCESS) + I_FatalError("Failed to submit command buffer!\n"); + } Flush3D.Unclock(); diff --git a/src/rendering/vulkan/system/vk_framebuffer.h b/src/rendering/vulkan/system/vk_framebuffer.h index 8780fdb86c..401b8f8578 100644 --- a/src/rendering/vulkan/system/vk_framebuffer.h +++ b/src/rendering/vulkan/system/vk_framebuffer.h @@ -68,6 +68,7 @@ private: std::unique_ptr mGraphicsCommandPool; std::unique_ptr mUploadCommands; std::unique_ptr mPresentCommands; + std::unique_ptr mUploadSemaphore; std::unique_ptr mRenderState; int camtexcount = 0;