settings.cpp 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. // SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #include <string_view>
  4. #include "common/assert.h"
  5. #include "common/fs/path_util.h"
  6. #include "common/logging/log.h"
  7. #include "common/settings.h"
  8. namespace Settings {
  9. Values values;
  10. static bool configuring_global = true;
  11. std::string GetTimeZoneString() {
  12. static constexpr std::array timezones{
  13. "auto", "default", "CET", "CST6CDT", "Cuba", "EET", "Egypt", "Eire",
  14. "EST", "EST5EDT", "GB", "GB-Eire", "GMT", "GMT+0", "GMT-0", "GMT0",
  15. "Greenwich", "Hongkong", "HST", "Iceland", "Iran", "Israel", "Jamaica", "Japan",
  16. "Kwajalein", "Libya", "MET", "MST", "MST7MDT", "Navajo", "NZ", "NZ-CHAT",
  17. "Poland", "Portugal", "PRC", "PST8PDT", "ROC", "ROK", "Singapore", "Turkey",
  18. "UCT", "Universal", "UTC", "W-SU", "WET", "Zulu",
  19. };
  20. const auto time_zone_index = static_cast<std::size_t>(values.time_zone_index.GetValue());
  21. ASSERT(time_zone_index < timezones.size());
  22. return timezones[time_zone_index];
  23. }
  24. void LogSettings() {
  25. const auto log_setting = [](std::string_view name, const auto& value) {
  26. LOG_INFO(Config, "{}: {}", name, value);
  27. };
  28. const auto log_path = [](std::string_view name, const std::filesystem::path& path) {
  29. LOG_INFO(Config, "{}: {}", name, Common::FS::PathToUTF8String(path));
  30. };
  31. LOG_INFO(Config, "yuzu Configuration:");
  32. log_setting("Controls_UseDockedMode", values.use_docked_mode.GetValue());
  33. log_setting("System_RngSeed", values.rng_seed.GetValue().value_or(0));
  34. log_setting("System_DeviceName", values.device_name.GetValue());
  35. log_setting("System_CurrentUser", values.current_user.GetValue());
  36. log_setting("System_LanguageIndex", values.language_index.GetValue());
  37. log_setting("System_RegionIndex", values.region_index.GetValue());
  38. log_setting("System_TimeZoneIndex", values.time_zone_index.GetValue());
  39. log_setting("Core_UseMultiCore", values.use_multi_core.GetValue());
  40. log_setting("CPU_Accuracy", values.cpu_accuracy.GetValue());
  41. log_setting("Renderer_UseResolutionScaling", values.resolution_setup.GetValue());
  42. log_setting("Renderer_ScalingFilter", values.scaling_filter.GetValue());
  43. log_setting("Renderer_FSRSlider", values.fsr_sharpening_slider.GetValue());
  44. log_setting("Renderer_AntiAliasing", values.anti_aliasing.GetValue());
  45. log_setting("Renderer_UseSpeedLimit", values.use_speed_limit.GetValue());
  46. log_setting("Renderer_SpeedLimit", values.speed_limit.GetValue());
  47. log_setting("Renderer_UseDiskShaderCache", values.use_disk_shader_cache.GetValue());
  48. log_setting("Renderer_GPUAccuracyLevel", values.gpu_accuracy.GetValue());
  49. log_setting("Renderer_UseAsynchronousGpuEmulation",
  50. values.use_asynchronous_gpu_emulation.GetValue());
  51. log_setting("Renderer_NvdecEmulation", values.nvdec_emulation.GetValue());
  52. log_setting("Renderer_AccelerateASTC", values.accelerate_astc.GetValue());
  53. log_setting("Renderer_AsyncASTC", values.async_astc.GetValue());
  54. log_setting("Renderer_UseVsync", values.use_vsync.GetValue());
  55. log_setting("Renderer_ShaderBackend", values.shader_backend.GetValue());
  56. log_setting("Renderer_UseAsynchronousShaders", values.use_asynchronous_shaders.GetValue());
  57. log_setting("Renderer_AnisotropicFilteringLevel", values.max_anisotropy.GetValue());
  58. log_setting("Audio_OutputEngine", values.sink_id.GetValue());
  59. log_setting("Audio_OutputDevice", values.audio_output_device_id.GetValue());
  60. log_setting("Audio_InputDevice", values.audio_input_device_id.GetValue());
  61. log_setting("DataStorage_UseVirtualSd", values.use_virtual_sd.GetValue());
  62. log_path("DataStorage_CacheDir", Common::FS::GetYuzuPath(Common::FS::YuzuPath::CacheDir));
  63. log_path("DataStorage_ConfigDir", Common::FS::GetYuzuPath(Common::FS::YuzuPath::ConfigDir));
  64. log_path("DataStorage_LoadDir", Common::FS::GetYuzuPath(Common::FS::YuzuPath::LoadDir));
  65. log_path("DataStorage_NANDDir", Common::FS::GetYuzuPath(Common::FS::YuzuPath::NANDDir));
  66. log_path("DataStorage_SDMCDir", Common::FS::GetYuzuPath(Common::FS::YuzuPath::SDMCDir));
  67. log_setting("Debugging_ProgramArgs", values.program_args.GetValue());
  68. log_setting("Debugging_GDBStub", values.use_gdbstub.GetValue());
  69. log_setting("Input_EnableMotion", values.motion_enabled.GetValue());
  70. log_setting("Input_EnableVibration", values.vibration_enabled.GetValue());
  71. log_setting("Input_EnableTouch", values.touchscreen.enabled);
  72. log_setting("Input_EnableMouse", values.mouse_enabled.GetValue());
  73. log_setting("Input_EnableKeyboard", values.keyboard_enabled.GetValue());
  74. log_setting("Input_EnableRingController", values.enable_ring_controller.GetValue());
  75. log_setting("Input_EnableIrSensor", values.enable_ir_sensor.GetValue());
  76. log_setting("Input_EnableCustomJoycon", values.enable_joycon_driver.GetValue());
  77. log_setting("Input_EnableCustomProController", values.enable_procon_driver.GetValue());
  78. log_setting("Input_EnableRawInput", values.enable_raw_input.GetValue());
  79. }
  80. bool IsConfiguringGlobal() {
  81. return configuring_global;
  82. }
  83. void SetConfiguringGlobal(bool is_global) {
  84. configuring_global = is_global;
  85. }
  86. bool IsGPULevelExtreme() {
  87. return values.gpu_accuracy.GetValue() == GPUAccuracy::Extreme;
  88. }
  89. bool IsGPULevelHigh() {
  90. return values.gpu_accuracy.GetValue() == GPUAccuracy::Extreme ||
  91. values.gpu_accuracy.GetValue() == GPUAccuracy::High;
  92. }
  93. bool IsFastmemEnabled() {
  94. if (values.cpu_debug_mode) {
  95. return static_cast<bool>(values.cpuopt_fastmem);
  96. }
  97. return true;
  98. }
  99. float Volume() {
  100. if (values.audio_muted) {
  101. return 0.0f;
  102. }
  103. return values.volume.GetValue() / static_cast<f32>(values.volume.GetDefault());
  104. }
  105. void UpdateRescalingInfo() {
  106. const auto setup = values.resolution_setup.GetValue();
  107. auto& info = values.resolution_info;
  108. info.downscale = false;
  109. switch (setup) {
  110. case ResolutionSetup::Res1_2X:
  111. info.up_scale = 1;
  112. info.down_shift = 1;
  113. info.downscale = true;
  114. break;
  115. case ResolutionSetup::Res3_4X:
  116. info.up_scale = 3;
  117. info.down_shift = 2;
  118. info.downscale = true;
  119. break;
  120. case ResolutionSetup::Res1X:
  121. info.up_scale = 1;
  122. info.down_shift = 0;
  123. break;
  124. case ResolutionSetup::Res3_2X:
  125. info.up_scale = 3;
  126. info.down_shift = 1;
  127. break;
  128. case ResolutionSetup::Res2X:
  129. info.up_scale = 2;
  130. info.down_shift = 0;
  131. break;
  132. case ResolutionSetup::Res3X:
  133. info.up_scale = 3;
  134. info.down_shift = 0;
  135. break;
  136. case ResolutionSetup::Res4X:
  137. info.up_scale = 4;
  138. info.down_shift = 0;
  139. break;
  140. case ResolutionSetup::Res5X:
  141. info.up_scale = 5;
  142. info.down_shift = 0;
  143. break;
  144. case ResolutionSetup::Res6X:
  145. info.up_scale = 6;
  146. info.down_shift = 0;
  147. break;
  148. case ResolutionSetup::Res7X:
  149. info.up_scale = 7;
  150. info.down_shift = 0;
  151. break;
  152. case ResolutionSetup::Res8X:
  153. info.up_scale = 8;
  154. info.down_shift = 0;
  155. break;
  156. default:
  157. ASSERT(false);
  158. info.up_scale = 1;
  159. info.down_shift = 0;
  160. break;
  161. }
  162. info.up_factor = static_cast<f32>(info.up_scale) / (1U << info.down_shift);
  163. info.down_factor = static_cast<f32>(1U << info.down_shift) / info.up_scale;
  164. info.active = info.up_scale != 1 || info.down_shift != 0;
  165. }
  166. void RestoreGlobalState(bool is_powered_on) {
  167. // If a game is running, DO NOT restore the global settings state
  168. if (is_powered_on) {
  169. return;
  170. }
  171. // Audio
  172. values.volume.SetGlobal(true);
  173. // Core
  174. values.use_multi_core.SetGlobal(true);
  175. values.use_extended_memory_layout.SetGlobal(true);
  176. // CPU
  177. values.cpu_accuracy.SetGlobal(true);
  178. values.cpuopt_unsafe_unfuse_fma.SetGlobal(true);
  179. values.cpuopt_unsafe_reduce_fp_error.SetGlobal(true);
  180. values.cpuopt_unsafe_ignore_standard_fpcr.SetGlobal(true);
  181. values.cpuopt_unsafe_inaccurate_nan.SetGlobal(true);
  182. values.cpuopt_unsafe_fastmem_check.SetGlobal(true);
  183. values.cpuopt_unsafe_ignore_global_monitor.SetGlobal(true);
  184. // Renderer
  185. values.fsr_sharpening_slider.SetGlobal(true);
  186. values.renderer_backend.SetGlobal(true);
  187. values.async_presentation.SetGlobal(true);
  188. values.renderer_force_max_clock.SetGlobal(true);
  189. values.vulkan_device.SetGlobal(true);
  190. values.fullscreen_mode.SetGlobal(true);
  191. values.aspect_ratio.SetGlobal(true);
  192. values.resolution_setup.SetGlobal(true);
  193. values.scaling_filter.SetGlobal(true);
  194. values.anti_aliasing.SetGlobal(true);
  195. values.max_anisotropy.SetGlobal(true);
  196. values.use_speed_limit.SetGlobal(true);
  197. values.speed_limit.SetGlobal(true);
  198. values.use_disk_shader_cache.SetGlobal(true);
  199. values.gpu_accuracy.SetGlobal(true);
  200. values.use_asynchronous_gpu_emulation.SetGlobal(true);
  201. values.nvdec_emulation.SetGlobal(true);
  202. values.accelerate_astc.SetGlobal(true);
  203. values.async_astc.SetGlobal(true);
  204. values.use_vsync.SetGlobal(true);
  205. values.shader_backend.SetGlobal(true);
  206. values.use_asynchronous_shaders.SetGlobal(true);
  207. values.use_fast_gpu_time.SetGlobal(true);
  208. values.use_pessimistic_flushes.SetGlobal(true);
  209. values.use_vulkan_driver_pipeline_cache.SetGlobal(true);
  210. values.bg_red.SetGlobal(true);
  211. values.bg_green.SetGlobal(true);
  212. values.bg_blue.SetGlobal(true);
  213. // System
  214. values.language_index.SetGlobal(true);
  215. values.region_index.SetGlobal(true);
  216. values.time_zone_index.SetGlobal(true);
  217. values.rng_seed.SetGlobal(true);
  218. values.sound_index.SetGlobal(true);
  219. // Controls
  220. values.players.SetGlobal(true);
  221. values.use_docked_mode.SetGlobal(true);
  222. values.vibration_enabled.SetGlobal(true);
  223. values.motion_enabled.SetGlobal(true);
  224. }
  225. } // namespace Settings