PostProcessing: Refactor config to use separate sections

This commit is contained in:
Stenzek
2023-08-27 22:48:40 +10:00
parent 8db8baf33f
commit b217f64bcf
37 changed files with 1630 additions and 1555 deletions

View File

@ -190,4 +190,4 @@
</ClCompile>
</ItemDefinitionGroup>
<Import Project="..\..\dep\msvc\vsprops\Targets.props" />
</Project>
</Project>

View File

@ -121,4 +121,4 @@
<ClInclude Include="fullscreen_ui.h" />
<ClInclude Include="shader_cache_version.h" />
</ItemGroup>
</Project>
</Project>

View File

@ -24,9 +24,10 @@
#include "util/imgui_manager.h"
#include "util/ini_settings_interface.h"
#include "util/input_manager.h"
#include "util/postprocessing_chain.h"
#include "util/postprocessing.h"
#include "common/byte_stream.h"
#include "common/error.h"
#include "common/file_system.h"
#include "common/log.h"
#include "common/make_array.h"
@ -201,6 +202,12 @@ enum class GameListPage
Count
};
struct PostProcessingStageInfo
{
std::string name;
std::vector<PostProcessing::ShaderOption> options;
};
//////////////////////////////////////////////////////////////////////////
// Utility
//////////////////////////////////////////////////////////////////////////
@ -382,8 +389,7 @@ static void DrawFolderSetting(SettingsInterface* bsi, const char* title, const c
static void PopulateGraphicsAdapterList();
static void PopulateGameListDirectoryCache(SettingsInterface* si);
static void PopulatePostProcessingChain();
static void SavePostProcessingChain();
static void PopulatePostProcessingChain(SettingsInterface* si);
static void BeginInputBinding(SettingsInterface* bsi, InputBindingInfo::Type type, const std::string_view& section,
const std::string_view& key, const std::string_view& display_name);
static void DrawInputBindingWindow();
@ -398,7 +404,7 @@ static std::unique_ptr<GameList::Entry> s_game_settings_entry;
static std::vector<std::pair<std::string, bool>> s_game_list_directories_cache;
static std::vector<std::string> s_graphics_adapter_list_cache;
static std::vector<std::string> s_fullscreen_mode_list_cache;
static PostProcessingChain s_postprocessing_chain;
static std::vector<PostProcessingStageInfo> s_postprocessing_stages;
static std::vector<const HotkeyInfo*> s_hotkey_list_cache;
static std::atomic_bool s_settings_changed{false};
static std::atomic_bool s_game_settings_changed{false};
@ -741,7 +747,7 @@ void FullscreenUI::Shutdown()
s_cover_image_map.clear();
s_game_list_sorted_entries = {};
s_game_list_directories_cache = {};
s_postprocessing_chain.ClearStages();
s_postprocessing_stages = {};
s_fullscreen_mode_list_cache = {};
s_graphics_adapter_list_cache = {};
s_hotkey_list_cache = {};
@ -2386,7 +2392,7 @@ void FullscreenUI::SwitchToSettings()
s_game_settings_interface.reset();
PopulateGraphicsAdapterList();
PopulatePostProcessingChain();
PopulatePostProcessingChain(GetEditingSettingsInterface());
s_current_main_window = MainWindowType::Settings;
s_settings_page = SettingsPage::Interface;
@ -3967,18 +3973,17 @@ void FullscreenUI::DrawDisplaySettingsPage()
EndMenuButtons();
}
void FullscreenUI::PopulatePostProcessingChain()
void FullscreenUI::PopulatePostProcessingChain(SettingsInterface* si)
{
std::string chain_value(GetEditingSettingsInterface()->GetStringValue("Display", "PostProcessChain", ""));
s_postprocessing_chain.CreateFromString(chain_value);
}
void FullscreenUI::SavePostProcessingChain()
{
SettingsInterface* bsi = GetEditingSettingsInterface();
const std::string config(s_postprocessing_chain.GetConfigString());
bsi->SetStringValue("Display", "PostProcessChain", config.c_str());
SetSettingsChanged(bsi);
const u32 stages = PostProcessing::Config::GetStageCount(*si);
s_postprocessing_stages.reserve(stages);
for (u32 i = 0; i < stages; i++)
{
PostProcessingStageInfo psi;
psi.name = PostProcessing::Config::GetStageShaderName(*si, i);
psi.options = PostProcessing::Config::GetStageOptions(*si, i);
s_postprocessing_stages.push_back(std::move(psi));
}
}
enum
@ -4005,7 +4010,7 @@ void FullscreenUI::DrawPostProcessingSettingsPage()
FSUI_CSTR("Reloads the shaders from disk, applying any changes."),
bsi->GetBoolValue("Display", "PostProcessing", false)))
{
if (!g_gpu || g_gpu->UpdatePostProcessingChain())
if (System::IsValid() && PostProcessing::ReloadShaders())
ShowToast(std::string(), FSUI_STR("Post-processing shaders reloaded."));
}
@ -4013,25 +4018,32 @@ void FullscreenUI::DrawPostProcessingSettingsPage()
if (MenuButton(FSUI_ICONSTR(ICON_FA_PLUS, "Add Shader"), FSUI_CSTR("Adds a new shader to the chain.")))
{
std::vector<std::pair<std::string, std::string>> shaders = PostProcessing::GetAvailableShaderNames();
ImGuiFullscreen::ChoiceDialogOptions options;
for (std::string& name : PostProcessingChain::GetAvailableShaderNames())
options.emplace_back(std::move(name), false);
options.reserve(shaders.size());
for (auto& [display_name, name] : shaders)
options.emplace_back(std::move(display_name), false);
OpenChoiceDialog(FSUI_ICONSTR(ICON_FA_PLUS, "Add Shader"), false, std::move(options),
[](s32 index, const std::string& title, bool checked) {
if (index < 0)
[shaders = std::move(shaders)](s32 index, const std::string& title, bool checked) {
if (index < 0 || static_cast<u32>(index) >= shaders.size())
return;
if (s_postprocessing_chain.AddStage(title))
const std::string& shader_name = shaders[index].second;
SettingsInterface* bsi = GetEditingSettingsInterface();
Error error;
if (PostProcessing::Config::AddStage(*bsi, shader_name, &error))
{
ShowToast(std::string(), fmt::format(FSUI_FSTR("Shader {} added as stage {}."), title,
s_postprocessing_chain.GetStageCount()));
SavePostProcessingChain();
PostProcessing::Config::GetStageCount(*bsi)));
PopulatePostProcessingChain(bsi);
SetSettingsChanged(bsi);
}
else
{
ShowToast(std::string(),
fmt::format(FSUI_FSTR("Failed to load shader {}. It may be invalid."), title));
fmt::format(FSUI_FSTR("Failed to load shader {}. It may be invalid.\nError was:"),
title, error.GetDescription()));
}
CloseChoiceDialog();
@ -4047,9 +4059,11 @@ void FullscreenUI::DrawPostProcessingSettingsPage()
if (!confirmed)
return;
s_postprocessing_chain.ClearStages();
SettingsInterface* bsi = GetEditingSettingsInterface();
PostProcessing::Config::ClearStages(*bsi);
PopulatePostProcessingChain(bsi);
SetSettingsChanged(bsi);
ShowToast(std::string(), FSUI_STR("Post-processing chain cleared."));
SavePostProcessingChain();
});
}
@ -4058,11 +4072,12 @@ void FullscreenUI::DrawPostProcessingSettingsPage()
SmallString str;
SmallString tstr;
for (u32 stage_index = 0; stage_index < s_postprocessing_chain.GetStageCount(); stage_index++)
for (u32 stage_index = 0; stage_index < static_cast<u32>(s_postprocessing_stages.size()); stage_index++)
{
PostProcessingStageInfo& si = s_postprocessing_stages[stage_index];
ImGui::PushID(stage_index);
PostProcessingShader* stage = s_postprocessing_chain.GetShaderStage(stage_index);
str.Fmt(FSUI_FSTR("Stage {}: {}"), stage_index + 1, stage->GetName());
str.Fmt(FSUI_FSTR("Stage {}: {}"), stage_index + 1, si.name);
MenuHeading(str);
if (MenuButton(FSUI_ICONSTR(ICON_FA_TIMES, "Remove From Chain"), FSUI_CSTR("Removes this shader from the chain.")))
@ -4080,17 +4095,20 @@ void FullscreenUI::DrawPostProcessingSettingsPage()
if (MenuButton(FSUI_ICONSTR(ICON_FA_ARROW_DOWN, "Move Down"),
FSUI_CSTR("Moves this shader lower in the chain, applying it later."),
(stage_index != (s_postprocessing_chain.GetStageCount() - 1))))
(stage_index != (s_postprocessing_stages.size() - 1))))
{
postprocessing_action = POSTPROCESSING_ACTION_MOVE_DOWN;
postprocessing_action_index = stage_index;
}
for (PostProcessingShader::Option& opt : stage->GetOptions())
for (PostProcessing::ShaderOption& opt : si.options)
{
if (opt.ui_name.empty())
continue;
switch (opt.type)
{
case PostProcessingShader::Option::Type::Bool:
case PostProcessing::ShaderOption::Type::Bool:
{
bool value = (opt.value[0].int_value != 0);
tstr.Fmt(ICON_FA_COGS "{}", opt.ui_name);
@ -4100,12 +4118,13 @@ void FullscreenUI::DrawPostProcessingSettingsPage()
&value))
{
opt.value[0].int_value = (value != 0);
SavePostProcessingChain();
PostProcessing::Config::SetStageOption(*bsi, stage_index, opt);
SetSettingsChanged(bsi);
}
}
break;
case PostProcessingShader::Option::Type::Float:
case PostProcessing::ShaderOption::Type::Float:
{
tstr.Fmt(ICON_FA_RULER_VERTICAL "{}##{}", opt.ui_name, opt.name);
str.Fmt(FSUI_FSTR("Value: {} | Default: {} | Minimum: {} | Maximum: {}"), opt.value[0].float_value,
@ -4148,48 +4167,44 @@ void FullscreenUI::DrawPostProcessingSettingsPage()
}
#else
ImGui::SetNextItemWidth(end);
bool changed = false;
switch (opt.vector_size)
{
case 1:
{
if (ImGui::SliderFloat("##value", &opt.value[0].float_value, opt.min_value[0].float_value,
opt.max_value[0].float_value))
{
SavePostProcessingChain();
}
changed = ImGui::SliderFloat("##value", &opt.value[0].float_value, opt.min_value[0].float_value,
opt.max_value[0].float_value);
}
break;
case 2:
{
if (ImGui::SliderFloat2("##value", &opt.value[0].float_value, opt.min_value[0].float_value,
opt.max_value[0].float_value))
{
SavePostProcessingChain();
}
changed = ImGui::SliderFloat2("##value", &opt.value[0].float_value, opt.min_value[0].float_value,
opt.max_value[0].float_value);
}
break;
case 3:
{
if (ImGui::SliderFloat3("##value", &opt.value[0].float_value, opt.min_value[0].float_value,
opt.max_value[0].float_value))
{
SavePostProcessingChain();
}
changed = ImGui::SliderFloat3("##value", &opt.value[0].float_value, opt.min_value[0].float_value,
opt.max_value[0].float_value);
}
break;
case 4:
{
if (ImGui::SliderFloat4("##value", &opt.value[0].float_value, opt.min_value[0].float_value,
opt.max_value[0].float_value))
{
SavePostProcessingChain();
}
changed = ImGui::SliderFloat4("##value", &opt.value[0].float_value, opt.min_value[0].float_value,
opt.max_value[0].float_value);
}
break;
}
if (changed)
{
PostProcessing::Config::SetStageOption(*bsi, stage_index, opt);
SetSettingsChanged(bsi);
}
#endif
ImGui::SetCursorPosY(ImGui::GetCursorPosY() + LayoutScale(10.0f));
@ -4208,7 +4223,7 @@ void FullscreenUI::DrawPostProcessingSettingsPage()
}
break;
case PostProcessingShader::Option::Type::Int:
case PostProcessing::ShaderOption::Type::Int:
{
tstr.Fmt(ICON_FA_RULER_VERTICAL "{}##{}", opt.ui_name, opt.name);
str.Fmt(FSUI_FSTR("Value: {} | Default: {} | Minimum: {} | Maximum: {}"), opt.value[0].int_value,
@ -4250,49 +4265,44 @@ void FullscreenUI::DrawPostProcessingSettingsPage()
}
}
#else
bool changed = false;
ImGui::SetNextItemWidth(end);
switch (opt.vector_size)
{
case 1:
{
if (ImGui::SliderInt("##value", &opt.value[0].int_value, opt.min_value[0].int_value,
opt.max_value[0].int_value))
{
SavePostProcessingChain();
}
changed = ImGui::SliderInt("##value", &opt.value[0].int_value, opt.min_value[0].int_value,
opt.max_value[0].int_value);
}
break;
case 2:
{
if (ImGui::SliderInt2("##value", &opt.value[0].int_value, opt.min_value[0].int_value,
opt.max_value[0].int_value))
{
SavePostProcessingChain();
}
changed = ImGui::SliderInt2("##value", &opt.value[0].int_value, opt.min_value[0].int_value,
opt.max_value[0].int_value);
}
break;
case 3:
{
if (ImGui::SliderInt2("##value", &opt.value[0].int_value, opt.min_value[0].int_value,
opt.max_value[0].int_value))
{
SavePostProcessingChain();
}
changed = ImGui::SliderInt2("##value", &opt.value[0].int_value, opt.min_value[0].int_value,
opt.max_value[0].int_value);
}
break;
case 4:
{
if (ImGui::SliderInt4("##value", &opt.value[0].int_value, opt.min_value[0].int_value,
opt.max_value[0].int_value))
{
SavePostProcessingChain();
}
changed = ImGui::SliderInt4("##value", &opt.value[0].int_value, opt.min_value[0].int_value,
opt.max_value[0].int_value);
}
break;
}
if (changed)
{
PostProcessing::Config::SetStageOption(*bsi, stage_index, opt);
SetSettingsChanged(bsi);
}
#endif
ImGui::SetCursorPosY(ImGui::GetCursorPosY() + LayoutScale(10.0f));
@ -4320,23 +4330,26 @@ void FullscreenUI::DrawPostProcessingSettingsPage()
{
case POSTPROCESSING_ACTION_REMOVE:
{
PostProcessingShader* stage = s_postprocessing_chain.GetShaderStage(postprocessing_action_index);
const PostProcessingStageInfo& si = s_postprocessing_stages[postprocessing_action_index];
ShowToast(std::string(),
fmt::format(FSUI_FSTR("Removed stage {} ({})."), postprocessing_action_index + 1, stage->GetName()));
s_postprocessing_chain.RemoveStage(postprocessing_action_index);
SavePostProcessingChain();
fmt::format(FSUI_FSTR("Removed stage {} ({})."), postprocessing_action_index + 1, si.name));
PostProcessing::Config::RemoveStage(*bsi, postprocessing_action_index);
PopulatePostProcessingChain(bsi);
SetSettingsChanged(bsi);
}
break;
case POSTPROCESSING_ACTION_MOVE_UP:
{
s_postprocessing_chain.MoveStageUp(postprocessing_action_index);
SavePostProcessingChain();
PostProcessing::Config::MoveStageUp(*bsi, postprocessing_action_index);
PopulatePostProcessingChain(bsi);
SetSettingsChanged(bsi);
}
break;
case POSTPROCESSING_ACTION_MOVE_DOWN:
{
s_postprocessing_chain.MoveStageDown(postprocessing_action_index);
SavePostProcessingChain();
PostProcessing::Config::MoveStageDown(*bsi, postprocessing_action_index);
PopulatePostProcessingChain(bsi);
SetSettingsChanged(bsi);
}
break;
default:

