From 42e5407952f04fd326f680f7203ec07f52c6e79a Mon Sep 17 00:00:00 2001 From: Angelos Gkountis Date: Wed, 6 Jun 2018 14:10:33 +0100 Subject: [PATCH] Dali demo now works with the new grapics design > The Graphics api controller now accumulates all the secondary command buffers created by the SubmitCommands method. > The accumulated secondary command buffers are only submitted at the end of the frame. > This is needed because command buffers no longer reference the resources they use. > Removed the call to QueueWaitIdle at the Present method of the swapchain. This call is not needed because synchronization is handled by a fence. Change-Id: I010dfc848e009824eccaf9212a58a21c1b642d3d --- dali/graphics/vulkan/api/vulkan-api-controller.cpp | 19 ++++++++++++------- dali/graphics/vulkan/vulkan-graphics.h | 2 +- dali/graphics/vulkan/vulkan-swapchain.cpp | 6 ++---- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/dali/graphics/vulkan/api/vulkan-api-controller.cpp b/dali/graphics/vulkan/api/vulkan-api-controller.cpp index b0526ce..c07249d 100644 --- a/dali/graphics/vulkan/api/vulkan-api-controller.cpp +++ b/dali/graphics/vulkan/api/vulkan-api-controller.cpp @@ -101,7 +101,13 @@ struct Controller::Impl void EndFrame() { auto swapchain = mGraphics.GetSwapchainForFBID( 0u ); + + // execute as secondary buffers + swapchain->GetPrimaryCommandBuffer() + ->ExecuteCommands( mSecondaryCommandBufferRefs ); + swapchain->Present(); + mSecondaryCommandBufferRefs.clear(); } API::TextureFactory& GetTextureFactory() const @@ -146,8 +152,6 @@ struct Controller::Impl mBufferTransferRequests.clear(); } - std::vector cmdBufRefs{}; - // Prepare pipelines for( auto&& command : commands ) { @@ -211,13 +215,9 @@ struct Controller::Impl drawCommand.firstInstance); } cmdbuf->End(); - cmdBufRefs.emplace_back( cmdbuf ); + mSecondaryCommandBufferRefs.emplace_back( cmdbuf ); } - // execute as secondary buffers - mGraphics.GetSwapchainForFBID(0)->GetPrimaryCommandBuffer() - ->ExecuteCommands( cmdBufRefs ); - } // resources @@ -247,6 +247,11 @@ struct Controller::Impl std::unique_ptr mUboManager; + // Accumulate all the secondary command buffers of the frame here to avoid them being overwritten + // This accumulator vector gets cleared at the end of the frame. The command buffers are returned to the pool + // and ready to be used for the next frame. + std::vector mSecondaryCommandBufferRefs; + }; // TODO: @todo temporarily ignore missing return type, will be fixed later diff --git a/dali/graphics/vulkan/vulkan-graphics.h b/dali/graphics/vulkan/vulkan-graphics.h index 51d4515..5268cdd 100644 --- a/dali/graphics/vulkan/vulkan-graphics.h +++ b/dali/graphics/vulkan/vulkan-graphics.h @@ -139,7 +139,7 @@ public: // Create methods RefCountedSampler CreateSampler( const vk::SamplerCreateInfo& samplerCreateInfo ); public: // Actions - vk::Result WaitForFence( RefCountedFence fence, uint32_t timeout = 0 ); + vk::Result WaitForFence( RefCountedFence fence, uint32_t timeout = std::numeric_limits< uint32_t >::max() ); vk::Result WaitForFences( const std::vector< RefCountedFence >& fences, bool waitAll = true, diff --git a/dali/graphics/vulkan/vulkan-swapchain.cpp b/dali/graphics/vulkan/vulkan-swapchain.cpp index 68aae53..bde0881 100644 --- a/dali/graphics/vulkan/vulkan-swapchain.cpp +++ b/dali/graphics/vulkan/vulkan-swapchain.cpp @@ -421,6 +421,7 @@ struct Swapchain::Impl .setFramebuffer(swapBuffer.framebuffer->GetVkHandle() ) .setRenderPass(swapBuffer.framebuffer->GetRenderPassVkHandle()) .setSubpass( 0 ); + swapBuffer.masterCmdBuffer->Reset(); swapBuffer.masterCmdBuffer->Begin( vk::CommandBufferUsageFlagBits::eRenderPassContinue, &inheritanceInfo ); @@ -536,7 +537,7 @@ struct Swapchain::Impl mGraphics.Submit( mQueue, { std::move(submissionData) } , swapBuffer.endOfFrameFence ); - mGraphics.WaitForFence(swapBuffer.endOfFrameFence); + mGraphics.WaitForFence( swapBuffer.endOfFrameFence ); // fixme: use semaphores to synchronize all previously submitted command buffers! vk::PresentInfoKHR presentInfo{}; @@ -550,9 +551,6 @@ struct Swapchain::Impl mGraphics.Present( mQueue, presentInfo ); - // just to speed things up :P - mGraphics.QueueWaitIdle( mQueue ); - mGraphics.CollectGarbage(); return true; -- 2.7.4