v3dv: postpone tile state allocation for render pass jobs
authorIago Toral Quiroga <itoral@igalia.com>
Wed, 27 Jul 2022 08:21:44 +0000 (10:21 +0200)
committerMarge Bot <emma+marge@anholt.net>
Mon, 15 Aug 2022 23:35:16 +0000 (23:35 +0000)
These are jobs for which we may want to enable double-buffering,
which affects tile state allocation. Since the idea is that we
want to decide about double buffering late, we also want to
postpone allocation of the tile state until we are about to
emit the RCL for the job.

Reviewed-by: Alejandro PiƱeiro <apinheiro@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17854>

src/broadcom/vulkan/v3dv_cmd_buffer.c
src/broadcom/vulkan/v3dv_meta_clear.c
src/broadcom/vulkan/v3dv_meta_copy.c
src/broadcom/vulkan/v3dv_private.h
src/broadcom/vulkan/v3dvx_meta_common.c
src/broadcom/vulkan/v3dvx_queue.c

index 9983879..6e60204 100644 (file)
@@ -471,6 +471,7 @@ v3dv_job_start_frame(struct v3dv_job *job,
                      uint32_t height,
                      uint32_t layers,
                      bool allocate_tile_state_for_all_layers,
+                     bool allocate_tile_state_now,
                      uint32_t render_target_count,
                      uint8_t max_internal_bpp,
                      bool msaa)
