settings.cpp 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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_EnableRawInput", values.enable_raw_input.GetValue());
  72. }
  73. bool IsConfiguringGlobal() {
  74. return configuring_global;
  75. }
  76. void SetConfiguringGlobal(bool is_global) {
  77. configuring_global = is_global;
  78. }
  79. bool IsGPULevelExtreme() {
  80. return values.gpu_accuracy.GetValue() == GPUAccuracy::Extreme;
  81. }
  82. bool IsGPULevelHigh() {
  83. return values.gpu_accuracy.GetValue() == GPUAccuracy::Extreme ||
  84. values.gpu_accuracy.GetValue() == GPUAccuracy::High;
  85. }
  86. bool IsFastmemEnabled() {
  87. if (values.cpu_debug_mode) {
  88. return static_cast<bool>(values.cpuopt_fastmem);
  89. }
  90. return true;
  91. }
  92. float Volume() {
  93. if (values.audio_muted) {
  94. return 0.0f;
  95. }
  96. return values.volume.GetValue() / static_cast<f32>(values.volume.GetDefault());
  97. }
  98. void UpdateRescalingInfo() {
  99. const auto setup = values.resolution_setup.GetValue();
  100. auto& info = values.resolution_info;
  101. info.downscale = false;
  102. switch (setup) {
  103. case ResolutionSetup::Res1_2X:
  104. info.up_scale = 1;
  105. info.down_shift = 1;
  106. info.downscale = true;
  107. break;
  108. case ResolutionSetup::Res3_4X:
  109. info.up_scale = 3;
  110. info.down_shift = 2;
  111. info.downscale = true;
  112. break;
  113. case ResolutionSetup::Res1X:
  114. info.up_scale = 1;
  115. info.down_shift = 0;
  116. break;
  117. case ResolutionSetup::Res3_2X:
  118. info.up_scale = 3;
  119. info.down_shift = 1;
  120. break;
  121. case ResolutionSetup::Res2X:
  122. info.up_scale = 2;
  123. info.down_shift = 0;
  124. break;
  125. case ResolutionSetup::Res3X:
  126. info.up_scale = 3;
  127. info.down_shift = 0;
  128. break;
  129. case ResolutionSetup::Res4X:
  130. info.up_scale = 4;
  131. info.down_shift = 0;
  132. break;
  133. case ResolutionSetup::Res5X:
  134. info.up_scale = 5;
  135. info.down_shift = 0;
  136. break;
  137. case ResolutionSetup::Res6X:
  138. info.up_scale = 6;
  139. info.down_shift = 0;
  140. break;
  141. case ResolutionSetup::Res7X:
  142. info.up_scale = 7;
  143. info.down_shift = 0;
  144. break;
  145. case ResolutionSetup::Res8X:
  146. info.up_scale = 8;
  147. info.down_shift = 0;
  148. break;
  149. default:
  150. ASSERT(false);
  151. info.up_scale = 1;
  152. info.down_shift = 0;
  153. break;
  154. }
  155. info.up_factor = static_cast<f32>(info.up_scale) / (1U << info.down_shift);
  156. info.down_factor = static_cast<f32>(1U << info.down_shift) / info.up_scale;
  157. info.active = info.up_scale != 1 || info.down_shift != 0;
  158. }
  159. void RestoreGlobalState(bool is_powered_on) {
  160. // If a game is running, DO NOT restore the global settings state
  161. if (is_powered_on) {
  162. return;
  163. }
  164. // Audio
  165. values.volume.SetGlobal(true);
  166. // Core
  167. values.use_multi_core.SetGlobal(true);
  168. values.use_extended_memory_layout.SetGlobal(true);
  169. // CPU
  170. values.cpu_accuracy.SetGlobal(true);
  171. values.cpuopt_unsafe_unfuse_fma.SetGlobal(true);
  172. values.cpuopt_unsafe_reduce_fp_error.SetGlobal(true);
  173. values.cpuopt_unsafe_ignore_standard_fpcr.SetGlobal(true);
  174. values.cpuopt_unsafe_inaccurate_nan.SetGlobal(true);
  175. values.cpuopt_unsafe_fastmem_check.SetGlobal(true);
  176. values.cpuopt_unsafe_ignore_global_monitor.SetGlobal(true);
  177. // Renderer
  178. values.fsr_sharpening_slider.SetGlobal(true);
  179. values.renderer_backend.SetGlobal(true);
  180. values.renderer_force_max_clock.SetGlobal(true);
  181. values.vulkan_device.SetGlobal(true);
  182. values.fullscreen_mode.SetGlobal(true);
  183. values.aspect_ratio.SetGlobal(true);
  184. values.resolution_setup.SetGlobal(true);
  185. values.scaling_filter.SetGlobal(true);
  186. values.anti_aliasing.SetGlobal(true);
  187. values.max_anisotropy.SetGlobal(true);
  188. values.use_speed_limit.SetGlobal(true);
  189. values.speed_limit.SetGlobal(true);
  190. values.use_disk_shader_cache.SetGlobal(true);
  191. values.gpu_accuracy.SetGlobal(true);
  192. values.use_asynchronous_gpu_emulation.SetGlobal(true);
  193. values.nvdec_emulation.SetGlobal(true);
  194. values.accelerate_astc.SetGlobal(true);
  195. values.async_astc.SetGlobal(true);
  196. values.use_vsync.SetGlobal(true);
  197. values.shader_backend.SetGlobal(true);
  198. values.use_asynchronous_shaders.SetGlobal(true);
  199. values.use_fast_gpu_time.SetGlobal(true);
  200. values.use_pessimistic_flushes.SetGlobal(true);
  201. values.use_vulkan_driver_pipeline_cache.SetGlobal(true);
  202. values.bg_red.SetGlobal(true);
  203. values.bg_green.SetGlobal(true);
  204. values.bg_blue.SetGlobal(true);
  205. // System
  206. values.language_index.SetGlobal(true);
  207. values.region_index.SetGlobal(true);
  208. values.time_zone_index.SetGlobal(true);
  209. values.rng_seed.SetGlobal(true);
  210. values.sound_index.SetGlobal(true);
  211. // Controls
  212. values.players.SetGlobal(true);
  213. values.use_docked_mode.SetGlobal(true);
  214. values.vibration_enabled.SetGlobal(true);
  215. values.motion_enabled.SetGlobal(true);
  216. }
  217. } // namespace Settings