VideoConfig.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  1. // Copyright 2008 Dolphin Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #include "VideoCommon/VideoConfig.h"
  4. #include <algorithm>
  5. #include "Common/CPUDetect.h"
  6. #include "Common/CommonTypes.h"
  7. #include "Common/StringUtil.h"
  8. #include "Core/CPUThreadConfigCallback.h"
  9. #include "Core/Config/GraphicsSettings.h"
  10. #include "Core/Config/MainSettings.h"
  11. #include "Core/ConfigManager.h"
  12. #include "Core/Core.h"
  13. #include "Core/Movie.h"
  14. #include "Core/System.h"
  15. #include "VideoCommon/AbstractGfx.h"
  16. #include "VideoCommon/BPFunctions.h"
  17. #include "VideoCommon/DriverDetails.h"
  18. #include "VideoCommon/Fifo.h"
  19. #include "VideoCommon/FramebufferManager.h"
  20. #include "VideoCommon/FreeLookCamera.h"
  21. #include "VideoCommon/GraphicsModSystem/Config/GraphicsMod.h"
  22. #include "VideoCommon/GraphicsModSystem/Runtime/GraphicsModManager.h"
  23. #include "VideoCommon/OnScreenDisplay.h"
  24. #include "VideoCommon/PixelShaderManager.h"
  25. #include "VideoCommon/Present.h"
  26. #include "VideoCommon/ShaderGenCommon.h"
  27. #include "VideoCommon/TextureCacheBase.h"
  28. #include "VideoCommon/VertexManagerBase.h"
  29. #include "VideoCommon/VideoCommon.h"
  30. VideoConfig g_Config;
  31. VideoConfig g_ActiveConfig;
  32. static bool s_has_registered_callback = false;
  33. static bool IsVSyncActive(bool enabled)
  34. {
  35. // Vsync is disabled when the throttler is disabled by the tab key.
  36. return enabled && !Core::GetIsThrottlerTempDisabled() &&
  37. Config::Get(Config::MAIN_EMULATION_SPEED) == 1.0;
  38. }
  39. void UpdateActiveConfig()
  40. {
  41. auto& movie = Core::System::GetInstance().GetMovie();
  42. if (movie.IsPlayingInput() && movie.IsConfigSaved())
  43. movie.SetGraphicsConfig();
  44. g_ActiveConfig = g_Config;
  45. g_ActiveConfig.bVSyncActive = IsVSyncActive(g_ActiveConfig.bVSync);
  46. }
  47. void VideoConfig::Refresh()
  48. {
  49. if (!s_has_registered_callback)
  50. {
  51. // There was a race condition between the video thread and the host thread here, if
  52. // corrections need to be made by VerifyValidity(). Briefly, the config will contain
  53. // invalid values. Instead, pause the video thread first, update the config and correct
  54. // it, then resume emulation, after which the video thread will detect the config has
  55. // changed and act accordingly.
  56. CPUThreadConfigCallback::AddConfigChangedCallback([]() {
  57. auto& system = Core::System::GetInstance();
  58. const bool lock_gpu_thread = Core::IsRunning(system);
  59. if (lock_gpu_thread)
  60. system.GetFifo().PauseAndLock(true, false);
  61. g_Config.Refresh();
  62. g_Config.VerifyValidity();
  63. if (lock_gpu_thread)
  64. system.GetFifo().PauseAndLock(false, true);
  65. });
  66. s_has_registered_callback = true;
  67. }
  68. bVSync = Config::Get(Config::GFX_VSYNC);
  69. iAdapter = Config::Get(Config::GFX_ADAPTER);
  70. iManuallyUploadBuffers = Config::Get(Config::GFX_MTL_MANUALLY_UPLOAD_BUFFERS);
  71. iUsePresentDrawable = Config::Get(Config::GFX_MTL_USE_PRESENT_DRAWABLE);
  72. bWidescreenHack = Config::Get(Config::GFX_WIDESCREEN_HACK);
  73. aspect_mode = Config::Get(Config::GFX_ASPECT_RATIO);
  74. custom_aspect_width = Config::Get(Config::GFX_CUSTOM_ASPECT_RATIO_WIDTH);
  75. custom_aspect_height = Config::Get(Config::GFX_CUSTOM_ASPECT_RATIO_HEIGHT);
  76. suggested_aspect_mode = Config::Get(Config::GFX_SUGGESTED_ASPECT_RATIO);
  77. widescreen_heuristic_transition_threshold =
  78. Config::Get(Config::GFX_WIDESCREEN_HEURISTIC_TRANSITION_THRESHOLD);
  79. widescreen_heuristic_aspect_ratio_slop =
  80. Config::Get(Config::GFX_WIDESCREEN_HEURISTIC_ASPECT_RATIO_SLOP);
  81. widescreen_heuristic_standard_ratio =
  82. Config::Get(Config::GFX_WIDESCREEN_HEURISTIC_STANDARD_RATIO);
  83. widescreen_heuristic_widescreen_ratio =
  84. Config::Get(Config::GFX_WIDESCREEN_HEURISTIC_WIDESCREEN_RATIO);
  85. bCrop = Config::Get(Config::GFX_CROP);
  86. iSafeTextureCache_ColorSamples = Config::Get(Config::GFX_SAFE_TEXTURE_CACHE_COLOR_SAMPLES);
  87. bShowFPS = Config::Get(Config::GFX_SHOW_FPS);
  88. bShowFTimes = Config::Get(Config::GFX_SHOW_FTIMES);
  89. bShowVPS = Config::Get(Config::GFX_SHOW_VPS);
  90. bShowVTimes = Config::Get(Config::GFX_SHOW_VTIMES);
  91. bShowGraphs = Config::Get(Config::GFX_SHOW_GRAPHS);
  92. bShowSpeed = Config::Get(Config::GFX_SHOW_SPEED);
  93. bShowSpeedColors = Config::Get(Config::GFX_SHOW_SPEED_COLORS);
  94. iPerfSampleUSec = Config::Get(Config::GFX_PERF_SAMP_WINDOW) * 1000;
  95. bShowNetPlayPing = Config::Get(Config::GFX_SHOW_NETPLAY_PING);
  96. bShowNetPlayMessages = Config::Get(Config::GFX_SHOW_NETPLAY_MESSAGES);
  97. bLogRenderTimeToFile = Config::Get(Config::GFX_LOG_RENDER_TIME_TO_FILE);
  98. bOverlayStats = Config::Get(Config::GFX_OVERLAY_STATS);
  99. bOverlayProjStats = Config::Get(Config::GFX_OVERLAY_PROJ_STATS);
  100. bOverlayScissorStats = Config::Get(Config::GFX_OVERLAY_SCISSOR_STATS);
  101. bDumpTextures = Config::Get(Config::GFX_DUMP_TEXTURES);
  102. bDumpMipmapTextures = Config::Get(Config::GFX_DUMP_MIP_TEXTURES);
  103. bDumpBaseTextures = Config::Get(Config::GFX_DUMP_BASE_TEXTURES);
  104. bHiresTextures = Config::Get(Config::GFX_HIRES_TEXTURES);
  105. bCacheHiresTextures = Config::Get(Config::GFX_CACHE_HIRES_TEXTURES);
  106. bDumpEFBTarget = Config::Get(Config::GFX_DUMP_EFB_TARGET);
  107. bDumpXFBTarget = Config::Get(Config::GFX_DUMP_XFB_TARGET);
  108. bDumpFramesAsImages = Config::Get(Config::GFX_DUMP_FRAMES_AS_IMAGES);
  109. bUseFFV1 = Config::Get(Config::GFX_USE_FFV1);
  110. sDumpFormat = Config::Get(Config::GFX_DUMP_FORMAT);
  111. sDumpCodec = Config::Get(Config::GFX_DUMP_CODEC);
  112. sDumpPixelFormat = Config::Get(Config::GFX_DUMP_PIXEL_FORMAT);
  113. sDumpEncoder = Config::Get(Config::GFX_DUMP_ENCODER);
  114. sDumpPath = Config::Get(Config::GFX_DUMP_PATH);
  115. iBitrateKbps = Config::Get(Config::GFX_BITRATE_KBPS);
  116. frame_dumps_resolution_type = Config::Get(Config::GFX_FRAME_DUMPS_RESOLUTION_TYPE);
  117. bEnableGPUTextureDecoding = Config::Get(Config::GFX_ENABLE_GPU_TEXTURE_DECODING);
  118. bPreferVSForLinePointExpansion = Config::Get(Config::GFX_PREFER_VS_FOR_LINE_POINT_EXPANSION);
  119. bEnablePixelLighting = Config::Get(Config::GFX_ENABLE_PIXEL_LIGHTING);
  120. bFastDepthCalc = Config::Get(Config::GFX_FAST_DEPTH_CALC);
  121. iMultisamples = Config::Get(Config::GFX_MSAA);
  122. bSSAA = Config::Get(Config::GFX_SSAA);
  123. iEFBScale = Config::Get(Config::GFX_EFB_SCALE);
  124. bTexFmtOverlayEnable = Config::Get(Config::GFX_TEXFMT_OVERLAY_ENABLE);
  125. bTexFmtOverlayCenter = Config::Get(Config::GFX_TEXFMT_OVERLAY_CENTER);
  126. bWireFrame = Config::Get(Config::GFX_ENABLE_WIREFRAME);
  127. bDisableFog = Config::Get(Config::GFX_DISABLE_FOG);
  128. bBorderlessFullscreen = Config::Get(Config::GFX_BORDERLESS_FULLSCREEN);
  129. bEnableValidationLayer = Config::Get(Config::GFX_ENABLE_VALIDATION_LAYER);
  130. bBackendMultithreading = Config::Get(Config::GFX_BACKEND_MULTITHREADING);
  131. iCommandBufferExecuteInterval = Config::Get(Config::GFX_COMMAND_BUFFER_EXECUTE_INTERVAL);
  132. bShaderCache = Config::Get(Config::GFX_SHADER_CACHE);
  133. bWaitForShadersBeforeStarting = Config::Get(Config::GFX_WAIT_FOR_SHADERS_BEFORE_STARTING);
  134. iShaderCompilationMode = Config::Get(Config::GFX_SHADER_COMPILATION_MODE);
  135. iShaderCompilerThreads = Config::Get(Config::GFX_SHADER_COMPILER_THREADS);
  136. iShaderPrecompilerThreads = Config::Get(Config::GFX_SHADER_PRECOMPILER_THREADS);
  137. bCPUCull = Config::Get(Config::GFX_CPU_CULL);
  138. texture_filtering_mode = Config::Get(Config::GFX_ENHANCE_FORCE_TEXTURE_FILTERING);
  139. iMaxAnisotropy = Config::Get(Config::GFX_ENHANCE_MAX_ANISOTROPY);
  140. output_resampling_mode = Config::Get(Config::GFX_ENHANCE_OUTPUT_RESAMPLING);
  141. sPostProcessingShader = Config::Get(Config::GFX_ENHANCE_POST_SHADER);
  142. bForceTrueColor = Config::Get(Config::GFX_ENHANCE_FORCE_TRUE_COLOR);
  143. bDisableCopyFilter = Config::Get(Config::GFX_ENHANCE_DISABLE_COPY_FILTER);
  144. bArbitraryMipmapDetection = Config::Get(Config::GFX_ENHANCE_ARBITRARY_MIPMAP_DETECTION);
  145. fArbitraryMipmapDetectionThreshold =
  146. Config::Get(Config::GFX_ENHANCE_ARBITRARY_MIPMAP_DETECTION_THRESHOLD);
  147. bHDR = Config::Get(Config::GFX_ENHANCE_HDR_OUTPUT);
  148. color_correction.bCorrectColorSpace = Config::Get(Config::GFX_CC_CORRECT_COLOR_SPACE);
  149. color_correction.game_color_space = Config::Get(Config::GFX_CC_GAME_COLOR_SPACE);
  150. color_correction.bCorrectGamma = Config::Get(Config::GFX_CC_CORRECT_GAMMA);
  151. color_correction.fGameGamma = Config::Get(Config::GFX_CC_GAME_GAMMA);
  152. color_correction.bSDRDisplayGammaSRGB = Config::Get(Config::GFX_CC_SDR_DISPLAY_GAMMA_SRGB);
  153. color_correction.fSDRDisplayCustomGamma = Config::Get(Config::GFX_CC_SDR_DISPLAY_CUSTOM_GAMMA);
  154. color_correction.fHDRPaperWhiteNits = Config::Get(Config::GFX_CC_HDR_PAPER_WHITE_NITS);
  155. stereo_mode = Config::Get(Config::GFX_STEREO_MODE);
  156. stereo_per_eye_resolution_full = Config::Get(Config::GFX_STEREO_PER_EYE_RESOLUTION_FULL);
  157. iStereoDepth = Config::Get(Config::GFX_STEREO_DEPTH);
  158. iStereoConvergencePercentage = Config::Get(Config::GFX_STEREO_CONVERGENCE_PERCENTAGE);
  159. bStereoSwapEyes = Config::Get(Config::GFX_STEREO_SWAP_EYES);
  160. iStereoConvergence = Config::Get(Config::GFX_STEREO_CONVERGENCE);
  161. bStereoEFBMonoDepth = Config::Get(Config::GFX_STEREO_EFB_MONO_DEPTH);
  162. iStereoDepthPercentage = Config::Get(Config::GFX_STEREO_DEPTH_PERCENTAGE);
  163. bEFBAccessEnable = Config::Get(Config::GFX_HACK_EFB_ACCESS_ENABLE);
  164. bEFBAccessDeferInvalidation = Config::Get(Config::GFX_HACK_EFB_DEFER_INVALIDATION);
  165. bBBoxEnable = Config::Get(Config::GFX_HACK_BBOX_ENABLE);
  166. bForceProgressive = Config::Get(Config::GFX_HACK_FORCE_PROGRESSIVE);
  167. bSkipEFBCopyToRam = Config::Get(Config::GFX_HACK_SKIP_EFB_COPY_TO_RAM);
  168. bSkipXFBCopyToRam = Config::Get(Config::GFX_HACK_SKIP_XFB_COPY_TO_RAM);
  169. bDisableCopyToVRAM = Config::Get(Config::GFX_HACK_DISABLE_COPY_TO_VRAM);
  170. bDeferEFBCopies = Config::Get(Config::GFX_HACK_DEFER_EFB_COPIES);
  171. bImmediateXFB = Config::Get(Config::GFX_HACK_IMMEDIATE_XFB);
  172. bVISkip = Config::Get(Config::GFX_HACK_VI_SKIP);
  173. bSkipPresentingDuplicateXFBs = bVISkip || Config::Get(Config::GFX_HACK_SKIP_DUPLICATE_XFBS);
  174. bCopyEFBScaled = Config::Get(Config::GFX_HACK_COPY_EFB_SCALED);
  175. bEFBEmulateFormatChanges = Config::Get(Config::GFX_HACK_EFB_EMULATE_FORMAT_CHANGES);
  176. bVertexRounding = Config::Get(Config::GFX_HACK_VERTEX_ROUNDING);
  177. iEFBAccessTileSize = Config::Get(Config::GFX_HACK_EFB_ACCESS_TILE_SIZE);
  178. iMissingColorValue = Config::Get(Config::GFX_HACK_MISSING_COLOR_VALUE);
  179. bFastTextureSampling = Config::Get(Config::GFX_HACK_FAST_TEXTURE_SAMPLING);
  180. #ifdef __APPLE__
  181. bNoMipmapping = Config::Get(Config::GFX_HACK_NO_MIPMAPPING);
  182. #endif
  183. bPerfQueriesEnable = Config::Get(Config::GFX_PERF_QUERIES_ENABLE);
  184. bGraphicMods = Config::Get(Config::GFX_MODS_ENABLE);
  185. customDriverLibraryName = Config::Get(Config::GFX_DRIVER_LIB_NAME);
  186. }
  187. void VideoConfig::VerifyValidity()
  188. {
  189. // TODO: Check iMaxAnisotropy value
  190. if (iAdapter < 0 || iAdapter > ((int)backend_info.Adapters.size() - 1))
  191. iAdapter = 0;
  192. if (std::find(backend_info.AAModes.begin(), backend_info.AAModes.end(), iMultisamples) ==
  193. backend_info.AAModes.end())
  194. iMultisamples = 1;
  195. if (stereo_mode != StereoMode::Off)
  196. {
  197. if (!backend_info.bSupportsGeometryShaders)
  198. {
  199. OSD::AddMessage(
  200. "Stereoscopic 3D isn't supported by your GPU, support for OpenGL 3.2 is required.",
  201. 10000);
  202. stereo_mode = StereoMode::Off;
  203. }
  204. }
  205. }
  206. bool VideoConfig::UsingUberShaders() const
  207. {
  208. return iShaderCompilationMode == ShaderCompilationMode::SynchronousUberShaders ||
  209. iShaderCompilationMode == ShaderCompilationMode::AsynchronousUberShaders;
  210. }
  211. static u32 GetNumAutoShaderCompilerThreads()
  212. {
  213. // Automatic number.
  214. return static_cast<u32>(std::clamp(cpu_info.num_cores - 3, 1, 4));
  215. }
  216. static u32 GetNumAutoShaderPreCompilerThreads()
  217. {
  218. // Automatic number. We use clamp(cpus - 2, 1, infty) here.
  219. // We chose this because we don't want to limit our speed-up
  220. // and at the same time leave two logical cores for the dolphin UI and the rest of the OS.
  221. return static_cast<u32>(std::max(cpu_info.num_cores - 2, 1));
  222. }
  223. u32 VideoConfig::GetShaderCompilerThreads() const
  224. {
  225. if (!backend_info.bSupportsBackgroundCompiling)
  226. return 0;
  227. if (iShaderCompilerThreads >= 0)
  228. return static_cast<u32>(iShaderCompilerThreads);
  229. else
  230. return GetNumAutoShaderCompilerThreads();
  231. }
  232. u32 VideoConfig::GetShaderPrecompilerThreads() const
  233. {
  234. // When using background compilation, always keep the same thread count.
  235. if (!bWaitForShadersBeforeStarting)
  236. return GetShaderCompilerThreads();
  237. if (!backend_info.bSupportsBackgroundCompiling)
  238. return 0;
  239. if (iShaderPrecompilerThreads >= 0)
  240. return static_cast<u32>(iShaderPrecompilerThreads);
  241. else if (!DriverDetails::HasBug(DriverDetails::BUG_BROKEN_MULTITHREADED_SHADER_PRECOMPILATION))
  242. return GetNumAutoShaderPreCompilerThreads();
  243. else
  244. return 1;
  245. }
  246. void CheckForConfigChanges()
  247. {
  248. const ShaderHostConfig old_shader_host_config = ShaderHostConfig::GetCurrent();
  249. const StereoMode old_stereo = g_ActiveConfig.stereo_mode;
  250. const u32 old_multisamples = g_ActiveConfig.iMultisamples;
  251. const int old_anisotropy = g_ActiveConfig.iMaxAnisotropy;
  252. const int old_efb_access_tile_size = g_ActiveConfig.iEFBAccessTileSize;
  253. const auto old_texture_filtering_mode = g_ActiveConfig.texture_filtering_mode;
  254. const bool old_vsync = g_ActiveConfig.bVSyncActive;
  255. const bool old_bbox = g_ActiveConfig.bBBoxEnable;
  256. const int old_efb_scale = g_ActiveConfig.iEFBScale;
  257. const u32 old_game_mod_changes =
  258. g_ActiveConfig.graphics_mod_config ? g_ActiveConfig.graphics_mod_config->GetChangeCount() : 0;
  259. const bool old_graphics_mods_enabled = g_ActiveConfig.bGraphicMods;
  260. const AspectMode old_aspect_mode = g_ActiveConfig.aspect_mode;
  261. const AspectMode old_suggested_aspect_mode = g_ActiveConfig.suggested_aspect_mode;
  262. const bool old_widescreen_hack = g_ActiveConfig.bWidescreenHack;
  263. const auto old_post_processing_shader = g_ActiveConfig.sPostProcessingShader;
  264. const auto old_hdr = g_ActiveConfig.bHDR;
  265. UpdateActiveConfig();
  266. FreeLook::UpdateActiveConfig();
  267. g_vertex_manager->OnConfigChange();
  268. g_freelook_camera.SetControlType(FreeLook::GetActiveConfig().camera_config.control_type);
  269. if (g_ActiveConfig.bGraphicMods && !old_graphics_mods_enabled)
  270. {
  271. g_ActiveConfig.graphics_mod_config = GraphicsModGroupConfig(SConfig::GetInstance().GetGameID());
  272. g_ActiveConfig.graphics_mod_config->Load();
  273. }
  274. if (g_ActiveConfig.graphics_mod_config &&
  275. (old_game_mod_changes != g_ActiveConfig.graphics_mod_config->GetChangeCount()))
  276. {
  277. g_graphics_mod_manager->Load(*g_ActiveConfig.graphics_mod_config);
  278. }
  279. // Update texture cache settings with any changed options.
  280. g_texture_cache->OnConfigChanged(g_ActiveConfig);
  281. // EFB tile cache doesn't need to notify the backend.
  282. if (old_efb_access_tile_size != g_ActiveConfig.iEFBAccessTileSize)
  283. g_framebuffer_manager->SetEFBCacheTileSize(std::max(g_ActiveConfig.iEFBAccessTileSize, 0));
  284. // Determine which (if any) settings have changed.
  285. ShaderHostConfig new_host_config = ShaderHostConfig::GetCurrent();
  286. u32 changed_bits = 0;
  287. if (old_shader_host_config.bits != new_host_config.bits)
  288. changed_bits |= CONFIG_CHANGE_BIT_HOST_CONFIG;
  289. if (old_stereo != g_ActiveConfig.stereo_mode)
  290. changed_bits |= CONFIG_CHANGE_BIT_STEREO_MODE;
  291. if (old_multisamples != g_ActiveConfig.iMultisamples)
  292. changed_bits |= CONFIG_CHANGE_BIT_MULTISAMPLES;
  293. if (old_anisotropy != g_ActiveConfig.iMaxAnisotropy)
  294. changed_bits |= CONFIG_CHANGE_BIT_ANISOTROPY;
  295. if (old_texture_filtering_mode != g_ActiveConfig.texture_filtering_mode)
  296. changed_bits |= CONFIG_CHANGE_BIT_FORCE_TEXTURE_FILTERING;
  297. if (old_vsync != g_ActiveConfig.bVSyncActive)
  298. changed_bits |= CONFIG_CHANGE_BIT_VSYNC;
  299. if (old_bbox != g_ActiveConfig.bBBoxEnable)
  300. changed_bits |= CONFIG_CHANGE_BIT_BBOX;
  301. if (old_efb_scale != g_ActiveConfig.iEFBScale)
  302. changed_bits |= CONFIG_CHANGE_BIT_TARGET_SIZE;
  303. if (old_aspect_mode != g_ActiveConfig.aspect_mode)
  304. changed_bits |= CONFIG_CHANGE_BIT_ASPECT_RATIO;
  305. if (old_suggested_aspect_mode != g_ActiveConfig.suggested_aspect_mode)
  306. changed_bits |= CONFIG_CHANGE_BIT_ASPECT_RATIO;
  307. if (old_widescreen_hack != g_ActiveConfig.bWidescreenHack)
  308. changed_bits |= CONFIG_CHANGE_BIT_ASPECT_RATIO;
  309. if (old_post_processing_shader != g_ActiveConfig.sPostProcessingShader)
  310. changed_bits |= CONFIG_CHANGE_BIT_POST_PROCESSING_SHADER;
  311. if (old_hdr != g_ActiveConfig.bHDR)
  312. changed_bits |= CONFIG_CHANGE_BIT_HDR;
  313. // No changes?
  314. if (changed_bits == 0)
  315. return;
  316. float old_scale = g_framebuffer_manager->GetEFBScale();
  317. // Framebuffer changed?
  318. if (changed_bits & (CONFIG_CHANGE_BIT_MULTISAMPLES | CONFIG_CHANGE_BIT_STEREO_MODE |
  319. CONFIG_CHANGE_BIT_TARGET_SIZE | CONFIG_CHANGE_BIT_HDR))
  320. {
  321. g_framebuffer_manager->RecreateEFBFramebuffer();
  322. }
  323. if (old_scale != g_framebuffer_manager->GetEFBScale())
  324. {
  325. auto& system = Core::System::GetInstance();
  326. auto& pixel_shader_manager = system.GetPixelShaderManager();
  327. pixel_shader_manager.Dirty();
  328. }
  329. // Reload shaders if host config has changed.
  330. if (changed_bits & (CONFIG_CHANGE_BIT_HOST_CONFIG | CONFIG_CHANGE_BIT_MULTISAMPLES))
  331. {
  332. OSD::AddMessage("Video config changed, reloading shaders.", OSD::Duration::NORMAL);
  333. g_gfx->WaitForGPUIdle();
  334. g_vertex_manager->InvalidatePipelineObject();
  335. g_vertex_manager->NotifyCustomShaderCacheOfHostChange(new_host_config);
  336. g_shader_cache->SetHostConfig(new_host_config);
  337. g_shader_cache->Reload();
  338. g_framebuffer_manager->RecompileShaders();
  339. }
  340. // Viewport and scissor rect have to be reset since they will be scaled differently.
  341. if (changed_bits & CONFIG_CHANGE_BIT_TARGET_SIZE)
  342. {
  343. BPFunctions::SetScissorAndViewport();
  344. }
  345. // Notify all listeners
  346. ConfigChangedEvent::Trigger(changed_bits);
  347. // TODO: Move everything else to the ConfigChanged event
  348. }
  349. static Common::EventHook s_check_config_event = AfterFrameEvent::Register(
  350. [](Core::System&) { CheckForConfigChanges(); }, "CheckForConfigChanges");