Skip to content

Commit

Permalink
PostProcessing: Get rid of Timer global
Browse files Browse the repository at this point in the history
  • Loading branch information
stenzek committed Jan 2, 2025
1 parent ba15a76 commit 87e3670
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 23 deletions.
20 changes: 8 additions & 12 deletions src/util/postprocessing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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<u64, std::unique_ptr<GPUSampler>> s_samplers;
static std::unique_ptr<GPUTexture> s_dummy_texture;
Expand Down Expand Up @@ -525,7 +525,7 @@ void PostProcessing::Chain::UpdateSettings(std::unique_lock<std::mutex>& setting

if (stage_count > 0)
{
s_timer.Reset();
s_start_time = Timer::GetCurrentValue();
DEV_LOG("Loaded {} post-processing stages.", stage_count);
}

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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<Shader>& 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;
Expand Down Expand Up @@ -744,7 +745,7 @@ void PostProcessing::Initialize()
{
DisplayChain.LoadStages();
InternalChain.LoadStages();
s_timer.Reset();
s_start_time = Timer::GetCurrentValue();
}

void PostProcessing::UpdateSettings()
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 0 additions & 2 deletions src/util/postprocessing.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,6 @@ void Shutdown();
GPUSampler* GetSampler(const GPUSampler::Config& config);
GPUTexture* GetDummyTexture();

const Timer& GetTimer();

extern Chain DisplayChain;
extern Chain InternalChain;

Expand Down
2 changes: 1 addition & 1 deletion src/util/postprocessing_shader.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class Shader

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<ShaderOption>;
Expand Down
9 changes: 6 additions & 3 deletions src/util/postprocessing_shader_fx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);
Expand Down Expand Up @@ -1509,8 +1513,7 @@ GPUDevice::PresentResult PostProcessing::ReShadeFXShader::Apply(GPUTexture* inpu

case SourceOptionType::Timer:
{
const float value = static_cast<float>(PostProcessing::GetTimer().GetTimeMilliseconds());
std::memcpy(dst, &value, sizeof(value));
std::memcpy(dst, &time, sizeof(time));
}
break;

Expand Down
2 changes: 1 addition & 1 deletion src/util/postprocessing_shader_fx.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class ReShadeFXShader final : public Shader
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;
Expand Down
6 changes: 3 additions & 3 deletions src/util/postprocessing_shader_glsl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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<float>(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;
Expand Down
2 changes: 1 addition & 1 deletion src/util/postprocessing_shader_glsl.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class GLSLShader final : public Shader
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
Expand Down

0 comments on commit 87e3670

Please sign in to comment.