mirror of
https://github.com/gnif/LookingGlass.git
synced 2024-11-10 08:38:20 +00:00
[client] egl: precompute CAS filter constants on CPU
This commit is contained in:
parent
3a1a9121eb
commit
8b2db071d8
@ -21,9 +21,11 @@
|
|||||||
#include "filter.h"
|
#include "filter.h"
|
||||||
#include "framebuffer.h"
|
#include "framebuffer.h"
|
||||||
|
|
||||||
|
#include "common/countedbuffer.h"
|
||||||
#include "common/debug.h"
|
#include "common/debug.h"
|
||||||
#include "common/option.h"
|
#include "common/option.h"
|
||||||
#include "cimgui.h"
|
#include "cimgui.h"
|
||||||
|
#include "ffx.h"
|
||||||
|
|
||||||
#include "basic.vert.h"
|
#include "basic.vert.h"
|
||||||
#include "ffx_cas.frag.h"
|
#include "ffx_cas.frag.h"
|
||||||
@ -34,10 +36,11 @@ typedef struct EGL_FilterFFXCAS
|
|||||||
|
|
||||||
EGL_Shader * shader;
|
EGL_Shader * shader;
|
||||||
bool enable;
|
bool enable;
|
||||||
EGL_Uniform uniform;
|
|
||||||
|
|
||||||
enum EGL_PixelFormat pixFmt;
|
enum EGL_PixelFormat pixFmt;
|
||||||
unsigned int width, height;
|
unsigned int width, height;
|
||||||
|
float sharpness;
|
||||||
|
CountedBuffer * consts;
|
||||||
bool prepared;
|
bool prepared;
|
||||||
|
|
||||||
EGL_Framebuffer * fb;
|
EGL_Framebuffer * fb;
|
||||||
@ -69,6 +72,12 @@ static void egl_filterFFXCASEarlyInit(void)
|
|||||||
option_register(options);
|
option_register(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void casUpdateConsts(EGL_FilterFFXCAS * this)
|
||||||
|
{
|
||||||
|
ffxCasConst((uint32_t *) this->consts->data, this->sharpness, this->width, this->height,
|
||||||
|
this->width, this->height);
|
||||||
|
}
|
||||||
|
|
||||||
static bool egl_filterFFXCASInit(EGL_Filter ** filter)
|
static bool egl_filterFFXCASInit(EGL_Filter ** filter)
|
||||||
{
|
{
|
||||||
EGL_FilterFFXCAS * this = calloc(1, sizeof(*this));
|
EGL_FilterFFXCAS * this = calloc(1, sizeof(*this));
|
||||||
@ -93,12 +102,15 @@ static bool egl_filterFFXCASInit(EGL_Filter ** filter)
|
|||||||
goto error_shader;
|
goto error_shader;
|
||||||
}
|
}
|
||||||
|
|
||||||
this->enable = option_get_bool("eglFilter", "ffxCAS");
|
this->consts = countedBufferNew(8 * sizeof(GLuint));
|
||||||
this->uniform.type = EGL_UNIFORM_TYPE_1F;
|
egl_shaderSetUniforms(this->shader, &(EGL_Uniform) {
|
||||||
this->uniform.location =
|
.type = EGL_UNIFORM_TYPE_4UIV,
|
||||||
egl_shaderGetUniform(this->shader, "uSharpness");
|
.location = egl_shaderGetUniform(this->shader, "uConsts"),
|
||||||
this->uniform.f[0] =
|
.v = this->consts,
|
||||||
option_get_float("eglFilter", "ffxCASSharpness");
|
}, 1);
|
||||||
|
|
||||||
|
this->enable = option_get_bool("eglFilter", "ffxCAS");
|
||||||
|
this->sharpness = option_get_float("eglFilter", "ffxCASSharpness");
|
||||||
|
|
||||||
if (!egl_framebufferInit(&this->fb))
|
if (!egl_framebufferInit(&this->fb))
|
||||||
{
|
{
|
||||||
@ -139,7 +151,7 @@ static bool egl_filterFFXCASImguiConfig(EGL_Filter * filter)
|
|||||||
|
|
||||||
bool redraw = false;
|
bool redraw = false;
|
||||||
bool cas = this->enable;
|
bool cas = this->enable;
|
||||||
float casSharpness = this->uniform.f[0];
|
float casSharpness = this->sharpness;
|
||||||
|
|
||||||
igCheckbox("AMD FidelityFX CAS", &cas);
|
igCheckbox("AMD FidelityFX CAS", &cas);
|
||||||
if (cas != this->enable)
|
if (cas != this->enable)
|
||||||
@ -156,7 +168,7 @@ static bool egl_filterFFXCASImguiConfig(EGL_Filter * filter)
|
|||||||
igSliderFloat("##casSharpness", &casSharpness, 0.0f, 1.0f, NULL, 0);
|
igSliderFloat("##casSharpness", &casSharpness, 0.0f, 1.0f, NULL, 0);
|
||||||
igPopItemWidth();
|
igPopItemWidth();
|
||||||
|
|
||||||
if (casSharpness != this->uniform.f[0])
|
if (casSharpness != this->sharpness)
|
||||||
{
|
{
|
||||||
// enable CAS if the sharpness was changed
|
// enable CAS if the sharpness was changed
|
||||||
if (!cas)
|
if (!cas)
|
||||||
@ -165,7 +177,8 @@ static bool egl_filterFFXCASImguiConfig(EGL_Filter * filter)
|
|||||||
this->enable = true;
|
this->enable = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
this->uniform.f[0] = casSharpness;
|
this->sharpness = casSharpness;
|
||||||
|
casUpdateConsts(this);
|
||||||
redraw = true;
|
redraw = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -190,6 +203,7 @@ static bool egl_filterFFXCASSetup(EGL_Filter * filter,
|
|||||||
this->width = width;
|
this->width = width;
|
||||||
this->height = height;
|
this->height = height;
|
||||||
this->prepared = false;
|
this->prepared = false;
|
||||||
|
casUpdateConsts(this);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -212,7 +226,6 @@ static bool egl_filterFFXCASPrepare(EGL_Filter * filter)
|
|||||||
if (this->prepared)
|
if (this->prepared)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
egl_shaderSetUniforms(this->shader, &this->uniform, 1);
|
|
||||||
this->prepared = true;
|
this->prepared = true;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -7,7 +7,7 @@ in vec2 fragCoord;
|
|||||||
out vec4 fragColor;
|
out vec4 fragColor;
|
||||||
|
|
||||||
uniform sampler2D texture;
|
uniform sampler2D texture;
|
||||||
uniform float uSharpness;
|
uniform uvec4 uConsts[2];
|
||||||
|
|
||||||
#define A_GPU 1
|
#define A_GPU 1
|
||||||
#define A_GLSL 1
|
#define A_GLSL 1
|
||||||
@ -32,17 +32,8 @@ void main()
|
|||||||
{
|
{
|
||||||
vec2 res = vec2(textureSize(texture, 0));
|
vec2 res = vec2(textureSize(texture, 0));
|
||||||
uvec2 point = uvec2(fragCoord * res);
|
uvec2 point = uvec2(fragCoord * res);
|
||||||
|
|
||||||
vec4 color;
|
|
||||||
uvec4 const0;
|
|
||||||
uvec4 const1;
|
|
||||||
|
|
||||||
CasSetup(const0, const1, uSharpness,
|
|
||||||
res.x, res.y, res.x, res.y);
|
|
||||||
|
|
||||||
CasFilter(
|
CasFilter(
|
||||||
fragColor.r, fragColor.g, fragColor.b,
|
fragColor.r, fragColor.g, fragColor.b,
|
||||||
point,
|
point, uConsts[0], uConsts[1], true);
|
||||||
const0, const1,
|
|
||||||
true);
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user