From 87e367076dac99ab5c2e1880283b6b7d888bbebf Mon Sep 17 00:00:00 2001 From: Stenzek Date: Thu, 2 Jan 2025 21:40:01 +1000 Subject: [PATCH] PostProcessing: Get rid of Timer global --- src/util/postprocessing.cpp | 20 ++++++++------------ src/util/postprocessing.h | 2 -- src/util/postprocessing_shader.h | 2 +- src/util/postprocessing_shader_fx.cpp | 9 ++++++--- src/util/postprocessing_shader_fx.h | 2 +- src/util/postprocessing_shader_glsl.cpp | 6 +++--- src/util/postprocessing_shader_glsl.h | 2 +- 7 files changed, 20 insertions(+), 23 deletions(-) diff --git a/src/util/postprocessing.cpp b/src/util/postprocessing.cpp index 5e93e6994..14d43fd1b 100644 --- a/src/util/postprocessing.cpp +++ b/src/util/postprocessing.cpp @@ -11,8 +11,8 @@ #include "shadergen.h" // TODO: Remove me -#include "core/host.h" #include "core/fullscreen_ui.h" +#include "core/host.h" #include "core/settings.h" #include "IconsFontAwesome5.h" @@ -51,7 +51,7 @@ ALWAYS_INLINE void ForAllChains(const T& F) Chain DisplayChain(Config::DISPLAY_CHAIN_SECTION); Chain InternalChain(Config::INTERNAL_CHAIN_SECTION); -static Timer s_timer; +static Timer::Value s_start_time; static std::unordered_map> s_samplers; static std::unique_ptr s_dummy_texture; @@ -525,7 +525,7 @@ void PostProcessing::Chain::UpdateSettings(std::unique_lock& setting if (stage_count > 0) { - s_timer.Reset(); + s_start_time = Timer::GetCurrentValue(); DEV_LOG("Loaded {} post-processing stages.", stage_count); } @@ -555,7 +555,7 @@ void PostProcessing::Chain::Toggle() m_enabled = new_enabled; m_needs_depth_buffer = new_enabled && m_wants_depth_buffer; if (m_enabled) - s_timer.Reset(); + s_start_time = Timer::GetCurrentValue(); } bool PostProcessing::Chain::CheckTargets(GPUTexture::Format target_format, u32 target_width, u32 target_height, @@ -693,13 +693,14 @@ GPUDevice::PresentResult PostProcessing::Chain::Apply(GPUTexture* input_color, G draw_final_target = GetTextureUnusedAtEndOfChain(); } + const float time = Timer::ConvertValueToSeconds(Timer::GetCurrentValue() - s_start_time); for (const std::unique_ptr& stage : m_stages) { const bool is_final = (stage.get() == m_stages.back().get()); if (const GPUDevice::PresentResult pres = stage->Apply(input_color, input_depth, is_final ? draw_final_target : output, final_rect, orig_width, - orig_height, native_width, native_height, m_target_width, m_target_height); + orig_height, native_width, native_height, m_target_width, m_target_height, time); pres != GPUDevice::PresentResult::OK) { return pres; @@ -744,7 +745,7 @@ void PostProcessing::Initialize() { DisplayChain.LoadStages(); InternalChain.LoadStages(); - s_timer.Reset(); + s_start_time = Timer::GetCurrentValue(); } void PostProcessing::UpdateSettings() @@ -780,7 +781,7 @@ bool PostProcessing::ReloadShaders() chain.DestroyTextures(); chain.LoadStages(); }); - s_timer.Reset(); + s_start_time = Timer::GetCurrentValue(); Host::AddIconOSDMessage("PostProcessing", ICON_FA_PAINT_ROLLER, TRANSLATE_STR("OSDMessage", "Post-processing shaders reloaded."), Host::OSD_QUICK_DURATION); @@ -869,11 +870,6 @@ SettingsInterface& PostProcessing::GetLoadSettingsInterface(const char* section) return *Host::Internal::GetBaseSettingsLayer(); } -const Timer& PostProcessing::GetTimer() -{ - return s_timer; -} - GPUSampler* PostProcessing::GetSampler(const GPUSampler::Config& config) { auto it = s_samplers.find(config.key); diff --git a/src/util/postprocessing.h b/src/util/postprocessing.h index 6c78cb12f..6a9ff4fb2 100644 --- a/src/util/postprocessing.h +++ b/src/util/postprocessing.h @@ -175,8 +175,6 @@ void Shutdown(); GPUSampler* GetSampler(const GPUSampler::Config& config); GPUTexture* GetDummyTexture(); -const Timer& GetTimer(); - extern Chain DisplayChain; extern Chain InternalChain; diff --git a/src/util/postprocessing_shader.h b/src/util/postprocessing_shader.h index b9137b71a..e3d1be91d 100644 --- a/src/util/postprocessing_shader.h +++ b/src/util/postprocessing_shader.h @@ -51,7 +51,7 @@ public: virtual GPUDevice::PresentResult Apply(GPUTexture* input_color, GPUTexture* input_depth, GPUTexture* final_target, GSVector4i final_rect, s32 orig_width, s32 orig_height, s32 native_width, - s32 native_height, u32 target_width, u32 target_height) = 0; + s32 native_height, u32 target_width, u32 target_height, float time) = 0; protected: using OptionList = std::vector; diff --git a/src/util/postprocessing_shader_fx.cpp b/src/util/postprocessing_shader_fx.cpp index 159406513..157b7a3b4 100644 --- a/src/util/postprocessing_shader_fx.cpp +++ b/src/util/postprocessing_shader_fx.cpp @@ -1469,7 +1469,8 @@ bool PostProcessing::ReShadeFXShader::ResizeOutput(GPUTexture::Format format, u3 GPUDevice::PresentResult PostProcessing::ReShadeFXShader::Apply(GPUTexture* input_color, GPUTexture* input_depth, GPUTexture* final_target, GSVector4i final_rect, s32 orig_width, s32 orig_height, s32 native_width, - s32 native_height, u32 target_width, u32 target_height) + s32 native_height, u32 target_width, u32 target_height, + float time) { GL_PUSH_FMT("PostProcessingShaderFX {}", m_name); @@ -1478,6 +1479,9 @@ GPUDevice::PresentResult PostProcessing::ReShadeFXShader::Apply(GPUTexture* inpu // Reshade always draws at full size. g_gpu_device->SetViewportAndScissor(GSVector4i(0, 0, target_width, target_height)); + // Reshade timer variable is in milliseconds. + time *= 1000.0f; + if (m_uniforms_size > 0) { GL_SCOPE_FMT("Uniforms: {} bytes", m_uniforms_size); @@ -1509,8 +1513,7 @@ GPUDevice::PresentResult PostProcessing::ReShadeFXShader::Apply(GPUTexture* inpu case SourceOptionType::Timer: { - const float value = static_cast(PostProcessing::GetTimer().GetTimeMilliseconds()); - std::memcpy(dst, &value, sizeof(value)); + std::memcpy(dst, &time, sizeof(time)); } break; diff --git a/src/util/postprocessing_shader_fx.h b/src/util/postprocessing_shader_fx.h index 2f20e2147..8b98218fe 100644 --- a/src/util/postprocessing_shader_fx.h +++ b/src/util/postprocessing_shader_fx.h @@ -38,7 +38,7 @@ public: ProgressCallback* progress) override; GPUDevice::PresentResult Apply(GPUTexture* input_color, GPUTexture* input_depth, GPUTexture* final_target, GSVector4i final_rect, s32 orig_width, s32 orig_height, s32 native_width, - s32 native_height, u32 target_width, u32 target_height) override; + s32 native_height, u32 target_width, u32 target_height, float time) override; private: using TextureID = s32; diff --git a/src/util/postprocessing_shader_glsl.cpp b/src/util/postprocessing_shader_glsl.cpp index c699b51a5..c3639252d 100644 --- a/src/util/postprocessing_shader_glsl.cpp +++ b/src/util/postprocessing_shader_glsl.cpp @@ -170,7 +170,8 @@ bool PostProcessing::GLSLShader::CompilePipeline(GPUTexture::Format format, u32 GPUDevice::PresentResult PostProcessing::GLSLShader::Apply(GPUTexture* input_color, GPUTexture* input_depth, GPUTexture* final_target, GSVector4i final_rect, s32 orig_width, s32 orig_height, s32 native_width, - s32 native_height, u32 target_width, u32 target_height) + s32 native_height, u32 target_width, u32 target_height, + float time) { GL_SCOPE_FMT("GLSL Shader {}", m_name); @@ -194,8 +195,7 @@ GPUDevice::PresentResult PostProcessing::GLSLShader::Apply(GPUTexture* input_col const u32 uniforms_size = GetUniformsSize(); void* uniforms = g_gpu_device->MapUniformBuffer(uniforms_size); FillUniformBuffer(uniforms, final_rect.left, final_rect.top, final_rect.width(), final_rect.height(), target_width, - target_height, orig_width, orig_height, native_width, native_height, - static_cast(PostProcessing::GetTimer().GetTimeSeconds())); + target_height, orig_width, orig_height, native_width, native_height, time); g_gpu_device->UnmapUniformBuffer(uniforms_size); g_gpu_device->Draw(3, 0); return GPUDevice::PresentResult::OK; diff --git a/src/util/postprocessing_shader_glsl.h b/src/util/postprocessing_shader_glsl.h index c983ffdfb..ba17ac712 100644 --- a/src/util/postprocessing_shader_glsl.h +++ b/src/util/postprocessing_shader_glsl.h @@ -27,7 +27,7 @@ public: ProgressCallback* progress) override; GPUDevice::PresentResult Apply(GPUTexture* input_color, GPUTexture* input_depth, GPUTexture* final_target, GSVector4i final_rect, s32 orig_width, s32 orig_height, s32 native_width, - s32 native_height, u32 target_width, u32 target_height) override; + s32 native_height, u32 target_width, u32 target_height, float time) override; private: struct CommonUniforms