radv: add radv_decompress_resolve_{subpass}_src() helpers
authorSamuel Pitoiset <samuel.pitoiset@gmail.com>
Wed, 11 Apr 2018 12:09:16 +0000 (14:09 +0200)
committerSamuel Pitoiset <samuel.pitoiset@gmail.com>
Thu, 12 Apr 2018 07:58:44 +0000 (09:58 +0200)
This helper shares common code before resolving using either
a fragment or a compute shader.

Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
src/amd/vulkan/radv_meta.h
src/amd/vulkan/radv_meta_resolve.c
src/amd/vulkan/radv_meta_resolve_cs.c
src/amd/vulkan/radv_meta_resolve_fs.c

index 57b76c13262e413cbd84acdc2b93fbbfa93ac46e..47eec5cd6a0f5aeb5feb338034bcb120deeac3ef 100644 (file)
@@ -191,6 +191,13 @@ void radv_meta_resolve_fragment_image(struct radv_cmd_buffer *cmd_buffer,
                                      uint32_t region_count,
                                      const VkImageResolve *regions);
 
+void radv_decompress_resolve_subpass_src(struct radv_cmd_buffer *cmd_buffer);
+
+void radv_decompress_resolve_src(struct radv_cmd_buffer *cmd_buffer,
+                                struct radv_image *src_image,
+                                uint32_t region_count,
+                                const VkImageResolve *regions);
+
 void radv_blit_to_prime_linear(struct radv_cmd_buffer *cmd_buffer,
                               struct radv_image *image,
                               struct radv_image *linear_image);
index e932976df280ebdffe9edb8dc3c77dc8ae3c581b..1828eb37f46ebc3765dd43773c50475aa9d4f2bf 100644 (file)
@@ -670,3 +670,61 @@ radv_cmd_buffer_resolve_subpass(struct radv_cmd_buffer *cmd_buffer)
        cmd_buffer->state.subpass = subpass;
        radv_meta_restore(&saved_state, cmd_buffer);
 }
