radeonsi: move si_upload_const_buffer to a better place
[mesa.git] / src / gallium / drivers / radeonsi / si_state_draw.c
index 90f9703cfd3e30bda7401ecf5c3dfb037b235c81..8dbf373d5f0fe98d91dccb5e47ad0ec5ab5d2015 100644 (file)
@@ -27,6 +27,8 @@
 #include "util/u_memory.h"
 #include "util/u_framebuffer.h"
 #include "util/u_blitter.h"
+#include "util/u_index_modify.h"
+#include "util/u_upload_mgr.h"
 #include "tgsi/tgsi_parse.h"
 #include "si_pipe.h"
 #include "si_shader.h"
@@ -718,10 +720,27 @@ void si_draw_vbo(struct pipe_context *ctx, const struct pipe_draw_info *info)
                ib.offset = sctx->index_buffer.offset + info->start * ib.index_size;
 
                /* Translate or upload, if needed. */
-               si_translate_index_buffer(sctx, &ib, info->count);
+               if (ib.index_size == 1) {
+                       struct pipe_resource *out_buffer = NULL;
+                       unsigned out_offset;
+                       void *ptr;
+
+                       u_upload_alloc(sctx->b.uploader, 0, info->count * 2,
+                                      &out_offset, &out_buffer, &ptr);
+
+                       util_shorten_ubyte_elts_to_userptr(
+                                               &sctx->b.b, &ib, 0, ib.offset, info->count, ptr);
+
+                       pipe_resource_reference(&ib.buffer, NULL);
+                       ib.user_buffer = NULL;
+                       ib.buffer = out_buffer;
+                       ib.offset = out_offset;
+                       ib.index_size = 2;
+               }
 
                if (ib.user_buffer && !ib.buffer) {
-                       si_upload_index_buffer(sctx, &ib, info->count);
+                       u_upload_data(sctx->b.uploader, 0, info->count * ib.index_size,
+                                     ib.user_buffer, &ib.offset, &ib.buffer);
                }
        }
 
@@ -750,7 +769,7 @@ void si_draw_vbo(struct pipe_context *ctx, const struct pipe_draw_info *info)
        sctx->pm4_dirty_cdwords = 0;
 
 #if SI_TRACE_CS
-       if (sctx->screen->trace_bo) {
+       if (sctx->screen->b.trace_bo) {
                si_trace_emit(sctx);
        }
 #endif
@@ -777,4 +796,5 @@ void si_draw_vbo(struct pipe_context *ctx, const struct pipe_draw_info *info)
        }
 
        pipe_resource_reference(&ib.buffer, NULL);
+       sctx->b.num_draw_calls++;
 }