Change priority order of X11 WSI extensions

master
Camilla Berglund ago%!(EXTRA string=9 years)
parent 65870346e4
commit 6e103d5dca
  1. 106
      src/x11_window.c

@ -2123,19 +2123,19 @@ char** _glfwPlatformGetRequiredInstanceExtensions(int* count)
*count = 0; *count = 0;
if (!_glfw.vk.KHR_xlib_surface) if (!_glfw.vk.KHR_xcb_surface || !_glfw.x11.x11xcb.handle)
{ {
if (!_glfw.vk.KHR_xcb_surface || !_glfw.x11.x11xcb.handle) if (!_glfw.vk.KHR_xlib_surface)
return NULL; return NULL;
} }
extensions = calloc(2, sizeof(char*)); extensions = calloc(2, sizeof(char*));
extensions[0] = strdup("VK_KHR_surface"); extensions[0] = strdup("VK_KHR_surface");
if (_glfw.vk.KHR_xlib_surface) if (_glfw.vk.KHR_xcb_surface)
extensions[1] = strdup("VK_KHR_xlib_surface");
else
extensions[1] = strdup("VK_KHR_xcb_surface"); extensions[1] = strdup("VK_KHR_xcb_surface");
else
extensions[1] = strdup("VK_KHR_xlib_surface");
*count = 2; *count = 2;
return extensions; return extensions;
@ -2148,24 +2148,7 @@ int _glfwPlatformGetPhysicalDevicePresentationSupport(VkInstance instance,
VisualID visualID = XVisualIDFromVisual(DefaultVisual(_glfw.x11.display, VisualID visualID = XVisualIDFromVisual(DefaultVisual(_glfw.x11.display,
_glfw.x11.screen)); _glfw.x11.screen));
if (_glfw.vk.KHR_xlib_surface) if (_glfw.vk.KHR_xcb_surface)
{
PFN_vkGetPhysicalDeviceXlibPresentationSupportKHR vkGetPhysicalDeviceXlibPresentationSupportKHR =
(PFN_vkGetPhysicalDeviceXlibPresentationSupportKHR)
vkGetInstanceProcAddr(instance, "vkGetPhysicalDeviceXlibPresentationSupportKHR");
if (!vkGetPhysicalDeviceXlibPresentationSupportKHR)
{
_glfwInputError(GLFW_API_UNAVAILABLE,
"X11: Vulkan instance missing VK_KHR_xlib_surface extension");
return GLFW_FALSE;
}
return vkGetPhysicalDeviceXlibPresentationSupportKHR(device,
queuefamily,
_glfw.x11.display,
visualID);
}
else
{ {
PFN_vkGetPhysicalDeviceXcbPresentationSupportKHR vkGetPhysicalDeviceXcbPresentationSupportKHR = PFN_vkGetPhysicalDeviceXcbPresentationSupportKHR vkGetPhysicalDeviceXcbPresentationSupportKHR =
(PFN_vkGetPhysicalDeviceXcbPresentationSupportKHR) (PFN_vkGetPhysicalDeviceXcbPresentationSupportKHR)
@ -2191,6 +2174,23 @@ int _glfwPlatformGetPhysicalDevicePresentationSupport(VkInstance instance,
connection, connection,
visualID); visualID);
} }
else
{
PFN_vkGetPhysicalDeviceXlibPresentationSupportKHR vkGetPhysicalDeviceXlibPresentationSupportKHR =
(PFN_vkGetPhysicalDeviceXlibPresentationSupportKHR)
vkGetInstanceProcAddr(instance, "vkGetPhysicalDeviceXlibPresentationSupportKHR");
if (!vkGetPhysicalDeviceXlibPresentationSupportKHR)
{
_glfwInputError(GLFW_API_UNAVAILABLE,
"X11: Vulkan instance missing VK_KHR_xlib_surface extension");
return GLFW_FALSE;
}
return vkGetPhysicalDeviceXlibPresentationSupportKHR(device,
queuefamily,
_glfw.x11.display,
visualID);
}
} }
VkResult _glfwPlatformCreateWindowSurface(VkInstance instance, VkResult _glfwPlatformCreateWindowSurface(VkInstance instance,
@ -2198,31 +2198,40 @@ VkResult _glfwPlatformCreateWindowSurface(VkInstance instance,
const VkAllocationCallbacks* allocator, const VkAllocationCallbacks* allocator,
VkSurfaceKHR* surface) VkSurfaceKHR* surface)
{ {
if (_glfw.vk.KHR_xlib_surface) if (_glfw.vk.KHR_xcb_surface)
{ {
VkResult err; VkResult err;
VkXlibSurfaceCreateInfoKHR sci; VkXcbSurfaceCreateInfoKHR sci;
PFN_vkCreateXlibSurfaceKHR vkCreateXlibSurfaceKHR; PFN_vkCreateXcbSurfaceKHR vkCreateXcbSurfaceKHR;
vkCreateXlibSurfaceKHR = (PFN_vkCreateXlibSurfaceKHR) xcb_connection_t* connection =
vkGetInstanceProcAddr(instance, "vkCreateXlibSurfaceKHR"); _glfw.x11.x11xcb.XGetXCBConnection(_glfw.x11.display);
if (!vkCreateXlibSurfaceKHR) if (!connection)
{
_glfwInputError(GLFW_PLATFORM_ERROR,
"X11: Failed to retrieve XCB connection");
return VK_ERROR_EXTENSION_NOT_PRESENT;
}
vkCreateXcbSurfaceKHR = (PFN_vkCreateXcbSurfaceKHR)
vkGetInstanceProcAddr(instance, "vkCreateXcbSurfaceKHR");
if (!vkCreateXcbSurfaceKHR)
{ {
_glfwInputError(GLFW_API_UNAVAILABLE, _glfwInputError(GLFW_API_UNAVAILABLE,
"X11: Vulkan instance missing VK_KHR_xlib_surface extension"); "X11: Vulkan instance missing VK_KHR_xcb_surface extension");
return VK_ERROR_EXTENSION_NOT_PRESENT; return VK_ERROR_EXTENSION_NOT_PRESENT;
} }
memset(&sci, 0, sizeof(sci)); memset(&sci, 0, sizeof(sci));
sci.sType = VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR; sci.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
sci.dpy = _glfw.x11.display; sci.connection = connection;
sci.window = window->x11.handle; sci.window = window->x11.handle;
err = vkCreateXlibSurfaceKHR(instance, &sci, allocator, surface); err = vkCreateXcbSurfaceKHR(instance, &sci, allocator, surface);
if (err) if (err)
{ {
_glfwInputError(GLFW_PLATFORM_ERROR, _glfwInputError(GLFW_PLATFORM_ERROR,
"X11: Failed to create Vulkan X11 surface: %s", "X11: Failed to create Vulkan XCB surface: %s",
_glfwGetVulkanResultString(err)); _glfwGetVulkanResultString(err));
} }
@ -2231,37 +2240,28 @@ VkResult _glfwPlatformCreateWindowSurface(VkInstance instance,
else else
{ {
VkResult err; VkResult err;
VkXcbSurfaceCreateInfoKHR sci; VkXlibSurfaceCreateInfoKHR sci;
PFN_vkCreateXcbSurfaceKHR vkCreateXcbSurfaceKHR; PFN_vkCreateXlibSurfaceKHR vkCreateXlibSurfaceKHR;
xcb_connection_t* connection =
_glfw.x11.x11xcb.XGetXCBConnection(_glfw.x11.display);
if (!connection)
{
_glfwInputError(GLFW_PLATFORM_ERROR,
"X11: Failed to retrieve XCB connection");
return VK_ERROR_EXTENSION_NOT_PRESENT;
}
vkCreateXcbSurfaceKHR = (PFN_vkCreateXcbSurfaceKHR) vkCreateXlibSurfaceKHR = (PFN_vkCreateXlibSurfaceKHR)
vkGetInstanceProcAddr(instance, "vkCreateXcbSurfaceKHR"); vkGetInstanceProcAddr(instance, "vkCreateXlibSurfaceKHR");
if (!vkCreateXcbSurfaceKHR) if (!vkCreateXlibSurfaceKHR)
{ {
_glfwInputError(GLFW_API_UNAVAILABLE, _glfwInputError(GLFW_API_UNAVAILABLE,
"X11: Vulkan instance missing VK_KHR_xcb_surface extension"); "X11: Vulkan instance missing VK_KHR_xlib_surface extension");
return VK_ERROR_EXTENSION_NOT_PRESENT; return VK_ERROR_EXTENSION_NOT_PRESENT;
} }
memset(&sci, 0, sizeof(sci)); memset(&sci, 0, sizeof(sci));
sci.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR; sci.sType = VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR;
sci.connection = connection; sci.dpy = _glfw.x11.display;
sci.window = window->x11.handle; sci.window = window->x11.handle;
err = vkCreateXcbSurfaceKHR(instance, &sci, allocator, surface); err = vkCreateXlibSurfaceKHR(instance, &sci, allocator, surface);
if (err) if (err)
{ {
_glfwInputError(GLFW_PLATFORM_ERROR, _glfwInputError(GLFW_PLATFORM_ERROR,
"X11: Failed to create Vulkan XCB surface: %s", "X11: Failed to create Vulkan X11 surface: %s",
_glfwGetVulkanResultString(err)); _glfwGetVulkanResultString(err));
} }

Loading…
Cancel
Save