From 0a9c764dc4973cf17e982ee142b9929690b1aa73 Mon Sep 17 00:00:00 2001 From: iwubcode Date: Tue, 2 Feb 2021 23:02:41 -0600 Subject: [PATCH 1/2] VideoCommon: Join the prefetch thread before clearing to avoid a potential crash that can occur by multiple threads touching a single resource --- Source/Core/VideoCommon/HiresTextures.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/Source/Core/VideoCommon/HiresTextures.cpp b/Source/Core/VideoCommon/HiresTextures.cpp index cbb2566470..d55eadf022 100644 --- a/Source/Core/VideoCommon/HiresTextures.cpp +++ b/Source/Core/VideoCommon/HiresTextures.cpp @@ -56,14 +56,7 @@ void HiresTexture::Init() void HiresTexture::Shutdown() { - if (s_prefetcher.joinable()) - { - s_textureCacheAbortLoading.Set(); - s_prefetcher.join(); - } - - s_textureMap.clear(); - s_textureCache.clear(); + Clear(); } void HiresTexture::Update() @@ -147,6 +140,11 @@ void HiresTexture::Update() void HiresTexture::Clear() { + if (s_prefetcher.joinable()) + { + s_textureCacheAbortLoading.Set(); + s_prefetcher.join(); + } s_textureMap.clear(); s_textureCache.clear(); } From ce7db2e32bb60d4ef5f107dc913ff19f9ad39057 Mon Sep 17 00:00:00 2001 From: iwubcode Date: Tue, 2 Feb 2021 23:04:33 -0600 Subject: [PATCH 2/2] InputCommon: When using dynamic input textures, only call force reload textures once for packs that have multiple configurations --- .../InputCommon/DynamicInputTextureConfiguration.cpp | 12 ++---------- .../InputCommon/DynamicInputTextureConfiguration.h | 2 +- .../Core/InputCommon/DynamicInputTextureManager.cpp | 8 +++++++- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/Source/Core/InputCommon/DynamicInputTextureConfiguration.cpp b/Source/Core/InputCommon/DynamicInputTextureConfiguration.cpp index 171b74f3d2..d55099e856 100644 --- a/Source/Core/InputCommon/DynamicInputTextureConfiguration.cpp +++ b/Source/Core/InputCommon/DynamicInputTextureConfiguration.cpp @@ -17,10 +17,8 @@ #include "Common/Logging/Log.h" #include "Common/StringUtil.h" #include "Core/ConfigManager.h" -#include "Core/Core.h" #include "InputCommon/ControllerEmu/ControllerEmu.h" #include "InputCommon/ImageOperations.h" -#include "VideoCommon/RenderBase.h" namespace { @@ -251,7 +249,7 @@ DynamicInputTextureConfiguration::DynamicInputTextureConfiguration(const std::st DynamicInputTextureConfiguration::~DynamicInputTextureConfiguration() = default; -void DynamicInputTextureConfiguration::GenerateTextures(const IniFile::Section* sec, +bool DynamicInputTextureConfiguration::GenerateTextures(const IniFile::Section* sec, const std::string& controller_name) const { bool any_dirty = false; @@ -260,13 +258,7 @@ void DynamicInputTextureConfiguration::GenerateTextures(const IniFile::Section* any_dirty |= GenerateTexture(sec, controller_name, texture_data); } - if (!any_dirty) - return; - if (Core::GetState() == Core::State::Starting) - return; - if (!g_renderer) - return; - g_renderer->ForceReloadTextures(); + return any_dirty; } bool DynamicInputTextureConfiguration::GenerateTexture( diff --git a/Source/Core/InputCommon/DynamicInputTextureConfiguration.h b/Source/Core/InputCommon/DynamicInputTextureConfiguration.h index 15e4d37129..e5a4e722bf 100644 --- a/Source/Core/InputCommon/DynamicInputTextureConfiguration.h +++ b/Source/Core/InputCommon/DynamicInputTextureConfiguration.h @@ -19,7 +19,7 @@ class DynamicInputTextureConfiguration public: explicit DynamicInputTextureConfiguration(const std::string& json_file); ~DynamicInputTextureConfiguration(); - void GenerateTextures(const IniFile::Section* sec, const std::string& controller_name) const; + bool GenerateTextures(const IniFile::Section* sec, const std::string& controller_name) const; private: struct DynamicInputTextureData diff --git a/Source/Core/InputCommon/DynamicInputTextureManager.cpp b/Source/Core/InputCommon/DynamicInputTextureManager.cpp index 437d083ee9..31d0ee2aeb 100644 --- a/Source/Core/InputCommon/DynamicInputTextureManager.cpp +++ b/Source/Core/InputCommon/DynamicInputTextureManager.cpp @@ -10,9 +10,11 @@ #include "Common/FileSearch.h" #include "Common/FileUtil.h" #include "Core/ConfigManager.h" +#include "Core/Core.h" #include "InputCommon/DynamicInputTextureConfiguration.h" #include "VideoCommon/HiresTextures.h" +#include "VideoCommon/RenderBase.h" namespace InputCommon { @@ -41,9 +43,13 @@ void DynamicInputTextureManager::Load() void DynamicInputTextureManager::GenerateTextures(const IniFile::Section* sec, const std::string& controller_name) { + bool any_dirty = false; for (const auto& configuration : m_configuration) { - configuration.GenerateTextures(sec, controller_name); + any_dirty |= configuration.GenerateTextures(sec, controller_name); } + + if (any_dirty && g_renderer && Core::GetState() != Core::State::Starting) + g_renderer->ForceReloadTextures(); } } // namespace InputCommon