• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_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 
61     IRenderNode(const IRenderNode&) = delete;
62     IRenderNode& operator=(const IRenderNode&) = delete;
63 
64     /** Sequential, called once after render graph has been initialized.
65      * Anything can be done here, including gpu resource creation.
66      * Note: InitNode can get called multiple times during runtime e.g. after hot-reloading assets. The node must
67      * invalidate any changed state/ handles and assume it starts from scratch.
68      * @param renderNodeContextMgr Provides access to needed managers.
69      */
70     virtual void InitNode(IRenderNodeContextManager& renderNodeContextMgr) = 0;
71 
72     /** Sequential, called before ExecuteFrame every frame.
73      * Create/destroy gpu resources here if needed. Prefer not doing any other work.
74      * IRenderNodeGpuResourceManager keeps track of created resources
75      * -> do not explicitly destroy if not needed.
76      */
77     virtual void PreExecuteFrame() = 0;
78 
79     /** Parallel, called every frame after every ExecuteCreateGpuResources().
80      * Do NOT create gpu resources here.
81      * @param cmdList Render command list for rendering/compute calls.
82      */
83     virtual void ExecuteFrame(IRenderCommandList& cmdList) = 0;
84 
85 protected:
86     IRenderNode() = default;
87     virtual ~IRenderNode() = default;
88 };
89 RENDER_END_NAMESPACE()
90 
91 #endif // API_RENDER_IRENDER_NODE_H
92