1 /* 2 * Copyright (c) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef SCENE_INTERFACE_RESOURCE_BITMAP_INFO_H 17 #define SCENE_INTERFACE_RESOURCE_BITMAP_INFO_H 18 19 #include <scene/base/namespace.h> 20 #include <scene/base/types.h> 21 22 #include <base/util/formats.h> 23 #include <core/resources/intf_resource.h> 24 25 #include <meta/base/interface_macros.h> 26 27 SCENE_BEGIN_NAMESPACE() 28 29 enum class ImageLoadFlags : uint32_t { 30 /** Generate mipmaps if not already included in the image file. */ 31 GENERATE_MIPS = 0x00000001, 32 /** Force linear RGB. */ 33 FORCE_LINEAR_RGB_BIT = 0x00000002, 34 /** Force SRGB. */ 35 FORCE_SRGB_BIT = 0x00000004, 36 /** Force grayscale. */ 37 FORCE_GRAYSCALE_BIT = 0x00000008, 38 /** Flip image vertically when loaded. */ 39 FLIP_VERTICALLY_BIT = 0x00000010, 40 /** Premultiply color values with the alpha value if an alpha channel is present. */ 41 PREMULTIPLY_ALPHA = 0x00000020, 42 }; 43 constexpr inline ImageLoadFlags operator|(ImageLoadFlags l, ImageLoadFlags r) 44 { 45 return ImageLoadFlags(uint32_t(l) | uint32_t(r)); 46 } 47 48 /** Image usage flags */ 49 enum class ImageUsageFlag : uint32_t { 50 /** Transfer source bit */ 51 TRANSFER_SRC_BIT = 0x00000001, 52 /** Transfer destination bit */ 53 TRANSFER_DST_BIT = 0x00000002, 54 /** Sampled bit */ 55 SAMPLED_BIT = 0x00000004, 56 /** Storage bit */ 57 STORAGE_BIT = 0x00000008, 58 /** Color attachment bit */ 59 COLOR_ATTACHMENT_BIT = 0x00000010, 60 /** Depth stencil attachment bit */ 61 DEPTH_STENCIL_ATTACHMENT_BIT = 0x00000020, 62 /** Transient attachment bit */ 63 TRANSIENT_ATTACHMENT_BIT = 0x00000040, 64 /** Input attachment bit */ 65 INPUT_ATTACHMENT_BIT = 0x00000080, 66 /** Fragment shading rate attachment bit */ 67 FRAGMENT_SHADING_RATE_ATTACHMENT_BIT = 0x00000100, 68 }; 69 constexpr inline ImageUsageFlag operator|(ImageUsageFlag l, ImageUsageFlag r) 70 { 71 return ImageUsageFlag(uint32_t(l) | uint32_t(r)); 72 } 73 74 enum class MemoryPropertyFlag : uint32_t { 75 /** Device local bit */ 76 DEVICE_LOCAL_BIT = 0x00000001, 77 /** Host visible bit */ 78 HOST_VISIBLE_BIT = 0x00000002, 79 /** Host visible bit */ 80 HOST_COHERENT_BIT = 0x00000004, 81 /** Host cached bit, always preferred not required for allocation */ 82 HOST_CACHED_BIT = 0x00000008, 83 /** Lazily allocated bit, always preferred not required for allocation */ 84 LAZILY_ALLOCATED_BIT = 0x00000010, 85 /** Protected bit, always preferred not required for allocation */ 86 PROTECTED_BIT = 0x00000020, 87 }; 88 constexpr inline MemoryPropertyFlag operator|(MemoryPropertyFlag l, MemoryPropertyFlag r) 89 { 90 return MemoryPropertyFlag(uint32_t(l) | uint32_t(r)); 91 } 92 93 /** Engine image creation flags */ 94 enum class EngineImageCreationFlag : uint32_t { 95 /** Dynamic barriers */ 96 DYNAMIC_BARRIERS = 0x00000001, 97 /** Reset state on frame borders */ 98 RESET_STATE_ON_FRAME_BORDERS = 0x00000002, 99 /** Generate mips */ 100 GENERATE_MIPS = 0x00000004, 101 /** Scale image when created from data */ 102 SCALE = 0x00000008, 103 /** Destroy is deferred to the end of the current frame */ 104 DEFERRED_DESTROY = 0x00000010, 105 }; 106 constexpr inline EngineImageCreationFlag operator|(EngineImageCreationFlag l, EngineImageCreationFlag r) 107 { 108 return EngineImageCreationFlag(uint32_t(l) | uint32_t(r)); 109 } 110 111 struct ImageInfo { 112 ImageUsageFlag usageFlags {}; 113 MemoryPropertyFlag memoryFlags {}; 114 EngineImageCreationFlag creationFlags {}; 115 }; 116 117 struct ImageLoadInfo { 118 ImageLoadFlags loadFlags {}; 119 ImageInfo info; 120 }; 121 122 struct ImageCreateInfo { 123 BASE_NS::Math::UVec2 size {}; 124 BASE_NS::Format format { BASE_NS::Format::BASE_FORMAT_R8G8B8A8_SRGB }; 125 ImageInfo info; 126 }; 127 128 constexpr ImageCreateInfo DEFAULT_RENDER_TARGET_CREATE_INFO = { {}, BASE_NS::Format::BASE_FORMAT_R8G8B8A8_SRGB, 129 { ImageUsageFlag::COLOR_ATTACHMENT_BIT, MemoryPropertyFlag::DEVICE_LOCAL_BIT, 130 EngineImageCreationFlag::RESET_STATE_ON_FRAME_BORDERS | EngineImageCreationFlag::DYNAMIC_BARRIERS } }; 131 132 constexpr ImageCreateInfo DEFAULT_IMAGE_CREATE_INFO = DEFAULT_RENDER_TARGET_CREATE_INFO; 133 134 constexpr ImageLoadInfo DEFAULT_IMAGE_LOAD_INFO = { ImageLoadFlags::GENERATE_MIPS, 135 ImageInfo { ImageUsageFlag::SAMPLED_BIT | ImageUsageFlag::TRANSFER_DST_BIT | ImageUsageFlag::TRANSFER_SRC_BIT, 136 MemoryPropertyFlag::DEVICE_LOCAL_BIT, EngineImageCreationFlag::GENERATE_MIPS } }; 137 138 SCENE_END_NAMESPACE() 139 140 META_TYPE(SCENE_NS::ImageLoadFlags) 141 META_TYPE(SCENE_NS::ImageInfo) 142 META_TYPE(SCENE_NS::ImageLoadInfo) 143 META_TYPE(SCENE_NS::ImageCreateInfo) 144 145 #endif 146