Windows: Avoid restarting completely on GPU change.

This retains the logger, avoids an annoying window open/close, and most
importantly for me: keeps the debugger attached.
This commit is contained in:
Unknown W. Brackets 2017-04-15 16:33:30 -07:00
parent 638a015ced
commit e8e65881b8
9 changed files with 33 additions and 12 deletions

View File

@ -97,6 +97,10 @@ static volatile CPUThreadState cpuThreadState = CPU_THREAD_NOT_RUNNING;
static GPUBackend gpuBackend;
void ResetUIState() {
globalUIState = UISTATE_MENU;
}
void UpdateUIState(GlobalUIState newState) {
// Never leave the EXIT state.
if (globalUIState != newState && globalUIState != UISTATE_EXIT) {

View File

@ -54,6 +54,7 @@ enum PSPDirectories {
class GraphicsContext;
enum class GPUBackend;
void ResetUIState();
void UpdateUIState(GlobalUIState newState);
GlobalUIState GetUIState();

View File

@ -1057,8 +1057,7 @@ void GameSettingsScreen::CallbackRenderingBackend(bool yes) {
// 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) {
g_Config.bRestartRequired = true;
PostMessage(MainWindow::GetHWND(), WM_CLOSE, 0, 0);
System_SendMessage("graphics_restart", "");
} else {
g_Config.iGPUBackend = (int)GetGPUBackend();
}

View File

@ -112,6 +112,7 @@ unsigned int WINAPI TheThread(void *)
args.push_back(string.c_str());
}
bool performingRestart = NativeIsRestarting();
NativeInit(static_cast<int>(args.size()), &args[0], "1234", "1234", nullptr);
Host *nativeHost = host;
@ -123,6 +124,14 @@ unsigned int WINAPI TheThread(void *)
std::string error_string;
if (!host->InitGraphics(&error_string, &graphicsContext)) {
// Before anything: are we restarting right now?
if (performingRestart) {
// Okay, switching graphics didn't work out. Probably a driver bug - fallback to restart.
// This happens on NVIDIA when switching OpenGL -> Vulkan.
g_Config.Save();
W32Util::ExitAndRestart();
}
I18NCategory *err = GetI18NCategory("Error");
Reporting::ReportMessage("Graphics init error: %s", error_string.c_str());

View File

@ -882,6 +882,14 @@ namespace MainWindow
BrowseBackgroundDone();
break;
case WM_USER_RESTART_EMUTHREAD:
NativeSetRestarting();
EmuThread_Stop();
coreState = CORE_POWERUP;
ResetUIState();
EmuThread_Start();
break;
case WM_MENUSELECT:
// Called when a menu is opened. Also when an item is selected, but meh.
UpdateMenus(true);

View File

@ -20,6 +20,7 @@ namespace MainWindow
WM_USER_WINDOW_TITLE_CHANGED = WM_USER + 103,
WM_USER_BROWSE_BOOT_DONE = WM_USER + 104,
WM_USER_TOGGLE_FULLSCREEN = WM_USER + 105,
WM_USER_RESTART_EMUTHREAD = WM_USER + 106,
};
enum {

View File

@ -770,26 +770,22 @@ namespace MainWindow {
case ID_OPTIONS_DIRECT3D9:
g_Config.iGPUBackend = GPU_BACKEND_DIRECT3D9;
g_Config.bRestartRequired = true;
PostMessage(MainWindow::GetHWND(), WM_CLOSE, 0, 0);
PostMessage(MainWindow::GetHWND(), WM_USER_RESTART_EMUTHREAD, 0, 0);
break;
case ID_OPTIONS_DIRECT3D11:
g_Config.iGPUBackend = GPU_BACKEND_DIRECT3D11;
g_Config.bRestartRequired = true;
PostMessage(MainWindow::GetHWND(), WM_CLOSE, 0, 0);
PostMessage(MainWindow::GetHWND(), WM_USER_RESTART_EMUTHREAD, 0, 0);
break;
case ID_OPTIONS_OPENGL:
g_Config.iGPUBackend = GPU_BACKEND_OPENGL;
g_Config.bRestartRequired = true;
PostMessage(MainWindow::GetHWND(), WM_CLOSE, 0, 0);
PostMessage(MainWindow::GetHWND(), WM_USER_RESTART_EMUTHREAD, 0, 0);
break;
case ID_OPTIONS_VULKAN:
g_Config.iGPUBackend = GPU_BACKEND_VULKAN;
g_Config.bRestartRequired = true;
PostMessage(MainWindow::GetHWND(), WM_CLOSE, 0, 0);
PostMessage(MainWindow::GetHWND(), WM_USER_RESTART_EMUTHREAD, 0, 0);
break;
case ID_OPTIONS_NONBUFFEREDRENDERING: setRenderingMode(FB_NON_BUFFERED_MODE); break;

View File

@ -146,7 +146,6 @@ void WindowsHost::ShutdownGraphics() {
gfx_->Shutdown();
delete gfx_;
gfx_ = nullptr;
PostMessage(mainWindow_, WM_CLOSE, 0, 0);
}
void WindowsHost::SetWindowTitle(const char *message) {

View File

@ -231,7 +231,11 @@ int System_GetPropertyInt(SystemProperty prop) {
void System_SendMessage(const char *command, const char *parameter) {
if (!strcmp(command, "finish")) {
PostMessage(MainWindow::GetHWND(), WM_CLOSE, 0, 0);
if (!NativeIsRestarting()) {
PostMessage(MainWindow::GetHWND(), WM_CLOSE, 0, 0);
}
} else if (!strcmp(command, "graphics_restart")) {
PostMessage(MainWindow::GetHWND(), MainWindow::WM_USER_RESTART_EMUTHREAD, 0, 0);
} else if (!strcmp(command, "setclipboardtext")) {
if (OpenClipboard(MainWindow::GetDisplayHWND())) {
std::wstring data = ConvertUTF8ToWString(parameter);