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 /** Records image layout transition barrier for one image */
59 void ImageLayoutTransition(vk::Image image, vk::ImageLayout oldLayout, vk::ImageLayout newLayout, vk::ImageAspectFlags aspectMask);
61 /** Push wait semaphores */
62 void PushWaitSemaphores(const std::vector< vk::Semaphore >& semaphores,
63 const std::vector< vk::PipelineStageFlags >& stages);
65 /** Push signal semaphores */
66 void PushSignalSemaphores(const std::vector< vk::Semaphore >& semaphores);
72 const std::vector< vk::Semaphore >& GetSignalSemaphores() const;
78 const std::vector< vk::Semaphore >& GetSWaitSemaphores() const;
84 const std::vector< vk::PipelineStageFlags >& GetWaitSemaphoreStages() const;
86 /** Returns Vulkan object associated with the buffer */
87 vk::CommandBuffer GetVkCommandBuffer() const;
89 operator vk::CommandBuffer() const
91 return GetVkCommandBuffer();
95 * Tests if the command buffer is primary
96 * @return Returns true if the command buffer is primary
98 bool IsPrimary() const;
101 * Binds an array of vertex buffers
102 * @param firstBinding
103 * @param bindingCount
107 void BindVertexBuffers(uint32_t firstBinding, uint32_t bindingCount,
108 std::vector<Dali::Graphics::Vulkan::Handle<Buffer>> buffers,
109 const vk::DeviceSize *pOffsets);
112 * Binds an index buffer
117 void BindIndexBuffer( BufferRef buffer, uint32_t offset, vk::IndexType indexType);
120 * Binds single vertex buffer
125 void BindVertexBuffer(uint32_t binding, Dali::Graphics::Vulkan::Handle<Buffer> buffer, vk::DeviceSize offset );
128 * Binds graphics pipeline
131 void BindGraphicsPipeline( Handle<Pipeline> pipeline );
135 * @param descriptorSets
138 * @param descriptorSetCount
140 void BindDescriptorSets( std::vector<Dali::Graphics::Vulkan::Handle<DescriptorSet>> descriptorSets,
141 Handle<Pipeline> pipeline, uint32_t firstSet, uint32_t descriptorSetCount );
144 * Binds descriptor sets to the most recently bound Pipeline
145 * @param descriptorSets
148 void BindDescriptorSets( std::vector<Dali::Graphics::Vulkan::Handle<DescriptorSet>> descriptorSets, uint32_t firstSet );
151 * Issues draw command
153 * @param instanceCount
155 * @param firstInstance
157 void Draw( uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance );
160 * Issues draw indexed primiteve command
162 * @param instanceCount
164 * @param vertexOffset
165 * @param firstInstance
167 void DrawIndexed( uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, uint32_t vertexOffset, uint32_t firstInstance );
170 * Begins render pass using VkRenderPass and VkFramebuffer associated with FBID
171 * @todo should be replaced with proper implementation and use the framebuffer
172 * @param framebufferId
175 void BeginRenderPass( FBID framebufferId, uint32_t bufferIndex );
178 * Allows to issue custom VkRenderPassBeginInfo structure
179 * @param renderPassBeginInfo
180 * @param subpassContents
182 void BeginRenderPass( vk::RenderPassBeginInfo renderPassBeginInfo, vk::SubpassContents subpassContents );
185 * Ends current render pass
187 void EndRenderPass();
190 * Executes secondary command buffers within primary command buffer
191 * @param commandBuffers
193 void ExecuteCommands( std::vector<Dali::Graphics::Vulkan::Handle<CommandBuffer>> commandBuffers );
200 * @param srcAccessMask
201 * @param dstAccessMask
202 * @param srcStageMask
203 * @param dstStageMask
208 void RecordImageLayoutTransition(vk::Image image,
209 vk::AccessFlags srcAccessMask,
210 vk::AccessFlags dstAccessMask,
211 vk::PipelineStageFlags srcStageMask,
212 vk::PipelineStageFlags dstStageMask,
213 vk::ImageLayout oldLayout,
214 vk::ImageLayout newLayout,
215 vk::ImageAspectFlags aspectMask);
219 // Constructor called by the CommandPool only
220 CommandBuffer( CommandPool& commandPool, const vk::CommandBufferAllocateInfo& allocateInfo, vk::CommandBuffer vkCommandBuffer );
223 std::unique_ptr<Impl> mImpl;
227 } // namespace Vulkan
228 } // namespace Graphics
231 #endif // DALI_GRAPHICS_VULKAN_COMMAND_BUFFER_H