diff options
| author | 2023-01-27 19:28:35 -0500 | |
|---|---|---|
| committer | 2023-01-27 19:28:35 -0500 | |
| commit | 6fa86989f10ef9f87701147e4b4b426f309edac4 (patch) | |
| tree | e4b3c203e4a2349ec8f72e5f5d162eab2a1d9ecd /src/video_core/host_shaders | |
| parent | Merge pull request #9666 from liamwhite/wait-for-me (diff) | |
| parent | video_core/opengl: Add FSR upscaling filter to the OpenGL renderer (diff) | |
| download | yuzu-6fa86989f10ef9f87701147e4b4b426f309edac4.tar.gz yuzu-6fa86989f10ef9f87701147e4b4b426f309edac4.tar.xz yuzu-6fa86989f10ef9f87701147e4b4b426f309edac4.zip | |
Merge pull request #9539 from Wollnashorn/opengl-fsr
video_core/opengl: Added FSR upscaling filter to the OpenGL renderer
Diffstat (limited to 'src/video_core/host_shaders')
4 files changed, 154 insertions, 2 deletions
diff --git a/src/video_core/host_shaders/CMakeLists.txt b/src/video_core/host_shaders/CMakeLists.txt index e968ae220..dad7b07d4 100644 --- a/src/video_core/host_shaders/CMakeLists.txt +++ b/src/video_core/host_shaders/CMakeLists.txt | |||
| @@ -3,12 +3,16 @@ | |||
| 3 | 3 | ||
| 4 | set(FIDELITYFX_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/externals/FidelityFX-FSR/ffx-fsr) | 4 | set(FIDELITYFX_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/externals/FidelityFX-FSR/ffx-fsr) |
| 5 | 5 | ||
| 6 | set(GLSL_INCLUDES | 6 | set(FIDELITYFX_FILES |
| 7 | fidelityfx_fsr.comp | ||
| 8 | ${FIDELITYFX_INCLUDE_DIR}/ffx_a.h | 7 | ${FIDELITYFX_INCLUDE_DIR}/ffx_a.h |
| 9 | ${FIDELITYFX_INCLUDE_DIR}/ffx_fsr1.h | 8 | ${FIDELITYFX_INCLUDE_DIR}/ffx_fsr1.h |
| 10 | ) | 9 | ) |
| 11 | 10 | ||
| 11 | set(GLSL_INCLUDES | ||
| 12 | fidelityfx_fsr.comp | ||
| 13 | ${FIDELITYFX_FILES} | ||
| 14 | ) | ||
| 15 | |||
| 12 | set(SHADER_FILES | 16 | set(SHADER_FILES |
| 13 | astc_decoder.comp | 17 | astc_decoder.comp |
| 14 | blit_color_float.frag | 18 | blit_color_float.frag |
| @@ -24,6 +28,9 @@ set(SHADER_FILES | |||
| 24 | fxaa.vert | 28 | fxaa.vert |
| 25 | opengl_convert_s8d24.comp | 29 | opengl_convert_s8d24.comp |
| 26 | opengl_copy_bc4.comp | 30 | opengl_copy_bc4.comp |
| 31 | opengl_fidelityfx_fsr.frag | ||
| 32 | opengl_fidelityfx_fsr_easu.frag | ||
| 33 | opengl_fidelityfx_fsr_rcas.frag | ||
| 27 | opengl_present.frag | 34 | opengl_present.frag |
| 28 | opengl_present.vert | 35 | opengl_present.vert |
| 29 | opengl_present_scaleforce.frag | 36 | opengl_present_scaleforce.frag |
| @@ -118,6 +125,25 @@ foreach(FILENAME IN ITEMS ${SHADER_FILES}) | |||
| 118 | endif() | 125 | endif() |
| 119 | endforeach() | 126 | endforeach() |
| 120 | 127 | ||
| 128 | foreach(FILEPATH IN ITEMS ${FIDELITYFX_FILES}) | ||
| 129 | get_filename_component(FILENAME ${FILEPATH} NAME) | ||
| 130 | string(REPLACE "." "_" HEADER_NAME ${FILENAME}) | ||
| 131 | set(SOURCE_FILE ${FILEPATH}) | ||
| 132 | set(SOURCE_HEADER_FILE ${SHADER_DIR}/${HEADER_NAME}.h) | ||
| 133 | add_custom_command( | ||
| 134 | OUTPUT | ||
| 135 | ${SOURCE_HEADER_FILE} | ||
| 136 | COMMAND | ||
| 137 | ${CMAKE_COMMAND} -P ${HEADER_GENERATOR} ${SOURCE_FILE} ${SOURCE_HEADER_FILE} ${INPUT_FILE} | ||
| 138 | MAIN_DEPENDENCY | ||
| 139 | ${SOURCE_FILE} | ||
| 140 | DEPENDS | ||
| 141 | ${INPUT_FILE} | ||
| 142 | # HEADER_GENERATOR should be included here but msbuild seems to assume it's always modified | ||
| 143 | ) | ||
| 144 | set(SHADER_HEADERS ${SHADER_HEADERS} ${SOURCE_HEADER_FILE}) | ||
| 145 | endforeach() | ||
| 146 | |||
| 121 | set(SHADER_SOURCES ${SHADER_FILES}) | 147 | set(SHADER_SOURCES ${SHADER_FILES}) |
| 122 | list(APPEND SHADER_SOURCES ${GLSL_INCLUDES}) | 148 | list(APPEND SHADER_SOURCES ${GLSL_INCLUDES}) |
| 123 | 149 | ||
diff --git a/src/video_core/host_shaders/opengl_fidelityfx_fsr.frag b/src/video_core/host_shaders/opengl_fidelityfx_fsr.frag new file mode 100644 index 000000000..16d22f58e --- /dev/null +++ b/src/video_core/host_shaders/opengl_fidelityfx_fsr.frag | |||
| @@ -0,0 +1,108 @@ | |||
| 1 | // SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project | ||
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later | ||
| 3 | |||
| 4 | //!#version 460 core | ||
| 5 | #extension GL_ARB_separate_shader_objects : enable | ||
| 6 | #extension GL_ARB_shading_language_420pack : enable | ||
| 7 | |||
| 8 | #extension GL_AMD_gpu_shader_half_float : enable | ||
| 9 | #extension GL_NV_gpu_shader5 : enable | ||
| 10 | |||
| 11 | // FidelityFX Super Resolution Sample | ||
| 12 | // | ||
| 13 | // Copyright (c) 2021 Advanced Micro Devices, Inc. All rights reserved. | ||
| 14 | // Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| 15 | // of this software and associated documentation files(the "Software"), to deal | ||
| 16 | // in the Software without restriction, including without limitation the rights | ||
| 17 | // to use, copy, modify, merge, publish, distribute, sublicense, and / or sell | ||
| 18 | // copies of the Software, and to permit persons to whom the Software is | ||
| 19 | // furnished to do so, subject to the following conditions : | ||
| 20 | // The above copyright notice and this permission notice shall be included in | ||
| 21 | // all copies or substantial portions of the Software. | ||
| 22 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| 23 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| 24 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE | ||
| 25 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| 26 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| 27 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
| 28 | // THE SOFTWARE. | ||
| 29 | |||
| 30 | layout (location = 0) uniform uvec4 constants[4]; | ||
| 31 | |||
| 32 | #define A_GPU 1 | ||
| 33 | #define A_GLSL 1 | ||
| 34 | |||
| 35 | #ifdef YUZU_USE_FP16 | ||
| 36 | #define A_HALF | ||
| 37 | #endif | ||
| 38 | #include "ffx_a.h" | ||
| 39 | |||
| 40 | #ifndef YUZU_USE_FP16 | ||
| 41 | layout (binding=0) uniform sampler2D InputTexture; | ||
| 42 | #if USE_EASU | ||
| 43 | #define FSR_EASU_F 1 | ||
| 44 | AF4 FsrEasuRF(AF2 p) { AF4 res = textureGather(InputTexture, p, 0); return res; } | ||
| 45 | AF4 FsrEasuGF(AF2 p) { AF4 res = textureGather(InputTexture, p, 1); return res; } | ||
| 46 | AF4 FsrEasuBF(AF2 p) { AF4 res = textureGather(InputTexture, p, 2); return res; } | ||
| 47 | #endif | ||
| 48 | #if USE_RCAS | ||
| 49 | #define FSR_RCAS_F | ||
| 50 | AF4 FsrRcasLoadF(ASU2 p) { return texelFetch(InputTexture, ASU2(p), 0); } | ||
| 51 | void FsrRcasInputF(inout AF1 r, inout AF1 g, inout AF1 b) {} | ||
| 52 | #endif | ||
| 53 | #else | ||
| 54 | layout (binding=0) uniform sampler2D InputTexture; | ||
| 55 | #if USE_EASU | ||
| 56 | #define FSR_EASU_H 1 | ||
| 57 | AH4 FsrEasuRH(AF2 p) { AH4 res = AH4(textureGather(InputTexture, p, 0)); return res; } | ||
| 58 | AH4 FsrEasuGH(AF2 p) { AH4 res = AH4(textureGather(InputTexture, p, 1)); return res; } | ||
| 59 | AH4 FsrEasuBH(AF2 p) { AH4 res = AH4(textureGather(InputTexture, p, 2)); return res; } | ||
| 60 | #endif | ||
| 61 | #if USE_RCAS | ||
| 62 | #define FSR_RCAS_H | ||
| 63 | AH4 FsrRcasLoadH(ASW2 p) { return AH4(texelFetch(InputTexture, ASU2(p), 0)); } | ||
| 64 | void FsrRcasInputH(inout AH1 r,inout AH1 g,inout AH1 b){} | ||
| 65 | #endif | ||
| 66 | #endif | ||
| 67 | |||
| 68 | #include "ffx_fsr1.h" | ||
| 69 | |||
| 70 | #if USE_RCAS | ||
| 71 | layout(location = 0) in vec2 frag_texcoord; | ||
| 72 | #endif | ||
| 73 | layout (location = 0) out vec4 frag_color; | ||
| 74 | |||
| 75 | void CurrFilter(AU2 pos) | ||
| 76 | { | ||
| 77 | #if USE_EASU | ||
| 78 | #ifndef YUZU_USE_FP16 | ||
| 79 | AF3 c; | ||
| 80 | FsrEasuF(c, pos, constants[0], constants[1], constants[2], constants[3]); | ||
| 81 | frag_color = AF4(c, 1.0); | ||
| 82 | #else | ||
| 83 | AH3 c; | ||
| 84 | FsrEasuH(c, pos, constants[0], constants[1], constants[2], constants[3]); | ||
| 85 | frag_color = AH4(c, 1.0); | ||
| 86 | #endif | ||
| 87 | #endif | ||
| 88 | #if USE_RCAS | ||
| 89 | #ifndef YUZU_USE_FP16 | ||
| 90 | AF3 c; | ||
| 91 | FsrRcasF(c.r, c.g, c.b, pos, constants[0]); | ||
| 92 | frag_color = AF4(c, 1.0); | ||
| 93 | #else | ||
| 94 | AH3 c; | ||
| 95 | FsrRcasH(c.r, c.g, c.b, pos, constants[0]); | ||
| 96 | frag_color = AH4(c, 1.0); | ||
| 97 | #endif | ||
| 98 | #endif | ||
| 99 | } | ||
| 100 | |||
| 101 | void main() | ||
| 102 | { | ||
| 103 | #if USE_RCAS | ||
| 104 | CurrFilter(AU2(frag_texcoord * vec2(textureSize(InputTexture, 0)))); | ||
| 105 | #else | ||
| 106 | CurrFilter(AU2(gl_FragCoord.xy)); | ||
| 107 | #endif | ||
| 108 | } | ||
diff --git a/src/video_core/host_shaders/opengl_fidelityfx_fsr_easu.frag b/src/video_core/host_shaders/opengl_fidelityfx_fsr_easu.frag new file mode 100644 index 000000000..d39f80ac1 --- /dev/null +++ b/src/video_core/host_shaders/opengl_fidelityfx_fsr_easu.frag | |||
| @@ -0,0 +1,9 @@ | |||
| 1 | // SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project | ||
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later | ||
| 3 | |||
| 4 | #version 460 core | ||
| 5 | #extension GL_GOOGLE_include_directive : enable | ||
| 6 | |||
| 7 | #define USE_EASU 1 | ||
| 8 | |||
| 9 | #include "opengl_fidelityfx_fsr.frag" | ||
diff --git a/src/video_core/host_shaders/opengl_fidelityfx_fsr_rcas.frag b/src/video_core/host_shaders/opengl_fidelityfx_fsr_rcas.frag new file mode 100644 index 000000000..cfa78ddc7 --- /dev/null +++ b/src/video_core/host_shaders/opengl_fidelityfx_fsr_rcas.frag | |||
| @@ -0,0 +1,9 @@ | |||
| 1 | // SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project | ||
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later | ||
| 3 | |||
| 4 | #version 460 core | ||
| 5 | #extension GL_GOOGLE_include_directive : enable | ||
| 6 | |||
| 7 | #define USE_RCAS 1 | ||
| 8 | |||
| 9 | #include "opengl_fidelityfx_fsr.frag" | ||