radv: Add support for driconf.
[mesa.git] / src / amd / vulkan / radv_device.c
index 34d93b262f85563f70ba465cc75e095f3800cb18..f44b6842c2ec9259c32676ec8e2447b5990bd7b4 100644 (file)
@@ -48,6 +48,8 @@
 #include "util/build_id.h"
 #include "util/debug.h"
 #include "util/mesa-sha1.h"
+#include "compiler/glsl_types.h"
+#include "util/xmlpool.h"
 
 static int
 radv_device_get_cache_uuid(enum radeon_family family, void *uuid)
@@ -87,7 +89,6 @@ static void
 radv_get_device_name(enum radeon_family family, char *name, size_t name_len)
 {
        const char *chip_string;
-       char llvm_string[32] = {};
 
        switch (family) {
        case CHIP_TAHITI: chip_string = "AMD RADV TAHITI"; break;
@@ -116,10 +117,7 @@ radv_get_device_name(enum radeon_family family, char *name, size_t name_len)
        default: chip_string = "AMD RADV unknown"; break;
        }
 
-       snprintf(llvm_string, sizeof(llvm_string),
-                " (LLVM %i.%i.%i)", (HAVE_LLVM >> 8) & 0xff,
-                HAVE_LLVM & 0xff, MESA_LLVM_VERSION_PATCH);
-       snprintf(name, name_len, "%s%s", chip_string, llvm_string);
+       snprintf(name, name_len, "%s (LLVM " MESA_LLVM_VERSION_STRING ")", chip_string);
 }
 
 static uint64_t
@@ -337,7 +335,7 @@ radv_physical_device_init(struct radv_physical_device *device,
            device->rad_info.chip_class > GFX9)
                fprintf(stderr, "WARNING: radv is not a conformant vulkan implementation, testing use only.\n");
 
