Shader Reflection
[platform/core/uifw/dali-core.git] / dali / graphics-api / graphics-types.h
1 #ifndef DALI_GRAPHICS_API_TYPES
2 #define DALI_GRAPHICS_API_TYPES
3
4 /*
5  * Copyright (c) 2021 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 // EXTERNAL INCLUDES
22 #include <memory>
23 #include <string>
24 #include <utility>
25 #include <vector>
26
27 namespace Dali
28 {
29 namespace Graphics
30 {
31 class CommandBuffer;
32 class Texture;
33 class Buffer;
34 class Shader;
35 class Framebuffer;
36
37 /**
38  * @brief Structure describes 2D offset
39  */
40 struct Offset2D
41 {
42   int32_t x = 0;
43   int32_t y = 0;
44 };
45
46 /**
47  * @brief Structure describes 2D dimensions
48  */
49 struct Extent2D
50 {
51   uint32_t width;
52   uint32_t height;
53 };
54
55 /**
56  * @brief Structure describes 2D rectangle (offset, extent)
57  */
58 struct Rect2D
59 {
60   int32_t  x      = 0;
61   int32_t  y      = 0;
62   uint32_t width  = 0;
63   uint32_t height = 0;
64 };
65
66 /**
67  * @brief Structure represents area of viewport
68  */
69 struct Viewport
70 {
71   float x        = 0.0f;
72   float y        = 0.0f;
73   float width    = 0.0f;
74   float height   = 0.0f;
75   float minDepth = 0.0f;
76   float maxDepth = 0.0f;
77 };
78
79 /**
80  * @brief Describes vertex attribute input rate
81  */
82 enum class VertexInputRate
83 {
84   PER_VERTEX,  ///< Attribute read per vertex
85   PER_INSTANCE ///< Attribute read per instance
86 };
87
88 /**
89  * @brief Vertex input format
90  *
91  * When UNDEFINED, the reflection is used to determine what
92  * the actual format is.
93  */
94 enum class VertexInputFormat
95 {
96   UNDEFINED,
97   FVECTOR2,
98   FVECTOR3,
99   FVECTOR4,
100   IVECTOR2,
101   IVECTOR3,
102   IVECTOR4,
103   FLOAT,
104   INTEGER,
105 };
106
107 /**
108  * @brief Logic operators used by color blending state
109  * when logicOpEnable is set.
110  */
111 enum class LogicOp
112 {
113   CLEAR         = 0,
114   AND           = 1,
115   AND_REVERSE   = 2,
116   COPY          = 3,
117   AND_INVERTED  = 4,
118   NO_OP         = 5,
119   XOR           = 6,
120   OR            = 7,
121   NOR           = 8,
122   EQUIVALENT    = 9,
123   INVERT        = 10,
124   OR_REVERSE    = 11,
125   COPY_INVERTED = 12,
126   OR_INVERTED   = 13,
127   NAND          = 14,
128   SET           = 15,
129 };
130
131 /**
132  * @brief Blend factors
133  */
134 enum class BlendFactor
135 {
136   ZERO                     = 0,
137   ONE                      = 1,
138   SRC_COLOR                = 2,
139   ONE_MINUS_SRC_COLOR      = 3,
140   DST_COLOR                = 4,
141   ONE_MINUS_DST_COLOR      = 5,
142   SRC_ALPHA                = 6,
143   ONE_MINUS_SRC_ALPHA      = 7,
144   DST_ALPHA                = 8,
145   ONE_MINUS_DST_ALPHA      = 9,
146   CONSTANT_COLOR           = 10,
147   ONE_MINUS_CONSTANT_COLOR = 11,
148   CONSTANT_ALPHA           = 12,
149   ONE_MINUS_CONSTANT_ALPHA = 13,
150   SRC_ALPHA_SATURATE       = 14,
151   SRC1_COLOR               = 15,
152   ONE_MINUS_SRC1_COLOR     = 16,
153   SRC1_ALPHA               = 17,
154   ONE_MINUS_SRC1_ALPHA     = 18,
155 };
156
157 /**
158  * @brief Blend operators
159  */
160 enum class BlendOp
161 {
162   ADD              = 0,
163   SUBTRACT         = 1,
164   REVERSE_SUBTRACT = 2,
165   MIN              = 3,
166   MAX              = 4,
167 };
168
169 /**
170  * @brief Compare operators
171  */
172 enum class CompareOp
173 {
174   NEVER,
175   LESS,
176   EQUAL,
177   LESS_OR_EQUAL,
178   GREATER,
179   NOT_EQUAL,
180   GREATER_OR_EQUAL,
181   ALWAYS
182 };
183
184 /**
185  * @brief Stencil operators
186  */
187 enum class StencilOp
188 {
189   KEEP,
190   ZERO,
191   REPLACE,
192   INCREMENT_AND_CLAMP,
193   DECREMENT_AND_CLAMP,
194   INVERT,
195   INCREMENT_AND_WRAP,
196   DECREMENT_AND_WRAP
197 };
198
199 /**
200  * @brief Backface culling modes
201  */
202 enum class CullMode
203 {
204   NONE,
205   FRONT,
206   BACK,
207   FRONT_AND_BACK
208 };
209
210 /**
211  * @brief Polygon drawing modes
212  */
213 enum class PolygonMode
214 {
215   FILL,
216   LINE,
217   POINT
218 };
219
220 /**
221  * @brief Front face direction
222  */
223 enum class FrontFace
224 {
225   COUNTER_CLOCKWISE,
226   CLOCKWISE
227 };
228
229 /**
230  * @brief Primitive geometry topology
231  */
232 enum class PrimitiveTopology
233 {
234   POINT_LIST,
235   LINE_LIST,
236   LINE_LOOP,
237   LINE_STRIP,
238   TRIANGLE_LIST,
239   TRIANGLE_STRIP,
240   TRIANGLE_FAN
241 };
242
243 /**
244  * @brief Sampler address ( wrapping ) mode
245  */
246 enum class SamplerAddressMode
247 {
248   REPEAT,
249   MIRRORED_REPEAT,
250   CLAMP_TO_EDGE,
251   CLAMP_TO_BORDER,
252   MIRROR_CLAMP_TO_EDGE
253 };
254
255 /**
256  * @brief Filtering mode
257  */
258 enum class SamplerFilter
259 {
260   NEAREST,
261   LINEAR
262 };
263
264 /**
265  * @brief Mipmap mode
266  */
267 enum class SamplerMipmapMode
268 {
269   NONE,
270   NEAREST,
271   LINEAR
272 };
273
274 /**
275  * @brief Describes pipeline's color blend state
276  */
277 struct ColorBlendState
278 {
279   bool        logicOpEnable           = false;
280   LogicOp     logicOp                 = {};
281   float       blendConstants[4]       = {0.0f, 0.0f, 0.0f, 0.0f};
282   bool        blendEnable             = false;
283   BlendFactor srcColorBlendFactor     = BlendFactor::ZERO;
284   BlendFactor dstColorBlendFactor     = BlendFactor::ZERO;
285   BlendOp     colorBlendOp            = {};
286   BlendFactor srcAlphaBlendFactor     = BlendFactor::ZERO;
287   BlendFactor dstAlphaBlendFactor     = BlendFactor::ZERO;
288   BlendOp     alphaBlendOp            = {};
289   uint32_t    colorComponentWriteBits = {0u};
290
291   auto& SetLogicOpEnable(bool value)
292   {
293     logicOpEnable = value;
294     return *this;
295   }
296
297   auto& SetLogicOp(LogicOp value)
298   {
299     logicOp = value;
300     return *this;
301   }
302
303   auto& SetBlendConstants(float value[4])
304   {
305     std::copy(value, value + 4, blendConstants);
306     return *this;
307   }
308
309   auto& SetBlendEnable(bool value)
310   {
311     blendEnable = value;
312     return *this;
313   }
314
315   auto& SetSrcColorBlendFactor(BlendFactor value)
316   {
317     srcColorBlendFactor = value;
318     return *this;
319   }
320
321   auto& SetDstColorBlendFactor(BlendFactor value)
322   {
323     dstColorBlendFactor = value;
324     return *this;
325   }
326
327   auto& SetColorBlendOp(BlendOp value)
328   {
329     colorBlendOp = value;
330     return *this;
331   }
332
333   auto& SetSrcAlphaBlendFactor(BlendFactor value)
334   {
335     srcAlphaBlendFactor = value;
336     return *this;
337   }
338
339   auto& SetDstAlphaBlendFactor(BlendFactor value)
340   {
341     dstAlphaBlendFactor = value;
342     return *this;
343   }
344
345   auto& SetAlphaBlendOp(BlendOp value)
346   {
347     alphaBlendOp = value;
348     return *this;
349   }
350
351   auto& SetColorComponentsWriteBits(uint32_t value)
352   {
353     colorComponentWriteBits = value;
354     return *this;
355   }
356 };
357
358 /**
359  * @brief  Framebuffer state
360  */
361 struct FramebufferState
362 {
363   const Framebuffer* framebuffer{nullptr};
364
365   auto& SetFramebuffer(const Framebuffer& value)
366   {
367     framebuffer = &value;
368     return *this;
369   }
370 };
371
372 /**
373  * @brief Describes pipeline's viewport and scissor state
374  */
375 struct ViewportState
376 {
377   Viewport viewport{0.0, 0.0, 0.0, 0.0};
378   Rect2D   scissor{0, 0, 0, 0};
379   bool     scissorTestEnable{false};
380
381   auto& SetViewport(const Viewport& value)
382   {
383     viewport = value;
384     return *this;
385   }
386
387   auto& SetScissor(const Rect2D& value)
388   {
389     scissor = value;
390     return *this;
391   }
392
393   auto& SetScissorTestEnable(bool value)
394   {
395     scissorTestEnable = value;
396     return *this;
397   }
398 };
399
400 /**
401  * @brief Describes stencil operation state
402  */
403 struct StencilOpState
404 {
405   StencilOp failOp{};
406   StencilOp passOp{};
407   StencilOp depthFailOp{};
408   CompareOp compareOp{};
409   uint32_t  compareMask{0u};
410   uint32_t  writeMask{0u};
411   uint32_t  reference{0u};
412
413   auto& SetFailOp(StencilOp value)
414   {
415     failOp = value;
416     return *this;
417   }
418
419   auto& SetPassOp(StencilOp value)
420   {
421     failOp = value;
422     return *this;
423   }
424
425   auto& SetDepthFailOp(StencilOp value)
426   {
427     failOp = value;
428     return *this;
429   }
430
431   auto& SetCompareOp(CompareOp value)
432   {
433     compareOp = value;
434     return *this;
435   }
436
437   auto& SetCompareMask(uint32_t value)
438   {
439     compareMask = value;
440     return *this;
441   }
442
443   auto& SetWriteMask(uint32_t value)
444   {
445     writeMask = value;
446     return *this;
447   }
448
449   auto& SetReference(uint32_t value)
450   {
451     reference = value;
452     return *this;
453   }
454 };
455
456 /**
457  * @brief Describes pipeline's viewport and scissor state
458  */
459 struct DepthStencilState
460 {
461   bool      depthTestEnable{false};
462   bool      depthWriteEnable{false};
463   CompareOp depthCompareOp{};
464
465   bool           stencilTestEnable{false};
466   StencilOpState front{};
467   StencilOpState back{};
468
469   auto& SetDepthTestEnable(bool value)
470   {
471     depthTestEnable = value;
472     return *this;
473   }
474
475   auto& SetDepthWriteEnable(bool value)
476   {
477     depthWriteEnable = value;
478     return *this;
479   }
480
481   auto& SetDepthCompareOp(CompareOp value)
482   {
483     depthCompareOp = value;
484     return *this;
485   }
486
487   auto& SetFront(StencilOpState value)
488   {
489     front = value;
490     return *this;
491   }
492
493   auto& SetBack(StencilOpState value)
494   {
495     back = value;
496     return *this;
497   }
498
499   auto& SetStencilTestEnable(bool value)
500   {
501     stencilTestEnable = value;
502     return *this;
503   }
504 };
505
506 /**
507  * @brief Rasterization state descriptor
508  */
509 struct RasterizationState
510 {
511   CullMode    cullMode{};
512   PolygonMode polygonMode{};
513   FrontFace   frontFace{};
514
515   auto& SetCullMode(CullMode value)
516   {
517     cullMode = value;
518     return *this;
519   }
520
521   auto& SetPolygonMode(PolygonMode value)
522   {
523     polygonMode = value;
524     return *this;
525   }
526
527   auto& SetFrontFace(FrontFace value)
528   {
529     frontFace = value;
530     return *this;
531   }
532 };
533
534 /**
535  * @brief Input assembly state descriptor.
536  *
537  * Structure describes the topology for submitted
538  * geometry.
539  */
540 struct InputAssemblyState
541 {
542   PrimitiveTopology topology{};
543   bool              primitiveRestartEnable{true};
544
545   auto& SetTopology(PrimitiveTopology value)
546   {
547     topology = value;
548     return *this;
549   }
550
551   auto& SetPrimitiveRestartEnable(bool value)
552   {
553     primitiveRestartEnable = true;
554     return *this;
555   }
556 };
557
558 /**
559  * @brief Pipeline dynamic state bits
560  */
561 namespace PipelineDynamicStateBits
562 {
563 const uint32_t VIEWPORT_BIT             = 1 << 0;
564 const uint32_t SCISSOR_BIT              = 1 << 1;
565 const uint32_t LINE_WIDTH_BIT           = 1 << 2;
566 const uint32_t DEPTH_BIAS_BIT           = 1 << 3;
567 const uint32_t BLEND_CONSTANTS_BIT      = 1 << 4;
568 const uint32_t DEPTH_BOUNDS_BIT         = 1 << 5;
569 const uint32_t STENCIL_COMPARE_MASK_BIT = 1 << 6;
570 const uint32_t STENCIL_WRITE_MASK_BIT   = 1 << 7;
571 const uint32_t STENCIL_REFERENCE_BIT    = 1 << 8;
572 } // namespace PipelineDynamicStateBits
573
574 const uint32_t PIPELINE_DYNAMIC_STATE_COUNT(9u);
575
576 using PipelineDynamicStateMask = uint32_t;
577
578 /**
579  * @brief Structure describes vertex input state of the pipeline.
580  * It specifies buffer binding and attribute format to be used.
581  */
582 struct VertexInputState
583 {
584   VertexInputState() = default;
585
586   /**
587    * @brief Vertex buffer binding
588    */
589   struct Binding
590   {
591     Binding(uint32_t _stride, VertexInputRate _inputRate)
592     : stride(_stride),
593       inputRate(_inputRate)
594     {
595     }
596     uint32_t        stride;
597     VertexInputRate inputRate;
598   };
599
600   /**
601    * @brief Attribute description
602    */
603   struct Attribute
604   {
605     Attribute(uint32_t _location, uint32_t _binding, uint32_t _offset, VertexInputFormat _format)
606     : location(_location),
607       binding(_binding),
608       offset(_offset),
609       format(_format)
610     {
611     }
612
613     uint32_t          location;
614     uint32_t          binding;
615     uint32_t          offset;
616     VertexInputFormat format;
617   };
618
619   VertexInputState(std::vector<Binding> _bufferBindings, std::vector<Attribute> _attributes)
620   : bufferBindings(std::move(_bufferBindings)),
621     attributes(std::move(_attributes))
622   {
623   }
624
625   std::vector<Binding>   bufferBindings{};
626   std::vector<Attribute> attributes{};
627 };
628
629 /**
630  * @brief List of all possible formats
631  * Not all formats may be supported
632  */
633 enum class Format
634 {
635   UNDEFINED,
636   // GLES compatible, luminance doesn't exist in Vulkan
637   L8,
638   L8A8,
639
640   // Vulkan compatible
641   R4G4_UNORM_PACK8,
642   R4G4B4A4_UNORM_PACK16,
643   B4G4R4A4_UNORM_PACK16,
644   R5G6B5_UNORM_PACK16,
645   B5G6R5_UNORM_PACK16,
646   R5G5B5A1_UNORM_PACK16,
647   B5G5R5A1_UNORM_PACK16,
648   A1R5G5B5_UNORM_PACK16,
649   R8_UNORM,
650   R8_SNORM,
651   R8_USCALED,
652   R8_SSCALED,
653   R8_UINT,
654   R8_SINT,
655   R8_SRGB,
656   R8G8_UNORM,
657   R8G8_SNORM,
658   R8G8_USCALED,
659   R8G8_SSCALED,
660   R8G8_UINT,
661   R8G8_SINT,
662   R8G8_SRGB,
663   R8G8B8_UNORM,
664   R8G8B8_SNORM,
665   R8G8B8_USCALED,
666   R8G8B8_SSCALED,
667   R8G8B8_UINT,
668   R8G8B8_SINT,
669   R8G8B8_SRGB,
670   B8G8R8_UNORM,
671   B8G8R8_SNORM,
672   B8G8R8_USCALED,
673   B8G8R8_SSCALED,
674   B8G8R8_UINT,
675   B8G8R8_SINT,
676   B8G8R8_SRGB,
677   R8G8B8A8_UNORM,
678   R8G8B8A8_SNORM,
679   R8G8B8A8_USCALED,
680   R8G8B8A8_SSCALED,
681   R8G8B8A8_UINT,
682   R8G8B8A8_SINT,
683   R8G8B8A8_SRGB,
684   B8G8R8A8_UNORM,
685   B8G8R8A8_SNORM,
686   B8G8R8A8_USCALED,
687   B8G8R8A8_SSCALED,
688   B8G8R8A8_UINT,
689   B8G8R8A8_SINT,
690   B8G8R8A8_SRGB,
691   A8B8G8R8_UNORM_PACK32,
692   A8B8G8R8_SNORM_PACK32,
693   A8B8G8R8_USCALED_PACK32,
694   A8B8G8R8_SSCALED_PACK32,
695   A8B8G8R8_UINT_PACK32,
696   A8B8G8R8_SINT_PACK32,
697   A8B8G8R8_SRGB_PACK32,
698   A2R10G10B10_UNORM_PACK32,
699   A2R10G10B10_SNORM_PACK32,
700   A2R10G10B10_USCALED_PACK32,
701   A2R10G10B10_SSCALED_PACK32,
702   A2R10G10B10_UINT_PACK32,
703   A2R10G10B10_SINT_PACK32,
704   A2B10G10R10_UNORM_PACK32,
705   A2B10G10R10_SNORM_PACK32,
706   A2B10G10R10_USCALED_PACK32,
707   A2B10G10R10_SSCALED_PACK32,
708   A2B10G10R10_UINT_PACK32,
709   A2B10G10R10_SINT_PACK32,
710   R16_UNORM,
711   R16_SNORM,
712   R16_USCALED,
713   R16_SSCALED,
714   R16_UINT,
715   R16_SINT,
716   R16_SFLOAT,
717   R16G16_UNORM,
718   R16G16_SNORM,
719   R16G16_USCALED,
720   R16G16_SSCALED,
721   R16G16_UINT,
722   R16G16_SINT,
723   R16G16_SFLOAT,
724   R16G16B16_UNORM,
725   R16G16B16_SNORM,
726   R16G16B16_USCALED,
727   R16G16B16_SSCALED,
728   R16G16B16_UINT,
729   R16G16B16_SINT,
730   R16G16B16_SFLOAT,
731   R16G16B16A16_UNORM,
732   R16G16B16A16_SNORM,
733   R16G16B16A16_USCALED,
734   R16G16B16A16_SSCALED,
735   R16G16B16A16_UINT,
736   R16G16B16A16_SINT,
737   R16G16B16A16_SFLOAT,
738   R32_UINT,
739   R32_SINT,
740   R32_SFLOAT,
741   R32G32_UINT,
742   R32G32_SINT,
743   R32G32_SFLOAT,
744   R32G32B32_UINT,
745   R32G32B32_SINT,
746   R32G32B32_SFLOAT,
747   R32G32B32A32_UINT,
748   R32G32B32A32_SINT,
749   R32G32B32A32_SFLOAT,
750   R64_UINT,
751   R64_SINT,
752   R64_SFLOAT,
753   R64G64_UINT,
754   R64G64_SINT,
755   R64G64_SFLOAT,
756   R64G64B64_UINT,
757   R64G64B64_SINT,
758   R64G64B64_SFLOAT,
759   R64G64B64A64_UINT,
760   R64G64B64A64_SINT,
761   R64G64B64A64_SFLOAT,
762   B10G11R11_UFLOAT_PACK32,
763   E5B9G9R9_UFLOAT_PACK32,
764   D16_UNORM,
765   X8_D24_UNORM_PACK32,
766   D32_SFLOAT,
767   S8_UINT,
768   D16_UNORM_S8_UINT,
769   D24_UNORM_S8_UINT,
770   D32_SFLOAT_S8_UINT,
771   BC1_RGB_UNORM_BLOCK,
772   BC1_RGB_SRGB_BLOCK,
773   BC1_RGBA_UNORM_BLOCK,
774   BC1_RGBA_SRGB_BLOCK,
775   BC2_UNORM_BLOCK,
776   BC2_SRGB_BLOCK,
777   BC3_UNORM_BLOCK,
778   BC3_SRGB_BLOCK,
779   BC4_UNORM_BLOCK,
780   BC4_SNORM_BLOCK,
781   BC5_UNORM_BLOCK,
782   BC5_SNORM_BLOCK,
783   BC6H_UFLOAT_BLOCK,
784   BC6H_SFLOAT_BLOCK,
785   BC7_UNORM_BLOCK,
786   BC7_SRGB_BLOCK,
787   ETC2_R8G8B8_UNORM_BLOCK,
788   ETC2_R8G8B8_SRGB_BLOCK,
789   ETC2_R8G8B8A1_UNORM_BLOCK,
790   ETC2_R8G8B8A1_SRGB_BLOCK,
791   ETC2_R8G8B8A8_UNORM_BLOCK,
792   ETC2_R8G8B8A8_SRGB_BLOCK,
793   EAC_R11_UNORM_BLOCK,
794   EAC_R11_SNORM_BLOCK,
795   EAC_R11G11_UNORM_BLOCK,
796   EAC_R11G11_SNORM_BLOCK,
797   ASTC_4x4_UNORM_BLOCK,
798   ASTC_4x4_SRGB_BLOCK,
799   ASTC_5x4_UNORM_BLOCK,
800   ASTC_5x4_SRGB_BLOCK,
801   ASTC_5x5_UNORM_BLOCK,
802   ASTC_5x5_SRGB_BLOCK,
803   ASTC_6x5_UNORM_BLOCK,
804   ASTC_6x5_SRGB_BLOCK,
805   ASTC_6x6_UNORM_BLOCK,
806   ASTC_6x6_SRGB_BLOCK,
807   ASTC_8x5_UNORM_BLOCK,
808   ASTC_8x5_SRGB_BLOCK,
809   ASTC_8x6_UNORM_BLOCK,
810   ASTC_8x6_SRGB_BLOCK,
811   ASTC_8x8_UNORM_BLOCK,
812   ASTC_8x8_SRGB_BLOCK,
813   ASTC_10x5_UNORM_BLOCK,
814   ASTC_10x5_SRGB_BLOCK,
815   ASTC_10x6_UNORM_BLOCK,
816   ASTC_10x6_SRGB_BLOCK,
817   ASTC_10x8_UNORM_BLOCK,
818   ASTC_10x8_SRGB_BLOCK,
819   ASTC_10x10_UNORM_BLOCK,
820   ASTC_10x10_SRGB_BLOCK,
821   ASTC_12x10_UNORM_BLOCK,
822   ASTC_12x10_SRGB_BLOCK,
823   ASTC_12x12_UNORM_BLOCK,
824   ASTC_12x12_SRGB_BLOCK,
825   PVRTC1_2BPP_UNORM_BLOCK_IMG,
826   PVRTC1_4BPP_UNORM_BLOCK_IMG,
827   PVRTC2_2BPP_UNORM_BLOCK_IMG,
828   PVRTC2_4BPP_UNORM_BLOCK_IMG,
829   PVRTC1_2BPP_SRGB_BLOCK_IMG,
830   PVRTC1_4BPP_SRGB_BLOCK_IMG,
831   PVRTC2_2BPP_SRGB_BLOCK_IMG,
832   PVRTC2_4BPP_SRGB_BLOCK_IMG,
833 };
834
835 /**
836  * @brief Flags specifying a buffer usage
837  */
838 enum class BufferUsage
839 {
840   TRANSFER_SRC         = 1 << 0,
841   TRANSFER_DST         = 1 << 1,
842   UNIFORM_TEXEL_BUFFER = 1 << 2,
843   STORAGE_TEXEL_BUFFER = 1 << 3,
844   UNIFORM_BUFFER       = 1 << 4,
845   STORAGE_BUFFER       = 1 << 5,
846   INDEX_BUFFER         = 1 << 6,
847   VERTEX_BUFFER        = 1 << 7,
848   INDIRECT_BUFFER      = 1 << 8,
849 };
850
851 using BufferUsageFlags = uint32_t;
852
853 inline BufferUsageFlags operator|(BufferUsageFlags flags, BufferUsage usage)
854 {
855   flags |= static_cast<uint32_t>(usage);
856   return flags;
857 }
858
859 /**
860  * @brief The structure describes memory requirements of GPU resource (texture, buffer)
861  */
862 struct MemoryRequirements
863 {
864   size_t size;
865   size_t alignment;
866 };
867
868 using TextureUpdateFlags = uint32_t;
869 enum class TextureUpdateFlagBits
870 {
871   KEEP_SOURCE = 1 << 0,
872 };
873
874 /**
875  * @brief Texture update info
876  *
877  * Describes the texture update to be executed by
878  * Controller::UpdateTextures()
879  */
880 struct TextureUpdateInfo
881 {
882   Texture* dstTexture{};
883   Offset2D dstOffset2D;
884   uint32_t layer{};
885   uint32_t level{};
886
887   uint32_t srcReference{};
888   Extent2D srcExtent2D{};
889   uint32_t srcOffset{};
890   uint32_t srcSize{};
891 };
892
893 /**
894  * @brief Texture update source info
895  *
896  * Describes the source of data (memory, buffer or another texture)
897  * to be used when updating textures using Controller::UpdateTextures().
898  */
899 struct TextureUpdateSourceInfo
900 {
901   enum class Type
902   {
903     BUFFER,
904     MEMORY,
905     TEXTURE
906   };
907
908   Type sourceType;
909
910   struct BufferSource
911   {
912     Buffer* buffer;
913   } bufferSource;
914
915   struct MemorySource
916   {
917     void* memory;
918   } memorySource;
919
920   struct TextureSource
921   {
922     Texture* texture;
923   } textureSource;
924 };
925
926 /**
927  * @brief Properties of texture
928  */
929 struct TextureProperties
930 {
931   Format   format;                   ///< Texture format
932   Format   format1;                  ///< Texture format (if emulated)
933   bool     emulated;                 ///< Format is emulated (for example RGB as RGBA)
934   bool     compressed;               ///< Texture is compressed
935   bool     packed;                   ///< Texture is packed
936   Extent2D extent2D;                 ///< Size of texture
937   bool     directWriteAccessEnabled; ///< Direct write access (mappable textures)
938 };
939
940 /**
941  * @brief Texture tiling that directly refers to the tiling
942  * mode supported by the Vulkan. Other implementations
943  * of the backend may ignore the value.
944  */
945 enum class TextureTiling
946 {
947   OPTIMAL,
948   LINEAR
949 };
950
951 /**
952  * @brief Texture color attachment used by FramebufferCreateInfo
953  */
954 struct ColorAttachment
955 {
956   uint32_t attachmentId;
957   Texture* texture;
958   uint32_t layerId;
959   uint32_t levelId;
960 };
961
962 /**
963  * @brief Depth stencil attachment used by FramebufferCreateInfo
964  */
965 struct DepthStencilAttachment
966 {
967   // TODO:
968 };
969
970 /**
971  * @brief Submit flags
972  */
973 using SubmitFlags = uint32_t;
974
975 /**
976  * Submit flag bits
977  */
978 enum class SubmitFlagBits : uint32_t
979 {
980   FLUSH         = 1 << 0, // Flush immediately
981   DONT_OPTIMIZE = 1 << 1  // Tells controller not to optimize commands
982 };
983
984 template<typename T>
985 inline SubmitFlags operator|(T flags, SubmitFlagBits bit)
986 {
987   return static_cast<SubmitFlags>(flags) | static_cast<SubmitFlags>(bit);
988 }
989
990 /**
991  * @brief Describes command buffers submission
992  */
993 struct SubmitInfo
994 {
995   std::vector<CommandBuffer*> cmdBuffer;
996   SubmitFlags                 flags;
997 };
998
999 /**
1000  * @brief Shader language enum
1001  */
1002 enum class ShaderLanguage
1003 {
1004   GLSL_1,
1005   GLSL_3_1,
1006   GLSL_3_2,
1007   SPIRV_1_0,
1008   SPIRV_1_1,
1009 };
1010
1011 /**
1012  * @brief Pipeline stages
1013  */
1014 enum class PipelineStage
1015 {
1016   TOP_OF_PIPELINE,
1017   VERTEX_SHADER,
1018   GEOMETRY_SHADER,
1019   FRAGMENT_SHADER,
1020   COMPUTE_SHADER,
1021   TESSELATION_CONTROL,
1022   TESSELATION_EVALUATION,
1023   BOTTOM_OF_PIPELINE
1024 };
1025
1026 /**
1027  * @brief Vertex attribute format
1028  *
1029  * TODO: to be replaced with Format
1030  */
1031 enum class VertexInputAttributeFormat
1032 {
1033   UNDEFINED,
1034   FLOAT,
1035   INTEGER,
1036   VEC2,
1037   VEC3,
1038   VEC4
1039 };
1040
1041 /**
1042  * @brief Uniform class
1043  */
1044 enum class UniformClass
1045 {
1046   SAMPLER,
1047   IMAGE,
1048   COMBINED_IMAGE_SAMPLER,
1049   UNIFORM_BUFFER,
1050   UNIFORM,
1051   UNDEFINED
1052 };
1053
1054 /**
1055  * @brief Type of texture
1056  */
1057 enum class TextureType
1058 {
1059   TEXTURE_2D,
1060   TEXTURE_3D,
1061   TEXTURE_CUBEMAP,
1062 };
1063
1064 /**
1065  * @brief The information of the uniform
1066  */
1067 struct UniformInfo
1068 {
1069   std::string  name{""};
1070   UniformClass uniformClass{UniformClass::UNDEFINED};
1071   uint32_t     binding{0u};
1072   uint32_t     bufferIndex{0u};
1073   uint32_t     offset{0u};
1074   uint32_t     location{0u};
1075
1076   bool operator==(const UniformInfo& rhs)
1077   {
1078     return name == rhs.name &&
1079            uniformClass == rhs.uniformClass &&
1080            binding == rhs.binding &&
1081            bufferIndex == rhs.bufferIndex &&
1082            offset == rhs.offset &&
1083            location == rhs.location;
1084   }
1085 };
1086
1087 /**
1088  * @brief The information of the uniform block
1089  */
1090 struct UniformBlockInfo
1091 {
1092   std::string              name{""};
1093   uint32_t                 descriptorSet{0u};
1094   uint32_t                 binding{0u};
1095   uint32_t                 size{0u};
1096   std::vector<UniformInfo> members{};
1097 };
1098
1099 /**
1100  * @brief Describes pipeline's shading stages
1101  *
1102  * Shader state binds shader and pipeline stage that the
1103  * shader will be executed. The shader may be created with
1104  * pipeline stage and the pipelineStage member may be ignored
1105  * by setting inheritPipelineStage to true.
1106  */
1107 struct ShaderState
1108 {
1109   const Shader* shader{nullptr};             // shader to attach
1110   PipelineStage pipelineStage{};             // pipeline stage to execute the shader
1111   bool          inheritPipelineStage{false}; // stage inheritance
1112
1113   auto& SetShader(const Shader& value)
1114   {
1115     shader = &value;
1116     return *this;
1117   }
1118
1119   auto& SetPipelineStage(PipelineStage value)
1120   {
1121     pipelineStage = value;
1122     return *this;
1123   }
1124
1125   auto& SetInheritPipelineStage(bool value)
1126   {
1127     inheritPipelineStage = value;
1128     return *this;
1129   }
1130 };
1131
1132 /**
1133  * @brief Flag determining usage of texture
1134  */
1135 using TextureUsageFlags = uint32_t;
1136 enum class TextureUsageFlagBits : uint32_t
1137 {
1138   SAMPLE                   = 1 << 0,
1139   COLOR_ATTACHMENT         = 1 << 1,
1140   DEPTH_STENCIL_ATTACHMENT = 1 << 2,
1141   DONT_CARE                = 1 << 4,
1142 };
1143
1144 template<typename T>
1145 inline TextureUsageFlags operator|(T flags, TextureUsageFlagBits bit)
1146 {
1147   return static_cast<TextureUsageFlags>(flags) | static_cast<TextureUsageFlags>(bit);
1148 }
1149
1150 using TextureFormat = Dali::Graphics::Format;
1151
1152 /**
1153  * @brief Texture mipmap disable/enable enum
1154  */
1155 enum class TextureMipMapFlag
1156 {
1157   ENABLED,
1158   DISABLED,
1159 };
1160
1161 /**
1162  * @brief Depth/stencil attachment flag
1163  */
1164 enum class TextureDepthStencilFlag
1165 {
1166   NONE,
1167   DEPTH,
1168   STENCIL,
1169   DEPTH_STENCIL,
1170 };
1171
1172 /**
1173  * @brief Layout of texture
1174  *
1175  * Specifies how the memory will be allocated, organized and accessed.
1176  */
1177 enum class TextureLayout
1178 {
1179   LINEAR, ///< Creates linear memory, mapping possible
1180   OPTIMAL ///< Usually, read-only memory, driver-optimal layout
1181 };
1182
1183 /**
1184  * @brief Level of command buffer
1185  */
1186 enum class CommandBufferLevel
1187 {
1188   PRIMARY,  ///< Primary buffer can be executed on its own
1189   SECONDARY ///< Secondary buffer must be executed within scope of Primary buffer
1190 };
1191
1192 /**
1193  * @brief Enum indicating whether shader source
1194  * is text-based or binary.
1195  */
1196 enum class ShaderSourceMode
1197 {
1198   TEXT,
1199   BINARY
1200 };
1201
1202 /**
1203  * @brief Memory usage flags to be set when mapping the buffer
1204  */
1205 using MemoryUsageFlags = uint32_t;
1206 enum class MemoryUsageFlagBits : uint32_t
1207 {
1208   WRITE        = 1 << 0,
1209   READ         = 1 << 1,
1210   PERSISTENT   = 1 << 2,
1211   ASYNCHRONOUS = 1 << 3,
1212   DONT_CARE    = 1 << 4,
1213 };
1214
1215 template<typename T>
1216 inline MemoryUsageFlags operator|(T flags, MemoryUsageFlagBits bit)
1217 {
1218   return static_cast<MemoryUsageFlags>(flags) | static_cast<MemoryUsageFlags>(bit);
1219 }
1220
1221 /**
1222  * @brief Describes buffer mapping details
1223  */
1224 struct MapBufferInfo
1225 {
1226   Buffer*          buffer;
1227   MemoryUsageFlags usage;
1228   uint32_t         offset;
1229   uint32_t         size;
1230 };
1231
1232 /**
1233  * @brief Describes buffer mapping details
1234  * TODO: mapping by texture level and layer
1235  */
1236 struct MapTextureInfo
1237 {
1238   Texture*         texture;
1239   MemoryUsageFlags usage;
1240   uint32_t         offset;
1241   uint32_t         size;
1242 };
1243
1244 /**
1245  * @brief GraphicsStructureType enum is used by all create info structures
1246  * in order to identify by the implementation which structure it is
1247  * dealing with.
1248  */
1249 enum class GraphicsStructureType : uint32_t
1250 {
1251   BUFFER_CREATE_INFO_STRUCT,
1252   COMMAND_BUFFER_CREATE_INFO_STRUCT,
1253   FRAMEBUFFER_CREATE_INFO_STRUCT,
1254   PIPELINE_CREATE_INFO_STRUCT,
1255   RENDERPASS_CREATE_INFO_STRUCT,
1256   SAMPLER_CREATE_INFO_STRUCT,
1257   SHADER_CREATE_INFO_STRUCT,
1258   TEXTURE_CREATE_INFO_STRUCT,
1259   RENDER_TARGET_CREATE_INFO_STRUCT
1260 };
1261
1262 /**
1263  * @brief Helper function to be used by the extension developers
1264  *
1265  * The value of custom type must be unique and recognizable by the
1266  * implementation.
1267  *
1268  * @param customValue Custom value of GraphicsStructureType
1269  * @return Integer converted to GraphicsStructureType
1270  */
1271 inline GraphicsStructureType GraphicsExtensionType(uint32_t customValue)
1272 {
1273   return static_cast<GraphicsStructureType>(customValue);
1274 }
1275
1276 /**
1277  * @brief The allocation callbacks may be passed when the object is created.
1278  */
1279 struct AllocationCallbacks
1280 {
1281   void* userData                                                                          = nullptr; ///< User data passed to the allocator
1282   void* (*allocCallback)(size_t size, size_t alignment, void* userData)                   = nullptr;
1283   void* (*reallocCallback)(void* original, size_t size, size_t alignment, void* userData) = nullptr;
1284   void (*freeCallback)(void* memory, void* userData)                                      = nullptr;
1285 };
1286
1287 /**
1288  * @brief The ExtensionCreateInfo structure should be a base of any
1289  * extension create info structure. The structure isn't virtual
1290  * so the implementation must prevent slicing it.
1291  */
1292 struct ExtensionCreateInfo
1293 {
1294   GraphicsStructureType type{};
1295   ExtensionCreateInfo*  nextExtension{};
1296 };
1297
1298 /**
1299  * @brief Default deleter for graphics unique pointers
1300  *
1301  * Returned unique_ptr may require custom deleter. To get it working
1302  * with std::unique_ptr the custom type is used with polymorphic deleter
1303  */
1304 template<class T>
1305 struct DefaultDeleter
1306 {
1307   DefaultDeleter() = default;
1308
1309   /**
1310    * @brief Conversion constructor
1311    *
1312    * This constructor will set the lambda for type passed
1313    * as an argument.
1314    */
1315   template<class P, template<typename> typename U>
1316   DefaultDeleter(const U<P>& deleter)
1317   {
1318     deleteFunction = [](T* object) { U<P>()(static_cast<P*>(object)); };
1319   }
1320
1321   /**
1322    * @brief Conversion constructor from DefaultDelete<P>
1323    *
1324    * This constructor transfers deleteFunction only
1325    */
1326   template<class P>
1327   explicit DefaultDeleter(const DefaultDeleter<P>& deleter)
1328   {
1329     deleteFunction = decltype(deleteFunction)(deleter.deleteFunction);
1330   }
1331
1332   /**
1333    * @brief Default deleter
1334    *
1335    * Default deleter will use standard 'delete' call in order
1336    * to discard graphics objects unless a custom deleter was
1337    * used.
1338    *
1339    * @param[in] object Object to delete
1340    */
1341   void operator()(T* object)
1342   {
1343     if(deleteFunction)
1344     {
1345       deleteFunction(object);
1346     }
1347     else
1348     {
1349       delete object;
1350     }
1351   }
1352
1353   void (*deleteFunction)(T* object){nullptr}; ///< Custom delete function
1354 };
1355
1356 /**
1357  * unique_ptr defined in the Graphics scope
1358  */
1359 template<class T, class D = DefaultDeleter<T>>
1360 using UniquePtr = std::unique_ptr<T, D>;
1361
1362 /**
1363  * @brief MakeUnique<> version that returns Graphics::UniquePtr
1364  * @param[in] args Arguments for construction
1365  * @return
1366  */
1367 template<class T, class Deleter = DefaultDeleter<T>, class... Args>
1368 std::enable_if_t<!std::is_array<T>::value, Graphics::UniquePtr<T>>
1369 MakeUnique(Args&&... args)
1370 {
1371   return UniquePtr<T>(new T(std::forward<Args>(args)...), Deleter());
1372 }
1373
1374 } // namespace Graphics
1375 } // namespace Dali
1376
1377 #endif //DALI_GRAPHICS_API_TYPES_H