diff --git a/client/renderers/EGL/filter_ffx_fsr1.c b/client/renderers/EGL/filter_ffx_fsr1.c index d67b4250..2890880e 100644 --- a/client/renderers/EGL/filter_ffx_fsr1.c +++ b/client/renderers/EGL/filter_ffx_fsr1.c @@ -21,9 +21,12 @@ #include "filter.h" #include "framebuffer.h" +#include "common/array.h" +#include "common/countedbuffer.h" #include "common/debug.h" #include "common/option.h" #include "cimgui.h" +#include "ffx.h" #include "basic.vert.h" #include "ffx_fsr1_easu.frag.h" @@ -36,7 +39,7 @@ typedef struct EGL_FilterFFXFSR1 EGL_Shader * easu, * rcas; bool enable, active; float sharpness; - EGL_Uniform easuUniform, rcasUniform; + EGL_Uniform easuUniform[2], rcasUniform; enum EGL_PixelFormat pixFmt; unsigned int width, height; @@ -73,6 +76,11 @@ static void egl_filterFFXFSR1EarlyInit(void) option_register(options); } +static void rcasUpdateUniform(EGL_FilterFFXFSR1 * this) +{ + ffxFsrRcasConst(this->rcasUniform.ui, 2.0f - this->sharpness * 2.0f); +} + static bool egl_filterFFXFSR1Init(EGL_Filter ** filter) { EGL_FilterFFXFSR1 * this = calloc(1, sizeof(*this)); @@ -115,15 +123,18 @@ static bool egl_filterFFXFSR1Init(EGL_Filter ** filter) this->enable = option_get_bool("eglFilter", "ffxFSR"); - this->easuUniform.type = EGL_UNIFORM_TYPE_2UI; - this->easuUniform.location = + this->easuUniform[0].type = EGL_UNIFORM_TYPE_4UIV; + this->easuUniform[0].location = + egl_shaderGetUniform(this->easu, "uConsts"); + this->easuUniform[0].v = countedBufferNew(16 * sizeof(GLuint)); + this->easuUniform[1].type = EGL_UNIFORM_TYPE_2F; + this->easuUniform[1].location = egl_shaderGetUniform(this->easu, "uOutRes"); - this->rcasUniform.type = EGL_UNIFORM_TYPE_1F; - this->rcasUniform.location = - egl_shaderGetUniform(this->rcas, "uSharpness"); + this->rcasUniform.type = EGL_UNIFORM_TYPE_4UI; + this->rcasUniform.location = egl_shaderGetUniform(this->rcas, "uConsts"); this->sharpness = option_get_float("eglFilter", "ffxFSRSharpness"); - this->rcasUniform.f[0] = 2.0f - this->sharpness * 2.0f; + rcasUpdateUniform(this); if (!egl_framebufferInit(&this->easuFb)) { @@ -269,7 +280,7 @@ static bool egl_filterFFXFSR1ImguiConfig(EGL_Filter * filter) } this->sharpness = sharpness; - this->rcasUniform.f[0] = 2.0f - sharpness * 2.0f; + rcasUpdateUniform(this); redraw = true; } @@ -313,6 +324,11 @@ static bool egl_filterFFXFSR1Setup(EGL_Filter * filter, this->sizeChanged = false; this->pixFmt = pixFmt; this->prepared = false; + + this->easuUniform[1].f[0] = this->width; + this->easuUniform[1].f[1] = this->height; + ffxFsrEasuConst((uint32_t *) this->easuUniform[0].v->data, this->inWidth, this->inHeight, + this->inWidth, this->inHeight, this->width, this->height); return true; } @@ -334,10 +350,7 @@ static bool egl_filterFFXFSR1Prepare(EGL_Filter * filter) if (this->prepared) return true; - this->easuUniform.ui[0] = this->width; - this->easuUniform.ui[1] = this->height; - - egl_shaderSetUniforms(this->easu, &this->easuUniform, 1); + egl_shaderSetUniforms(this->easu, this->easuUniform, ARRAY_LENGTH(this->easuUniform)); egl_shaderSetUniforms(this->rcas, &this->rcasUniform, 1); this->prepared = true; diff --git a/client/renderers/EGL/shader/ffx_fsr1_easu.frag b/client/renderers/EGL/shader/ffx_fsr1_easu.frag index 6fee05e9..d9e1ac14 100644 --- a/client/renderers/EGL/shader/ffx_fsr1_easu.frag +++ b/client/renderers/EGL/shader/ffx_fsr1_easu.frag @@ -7,7 +7,8 @@ in vec2 fragCoord; out vec4 fragColor; uniform sampler2D texture; -uniform uvec2 uOutRes; +uniform vec2 uOutRes; +uniform uvec4 uConsts[4]; #define A_GPU 1 #define A_GLSL 1 @@ -36,22 +37,8 @@ AF4 FsrEasuBF(AF2 p){return AF4(_textureGather(texture, p, 2));} void main() { - vec2 inRes = vec2(textureSize(texture, 0)); - vec2 outRes = vec2(uOutRes); - - AU4 con0, con1, con2, con3; - FsrEasuCon( - con0, - con1, - con2, - con3, - inRes.x , inRes.y, - inRes.x , inRes.y, - outRes.x, outRes.y - ); - vec3 color; - uvec2 point = uvec2(fragCoord * outRes); - FsrEasuF(color, point, con0, con1, con2, con3); - fragColor = vec4(color.xyz, 1); + uvec2 point = uvec2(fragCoord * uOutRes); + FsrEasuF(color, point, uConsts[0], uConsts[1], uConsts[2], uConsts[3]); + fragColor = vec4(color.rgb, 1); } diff --git a/client/renderers/EGL/shader/ffx_fsr1_rcas.frag b/client/renderers/EGL/shader/ffx_fsr1_rcas.frag index 0c59823a..61f8f2f1 100644 --- a/client/renderers/EGL/shader/ffx_fsr1_rcas.frag +++ b/client/renderers/EGL/shader/ffx_fsr1_rcas.frag @@ -7,7 +7,7 @@ in vec2 fragCoord; out vec4 fragColor; uniform sampler2D texture; -uniform float uSharpness; +uniform uvec4 uConsts; #define A_GPU 1 #define A_GLSL 1 @@ -27,9 +27,6 @@ void main() vec2 inRes = vec2(textureSize(texture, 0)); uvec2 point = uvec2(fragCoord * (inRes + 0.5f)); - uvec4 const0; - FsrRcasCon(const0, uSharpness); - - FsrRcasF(fragColor.r, fragColor.g, fragColor.b, point, const0); + FsrRcasF(fragColor.r, fragColor.g, fragColor.b, point, uConsts); fragColor.a = 1.0f; }