[Mesa-dev] [PATCH 5/6] radv: do not open random render node(s)

Emil Velikov emil.l.velikov at gmail.com
Fri Dec 2 16:31:48 UTC 2016


From: Emil Velikov <emil.velikov at collabora.com>

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 intereseted or not.

Cc: Michel Dänzer <michel.daenzer at amd.com>
Cc: Dave Airlie <airlied at redhat.com>
Signed-off-by: Emil Velikov <emil.velikov at collabora.com>
---
Afacit there is no system with more than one Intel GPU, but on the other
hand one can easily have setup with many AMD cards.

Dave, any reason why we are capped at 1 device ?
---
 src/amd/vulkan/radv_device.c | 51 +++++++++++++++++++++++++++++++-------------
 1 file changed, 36 insertions(+), 15 deletions(-)

diff --git a/src/amd/vulkan/radv_device.c b/src/amd/vulkan/radv_device.c
index 0defc0f..3eea0cd 100644
--- a/src/amd/vulkan/radv_device.c
+++ b/src/amd/vulkan/radv_device.c
@@ -300,6 +300,39 @@ void radv_DestroyInstance(
 	vk_free(&instance->alloc, instance);
 }
 
+static VkResult
+radv_enumerate_devices(struct radv_instance *instance)
+{
+	/* TODO: Check for more devices ? */
+	drmDevicePtr devices[8];
+	VkResult result = VK_SUCCESS;
+	int max_devices;
+
+	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) {
+
+			result = radv_physical_device_init(&instance->physicalDevice,
+							   instance,
+							   devices[i]->nodes[DRM_NODE_RENDER]);
+			if (result != VK_ERROR_INCOMPATIBLE_DRIVER)
+				break;
+		}
+	}
+
+	if (result == VK_ERROR_INCOMPATIBLE_DRIVER)
+		instance->physicalDeviceCount = 0;
+	else if (result == VK_SUCCESS)
+		instance->physicalDeviceCount = 1;
+
+	return result;
+}
+
 VkResult radv_EnumeratePhysicalDevices(
 	VkInstance                                  _instance,
 	uint32_t*                                   pPhysicalDeviceCount,
@@ -309,22 +342,10 @@ VkResult radv_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 = radv_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 = radv_enumerate_devices(instance);
+		if (result != VK_SUCCESS &&
+		    result != VK_ERROR_INCOMPATIBLE_DRIVER)
 			return result;
-		}
 	}
 
 	/* pPhysicalDeviceCount is an out parameter if pPhysicalDevices is NULL;
-- 
2.10.2



More information about the mesa-dev mailing list