From 084837b936ad027e0122ef116a9dcd591df25696 Mon Sep 17 00:00:00 2001 From: Quantum Date: Sat, 28 Aug 2021 15:57:54 -0400 Subject: [PATCH] [client] egl: add loadState and saveState for filters --- client/renderers/EGL/filter.h | 16 ++++++++++++++++ client/renderers/EGL/filter_downscale.c | 12 ++++++++++++ client/renderers/EGL/filter_ffx_cas.c | 21 +++++++++++++++++++-- client/renderers/EGL/filter_ffx_fsr1.c | 22 +++++++++++++++++++--- 4 files changed, 66 insertions(+), 5 deletions(-) diff --git a/client/renderers/EGL/filter.h b/client/renderers/EGL/filter.h index 6eb25799..f8c65901 100644 --- a/client/renderers/EGL/filter.h +++ b/client/renderers/EGL/filter.h @@ -50,6 +50,12 @@ typedef struct EGL_FilterOps * Returns true if a redraw is required */ bool (*imguiConfig)(EGL_Filter * filter); + /* writes filter state to options */ + void (*saveState)(EGL_Filter * filter); + + /* reads filter state from options */ + void (*loadState)(EGL_Filter * filter); + /* set the input format of the filter */ bool (*setup)(EGL_Filter * filter, enum EGL_PixelFormat pixFmt, unsigned int width, unsigned int height); @@ -103,6 +109,16 @@ static inline bool egl_filterImguiConfig(EGL_Filter * filter) return filter->ops.imguiConfig(filter); } +static inline void egl_filterSaveState(EGL_Filter * filter) +{ + filter->ops.saveState(filter); +} + +static inline void egl_filterLoadState(EGL_Filter * filter) +{ + filter->ops.loadState(filter); +} + static inline bool egl_filterSetup(EGL_Filter * filter, enum EGL_PixelFormat pixFmt, unsigned int width, unsigned int height) { diff --git a/client/renderers/EGL/filter_downscale.c b/client/renderers/EGL/filter_downscale.c index d1f54009..122852d9 100644 --- a/client/renderers/EGL/filter_downscale.c +++ b/client/renderers/EGL/filter_downscale.c @@ -83,6 +83,16 @@ static void egl_filterDownscaleEarlyInit(void) option_register(options); } +static void egl_filterDownscaleSaveState(EGL_Filter * filter) +{ + // not implemented +} + +static void egl_filterDownscaleLoadState(EGL_Filter * filter) +{ + // not implemented +} + static bool egl_filterDownscaleInit(EGL_Filter ** filter) { EGL_FilterDownscale * this = calloc(1, sizeof(*this)); @@ -364,6 +374,8 @@ EGL_FilterOps egl_filterDownscaleOps = .init = egl_filterDownscaleInit, .free = egl_filterDownscaleFree, .imguiConfig = egl_filterDownscaleImguiConfig, + .saveState = egl_filterDownscaleSaveState, + .loadState = egl_filterDownscaleLoadState, .setup = egl_filterDownscaleSetup, .getOutputRes = egl_filterDownscaleGetOutputRes, .prepare = egl_filterDownscalePrepare, diff --git a/client/renderers/EGL/filter_ffx_cas.c b/client/renderers/EGL/filter_ffx_cas.c index 95024bc7..623d3e9b 100644 --- a/client/renderers/EGL/filter_ffx_cas.c +++ b/client/renderers/EGL/filter_ffx_cas.c @@ -79,6 +79,22 @@ static void casUpdateConsts(EGL_FilterFFXCAS * this) this->width, this->height); } +static void egl_filterFFXCASSaveState(EGL_Filter * filter) +{ + EGL_FilterFFXCAS * this = UPCAST(EGL_FilterFFXCAS, filter); + + option_set_bool ("eglFilter", "ffxCAS", this->enable); + option_set_float("eglFilter", "ffxCASSharpness", this->sharpness); +} + +static void egl_filterFFXCASLoadState(EGL_Filter * filter) +{ + EGL_FilterFFXCAS * this = UPCAST(EGL_FilterFFXCAS, filter); + + this->enable = option_get_bool ("eglFilter", "ffxCAS"); + this->sharpness = option_get_float("eglFilter", "ffxCASSharpness"); +} + static bool egl_filterFFXCASInit(EGL_Filter ** filter) { EGL_FilterFFXCAS * this = calloc(1, sizeof(*this)); @@ -116,8 +132,7 @@ static bool egl_filterFFXCASInit(EGL_Filter ** filter) .v = this->consts, }, 1); - this->enable = option_get_bool("eglFilter", "ffxCAS"); - this->sharpness = option_get_float("eglFilter", "ffxCASSharpness"); + egl_filterFFXCASLoadState(&this->base); if (!egl_framebufferInit(&this->fb)) { @@ -270,6 +285,8 @@ EGL_FilterOps egl_filterFFXCASOps = .init = egl_filterFFXCASInit, .free = egl_filterFFXCASFree, .imguiConfig = egl_filterFFXCASImguiConfig, + .saveState = egl_filterFFXCASSaveState, + .loadState = egl_filterFFXCASLoadState, .setup = egl_filterFFXCASSetup, .getOutputRes = egl_filterFFXCASGetOutputRes, .prepare = egl_filterFFXCASPrepare, diff --git a/client/renderers/EGL/filter_ffx_fsr1.c b/client/renderers/EGL/filter_ffx_fsr1.c index dc26ec80..d90509eb 100644 --- a/client/renderers/EGL/filter_ffx_fsr1.c +++ b/client/renderers/EGL/filter_ffx_fsr1.c @@ -82,6 +82,22 @@ static void rcasUpdateUniform(EGL_FilterFFXFSR1 * this) ffxFsrRcasConst(this->rcasUniform.ui, 2.0f - this->sharpness * 2.0f); } +static void egl_filterFFXFSR1SaveState(EGL_Filter * filter) +{ + EGL_FilterFFXFSR1 * this = UPCAST(EGL_FilterFFXFSR1, filter); + + option_set_bool ("eglFilter", "ffxFSR", this->enable); + option_set_float("eglFilter", "ffxFSRSharpness", this->sharpness); +} + +static void egl_filterFFXFSR1LoadState(EGL_Filter * filter) +{ + EGL_FilterFFXFSR1 * this = UPCAST(EGL_FilterFFXFSR1, filter); + + this->enable = option_get_bool ("eglFilter", "ffxFSR"); + this->sharpness = option_get_float("eglFilter", "ffxFSRSharpness"); +} + static bool egl_filterFFXFSR1Init(EGL_Filter ** filter) { EGL_FilterFFXFSR1 * this = calloc(1, sizeof(*this)); @@ -128,8 +144,7 @@ static bool egl_filterFFXFSR1Init(EGL_Filter ** filter) goto error_rcas; } - - this->enable = option_get_bool("eglFilter", "ffxFSR"); + egl_filterFFXFSR1LoadState(&this->base); this->easuUniform[0].type = EGL_UNIFORM_TYPE_4UIV; this->easuUniform[0].location = @@ -141,7 +156,6 @@ static bool egl_filterFFXFSR1Init(EGL_Filter ** filter) this->rcasUniform.type = EGL_UNIFORM_TYPE_4UI; this->rcasUniform.location = egl_shaderGetUniform(this->rcas, "uConsts"); - this->sharpness = option_get_float("eglFilter", "ffxFSRSharpness"); rcasUpdateUniform(this); if (!egl_framebufferInit(&this->easuFb)) @@ -406,6 +420,8 @@ EGL_FilterOps egl_filterFFXFSR1Ops = .init = egl_filterFFXFSR1Init, .free = egl_filterFFXFSR1Free, .imguiConfig = egl_filterFFXFSR1ImguiConfig, + .saveState = egl_filterFFXFSR1SaveState, + .loadState = egl_filterFFXFSR1LoadState, .setup = egl_filterFFXFSR1Setup, .setOutputResHint = egl_filterFFXFSR1SetOutputResHint, .getOutputRes = egl_filterFFXFSR1GetOutputRes,