settings.cpp 11 KB

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