radv: pass the HTILE buffer to radv_copy_vrs_htile()
authorSamuel Pitoiset <samuel.pitoiset@gmail.com>
Fri, 6 Aug 2021 13:00:11 +0000 (15:00 +0200)
committerMarge Bot <eric+marge@anholt.net>
Thu, 2 Sep 2021 19:39:04 +0000 (19:39 +0000)
Will be used to use a global HTILE buffer without an image.

Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12243>

src/amd/vulkan/radv_cmd_buffer.c
src/amd/vulkan/radv_meta.h
src/amd/vulkan/radv_meta_copy_vrs_htile.c

index a013d58..3cf3dbc 100644 (file)
@@ -5142,14 +5142,22 @@ radv_cmd_buffer_begin_subpass(struct radv_cmd_buffer *cmd_buffer, uint32_t subpa
           */
          int ds_idx = subpass->depth_stencil_attachment->attachment;
          struct radv_image_view *ds_iview = cmd_buffer->state.attachments[ds_idx].iview;
+         struct radv_image *ds_image = ds_iview->image;
 
          VkExtent2D extent = {
-            .width = ds_iview->image->info.width,
-            .height = ds_iview->image->info.height,
+            .width = ds_image->info.width,
+            .height = ds_image->info.height,
          };
 
+         /* HTILE buffer */
+         uint64_t htile_offset = ds_image->offset + ds_image->planes[0].surface.meta_offset;
+         uint64_t htile_size = ds_image->planes[0].surface.meta_slice_size;
+         struct radv_buffer htile_buffer = {.bo = ds_image->bo,
+                                            .offset = htile_offset,
+                                            .size = htile_size};
+
          /* Copy the VRS rates to the HTILE buffer. */
-         radv_copy_vrs_htile(cmd_buffer, vrs_iview->image, &extent, ds_iview->image, true);
+         radv_copy_vrs_htile(cmd_buffer, vrs_iview->image, &extent, ds_image, &htile_buffer, true);
       } else {
          /* When a subpass uses a VRS attachment without binding a depth/stencil attachment, we have
           * to copy the VRS rates to our internal HTILE buffer.
@@ -5158,13 +5166,20 @@ radv_cmd_buffer_begin_subpass(struct radv_cmd_buffer *cmd_buffer, uint32_t subpa
          struct radv_image *ds_image = radv_cmd_buffer_get_vrs_image(cmd_buffer);
 
          if (ds_image) {
+            /* HTILE buffer */
+            uint64_t htile_offset = ds_image->offset + ds_image->planes[0].surface.meta_offset;
+            uint64_t htile_size = ds_image->planes[0].surface.meta_slice_size;
+            struct radv_buffer htile_buffer = {.bo = ds_image->bo,
+                                               .offset = htile_offset,
+                                               .size = htile_size};
+
             VkExtent2D extent = {
                .width = MIN2(fb->width, ds_image->info.width),
                .height = MIN2(fb->height, ds_image->info.height),
             };
 
             /* Copy the VRS rates to the HTILE buffer. */
-            radv_copy_vrs_htile(cmd_buffer, vrs_iview->image, &extent, ds_image, false);
+            radv_copy_vrs_htile(cmd_buffer, vrs_iview->image, &extent, ds_image, &htile_buffer, false);
          }
       }
    }
index 30c5652..7500b89 100644 (file)
@@ -220,7 +220,8 @@ void radv_retile_dcc(struct radv_cmd_buffer *cmd_buffer, struct radv_image *imag
 void radv_expand_fmask_image_inplace(struct radv_cmd_buffer *cmd_buffer, struct radv_image *image,
                                      const VkImageSubresourceRange *subresourceRange);
 void radv_copy_vrs_htile(struct radv_cmd_buffer *cmd_buffer, struct radv_image *vrs_image,
-                         VkExtent2D *extent, struct radv_image *dst_image, bool read_htile_value);
+                         VkExtent2D *extent, struct radv_image *dst_image,
+                         struct radv_buffer *htile_buffer, bool read_htile_value);
 
 void radv_meta_resolve_compute_image(struct radv_cmd_buffer *cmd_buffer,
                                      struct radv_image *src_image, VkFormat src_format,
index aa5d584..ad89967 100644 (file)
@@ -220,7 +220,8 @@ fail:
 
 void
 radv_copy_vrs_htile(struct radv_cmd_buffer *cmd_buffer, struct radv_image *vrs_image,
-                    VkExtent2D *extent, struct radv_image *dst_image, bool read_htile_value)
+                    VkExtent2D *extent, struct radv_image *dst_image,
+                    struct radv_buffer *htile_buffer, bool read_htile_value)
 {
    struct radv_device *device = cmd_buffer->device;
    struct radv_meta_state *state = &device->meta_state;
@@ -249,13 +250,6 @@ radv_copy_vrs_htile(struct radv_cmd_buffer *cmd_buffer, struct radv_image *vrs_i
    radv_CmdBindPipeline(radv_cmd_buffer_to_handle(cmd_buffer), VK_PIPELINE_BIND_POINT_COMPUTE,
                         state->copy_vrs_htile_pipeline);
 
-   /* HTILE buffer */
-   uint64_t htile_offset = dst_image->offset + dst_image->planes[0].surface.meta_offset;
-   uint64_t htile_size = dst_image->planes[0].surface.meta_slice_size;
-   struct radv_buffer htile_buffer = {.bo = dst_image->bo,
-                                      .offset = htile_offset,
-                                      .size = htile_size};
-
    radv_image_view_init(&vrs_iview, cmd_buffer->device,
                         &(VkImageViewCreateInfo){
                            .sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
@@ -292,9 +286,9 @@ radv_copy_vrs_htile(struct radv_cmd_buffer *cmd_buffer, struct radv_image *vrs_i
           .dstArrayElement = 0,
           .descriptorCount = 1,
           .descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
-          .pBufferInfo = &(VkDescriptorBufferInfo){.buffer = radv_buffer_to_handle(&htile_buffer),
+          .pBufferInfo = &(VkDescriptorBufferInfo){.buffer = radv_buffer_to_handle(htile_buffer),
                                                    .offset = 0,
-                                                   .range = htile_size}}});
+                                                   .range = htile_buffer->size}}});
 
    const unsigned constants[3] = {
       dst_image->planes[0].surface.meta_pitch, dst_image->planes[0].surface.meta_slice_size,