diff --git a/filament/backend/src/vulkan/VulkanCommands.cpp b/filament/backend/src/vulkan/VulkanCommands.cpp index 39674fc0b44d..f5b8e9029ab8 100644 --- a/filament/backend/src/vulkan/VulkanCommands.cpp +++ b/filament/backend/src/vulkan/VulkanCommands.cpp @@ -268,13 +268,18 @@ bool VulkanCommands::flush() { VK_NULL_HANDLE, VK_NULL_HANDLE, }; - + uint32_t waitSemaphoreCount = 0; + if (mSubmissionSignal) { + signals[waitSemaphoreCount++] = mSubmissionSignal; + } + if (mInjectedSignal) { + signals[waitSemaphoreCount++] = mInjectedSignal; + } VkCommandBuffer const cmdbuffer = currentbuf->buffer(); - VkSubmitInfo submitInfo{ .sType = VK_STRUCTURE_TYPE_SUBMIT_INFO, - .waitSemaphoreCount = 0, - .pWaitSemaphores = signals, + .waitSemaphoreCount = waitSemaphoreCount, + .pWaitSemaphores = waitSemaphoreCount > 0 ? signals : nullptr, .pWaitDstStageMask = waitDestStageMasks, .commandBufferCount = 1, .pCommandBuffers = &cmdbuffer, @@ -282,19 +287,6 @@ bool VulkanCommands::flush() { .pSignalSemaphores = &renderingFinished, }; - if (mSubmissionSignal) { - signals[submitInfo.waitSemaphoreCount++] = mSubmissionSignal; - } - - if (mInjectedSignal) { - signals[submitInfo.waitSemaphoreCount++] = mInjectedSignal; - } - - // To address a validation warning. - if (submitInfo.waitSemaphoreCount == 0) { - submitInfo.pWaitSemaphores = VK_NULL_HANDLE; - } - #if FVK_ENABLED(FVK_DEBUG_COMMAND_BUFFER) slog.i << "Submitting cmdbuffer=" << cmdbuffer << " wait=(" << signals[0] << ", " << signals[1] << ") " diff --git a/filament/backend/src/vulkan/VulkanSwapChain.cpp b/filament/backend/src/vulkan/VulkanSwapChain.cpp index e85844f951a5..af18e36fcc61 100644 --- a/filament/backend/src/vulkan/VulkanSwapChain.cpp +++ b/filament/backend/src/vulkan/VulkanSwapChain.cpp @@ -99,11 +99,16 @@ void VulkanSwapChain::present() { mColors[mCurrentSwapIndex]->transitionLayout(cmdbuf, subresources, VulkanLayout::PRESENT); } mCommands->flush(); - VkSemaphore const finishedDrawing = mCommands->acquireFinishedSignal(); - VkResult const result = mPlatform->present(swapChain, mCurrentSwapIndex, finishedDrawing); - ASSERT_POSTCONDITION(result == VK_SUCCESS || result == VK_SUBOPTIMAL_KHR - || result == VK_ERROR_OUT_OF_DATE_KHR, - "Cannot present in swapchain."); + + // We only present if it is not headless. No-op for headless (but note that we still need the + // flush() in the above line). + if (!mHeadless) { + VkSemaphore const finishedDrawing = mCommands->acquireFinishedSignal(); + VkResult const result = mPlatform->present(swapChain, mCurrentSwapIndex, finishedDrawing); + ASSERT_POSTCONDITION(result == VK_SUCCESS || result == VK_SUBOPTIMAL_KHR || + result == VK_ERROR_OUT_OF_DATE_KHR, + "Cannot present in swapchain."); + } // We presented the last acquired buffer. mAcquired = false;