[Vulkan] Basic Vulkan backend
[platform/core/uifw/dali-core.git] / dali / graphics / vulkan / vulkan-command-buffer.h
index 3fb0675..2dab9f7 100644 (file)
@@ -27,19 +27,20 @@ namespace Graphics
 {
 namespace Vulkan
 {
-
+class Image;
 class Graphics;
-class CommandPool;
-class CommandBuffer
+class Buffer;
+class Pipeline;
+class DescriptorSet;
+class CommandBuffer : public VkManaged
 {
+  friend class CommandPool;
+
 public:
-  CommandBuffer() = delete;
 
-  CommandBuffer(Graphics& graphics, CommandPool& ownerPool, vk::CommandBuffer commandBuffer);
-  CommandBuffer(Graphics& graphics, CommandPool& ownerPool, const vk::CommandBufferAllocateInfo& allocateInfo);
-  CommandBuffer(Graphics& graphics, CommandPool& ownerPool);
+  CommandBuffer() = delete;
 
-  ~CommandBuffer();
+  ~CommandBuffer() override;
 
   /** Begin recording */
   void Begin(vk::CommandBufferUsageFlags       usageFlags      = vk::CommandBufferUsageFlags{},
@@ -64,28 +65,146 @@ public:
   /** Push signal semaphores */
   void PushSignalSemaphores(const std::vector< vk::Semaphore >& semaphores);
 
-  const std::vector< vk::Semaphore >& GetSignalSemaphores() const
-  {
-    return mSignalSemaphores;
-  }
+  /**
+   *
+   * @return
+   */
+  const std::vector< vk::Semaphore >& GetSignalSemaphores() const;
 
-  const std::vector< vk::Semaphore >& GetSWaitSemaphores() const
-  {
-    return mWaitSemaphores;
-  }
+  /**
+   *
+   * @return
+   */
+  const std::vector< vk::Semaphore >& GetSWaitSemaphores() const;
 
-  const std::vector< vk::PipelineStageFlags >& GetWaitSemaphoreStages() const
-  {
-    return mWaitStages;
-  }
+  /**
+   *
+   * @return
+   */
+  const std::vector< vk::PipelineStageFlags >& GetWaitSemaphoreStages() const;
 
   /** Returns Vulkan object associated with the buffer */
-  inline const vk::CommandBuffer& Get() const
+  vk::CommandBuffer GetVkCommandBuffer() const;
+
+  operator vk::CommandBuffer() const
   {
-    return mCommandBuffer;
+    return GetVkCommandBuffer();
   }
 
+  /**
+   * Tests if the command buffer is primary
+   * @return Returns true if the command buffer is primary
+   */
+  bool IsPrimary() const;
+
+  /**
+   * Binds an array of vertex buffers
+   * @param firstBinding
+   * @param bindingCount
+   * @param buffers
+   * @param pOffsets
+   */
+  void BindVertexBuffers(uint32_t firstBinding, uint32_t bindingCount,
+                         std::vector<Dali::Graphics::Vulkan::Handle<Buffer>> buffers,
+                         const vk::DeviceSize *pOffsets);
+
+  /**
+   * Binds an index buffer
+   * @param buffer
+   * @param offset
+   * @param indexType
+   */
+  void BindIndexBuffer( BufferRef buffer, uint32_t offset, vk::IndexType indexType);
+
+  /**
+   * Binds single vertex buffer
+   * @param binding
+   * @param buffer
+   * @param offset
+   */
+  void BindVertexBuffer(uint32_t binding, Dali::Graphics::Vulkan::Handle<Buffer> buffer, vk::DeviceSize offset );
+
+  /**
+   * Binds graphics pipeline
+   * @param pipeline
+   */
+  void BindGraphicsPipeline( Handle<Pipeline> pipeline );
+
+  /**
+   *
+   * @param descriptorSets
+   * @param pipeline
+   * @param firstSet
+   * @param descriptorSetCount
+   */
+  void BindDescriptorSets( std::vector<Dali::Graphics::Vulkan::Handle<DescriptorSet>> descriptorSets,
+                           Handle<Pipeline> pipeline, uint32_t firstSet, uint32_t descriptorSetCount );
+
+  /**
+   * Binds descriptor sets to the most recently bound Pipeline
+   * @param descriptorSets
+   * @param firstSet
+   */
+  void BindDescriptorSets( std::vector<Dali::Graphics::Vulkan::Handle<DescriptorSet>> descriptorSets, uint32_t firstSet );
+
+  /**
+   * Issues draw command
+   * @param vertexCount
+   * @param instanceCount
+   * @param firstVertex
+   * @param firstInstance
+   */
+  void Draw( uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance );
+
+  /**
+   * Issues draw indexed primiteve command
+   * @param indexCount
+   * @param instanceCount
+   * @param firstIndex
+   * @param vertexOffset
+   * @param firstInstance
+   */
+  void DrawIndexed( uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, uint32_t vertexOffset, uint32_t firstInstance );
+
+  /**
+   * Begins render pass using VkRenderPass and VkFramebuffer associated with FBID
+   * @todo should be replaced with proper implementation and use the framebuffer
+   * @param framebufferId
+   * @param bufferIndex
+   */
+  void BeginRenderPass( FBID framebufferId, uint32_t bufferIndex );
+
+  /**
+   * Allows to issue custom VkRenderPassBeginInfo structure
+   * @param renderPassBeginInfo
+   * @param subpassContents
+   */
+  void BeginRenderPass( vk::RenderPassBeginInfo renderPassBeginInfo, vk::SubpassContents subpassContents );
+
+  /**
+   * Ends current render pass
+   */
+  void EndRenderPass();
+
+  /**
+   * Executes secondary command buffers within primary command buffer
+   * @param commandBuffers
+   */
+  void ExecuteCommands( std::vector<Dali::Graphics::Vulkan::Handle<CommandBuffer>> commandBuffers );
+
 private:
+
+  /**
+   *
+   * @param image
+   * @param srcAccessMask
+   * @param dstAccessMask
+   * @param srcStageMask
+   * @param dstStageMask
+   * @param oldLayout
+   * @param newLayout
+   * @param aspectMask
+   */
   void RecordImageLayoutTransition(vk::Image             image,
                                    vk::AccessFlags        srcAccessMask,
                                    vk::AccessFlags        dstAccessMask,
@@ -96,18 +215,13 @@ private:
                                    vk::ImageAspectFlags   aspectMask);
 
 private:
-  Graphics& mGraphics;
-
-  CommandPool& mCommandPool;
 
-  // semaphores per command buffer
-  std::vector< vk::Semaphore >          mSignalSemaphores;
-  std::vector< vk::Semaphore >          mWaitSemaphores;
-  std::vector< vk::PipelineStageFlags > mWaitStages;
+  // Constructor called by the CommandPool only
+  CommandBuffer( CommandPool& commandPool, const vk::CommandBufferAllocateInfo& allocateInfo, vk::CommandBuffer vkCommandBuffer );
 
-  vk::CommandBuffer mCommandBuffer;
+  class Impl;
+  std::unique_ptr<Impl> mImpl;
 
-  bool mRecording;
 };
 
 } // namespace Vulkan