radv/vulkan: Move radv_get_driver_version to src/vulkan/util
[mesa.git] / src / amd / vulkan / radv_device.c
index 8defb736b2c50c56ebe615828f960c653ca12a4e..5fdb894146cb1d3347248765ea20c7ccaba391dd 100644 (file)
@@ -33,7 +33,7 @@
 #include "radv_cs.h"
 #include "util/disk_cache.h"
 #include "util/strtod.h"
-#include "util/vk_util.h"
+#include "vk_util.h"
 #include <xf86drm.h>
 #include <amdgpu.h>
 #include <amdgpu_drm.h>
@@ -304,6 +304,12 @@ radv_physical_device_init(struct radv_physical_device *device,
 
        radv_get_device_uuid(drm_device, 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;
+       }
+
        return VK_SUCCESS;
 
 fail:
@@ -508,8 +514,8 @@ void radv_GetPhysicalDeviceFeatures(
        VkPhysicalDevice                            physicalDevice,
        VkPhysicalDeviceFeatures*                   pFeatures)
 {
-       //   RADV_FROM_HANDLE(radv_physical_device, pdevice, physicalDevice);
-
+       RADV_FROM_HANDLE(radv_physical_device, pdevice, physicalDevice);
+       bool is_gfx9 = pdevice->rad_info.chip_class >= GFX9;
        memset(pFeatures, 0, sizeof(*pFeatures));
 
        *pFeatures = (VkPhysicalDeviceFeatures) {
@@ -517,8 +523,8 @@ void radv_GetPhysicalDeviceFeatures(
                .fullDrawIndexUint32                      = true,
                .imageCubeArray                           = true,
                .independentBlend                         = true,
-               .geometryShader                           = true,
-               .tessellationShader                       = true,
+               .geometryShader                           = !is_gfx9,
+               .tessellationShader                       = !is_gfx9,
                .sampleRateShading                        = false,
                .dualSrcBlend                             = true,
                .logicOp                                  = true,
@@ -568,28 +574,6 @@ void radv_GetPhysicalDeviceFeatures2KHR(
        return radv_GetPhysicalDeviceFeatures(physicalDevice, &pFeatures->features);
 }
 
-static uint32_t radv_get_driver_version()
-{
-       const char *minor_string = strchr(VERSION, '.');
-       const char *patch_string = minor_string ? strchr(minor_string + 1, ','): NULL;
-       int major = atoi(VERSION);
-       int minor = minor_string ? atoi(minor_string + 1) : 0;
-       int patch = patch_string ? atoi(patch_string + 1) : 0;
-       if (strstr(VERSION, "devel")) {
-               if (patch == 0) {
-                       patch = 99;
-                       if (minor == 0) {
-                               minor = 99;
-                               --major;
-                       } else
-                               --minor;
-               } else
-                       --patch;
-       }
-       uint32_t version = VK_MAKE_VERSION(major, minor, patch);
-       return version;
-}
-
 void radv_GetPhysicalDeviceProperties(
        VkPhysicalDevice                            physicalDevice,
        VkPhysicalDeviceProperties*                 pProperties)
@@ -725,10 +709,10 @@ void radv_GetPhysicalDeviceProperties(
 
        *pProperties = (VkPhysicalDeviceProperties) {
                .apiVersion = VK_MAKE_VERSION(1, 0, 42),
-               .driverVersion = radv_get_driver_version(),
+               .driverVersion = vk_get_driver_version(),
                .vendorID = 0x1002,
                .deviceID = pdevice->rad_info.pci_id,
-               .deviceType = VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU,
+               .deviceType = pdevice->rad_info.has_dedicated_vram ? VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU : VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU,
                .limits = limits,
                .sparseProperties = {0},
        };
@@ -1103,6 +1087,7 @@ VkResult radv_CreateDevice(
                case RADV_QUEUE_COMPUTE:
                        si_cs_emit_cache_flush(device->flush_cs[family],
                                               device->physical_device->rad_info.chip_class,
+                                              NULL, 0,
                                               family == RADV_QUEUE_COMPUTE && device->physical_device->rad_info.chip_class >= CIK,
                                               RADV_CMD_FLAG_INV_ICACHE |
                                               RADV_CMD_FLAG_INV_SMEM_L1 |
@@ -1118,6 +1103,7 @@ VkResult radv_CreateDevice(
                case RADV_QUEUE_COMPUTE:
                        si_cs_emit_cache_flush(device->flush_shader_cs[family],
                                               device->physical_device->rad_info.chip_class,
+                                              NULL, 0,
                                               family == RADV_QUEUE_COMPUTE && device->physical_device->rad_info.chip_class >= CIK,
                                               family == RADV_QUEUE_COMPUTE ? RADV_CMD_FLAG_CS_PARTIAL_FLUSH : (RADV_CMD_FLAG_CS_PARTIAL_FLUSH | RADV_CMD_FLAG_PS_PARTIAL_FLUSH) |
                                               RADV_CMD_FLAG_INV_ICACHE |
@@ -1720,6 +1706,10 @@ radv_get_preamble_cs(struct radv_queue *queue,
                                                       S_030938_SIZE(tess_factor_ring_size / 4));
                                radeon_set_uconfig_reg(cs, R_030940_VGT_TF_MEMORY_BASE,
                                                       tf_va >> 8);
+                               if (queue->device->physical_device->rad_info.chip_class >= GFX9) {
+                                       radeon_set_uconfig_reg(cs, R_030944_VGT_TF_MEMORY_BASE_HI,
+                                                              tf_va >> 40);
+                               }
                                radeon_set_uconfig_reg(cs, R_03093C_VGT_HS_OFFCHIP_PARAM, hs_offchip_param);
                        } else {
                                radeon_set_config_reg(cs, R_008988_VGT_TF_RING_SIZE,
@@ -1763,6 +1753,7 @@ radv_get_preamble_cs(struct radv_queue *queue,
                if (!i) {
                        si_cs_emit_cache_flush(cs,
                                               queue->device->physical_device->rad_info.chip_class,
+                                              NULL, 0,
                                               queue->queue_family_index == RING_COMPUTE &&
                                                 queue->device->physical_device->rad_info.chip_class >= CIK,
                                               RADV_CMD_FLAG_INV_ICACHE |
@@ -2913,7 +2904,39 @@ radv_initialise_ds_surface(struct radv_device *device,
        va = device->ws->buffer_get_va(iview->bo) + iview->image->offset;
        s_offs = z_offs = va;
 
-       {
+       if (device->physical_device->rad_info.chip_class >= GFX9) {
+               assert(iview->image->surface.u.gfx9.surf_offset == 0);
+               s_offs += iview->image->surface.u.gfx9.stencil_offset;
+
+               ds->db_z_info = S_028038_FORMAT(format) |
+                       S_028038_NUM_SAMPLES(util_logbase2(iview->image->info.samples)) |
+                       S_028038_SW_MODE(iview->image->surface.u.gfx9.surf.swizzle_mode) |
+                       S_028038_MAXMIP(iview->image->info.levels - 1);
+               ds->db_stencil_info = S_02803C_FORMAT(stencil_format) |
+                       S_02803C_SW_MODE(iview->image->surface.u.gfx9.stencil.swizzle_mode);
+
+               ds->db_z_info2 = S_028068_EPITCH(iview->image->surface.u.gfx9.surf.epitch);
+               ds->db_stencil_info2 = S_02806C_EPITCH(iview->image->surface.u.gfx9.stencil.epitch);
+               ds->db_depth_view |= S_028008_MIPID(level);
+
+               ds->db_depth_size = S_02801C_X_MAX(iview->image->info.width - 1) |
+                       S_02801C_Y_MAX(iview->image->info.height - 1);
+
+               /* Only use HTILE for the first level. */
+               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))
+                               /* 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 +
+                               iview->image->htile_offset;
+                       ds->db_htile_data_base = va >> 8;
+                       ds->db_htile_surface = S_028ABC_FULL_CACHE(1) |
+                               S_028ABC_PIPE_ALIGNED(iview->image->surface.u.gfx9.htile.pipe_aligned) |
+                               S_028ABC_RB_ALIGNED(iview->image->surface.u.gfx9.htile.rb_aligned);
+               }
+       } else {
                const struct legacy_surf_level *level_info = &iview->image->surface.u.legacy.level[level];
 
                if (stencil_only)