vulkan: add vk_x11_strict_image_count option
[mesa.git] / src / amd / vulkan / radv_device.c
index 4aafe6e78aa0c389a3de4d43d96703eb61479cf7..bdc38a555dedd44fc753211db19532c57c9576d9 100644 (file)
@@ -29,6 +29,7 @@
 #include <string.h>
 #include <unistd.h>
 #include <fcntl.h>
+#include <llvm/Config/llvm-config.h>
 #include "radv_debug.h"
 #include "radv_private.h"
 #include "radv_shader.h"
@@ -173,12 +174,11 @@ radv_physical_device_init_mem_types(struct radv_physical_device *device)
                        .heapIndex = vram_index,
                };
        }
-       if (gart_index >= 0) {
+       if (gart_index >= 0 && device->rad_info.has_dedicated_vram) {
                device->mem_type_indices[type_count] = RADV_MEM_TYPE_GTT_WRITE_COMBINE;
                device->memory_properties.memoryTypes[type_count++] = (VkMemoryType) {
                        .propertyFlags = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
-                       VK_MEMORY_PROPERTY_HOST_COHERENT_BIT |
-                       (device->rad_info.has_dedicated_vram ? 0 : VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT),
+                       VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
                        .heapIndex = gart_index,
                };
        }
@@ -191,6 +191,19 @@ radv_physical_device_init_mem_types(struct radv_physical_device *device)
                        .heapIndex = visible_vram_index,
                };
        }
