radv: init the trace BO before compiling meta shaders
[mesa.git] / src / amd / vulkan / radv_device.c
index 7c218b14783eb8b691c675b30a0b6f0097f1fd5b..28a941e219c3c1b11a1c5e2d9d04271f8b54c3cd 100644 (file)
@@ -31,6 +31,7 @@
 #include <fcntl.h>
 #include "radv_debug.h"
 #include "radv_private.h"
+#include "radv_shader.h"
 #include "radv_cs.h"
 #include "util/disk_cache.h"
 #include "util/strtod.h"
@@ -169,7 +170,23 @@ static const VkExtensionProperties common_device_extensions[] = {
                .extensionName = VK_KHR_VARIABLE_POINTERS_EXTENSION_NAME,
                .specVersion = 1,
        },
+       {
+               .extensionName = VK_KHR_IMAGE_FORMAT_LIST_EXTENSION_NAME,
+               .specVersion = 1,
+       },
+       {
+               .extensionName = VK_KHR_BIND_MEMORY_2_EXTENSION_NAME,
+               .specVersion = 1,
+       },
+};
+
+static const VkExtensionProperties rasterization_order_extension[] ={
+       {
+               .extensionName = VK_AMD_RASTERIZATION_ORDER_EXTENSION_NAME,
+               .specVersion = 1,
+       },
 };