+
+/**
+ * Decompress CMask/FMask before resolving a multisampled source image inside a
+ * subpass.
+ */
+void
+radv_decompress_resolve_subpass_src(struct radv_cmd_buffer *cmd_buffer)
+{
+       const struct radv_subpass *subpass = cmd_buffer->state.subpass;
+       struct radv_framebuffer *fb = cmd_buffer->state.framebuffer;
+
+       for (uint32_t i = 0; i < subpass->color_count; ++i) {
+               VkAttachmentReference src_att = subpass->color_attachments[i];
+               VkAttachmentReference dest_att = subpass->resolve_attachments[i];
+
+               if (src_att.attachment == VK_ATTACHMENT_UNUSED ||
+                   dest_att.attachment == VK_ATTACHMENT_UNUSED)
+                       continue;
+
+               struct radv_image_view *src_iview =
+                       fb->attachments[src_att.attachment].attachment;
+
+               VkImageSubresourceRange range;
+               range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
+               range.baseMipLevel = 0;
+               range.levelCount = 1;
+               range.baseArrayLayer = 0;
+               range.layerCount = 1;
+
+               radv_fast_clear_flush_image_inplace(cmd_buffer,
+                                                   src_iview->image, &range);
+       }
+}
+
+/**
+ * Decompress CMask/FMask before resolving a multisampled source image.
+ */
+void
+radv_decompress_resolve_src(struct radv_cmd_buffer *cmd_buffer,
+                           struct radv_image *src_image,
+                           uint32_t region_count,
+                           const VkImageResolve *regions)
+{
+       for (uint32_t r = 0; r < region_count; ++r) {
+               const VkImageResolve *region = &regions[r];
+               const uint32_t src_base_layer =
+                       radv_meta_get_iview_layer(src_image, &region->srcSubresource,
+                                                 &region->srcOffset);
+               VkImageSubresourceRange range;
+               range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
+               range.baseMipLevel = region->srcSubresource.mipLevel;
+               range.levelCount = 1;
+               range.baseArrayLayer = src_base_layer;
+               range.layerCount = region->srcSubresource.layerCount;
+
+               radv_fast_clear_flush_image_inplace(cmd_buffer, src_image, &range);
+       }
+}
index ca8f826f5388445901e976ee244bf5549b48208e..6d605aba017fbbdd2f861895b31da5d47267d6f3 100644 (file)
@@ -388,19 +388,8 @@ void radv_meta_resolve_compute_image(struct radv_cmd_buffer *cmd_buffer,
 {
        struct radv_meta_saved_state saved_state;
 
-       for (uint32_t r = 0; r < region_count; ++r) {
-               const VkImageResolve *region = &regions[r];
-               const uint32_t src_base_layer =
-                       radv_meta_get_iview_layer(src_image, &region->srcSubresource,
-                                                 &region->srcOffset);
-               VkImageSubresourceRange range;
-               range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
-               range.baseMipLevel = region->srcSubresource.mipLevel;
-               range.levelCount = 1;
-               range.baseArrayLayer = src_base_layer;
-               range.layerCount = region->srcSubresource.layerCount;
-               radv_fast_clear_flush_image_inplace(cmd_buffer, src_image, &range);
-       }
+       radv_decompress_resolve_src(cmd_buffer, src_image,
+                                   region_count, regions);
 
        radv_meta_save(&saved_state, cmd_buffer,
                       RADV_META_SAVE_COMPUTE_PIPELINE |
@@ -504,24 +493,7 @@ radv_cmd_buffer_resolve_subpass_cs(struct radv_cmd_buffer *cmd_buffer)
                                        RADV_CMD_FLAG_INV_GLOBAL_L2 |
                                        RADV_CMD_FLAG_INV_VMEM_L1;
 
-       for (uint32_t i = 0; i < subpass->color_count; ++i) {
-               VkAttachmentReference src_att = subpass->color_attachments[i];
-               VkAttachmentReference dest_att = subpass->resolve_attachments[i];
-
-               if (src_att.attachment == VK_ATTACHMENT_UNUSED ||
-                   dest_att.attachment == VK_ATTACHMENT_UNUSED)
-                       continue;
-
-               struct radv_image_view *src_iview = cmd_buffer->state.framebuffer->attachments[src_att.attachment].attachment;
-
-               VkImageSubresourceRange range;
-               range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
-               range.baseMipLevel = 0;
-               range.levelCount = 1;
-               range.baseArrayLayer = 0;
-               range.layerCount = 1;
-               radv_fast_clear_flush_image_inplace(cmd_buffer, src_iview->image, &range);
-       }
+       radv_decompress_resolve_subpass_src(cmd_buffer);
 
        radv_meta_save(&saved_state, cmd_buffer,
                       RADV_META_SAVE_COMPUTE_PIPELINE |
index 08c9282bf0df3b89fea4ed5a730efc1b3b41c387..499b3ae27af5031f7bb1470568a0ee68aa107950 100644 (file)
@@ -457,19 +457,9 @@ void radv_meta_resolve_fragment_image(struct radv_cmd_buffer *cmd_buffer,
        unsigned fs_key = radv_format_meta_fs_key(dest_image->vk_format);
        unsigned dst_layout = radv_meta_dst_layout_from_layout(dest_image_layout);
        VkRenderPass rp;
-       for (uint32_t r = 0; r < region_count; ++r) {
-               const VkImageResolve *region = &regions[r];
-               const uint32_t src_base_layer =
-                       radv_meta_get_iview_layer(src_image, &region->srcSubresource,
-                                                 &region->srcOffset);
-               VkImageSubresourceRange range;
-               range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
-               range.baseMipLevel = region->srcSubresource.mipLevel;
-               range.levelCount = 1;
-               range.baseArrayLayer = src_base_layer;
-               range.layerCount = region->srcSubresource.layerCount;
-               radv_fast_clear_flush_image_inplace(cmd_buffer, src_image, &range);
-       }
+
+       radv_decompress_resolve_src(cmd_buffer, src_image,
+                                   region_count, regions);
 
        rp = device->meta_state.resolve_fragment.rc[samples_log2].render_pass[fs_key][dst_layout];
 
@@ -618,6 +608,8 @@ radv_cmd_buffer_resolve_subpass_fs(struct radv_cmd_buffer *cmd_buffer)
                                        RADV_CMD_FLAG_INV_GLOBAL_L2 |
                                        RADV_CMD_FLAG_INV_VMEM_L1;
 
+       radv_decompress_resolve_subpass_src(cmd_buffer);
+
        for (uint32_t i = 0; i < subpass->color_count; ++i) {
                VkAttachmentReference src_att = subpass->color_attachments[i];
                VkAttachmentReference dest_att = subpass->resolve_attachments[i];
@@ -629,16 +621,6 @@ radv_cmd_buffer_resolve_subpass_fs(struct radv_cmd_buffer *cmd_buffer)
                struct radv_image_view *dest_iview = cmd_buffer->state.framebuffer->attachments[dest_att.attachment].attachment;
                struct radv_image_view *src_iview = cmd_buffer->state.framebuffer->attachments[src_att.attachment].attachment;
 
-               {
-                       VkImageSubresourceRange range;
-                       range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
-                       range.baseMipLevel = 0;
-                       range.levelCount = 1;
-                       range.baseArrayLayer = 0;
-                       range.layerCount = 1;
-                       radv_fast_clear_flush_image_inplace(cmd_buffer, src_iview->image, &range);
-               }
-
                struct radv_subpass resolve_subpass = {
                        .color_count = 1,
                        .color_attachments = (VkAttachmentReference[]) { dest_att },