fidelityfx_fsr.frag 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. // SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. //!#version 460 core
  4. #extension GL_ARB_separate_shader_objects : enable
  5. #extension GL_ARB_shading_language_420pack : enable
  6. #extension GL_GOOGLE_include_directive : enable
  7. #extension GL_EXT_shader_explicit_arithmetic_types : require
  8. // FidelityFX Super Resolution Sample
  9. //
  10. // Copyright (c) 2021 Advanced Micro Devices, Inc. All rights reserved.
  11. // Permission is hereby granted, free of charge, to any person obtaining a copy
  12. // of this software and associated documentation files(the "Software"), to deal
  13. // in the Software without restriction, including without limitation the rights
  14. // to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
  15. // copies of the Software, and to permit persons to whom the Software is
  16. // furnished to do so, subject to the following conditions :
  17. // The above copyright notice and this permission notice shall be included in
  18. // all copies or substantial portions of the Software.
  19. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
  22. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  23. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  24. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  25. // THE SOFTWARE.
  26. layout( push_constant ) uniform constants {
  27. uvec4 Const0;
  28. uvec4 Const1;
  29. uvec4 Const2;
  30. uvec4 Const3;
  31. };
  32. layout(set=0,binding=0) uniform sampler2D InputTexture;
  33. #define A_GPU 1
  34. #define A_GLSL 1
  35. #define FSR_RCAS_PASSTHROUGH_ALPHA 1
  36. #ifndef YUZU_USE_FP16
  37. #include "ffx_a.h"
  38. #if USE_EASU
  39. #define FSR_EASU_F 1
  40. AF4 FsrEasuRF(AF2 p) { AF4 res = textureGather(InputTexture, p, 0); return res; }
  41. AF4 FsrEasuGF(AF2 p) { AF4 res = textureGather(InputTexture, p, 1); return res; }
  42. AF4 FsrEasuBF(AF2 p) { AF4 res = textureGather(InputTexture, p, 2); return res; }
  43. #endif
  44. #if USE_RCAS
  45. #define FSR_RCAS_F 1
  46. AF4 FsrRcasLoadF(ASU2 p) { return texelFetch(InputTexture, ASU2(p), 0); }
  47. void FsrRcasInputF(inout AF1 r, inout AF1 g, inout AF1 b) {}
  48. #endif
  49. #else
  50. #define A_HALF
  51. #include "ffx_a.h"
  52. #if USE_EASU
  53. #define FSR_EASU_H 1
  54. AH4 FsrEasuRH(AF2 p) { AH4 res = AH4(textureGather(InputTexture, p, 0)); return res; }
  55. AH4 FsrEasuGH(AF2 p) { AH4 res = AH4(textureGather(InputTexture, p, 1)); return res; }
  56. AH4 FsrEasuBH(AF2 p) { AH4 res = AH4(textureGather(InputTexture, p, 2)); return res; }
  57. #endif
  58. #if USE_RCAS
  59. #define FSR_RCAS_H 1
  60. AH4 FsrRcasLoadH(ASW2 p) { return AH4(texelFetch(InputTexture, ASU2(p), 0)); }
  61. void FsrRcasInputH(inout AH1 r,inout AH1 g,inout AH1 b){}
  62. #endif
  63. #endif
  64. #include "ffx_fsr1.h"
  65. layout (location = 0) in vec2 frag_texcoord;
  66. layout (location = 0) out vec4 frag_color;
  67. void CurrFilter(AU2 pos) {
  68. #if USE_EASU
  69. #ifndef YUZU_USE_FP16
  70. AF3 c;
  71. FsrEasuF(c, pos, Const0, Const1, Const2, Const3);
  72. frag_color = AF4(c, texture(InputTexture, frag_texcoord).a);
  73. #else
  74. AH3 c;
  75. FsrEasuH(c, pos, Const0, Const1, Const2, Const3);
  76. frag_color = AH4(c, texture(InputTexture, frag_texcoord).a);
  77. #endif
  78. #endif
  79. #if USE_RCAS
  80. #ifndef YUZU_USE_FP16
  81. AF4 c;
  82. FsrRcasF(c.r, c.g, c.b, c.a, pos, Const0);
  83. frag_color = c;
  84. #else
  85. AH4 c;
  86. FsrRcasH(c.r, c.g, c.b, c.a, pos, Const0);
  87. frag_color = c;
  88. #endif
  89. #endif
  90. }
  91. void main() {
  92. #if USE_RCAS
  93. CurrFilter(AU2(frag_texcoord * vec2(textureSize(InputTexture, 0))));
  94. #else
  95. CurrFilter(AU2(gl_FragCoord.xy));
  96. #endif
  97. }