diff options
author | Emil Velikov <[email protected]> | 2016-12-01 21:21:10 +0000 |
---|---|---|
committer | Emil Velikov <[email protected]> | 2017-03-15 11:38:05 +0000 |
commit | b1fb6e8d8c059598d08a64bbb90395ad9b14975d (patch) | |
tree | 7c5bd007a0550dc3466949c1972279e9324a9663 /src/intel/vulkan | |
parent | 743315f2696d77bc731baefdc9433994d3a4cfb3 (diff) |
anv: do not open random render node(s)
drmGetDevices2() provides us with enough flexibility to build heuristics
upon. Opening a random node on the other hand will wake up the device,
regardless if it's the one we're interested or not.
v2: Rebase, explicitly require/check for libdrm
v3: Return VK_ERROR_INCOMPATIBLE_DRIVER for no devices (Ilia)
v4: Rebase
Cc: Jason Ekstrand <[email protected]>
Signed-off-by: Emil Velikov <[email protected]>
Reviewed-by: Eric Engestrom <[email protected]> (v1)
Tested-by: Mike Lothian <[email protected]>
Diffstat (limited to 'src/intel/vulkan')
-rw-r--r-- | src/intel/vulkan/anv_device.c | 53 |
1 files changed, 38 insertions, 15 deletions
diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c index 5d1bbf60859..253cd39d7fb 100644 --- a/src/intel/vulkan/anv_device.c +++ b/src/intel/vulkan/anv_device.c @@ -27,6 +27,7 @@ #include <sys/mman.h> #include <unistd.h> #include <fcntl.h> +#include <xf86drm.h> #include "anv_private.h" #include "util/strtod.h" @@ -384,6 +385,40 @@ void anv_DestroyInstance( vk_free(&instance->alloc, instance); } +static VkResult +anv_enumerate_devices(struct anv_instance *instance) +{ + /* TODO: Check for more devices ? */ + drmDevicePtr devices[8]; + VkResult result = VK_ERROR_INCOMPATIBLE_DRIVER; + int max_devices; + + instance->physicalDeviceCount = 0; + + max_devices = drmGetDevices2(0, devices, sizeof(devices)); + if (max_devices < 1) + return VK_ERROR_INCOMPATIBLE_DRIVER; + + for (unsigned i = 0; i < (unsigned)max_devices; i++) { + if (devices[i]->available_nodes & 1 << DRM_NODE_RENDER && + devices[i]->bustype == DRM_BUS_PCI && + devices[i]->deviceinfo.pci->vendor_id == 0x8086) { + + result = anv_physical_device_init(&instance->physicalDevice, + instance, + devices[i]->nodes[DRM_NODE_RENDER]); + if (result != VK_ERROR_INCOMPATIBLE_DRIVER) + break; + } + } + + if (result == VK_SUCCESS) + instance->physicalDeviceCount = 1; + + return result; +} + + VkResult anv_EnumeratePhysicalDevices( VkInstance _instance, uint32_t* pPhysicalDeviceCount, @@ -394,22 +429,10 @@ VkResult anv_EnumeratePhysicalDevices( VkResult result; if (instance->physicalDeviceCount < 0) { - char path[20]; - for (unsigned i = 0; i < 8; i++) { - snprintf(path, sizeof(path), "/dev/dri/renderD%d", 128 + i); - result = anv_physical_device_init(&instance->physicalDevice, - instance, path); - if (result != VK_ERROR_INCOMPATIBLE_DRIVER) - break; - } - - if (result == VK_ERROR_INCOMPATIBLE_DRIVER) { - instance->physicalDeviceCount = 0; - } else if (result == VK_SUCCESS) { - instance->physicalDeviceCount = 1; - } else { + result = anv_enumerate_devices(instance); + if (result != VK_SUCCESS && + result != VK_ERROR_INCOMPATIBLE_DRIVER) return result; - } } if (instance->physicalDeviceCount > 0) { |