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_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 #define POST_PROCESS_INDEX_DOF 12
47 #define POST_PROCESS_INDEX_MOTION_BLUR 13
48 
49 // should be aligned to 512 (i.e. 14 x vec4 + 2 x vec4 + 16 x vec4)
50 #define POST_PROCESS_GLOBAL_VEC4_FACTOR_COUNT 14
51 #define POST_PROCESS_GLOBAL_USER_VEC4_FACTOR_COUNT 16
52 // aligned to 256
53 #define POST_PROCESS_LOCAL_VEC4_FACTOR_COUNT 16
54 
55 #define CORE_POST_PROCESS_TONEMAP_ACES 0
56 #define CORE_POST_PROCESS_TONEMAP_ACES_2020 1
57 #define CORE_POST_PROCESS_TONEMAP_FILMIC 2
58 
59 #define CORE_POST_PROCESS_COLOR_CONVERSION_SRGB 1
60 
61 #else
62 
63 // note global post process UBO struct alignment for 512
64 constexpr uint32_t POST_PROCESS_GLOBAL_VEC4_FACTOR_COUNT { 14u };
65 constexpr uint32_t POST_PROCESS_GLOBAL_USER_VEC4_FACTOR_COUNT { 16u };
66 // note UBO struct alignment for 256
67 constexpr uint32_t POST_PROCESS_LOCAL_VEC4_FACTOR_COUNT { 16u };
68 
69 #endif
70 
71 // the same data throughout the pipeline
72 // should be aligned to 512 (i.e. 32 x vec4)
73 // needs to match api/core/render/RenderDataStoreRenderPods.h
74 struct GlobalPostProcessStruct {
75     // enable flags
76     uvec4 flags;
77     // .x = delta time (ms), .y = tick delta time (ms), .z = tick total time (s), .w = frame index (asuint)
78     vec4 renderTimings;
79 
80     // all factors from defines
81     vec4 factors[POST_PROCESS_GLOBAL_VEC4_FACTOR_COUNT];
82 
83     // all user factors that are automatically mapped
84     vec4 userFactors[POST_PROCESS_GLOBAL_USER_VEC4_FACTOR_COUNT];
85 };
86 
87 // local data for a specific post process
88 // should be aligned to 256 (i.e. 16 x vec4)
89 // NOTE: one can create a new struct in their own shader, please note the alignment
90 struct LocalPostProcessStruct {
91     // all factors for the specific post process material
92     vec4 factors[POST_PROCESS_LOCAL_VEC4_FACTOR_COUNT];
93 };
94 
95 struct LocalPostProcessPushConstantStruct {
96     // viewport size and inverse viewport size for this draw
97     vec4 viewportSizeInvSize;
98     // fast factors for effect, might be direction for blur, some specific coefficients etc.
99     vec4 factor;
100 };
101 
102 struct PostProcessTonemapStruct {
103     vec4 texSizeInvTexSize;
104 
105     uvec4 flags;
106 
107     vec4 tonemap;
108     vec4 vignette;
109     vec4 colorFringe;
110     vec4 dither;
111     // .x is thresholdHard, .y is thresholdSoft, .z is amountCoefficient, .w is dirtMaskCoefficient
112     vec4 bloomParameters;
113 };
114 
115 #endif // API_RENDER_SHADERS_COMMON_POST_PROCESS_STRUCTS_COMMON_H
116