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>
#include "lima_util.h"
#include "lima_gpu.h"
+#include "pan_minmax_cache.h"
+
#include <drm-uapi/lima_drm.h>
static bool
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) {
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);
#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 *
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,
if (res->damage.region)
FREE(res->damage.region);
+ if (res->index_cache)
+ FREE(res->index_cache);
+
FREE(res);
}
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 +
free(trans->staging);
}
+ panfrost_minmax_cache_invalidate(res->index_cache, ptrans);
+
pipe_resource_reference(&ptrans->resource, NULL);
slab_free(&ctx->transfer_pool, trans);
}
#define LIMA_MAX_MIP_LEVELS 13
struct lima_screen;
+struct panfrost_minmax_cache;
struct lima_resource_level {
uint32_t width;
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];