diff --git a/src/util/postprocessing.cpp b/src/util/postprocessing.cpp index b29bf7893..f80033e4d 100644 --- a/src/util/postprocessing.cpp +++ b/src/util/postprocessing.cpp @@ -30,6 +30,7 @@ LOG_CHANNEL(PostProcessing); namespace PostProcessing { + template static u32 ParseVector(std::string_view line, ShaderOption::ValueVector* values); @@ -51,10 +52,8 @@ ALWAYS_INLINE void ForAllChains(const T& F) Chain DisplayChain(Config::DISPLAY_CHAIN_SECTION); Chain InternalChain(Config::INTERNAL_CHAIN_SECTION); -static Timer::Value s_start_time; +Timer::Value Chain::s_start_time; -static std::unordered_map> s_samplers; -static std::unique_ptr s_dummy_texture; } // namespace PostProcessing template @@ -374,6 +373,8 @@ void PostProcessing::Config::ClearStages(SettingsInterface& si, const char* sect PostProcessing::Chain::Chain(const char* section) : m_section(section) { + if (s_start_time == 0) [[unlikely]] + s_start_time = Timer::GetCurrentValue(); } PostProcessing::Chain::~Chain() = default; @@ -677,7 +678,6 @@ void PostProcessing::Initialize() { DisplayChain.LoadStages(); InternalChain.LoadStages(); - s_start_time = Timer::GetCurrentValue(); } void PostProcessing::UpdateSettings() @@ -688,8 +688,6 @@ void PostProcessing::UpdateSettings() void PostProcessing::Shutdown() { - g_gpu_device->RecycleTexture(std::move(s_dummy_texture)); - s_samplers.clear(); ForAllChains([](Chain& chain) { chain.ClearStages(); chain.DestroyTextures(); @@ -711,7 +709,6 @@ bool PostProcessing::ReloadShaders() chain.DestroyTextures(); chain.LoadStages(); }); - s_start_time = Timer::GetCurrentValue(); Host::AddIconOSDMessage("PostProcessing", ICON_FA_PAINT_ROLLER, TRANSLATE_STR("OSDMessage", "Post-processing shaders reloaded."), Host::OSD_QUICK_DURATION); @@ -799,31 +796,3 @@ SettingsInterface& PostProcessing::GetLoadSettingsInterface(const char* section) else return *Host::Internal::GetBaseSettingsLayer(); } - -GPUSampler* PostProcessing::GetSampler(const GPUSampler::Config& config) -{ - auto it = s_samplers.find(config.key); - if (it != s_samplers.end()) - return it->second.get(); - - std::unique_ptr sampler = g_gpu_device->CreateSampler(config); - if (!sampler) - ERROR_LOG("Failed to create GPU sampler with config={:X}", config.key); - - it = s_samplers.emplace(config.key, std::move(sampler)).first; - return it->second.get(); -} - -GPUTexture* PostProcessing::GetDummyTexture() -{ - if (s_dummy_texture) - return s_dummy_texture.get(); - - const u32 zero = 0; - s_dummy_texture = g_gpu_device->FetchTexture(1, 1, 1, 1, 1, GPUTexture::Type::Texture, GPUTexture::Format::RGBA8, - GPUTexture::Flags::None, &zero, sizeof(zero)); - if (!s_dummy_texture) - ERROR_LOG("Failed to create dummy texture."); - - return s_dummy_texture.get(); -} diff --git a/src/util/postprocessing.h b/src/util/postprocessing.h index fe2f5f1c9..48e615630 100644 --- a/src/util/postprocessing.h +++ b/src/util/postprocessing.h @@ -5,14 +5,14 @@ #include "gpu_device.h" +#include "common/timer.h" + #include #include #include #include #include -class Timer; - class GPUPipeline; class GPUSampler; class GPUTexture; @@ -155,6 +155,8 @@ private: std::vector> m_stages; std::unique_ptr m_input_texture; std::unique_ptr m_output_texture; + + static Timer::Value s_start_time; }; // [display_name, filename] @@ -170,9 +172,6 @@ bool ReloadShaders(); void Shutdown(); -GPUSampler* GetSampler(const GPUSampler::Config& config); -GPUTexture* GetDummyTexture(); - extern Chain DisplayChain; extern Chain InternalChain; diff --git a/src/util/postprocessing_shader_fx.cpp b/src/util/postprocessing_shader_fx.cpp index 157b7a3b4..a5d733e97 100644 --- a/src/util/postprocessing_shader_fx.cpp +++ b/src/util/postprocessing_shader_fx.cpp @@ -1258,7 +1258,7 @@ bool PostProcessing::ReShadeFXShader::CreatePasses(GPUTexture::Format backbuffer DEV_LOG("Pass {} Texture {} => {}", pi.name, tb.texture_name, sampler.texture_id); - sampler.sampler = GetSampler(MapSampler(sb)); + sampler.sampler = g_gpu_device->GetSampler(MapSampler(sb)); if (!sampler.sampler) { Error::SetString(error, "Failed to create sampler."); @@ -1303,7 +1303,7 @@ GPUTexture* PostProcessing::ReShadeFXShader::GetTextureByID(TextureID id, GPUTex } else if (id == INPUT_DEPTH_TEXTURE) { - return input_depth ? input_depth : GetDummyTexture(); + return input_depth ? input_depth : g_gpu_device->GetEmptyTexture(); } else if (id == OUTPUT_COLOR_TEXTURE) {