diff options
author | Emil Velikov <[email protected]> | 2016-12-01 20:58:20 +0000 |
---|---|---|
committer | Emil Velikov <[email protected]> | 2017-03-15 11:38:02 +0000 |
commit | 743315f2696d77bc731baefdc9433994d3a4cfb3 (patch) | |
tree | 1bf67aa694be84bb1901b5333c2e560ba237b468 /src/amd/vulkan | |
parent | 8ff2937dfa60dd86ed0ee0b5bfb3d80f5ab0ae7e (diff) |
radv: 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.
v3: Return VK_ERROR_INCOMPATIBLE_DRIVER for no devices (Ilia)
Cc: Michel Dänzer <[email protected]>
Cc: Dave Airlie <[email protected]>
Signed-off-by: Emil Velikov <[email protected]>
Reviewed-by: Bas Nieuwenhuizen <[email protected]> (v1)
Reviewed-by: Eric Engestrom <[email protected]> (v1)
Tested-by: Mike Lothian <[email protected]>
Diffstat (limited to 'src/amd/vulkan')
-rw-r--r-- | src/amd/vulkan/radv_device.c | 48 |
1 files changed, 36 insertions, 12 deletions
diff --git a/src/amd/vulkan/radv_device.c b/src/amd/vulkan/radv_device.c index d1fd58d77b9..bc136e4489b 100644 --- a/src/amd/vulkan/radv_device.c +++ b/src/amd/vulkan/radv_device.c @@ -379,28 +379,52 @@ void radv_DestroyInstance( vk_free(&instance->alloc, instance); } -VkResult radv_EnumeratePhysicalDevices( - VkInstance _instance, - uint32_t* pPhysicalDeviceCount, - VkPhysicalDevice* pPhysicalDevices) +static VkResult +radv_enumerate_devices(struct radv_instance *instance) { - RADV_FROM_HANDLE(radv_instance, instance, _instance); - VkResult result; + /* 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 == 0x1002) { - if (instance->physicalDeviceCount < 0) { - char path[20]; - instance->physicalDeviceCount = 0; - for (unsigned i = 0; i < RADV_MAX_DRM_DEVICES; i++) { - snprintf(path, sizeof(path), "/dev/dri/renderD%d", 128 + i); result = radv_physical_device_init(instance->physicalDevices + instance->physicalDeviceCount, - instance, path); + instance, + devices[i]->nodes[DRM_NODE_RENDER]); if (result == VK_SUCCESS) ++instance->physicalDeviceCount; else if (result != VK_ERROR_INCOMPATIBLE_DRIVER) return result; } } + return result; +} + +VkResult radv_EnumeratePhysicalDevices( + VkInstance _instance, + uint32_t* pPhysicalDeviceCount, + VkPhysicalDevice* pPhysicalDevices) +{ + RADV_FROM_HANDLE(radv_instance, instance, _instance); + VkResult result; + + if (instance->physicalDeviceCount < 0) { + result = radv_enumerate_devices(instance); + if (result != VK_SUCCESS && + result != VK_ERROR_INCOMPATIBLE_DRIVER) + return result; + } if (!pPhysicalDevices) { *pPhysicalDeviceCount = instance->physicalDeviceCount; |