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.
38 * @brief Structure describes 2D offset
47 * @brief Structure describes 2D dimensions
56 * @brief Structure describes 2D rectangle (offset, extent)
67 * @brief Structure represents area of viewport
75 float minDepth = 0.0f;
76 float maxDepth = 0.0f;
80 * @brief Describes vertex attribute input rate
82 enum class VertexInputRate
84 PER_VERTEX, ///< Attribute read per vertex
85 PER_INSTANCE ///< Attribute read per instance
89 * @brief Vertex input format
91 * When UNDEFINED, the reflection is used to determine what
92 * the actual format is.
94 enum class VertexInputFormat
108 * @brief Logic operators used by color blending state
109 * when logicOpEnable is set.
132 * @brief Blend factors
134 enum class BlendFactor
139 ONE_MINUS_SRC_COLOR = 3,
141 ONE_MINUS_DST_COLOR = 5,
143 ONE_MINUS_SRC_ALPHA = 7,
145 ONE_MINUS_DST_ALPHA = 9,
147 ONE_MINUS_CONSTANT_COLOR = 11,
149 ONE_MINUS_CONSTANT_ALPHA = 13,
150 SRC_ALPHA_SATURATE = 14,
152 ONE_MINUS_SRC1_COLOR = 16,
154 ONE_MINUS_SRC1_ALPHA = 18,
158 * @brief Blend operators
164 REVERSE_SUBTRACT = 2,
170 * @brief Compare operators
185 * @brief Stencil operators
200 * @brief Backface culling modes
211 * @brief Polygon drawing modes
213 enum class PolygonMode
221 * @brief Front face direction
230 * @brief Primitive geometry topology
232 enum class PrimitiveTopology
243 * @brief Sampler address ( wrapping ) mode
245 enum class SamplerAddressMode
255 * @brief Filtering mode
257 enum class SamplerFilter
266 enum class SamplerMipmapMode
274 * @brief Describes pipeline's color blend state
276 struct ColorBlendState
278 bool logicOpEnable = false;
279 LogicOp logicOp = {};
280 float blendConstants[4] = {0.0f, 0.0f, 0.0f, 0.0f};
281 bool blendEnable = false;
282 BlendFactor srcColorBlendFactor = BlendFactor::ZERO;
283 BlendFactor dstColorBlendFactor = BlendFactor::ZERO;
284 BlendOp colorBlendOp = {};
285 BlendFactor srcAlphaBlendFactor = BlendFactor::ZERO;
286 BlendFactor dstAlphaBlendFactor = BlendFactor::ZERO;
287 BlendOp alphaBlendOp = {};
288 uint32_t colorComponentWriteBits = {0u};
290 auto& SetLogicOpEnable(bool value)
292 logicOpEnable = value;
296 auto& SetLogicOp(LogicOp value)
302 auto& SetBlendConstants(float value[4])
304 std::copy(value, value + 4, blendConstants);
308 auto& SetBlendEnable(bool value)
314 auto& SetSrcColorBlendFactor(BlendFactor value)
316 srcColorBlendFactor = value;
320 auto& SetDstColorBlendFactor(BlendFactor value)
322 dstColorBlendFactor = value;
326 auto& SetColorBlendOp(BlendOp value)
328 colorBlendOp = value;
332 auto& SetSrcAlphaBlendFactor(BlendFactor value)
334 srcAlphaBlendFactor = value;
338 auto& SetDstAlphaBlendFactor(BlendFactor value)
340 dstAlphaBlendFactor = value;
344 auto& SetAlphaBlendOp(BlendOp value)
346 alphaBlendOp = value;
350 auto& SetColorComponentsWriteBits(uint32_t value)
352 colorComponentWriteBits = value;
358 * @brief Framebuffer state
360 struct FramebufferState
362 const Framebuffer* framebuffer{nullptr};
364 auto& SetFramebuffer(const Framebuffer& value)
366 framebuffer = &value;
372 * @brief Describes pipeline's viewport and scissor state
376 Viewport viewport{0.0, 0.0, 0.0, 0.0};
377 Rect2D scissor{0, 0, 0, 0};
378 bool scissorTestEnable{false};
380 auto& SetViewport(const Viewport& value)
386 auto& SetScissor(const Rect2D& value)
392 auto& SetScissorTestEnable(bool value)
394 scissorTestEnable = value;
400 * @brief Describes stencil operation state
402 struct StencilOpState
406 StencilOp depthFailOp{};
407 CompareOp compareOp{};
408 uint32_t compareMask{0u};
409 uint32_t writeMask{0u};
410 uint32_t reference{0u};
412 auto& SetFailOp(StencilOp value)
418 auto& SetPassOp(StencilOp value)
424 auto& SetDepthFailOp(StencilOp value)
430 auto& SetCompareOp(CompareOp value)
436 auto& SetCompareMask(uint32_t value)
442 auto& SetWriteMask(uint32_t value)
448 auto& SetReference(uint32_t value)
456 * @brief Describes pipeline's viewport and scissor state
458 struct DepthStencilState
460 bool depthTestEnable{false};
461 bool depthWriteEnable{false};
462 CompareOp depthCompareOp{};
464 bool stencilTestEnable{false};
465 StencilOpState front{};
466 StencilOpState back{};
468 auto& SetDepthTestEnable(bool value)
470 depthTestEnable = value;
474 auto& SetDepthWriteEnable(bool value)
476 depthWriteEnable = value;
480 auto& SetDepthCompareOp(CompareOp value)
482 depthCompareOp = value;
486 auto& SetFront(StencilOpState value)
492 auto& SetBack(StencilOpState value)
498 auto& SetStencilTestEnable(bool value)
500 stencilTestEnable = value;
506 * @brief Rasterization state descriptor
508 struct RasterizationState
511 PolygonMode polygonMode{};
512 FrontFace frontFace{};
514 auto& SetCullMode(CullMode value)
520 auto& SetPolygonMode(PolygonMode value)
526 auto& SetFrontFace(FrontFace value)
534 * @brief Input assembly state descriptor.
536 * Structure describes the topology for submitted
539 struct InputAssemblyState
541 PrimitiveTopology topology{};
542 bool primitiveRestartEnable{true};
544 auto& SetTopology(PrimitiveTopology value)
550 auto& SetPrimitiveRestartEnable(bool value)
552 primitiveRestartEnable = true;
558 * @brief Pipeline dynamic state bits
560 namespace PipelineDynamicStateBits
562 const uint32_t VIEWPORT_BIT = 1 << 0;
563 const uint32_t SCISSOR_BIT = 1 << 1;
564 const uint32_t LINE_WIDTH_BIT = 1 << 2;
565 const uint32_t DEPTH_BIAS_BIT = 1 << 3;
566 const uint32_t BLEND_CONSTANTS_BIT = 1 << 4;
567 const uint32_t DEPTH_BOUNDS_BIT = 1 << 5;
568 const uint32_t STENCIL_COMPARE_MASK_BIT = 1 << 6;
569 const uint32_t STENCIL_WRITE_MASK_BIT = 1 << 7;
570 const uint32_t STENCIL_REFERENCE_BIT = 1 << 8;
571 } // namespace PipelineDynamicStateBits
573 const uint32_t PIPELINE_DYNAMIC_STATE_COUNT(9u);
575 using PipelineDynamicStateMask = uint32_t;
578 * @brief Structure describes vertex input state of the pipeline.
579 * It specifies buffer binding and attribute format to be used.
581 struct VertexInputState
583 VertexInputState() = default;
586 * @brief Vertex buffer binding
590 Binding(uint32_t _stride, VertexInputRate _inputRate)
592 inputRate(_inputRate)
596 VertexInputRate inputRate;
600 * @brief Attribute description
604 Attribute(uint32_t _location, uint32_t _binding, uint32_t _offset, VertexInputFormat _format)
605 : location(_location),
615 VertexInputFormat format;
618 VertexInputState(std::vector<Binding> _bufferBindings, std::vector<Attribute> _attributes)
619 : bufferBindings(std::move(_bufferBindings)),
620 attributes(std::move(_attributes))
624 std::vector<Binding> bufferBindings{};
625 std::vector<Attribute> attributes{};
629 * @brief List of all possible formats
630 * Not all formats may be supported
635 // GLES compatible, luminance doesn't exist in Vulkan
641 R4G4B4A4_UNORM_PACK16,
642 B4G4R4A4_UNORM_PACK16,
645 R5G5B5A1_UNORM_PACK16,
646 B5G5R5A1_UNORM_PACK16,
647 A1R5G5B5_UNORM_PACK16,
690 A8B8G8R8_UNORM_PACK32,
691 A8B8G8R8_SNORM_PACK32,
692 A8B8G8R8_USCALED_PACK32,
693 A8B8G8R8_SSCALED_PACK32,
694 A8B8G8R8_UINT_PACK32,
695 A8B8G8R8_SINT_PACK32,
696 A8B8G8R8_SRGB_PACK32,
697 A2R10G10B10_UNORM_PACK32,
698 A2R10G10B10_SNORM_PACK32,
699 A2R10G10B10_USCALED_PACK32,
700 A2R10G10B10_SSCALED_PACK32,
701 A2R10G10B10_UINT_PACK32,
702 A2R10G10B10_SINT_PACK32,
703 A2B10G10R10_UNORM_PACK32,
704 A2B10G10R10_SNORM_PACK32,
705 A2B10G10R10_USCALED_PACK32,
706 A2B10G10R10_SSCALED_PACK32,
707 A2B10G10R10_UINT_PACK32,
708 A2B10G10R10_SINT_PACK32,
732 R16G16B16A16_USCALED,
733 R16G16B16A16_SSCALED,
761 B10G11R11_UFLOAT_PACK32,
762 E5B9G9R9_UFLOAT_PACK32,
772 BC1_RGBA_UNORM_BLOCK,
786 ETC2_R8G8B8_UNORM_BLOCK,
787 ETC2_R8G8B8_SRGB_BLOCK,
788 ETC2_R8G8B8A1_UNORM_BLOCK,
789 ETC2_R8G8B8A1_SRGB_BLOCK,
790 ETC2_R8G8B8A8_UNORM_BLOCK,
791 ETC2_R8G8B8A8_SRGB_BLOCK,
794 EAC_R11G11_UNORM_BLOCK,
795 EAC_R11G11_SNORM_BLOCK,
796 ASTC_4x4_UNORM_BLOCK,
798 ASTC_5x4_UNORM_BLOCK,
800 ASTC_5x5_UNORM_BLOCK,
802 ASTC_6x5_UNORM_BLOCK,
804 ASTC_6x6_UNORM_BLOCK,
806 ASTC_8x5_UNORM_BLOCK,
808 ASTC_8x6_UNORM_BLOCK,
810 ASTC_8x8_UNORM_BLOCK,
812 ASTC_10x5_UNORM_BLOCK,
813 ASTC_10x5_SRGB_BLOCK,
814 ASTC_10x6_UNORM_BLOCK,
815 ASTC_10x6_SRGB_BLOCK,
816 ASTC_10x8_UNORM_BLOCK,
817 ASTC_10x8_SRGB_BLOCK,
818 ASTC_10x10_UNORM_BLOCK,
819 ASTC_10x10_SRGB_BLOCK,
820 ASTC_12x10_UNORM_BLOCK,
821 ASTC_12x10_SRGB_BLOCK,
822 ASTC_12x12_UNORM_BLOCK,
823 ASTC_12x12_SRGB_BLOCK,
824 PVRTC1_2BPP_UNORM_BLOCK_IMG,
825 PVRTC1_4BPP_UNORM_BLOCK_IMG,
826 PVRTC2_2BPP_UNORM_BLOCK_IMG,
827 PVRTC2_4BPP_UNORM_BLOCK_IMG,
828 PVRTC1_2BPP_SRGB_BLOCK_IMG,
829 PVRTC1_4BPP_SRGB_BLOCK_IMG,
830 PVRTC2_2BPP_SRGB_BLOCK_IMG,
831 PVRTC2_4BPP_SRGB_BLOCK_IMG,
835 * @brief Flags specifying a buffer usage
837 enum class BufferUsage
839 TRANSFER_SRC = 1 << 0,
840 TRANSFER_DST = 1 << 1,
841 UNIFORM_TEXEL_BUFFER = 1 << 2,
842 STORAGE_TEXEL_BUFFER = 1 << 3,
843 UNIFORM_BUFFER = 1 << 4,
844 STORAGE_BUFFER = 1 << 5,
845 INDEX_BUFFER = 1 << 6,
846 VERTEX_BUFFER = 1 << 7,
847 INDIRECT_BUFFER = 1 << 8,
850 using BufferUsageFlags = uint32_t;
852 inline BufferUsageFlags operator|(BufferUsageFlags flags, BufferUsage usage)
854 flags |= static_cast<uint32_t>(usage);
859 * @brief The structure describes memory requirements of GPU resource (texture, buffer)
861 struct MemoryRequirements
867 using TextureUpdateFlags = uint32_t;
868 enum class TextureUpdateFlagBits
870 KEEP_SOURCE = 1 << 0,
874 * @brief Texture update info
876 * Describes the texture update to be executed by
877 * Controller::UpdateTextures()
879 struct TextureUpdateInfo
881 Texture* dstTexture{};
882 Offset2D dstOffset2D;
886 uint32_t srcReference{};
887 Extent2D srcExtent2D{};
888 uint32_t srcOffset{};
893 * @brief Texture update source info
895 * Describes the source of data (memory, buffer or another texture)
896 * to be used when updating textures using Controller::UpdateTextures().
898 struct TextureUpdateSourceInfo
926 * @brief Properties of texture
928 struct TextureProperties
930 Format format; ///< Texture format
931 Format format1; ///< Texture format (if emulated)
932 bool emulated; ///< Format is emulated (for example RGB as RGBA)
933 bool compressed; ///< Texture is compressed
934 bool packed; ///< Texture is packed
935 Extent2D extent2D; ///< Size of texture
936 bool directWriteAccessEnabled; ///< Direct write access (mappable textures)
940 * @brief Texture tiling that directly refers to the tiling
941 * mode supported by the Vulkan. Other implementations
942 * of the backend may ignore the value.
944 enum class TextureTiling
951 * @brief Texture color attachment used by FramebufferCreateInfo
953 struct ColorAttachment
955 uint32_t attachmentId;
962 * @brief Depth stencil attachment used by FramebufferCreateInfo
964 struct DepthStencilAttachment
970 * @brief Submit flags
972 using SubmitFlags = uint32_t;
977 enum class SubmitFlagBits : uint32_t
979 FLUSH = 1 << 0, // Flush immediately
980 DONT_OPTIMIZE = 1 << 1 // Tells controller not to optimize commands
984 inline SubmitFlags operator|(T flags, SubmitFlagBits bit)
986 return static_cast<SubmitFlags>(flags) | static_cast<SubmitFlags>(bit);
990 * @brief Describes command buffers submission
994 std::vector<CommandBuffer*> cmdBuffer;
999 * @brief Shader language enum
1001 enum class ShaderLanguage
1011 * @brief Pipeline stages
1013 enum class PipelineStage
1020 TESSELATION_CONTROL,
1021 TESSELATION_EVALUATION,
1026 * @brief Vertex attribute format
1028 * TODO: to be replaced with Format
1030 enum class VertexInputAttributeFormat
1041 * @brief Type of texture
1043 enum class TextureType
1051 * @brief Describes pipeline's shading stages
1053 * Shader state binds shader and pipeline stage that the
1054 * shader will be executed. The shader may be created with
1055 * pipeline stage and the pipelineStage member may be ignored
1056 * by setting inheritPipelineStage to true.
1060 const Shader* shader{nullptr}; // shader to attach
1061 PipelineStage pipelineStage{}; // pipeline stage to execute the shader
1062 bool inheritPipelineStage{false}; // stage inheritance
1064 auto& SetShader(const Shader& value)
1070 auto& SetPipelineStage(PipelineStage value)
1072 pipelineStage = value;
1076 auto& SetInheritPipelineStage(bool value)
1078 inheritPipelineStage = value;
1084 * @brief Flag determining usage of texture
1086 using TextureUsageFlags = uint32_t;
1087 enum class TextureUsageFlagBits : uint32_t
1090 COLOR_ATTACHMENT = 1 << 1,
1091 DEPTH_STENCIL_ATTACHMENT = 1 << 2,
1095 template<typename T>
1096 inline TextureUsageFlags operator|(T flags, TextureUsageFlagBits bit)
1098 return static_cast<TextureUsageFlags>(flags) | static_cast<TextureUsageFlags>(bit);
1101 using TextureFormat = Dali::Graphics::Format;
1104 * @brief Texture mipmap disable/enable enum
1106 enum class TextureMipMapFlag
1113 * @brief Depth/stencil attachment flag
1115 enum class TextureDepthStencilFlag
1124 * @brief Layout of texture
1126 * Specifies how the memory will be allocated, organized and accessed.
1128 enum class TextureLayout
1130 LINEAR, ///< Creates linear memory, mapping possible
1131 OPTIMAL ///< Usually, read-only memory, driver-optimal layout
1135 * @brief Level of command buffer
1137 enum class CommandBufferLevel
1139 PRIMARY, ///< Primary buffer can be executed on its own
1140 SECONDARY ///< Secondary buffer must be executed within scope of Primary buffer
1144 * @brief Enum indicating whether shader source
1145 * is text-based or binary.
1147 enum class ShaderSourceMode
1154 * @brief Memory usage flags to be set when mapping the buffer
1156 using MemoryUsageFlags = uint32_t;
1157 enum class MemoryUsageFlagBits : uint32_t
1161 PERSISTENT = 1 << 2,
1162 ASYNCHRONOUS = 1 << 3,
1166 template<typename T>
1167 inline MemoryUsageFlags operator|(T flags, MemoryUsageFlagBits bit)
1169 return static_cast<MemoryUsageFlags>(flags) | static_cast<MemoryUsageFlags>(bit);
1173 * @brief Describes buffer mapping details
1175 struct MapBufferInfo
1178 MemoryUsageFlags usage;
1184 * @brief Describes buffer mapping details
1185 * TODO: mapping by texture level and layer
1187 struct MapTextureInfo
1190 MemoryUsageFlags usage;
1196 * @brief GraphicsStructureType enum is used by all create info structures
1197 * in order to identify by the implementation which structure it is
1200 enum class GraphicsStructureType : uint32_t
1202 BUFFER_CREATE_INFO_STRUCT,
1203 COMMAND_BUFFER_CREATE_INFO_STRUCT,
1204 FRAMEBUFFER_CREATE_INFO_STRUCT,
1205 PIPELINE_CREATE_INFO_STRUCT,
1206 RENDERPASS_CREATE_INFO_STRUCT,
1207 SAMPLER_CREATE_INFO_STRUCT,
1208 SHADER_CREATE_INFO_STRUCT,
1209 TEXTURE_CREATE_INFO_STRUCT,
1210 RENDER_TARGET_CREATE_INFO_STRUCT
1214 * @brief Helper function to be used by the extension developers
1216 * The value of custom type must be unique and recognizable by the
1219 * @param customValue Custom value of GraphicsStructureType
1220 * @return Integer converted to GraphicsStructureType
1222 inline GraphicsStructureType GraphicsExtensionType(uint32_t customValue)
1224 return static_cast<GraphicsStructureType>(customValue);
1228 * @brief The allocation callbacks may be passed when the object is created.
1230 struct AllocationCallbacks
1232 void* userData = nullptr; ///< User data passed to the allocator
1233 void* (*allocCallback)(size_t size, size_t alignment, void* userData) = nullptr;
1234 void* (*reallocCallback)(void* original, size_t size, size_t alignment, void* userData) = nullptr;
1235 void (*freeCallback)(void* memory, void* userData) = nullptr;
1239 * @brief The ExtensionCreateInfo structure should be a base of any
1240 * extension create info structure. The structure isn't virtual
1241 * so the implementation must prevent slicing it.
1243 struct ExtensionCreateInfo
1245 GraphicsStructureType type{};
1246 ExtensionCreateInfo* nextExtension{};
1250 * @brief Default deleter for graphics unique pointers
1252 * Returned unique_ptr may require custom deleter. To get it working
1253 * with std::unique_ptr the custom type is used with polymorphic deleter
1256 struct DefaultDeleter
1258 DefaultDeleter() = default;
1261 * @brief Conversion constructor
1263 * This constructor will set the lambda for type passed
1266 template<class P, template<typename> typename U>
1267 DefaultDeleter(const U<P>& deleter)
1269 deleteFunction = [](T* object) { U<P>()(static_cast<P*>(object)); };
1273 * @brief Conversion constructor from DefaultDelete<P>
1275 * This constructor transfers deleteFunction only
1278 explicit DefaultDeleter(const DefaultDeleter<P>& deleter)
1280 deleteFunction = decltype(deleteFunction)(deleter.deleteFunction);
1284 * @brief Default deleter
1286 * Default deleter will use standard 'delete' call in order
1287 * to discard graphics objects unless a custom deleter was
1290 * @param[in] object Object to delete
1292 void operator()(T* object)
1296 deleteFunction(object);
1304 void (*deleteFunction)(T* object){nullptr}; ///< Custom delete function
1308 * unique_ptr defined in the Graphics scope
1310 template<class T, class D = DefaultDeleter<T>>
1311 using UniquePtr = std::unique_ptr<T, D>;
1314 * @brief MakeUnique<> version that returns Graphics::UniquePtr
1315 * @param[in] args Arguments for construction
1318 template<class T, class Deleter = DefaultDeleter<T>, class... Args>
1319 std::enable_if_t<!std::is_array<T>::value, Graphics::UniquePtr<T>>
1320 MakeUnique(Args&&... args)
1322 return UniquePtr<T>(new T(std::forward<Args>(args)...), Deleter());
1325 } // namespace Graphics
1328 #endif //DALI_GRAPHICS_API_TYPES_H