Vulkan: Fallback to XCB for Xlib surfaces
Chromium builds the Vulkan loader without support Xlib (because it prefers XCB) which caused Xlib wgpu::SwapChain creation to fail on the Vulkan backend. This CL adds a fallback to use VK_KHR_xcb_surface if VK_KHR_xlib_surface isn't present. Bug: dawn:662 Change-Id: I0e0128ee6b5c75da03998dbae231d17e48bacc81 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/41180 Reviewed-by: Austin Eng <enga@chromium.org> Commit-Queue: Austin Eng <enga@chromium.org> Auto-Submit: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
parent
b0ca30280a
commit
fb0bf70459
|
@ -162,6 +162,7 @@ namespace dawn_native { namespace vulkan {
|
||||||
|
|
||||||
#if defined(DAWN_USE_X11)
|
#if defined(DAWN_USE_X11)
|
||||||
# define VK_USE_PLATFORM_XLIB_KHR
|
# define VK_USE_PLATFORM_XLIB_KHR
|
||||||
|
# define VK_USE_PLATFORM_XCB_KHR
|
||||||
# include "common/xlib_with_undefs.h"
|
# include "common/xlib_with_undefs.h"
|
||||||
#endif // defined(DAWN_USE_X11)
|
#endif // defined(DAWN_USE_X11)
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
// This header includes <X11/Xlib.h> but removes all the extra defines that conflict with
|
// This header includes <X11/Xlib.h> but removes all the extra defines that conflict with
|
||||||
// identifiers in internal code. It should never be included in something that is part of the public
|
// identifiers in internal code. It should never be included in something that is part of the public
|
||||||
// interface.
|
// interface.
|
||||||
|
#include <X11/Xlib-xcb.h>
|
||||||
#include <X11/Xlib.h>
|
#include <X11/Xlib.h>
|
||||||
|
|
||||||
#undef Success
|
#undef Success
|
||||||
|
|
|
@ -295,7 +295,10 @@ source_set("dawn_native_sources") {
|
||||||
]
|
]
|
||||||
|
|
||||||
if (dawn_use_x11) {
|
if (dawn_use_x11) {
|
||||||
libs += [ "X11" ]
|
libs += [
|
||||||
|
"X11",
|
||||||
|
"X11-xcb",
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_win) {
|
if (is_win) {
|
||||||
|
|
|
@ -179,8 +179,17 @@ target_link_libraries(dawn_native
|
||||||
)
|
)
|
||||||
|
|
||||||
if (DAWN_USE_X11)
|
if (DAWN_USE_X11)
|
||||||
find_package(X11 REQUIRED)
|
find_package(X11 REQUIRED OPTIONAL_COMPONENTS X11_xcb)
|
||||||
target_link_libraries(dawn_native PRIVATE ${X11_LIBRARIES})
|
target_link_libraries(dawn_native PRIVATE ${X11_LIBRARIES})
|
||||||
|
target_include_directories(dawn_native PRIVATE ${X11_INCLUDE_DIR})
|
||||||
|
|
||||||
|
if (DAWN_ENABLE_VULKAN)
|
||||||
|
if (NOT X11_X11_xcb_FOUND)
|
||||||
|
message(FATAL_ERROR "X11::X11_xcb cannot be found, maybe because cmake < 3.18. Consider filing an issue for Dawn to bundle its own FindX11_XCB script")
|
||||||
|
endif()
|
||||||
|
target_link_libraries(dawn_native PRIVATE ${X11_X11_xcb_LIB})
|
||||||
|
target_include_directories(dawn_native PRIVATE ${X11_X11_xcb_INCLUDE_PATH})
|
||||||
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if (WIN32)
|
if (WIN32)
|
||||||
|
|
|
@ -145,6 +145,26 @@ namespace dawn_native { namespace vulkan {
|
||||||
"CreateXlibSurface"));
|
"CreateXlibSurface"));
|
||||||
return vkSurface;
|
return vkSurface;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Fall back to using XCB surfaces if the Xlib extension isn't available.
|
||||||
|
// See https://xcb.freedesktop.org/MixingCalls/ for more information about
|
||||||
|
// interoperability between Xlib and XCB
|
||||||
|
if (info.HasExt(InstanceExt::XcbSurface)) {
|
||||||
|
VkXcbSurfaceCreateInfoKHR createInfo;
|
||||||
|
createInfo.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
|
||||||
|
createInfo.pNext = nullptr;
|
||||||
|
createInfo.flags = 0;
|
||||||
|
// The XCB connection lives as long as the X11 display.
|
||||||
|
createInfo.connection =
|
||||||
|
XGetXCBConnection(static_cast<Display*>(surface->GetXDisplay()));
|
||||||
|
createInfo.window = surface->GetXWindow();
|
||||||
|
|
||||||
|
VkSurfaceKHR vkSurface = VK_NULL_HANDLE;
|
||||||
|
DAWN_TRY(CheckVkSuccess(
|
||||||
|
fn.CreateXcbSurfaceKHR(instance, &createInfo, nullptr, &*vkSurface),
|
||||||
|
"CreateXcbSurfaceKHR"));
|
||||||
|
return vkSurface;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
#endif // defined(DAWN_USE_X11)
|
#endif // defined(DAWN_USE_X11)
|
||||||
|
|
||||||
|
|
|
@ -152,6 +152,10 @@ namespace dawn_native { namespace vulkan {
|
||||||
GET_INSTANCE_PROC(CreateXlibSurfaceKHR);
|
GET_INSTANCE_PROC(CreateXlibSurfaceKHR);
|
||||||
GET_INSTANCE_PROC(GetPhysicalDeviceXlibPresentationSupportKHR);
|
GET_INSTANCE_PROC(GetPhysicalDeviceXlibPresentationSupportKHR);
|
||||||
}
|
}
|
||||||
|
if (globalInfo.HasExt(InstanceExt::XcbSurface)) {
|
||||||
|
GET_INSTANCE_PROC(CreateXcbSurfaceKHR);
|
||||||
|
GET_INSTANCE_PROC(GetPhysicalDeviceXcbPresentationSupportKHR);
|
||||||
|
}
|
||||||
#endif // defined(DAWN_USE_X11)
|
#endif // defined(DAWN_USE_X11)
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
|
@ -137,6 +137,11 @@ namespace dawn_native { namespace vulkan {
|
||||||
PFN_vkCreateXlibSurfaceKHR CreateXlibSurfaceKHR = nullptr;
|
PFN_vkCreateXlibSurfaceKHR CreateXlibSurfaceKHR = nullptr;
|
||||||
PFN_vkGetPhysicalDeviceXlibPresentationSupportKHR
|
PFN_vkGetPhysicalDeviceXlibPresentationSupportKHR
|
||||||
GetPhysicalDeviceXlibPresentationSupportKHR = nullptr;
|
GetPhysicalDeviceXlibPresentationSupportKHR = nullptr;
|
||||||
|
|
||||||
|
// KHR_xcb_surface
|
||||||
|
PFN_vkCreateXcbSurfaceKHR CreateXcbSurfaceKHR = nullptr;
|
||||||
|
PFN_vkGetPhysicalDeviceXcbPresentationSupportKHR
|
||||||
|
GetPhysicalDeviceXcbPresentationSupportKHR = nullptr;
|
||||||
#endif // defined(DAWN_USE_X11)
|
#endif // defined(DAWN_USE_X11)
|
||||||
|
|
||||||
// ---------- Device procs
|
// ---------- Device procs
|
||||||
|
|
Loading…
Reference in New Issue