@@ -487,8 +488,14 @@ v3dv_job_start_frame(struct v3dv_job *job,
    v3dv_return_if_oom(NULL, job);
 
    job->allocate_tile_state_for_all_layers = allocate_tile_state_for_all_layers;
-   if (!v3dv_job_allocate_tile_state(job))
-      return;
+
+   /* For subpass jobs we postpone tile state allocation until we are finishing
+    * the job and have made a decision about double-buffer.
+    */
+   if (allocate_tile_state_now) {
+      if (!v3dv_job_allocate_tile_state(job))
+         return;
+   }
 
    v3dv_X(job->device, job_emit_binning_prolog)(job, tiling,
       allocate_tile_state_for_all_layers ? tiling->layers : 1);
@@ -500,7 +507,8 @@ v3dv_job_start_frame(struct v3dv_job *job,
 static void
 cmd_buffer_end_render_pass_frame(struct v3dv_cmd_buffer *cmd_buffer)
 {
-   assert(cmd_buffer->state.job);
+   struct v3dv_job *job = cmd_buffer->state.job;
+   assert(job);
 
    /* Typically, we have a single job for each subpass and we emit the job's RCL
     * here when we are ending the frame for the subpass. However, some commands
@@ -510,10 +518,17 @@ cmd_buffer_end_render_pass_frame(struct v3dv_cmd_buffer *cmd_buffer)
     * those jobs, so we only emit the subpass RCL if the job has not recorded
     * any RCL commands of its own.
     */
-   if (v3dv_cl_offset(&cmd_buffer->state.job->rcl) == 0)
+   if (v3dv_cl_offset(&job->rcl) == 0) {
+      /* At this point we have decided whether we want to use double-buffer or
+       * not and the job's frame tiling represents that decision so we can
+       * allocate the tile state, which we need to do before we emit the RCL.
+       */
+      v3dv_job_allocate_tile_state(job);
+
       v3dv_X(cmd_buffer->device, cmd_buffer_emit_render_pass_rcl)(cmd_buffer);
+   }
 
-   v3dv_X(cmd_buffer->device, job_emit_binning_flush)(cmd_buffer->state.job);
+   v3dv_X(cmd_buffer->device, job_emit_binning_flush)(job);
 }
 
 struct v3dv_job *
@@ -1629,7 +1644,7 @@ cmd_buffer_subpass_create_job(struct v3dv_cmd_buffer *cmd_buffer,
                            framebuffer->width,
                            framebuffer->height,
                            layers,
-                           true,
+                           true, false,
                            subpass->color_count,
                            internal_bpp,
                            msaa);
@@ -2593,7 +2608,7 @@ cmd_buffer_restart_job_for_msaa_if_needed(struct v3dv_cmd_buffer *cmd_buffer)
                         old_job->frame_tiling.width,
                         old_job->frame_tiling.height,
                         old_job->frame_tiling.layers,
-                        true,
+                        true, false,
                         old_job->frame_tiling.render_target_count,
                         old_job->frame_tiling.internal_bpp,
                         true /* msaa */);
index 5521bdc..889555f 100644 (file)
@@ -119,8 +119,8 @@ clear_image_tlb(struct v3dv_cmd_buffer *cmd_buffer,
       if (!job)
          return true;
 
-      v3dv_job_start_frame(job, width, height, max_layer, false,
-                           1, internal_bpp,
+      v3dv_job_start_frame(job, width, height, max_layer,
+                           false, true, 1, internal_bpp,
                            image->vk.samples > VK_SAMPLE_COUNT_1_BIT);
 
       struct v3dv_meta_framebuffer framebuffer;
index 67184aa..437a86d 100644 (file)
@@ -407,7 +407,7 @@ copy_image_to_buffer_tlb(struct v3dv_cmd_buffer *cmd_buffer,
    const uint32_t width = DIV_ROUND_UP(region->imageExtent.width, block_w);
    const uint32_t height = DIV_ROUND_UP(region->imageExtent.height, block_h);
 
-   v3dv_job_start_frame(job, width, height, num_layers, false,
+   v3dv_job_start_frame(job, width, height, num_layers, false, true,
                         1, internal_bpp, false);
 
    struct v3dv_meta_framebuffer framebuffer;
@@ -948,7 +948,8 @@ copy_image_tlb(struct v3dv_cmd_buffer *cmd_buffer,
    const uint32_t width = DIV_ROUND_UP(region->extent.width, block_w);
    const uint32_t height = DIV_ROUND_UP(region->extent.height, block_h);
 
-   v3dv_job_start_frame(job, width, height, num_layers, false, 1, internal_bpp,
+   v3dv_job_start_frame(job, width, height, num_layers,
+                        false, true, 1, internal_bpp,
                         src->vk.samples > VK_SAMPLE_COUNT_1_BIT);
 
    struct v3dv_meta_framebuffer framebuffer;
@@ -1448,7 +1449,7 @@ copy_buffer_to_image_tlb(struct v3dv_cmd_buffer *cmd_buffer,
    const uint32_t width = DIV_ROUND_UP(region->imageExtent.width, block_w);
    const uint32_t height = DIV_ROUND_UP(region->imageExtent.height, block_h);
 
-   v3dv_job_start_frame(job, width, height, num_layers, false,
+   v3dv_job_start_frame(job, width, height, num_layers, false, true,
                         1, internal_bpp, false);
 
    struct v3dv_meta_framebuffer framebuffer;
@@ -4288,7 +4289,7 @@ resolve_image_tlb(struct v3dv_cmd_buffer *cmd_buffer,
       (fb_format, region->srcSubresource.aspectMask,
        &internal_type, &internal_bpp);
 
-   v3dv_job_start_frame(job, width, height, num_layers, false,
+   v3dv_job_start_frame(job, width, height, num_layers, false, true,
                         1, internal_bpp, true);
 
    struct v3dv_meta_framebuffer framebuffer;
index efb4e57..8e1fe34 100644 (file)
@@ -1203,6 +1203,7 @@ void v3dv_job_start_frame(struct v3dv_job *job,
                           uint32_t height,
                           uint32_t layers,
                           bool allocate_tile_state_for_all_layers,
+                          bool allocate_tile_state_now,
                           uint32_t render_target_count,
                           uint8_t max_internal_bpp,
                           bool msaa);
index 4e68563..52a1dea 100644 (file)
@@ -1274,7 +1274,8 @@ v3dX(meta_copy_buffer)(struct v3dv_cmd_buffer *cmd_buffer,
       uint32_t width, height;
       framebuffer_size_for_pixel_count(num_items, &width, &height);
 
-      v3dv_job_start_frame(job, width, height, 1, true, 1, internal_bpp, false);
+      v3dv_job_start_frame(job, width, height, 1, true, true,
+                           1, internal_bpp, false);
 
       struct v3dv_meta_framebuffer framebuffer;
       v3dX(meta_framebuffer_init)(&framebuffer, vk_format, internal_type,
@@ -1320,7 +1321,8 @@ v3dX(meta_fill_buffer)(struct v3dv_cmd_buffer *cmd_buffer,
       uint32_t width, height;
       framebuffer_size_for_pixel_count(num_items, &width, &height);
 
-      v3dv_job_start_frame(job, width, height, 1, true, 1, internal_bpp, false);
+      v3dv_job_start_frame(job, width, height, 1, true, true,
+                           1, internal_bpp, false);
 
       struct v3dv_meta_framebuffer framebuffer;
       v3dX(meta_framebuffer_init)(&framebuffer, VK_FORMAT_R8G8B8A8_UINT,
index 54b0b1c..efe63de 100644 (file)
@@ -29,7 +29,7 @@
 void
 v3dX(job_emit_noop)(struct v3dv_job *job)
 {
-   v3dv_job_start_frame(job, 1, 1, 1, true, 1, V3D_INTERNAL_BPP_32, false);
+   v3dv_job_start_frame(job, 1, 1, 1, true, true, 1, V3D_INTERNAL_BPP_32, false);
    v3dX(job_emit_binning_flush)(job);
 
    struct v3dv_cl *rcl = &job->rcl;