• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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_NODECONTEXT_IRENDER_POST_PROCESS_NODE_H
17 #define API_RENDER_NODECONTEXT_IRENDER_POST_PROCESS_NODE_H
18 
19 #include <base/containers/array_view.h>
20 #include <base/util/uid.h>
21 #include <core/plugin/intf_interface.h>
22 #include <core/property/intf_property_handle.h>
23 #include <render/namespace.h>
24 #include <render/nodecontext/intf_render_node.h>
25 #include <render/nodecontext/intf_render_post_process.h>
26 #include <render/render_data_structures.h>
27 
28 RENDER_BEGIN_NAMESPACE()
29 
30 class IRenderNodeContextManager;
31 class IRenderCommandList;
32 
33 /** @ingroup group_render_irenderpostprocessnode */
34 /**
35  * Provides interface for post processes which can run custom code in render nodes
36  */
37 class IRenderPostProcessNode : public CORE_NS::IInterface {
38 public:
39     static constexpr auto UID = BASE_NS::Uid("99cb059f-186b-4c38-b75b-28b2e805d63d");
40 
41     using Ptr = BASE_NS::refcnt_ptr<IRenderPostProcessNode>;
42 
43     /** Get property handle for built-in input properties during rendering.
44      * These properties should be updated every frame when executed.
45      * @return Pointer to property handle if properties present, nullptr otherwise.
46      */
47     virtual CORE_NS::IPropertyHandle* GetRenderInputProperties() = 0;
48 
49     /** Get property handle for built-in output properties during rendering.
50      * These properties are updated every frame during PreExecute and should be taken into account after that.
51      * @return Pointer to property handle if properties present, nullptr otherwise.
52      */
53     virtual CORE_NS::IPropertyHandle* GetRenderOutputProperties() = 0;
54 
55     /** Render area request.
56      * 1. If the area is default 0-0-0-0 -> check the output target size
57      * 2. If no output target set from outside use this for intermediate output target
58      * 3. If the are is non-default, apply to output target or create the sized output target
59      */
60     struct RenderAreaRequest {
61         /* Render are, used as explained abofe */
62         RENDER_NS::RenderPassDesc::RenderArea area;
63     };
64     /** Set render area request
65      * 1. If output given, non-default values affect the area
66      * 2. If no output given, creates an output intermadiate target for given size.
67      */
68     virtual void SetRenderAreaRequest(const RenderAreaRequest& renderAreaRequest) = 0;
69 
70     /** Get descriptor counts needed for custom post process execution.
71      * If shares descriptor sets with the main render node.
72      * This is called and evaluated during rendering.
73      * This method needs to return correct values after Init().
74      * @return Descriptor counts
75      */
76     virtual DescriptorCounts GetRenderDescriptorCounts() const = 0;
77 
78     /** Called every frame before ExecuteFrame.
79      * This should return false if the effect is disabled.
80      * @param ExecuteFlags Execute flags information for ExecuteFrame run.
81      */
82     virtual IRenderNode::ExecuteFlags GetExecuteFlags() const = 0;
83 
84     /** Sequential, called when the actual render node is initialized or rest are being done.
85      * Note: Init can get called multiple times during runtime. The node must
86      * invalidate any changed state/ handles and assume it starts from scratch.
87      * This is called and evaluated during rendering.
88      * @param postProcess IRenderPostProcess implementation where the input properties come from.
89      * @param renderNodeContextMgr Provides access to needed managers.
90      */
91     virtual void Init(const IRenderPostProcess::Ptr& postProcess, IRenderNodeContextManager& renderNodeContextMgr) = 0;
92 
93     /** Sequential, called before ExecuteFrame every frame by the actual render node.
94      * Create/destroy gpu resources here if needed. Descriptor sets should be created here as well.
95      * Prefer not doing any other work.
96      * IRenderNodeGpuResourceManager keeps track of created resources, just store the handle references.
97      * This is called and evaluated during rendering.
98      */
99     virtual void PreExecute() = 0;
100 
101     /** Parallel, called every frame by the actual post process handling render node.
102      * Should make sure internally if the effect should be applied.
103      * Do NOT create gpu resources here.
104      * This is called and evaluated during rendering.
105      * @param cmdList Render command list for rendering/compute calls.
106      */
107     virtual void Execute(IRenderCommandList& cmdList) = 0;
108 
109 protected:
110     IRenderPostProcessNode() = default;
111     virtual ~IRenderPostProcessNode() = default;
112 
113     IRenderPostProcessNode(const IRenderPostProcessNode&) = delete;
114     IRenderPostProcessNode& operator=(const IRenderPostProcessNode&) = delete;
115     IRenderPostProcessNode(IRenderPostProcessNode&&) = delete;
116     IRenderPostProcessNode& operator=(IRenderPostProcessNode&&) = delete;
117 };
118 RENDER_END_NAMESPACE()
119 
120 #endif // API_RENDER_NODECONTEXT_IRENDER_POST_PROCESS_NODE_H
121