settings.cpp 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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_UseVsync", values.use_vsync.GetValue());
  54. log_setting("Renderer_ShaderBackend", values.shader_backend.GetValue());
  55. log_setting("Renderer_UseAsynchronousShaders", values.use_asynchronous_shaders.GetValue());
  56. log_setting("Renderer_AnisotropicFilteringLevel", values.max_anisotropy.GetValue());
  57. log_setting("Audio_OutputEngine", values.sink_id.GetValue());
  58. log_setting("Audio_OutputDevice", values.audio_output_device_id.GetValue());
  59. log_setting("Audio_InputDevice", values.audio_input_device_id.GetValue());
  60. log_setting("DataStorage_UseVirtualSd", values.use_virtual_sd.GetValue());
  61. log_path("DataStorage_CacheDir", Common::FS::GetYuzuPath(Common::FS::YuzuPath::CacheDir));
  62. log_path("DataStorage_ConfigDir", Common::FS::GetYuzuPath(Common::FS::YuzuPath::ConfigDir));
  63. log_path("DataStorage_LoadDir", Common::FS::GetYuzuPath(Common::FS::YuzuPath::LoadDir));
  64. log_path("DataStorage_NANDDir", Common::FS::GetYuzuPath(Common::FS::YuzuPath::NANDDir));
  65. log_path("DataStorage_SDMCDir", Common::FS::GetYuzuPath(Common::FS::YuzuPath::SDMCDir));
  66. log_setting("Debugging_ProgramArgs", values.program_args.GetValue());
  67. log_setting("Debugging_GDBStub", values.use_gdbstub.GetValue());
  68. log_setting("Input_EnableMotion", values.motion_enabled.GetValue());
  69. log_setting("Input_EnableVibration", values.vibration_enabled.GetValue());
  70. log_setting("Input_EnableRawInput", values.enable_raw_input.GetValue());
  71. }
  72. bool IsConfiguringGlobal() {
  73. return configuring_global;
  74. }
  75. void SetConfiguringGlobal(bool is_global) {
  76. configuring_global = is_global;
  77. }
  78. bool IsGPULevelExtreme() {
  79. return values.gpu_accuracy.GetValue() == GPUAccuracy::Extreme;
  80. }
  81. bool IsGPULevelHigh() {
  82. return values.gpu_accuracy.GetValue() == GPUAccuracy::Extreme ||
  83. values.gpu_accuracy.GetValue() == GPUAccuracy::High;
  84. }
  85. bool IsFastmemEnabled() {
  86. if (values.cpu_debug_mode) {
  87. return static_cast<bool>(values.cpuopt_fastmem);
  88. }
  89. return true;
  90. }
  91. float Volume() {
  92. if (values.audio_muted) {
  93. return 0.0f;
  94. }
  95. return values.volume.GetValue() / static_cast<f32>(values.volume.GetDefault());
  96. }
  97. void UpdateRescalingInfo() {
  98. const auto setup = values.resolution_setup.GetValue();
  99. auto& info = values.resolution_info;
  100. info.downscale = false;
  101. switch (setup) {
  102. case ResolutionSetup::Res1_2X:
  103. info.up_scale = 1;
  104. info.down_shift = 1;
  105. info.downscale = true;
  106. break;
  107. case ResolutionSetup::Res3_4X:
  108. info.up_scale = 3;
  109. info.down_shift = 2;
  110. info.downscale = true;
  111. break;
  112. case ResolutionSetup::Res1X:
  113. info.up_scale = 1;
  114. info.down_shift = 0;
  115. break;
  116. case ResolutionSetup::Res2X:
  117. info.up_scale = 2;
  118. info.down_shift = 0;
  119. break;
  120. case ResolutionSetup::Res3X:
  121. info.up_scale = 3;
  122. info.down_shift = 0;
  123. break;
  124. case ResolutionSetup::Res4X:
  125. info.up_scale = 4;
  126. info.down_shift = 0;
  127. break;
  128. case ResolutionSetup::Res5X:
  129. info.up_scale = 5;
  130. info.down_shift = 0;
  131. break;
  132. case ResolutionSetup::Res6X:
  133. info.up_scale = 6;
  134. info.down_shift = 0;
  135. break;
  136. default:
  137. ASSERT(false);
  138. info.up_scale = 1;
  139. info.down_shift = 0;
  140. break;
  141. }
  142. info.up_factor = static_cast<f32>(info.up_scale) / (1U << info.down_shift);
  143. info.down_factor = static_cast<f32>(1U << info.down_shift) / info.up_scale;
  144. info.active = info.up_scale != 1 || info.down_shift != 0;
  145. }
  146. void RestoreGlobalState(bool is_powered_on) {
  147. // If a game is running, DO NOT restore the global settings state
  148. if (is_powered_on) {
  149. return;
  150. }
  151. // Audio
  152. values.volume.SetGlobal(true);
  153. // Core
  154. values.use_multi_core.SetGlobal(true);
  155. values.use_extended_memory_layout.SetGlobal(true);
  156. // CPU
  157. values.cpu_accuracy.SetGlobal(true);
  158. values.cpuopt_unsafe_unfuse_fma.SetGlobal(true);
  159. values.cpuopt_unsafe_reduce_fp_error.SetGlobal(true);
  160. values.cpuopt_unsafe_ignore_standard_fpcr.SetGlobal(true);
  161. values.cpuopt_unsafe_inaccurate_nan.SetGlobal(true);
  162. values.cpuopt_unsafe_fastmem_check.SetGlobal(true);
  163. values.cpuopt_unsafe_ignore_global_monitor.SetGlobal(true);
  164. // Renderer
  165. values.fsr_sharpening_slider.SetGlobal(true);
  166. values.renderer_backend.SetGlobal(true);
  167. values.renderer_force_max_clock.SetGlobal(true);
  168. values.vulkan_device.SetGlobal(true);
  169. values.aspect_ratio.SetGlobal(true);
  170. values.max_anisotropy.SetGlobal(true);
  171. values.use_speed_limit.SetGlobal(true);
  172. values.speed_limit.SetGlobal(true);
  173. values.use_disk_shader_cache.SetGlobal(true);
  174. values.gpu_accuracy.SetGlobal(true);
  175. values.use_asynchronous_gpu_emulation.SetGlobal(true);
  176. values.nvdec_emulation.SetGlobal(true);
  177. values.accelerate_astc.SetGlobal(true);
  178. values.use_vsync.SetGlobal(true);
  179. values.shader_backend.SetGlobal(true);
  180. values.use_asynchronous_shaders.SetGlobal(true);
  181. values.use_fast_gpu_time.SetGlobal(true);
  182. values.use_pessimistic_flushes.SetGlobal(true);
  183. values.bg_red.SetGlobal(true);
  184. values.bg_green.SetGlobal(true);
  185. values.bg_blue.SetGlobal(true);
  186. // System
  187. values.language_index.SetGlobal(true);
  188. values.region_index.SetGlobal(true);
  189. values.time_zone_index.SetGlobal(true);
  190. values.rng_seed.SetGlobal(true);
  191. values.sound_index.SetGlobal(true);
  192. // Controls
  193. values.players.SetGlobal(true);
  194. values.use_docked_mode.SetGlobal(true);
  195. values.vibration_enabled.SetGlobal(true);
  196. values.motion_enabled.SetGlobal(true);
  197. }
  198. } // namespace Settings