1 #ifndef DALI_GRAPHICS_VULKAN_COMMAND_BUFFER_H
2 #define DALI_GRAPHICS_VULKAN_COMMAND_BUFFER_H
5 * Copyright (c) 2018 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
22 #include <dali/graphics/vulkan/vulkan-types.h>
35 class CommandBuffer : public VkManaged
37 friend class CommandPool;
38 friend struct CommandBufferPool;
42 CommandBuffer() = delete;
44 ~CommandBuffer() override;
46 /** Begin recording */
47 void Begin(vk::CommandBufferUsageFlags usageFlags = vk::CommandBufferUsageFlags{},
48 vk::CommandBufferInheritanceInfo* inheritanceInfo = nullptr);
50 /** Finish recording */
53 /** Reset command buffer */
56 /** Free command buffer */
59 /** Push wait semaphores */
60 void PushWaitSemaphores(const std::vector< vk::Semaphore >& semaphores,
61 const std::vector< vk::PipelineStageFlags >& stages);
63 /** Push signal semaphores */
64 void PushSignalSemaphores(const std::vector< vk::Semaphore >& semaphores);
70 const std::vector< vk::Semaphore >& GetSignalSemaphores() const;
76 const std::vector< vk::Semaphore >& GetSWaitSemaphores() const;
82 const std::vector< vk::PipelineStageFlags >& GetWaitSemaphoreStages() const;
84 /** Returns Vulkan object associated with the buffer */
85 vk::CommandBuffer GetVkCommandBuffer() const;
87 operator vk::CommandBuffer() const
89 return GetVkCommandBuffer();
93 * Tests if the command buffer is primary
94 * @return Returns true if the command buffer is primary
96 bool IsPrimary() const;
99 * Binds an array of vertex buffers
100 * @param firstBinding
101 * @param bindingCount
105 void BindVertexBuffers(uint32_t firstBinding, uint32_t bindingCount,
106 std::vector<Dali::Graphics::Vulkan::Handle<Buffer>> buffers,
107 const vk::DeviceSize *pOffsets);
110 * Binds an index buffer
115 void BindIndexBuffer( BufferRef buffer, uint32_t offset, vk::IndexType indexType);
118 * Binds single vertex buffer
123 void BindVertexBuffer(uint32_t binding, const Dali::Graphics::Vulkan::Handle<Buffer>& buffer, vk::DeviceSize offset );
126 * Binds graphics pipeline
129 void BindGraphicsPipeline( Handle<Pipeline> pipeline );
133 * @param descriptorSets
136 * @param descriptorSetCount
138 void BindDescriptorSets( std::vector<Dali::Graphics::Vulkan::Handle<DescriptorSet>> descriptorSets,
139 Handle<Pipeline> pipeline, uint32_t firstSet, uint32_t descriptorSetCount );
142 * Binds descriptor sets to the most recently bound Pipeline
143 * @param descriptorSets
146 void BindDescriptorSets( std::vector<Dali::Graphics::Vulkan::Handle<DescriptorSet>> descriptorSets, uint32_t firstSet );
149 * Issues draw command
151 * @param instanceCount
153 * @param firstInstance
155 void Draw( uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance );
158 * Issues draw indexed primiteve command
160 * @param instanceCount
162 * @param vertexOffset
163 * @param firstInstance
165 void DrawIndexed( uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, uint32_t vertexOffset, uint32_t firstInstance );
168 * Begins render pass using VkRenderPass and VkFramebuffer associated with FBID
169 * @todo should be replaced with proper implementation and use the framebuffer
170 * @param framebufferId
173 void BeginRenderPass( FBID framebufferId, uint32_t bufferIndex );
176 * Allows to issue custom VkRenderPassBeginInfo structure
177 * @param renderPassBeginInfo
178 * @param subpassContents
180 void BeginRenderPass( vk::RenderPassBeginInfo renderPassBeginInfo, vk::SubpassContents subpassContents );
183 * Ends current render pass
185 void EndRenderPass();
188 * Records pipeline barrier
189 * @param srcStageMask
190 * @param dstStageMask
191 * @param dependencyFlags
192 * @param memoryBarriers
193 * @param bufferBarriers
194 * @param imageBarriers
196 void PipelineBarrier( vk::PipelineStageFlags srcStageMask,
197 vk::PipelineStageFlags dstStageMask,
198 vk::DependencyFlags dependencyFlags,
199 std::vector<vk::MemoryBarrier> memoryBarriers,
200 std::vector<vk::BufferMemoryBarrier> bufferBarriers,
201 std::vector<vk::ImageMemoryBarrier> imageBarriers );
204 * Executes secondary command buffers within primary command buffer
205 * @param commandBuffers
207 void ExecuteCommands( std::vector<Dali::Graphics::Vulkan::Handle<CommandBuffer>> commandBuffers );
210 * Copies buffer into the specified image
216 void CopyBufferToImage( BufferRef srcBuffer, ImageRef dstImage, vk::ImageLayout dstLayout,
217 std::vector<vk::BufferImageCopy> regions );
220 * Creates layout transition barrier
223 vk::ImageMemoryBarrier ImageLayoutTransitionBarrier( ImageRef image,
224 vk::AccessFlags srcAccessMask,
225 vk::AccessFlags dstAccessMask,
226 vk::ImageLayout oldLayout,
227 vk::ImageLayout newLayout,
228 vk::ImageAspectFlags aspectMask
232 * Simplified version of memory barrier generation based on data stored inside the Image
238 vk::ImageMemoryBarrier ImageLayoutTransitionBarrier( ImageRef image,
239 vk::ImageLayout olsLayout,
240 vk::ImageLayout newLayout,
241 vk::ImageAspectFlags aspectMask
245 * Implements VkManaged::OnDestroy
248 bool OnDestroy() override;
253 * Returns allocation index
256 uint32_t GetPoolAllocationIndex() const;
260 // Constructor called by the CommandPool only
261 CommandBuffer( CommandPool& commandPool, uint32_t poolIndex, const vk::CommandBufferAllocateInfo& allocateInfo, vk::CommandBuffer vkCommandBuffer );
263 std::unique_ptr<Impl> mImpl;
267 } // namespace Vulkan
268 } // namespace Graphics
271 #endif // DALI_GRAPHICS_VULKAN_COMMAND_BUFFER_H