From: Bas Nieuwenhuizen Date: Mon, 16 Jan 2017 20:25:10 +0000 (+0100) Subject: radv: Support multiple devices. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=5ae4de18d93eb47fefe09b516189a2794f2e4a51;p=mesa.git radv: Support multiple devices. Pretty straightforward. Also deleted the big comment block as it is a pretty standard pattern for filling in arrays. Also removed the error message on non-existent devices, as getting 7 errors printed to the console each time you enumerate the devices is pretty confusing. v2: Add constant for number of DRM devices. Signed-off-by: Bas Nieuwenhuizen Reviewed-by: Dave Airlie --- diff --git a/src/amd/vulkan/radv_device.c b/src/amd/vulkan/radv_device.c index 10d4d2bad28..9371536aa61 100644 --- a/src/amd/vulkan/radv_device.c +++ b/src/amd/vulkan/radv_device.c @@ -190,8 +190,7 @@ radv_physical_device_init(struct radv_physical_device *device, fd = open(path, O_RDWR | O_CLOEXEC); if (fd < 0) - return vk_errorf(VK_ERROR_INCOMPATIBLE_DRIVER, - "failed to open %s: %m", path); + return VK_ERROR_INCOMPATIBLE_DRIVER; version = drmGetVersion(fd); if (!version) { @@ -365,10 +364,8 @@ void radv_DestroyInstance( { RADV_FROM_HANDLE(radv_instance, instance, _instance); - if (instance->physicalDeviceCount > 0) { - /* We support at most one physical device. */ - assert(instance->physicalDeviceCount == 1); - radv_physical_device_finish(&instance->physicalDevice); + for (int i = 0; i < instance->physicalDeviceCount; ++i) { + radv_physical_device_finish(instance->physicalDevices + i); } VG(VALGRIND_DESTROY_MEMPOOL(instance)); @@ -388,52 +385,29 @@ VkResult radv_EnumeratePhysicalDevices( if (instance->physicalDeviceCount < 0) { char path[20]; - for (unsigned i = 0; i < 8; i++) { + 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->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 { - 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; } } - /* pPhysicalDeviceCount is an out parameter if pPhysicalDevices is NULL; - * otherwise it's an inout parameter. - * - * The Vulkan spec (git aaed022) says: - * - * pPhysicalDeviceCount is a pointer to an unsigned integer variable - * that is initialized with the number of devices the application is - * prepared to receive handles to. pname:pPhysicalDevices is pointer to - * an array of at least this many VkPhysicalDevice handles [...]. - * - * Upon success, if pPhysicalDevices is NULL, vkEnumeratePhysicalDevices - * overwrites the contents of the variable pointed to by - * pPhysicalDeviceCount with the number of physical devices in in the - * instance; otherwise, vkEnumeratePhysicalDevices overwrites - * pPhysicalDeviceCount with the number of physical handles written to - * pPhysicalDevices. - */ if (!pPhysicalDevices) { *pPhysicalDeviceCount = instance->physicalDeviceCount; - } else if (*pPhysicalDeviceCount >= 1) { - pPhysicalDevices[0] = radv_physical_device_to_handle(&instance->physicalDevice); - *pPhysicalDeviceCount = 1; - } else if (*pPhysicalDeviceCount < instance->physicalDeviceCount) { - return VK_INCOMPLETE; } else { - *pPhysicalDeviceCount = 0; + *pPhysicalDeviceCount = MIN2(*pPhysicalDeviceCount, instance->physicalDeviceCount); + for (unsigned i = 0; i < *pPhysicalDeviceCount; ++i) + pPhysicalDevices[i] = radv_physical_device_to_handle(instance->physicalDevices + i); } - return VK_SUCCESS; + return *pPhysicalDeviceCount < instance->physicalDeviceCount ? VK_INCOMPLETE + : VK_SUCCESS; } void radv_GetPhysicalDeviceFeatures( diff --git a/src/amd/vulkan/radv_private.h b/src/amd/vulkan/radv_private.h index 112c2a6e97e..0b8f50a5d6d 100644 --- a/src/amd/vulkan/radv_private.h +++ b/src/amd/vulkan/radv_private.h @@ -81,6 +81,7 @@ typedef uint32_t xcb_window_t; #define MAX_DYNAMIC_BUFFERS 16 #define MAX_SAMPLES_LOG2 4 #define NUM_META_FS_KEYS 11 +#define RADV_MAX_DRM_DEVICES 8 #define NUM_DEPTH_CLEAR_PIPELINES 3 @@ -290,7 +291,7 @@ struct radv_instance { uint32_t apiVersion; int physicalDeviceCount; - struct radv_physical_device physicalDevice; + struct radv_physical_device physicalDevices[RADV_MAX_DRM_DEVICES]; uint64_t debug_flags; };