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.
This commit is contained in:
Unknown W. Brackets 2016-01-05 22:37:28 -08:00
parent 8b27bc51f5
commit aa0055cea7
12 changed files with 49 additions and 43 deletions

View File

@ -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();

View File

@ -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

View File

@ -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
}

View File

@ -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;
}

View File

@ -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);

View File

@ -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;

View File

@ -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 {

View File

@ -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) {

View File

@ -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)));
}

View File

@ -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();
}

View File

@ -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;

View File

@ -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();