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_NODE_CONTEXT_PSO_MANAGER_H 17 #define API_RENDER_NODE_CONTEXT_PSO_MANAGER_H 18 19 #include <cstddef> 20 21 #include <render/namespace.h> 22 #include <render/render_data_structures.h> 23 #include <render/resource_handle.h> 24 25 RENDER_BEGIN_NAMESPACE() 26 class Device; 27 struct PipelineLayout; 28 struct ViewportDesc; 29 struct ScissorDesc; 30 struct RenderPassDesc; 31 32 /** \addtogroup group_render_inodecontextpsomanager 33 * @{ 34 */ 35 /** class INodeContextPsoManager 36 * Creates and caches pipeline state objects. 37 * Recources are: 38 * - Compute psos 39 * - Graphics psos 40 * Prefer using the methods with handles. 41 */ 42 class INodeContextPsoManager { 43 public: 44 INodeContextPsoManager(const INodeContextPsoManager&) = delete; 45 INodeContextPsoManager& operator=(const INodeContextPsoManager&) = delete; 46 47 /** Creates new compute psos on demand and caches 48 * @param shaderHandle Handle to shader resource 49 * @param pipelineLayoutHandle A valid handle to pipeline layout 50 * @param shaderSpecialization Shader specialization 51 * @return Compute pso handle 52 */ 53 virtual RenderHandle GetComputePsoHandle(const RenderHandle shader, const RenderHandle pipelineLayout, 54 const ShaderSpecializationConstantDataView& shaderSpecialization) = 0; 55 56 /** Creates new compute psos on demand and caches 57 * @param shaderHandle Handle to shader resource 58 * @param pipelineLayout Pipeline layout 59 * @param shaderSpecialization Shader specialization 60 * @return Compute pso handle 61 */ 62 virtual RenderHandle GetComputePsoHandle(const RenderHandle shader, const PipelineLayout& pipelineLayout, 63 const ShaderSpecializationConstantDataView& shaderSpecialization) = 0; 64 65 /** Creates new graphics psos on demand and caches. Prefer using this method. 66 * Add additional dynamic states and atleast prefer using dynamic viewport and dynamic scissor 67 * for less graphics pipelines 68 * All inputs are copied, ie. no need to store them 69 * @param shaderHandle A valid shader handle 70 * @param graphicsState A valid graphics state handle 71 * @param pipelineLayout A valid pipeline layout handle 72 * @param vertexInputDeclaration If a valid handle, it is used. Otherwise empty vertex input declaration. 73 * @param shaderSpecialization Shader specialization 74 * @param dynamicStates Dynamic state enums 75 * @return Graphics pso handle 76 */ 77 virtual RenderHandle GetGraphicsPsoHandle(const RenderHandle shader, const RenderHandle graphicsState, 78 const RenderHandle pipelineLayout, const RenderHandle vertexInputDeclaration, 79 const ShaderSpecializationConstantDataView& shaderSpecialization, 80 const BASE_NS::array_view<const DynamicStateEnum> dynamicStates) = 0; 81 82 /** Creates new graphics psos on demand and caches. 83 * Prefer using dynamic viewport and dynamic scissor for less graphics pipelines 84 * All inputs are copied, ie. no need to store them 85 * @param shader Handle to shader resource 86 * @param graphicsState Handle to graphics state 87 * @param pipelineLayout Pipeline layout 88 * @param vertexInputDeclarationView Vertex input declaration view 89 * @param shaderSpecialization Shader specialization 90 * @param dynamicStates Dynamic state enums 91 * @return Graphics pso handle 92 */ 93 virtual RenderHandle GetGraphicsPsoHandle(const RenderHandle shader, const RenderHandle graphicsState, 94 const PipelineLayout& pipelineLayout, const VertexInputDeclarationView& vertexInputDeclarationView, 95 const ShaderSpecializationConstantDataView& shaderSpecialization, 96 const BASE_NS::array_view<const DynamicStateEnum> dynamicStates) = 0; 97 98 /** Creates new graphics psos on demand and caches. Overrides the default graphics state from shader. 99 * Prefer using dynamic viewport and dynamic scissor for less graphics pipelines 100 * All inputs are copied, ie. no need to store them 101 * @param shaderHandle Handle to shader resource 102 * @param graphicsState A graphics state which overrides the default graphics state from the shader 103 * @param pipelineLayout Pipeline layout 104 * @param vertexInputDeclarationView Vertex input declaration view 105 * @param shaderSpecialization Shader specialization 106 * @param dynamicStates Dynamic state enums 107 * @return Graphics pso handle 108 */ 109 virtual RenderHandle GetGraphicsPsoHandle(const RenderHandle shaderHandle, const GraphicsState& graphicsState, 110 const PipelineLayout& pipelineLayout, const VertexInputDeclarationView& vertexInputDeclarationView, 111 const ShaderSpecializationConstantDataView& shaderSpecialization, 112 const BASE_NS::array_view<const DynamicStateEnum> dynamicStates) = 0; 113 114 protected: 115 INodeContextPsoManager() = default; 116 virtual ~INodeContextPsoManager() = default; 117 }; 118 /** @} */ 119 RENDER_END_NAMESPACE() 120 121 #endif // API_RENDER_NODE_CONTEXT_PSO_MANAGER_H 122