diff options
author | Jason Ekstrand <[email protected]> | 2018-10-18 10:08:32 -0500 |
---|---|---|
committer | Jason Ekstrand <[email protected]> | 2018-10-18 11:29:00 -0500 |
commit | baa38c144f6ab544bccabff3739631bab33e4cd7 (patch) | |
tree | f7206b476b65bd2d3d3b5e5b5544ef15d82685a4 /src/vulkan | |
parent | c20ba1be1843d035f36e9794bee7aea9abfc2f8b (diff) |
vulkan/wsi: Use VK_EXT_pci_bus_info for DRM fd matching
This lets us avoid passing the DRM fd around all over the place and gets
us closer to layer utopia.
Reviewed-by: Lionel Landwerlin <[email protected]>
Reviewed-by: Eric Engestrom <[email protected]>
Diffstat (limited to 'src/vulkan')
-rw-r--r-- | src/vulkan/wsi/wsi_common.c | 45 | ||||
-rw-r--r-- | src/vulkan/wsi/wsi_common.h | 5 | ||||
-rw-r--r-- | src/vulkan/wsi/wsi_common_display.c | 22 | ||||
-rw-r--r-- | src/vulkan/wsi/wsi_common_private.h | 6 | ||||
-rw-r--r-- | src/vulkan/wsi/wsi_common_wayland.c | 3 | ||||
-rw-r--r-- | src/vulkan/wsi/wsi_common_x11.c | 34 | ||||
-rw-r--r-- | src/vulkan/wsi/wsi_common_x11.h | 1 |
7 files changed, 56 insertions, 60 deletions
diff --git a/src/vulkan/wsi/wsi_common.c b/src/vulkan/wsi/wsi_common.c index ad4b8c9075e..51d8655a5a9 100644 --- a/src/vulkan/wsi/wsi_common.c +++ b/src/vulkan/wsi/wsi_common.c @@ -27,6 +27,7 @@ #include "vk_util.h" #include <unistd.h> +#include <xf86drm.h> VkResult wsi_device_init(struct wsi_device *wsi, @@ -44,10 +45,19 @@ wsi_device_init(struct wsi_device *wsi, #define WSI_GET_CB(func) \ PFN_vk##func func = (PFN_vk##func)proc_addr(pdevice, "vk" #func) + WSI_GET_CB(GetPhysicalDeviceProperties2); WSI_GET_CB(GetPhysicalDeviceMemoryProperties); WSI_GET_CB(GetPhysicalDeviceQueueFamilyProperties); #undef WSI_GET_CB + wsi->pci_bus_info.sType = + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PCI_BUS_INFO_PROPERTIES_EXT; + VkPhysicalDeviceProperties2 pdp2 = { + .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2, + .pNext = &wsi->pci_bus_info, + }; + GetPhysicalDeviceProperties2(pdevice, &pdp2); + GetPhysicalDeviceMemoryProperties(pdevice, &wsi->memory_props); GetPhysicalDeviceQueueFamilyProperties(pdevice, &wsi->queue_family_count, NULL); @@ -121,6 +131,32 @@ wsi_device_finish(struct wsi_device *wsi, #endif } +bool +wsi_device_matches_drm_fd(const struct wsi_device *wsi, int drm_fd) +{ + drmDevicePtr fd_device; + int ret = drmGetDevice(drm_fd, &fd_device); + if (ret) + return false; + + bool match = false; + switch (fd_device->bustype) { + case DRM_BUS_PCI: + match = wsi->pci_bus_info.pciDomain == fd_device->businfo.pci->domain && + wsi->pci_bus_info.pciBus == fd_device->businfo.pci->bus && + wsi->pci_bus_info.pciDevice == fd_device->businfo.pci->dev && + wsi->pci_bus_info.pciFunction == fd_device->businfo.pci->func; + break; + + default: + break; + } + + drmFreeDevice(&fd_device); + + return match; +} + VkResult wsi_swapchain_init(const struct wsi_device *wsi, struct wsi_swapchain *chain, @@ -675,7 +711,6 @@ wsi_destroy_image(const struct wsi_swapchain *chain, VkResult wsi_common_get_surface_support(struct wsi_device *wsi_device, - int local_fd, uint32_t queueFamilyIndex, VkSurfaceKHR _surface, VkBool32* pSupported) @@ -684,7 +719,7 @@ wsi_common_get_surface_support(struct wsi_device *wsi_device, struct wsi_interface *iface = wsi_device->wsi[surface->platform]; return iface->get_support(surface, wsi_device, - queueFamilyIndex, local_fd, pSupported); + queueFamilyIndex, pSupported); } VkResult @@ -805,7 +840,6 @@ wsi_common_get_surface_present_modes(struct wsi_device *wsi_device, VkResult wsi_common_get_present_rectangles(struct wsi_device *wsi_device, - int local_fd, VkSurfaceKHR _surface, uint32_t* pRectCount, VkRect2D* pRects) @@ -813,14 +847,13 @@ wsi_common_get_present_rectangles(struct wsi_device *wsi_device, ICD_FROM_HANDLE(VkIcdSurfaceBase, surface, _surface); struct wsi_interface *iface = wsi_device->wsi[surface->platform]; - return iface->get_present_rectangles(surface, wsi_device, local_fd, + return iface->get_present_rectangles(surface, wsi_device, pRectCount, pRects); } VkResult wsi_common_create_swapchain(struct wsi_device *wsi, VkDevice device, - int fd, const VkSwapchainCreateInfoKHR *pCreateInfo, const VkAllocationCallbacks *pAllocator, VkSwapchainKHR *pSwapchain) @@ -829,7 +862,7 @@ wsi_common_create_swapchain(struct wsi_device *wsi, struct wsi_interface *iface = wsi->wsi[surface->platform]; struct wsi_swapchain *swapchain; - VkResult result = iface->create_swapchain(surface, device, wsi, fd, + VkResult result = iface->create_swapchain(surface, device, wsi, pCreateInfo, pAllocator, &swapchain); if (result != VK_SUCCESS) diff --git a/src/vulkan/wsi/wsi_common.h b/src/vulkan/wsi/wsi_common.h index 5b69c573d9e..f6ca013c2a8 100644 --- a/src/vulkan/wsi/wsi_common.h +++ b/src/vulkan/wsi/wsi_common.h @@ -97,6 +97,8 @@ struct wsi_device { VkPhysicalDeviceMemoryProperties memory_props; uint32_t queue_family_count; + VkPhysicalDevicePCIBusInfoPropertiesEXT pci_bus_info; + bool supports_modifiers; uint64_t (*image_get_modifier)(VkImage image); @@ -166,7 +168,6 @@ ICD_DEFINE_NONDISP_HANDLE_CASTS(VkIcdSurfaceBase, VkSurfaceKHR) VkResult wsi_common_get_surface_support(struct wsi_device *wsi_device, - int local_fd, uint32_t queueFamilyIndex, VkSurfaceKHR surface, VkBool32* pSupported); @@ -201,7 +202,6 @@ wsi_common_get_surface_present_modes(struct wsi_device *wsi_device, VkResult wsi_common_get_present_rectangles(struct wsi_device *wsi, - int local_fd, VkSurfaceKHR surface, uint32_t* pRectCount, VkRect2D* pRects); @@ -226,7 +226,6 @@ wsi_common_acquire_next_image2(const struct wsi_device *wsi, VkResult wsi_common_create_swapchain(struct wsi_device *wsi, VkDevice device, - int fd, const VkSwapchainCreateInfoKHR *pCreateInfo, const VkAllocationCallbacks *pAllocator, VkSwapchainKHR *pSwapchain); diff --git a/src/vulkan/wsi/wsi_common_display.c b/src/vulkan/wsi/wsi_common_display.c index 2315717ef8e..fd0d30ad80c 100644 --- a/src/vulkan/wsi/wsi_common_display.c +++ b/src/vulkan/wsi/wsi_common_display.c @@ -803,7 +803,6 @@ static VkResult wsi_display_surface_get_support(VkIcdSurfaceBase *surface, struct wsi_device *wsi_device, uint32_t queueFamilyIndex, - int local_fd, VkBool32* pSupported) { *pSupported = VK_TRUE; @@ -934,27 +933,9 @@ wsi_display_surface_get_present_modes(VkIcdSurfaceBase *surface, return vk_outarray_status(&conn); } -static bool -fds_are_same_gpu(int fd1, int fd2) -{ - if (fd1 == -1 || fd2 == -1) - return false; - - char *fd1_dev = drmGetRenderDeviceNameFromFd(fd1); - char *fd2_dev = drmGetRenderDeviceNameFromFd(fd2); - - int ret = strcmp(fd1_dev, fd2_dev); - - free(fd1_dev); - free(fd2_dev); - - return ret == 0; -} - static VkResult wsi_display_surface_get_present_rectangles(VkIcdSurfaceBase *surface_base, struct wsi_device *wsi_device, - int local_fd, uint32_t* pRectCount, VkRect2D* pRects) { @@ -962,7 +943,7 @@ wsi_display_surface_get_present_rectangles(VkIcdSurfaceBase *surface_base, wsi_display_mode *mode = wsi_display_mode_from_handle(surface->displayMode); VK_OUTARRAY_MAKE(out, pRects, pRectCount); - if (fds_are_same_gpu(local_fd, mode->connector->wsi->fd)) { + if (wsi_device_matches_drm_fd(wsi_device, mode->connector->wsi->fd)) { vk_outarray_append(&out, rect) { *rect = (VkRect2D) { .offset = { 0, 0 }, @@ -1730,7 +1711,6 @@ wsi_display_surface_create_swapchain( VkIcdSurfaceBase *icd_surface, VkDevice device, struct wsi_device *wsi_device, - int local_fd, const VkSwapchainCreateInfoKHR *create_info, const VkAllocationCallbacks *allocator, struct wsi_swapchain **swapchain_out) diff --git a/src/vulkan/wsi/wsi_common_private.h b/src/vulkan/wsi/wsi_common_private.h index d8290b69331..50a78acacb0 100644 --- a/src/vulkan/wsi/wsi_common_private.h +++ b/src/vulkan/wsi/wsi_common_private.h @@ -69,6 +69,9 @@ struct wsi_swapchain { const VkPresentRegionKHR *damage); }; +bool +wsi_device_matches_drm_fd(const struct wsi_device *wsi, int drm_fd); + VkResult wsi_swapchain_init(const struct wsi_device *wsi, struct wsi_swapchain *chain, @@ -101,7 +104,6 @@ struct wsi_interface { VkResult (*get_support)(VkIcdSurfaceBase *surface, struct wsi_device *wsi_device, uint32_t queueFamilyIndex, - int local_fd, VkBool32* pSupported); VkResult (*get_capabilities2)(VkIcdSurfaceBase *surface, const void *info_next, @@ -120,13 +122,11 @@ struct wsi_interface { VkPresentModeKHR* pPresentModes); VkResult (*get_present_rectangles)(VkIcdSurfaceBase *surface, struct wsi_device *wsi_device, - int local_fd, uint32_t* pRectCount, VkRect2D* pRects); VkResult (*create_swapchain)(VkIcdSurfaceBase *surface, VkDevice device, struct wsi_device *wsi_device, - int local_fd, const VkSwapchainCreateInfoKHR* pCreateInfo, const VkAllocationCallbacks* pAllocator, struct wsi_swapchain **swapchain); diff --git a/src/vulkan/wsi/wsi_common_wayland.c b/src/vulkan/wsi/wsi_common_wayland.c index dccb530dae3..e9cc22ec603 100644 --- a/src/vulkan/wsi/wsi_common_wayland.c +++ b/src/vulkan/wsi/wsi_common_wayland.c @@ -465,7 +465,6 @@ static VkResult wsi_wl_surface_get_support(VkIcdSurfaceBase *surface, struct wsi_device *wsi_device, uint32_t queueFamilyIndex, - int local_fd, VkBool32* pSupported) { *pSupported = true; @@ -604,7 +603,6 @@ wsi_wl_surface_get_present_modes(VkIcdSurfaceBase *surface, static VkResult wsi_wl_surface_get_present_rectangles(VkIcdSurfaceBase *surface, struct wsi_device *wsi_device, - int local_fd, uint32_t* pRectCount, VkRect2D* pRects) { @@ -908,7 +906,6 @@ static VkResult wsi_wl_surface_create_swapchain(VkIcdSurfaceBase *icd_surface, VkDevice device, struct wsi_device *wsi_device, - int local_fd, const VkSwapchainCreateInfoKHR* pCreateInfo, const VkAllocationCallbacks* pAllocator, struct wsi_swapchain **swapchain_out) diff --git a/src/vulkan/wsi/wsi_common_x11.c b/src/vulkan/wsi/wsi_common_x11.c index 8c621ddf568..16a544ec775 100644 --- a/src/vulkan/wsi/wsi_common_x11.c +++ b/src/vulkan/wsi/wsi_common_x11.c @@ -99,29 +99,22 @@ wsi_dri3_open(xcb_connection_t *conn, } static bool -wsi_x11_check_dri3_compatible(xcb_connection_t *conn, int local_fd) +wsi_x11_check_dri3_compatible(const struct wsi_device *wsi_dev, + xcb_connection_t *conn) { xcb_screen_iterator_t screen_iter = xcb_setup_roots_iterator(xcb_get_setup(conn)); xcb_screen_t *screen = screen_iter.data; int dri3_fd = wsi_dri3_open(conn, screen->root, None); - if (dri3_fd != -1) { - char *local_dev = drmGetRenderDeviceNameFromFd(local_fd); - char *dri3_dev = drmGetRenderDeviceNameFromFd(dri3_fd); - int ret; - - close(dri3_fd); + if (dri3_fd == -1) + return true; - ret = strcmp(local_dev, dri3_dev); + bool match = wsi_device_matches_drm_fd(wsi_dev, dri3_fd); - free(local_dev); - free(dri3_dev); + close(dri3_fd); - if (ret != 0) - return false; - } - return true; + return match; } static struct wsi_x11_connection * @@ -382,7 +375,6 @@ visual_has_alpha(xcb_visualtype_t *visual, unsigned depth) VkBool32 wsi_get_physical_device_xcb_presentation_support( struct wsi_device *wsi_device, uint32_t queueFamilyIndex, - int fd, bool can_handle_different_gpu, xcb_connection_t* connection, xcb_visualid_t visual_id) @@ -397,7 +389,7 @@ VkBool32 wsi_get_physical_device_xcb_presentation_support( return false; if (!can_handle_different_gpu) - if (!wsi_x11_check_dri3_compatible(connection, fd)) + if (!wsi_x11_check_dri3_compatible(wsi_device, connection)) return false; unsigned visual_depth; @@ -432,7 +424,6 @@ static VkResult x11_surface_get_support(VkIcdSurfaceBase *icd_surface, struct wsi_device *wsi_device, uint32_t queueFamilyIndex, - int local_fd, VkBool32* pSupported) { xcb_connection_t *conn = x11_surface_get_connection(icd_surface); @@ -601,7 +592,6 @@ x11_surface_get_present_modes(VkIcdSurfaceBase *surface, static bool x11_surface_is_local_to_gpu(struct wsi_device *wsi_dev, - int local_fd, xcb_connection_t *conn) { struct wsi_x11_connection *wsi_conn = @@ -613,7 +603,7 @@ x11_surface_is_local_to_gpu(struct wsi_device *wsi_dev, if (!wsi_x11_check_for_dri3(wsi_conn)) return false; - if (!wsi_x11_check_dri3_compatible(conn, local_fd)) + if (!wsi_x11_check_dri3_compatible(wsi_dev, conn)) return false; return true; @@ -622,7 +612,6 @@ x11_surface_is_local_to_gpu(struct wsi_device *wsi_dev, static VkResult x11_surface_get_present_rectangles(VkIcdSurfaceBase *icd_surface, struct wsi_device *wsi_device, - int local_fd, uint32_t* pRectCount, VkRect2D* pRects) { @@ -630,7 +619,7 @@ x11_surface_get_present_rectangles(VkIcdSurfaceBase *icd_surface, xcb_window_t window = x11_surface_get_window(icd_surface); VK_OUTARRAY_MAKE(out, pRects, pRectCount); - if (x11_surface_is_local_to_gpu(wsi_device, local_fd, conn)) { + if (x11_surface_is_local_to_gpu(wsi_device, conn)) { vk_outarray_append(&out, rect) { xcb_generic_error_t *err = NULL; xcb_get_geometry_cookie_t geom_cookie = xcb_get_geometry(conn, window); @@ -1321,7 +1310,6 @@ static VkResult x11_surface_create_swapchain(VkIcdSurfaceBase *icd_surface, VkDevice device, struct wsi_device *wsi_device, - int local_fd, const VkSwapchainCreateInfoKHR *pCreateInfo, const VkAllocationCallbacks* pAllocator, struct wsi_swapchain **swapchain_out) @@ -1388,7 +1376,7 @@ x11_surface_create_swapchain(VkIcdSurfaceBase *icd_surface, else chain->last_present_mode = XCB_PRESENT_COMPLETE_MODE_COPY; - if (!wsi_x11_check_dri3_compatible(conn, local_fd)) + if (!wsi_x11_check_dri3_compatible(wsi_device, conn)) chain->base.use_prime_blit = true; chain->event_id = xcb_generate_id(chain->conn); diff --git a/src/vulkan/wsi/wsi_common_x11.h b/src/vulkan/wsi/wsi_common_x11.h index e9b3ecfb2e0..99b1bcdc6fd 100644 --- a/src/vulkan/wsi/wsi_common_x11.h +++ b/src/vulkan/wsi/wsi_common_x11.h @@ -28,7 +28,6 @@ VkBool32 wsi_get_physical_device_xcb_presentation_support( struct wsi_device *wsi_device, uint32_t queueFamilyIndex, - int local_fd, bool can_handle_different_gpu, xcb_connection_t* connection, xcb_visualid_t visual_id); |