1 /* 2 * Copyright (c) 2022 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 /** Triangle noise */ 214 TRIANGLE_NOISE = 1, 215 /** Triangle noise rgb */ 216 TRIANGLE_NOISE_RGB = 2, 217 }; 218 219 /* Dither type */ 220 DitherType ditherType { DitherType::INTERLEAVED_NOISE }; 221 222 /* Amount coefficient */ 223 float amountCoefficient { 1.0f / 255.0f }; 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 /** PBRNeutral */ 267 TONEMAP_PBR_NEUTRAL = 3, 268 }; 269 270 /** Tonemap type */ 271 TonemapType tonemapType { TonemapType::TONEMAP_ACES }; 272 /** Exposure */ 273 float exposure { 0.7f }; 274 }; 275 276 /** Opto-electronic conversion functions. */ 277 struct ColorConversionConfiguration { 278 /** Color conversion flags */ 279 enum ConversionFunctionType { 280 /** Linear -> no conversion in normal situation. */ 281 CONVERSION_LINEAR = 0, 282 /** Linear to sRGB conversion */ 283 CONVERSION_LINEAR_TO_SRGB = (1 << 0), 284 /** Multiple rgb with alpha */ 285 CONVERSION_MULTIPLY_WITH_ALPHA = (1 << 1), 286 }; 287 using ColorConversionFlags = uint32_t; 288 289 /** Conversion function type flags */ 290 ColorConversionFlags conversionFunctionType { ConversionFunctionType::CONVERSION_LINEAR }; 291 }; 292 293 /** Fxaa Antialiasing configuration. */ 294 struct FxaaConfiguration { 295 enum class Sharpness { SOFT = 0, MEDIUM = 1, SHARP = 2 }; 296 enum class Quality { LOW = 0, MEDIUM = 1, HIGH = 2 }; 297 298 /** Edge sharpness. */ 299 Sharpness sharpness { Sharpness::SHARP }; 300 /** Overall edge quality. */ 301 Quality quality { Quality::MEDIUM }; 302 }; 303 304 /** Taa Antialiasing configuration. */ 305 struct TaaConfiguration { 306 enum class Sharpness { SOFT = 0, MEDIUM = 1, SHARP = 2 }; 307 enum class Quality { LOW = 0, MEDIUM = 1, HIGH = 2 }; 308 309 /** Edge sharpness. */ 310 Sharpness sharpness { Sharpness::SHARP }; 311 /** Overall edge quality. */ 312 Quality quality { Quality::MEDIUM }; 313 /** Whether to use bicubic sampling. */ 314 bool useBicubic { true }; 315 /** Whether to use mean-variance clipping of the history color. */ 316 bool useVarianceClipping { true }; 317 /** Whether to use yCoCG filtering. */ 318 bool useyCoCG { true }; 319 /** If set to true, do not use bicubic filtering for edges. */ 320 bool ignoreBicubicEdges { true }; 321 }; 322 323 /** Depth of field configuration. 324 * This is expected to be filled so that focusPoint is between nearPlane and farPlane. 325 * Amount of blurriness: 326 * nearPlane focusPoint farPlane 327 * nearBlur | (nearBlur..0) | 0 | (0..farBlur) | farBlur 328 * | nearTransitionRange | focusRange | farTransitionRange | 329 */ 330 struct DofConfiguration { 331 /** Distance to point of focus. */ 332 float focusPoint { 3.f }; 333 /** Range around focusPoint which is in focus. */ 334 float focusRange { 1.f }; 335 /** Range before focusRange where the view transitions from blurred to focused. */ 336 float nearTransitionRange { 1.f }; 337 /** Range after focusRange where the view transitions from focused to blurred. */ 338 float farTransitionRange { 1.f }; 339 /** Blur level used close to the viewer. */ 340 float nearBlur { 2.f }; 341 /** Blur level used far away from the viewer. */ 342 float farBlur { 2.f }; 343 /** View near plane. */ 344 float nearPlane { 0.1f }; 345 /** View far plane. */ 346 float farPlane { 1000.f }; 347 }; 348 349 /** Motion blur configuration. 350 */ 351 struct MotionBlurConfiguration { 352 /** Sharpness of the effect. */ 353 enum class Sharpness : uint32_t { SOFT = 0, MEDIUM = 1, SHARP = 2 }; 354 /** Quality of the effect. */ 355 enum class Quality : uint32_t { LOW = 0U, MEDIUM = 1U, HIGH = 2U }; 356 357 /** Sharpness. */ 358 Sharpness sharpness { Sharpness::SHARP }; 359 /** Quality. */ 360 Quality quality { Quality::HIGH }; 361 /** Alpha blending. 1.0 -> fully motion blur sample. */ 362 float alpha { 1.0f }; 363 /** Velocity coefficient. */ 364 float velocityCoefficient { 1.0f }; 365 }; 366 367 /** Lens flare configuration. 368 */ 369 struct LensFlareConfiguration { 370 /** Quality of the effect. */ 371 enum class Quality : uint32_t { LOW = 0U, MEDIUM = 1U, HIGH = 2U }; 372 373 /** Quality. */ 374 Quality quality { Quality::HIGH }; 375 /** Intensity of the effect. */ 376 float intensity { 1.0f }; 377 /** Flare position */ 378 BASE_NS::Math::Vec3 flarePosition { 0.0f, 0.0f, 0.0f }; 379 }; 380 381 /** Post process configuration POD. */ 382 struct PostProcessConfiguration { 383 /** Post process enable flags. Used in shader as well, must match render_post_process_structs_common.h */ 384 enum PostProcessEnableFlagBits : uint32_t { 385 /** Enable tonemap */ 386 ENABLE_TONEMAP_BIT = (1 << 0), 387 /** Enable vignette */ 388 ENABLE_VIGNETTE_BIT = (1 << 1), 389 /** Enable dither */ 390 ENABLE_DITHER_BIT = (1 << 2), 391 /** Enable color conversion */ 392 ENABLE_COLOR_CONVERSION_BIT = (1 << 3), 393 /** Enable fringe */ 394 ENABLE_COLOR_FRINGE_BIT = (1 << 4), 395 396 /** Enable blur */ 397 ENABLE_BLUR_BIT = (1 << 8), 398 /** Enable bloom */ 399 ENABLE_BLOOM_BIT = (1 << 9), 400 /** Enable FXAA */ 401 ENABLE_FXAA_BIT = (1 << 10), 402 /** Enable TAA */ 403 ENABLE_TAA_BIT = (1 << 11), 404 /** Enable depth of field */ 405 ENABLE_DOF_BIT = (1 << 12), 406 /** Enable motion blur */ 407 ENABLE_MOTION_BLUR_BIT = (1 << 13), 408 /** Enable lens flare */ 409 ENABLE_LENS_FLARE_BIT = (1 << 14), 410 }; 411 using PostProcessEnableFlags = uint32_t; 412 413 /** Factor indices. */ 414 enum PostProcessFactorIndices : uint32_t { 415 INDEX_TONEMAP = 0, 416 INDEX_VIGNETTE = 1, 417 INDEX_DITHER = 2, 418 INDEX_COLOR_CONVERSION = 3, 419 INDEX_COLOR_FRINGE = 4, 420 421 INDEX_BLUR = 8, 422 INDEX_BLOOM = 9, 423 INDEX_FXAA = 10, 424 INDEX_TAA = 11, 425 INDEX_DOF = 12, 426 INDEX_MOTION_BLUR = 13, 427 INDEX_LENS_FLARE = 14, 428 429 INDEX_FACTOR_COUNT = 15, 430 }; 431 /** Enabled flags */ 432 PostProcessEnableFlags enableFlags { 0u }; 433 434 /** Tonemap configuration */ 435 TonemapConfiguration tonemapConfiguration; 436 /** Vignette configuration */ 437 VignetteConfiguration vignetteConfiguration; 438 /** Dither configuration */ 439 DitherConfiguration ditherConfiguration; 440 /** Color conversion configuration */ 441 ColorConversionConfiguration colorConversionConfiguration; 442 443 /** Color fringe configuration */ 444 ColorFringeConfiguration colorFringeConfiguration; 445 446 /** Bloom configuration */ 447 BloomConfiguration bloomConfiguration; 448 /** Blur configuration */ 449 BlurConfiguration blurConfiguration; 450 451 /** Fxaa antialiasing configuration */ 452 FxaaConfiguration fxaaConfiguration; 453 /** Taa antialiasing configuration */ 454 TaaConfiguration taaConfiguration; 455 456 /** Depth of field configuration */ 457 DofConfiguration dofConfiguration; 458 459 /** Motion blur configuration */ 460 MotionBlurConfiguration motionBlurConfiguration; 461 462 /** Lens flare configuration */ 463 LensFlareConfiguration lensFlareConfiguration; 464 465 /** User post process factors which are automatically mapped and can be used easily anywhere in the pipeline */ 466 BASE_NS::Math::Vec4 userFactors[PostProcessConstants::USER_GLOBAL_FACTOR_COUNT]; 467 }; 468 469 /** Render post process configuration (must match render_post_process_structs_common.h */ 470 struct RenderPostProcessConfiguration { 471 /* Single uvec4 for flags .x has post process specialization flags */ 472 BASE_NS::Math::UVec4 flags { 0, 0, 0, 0 }; 473 // .x = delta time (ms), .y = tick delta time (ms), .z = tick total time (s), .w = frame index (asuint) 474 BASE_NS::Math::Vec4 renderTimings { 0.0f, 0.0f, 0.0f, 0.0f }; 475 /* All built-in post process factors */ 476 BASE_NS::Math::Vec4 factors[PostProcessConstants::GLOBAL_FACTOR_COUNT]; 477 478 /* All user post process factors */ 479 BASE_NS::Math::Vec4 userFactors[PostProcessConstants::USER_GLOBAL_FACTOR_COUNT]; 480 }; 481 482 /** Default render pod store for shader specialization */ 483 struct ShaderSpecializationRenderPod { 484 /* Max supported specialization constants */ 485 static constexpr uint32_t MAX_SPECIALIZATION_CONSTANT_COUNT { 8u }; 486 /* Constant flags are mapped in order, use constant_id 0, 1.. in shaders. 487 * Do not leave unused constant ids. 488 */ 489 struct ConstantFlags { 490 /** Value */ 491 uint32_t value { 0u }; 492 }; 493 494 /** Count of constants */ 495 uint32_t specializationConstantCount { 0u }; 496 /** Specialization data */ 497 ConstantFlags specializationFlags[MAX_SPECIALIZATION_CONSTANT_COUNT] {}; 498 }; 499 /** @} */ 500 RENDER_END_NAMESPACE() 501 502 #endif // API_RENDER_RENDER_DATA_STORE_RENDER_PODS_H 503