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