Mesa (main): v3d,v3dv: move tile size calculation to a common helper

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Mon Nov 15 11:58:40 UTC 2021


Module: Mesa
Branch: main
Commit: f384c763fc6e65c8f17f05190b14f379d6602c1e
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=f384c763fc6e65c8f17f05190b14f379d6602c1e

Author: Iago Toral Quiroga <itoral at igalia.com>
Date:   Mon Nov 15 11:09:38 2021 +0100

v3d,v3dv: move tile size calculation to a common helper

We had this code replicated in 3 places across both drivers.

Reviewed-by: Alejandro Piñeiro <apinheiro at igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13790>

---

 src/broadcom/common/v3d_util.c        | 32 +++++++++++++++++++++++++++++++
 src/broadcom/common/v3d_util.h        |  5 +++++
 src/broadcom/vulkan/v3dv_cmd_buffer.c | 27 ++------------------------
 src/broadcom/vulkan/v3dv_pass.c       | 36 +++++++----------------------------
 src/gallium/drivers/v3d/v3d_context.c | 26 +++++--------------------
 5 files changed, 51 insertions(+), 75 deletions(-)

diff --git a/src/broadcom/common/v3d_util.c b/src/broadcom/common/v3d_util.c
index 424656fd8b1..ecbe5382f34 100644
--- a/src/broadcom/common/v3d_util.c
+++ b/src/broadcom/common/v3d_util.c
@@ -86,3 +86,35 @@ v3d_csd_choose_workgroups_per_supergroup(struct v3d_device_info *devinfo,
 
    return best_wgs_per_sg;
 }
+
+void
+v3d_choose_tile_size(uint32_t color_attachment_count,
+                     uint32_t max_color_bpp, bool msaa,
+                     uint32_t *width, uint32_t *height)
+{
+   static const uint8_t tile_sizes[] = {
+      64, 64,
+      64, 32,
+      32, 32,
+      32, 16,
+      16, 16,
+      16,  8,
+       8,  8
+   };
+
+   uint32_t idx = 0;
+   if (color_attachment_count > 2)
+      idx += 2;
+   else if (color_attachment_count > 1)
+      idx += 1;
+
+   if (msaa)
+      idx += 2;
+
+   idx += max_color_bpp;
+
+   assert(idx < ARRAY_SIZE(tile_sizes) / 2);
+
+   *width = tile_sizes[idx * 2];
+   *height = tile_sizes[idx * 2 + 1];
+}
diff --git a/src/broadcom/common/v3d_util.h b/src/broadcom/common/v3d_util.h
index b9804f235ae..69c91e9a5f5 100644
--- a/src/broadcom/common/v3d_util.h
+++ b/src/broadcom/common/v3d_util.h
@@ -34,4 +34,9 @@ v3d_csd_choose_workgroups_per_supergroup(struct v3d_device_info *devinfo,
                                          uint32_t num_wgs,
                                          uint32_t wg_size);
 
+void
+v3d_choose_tile_size(uint32_t color_attachment_count,
+                     uint32_t max_color_bpp, bool msaa,
+                     uint32_t *width, uint32_t *height);
+
 #endif
