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.
37 * @brief Structure describes 2D offset
46 * @brief Structure describes 2D dimensions
55 * @brief Structure describes 2D rectangle (offset, extent)
66 * @brief Structure represents area of viewport
74 float minDepth = 0.0f;
75 float maxDepth = 0.0f;
79 * @brief Describes vertex attribute input rate
81 enum class VertexInputRate
83 PER_VERTEX, ///< Attribute read per vertex
84 PER_INSTANCE ///< Attribute read per instance
88 * @brief Vertex input format
90 * When UNDEFINED, the reflection is used to determine what
91 * the actual format is.
93 enum class VertexInputFormat
107 * @brief Logic operators used by color blending state
108 * when logicOpEnable is set.
131 * @brief Blend factors
133 enum class BlendFactor
138 ONE_MINUS_SRC_COLOR = 3,
140 ONE_MINUS_DST_COLOR = 5,
142 ONE_MINUS_SRC_ALPHA = 7,
144 ONE_MINUS_DST_ALPHA = 9,
146 ONE_MINUS_CONSTANT_COLOR = 11,
148 ONE_MINUS_CONSTANT_ALPHA = 13,
149 SRC_ALPHA_SATURATE = 14,
151 ONE_MINUS_SRC1_COLOR = 16,
153 ONE_MINUS_SRC1_ALPHA = 18,
157 * @brief Blend operators
163 REVERSE_SUBTRACT = 2,
169 * @brief Compare operators
184 * @brief Stencil operators
199 * @brief Backface culling modes
210 * @brief Polygon drawing modes
212 enum class PolygonMode
220 * @brief Front face direction
229 * @brief Primitive geometry topology
231 enum class PrimitiveTopology
242 * @brief Sampler address ( wrapping ) mode
244 enum class SamplerAddressMode
254 * @brief Filtering mode
256 enum class SamplerFilter
265 enum class SamplerMipmapMode
273 * @brief Describes pipeline's color blend state
275 struct ColorBlendState
277 bool logicOpEnable = false;
278 LogicOp logicOp = {};
279 float blendConstants[4] = {0.0f, 0.0f, 0.0f, 0.0f};
280 bool blendEnable = false;
281 BlendFactor srcColorBlendFactor = BlendFactor::ZERO;
282 BlendFactor dstColorBlendFactor = BlendFactor::ZERO;
283 BlendOp colorBlendOp = {};
284 BlendFactor srcAlphaBlendFactor = BlendFactor::ZERO;
285 BlendFactor dstAlphaBlendFactor = BlendFactor::ZERO;
286 BlendOp alphaBlendOp = {};
287 uint32_t colorComponentWriteBits = {0u};
289 auto& SetLogicOpEnable(bool value)
291 logicOpEnable = value;
295 auto& SetLogicOp(LogicOp value)
301 auto& SetBlendConstants(float value[4])
303 std::copy(value, value + 4, blendConstants);
307 auto& SetBlendEnable(bool value)
313 auto& SetSrcColorBlendFactor(BlendFactor value)
315 srcColorBlendFactor = value;
319 auto& SetDstColorBlendFactor(BlendFactor value)
321 dstColorBlendFactor = value;
325 auto& SetColorBlendOp(BlendOp value)
327 colorBlendOp = value;
331 auto& SetSrcAlphaBlendFactor(BlendFactor value)
333 srcAlphaBlendFactor = value;
337 auto& SetDstAlphaBlendFactor(BlendFactor value)
339 dstAlphaBlendFactor = value;
343 auto& SetAlphaBlendOp(BlendOp value)
345 alphaBlendOp = value;
349 auto& SetColorComponentsWriteBits(uint32_t value)
351 colorComponentWriteBits = value;
357 * @brief Framebuffer state
359 struct FramebufferState
361 const Framebuffer* framebuffer{nullptr};
363 auto& SetFramebuffer(const Framebuffer& value)
365 framebuffer = &value;
371 * @brief Describes pipeline's viewport and scissor state
375 Viewport viewport{0.0, 0.0, 0.0, 0.0};
376 Rect2D scissor{0, 0, 0, 0};
377 bool scissorTestEnable{false};
379 auto& SetViewport(const Viewport& value)
385 auto& SetScissor(const Rect2D& value)
391 auto& SetScissorTestEnable(bool value)
393 scissorTestEnable = value;
399 * @brief Describes stencil operation state
401 struct StencilOpState
405 StencilOp depthFailOp{};
406 CompareOp compareOp{};
407 uint32_t compareMask{0u};
408 uint32_t writeMask{0u};
409 uint32_t reference{0u};
411 auto& SetFailOp(StencilOp value)
417 auto& SetPassOp(StencilOp value)
423 auto& SetDepthFailOp(StencilOp value)
429 auto& SetCompareOp(CompareOp value)
435 auto& SetCompareMask(uint32_t value)
441 auto& SetWriteMask(uint32_t value)
447 auto& SetReference(uint32_t value)
455 * @brief Describes pipeline's viewport and scissor state
457 struct DepthStencilState
459 bool depthTestEnable{false};
460 bool depthWriteEnable{false};
461 CompareOp depthCompareOp{};
463 bool stencilTestEnable{false};
464 StencilOpState front{};
465 StencilOpState back{};
467 auto& SetDepthTestEnable(bool value)
469 depthTestEnable = value;
473 auto& SetDepthWriteEnable(bool value)
475 depthWriteEnable = value;
479 auto& SetDepthCompareOp(CompareOp value)
481 depthCompareOp = value;
485 auto& SetFront(StencilOpState value)
491 auto& SetBack(StencilOpState value)
497 auto& SetStencilTestEnable(bool value)
499 stencilTestEnable = value;
505 * @brief Rasterization state descriptor
507 struct RasterizationState
510 PolygonMode polygonMode{};
511 FrontFace frontFace{};
513 auto& SetCullMode(CullMode value)
519 auto& SetPolygonMode(PolygonMode value)
525 auto& SetFrontFace(FrontFace value)
533 * @brief Input assembly state descriptor.
535 * Structure describes the topology for submitted
538 struct InputAssemblyState
540 PrimitiveTopology topology{};
541 bool primitiveRestartEnable{true};
543 auto& SetTopology(PrimitiveTopology value)
549 auto& SetPrimitiveRestartEnable(bool value)
551 primitiveRestartEnable = true;
557 * @brief Pipeline dynamic state bits
559 namespace PipelineDynamicStateBits
561 const uint32_t VIEWPORT_BIT = 1 << 0;
562 const uint32_t SCISSOR_BIT = 1 << 1;
563 const uint32_t LINE_WIDTH_BIT = 1 << 2;
564 const uint32_t DEPTH_BIAS_BIT = 1 << 3;
565 const uint32_t BLEND_CONSTANTS_BIT = 1 << 4;
566 const uint32_t DEPTH_BOUNDS_BIT = 1 << 5;
567 const uint32_t STENCIL_COMPARE_MASK_BIT = 1 << 6;
568 const uint32_t STENCIL_WRITE_MASK_BIT = 1 << 7;
569 const uint32_t STENCIL_REFERENCE_BIT = 1 << 8;
570 } // namespace PipelineDynamicStateBits
572 const uint32_t PIPELINE_DYNAMIC_STATE_COUNT(9u);
574 using PipelineDynamicStateMask = uint32_t;
577 * @brief Structure describes vertex input state of the pipeline.
578 * It specifies buffer binding and attribute format to be used.
580 struct VertexInputState
582 VertexInputState() = default;
585 * @brief Vertex buffer binding
589 Binding(uint32_t _stride, VertexInputRate _inputRate)
591 inputRate(_inputRate)
595 VertexInputRate inputRate;
599 * @brief Attribute description
603 Attribute(uint32_t _location, uint32_t _binding, uint32_t _offset, VertexInputFormat _format)
604 : location(_location),
614 VertexInputFormat format;
617 VertexInputState(std::vector<Binding> _bufferBindings, std::vector<Attribute> _attributes)
618 : bufferBindings(std::move(_bufferBindings)),
619 attributes(std::move(_attributes))
623 std::vector<Binding> bufferBindings{};
624 std::vector<Attribute> attributes{};
628 * @brief List of all possible formats
629 * Not all formats may be supported
634 // GLES compatible, luminance doesn't exist in Vulkan
640 R4G4B4A4_UNORM_PACK16,
641 B4G4R4A4_UNORM_PACK16,
644 R5G5B5A1_UNORM_PACK16,
645 B5G5R5A1_UNORM_PACK16,
646 A1R5G5B5_UNORM_PACK16,
689 A8B8G8R8_UNORM_PACK32,
690 A8B8G8R8_SNORM_PACK32,
691 A8B8G8R8_USCALED_PACK32,
692 A8B8G8R8_SSCALED_PACK32,
693 A8B8G8R8_UINT_PACK32,
694 A8B8G8R8_SINT_PACK32,
695 A8B8G8R8_SRGB_PACK32,
696 A2R10G10B10_UNORM_PACK32,
697 A2R10G10B10_SNORM_PACK32,
698 A2R10G10B10_USCALED_PACK32,
699 A2R10G10B10_SSCALED_PACK32,
700 A2R10G10B10_UINT_PACK32,
701 A2R10G10B10_SINT_PACK32,
702 A2B10G10R10_UNORM_PACK32,
703 A2B10G10R10_SNORM_PACK32,
704 A2B10G10R10_USCALED_PACK32,
705 A2B10G10R10_SSCALED_PACK32,
706 A2B10G10R10_UINT_PACK32,
707 A2B10G10R10_SINT_PACK32,
731 R16G16B16A16_USCALED,
732 R16G16B16A16_SSCALED,
760 B10G11R11_UFLOAT_PACK32,
761 E5B9G9R9_UFLOAT_PACK32,
771 BC1_RGBA_UNORM_BLOCK,
785 ETC2_R8G8B8_UNORM_BLOCK,
786 ETC2_R8G8B8_SRGB_BLOCK,
787 ETC2_R8G8B8A1_UNORM_BLOCK,
788 ETC2_R8G8B8A1_SRGB_BLOCK,
789 ETC2_R8G8B8A8_UNORM_BLOCK,
790 ETC2_R8G8B8A8_SRGB_BLOCK,
793 EAC_R11G11_UNORM_BLOCK,
794 EAC_R11G11_SNORM_BLOCK,
795 ASTC_4x4_UNORM_BLOCK,
797 ASTC_5x4_UNORM_BLOCK,
799 ASTC_5x5_UNORM_BLOCK,
801 ASTC_6x5_UNORM_BLOCK,
803 ASTC_6x6_UNORM_BLOCK,
805 ASTC_8x5_UNORM_BLOCK,
807 ASTC_8x6_UNORM_BLOCK,
809 ASTC_8x8_UNORM_BLOCK,
811 ASTC_10x5_UNORM_BLOCK,
812 ASTC_10x5_SRGB_BLOCK,
813 ASTC_10x6_UNORM_BLOCK,
814 ASTC_10x6_SRGB_BLOCK,
815 ASTC_10x8_UNORM_BLOCK,
816 ASTC_10x8_SRGB_BLOCK,
817 ASTC_10x10_UNORM_BLOCK,
818 ASTC_10x10_SRGB_BLOCK,
819 ASTC_12x10_UNORM_BLOCK,
820 ASTC_12x10_SRGB_BLOCK,
821 ASTC_12x12_UNORM_BLOCK,
822 ASTC_12x12_SRGB_BLOCK,
823 PVRTC1_2BPP_UNORM_BLOCK_IMG,
824 PVRTC1_4BPP_UNORM_BLOCK_IMG,
825 PVRTC2_2BPP_UNORM_BLOCK_IMG,
826 PVRTC2_4BPP_UNORM_BLOCK_IMG,
827 PVRTC1_2BPP_SRGB_BLOCK_IMG,
828 PVRTC1_4BPP_SRGB_BLOCK_IMG,
829 PVRTC2_2BPP_SRGB_BLOCK_IMG,
830 PVRTC2_4BPP_SRGB_BLOCK_IMG,
834 * @brief Flags specifying a buffer usage
836 enum class BufferUsage
838 TRANSFER_SRC = 1 << 0,
839 TRANSFER_DST = 1 << 1,
840 UNIFORM_TEXEL_BUFFER = 1 << 2,
841 STORAGE_TEXEL_BUFFER = 1 << 3,
842 UNIFORM_BUFFER = 1 << 4,
843 STORAGE_BUFFER = 1 << 5,
844 INDEX_BUFFER = 1 << 6,
845 VERTEX_BUFFER = 1 << 7,
846 INDIRECT_BUFFER = 1 << 8,
849 using BufferUsageFlags = uint32_t;
851 inline BufferUsageFlags operator|(BufferUsageFlags flags, BufferUsage usage)
853 flags |= static_cast<uint32_t>(usage);
858 * @brief The structure describes memory requirements of GPU resource (texture, buffer)
860 struct MemoryRequirements
866 using TextureUpdateFlags = uint32_t;
867 enum class TextureUpdateFlagBits
869 KEEP_SOURCE = 1 << 0,
873 * @brief Texture update info
875 * Describes the texture update to be executed by
876 * Controller::UpdateTextures()
878 struct TextureUpdateInfo
880 Texture* dstTexture{};
881 Offset2D dstOffset2D;
885 uint32_t srcReference{};
886 Extent2D srcExtent2D{};
887 uint32_t srcOffset{};
892 * @brief Texture update source info
894 * Describes the source of data (memory, buffer or another texture)
895 * to be used when updating textures using Controller::UpdateTextures().
897 struct TextureUpdateSourceInfo
925 * @brief Properties of texture
927 struct TextureProperties
929 Format format; ///< Texture format
930 Format format1; ///< Texture format (if emulated)
931 bool emulated; ///< Format is emulated (for example RGB as RGBA)
932 bool compressed; ///< Texture is compressed
933 bool packed; ///< Texture is packed
934 Extent2D extent2D; ///< Size of texture
935 bool directWriteAccessEnabled; ///< Direct write access (mappable textures)
939 * @brief Texture tiling that directly refers to the tiling
940 * mode supported by the Vulkan. Other implementations
941 * of the backend may ignore the value.
943 enum class TextureTiling
950 * @brief Texture color attachment used by FramebufferCreateInfo
952 struct ColorAttachment
954 uint32_t attachmentId;
961 * @brief Depth stencil attachment used by FramebufferCreateInfo
963 struct DepthStencilAttachment
969 * @brief Submit flags
971 using SubmitFlags = uint32_t;
976 enum class SubmitFlagBits : uint32_t
978 FLUSH = 1 << 0, // Flush immediately
979 DONT_OPTIMIZE = 1 << 1 // Tells controller not to optimize commands
983 inline SubmitFlags operator|(T flags, SubmitFlagBits bit)
985 return static_cast<SubmitFlags>(flags) | static_cast<SubmitFlags>(bit);
989 * @brief Describes command buffers submission
993 std::vector<CommandBuffer*> cmdBuffer;
998 * @brief Shader language enum
1000 enum class ShaderLanguage
1010 * @brief Pipeline stages
1012 enum class PipelineStage
1019 TESSELATION_CONTROL,
1020 TESSELATION_EVALUATION,
1025 * @brief Vertex attribute format
1027 * TODO: to be replaced with Format
1029 enum class VertexInputAttributeFormat
1040 * @brief Type of texture
1042 enum class TextureType
1050 * @brief Describes pipeline's shading stages
1052 * Shader state binds shader and pipeline stage that the
1053 * shader will be executed. The shader may be created with
1054 * pipeline stage and the pipelineStage member may be ignored
1055 * by setting inheritPipelineStage to true.
1059 const Shader* shader{nullptr}; // shader to attach
1060 PipelineStage pipelineStage{}; // pipeline stage to execute the shader
1061 bool inheritPipelineStage{false}; // stage inheritance
1063 auto& SetShader(const Shader& value)
1069 auto& SetPipelineStage(PipelineStage value)
1071 pipelineStage = value;
1075 auto& SetInheritPipelineStage(bool value)
1077 inheritPipelineStage = value;
1083 * @brief Flag determining usage of texture
1085 using TextureUsageFlags = uint32_t;
1086 enum class TextureUsageFlagBits : uint32_t
1089 COLOR_ATTACHMENT = 1 << 1,
1090 DEPTH_STENCIL_ATTACHMENT = 1 << 2,
1094 template<typename T>
1095 inline TextureUsageFlags operator|(T flags, TextureUsageFlagBits bit)
1097 return static_cast<TextureUsageFlags>(flags) | static_cast<TextureUsageFlags>(bit);
1100 using TextureFormat = Dali::Graphics::Format;
1103 * @brief Texture mipmap disable/enable enum
1105 enum class TextureMipMapFlag
1112 * @brief Depth/stencil attachment flag
1114 enum class TextureDepthStencilFlag
1123 * @brief Layout of texture
1125 * Specifies how the memory will be allocated, organized and accessed.
1127 enum class TextureLayout
1129 LINEAR, ///< Creates linear memory, mapping possible
1130 OPTIMAL ///< Usually, read-only memory, driver-optimal layout
1134 * @brief Level of command buffer
1136 enum class CommandBufferLevel
1138 PRIMARY, ///< Primary buffer can be executed on its own
1139 SECONDARY ///< Secondary buffer must be executed within scope of Primary buffer
1143 * @brief Enum indicating whether shader source
1144 * is text-based or binary.
1146 enum class ShaderSourceMode
1153 * @brief Memory usage flags to be set when mapping the buffer
1155 using MemoryUsageFlags = uint32_t;
1156 enum class MemoryUsageFlagBits : uint32_t
1160 PERSISTENT = 1 << 2,
1161 ASYNCHRONOUS = 1 << 3,
1165 template<typename T>
1166 inline MemoryUsageFlags operator|(T flags, MemoryUsageFlagBits bit)
1168 return static_cast<MemoryUsageFlags>(flags) | static_cast<MemoryUsageFlags>(bit);
1172 * @brief Describes buffer mapping details
1174 struct MapBufferInfo
1177 MemoryUsageFlags usage;
1183 * @brief Describes buffer mapping details
1184 * TODO: mapping by texture level and layer
1186 struct MapTextureInfo
1189 MemoryUsageFlags usage;
1195 * @brief GraphicsStructureType enum is used by all create info structures
1196 * in order to identify by the implementation which structure it is
1199 enum class GraphicsStructureType : uint32_t
1201 BUFFER_CREATE_INFO_STRUCT,
1202 COMMAND_BUFFER_CREATE_INFO_STRUCT,
1203 FRAMEBUFFER_CREATE_INFO_STRUCT,
1204 PIPELINE_CREATE_INFO_STRUCT,
1205 RENDERPASS_CREATE_INFO_STRUCT,
1206 SAMPLER_CREATE_INFO_STRUCT,
1207 SHADER_CREATE_INFO_STRUCT,
1208 TEXTURE_CREATE_INFO_STRUCT,
1209 RENDER_TARGET_CREATE_INFO_STRUCT
1213 * @brief Helper function to be used by the extension developers
1215 * The value of custom type must be unique and recognizable by the
1218 * @param customValue Custom value of GraphicsStructureType
1219 * @return Integer converted to GraphicsStructureType
1221 inline GraphicsStructureType GraphicsExtensionType(uint32_t customValue)
1223 return static_cast<GraphicsStructureType>(customValue);
1227 * @brief The allocation callbacks may be passed when the object is created.
1229 struct AllocationCallbacks
1231 void* userData = nullptr; ///< User data passed to the allocator
1232 void* (*allocCallback)(size_t size, size_t alignment, void* userData) = nullptr;
1233 void* (*reallocCallback)(void* original, size_t size, size_t alignment, void* userData) = nullptr;
1234 void (*freeCallback)(void* memory, void* userData) = nullptr;
1238 * @brief The ExtensionCreateInfo structure should be a base of any
1239 * extension create info structure. The structure isn't virtual
1240 * so the implementation must prevent slicing it.
1242 struct ExtensionCreateInfo
1244 GraphicsStructureType type{};
1245 ExtensionCreateInfo* nextExtension{};
1248 } // namespace Graphics
1251 #endif //DALI_GRAPHICS_API_TYPES_H