Re: [Mesa-dev] [PATCH] panfrost: Cache index buffer bounds

2019-03-26 Thread Alyssa Rosenzweig
> It doesn't, but the inside of your caching function should probably be
> using it.

Ah, I see, fair point :)

Will we want this caching to be moved up to shared Gallium or no?


___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev

Re: [Mesa-dev] [PATCH] panfrost: Cache index buffer bounds

2019-03-26 Thread Eric Anholt
Alyssa Rosenzweig  writes:

>> Can you reuse u_vbuf_get_minmax_index()?
>
> From a preliminary read, it didn't look like that did caching?

It doesn't, but the inside of your caching function should probably be
using it.


signature.asc
Description: PGP signature
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev

Re: [Mesa-dev] [PATCH] panfrost: Cache index buffer bounds

2019-03-25 Thread Alyssa Rosenzweig
> Can you reuse u_vbuf_get_minmax_index()?

From a preliminary read, it didn't look like that did caching?
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev

Re: [Mesa-dev] [PATCH] panfrost: Cache index buffer bounds

2019-03-25 Thread Eric Anholt
Alyssa Rosenzweig  writes:

> This code is probably a wholesale duplication of the corresponding code
> in mesa/src/vbo/vbo_minmax_indices.c; we should investigate reusing
> that.

Can you reuse u_vbuf_get_minmax_index()?


signature.asc
Description: PGP signature
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev

[Mesa-dev] [PATCH] panfrost: Cache index buffer bounds

2019-03-24 Thread Alyssa Rosenzweig
This code is probably a wholesale duplication of the corresponding code
in mesa/src/vbo/vbo_minmax_indices.c; we should investigate reusing
that.

Signed-off-by: Alyssa Rosenzweig 
---
 src/gallium/drivers/panfrost/pan_context.c  | 108 ++--
 src/gallium/drivers/panfrost/pan_resource.c |  37 ++-
 src/gallium/drivers/panfrost/pan_resource.h |   9 ++
 3 files changed, 117 insertions(+), 37 deletions(-)

diff --git a/src/gallium/drivers/panfrost/pan_context.c 
b/src/gallium/drivers/panfrost/pan_context.c
index 19cdb6c0444..2e8a0f03b1a 100644
--- a/src/gallium/drivers/panfrost/pan_context.c
+++ b/src/gallium/drivers/panfrost/pan_context.c
@@ -1355,17 +1355,82 @@ panfrost_translate_index_size(unsigned size)
 }
 }
 
-static const uint8_t *
-panfrost_get_index_buffer_raw(const struct pipe_draw_info *info)
+#define CALCULATE_MIN_MAX_INDEX(T, buffer, start, count) \
+for (unsigned _idx = (start); _idx < (start + count); ++_idx) { \
+T idx = buffer[_idx]; \
+if (idx > max_index) max_index = idx; \
+if (idx < min_index) min_index = idx; \
+}
+
+/* Computes the index bounds, rescanning if necessary */
+
+static void
+panfrost_get_index_bounds(
+const struct pipe_draw_info *info,
+int *o_min_index,
+int *o_max_index)
 {
-if (info->has_user_indices) {
-return (const uint8_t *) info->index.user;
+int min_index = INT_MAX, max_index = 0;
+
+struct panfrost_resource *rsrc =
+info->has_user_indices ? NULL :
+pan_resource(info->index.resource);
+
+if (rsrc) {
+assert(rsrc->bo);
+}
+
+uint64_t key = ((uint64_t) info->start << 32) | ((uint32_t) 
info->count);
+
+/* Reuse bounds from cache if possible */
+if (rsrc) {
+struct panfrost_indices *cached = (struct panfrost_indices *)
+_mesa_hash_table_u64_search(rsrc->indices, key);
+
+if (cached) {
+*o_min_index = cached->min;
+*o_max_index = cached->max;
+return;
+}
+}
+
+const uint8_t *ibuf8 =
+rsrc ? rsrc->bo->cpu[0] : info->index.user;
+
+/* Scan the buffer */
+
+if (info->index_size == 1) {
+CALCULATE_MIN_MAX_INDEX(uint8_t, ibuf8, info->start, 
info->count);
+} else if (info->index_size == 2) {
+const uint16_t *ibuf16 = (const uint16_t *) ibuf8;
+CALCULATE_MIN_MAX_INDEX(uint16_t, ibuf16, info->start, 
info->count);
+} else if (info->index_size == 4) {
+const uint32_t *ibuf32 = (const uint32_t *) ibuf8;
+CALCULATE_MIN_MAX_INDEX(uint32_t, ibuf32, info->start, 
info->count);
 } else {
-struct panfrost_resource *rsrc = (struct panfrost_resource *) 
(info->index.resource);
-return (const uint8_t *) rsrc->bo->cpu[0];
+assert(0);
+}
+
+/* Make sure we didn't go crazy */
+assert(min_index < INT_MAX);
+assert(max_index > 0);
+assert(max_index > min_index);
+
+/* Write bounds back */
+*o_min_index = min_index;
+*o_max_index = max_index;
+
+/* Write bounds to cache */
+if (rsrc) {
+struct panfrost_indices *ind = CALLOC_STRUCT(panfrost_indices);
+ind->min = min_index;
+ind->max = max_index;
+_mesa_hash_table_u64_insert(rsrc->indices, key, ind);
 }
 }
 
+#undef CALCULATE_MIN_MAX_INDEX
+
 /* Gets a GPU address for the associated index buffer. Only gauranteed to be
  * good for the duration of the draw (transient), could last longer */
 
@@ -1381,18 +1446,11 @@ panfrost_get_index_buffer_mapped(struct 
panfrost_context *ctx, const struct pipe
 return rsrc->bo->gpu[0] + offset;
 } else {
 /* Otherwise, we need to upload to transient memory */
-const uint8_t *ibuf8 = panfrost_get_index_buffer_raw(info);
+const uint8_t *ibuf8 = (const uint8_t *) info->index.user;
 return panfrost_upload_transient(ctx, ibuf8 + offset, 
info->count * info->index_size);
 }
 }
 
-#define CALCULATE_MIN_MAX_INDEX(T, buffer, start, count) \
-for (unsigned _idx = (start); _idx < (start + count); ++_idx) { \
-T idx = buffer[_idx]; \
-if (idx > max_index) max_index = idx; \
-if (idx < min_index) min_index = idx; \
-}
-
 static void
 panfrost_draw_vbo(
 struct pipe_context *pipe,
@@ -1445,27 +1503,9 @@ panfrost_draw_vbo(
 /* Calculate the min/max index used so we can figure out how
  * many times to invoke the vertex shader */
 
-const uint8_t *ibuf8 =