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 <michel.daenzer@amd.com> Cc: Dave Airlie <airlied@redhat.com> Signed-off-by: Emil Velikov <emil.velikov@collabora.com> Reviewed-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl> (v1) Reviewed-by: Eric Engestrom <eric.engestrom@imgtec.com> (v1) Tested-by: Mike Lothian <mike@fireburn.co.uk>
This commit is contained in:
committed by
Emil Velikov
parent
8ff2937dfa
commit
743315f269
@@ -379,6 +379,38 @@ void radv_DestroyInstance(
|
|||||||
vk_free(&instance->alloc, instance);
|
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_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) {
|
||||||
|
|
||||||
|
result = radv_physical_device_init(instance->physicalDevices +
|
||||||
|
instance->physicalDeviceCount,
|
||||||
|
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(
|
VkResult radv_EnumeratePhysicalDevices(
|
||||||
VkInstance _instance,
|
VkInstance _instance,
|
||||||
uint32_t* pPhysicalDeviceCount,
|
uint32_t* pPhysicalDeviceCount,
|
||||||
@@ -388,18 +420,10 @@ VkResult radv_EnumeratePhysicalDevices(
|
|||||||
VkResult result;
|
VkResult result;
|
||||||
|
|
||||||
if (instance->physicalDeviceCount < 0) {
|
if (instance->physicalDeviceCount < 0) {
|
||||||
char path[20];
|
result = radv_enumerate_devices(instance);
|
||||||
instance->physicalDeviceCount = 0;
|
if (result != VK_SUCCESS &&
|
||||||
for (unsigned i = 0; i < RADV_MAX_DRM_DEVICES; i++) {
|
result != VK_ERROR_INCOMPATIBLE_DRIVER)
|
||||||
snprintf(path, sizeof(path), "/dev/dri/renderD%d", 128 + i);
|
return result;
|
||||||
result = radv_physical_device_init(instance->physicalDevices +
|
|
||||||
instance->physicalDeviceCount,
|
|
||||||
instance, path);
|
|
||||||
if (result == VK_SUCCESS)
|
|
||||||
++instance->physicalDeviceCount;
|
|
||||||
else if (result != VK_ERROR_INCOMPATIBLE_DRIVER)
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!pPhysicalDevices) {
|
if (!pPhysicalDevices) {
|
||||||
|
|||||||
Reference in New Issue
Block a user