• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_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  * Deprecated: prefer using IRenderFrameUtil::SetBackBufferConfiguration()
31  */
32 struct NodeGraphBackBufferConfiguration {
33     /** Max back buffer name length */
34     static constexpr uint32_t CORE_MAX_BACK_BUFFER_NAME_LENGTH { 128 };
35 
36     /** Back buffer type */
37     enum class BackBufferType : uint32_t {
38         /** Undefined */
39         UNDEFINED,
40         /** Swapchain */
41         SWAPCHAIN,
42         /** GPU image */
43         GPU_IMAGE,
44         /** GPU image buffer copy */
45         GPU_IMAGE_BUFFER_COPY,
46     };
47 
48     /** Name of the GpuImage in render node graph json where rendering happens.
49      * Image with this name must have been created by the application (or by the engine). */
50     char backBufferName[CORE_MAX_BACK_BUFFER_NAME_LENGTH];
51 
52     /** Back buffer type */
53     BackBufferType backBufferType = { BackBufferType::UNDEFINED };
54 
55     /** Handle to the final target.
56      * If backbufferType is SWAPCHAIN this handle is not used.
57      * If backbufferType is GPU_IMAGE this must point to a valid GpuImage.
58      * If backbufferType is GPU_IMAGE_BUFFER_COPY this must point to a valid (linear) GpuImage. */
59     RenderHandle backBufferHandle;
60     /* If backbufferType is GPU_IMAGE_BUFFER_COPY this must point to a valid GpuBuffer where image data is copied. */
61     RenderHandle gpuBufferHandle;
62 
63     /** Present */
64     bool present { false };
65 
66     /** Binary semaphore for signaling end of frame, i.e. when rendered to back buffer */
67     uint64_t gpuSemaphoreHandle { 0 };
68 };
69 
70 /** Post process name constants. */
71 struct PostProcessConstants {
72     /** Render built-in post process indices */
73     enum POST_PROCESS_INDICES {
74         /** Render tonemap */
75         RENDER_TONEMAP = 0,
76         /** Render vignette */
77         RENDER_VIGNETTE = 1,
78         /** Render dither */
79         RENDER_DITHER = 2,
80         /** Render color conversion */
81         RENDER_COLOR_CONVERSION = 3,
82         /** Render fringe */
83         RENDER_COLOR_FRINGE_BIT = 4,
84 
85         /** Render empty */
86         RENDER_EMPTY_5 = 5,
87         /** Render empty */
88         RENDER_EMPTY_6 = 6,
89         /** Render empty */
90         RENDER_EMPTY_7 = 7,
91 
92         /** Render blur index */
93         RENDER_BLUR = 8,
94         /** Render bloom index */
95         RENDER_BLOOM = 9,
96         /** Render fxaa index */
97         RENDER_FXAA = 10,
98         /** Render taa index */
99         RENDER_TAA = 11,
100         /** Render dof index */
101         RENDER_DOF = 12,
102         /** Render motion blur */
103         RENDER_MOTION_BLUR = 13,
104         /** Built-in meaningfull post process count */
105         POST_PROCESS_COUNT = 14,
106     };
107 
108     /** Render built-in post process names */
109     static constexpr BASE_NS::string_view POST_PROCESS_NAMES[POST_PROCESS_INDICES::POST_PROCESS_COUNT] {
110         "render_tonemap",
111         "render_vignette",
112         "render_dither",
113         "render_color_conversion",
114         "render_color_fringe",
115         "",
116         "",
117         "",
118         "render_blur",
119         "render_bloom",
120         "render_fxaa",
121         "render_taa",
122         "render_dof",
123         "render_motion_blur",
124     };
125 
126     /** First available post process id for user custom effects */
127     static constexpr uint32_t FIRST_USER_POST_PROCESS_ID { 16u };
128     /** Last available post process id for user custom effects */
129     static constexpr uint32_t LAST_USER_POST_PROCESS_ID { 31u };
130 
131     /** Global post process factor count */
132     static constexpr uint32_t GLOBAL_FACTOR_COUNT { POST_PROCESS_INDICES::POST_PROCESS_COUNT };
133     /** User global post process factor count */
134     static constexpr uint32_t USER_GLOBAL_FACTOR_COUNT { 16u };
135     /** User local post process factor count */
136     static constexpr uint32_t USER_LOCAL_FACTOR_COUNT { USER_GLOBAL_FACTOR_COUNT };
137     /** User local post process factor byte size */
138     static constexpr uint32_t USER_LOCAL_FACTOR_BYTE_SIZE { 256u };
139 };
140 
141 /** Bloom post process configuration. */
142 struct BloomConfiguration {
143     /** Bloom quality type enum */
144     enum BloomQualityType {
145         /** Low quality */
146         QUALITY_TYPE_LOW = 0,
147         /** Normal quality */
148         QUALITY_TYPE_NORMAL = 1,
149         /** High quality */
150         QUALITY_TYPE_HIGH = 2,
151     };
152     /** Bloom type enum */
153     enum BloomType {
154         /** Normal, smooth to every direction */
155         TYPE_NORMAL = 0,
156         /** Blurred/Blooms more in horizontal direction */
157         TYPE_HORIZONTAL = 1,
158         /** Blurred/Blooms more in vertical direction */
159         TYPE_VERTICAL = 2,
160         /** Bilateral filter, uses depth if available */
161         TYPE_BILATERAL = 3,
162     };
163 
164     /** Bloom type */
165     BloomType bloomType { BloomType::TYPE_NORMAL };
166     /** Bloom quality type */
167     BloomQualityType bloomQualityType { BloomQualityType::QUALITY_TYPE_NORMAL };
168 
169     /** Threshold hard (Default: 1.0f) */
170     float thresholdHard { 1.0f };
171     /** Threshold soft (Default: 2.0f) */
172     float thresholdSoft { 2.0f };
173     /** Coefficient amount */
174     float amountCoefficient { 0.25f };
175     /** Dirt mask coefficient */
176     float dirtMaskCoefficient { 0.0f };
177     /** Scatter (amount of bloom spread). (1.0 full spread / default) */
178     float scatter { 1.0f };
179     /** Scaling factor. Controls the amount of scaling and bloom spread
180      * Reduces the downscale and upscale steps
181      * Values 0 - 1. Value of 0.5 halves the scale steps
182      */
183     float scaleFactor { 1.0f };
184 
185     /** Optional dirt mask image handle */
186     RenderHandle dirtMaskImage {};
187     /** Use compute dispatches for bloom */
188     bool useCompute { false };
189 };
190 
191 /** Vignette post process configuration. */
192 struct VignetteConfiguration {
193     /** Coefficient (Default: 0.5f) */
194     float coefficient { 0.5f };
195     /** Power (Default: 0.4f) */
196     float power { 0.4f };
197 };
198 
199 /** Color fringe post process configuration. */
200 struct ColorFringeConfiguration {
201     /** Coefficient */
202     float coefficient { 1.0f };
203     /** Distance coefficient */
204     float distanceCoefficient { 2.0f };
205 };
206 
207 /** Dither post process configuration. */
208 struct DitherConfiguration {
209     /** Dither type enum */
210     enum DitherType {
211         /** Interleaved noise */
212         INTERLEAVED_NOISE = 0,
213         /** Interleaved noise */
214         TRIANGLE_NOISE = 0,
215         /** Interleaved noise */
216         TRIANGLE_NOISE_RGB = 0,
217     };
218 
219     /* Dither type */
220     DitherType ditherType { DitherType::INTERLEAVED_NOISE };
221 
222     /* Amount coefficient */
223     float amountCoefficient { 0.1f };
224 };
225 
226 struct BlurConfiguration {
227     /** Blur quality type enum */
228     enum BlurQualityType {
229         /** Low */
230         QUALITY_TYPE_LOW = 0,
231         /** Normal */
232         QUALITY_TYPE_NORMAL = 1,
233         /** Gaussian like, more smooth */
234         QUALITY_TYPE_HIGH = 2,
235     };
236     /** Blur type enum */
237     enum BlurType {
238         /** Normal, smooth to every direction */
239         TYPE_NORMAL = 0,
240         /** Blurred more in horizontal direction */
241         TYPE_HORIZONTAL = 1,
242         /** Blurred more in vertical direction */
243         TYPE_VERTICAL = 2,
244     };
245 
246     /** Blur type */
247     BlurType blurType { BlurType::TYPE_NORMAL };
248     /** Blur quality type */
249     BlurQualityType blurQualityType { BlurQualityType::QUALITY_TYPE_NORMAL };
250     /** Blur desired filter size in pixels. Might not be exact. */
251     float filterSize { 1.0f };
252     /** Blur quality max mip. If mips available. With this one could only blur to first (few) mips */
253     uint32_t maxMipLevel { ~0u };
254 };
255 
256 /** Tonemap configuration. */
257 struct TonemapConfiguration {
258     /** Tonemap type */
259     enum TonemapType {
260         /** Aces */
261         TONEMAP_ACES = 0,
262         /** Aces 2020 */
263         TONEMAP_ACES_2020 = 1,
264         /** Filmic */
265         TONEMAP_FILMIC = 2,
266     };
267 
268     /** Tonemap type */
269     TonemapType tonemapType { TonemapType::TONEMAP_ACES };
270     /** Exposure */
271     float exposure { 0.7f };
272 };
273 
274 /** Opto-electronic conversion functions. */
275 struct ColorConversionConfiguration {
276     /** Tonemap type */
277     enum ConversionFunctionType {
278         /** Linear -> no conversion in normal situation. */
279         CONVERSION_LINEAR = 0,
280         /** Linear to sRGB conversion */
281         CONVERSION_LINEAR_TO_SRGB = 1,
282     };
283 
284     /** Conversion function type */
285     ConversionFunctionType conversionFunctionType { ConversionFunctionType::CONVERSION_LINEAR };
286 };
287 
288 /** Fxaa Antialiasing configuration. */
289 struct FxaaConfiguration {
290     enum class Sharpness { SOFT = 0, MEDIUM = 1, SHARP = 2 };
291     enum class Quality { LOW = 0, MEDIUM = 1, HIGH = 2 };
292 
293     /** Edge sharpness. */
294     Sharpness sharpness { Sharpness::SHARP };
295     /** Overall edge quality. */
296     Quality quality { Quality::MEDIUM };
297 };
298 
299 /** Taa Antialiasing configuration. */
300 struct TaaConfiguration {
301     enum class Sharpness { SOFT = 0, MEDIUM = 1, SHARP = 2 };
302     enum class Quality { LOW = 0, MEDIUM = 1, HIGH = 2 };
303 
304     /** Edge sharpness. */
305     Sharpness sharpness { Sharpness::SHARP };
306     /** Overall edge quality. */
307     Quality quality { Quality::MEDIUM };
308     /** Whether to use bicubic sampling. */
309     bool useBicubic { true };
310     /** Whether to use mean-variance clipping of the history color. */
311     bool useVarianceClipping { true };
312     /** Whether to use yCoCG filtering. */
313     bool useyCoCG { true };
314     /** If set to true, do not use bicubic filtering for edges. */
315     bool ignoreBicubicEdges { true };
316 };
317 
318 /** Depth of field configuration.
319  * This is expected to be filled so that focusPoint is between nearPlane and farPlane.
320  * Amount of blurriness:
321  * nearPlane                             focusPoint                            farPlane
322  *      nearBlur |    (nearBlur..0)    |      0     |    (0..farBlur)    | farBlur
323  *               | nearTransitionRange | focusRange | farTransitionRange |
324  */
325 struct DofConfiguration {
326     /** Distance to point of focus. */
327     float focusPoint { 3.f };
328     /** Range around focusPoint which is in focus. */
329     float focusRange { 1.f };
330     /** Range before focusRange where the view transitions from blurred to focused. */
331     float nearTransitionRange { 1.f };
332     /** Range after focusRange where the view transitions from focused to blurred. */
333     float farTransitionRange { 1.f };
334     /** Blur level used close to the viewer. */
335     float nearBlur { 2.f };
336     /** Blur level used far away from the viewer. */
337     float farBlur { 2.f };
338     /** View near plane. */
339     float nearPlane { 0.1f };
340     /** View far plane. */
341     float farPlane { 1000.f };
342 };
343 
344 /** Motion blur configuration.
345  */
346 struct MotionBlurConfiguration {
347     /** Sharpness of the effect. */
348     enum class Sharpness : uint32_t { SOFT = 0, MEDIUM = 1, SHARP = 2 };
349     /** Quality of the effect. */
350     enum class Quality : uint32_t { LOW = 0U, MEDIUM = 1U, HIGH = 2U };
351 
352     /** Sharpness. */
353     Sharpness sharpness { Sharpness::SHARP };
354     /** Quality. */
355     Quality quality { Quality::HIGH };
356     /** Alpha blending. 1.0 -> fully motion blur sample. */
357     float alpha { 1.0f };
358     /** Velocity coefficient. */
359     float velocityCoefficient { 1.0f };
360 };
361 
362 /** Lens flare configuration.
363  */
364 struct LensFlareConfiguration {
365     /** Quality of the effect. */
366     enum class Quality : uint32_t { LOW = 0U, MEDIUM = 1U, HIGH = 2U };
367 
368     /** Quality. */
369     Quality quality { Quality::HIGH };
370     /** Intensity of the effect. */
371     float intensity { 1.0f };
372     /** Flare position */
373     BASE_NS::Math::Vec3 flarePosition { 0.0f, 0.0f, 0.0f };
374 };
375 
376 /** Post process configuration POD. */
377 struct PostProcessConfiguration {
378     /** Post process enable flags. Used in shader as well, must match render_post_process_structs_common.h */
379     enum PostProcessEnableFlagBits : uint32_t {
380         /** Enable tonemap */
381         ENABLE_TONEMAP_BIT = (1 << 0),
382         /** Enable vignette */
383         ENABLE_VIGNETTE_BIT = (1 << 1),
384         /** Enable dither */
385         ENABLE_DITHER_BIT = (1 << 2),
386         /** Enable color conversion */
387         ENABLE_COLOR_CONVERSION_BIT = (1 << 3),
388         /** Enable fringe */
389         ENABLE_COLOR_FRINGE_BIT = (1 << 4),
390 
391         /** Enable blur */
392         ENABLE_BLUR_BIT = (1 << 8),
393         /** Enable bloom */
394         ENABLE_BLOOM_BIT = (1 << 9),
395         /** Enable FXAA */
396         ENABLE_FXAA_BIT = (1 << 10),
397         /** Enable TAA */
398         ENABLE_TAA_BIT = (1 << 11),
399         /** Enable depth of field */
400         ENABLE_DOF_BIT = (1 << 12),
401         /** Enable motion blur */
402         ENABLE_MOTION_BLUR_BIT = (1 << 13),
403         /** Enable lens flare */
404         ENABLE_LENS_FLARE_BIT = (1 << 14),
405     };
406     using PostProcessEnableFlags = uint32_t;
407 
408     /** Factor indices. */
409     enum PostProcessFactorIndices : uint32_t {
410         INDEX_TONEMAP = 0,
411         INDEX_VIGNETTE = 1,
412         INDEX_DITHER = 2,
413         INDEX_COLOR_CONVERSION = 3,
414         INDEX_COLOR_FRINGE = 4,
415 
416         INDEX_BLUR = 8,
417         INDEX_BLOOM = 9,
418         INDEX_FXAA = 10,
419         INDEX_TAA = 11,
420         INDEX_DOF = 12,
421         INDEX_MOTION_BLUR = 13,
422         INDEX_LENS_FLARE = 14,
423 
424         INDEX_FACTOR_COUNT = 15,
425     };
426     /** Enabled flags */
427     PostProcessEnableFlags enableFlags { 0u };
428 
429     /** Tonemap configuration */
430     TonemapConfiguration tonemapConfiguration;
431     /** Vignette configuration */
432     VignetteConfiguration vignetteConfiguration;
433     /** Dither configuration */
434     DitherConfiguration ditherConfiguration;
435     /** Color conversion configuration */
436     ColorConversionConfiguration colorConversionConfiguration;
437 
438     /** Color fringe configuration */
439     ColorFringeConfiguration colorFringeConfiguration;
440 
441     /** Bloom configuration */
442     BloomConfiguration bloomConfiguration;
443     /** Blur configuration */
444     BlurConfiguration blurConfiguration;
445 
446     /** Fxaa antialiasing configuration */
447     FxaaConfiguration fxaaConfiguration;
448     /** Taa antialiasing configuration */
449     TaaConfiguration taaConfiguration;
450 
451     /** Depth of field configuration */
452     DofConfiguration dofConfiguration;
453 
454     /** Motion blur configuration */
455     MotionBlurConfiguration motionBlurConfiguration;
456 
457     /** Lens flare configuration */
458     LensFlareConfiguration lensFlareConfiguration;
459 
460     /** User post process factors which are automatically mapped and can be used easily anywhere in the pipeline */
461     BASE_NS::Math::Vec4 userFactors[PostProcessConstants::USER_GLOBAL_FACTOR_COUNT];
462 };
463 
464 /** Render post process configuration (must match render_post_process_structs_common.h */
465 struct RenderPostProcessConfiguration {
466     /* Single uvec4 for flags .x has post process specialization flags */
467     BASE_NS::Math::UVec4 flags { 0, 0, 0, 0 };
468     // .x = delta time (ms), .y = tick delta time (ms), .z = tick total time (s), .w = frame index (asuint)
469     BASE_NS::Math::Vec4 renderTimings { 0.0f, 0.0f, 0.0f, 0.0f };
470     /* All built-in post process factors */
471     BASE_NS::Math::Vec4 factors[PostProcessConstants::GLOBAL_FACTOR_COUNT];
472 
473     /* All user post process factors */
474     BASE_NS::Math::Vec4 userFactors[PostProcessConstants::USER_GLOBAL_FACTOR_COUNT];
475 };
476 
477 /** Default render pod store for shader specialization */
478 struct ShaderSpecializationRenderPod {
479     /* Max supported specialization constants */
480     static constexpr uint32_t MAX_SPECIALIZATION_CONSTANT_COUNT { 8u };
481     /* Constant flags are mapped in order, use constant_id 0, 1.. in shaders.
482      * Do not leave unused constant ids.
483      */
484     struct ConstantFlags {
485         /** Value */
486         uint32_t value { 0u };
487     };
488 
489     /** Count of constants */
490     uint32_t specializationConstantCount { 0u };
491     /** Specialization data */
492     ConstantFlags specializationFlags[MAX_SPECIALIZATION_CONSTANT_COUNT] {};
493 };
494 /** @} */
495 RENDER_END_NAMESPACE()
496 
497 #endif // API_RENDER_RENDER_DATA_STORE_RENDER_PODS_H
498