[Vulkan] Basic Vulkan backend
[platform/core/uifw/dali-core.git] / dali / graphics / vulkan / vulkan-shader.h
1 #ifndef DALI_GRAPHICS_VULKAN_SHADER
2 #define DALI_GRAPHICS_VULKAN_SHADER
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 // INTERNAL INCLUDES
22 #include <dali/graphics/vulkan/vulkan-types.h>
23
24 namespace Dali
25 {
26 namespace Graphics
27 {
28 namespace Vulkan
29 {
30 class Graphics;
31 class Shader : public VkManaged // can be overriden as ShaderGLSL for example
32 {
33 public:
34
35   enum class Type
36   {
37     VERTEX = static_cast<int>( vk::ShaderStageFlagBits::eVertex ),
38     FRAGMENT = static_cast<int>( vk::ShaderStageFlagBits::eFragment ),
39     COMPUTE = static_cast<int>( vk::ShaderStageFlagBits::eCompute ),
40     GEOMETRY = static_cast<int>( vk::ShaderStageFlagBits::eGeometry ),
41   };
42
43   /**
44    *
45    * @param graphics
46    * @param info
47    * @return
48    */
49   static Handle<Shader> New( Graphics& graphics, const vk::ShaderModuleCreateInfo& info );
50
51   /**
52    * Creates new shader module from SPIRV code
53    * @param graphics
54    * @param bytes
55    * @param size
56    * @return
57    */
58   static Handle<Shader> New( Graphics& graphics, const void* bytes, std::size_t size );
59
60   /**
61    *
62    */
63   ~Shader();
64
65   vk::ShaderModule GetVkShaderModule() const;
66
67   const std::vector<vk::DescriptorSetLayout>& GetDescriptorSetLayouts() const;
68
69   bool OnDestroy() override;
70
71   operator vk::ShaderModule() const
72   {
73     return GetVkShaderModule();
74   }
75
76 public:
77
78   void SetDescriptorSetLayout( uint32_t set, vk::DescriptorSetLayoutCreateInfo info );
79
80 private:
81
82   Shader( Graphics& graphics, const vk::ShaderModuleCreateInfo& info );
83
84 private:
85
86   class Impl;
87   std::unique_ptr<Impl> mImpl;
88 };
89
90 using ShaderRef = Handle<Shader>;
91
92 } // Namespace Vulkan
93
94 } // Namespace Graphics
95
96 } // Namespace Dali
97
98 #endif // DALI_GRAPHICS_VULKAN_SHADER