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