diff --git a/src/broadcom/vulkan/v3dv_cmd_buffer.c b/src/broadcom/vulkan/v3dv_cmd_buffer.c
index 4fe78ad71e7..ae43b12af94 100644
--- a/src/broadcom/vulkan/v3dv_cmd_buffer.c
+++ b/src/broadcom/vulkan/v3dv_cmd_buffer.c
@@ -432,16 +432,6 @@ job_compute_frame_tiling(struct v3dv_job *job,
                          uint8_t max_internal_bpp,
                          bool msaa)
 {
-   static const uint8_t tile_sizes[] = {
-      64, 64,
-      64, 32,
-      32, 32,
-      32, 16,
-      16, 16,
-      16,  8,
-       8,  8
-   };
-
    assert(job);
    struct v3dv_frame_tiling *tiling = &job->frame_tiling;
 
@@ -450,23 +440,10 @@ job_compute_frame_tiling(struct v3dv_job *job,
    tiling->layers = layers;
    tiling->render_target_count = render_target_count;
    tiling->msaa = msaa;
-
-   uint32_t tile_size_index = 0;
-
-   if (render_target_count > 2)
-      tile_size_index += 2;
-   else if (render_target_count > 1)
-      tile_size_index += 1;
-
-   if (msaa)
-      tile_size_index += 2;
-
    tiling->internal_bpp = max_internal_bpp;
-   tile_size_index += tiling->internal_bpp;
-   assert(tile_size_index < ARRAY_SIZE(tile_sizes) / 2);
 
-   tiling->tile_width = tile_sizes[tile_size_index * 2];
-   tiling->tile_height = tile_sizes[tile_size_index * 2 + 1];
+   v3d_choose_tile_size(render_target_count, max_internal_bpp, msaa,
+                         &tiling->tile_width, &tiling->tile_height);
 
    tiling->draw_tiles_x = DIV_ROUND_UP(width, tiling->tile_width);
    tiling->draw_tiles_y = DIV_ROUND_UP(height, tiling->tile_height);
diff --git a/src/broadcom/vulkan/v3dv_pass.c b/src/broadcom/vulkan/v3dv_pass.c
index 3eb70a250e5..7347a189904 100644
--- a/src/broadcom/vulkan/v3dv_pass.c
+++ b/src/broadcom/vulkan/v3dv_pass.c
@@ -285,25 +285,13 @@ subpass_get_granularity(struct v3dv_device *device,
                         uint32_t subpass_idx,
                         VkExtent2D *granularity)
 {
-   static const uint8_t tile_sizes[] = {
-      64, 64,
-      64, 32,
-      32, 32,
-      32, 16,
-      16, 16,
-      16,  8,
-       8,  8
-   };
-
-   /* Our tile size depends on the number of color attachments and the maximum
-    * bpp across them.
-    */
+   /* Granularity is defined by the tile size */
    assert(subpass_idx < pass->subpass_count);
    struct v3dv_subpass *subpass = &pass->subpasses[subpass_idx];
    const uint32_t color_attachment_count = subpass->color_count;
 
    bool msaa = false;
-   uint32_t max_internal_bpp = 0;
+   uint32_t max_bpp = 0;
    for (uint32_t i = 0; i < color_attachment_count; i++) {
       uint32_t attachment_idx = subpass->color_attachments[i].attachment;
       if (attachment_idx == VK_ATTACHMENT_UNUSED)
@@ -315,27 +303,17 @@ subpass_get_granularity(struct v3dv_device *device,
       v3dv_X(device, get_internal_type_bpp_for_output_format)
          (format->rt_type, &internal_type, &internal_bpp);
 
-      max_internal_bpp = MAX2(max_internal_bpp, internal_bpp);
+      max_bpp = MAX2(max_bpp, internal_bpp);
 
       if (desc->samples > VK_SAMPLE_COUNT_1_BIT)
          msaa = true;
    }
 
-   uint32_t idx = 0;
-   if (color_attachment_count > 2)
-      idx += 2;
-   else if (color_attachment_count > 1)
-      idx += 1;
-
-   if (msaa)
-      idx += 2;
-
-   idx += max_internal_bpp;
-
-   assert(idx < ARRAY_SIZE(tile_sizes));
+   uint32_t width, height;
+   v3d_choose_tile_size(color_attachment_count, max_bpp, msaa, &width, &height);
    *granularity = (VkExtent2D) {
-      .width = tile_sizes[idx * 2],
-      .height = tile_sizes[idx * 2 + 1]
+      .width = width,
+      .height = height
    };
 }
 
diff --git a/src/gallium/drivers/v3d/v3d_context.c b/src/gallium/drivers/v3d/v3d_context.c
index dd7928ace15..70b773c0e8d 100644
--- a/src/gallium/drivers/v3d/v3d_context.c
+++ b/src/gallium/drivers/v3d/v3d_context.c
@@ -38,6 +38,7 @@
 #include "v3d_context.h"
 #include "v3d_resource.h"
 #include "broadcom/compiler/v3d_compiler.h"
+#include "broadcom/common/v3d_util.h"
 
 void
 v3d_flush(struct pipe_context *pctx)
@@ -248,27 +249,13 @@ v3d_get_tile_buffer_size(bool is_msaa,
                          uint32_t *tile_height,
                          uint32_t *max_bpp)
 {
-        static const uint8_t tile_sizes[] = {
-                64, 64,
-                64, 32,
-                32, 32,
-                32, 16,
-                16, 16,
-        };
-        int tile_size_index = 0;
-        if (is_msaa)
-                tile_size_index += 2;
-
-        if (cbufs[3] || cbufs[2])
-                tile_size_index += 2;
-        else if (cbufs[1])
-                tile_size_index++;
-
+        uint32_t max_cbuf_idx = 0;
         *max_bpp = 0;
         for (int i = 0; i < nr_cbufs; i++) {
                 if (cbufs[i]) {
                         struct v3d_surface *surf = v3d_surface(cbufs[i]);
                         *max_bpp = MAX2(*max_bpp, surf->internal_bpp);
+                        max_cbuf_idx = MAX2(i, max_cbuf_idx);
                 }
         }
 
@@ -278,11 +265,8 @@ v3d_get_tile_buffer_size(bool is_msaa,
                 *max_bpp = MAX2(*max_bpp, bsurf->internal_bpp);
         }
 
-        tile_size_index += *max_bpp;
-
-        assert(tile_size_index < ARRAY_SIZE(tile_sizes));
-        *tile_width = tile_sizes[tile_size_index * 2 + 0];
-        *tile_height = tile_sizes[tile_size_index * 2 + 1];
+        v3d_choose_tile_size(max_cbuf_idx + 1, *max_bpp, is_msaa,
+                             tile_width, tile_height);
 }
 
 static void



More information about the mesa-commit mailing list