PostProcessing: Get rid of Timer global

This commit is contained in:
Stenzek 2025-01-02 21:40:01 +10:00
parent ba15a76d7b
commit 87e367076d
No known key found for this signature in database
7 changed files with 20 additions and 23 deletions

View File

@ -11,8 +11,8 @@
#include "shadergen.h" #include "shadergen.h"
// TODO: Remove me // TODO: Remove me
#include "core/host.h"
#include "core/fullscreen_ui.h" #include "core/fullscreen_ui.h"
#include "core/host.h"
#include "core/settings.h" #include "core/settings.h"
#include "IconsFontAwesome5.h" #include "IconsFontAwesome5.h"
@ -51,7 +51,7 @@ ALWAYS_INLINE void ForAllChains(const T& F)
Chain DisplayChain(Config::DISPLAY_CHAIN_SECTION); Chain DisplayChain(Config::DISPLAY_CHAIN_SECTION);
Chain InternalChain(Config::INTERNAL_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::unordered_map<u64, std::unique_ptr<GPUSampler>> s_samplers;
static std::unique_ptr<GPUTexture> s_dummy_texture; static std::unique_ptr<GPUTexture> s_dummy_texture;
@ -525,7 +525,7 @@ void PostProcessing::Chain::UpdateSettings(std::unique_lock<std::mutex>& setting
if (stage_count > 0) if (stage_count > 0)
{ {
s_timer.Reset(); s_start_time = Timer::GetCurrentValue();
DEV_LOG("Loaded {} post-processing stages.", stage_count); DEV_LOG("Loaded {} post-processing stages.", stage_count);
} }
@ -555,7 +555,7 @@ void PostProcessing::Chain::Toggle()
m_enabled = new_enabled; m_enabled = new_enabled;
m_needs_depth_buffer = new_enabled && m_wants_depth_buffer; m_needs_depth_buffer = new_enabled && m_wants_depth_buffer;
if (m_enabled) 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, 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(); draw_final_target = GetTextureUnusedAtEndOfChain();
} }
const float time = Timer::ConvertValueToSeconds(Timer::GetCurrentValue() - s_start_time);
for (const std::unique_ptr<Shader>& stage : m_stages) for (const std::unique_ptr<Shader>& stage : m_stages)
{ {
const bool is_final = (stage.get() == m_stages.back().get()); const bool is_final = (stage.get() == m_stages.back().get());
if (const GPUDevice::PresentResult pres = if (const GPUDevice::PresentResult pres =
stage->Apply(input_color, input_depth, is_final ? draw_final_target : output, final_rect, orig_width, 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) pres != GPUDevice::PresentResult::OK)
{ {
return pres; return pres;
@ -744,7 +745,7 @@ void PostProcessing::Initialize()
{ {
DisplayChain.LoadStages(); DisplayChain.LoadStages();
InternalChain.LoadStages(); InternalChain.LoadStages();
s_timer.Reset(); s_start_time = Timer::GetCurrentValue();
} }
void PostProcessing::UpdateSettings() void PostProcessing::UpdateSettings()
@ -780,7 +781,7 @@ bool PostProcessing::ReloadShaders()
chain.DestroyTextures(); chain.DestroyTextures();
chain.LoadStages(); chain.LoadStages();
}); });
s_timer.Reset(); s_start_time = Timer::GetCurrentValue();
Host::AddIconOSDMessage("PostProcessing", ICON_FA_PAINT_ROLLER, Host::AddIconOSDMessage("PostProcessing", ICON_FA_PAINT_ROLLER,
TRANSLATE_STR("OSDMessage", "Post-processing shaders reloaded."), Host::OSD_QUICK_DURATION); 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(); return *Host::Internal::GetBaseSettingsLayer();
} }
const Timer& PostProcessing::GetTimer()
{
return s_timer;
}
GPUSampler* PostProcessing::GetSampler(const GPUSampler::Config& config) GPUSampler* PostProcessing::GetSampler(const GPUSampler::Config& config)
{ {
auto it = s_samplers.find(config.key); auto it = s_samplers.find(config.key);

View File

@ -175,8 +175,6 @@ void Shutdown();
GPUSampler* GetSampler(const GPUSampler::Config& config); GPUSampler* GetSampler(const GPUSampler::Config& config);
GPUTexture* GetDummyTexture(); GPUTexture* GetDummyTexture();
const Timer& GetTimer();
extern Chain DisplayChain; extern Chain DisplayChain;
extern Chain InternalChain; extern Chain InternalChain;

View File

@ -51,7 +51,7 @@ public:
virtual GPUDevice::PresentResult Apply(GPUTexture* input_color, GPUTexture* input_depth, GPUTexture* final_target, 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, 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: protected:
using OptionList = std::vector<ShaderOption>; using OptionList = std::vector<ShaderOption>;

View File

@ -1469,7 +1469,8 @@ bool PostProcessing::ReShadeFXShader::ResizeOutput(GPUTexture::Format format, u3
GPUDevice::PresentResult PostProcessing::ReShadeFXShader::Apply(GPUTexture* input_color, GPUTexture* input_depth, GPUDevice::PresentResult PostProcessing::ReShadeFXShader::Apply(GPUTexture* input_color, GPUTexture* input_depth,
GPUTexture* final_target, GSVector4i final_rect, GPUTexture* final_target, GSVector4i final_rect,
s32 orig_width, s32 orig_height, s32 native_width, 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); GL_PUSH_FMT("PostProcessingShaderFX {}", m_name);
@ -1478,6 +1479,9 @@ GPUDevice::PresentResult PostProcessing::ReShadeFXShader::Apply(GPUTexture* inpu
// Reshade always draws at full size. // Reshade always draws at full size.
g_gpu_device->SetViewportAndScissor(GSVector4i(0, 0, target_width, target_height)); 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) if (m_uniforms_size > 0)
{ {
GL_SCOPE_FMT("Uniforms: {} bytes", m_uniforms_size); GL_SCOPE_FMT("Uniforms: {} bytes", m_uniforms_size);
@ -1509,8 +1513,7 @@ GPUDevice::PresentResult PostProcessing::ReShadeFXShader::Apply(GPUTexture* inpu
case SourceOptionType::Timer: case SourceOptionType::Timer:
{ {
const float value = static_cast<float>(PostProcessing::GetTimer().GetTimeMilliseconds()); std::memcpy(dst, &time, sizeof(time));
std::memcpy(dst, &value, sizeof(value));
} }
break; break;

View File

@ -38,7 +38,7 @@ public:
ProgressCallback* progress) override; ProgressCallback* progress) override;
GPUDevice::PresentResult Apply(GPUTexture* input_color, GPUTexture* input_depth, GPUTexture* final_target, GPUDevice::PresentResult Apply(GPUTexture* input_color, GPUTexture* input_depth, GPUTexture* final_target,
GSVector4i final_rect, s32 orig_width, s32 orig_height, s32 native_width, 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: private:
using TextureID = s32; using TextureID = s32;

View File

@ -170,7 +170,8 @@ bool PostProcessing::GLSLShader::CompilePipeline(GPUTexture::Format format, u32
GPUDevice::PresentResult PostProcessing::GLSLShader::Apply(GPUTexture* input_color, GPUTexture* input_depth, GPUDevice::PresentResult PostProcessing::GLSLShader::Apply(GPUTexture* input_color, GPUTexture* input_depth,
GPUTexture* final_target, GSVector4i final_rect, GPUTexture* final_target, GSVector4i final_rect,
s32 orig_width, s32 orig_height, s32 native_width, 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); GL_SCOPE_FMT("GLSL Shader {}", m_name);
@ -194,8 +195,7 @@ GPUDevice::PresentResult PostProcessing::GLSLShader::Apply(GPUTexture* input_col
const u32 uniforms_size = GetUniformsSize(); const u32 uniforms_size = GetUniformsSize();
void* uniforms = g_gpu_device->MapUniformBuffer(uniforms_size); void* uniforms = g_gpu_device->MapUniformBuffer(uniforms_size);
FillUniformBuffer(uniforms, final_rect.left, final_rect.top, final_rect.width(), final_rect.height(), target_width, 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, target_height, orig_width, orig_height, native_width, native_height, time);
static_cast<float>(PostProcessing::GetTimer().GetTimeSeconds()));
g_gpu_device->UnmapUniformBuffer(uniforms_size); g_gpu_device->UnmapUniformBuffer(uniforms_size);
g_gpu_device->Draw(3, 0); g_gpu_device->Draw(3, 0);
return GPUDevice::PresentResult::OK; return GPUDevice::PresentResult::OK;

View File

@ -27,7 +27,7 @@ public:
ProgressCallback* progress) override; ProgressCallback* progress) override;
GPUDevice::PresentResult Apply(GPUTexture* input_color, GPUTexture* input_depth, GPUTexture* final_target, GPUDevice::PresentResult Apply(GPUTexture* input_color, GPUTexture* input_depth, GPUTexture* final_target,
GSVector4i final_rect, s32 orig_width, s32 orig_height, s32 native_width, 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: private:
struct CommonUniforms struct CommonUniforms