From 87e3e4097f07187ee1e1c0e934755050d93a899c Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Fri, 25 Sep 2020 22:56:01 +1000 Subject: [PATCH] libretro: Use saves/duckstation_cache as shader cache directory --- .../libretro_host_interface.cpp | 30 ++++++++++++++++--- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/src/duckstation-libretro/libretro_host_interface.cpp b/src/duckstation-libretro/libretro_host_interface.cpp index e4c5df5c2..f9c7c5ab0 100644 --- a/src/duckstation-libretro/libretro_host_interface.cpp +++ b/src/duckstation-libretro/libretro_host_interface.cpp @@ -159,9 +159,31 @@ std::string LibretroHostInterface::GetGameMemoryCardPath(const char* game_code, std::string LibretroHostInterface::GetShaderCacheBasePath() const { - // TODO: Is there somewhere we can save our shaders? - Log_WarningPrint("No shader cache directory available, startup will be slower."); - return std::string(); + // Use the save directory, and failing that, the system directory. + const char* save_directory_ptr = nullptr; + if (!g_retro_environment_callback(RETRO_ENVIRONMENT_GET_SAVE_DIRECTORY, &save_directory_ptr) || !save_directory_ptr) + { + save_directory_ptr = nullptr; + if (!g_retro_environment_callback(RETRO_ENVIRONMENT_GET_SYSTEM_DIRECTORY, &save_directory_ptr) || + !save_directory_ptr) + { + Log_WarningPrint("No shader cache directory available, startup will be slower."); + return std::string(); + } + } + + // Use a directory named "duckstation_cache" in the save/system directory. + std::string shader_cache_path = StringUtil::StdStringFromFormat( + "%s" FS_OSPATH_SEPARATOR_STR "duckstation_cache" FS_OSPATH_SEPARATOR_STR, save_directory_ptr); + if (!FileSystem::DirectoryExists(shader_cache_path.c_str()) && + !FileSystem::CreateDirectory(shader_cache_path.c_str(), false)) + { + Log_ErrorPrintf("Failed to create shader cache directory: '%s'", shader_cache_path.c_str()); + return std::string(); + } + + Log_InfoPrintf("Shader cache directory: '%s'", shader_cache_path.c_str()); + return shader_cache_path; } std::string LibretroHostInterface::GetStringSettingValue(const char* section, const char* key, @@ -1031,7 +1053,7 @@ void LibretroHostInterface::SwitchToHardwareRenderer() wi.surface_height = avi.geometry.base_height; wi.surface_scale = 1.0f; if (!display || !display->CreateRenderDevice(wi, {}, g_settings.gpu_use_debug_device) || - !display->InitializeRenderDevice({}, g_settings.gpu_use_debug_device)) + !display->InitializeRenderDevice(GetShaderCacheBasePath(), g_settings.gpu_use_debug_device)) { Log_ErrorPrintf("Failed to create hardware host display"); return;