mirror of https://github.com/AxioDL/boo.git
Fallback flow for graphics APIs
This commit is contained in:
parent
1c8236d100
commit
66c64cde08
|
@ -45,7 +45,7 @@ public:
|
|||
virtual EGraphicsAPI getAPI() const=0;
|
||||
virtual EPixelFormat getPixelFormat() const=0;
|
||||
virtual void setPixelFormat(EPixelFormat pf)=0;
|
||||
virtual void initializeContext(void* handle)=0;
|
||||
virtual bool initializeContext(void* handle)=0;
|
||||
virtual void makeCurrent()=0;
|
||||
virtual void postInit()=0;
|
||||
virtual void present()=0;
|
||||
|
|
|
@ -74,7 +74,7 @@ struct VulkanContext
|
|||
std::unordered_map<const boo::IWindow*, std::unique_ptr<Window>> m_windows;
|
||||
|
||||
void initVulkan(const char* appName);
|
||||
void enumerateDevices();
|
||||
bool enumerateDevices();
|
||||
void initDevice();
|
||||
void initSwapChain(Window& windowCtx, VkSurfaceKHR surface, VkFormat format, VkColorSpaceKHR colorspace);
|
||||
void resizeSwapChain(Window& windowCtx, VkSurfaceKHR surface, VkFormat format, VkColorSpaceKHR colorspace);
|
||||
|
|
|
@ -342,26 +342,32 @@ void VulkanContext::initVulkan(const char* appName)
|
|||
#endif
|
||||
}
|
||||
|
||||
void VulkanContext::enumerateDevices()
|
||||
bool VulkanContext::enumerateDevices()
|
||||
{
|
||||
uint32_t gpuCount = 1;
|
||||
ThrowIfFailed(vk::EnumeratePhysicalDevices(m_instance, &gpuCount, nullptr));
|
||||
assert(gpuCount);
|
||||
if (!gpuCount)
|
||||
return false;
|
||||
m_gpus.resize(gpuCount);
|
||||
|
||||
ThrowIfFailed(vk::EnumeratePhysicalDevices(m_instance, &gpuCount, m_gpus.data()));
|
||||
assert(gpuCount >= 1);
|
||||
if (!gpuCount)
|
||||
return false;
|
||||
|
||||
vk::GetPhysicalDeviceQueueFamilyProperties(m_gpus[0], &m_queueCount, nullptr);
|
||||
assert(m_queueCount >= 1);
|
||||
if (!m_queueCount)
|
||||
return false;
|
||||
|
||||
m_queueProps.resize(m_queueCount);
|
||||
vk::GetPhysicalDeviceQueueFamilyProperties(m_gpus[0], &m_queueCount, m_queueProps.data());
|
||||
assert(m_queueCount >= 1);
|
||||
if (!m_queueCount)
|
||||
return false;
|
||||
|
||||
/* This is as good a place as any to do this */
|
||||
vk::GetPhysicalDeviceMemoryProperties(m_gpus[0], &m_memoryProperties);
|
||||
vk::GetPhysicalDeviceProperties(m_gpus[0], &m_gpuProps);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void VulkanContext::initDevice()
|
||||
|
|
|
@ -219,7 +219,7 @@ public:
|
|||
m_pf = pf;
|
||||
}
|
||||
|
||||
void initializeContext(void*)
|
||||
bool initializeContext(void*)
|
||||
{
|
||||
m_nsContext = [[GraphicsContextCocoaGLInternal alloc] initWithBooContext:this];
|
||||
if (!m_nsContext)
|
||||
|
@ -229,6 +229,7 @@ public:
|
|||
CVDisplayLinkSetOutputCallback(m_dispLink, (CVDisplayLinkOutputCallback)DLCallback, this);
|
||||
CVDisplayLinkStart(m_dispLink);
|
||||
m_commandQueue = _NewGLCommandQueue(this);
|
||||
return true;
|
||||
}
|
||||
|
||||
void makeCurrent()
|
||||
|
@ -375,7 +376,7 @@ public:
|
|||
m_pf = pf;
|
||||
}
|
||||
|
||||
void initializeContext(void*)
|
||||
bool initializeContext(void*)
|
||||
{
|
||||
MetalContext::Window& w = m_metalCtx->m_windows[m_parentWindow];
|
||||
m_nsContext = [[GraphicsContextCocoaMetalInternal alloc] initWithBooContext:this];
|
||||
|
@ -387,6 +388,7 @@ public:
|
|||
CVDisplayLinkSetOutputCallback(m_dispLink, (CVDisplayLinkOutputCallback)DLCallback, this);
|
||||
CVDisplayLinkStart(m_dispLink);
|
||||
m_commandQueue = _NewMetalCommandQueue(m_metalCtx, m_parentWindow, this);
|
||||
return true;
|
||||
}
|
||||
|
||||
void makeCurrent()
|
||||
|
|
|
@ -164,7 +164,7 @@ public:
|
|||
m_pf = pf;
|
||||
}
|
||||
|
||||
void initializeContext(void*) {}
|
||||
bool initializeContext(void*) {return true;}
|
||||
|
||||
void makeCurrent() {}
|
||||
|
||||
|
@ -305,7 +305,7 @@ public:
|
|||
m_pf = pf;
|
||||
}
|
||||
|
||||
void initializeContext(void*) {}
|
||||
bool initializeContext(void*) {return true;}
|
||||
|
||||
void makeCurrent()
|
||||
{
|
||||
|
@ -487,7 +487,7 @@ public:
|
|||
m_pf = pf;
|
||||
}
|
||||
|
||||
void initializeContext(void* getVkProc)
|
||||
bool initializeContext(void* getVkProc)
|
||||
{
|
||||
vk::init_dispatch_table_top(PFN_vkGetInstanceProcAddr(getVkProc));
|
||||
if (m_ctx->m_instance == VK_NULL_HANDLE)
|
||||
|
@ -500,7 +500,8 @@ public:
|
|||
}
|
||||
|
||||
vk::init_dispatch_table_middle(m_ctx->m_instance, false);
|
||||
m_ctx->enumerateDevices();
|
||||
if (!m_ctx->enumerateDevices())
|
||||
return false;
|
||||
|
||||
m_windowCtx =
|
||||
m_ctx->m_windows.emplace(std::make_pair(m_parentWindow,
|
||||
|
@ -554,7 +555,7 @@ public:
|
|||
if (!vk::GetPhysicalDeviceWin32PresentationSupportKHR(m_ctx->m_gpus[0], m_ctx->m_graphicsQueueFamilyIndex))
|
||||
{
|
||||
Log.report(logvisor::Fatal, "Win32 doesn't support vulkan present");
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Get the list of VkFormats that are supported */
|
||||
|
@ -582,6 +583,7 @@ public:
|
|||
|
||||
m_dataFactory = new class VulkanDataFactory(this, m_ctx, m_sampleCount);
|
||||
m_commandQueue = _NewVulkanCommandQueue(m_ctx, m_ctx->m_windows[m_parentWindow].get(), this);
|
||||
return true;
|
||||
}
|
||||
|
||||
void makeCurrent() {}
|
||||
|
@ -974,7 +976,7 @@ public:
|
|||
{
|
||||
m_gfxCtx.reset(new GraphicsContextWin32Vulkan(this, wndInstance, m_hwnd, &g_VulkanContext,
|
||||
b3dCtx, sampleCount));
|
||||
m_gfxCtx->initializeContext(vulkanHandle);
|
||||
if (m_gfxCtx->initializeContext(vulkanHandle))
|
||||
return;
|
||||
}
|
||||
m_gfxCtx.reset(new GraphicsContextWin32D3D(api, this, m_hwnd, b3dCtx, sampleCount));
|
||||
|
|
|
@ -50,9 +50,9 @@ public:
|
|||
m_pf = pf;
|
||||
}
|
||||
|
||||
void initializeContext(void*)
|
||||
bool initializeContext(void*)
|
||||
{
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void makeCurrent()
|
||||
|
|
|
@ -439,7 +439,7 @@ public:
|
|||
m_pf = pf;
|
||||
}
|
||||
|
||||
void initializeContext(void*)
|
||||
bool initializeContext(void*)
|
||||
{
|
||||
if (!glXCreateContextAttribsARB)
|
||||
{
|
||||
|
@ -522,6 +522,8 @@ public:
|
|||
XUnlockDisplay(m_xDisp);
|
||||
m_commandQueue = _NewGLCommandQueue(this);
|
||||
XLockDisplay(m_xDisp);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void makeCurrent()
|
||||
|
@ -675,7 +677,7 @@ public:
|
|||
m_pf = pf;
|
||||
}
|
||||
|
||||
void initializeContext(void* getVkProc)
|
||||
bool initializeContext(void* getVkProc)
|
||||
{
|
||||
if (!glXWaitVideoSyncSGI)
|
||||
{
|
||||
|
@ -690,7 +692,8 @@ public:
|
|||
m_ctx->initVulkan(APP->getUniqueName().c_str());
|
||||
|
||||
vk::init_dispatch_table_middle(m_ctx->m_instance, false);
|
||||
m_ctx->enumerateDevices();
|
||||
if (!m_ctx->enumerateDevices())
|
||||
return false;
|
||||
|
||||
m_windowCtx =
|
||||
m_ctx->m_windows.emplace(std::make_pair(m_parentWindow,
|
||||
|
@ -744,7 +747,7 @@ public:
|
|||
if (!vk::GetPhysicalDeviceXcbPresentationSupportKHR(m_ctx->m_gpus[0], m_ctx->m_graphicsQueueFamilyIndex, m_xcbConn, m_visualid))
|
||||
{
|
||||
Log.report(logvisor::Fatal, "XCB visual doesn't support vulkan present");
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Get the list of VkFormats that are supported */
|
||||
|
@ -817,6 +820,8 @@ public:
|
|||
|
||||
m_dataFactory = new class VulkanDataFactory(this, m_ctx, m_drawSamples);
|
||||
m_commandQueue = _NewVulkanCommandQueue(m_ctx, m_ctx->m_windows[m_parentWindow].get(), this);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void makeCurrent() {}
|
||||
|
@ -916,14 +921,21 @@ public:
|
|||
if (!S_ATOMS)
|
||||
S_ATOMS = new XlibAtoms(display);
|
||||
|
||||
for (int i = 1; i >= 0 ; --i)
|
||||
{
|
||||
#if BOO_HAS_VULKAN
|
||||
if (vulkanHandle)
|
||||
if (vulkanHandle && i == 1)
|
||||
{
|
||||
m_gfxCtx.reset(new GraphicsContextXlibVulkan(this, display, (xcb_connection_t*)xcbConn, defaultScreen,
|
||||
&g_VulkanContext, m_visualId, drawSamples));
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
i = 0;
|
||||
m_gfxCtx.reset(new GraphicsContextXlibGLX(IGraphicsContext::EGraphicsAPI::OpenGL3_3,
|
||||
this, display, defaultScreen, lastCtx, m_visualId, drawSamples));
|
||||
}
|
||||
|
||||
/* Default screen */
|
||||
Screen* screen = ScreenOfDisplay(display, defaultScreen);
|
||||
|
@ -1017,7 +1029,15 @@ public:
|
|||
setCursor(EMouseCursor::Pointer);
|
||||
XFlush(m_xDisp);
|
||||
|
||||
m_gfxCtx->initializeContext(vulkanHandle);
|
||||
if (!m_gfxCtx->initializeContext(vulkanHandle))
|
||||
{
|
||||
XUnmapWindow(m_xDisp, m_windowId);
|
||||
XDestroyWindow(m_xDisp, m_windowId);
|
||||
XFreeColormap(m_xDisp, m_colormapId);
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
~WindowXlib()
|
||||
|
|
Loading…
Reference in New Issue