[Vulkan] Cleanup after removing rendering backend
[platform/core/uifw/dali-core.git] / dali / graphics / vulkan / api / vulkan-api-render-command.h
1 #ifndef DALI_GRAPHICS_VULKAN_API_RENDER_COMMAND_H
2 #define DALI_GRAPHICS_VULKAN_API_RENDER_COMMAND_H
3
4 /*
5  * Copyright (c) 2018 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 #include <dali/graphics-api/graphics-api-render-command.h>
22 #include <dali/graphics-api/graphics-api-shader-details.h>
23 #include <dali/graphics/vulkan/vulkan-types.h>
24
25 namespace Dali
26 {
27 namespace Graphics
28 {
29 namespace Vulkan
30 {
31 class PipelineCache;
32 }
33
34 namespace VulkanAPI
35 {
36 class Controller;
37 class Ubo;
38
39 /**
40  * Render command stores internal command buffer per draw call
41  *
42  * For Vulkan:
43  *
44  * - RenderCommand stores all the relevant data
45  * - Changing pipeline determines recreating certain resources
46  * - Currently each RC has own DescriptorSetPool
47  * - Currently each RC has a handle to UBOs
48  * - UBOs are assigned upon pipeline creation/assignment
49  * - Descriptor sets are allocated upon pipeline creation
50  * - Note: need resource "versioning"
51  */
52 class RenderCommand : public Graphics::API::RenderCommand
53 {
54 public:
55
56   constexpr static uint32_t UPDATE_ALL = 0xffffffff;
57
58   RenderCommand( VulkanAPI::Controller& controller,
59                  Vulkan::Graphics& graphics,
60                  Vulkan::PipelineCache& pipelineCache );
61
62   ~RenderCommand() override;
63
64   /**
65    * Forces pipeline compilation whenever something changed and
66    * updates cache
67    * @return
68    */
69   bool PreparePipeline();
70
71   /**
72    * Updates uniform buffers
73    */
74   void UpdateUniformBuffers();
75
76   /**
77    * Writes uniform buffers into descriptor set
78    */
79   void BindUniformBuffers();
80
81   /**
82    * Writes texture/sample combo into descriptor set
83    */
84   void BindTexturesAndSamplers();
85
86   /**
87    * Returns an array of updated descriptor sets
88    * @return
89    */
90   const std::vector<Vulkan::DescriptorSetRef>& GetDescriptorSets() const;
91
92   /**
93    * Returns associated Vulkan command buffer
94    * @return
95    */
96   const Vulkan::CommandBufferRef& GetCommandBuffer() const;
97
98   /**
99    * Returns pipeline cache
100    * @return
101    */
102   const Vulkan::PipelineCache& GetPipelineCache() const;
103
104   /**
105    * Returns pipeline
106    * @return
107    */
108   const Vulkan::PipelineRef& GetPipeline() const;
109
110
111
112 private:
113
114   const vk::PipelineColorBlendStateCreateInfo*      PrepareColorBlendStateCreateInfo();
115
116   const vk::PipelineDepthStencilStateCreateInfo*    PrepareDepthStencilStateCreateInfo();
117
118   const vk::PipelineInputAssemblyStateCreateInfo*   PrepareInputAssemblyStateCreateInfo();
119
120   const vk::PipelineMultisampleStateCreateInfo*     PrepareMultisampleStateCreateInfo();
121
122   const vk::PipelineRasterizationStateCreateInfo*   PrepareRasterizationStateCreateInfo();
123
124   const vk::PipelineTessellationStateCreateInfo*    PrepareTesselationStateCreateInfo();
125
126   const vk::PipelineVertexInputStateCreateInfo*     PrepareVertexInputStateCreateInfo();
127
128   const vk::PipelineViewportStateCreateInfo*        PrepareViewportStateCreateInfo();
129
130   /**
131    * Allocates UBO memory based on the pipeline. Executed only
132    * once per pipeline
133    */
134   void AllocateUniformBufferMemory();
135
136 private:
137
138   /**
139    * Describes assigned UBO buffers
140    */
141
142   struct VulkanPipelineState;
143   std::unique_ptr<VulkanPipelineState>  mVulkanPipelineState;
144
145   VulkanAPI::Controller&                mController;
146   Vulkan::Graphics&                     mGraphics;
147   Vulkan::PipelineCache&                mPipelineCache;
148   Vulkan::CommandBufferRef              mCommandBuffer;
149   Vulkan::PipelineRef                   mPipeline;
150   Vulkan::DescriptorPoolRef             mDescriptorPool;
151
152   std::vector<vk::DescriptorSetLayout>  mVkDescriptorSetLayouts;
153
154   std::vector<Vulkan::DescriptorSetRef> mDescriptorSets;
155
156   std::vector<std::unique_ptr<Ubo>>     mUboBuffers;
157
158   uint32_t mUpdateFlags;
159 };
160
161 }
162 }
163 }
164 #endif //DALI_GRAPHICS_VULKAN_API_RENDER_COMMAND_H