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 API_RENDER_DEVICE_PIPELINE_LAYOUT_DESC_H 17 #define API_RENDER_DEVICE_PIPELINE_LAYOUT_DESC_H 18 19 #include <cstdint> 20 21 #include <base/containers/array_view.h> 22 #include <base/containers/vector.h> 23 #include <render/device/pipeline_state_desc.h> 24 #include <render/namespace.h> 25 26 RENDER_BEGIN_NAMESPACE() 27 /** \addtogroup group_render_pipelinelayoutdesc 28 * @{ 29 */ 30 /** Pipeline layout constants */ 31 struct PipelineLayoutConstants { 32 /** Max descriptor set count */ 33 static constexpr uint32_t MAX_DESCRIPTOR_SET_COUNT { 4u }; 34 /** Max dynamic descriptor offset count */ 35 static constexpr uint32_t MAX_DYNAMIC_DESCRIPTOR_OFFSET_COUNT { 16u }; 36 /** Invalid index */ 37 static constexpr uint32_t INVALID_INDEX { ~0u }; 38 /** Max push constant byte size */ 39 static constexpr uint32_t MAX_PUSH_CONSTANT_BYTE_SIZE { 128u }; 40 /** Max binding count in a set */ 41 static constexpr uint32_t MAX_DESCRIPTOR_SET_BINDING_COUNT { 16u }; 42 /** Max push constant ranges */ 43 static constexpr uint32_t MAX_PUSH_CONSTANT_RANGE_COUNT { 1u }; 44 /** Max UBO bind byte size */ 45 static constexpr uint32_t MAX_UBO_BIND_BYTE_SIZE { 16u * 1024u }; 46 /** UBO bind offset alignemtn */ 47 static constexpr uint32_t MIN_UBO_BIND_OFFSET_ALIGNMENT_BYTE_SIZE { 256u }; 48 }; 49 50 enum AdditionalDescriptorTypeImageFlagBits { 51 /** Depth */ 52 CORE_DESCRIPTOR_TYPE_IMAGE_DEPTH_BIT = 0x00000001, 53 /** Array */ 54 CORE_DESCRIPTOR_TYPE_IMAGE_ARRAY_BIT = 0x00000002, 55 /** Multisample */ 56 CORE_DESCRIPTOR_TYPE_IMAGE_MULTISAMPLE_BIT = 0x00000004, 57 /** Sampled */ 58 CORE_DESCRIPTOR_TYPE_IMAGE_SAMPLED_BIT = 0x00000008, 59 /** Image load store */ 60 CORE_DESCRIPTOR_TYPE_IMAGE_LOAD_STORE_BIT = 0x00000010, 61 62 /** 1D */ 63 CORE_DESCRIPTOR_TYPE_IMAGE_DIMENSION_1D_BIT = 0x00010000, 64 /** 2D */ 65 CORE_DESCRIPTOR_TYPE_IMAGE_DIMENSION_2D_BIT = 0x00020000, 66 /** 3D */ 67 CORE_DESCRIPTOR_TYPE_IMAGE_DIMENSION_3D_BIT = 0x00040000, 68 /** Cube */ 69 CORE_DESCRIPTOR_TYPE_IMAGE_DIMENSION_CUBE_BIT = 0x00080000, 70 /** Image load store */ 71 CORE_DESCRIPTOR_TYPE_IMAGE_DIMENSION_BUFFER_BIT = 0x0010000, 72 /** Input attachment */ 73 CORE_DESCRIPTOR_TYPE_IMAGE_DIMENSION_SUBPASS_BIT = 0x00200000, 74 }; 75 76 /** Container for additional descriptor type flags */ 77 using AdditionalDescriptorTypeFlags = uint32_t; 78 79 /** Descriptor set layout binding */ 80 struct DescriptorSetLayoutBinding { 81 /** Binding */ 82 uint32_t binding { PipelineLayoutConstants::INVALID_INDEX }; 83 /** Descriptor type */ 84 DescriptorType descriptorType { DescriptorType::CORE_DESCRIPTOR_TYPE_MAX_ENUM }; 85 /** Descriptor count */ 86 uint32_t descriptorCount { 0U }; 87 /** Stage flags */ 88 ShaderStageFlags shaderStageFlags { 0U }; 89 /** Additional flags by type, all packed to a single uint */ 90 AdditionalDescriptorTypeFlags additionalDescriptorTypeFlags { 0U }; 91 }; 92 93 /** Descriptor set layout bindings */ 94 struct DescriptorSetLayoutBindings { 95 /** Bindings array */ 96 BASE_NS::vector<DescriptorSetLayoutBinding> binding; 97 }; 98 99 /** Descriptor set layout binding resource */ 100 struct DescriptorSetLayoutBindingResource { 101 /** Binding */ 102 DescriptorSetLayoutBinding binding; 103 /** Resource index to typed data */ 104 uint32_t resourceIndex { PipelineLayoutConstants::INVALID_INDEX }; 105 }; 106 107 /** Bindable buffer */ 108 struct BindableBuffer { 109 /** Handle */ 110 RenderHandle handle {}; 111 /** Byte offset to buffer */ 112 uint32_t byteOffset { 0u }; 113 /** Byte size for buffer binding */ 114 uint32_t byteSize { PipelineStateConstants::GPU_BUFFER_WHOLE_SIZE }; 115 }; 116 117 /** Bindable image */ 118 struct BindableImage { 119 /** Handle */ 120 RenderHandle handle {}; 121 /** Mip level for specific binding */ 122 uint32_t mip { PipelineStateConstants::GPU_IMAGE_ALL_MIP_LEVELS }; 123 /** Layer level for specific binding */ 124 uint32_t layer { PipelineStateConstants::GPU_IMAGE_ALL_LAYERS }; 125 /** Custom image layout */ 126 ImageLayout imageLayout { ImageLayout::CORE_IMAGE_LAYOUT_UNDEFINED }; 127 /** Sampler handle for combined image sampler */ 128 RenderHandle samplerHandle {}; 129 }; 130 131 /** Bindable sampler */ 132 struct BindableSampler { 133 /** Handle */ 134 RenderHandle handle {}; 135 }; 136 137 /** Bindable buffer with render handle reference */ 138 struct BindableBufferWithHandleReference { 139 /** Handle */ 140 RenderHandleReference handle; 141 /** Byte offset to buffer */ 142 uint32_t byteOffset { 0u }; 143 /** Byte size for buffer binding */ 144 uint32_t byteSize { PipelineStateConstants::GPU_BUFFER_WHOLE_SIZE }; 145 }; 146 147 /** Bindable image with render handle reference */ 148 struct BindableImageWithHandleReference { 149 /** Handle */ 150 RenderHandleReference handle; 151 /** Mip level for specific binding */ 152 uint32_t mip { PipelineStateConstants::GPU_IMAGE_ALL_MIP_LEVELS }; 153 /** Layer level for specific binding */ 154 uint32_t layer { PipelineStateConstants::GPU_IMAGE_ALL_LAYERS }; 155 /** Custom image layout */ 156 ImageLayout imageLayout { ImageLayout::CORE_IMAGE_LAYOUT_UNDEFINED }; 157 /** Sampler handle for combined image sampler */ 158 RenderHandleReference samplerHandle; 159 }; 160 161 /** Bindable sampler with render handle reference */ 162 struct BindableSamplerWithHandleReference { 163 /** Handle */ 164 RenderHandleReference handle; 165 }; 166 167 /** Descriptor structure for buffer */ 168 struct BufferDescriptor { 169 /** Descriptor set layout binding */ 170 DescriptorSetLayoutBinding binding {}; 171 /** Bindable resource structure with handle */ 172 BindableBuffer resource {}; 173 /** Resource state in the pipeline */ 174 GpuResourceState state {}; 175 176 /** Array offset to resources for array descriptors */ 177 uint32_t arrayOffset { 0 }; 178 179 /** Additional flags */ 180 AdditionalDescriptorFlags additionalFlags { 0u }; 181 }; 182 183 /** Descriptor structure for image */ 184 struct ImageDescriptor { 185 /** Descriptor set layout binding */ 186 DescriptorSetLayoutBinding binding {}; 187 /** Bindable resource structure with handle */ 188 BindableImage resource {}; 189 /** Resource state in the pipeline */ 190 GpuResourceState state {}; 191 192 /** Array offset to resources for array descriptors */ 193 uint32_t arrayOffset { 0 }; 194 195 /** Additional flags */ 196 AdditionalDescriptorFlags additionalFlags { 0u }; 197 }; 198 199 /** Descriptor structure for sampler */ 200 struct SamplerDescriptor { 201 /** Descriptor set layout binding */ 202 DescriptorSetLayoutBinding binding {}; 203 /** Bindable resource structure with handle */ 204 BindableSampler resource {}; 205 206 /** Array offset to resources for array descriptors */ 207 uint32_t arrayOffset { 0 }; 208 209 /** Additional flags */ 210 AdditionalDescriptorFlags additionalFlags { 0u }; 211 }; 212 213 /** Descriptor set layout binding resources */ 214 struct DescriptorSetLayoutBindingResources { 215 /** Bindings */ 216 BASE_NS::array_view<const DescriptorSetLayoutBindingResource> bindings; 217 218 /** Buffer descriptors */ 219 BASE_NS::array_view<const BufferDescriptor> buffers; 220 /** Image descriptors */ 221 BASE_NS::array_view<const ImageDescriptor> images; 222 /** Sampler descriptors */ 223 BASE_NS::array_view<const SamplerDescriptor> samplers; 224 225 /** Mask of bindings in the descriptor set. Max uint is value which means that not set */ 226 uint32_t descriptorSetBindingMask { ~0u }; 227 /** Current binding mask. Max uint is value which means that not set */ 228 uint32_t bindingMask { ~0u }; 229 }; 230 231 /** Descriptor set layout */ 232 struct DescriptorSetLayout { 233 /** Set */ 234 uint32_t set { PipelineLayoutConstants::INVALID_INDEX }; 235 /** Bindings */ 236 BASE_NS::vector<DescriptorSetLayoutBinding> bindings; 237 }; 238 239 /** Push constant */ 240 struct PushConstant { 241 /** Shader stage flags */ 242 ShaderStageFlags shaderStageFlags { 0 }; 243 /** Byte size */ 244 uint32_t byteSize { 0 }; 245 }; 246 247 /** Pipeline layout */ 248 struct PipelineLayout { 249 /** Push constant */ 250 PushConstant pushConstant; 251 /** [[DEPRECATED DO NOT USE]] Descriptor set count */ 252 uint32_t descriptorSetCount { 0 }; 253 /** Descriptor sets */ 254 DescriptorSetLayout descriptorSetLayouts[PipelineLayoutConstants::MAX_DESCRIPTOR_SET_COUNT] {}; 255 }; 256 257 /** Shader thread group variables (can be used with group count and group sizes */ 258 struct ShaderThreadGroup { 259 /** Thread group variable X */ 260 uint32_t x { 1u }; 261 /** Thread group variable Y */ 262 uint32_t y { 1u }; 263 /** Thread group variable Z */ 264 uint32_t z { 1u }; 265 }; 266 /** @} */ 267 RENDER_END_NAMESPACE() 268 269 #endif // API_RENDER_DEVICE_PIPELINE_LAYOUT_DESC_H 270