0.2.0-dev Download ZIP
134 lines ·4.1 KB Raw
| 1 | // This file is part of the FidelityFX SDK. |
| 2 | // |
| 3 | // Copyright (c) 2022-2023 Advanced Micro Devices, Inc. All rights reserved. |
| 4 | // |
| 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy |
| 6 | // of this software and associated documentation files (the "Software"), to deal |
| 7 | // in the Software without restriction, including without limitation the rights |
| 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 9 | // copies of the Software, and to permit persons to whom the Software is |
| 10 | // furnished to do so, subject to the following conditions: |
| 11 | // The above copyright notice and this permission notice shall be included in |
| 12 | // all copies or substantial portions of the Software. |
| 13 | // |
| 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 20 | // THE SOFTWARE. |
| 21 | |
| 22 | //#version 450 |
| 23 | |
| 24 | #extension GL_GOOGLE_include_directive : require |
| 25 | #extension GL_EXT_samplerless_texture_functions : require |
| 26 | |
| 27 | #define FSR2_BIND_SRV_INPUT_COLOR 0 |
| 28 | #define FSR2_BIND_UAV_SPD_GLOBAL_ATOMIC 1 |
| 29 | #define FSR2_BIND_UAV_EXPOSURE_MIP_LUMA_CHANGE 2 |
| 30 | #define FSR2_BIND_UAV_EXPOSURE_MIP_5 3 |
| 31 | #define FSR2_BIND_UAV_AUTO_EXPOSURE 4 |
| 32 | #define FSR2_BIND_CB_FSR2 5 |
| 33 | #define FSR2_BIND_CB_SPD 6 |
| 34 | |
| 35 | #include "ffx_fsr2_callbacks_glsl.h" |
| 36 | #include "ffx_fsr2_common.h" |
| 37 | |
| 38 | #if defined(FSR2_BIND_CB_SPD) |
| 39 | layout (set = 1, binding = FSR2_BIND_CB_SPD, std140) uniform cbSPD_t |
| 40 | { |
| 41 | uint mips; |
| 42 | uint numWorkGroups; |
| 43 | uvec2 workGroupOffset; |
| 44 | uvec2 renderSize; |
| 45 | } cbSPD; |
| 46 | |
| 47 | uint MipCount() |
| 48 | { |
| 49 | return cbSPD.mips; |
| 50 | } |
| 51 | |
| 52 | uint NumWorkGroups() |
| 53 | { |
| 54 | return cbSPD.numWorkGroups; |
| 55 | } |
| 56 | |
| 57 | uvec2 WorkGroupOffset() |
| 58 | { |
| 59 | return cbSPD.workGroupOffset; |
| 60 | } |
| 61 | |
| 62 | uvec2 SPD_RenderSize() |
| 63 | { |
| 64 | return cbSPD.renderSize; |
| 65 | } |
| 66 | #endif |
| 67 | |
| 68 | vec2 SPD_LoadExposureBuffer() |
| 69 | { |
| 70 | return imageLoad(rw_auto_exposure, ivec2(0,0)).xy; |
| 71 | } |
| 72 | |
| 73 | void SPD_SetExposureBuffer(vec2 value) |
| 74 | { |
| 75 | imageStore(rw_auto_exposure, ivec2(0,0), vec4(value, 0.0f, 0.0f)); |
| 76 | } |
| 77 | |
| 78 | vec4 SPD_LoadMipmap5(ivec2 iPxPos) |
| 79 | { |
| 80 | return vec4(imageLoad(rw_img_mip_5, iPxPos).x, 0.0f, 0.0f, 0.0f); |
| 81 | } |
| 82 | |
| 83 | void SPD_SetMipmap(ivec2 iPxPos, uint slice, float value) |
| 84 | { |
| 85 | switch (slice) |
| 86 | { |
| 87 | case FFX_FSR2_SHADING_CHANGE_MIP_LEVEL: |
| 88 | imageStore(rw_img_mip_shading_change, iPxPos, vec4(value, 0.0f, 0.0f, 0.0f)); |
| 89 | break; |
| 90 | case 5: |
| 91 | imageStore(rw_img_mip_5, iPxPos, vec4(value, 0.0f, 0.0f, 0.0f)); |
| 92 | break; |
| 93 | default: |
| 94 | |
| 95 | // avoid flattened side effect |
| 96 | #if defined(FSR2_BIND_UAV_EXPOSURE_MIP_LUMA_CHANGE) |
| 97 | imageStore(rw_img_mip_shading_change, iPxPos, vec4(imageLoad(rw_img_mip_shading_change, iPxPos).x, 0.0f, 0.0f, 0.0f)); |
| 98 | #elif defined(FSR2_BIND_UAV_EXPOSURE_MIP_5) |
| 99 | imageStore(rw_img_mip_5, iPxPos, vec4(imageLoad(rw_img_mip_5, iPxPos).x, 0.0f, 0.0f, 0.0f)); |
| 100 | #endif |
| 101 | break; |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | void SPD_IncreaseAtomicCounter(inout uint spdCounter) |
| 106 | { |
| 107 | spdCounter = imageAtomicAdd(rw_spd_global_atomic, ivec2(0,0), 1); |
| 108 | } |
| 109 | |
| 110 | void SPD_ResetAtomicCounter() |
| 111 | { |
| 112 | imageStore(rw_spd_global_atomic, ivec2(0,0), uvec4(0)); |
| 113 | } |
| 114 | |
| 115 | #include "ffx_fsr2_compute_luminance_pyramid.h" |
| 116 | |
| 117 | #ifndef FFX_FSR2_THREAD_GROUP_WIDTH |
| 118 | #define FFX_FSR2_THREAD_GROUP_WIDTH 256 |
| 119 | #endif // #ifndef FFX_FSR2_THREAD_GROUP_WIDTH |
| 120 | #ifndef FFX_FSR2_THREAD_GROUP_HEIGHT |
| 121 | #define FFX_FSR2_THREAD_GROUP_HEIGHT 1 |
| 122 | #endif // #ifndef FFX_FSR2_THREAD_GROUP_HEIGHT |
| 123 | #ifndef FFX_FSR2_THREAD_GROUP_DEPTH |
| 124 | #define FFX_FSR2_THREAD_GROUP_DEPTH 1 |
| 125 | #endif // #ifndef FFX_FSR2_THREAD_GROUP_DEPTH |
| 126 | #ifndef FFX_FSR2_NUM_THREADS |
| 127 | #define FFX_FSR2_NUM_THREADS layout (local_size_x = FFX_FSR2_THREAD_GROUP_WIDTH, local_size_y = FFX_FSR2_THREAD_GROUP_HEIGHT, local_size_z = FFX_FSR2_THREAD_GROUP_DEPTH) in; |
| 128 | #endif // #ifndef FFX_FSR2_NUM_THREADS |
| 129 | |
| 130 | FFX_FSR2_NUM_THREADS |
| 131 | void main() |
| 132 | { |
| 133 | ComputeAutoExposure(gl_WorkGroupID.xyz, gl_LocalInvocationIndex); |
| 134 | } |