From 9fa24700b69b98b2569f4bd1353482cbfb1ec2d7 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Thu, 1 Mar 2018 18:03:24 +1000 Subject: [PATCH] VideoConfig: Collapse ubershader configuration fields to a single value --- Source/Core/Core/Analytics.cpp | 13 +++++--- Source/Core/Core/Config/GraphicsSettings.cpp | 8 ++--- Source/Core/Core/Config/GraphicsSettings.h | 4 +-- .../Core/ConfigLoaders/IsSettingSaveable.cpp | 4 +-- .../Config/Graphics/EnhancementsWidget.cpp | 19 ++---------- Source/Core/DolphinWX/VideoConfigDiag.cpp | 29 +++-------------- Source/Core/DolphinWX/VideoConfigDiag.h | 1 - Source/Core/VideoCommon/ShaderCache.cpp | 2 +- Source/Core/VideoCommon/VertexManagerBase.cpp | 27 +++++++--------- Source/Core/VideoCommon/VideoConfig.cpp | 16 +--------- Source/Core/VideoCommon/VideoConfig.h | 31 ++++++------------- 11 files changed, 42 insertions(+), 112 deletions(-) diff --git a/Source/Core/Core/Analytics.cpp b/Source/Core/Core/Analytics.cpp index 39f62b3f13..db881d61de 100644 --- a/Source/Core/Core/Analytics.cpp +++ b/Source/Core/Core/Analytics.cpp @@ -180,13 +180,16 @@ void DolphinAnalytics::MakeBaseBuilder() static const char* GetUbershaderMode(const VideoConfig& video_config) { - if (video_config.bDisableSpecializedShaders) + switch (video_config.iUberShaderMode) + { + case UberShaderMode::Exclusive: return "exclusive"; - - if (video_config.bBackgroundShaderCompiling) + case UberShaderMode::Hybrid: return "hybrid"; - - return "disabled"; + case UberShaderMode::Disabled: + default: + return "disabled"; + } } void DolphinAnalytics::MakePerGameBuilder() diff --git a/Source/Core/Core/Config/GraphicsSettings.cpp b/Source/Core/Core/Config/GraphicsSettings.cpp index 5f8d4c102a..b06ccdaf41 100644 --- a/Source/Core/Core/Config/GraphicsSettings.cpp +++ b/Source/Core/Core/Config/GraphicsSettings.cpp @@ -76,12 +76,8 @@ const ConfigInfo GFX_BACKEND_MULTITHREADING{ const ConfigInfo GFX_COMMAND_BUFFER_EXECUTE_INTERVAL{ {System::GFX, "Settings", "CommandBufferExecuteInterval"}, 100}; const ConfigInfo GFX_SHADER_CACHE{{System::GFX, "Settings", "ShaderCache"}, true}; -const ConfigInfo GFX_BACKGROUND_SHADER_COMPILING{ - {System::GFX, "Settings", "BackgroundShaderCompiling"}, false}; -const ConfigInfo GFX_DISABLE_SPECIALIZED_SHADERS{ - {System::GFX, "Settings", "DisableSpecializedShaders"}, false}; -const ConfigInfo GFX_PRECOMPILE_UBER_SHADERS{ - {System::GFX, "Settings", "PrecompileUberShaders"}, true}; +const ConfigInfo GFX_UBERSHADER_MODE{{System::GFX, "Settings", "UberShaderMode"}, + static_cast(UberShaderMode::Disabled)}; const ConfigInfo GFX_SHADER_COMPILER_THREADS{ {System::GFX, "Settings", "ShaderCompilerThreads"}, 1}; const ConfigInfo GFX_SHADER_PRECOMPILER_THREADS{ diff --git a/Source/Core/Core/Config/GraphicsSettings.h b/Source/Core/Core/Config/GraphicsSettings.h index 70613bee00..5f07d1906a 100644 --- a/Source/Core/Core/Config/GraphicsSettings.h +++ b/Source/Core/Core/Config/GraphicsSettings.h @@ -59,9 +59,7 @@ extern const ConfigInfo GFX_ENABLE_VALIDATION_LAYER; extern const ConfigInfo GFX_BACKEND_MULTITHREADING; extern const ConfigInfo GFX_COMMAND_BUFFER_EXECUTE_INTERVAL; extern const ConfigInfo GFX_SHADER_CACHE; -extern const ConfigInfo GFX_BACKGROUND_SHADER_COMPILING; -extern const ConfigInfo GFX_DISABLE_SPECIALIZED_SHADERS; -extern const ConfigInfo GFX_PRECOMPILE_UBER_SHADERS; +extern const ConfigInfo GFX_UBERSHADER_MODE; extern const ConfigInfo GFX_SHADER_COMPILER_THREADS; extern const ConfigInfo GFX_SHADER_PRECOMPILER_THREADS; diff --git a/Source/Core/Core/ConfigLoaders/IsSettingSaveable.cpp b/Source/Core/Core/ConfigLoaders/IsSettingSaveable.cpp index d625ba3dce..abc30b24d3 100644 --- a/Source/Core/Core/ConfigLoaders/IsSettingSaveable.cpp +++ b/Source/Core/Core/ConfigLoaders/IsSettingSaveable.cpp @@ -46,9 +46,7 @@ bool IsSettingSaveable(const Config::ConfigLocation& config_location) Config::GFX_DISABLE_FOG.location, Config::GFX_BORDERLESS_FULLSCREEN.location, Config::GFX_ENABLE_VALIDATION_LAYER.location, Config::GFX_BACKEND_MULTITHREADING.location, Config::GFX_COMMAND_BUFFER_EXECUTE_INTERVAL.location, Config::GFX_SHADER_CACHE.location, - Config::GFX_BACKGROUND_SHADER_COMPILING.location, - Config::GFX_DISABLE_SPECIALIZED_SHADERS.location, - Config::GFX_PRECOMPILE_UBER_SHADERS.location, Config::GFX_SHADER_COMPILER_THREADS.location, + Config::GFX_UBERSHADER_MODE.location, Config::GFX_SHADER_COMPILER_THREADS.location, Config::GFX_SHADER_PRECOMPILER_THREADS.location, Config::GFX_SW_ZCOMPLOC.location, Config::GFX_SW_ZFREEZE.location, diff --git a/Source/Core/DolphinQt2/Config/Graphics/EnhancementsWidget.cpp b/Source/Core/DolphinQt2/Config/Graphics/EnhancementsWidget.cpp index 8182e65d85..b6baa9819f 100644 --- a/Source/Core/DolphinQt2/Config/Graphics/EnhancementsWidget.cpp +++ b/Source/Core/DolphinQt2/Config/Graphics/EnhancementsWidget.cpp @@ -63,9 +63,8 @@ void EnhancementsWidget::CreateWidgets() m_af_combo = new GraphicsChoice({tr("1x"), tr("2x"), tr("4x"), tr("8x"), tr("16x")}, Config::GFX_ENHANCE_MAX_ANISOTROPY); - m_ubershader_combo = new QComboBox; - for (const auto& option : {tr("Disabled"), tr("Hybrid"), tr("Exclusive")}) - m_ubershader_combo->addItem(option); + m_ubershader_combo = new GraphicsChoice({tr("Disabled"), tr("Hybrid"), tr("Exclusive")}, + Config::GFX_UBERSHADER_MODE); m_pp_effect = new QComboBox(); m_configure_pp_effect = new QPushButton(tr("Configure")); @@ -131,9 +130,6 @@ void EnhancementsWidget::ConnectWidgets() { connect(m_aa_combo, static_cast(&QComboBox::currentIndexChanged), [this](int) { SaveSettings(); }); - connect(m_ubershader_combo, - static_cast(&QComboBox::currentIndexChanged), - [this](int) { SaveSettings(); }); connect(m_pp_effect, static_cast(&QComboBox::currentIndexChanged), [this](int) { SaveSettings(); }); connect(m_3d_mode, static_cast(&QComboBox::currentIndexChanged), @@ -156,13 +152,6 @@ void EnhancementsWidget::LoadSettings() QString::fromStdString(std::to_string(aa_selection) + "x " + (ssaa ? "SSAA" : "MSAA"))); m_aa_combo->setEnabled(m_aa_combo->count() > 1); - if (Config::GetBase(Config::GFX_DISABLE_SPECIALIZED_SHADERS)) - m_ubershader_combo->setCurrentIndex(2); - else if (Config::GetBase(Config::GFX_BACKGROUND_SHADER_COMPILING)) - m_ubershader_combo->setCurrentIndex(1); - else - m_ubershader_combo->setCurrentIndex(0); - // Post Processing Shader std::vector shaders = g_Config.stereo_mode == StereoMode::Anaglyph ? @@ -220,10 +209,6 @@ void EnhancementsWidget::SaveSettings() Config::SetBaseOrCurrent(Config::GFX_SSAA, is_ssaa); - int us_value = m_ubershader_combo->currentIndex(); - Config::SetBaseOrCurrent(Config::GFX_BACKGROUND_SHADER_COMPILING, us_value == 1); - Config::SetBaseOrCurrent(Config::GFX_DISABLE_SPECIALIZED_SHADERS, us_value == 2); - Config::SetBaseOrCurrent(Config::GFX_ENHANCE_POST_SHADER, m_pp_effect->currentText().toStdString()); diff --git a/Source/Core/DolphinWX/VideoConfigDiag.cpp b/Source/Core/DolphinWX/VideoConfigDiag.cpp index a4dfebfbed..874508459e 100644 --- a/Source/Core/DolphinWX/VideoConfigDiag.cpp +++ b/Source/Core/DolphinWX/VideoConfigDiag.cpp @@ -534,24 +534,13 @@ VideoConfigDiag::VideoConfigDiag(wxWindow* parent, const std::string& title) // ubershaders { const std::array mode_choices = {{_("Disabled"), _("Hybrid"), _("Exclusive")}}; - - wxChoice* const choice_mode = - new wxChoice(page_enh, wxID_ANY, wxDefaultPosition, wxDefaultSize, - static_cast(mode_choices.size()), mode_choices.data()); - RegisterControl(choice_mode, wxGetTranslation(ubershader_desc)); szr_enh->Add(new wxStaticText(page_enh, wxID_ANY, _("Ubershaders:")), wxGBPosition(row, 0), wxDefaultSpan, wxALIGN_CENTER_VERTICAL); - szr_enh->Add(choice_mode, wxGBPosition(row, 1), span2, wxALIGN_CENTER_VERTICAL); + szr_enh->Add(CreateChoice(page_enh, Config::GFX_UBERSHADER_MODE, + wxGetTranslation(ubershader_desc), mode_choices.size(), + mode_choices.data()), + wxGBPosition(row, 1), span2, wxALIGN_CENTER_VERTICAL); row += 1; - - // Determine ubershader mode - choice_mode->Bind(wxEVT_CHOICE, &VideoConfigDiag::OnUberShaderModeChanged, this); - if (Config::GetBase(Config::GFX_DISABLE_SPECIALIZED_SHADERS)) - choice_mode->SetSelection(2); - else if (Config::GetBase(Config::GFX_BACKGROUND_SHADER_COMPILING)) - choice_mode->SetSelection(1); - else - choice_mode->SetSelection(0); } // postproc shader @@ -1290,13 +1279,3 @@ void VideoConfigDiag::OnAAChanged(wxCommandEvent& ev) Config::SetBaseOrCurrent(Config::GFX_MSAA, vconfig.backend_info.AAModes[mode]); } - -void VideoConfigDiag::OnUberShaderModeChanged(wxCommandEvent& ev) -{ - // 0: No ubershaders - // 1: Hybrid ubershaders - // 2: Only ubershaders - int mode = ev.GetInt(); - Config::SetBaseOrCurrent(Config::GFX_BACKGROUND_SHADER_COMPILING, mode == 1); - Config::SetBaseOrCurrent(Config::GFX_DISABLE_SPECIALIZED_SHADERS, mode == 2); -} diff --git a/Source/Core/DolphinWX/VideoConfigDiag.h b/Source/Core/DolphinWX/VideoConfigDiag.h index d02d344325..a15472885a 100644 --- a/Source/Core/DolphinWX/VideoConfigDiag.h +++ b/Source/Core/DolphinWX/VideoConfigDiag.h @@ -139,7 +139,6 @@ protected: void PopulatePostProcessingShaders(); void PopulateAAList(); void OnAAChanged(wxCommandEvent& ev); - void OnUberShaderModeChanged(wxCommandEvent& ev); wxChoice* choice_backend; wxChoice* choice_adapter; diff --git a/Source/Core/VideoCommon/ShaderCache.cpp b/Source/Core/VideoCommon/ShaderCache.cpp index 1e4a0ef741..43a31dfd6b 100644 --- a/Source/Core/VideoCommon/ShaderCache.cpp +++ b/Source/Core/VideoCommon/ShaderCache.cpp @@ -38,7 +38,7 @@ bool ShaderCache::Initialize() } // Queue ubershader precompiling if required. - if (g_ActiveConfig.CanPrecompileUberShaders()) + if (g_ActiveConfig.UsingUberShaders()) PrecompileUberShaders(); // Compile all known UIDs. diff --git a/Source/Core/VideoCommon/VertexManagerBase.cpp b/Source/Core/VideoCommon/VertexManagerBase.cpp index f32ac72b0a..b54b8060b9 100644 --- a/Source/Core/VideoCommon/VertexManagerBase.cpp +++ b/Source/Core/VideoCommon/VertexManagerBase.cpp @@ -566,27 +566,24 @@ void VertexManagerBase::UpdatePipelineObject() m_current_pipeline_object = nullptr; m_pipeline_config_changed = false; - // Try for specialized shaders. - if (!g_ActiveConfig.bDisableSpecializedShaders) + if (g_ActiveConfig.iUberShaderMode == UberShaderMode::Disabled) + { + // Ubershaders disabled? Block and compile the specialized shader. + m_current_pipeline_object = g_shader_cache->GetPipelineForUid(m_current_pipeline_config); + return; + } + else if (g_ActiveConfig.iUberShaderMode == UberShaderMode::Hybrid) { // Can we background compile shaders? If so, get the pipeline asynchronously. - if (g_ActiveConfig.bBackgroundShaderCompiling) + auto res = g_shader_cache->GetPipelineForUidAsync(m_current_pipeline_config); + if (res) { - auto res = g_shader_cache->GetPipelineForUidAsync(m_current_pipeline_config); - if (res) - { - // Specialized shaders are ready. - m_current_pipeline_object = *res; - return; - } - } - else - { - m_current_pipeline_object = g_shader_cache->GetPipelineForUid(m_current_pipeline_config); + // Specialized shaders are ready, prefer these. + m_current_pipeline_object = *res; return; } } - // Fallback to ubershaders. + // Exclusive ubershader mode, or hybrid and shaders are still compiling. m_current_pipeline_object = g_shader_cache->GetUberPipelineForUid(m_current_uber_pipeline_config); } diff --git a/Source/Core/VideoCommon/VideoConfig.cpp b/Source/Core/VideoCommon/VideoConfig.cpp index d8c0dfaa6c..c14a00757a 100644 --- a/Source/Core/VideoCommon/VideoConfig.cpp +++ b/Source/Core/VideoCommon/VideoConfig.cpp @@ -102,9 +102,7 @@ void VideoConfig::Refresh() bBackendMultithreading = Config::Get(Config::GFX_BACKEND_MULTITHREADING); iCommandBufferExecuteInterval = Config::Get(Config::GFX_COMMAND_BUFFER_EXECUTE_INTERVAL); bShaderCache = Config::Get(Config::GFX_SHADER_CACHE); - bBackgroundShaderCompiling = Config::Get(Config::GFX_BACKGROUND_SHADER_COMPILING); - bDisableSpecializedShaders = Config::Get(Config::GFX_DISABLE_SPECIALIZED_SHADERS); - bPrecompileUberShaders = Config::Get(Config::GFX_PRECOMPILE_UBER_SHADERS); + iUberShaderMode = static_cast(Config::Get(Config::GFX_UBERSHADER_MODE)); iShaderCompilerThreads = Config::Get(Config::GFX_SHADER_COMPILER_THREADS); iShaderPrecompilerThreads = Config::Get(Config::GFX_SHADER_PRECOMPILER_THREADS); @@ -206,15 +204,3 @@ u32 VideoConfig::GetShaderPrecompilerThreads() const else return GetNumAutoShaderCompilerThreads(); } - -bool VideoConfig::CanPrecompileUberShaders() const -{ - // We don't want to precompile ubershaders if they're never going to be used. - return bPrecompileUberShaders && (bBackgroundShaderCompiling || bDisableSpecializedShaders); -} - -bool VideoConfig::CanBackgroundCompileShaders() const -{ - // We require precompiled ubershaders to background compile shaders. - return bBackgroundShaderCompiling && bPrecompileUberShaders; -} diff --git a/Source/Core/VideoCommon/VideoConfig.h b/Source/Core/VideoCommon/VideoConfig.h index 7839cb0e8f..2b69919528 100644 --- a/Source/Core/VideoCommon/VideoConfig.h +++ b/Source/Core/VideoCommon/VideoConfig.h @@ -42,6 +42,13 @@ enum class StereoMode : int Nvidia3DVision }; +enum class UberShaderMode : int +{ + Disabled, + Hybrid, + Exclusive +}; + struct ProjectionHackConfig final { bool m_enable; @@ -161,25 +168,8 @@ struct VideoConfig final // Currently only supported with Vulkan. int iCommandBufferExecuteInterval; - // The following options determine the ubershader mode: - // No ubershaders: - // - bBackgroundShaderCompiling = false - // - bDisableSpecializedShaders = false - // Hybrid/background compiling: - // - bBackgroundShaderCompiling = true - // - bDisableSpecializedShaders = false - // Ubershaders only: - // - bBackgroundShaderCompiling = false - // - bDisableSpecializedShaders = true - - // Enable background shader compiling, use ubershaders while waiting. - bool bBackgroundShaderCompiling; - - // Use ubershaders only, don't compile specialized shaders. - bool bDisableSpecializedShaders; - - // Precompile ubershader variants at boot/config reload time. - bool bPrecompileUberShaders; + // Shader compilation settings. + UberShaderMode iUberShaderMode; // Number of shader compiler threads. // 0 disables background compilation. @@ -247,10 +237,9 @@ struct VideoConfig final return backend_info.bSupportsGPUTextureDecoding && bEnableGPUTextureDecoding; } bool UseVertexRounding() const { return bVertexRounding && iEFBScale != 1; } + bool UsingUberShaders() const { return iUberShaderMode != UberShaderMode::Disabled; } u32 GetShaderCompilerThreads() const; u32 GetShaderPrecompilerThreads() const; - bool CanPrecompileUberShaders() const; - bool CanBackgroundCompileShaders() const; }; extern VideoConfig g_Config;