From ac48b2eea43164349e6b112604d44490a4d731c5 Mon Sep 17 00:00:00 2001 From: Pokechu22 Date: Sun, 9 Apr 2023 23:15:41 -0700 Subject: [PATCH] EnhancementsWidget: Handle gaps in AA mode list Mesa (llvmpipe) only reports 4x MSAA, and doesn't report 2x (or 1x, but we implicitly add that). The old logic did not handle this correctly, causing selecting 4x to fail and fall back to None. This also removes VideoUtils::GetAvailableAntialiasingModes, and thus VideoUtils entirely, as its only other function was removed in 1f74653501fec1dd059705f8a3eff1edb259d4d9. --- Source/Core/DolphinLib.props | 2 - .../Config/Graphics/EnhancementsWidget.cpp | 50 +++++++++++-------- Source/Core/UICommon/CMakeLists.txt | 2 - Source/Core/UICommon/VideoUtils.cpp | 43 ---------------- Source/Core/UICommon/VideoUtils.h | 12 ----- 5 files changed, 28 insertions(+), 81 deletions(-) delete mode 100644 Source/Core/UICommon/VideoUtils.cpp delete mode 100644 Source/Core/UICommon/VideoUtils.h diff --git a/Source/Core/DolphinLib.props b/Source/Core/DolphinLib.props index 05142ae672..ec9ac2065a 100644 --- a/Source/Core/DolphinLib.props +++ b/Source/Core/DolphinLib.props @@ -534,7 +534,6 @@ - @@ -1160,7 +1159,6 @@ - diff --git a/Source/Core/DolphinQt/Config/Graphics/EnhancementsWidget.cpp b/Source/Core/DolphinQt/Config/Graphics/EnhancementsWidget.cpp index 113c9fe835..c5889d2ad4 100644 --- a/Source/Core/DolphinQt/Config/Graphics/EnhancementsWidget.cpp +++ b/Source/Core/DolphinQt/Config/Graphics/EnhancementsWidget.cpp @@ -23,8 +23,6 @@ #include "DolphinQt/QtUtils/NonDefaultQPushButton.h" #include "DolphinQt/Settings.h" -#include "UICommon/VideoUtils.h" - #include "VideoCommon/PostProcessing.h" #include "VideoCommon/VideoBackendBase.h" #include "VideoCommon/VideoCommon.h" @@ -260,18 +258,38 @@ void EnhancementsWidget::LoadSettings() m_block_save = true; // Anti-Aliasing - const int aa_selection = Config::Get(Config::GFX_MSAA); + const u32 aa_selection = Config::Get(Config::GFX_MSAA); const bool ssaa = Config::Get(Config::GFX_SSAA); const int aniso = Config::Get(Config::GFX_ENHANCE_MAX_ANISOTROPY); const TextureFilteringMode tex_filter_mode = Config::Get(Config::GFX_ENHANCE_FORCE_TEXTURE_FILTERING); m_aa_combo->clear(); - for (const auto& option : VideoUtils::GetAvailableAntialiasingModes(m_msaa_modes)) - m_aa_combo->addItem(option == "None" ? tr("None") : QString::fromStdString(option)); - m_aa_combo->setCurrentText( - QString::fromStdString(std::to_string(aa_selection) + "x " + (ssaa ? "SSAA" : "MSAA"))); + for (const u32 aa_mode : g_Config.backend_info.AAModes) + { + if (aa_mode == 1) + m_aa_combo->addItem(tr("None"), 1); + else + m_aa_combo->addItem(tr("%1x MSAA").arg(aa_mode), static_cast(aa_mode)); + + if (aa_mode == aa_selection && !ssaa) + m_aa_combo->setCurrentIndex(m_aa_combo->count() - 1); + } + if (g_Config.backend_info.bSupportsSSAA) + { + for (const u32 aa_mode : g_Config.backend_info.AAModes) + { + if (aa_mode != 1) // don't show "None" twice + { + // Mark SSAA using negative values in the variant + m_aa_combo->addItem(tr("%1x SSAA").arg(aa_mode), -static_cast(aa_mode)); + if (aa_mode == aa_selection && ssaa) + m_aa_combo->setCurrentIndex(m_aa_combo->count() - 1); + } + } + } + m_aa_combo->setEnabled(m_aa_combo->count() > 1); switch (tex_filter_mode) @@ -310,22 +328,10 @@ void EnhancementsWidget::SaveSettings() if (m_block_save) return; - bool is_ssaa = m_aa_combo->currentText().endsWith(QStringLiteral("SSAA")); - - int aa_value = m_aa_combo->currentIndex(); - - if (aa_value == 0) - { - aa_value = 1; - } - else - { - if (aa_value > m_msaa_modes) - aa_value -= m_msaa_modes; - aa_value = std::pow(2, aa_value); - } - Config::SetBaseOrCurrent(Config::GFX_MSAA, static_cast(aa_value)); + const u32 aa_value = static_cast(std::abs(m_aa_combo->currentData().toInt())); + const bool is_ssaa = m_aa_combo->currentData().toInt() < 0; + Config::SetBaseOrCurrent(Config::GFX_MSAA, aa_value); Config::SetBaseOrCurrent(Config::GFX_SSAA, is_ssaa); const int texture_filtering_selection = m_texture_filtering_combo->currentData().toInt(); diff --git a/Source/Core/UICommon/CMakeLists.txt b/Source/Core/UICommon/CMakeLists.txt index f2ffbd0821..947aeae346 100644 --- a/Source/Core/UICommon/CMakeLists.txt +++ b/Source/Core/UICommon/CMakeLists.txt @@ -23,8 +23,6 @@ add_library(uicommon UICommon.h USBUtils.cpp USBUtils.h - VideoUtils.cpp - VideoUtils.h ) target_link_libraries(uicommon diff --git a/Source/Core/UICommon/VideoUtils.cpp b/Source/Core/UICommon/VideoUtils.cpp deleted file mode 100644 index 17947e81b2..0000000000 --- a/Source/Core/UICommon/VideoUtils.cpp +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright 2017 Dolphin Emulator Project -// SPDX-License-Identifier: GPL-2.0-or-later - -#include "UICommon/VideoUtils.h" - -#include "Common/Assert.h" -#include "VideoCommon/VideoConfig.h" - -namespace VideoUtils -{ -std::vector GetAvailableAntialiasingModes(int& msaa_modes) -{ - std::vector modes; - const auto& aa_modes = g_Config.backend_info.AAModes; - const bool supports_ssaa = g_Config.backend_info.bSupportsSSAA; - msaa_modes = 0; - - for (const auto mode : aa_modes) - { - if (mode == 1) - { - modes.push_back("None"); - ASSERT_MSG(VIDEO, !supports_ssaa || msaa_modes == 0, "SSAA setting won't work correctly"); - } - else - { - modes.push_back(std::to_string(mode) + "x MSAA"); - msaa_modes++; - } - } - - if (supports_ssaa) - { - for (const auto mode : aa_modes) - { - if (mode != 1) - modes.push_back(std::to_string(mode) + "x SSAA"); - } - } - - return modes; -} -} // namespace VideoUtils diff --git a/Source/Core/UICommon/VideoUtils.h b/Source/Core/UICommon/VideoUtils.h deleted file mode 100644 index 492813adab..0000000000 --- a/Source/Core/UICommon/VideoUtils.h +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright 2017 Dolphin Emulator Project -// SPDX-License-Identifier: GPL-2.0-or-later - -#pragma once - -#include -#include - -namespace VideoUtils -{ -std::vector GetAvailableAntialiasingModes(int& m_msaa_modes); -} // namespace VideoUtils