[Vulkan] Builtin shaders and shaders offline compilation script
[platform/core/uifw/dali-core.git] / dali / graphics-api / graphics-api-shader-details.h
1 #ifndef DALI_GRAPHICS_API_SHADER_DETAILS_H
2 #define DALI_GRAPHICS_API_SHADER_DETAILS_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 #include <string>
22 #include <vector>
23 #include <iostream>
24
25 namespace Dali
26 {
27 namespace Graphics
28 {
29 namespace API
30 {
31 namespace ShaderDetails
32 {
33
34 constexpr uint32_t ERROR_VERTEX_INPUT_ATTRIBUTE_NOT_FOUND( -1u );
35
36 enum class ShaderSourceType
37 {
38   STRING,
39   BINARY
40 };
41
42 struct ShaderSource
43 {
44   /**
45    * Creates shader source object from source string
46    * @param sourceString
47    */
48   explicit ShaderSource( const std::string& sourceString )
49   {
50     source = sourceString;
51     type = ShaderSourceType::STRING;
52   }
53
54   /**
55    * Creates shader source object from vector
56    * @param sourceBinary
57    */
58   template<class T>
59   explicit ShaderSource( const std::vector<T>& sourceBinary )
60   {
61     if(!sourceBinary.empty())
62     {
63       code.resize(sourceBinary.size() * sizeof(T));
64       auto begin = reinterpret_cast<const char *>(&*sourceBinary.begin());
65       auto end   = reinterpret_cast<const char *>(&*sourceBinary.end());
66       std::copy(begin, end, code.begin());
67     }
68     type = ShaderSourceType::BINARY;
69   }
70
71   template<char>
72   explicit ShaderSource( const std::vector<char>& sourceBinary )
73   {
74     if( !sourceBinary.empty() )
75     {
76       code = sourceBinary;
77     }
78     type = ShaderSourceType::BINARY;
79   }
80
81   /**
82    * Creates shader source object from C-Style binary data
83    * @param pBinary
84    * @param size
85    */
86   explicit ShaderSource( const void* pBinary, uint32_t size )
87   {
88     code.resize( size );
89     auto begin = reinterpret_cast<const char*>(pBinary);
90     auto end = begin + size;
91     std::copy( begin, end, code.begin() );
92     type = ShaderSourceType::BINARY;
93   }
94
95   ShaderSource( const ShaderSource& shaderSource ) = default;
96
97   /**
98    * Tests whether the shader module has been set
99    * @return
100    */
101   bool IsSet() const
102   {
103     if( type == ShaderSourceType::BINARY )
104     {
105       return !code.empty();
106     }
107
108     return !source.empty();
109   }
110
111   bool operator==(const ShaderSource& rhs ) const
112   {
113     if( type == ShaderSourceType::BINARY )
114     {
115       return code == rhs.code;
116     }
117     else
118     {
119       return source == rhs.source;
120     }
121   }
122
123   std::string       source;
124   std::vector<char> code;
125   ShaderSourceType type;
126 };
127
128 enum class Language {
129   GLSL_1,
130   GLSL_3_1,
131   GLSL_3_2,
132   SPIRV_1_0,
133   SPIRV_1_1,
134 };
135
136 enum class PipelineStage {
137   VERTEX,
138   GEOMETRY,
139   FRAGMENT,
140   COMPUTE,
141   TESSELATION_CONTROL,
142   TESSELATION_EVALUATION,
143 };
144
145 enum class VertexInputAttributeFormat
146 {
147   UNDEFINED,
148   FLOAT,
149   INTEGER,
150   VEC2,
151   VEC3,
152   VEC4
153 };
154
155 enum class UniformClass
156 {
157   SAMPLER,
158   IMAGE,
159   COMBINED_IMAGE_SAMPLER,
160   UNIFORM_BUFFER,
161   UNDEFINED
162 };
163
164 struct UniformInfo
165 {
166   std::string   name{""};
167   UniformClass  uniformClass{ UniformClass::UNDEFINED };
168   uint32_t      binding { 0u };
169   uint32_t      bufferIndex { 0u };
170   uint32_t      offset { 0u };
171   uint32_t      location { 0u };
172 };
173
174 struct UniformBlockInfo
175 {
176   std::string name {""};
177   uint32_t    descriptorSet {0u};
178   uint32_t    binding {0u};
179   uint32_t    size {0u};
180   std::vector<UniformInfo> members {};
181 };
182
183 } // namespace TextureDetails
184 } // namespace API
185 } // namespace Graphics
186 } // namespace Dali
187
188 #endif // DALI_GRAPHICS_API_SHADER_DETAILS_H