1 /* 2 * Copyright (C) 2023 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_INODE_CONTEXT_DESCRIPTORSET_MANAGER_H 17 #define API_RENDER_INODE_CONTEXT_DESCRIPTORSET_MANAGER_H 18 19 #include <cstddef> 20 21 #include <base/containers/array_view.h> 22 #include <base/containers/unique_ptr.h> 23 #include <base/containers/vector.h> 24 #include <render/namespace.h> 25 #include <render/nodecontext/intf_pipeline_descriptor_set_binder.h> 26 #include <render/render_data_structures.h> 27 #include <render/resource_handle.h> 28 29 RENDER_BEGIN_NAMESPACE() 30 class Device; 31 struct PipelineLayout; 32 33 /** @ingroup group_render_inodecontextdescriptorsetmanager */ 34 /** 35 * INodeContextDescriptorSetManager 36 * Creates and caches descriptor sets. 37 * 38 * Single descriptor set can only be updated once per frame. I.e you need to create as many descriptor sets as you need 39 * per frame. (Descriptor sets are internally buffered for GPU frames). 40 * 41 * One should use normal descriptor sets and use ResetAndReserve when one needs more sets. 42 * 43 * There is a possiblity to use one frame descriptor sets which do not need reserving. 44 * The methods CreateOneFrameXXX creates a descriptor set which is valid for current frame. 45 * This could be used with user inputs where one cannot pre-calculate the need of descriptors properly. 46 */ 47 class INodeContextDescriptorSetManager { 48 public: 49 INodeContextDescriptorSetManager(const INodeContextDescriptorSetManager&) = delete; 50 INodeContextDescriptorSetManager& operator=(const INodeContextDescriptorSetManager&) = delete; 51 52 /** Reset non-dynamic (not one frame) descriptor sets and reserve descriptors. 53 * Reset only when a new pool is needed. (Currently allocated descriptors are not enough) 54 * Needs to reserve all the descriptors which are used in a single frame. 55 * To reiterate: All old descriptor set handles become invalid when this is called. */ 56 virtual void ResetAndReserve(const DescriptorCounts& descriptorCounts) = 0; 57 58 /** Creates a new descriptor set and gives its handle. */ 59 virtual RenderHandle CreateDescriptorSet( 60 const BASE_NS::array_view<const DescriptorSetLayoutBinding> descriptorSetLayoutBindings) = 0; 61 /** Creates new descriptor sets for all given descriptor sets. */ 62 virtual BASE_NS::vector<RenderHandle> CreateDescriptorSets( 63 const BASE_NS::array_view<const DescriptorSetLayoutBindings> descriptorSetsLayoutBindings) = 0; 64 /** Creates a single descriptor set from pipeline layout. */ 65 virtual RenderHandle CreateDescriptorSet(const uint32_t set, const PipelineLayout& pipelineLayout) = 0; 66 67 /** Create a IDescriptorSetBinder based on a descriptor set handle and layout bindings. 68 * Layout bindings are expected to be sorted starting from the smallest index. 69 */ 70 virtual IDescriptorSetBinder::Ptr CreateDescriptorSetBinder(const RenderHandle handle, 71 const BASE_NS::array_view<const DescriptorSetLayoutBinding> descriptorSetLayoutBindings) = 0; 72 73 /** Create a IPipelineDescriptorSetBinder based on pipeline layout. 74 * @param pipelineLayout PipelineLayout 75 */ 76 virtual IPipelineDescriptorSetBinder::Ptr CreatePipelineDescriptorSetBinder( 77 const PipelineLayout& pipelineLayout) = 0; 78 79 /** Create a IPipelineDescriptorSetBinder based on pipeline layout, handles, and layout bindings. 80 * Pipeline layout sets and their bindings are expected to be sorted starting from smallest index. 81 * @param pipelineLayout PipelineLayout 82 * @param handles Descriptor set handles 83 * @param descriptorSetsLayoutBindings Descriptor set layout bindings 84 */ 85 virtual IPipelineDescriptorSetBinder::Ptr CreatePipelineDescriptorSetBinder(const PipelineLayout& pipelineLayout, 86 const BASE_NS::array_view<const RenderHandle> handles, 87 const BASE_NS::array_view<const DescriptorSetLayoutBindings> descriptorSetsLayoutBindings) = 0; 88 89 /** Creates a one frame new descriptor set and gives its handle. Valid for a one frame and does not need reserve. */ 90 virtual RenderHandle CreateOneFrameDescriptorSet( 91 const BASE_NS::array_view<const DescriptorSetLayoutBinding> descriptorSetLayoutBindings) = 0; 92 /** Creates a one frame new dynamic descriptor sets for all given descriptor sets. Valid for a one frame and does 93 * not need reserve. */ 94 virtual BASE_NS::vector<RenderHandle> CreateOneFrameDescriptorSets( 95 const BASE_NS::array_view<const DescriptorSetLayoutBindings> descriptorSetsLayoutBindings) = 0; 96 /** Creates a one frame dynamic single descriptor set from pipeline layout. Valid for a one frame and does not need 97 * reserve. */ 98 virtual RenderHandle CreateOneFrameDescriptorSet(const uint32_t set, const PipelineLayout& pipelineLayout) = 0; 99 100 protected: 101 INodeContextDescriptorSetManager() = default; 102 virtual ~INodeContextDescriptorSetManager() = default; 103 }; 104 RENDER_END_NAMESPACE() 105 106 #endif // API_RENDER_INODE_CONTEXT_DESCRIPTORSET_MANAGER_H 107