summaryrefslogtreecommitdiff
path: root/src/video_core/host_shaders
diff options
context:
space:
mode:
authorGravatar Marshall Mohror2021-10-16 20:33:58 -0500
committerGravatar Fernando Sahmkow2021-11-16 22:11:31 +0100
commit37cb0377ae30e2139f6fa381d04124e51fcccded (patch)
treea1cd811a61535d8aa8790a9ac0400b0e79976499 /src/video_core/host_shaders
parentTexture Cache: Rescale conversions between depth and color (diff)
downloadyuzu-37cb0377ae30e2139f6fa381d04124e51fcccded.tar.gz
yuzu-37cb0377ae30e2139f6fa381d04124e51fcccded.tar.xz
yuzu-37cb0377ae30e2139f6fa381d04124e51fcccded.zip
vulkan: Implement FidelityFX Super Resolution
Diffstat (limited to 'src/video_core/host_shaders')
-rw-r--r--src/video_core/host_shaders/CMakeLists.txt17
-rw-r--r--src/video_core/host_shaders/fidelityfx_fsr.comp114
-rw-r--r--src/video_core/host_shaders/vulkan_fidelityfx_fsr_easu.comp13
-rw-r--r--src/video_core/host_shaders/vulkan_fidelityfx_fsr_rcas.comp13
4 files changed, 155 insertions, 2 deletions
diff --git a/src/video_core/host_shaders/CMakeLists.txt b/src/video_core/host_shaders/CMakeLists.txt
index 664d6ce5d..32e2ab500 100644
--- a/src/video_core/host_shaders/CMakeLists.txt
+++ b/src/video_core/host_shaders/CMakeLists.txt
@@ -1,3 +1,11 @@
1set(FIDELITYFX_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/externals/FidelityFX-FSR/ffx-fsr)
2
3set(GLSL_INCLUDES
4 fidelityfx_fsr.comp
5 ${FIDELITYFX_INCLUDE_DIR}/ffx_a.h
6 ${FIDELITYFX_INCLUDE_DIR}/ffx_fsr1.h
7)
8
1set(SHADER_FILES 9set(SHADER_FILES
2 astc_decoder.comp 10 astc_decoder.comp
3 block_linear_unswizzle_2d.comp 11 block_linear_unswizzle_2d.comp
@@ -13,6 +21,8 @@ set(SHADER_FILES
13 present_bicubic.frag 21 present_bicubic.frag
14 vulkan_blit_color_float.frag 22 vulkan_blit_color_float.frag
15 vulkan_blit_depth_stencil.frag 23 vulkan_blit_depth_stencil.frag
24 vulkan_fidelityfx_fsr_easu.comp
25 vulkan_fidelityfx_fsr_rcas.comp
16 vulkan_present.frag 26 vulkan_present.frag
17 vulkan_present.vert 27 vulkan_present.vert
18 vulkan_quad_indexed.comp 28 vulkan_quad_indexed.comp
@@ -78,7 +88,7 @@ foreach(FILENAME IN ITEMS ${SHADER_FILES})
78 OUTPUT 88 OUTPUT
79 ${SPIRV_HEADER_FILE} 89 ${SPIRV_HEADER_FILE}
80 COMMAND 90 COMMAND
81 ${GLSLANGVALIDATOR} -V ${QUIET_FLAG} ${GLSL_FLAGS} --variable-name ${SPIRV_VARIABLE_NAME} -o ${SPIRV_HEADER_FILE} ${SOURCE_FILE} 91 ${GLSLANGVALIDATOR} -V ${QUIET_FLAG} -I"${FIDELITYFX_INCLUDE_DIR}" ${GLSL_FLAGS} --variable-name ${SPIRV_VARIABLE_NAME} -o ${SPIRV_HEADER_FILE} ${SOURCE_FILE}
82 MAIN_DEPENDENCY 92 MAIN_DEPENDENCY
83 ${SOURCE_FILE} 93 ${SOURCE_FILE}
84 ) 94 )
@@ -86,9 +96,12 @@ foreach(FILENAME IN ITEMS ${SHADER_FILES})
86 endif() 96 endif()
87endforeach() 97endforeach()
88 98
99set(SHADER_SOURCES ${SHADER_FILES})
100list(APPEND SHADER_SOURCES ${GLSL_INCLUDES})
101
89add_custom_target(host_shaders 102add_custom_target(host_shaders
90 DEPENDS 103 DEPENDS
91 ${SHADER_HEADERS} 104 ${SHADER_HEADERS}
92 SOURCES 105 SOURCES
93 ${SHADER_FILES} 106 ${SHADER_SOURCES}
94) 107)
diff --git a/src/video_core/host_shaders/fidelityfx_fsr.comp b/src/video_core/host_shaders/fidelityfx_fsr.comp
new file mode 100644
index 000000000..cbb601580
--- /dev/null
+++ b/src/video_core/host_shaders/fidelityfx_fsr.comp
@@ -0,0 +1,114 @@
1// Copyright 2021 yuzu Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5//!#version 460 core
6#extension GL_ARB_separate_shader_objects : enable
7#extension GL_ARB_shading_language_420pack : enable
8#extension GL_GOOGLE_include_directive : enable
9#extension GL_EXT_shader_explicit_arithmetic_types : require
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
30layout( push_constant ) uniform constants {
31 u32vec2 input_size;
32};
33
34uvec4 Const0;
35uvec4 Const1;
36uvec4 Const2;
37uvec4 Const3;
38
39#define A_GPU 1
40#define A_GLSL 1
41#define A_HALF
42
43#include "ffx_a.h"
44
45f16vec4 LinearToSRGB(f16vec4 linear) {
46 bvec4 selector = greaterThan(linear, f16vec4(0.00313066844250063));
47 f16vec4 low = linear * float16_t(12.92);
48 f16vec4 high = float16_t(1.055) * pow(linear, f16vec4(1 / 2.4)) - float16_t(0.055);
49 return mix(low, high, selector);
50}
51
52f16vec4 SRGBToLinear(f16vec4 srgb) {
53 bvec4 selector = greaterThan(srgb, f16vec4(0.0404482362771082));
54 f16vec4 low = srgb * float16_t(1.0 / 12.92);
55 f16vec4 high = pow((srgb + float16_t(0.055)) * float16_t(1.0 / 1.055), f16vec4(2.4));
56 return mix(low, high, selector);
57}
58
59#if USE_EASU
60 #define FSR_EASU_H 1
61 f16vec4 FsrEasuRH(vec2 p) { f16vec4 res = f16vec4(textureGather(InputTexture, p, 0)); return res; }
62 f16vec4 FsrEasuGH(vec2 p) { f16vec4 res = f16vec4(textureGather(InputTexture, p, 1)); return res; }
63 f16vec4 FsrEasuBH(vec2 p) { f16vec4 res = f16vec4(textureGather(InputTexture, p, 2)); return res; }
64#endif
65#if USE_RCAS
66 #define FSR_RCAS_H 1
67 f16vec4 FsrRcasLoadH(ASW2 p) { return f16vec4(texelFetch(InputTexture, ASU2(p), 0)); }
68 void FsrRcasInputH(inout float16_t r, inout float16_t g, inout float16_t b) {}
69#endif
70
71#include "ffx_fsr1.h"
72
73void CurrFilter(u32vec2 pos) {
74 // For debugging
75#if USE_BILINEAR
76 vec2 pp = (vec2(pos) * vec2_AU2(Const0.xy) + vec2_AU2(Const0.zw)) * vec2_AU2(Const1.xy) + vec2(0.5, -0.5) * vec2_AU2(Const1.zw);
77 imageStore(OutputTexture, ivec2(pos), textureLod(InputTexture, pp, 0.0));
78#endif
79#if USE_EASU
80 f16vec3 c;
81 FsrEasuH(c, pos, Const0, Const1, Const2, Const3);
82 imageStore(OutputTexture, ivec2(pos), f16vec4(c, 1));
83#endif
84#if USE_RCAS
85 f16vec3 c;
86 FsrRcasH(c.r, c.g, c.b, pos, Const0);
87 imageStore(OutputTexture, ivec2(pos), f16vec4(c, 1));
88#endif
89
90}
91
92layout(local_size_x=64) in;
93void main() {
94
95#if USE_EASU || USE_BILINEAR
96 vec2 ires = vec2(input_size);
97 vec2 tres = textureSize(InputTexture, 0);
98 vec2 ores = imageSize(OutputTexture);
99 FsrEasuCon(Const0, Const1, Const2, Const3, ires.x, ires.y, tres.x, tres.y, ores.x, ores.y);
100#endif
101#if USE_RCAS
102 FsrRcasCon(Const0, 0.25f);
103#endif
104
105 // Do remapping of local xy in workgroup for a more PS-like swizzle pattern.
106 AU2 gxy = ARmp8x8(gl_LocalInvocationID.x) + AU2(gl_WorkGroupID.x << 4u, gl_WorkGroupID.y << 4u);
107 CurrFilter(gxy);
108 gxy.x += 8u;
109 CurrFilter(gxy);
110 gxy.y += 8u;
111 CurrFilter(gxy);
112 gxy.x -= 8u;
113 CurrFilter(gxy);
114}
diff --git a/src/video_core/host_shaders/vulkan_fidelityfx_fsr_easu.comp b/src/video_core/host_shaders/vulkan_fidelityfx_fsr_easu.comp
new file mode 100644
index 000000000..6525eeeb5
--- /dev/null
+++ b/src/video_core/host_shaders/vulkan_fidelityfx_fsr_easu.comp
@@ -0,0 +1,13 @@
1// Copyright 2021 yuzu Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#version 460 core
6#extension GL_GOOGLE_include_directive : enable
7
8layout(set=0,binding=0) uniform sampler2D InputTexture;
9layout(set=0,binding=1,rgba16f) uniform image2D OutputTexture;
10
11#define USE_EASU 1
12
13#include "fidelityfx_fsr.comp"
diff --git a/src/video_core/host_shaders/vulkan_fidelityfx_fsr_rcas.comp b/src/video_core/host_shaders/vulkan_fidelityfx_fsr_rcas.comp
new file mode 100644
index 000000000..9463ed842
--- /dev/null
+++ b/src/video_core/host_shaders/vulkan_fidelityfx_fsr_rcas.comp
@@ -0,0 +1,13 @@
1// Copyright 2021 yuzu Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#version 460 core
6#extension GL_GOOGLE_include_directive : enable
7
8layout(set=0,binding=0) uniform sampler2D InputTexture;
9layout(set=0,binding=1,rgba16f) uniform image2D OutputTexture;
10
11#define USE_RCAS 1
12
13#include "fidelityfx_fsr.comp"