From aa0055cea72d1478c560cee4a44ac43f6ffcad42 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Tue, 5 Jan 2016 22:37:28 -0800 Subject: [PATCH] Track the running GPU backend separate from config. This way we can change the config directly when we want to save a new setting, rather than having hacks to use a temp var. --- Core/Config.cpp | 5 ----- Core/Config.h | 11 ++++++----- Core/Screenshot.cpp | 4 ++-- Core/System.cpp | 10 ++++++++++ Core/System.h | 4 ++++ GPU/Common/FramebufferCommon.cpp | 8 +++----- UI/DevScreens.cpp | 4 ++-- UI/EmuScreen.cpp | 6 +++--- UI/GameSettingsScreen.cpp | 13 +++++++++---- UI/NativeApp.cpp | 11 ++++++----- Windows/MainWindowMenu.cpp | 6 ++++-- Windows/main.cpp | 10 ---------- 12 files changed, 49 insertions(+), 43 deletions(-) diff --git a/Core/Config.cpp b/Core/Config.cpp index c909ab7620..38d807bbd0 100644 --- a/Core/Config.cpp +++ b/Core/Config.cpp @@ -442,7 +442,6 @@ static ConfigSetting graphicsSettings[] = { ReportedConfigSetting("FrameRate", &g_Config.iFpsLimit, 0, true, true), #ifdef _WIN32 ConfigSetting("FrameSkipUnthrottle", &g_Config.bFrameSkipUnthrottle, false, true, true), - ConfigSetting("TemporaryGPUBackend", &g_Config.iTempGPUBackend, -1, false), ConfigSetting("RestartRequired", &g_Config.bRestartRequired, false, false), #else ConfigSetting("FrameSkipUnthrottle", &g_Config.bFrameSkipUnthrottle, true), @@ -943,10 +942,6 @@ void Config::Load(const char *iniFileName, const char *controllerIniFilename) { CleanRecent(); -#ifdef _WIN32 - iTempGPUBackend = iGPUBackend; -#endif - // Fix Wrong MAC address by old version by "Change MAC address" if (sMACAddress.length() != 17) sMACAddress = CreateRandMAC(); diff --git a/Core/Config.h b/Core/Config.h index 318fa89d07..6d9e2b2b9b 100644 --- a/Core/Config.h +++ b/Core/Config.h @@ -45,9 +45,13 @@ enum BufferFilter { }; // Software is not among these because it will have one of these perform the blit to display. +enum class GPUBackend { + OPENGL = 0, + DIRECT3D9 = 1, +}; enum { - GPU_BACKEND_OPENGL = 0, - GPU_BACKEND_DIRECT3D9 = 1, + GPU_BACKEND_OPENGL = GPUBackend::OPENGL, + GPU_BACKEND_DIRECT3D9 = GPUBackend::DIRECT3D9, }; enum AudioBackendType { @@ -96,9 +100,6 @@ public: bool bTopMost; std::string sFont; bool bIgnoreWindowsKey; - // Used for switching the GPU backend in GameSettingsScreen. - // Without this, PPSSPP instantly crashes if we edit iGPUBackend directly... - int iTempGPUBackend; bool bRestartRequired; #endif diff --git a/Core/Screenshot.cpp b/Core/Screenshot.cpp index b758c30ad2..c2d95ac3cc 100644 --- a/Core/Screenshot.cpp +++ b/Core/Screenshot.cpp @@ -221,10 +221,10 @@ bool TakeGameScreenshot(const char *filename, ScreenshotFormat fmt, ScreenshotTy success = gpuDebug->GetCurrentFramebuffer(buf); } } else { - if (g_Config.iGPUBackend == GPU_BACKEND_OPENGL) { + if (GetGPUBackend() == GPUBackend::OPENGL) { success = GLES_GPU::GetDisplayFramebuffer(buf); #ifdef _WIN32 - } else if (g_Config.iGPUBackend == GPU_BACKEND_DIRECT3D9) { + } else if (GetGPUBackend() == GPUBackend::DIRECT3D9) { success = DX9::DIRECTX9_GPU::GetDisplayFramebuffer(buf); #endif } diff --git a/Core/System.cpp b/Core/System.cpp index a228b9308e..06246507d6 100644 --- a/Core/System.cpp +++ b/Core/System.cpp @@ -90,6 +90,8 @@ volatile CoreState coreState = CORE_STEPPING; volatile bool coreStatePending = false; static volatile CPUThreadState cpuThreadState = CPU_THREAD_NOT_RUNNING; +static GPUBackend gpuBackend; + void UpdateUIState(GlobalUIState newState) { // Never leave the EXIT state. if (globalUIState != newState && globalUIState != UISTATE_EXIT) { @@ -102,6 +104,14 @@ GlobalUIState GetUIState() { return globalUIState; } +void SetGPUBackend(GPUBackend type) { + gpuBackend = type; +} + +GPUBackend GetGPUBackend() { + return gpuBackend; +} + bool IsAudioInitialised() { return audioInitialized; } diff --git a/Core/System.h b/Core/System.h index b32a14b26a..9a11b5241f 100644 --- a/Core/System.h +++ b/Core/System.h @@ -48,10 +48,14 @@ enum PSPDirectories { }; class GraphicsContext; +enum class GPUBackend; void UpdateUIState(GlobalUIState newState); GlobalUIState GetUIState(); +void SetGPUBackend(GPUBackend type); +GPUBackend GetGPUBackend(); + bool PSP_Init(const CoreParameter &coreParam, std::string *error_string); bool PSP_InitStart(const CoreParameter &coreParam, std::string *error_string); bool PSP_InitUpdate(std::string *error_string); diff --git a/GPU/Common/FramebufferCommon.cpp b/GPU/Common/FramebufferCommon.cpp index 0f56e743da..37018a0f62 100644 --- a/GPU/Common/FramebufferCommon.cpp +++ b/GPU/Common/FramebufferCommon.cpp @@ -50,11 +50,9 @@ void CenterDisplayOutputRect(float *x, float *y, float *w, float *h, float origW float offsetX = (g_Config.fSmallDisplayOffsetX - 0.5f) * 2.0f * frameW; float offsetY = (g_Config.fSmallDisplayOffsetY - 0.5f) * 2.0f * frameH; // Have to invert Y for GL -#ifdef _WIN32 - if (g_Config.iGPUBackend == GPU_BACKEND_OPENGL) { offsetY = offsetY * -1.0f; } -#else - offsetY = offsetY * -1.0f; -#endif + if (GetGPUBackend() == GPUBackend::OPENGL) { + offsetY = offsetY * -1.0f; + } float customZoom = g_Config.fSmallDisplayCustomZoom / 8.0f; float smallDisplayW = origW * customZoom; float smallDisplayH = origH * customZoom; diff --git a/UI/DevScreens.cpp b/UI/DevScreens.cpp index f6e530edc2..fc3bdd52df 100644 --- a/UI/DevScreens.cpp +++ b/UI/DevScreens.cpp @@ -356,7 +356,7 @@ void SystemInfoScreen::CreateViews() { deviceSpecs->Add(new InfoItem("Model", thin3d->GetInfoString(T3DInfo::RENDERER))); #ifdef _WIN32 deviceSpecs->Add(new InfoItem("Driver Version", System_GetProperty(SYSPROP_GPUDRIVER_VERSION))); - if (g_Config.iGPUBackend == GPU_BACKEND_DIRECT3D9) { + if (GetGPUBackend() == GPUBackend::DIRECT3D9) { deviceSpecs->Add(new InfoItem("D3DX Version", StringFromFormat("%d", GetD3DXVersion()))); } #endif @@ -378,7 +378,7 @@ void SystemInfoScreen::CreateViews() { deviceSpecs->Add(new ItemHeader("Version Information")); std::string apiVersion; - if (g_Config.iGPUBackend == GPU_BACKEND_OPENGL) { + if (GetGPUBackend() == GPUBackend::OPENGL) { if (gl_extensions.IsGLES) { apiVersion = StringFromFormat("v%d.%d.%d ES", gl_extensions.ver[0], gl_extensions.ver[1], gl_extensions.ver[2]); } else { diff --git a/UI/EmuScreen.cpp b/UI/EmuScreen.cpp index fd2a5f25e6..3b785c2d7b 100644 --- a/UI/EmuScreen.cpp +++ b/UI/EmuScreen.cpp @@ -98,7 +98,7 @@ void EmuScreen::bootGame(const std::string &filename) { CoreParameter coreParam; coreParam.cpuCore = g_Config.bJit ? CPU_JIT : CPU_INTERPRETER; coreParam.gpuCore = g_Config.bSoftwareRendering ? GPU_SOFTWARE : GPU_GLES; - if (g_Config.iGPUBackend == GPU_BACKEND_DIRECT3D9) { + if (GetGPUBackend() == GPUBackend::DIRECT3D9) { coreParam.gpuCore = GPU_DIRECTX9; } // Preserve the existing graphics context. @@ -152,7 +152,7 @@ void EmuScreen::bootComplete() { #endif memset(virtKeys, 0, sizeof(virtKeys)); - if (g_Config.iGPUBackend == GPU_BACKEND_OPENGL) { + if (GetGPUBackend() == GPUBackend::OPENGL) { const char *renderer = (const char*)glGetString(GL_RENDERER); if (strstr(renderer, "Chainfire3D") != 0) { osm.Show(sc->T("Chainfire3DWarning", "WARNING: Chainfire3D detected, may cause problems"), 10.0f, 0xFF30a0FF, -1, true); @@ -901,7 +901,7 @@ void EmuScreen::render() { if (invalid_) return; - if (useBufferedRendering && g_Config.iGPUBackend == GPU_BACKEND_OPENGL) + if (useBufferedRendering && GetGPUBackend() == GPUBackend::OPENGL) fbo_unbind(); if (!osm.IsEmpty() || g_Config.bShowDebugStats || g_Config.iShowFPSCounter || g_Config.bShowTouchControls || g_Config.bShowDeveloperMenu || g_Config.bShowAudioDebug || saveStatePreview_->GetVisibility() != UI::V_GONE || g_Config.bShowFrameProfiler) { diff --git a/UI/GameSettingsScreen.cpp b/UI/GameSettingsScreen.cpp index fdf7278623..7de23b92b3 100644 --- a/UI/GameSettingsScreen.cpp +++ b/UI/GameSettingsScreen.cpp @@ -135,7 +135,7 @@ void GameSettingsScreen::CreateViews() { graphicsSettings->Add(new ItemHeader(gr->T("Rendering Mode"))); #if defined(_WIN32) static const char *renderingBackend[] = { "OpenGL", "Direct3D9" }; - PopupMultiChoice *renderingBackendChoice = graphicsSettings->Add(new PopupMultiChoice(&g_Config.iTempGPUBackend, gr->T("Backend"), renderingBackend, GPU_BACKEND_OPENGL, ARRAY_SIZE(renderingBackend), gr->GetName(), screenManager())); + PopupMultiChoice *renderingBackendChoice = graphicsSettings->Add(new PopupMultiChoice(&g_Config.iGPUBackend, gr->T("Backend"), renderingBackend, GPU_BACKEND_OPENGL, ARRAY_SIZE(renderingBackend), gr->GetName(), screenManager())); renderingBackendChoice->OnChoice.Handle(this, &GameSettingsScreen::OnRenderingBackend); #endif static const char *renderingMode[] = { "Non-Buffered Rendering", "Buffered Rendering", "Read Framebuffers To Memory (CPU)", "Read Framebuffers To Memory (GPU)"}; @@ -871,13 +871,18 @@ void GlobalSettingsScreen::CreateViews() { void GameSettingsScreen::CallbackRenderingBackend(bool yes) { #if defined(_WIN32) - // If the user ends up deciding not to restart, set the temporary variable back to the current backend + // If the user ends up deciding not to restart, set the config back to the current backend // so it doesn't get switched by accident. if (yes) { + if (g_Config.iGPUBackend == (int)GPUBackend::DIRECT3D9) { + // TODO: Remove once software renderer supports D3D9. + g_Config.bSoftwareRendering = false; + } + g_Config.bRestartRequired = true; PostMessage(MainWindow::GetHWND(), WM_CLOSE, 0, 0); } else { - g_Config.iTempGPUBackend = g_Config.iGPUBackend; + g_Config.iGPUBackend = (int)GetGPUBackend(); } #endif } @@ -887,7 +892,7 @@ UI::EventReturn GameSettingsScreen::OnRenderingBackend(UI::EventParams &e) { I18NCategory *di = GetI18NCategory("Dialog"); // It only makes sense to show the restart prompt if the backend was actually changed. - if (g_Config.iTempGPUBackend != g_Config.iGPUBackend) { + if (g_Config.iGPUBackend != (int)GetGPUBackend()) { screenManager()->push(new PromptScreen(di->T("ChangingGPUBackends", "Changing GPU backends requires PPSSPP to restart. Restart now?"), di->T("Yes"), di->T("No"), std::bind(&GameSettingsScreen::CallbackRenderingBackend, this, placeholder::_1))); } diff --git a/UI/NativeApp.cpp b/UI/NativeApp.cpp index adf7da59e9..0c5b26ab5a 100644 --- a/UI/NativeApp.cpp +++ b/UI/NativeApp.cpp @@ -501,7 +501,8 @@ void NativeInit(int argc, const char *argv[], // We do this here, instead of in NativeInitGraphics, because the display may be reset. // When it's reset we don't want to forget all our managed things. - if (g_Config.iGPUBackend == GPU_BACKEND_OPENGL) { + SetGPUBackend((GPUBackend) g_Config.iGPUBackend); + if (GetGPUBackend() == GPUBackend::OPENGL) { gl_lost_manager_init(); } } @@ -689,7 +690,7 @@ void NativeRender(GraphicsContext *graphicsContext) { // Apply the UIContext bounds as a 2D transformation matrix. Matrix4x4 ortho; - if (g_Config.iGPUBackend == GPU_BACKEND_DIRECT3D9) { + if (GetGPUBackend() == GPUBackend::DIRECT3D9) { ortho.setOrthoD3D(0.0f, xres, yres, 0.0f, -1.0f, 1.0f); Matrix4x4 translation; translation.setTranslation(Vec3(-0.5f, -0.5f, 0.0f)); @@ -718,7 +719,7 @@ void NativeRender(GraphicsContext *graphicsContext) { graphicsContext->Resize(); // TODO: Move this to new GraphicsContext objects for each backend. #ifndef _WIN32 - if (g_Config.iGPUBackend == GPU_BACKEND_OPENGL) { + if (GetGPUBackend() == GPUBackend::OPENGL) { PSP_CoreParameter().pixelWidth = pixel_xres; PSP_CoreParameter().pixelHeight = pixel_yres; NativeMessageReceived("gpu resized", ""); @@ -757,7 +758,7 @@ void NativeDeviceLost() { g_gameInfoCache.Clear(); screenManager->deviceLost(); - if (g_Config.iGPUBackend == GPU_BACKEND_OPENGL) { + if (GetGPUBackend() == GPUBackend::OPENGL) { gl_lost(); } // Should dirty EVERYTHING @@ -915,7 +916,7 @@ void NativeResized() { } void NativeShutdown() { - if (g_Config.iGPUBackend == GPU_BACKEND_OPENGL) { + if (GetGPUBackend() == GPUBackend::OPENGL) { gl_lost_manager_shutdown(); } diff --git a/Windows/MainWindowMenu.cpp b/Windows/MainWindowMenu.cpp index e7ed9dea07..9e87c9d83d 100644 --- a/Windows/MainWindowMenu.cpp +++ b/Windows/MainWindowMenu.cpp @@ -666,13 +666,15 @@ namespace MainWindow { break; case ID_OPTIONS_DIRECTX: - g_Config.iTempGPUBackend = GPU_BACKEND_DIRECT3D9; + g_Config.iGPUBackend = GPU_BACKEND_DIRECT3D9; + // TODO: Remove once software renderer supports D3D9. + g_Config.bSoftwareRendering = false; g_Config.bRestartRequired = true; PostMessage(MainWindow::GetHWND(), WM_CLOSE, 0, 0); break; case ID_OPTIONS_OPENGL: - g_Config.iTempGPUBackend = GPU_BACKEND_OPENGL; + g_Config.iGPUBackend = GPU_BACKEND_OPENGL; g_Config.bRestartRequired = true; PostMessage(MainWindow::GetHWND(), WM_CLOSE, 0, 0); break; diff --git a/Windows/main.cpp b/Windows/main.cpp index 6cbe20f783..375a8a12ee 100644 --- a/Windows/main.cpp +++ b/Windows/main.cpp @@ -600,16 +600,6 @@ int WINAPI WinMain(HINSTANCE _hInstance, HINSTANCE hPrevInstance, LPSTR szCmdLin timeEndPeriod(1); delete host; - // Is there a safer place to do this? - // Doing this in Config::Save requires knowing if the UI state is UISTATE_EXIT, - // but that causes UnitTest to fail linking with 400 errors if System.h is included.. - if (g_Config.iTempGPUBackend != g_Config.iGPUBackend) { - g_Config.iGPUBackend = g_Config.iTempGPUBackend; - - // For now, turn off software rendering too, similar to the command-line. - g_Config.bSoftwareRendering = false; - } - g_Config.Save(); g_gameInfoCache.Clear(); g_gameInfoCache.Shutdown();