From 95dba598268f82ffe0d1b180893cd2759d7a5827 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Sat, 31 Oct 2020 14:39:38 +1000 Subject: [PATCH] libretro: Add MSAA options --- README.md | 1 + src/common/string_util.h | 5 ++++ .../libretro_host_interface.cpp | 24 ++++++++++++++++++- 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 797d40801..1237c36e2 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,7 @@ A "BIOS" ROM image is required to to start the emulator and to play games. You c ## Latest News +- 2020/10/31: Multisample antialiasing added as an enhancement. - 2020/10/30: Option to use analog stick as d-pad for analog controller added. - 2020/10/20: New cheat manager with memory scanning added. More features will be added over time. - 2020/10/05: CD-ROM read speedup enhancement added. diff --git a/src/common/string_util.h b/src/common/string_util.h index 891c689b8..f1a43111c 100644 --- a/src/common/string_util.h +++ b/src/common/string_util.h @@ -112,6 +112,11 @@ ALWAYS_INLINE static bool StartsWith(const std::string_view& str, const char* pr { return (str.compare(0, std::strlen(prefix), prefix) == 0); } +ALWAYS_INLINE static bool EndsWith(const std::string_view& str, const char* suffix) +{ + const std::size_t suffix_length = std::strlen(suffix); + return (str.length() >= suffix_length && str.compare(str.length() - suffix_length, suffix_length, suffix) == 0); +} #ifdef WIN32 diff --git a/src/duckstation-libretro/libretro_host_interface.cpp b/src/duckstation-libretro/libretro_host_interface.cpp index 38d7f62f6..18e0699ba 100644 --- a/src/duckstation-libretro/libretro_host_interface.cpp +++ b/src/duckstation-libretro/libretro_host_interface.cpp @@ -457,7 +457,7 @@ void LibretroHostInterface::OnSystemDestroyed() m_using_hardware_renderer = false; } -static std::array s_option_definitions = {{ +static std::array s_option_definitions = {{ {"duckstation_Console.Region", "Console Region", "Determines which region/hardware to emulate. Auto-Detect will use the region of the disc inserted.", @@ -559,6 +559,23 @@ static std::array s_option_definitions = {{ {"15", "15x"}, {"16", "16x"}}, "1"}, + {"duckstation_GPU.MSAA", + "Multisample Antialiasing", + "Uses multisample antialiasing for rendering 3D objects. Can smooth out jagged edges on polygons at a lower " + "cost to performance compared to increasing the resolution scale, but may be more likely to cause rendering " + "errors in some games.", + {{"1", "Disabled"}, + {"2", "2x MSAA"}, + {"4", "4x MSAA"}, + {"8", "8x MSAA"}, + {"16", "16x MSAA"}, + {"32", "32x MSAA"}, + {"2-ssaa", "2x SSAA"}, + {"4-ssaa", "4x SSAA"}, + {"8-ssaa", "8x SSAA"}, + {"16-ssaa", "16x SSAA"}, + {"32-ssaa", "32x SSAA"}}, + "1"}, {"duckstation_GPU.TrueColor", "True Color Rendering", "Disables dithering and uses the full 8 bits per channel of color information. May break rendering in some games.", @@ -781,6 +798,11 @@ void LibretroHostInterface::LoadSettings() g_settings.cpu_overclock_enable = (overclock_percent != 100); g_settings.UpdateOverclockActive(); + // convert msaa settings + const std::string msaa = si.GetStringValue("GPU", "MSAA", "1"); + g_settings.gpu_multisamples = StringUtil::FromChars(msaa).value_or(1); + g_settings.gpu_per_sample_shading = StringUtil::EndsWith(msaa, "-ssaa"); + // Ensure we don't use the standalone memcard directory in shared mode. for (u32 i = 0; i < NUM_CONTROLLER_AND_CARD_PORTS; i++) g_settings.memory_card_paths[i] = GetSharedMemoryCardPath(i);