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