1 #ifndef DALI_GRAPHICS_VULKAN_COMMAND_BUFFER_H
2 #define DALI_GRAPHICS_VULKAN_COMMAND_BUFFER_H
5 * Copyright (c) 2017 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;
41 CommandBuffer() = delete;
43 ~CommandBuffer() override;
45 /** Begin recording */
46 void Begin(vk::CommandBufferUsageFlags usageFlags = vk::CommandBufferUsageFlags{},
47 vk::CommandBufferInheritanceInfo* inheritanceInfo = nullptr);
49 /** Finish recording */
52 /** Reset command buffer */
55 /** Free command buffer */
58 /** Push wait semaphores */
59 void PushWaitSemaphores(const std::vector< vk::Semaphore >& semaphores,
60 const std::vector< vk::PipelineStageFlags >& stages);
62 /** Push signal semaphores */
63 void PushSignalSemaphores(const std::vector< vk::Semaphore >& semaphores);
69 const std::vector< vk::Semaphore >& GetSignalSemaphores() const;
75 const std::vector< vk::Semaphore >& GetSWaitSemaphores() const;
81 const std::vector< vk::PipelineStageFlags >& GetWaitSemaphoreStages() const;
83 /** Returns Vulkan object associated with the buffer */
84 vk::CommandBuffer GetVkCommandBuffer() const;
86 operator vk::CommandBuffer() const
88 return GetVkCommandBuffer();
92 * Tests if the command buffer is primary
93 * @return Returns true if the command buffer is primary
95 bool IsPrimary() const;
98 * Binds an array of vertex buffers
100 * @param bindingCount
104 void BindVertexBuffers(uint32_t firstBinding, uint32_t bindingCount,
105 std::vector<Dali::Graphics::Vulkan::Handle<Buffer>> buffers,
106 const vk::DeviceSize *pOffsets);
109 * Binds an index buffer
114 void BindIndexBuffer( BufferRef buffer, uint32_t offset, vk::IndexType indexType);
117 * Binds single vertex buffer
122 void BindVertexBuffer(uint32_t binding, Dali::Graphics::Vulkan::Handle<Buffer> buffer, vk::DeviceSize offset );
125 * Binds graphics pipeline
128 void BindGraphicsPipeline( Handle<Pipeline> pipeline );
132 * @param descriptorSets
135 * @param descriptorSetCount
137 void BindDescriptorSets( std::vector<Dali::Graphics::Vulkan::Handle<DescriptorSet>> descriptorSets,
138 Handle<Pipeline> pipeline, uint32_t firstSet, uint32_t descriptorSetCount );
141 * Binds descriptor sets to the most recently bound Pipeline
142 * @param descriptorSets
145 void BindDescriptorSets( std::vector<Dali::Graphics::Vulkan::Handle<DescriptorSet>> descriptorSets, uint32_t firstSet );
148 * Issues draw command
150 * @param instanceCount
152 * @param firstInstance
154 void Draw( uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance );
157 * Issues draw indexed primiteve command
159 * @param instanceCount
161 * @param vertexOffset
162 * @param firstInstance
164 void DrawIndexed( uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, uint32_t vertexOffset, uint32_t firstInstance );
167 * Begins render pass using VkRenderPass and VkFramebuffer associated with FBID
168 * @todo should be replaced with proper implementation and use the framebuffer
169 * @param framebufferId
172 void BeginRenderPass( FBID framebufferId, uint32_t bufferIndex );
175 * Allows to issue custom VkRenderPassBeginInfo structure
176 * @param renderPassBeginInfo
177 * @param subpassContents
179 void BeginRenderPass( vk::RenderPassBeginInfo renderPassBeginInfo, vk::SubpassContents subpassContents );
182 * Ends current render pass
184 void EndRenderPass();
187 * Records pipeline barrier
188 * @param srcStageMask
189 * @param dstStageMask
190 * @param dependencyFlags
191 * @param memoryBarriers
192 * @param bufferBarriers
193 * @param imageBarriers
195 void PipelineBarrier( vk::PipelineStageFlags srcStageMask,
196 vk::PipelineStageFlags dstStageMask,
197 vk::DependencyFlags dependencyFlags,
198 std::vector<vk::MemoryBarrier> memoryBarriers,
199 std::vector<vk::BufferMemoryBarrier> bufferBarriers,
200 std::vector<vk::ImageMemoryBarrier> imageBarriers );
203 * Executes secondary command buffers within primary command buffer
204 * @param commandBuffers
206 void ExecuteCommands( std::vector<Dali::Graphics::Vulkan::Handle<CommandBuffer>> commandBuffers );
209 * Copies buffer into the specified image
215 void CopyBufferToImage( BufferRef srcBuffer, ImageRef dstImage, vk::ImageLayout dstLayout,
216 std::vector<vk::BufferImageCopy> regions );
218 void OnRelease( uint32_t refcount ) override;
221 * Creates layout transition barrier
224 vk::ImageMemoryBarrier ImageLayoutTransitionBarrier( ImageRef image,
225 vk::AccessFlags srcAccessMask,
226 vk::AccessFlags dstAccessMask,
227 vk::ImageLayout oldLayout,
228 vk::ImageLayout newLayout,
229 vk::ImageAspectFlags aspectMask
233 * Simplified version of memory barrier generation based on data stored inside the Image
239 vk::ImageMemoryBarrier ImageLayoutTransitionBarrier( ImageRef image,
240 vk::ImageLayout newLayout,
241 vk::ImageAspectFlags aspectMask
246 // Constructor called by the CommandPool only
247 CommandBuffer( CommandPool& commandPool, const vk::CommandBufferAllocateInfo& allocateInfo, vk::CommandBuffer vkCommandBuffer );
250 std::unique_ptr<Impl> mImpl;
254 } // namespace Vulkan
255 } // namespace Graphics
258 #endif // DALI_GRAPHICS_VULKAN_COMMAND_BUFFER_H