radv: add a LLVM version string workaround for SotTR and ACO
[mesa.git] / src / amd / vulkan / radv_device.c
index d5d1553e5f92c8899c8e45e085359cb86b539707..fc102e23cedcadde9255af3b01a06beb6181071d 100644 (file)
@@ -238,6 +238,25 @@ radv_physical_device_init_mem_types(struct radv_physical_device *device)
        }
 }
 
+static const char *
+radv_get_compiler_string(struct radv_physical_device *pdevice)
+{
+       if (pdevice->use_aco) {
+               /* Some games like SotTR apply shader workarounds if the LLVM
+                * version is too old or if the LLVM version string is
+                * missing. This gives 2-5% performance with SotTR and ACO.
+                */
+               if (driQueryOptionb(&pdevice->instance->dri_options,
+                                   "radv_report_llvm9_version_string")) {
+                       return "ACO/LLVM 9.0.1";
+               }
+
+               return "ACO";
+       }
+
+       return "LLVM " MESA_LLVM_VERSION_STRING;
+}
+
 static VkResult
 radv_physical_device_try_create(struct radv_instance *instance,
                                drmDevicePtr drm_device,
@@ -334,8 +353,7 @@ radv_physical_device_try_create(struct radv_instance *instance,
 
        snprintf(device->name, sizeof(device->name),
                 "AMD RADV %s (%s)",
-                device->rad_info.name,
-                device->use_aco ? "ACO" : "LLVM " MESA_LLVM_VERSION_STRING);
+                device->rad_info.name, radv_get_compiler_string(device));
 
        if (radv_device_get_cache_uuid(device->rad_info.family, device->cache_uuid)) {
                result = vk_errorf(instance, VK_ERROR_INITIALIZATION_FAILED,
@@ -394,7 +412,9 @@ radv_physical_device_try_create(struct radv_instance *instance,
        }
 
        radv_physical_device_init_mem_types(device);
-       radv_fill_device_extension_table(device, &device->supported_extensions);
+
+       radv_physical_device_get_supported_extensions(device,
+                                                     &device->supported_extensions);
 
        if (drm_device)
                device->bus_info = *drm_device->businfo.pci;
@@ -576,6 +596,7 @@ DRI_CONF_BEGIN
                DRI_CONF_ADAPTIVE_SYNC("true")
                DRI_CONF_VK_X11_OVERRIDE_MIN_IMAGE_COUNT(0)
                DRI_CONF_VK_X11_STRICT_IMAGE_COUNT("false")
+               DRI_CONF_RADV_REPORT_LLVM9_VERSION_STRING("false")
        DRI_CONF_SECTION_END
 
        DRI_CONF_SECTION_DEBUG
@@ -606,7 +627,7 @@ VkResult radv_CreateInstance(
        if (!instance)
                return vk_error(NULL, VK_ERROR_OUT_OF_HOST_MEMORY);
 
-       instance->_loader_data.loaderMagic = ICD_LOADER_MAGIC;
+       vk_object_base_init(NULL, &instance->base, VK_OBJECT_TYPE_INSTANCE);
 
        if (pAllocator)
                instance->alloc = *pAllocator;
@@ -657,7 +678,7 @@ VkResult radv_CreateInstance(
                }
 
                if (idx >= RADV_INSTANCE_EXTENSION_COUNT ||
-                   !radv_supported_instance_extensions.extensions[idx]) {
+                   !radv_instance_extensions_supported.extensions[idx]) {
                        vk_free2(&default_alloc, pAllocator, instance);
                        return vk_error(instance, VK_ERROR_EXTENSION_NOT_PRESENT);
                }
@@ -755,6 +776,7 @@ void radv_DestroyInstance(
 
        vk_debug_report_instance_destroy(&instance->debug_report_callbacks);
 
+       vk_object_base_finish(&instance->base);
        vk_free(&instance->alloc, instance);
 }
 
@@ -1273,6 +1295,12 @@ void radv_GetPhysicalDeviceFeatures2(
                        features->nullDescriptor = true;
                        break;
                }
+               case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PRIVATE_DATA_FEATURES_EXT: {
+                       VkPhysicalDevicePrivateDataFeaturesEXT *features =
+                               (VkPhysicalDevicePrivateDataFeaturesEXT *)ext;
+                       features->privateData = true;
+                       break;
+               }
                default:
                        break;
                }
@@ -1483,7 +1511,7 @@ radv_get_physical_device_properties_1_2(struct radv_physical_device *pdevice,
        snprintf(p->driverName, VK_MAX_DRIVER_NAME_SIZE, "radv");
        snprintf(p->driverInfo, VK_MAX_DRIVER_INFO_SIZE,
                 "Mesa " PACKAGE_VERSION MESA_GIT_SHA1 " (%s)",
-                pdevice->use_aco ? "ACO" : "LLVM " MESA_LLVM_VERSION_STRING);
+                radv_get_compiler_string(pdevice));
        p->conformanceVersion = (VkConformanceVersion) {
                .major = 1,
                .minor = 2,
@@ -2520,7 +2548,7 @@ static void run_secure_compile_device(struct radv_device *device, unsigned proce
                        struct radv_pipeline *pipeline;
                        bool sc_read = true;
 
-                       pipeline = vk_zalloc2(&device->alloc, NULL, sizeof(*pipeline), 8,
+                       pipeline = vk_zalloc2(&device->vk.alloc, NULL, sizeof(*pipeline), 8,
                                              VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
 
                        pipeline->device = device;
@@ -2646,7 +2674,7 @@ static void run_secure_compile_device(struct radv_device *device, unsigned proce
                                free((void *) pStages[i]);
                        }
 
-                       vk_free(&device->alloc, pipeline);
+                       vk_free(&device->vk.alloc, pipeline);
 
                        sc_type = RADV_SC_TYPE_COMPILE_PIPELINE_FINISHED;
                        write(fd_secure_output, &sc_type, sizeof(sc_type));
@@ -2761,7 +2789,7 @@ static void destroy_secure_compile_device(struct radv_device *device, unsigned p
 
 static VkResult fork_secure_compile_idle_device(struct radv_device *device)
 {
-       device->sc_state = vk_zalloc(&device->alloc,
+       device->sc_state = vk_zalloc(&device->vk.alloc,
                                     sizeof(struct radv_secure_compile_state),
                                     8, VK_SYSTEM_ALLOCATION_SCOPE_DEVICE);
 
@@ -2788,7 +2816,7 @@ static VkResult fork_secure_compile_idle_device(struct radv_device *device)
                }
        }
 
-       device->sc_state->secure_compile_processes = vk_zalloc(&device->alloc,
+       device->sc_state->secure_compile_processes = vk_zalloc(&device->vk.alloc,
                                                                sizeof(struct radv_secure_compile_process) * sc_threads, 8,
                                                                VK_SYSTEM_ALLOCATION_SCOPE_DEVICE);
 
@@ -2961,21 +2989,19 @@ VkResult radv_CreateDevice(
        if (!device)
                return vk_error(physical_device->instance, VK_ERROR_OUT_OF_HOST_MEMORY);
 
-       device->_loader_data.loaderMagic = ICD_LOADER_MAGIC;
+       vk_device_init(&device->vk, pCreateInfo,
+                      &physical_device->instance->alloc, pAllocator);
+
        device->instance = physical_device->instance;
        device->physical_device = physical_device;
 
        device->ws = physical_device->ws;
-       if (pAllocator)
-               device->alloc = *pAllocator;
-       else
-               device->alloc = physical_device->instance->alloc;
 
        for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) {
                const char *ext_name = pCreateInfo->ppEnabledExtensionNames[i];
                int index = radv_get_device_extension_index(ext_name);
                if (index < 0 || !physical_device->supported_extensions.extensions[index]) {
-                       vk_free(&device->alloc, device);
+                       vk_free(&device->vk.alloc, device);
                        return vk_error(physical_device->instance, VK_ERROR_EXTENSION_NOT_PRESENT);
                }
 
@@ -3013,7 +3039,7 @@ VkResult radv_CreateDevice(
 
                assert(!global_priority || device->physical_device->rad_info.has_ctx_priority);
 
-               device->queues[qfi] = vk_alloc(&device->alloc,
+               device->queues[qfi] = vk_alloc(&device->vk.alloc,
                                               queue_create->queueCount * sizeof(struct radv_queue), 8, VK_SYSTEM_ALLOCATION_SCOPE_DEVICE);
                if (!device->queues[qfi]) {
                        result = VK_ERROR_OUT_OF_HOST_MEMORY;
@@ -3197,10 +3223,10 @@ fail:
                for (unsigned q = 0; q < device->queue_count[i]; q++)
                        radv_queue_finish(&device->queues[i][q]);
                if (device->queue_count[i])
-                       vk_free(&device->alloc, device->queues[i]);
+                       vk_free(&device->vk.alloc, device->queues[i]);
        }
 
-       vk_free(&device->alloc, device);
+       vk_free(&device->vk.alloc, device);
        return result;
 }
 
@@ -3223,7 +3249,7 @@ void radv_DestroyDevice(
                for (unsigned q = 0; q < device->queue_count[i]; q++)
                        radv_queue_finish(&device->queues[i][q]);
                if (device->queue_count[i])
-                       vk_free(&device->alloc, device->queues[i]);
+                       vk_free(&device->vk.alloc, device->queues[i]);
                if (device->empty_cs[i])
                        device->ws->cs_destroy(device->empty_cs[i]);
        }
@@ -3247,10 +3273,10 @@ void radv_DestroyDevice(
 
        if (device->sc_state) {
                free(device->sc_state->uid);
-               vk_free(&device->alloc, device->sc_state->secure_compile_processes);
+               vk_free(&device->vk.alloc, device->sc_state->secure_compile_processes);
        }
-       vk_free(&device->alloc, device->sc_state);
-       vk_free(&device->alloc, device);
+       vk_free(&device->vk.alloc, device->sc_state);
+       vk_free(&device->vk.alloc, device);
 }
 
 VkResult radv_EnumerateInstanceLayerProperties(
@@ -4930,7 +4956,7 @@ VkResult radv_EnumerateInstanceExtensionProperties(
        VK_OUTARRAY_MAKE(out, pProperties, pPropertyCount);
 
        for (int i = 0; i < RADV_INSTANCE_EXTENSION_COUNT; i++) {
-               if (radv_supported_instance_extensions.extensions[i]) {
+               if (radv_instance_extensions_supported.extensions[i]) {
                        vk_outarray_append(&out, prop) {
                                *prop = radv_instance_extensions[i];
                        }
@@ -5102,7 +5128,8 @@ static void radv_free_memory(struct radv_device *device,
                mem->bo = NULL;
        }
 
-       vk_free2(&device->alloc, pAllocator, mem);
+       vk_object_base_finish(&mem->base);
+       vk_free2(&device->vk.alloc, pAllocator, mem);
 }
 
 static VkResult radv_alloc_memory(struct radv_device *device,
@@ -5139,11 +5166,14 @@ static VkResult radv_alloc_memory(struct radv_device *device,
                return VK_SUCCESS;
        }
 
-       mem = vk_zalloc2(&device->alloc, pAllocator, sizeof(*mem), 8,
+       mem = vk_zalloc2(&device->vk.alloc, pAllocator, sizeof(*mem), 8,
                          VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
        if (mem == NULL)
                return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY);
 
+       vk_object_base_init(&device->vk, &mem->base,
+                           VK_OBJECT_TYPE_DEVICE_MEMORY);
+
        if (wsi_info && wsi_info->implicit_sync)
                flags |= RADEON_FLAG_IMPLICIT_SYNC;
 
@@ -5596,19 +5626,21 @@ VkResult radv_CreateFence(
        VkExternalFenceHandleTypeFlags handleTypes =
                export ? export->handleTypes : 0;
 
-       struct radv_fence *fence = vk_alloc2(&device->alloc, pAllocator,
+       struct radv_fence *fence = vk_alloc2(&device->vk.alloc, pAllocator,
                                               sizeof(*fence), 8,
                                               VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
 
        if (!fence)
                return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY);
 
+       vk_object_base_init(&device->vk, &fence->base, VK_OBJECT_TYPE_FENCE);
+
        fence->fence_wsi = NULL;
        fence->temp_syncobj = 0;
        if (device->always_use_syncobj || handleTypes) {
                int ret = device->ws->create_syncobj(device->ws, &fence->syncobj);
                if (ret) {
-                       vk_free2(&device->alloc, pAllocator, fence);
+                       vk_free2(&device->vk.alloc, pAllocator, fence);
                        return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY);
                }
                if (pCreateInfo->flags & VK_FENCE_CREATE_SIGNALED_BIT) {
@@ -5618,7 +5650,7 @@ VkResult radv_CreateFence(
        } else {
                fence->fence = device->ws->create_fence();
                if (!fence->fence) {
-                       vk_free2(&device->alloc, pAllocator, fence);
+                       vk_free2(&device->vk.alloc, pAllocator, fence);
                        return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY);
                }
                fence->syncobj = 0;
@@ -5650,7 +5682,9 @@ void radv_DestroyFence(
                device->ws->destroy_fence(fence->fence);
        if (fence->fence_wsi)
                fence->fence_wsi->destroy(fence->fence_wsi);
-       vk_free2(&device->alloc, pAllocator, fence);
+
+       vk_object_base_finish(&fence->base);
+       vk_free2(&device->vk.alloc, pAllocator, fence);
 }
 
 
@@ -6062,12 +6096,15 @@ VkResult radv_CreateSemaphore(
        uint64_t initial_value = 0;
        VkSemaphoreTypeKHR type = radv_get_semaphore_type(pCreateInfo->pNext, &initial_value);
 
-       struct radv_semaphore *sem = vk_alloc2(&device->alloc, pAllocator,
+       struct radv_semaphore *sem = vk_alloc2(&device->vk.alloc, pAllocator,
                                               sizeof(*sem), 8,
                                               VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
        if (!sem)
                return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY);
 
+       vk_object_base_init(&device->vk, &sem->base,
+                           VK_OBJECT_TYPE_SEMAPHORE);
+
        sem->temporary.kind = RADV_SEMAPHORE_NONE;
        sem->permanent.kind = RADV_SEMAPHORE_NONE;
 
@@ -6078,14 +6115,14 @@ VkResult radv_CreateSemaphore(
                assert (device->physical_device->rad_info.has_syncobj);
                int ret = device->ws->create_syncobj(device->ws, &sem->permanent.syncobj);
                if (ret) {
-                       vk_free2(&device->alloc, pAllocator, sem);
+                       vk_free2(&device->vk.alloc, pAllocator, sem);
                        return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY);
                }
                sem->permanent.kind = RADV_SEMAPHORE_SYNCOBJ;
        } else {
                sem->permanent.ws_sem = device->ws->create_sem(device->ws);
                if (!sem->permanent.ws_sem) {
-                       vk_free2(&device->alloc, pAllocator, sem);
+                       vk_free2(&device->vk.alloc, pAllocator, sem);
                        return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY);
                }
                sem->permanent.kind = RADV_SEMAPHORE_WINSYS;
@@ -6107,7 +6144,8 @@ void radv_DestroySemaphore(
 
        radv_destroy_semaphore_part(device, &sem->temporary);
        radv_destroy_semaphore_part(device, &sem->permanent);
-       vk_free2(&device->alloc, pAllocator, sem);
+       vk_object_base_finish(&sem->base);
+       vk_free2(&device->vk.alloc, pAllocator, sem);
 }
 
 VkResult
@@ -6221,19 +6259,21 @@ VkResult radv_CreateEvent(
        VkEvent*                                    pEvent)
 {
        RADV_FROM_HANDLE(radv_device, device, _device);
-       struct radv_event *event = vk_alloc2(&device->alloc, pAllocator,
+       struct radv_event *event = vk_alloc2(&device->vk.alloc, pAllocator,
                                               sizeof(*event), 8,
                                               VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
 
        if (!event)
                return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY);
 
+       vk_object_base_init(&device->vk, &event->base, VK_OBJECT_TYPE_EVENT);
+
        event->bo = device->ws->buffer_create(device->ws, 8, 8,
                                              RADEON_DOMAIN_GTT,
                                              RADEON_FLAG_VA_UNCACHED | RADEON_FLAG_CPU_ACCESS | RADEON_FLAG_NO_INTERPROCESS_SHARING,
                                              RADV_BO_PRIORITY_FENCE);
        if (!event->bo) {
-               vk_free2(&device->alloc, pAllocator, event);
+               vk_free2(&device->vk.alloc, pAllocator, event);
                return vk_error(device->instance, VK_ERROR_OUT_OF_DEVICE_MEMORY);
        }
 
@@ -6255,7 +6295,8 @@ void radv_DestroyEvent(
        if (!event)
                return;
        device->ws->buffer_destroy(event->bo);
-       vk_free2(&device->alloc, pAllocator, event);
+       vk_object_base_finish(&event->base);
+       vk_free2(&device->vk.alloc, pAllocator, event);
 }
 
 VkResult radv_GetEventStatus(
@@ -6303,11 +6344,13 @@ VkResult radv_CreateBuffer(
 
        assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO);
 
-       buffer = vk_alloc2(&device->alloc, pAllocator, sizeof(*buffer), 8,
+       buffer = vk_alloc2(&device->vk.alloc, pAllocator, sizeof(*buffer), 8,
                             VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
        if (buffer == NULL)
                return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY);
 
+       vk_object_base_init(&device->vk, &buffer->base, VK_OBJECT_TYPE_BUFFER);
+
        buffer->size = pCreateInfo->size;
        buffer->usage = pCreateInfo->usage;
        buffer->bo = NULL;
@@ -6323,7 +6366,7 @@ VkResult radv_CreateBuffer(
                                                       4096, 0, RADEON_FLAG_VIRTUAL,
                                                       RADV_BO_PRIORITY_VIRTUAL);
                if (!buffer->bo) {
-                       vk_free2(&device->alloc, pAllocator, buffer);
+                       vk_free2(&device->vk.alloc, pAllocator, buffer);
                        return vk_error(device->instance, VK_ERROR_OUT_OF_DEVICE_MEMORY);
                }
        }
@@ -6347,7 +6390,8 @@ void radv_DestroyBuffer(
        if (buffer->flags & VK_BUFFER_CREATE_SPARSE_BINDING_BIT)
                device->ws->buffer_destroy(buffer->bo);
 
-       vk_free2(&device->alloc, pAllocator, buffer);
+       vk_object_base_finish(&buffer->base);
+       vk_free2(&device->vk.alloc, pAllocator, buffer);
 }
 
 VkDeviceAddress radv_GetBufferDeviceAddress(
@@ -6911,11 +6955,14 @@ VkResult radv_CreateFramebuffer(
        size_t size = sizeof(*framebuffer);
        if (!imageless_create_info)
                size += sizeof(struct radv_image_view*) * pCreateInfo->attachmentCount;
-       framebuffer = vk_alloc2(&device->alloc, pAllocator, size, 8,
+       framebuffer = vk_alloc2(&device->vk.alloc, pAllocator, size, 8,
                                  VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
        if (framebuffer == NULL)
                return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY);
 
+       vk_object_base_init(&device->vk, &framebuffer->base,
+                           VK_OBJECT_TYPE_FRAMEBUFFER);
+
        framebuffer->attachment_count = pCreateInfo->attachmentCount;
        framebuffer->width = pCreateInfo->width;
        framebuffer->height = pCreateInfo->height;
@@ -6953,7 +7000,8 @@ void radv_DestroyFramebuffer(
 
        if (!fb)
                return;
-       vk_free2(&device->alloc, pAllocator, fb);
+       vk_object_base_finish(&fb->base);
+       vk_free2(&device->vk.alloc, pAllocator, fb);
 }
 
 static unsigned radv_tex_wrap(VkSamplerAddressMode address_mode)
@@ -7169,11 +7217,14 @@ VkResult radv_CreateSampler(
 
        assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO);
 
-       sampler = vk_alloc2(&device->alloc, pAllocator, sizeof(*sampler), 8,
+       sampler = vk_alloc2(&device->vk.alloc, pAllocator, sizeof(*sampler), 8,
                              VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
        if (!sampler)
                return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY);
 
+       vk_object_base_init(&device->vk, &sampler->base,
+                           VK_OBJECT_TYPE_SAMPLER);
+
        radv_init_sampler(device, sampler, pCreateInfo);
 
        sampler->ycbcr_sampler = ycbcr_conversion ? radv_sampler_ycbcr_conversion_from_handle(ycbcr_conversion->conversion): NULL;
@@ -7192,7 +7243,8 @@ void radv_DestroySampler(
 
        if (!sampler)
                return;
-       vk_free2(&device->alloc, pAllocator, sampler);
+       vk_object_base_finish(&sampler->base);
+       vk_free2(&device->vk.alloc, pAllocator, sampler);
 }
 
 /* vk_icd.h does not declare this function, so we declare it here to
@@ -7753,3 +7805,48 @@ void radv_GetPhysicalDeviceMultisamplePropertiesEXT(
                pMultisampleProperties->maxSampleLocationGridSize = (VkExtent2D){ 0, 0 };
        }
 }
+
+VkResult radv_CreatePrivateDataSlotEXT(
+    VkDevice                                    _device,
+    const VkPrivateDataSlotCreateInfoEXT*       pCreateInfo,
+    const VkAllocationCallbacks*                pAllocator,
+    VkPrivateDataSlotEXT*                       pPrivateDataSlot)
+{
+       RADV_FROM_HANDLE(radv_device, device, _device);
+       return vk_private_data_slot_create(&device->vk, pCreateInfo, pAllocator,
+                                          pPrivateDataSlot);
+}
+
+void radv_DestroyPrivateDataSlotEXT(
+    VkDevice                                    _device,
+    VkPrivateDataSlotEXT                        privateDataSlot,
+    const VkAllocationCallbacks*                pAllocator)
+{
+       RADV_FROM_HANDLE(radv_device, device, _device);
+       vk_private_data_slot_destroy(&device->vk, privateDataSlot, pAllocator);
+}
+
+VkResult radv_SetPrivateDataEXT(
+    VkDevice                                    _device,
+    VkObjectType                                objectType,
+    uint64_t                                    objectHandle,
+    VkPrivateDataSlotEXT                        privateDataSlot,
+    uint64_t                                    data)
+{
+       RADV_FROM_HANDLE(radv_device, device, _device);
+       return vk_object_base_set_private_data(&device->vk, objectType,
+                                              objectHandle, privateDataSlot,
+                                              data);
+}
+
+void radv_GetPrivateDataEXT(
+    VkDevice                                    _device,
+    VkObjectType                                objectType,
+    uint64_t                                    objectHandle,
+    VkPrivateDataSlotEXT                        privateDataSlot,
+    uint64_t*                                   pData)
+{
+       RADV_FROM_HANDLE(radv_device, device, _device);
+       vk_object_base_get_private_data(&device->vk, objectType, objectHandle,
+                                       privateDataSlot, pData);
+}