Skip to content
This repository has been archived by the owner on Nov 1, 2021. It is now read-only.

Commit

Permalink
render/vulkan: migrate to VK_EXT_physical_device_drm
Browse files Browse the repository at this point in the history
  • Loading branch information
emersion committed Sep 29, 2021
1 parent 22427e0 commit 0ae5b0b
Showing 1 changed file with 18 additions and 38 deletions.
56 changes: 18 additions & 38 deletions render/vulkan/vulkan.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#include <assert.h>
#include <math.h>
#include <stdlib.h>
#include <stdint.h>
#include <math.h>
#include <assert.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <xf86drm.h>
#include <vulkan/vulkan.h>
Expand Down Expand Up @@ -321,29 +323,13 @@ VkPhysicalDevice vulkan_find_drm_phdev(struct wlr_vk_instance *ini, int drm_fd)
return VK_NULL_HANDLE;
}

// TODO: use VK_EXT_physical_device_drm when available as it allows
// us to match non-pci gpus.
// See https://github.com/KhronosGroup/Vulkan-Docs/pull/1356
// We still might want to fall back to the PCI extension if the
// other one is not available.

drmDevicePtr dev_ptr;
if (drmGetDevice(drm_fd, &dev_ptr) != 0) {
wlr_log_errno(WLR_ERROR, "drmGetDevice failed");
return VK_NULL_HANDLE;
}

if (dev_ptr->bustype != DRM_BUS_PCI) {
wlr_log(WLR_ERROR, "Can't match vulkan and non-PCI drm device");
drmFreeDevice(&dev_ptr);
struct stat drm_stat = {0};
if (fstat(drm_fd, &drm_stat) != 0) {
wlr_log_errno(WLR_ERROR, "fstat failed");
return VK_NULL_HANDLE;
}

drmPciBusInfo drm_pci_info = *dev_ptr->businfo.pci;

drmFreeDevice(&dev_ptr);

for (unsigned i = 0u; i < num_phdevs; ++i) {
for (uint32_t i = 0; i < num_phdevs; ++i) {
VkPhysicalDevice phdev = phdevs[i];

// check whether device supports vulkan 1.1, needed for
Expand Down Expand Up @@ -377,32 +363,26 @@ VkPhysicalDevice vulkan_find_drm_phdev(struct wlr_vk_instance *ini, int drm_fd)
continue;
}

const char *name = VK_EXT_PCI_BUS_INFO_EXTENSION_NAME;

const char *name = VK_EXT_PHYSICAL_DEVICE_DRM_EXTENSION_NAME;
if (find_extensions(avail_ext_props, avail_extc, &name, 1) != NULL) {
wlr_log(WLR_INFO, " Can't check pci info of device, "
"as it does not support the PCI_BUS_INFO extensions");
wlr_log(WLR_DEBUG, " Ignoring physical device \"%s\": "
"VK_EXT_physical_device_drm not supported",
phdev_props.deviceName);
continue;
}

VkPhysicalDevicePCIBusInfoPropertiesEXT bus_info = {0};
bus_info.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PCI_BUS_INFO_PROPERTIES_EXT;
VkPhysicalDeviceDrmPropertiesEXT drm_props = {0};
drm_props.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DRM_PROPERTIES_EXT;

VkPhysicalDeviceProperties2 props = {0};
props.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2;

props.pNext = &bus_info;
props.pNext = &drm_props;

ini->api.getPhysicalDeviceProperties2(phdev, &props);

wlr_log(WLR_INFO, " PCI bus: %04x:%02x:%02x.%x", bus_info.pciDomain,
bus_info.pciBus, bus_info.pciDevice, bus_info.pciFunction);

if (bus_info.pciDevice == drm_pci_info.dev &&
bus_info.pciBus == drm_pci_info.bus &&
bus_info.pciDomain == drm_pci_info.domain &&
bus_info.pciFunction == drm_pci_info.func) {
wlr_log(WLR_INFO, "Found matching vulkan device from drm pci info: %s",
dev_t render_devid = makedev(drm_props.renderMajor, drm_props.renderMinor);
if (render_devid == drm_stat.st_rdev) {
wlr_log(WLR_INFO, "Found matching Vulkan physical device: %s",
phdev_props.deviceName);
return phdev;
}
Expand Down

0 comments on commit 0ae5b0b

Please sign in to comment.