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_DATA_STORE_POST_PROCESS_H
17 #define API_RENDER_IRENDER_DATA_STORE_POST_PROCESS_H
18
19 #include <cstdint>
20
21 #include <base/containers/fixed_string.h>
22 #include <base/containers/string_view.h>
23 #include <base/containers/vector.h>
24 #include <base/math/vector.h>
25 #include <base/util/uid.h>
26 #include <render/datastore/intf_render_data_store.h>
27 #include <render/datastore/render_data_store_render_pods.h>
28 #include <render/namespace.h>
29
RENDER_BEGIN_NAMESPACE()30 RENDER_BEGIN_NAMESPACE()
31 /** @ingroup group_render_irenderdatastorepostprocess */
32 /** IRenderDataStorePostProcess interface.
33 * Internally synchronized.
34 *
35 * Post process mapper for low-level post process PODs
36 * One can add names for custom post process and add their local data
37 *
38 * Usage:
39 * Create() with a unique name.
40 * Get() get (preferrably only a single post process data).
41 * Destroy() destroy from render data store.
42 */
43 class IRenderDataStorePostProcess : public IRenderDataStore {
44 public:
45 static constexpr BASE_NS::Uid UID { "329a8427-4c0f-48ab-b9fa-3f9bc6dfbcbd" };
46
47 /** Values map to render_data_store_render_pods.h */
48 struct GlobalFactors {
49 /** Enabled flags */
50 uint32_t enableFlags { 0u };
51
52 /** User post process factors which are automatically mapped and can be used easily anywhere in the pipeline */
53 BASE_NS::Math::Vec4 factors[PostProcessConstants::GLOBAL_FACTOR_COUNT];
54
55 /** User post process factors which are automatically mapped and can be used easily anywhere in the pipeline */
56 BASE_NS::Math::Vec4 userFactors[PostProcessConstants::USER_GLOBAL_FACTOR_COUNT];
57 };
58
59 struct PostProcess {
60 /* Name for the post process (flags and data fetched with this) e.g. "custom_tonemap" */
61 BASE_NS::fixed_string<64u> name;
62 /* Id, created when post process created */
63 uint32_t id { ~0u };
64 /* Factor index to fetch user factors from GlobalPostProcess struct */
65 uint32_t factorIndex { ~0u };
66 /* Default shader handle for the post process */
67 RenderHandleReference shader {};
68
69 struct Variables {
70 /* Factor index to fetch user factors from GlobalPostProcess struct */
71 uint32_t userFactorIndex { ~0u };
72 /* Factor which can be mapped to various parts of the pipeline with GlobalPostProcess struct */
73 BASE_NS::Math::Vec4 factor { 0.0f, 0.0f, 0.0f, 0.0f };
74 /* Factors which are mapped with LocalPostProcess struct. Byte data to pass data without conversions */
75 uint8_t customPropertyData[PostProcessConstants::USER_LOCAL_FACTOR_BYTE_SIZE] {};
76 /* Is the post process enabled */
77 bool enabled { false };
78 /* Additional flags */
79 uint32_t flags { 0u };
80 };
81 Variables variables;
82 };
83
84 /** Create a new post process with POD or use existing. (Unique names with render data store pods)
85 * If the name is already the already created object is returned.
86 * @param name A unique name for the post process stack.
87 */
88 virtual void Create(const BASE_NS::string_view name) = 0;
89
90 /** Create a new single post process to already created post process
91 * If the name is already the already created the object is not created again.
92 * NOTE: if "materialMetaData" is found from the shader the localFactorData is fetch from it.
93 * One needs to do Set() to override this default built-in data.
94 * @param name A unique name of the post process.
95 * @param ppName A unique name for the single post process.
96 * @param shader Optional shader handle to be used as post process default shader.
97 */
98 virtual void Create(
99 const BASE_NS::string_view name, const BASE_NS::string_view ppName, const RenderHandleReference& shader) = 0;
100
101 /** Destroy. The related render data store post process pod is destroyed as well
102 * @param name Name of the post process.
103 */
104 virtual void Destroy(const BASE_NS::string_view name) = 0;
105
106 /** Destroy a single post process.
107 * @param name Name of the post process.
108 * @param ppName Name of the single post process effect.
109 */
110 virtual void Destroy(const BASE_NS::string_view name, const BASE_NS::string_view ppName) = 0;
111
112 /** Checks that the post process is already created.
113 * @param name Name of the post process.
114 * @return Boolean value.
115 */
116 virtual bool Contains(const BASE_NS::string_view name) const = 0;
117
118 /** Checks that the post process and its single post process is already created.
119 * @param name Name of the post process.
120 * @param ppName Name of the single post process.
121 * @return Boolean value.
122 */
123 virtual bool Contains(const BASE_NS::string_view name, const BASE_NS::string_view ppName) const = 0;
124
125 /** Set variables to a single post process.
126 * @param name Name of the post process stack
127 * @param ppName Name of the single post process effect.
128 * @param vars Variables to set for the single post process
129 */
130 virtual void Set(
131 const BASE_NS::string_view name, const BASE_NS::string_view ppName, const PostProcess::Variables& vars) = 0;
132
133 /** Set multiple variables to a post process. They are filled in order.
134 * @param name Name of the post process stack
135 * @param vars Variables to set for the single post processes
136 */
137 virtual void Set(const BASE_NS::string_view name, const BASE_NS::array_view<PostProcess::Variables> vars) = 0;
138
139 /** Get global post process data.
140 * @param name Name of the post process stack
141 * @return Global factors
142 */
143 virtual GlobalFactors GetGlobalFactors(const BASE_NS::string_view name) const = 0;
144
145 /** Get all post processes by name. Copies all data should not be used every frame.
146 * @param name Name of the post process stack
147 */
148 virtual BASE_NS::vector<PostProcess> Get(const BASE_NS::string_view name) const = 0;
149
150 /** Get a single post process data.
151 * @param name Name of the post process stack
152 * @param ppName Name of the single post process
153 * @return Single post process
154 */
155 virtual PostProcess Get(const BASE_NS::string_view name, const BASE_NS::string_view ppName) const = 0;
156
157 protected:
158 virtual ~IRenderDataStorePostProcess() override = default;
159 IRenderDataStorePostProcess() = default;
160 };
161 RENDER_END_NAMESPACE()
162
163 #endif // API_RENDER_IRENDER_DATA_STORE_POST_PROCESS_H
164