radv: remove the LLVM version string when ACO is used
[mesa.git] / src / amd / vulkan / radv_device.c
index 6fd80ad16a030c1c003da57d9619a205cc4c8b7b..d5d1553e5f92c8899c8e45e085359cb86b539707 100644 (file)
@@ -239,9 +239,9 @@ radv_physical_device_init_mem_types(struct radv_physical_device *device)
 }
 
 static VkResult
-radv_physical_device_init(struct radv_physical_device *device,
-                         struct radv_instance *instance,
-                         drmDevicePtr drm_device)
+radv_physical_device_try_create(struct radv_instance *instance,
+                               drmDevicePtr drm_device,
+                               struct radv_physical_device **device_out)
 {
        VkResult result;
        int fd = -1;
@@ -285,6 +285,14 @@ radv_physical_device_init(struct radv_physical_device *device,
                                radv_logi("Found compatible device '%s'.", path);
        }
 
+       struct radv_physical_device *device =
+               vk_zalloc2(&instance->alloc, NULL, sizeof(*device), 8,
+                          VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
+       if (!device) {
+               result = vk_error(instance, VK_ERROR_OUT_OF_HOST_MEMORY);
+               goto fail_fd;
+       }
+
        device->_loader_data.loaderMagic = ICD_LOADER_MAGIC;
        device->instance = instance;
 
@@ -296,8 +304,9 @@ radv_physical_device_init(struct radv_physical_device *device,
        }
 
        if (!device->ws) {
-               result = vk_error(instance, VK_ERROR_INITIALIZATION_FAILED);
-               goto fail_fd;
+               result = vk_errorf(instance, VK_ERROR_INITIALIZATION_FAILED,
+                                  "failed to initialize winsys");
+               goto fail_alloc;
        }
 
        if (drm_device && instance->enabled_extensions.KHR_display) {
@@ -324,8 +333,9 @@ radv_physical_device_init(struct radv_physical_device *device,
        device->use_aco = instance->perftest_flags & RADV_PERFTEST_ACO;
 
        snprintf(device->name, sizeof(device->name),
-                "AMD RADV%s %s (LLVM " MESA_LLVM_VERSION_STRING ")", device->use_aco ? "/ACO" : "",
-                device->rad_info.name);
+                "AMD RADV %s (%s)",
+                device->rad_info.name,
+                device->use_aco ? "ACO" : "LLVM " MESA_LLVM_VERSION_STRING);
 
        if (radv_device_get_cache_uuid(device->rad_info.family, device->cache_uuid)) {
                result = vk_errorf(instance, VK_ERROR_INITIALIZATION_FAILED,
@@ -402,12 +412,16 @@ radv_physical_device_init(struct radv_physical_device *device,
                goto fail_disk_cache;
        }
 
+       *device_out = device;
+
        return VK_SUCCESS;
 
 fail_disk_cache:
        disk_cache_destroy(device->disk_cache);
 fail_wsi:
        device->ws->destroy(device->ws);
+fail_alloc:
+       vk_free(&instance->alloc, device);
 fail_fd:
        close(fd);
        if (master_fd != -1)
@@ -416,7 +430,7 @@ fail_fd:
 }
 
 static void
-radv_physical_device_finish(struct radv_physical_device *device)
+radv_physical_device_destroy(struct radv_physical_device *device)
 {
        radv_finish_wsi(device);
        device->ws->destroy(device->ws);
@@ -424,6 +438,7 @@ radv_physical_device_finish(struct radv_physical_device *device)
        close(device->local_fd);
        if (device->master_fd != -1)
                close(device->master_fd);
+       vk_free(&device->instance->alloc, device);
 }
 
 static void *
@@ -611,8 +626,6 @@ VkResult radv_CreateInstance(
        if (instance->apiVersion == 0)
                instance->apiVersion = VK_API_VERSION_1_0;
 
-       instance->physicalDeviceCount = -1;
-
        /* Get secure compile thread count. NOTE: We cap this at 32 */
 #define MAX_SC_PROCS 32
        char *num_sc_threads = getenv("RADV_SECURE_COMPILE_THREADS");
@@ -696,6 +709,9 @@ VkResult radv_CreateInstance(
                }
        }
 
+       instance->physical_devices_enumerated = false;
+       list_inithead(&instance->physical_devices);
+
        result = vk_debug_report_instance_init(&instance->debug_report_callbacks);
        if (result != VK_SUCCESS) {
                vk_free2(&default_alloc, pAllocator, instance);
@@ -723,8 +739,9 @@ void radv_DestroyInstance(
        if (!instance)
                return;
 
-       for (int i = 0; i < instance->physicalDeviceCount; ++i) {
-               radv_physical_device_finish(instance->physicalDevices + i);
+       list_for_each_entry_safe(struct radv_physical_device, pdevice,
+                                &instance->physical_devices, link) {
+               radv_physical_device_destroy(pdevice);
        }
 
        vk_free(&instance->alloc, instance->engineName);
@@ -744,23 +761,28 @@ void radv_DestroyInstance(
 static VkResult
 radv_enumerate_physical_devices(struct radv_instance *instance)
 {
+       if (instance->physical_devices_enumerated)
+               return VK_SUCCESS;
+
+       instance->physical_devices_enumerated = true;
+
        /* TODO: Check for more devices ? */
        drmDevicePtr devices[8];
        VkResult result = VK_SUCCESS;
        int max_devices;
 
-       instance->physicalDeviceCount = 0;
-
        if (getenv("RADV_FORCE_FAMILY")) {
                /* When RADV_FORCE_FAMILY is set, the driver creates a nul
                 * device that allows to test the compiler without having an
                 * AMDGPU instance.
                 */
-               result = radv_physical_device_init(instance->physicalDevices +
-                                                  instance->physicalDeviceCount,
-                                                  instance, NULL);
+               struct radv_physical_device *pdevice;
+
+               result = radv_physical_device_try_create(instance, NULL, &pdevice);
+               if (result != VK_SUCCESS)
+                       return result;
 
-               ++instance->physicalDeviceCount;
+               list_addtail(&pdevice->link, &instance->physical_devices);
                return VK_SUCCESS;
        }
 
@@ -777,10 +799,9 @@ radv_enumerate_physical_devices(struct radv_instance *instance)
                    devices[i]->bustype == DRM_BUS_PCI &&
                    devices[i]->deviceinfo.pci->vendor_id == ATI_VENDOR_ID) {
 
-                       result = radv_physical_device_init(instance->physicalDevices +
-                                                          instance->physicalDeviceCount,
-                                                          instance,
-                                                          devices[i]);
+                       struct radv_physical_device *pdevice;
+                       result = radv_physical_device_try_create(instance, devices[i],
+                                                                &pdevice);
                        /* Incompatible DRM device, skip. */
                        if (result == VK_ERROR_INCOMPATIBLE_DRIVER) {
                                result = VK_SUCCESS;
@@ -791,7 +812,7 @@ radv_enumerate_physical_devices(struct radv_instance *instance)
                        if (result != VK_SUCCESS)
                                break;
 
-                       ++instance->physicalDeviceCount;
+                       list_addtail(&pdevice->link, &instance->physical_devices);
                }
        }
        drmFreeDevices(devices, max_devices);
@@ -806,24 +827,20 @@ VkResult radv_EnumeratePhysicalDevices(
        VkPhysicalDevice*                           pPhysicalDevices)
 {
        RADV_FROM_HANDLE(radv_instance, instance, _instance);
-       VkResult result;
+       VK_OUTARRAY_MAKE(out, pPhysicalDevices, pPhysicalDeviceCount);
 
-       if (instance->physicalDeviceCount < 0) {
-               result = radv_enumerate_physical_devices(instance);
-               if (result != VK_SUCCESS)
-                       return result;
-       }
+       VkResult result = radv_enumerate_physical_devices(instance);
+       if (result != VK_SUCCESS)
+               return result;
 
-       if (!pPhysicalDevices) {
-               *pPhysicalDeviceCount = instance->physicalDeviceCount;
-       } else {
-               *pPhysicalDeviceCount = MIN2(*pPhysicalDeviceCount, instance->physicalDeviceCount);
-               for (unsigned i = 0; i < *pPhysicalDeviceCount; ++i)
-                       pPhysicalDevices[i] = radv_physical_device_to_handle(instance->physicalDevices + i);
+       list_for_each_entry(struct radv_physical_device, pdevice,
+                           &instance->physical_devices, link) {
+               vk_outarray_append(&out, i) {
+                       *i = radv_physical_device_to_handle(pdevice);
+               }
        }
 
-       return *pPhysicalDeviceCount < instance->physicalDeviceCount ? VK_INCOMPLETE
-                                                                    : VK_SUCCESS;
+       return vk_outarray_status(&out);
 }
 
 VkResult radv_EnumeratePhysicalDeviceGroups(
@@ -832,26 +849,24 @@ VkResult radv_EnumeratePhysicalDeviceGroups(
     VkPhysicalDeviceGroupProperties*            pPhysicalDeviceGroupProperties)
 {
        RADV_FROM_HANDLE(radv_instance, instance, _instance);
-       VkResult result;
+       VK_OUTARRAY_MAKE(out, pPhysicalDeviceGroupProperties,
+                             pPhysicalDeviceGroupCount);
 
-       if (instance->physicalDeviceCount < 0) {
-               result = radv_enumerate_physical_devices(instance);
-               if (result != VK_SUCCESS)
-                       return result;
-       }
+       VkResult result = radv_enumerate_physical_devices(instance);
+       if (result != VK_SUCCESS)
+               return result;
 
-       if (!pPhysicalDeviceGroupProperties) {
-               *pPhysicalDeviceGroupCount = instance->physicalDeviceCount;
-       } else {
-               *pPhysicalDeviceGroupCount = MIN2(*pPhysicalDeviceGroupCount, instance->physicalDeviceCount);
-               for (unsigned i = 0; i < *pPhysicalDeviceGroupCount; ++i) {
-                       pPhysicalDeviceGroupProperties[i].physicalDeviceCount = 1;
-                       pPhysicalDeviceGroupProperties[i].physicalDevices[0] = radv_physical_device_to_handle(instance->physicalDevices + i);
-                       pPhysicalDeviceGroupProperties[i].subsetAllocation = false;
+       list_for_each_entry(struct radv_physical_device, pdevice,
+                           &instance->physical_devices, link) {
+               vk_outarray_append(&out, p) {
+                       p->physicalDeviceCount = 1;
+                       memset(p->physicalDevices, 0, sizeof(p->physicalDevices));
+                       p->physicalDevices[0] = radv_physical_device_to_handle(pdevice);
+                       p->subsetAllocation = false;
                }
        }
-       return *pPhysicalDeviceGroupCount < instance->physicalDeviceCount ? VK_INCOMPLETE
-                                                                         : VK_SUCCESS;
+
+       return vk_outarray_status(&out);
 }
 
 void radv_GetPhysicalDeviceFeatures(
@@ -1467,8 +1482,8 @@ radv_get_physical_device_properties_1_2(struct radv_physical_device *pdevice,
        p->driverID = VK_DRIVER_ID_MESA_RADV;
        snprintf(p->driverName, VK_MAX_DRIVER_NAME_SIZE, "radv");
        snprintf(p->driverInfo, VK_MAX_DRIVER_INFO_SIZE,
-                "Mesa " PACKAGE_VERSION MESA_GIT_SHA1
-                " (LLVM " MESA_LLVM_VERSION_STRING ")");
+                "Mesa " PACKAGE_VERSION MESA_GIT_SHA1 " (%s)",
+                pdevice->use_aco ? "ACO" : "LLVM " MESA_LLVM_VERSION_STRING);
        p->conformanceVersion = (VkConformanceVersion) {
                .major = 1,
                .minor = 2,
@@ -6455,18 +6470,20 @@ radv_initialise_color_surface(struct radv_device *device,
        cb->cb_color_base = va >> 8;
 
        if (device->physical_device->rad_info.chip_class >= GFX9) {
-               struct gfx9_surf_meta_flags meta;
-               if (iview->image->dcc_offset)
-                       meta = surf->u.gfx9.dcc;
-               else
-                       meta = surf->u.gfx9.cmask;
-
                if (device->physical_device->rad_info.chip_class >= GFX10) {
                        cb->cb_color_attrib3 |= S_028EE0_COLOR_SW_MODE(surf->u.gfx9.surf.swizzle_mode) |
                                S_028EE0_FMASK_SW_MODE(surf->u.gfx9.fmask.swizzle_mode) |
-                               S_028EE0_CMASK_PIPE_ALIGNED(surf->u.gfx9.cmask.pipe_aligned) |
+                               S_028EE0_CMASK_PIPE_ALIGNED(1) |
                                S_028EE0_DCC_PIPE_ALIGNED(surf->u.gfx9.dcc.pipe_aligned);
                } else {
+                       struct gfx9_surf_meta_flags meta = {
+                               .rb_aligned = 1,
+                               .pipe_aligned = 1,
+                       };
+
+                       if (iview->image->dcc_offset)
+                               meta = surf->u.gfx9.dcc;
+
                        cb->cb_color_attrib |= S_028C74_COLOR_SW_MODE(surf->u.gfx9.surf.swizzle_mode) |
                                S_028C74_FMASK_SW_MODE(surf->u.gfx9.fmask.swizzle_mode) |
                                S_028C74_RB_ALIGNED(meta.rb_aligned) |
@@ -6794,10 +6811,10 @@ radv_initialise_ds_surface(struct radv_device *device,
                                iview->image->htile_offset;
                        ds->db_htile_data_base = va >> 8;
                        ds->db_htile_surface = S_028ABC_FULL_CACHE(1) |
-                               S_028ABC_PIPE_ALIGNED(surf->u.gfx9.htile.pipe_aligned);
+                               S_028ABC_PIPE_ALIGNED(1);
 
                        if (device->physical_device->rad_info.chip_class == GFX9) {
-                               ds->db_htile_surface |= S_028ABC_RB_ALIGNED(surf->u.gfx9.htile.rb_aligned);
+                               ds->db_htile_surface |= S_028ABC_RB_ALIGNED(1);
                        }
                }
        } else {