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/wsi/wsi_common.c | |
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/wsi/wsi_common.c')
-rw-r--r-- | src/vulkan/wsi/wsi_common.c | 45 |
1 files changed, 39 insertions, 6 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) |