+       if (gart_index >= 0 && !device->rad_info.has_dedicated_vram) {
+               /* Put GTT after visible VRAM for GPUs without dedicated VRAM
+                * as they have identical property flags, and according to the
+                * spec, for types with identical flags, the one with greater
+                * performance must be given a lower index. */
+               device->mem_type_indices[type_count] = RADV_MEM_TYPE_GTT_WRITE_COMBINE;
+               device->memory_properties.memoryTypes[type_count++] = (VkMemoryType) {
+                       .propertyFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
+                       VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
+                       VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
+                       .heapIndex = gart_index,
+               };
+       }
        if (gart_index >= 0) {
                device->mem_type_indices[type_count] = RADV_MEM_TYPE_GTT_CACHED;
                device->memory_properties.memoryTypes[type_count++] = (VkMemoryType) {
@@ -342,47 +355,12 @@ radv_physical_device_init(struct radv_physical_device *device,
        radv_get_driver_uuid(&device->driver_uuid);
        radv_get_device_uuid(&device->rad_info, &device->device_uuid);
 
-       if (device->rad_info.family == CHIP_STONEY ||
-           device->rad_info.chip_class >= GFX9) {
-               device->has_rbplus = true;
-               device->rbplus_allowed = device->rad_info.family == CHIP_STONEY ||
-                                        device->rad_info.family == CHIP_VEGA12 ||
-                                        device->rad_info.family == CHIP_RAVEN ||
-                                        device->rad_info.family == CHIP_RAVEN2 ||
-                                        device->rad_info.family == CHIP_RENOIR;
-       }
-
-       /* The mere presence of CLEAR_STATE in the IB causes random GPU hangs
-        * on GFX6.
-        */
-       device->has_clear_state = device->rad_info.chip_class >= GFX7;
-
-       device->cpdma_prefetch_writes_memory = device->rad_info.chip_class <= GFX8;
-
-       /* Vega10/Raven need a special workaround for a hardware bug. */
-       device->has_scissor_bug = device->rad_info.family == CHIP_VEGA10 ||
-                                 device->rad_info.family == CHIP_RAVEN;
-
-       device->has_tc_compat_zrange_bug = device->rad_info.chip_class < GFX10;
-
-       /* Out-of-order primitive rasterization. */
-       device->has_out_of_order_rast = device->rad_info.chip_class >= GFX8 &&
-                                       device->rad_info.max_se >= 2;
-       device->out_of_order_rast_allowed = device->has_out_of_order_rast &&
+       device->out_of_order_rast_allowed = device->rad_info.has_out_of_order_rast &&
                                            !(device->instance->debug_flags & RADV_DEBUG_NO_OUT_OF_ORDER);
 
        device->dcc_msaa_allowed =
                (device->instance->perftest_flags & RADV_PERFTEST_DCC_MSAA);
 
-       /* TODO: Figure out how to use LOAD_CONTEXT_REG on GFX6-GFX7. */
-       device->has_load_ctx_reg_pkt = device->rad_info.chip_class >= GFX9 ||
-                                      (device->rad_info.chip_class >= GFX8 &&
-                                       device->rad_info.me_fw_feature >= 41);
-
-       device->has_dcc_constant_encode = device->rad_info.family == CHIP_RAVEN2 ||
-                                         device->rad_info.family == CHIP_RENOIR ||
-                                         device->rad_info.chip_class >= GFX10;
-
        device->use_shader_ballot = device->rad_info.chip_class >= GFX8 &&
                                    device->instance->perftest_flags & RADV_PERFTEST_SHADER_BALLOT;
 
@@ -496,6 +474,8 @@ static const struct debug_control radv_debug_options[] = {
        {"nobinning", RADV_DEBUG_NOBINNING},
        {"noloadstoreopt", RADV_DEBUG_NO_LOAD_STORE_OPT},
        {"nongg", RADV_DEBUG_NO_NGG},
+       {"noshaderballot", RADV_DEBUG_NO_SHADER_BALLOT},
+       {"allentrypoints", RADV_DEBUG_ALL_ENTRYPOINTS},
        {NULL, 0}
 };
 
@@ -552,8 +532,16 @@ radv_handle_per_app_options(struct radv_instance *instance,
                 * load/store memory operations.
                 * See https://reviews.llvm.org/D61313
                 */
-               if (HAVE_LLVM < 0x900)
+               if (LLVM_VERSION_MAJOR < 9)
                        instance->debug_flags |= RADV_DEBUG_NO_LOAD_STORE_OPT;
+       } else if (!strcmp(name, "Wolfenstein: Youngblood")) {
+               if (!(instance->debug_flags & RADV_DEBUG_NO_SHADER_BALLOT)) {
+                       /* Force enable VK_AMD_shader_ballot because it looks
+                        * safe and it gives a nice boost (+20% on Vega 56 at
+                        * this time).
+                        */
+                       instance->perftest_flags |= RADV_PERFTEST_SHADER_BALLOT;
+               }
        }
 }
 
@@ -568,8 +556,10 @@ static int radv_get_instance_extension_index(const char *name)
 
 static const char radv_dri_options_xml[] =
 DRI_CONF_BEGIN
-       DRI_CONF_SECTION_QUALITY
+       DRI_CONF_SECTION_PERFORMANCE
                DRI_CONF_ADAPTIVE_SYNC("true")
+               DRI_CONF_VK_X11_OVERRIDE_MIN_IMAGE_COUNT(0)
+               DRI_CONF_VK_X11_STRICT_IMAGE_COUNT("false")
        DRI_CONF_SECTION_END
 DRI_CONF_END;
 
@@ -578,7 +568,9 @@ 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);
+                           0, "radv", NULL,
+                           instance->engineName,
+                           instance->engineVersion);
 }
 
 VkResult radv_CreateInstance(
@@ -599,6 +591,13 @@ VkResult radv_CreateInstance(
                client_version = VK_API_VERSION_1_0;
        }
 
+       const char *engine_name = NULL;
+       uint32_t engine_version = 0;
+       if (pCreateInfo->pApplicationInfo) {
+               engine_name = pCreateInfo->pApplicationInfo->pEngineName;
+               engine_version = pCreateInfo->pApplicationInfo->engineVersion;
+       }
+
        instance = vk_zalloc2(&default_alloc, pAllocator, sizeof(*instance), 8,
                              VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
        if (!instance)
@@ -642,6 +641,10 @@ VkResult radv_CreateInstance(
                return vk_error(instance, result);
        }
 
+       instance->engineName = vk_strdup(&instance->alloc, engine_name,
+                                        VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
+       instance->engineVersion = engine_version;
+
        _mesa_locale_init();
        glsl_type_singleton_init_or_ref();
 
@@ -668,6 +671,8 @@ void radv_DestroyInstance(
                radv_physical_device_finish(instance->physicalDevices + i);
        }
 
+       vk_free(&instance->alloc, instance->engineName);
+
        VG(VALGRIND_DESTROY_MEMPOOL(instance));
 
        glsl_type_singleton_decref();
@@ -870,7 +875,7 @@ void radv_GetPhysicalDeviceFeatures2(
                        features->storageBuffer16BitAccess = enabled;
                        features->uniformAndStorageBuffer16BitAccess = enabled;
                        features->storagePushConstant16 = enabled;
-                       features->storageInputOutput16 = enabled && HAVE_LLVM >= 0x900;
+                       features->storageInputOutput16 = enabled && LLVM_VERSION_MAJOR >= 9;
                        break;
                }
                case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_YCBCR_CONVERSION_FEATURES: {
@@ -969,15 +974,15 @@ void radv_GetPhysicalDeviceFeatures2(
                case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FLOAT16_INT8_FEATURES_KHR: {
                        VkPhysicalDeviceFloat16Int8FeaturesKHR *features =
                                (VkPhysicalDeviceFloat16Int8FeaturesKHR*)ext;
-                       features->shaderFloat16 = pdevice->rad_info.chip_class >= GFX8 && HAVE_LLVM >= 0x0800;
+                       features->shaderFloat16 = pdevice->rad_info.chip_class >= GFX8;
                        features->shaderInt8 = true;
                        break;
                }
                case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_ATOMIC_INT64_FEATURES_KHR: {
                        VkPhysicalDeviceShaderAtomicInt64FeaturesKHR *features =
                                (VkPhysicalDeviceShaderAtomicInt64FeaturesKHR *)ext;
-                       features->shaderBufferInt64Atomics = HAVE_LLVM >= 0x0900;
-                       features->shaderSharedInt64Atomics = HAVE_LLVM >= 0x0900;
+                       features->shaderBufferInt64Atomics = LLVM_VERSION_MAJOR >= 9;
+                       features->shaderSharedInt64Atomics = LLVM_VERSION_MAJOR >= 9;
                        break;
                }
                case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INLINE_UNIFORM_BLOCK_FEATURES_EXT: {
@@ -1285,7 +1290,7 @@ void radv_GetPhysicalDeviceProperties2(
 
                        /* SGPR. */
                        properties->sgprsPerSimd =
-                               ac_get_num_physical_sgprs(pdevice->rad_info.chip_class);
+                               ac_get_num_physical_sgprs(&pdevice->rad_info);
                        properties->minSgprAllocation =
                                pdevice->rad_info.chip_class >= GFX8 ? 16 : 8;
                        properties->maxSgprAllocation =
@@ -1301,6 +1306,15 @@ void radv_GetPhysicalDeviceProperties2(
                        properties->vgprAllocationGranularity = 4;
                        break;
                }
+               case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_CORE_PROPERTIES_2_AMD: {
+                       VkPhysicalDeviceShaderCoreProperties2AMD *properties =
+                               (VkPhysicalDeviceShaderCoreProperties2AMD *)ext;
+
+                       properties->shaderCoreFeatures = 0;
+                       properties->activeComputeUnitCount =
+                               pdevice->rad_info.num_good_compute_units;
+                       break;
+               }
                case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VERTEX_ATTRIBUTE_DIVISOR_PROPERTIES_EXT: {
                        VkPhysicalDeviceVertexAttributeDivisorPropertiesEXT *properties =
                                (VkPhysicalDeviceVertexAttributeDivisorPropertiesEXT *)ext;
@@ -1979,9 +1993,6 @@ VkResult radv_CreateDevice(
 
        device->tess_offchip_block_dw_size =
                device->physical_device->rad_info.family == CHIP_HAWAII ? 4096 : 8192;
-       device->has_distributed_tess =
-               device->physical_device->rad_info.chip_class >= GFX8 &&
-               device->physical_device->rad_info.max_se >= 2;
 
        if (getenv("RADV_TRACE_FILE")) {
                const char *filename = getenv("RADV_TRACE_FILE");
@@ -3253,11 +3264,16 @@ PFN_vkVoidFunction radv_GetInstanceProcAddr(
        const char*                                 pName)
 {
        RADV_FROM_HANDLE(radv_instance, instance, _instance);
+       bool unchecked = instance ? instance->debug_flags & RADV_DEBUG_ALL_ENTRYPOINTS : false;
 
-       return radv_lookup_entrypoint_checked(pName,
-                                             instance ? instance->apiVersion : 0,
-                                             instance ? &instance->enabled_extensions : NULL,
-                                             NULL);
+       if (unchecked) {
+               return radv_lookup_entrypoint_unchecked(pName);
+       } else {
+               return radv_lookup_entrypoint_checked(pName,
+                                                     instance ? instance->apiVersion : 0,
+                                                     instance ? &instance->enabled_extensions : NULL,
+                                                     NULL);
+       }
 }
 
 /* The loader wants us to expose a second GetInstanceProcAddr function
@@ -3298,11 +3314,16 @@ PFN_vkVoidFunction radv_GetDeviceProcAddr(
        const char*                                 pName)
 {
        RADV_FROM_HANDLE(radv_device, device, _device);
+       bool unchecked = device ? device->instance->debug_flags & RADV_DEBUG_ALL_ENTRYPOINTS : false;
 
-       return radv_lookup_entrypoint_checked(pName,
-                                             device->instance->apiVersion,
-                                             &device->instance->enabled_extensions,
-                                             &device->enabled_extensions);
+       if (unchecked) {
+               return radv_lookup_entrypoint_unchecked(pName);
+       } else {
+               return radv_lookup_entrypoint_checked(pName,
+                                                     device->instance->apiVersion,
+                                                     &device->instance->enabled_extensions,
+                                                     &device->enabled_extensions);
+       }
 }
 
 bool radv_get_memory_fd(struct radv_device *device,