win32: Try to handle race in changing drivers.

This commit is contained in:
BearOso 2023-02-20 15:15:38 -06:00
parent 4f08da4cd8
commit 54770ef3cc
2 changed files with 25 additions and 7 deletions

View File

@ -14,9 +14,15 @@ bool CVulkan::Initialize(HWND hWnd)
current_width = window_rect.right - window_rect.left; current_width = window_rect.right - window_rect.left;
current_height = window_rect.bottom - window_rect.top; current_height = window_rect.bottom - window_rect.top;
context = std::make_unique<Vulkan::Context>(); try {
if (!context->init_win32(0, hWnd)) context = std::make_unique<Vulkan::Context>();
if (!context->init_win32(0, hWnd))
return false;
}
catch (std::exception& e)
{
return false; return false;
}
if (GUI.shaderEnabled && GUI.OGLshaderFileName && GUI.OGLshaderFileName[0]) if (GUI.shaderEnabled && GUI.OGLshaderFileName && GUI.OGLshaderFileName[0])
{ {

View File

@ -107,6 +107,9 @@ returns true if successful, false otherwise
bool WinDisplayReset(void) bool WinDisplayReset(void)
{ {
S9xDisplayOutput->DeInitialize(); S9xDisplayOutput->DeInitialize();
if (S9xDisplayOutput == (IS9xDisplayOutput *)&VulkanDriver && GUI.outputMethod == OPENGL)
Sleep(500);
switch(GUI.outputMethod) { switch(GUI.outputMethod) {
default: default:
case DIRECT3D: case DIRECT3D:
@ -124,14 +127,23 @@ bool WinDisplayReset(void)
S9xDisplayOutput = &VulkanDriver; S9xDisplayOutput = &VulkanDriver;
break; break;
} }
if(S9xDisplayOutput->Initialize(GUI.hWnd)) {
bool initialized = S9xDisplayOutput->Initialize(GUI.hWnd);
if (!initialized) {
S9xDisplayOutput->DeInitialize();
Sleep(500);
initialized = S9xDisplayOutput->Initialize(GUI.hWnd);
}
if (initialized) {
S9xGraphicsDeinit(); S9xGraphicsDeinit();
S9xSetWinPixelFormat (); S9xSetWinPixelFormat();
S9xGraphicsInit(); S9xGraphicsInit();
if (GUI.DWMSync) if (GUI.DWMSync)
{ {
HMODULE dwmlib = LoadLibrary(TEXT("dwmapi")); HMODULE dwmlib = LoadLibrary(TEXT("dwmapi"));
DwmFlushProc = (DWMFLUSHPROC)GetProcAddress(dwmlib, "DwmFlush"); DwmFlushProc = (DWMFLUSHPROC)GetProcAddress(dwmlib, "DwmFlush");
DwmIsCompositionEnabledProc = (DWMISCOMPOSITIONENABLEDPROC)GetProcAddress(dwmlib, "DwmIsCompositionEnabled"); DwmIsCompositionEnabledProc = (DWMISCOMPOSITIONENABLEDPROC)GetProcAddress(dwmlib, "DwmIsCompositionEnabled");