Skip to content

Commit

Permalink
Fix Vulkan renderer on wayland (#3143)
Browse files Browse the repository at this point in the history
* Initial proof-of-concept of vulkan renderer working on wayland

* Get wayland surface from the window handle
  • Loading branch information
belegdol authored Aug 2, 2023
1 parent 8b6a6bd commit 3101a0d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
19 changes: 19 additions & 0 deletions src/renderer_vk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
# import <Metal/Metal.h>
#endif // BX_PLATFORM_OSX

#if WL_EGL_PLATFORM
# include <wayland-egl-backend.h>
#endif

namespace bgfx { namespace vk
{
static char s_viewName[BGFX_CONFIG_MAX_VIEWS][BGFX_CONFIG_MAX_VIEW_NAME];
Expand Down Expand Up @@ -6770,6 +6774,20 @@ VK_DESTROY
}
}
#elif BX_PLATFORM_LINUX
#if WL_EGL_PLATFORM
{
if (NULL != vkCreateWaylandSurfaceKHR)
{
VkWaylandSurfaceCreateInfoKHR sci;
sci.sType = VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR;
sci.pNext = NULL;
sci.flags = 0;
sci.display = (wl_display*)g_platformData.ndt;
sci.surface = (wl_surface*)((wl_egl_window*)g_platformData.nwh)->surface;
result = vkCreateWaylandSurfaceKHR(instance, &sci, allocatorCb, &m_surface);
}
}
#else
{
if (NULL != vkCreateXlibSurfaceKHR)
{
Expand Down Expand Up @@ -6806,6 +6824,7 @@ VK_DESTROY
}
}
}
#endif // WL_EGL_PLATFORM
#elif BX_PLATFORM_OSX
{
if (NULL != vkCreateMacOSSurfaceMVK)
Expand Down
18 changes: 14 additions & 4 deletions src/renderer_vk.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@
# define KHR_SURFACE_EXTENSION_NAME VK_KHR_ANDROID_SURFACE_EXTENSION_NAME
# define VK_IMPORT_INSTANCE_PLATFORM VK_IMPORT_INSTANCE_ANDROID
#elif BX_PLATFORM_LINUX
#if WL_EGL_PLATFORM
# define VK_USE_PLATFORM_WAYLAND_KHR
# define KHR_SURFACE_EXTENSION_NAME VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME
#else
# define VK_USE_PLATFORM_XLIB_KHR
# define VK_USE_PLATFORM_XCB_KHR
//# define VK_USE_PLATFORM_WAYLAND_KHR
# define KHR_SURFACE_EXTENSION_NAME VK_KHR_XCB_SURFACE_EXTENSION_NAME
#endif // WL_EGL_PLATFORM
# define VK_IMPORT_INSTANCE_PLATFORM VK_IMPORT_INSTANCE_LINUX
#elif BX_PLATFORM_WINDOWS
# define VK_USE_PLATFORM_WIN32_KHR
Expand Down Expand Up @@ -62,6 +66,14 @@
/* VK_KHR_android_surface */ \
VK_IMPORT_INSTANCE_FUNC(true, vkCreateAndroidSurfaceKHR); \

#if WL_EGL_PLATFORM
#define VK_IMPORT_INSTANCE_LINUX \
/* VK_KHR_wayland_surface */ \
VK_IMPORT_INSTANCE_FUNC(true, vkCreateWaylandSurfaceKHR); \
VK_IMPORT_INSTANCE_FUNC(true, vkGetPhysicalDeviceWaylandPresentationSupportKHR); \


#else
#define VK_IMPORT_INSTANCE_LINUX \
/* VK_KHR_xlib_surface */ \
VK_IMPORT_INSTANCE_FUNC(true, vkCreateXlibSurfaceKHR); \
Expand All @@ -70,9 +82,7 @@
VK_IMPORT_INSTANCE_FUNC(true, vkCreateXcbSurfaceKHR); \
VK_IMPORT_INSTANCE_FUNC(true, vkGetPhysicalDeviceXcbPresentationSupportKHR); \

// /* VK_KHR_wayland_surface */
// VK_IMPORT_INSTANCE_FUNC(true, vkCreateWaylandSurfaceKHR);
// VK_IMPORT_INSTANCE_FUNC(true, vkGetPhysicalDeviceWaylandPresentationSupportKHR);
#endif // WL_EGL_PLATFORM

#define VK_IMPORT_INSTANCE_WINDOWS \
/* VK_KHR_win32_surface */ \
Expand Down

0 comments on commit 3101a0d

Please sign in to comment.