-       radv_get_driver_uuid(&device->device_uuid);
+       radv_get_driver_uuid(&device->driver_uuid);
        radv_get_device_uuid(&device->rad_info, &device->device_uuid);
 
        if (device->rad_info.family == CHIP_STONEY ||
@@ -369,6 +367,11 @@ radv_physical_device_init(struct radv_physical_device *device,
        device->dcc_msaa_allowed =
                (device->instance->perftest_flags & RADV_PERFTEST_DCC_MSAA);
 
+       /* TODO: Figure out how to use LOAD_CONTEXT_REG on SI/CIK. */
+       device->has_load_ctx_reg_pkt = device->rad_info.chip_class >= GFX9 ||
+                                      (device->rad_info.chip_class >= VI &&
+                                       device->rad_info.me_fw_feature >= 41);
+
        radv_physical_device_init_mem_types(device);
        radv_fill_device_extension_table(device, &device->supported_extensions);
 
@@ -475,6 +478,7 @@ static const struct debug_control radv_perftest_options[] = {
        {"sisched", RADV_PERFTEST_SISCHED},
        {"localbos", RADV_PERFTEST_LOCAL_BOS},
        {"dccmsaa", RADV_PERFTEST_DCC_MSAA},
+       {"bolist", RADV_PERFTEST_BO_LIST},
        {NULL, 0}
 };
 
@@ -517,6 +521,17 @@ static int radv_get_instance_extension_index(const char *name)
        return -1;
 }
 
+static const char radv_dri_options_xml[] =
+DRI_CONF_BEGIN
+DRI_CONF_END;
+
+static void  radv_init_dri_options(struct radv_instance *instance)
+{
+       driParseOptionInfo(&instance->available_dri_options, radv_dri_options_xml);
+       driParseConfigFiles(&instance->dri_options,
+                           &instance->available_dri_options,
+                           0, "radv", NULL);
+}
 
 VkResult radv_CreateInstance(
        const VkInstanceCreateInfo*                 pCreateInfo,
@@ -580,9 +595,11 @@ VkResult radv_CreateInstance(
        }
 
        _mesa_locale_init();
+       glsl_type_singleton_init_or_ref();
 
        VG(VALGRIND_CREATE_MEMPOOL(instance, 0, false));
 
+       radv_init_dri_options(instance);
        radv_handle_per_app_options(instance, pCreateInfo->pApplicationInfo);
 
        *pInstance = radv_instance_to_handle(instance);
@@ -605,8 +622,12 @@ void radv_DestroyInstance(
 
        VG(VALGRIND_DESTROY_MEMPOOL(instance));
 
+       glsl_type_singleton_decref();
        _mesa_locale_fini();
 
+       driDestroyOptionCache(&instance->dri_options);
+       driDestroyOptionInfo(&instance->available_dri_options);
+
        vk_debug_report_instance_destroy(&instance->debug_report_callbacks);
 
        vk_free(&instance->alloc, instance);
@@ -734,8 +755,7 @@ void radv_GetPhysicalDeviceFeatures(
                .alphaToOne                               = true,
                .multiViewport                            = true,
                .samplerAnisotropy                        = true,
-               .textureCompressionETC2                   = pdevice->rad_info.chip_class >= GFX9 ||
-                                                           pdevice->rad_info.family == CHIP_STONEY,
+               .textureCompressionETC2                   = radv_device_supports_etc(pdevice),
                .textureCompressionASTC_LDR               = false,
                .textureCompressionBC                     = true,
                .occlusionQueryPrecise                    = true,
@@ -802,7 +822,7 @@ void radv_GetPhysicalDeviceFeatures2(
                        features->storageBuffer16BitAccess = enabled;
                        features->uniformAndStorageBuffer16BitAccess = enabled;
                        features->storagePushConstant16 = enabled;
-                       features->storageInputOutput16 = enabled;
+                       features->storageInputOutput16 = enabled && HAVE_LLVM >= 0x900;
                        break;
                }
                case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_YCBCR_CONVERSION_FEATURES: {
@@ -817,13 +837,13 @@ void radv_GetPhysicalDeviceFeatures2(
                        features->shaderInputAttachmentArrayDynamicIndexing = true;
                        features->shaderUniformTexelBufferArrayDynamicIndexing = true;
                        features->shaderStorageTexelBufferArrayDynamicIndexing = true;
-                       features->shaderUniformBufferArrayNonUniformIndexing = false;
-                       features->shaderSampledImageArrayNonUniformIndexing = false;
-                       features->shaderStorageBufferArrayNonUniformIndexing = false;
-                       features->shaderStorageImageArrayNonUniformIndexing = false;
-                       features->shaderInputAttachmentArrayNonUniformIndexing = false;
-                       features->shaderUniformTexelBufferArrayNonUniformIndexing = false;
-                       features->shaderStorageTexelBufferArrayNonUniformIndexing = false;
+                       features->shaderUniformBufferArrayNonUniformIndexing = true;
+                       features->shaderSampledImageArrayNonUniformIndexing = true;
+                       features->shaderStorageBufferArrayNonUniformIndexing = true;
+                       features->shaderStorageImageArrayNonUniformIndexing = true;
+                       features->shaderInputAttachmentArrayNonUniformIndexing = true;
+                       features->shaderUniformTexelBufferArrayNonUniformIndexing = true;
+                       features->shaderStorageTexelBufferArrayNonUniformIndexing = true;
                        features->descriptorBindingUniformBufferUpdateAfterBind = true;
                        features->descriptorBindingSampledImageUpdateAfterBind = true;
                        features->descriptorBindingStorageImageUpdateAfterBind = true;
@@ -869,6 +889,67 @@ void radv_GetPhysicalDeviceFeatures2(
                        features->memoryPriority = VK_TRUE;
                        break;
                }
+               case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BUFFER_ADDRESS_FEATURES_EXT: {
+                       VkPhysicalDeviceBufferAddressFeaturesEXT *features =
+                               (VkPhysicalDeviceBufferAddressFeaturesEXT *)ext;
+                       features->bufferDeviceAddress = true;
+                       features->bufferDeviceAddressCaptureReplay = false;
+                       features->bufferDeviceAddressMultiDevice = false;
+                       break;
+               }
+               case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEPTH_CLIP_ENABLE_FEATURES_EXT: {
+                       VkPhysicalDeviceDepthClipEnableFeaturesEXT *features =
+                               (VkPhysicalDeviceDepthClipEnableFeaturesEXT *)ext;
+                       features->depthClipEnable = true;
+                       break;
+               }
+               case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_HOST_QUERY_RESET_FEATURES_EXT: {
+                       VkPhysicalDeviceHostQueryResetFeaturesEXT *features =
+                               (VkPhysicalDeviceHostQueryResetFeaturesEXT *)ext;
+                       features->hostQueryReset = true;
+                       break;
+               }
+               case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_8BIT_STORAGE_FEATURES_KHR: {
+                       VkPhysicalDevice8BitStorageFeaturesKHR *features =
+                           (VkPhysicalDevice8BitStorageFeaturesKHR*)ext;
+                       bool enabled = pdevice->rad_info.chip_class >= VI;
+                       features->storageBuffer8BitAccess = enabled;
+                       features->uniformAndStorageBuffer8BitAccess = enabled;
+                       features->storagePushConstant8 = enabled;
+                       break;
+               }
+               case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FLOAT16_INT8_FEATURES_KHR: {
+                       VkPhysicalDeviceFloat16Int8FeaturesKHR *features =
+                               (VkPhysicalDeviceFloat16Int8FeaturesKHR*)ext;
+                       features->shaderFloat16 = pdevice->rad_info.chip_class >= VI && HAVE_LLVM >= 0x0800;
+                       features->shaderInt8 = true;
+                       break;
+               }
+               case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_ATOMIC_INT64_FEATURES_KHR: {
+                       VkPhysicalDeviceShaderAtomicInt64FeaturesKHR *features =
+                               (VkPhysicalDeviceShaderAtomicInt64FeaturesKHR *)ext;
+                       /* TODO: Enable this once the driver supports 64-bit
+                        * compare&swap atomic operations.
+                        */
+                       features->shaderBufferInt64Atomics = false;
+                       features->shaderSharedInt64Atomics = false;
+                       break;
+               }
+               case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INLINE_UNIFORM_BLOCK_FEATURES_EXT: {
+                       VkPhysicalDeviceInlineUniformBlockFeaturesEXT *features =
+                               (VkPhysicalDeviceInlineUniformBlockFeaturesEXT *)ext;
+
+                       features->inlineUniformBlock = true;
+                       features->descriptorBindingInlineUniformBlockUpdateAfterBind = true;
+                       break;
+               }
+               case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_COMPUTE_SHADER_DERIVATIVES_FEATURES_NV: {
+                       VkPhysicalDeviceComputeShaderDerivativesFeaturesNV *features =
+                               (VkPhysicalDeviceComputeShaderDerivativesFeaturesNV *)ext;
+                       features->computeDerivativeGroupQuads = false;
+                       features->computeDerivativeGroupLinear = true;
+                       break;
+               }
                default:
                        break;
                }
@@ -926,8 +1007,8 @@ void radv_GetPhysicalDeviceProperties(
                .maxDescriptorSetSampledImages            = max_descriptor_set_size,
                .maxDescriptorSetStorageImages            = max_descriptor_set_size,
                .maxDescriptorSetInputAttachments         = max_descriptor_set_size,
-               .maxVertexInputAttributes                 = 32,
-               .maxVertexInputBindings                   = 32,
+               .maxVertexInputAttributes                 = MAX_VERTEX_ATTRIBS,
+               .maxVertexInputBindings                   = MAX_VBS,
                .maxVertexInputAttributeOffset            = 2047,
                .maxVertexInputBindingStride              = 2048,
                .maxVertexOutputComponents                = 128,
@@ -998,7 +1079,7 @@ void radv_GetPhysicalDeviceProperties(
                .maxCullDistances                         = 8,
                .maxCombinedClipAndCullDistances          = 8,
                .discreteQueuePriorities                  = 2,
-               .pointSizeRange                           = { 0.125, 255.875 },
+               .pointSizeRange                           = { 0.0, 8192.0 },
                .lineWidthRange                           = { 0.0, 7.9921875 },
                .pointSizeGranularity                     = (1.0 / 8.0),
                .lineWidthGranularity                     = (1.0 / 128.0),
@@ -1129,7 +1210,7 @@ void radv_GetPhysicalDeviceProperties2(
 
                        /* SGPR. */
                        properties->sgprsPerSimd =
-                               radv_get_num_physical_sgprs(pdevice);
+                               ac_get_num_physical_sgprs(pdevice->rad_info.chip_class);
                        properties->minSgprAllocation =
                                pdevice->rad_info.chip_class >= VI ? 16 : 8;
                        properties->maxSgprAllocation =
@@ -1163,7 +1244,8 @@ void radv_GetPhysicalDeviceProperties2(
                        properties->robustBufferAccessUpdateAfterBind = false;
                        properties->quadDivergentImplicitLod = false;
 
-                       size_t max_descriptor_set_size = ((1ull << 31) - 16 * MAX_DYNAMIC_BUFFERS) /
+                       size_t max_descriptor_set_size = ((1ull << 31) - 16 * MAX_DYNAMIC_BUFFERS -
+                               MAX_INLINE_UNIFORM_BLOCK_SIZE * MAX_INLINE_UNIFORM_BLOCK_COUNT) /
                                  (32 /* uniform buffer, 32 due to potential space wasted on alignment */ +
                                   32 /* storage buffer, 32 due to potential space wasted on alignment */ +
                                   32 /* sampler, largest when combined with image */ +
@@ -1226,9 +1308,7 @@ void radv_GetPhysicalDeviceProperties2(
                        memset(driver_props->driverInfo, 0, VK_MAX_DRIVER_INFO_SIZE_KHR);
                        snprintf(driver_props->driverInfo, VK_MAX_DRIVER_INFO_SIZE_KHR,
                                "Mesa " PACKAGE_VERSION MESA_GIT_SHA1
-                               " (LLVM %d.%d.%d)",
-                                (HAVE_LLVM >> 8) & 0xff, HAVE_LLVM & 0xff,
-                                MESA_LLVM_VERSION_PATCH);
+                               " (LLVM " MESA_LLVM_VERSION_STRING ")");
 
                        driver_props->conformanceVersion = (VkConformanceVersionKHR) {
                                .major = 1,
@@ -1253,6 +1333,17 @@ void radv_GetPhysicalDeviceProperties2(
                        properties->transformFeedbackDraw = true;
                        break;
                }
+               case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INLINE_UNIFORM_BLOCK_PROPERTIES_EXT: {
+                       VkPhysicalDeviceInlineUniformBlockPropertiesEXT *props =
+                               (VkPhysicalDeviceInlineUniformBlockPropertiesEXT *)ext;
+
+                       props->maxInlineUniformBlockSize = MAX_INLINE_UNIFORM_BLOCK_SIZE;
+                       props->maxPerStageDescriptorInlineUniformBlocks = MAX_INLINE_UNIFORM_BLOCK_SIZE * MAX_SETS;
+                       props->maxPerStageDescriptorUpdateAfterBindInlineUniformBlocks = MAX_INLINE_UNIFORM_BLOCK_SIZE * MAX_SETS;
+                       props->maxDescriptorSetInlineUniformBlocks = MAX_INLINE_UNIFORM_BLOCK_COUNT;
+                       props->maxDescriptorSetUpdateAfterBindInlineUniformBlocks = MAX_INLINE_UNIFORM_BLOCK_COUNT;
+                       break;
+               }
                default:
                        break;
                }
@@ -1551,6 +1642,9 @@ static VkResult radv_bo_list_add(struct radv_device *device,
 {
        struct radv_bo_list *bo_list = &device->bo_list;
 
+       if (bo->is_local)
+               return VK_SUCCESS;
+
        if (unlikely(!device->use_global_bo_list))
                return VK_SUCCESS;
 
@@ -1578,6 +1672,9 @@ static void radv_bo_list_remove(struct radv_device *device,
 {
        struct radv_bo_list *bo_list = &device->bo_list;
 
+       if (bo->is_local)
+               return;
+
        if (unlikely(!device->use_global_bo_list))
                return;
 
@@ -1688,7 +1785,9 @@ VkResult radv_CreateDevice(
         * from the descriptor set anymore, so we have to use a global BO list.
         */
        device->use_global_bo_list =
-               device->enabled_extensions.EXT_descriptor_indexing;
+               (device->instance->perftest_flags & RADV_PERFTEST_BO_LIST) ||
+               device->enabled_extensions.EXT_descriptor_indexing ||
+               device->enabled_extensions.EXT_buffer_device_address;
 
        mtx_init(&device->shader_slab_mutex, mtx_plain);
        list_inithead(&device->shader_slabs);
@@ -2790,7 +2889,7 @@ VkResult radv_QueueSubmit(
        struct radeon_winsys_fence *base_fence = fence ? fence->fence : NULL;
        struct radeon_winsys_ctx *ctx = queue->hw_ctx;
        int ret;
-       uint32_t max_cs_submission = queue->device->trace_bo ? 1 : UINT32_MAX;
+       uint32_t max_cs_submission = queue->device->trace_bo ? 1 : RADV_MAX_IBS_PER_SUBMIT;
        uint32_t scratch_size = 0;
        uint32_t compute_scratch_size = 0;
        uint32_t esgs_ring_size = 0, gsvs_ring_size = 0;
@@ -3145,8 +3244,12 @@ static VkResult radv_alloc_memory(struct radv_device *device,
                if (mem_type_index == RADV_MEM_TYPE_GTT_WRITE_COMBINE)
                        flags |= RADEON_FLAG_GTT_WC;
 
-               if (!dedicate_info && !import_info && (!export_info || !export_info->handleTypes))
+               if (!dedicate_info && !import_info && (!export_info || !export_info->handleTypes)) {
                        flags |= RADEON_FLAG_NO_INTERPROCESS_SHARING;
+                       if (device->use_global_bo_list) {
+                               flags |= RADEON_FLAG_PREFER_LOCAL_BO;
+                       }
+               }
 
                mem->bo = device->ws->buffer_create(device->ws, alloc_size, device->physical_device->rad_info.max_alignment,
                                                    domain, flags, priority);
@@ -3616,7 +3719,7 @@ void radv_DestroyFence(
 }
 
 
-static uint64_t radv_get_current_time()
+uint64_t radv_get_current_time(void)
 {
        struct timespec tv;
        clock_gettime(CLOCK_MONOTONIC, &tv);
@@ -4026,6 +4129,15 @@ void radv_DestroyBuffer(
        vk_free2(&device->alloc, pAllocator, buffer);
 }
 
+VkDeviceAddress radv_GetBufferDeviceAddressEXT(
+       VkDevice                                    device,
+       const VkBufferDeviceAddressInfoEXT*         pInfo)
+{
+       RADV_FROM_HANDLE(radv_buffer, buffer, pInfo->buffer);
+       return radv_buffer_get_va(buffer->bo) + buffer->offset;
+}
+
+
 static inline unsigned
 si_tile_mode_index(const struct radv_image *image, unsigned level, bool stencil)
 {