Support both X11 and Wayland in the same build. (#3360)

* Support both X11 and Wayland in the same build.

 - Works for both Vulkan and OpenGL.
 - Remove --with-wayland from genie options.
 - Vulkan loads all three extensions for surface creation instead of only one.
 - Add width and height parameter to GlContext::createSwapChain(), which is needed for EGL to create
   a SwapChain with the given window size.
 - Dirty-fix the example-22-windows to recreate the FrameBuffer by first destroying and then
   recreating to make sure the window is released of its swapchain.
 - Fix dbgText glitch in example-22-windows.
 - Remove old X11-related dependencies for GLFW3.

* Formatting.
This commit is contained in:
Martijn Courteaux
2024-10-05 14:33:22 -07:00
committed by GitHub
parent 3f9fe0d34e
commit e488a07f1b
21 changed files with 224 additions and 242 deletions
+40 -10
View File
@@ -362,6 +362,20 @@ VK_IMPORT_DEVICE
KHR_draw_indirect_count,
KHR_get_physical_device_properties2,
# if BX_PLATFORM_ANDROID
KHR_android_surface,
# elif BX_PLATFORM_LINUX
KHR_wayland_surface,
KHR_xlib_surface,
KHR_xcb_surface,
# elif BX_PLATFORM_WINDOWS
KHR_win32_surface,
# elif BX_PLATFORM_OSX
MVK_macos_surface,
# elif BX_PLATFORM_NX
NN_vi_surface,
# endif
Count
};
@@ -386,6 +400,19 @@ VK_IMPORT_DEVICE
{ "VK_EXT_shader_viewport_index_layer", 1, false, false, true, Layer::Count },
{ "VK_KHR_draw_indirect_count", 1, false, false, true, Layer::Count },
{ "VK_KHR_get_physical_device_properties2", 1, false, false, true, Layer::Count },
# if BX_PLATFORM_ANDROID
{ VK_KHR_ANDROID_SURFACE_EXTENSION_NAME, 1, false, false, true, Layer::Count },
# elif BX_PLATFORM_LINUX
{ VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME, 1, false, false, true, Layer::Count },
{ VK_KHR_XLIB_SURFACE_EXTENSION_NAME, 1, false, false, true, Layer::Count },
{ VK_KHR_XCB_SURFACE_EXTENSION_NAME, 1, false, false, true, Layer::Count },
# elif BX_PLATFORM_WINDOWS
{ VK_KHR_WIN32_SURFACE_EXTENSION_NAME, 1, false, false, true, Layer::Count },
# elif BX_PLATFORM_OSX
{ VK_MVK_MACOS_SURFACE_EXTENSION_NAME, 1, false, false, true, Layer::Count },
# elif BX_PLATFORM_NX
{ VK_NN_VI_SURFACE_EXTENSION_NAME, 1, false, false, true, Layer::Count },
# endif
};
BX_STATIC_ASSERT(Extension::Count == BX_COUNTOF(s_extension) );
@@ -1178,7 +1205,7 @@ VK_IMPORT_DEVICE
#else
"libvulkan.so.1"
#endif // BX_PLATFORM_*
);
);
if (NULL == m_vulkan1Dll)
{
@@ -1244,12 +1271,11 @@ VK_IMPORT
}
uint32_t numEnabledExtensions = 0;
const char* enabledExtension[Extension::Count + 2];
const char* enabledExtension[Extension::Count + 1];
if (!headless)
{
enabledExtension[numEnabledExtensions++] = VK_KHR_SURFACE_EXTENSION_NAME;
enabledExtension[numEnabledExtensions++] = KHR_SURFACE_EXTENSION_NAME;
}
for (uint32_t ii = 0; ii < Extension::Count; ++ii)
@@ -4149,10 +4175,10 @@ VK_IMPORT_DEVICE
{
case UniformType::Mat3:
case UniformType::Mat3|kUniformFragmentBit:
{
{
float* value = (float*)data;
for (uint32_t ii = 0, count = num/3; ii < count; ++ii, loc += 3*16, value += 9)
{
{
Matrix4 mtx;
mtx.un.val[ 0] = value[0];
mtx.un.val[ 1] = value[1];
@@ -6514,7 +6540,8 @@ VK_DESTROY
bimg::TextureFormat::Enum tf = bimg::TextureFormat::Enum(m_textureFormat);
const bimg::ImageBlockInfo &blockInfo = bimg::getBlockInfo(tf);
for (uint32_t i = 0; i < _bufferImageCopyCount; ++i) {
for (uint32_t i = 0; i < _bufferImageCopyCount; ++i)
{
BX_ASSERT(
bx::uint32_mod(_bufferImageCopy[i].bufferOffset, blockInfo.blockSize) == 0
, "Misaligned texture of type %s to offset %u, which is not a multiple of %u."
@@ -6928,9 +6955,10 @@ VK_DESTROY
}
#elif BX_PLATFORM_LINUX
{
# if defined(WL_EGL_PLATFORM)
if (g_platformData.type == bgfx::NativeWindowHandleType::Wayland)
{
BGFX_FATAL(s_extension[Extension::KHR_wayland_surface].m_supported, Fatal::UnableToInitialize, VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME " not supported");
BGFX_FATAL(NULL != vkCreateWaylandSurfaceKHR, Fatal::UnableToInitialize, "vkCreateWaylandSurfaceKHR == 0");
VkWaylandSurfaceCreateInfoKHR sci;
sci.sType = VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR;
sci.pNext = NULL;
@@ -6940,10 +6968,10 @@ VK_DESTROY
result = vkCreateWaylandSurfaceKHR(instance, &sci, allocatorCb, &m_surface);
}
else
# endif // defined(WL_EGL_PLATFORM)
{
if (NULL != vkCreateXlibSurfaceKHR)
if (s_extension[Extension::KHR_xlib_surface].m_supported)
{
BGFX_FATAL(NULL != vkCreateXlibSurfaceKHR, Fatal::UnableToInitialize, "vkCreateXlibSurfaceKHR == 0")
VkXlibSurfaceCreateInfoKHR sci;
sci.sType = VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR;
sci.pNext = NULL;
@@ -6953,7 +6981,7 @@ VK_DESTROY
result = vkCreateXlibSurfaceKHR(instance, &sci, allocatorCb, &m_surface);
}
if (VK_SUCCESS != result)
if (VK_SUCCESS != result && s_extension[Extension::KHR_xcb_surface].m_supported)
{
void* xcbdll = bx::dlopen("libX11-xcb.so.1");
@@ -6965,6 +6993,8 @@ VK_DESTROY
union { void* ptr; xcb_window_t window; } cast = { m_nwh };
BGFX_FATAL(NULL != vkCreateXcbSurfaceKHR, Fatal::UnableToInitialize, "vkCreateXcbSurfaceKHR == 0")
VkXcbSurfaceCreateInfoKHR sci;
sci.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
sci.pNext = NULL;