1 #ifndef DALI_GRAPHICS_API_TYPES
2 #define DALI_GRAPHICS_API_TYPES
5 * Copyright (c) 2021 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
39 * @brief Structure describes 2D offset
48 * @brief Structure describes 2D dimensions
57 * @brief Structure describes 2D rectangle (offset, extent)
68 * @brief Structure represents area of viewport
76 float minDepth = 0.0f;
77 float maxDepth = 0.0f;
81 * @brief Describes vertex attribute input rate
83 enum class VertexInputRate
85 PER_VERTEX, ///< Attribute read per vertex
86 PER_INSTANCE ///< Attribute read per instance
90 * @brief Vertex input format
92 * When UNDEFINED, the reflection is used to determine what
93 * the actual format is.
95 enum class VertexInputFormat
109 * @brief Logic operators used by color blending state
110 * when logicOpEnable is set.
133 * @brief Blend factors
135 enum class BlendFactor
140 ONE_MINUS_SRC_COLOR = 3,
142 ONE_MINUS_DST_COLOR = 5,
144 ONE_MINUS_SRC_ALPHA = 7,
146 ONE_MINUS_DST_ALPHA = 9,
148 ONE_MINUS_CONSTANT_COLOR = 11,
150 ONE_MINUS_CONSTANT_ALPHA = 13,
151 SRC_ALPHA_SATURATE = 14,
153 ONE_MINUS_SRC1_COLOR = 16,
155 ONE_MINUS_SRC1_ALPHA = 18,
159 * @brief Blend operators
165 REVERSE_SUBTRACT = 2,
171 * @brief Compare operators
186 * @brief Stencil operators
201 * @brief Backface culling modes
212 * @brief Polygon drawing modes
214 enum class PolygonMode
222 * @brief Front face direction
231 * @brief Primitive geometry topology
233 enum class PrimitiveTopology
245 * @brief Sampler address ( wrapping ) mode
247 enum class SamplerAddressMode
257 * @brief Filtering mode
259 enum class SamplerFilter
268 enum class SamplerMipmapMode
276 * @brief Describes pipeline's color blend state
278 struct ColorBlendState
280 bool logicOpEnable = false;
281 LogicOp logicOp = {};
282 float blendConstants[4] = {0.0f, 0.0f, 0.0f, 0.0f};
283 bool blendEnable = false;
284 BlendFactor srcColorBlendFactor = BlendFactor::ZERO;
285 BlendFactor dstColorBlendFactor = BlendFactor::ZERO;
286 BlendOp colorBlendOp = {};
287 BlendFactor srcAlphaBlendFactor = BlendFactor::ZERO;
288 BlendFactor dstAlphaBlendFactor = BlendFactor::ZERO;
289 BlendOp alphaBlendOp = {};
290 uint32_t colorComponentWriteBits = {0u};
292 auto& SetLogicOpEnable(bool value)
294 logicOpEnable = value;
298 auto& SetLogicOp(LogicOp value)
304 auto& SetBlendConstants(float value[4])
306 std::copy(value, value + 4, blendConstants);
310 auto& SetBlendEnable(bool value)
316 auto& SetSrcColorBlendFactor(BlendFactor value)
318 srcColorBlendFactor = value;
322 auto& SetDstColorBlendFactor(BlendFactor value)
324 dstColorBlendFactor = value;
328 auto& SetColorBlendOp(BlendOp value)
330 colorBlendOp = value;
334 auto& SetSrcAlphaBlendFactor(BlendFactor value)
336 srcAlphaBlendFactor = value;
340 auto& SetDstAlphaBlendFactor(BlendFactor value)
342 dstAlphaBlendFactor = value;
346 auto& SetAlphaBlendOp(BlendOp value)
348 alphaBlendOp = value;
352 auto& SetColorComponentsWriteBits(uint32_t value)
354 colorComponentWriteBits = value;
360 * @brief Program State
364 const Program* program{nullptr};
366 auto& SetProgram(const Program& value)
374 * @brief Framebuffer state.
376 struct FramebufferState
378 const Framebuffer* framebuffer{nullptr};
380 auto& SetFramebuffer(const Framebuffer& value)
382 framebuffer = &value;
388 * @brief Describes pipeline's viewport and scissor state
392 Viewport viewport{0.0, 0.0, 0.0, 0.0};
393 Rect2D scissor{0, 0, 0, 0};
394 bool scissorTestEnable{false};
396 auto& SetViewport(const Viewport& value)
402 auto& SetScissor(const Rect2D& value)
408 auto& SetScissorTestEnable(bool value)
410 scissorTestEnable = value;
416 * @brief Describes stencil operation state
418 struct StencilOpState
422 StencilOp depthFailOp{};
423 CompareOp compareOp{};
424 uint32_t compareMask{0u};
425 uint32_t writeMask{0u};
426 uint32_t reference{0u};
428 auto& SetFailOp(StencilOp value)
434 auto& SetPassOp(StencilOp value)
440 auto& SetDepthFailOp(StencilOp value)
446 auto& SetCompareOp(CompareOp value)
452 auto& SetCompareMask(uint32_t value)
458 auto& SetWriteMask(uint32_t value)
464 auto& SetReference(uint32_t value)
472 * @brief Describes pipeline's viewport and scissor state
474 struct DepthStencilState
476 bool depthTestEnable{false};
477 bool depthWriteEnable{false};
478 CompareOp depthCompareOp{};
480 bool stencilTestEnable{false};
481 StencilOpState front{};
482 StencilOpState back{};
484 auto& SetDepthTestEnable(bool value)
486 depthTestEnable = value;
490 auto& SetDepthWriteEnable(bool value)
492 depthWriteEnable = value;
496 auto& SetDepthCompareOp(CompareOp value)
498 depthCompareOp = value;
502 auto& SetFront(StencilOpState value)
508 auto& SetBack(StencilOpState value)
514 auto& SetStencilTestEnable(bool value)
516 stencilTestEnable = value;
522 * @brief Rasterization state descriptor
524 struct RasterizationState
527 PolygonMode polygonMode{};
528 FrontFace frontFace{};
530 auto& SetCullMode(CullMode value)
536 auto& SetPolygonMode(PolygonMode value)
542 auto& SetFrontFace(FrontFace value)
550 * @brief Input assembly state descriptor.
552 * Structure describes the topology for submitted
555 struct InputAssemblyState
557 PrimitiveTopology topology{};
558 bool primitiveRestartEnable{true};
560 auto& SetTopology(PrimitiveTopology value)
566 auto& SetPrimitiveRestartEnable(bool value)
568 primitiveRestartEnable = true;
574 * @brief Pipeline dynamic state bits
576 namespace PipelineDynamicStateBits
578 const uint32_t VIEWPORT_BIT = 1 << 0;
579 const uint32_t SCISSOR_BIT = 1 << 1;
580 const uint32_t LINE_WIDTH_BIT = 1 << 2;
581 const uint32_t DEPTH_BIAS_BIT = 1 << 3;
582 const uint32_t BLEND_CONSTANTS_BIT = 1 << 4;
583 const uint32_t DEPTH_BOUNDS_BIT = 1 << 5;
584 const uint32_t STENCIL_COMPARE_MASK_BIT = 1 << 6;
585 const uint32_t STENCIL_WRITE_MASK_BIT = 1 << 7;
586 const uint32_t STENCIL_REFERENCE_BIT = 1 << 8;
587 } // namespace PipelineDynamicStateBits
589 const uint32_t PIPELINE_DYNAMIC_STATE_COUNT(9u);
591 using PipelineDynamicStateMask = uint32_t;
594 * @brief Structure describes vertex input state of the pipeline.
595 * It specifies buffer binding and attribute format to be used.
597 struct VertexInputState
599 VertexInputState() = default;
602 * @brief Vertex buffer binding
606 Binding(uint32_t _stride, VertexInputRate _inputRate)
608 inputRate(_inputRate)
612 VertexInputRate inputRate;
616 * @brief Attribute description
620 Attribute(uint32_t _location, uint32_t _binding, uint32_t _offset, VertexInputFormat _format)
621 : location(_location),
631 VertexInputFormat format;
634 VertexInputState(std::vector<Binding> _bufferBindings, std::vector<Attribute> _attributes)
635 : bufferBindings(std::move(_bufferBindings)),
636 attributes(std::move(_attributes))
640 std::vector<Binding> bufferBindings{};
641 std::vector<Attribute> attributes{};
645 * @brief List of all possible formats
646 * Not all formats may be supported
651 // GLES compatible, luminance doesn't exist in Vulkan
657 R4G4B4A4_UNORM_PACK16,
658 B4G4R4A4_UNORM_PACK16,
661 R5G5B5A1_UNORM_PACK16,
662 B5G5R5A1_UNORM_PACK16,
663 A1R5G5B5_UNORM_PACK16,
706 A8B8G8R8_UNORM_PACK32,
707 A8B8G8R8_SNORM_PACK32,
708 A8B8G8R8_USCALED_PACK32,
709 A8B8G8R8_SSCALED_PACK32,
710 A8B8G8R8_UINT_PACK32,
711 A8B8G8R8_SINT_PACK32,
712 A8B8G8R8_SRGB_PACK32,
713 A2R10G10B10_UNORM_PACK32,
714 A2R10G10B10_SNORM_PACK32,
715 A2R10G10B10_USCALED_PACK32,
716 A2R10G10B10_SSCALED_PACK32,
717 A2R10G10B10_UINT_PACK32,
718 A2R10G10B10_SINT_PACK32,
719 A2B10G10R10_UNORM_PACK32,
720 A2B10G10R10_SNORM_PACK32,
721 A2B10G10R10_USCALED_PACK32,
722 A2B10G10R10_SSCALED_PACK32,
723 A2B10G10R10_UINT_PACK32,
724 A2B10G10R10_SINT_PACK32,
748 R16G16B16A16_USCALED,
749 R16G16B16A16_SSCALED,
777 B10G11R11_UFLOAT_PACK32,
778 E5B9G9R9_UFLOAT_PACK32,
788 BC1_RGBA_UNORM_BLOCK,
802 ETC2_R8G8B8_UNORM_BLOCK,
803 ETC2_R8G8B8_SRGB_BLOCK,
804 ETC2_R8G8B8A1_UNORM_BLOCK,
805 ETC2_R8G8B8A1_SRGB_BLOCK,
806 ETC2_R8G8B8A8_UNORM_BLOCK,
807 ETC2_R8G8B8A8_SRGB_BLOCK,
810 EAC_R11G11_UNORM_BLOCK,
811 EAC_R11G11_SNORM_BLOCK,
812 ASTC_4x4_UNORM_BLOCK,
814 ASTC_5x4_UNORM_BLOCK,
816 ASTC_5x5_UNORM_BLOCK,
818 ASTC_6x5_UNORM_BLOCK,
820 ASTC_6x6_UNORM_BLOCK,
822 ASTC_8x5_UNORM_BLOCK,
824 ASTC_8x6_UNORM_BLOCK,
826 ASTC_8x8_UNORM_BLOCK,
828 ASTC_10x5_UNORM_BLOCK,
829 ASTC_10x5_SRGB_BLOCK,
830 ASTC_10x6_UNORM_BLOCK,
831 ASTC_10x6_SRGB_BLOCK,
832 ASTC_10x8_UNORM_BLOCK,
833 ASTC_10x8_SRGB_BLOCK,
834 ASTC_10x10_UNORM_BLOCK,
835 ASTC_10x10_SRGB_BLOCK,
836 ASTC_12x10_UNORM_BLOCK,
837 ASTC_12x10_SRGB_BLOCK,
838 ASTC_12x12_UNORM_BLOCK,
839 ASTC_12x12_SRGB_BLOCK,
840 PVRTC1_2BPP_UNORM_BLOCK_IMG,
841 PVRTC1_4BPP_UNORM_BLOCK_IMG,
842 PVRTC2_2BPP_UNORM_BLOCK_IMG,
843 PVRTC2_4BPP_UNORM_BLOCK_IMG,
844 PVRTC1_2BPP_SRGB_BLOCK_IMG,
845 PVRTC1_4BPP_SRGB_BLOCK_IMG,
846 PVRTC2_2BPP_SRGB_BLOCK_IMG,
847 PVRTC2_4BPP_SRGB_BLOCK_IMG,
851 * @brief Flags specifying a buffer usage
853 enum class BufferUsage
855 TRANSFER_SRC = 1 << 0,
856 TRANSFER_DST = 1 << 1,
857 UNIFORM_TEXEL_BUFFER = 1 << 2,
858 STORAGE_TEXEL_BUFFER = 1 << 3,
859 UNIFORM_BUFFER = 1 << 4,
860 STORAGE_BUFFER = 1 << 5,
861 INDEX_BUFFER = 1 << 6,
862 VERTEX_BUFFER = 1 << 7,
863 INDIRECT_BUFFER = 1 << 8,
866 using BufferUsageFlags = uint32_t;
868 inline BufferUsageFlags operator|(BufferUsageFlags flags, BufferUsage usage)
870 flags |= static_cast<uint32_t>(usage);
875 * @brief Buffer property bits
877 * Use these bits to set BufferPropertiesFlags.
879 enum class BufferPropertiesFlagBit : uint32_t
881 CPU_ALLOCATED = 1 << 0, ///< Buffer is allocated on the CPU side
882 TRANSIENT_MEMORY = 1 << 1, ///< Buffer memory will be short-lived
886 * @brief BufferPropetiesFlags alters behaviour of implementation
888 using BufferPropertiesFlags = uint32_t;
890 inline BufferPropertiesFlags operator|(BufferPropertiesFlags flags, BufferPropertiesFlagBit usage)
892 flags |= static_cast<uint32_t>(usage);
897 * @brief The structure describes memory requirements of GPU resource (texture, buffer)
899 struct MemoryRequirements
905 using TextureUpdateFlags = uint32_t;
906 enum class TextureUpdateFlagBits
908 KEEP_SOURCE = 1 << 0,
912 * @brief Texture update info
914 * Describes the texture update to be executed by
915 * Controller::UpdateTextures()
917 struct TextureUpdateInfo
919 Texture* dstTexture{};
920 Offset2D dstOffset2D;
924 uint32_t srcReference{};
925 Extent2D srcExtent2D{};
926 uint32_t srcOffset{};
931 * @brief Texture update source info
933 * Describes the source of data (memory, buffer or another texture)
934 * to be used when updating textures using Controller::UpdateTextures().
936 struct TextureUpdateSourceInfo
964 * @brief Properties of texture
966 struct TextureProperties
968 Format format; ///< Texture format
969 Format format1; ///< Texture format (if emulated)
970 bool emulated; ///< Format is emulated (for example RGB as RGBA)
971 bool compressed; ///< Texture is compressed
972 bool packed; ///< Texture is packed
973 Extent2D extent2D; ///< Size of texture
974 bool directWriteAccessEnabled; ///< Direct write access (mappable textures)
978 * @brief Texture tiling that directly refers to the tiling
979 * mode supported by the Vulkan. Other implementations
980 * of the backend may ignore the value.
982 enum class TextureTiling
989 * @brief Texture color attachment used by FramebufferCreateInfo
991 struct ColorAttachment
993 uint32_t attachmentId;
1000 * @brief Depth stencil attachment used by FramebufferCreateInfo
1002 struct DepthStencilAttachment
1005 Texture* depthTexture;
1006 Texture* stencilTexture;
1007 uint32_t depthLevel;
1008 uint32_t stencilLevel;
1012 * @brief Submit flags
1014 using SubmitFlags = uint32_t;
1019 enum class SubmitFlagBits : uint32_t
1021 FLUSH = 1 << 0, // Flush immediately
1022 DONT_OPTIMIZE = 1 << 1 // Tells controller not to optimize commands
1025 template<typename T>
1026 inline SubmitFlags operator|(T flags, SubmitFlagBits bit)
1028 return static_cast<SubmitFlags>(flags) | static_cast<SubmitFlags>(bit);
1032 * @brief Describes command buffers submission
1036 std::vector<CommandBuffer*> cmdBuffer;
1041 * @brief Shader language enum
1043 enum class ShaderLanguage
1053 * @brief Pipeline stages
1055 enum class PipelineStage
1062 TESSELATION_CONTROL,
1063 TESSELATION_EVALUATION,
1068 * @brief Vertex attribute format
1070 * TODO: to be replaced with Format
1072 enum class VertexInputAttributeFormat
1083 * @brief Uniform class
1085 enum class UniformClass
1089 COMBINED_IMAGE_SAMPLER,
1096 * @brief Type of texture
1098 enum class TextureType
1106 * @brief The information of the uniform
1110 std::string name{""};
1111 UniformClass uniformClass{UniformClass::UNDEFINED};
1112 uint32_t binding{0u};
1113 uint32_t bufferIndex{0u};
1114 uint32_t offset{0u};
1115 uint32_t location{0u};
1117 bool operator==(const UniformInfo& rhs)
1119 return name == rhs.name &&
1120 uniformClass == rhs.uniformClass &&
1121 binding == rhs.binding &&
1122 bufferIndex == rhs.bufferIndex &&
1123 offset == rhs.offset &&
1124 location == rhs.location;
1129 * @brief The information of the uniform block
1131 struct UniformBlockInfo
1133 std::string name{""};
1134 uint32_t descriptorSet{0u};
1135 uint32_t binding{0u};
1137 std::vector<UniformInfo> members{};
1141 * @brief Describes pipeline's shading stages
1143 * Shader state binds shader and pipeline stage that the
1144 * shader will be executed. The shader may be created with
1145 * pipeline stage and the pipelineStage member may be ignored
1146 * by setting inheritPipelineStage to true.
1150 const Shader* shader{nullptr}; // shader to attach
1151 PipelineStage pipelineStage{}; // pipeline stage to execute the shader
1152 bool inheritPipelineStage{false}; // stage inheritance
1154 auto& SetShader(const Shader& value)
1160 auto& SetPipelineStage(PipelineStage value)
1162 pipelineStage = value;
1166 auto& SetInheritPipelineStage(bool value)
1168 inheritPipelineStage = value;
1174 * @brief Flag determining usage of texture
1176 using TextureUsageFlags = uint32_t;
1177 enum class TextureUsageFlagBits : uint32_t
1180 COLOR_ATTACHMENT = 1 << 1,
1181 DEPTH_STENCIL_ATTACHMENT = 1 << 2,
1185 template<typename T>
1186 inline TextureUsageFlags operator|(T flags, TextureUsageFlagBits bit)
1188 return static_cast<TextureUsageFlags>(flags) | static_cast<TextureUsageFlags>(bit);
1191 using TextureFormat = Dali::Graphics::Format;
1194 * @brief Texture mipmap disable/enable enum
1196 enum class TextureMipMapFlag
1203 * @brief Depth/stencil attachment flag
1205 enum class TextureDepthStencilFlag
1214 * @brief Layout of texture
1216 * Specifies how the memory will be allocated, organized and accessed.
1218 enum class TextureLayout
1220 LINEAR, ///< Creates linear memory, mapping possible
1221 OPTIMAL ///< Usually, read-only memory, driver-optimal layout
1225 * @brief Level of command buffer
1227 enum class CommandBufferLevel
1229 PRIMARY, ///< Primary buffer can be executed on its own
1230 SECONDARY ///< Secondary buffer must be executed within scope of Primary buffer
1234 * @brief Enum indicating whether shader source
1235 * is text-based or binary.
1237 enum class ShaderSourceMode
1244 * @brief Memory usage flags to be set when mapping the buffer
1246 using MemoryUsageFlags = uint32_t;
1247 enum class MemoryUsageFlagBits : uint32_t
1251 PERSISTENT = 1 << 2,
1252 ASYNCHRONOUS = 1 << 3,
1256 template<typename T>
1257 inline MemoryUsageFlags operator|(T flags, MemoryUsageFlagBits bit)
1259 return static_cast<MemoryUsageFlags>(flags) | static_cast<MemoryUsageFlags>(bit);
1263 * @brief Describes buffer mapping details
1265 struct MapBufferInfo
1268 MemoryUsageFlags usage;
1274 * @brief Describes buffer mapping details
1275 * TODO: mapping by texture level and layer
1277 struct MapTextureInfo
1280 MemoryUsageFlags usage;
1286 * @brief GraphicsStructureType enum is used by all create info structures
1287 * in order to identify by the implementation which structure it is
1290 enum class GraphicsStructureType : uint32_t
1292 BUFFER_CREATE_INFO_STRUCT,
1293 COMMAND_BUFFER_CREATE_INFO_STRUCT,
1294 FRAMEBUFFER_CREATE_INFO_STRUCT,
1295 PROGRAM_CREATE_INFO_STRUCT,
1296 PIPELINE_CREATE_INFO_STRUCT,
1297 RENDERPASS_CREATE_INFO_STRUCT,
1298 SAMPLER_CREATE_INFO_STRUCT,
1299 SHADER_CREATE_INFO_STRUCT,
1300 TEXTURE_CREATE_INFO_STRUCT,
1301 RENDER_TARGET_CREATE_INFO_STRUCT
1305 * @brief Helper function to be used by the extension developers
1307 * The value of custom type must be unique and recognizable by the
1310 * @param customValue Custom value of GraphicsStructureType
1311 * @return Integer converted to GraphicsStructureType
1313 inline GraphicsStructureType GraphicsExtensionType(uint32_t customValue)
1315 return static_cast<GraphicsStructureType>(customValue);
1319 * @brief The allocation callbacks may be passed when the object is created.
1321 struct AllocationCallbacks
1323 void* userData = nullptr; ///< User data passed to the allocator
1324 void* (*allocCallback)(size_t size, size_t alignment, void* userData) = nullptr;
1325 void* (*reallocCallback)(void* original, size_t size, size_t alignment, void* userData) = nullptr;
1326 void (*freeCallback)(void* memory, void* userData) = nullptr;
1330 * @brief The ExtensionCreateInfo structure should be a base of any
1331 * extension create info structure. The structure isn't virtual
1332 * so the implementation must prevent slicing it.
1334 struct ExtensionCreateInfo
1336 GraphicsStructureType type{};
1337 ExtensionCreateInfo* nextExtension{};
1341 * @brief Default deleter for graphics unique pointers
1343 * Returned unique_ptr may require custom deleter. To get it working
1344 * with std::unique_ptr the custom type is used with polymorphic deleter
1347 struct DefaultDeleter
1349 DefaultDeleter() = default;
1352 * @brief Conversion constructor
1354 * This constructor will set the lambda for type passed
1357 template<class P, template<typename> typename U>
1358 DefaultDeleter(const U<P>& deleter)
1360 deleteFunction = [](T* object) { U<P>()(static_cast<P*>(object)); };
1364 * @brief Conversion constructor from DefaultDelete<P>
1366 * This constructor transfers deleteFunction only
1369 explicit DefaultDeleter(const DefaultDeleter<P>& deleter)
1371 deleteFunction = decltype(deleteFunction)(deleter.deleteFunction);
1375 * @brief Default deleter
1377 * Default deleter will use standard 'delete' call in order
1378 * to discard graphics objects unless a custom deleter was
1381 * @param[in] object Object to delete
1383 void operator()(T* object)
1387 deleteFunction(object);
1395 void (*deleteFunction)(T* object){nullptr}; ///< Custom delete function
1399 * unique_ptr defined in the Graphics scope
1401 template<class T, class D = DefaultDeleter<T>>
1402 using UniquePtr = std::unique_ptr<T, D>;
1405 * @brief MakeUnique<> version that returns Graphics::UniquePtr
1406 * @param[in] args Arguments for construction
1409 template<class T, class Deleter = DefaultDeleter<T>, class... Args>
1410 std::enable_if_t<!std::is_array<T>::value, Graphics::UniquePtr<T>>
1411 MakeUnique(Args&&... args)
1413 return UniquePtr<T>(new T(std::forward<Args>(args)...), Deleter());
1416 } // namespace Graphics
1419 #endif //DALI_GRAPHICS_API_TYPES_H