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_RENDER_NODE_UTIL_H 17 #define API_RENDER_RENDER_NODE_UTIL_H 18 19 #include <base/containers/array_view.h> 20 #include <base/containers/unique_ptr.h> 21 #include <render/datastore/intf_render_data_store_post_process.h> 22 #include <render/datastore/render_data_store_render_pods.h> 23 #include <render/device/pipeline_state_desc.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 struct PipelineLayout; 31 32 /** @ingroup group_render_irendernodeutil */ 33 /** Interface for helper class to create different required rendering types from inputs. 34 * Can create objects through IRenderNodeContextManager. 35 */ 36 class IRenderNodeUtil { 37 public: 38 /** Create input render pass from json data input render pass. 39 * @param renderPass Render pass from json format. 40 * @return Input render pass with handles. I.e. resources and their type-mapping used for rendering. 41 */ 42 virtual RenderNodeHandles::InputRenderPass CreateInputRenderPass( 43 const RenderNodeGraphInputs::InputRenderPass& renderPass) const = 0; 44 45 /** Create input resources from json data input render pass. 46 * @param inputResources Resources from json format. 47 * @return Input resources with handles. I.e. resources and their type-mapping used for rendering. 48 */ 49 virtual RenderNodeHandles::InputResources CreateInputResources( 50 const RenderNodeGraphInputs::InputResources& inputResources) const = 0; 51 52 /** Create a render pass based on render node handles. 53 * @param renderPass Input render pass. 54 * @return Render pass struct. 55 */ 56 virtual RenderPass CreateRenderPass(const RenderNodeHandles::InputRenderPass& renderPass) const = 0; 57 58 /** Create pipeline layout based on PL which is attached to the shader or if not found create from shader 59 * reflection. 60 * @param shaderHandle Shader handle. 61 * @return Pipeline layout that was reflected from the given shader. 62 */ 63 virtual PipelineLayout CreatePipelineLayout(const RenderHandle& shaderHandle) const = 0; 64 65 /** Get descriptor counts from pipeline layout. 66 * @param pipelineLayout Valid pipeline layout which matches upcoming bindings. 67 * @return Descriptor counts struct used to pass for reserving render node specific descriptor sets. 68 */ 69 virtual DescriptorCounts GetDescriptorCounts(const PipelineLayout& pipelineLayout) const = 0; 70 71 /** Get descriptor counts from desriptor set layout bindings. 72 * @param bindings Bindings. 73 * @return Descriptor counts struct used to pass for reserving render node specific descriptor sets. 74 */ 75 virtual DescriptorCounts GetDescriptorCounts( 76 const BASE_NS::array_view<DescriptorSetLayoutBinding> bindings) const = 0; 77 78 /** Create pipeline descriptor set binder. 79 * @param renderNodeContextMgr Access to render node resource managers. 80 * @param pipelineLayout Pipeline layout. 81 * @return A pipeline descriptor set binder based on pipeline layout. 82 */ 83 virtual IPipelineDescriptorSetBinder::Ptr CreatePipelineDescriptorSetBinder( 84 const PipelineLayout& pipelineLayout) const = 0; 85 86 /** Bind render node handle input resources to binder. 87 * @param resources Render node handle input resources. 88 * @param pipelineDescriptorSetBinder Pipeline descriptor set binder. 89 */ 90 virtual void BindResourcesToBinder(const RenderNodeHandles::InputResources& resources, 91 IPipelineDescriptorSetBinder& pipelineDescriptorSetBinder) const = 0; 92 93 /** Create default viewport based on render pass attachments render area. 94 * @param renderPass Render pass. 95 * @return A viewport desc based on render pass attachments. 96 */ 97 virtual ViewportDesc CreateDefaultViewport(const RenderPass& renderPass) const = 0; 98 99 /** Create default scissor based on render pass attachments render area. 100 * @param renderPass Render pass. 101 * @return A scissor descriptor based on render pass attachments. 102 */ 103 virtual ScissorDesc CreateDefaultScissor(const RenderPass& renderPass) const = 0; 104 105 /** Create post process configuration for shader usage. 106 * @param postProcessConfiguration Post process configuration. 107 * @return A RenderPostProcessConfiguration. 108 */ 109 virtual RenderPostProcessConfiguration GetRenderPostProcessConfiguration( 110 const PostProcessConfiguration& postProcessConfiguration) const = 0; 111 112 /** Create post process configuration for shader usage. 113 * @param postProcessConfiguration Post process configuration. 114 * @return A RenderPostProcessConfiguration. 115 */ 116 virtual RenderPostProcessConfiguration GetRenderPostProcessConfiguration( 117 const IRenderDataStorePostProcess::GlobalFactors& globalFactors) const = 0; 118 119 /** Has resources in render pass that might change every frame. 120 * For example broadcasted resources from different render nodes might change every frame. 121 * @param renderPass Input render pass for evaluation. 122 * @return Boolean if one should re-check/re-fetch new handles every frame. 123 */ 124 virtual bool HasChangeableResources(const RenderNodeGraphInputs::InputRenderPass& renderPass) const = 0; 125 126 /** Has resources as inputs that might change every frame. 127 * For example broadcasted resources from different render nodes might change every frame. 128 * @param resources Input resources for evaluation. 129 * @return Boolean if one should re-check/re-fetch new handles every frame. 130 */ 131 virtual bool HasChangeableResources(const RenderNodeGraphInputs::InputResources& resources) const = 0; 132 133 protected: 134 IRenderNodeUtil() = default; 135 virtual ~IRenderNodeUtil() = default; 136 }; 137 RENDER_END_NAMESPACE() 138 139 #endif // API_RENDER_RENDER_NODE_UTIL_H 140