lima: enable minmax cache for index buffers
authorVasily Khoruzhick <anarsoul@gmail.com>
Wed, 4 Mar 2020 06:05:52 +0000 (22:05 -0800)
committerMarge Bot <eric+marge@anholt.net>
Tue, 10 Mar 2020 02:41:27 +0000 (02:41 +0000)
Re-use minmax cache for index buffers from panfrost.

Reviewed-by: Andreas Baierl <ichgeh@imkreisrum.de>
Signed-off-by: Vasily Khoruzhick <anarsoul@gmail.com>
Tested-by: Marge Bot <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4051>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4051>

src/gallium/drivers/lima/lima_draw.c
src/gallium/drivers/lima/lima_resource.c
src/gallium/drivers/lima/lima_resource.h

index 12059cb1c62c0c90b84f7443cc8cee108d2b941b..637d5ec59d06a84034ebb224b91897b52d2d1973 100644 (file)
@@ -45,6 +45,8 @@
 #include "lima_util.h"
 #include "lima_gpu.h"
 
+#include "pan_minmax_cache.h"
+
 #include <drm-uapi/lima_drm.h>
 
 static bool
@@ -1007,14 +1009,14 @@ lima_draw_vbo_indexed(struct pipe_context *pctx,
    struct lima_context *ctx = lima_context(pctx);
    struct lima_job *job = lima_job_get(ctx);
    struct pipe_resource *indexbuf = NULL;
+   bool needs_indices = true;
 
    /* Mali Utgard GPU always need min/max index info for index draw,
     * compute it if upper layer does not do for us */
-   if (info->max_index == ~0u)
-      u_vbuf_get_minmax_index(pctx, info, &ctx->min_index, &ctx->max_index);
-   else {
+   if (info->max_index != ~0u) {
       ctx->min_index = info->min_index;
       ctx->max_index = info->max_index;
+      needs_indices = false;
    }
 
    if (info->has_user_indices) {
@@ -1024,6 +1026,15 @@ lima_draw_vbo_indexed(struct pipe_context *pctx,
    else {
       ctx->index_res = lima_resource(info->index.resource);
       ctx->index_offset = 0;
+      needs_indices = !panfrost_minmax_cache_get(ctx->index_res->index_cache, info->start,
+                                                 info->count, &ctx->min_index, &ctx->max_index);
+   }
+
+   if (needs_indices) {
+      u_vbuf_get_minmax_index(pctx, info, &ctx->min_index, &ctx->max_index);
+      if (!info->has_user_indices)
+         panfrost_minmax_cache_add(ctx->index_res->index_cache, info->start, info->count,
+                                   ctx->min_index, ctx->max_index);
    }
 
    lima_job_add_bo(job, LIMA_PIPE_GP, ctx->index_res->bo, LIMA_SUBMIT_BO_READ);
index 2cb4cde718e41e0f4f4ed417086a07d197a96400..9f429f8c32aa665fdf9f3789f53f1f5b8c390482 100644 (file)
@@ -45,6 +45,8 @@
 #include "lima_resource.h"
 #include "lima_bo.h"
 #include "lima_util.h"
+
+#include "pan_minmax_cache.h"
 #include "pan_tiling.h"
 
 static struct pipe_resource *
@@ -224,6 +226,9 @@ _lima_resource_create_with_modifiers(struct pipe_screen *pscreen,
       struct lima_resource *res = lima_resource(pres);
       res->tiled = should_tile;
 
+      if (templat->bind & PIPE_BIND_INDEX_BUFFER)
+         res->index_cache = CALLOC_STRUCT(panfrost_minmax_cache);
+
       debug_printf("%s: pres=%p width=%u height=%u depth=%u target=%d "
                    "bind=%x usage=%d tile=%d last_level=%d\n", __func__,
                    pres, pres->width0, pres->height0, pres->depth0,
@@ -275,6 +280,9 @@ lima_resource_destroy(struct pipe_screen *pscreen, struct pipe_resource *pres)
    if (res->damage.region)
       FREE(res->damage.region);
 
+   if (res->index_cache)
+      FREE(res->index_cache);
+
    FREE(res);
 }
 
@@ -584,9 +592,17 @@ lima_transfer_map(struct pipe_context *pctx,
 
       return trans->staging;
    } else {
+      unsigned dpw = PIPE_TRANSFER_MAP_DIRECTLY | PIPE_TRANSFER_WRITE |
+                     PIPE_TRANSFER_PERSISTENT;
+      if ((usage & dpw) == dpw && res->index_cache)
+         return NULL;
+
       ptrans->stride = res->levels[level].stride;
       ptrans->layer_stride = res->levels[level].layer_stride;
 
+      if ((usage & PIPE_TRANSFER_WRITE) && (usage & PIPE_TRANSFER_MAP_DIRECTLY))
+         panfrost_minmax_cache_invalidate(res->index_cache, ptrans);
+
       return bo->map + res->levels[level].offset +
          box->z * res->levels[level].layer_stride +
          box->y / util_format_get_blockheight(pres->format) * ptrans->stride +
@@ -630,6 +646,8 @@ lima_transfer_unmap(struct pipe_context *pctx,
       free(trans->staging);
    }
 
+   panfrost_minmax_cache_invalidate(res->index_cache, ptrans);
+
    pipe_resource_reference(&ptrans->resource, NULL);
    slab_free(&ctx->transfer_pool, trans);
 }
index d1f15eb502419c3431ec474808de9f2a8bd978a9..0b2d150b5eecd676b736039f3a6a8ecae4941cd5 100644 (file)
@@ -31,6 +31,7 @@
 #define LIMA_MAX_MIP_LEVELS 13
 
 struct lima_screen;
+struct panfrost_minmax_cache;
 
 struct lima_resource_level {
    uint32_t width;
@@ -52,6 +53,7 @@ struct lima_resource {
    struct lima_damage_region damage;
    struct renderonly_scanout *scanout;
    struct lima_bo *bo;
+   struct panfrost_minmax_cache *index_cache;
    bool tiled;
 
    struct lima_resource_level levels[LIMA_MAX_MIP_LEVELS];