• 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_SHADERS_COMMON_POST_PROCESS_STRUCTS_COMMON_H
17 #define API_RENDER_SHADERS_COMMON_POST_PROCESS_STRUCTS_COMMON_H
18 
19 #include "render/shaders/common/render_compatibility_common.h"
20 
21 // defines
22 #ifdef VULKAN
23 
24 // needs to match api/core/render/render_data_store_render_pods.h
25 #define POST_PROCESS_SPECIALIZATION_TONEMAP_BIT (1 << 0)
26 #define POST_PROCESS_SPECIALIZATION_VIGNETTE_BIT (1 << 1)
27 #define POST_PROCESS_SPECIALIZATION_DITHER_BIT (1 << 2)
28 #define POST_PROCESS_SPECIALIZATION_COLOR_CONVERSION_BIT (1 << 3)
29 #define POST_PROCESS_SPECIALIZATION_COLOR_FRINGE_BIT (1 << 4)
30 
31 #define POST_PROCESS_SPECIALIZATION_BLUR_BIT (1 << 8)
32 #define POST_PROCESS_SPECIALIZATION_BLOOM_BIT (1 << 9)
33 #define POST_PROCESS_SPECIALIZATION_FXAA_BIT (1 << 10)
34 #define POST_PROCESS_SPECIALIZATION_TAA_BIT (1 << 11)
35 
36 #define POST_PROCESS_INDEX_TONEMAP 0
37 #define POST_PROCESS_INDEX_VIGNETTE 1
38 #define POST_PROCESS_INDEX_DITHER 2
39 #define POST_PROCESS_INDEX_COLOR_CONVERSION 3
40 #define POST_PROCESS_INDEX_COLOR_FRINGE 4
41 
42 #define POST_PROCESS_INDEX_BLUR 8
43 #define POST_PROCESS_INDEX_BLOOM 9
44 #define POST_PROCESS_INDEX_FXAA 10
45 #define POST_PROCESS_INDEX_TAA 11
46 
47 // should be aligned to 256 (i.e. 14 x vec4 + 2 x vec4)
48 #define POST_PROCESS_GLOBAL_VEC4_FACTOR_COUNT 14
49 #define POST_PROCESS_LOCAL_VEC4_FACTOR_COUNT 16
50 
51 #define CORE_POST_PROCESS_TONEMAP_ACES 0
52 #define CORE_POST_PROCESS_TONEMAP_ACES_2020 1
53 #define CORE_POST_PROCESS_TONEMAP_FILMIC 2
54 
55 #define CORE_POST_PROCESS_COLOR_CONVERSION_SRGB 1
56 
57 #else
58 
59 // note UBO struct alignment for 256
60 constexpr uint32_t POST_PROCESS_GLOBAL_VEC4_FACTOR_COUNT { 14 };
61 constexpr uint32_t POST_PROCESS_LOCAL_VEC4_FACTOR_COUNT { 16 };
62 
63 #endif
64 
65 // the same data throughout the pipeline
66 // should be aligned to 256 (i.e. 16 x vec4)
67 // needs to match api/core/render/RenderDataStoreRenderPods.h
68 struct GlobalPostProcessStruct {
69     // enable flags
70     uvec4 flags;
71     // .x = delta time (ms), .y = tick delta time (ms), .z = tick total time (s), .w = frame index (asuint)
72     vec4 renderTimings;
73 
74     // all factors from defines
75     vec4 factors[POST_PROCESS_GLOBAL_VEC4_FACTOR_COUNT];
76 };
77 
78 // local data for a specific post process
79 // should be aligned to 256 (i.e. 16 x vec4)
80 // NOTE: one can create a new struct in their own shader, please note the alignment
81 struct LocalPostProcessStruct {
82     // all factors for the specific post process material
83     vec4 factors[POST_PROCESS_LOCAL_VEC4_FACTOR_COUNT];
84 };
85 
86 struct LocalPostProcessPushConstantStruct {
87     // viewport size and inverse viewport size for this draw
88     vec4 viewportSizeInvSize;
89     // fast factors for effect, might be direction for blur, some specific coefficients etc.
90     vec4 factor;
91 };
92 
93 struct PostProcessTonemapStruct {
94     vec4 texSizeInvTexSize;
95 
96     uvec4 flags;
97 
98     vec4 tonemap;
99     vec4 vignette;
100     vec4 colorFringe;
101     vec4 dither;
102     // .x is thresholdHard, .y is thresholdSoft, .z is amountCoefficient, .w is dirtMaskCoefficient
103     vec4 bloomParameters;
104 };
105 
106 #endif // API_RENDER_SHADERS_COMMON_POST_PROCESS_STRUCTS_COMMON_H
107