fidelityfx_fsr.comp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. layout(set=0,binding=1,rgba16f) uniform image2D OutputTexture;
  34. #define A_GPU 1
  35. #define A_GLSL 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. void CurrFilter(AU2 pos) {
  66. #if USE_BILINEAR
  67. AF2 pp = (AF2(pos) * AF2_AU2(Const0.xy) + AF2_AU2(Const0.zw)) * AF2_AU2(Const1.xy) + AF2(0.5, -0.5) * AF2_AU2(Const1.zw);
  68. imageStore(OutputTexture, ASU2(pos), textureLod(InputTexture, pp, 0.0));
  69. #endif
  70. #if USE_EASU
  71. #ifndef YUZU_USE_FP16
  72. AF3 c;
  73. FsrEasuF(c, pos, Const0, Const1, Const2, Const3);
  74. imageStore(OutputTexture, ASU2(pos), AF4(c, 1));
  75. #else
  76. AH3 c;
  77. FsrEasuH(c, pos, Const0, Const1, Const2, Const3);
  78. imageStore(OutputTexture, ASU2(pos), AH4(c, 1));
  79. #endif
  80. #endif
  81. #if USE_RCAS
  82. #ifndef YUZU_USE_FP16
  83. AF3 c;
  84. FsrRcasF(c.r, c.g, c.b, pos, Const0);
  85. imageStore(OutputTexture, ASU2(pos), AF4(c, 1));
  86. #else
  87. AH3 c;
  88. FsrRcasH(c.r, c.g, c.b, pos, Const0);
  89. imageStore(OutputTexture, ASU2(pos), AH4(c, 1));
  90. #endif
  91. #endif
  92. }
  93. layout(local_size_x=64) in;
  94. void main() {
  95. // Do remapping of local xy in workgroup for a more PS-like swizzle pattern.
  96. AU2 gxy = ARmp8x8(gl_LocalInvocationID.x) + AU2(gl_WorkGroupID.x << 4u, gl_WorkGroupID.y << 4u);
  97. CurrFilter(gxy);
  98. gxy.x += 8u;
  99. CurrFilter(gxy);
  100. gxy.y += 8u;
  101. CurrFilter(gxy);
  102. gxy.x -= 8u;
  103. CurrFilter(gxy);
  104. }