Simplified Vulkan backend [WIP]
[platform/core/uifw/dali-core.git] / dali / graphics / vulkan / vulkan-command-buffer.h
1 #ifndef DALI_GRAPHICS_VULKAN_COMMAND_BUFFER_H
2 #define DALI_GRAPHICS_VULKAN_COMMAND_BUFFER_H
3
4 /*
5  * Copyright (c) 2017 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20
21 // INTERNAL INCLUDES
22 #include <dali/graphics/vulkan/vulkan-types.h>
23
24 namespace Dali
25 {
26 namespace Graphics
27 {
28 namespace Vulkan
29 {
30
31 class Graphics;
32 class CommandPool;
33 class CommandBuffer
34 {
35 public:
36   CommandBuffer() = delete;
37
38   CommandBuffer(Graphics& graphics, CommandPool& ownerPool, vk::CommandBuffer commandBuffer);
39   CommandBuffer(Graphics& graphics, CommandPool& ownerPool, const vk::CommandBufferAllocateInfo& allocateInfo);
40   CommandBuffer(Graphics& graphics, CommandPool& ownerPool);
41
42   ~CommandBuffer();
43
44   /** Begin recording */
45   void Begin(vk::CommandBufferUsageFlags       usageFlags      = vk::CommandBufferUsageFlags{},
46              vk::CommandBufferInheritanceInfo* inheritanceInfo = nullptr);
47
48   /** Finish recording */
49   void End();
50
51   /** Reset command buffer */
52   void Reset();
53
54   /** Free command buffer */
55   void Free();
56
57   /** Records image layout transition barrier for one image */
58   void ImageLayoutTransition(vk::Image image, vk::ImageLayout oldLayout, vk::ImageLayout newLayout, vk::ImageAspectFlags aspectMask);
59
60   /** Push wait semaphores */
61   void PushWaitSemaphores(const std::vector< vk::Semaphore >&          semaphores,
62                           const std::vector< vk::PipelineStageFlags >& stages);
63
64   /** Push signal semaphores */
65   void PushSignalSemaphores(const std::vector< vk::Semaphore >& semaphores);
66
67   const std::vector< vk::Semaphore >& GetSignalSemaphores() const
68   {
69     return mSignalSemaphores;
70   }
71
72   const std::vector< vk::Semaphore >& GetSWaitSemaphores() const
73   {
74     return mWaitSemaphores;
75   }
76
77   const std::vector< vk::PipelineStageFlags >& GetWaitSemaphoreStages() const
78   {
79     return mWaitStages;
80   }
81
82   /** Returns Vulkan object associated with the buffer */
83   inline const vk::CommandBuffer& Get() const
84   {
85     return mCommandBuffer;
86   }
87
88 private:
89   void RecordImageLayoutTransition(vk::Image             image,
90                                    vk::AccessFlags        srcAccessMask,
91                                    vk::AccessFlags        dstAccessMask,
92                                    vk::PipelineStageFlags srcStageMask,
93                                    vk::PipelineStageFlags dstStageMask,
94                                    vk::ImageLayout        oldLayout,
95                                    vk::ImageLayout        newLayout,
96                                    vk::ImageAspectFlags   aspectMask);
97
98 private:
99   Graphics& mGraphics;
100
101   CommandPool& mCommandPool;
102
103   // semaphores per command buffer
104   std::vector< vk::Semaphore >          mSignalSemaphores;
105   std::vector< vk::Semaphore >          mWaitSemaphores;
106   std::vector< vk::PipelineStageFlags > mWaitStages;
107
108   vk::CommandBuffer mCommandBuffer;
109
110   bool mRecording;
111 };
112
113 } // namespace Vulkan
114 } // namespace Graphics
115 } // namespace Dali
116
117 #endif // DALI_GRAPHICS_VULKAN_COMMAND_BUFFER_H