• 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_RENDER_DATA_STORE_RENDER_PODS_H
17 #define API_RENDER_RENDER_DATA_STORE_RENDER_PODS_H
18 
19 #include <cstdint>
20 
21 #include <base/math/vector.h>
22 #include <render/namespace.h>
23 #include <render/resource_handle.h>
24 
25 RENDER_BEGIN_NAMESPACE()
26 /** \addtogroup group_render_renderdatastorerenderpods
27  *  @{
28  */
29 /** A POD for back buffer configuration */
30 struct NodeGraphBackBufferConfiguration {
31     /** Max back buffer name length */
32     static constexpr uint32_t CORE_MAX_BACK_BUFFER_NAME_LENGTH { 128 };
33 
34     /** Back buffer type */
35     enum class BackBufferType : uint32_t {
36         /** Undefined */
37         UNDEFINED,
38         /** Swapchain */
39         SWAPCHAIN,
40         /** GPU image */
41         GPU_IMAGE,
42         /** GPU image buffer copy */
43         GPU_IMAGE_BUFFER_COPY,
44     };
45 
46     /** Name of the GpuImage in render node graph json where rendering happens.
47      * Image with this name must have been created by the application (or by the engine). */
48     char backBufferName[CORE_MAX_BACK_BUFFER_NAME_LENGTH];
49 
50     /** Back buffer type */
51     BackBufferType backBufferType = { BackBufferType::UNDEFINED };
52 
53     /** Handle to the final target.
54      * - If backbufferType is SWAPCHAIN this handle is not used.
55      * - If backbufferType is GPU_IMAGE this must point to a valid GpuImage.
56      * - If backbufferType is GPU_IMAGE_BUFFER_COPY this must point to a valid (linear) GpuImage. */
57     RenderHandleReference backBufferHandle;
58     /* - If backbufferType is GPU_IMAGE_BUFFER_COPY this must point to a valid GpuBuffer where image data is copied. */
59     RenderHandleReference gpuBufferHandle;
60 
61     /** Present */
62     bool present { false };
63 
64     /** Binary semaphore for signaling end of frame, i.e. when rendered to back buffer */
65     uint64_t gpuSemaphoreHandle { 0 };
66 };
67 
68 /** Bloom post process configuration. */
69 struct BloomConfiguration {
70     /** Bloom quality type enum */
71     enum BloomQualityType {
72         /** Low quality */
73         QUALITY_TYPE_LOW = 0,
74         /** Normal quality */
75         QUALITY_TYPE_NORMAL = 1,
76         /** High quality */
77         QUALITY_TYPE_HIGH = 2,
78     };
79     /** Bloom type enum */
80     enum BloomType {
81         /** Normal, smooth to every direction */
82         TYPE_NORMAL = 0,
83         /** Blurred/Blooms more in horizontal direction */
84         TYPE_HORIZONTAL = 1,
85         /** Blurred/Blooms more in vertical direction */
86         TYPE_VERTICAL = 2,
87         /** Bilateral filter, uses depth if available */
88         TYPE_BILATERAL = 3,
89     };
90 
91     /** Bloom type */
92     BloomType bloomType { BloomType::TYPE_NORMAL };
93     /** Bloom quality type */
94     BloomQualityType bloomQualityType { BloomQualityType::QUALITY_TYPE_NORMAL };
95 
96     /** Threshold hard (Default: 1.0f) */
97     float thresholdHard { 1.0f };
98     /** Threshold soft (Default: 2.0f) */
99     float thresholdSoft { 2.0f };
100     /** Coefficient amount */
101     float amountCoefficient { 0.25f };
102     /** Dirt mask coefficient */
103     float dirtMaskCoefficient { 0.0f };
104 
105     /** Optional dirt mask image handle */
106     RenderHandleReference dirtMaskImage {};
107     /** Use compute dispatches for bloom */
108     bool useCompute { false };
109 };
110 
111 /** Vignette post process configuration. */
112 struct VignetteConfiguration {
113     /** Coefficient (Default: 0.5f) */
114     float coefficient { 0.5f };
115     /** Power (Default: 0.4f) */
116     float power { 0.4f };
117 };
118 
119 /** Color fringe post process configuration. */
120 struct ColorFringeConfiguration {
121     /** Coefficient */
122     float coefficient { 1.0f };
123     /** Distance coefficient */
124     float distanceCoefficient { 2.0f };
125 };
126 
127 /** Dither post process configuration. */
128 struct DitherConfiguration {
129     /** Dither type enum */
130     enum DitherType {
131         /** Interleaved noise */
132         INTERLEAVED_NOISE = 0,
133         /** Interleaved noise */
134         TRIANGLE_NOISE = 0,
135         /** Interleaved noise */
136         TRIANGLE_NOISE_RGB = 0,
137     };
138 
139     /* Dither type */
140     DitherType ditherType { DitherType::INTERLEAVED_NOISE };
141 
142     /* Amount coefficient */
143     float amountCoefficient { 0.1f };
144 };
145 
146 struct BlurConfiguration {
147     /** Blur quality type enum */
148     enum BlurQualityType {
149         /** Low */
150         QUALITY_TYPE_LOW = 0,
151         /** Normal */
152         QUALITY_TYPE_NORMAL = 1,
153         /** Gaussian like, more smooth */
154         QUALITY_TYPE_HIGH = 2,
155     };
156     /** Blur type enum */
157     enum BlurType {
158         /** Normal, smooth to every direction */
159         TYPE_NORMAL = 0,
160         /** Blurred more in horizontal direction */
161         TYPE_HORIZONTAL = 1,
162         /** Blurred more in vertical direction */
163         TYPE_VERTICAL = 2,
164     };
165 
166     /** Blur type */
167     BlurType blurType { BlurType::TYPE_NORMAL };
168     /** Blur quality type */
169     BlurQualityType blurQualityType { BlurQualityType::QUALITY_TYPE_NORMAL };
170     /** Blur desired filter size in pixels. Might not be exact. */
171     float filterSize { 1.0f };
172     /** Blur quality max mip. If mips available. With this one could only blur to first (few) mips */
173     uint32_t maxMipLevel { ~0u };
174 };
175 
176 /** Tonemap configuration. */
177 struct TonemapConfiguration {
178     /** Tonemap type */
179     enum TonemapType {
180         /** Aces */
181         TONEMAP_ACES = 0,
182         /** Aces 2020 */
183         TONEMAP_ACES_2020 = 1,
184         /** Filmic */
185         TONEMAP_FILMIC = 2,
186     };
187 
188     /** Tonemap type */
189     TonemapType tonemapType { TonemapType::TONEMAP_ACES };
190     /** Exposure */
191     float exposure { 0.7f };
192 };
193 
194 /** Opto-electronic conversion functions. */
195 struct ColorConversionConfiguration {
196     /** Tonemap type */
197     enum ConversionFunctionType {
198         /** Linear -> no conversion in normal situation. */
199         CONVERSION_LINEAR = 0,
200         /** Linear to sRGB conversion */
201         CONVERSION_LINEAR_TO_SRGB = 1,
202     };
203 
204     /** Conversion function type */
205     ConversionFunctionType conversionFunctionType { ConversionFunctionType::CONVERSION_LINEAR };
206 };
207 
208 /** Fxaa Antialiasing configuration. */
209 struct FxaaConfiguration {
210     enum class Sharpness { SOFT = 0, MEDIUM = 1, SHARP = 2 };
211     enum class Quality { LOW = 0, MEDIUM = 1, HIGH = 2 };
212 
213     /** Edge sharpness. */
214     Sharpness sharpness { Sharpness::SHARP };
215     /** Overall edge quality. */
216     Quality quality { Quality::MEDIUM };
217 };
218 
219 /** Taa Antialiasing configuration. */
220 struct TaaConfiguration {
221     enum class Sharpness { SOFT = 0, MEDIUM = 1, SHARP = 2 };
222     enum class Quality { LOW = 0, MEDIUM = 1, HIGH = 2 };
223 
224     /** Edge sharpness. */
225     Sharpness sharpness { Sharpness::SHARP };
226     /** Overall edge quality. */
227     Quality quality { Quality::MEDIUM };
228 };
229 
230 /** Post process configuration POD. */
231 struct PostProcessConfiguration {
232     /** Post process enable flags. Used in shader as well, must match render_post_process_structs_common.h */
233     enum PostProcessEnableFlagbits : uint32_t {
234         /** Enable tonemap */
235         ENABLE_TONEMAP_BIT = (1 << 0),
236         /** Enable vignette */
237         ENABLE_VIGNETTE_BIT = (1 << 1),
238         /** Enable dither */
239         ENABLE_DITHER_BIT = (1 << 2),
240         /** Enable color conversion */
241         ENABLE_COLOR_CONVERSION_BIT = (1 << 3),
242         /** Enable fringe */
243         ENABLE_COLOR_FRINGE_BIT = (1 << 4),
244 
245         /** Enable blur */
246         ENABLE_BLUR_BIT = (1 << 8),
247         /** Enable bloom */
248         ENABLE_BLOOM_BIT = (1 << 9),
249         /** Enable FXAA */
250         ENABLE_FXAA_BIT = (1 << 10),
251         /** Enable TAA */
252         ENABLE_TAA_BIT = (1 << 11),
253     };
254     using PostProcessEnableFlags = uint32_t;
255 
256     /** Factor indices. */
257     enum PostProcessFactorIndices : uint32_t {
258         INDEX_TONEMAP = 0,
259         INDEX_VIGNETTE = 1,
260         INDEX_DITHER = 2,
261         INDEX_COLOR_CONVERSION = 3,
262         INDEX_COLOR_FRINGE = 4,
263 
264         INDEX_BLUR = 8,
265         INDEX_BLOOM = 9,
266         INDEX_FXAA = 10,
267         INDEX_TAA = 11,
268 
269         INDEX_FACTOR_COUNT = 14,
270     };
271     /** Enabled flags */
272     PostProcessEnableFlags enableFlags { 0u };
273 
274     /** Tonemap configuration */
275     TonemapConfiguration tonemapConfiguration;
276     /** Vignette configuration */
277     VignetteConfiguration vignetteConfiguration;
278     /** Dither configuration */
279     DitherConfiguration ditherConfiguration;
280     /** Color conversion configuration */
281     ColorConversionConfiguration colorConversionConfiguration;
282 
283     /** Color fringe configuration */
284     ColorFringeConfiguration colorFringeConfiguration;
285 
286     /** Bloom configuration */
287     BloomConfiguration bloomConfiguration;
288     /** Blur configuration */
289     BlurConfiguration blurConfiguration;
290 
291     /** Fxaa antialiasing configuration */
292     FxaaConfiguration fxaaConfiguration;
293     /** Taa antialiasing configuration */
294     TaaConfiguration taaConfiguration;
295 };
296 
297 /** Render post process configuration (must match render_post_process_structs_common.h */
298 struct RenderPostProcessConfiguration {
299     /* Single uvec4 for flags .x has post process specialization flags */
300     BASE_NS::Math::UVec4 flags { 0, 0, 0, 0 };
301     // .x = delta time (ms), .y = tick delta time (ms), .z = tick total time (s), .w = frame index (asuint)
302     BASE_NS::Math::Vec4 renderTimings { 0.0f, 0.0f, 0.0f, 0.0f };
303     /* All post process factors */
304     BASE_NS::Math::Vec4 factors[PostProcessConfiguration::INDEX_FACTOR_COUNT];
305 };
306 
307 /** Default render pod store for shader specialization */
308 struct ShaderSpecializationRenderPod {
309     /* Max supported specialization constants */
310     static constexpr uint32_t MAX_SPECIALIZATION_CONSTANT_COUNT { 8u };
311     /* Constant flags are mapped in order, use constant_id 0, 1.. in shaders.
312      * Do not leave unused constant ids.
313      */
314     struct ConstantFlags {
315         /** Value */
316         uint32_t value { 0u };
317     };
318 
319     /** Count of constants */
320     uint32_t specializationConstantCount { 0u };
321     /** Specialization data */
322     ConstantFlags specializationFlags[MAX_SPECIALIZATION_CONSTANT_COUNT] {};
323 };
324 /** @} */
325 RENDER_END_NAMESPACE()
326 
327 #endif // API_RENDER_RENDER_DATA_STORE_RENDER_PODS_H
328