radv: Decompress DCC when the image format is not allowed for buffers.
authorBas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Sat, 15 Jun 2019 16:05:05 +0000 (18:05 +0200)
committerBas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Mon, 17 Jun 2019 10:56:50 +0000 (10:56 +0000)
Otherwise the buffer loads/stores in the bufimage meta operations fail.

If we decompress DCC then we can use the "canonical" format compatible
with the not-supported format.

CC: <mesa-stable@lists.freedesktop.org>
Reviewed-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
src/amd/vulkan/radv_formats.c
src/amd/vulkan/radv_meta_copy.c
src/amd/vulkan/radv_private.h

index d7b560082f631701aa15b710fc605e9e5a608b73..e61d793e7f2caab48f143cf959957da07fc8dac8 100644 (file)
@@ -547,7 +547,7 @@ static bool radv_is_storage_image_format_supported(struct radv_physical_device *
        }
 }
 
-static bool radv_is_buffer_format_supported(VkFormat format, bool *scaled)
+bool radv_is_buffer_format_supported(VkFormat format, bool *scaled)
 {
        const struct vk_format_description *desc = vk_format_description(format);
        unsigned data_format, num_format;
@@ -559,7 +559,8 @@ static bool radv_is_buffer_format_supported(VkFormat format, bool *scaled)
        num_format = radv_translate_buffer_numformat(desc,
                                                     vk_format_get_first_non_void_channel(format));
 
-       *scaled = (num_format == V_008F0C_BUF_NUM_FORMAT_SSCALED) || (num_format == V_008F0C_BUF_NUM_FORMAT_USCALED);
+       if (scaled)
+               *scaled = (num_format == V_008F0C_BUF_NUM_FORMAT_SSCALED) || (num_format == V_008F0C_BUF_NUM_FORMAT_USCALED);
        return data_format != V_008F0C_BUF_DATA_FORMAT_INVALID &&
                num_format != ~0;
 }
index 8081057d9df8abfb804c2317fb468d99d9b66a0e..9b92f64dc89580719c27c5d39bfc5165fb5d0b3c 100644 (file)
@@ -187,6 +187,24 @@ meta_copy_buffer_to_image(struct radv_cmd_buffer *cmd_buffer,
                                                        &pRegions[r].imageSubresource,
                                                        pRegions[r].imageSubresource.aspectMask);
 
+               if (!radv_is_buffer_format_supported(img_bsurf.format, NULL)) {
+                       uint32_t queue_mask = radv_image_queue_family_mask(image,
+                                                                          cmd_buffer->queue_family_index,
+                                                                          cmd_buffer->queue_family_index);
+                       MAYBE_UNUSED bool compressed = radv_layout_dcc_compressed(image, layout, queue_mask);
+                       if (compressed) {
+                               radv_decompress_dcc(cmd_buffer, image, &(VkImageSubresourceRange) {
+                                                               .aspectMask = pRegions[r].imageSubresource.aspectMask,
+                                                               .baseMipLevel = pRegions[r].imageSubresource.mipLevel,
+                                                               .levelCount = 1,
+                                                               .baseArrayLayer = pRegions[r].imageSubresource.baseArrayLayer,
+                                                               .layerCount = pRegions[r].imageSubresource.layerCount,
+                                                       });
+                       }
+                       img_bsurf.format = vk_format_for_size(vk_format_get_blocksize(img_bsurf.format));
+                       img_bsurf.current_layout = VK_IMAGE_LAYOUT_GENERAL;
+               }
+
                struct radv_meta_blit2d_buffer buf_bsurf = {
                        .bs = img_bsurf.bs,
                        .format = img_bsurf.format,
@@ -313,6 +331,24 @@ meta_copy_image_to_buffer(struct radv_cmd_buffer *cmd_buffer,
                                                        &pRegions[r].imageSubresource,
                                                        pRegions[r].imageSubresource.aspectMask);
 
+               if (!radv_is_buffer_format_supported(img_info.format, NULL)) {
+                       uint32_t queue_mask = radv_image_queue_family_mask(image,
+                                                                          cmd_buffer->queue_family_index,
+                                                                          cmd_buffer->queue_family_index);
+                       MAYBE_UNUSED bool compressed = radv_layout_dcc_compressed(image, layout, queue_mask);
+                       if (compressed) {
+                               radv_decompress_dcc(cmd_buffer, image, &(VkImageSubresourceRange) {
+                                                               .aspectMask = pRegions[r].imageSubresource.aspectMask,
+                                                               .baseMipLevel = pRegions[r].imageSubresource.mipLevel,
+                                                               .levelCount = 1,
+                                                               .baseArrayLayer = pRegions[r].imageSubresource.baseArrayLayer,
+                                                               .layerCount = pRegions[r].imageSubresource.layerCount,
+                                                       });
+                       }
+                       img_info.format = vk_format_for_size(vk_format_get_blocksize(img_info.format));
+                       img_info.current_layout = VK_IMAGE_LAYOUT_GENERAL;
+               }
+
                struct radv_meta_blit2d_buffer buf_info = {
                        .bs = img_info.bs,
                        .format = img_info.format,
index d6f396f0056565ad32a3eeda26ecc2dc813fe29f..37e56f044504ce4cd61e9cbb92d619cb9f46a86a 100644 (file)
@@ -1487,6 +1487,7 @@ uint32_t radv_translate_buffer_dataformat(const struct vk_format_description *de
                                          int first_non_void);
 uint32_t radv_translate_buffer_numformat(const struct vk_format_description *desc,
                                         int first_non_void);
+bool radv_is_buffer_format_supported(VkFormat format, bool *scaled);
 uint32_t radv_translate_colorformat(VkFormat format);
 uint32_t radv_translate_color_numformat(VkFormat format,
                                        const struct vk_format_description *desc,