Stolen from radeonsi

Signed-off-by: Constantine Kharlamov <hi-an...@yandex.ru>
---
 src/gallium/drivers/r600/r600_pipe.h         | 15 +++++++++++++++
 src/gallium/drivers/r600/r600_state_common.c |  8 +++++---
 2 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/src/gallium/drivers/r600/r600_pipe.h 
b/src/gallium/drivers/r600/r600_pipe.h
index 1d65cb317d..949065a8c0 100644
--- a/src/gallium/drivers/r600/r600_pipe.h
+++ b/src/gallium/drivers/r600/r600_pipe.h
@@ -950,6 +950,21 @@ static inline unsigned r600_get_flush_flags(enum 
r600_coherency coher)
        }
 }
 
+static inline unsigned
+r600_optimal_tcc_alignment(struct r600_context *rctx, unsigned upload_size)
+{
+       unsigned alignment;
+
+       /* If the upload size is less than the cache line size (e.g. 16, 32),
+        * the whole thing will fit into a cache line if we align it to its
+        * size.  The idea is that multiple small uploads can share a cache
+        * line.  If the upload size is greater, align it to the cache line
+        * size.
+        */
+       alignment = util_next_power_of_two(upload_size);
+       return MIN2(alignment, rctx->screen->b.info.tcc_cache_line_size);
+}
+
 #define     V_028A6C_OUTPRIM_TYPE_POINTLIST            0
 #define     V_028A6C_OUTPRIM_TYPE_LINESTRIP            1
 #define     V_028A6C_OUTPRIM_TYPE_TRISTRIP             2
diff --git a/src/gallium/drivers/r600/r600_state_common.c 
b/src/gallium/drivers/r600/r600_state_common.c
index 5293c4034f..04d2472aca 100644
--- a/src/gallium/drivers/r600/r600_state_common.c
+++ b/src/gallium/drivers/r600/r600_state_common.c
@@ -1722,7 +1722,7 @@ static void r600_draw_vbo(struct pipe_context *ctx, const 
struct pipe_draw_info
                        struct pipe_resource *out_buffer = NULL;
                        unsigned out_offset;
                        void *ptr;
-                       unsigned start, count;
+                       unsigned start, count, size;
 
                        if (likely(!info->indirect)) {
                                start = 0;
@@ -1744,8 +1744,10 @@ static void r600_draw_vbo(struct pipe_context *ctx, 
const struct pipe_draw_info
                                }
                        }
 
-                       u_upload_alloc(ctx->stream_uploader, start, count * 2,
-                                       256, &out_offset, &out_buffer, &ptr);
+                       size = count * 2;
+                       u_upload_alloc(ctx->stream_uploader, start, size,
+                                      r600_optimal_tcc_alignment(rctx, size),
+                                      &out_offset, &out_buffer, &ptr);
 
                        util_shorten_ubyte_elts_to_userptr(
                                                &rctx->b.b, &ib, 0, 0, 
ib.offset + start, count, ptr);
-- 
2.12.0

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

Reply via email to