diff --git a/backend/drm/backend.c b/backend/drm/backend.c index 9a8007495c..7d3a9d0d65 100644 --- a/backend/drm/backend.c +++ b/backend/drm/backend.c @@ -79,7 +79,10 @@ static bool backend_egl_params(struct wlr_backend *wlr_backend, } static bool backend_vulkan_queue_check(struct wlr_backend *wlr_backend, - uintptr_t vk_physical_device, uint32_t qfam) { + struct wlr_vk_instance *instance, uintptr_t vk_physical_device, + uint32_t qfam) { + // there is no drm/gbm/kms vulkan wsi so there is no need for + // present queues return true; } diff --git a/backend/headless/backend.c b/backend/headless/backend.c index 60342716fb..7cd7a259bb 100644 --- a/backend/headless/backend.c +++ b/backend/headless/backend.c @@ -93,7 +93,10 @@ static bool backend_egl_params(struct wlr_backend *wlr_backend, } static bool backend_vulkan_queue_check(struct wlr_backend *wlr_backend, - uintptr_t vk_physical_device, uint32_t qfam) { + struct wlr_vk_instance *instance, uintptr_t vk_physical_device, + uint32_t qfam) { + // there is no headless vulkan wsi so there is no need for + // present queues. Done manually return true; } diff --git a/backend/wayland/backend.c b/backend/wayland/backend.c index b23b1b6362..6ad7fc01ff 100644 --- a/backend/wayland/backend.c +++ b/backend/wayland/backend.c @@ -10,8 +10,7 @@ #include #include #ifdef WLR_HAS_VULKAN -#include -#include +#include #endif #include "backend/wayland.h" #include "util/signal.h" @@ -150,12 +149,12 @@ static bool backend_egl_params(struct wlr_backend *wlr_backend, } static bool backend_vulkan_queue_check(struct wlr_backend *wlr_backend, - uintptr_t vk_physical_device, uint32_t qfam) { + struct wlr_vk_instance *instance, uintptr_t vk_physical_device, + uint32_t qfam) { #ifdef WLR_HAS_VULKAN struct wlr_wl_backend *wl = get_wl_backend_from_backend(wlr_backend); - VkPhysicalDevice phdev = (VkPhysicalDevice) vk_physical_device; - return vkGetPhysicalDeviceWaylandPresentationSupportKHR(phdev, qfam, - wl->remote_display); + return wlr_vk_present_queue_supported_wl(instance, vk_physical_device, + qfam, wl->remote_display); #else return false; #endif diff --git a/backend/x11/backend.c b/backend/x11/backend.c index bff66b61b0..31cd1f57ec 100644 --- a/backend/x11/backend.c +++ b/backend/x11/backend.c @@ -21,8 +21,7 @@ #include #endif #ifdef WLR_HAS_VULKAN -#include -#include +#include #endif #include "backend/x11.h" #include "util/signal.h" @@ -239,12 +238,12 @@ static bool backend_egl_params(struct wlr_backend *wlr_backend, } static bool backend_vulkan_queue_check(struct wlr_backend *wlr_backend, - uintptr_t vk_physical_device, uint32_t qfam) { + struct wlr_vk_instance *instance, uintptr_t vk_physical_device, + uint32_t qfam) { #ifdef WLR_HAS_VULKAN struct wlr_x11_backend *x11 = get_x11_backend_from_backend(wlr_backend); - VkPhysicalDevice phdev = (VkPhysicalDevice) vk_physical_device; - return vkGetPhysicalDeviceXcbPresentationSupportKHR(phdev, qfam, - x11->xcb_conn, x11->screen->root_visual); + return wlr_vk_present_queue_supported_xcb(instance, vk_physical_device, + qfam, x11->xcb_conn, x11->screen->root_visual); #else return false; #endif diff --git a/include/wlr/backend/interface.h b/include/wlr/backend/interface.h index 51d82860fb..0ebb8f1224 100644 --- a/include/wlr/backend/interface.h +++ b/include/wlr/backend/interface.h @@ -13,6 +13,8 @@ #include #include +struct wlr_vk_instance; + struct wlr_backend_impl { bool (*start)(struct wlr_backend *backend); void (*destroy)(struct wlr_backend *backend); @@ -20,6 +22,7 @@ struct wlr_backend_impl { bool (*egl_params)(struct wlr_backend *backend, EGLenum *platform, void **remote_display, const EGLint **config_attribs, EGLint *visualid); bool (*vulkan_queue_family_present_support)(struct wlr_backend *backend, + struct wlr_vk_instance *instance, uintptr_t vk_physical_device, uint32_t queue_family); }; diff --git a/include/wlr/render/vulkan.h b/include/wlr/render/vulkan.h index e09c0f275d..d9ab8f75c0 100644 --- a/include/wlr/render/vulkan.h +++ b/include/wlr/render/vulkan.h @@ -4,7 +4,7 @@ #include #include -struct wlr_vk_device; +struct wlr_vk_instance; struct wlr_vk_renderer; // Creates all vulkan resources (inclusive instance) from scratch. @@ -13,8 +13,11 @@ struct wlr_texture *wlr_vk_texture_from_pixels(struct wlr_vk_renderer *renderer, enum wl_shm_format wl_fmt, uint32_t stride, uint32_t width, uint32_t height, const void *data); -// struct wlr_texture *wlr_vulkan_texture_from_dmabuf(struct wlr_vulkan *vulkan, -// struct wlr_dmabuf_attributes *attribs); +bool wlr_vk_present_queue_supported_xcb(struct wlr_vk_instance *instance, + uintptr_t vk_physical_device, uint32_t qfam, void *xcb_connection_t, + uint32_t visualid); +bool wlr_vk_present_queue_supported_wl(struct wlr_vk_instance *instance, + uintptr_t vk_physical_device, uint32_t qfam, struct wl_display *remote); #endif diff --git a/render/vulkan/renderer.c b/render/vulkan/renderer.c index e62b884397..21768fcde1 100644 --- a/render/vulkan/renderer.c +++ b/render/vulkan/renderer.c @@ -1186,7 +1186,7 @@ struct wlr_renderer *wlr_vk_renderer_create(struct wlr_backend *backend) { for (unsigned i = 0u; i < qfam_count; ++i) { bool graphics = queue_props[i].queueFlags & VK_QUEUE_GRAPHICS_BIT; bool present = backend->impl->vulkan_queue_family_present_support( - backend, (uintptr_t) phdev, i); + backend, ini, (uintptr_t) phdev, i); if (present) { queue_count = 2u; queues[0].family = i; diff --git a/render/vulkan/vulkan.c b/render/vulkan/vulkan.c index d5b6c6db47..b20219259d 100644 --- a/render/vulkan/vulkan.c +++ b/render/vulkan/vulkan.c @@ -433,3 +433,33 @@ void wlr_vk_device_destroy(struct wlr_vk_device *dev) { free(dev->extensions); free(dev); } + +bool wlr_vk_present_queue_supported_xcb(struct wlr_vk_instance *instance, + uintptr_t vk_physical_device, uint32_t qfam, + void *xcb_connection, uint32_t visualid) { +#ifdef WLR_HAS_X11_BACKEND + if (!vulkan_has_extension(instance->extension_count, instance->extensions, + VK_KHR_XCB_SURFACE_EXTENSION_NAME)) { + return false; + } + + VkPhysicalDevice phdev = (VkPhysicalDevice) vk_physical_device; + return vkGetPhysicalDeviceXcbPresentationSupportKHR(phdev, qfam, + xcb_connection, visualid); +#else + return false; +#endif +} + +bool wlr_vk_present_queue_supported_wl(struct wlr_vk_instance *instance, + uintptr_t vk_physical_device, uint32_t qfam, + struct wl_display *remote) { + if (!vulkan_has_extension(instance->extension_count, instance->extensions, + VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME)) { + return false; + } + + VkPhysicalDevice phdev = (VkPhysicalDevice) vk_physical_device; + return vkGetPhysicalDeviceWaylandPresentationSupportKHR(phdev, qfam, + remote); +}