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_IRENDER_NODE_H 17 #define API_RENDER_IRENDER_NODE_H 18 19 #include <base/containers/string_view.h> 20 #include <render/namespace.h> 21 #include <render/render_data_structures.h> 22 23 RENDER_BEGIN_NAMESPACE() 24 class IRenderCommandList; 25 class IRenderNodeContextManager; 26 struct RenderNodeGraphInputs; 27 28 /** @ingroup group_render_irendernode */ 29 /** Base class for render nodes 30 * 31 * Inherit to create new render node that can be used in render node graph. 32 * 33 * Render node methods are never called by the API user. 34 * Renderer calls the methods in correct pipeline positions automatically. 35 */ 36 class IRenderNode { 37 public: 38 /** Render node class type. */ 39 enum ClassType : uint32_t { 40 /** Basic render node (IRenderNode). */ 41 CLASS_TYPE_NODE = 0, 42 /** Render node with low-level backend access (IRenderBackendNode). */ 43 CLASS_TYPE_BACKEND_NODE = 1, 44 }; 45 /** Render node backend support flags. 46 * With typical render nodes, support is default (all backends). 47 * With backend render nodes, explicit selection should be done. 48 */ 49 enum BackendFlagBits : uint32_t { 50 /** Explicit default zero. Supports all backends */ 51 BACKEND_FLAG_BITS_DEFAULT = 0, 52 /** Explicit support for Vulkan */ 53 BACKEND_FLAG_BITS_EXPLICIT_VULKAN = (1 << 0), 54 /** Explicit support for GLES */ 55 BACKEND_FLAG_BITS_EXPLICIT_GLES = (1 << 1), 56 /** Explicit support for GL */ 57 BACKEND_FLAG_BITS_EXPLICIT_GL = (1 << 2), 58 }; 59 using BackendFlags = uint32_t; 60 /** Execute flagbits from HasExecuteFrameWork(). 61 * There's room to add more flags for e.g. type of work (or to not parallelize by itself) 62 */ 63 enum ExecuteFlagBits : uint32_t { 64 /** Default behaviour */ 65 EXECUTE_FLAG_BITS_DEFAULT = 0, 66 /** Do not execute render frame */ 67 EXECUTE_FLAG_BITS_DO_NOT_EXECUTE = (1 << 0), 68 }; 69 using ExecuteFlags = uint32_t; 70 71 IRenderNode(const IRenderNode&) = delete; 72 IRenderNode& operator=(const IRenderNode&) = delete; 73 74 /** Sequential, called once after render graph has been initialized. 75 * Anything can be done here, including gpu resource creation. 76 * Note: InitNode can get called multiple times during runtime e.g. after hot-reloading assets. The node must 77 * invalidate any changed state/ handles and assume it starts from scratch. 78 * @param renderNodeContextMgr Provides access to needed managers. 79 */ 80 virtual void InitNode(IRenderNodeContextManager& renderNodeContextMgr) = 0; 81 82 /** Sequential, called before ExecuteFrame every frame. 83 * Create/destroy gpu resources here if needed. Prefer not doing any other work. 84 * IRenderNodeGpuResourceManager keeps track of created resources 85 * -> do not explicitly destroy if not needed. 86 */ 87 virtual void PreExecuteFrame() = 0; 88 89 /** Parallel, called every frame after every PreExecuteFrame. 90 * Is not run if HasExecuteFrameWork() returns false. 91 * Do NOT create gpu resources here. 92 * @param cmdList Render command list for rendering/compute calls. 93 */ 94 virtual void ExecuteFrame(IRenderCommandList& cmdList) = 0; 95 96 /** Called every frame before ExecuteFrame. 97 * @param ExecuteFlags Execute flags information for ExecuteFrame run. 98 */ 99 virtual ExecuteFlags GetExecuteFlags() const = 0; 100 101 protected: 102 IRenderNode() = default; 103 virtual ~IRenderNode() = default; 104 }; 105 RENDER_END_NAMESPACE() 106 107 #endif // API_RENDER_IRENDER_NODE_H 108