UI: Ask for restart when changing graphics device.

Only for D3D11 and Vulkan.

Also, makes Vulkan follow D3D11 in not changing the setting if the device
is not found on startup.
This commit is contained in:
Unknown W. Brackets
2018-09-30 00:53:21 -07:00
parent f90439a70e
commit 7ee4d2d5a1
6 changed files with 60 additions and 15 deletions
+43 -10
View File
@@ -120,6 +120,18 @@ static std::string PostShaderTranslateName(const char *value) {
}
}
static std::string *GPUDeviceNameSetting() {
if (g_Config.iGPUBackend == (int)GPUBackend::VULKAN) {
return &g_Config.sVulkanDevice;
}
#ifdef _WIN32
if (g_Config.iGPUBackend == (int)GPUBackend::DIRECT3D11) {
return &g_Config.sD3D11Device;
}
#endif
return nullptr;
}
void GameSettingsScreen::CreateViews() {
ReloadAllPostShaderInfo();
@@ -212,18 +224,10 @@ void GameSettingsScreen::CreateViews() {
// Backends that don't allow a device choice will only expose one device.
if (draw->GetDeviceList().size() > 1) {
std::string *deviceNameSetting = nullptr;
if (g_Config.iGPUBackend == (int)GPUBackend::VULKAN) {
deviceNameSetting = &g_Config.sVulkanDevice;
}
#ifdef _WIN32
if (g_Config.iGPUBackend == (int)GPUBackend::DIRECT3D11) {
deviceNameSetting = &g_Config.sD3D11Device;
}
#endif
std::string *deviceNameSetting = GPUDeviceNameSetting();
if (deviceNameSetting) {
PopupMultiChoiceDynamic *deviceChoice = graphicsSettings->Add(new PopupMultiChoiceDynamic(deviceNameSetting, gr->T("Device"), draw->GetDeviceList(), nullptr, screenManager()));
deviceChoice->OnChoice.Handle(this, &GameSettingsScreen::OnRenderingBackend);
deviceChoice->OnChoice.Handle(this, &GameSettingsScreen::OnRenderingDevice);
}
}
@@ -1088,6 +1092,23 @@ void GameSettingsScreen::CallbackRenderingBackend(bool yes) {
}
}
void GameSettingsScreen::CallbackRenderingDevice(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) {
// Extra save here to make sure the choice really gets saved even if there are shutdown bugs in
// the GPU backend code.
g_Config.Save();
System_SendMessage("graphics_restart", "");
} else {
std::string *deviceNameSetting = GPUDeviceNameSetting();
if (deviceNameSetting)
*deviceNameSetting = GetGPUBackendDevice();
// Needed to redraw the setting.
RecreateViews();
}
}
UI::EventReturn GameSettingsScreen::OnRenderingBackend(UI::EventParams &e) {
I18NCategory *di = GetI18NCategory("Dialog");
@@ -1099,6 +1120,18 @@ UI::EventReturn GameSettingsScreen::OnRenderingBackend(UI::EventParams &e) {
return UI::EVENT_DONE;
}
UI::EventReturn GameSettingsScreen::OnRenderingDevice(UI::EventParams &e) {
I18NCategory *di = GetI18NCategory("Dialog");
// It only makes sense to show the restart prompt if the device was actually changed.
std::string *deviceNameSetting = GPUDeviceNameSetting();
if (deviceNameSetting && *deviceNameSetting != GetGPUBackendDevice()) {
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::CallbackRenderingDevice, this, std::placeholders::_1)));
}
return UI::EVENT_DONE;
}
UI::EventReturn GameSettingsScreen::OnChangeNickname(UI::EventParams &e) {
#if PPSSPP_PLATFORM(WINDOWS) || defined(USING_QT_UI)
const size_t name_len = 256;