PostProcessing: Get rid of GPU-dependent globals
This commit is contained in:
parent
338d29d271
commit
d589696eff
|
@ -30,6 +30,7 @@
|
||||||
LOG_CHANNEL(PostProcessing);
|
LOG_CHANNEL(PostProcessing);
|
||||||
|
|
||||||
namespace PostProcessing {
|
namespace PostProcessing {
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
static u32 ParseVector(std::string_view line, ShaderOption::ValueVector* values);
|
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 DisplayChain(Config::DISPLAY_CHAIN_SECTION);
|
||||||
Chain InternalChain(Config::INTERNAL_CHAIN_SECTION);
|
Chain InternalChain(Config::INTERNAL_CHAIN_SECTION);
|
||||||
|
|
||||||
static Timer::Value s_start_time;
|
Timer::Value Chain::s_start_time;
|
||||||
|
|
||||||
static std::unordered_map<u64, std::unique_ptr<GPUSampler>> s_samplers;
|
|
||||||
static std::unique_ptr<GPUTexture> s_dummy_texture;
|
|
||||||
} // namespace PostProcessing
|
} // namespace PostProcessing
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
@ -374,6 +373,8 @@ void PostProcessing::Config::ClearStages(SettingsInterface& si, const char* sect
|
||||||
|
|
||||||
PostProcessing::Chain::Chain(const char* section) : m_section(section)
|
PostProcessing::Chain::Chain(const char* section) : m_section(section)
|
||||||
{
|
{
|
||||||
|
if (s_start_time == 0) [[unlikely]]
|
||||||
|
s_start_time = Timer::GetCurrentValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
PostProcessing::Chain::~Chain() = default;
|
PostProcessing::Chain::~Chain() = default;
|
||||||
|
@ -677,7 +678,6 @@ void PostProcessing::Initialize()
|
||||||
{
|
{
|
||||||
DisplayChain.LoadStages();
|
DisplayChain.LoadStages();
|
||||||
InternalChain.LoadStages();
|
InternalChain.LoadStages();
|
||||||
s_start_time = Timer::GetCurrentValue();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PostProcessing::UpdateSettings()
|
void PostProcessing::UpdateSettings()
|
||||||
|
@ -688,8 +688,6 @@ void PostProcessing::UpdateSettings()
|
||||||
|
|
||||||
void PostProcessing::Shutdown()
|
void PostProcessing::Shutdown()
|
||||||
{
|
{
|
||||||
g_gpu_device->RecycleTexture(std::move(s_dummy_texture));
|
|
||||||
s_samplers.clear();
|
|
||||||
ForAllChains([](Chain& chain) {
|
ForAllChains([](Chain& chain) {
|
||||||
chain.ClearStages();
|
chain.ClearStages();
|
||||||
chain.DestroyTextures();
|
chain.DestroyTextures();
|
||||||
|
@ -711,7 +709,6 @@ bool PostProcessing::ReloadShaders()
|
||||||
chain.DestroyTextures();
|
chain.DestroyTextures();
|
||||||
chain.LoadStages();
|
chain.LoadStages();
|
||||||
});
|
});
|
||||||
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);
|
||||||
|
@ -799,31 +796,3 @@ SettingsInterface& PostProcessing::GetLoadSettingsInterface(const char* section)
|
||||||
else
|
else
|
||||||
return *Host::Internal::GetBaseSettingsLayer();
|
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<GPUSampler> 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();
|
|
||||||
}
|
|
||||||
|
|
|
@ -5,14 +5,14 @@
|
||||||
|
|
||||||
#include "gpu_device.h"
|
#include "gpu_device.h"
|
||||||
|
|
||||||
|
#include "common/timer.h"
|
||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
class Timer;
|
|
||||||
|
|
||||||
class GPUPipeline;
|
class GPUPipeline;
|
||||||
class GPUSampler;
|
class GPUSampler;
|
||||||
class GPUTexture;
|
class GPUTexture;
|
||||||
|
@ -155,6 +155,8 @@ private:
|
||||||
std::vector<std::unique_ptr<PostProcessing::Shader>> m_stages;
|
std::vector<std::unique_ptr<PostProcessing::Shader>> m_stages;
|
||||||
std::unique_ptr<GPUTexture> m_input_texture;
|
std::unique_ptr<GPUTexture> m_input_texture;
|
||||||
std::unique_ptr<GPUTexture> m_output_texture;
|
std::unique_ptr<GPUTexture> m_output_texture;
|
||||||
|
|
||||||
|
static Timer::Value s_start_time;
|
||||||
};
|
};
|
||||||
|
|
||||||
// [display_name, filename]
|
// [display_name, filename]
|
||||||
|
@ -170,9 +172,6 @@ bool ReloadShaders();
|
||||||
|
|
||||||
void Shutdown();
|
void Shutdown();
|
||||||
|
|
||||||
GPUSampler* GetSampler(const GPUSampler::Config& config);
|
|
||||||
GPUTexture* GetDummyTexture();
|
|
||||||
|
|
||||||
extern Chain DisplayChain;
|
extern Chain DisplayChain;
|
||||||
extern Chain InternalChain;
|
extern Chain InternalChain;
|
||||||
|
|
||||||
|
|
|
@ -1258,7 +1258,7 @@ bool PostProcessing::ReShadeFXShader::CreatePasses(GPUTexture::Format backbuffer
|
||||||
|
|
||||||
DEV_LOG("Pass {} Texture {} => {}", pi.name, tb.texture_name, sampler.texture_id);
|
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)
|
if (!sampler.sampler)
|
||||||
{
|
{
|
||||||
Error::SetString(error, "Failed to create 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)
|
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)
|
else if (id == OUTPUT_COLOR_TEXTURE)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue