Dali demo now works with the new grapics design
authorAngelos Gkountis <a.gkountis@samsung.com>
Wed, 6 Jun 2018 13:10:33 +0000 (14:10 +0100)
committerAdeel Kazmi <adeel.kazmi@samsung.com>
Mon, 11 Jun 2018 17:05:17 +0000 (17:05 +0000)
> 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
dali/graphics/vulkan/vulkan-graphics.h
dali/graphics/vulkan/vulkan-swapchain.cpp

index b0526ce..c07249d 100644 (file)
@@ -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<Vulkan::RefCountedCommandBuffer> 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<VulkanAPI::UboManager> 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<Vulkan::RefCountedCommandBuffer> mSecondaryCommandBufferRefs;
+
 };
 
 // TODO: @todo temporarily ignore missing return type, will be fixed later
index 51d4515..5268cdd 100644 (file)
@@ -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,
index 68aae53..bde0881 100644 (file)
@@ -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;