View File

@ -12,7 +12,7 @@
#include "util/gpu_device.h"
#include "util/imgui_manager.h"
#include "util/postprocessing_chain.h"
#include "util/postprocessing.h"
#include "util/shadergen.h"
#include "util/state_wrapper.h"
@ -65,8 +65,6 @@ bool GPU::Initialize()
return false;
}
UpdatePostProcessingChain();
g_gpu_device->SetGPUTimingEnabled(g_settings.display_show_gpu);
return true;
@ -1637,12 +1635,12 @@ bool GPU::RenderDisplay(GPUFramebuffer* target, const Common::Rectangle<s32>& dr
(target && target->GetRT()) ? target->GetRT()->GetFormat() : g_gpu_device->GetWindowFormat();
const u32 target_width = target ? target->GetWidth() : g_gpu_device->GetWindowWidth();
const u32 target_height = target ? target->GetHeight() : g_gpu_device->GetWindowHeight();
const bool really_postfx = (postfx && HasDisplayTexture() && m_post_processing_chain &&
m_post_processing_chain->CheckTargets(hdformat, target_width, target_height));
const bool really_postfx = (postfx && HasDisplayTexture() && PostProcessing::IsActive() &&
PostProcessing::CheckTargets(hdformat, target_width, target_height));
if (really_postfx)
{
g_gpu_device->ClearRenderTarget(m_post_processing_chain->GetInputTexture(), 0);
g_gpu_device->SetFramebuffer(m_post_processing_chain->GetInputFramebuffer());
g_gpu_device->ClearRenderTarget(PostProcessing::GetInputTexture(), 0);
g_gpu_device->SetFramebuffer(PostProcessing::GetInputFramebuffer());
}
else
{
@ -1676,7 +1674,7 @@ bool GPU::RenderDisplay(GPUFramebuffer* target, const Common::Rectangle<s32>& dr
if (really_postfx)
{
return m_post_processing_chain->Apply(target, draw_rect.left, draw_rect.top, draw_rect.GetWidth(),
return PostProcessing::Apply(target, draw_rect.left, draw_rect.top, draw_rect.GetWidth(),
draw_rect.GetHeight(), m_display_texture_view_width,
m_display_texture_view_height);
}
@ -1686,25 +1684,6 @@ bool GPU::RenderDisplay(GPUFramebuffer* target, const Common::Rectangle<s32>& dr
}
}
bool GPU::UpdatePostProcessingChain()
{
if (!g_settings.display_post_processing || g_settings.display_post_process_chain.empty())
{
m_post_processing_chain.reset();
return true;
}
m_post_processing_chain = std::make_unique<PostProcessingChain>();
if (!m_post_processing_chain->CreateFromString(g_settings.display_post_process_chain))
{
Host::AddOSDMessage(TRANSLATE_STR("OSDMessage", "Failed to load post processing shader chain."), 20.0f);
m_post_processing_chain.reset();
return false;
}
return true;
}
Common::Rectangle<float> GPU::CalculateDrawRect(s32 window_width, s32 window_height, float* out_left_padding,
float* out_top_padding, float* out_scale, float* out_x_scale,
bool apply_aspect_ratio /* = true */) const

View File

@ -27,8 +27,6 @@ class GPUFramebuffer;
class GPUTexture;
class GPUPipeline;
class PostProcessingChain;
class TimingEvent;
namespace Threading {
@ -207,8 +205,6 @@ public:
/// Draws the current display texture, with any post-processing.
bool PresentDisplay();
bool UpdatePostProcessingChain();
protected:
TickCount CRTCTicksToSystemTicks(TickCount crtc_ticks, TickCount fractional_ticks) const;
TickCount SystemTicksToCRTCTicks(TickCount sysclk_ticks, TickCount* fractional_ticks) const;
@ -603,8 +599,6 @@ protected:
s32 m_display_texture_view_width = 0;
s32 m_display_texture_view_height = 0;
std::unique_ptr<PostProcessingChain> m_post_processing_chain;
struct Stats
{
u32 num_vram_reads;

View File

@ -15,6 +15,7 @@
#include "util/gpu_device.h"
#include "util/input_manager.h"
#include "util/postprocessing.h"
#include "common/file_system.h"
@ -345,13 +346,13 @@ DEFINE_HOTKEY("DecreaseResolutionScale", TRANSLATE_NOOP("Hotkeys", "Graphics"),
DEFINE_HOTKEY("TogglePostProcessing", TRANSLATE_NOOP("Hotkeys", "Graphics"),
TRANSLATE_NOOP("Hotkeys", "Toggle Post-Processing"), [](s32 pressed) {
if (!pressed && System::IsValid())
System::TogglePostProcessing();
PostProcessing::Toggle();
})
DEFINE_HOTKEY("ReloadPostProcessingShaders", TRANSLATE_NOOP("Hotkeys", "Graphics"),
TRANSLATE_NOOP("Hotkeys", "Reload Post Processing Shaders"), [](s32 pressed) {
if (!pressed && System::IsValid())
System::ReloadPostProcessingShaders();
PostProcessing::ReloadShaders();
})
DEFINE_HOTKEY("ReloadTextureReplacements", TRANSLATE_NOOP("Hotkeys", "Graphics"),

View File

@ -264,7 +264,6 @@ void Settings::Load(SettingsInterface& si)
display_linear_filtering = si.GetBoolValue("Display", "LinearFiltering", true);
display_integer_scaling = si.GetBoolValue("Display", "IntegerScaling", false);
display_stretch = si.GetBoolValue("Display", "Stretch", false);
display_post_processing = si.GetBoolValue("Display", "PostProcessing", false);
display_show_osd_messages = si.GetBoolValue("Display", "ShowOSDMessages", true);
display_show_fps = si.GetBoolValue("Display", "ShowFPS", false);
display_show_speed = si.GetBoolValue("Display", "ShowSpeed", false);
@ -279,7 +278,6 @@ void Settings::Load(SettingsInterface& si)
display_internal_resolution_screenshots = si.GetBoolValue("Display", "InternalResolutionScreenshots", false);
display_stretch_vertically = si.GetBoolValue("Display", "StretchVertically", false);
video_sync_enabled = si.GetBoolValue("Display", "VSync", DEFAULT_VSYNC_VALUE);
display_post_process_chain = si.GetStringValue("Display", "PostProcessChain", "");
display_max_fps = si.GetFloatValue("Display", "MaxFPS", DEFAULT_DISPLAY_MAX_FPS);
display_osd_scale = si.GetFloatValue("Display", "OSDScale", DEFAULT_OSD_SCALE);
@ -486,7 +484,6 @@ void Settings::Save(SettingsInterface& si) const
si.SetBoolValue("Display", "LinearFiltering", display_linear_filtering);
si.SetBoolValue("Display", "IntegerScaling", display_integer_scaling);
si.SetBoolValue("Display", "Stretch", display_stretch);
si.SetBoolValue("Display", "PostProcessing", display_post_processing);
si.SetBoolValue("Display", "ShowOSDMessages", display_show_osd_messages);
si.SetBoolValue("Display", "ShowFPS", display_show_fps);
si.SetBoolValue("Display", "ShowSpeed", display_show_speed);
@ -501,10 +498,6 @@ void Settings::Save(SettingsInterface& si) const
si.SetBoolValue("Display", "InternalResolutionScreenshots", display_internal_resolution_screenshots);
si.SetBoolValue("Display", "StretchVertically", display_stretch_vertically);
si.SetBoolValue("Display", "VSync", video_sync_enabled);
if (display_post_process_chain.empty())
si.DeleteValue("Display", "PostProcessChain");
else
si.SetStringValue("Display", "PostProcessChain", display_post_process_chain.c_str());
si.SetFloatValue("Display", "MaxFPS", display_max_fps);
si.SetFloatValue("Display", "OSDScale", display_osd_scale);

View File

@ -94,7 +94,6 @@ struct Settings
GPURenderer gpu_renderer = DEFAULT_GPU_RENDERER;
std::string gpu_adapter;
std::string display_post_process_chain;
u32 gpu_resolution_scale = 1;
u32 gpu_multisamples = 1;
bool gpu_use_thread = true;
@ -132,7 +131,6 @@ struct Settings
bool display_linear_filtering = true;
bool display_integer_scaling = false;
bool display_stretch = false;
bool display_post_processing = false;
bool display_show_osd_messages = true;
bool display_show_fps = false;
bool display_show_speed = false;

View File

@ -41,6 +41,7 @@
#include "util/input_manager.h"
#include "util/iso_reader.h"
#include "util/platform_misc.h"
#include "util/postprocessing.h"
#include "util/state_wrapper.h"
#include "common/error.h"
@ -117,7 +118,7 @@ static void DestroySystem();
static std::string GetMediaPathFromSaveState(const char* path);
static bool DoLoadState(ByteStream* stream, bool force_software_renderer, bool update_display);
static bool DoState(StateWrapper& sw, GPUTexture** host_texture, bool update_display, bool is_memory_state);
static bool CreateGPU(GPURenderer renderer);
static bool CreateGPU(GPURenderer renderer, bool is_switching);
static bool SaveUndoLoadState();
/// Throttles the system, i.e. sleeps until it's time to execute the next frame.
@ -869,7 +870,7 @@ std::string System::GetInputProfilePath(const std::string_view& name)
return Path::Combine(EmuFolders::InputProfiles, fmt::format("{}.ini", name));
}
bool System::RecreateGPU(GPURenderer renderer, bool force_recreate_display, bool update_display /* = true*/)
bool System::RecreateGPU(GPURenderer renderer, bool force_recreate_device, bool update_display /* = true*/)
{
ClearMemorySaveStates();
g_gpu->RestoreGraphicsAPIState();
@ -883,10 +884,10 @@ bool System::RecreateGPU(GPURenderer renderer, bool force_recreate_display, bool
// create new renderer
g_gpu.reset();
if (force_recreate_display)
if (force_recreate_device)
Host::ReleaseGPUDevice();
if (!CreateGPU(renderer))
if (!CreateGPU(renderer, true))
{
if (!IsStartupCancelled())
Host::ReportErrorAsync("Error", "Failed to recreate GPU.");
@ -1530,7 +1531,7 @@ bool System::Initialize(bool force_software_renderer)
return false;
}
if (!CreateGPU(force_software_renderer ? GPURenderer::Software : g_settings.gpu_renderer))
if (!CreateGPU(force_software_renderer ? GPURenderer::Software : g_settings.gpu_renderer, false))
{
Bus::Shutdown();
CPU::Shutdown();
@ -1571,6 +1572,7 @@ bool System::Initialize(bool force_software_renderer)
MDEC::Initialize();
SIO::Initialize();
PCDrv::Initialize();
PostProcessing::Initialize();
static constexpr float WARNING_DURATION = 15.0f;
@ -1619,6 +1621,8 @@ void System::DestroySystem()
Host::ClearOSDMessages();
PostProcessing::Shutdown();
SaveStateSelectorUI::Close(true);
FullscreenUI::OnSystemDestroyed();
@ -1971,7 +1975,7 @@ void System::RecreateSystem()
PauseSystem(true);
}
bool System::CreateGPU(GPURenderer renderer)
bool System::CreateGPU(GPURenderer renderer, bool is_switching)
{
const RenderAPI api = Settings::GetRenderAPIForRenderer(renderer);
@ -1981,6 +1985,7 @@ bool System::CreateGPU(GPURenderer renderer)
{
Log_WarningPrintf("Recreating GPU device, expecting %s got %s", GPUDevice::RenderAPIToString(api),
GPUDevice::RenderAPIToString(g_gpu_device->GetRenderAPI()));
PostProcessing::Shutdown();
}
Host::ReleaseGPUDevice();
@ -1989,6 +1994,9 @@ bool System::CreateGPU(GPURenderer renderer)
Host::ReleaseRenderWindow();
return false;
}
if (is_switching)
PostProcessing::Initialize();
}
if (renderer == GPURenderer::Software)
@ -3482,13 +3490,13 @@ void System::CheckForSettingsChanges(const Settings& old_settings)
g_settings.gpu_threaded_presentation != old_settings.gpu_threaded_presentation))
{
// if debug device/threaded presentation change, we need to recreate the whole display
const bool recreate_display = (g_settings.gpu_use_debug_device != old_settings.gpu_use_debug_device ||
const bool recreate_device = (g_settings.gpu_use_debug_device != old_settings.gpu_use_debug_device ||
g_settings.gpu_threaded_presentation != old_settings.gpu_threaded_presentation);
Host::AddFormattedOSDMessage(5.0f, TRANSLATE("OSDMessage", "Switching to %s%s GPU renderer."),
Settings::GetRendererName(g_settings.gpu_renderer),
g_settings.gpu_use_debug_device ? " (debug)" : "");
RecreateGPU(g_settings.gpu_renderer, recreate_display);
RecreateGPU(g_settings.gpu_renderer, recreate_device);
}
if (IsValid())
@ -3661,12 +3669,6 @@ void System::CheckForSettingsChanges(const Settings& old_settings)
UpdateSpeedLimiterState();
}
if (g_settings.display_post_processing != old_settings.display_post_processing ||
g_settings.display_post_process_chain != old_settings.display_post_process_chain)
{
g_gpu->UpdatePostProcessingChain();
}
if (g_settings.inhibit_screensaver != old_settings.inhibit_screensaver)
{
if (g_settings.inhibit_screensaver)
@ -3674,6 +3676,8 @@ void System::CheckForSettingsChanges(const Settings& old_settings)
else
PlatformMisc::ResumeScreensaver();
}
PostProcessing::UpdateSettings();
}
if (g_gpu_device && g_settings.display_osd_scale != old_settings.display_osd_scale)
@ -4525,29 +4529,6 @@ void System::ApplyCheatCode(u32 index)
}
}
void System::TogglePostProcessing()
{
if (!IsValid())
return;
g_settings.display_post_processing = !g_settings.display_post_processing;
Host::AddKeyedOSDMessage("PostProcessing",
g_settings.display_post_processing ?
TRANSLATE_STR("OSDMessage", "Post-processing is now enabled.") :
TRANSLATE_STR("OSDMessage", "Post-processing is now disabled."),
Host::OSD_QUICK_DURATION);
g_gpu->UpdatePostProcessingChain();
}
void System::ReloadPostProcessingShaders()
{
if (!IsValid() || !g_settings.display_post_processing)
return;
if (!g_gpu->UpdatePostProcessingChain())
Host::AddOSDMessage(TRANSLATE_STR("OSDMessage", "Post-processing shaders reloaded."), Host::OSD_ERROR_DURATION);
}
void System::ToggleWidescreen()
{
g_settings.gpu_widescreen_hack = !g_settings.gpu_widescreen_hack;

View File

@ -246,7 +246,7 @@ void Execute();
void RecreateSystem();
/// Recreates the GPU component, saving/loading the state so it is preserved. Call when the GPU renderer changes.
bool RecreateGPU(GPURenderer renderer, bool force_recreate_display = false, bool update_display = true);
bool RecreateGPU(GPURenderer renderer, bool force_recreate_device = false, bool update_display = true);
void SingleStepCPU();
@ -425,12 +425,6 @@ void SetCheatCodeState(u32 index, bool enabled, bool save_to_file);
/// Immediately applies the specified cheat code.
void ApplyCheatCode(u32 index);
/// Temporarily toggles post-processing on/off.
void TogglePostProcessing();
/// Reloads post processing shaders with the current configuration.
void ReloadPostProcessingShaders();
/// Toggle Widescreen Hack and Aspect Ratio
void ToggleWidescreen();