@@ -72,7 +72,7 @@ class VulkanExample : public VulkanExampleBase
7272 // Resources for the compute part of the example
7373 // Number of compute command buffers: set to 1 for serialized processing or 2 for in-parallel with graphics queue
7474 struct Compute {
75- typedef struct ComputeSemaphores {
75+ struct ComputeSemaphores {
7676 VkSemaphore ready{ VK_NULL_HANDLE };
7777 VkSemaphore complete{ VK_NULL_HANDLE };
7878 };
@@ -683,45 +683,52 @@ class VulkanExample : public VulkanExampleBase
683683 if (!prepared)
684684 return ;
685685
686- VK_CHECK_RESULT (vkWaitForFences (device, 1 , &compute.fences [currentBuffer], VK_TRUE, UINT64_MAX));
687- VK_CHECK_RESULT (vkResetFences (device, 1 , &compute.fences [currentBuffer]));
686+ // Submit compute commands
687+ {
688+ VK_CHECK_RESULT (vkWaitForFences (device, 1 , &compute.fences [currentBuffer], VK_TRUE, UINT64_MAX));
689+ VK_CHECK_RESULT (vkResetFences (device, 1 , &compute.fences [currentBuffer]));
690+
691+ updateComputeUBO ();
692+ buildComputeCommandBuffer ();
693+
694+ VkPipelineStageFlags waitDstStageMask = VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT;
695+ VkSubmitInfo submitInfo = vks::initializers::submitInfo ();
696+ submitInfo.waitSemaphoreCount = 1 ;
697+ submitInfo.pWaitSemaphores = &compute.semaphores [((int )currentBuffer - 1 ) % maxConcurrentFrames].ready ;
698+ submitInfo.pWaitDstStageMask = &waitDstStageMask;
699+ submitInfo.signalSemaphoreCount = 1 ;
700+ submitInfo.pSignalSemaphores = &compute.semaphores [currentBuffer].complete ;
701+ submitInfo.commandBufferCount = 1 ;
702+ submitInfo.pCommandBuffers = &compute.commandBuffers [currentBuffer];
703+ VK_CHECK_RESULT (vkQueueSubmit (compute.queue , 1 , &submitInfo, compute.fences [currentBuffer]));
704+ }
688705
689- updateComputeUBO ();
690- buildComputeCommandBuffer ();
706+ // Submit graphics commands
707+ {
708+ VK_CHECK_RESULT (vkWaitForFences (device, 1 , &waitFences[currentBuffer], VK_TRUE, UINT64_MAX));
709+ VK_CHECK_RESULT (vkResetFences (device, 1 , &waitFences[currentBuffer]));
691710
692- VkPipelineStageFlags computeWaitDstStageMask = VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT;
693- VkSubmitInfo computeSubmitInfo = vks::initializers::submitInfo ();
694- computeSubmitInfo.waitSemaphoreCount = 1 ;
695- computeSubmitInfo.pWaitSemaphores = &compute.semaphores [((int )currentBuffer - 1 ) % maxConcurrentFrames].ready ;
696- computeSubmitInfo.pWaitDstStageMask = &computeWaitDstStageMask;
697- computeSubmitInfo.signalSemaphoreCount = 1 ;
698- computeSubmitInfo.pSignalSemaphores = &compute.semaphores [currentBuffer].complete ;
699- computeSubmitInfo.commandBufferCount = 1 ;
700- computeSubmitInfo.pCommandBuffers = &compute.commandBuffers [currentBuffer];
711+ VulkanExampleBase::prepareFrame (false );
701712
702- VK_CHECK_RESULT (vkQueueSubmit (compute.queue , 1 , &computeSubmitInfo, compute.fences [currentBuffer]));
713+ updateGraphicsUBO ();
714+ buildGraphicsCommandBuffer ();
703715
704- // Submit graphics commands
705- VulkanExampleBase::prepareFrame ();
706-
707- updateGraphicsUBO ();
708- buildGraphicsCommandBuffer ();
709-
710- VkPipelineStageFlags waitDstStageMask[2 ] = { VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_PIPELINE_STAGE_VERTEX_INPUT_BIT };
711- VkSemaphore waitSemaphores[2 ] = { presentCompleteSemaphores[currentBuffer], compute.semaphores [currentBuffer].complete };
712- VkSemaphore signalSemaphores[2 ] = { renderCompleteSemaphores[currentImageIndex], compute.semaphores [currentBuffer].ready };
713-
714- VkSubmitInfo submitInfo = vks::initializers::submitInfo ();
715- submitInfo.waitSemaphoreCount = 2 ;
716- submitInfo.pWaitDstStageMask = waitDstStageMask;
717- submitInfo.pWaitSemaphores = waitSemaphores;
718- submitInfo.signalSemaphoreCount = 2 ;
719- submitInfo.pSignalSemaphores = signalSemaphores;
720- submitInfo.commandBufferCount = 1 ;
721- submitInfo.pCommandBuffers = &drawCmdBuffers[currentBuffer];
722- VK_CHECK_RESULT (vkQueueSubmit (queue, 1 , &submitInfo, waitFences[currentBuffer]));
723-
724- VulkanExampleBase::submitFrame (VK_NULL_HANDLE, true );
716+ VkPipelineStageFlags waitDstStageMask[2 ] = { VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_PIPELINE_STAGE_VERTEX_INPUT_BIT };
717+ VkSemaphore waitSemaphores[2 ] = { presentCompleteSemaphores[currentBuffer], compute.semaphores [currentBuffer].complete };
718+ VkSemaphore signalSemaphores[2 ] = { renderCompleteSemaphores[currentImageIndex], compute.semaphores [currentBuffer].ready };
719+
720+ VkSubmitInfo submitInfo = vks::initializers::submitInfo ();
721+ submitInfo.waitSemaphoreCount = 2 ;
722+ submitInfo.pWaitSemaphores = waitSemaphores;
723+ submitInfo.pWaitDstStageMask = waitDstStageMask;
724+ submitInfo.commandBufferCount = 1 ;
725+ submitInfo.pCommandBuffers = &drawCmdBuffers[currentBuffer];
726+ submitInfo.signalSemaphoreCount = 2 ;
727+ submitInfo.pSignalSemaphores = signalSemaphores;
728+ VK_CHECK_RESULT (vkQueueSubmit (queue, 1 , &submitInfo, waitFences[currentBuffer]));
729+
730+ VulkanExampleBase::submitFrame (VK_NULL_HANDLE, true );
731+ }
725732 }
726733
727734 virtual void OnUpdateUIOverlay (vks::UIOverlay* overlay)
0 commit comments