radv: Add forcecompress debug flag.
[mesa.git] / src / amd / vulkan / radv_image.c
index 8c65eb6bc37474c4e6d3ad504300f7051898f86d..8671a6ffb77f882526db63a816c16f07b7aafbf2 100644 (file)
@@ -150,8 +150,12 @@ radv_surface_has_scanout(struct radv_device *device, const struct radv_image_cre
 }
 
 static bool
-radv_image_use_fast_clear_for_image(const struct radv_image *image)
+radv_image_use_fast_clear_for_image(const struct radv_device *device,
+                                    const struct radv_image *image)
 {
+       if (device->instance->debug_flags & RADV_DEBUG_FORCE_COMPRESS)
+               return true;
+
        if (image->info.samples <= 1 &&
            image->info.width * image->info.height <= 512 * 512) {
                /* Do not enable CMASK or DCC for small surfaces where the cost
@@ -196,7 +200,7 @@ radv_use_dcc_for_image(struct radv_device *device,
            vk_format_get_plane_count(format) > 1)
                return false;
 
-       if (!radv_image_use_fast_clear_for_image(image))
+       if (!radv_image_use_fast_clear_for_image(device, image))
                return false;
 
        /* TODO: Enable DCC for mipmaps on GFX9+. */
@@ -251,17 +255,21 @@ radv_use_dcc_for_image(struct radv_device *device,
 }
 
 static inline bool
-radv_use_fmask_for_image(const struct radv_image *image)
+radv_use_fmask_for_image(const struct radv_device *device,
+                         const struct radv_image *image)
 {
        return image->info.samples > 1 &&
-              image->usage & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
+              ((image->usage & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT) ||
+               (device->instance->debug_flags & RADV_DEBUG_FORCE_COMPRESS));
 }
 
 static inline bool
-radv_use_htile_for_image(const struct radv_image *image)
+radv_use_htile_for_image(const struct radv_device *device,
+                         const struct radv_image *image)
 {
        return image->info.levels == 1 &&
-              image->info.width * image->info.height >= 8 * 8;
+              ((image->info.width * image->info.height >= 8 * 8) ||
+               (device->instance->debug_flags & RADV_DEBUG_FORCE_COMPRESS));
 }
 
 static bool
@@ -479,7 +487,7 @@ radv_init_surface(struct radv_device *device,
 
        if (is_depth) {
                surface->flags |= RADEON_SURF_ZBUFFER;
-               if (!radv_use_htile_for_image(image) ||
+               if (!radv_use_htile_for_image(device, image) ||
                    (device->instance->debug_flags & RADV_DEBUG_NO_HIZ))
                        surface->flags |= RADEON_SURF_NO_HTILE;
                if (radv_use_tc_compat_htile_for_image(device, pCreateInfo, image_format))
@@ -498,7 +506,7 @@ radv_init_surface(struct radv_device *device,
        if (!radv_use_dcc_for_image(device, image, pCreateInfo, image_format))
                surface->flags |= RADEON_SURF_DISABLE_DCC;
 
-       if (!radv_use_fmask_for_image(image))
+       if (!radv_use_fmask_for_image(device, image))
                surface->flags |= RADEON_SURF_NO_FMASK;
 
        return 0;
@@ -1230,14 +1238,18 @@ radv_image_override_offset_stride(struct radv_device *device,
 }
 
 static void
-radv_image_alloc_single_sample_cmask(const struct radv_image *image,
+radv_image_alloc_single_sample_cmask(const struct radv_device *device,
+                                     const struct radv_image *image,
                                      struct radeon_surf *surf)
 {
        if (!surf->cmask_size || surf->cmask_offset || surf->bpe > 8 ||
            image->info.levels > 1 || image->info.depth > 1 ||
-           !radv_image_use_fast_clear_for_image(image))
+           radv_image_has_dcc(image) ||
+           !radv_image_use_fast_clear_for_image(device, image))
                return;
 
+       assert(image->info.storage_samples == 1);
+
        surf->cmask_offset = align64(surf->total_size, surf->cmask_alignment);
        surf->total_size = surf->cmask_offset + surf->cmask_size;
        surf->alignment = MAX2(surf->alignment, surf->cmask_alignment);
@@ -1311,7 +1323,7 @@ radv_image_create_layout(struct radv_device *device,
                device->ws->surface_init(device->ws, &info, &image->planes[plane].surface);
 
                if (!create_info.no_metadata_planes && image->plane_count == 1)
-                       radv_image_alloc_single_sample_cmask(image, &image->planes[plane].surface);
+                       radv_image_alloc_single_sample_cmask(device, image, &image->planes[plane].surface);
 
                image->planes[plane].offset = align(image->size, image->planes[plane].surface.alignment);
                image->size = image->planes[plane].offset + image->planes[plane].surface.total_size;
@@ -1332,6 +1344,23 @@ radv_image_create_layout(struct radv_device *device,
        return VK_SUCCESS;
 }
 
+static void
+radv_destroy_image(struct radv_device *device,
+                  const VkAllocationCallbacks *pAllocator,
+                  struct radv_image *image)
+{
+       if ((image->flags & VK_IMAGE_CREATE_SPARSE_BINDING_BIT) && image->bo)
+               device->ws->buffer_destroy(image->bo);
+
+       if (image->owned_memory != VK_NULL_HANDLE) {
+               RADV_FROM_HANDLE(radv_device_memory, mem, image->owned_memory);
+               radv_free_memory(device, pAllocator, mem);
+       }
+
+       vk_object_base_finish(&image->base);
+       vk_free2(&device->vk.alloc, pAllocator, image);
+}
+
 VkResult
 radv_image_create(VkDevice _device,
                  const struct radv_image_create_info *create_info,
@@ -1421,7 +1450,7 @@ radv_image_create(VkDevice _device,
                image->bo = device->ws->buffer_create(device->ws, image->size, image->alignment,
                                                      0, RADEON_FLAG_VIRTUAL, RADV_BO_PRIORITY_VIRTUAL);
                if (!image->bo) {
-                       vk_free2(&device->vk.alloc, alloc, image);
+                       radv_destroy_image(device, alloc, image);
                        return vk_error(device->instance, VK_ERROR_OUT_OF_DEVICE_MEMORY);
                }
        }
@@ -1751,14 +1780,7 @@ radv_DestroyImage(VkDevice _device, VkImage _image,
        if (!image)
                return;
 
-       if (image->flags & VK_IMAGE_CREATE_SPARSE_BINDING_BIT)
-               device->ws->buffer_destroy(image->bo);
-
-       if (image->owned_memory != VK_NULL_HANDLE)
-               radv_FreeMemory(_device, image->owned_memory, pAllocator);
-
-       vk_object_base_finish(&image->base);
-       vk_free2(&device->vk.alloc, pAllocator, image);
+       radv_destroy_image(device, pAllocator, image);
 }
 
 void radv_GetImageSubresourceLayout(