[Vulkan] graphics controller, multiple pipelines
[platform/core/uifw/dali-core.git] / dali / graphics / vulkan / vulkan-command-buffer.cpp
index d7ef0d1..ff64a71 100644 (file)
@@ -36,9 +36,11 @@ namespace Vulkan
 {
 struct CommandBuffer::Impl
 {
-  Impl( CommandPool& commandPool, const vk::CommandBufferAllocateInfo& allocateInfo, vk::CommandBuffer commandBuffer )
-  : mGraphics( commandPool.GetGraphics() ),
+  Impl( CommandBuffer& owner, CommandPool& commandPool, uint32_t poolIndex, const vk::CommandBufferAllocateInfo& allocateInfo, vk::CommandBuffer commandBuffer )
+  : mOwner( owner ),
+    mGraphics( commandPool.GetGraphics() ),
     mOwnerCommandPool( commandPool ),
+    mPoolAllocationIndex( poolIndex ),
     mAllocateInfo( allocateInfo ),
     mCommandBuffer( commandBuffer )
   {
@@ -46,11 +48,18 @@ struct CommandBuffer::Impl
 
   ~Impl()
   {
-    mResources.clear();
     mGraphics.GetDevice().freeCommandBuffers( mOwnerCommandPool.GetPool(),
                                               1, &mCommandBuffer );
   }
 
+  void ReleaseCommandBuffer()
+  {
+    mResources.clear();
+
+    // tell pool the buffer is not in use anymore
+    mOwnerCommandPool.ReleaseCommandBuffer(mOwner, false);
+  }
+
   bool Initialise()
   {
     return true;
@@ -131,7 +140,6 @@ struct CommandBuffer::Impl
     mGraphics.GetDevice().freeCommandBuffers( mOwnerCommandPool.GetPool(), mCommandBuffer );
   }
 
-#pragma GCC diagnostic pop
 
   /** Push wait semaphores */
   void PushWaitSemaphores( const std::vector<vk::Semaphore>&          semaphores,
@@ -284,7 +292,7 @@ struct CommandBuffer::Impl
       for( auto&& imageBarrier : imageBarriers )
       {
         ImageRef imageResource{};
-        if( imageResource = mGraphics.FindImage( imageBarrier.image ) )
+        if( (imageResource = mGraphics.FindImage( imageBarrier.image )) )
         {
           PushResource( imageResource );
         }
@@ -320,9 +328,10 @@ struct CommandBuffer::Impl
          .setSubresourceRange( vk::ImageSubresourceRange{ aspectMask, 0, image->GetLevelCount(), 0, image->GetLayerCount() } );
   }
 
-
+  CommandBuffer&                mOwner;
   Graphics&                     mGraphics;
   CommandPool&                  mOwnerCommandPool;
+  uint32_t                      mPoolAllocationIndex;
   vk::CommandBufferAllocateInfo mAllocateInfo{};
 
   vk::CommandBuffer mCommandBuffer{};
@@ -350,10 +359,11 @@ struct CommandBuffer::Impl
  */
 
 CommandBuffer::CommandBuffer( CommandPool&                         commandPool,
+                              uint32_t                             poolIndex,
                               const vk::CommandBufferAllocateInfo& allocateInfo,
                               vk::CommandBuffer                    vkCommandBuffer )
 {
-  mImpl = MakeUnique<Impl>( commandPool, allocateInfo, vkCommandBuffer );
+  mImpl = MakeUnique<Impl>( *this, commandPool, poolIndex, allocateInfo, vkCommandBuffer );
 }
 
 CommandBuffer::~CommandBuffer()
@@ -384,11 +394,6 @@ void CommandBuffer::Free()
   mImpl->Free();
 }
 
-void CommandBuffer::OnRelease( uint32_t refcount )
-{
-  VkManaged::OnRelease( refcount );
-}
-
 /** Push wait semaphores */
 void CommandBuffer::PushWaitSemaphores( const std::vector<vk::Semaphore>&          semaphores,
                                         const std::vector<vk::PipelineStageFlags>& stages )
@@ -441,7 +446,7 @@ void CommandBuffer::BindIndexBuffer( BufferRef buffer, uint32_t offset, vk::Inde
 }
 
 void CommandBuffer::BindVertexBuffer( uint32_t                               binding,
-                                      Dali::Graphics::Vulkan::Handle<Buffer> buffer,
+                                      const Dali::Graphics::Vulkan::Handle<Buffer>& buffer,
                                       vk::DeviceSize                         offset )
 {
   mImpl->BindVertexBuffers( binding, 1, std::vector<Handle<Buffer>>( {buffer} ), &offset );
@@ -529,6 +534,7 @@ vk::ImageMemoryBarrier CommandBuffer::ImageLayoutTransitionBarrier( ImageRef ima
 }
 
 vk::ImageMemoryBarrier CommandBuffer::ImageLayoutTransitionBarrier( ImageRef image,
+                                                     vk::ImageLayout        oldLayout,
                                                      vk::ImageLayout        newLayout,
                                                      vk::ImageAspectFlags   aspectMask
 ) const
@@ -537,8 +543,6 @@ vk::ImageMemoryBarrier CommandBuffer::ImageLayoutTransitionBarrier( ImageRef ima
   vk::AccessFlags  srcAccessMask, dstAccessMask;
   vk::PipelineStageFlags srcStageMask, dstStageMask;
 
-  auto oldLayout = image->GetVkImageLayout();
-
   switch( oldLayout )
   {
     case vk::ImageLayout::ePreinitialized:
@@ -621,6 +625,17 @@ vk::ImageMemoryBarrier CommandBuffer::ImageLayoutTransitionBarrier( ImageRef ima
                                               aspectMask  );
 }
 
+uint32_t CommandBuffer::GetPoolAllocationIndex() const
+{
+  return mImpl->mPoolAllocationIndex;
+}
+
+bool CommandBuffer::OnDestroy()
+{
+  mImpl->ReleaseCommandBuffer();
+  return true;
+}
+
 } // namespace Vulkan
 } // namespace Graphics
 } // namespace Dali