+
 static const VkExtensionProperties ext_sema_device_extensions[] = {
        {
                .extensionName = VK_KHR_EXTERNAL_SEMAPHORE_EXTENSION_NAME,
@@ -334,6 +351,15 @@ radv_physical_device_init(struct radv_physical_device *device,
        if (result != VK_SUCCESS)
                goto fail;
 
+       if (device->rad_info.chip_class >= VI && device->rad_info.max_se >= 2) {
+               result = radv_extensions_register(instance,
+                                               &device->extensions,
+                                               rasterization_order_extension,
+                                               ARRAY_SIZE(rasterization_order_extension));
+               if (result != VK_SUCCESS)
+                       goto fail;
+       }
+
        if (device->rad_info.has_syncobj) {
                result = radv_extensions_register(instance,
                                                  &device->extensions,
@@ -410,15 +436,32 @@ static const struct debug_control radv_debug_options[] = {
        {"allbos", RADV_DEBUG_ALL_BOS},
        {"noibs", RADV_DEBUG_NO_IBS},
        {"spirv", RADV_DEBUG_DUMP_SPIRV},
+       {"vmfaults", RADV_DEBUG_VM_FAULTS},
+       {"zerovram", RADV_DEBUG_ZERO_VRAM},
+       {"syncshaders", RADV_DEBUG_SYNC_SHADERS},
        {NULL, 0}
 };
 
+const char *
+radv_get_debug_option_name(int id)
+{
+       assert(id < ARRAY_SIZE(radv_debug_options) - 1);
+       return radv_debug_options[id].string;
+}
+
 static const struct debug_control radv_perftest_options[] = {
        {"nobatchchain", RADV_PERFTEST_NO_BATCHCHAIN},
        {"sisched", RADV_PERFTEST_SISCHED},
        {NULL, 0}
 };
 
+const char *
+radv_get_perftest_option_name(int id)
+{
+       assert(id < ARRAY_SIZE(radv_debug_options) - 1);
+       return radv_perftest_options[id].string;
+}
+
 VkResult radv_CreateInstance(
        const VkInstanceCreateInfo*                 pCreateInfo,
        const VkAllocationCallbacks*                pAllocator,
@@ -521,7 +564,7 @@ radv_enumerate_devices(struct radv_instance *instance)
        for (unsigned i = 0; i < (unsigned)max_devices; i++) {
                if (devices[i]->available_nodes & 1 << DRM_NODE_RENDER &&
                    devices[i]->bustype == DRM_BUS_PCI &&
-                   devices[i]->deviceinfo.pci->vendor_id == 0x1002) {
+                   devices[i]->deviceinfo.pci->vendor_id == ATI_VENDOR_ID) {
 
                        result = radv_physical_device_init(instance->physicalDevices +
                                                           instance->physicalDeviceCount,
@@ -784,7 +827,7 @@ void radv_GetPhysicalDeviceProperties(
        *pProperties = (VkPhysicalDeviceProperties) {
                .apiVersion = VK_MAKE_VERSION(1, 0, 42),
                .driverVersion = vk_get_driver_version(),
-               .vendorID = 0x1002,
+               .vendorID = ATI_VENDOR_ID,
                .deviceID = pdevice->rad_info.pci_id,
                .deviceType = pdevice->rad_info.has_dedicated_vram ? VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU : VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU,
                .limits = limits,
@@ -1160,6 +1203,11 @@ VkResult radv_CreateDevice(
                device->physical_device->rad_info.chip_class >= VI &&
                device->physical_device->rad_info.max_se >= 2;
 
+       if (getenv("RADV_TRACE_FILE")) {
+               if (!radv_init_trace(device))
+                       goto fail;
+       }
+
        result = radv_device_init_meta(device);
        if (result != VK_SUCCESS)
                goto fail;
@@ -1182,11 +1230,6 @@ VkResult radv_CreateDevice(
                device->ws->cs_finalize(device->empty_cs[family]);
        }
 
-       if (getenv("RADV_TRACE_FILE")) {
-               if (!radv_init_trace(device))
-                       goto fail;
-       }
-
        if (device->physical_device->rad_info.chip_class >= CIK)
                cik_create_gfx_config(device);
 
@@ -1355,13 +1398,13 @@ fill_geom_tess_rings(struct radv_queue *queue,
        uint32_t *desc = &map[4];
 
        if (esgs_ring_bo)
-               esgs_va = queue->device->ws->buffer_get_va(esgs_ring_bo);
+               esgs_va = radv_buffer_get_va(esgs_ring_bo);
        if (gsvs_ring_bo)
-               gsvs_va = queue->device->ws->buffer_get_va(gsvs_ring_bo);
+               gsvs_va = radv_buffer_get_va(gsvs_ring_bo);
        if (tess_factor_ring_bo)
-               tess_factor_va = queue->device->ws->buffer_get_va(tess_factor_ring_bo);
+               tess_factor_va = radv_buffer_get_va(tess_factor_ring_bo);
        if (tess_offchip_ring_bo)
-               tess_offchip_va = queue->device->ws->buffer_get_va(tess_offchip_ring_bo);
+               tess_offchip_va = radv_buffer_get_va(tess_offchip_ring_bo);
 
        /* stride 0, num records - size, add tid, swizzle, elsize4,
           index stride 64 */
@@ -1708,7 +1751,7 @@ radv_get_preamble_cs(struct radv_queue *queue,
                        uint32_t *map = (uint32_t*)queue->device->ws->buffer_map(descriptor_bo);
 
                        if (scratch_bo) {
-                               uint64_t scratch_va = queue->device->ws->buffer_get_va(scratch_bo);
+                               uint64_t scratch_va = radv_buffer_get_va(scratch_bo);
                                uint32_t rsrc1 = S_008F04_BASE_ADDRESS_HI(scratch_va >> 32) |
                                                 S_008F04_SWIZZLE_ENABLE(1);
                                map[0] = scratch_va;
@@ -1746,7 +1789,7 @@ radv_get_preamble_cs(struct radv_queue *queue,
                }
 
                if (tess_factor_ring_bo) {
-                       uint64_t tf_va = queue->device->ws->buffer_get_va(tess_factor_ring_bo);
+                       uint64_t tf_va = radv_buffer_get_va(tess_factor_ring_bo);
                        if (queue->device->physical_device->rad_info.chip_class >= CIK) {
                                radeon_set_uconfig_reg(cs, R_030938_VGT_TF_RING_SIZE,
                                                       S_030938_SIZE(tess_factor_ring_size / 4));
@@ -1775,7 +1818,7 @@ radv_get_preamble_cs(struct radv_queue *queue,
                                           R_00B430_SPI_SHADER_USER_DATA_HS_0,
                                           R_00B530_SPI_SHADER_USER_DATA_LS_0};
 
-                       uint64_t va = queue->device->ws->buffer_get_va(descriptor_bo);
+                       uint64_t va = radv_buffer_get_va(descriptor_bo);
 
                        for (int i = 0; i < ARRAY_SIZE(regs); ++i) {
                                radeon_set_sh_reg_seq(cs, regs[i], 2);
@@ -1785,7 +1828,7 @@ radv_get_preamble_cs(struct radv_queue *queue,
                }
 
                if (compute_scratch_bo) {
-                       uint64_t scratch_va = queue->device->ws->buffer_get_va(compute_scratch_bo);
+                       uint64_t scratch_va = radv_buffer_get_va(compute_scratch_bo);
                        uint32_t rsrc1 = S_008F04_BASE_ADDRESS_HI(scratch_va >> 32) |
                                         S_008F04_SWIZZLE_ENABLE(1);
 
@@ -2459,44 +2502,74 @@ void radv_GetDeviceMemoryCommitment(
        *pCommittedMemoryInBytes = 0;
 }
 
+VkResult radv_BindBufferMemory2KHR(VkDevice device,
+                                   uint32_t bindInfoCount,
+                                   const VkBindBufferMemoryInfoKHR *pBindInfos)
+{
+       for (uint32_t i = 0; i < bindInfoCount; ++i) {
+               RADV_FROM_HANDLE(radv_device_memory, mem, pBindInfos[i].memory);
+               RADV_FROM_HANDLE(radv_buffer, buffer, pBindInfos[i].buffer);
+
+               if (mem) {
+                       buffer->bo = mem->bo;
+                       buffer->offset = pBindInfos[i].memoryOffset;
+               } else {
+                       buffer->bo = NULL;
+               }
+       }
+       return VK_SUCCESS;
+}
+
 VkResult radv_BindBufferMemory(
        VkDevice                                    device,
-       VkBuffer                                    _buffer,
-       VkDeviceMemory                              _memory,
+       VkBuffer                                    buffer,
+       VkDeviceMemory                              memory,
        VkDeviceSize                                memoryOffset)
 {
-       RADV_FROM_HANDLE(radv_device_memory, mem, _memory);
-       RADV_FROM_HANDLE(radv_buffer, buffer, _buffer);
+       const VkBindBufferMemoryInfoKHR info = {
+               .sType = VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO_KHR,
+               .buffer = buffer,
+               .memory = memory,
+               .memoryOffset = memoryOffset
+       };
 
-       if (mem) {
-               buffer->bo = mem->bo;
-               buffer->offset = memoryOffset;
-       } else {
-               buffer->bo = NULL;
-               buffer->offset = 0;
-       }
+       return radv_BindBufferMemory2KHR(device, 1, &info);
+}
+
+VkResult radv_BindImageMemory2KHR(VkDevice device,
+                                  uint32_t bindInfoCount,
+                                  const VkBindImageMemoryInfoKHR *pBindInfos)
+{
+       for (uint32_t i = 0; i < bindInfoCount; ++i) {
+               RADV_FROM_HANDLE(radv_device_memory, mem, pBindInfos[i].memory);
+               RADV_FROM_HANDLE(radv_image, image, pBindInfos[i].image);
 
+               if (mem) {
+                       image->bo = mem->bo;
+                       image->offset = pBindInfos[i].memoryOffset;
+               } else {
+                       image->bo = NULL;
+                       image->offset = 0;
+               }
+       }
        return VK_SUCCESS;
 }
 
+
 VkResult radv_BindImageMemory(
        VkDevice                                    device,
-       VkImage                                     _image,
-       VkDeviceMemory                              _memory,
+       VkImage                                     image,
+       VkDeviceMemory                              memory,
        VkDeviceSize                                memoryOffset)
 {
-       RADV_FROM_HANDLE(radv_device_memory, mem, _memory);
-       RADV_FROM_HANDLE(radv_image, image, _image);
-
-       if (mem) {
-               image->bo = mem->bo;
-               image->offset = memoryOffset;
-       } else {
-               image->bo = NULL;
-               image->offset = 0;
-       }
+       const VkBindImageMemoryInfoKHR info = {
+               .sType = VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO_KHR,
+               .image = image,
+               .memory = memory,
+               .memoryOffset = memoryOffset
+       };
 
-       return VK_SUCCESS;
+       return radv_BindImageMemory2KHR(device, 1, &info);
 }
 
 
@@ -2789,7 +2862,7 @@ VkResult radv_CreateEvent(
 
        event->bo = device->ws->buffer_create(device->ws, 8, 8,
                                              RADEON_DOMAIN_GTT,
-                                             RADEON_FLAG_CPU_ACCESS);
+                                             RADEON_FLAG_VA_UNCACHED | RADEON_FLAG_CPU_ACCESS);
        if (!event->bo) {
                vk_free2(&device->alloc, pAllocator, event);
                return VK_ERROR_OUT_OF_DEVICE_MEMORY;
@@ -2933,7 +3006,7 @@ radv_initialise_color_surface(struct radv_device *device,
        /* Intensity is implemented as Red, so treat it that way. */
        cb->cb_color_attrib = S_028C74_FORCE_DST_ALPHA_1(desc->swizzle[3] == VK_SWIZZLE_1);
 
-       va = device->ws->buffer_get_va(iview->bo) + iview->image->offset;
+       va = radv_buffer_get_va(iview->bo) + iview->image->offset;
 
        cb->cb_color_base = va >> 8;
 
@@ -2985,11 +3058,11 @@ radv_initialise_color_surface(struct radv_device *device,
        }
 
        /* CMASK variables */
-       va = device->ws->buffer_get_va(iview->bo) + iview->image->offset;
+       va = radv_buffer_get_va(iview->bo) + iview->image->offset;
        va += iview->image->cmask.offset;
        cb->cb_color_cmask = va >> 8;
 
-       va = device->ws->buffer_get_va(iview->bo) + iview->image->offset;
+       va = radv_buffer_get_va(iview->bo) + iview->image->offset;
        va += iview->image->dcc_offset;
        cb->cb_dcc_base = va >> 8;
        cb->cb_dcc_base |= iview->image->surface.tile_swizzle;
@@ -3006,7 +3079,7 @@ radv_initialise_color_surface(struct radv_device *device,
        }
 
        if (iview->image->fmask.size) {
-               va = device->ws->buffer_get_va(iview->bo) + iview->image->offset + iview->image->fmask.offset;
+               va = radv_buffer_get_va(iview->bo) + iview->image->offset + iview->image->fmask.offset;
                cb->cb_color_fmask = va >> 8;
                cb->cb_color_fmask |= iview->image->fmask.tile_swizzle;
        } else {
@@ -3091,8 +3164,8 @@ radv_initialise_color_surface(struct radv_device *device,
        }
 
        if (device->physical_device->rad_info.chip_class >= GFX9) {
-               uint32_t max_slice = radv_surface_layer_count(iview);
-               unsigned mip0_depth = iview->base_layer + max_slice - 1;
+               unsigned mip0_depth = iview->image->type == VK_IMAGE_TYPE_3D ?
+                 (iview->extent.depth - 1) : (iview->image->info.array_size - 1);
 
                cb->cb_color_view |= S_028C6C_MIP_LEVEL(iview->base_mip);
                cb->cb_color_attrib |= S_028C74_MIP0_DEPTH(mip0_depth) |
@@ -3141,7 +3214,7 @@ radv_initialise_ds_surface(struct radv_device *device,
        }
 
        format = radv_translate_dbformat(iview->image->vk_format);
-       stencil_format = iview->image->surface.flags & RADEON_SURF_SBUFFER ?
+       stencil_format = iview->image->surface.has_stencil ?
                V_028044_STENCIL_8 : V_028044_STENCIL_INVALID;
 
        uint32_t max_slice = radv_surface_layer_count(iview);
@@ -3151,7 +3224,7 @@ radv_initialise_ds_surface(struct radv_device *device,
        ds->db_htile_data_base = 0;
        ds->db_htile_surface = 0;
 
-       va = device->ws->buffer_get_va(iview->bo) + iview->image->offset;
+       va = radv_buffer_get_va(iview->bo) + iview->image->offset;
        s_offs = z_offs = va;
 
        if (device->physical_device->rad_info.chip_class >= GFX9) {
@@ -3176,10 +3249,10 @@ radv_initialise_ds_surface(struct radv_device *device,
                if (iview->image->surface.htile_size && !level) {
                        ds->db_z_info |= S_028038_TILE_SURFACE_ENABLE(1);
 
-                       if (!(iview->image->surface.flags & RADEON_SURF_SBUFFER))
+                       if (!iview->image->surface.has_stencil)
                                /* Use all of the htile_buffer for depth if there's no stencil. */
                                ds->db_stencil_info |= S_02803C_TILE_STENCIL_DISABLE(1);
-                       va = device->ws->buffer_get_va(iview->bo) + iview->image->offset +
+                       va = radv_buffer_get_va(iview->bo) + iview->image->offset +
                                iview->image->htile_offset;
                        ds->db_htile_data_base = va >> 8;
                        ds->db_htile_surface = S_028ABC_FULL_CACHE(1) |
@@ -3239,11 +3312,11 @@ radv_initialise_ds_surface(struct radv_device *device,
                if (iview->image->surface.htile_size && !level) {
                        ds->db_z_info |= S_028040_TILE_SURFACE_ENABLE(1);
 
-                       if (!(iview->image->surface.flags & RADEON_SURF_SBUFFER))
+                       if (!iview->image->surface.has_stencil)
                                /* Use all of the htile_buffer for depth if there's no stencil. */
                                ds->db_stencil_info |= S_028044_TILE_STENCIL_DISABLE(1);
 
-                       va = device->ws->buffer_get_va(iview->bo) + iview->image->offset +
+                       va = radv_buffer_get_va(iview->bo) + iview->image->offset +
                                iview->image->htile_offset;
                        ds->db_htile_data_base = va >> 8;
                        ds->db_htile_surface = S_028ABC_FULL_CACHE(1);