Win32: Allow the Vulkan driver to fail at the loader stage.

This commit is contained in:
BearOso 2023-03-24 14:39:31 -05:00
parent 929a213b71
commit 3c50e995ee
2 changed files with 44 additions and 23 deletions

View File

@ -12,17 +12,6 @@ static std::unique_ptr<vk::DynamicLoader> dl;
Context::Context()
{
if (!dl)
{
dl = std::make_unique<vk::DynamicLoader>();
if (!dl->success())
return;
}
auto vkGetInstanceProcAddr =
dl->getProcAddress<PFN_vkGetInstanceProcAddr>("vkGetInstanceProcAddr");
VULKAN_HPP_DEFAULT_DISPATCHER.init(vkGetInstanceProcAddr);
}
Context::~Context()
@ -44,8 +33,28 @@ Context::~Context()
device.destroy();
}
static bool load_loader()
{
if (dl)
return true;
dl = std::make_unique<vk::DynamicLoader>();
if (!dl->success())
{
dl.reset();
return false;
}
auto vkGetInstanceProcAddr =
dl->getProcAddress<PFN_vkGetInstanceProcAddr>("vkGetInstanceProcAddr");
VULKAN_HPP_DEFAULT_DISPATCHER.init(vkGetInstanceProcAddr);
return true;
}
static vk::UniqueInstance create_instance_preamble(const char *wsi_extension)
{
load_loader();
if (!dl || !dl->success())
return vk::UniqueInstance();

View File

@ -98,15 +98,6 @@ void WinChangeWindowSize(unsigned int newWidth, unsigned int newHeight)
S9xDisplayOutput->ChangeRenderSize(newWidth,newHeight);
}
static void FlushMessageQueue()
{
for (MSG msg; PeekMessage(&msg, GUI.hWnd, 0, 0, PM_NOREMOVE);)
{
GetMessage(&msg, GUI.hWnd, 0, 0);
DispatchMessage(&msg);
}
}
/* WinDisplayReset
initializes the currently selected display output and
reinitializes the core graphics rendering
@ -115,10 +106,10 @@ returns true if successful, false otherwise
*/
bool WinDisplayReset(void)
{
const TCHAR* driverNames[] = { TEXT("DirectDraw"), TEXT("Direct3D"), TEXT("OpenGL"), TEXT("Vulkan") };
static bool VulkanUsed = false;
static bool OpenGLUsed = false;
S9xDisplayOutput->DeInitialize();
FlushMessageQueue();
switch(GUI.outputMethod) {
default:
@ -137,7 +128,6 @@ bool WinDisplayReset(void)
break;
}
S9xDisplayOutput = &OpenGL;
OpenGLUsed = true;
break;
case VULKAN:
if (OpenGLUsed)
@ -146,7 +136,6 @@ bool WinDisplayReset(void)
break;
}
S9xDisplayOutput = &VulkanDriver;
VulkanUsed = true;
break;
}
@ -155,10 +144,33 @@ bool WinDisplayReset(void)
if (!initialized) {
S9xDisplayOutput->DeInitialize();
Sleep(500);
auto oldDriverName = driverNames[GUI.outputMethod];
if (GUI.outputMethod == VULKAN)
{
GUI.outputMethod = OPENGL;
S9xDisplayOutput = &OpenGL;
}
else
{
GUI.outputMethod = DIRECT3D;
S9xDisplayOutput = &Direct3D;
}
auto newDriverName = driverNames[GUI.outputMethod];
TCHAR msg[512];
_stprintf(msg, TEXT("Couldn't load selected driver: %s. Trying %s."), oldDriverName, newDriverName);
MessageBox(GUI.hWnd, msg, TEXT("Snes9x Display Driver"), MB_OK | MB_ICONERROR);
initialized = S9xDisplayOutput->Initialize(GUI.hWnd);
}
if (initialized) {
if (S9xDisplayOutput == &VulkanDriver)
VulkanUsed = true;
if (S9xDisplayOutput == &OpenGL)
OpenGLUsed = true;
S9xGraphicsDeinit();
S9xSetWinPixelFormat();
S9xGraphicsInit();