settings.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. // SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #include <version>
  4. #if __cpp_lib_chrono >= 201907L
  5. #include <chrono>
  6. #include <exception>
  7. #include <stdexcept>
  8. #endif
  9. #include <string_view>
  10. #include "common/assert.h"
  11. #include "common/fs/path_util.h"
  12. #include "common/logging/log.h"
  13. #include "common/settings.h"
  14. #include "common/time_zone.h"
  15. namespace Settings {
  16. Values values;
  17. static bool configuring_global = true;
  18. std::string GetTimeZoneString() {
  19. const auto time_zone_index = static_cast<std::size_t>(values.time_zone_index.GetValue());
  20. ASSERT(time_zone_index < Common::TimeZone::GetTimeZoneStrings().size());
  21. std::string location_name;
  22. if (time_zone_index == 0) { // Auto
  23. #if __cpp_lib_chrono >= 201907L && !defined(MINGW)
  24. // Disabled for MinGW -- tzdb always returns Etc/UTC
  25. try {
  26. const struct std::chrono::tzdb& time_zone_data = std::chrono::get_tzdb();
  27. const std::chrono::time_zone* current_zone = time_zone_data.current_zone();
  28. std::string_view current_zone_name = current_zone->name();
  29. location_name = current_zone_name;
  30. } catch (std::runtime_error& runtime_error) {
  31. // VCRUNTIME will throw a runtime_error if the operating system's selected time zone
  32. // cannot be found
  33. location_name = Common::TimeZone::FindSystemTimeZone();
  34. LOG_WARNING(Common,
  35. "Error occurred when trying to determine system time zone:\n{}\nFalling "
  36. "back to hour offset \"{}\"",
  37. runtime_error.what(), location_name);
  38. }
  39. #else
  40. location_name = Common::TimeZone::FindSystemTimeZone();
  41. #endif
  42. } else {
  43. location_name = Common::TimeZone::GetTimeZoneStrings()[time_zone_index];
  44. }
  45. return location_name;
  46. }
  47. void LogSettings() {
  48. const auto log_setting = [](std::string_view name, const auto& value) {
  49. LOG_INFO(Config, "{}: {}", name, value);
  50. };
  51. const auto log_path = [](std::string_view name, const std::filesystem::path& path) {
  52. LOG_INFO(Config, "{}: {}", name, Common::FS::PathToUTF8String(path));
  53. };
  54. LOG_INFO(Config, "yuzu Configuration:");
  55. log_setting("Controls_UseDockedMode", values.use_docked_mode.GetValue());
  56. log_setting("System_RngSeed", values.rng_seed.GetValue().value_or(0));
  57. log_setting("System_DeviceName", values.device_name.GetValue());
  58. log_setting("System_CurrentUser", values.current_user.GetValue());
  59. log_setting("System_LanguageIndex", values.language_index.GetValue());
  60. log_setting("System_RegionIndex", values.region_index.GetValue());
  61. log_setting("System_TimeZoneIndex", values.time_zone_index.GetValue());
  62. log_setting("System_UnsafeMemoryLayout", values.use_unsafe_extended_memory_layout.GetValue());
  63. log_setting("Core_UseMultiCore", values.use_multi_core.GetValue());
  64. log_setting("CPU_Accuracy", values.cpu_accuracy.GetValue());
  65. log_setting("Renderer_UseResolutionScaling", values.resolution_setup.GetValue());
  66. log_setting("Renderer_ScalingFilter", values.scaling_filter.GetValue());
  67. log_setting("Renderer_FSRSlider", values.fsr_sharpening_slider.GetValue());
  68. log_setting("Renderer_AntiAliasing", values.anti_aliasing.GetValue());
  69. log_setting("Renderer_UseSpeedLimit", values.use_speed_limit.GetValue());
  70. log_setting("Renderer_SpeedLimit", values.speed_limit.GetValue());
  71. log_setting("Renderer_UseDiskShaderCache", values.use_disk_shader_cache.GetValue());
  72. log_setting("Renderer_GPUAccuracyLevel", values.gpu_accuracy.GetValue());
  73. log_setting("Renderer_UseAsynchronousGpuEmulation",
  74. values.use_asynchronous_gpu_emulation.GetValue());
  75. log_setting("Renderer_NvdecEmulation", values.nvdec_emulation.GetValue());
  76. log_setting("Renderer_AccelerateASTC", values.accelerate_astc.GetValue());
  77. log_setting("Renderer_AsyncASTC", values.async_astc.GetValue());
  78. log_setting("Renderer_AstcRecompression", values.astc_recompression.GetValue());
  79. log_setting("Renderer_UseVsync", values.vsync_mode.GetValue());
  80. log_setting("Renderer_UseReactiveFlushing", values.use_reactive_flushing.GetValue());
  81. log_setting("Renderer_ShaderBackend", values.shader_backend.GetValue());
  82. log_setting("Renderer_UseAsynchronousShaders", values.use_asynchronous_shaders.GetValue());
  83. log_setting("Renderer_AnisotropicFilteringLevel", values.max_anisotropy.GetValue());
  84. log_setting("Audio_OutputEngine", values.sink_id.GetValue());
  85. log_setting("Audio_OutputDevice", values.audio_output_device_id.GetValue());
  86. log_setting("Audio_InputDevice", values.audio_input_device_id.GetValue());
  87. log_setting("DataStorage_UseVirtualSd", values.use_virtual_sd.GetValue());
  88. log_path("DataStorage_CacheDir", Common::FS::GetYuzuPath(Common::FS::YuzuPath::CacheDir));
  89. log_path("DataStorage_ConfigDir", Common::FS::GetYuzuPath(Common::FS::YuzuPath::ConfigDir));
  90. log_path("DataStorage_LoadDir", Common::FS::GetYuzuPath(Common::FS::YuzuPath::LoadDir));
  91. log_path("DataStorage_NANDDir", Common::FS::GetYuzuPath(Common::FS::YuzuPath::NANDDir));
  92. log_path("DataStorage_SDMCDir", Common::FS::GetYuzuPath(Common::FS::YuzuPath::SDMCDir));
  93. log_setting("Debugging_ProgramArgs", values.program_args.GetValue());
  94. log_setting("Debugging_GDBStub", values.use_gdbstub.GetValue());
  95. log_setting("Input_EnableMotion", values.motion_enabled.GetValue());
  96. log_setting("Input_EnableVibration", values.vibration_enabled.GetValue());
  97. log_setting("Input_EnableTouch", values.touchscreen.enabled);
  98. log_setting("Input_EnableMouse", values.mouse_enabled.GetValue());
  99. log_setting("Input_EnableKeyboard", values.keyboard_enabled.GetValue());
  100. log_setting("Input_EnableRingController", values.enable_ring_controller.GetValue());
  101. log_setting("Input_EnableIrSensor", values.enable_ir_sensor.GetValue());
  102. log_setting("Input_EnableCustomJoycon", values.enable_joycon_driver.GetValue());
  103. log_setting("Input_EnableCustomProController", values.enable_procon_driver.GetValue());
  104. log_setting("Input_EnableRawInput", values.enable_raw_input.GetValue());
  105. }
  106. bool IsConfiguringGlobal() {
  107. return configuring_global;
  108. }
  109. void SetConfiguringGlobal(bool is_global) {
  110. configuring_global = is_global;
  111. }
  112. bool IsGPULevelExtreme() {
  113. return values.gpu_accuracy.GetValue() == GPUAccuracy::Extreme;
  114. }
  115. bool IsGPULevelHigh() {
  116. return values.gpu_accuracy.GetValue() == GPUAccuracy::Extreme ||
  117. values.gpu_accuracy.GetValue() == GPUAccuracy::High;
  118. }
  119. bool IsFastmemEnabled() {
  120. if (values.cpu_debug_mode) {
  121. return static_cast<bool>(values.cpuopt_fastmem);
  122. }
  123. return true;
  124. }
  125. float Volume() {
  126. if (values.audio_muted) {
  127. return 0.0f;
  128. }
  129. return values.volume.GetValue() / static_cast<f32>(values.volume.GetDefault());
  130. }
  131. void UpdateRescalingInfo() {
  132. const auto setup = values.resolution_setup.GetValue();
  133. auto& info = values.resolution_info;
  134. info.downscale = false;
  135. switch (setup) {
  136. case ResolutionSetup::Res1_2X:
  137. info.up_scale = 1;
  138. info.down_shift = 1;
  139. info.downscale = true;
  140. break;
  141. case ResolutionSetup::Res3_4X:
  142. info.up_scale = 3;
  143. info.down_shift = 2;
  144. info.downscale = true;
  145. break;
  146. case ResolutionSetup::Res1X:
  147. info.up_scale = 1;
  148. info.down_shift = 0;
  149. break;
  150. case ResolutionSetup::Res3_2X:
  151. info.up_scale = 3;
  152. info.down_shift = 1;
  153. break;
  154. case ResolutionSetup::Res2X:
  155. info.up_scale = 2;
  156. info.down_shift = 0;
  157. break;
  158. case ResolutionSetup::Res3X:
  159. info.up_scale = 3;
  160. info.down_shift = 0;
  161. break;
  162. case ResolutionSetup::Res4X:
  163. info.up_scale = 4;
  164. info.down_shift = 0;
  165. break;
  166. case ResolutionSetup::Res5X:
  167. info.up_scale = 5;
  168. info.down_shift = 0;
  169. break;
  170. case ResolutionSetup::Res6X:
  171. info.up_scale = 6;
  172. info.down_shift = 0;
  173. break;
  174. case ResolutionSetup::Res7X:
  175. info.up_scale = 7;
  176. info.down_shift = 0;
  177. break;
  178. case ResolutionSetup::Res8X:
  179. info.up_scale = 8;
  180. info.down_shift = 0;
  181. break;
  182. default:
  183. ASSERT(false);
  184. info.up_scale = 1;
  185. info.down_shift = 0;
  186. break;
  187. }
  188. info.up_factor = static_cast<f32>(info.up_scale) / (1U << info.down_shift);
  189. info.down_factor = static_cast<f32>(1U << info.down_shift) / info.up_scale;
  190. info.active = info.up_scale != 1 || info.down_shift != 0;
  191. }
  192. void RestoreGlobalState(bool is_powered_on) {
  193. // If a game is running, DO NOT restore the global settings state
  194. if (is_powered_on) {
  195. return;
  196. }
  197. // Audio
  198. values.volume.SetGlobal(true);
  199. // Core
  200. values.use_multi_core.SetGlobal(true);
  201. values.use_unsafe_extended_memory_layout.SetGlobal(true);
  202. // CPU
  203. values.cpu_accuracy.SetGlobal(true);
  204. values.cpuopt_unsafe_unfuse_fma.SetGlobal(true);
  205. values.cpuopt_unsafe_reduce_fp_error.SetGlobal(true);
  206. values.cpuopt_unsafe_ignore_standard_fpcr.SetGlobal(true);
  207. values.cpuopt_unsafe_inaccurate_nan.SetGlobal(true);
  208. values.cpuopt_unsafe_fastmem_check.SetGlobal(true);
  209. values.cpuopt_unsafe_ignore_global_monitor.SetGlobal(true);
  210. // Renderer
  211. values.fsr_sharpening_slider.SetGlobal(true);
  212. values.renderer_backend.SetGlobal(true);
  213. values.async_presentation.SetGlobal(true);
  214. values.renderer_force_max_clock.SetGlobal(true);
  215. values.vulkan_device.SetGlobal(true);
  216. values.fullscreen_mode.SetGlobal(true);
  217. values.aspect_ratio.SetGlobal(true);
  218. values.resolution_setup.SetGlobal(true);
  219. values.scaling_filter.SetGlobal(true);
  220. values.anti_aliasing.SetGlobal(true);
  221. values.max_anisotropy.SetGlobal(true);
  222. values.use_speed_limit.SetGlobal(true);
  223. values.speed_limit.SetGlobal(true);
  224. values.use_disk_shader_cache.SetGlobal(true);
  225. values.gpu_accuracy.SetGlobal(true);
  226. values.use_asynchronous_gpu_emulation.SetGlobal(true);
  227. values.nvdec_emulation.SetGlobal(true);
  228. values.accelerate_astc.SetGlobal(true);
  229. values.async_astc.SetGlobal(true);
  230. values.astc_recompression.SetGlobal(true);
  231. values.use_reactive_flushing.SetGlobal(true);
  232. values.shader_backend.SetGlobal(true);
  233. values.use_asynchronous_shaders.SetGlobal(true);
  234. values.use_fast_gpu_time.SetGlobal(true);
  235. values.use_vulkan_driver_pipeline_cache.SetGlobal(true);
  236. values.bg_red.SetGlobal(true);
  237. values.bg_green.SetGlobal(true);
  238. values.bg_blue.SetGlobal(true);
  239. values.enable_compute_pipelines.SetGlobal(true);
  240. values.use_video_framerate.SetGlobal(true);
  241. // System
  242. values.language_index.SetGlobal(true);
  243. values.region_index.SetGlobal(true);
  244. values.time_zone_index.SetGlobal(true);
  245. values.rng_seed.SetGlobal(true);
  246. values.sound_index.SetGlobal(true);
  247. // Controls
  248. values.players.SetGlobal(true);
  249. values.use_docked_mode.SetGlobal(true);
  250. values.vibration_enabled.SetGlobal(true);
  251. values.motion_enabled.SetGlobal(true);
  252. }
  253. } // namespace Settings