freedreno: fix indexbuffer upload
authorRob Clark <robdclark@gmail.com>
Sat, 13 May 2017 18:43:45 +0000 (14:43 -0400)
committerRob Clark <robdclark@gmail.com>
Sun, 14 May 2017 19:10:08 +0000 (15:10 -0400)
My fault for not having time to test Marek's patches while they were on
list.

Fixes: 330d0607 ("gallium: remove pipe_index_buffer and set_index_buffer")
Signed-off-by: Rob Clark <robdclark@gmail.com>
src/gallium/drivers/freedreno/a2xx/fd2_draw.c
src/gallium/drivers/freedreno/a3xx/fd3_draw.c
src/gallium/drivers/freedreno/a4xx/fd4_draw.h
src/gallium/drivers/freedreno/a5xx/fd5_draw.h
src/gallium/drivers/freedreno/freedreno_draw.c
src/gallium/drivers/freedreno/freedreno_draw.h

index 4f3161908847613a40bb0c18f6dd72b9cd5169dd..f7915d66c1aa14f7321d8b5f91a43daa067e151e 100644 (file)
@@ -109,7 +109,7 @@ fd2_draw_vbo(struct fd_context *ctx, const struct pipe_draw_info *info,
        OUT_RING(ring, info->min_index);        /* VGT_MIN_VTX_INDX */
 
        fd_draw_emit(ctx->batch, ring, ctx->primtypes[info->mode],
-                                IGNORE_VISIBILITY, info);
+                                IGNORE_VISIBILITY, info, index_offset);
 
        OUT_PKT3(ring, CP_SET_CONSTANT, 2);
        OUT_RING(ring, CP_REG(REG_A2XX_UNKNOWN_2010));
index 270322453e50faf2354ac3dc0ac6a4d6d124b2bd..761f25bc0158a7f751803e6cc85a92f963b3afce 100644 (file)
@@ -55,7 +55,7 @@ add_sat(uint32_t a, int32_t b)
 
 static void
 draw_impl(struct fd_context *ctx, struct fd_ringbuffer *ring,
-               struct fd3_emit *emit)
+               struct fd3_emit *emit, unsigned index_offset)
 {
        const struct pipe_draw_info *info = emit->info;
        enum pc_di_primtype primtype = ctx->primtypes[info->mode];
@@ -86,7 +86,7 @@ draw_impl(struct fd_context *ctx, struct fd_ringbuffer *ring,
 
        fd_draw_emit(ctx->batch, ring, primtype,
                        emit->key.binning_pass ? IGNORE_VISIBILITY : USE_VISIBILITY,
-                       info);
+                       info, index_offset);
 }
 
 /* fixup dirty shader state in case some "unrelated" (from the state-
@@ -157,14 +157,14 @@ fd3_draw_vbo(struct fd_context *ctx, const struct pipe_draw_info *info,
 
        emit.key.binning_pass = false;
        emit.dirty = dirty;
-       draw_impl(ctx, ctx->batch->draw, &emit);
+       draw_impl(ctx, ctx->batch->draw, &emit, index_offset);
 
        /* and now binning pass: */
        emit.key.binning_pass = true;
        emit.dirty = dirty & ~(FD_DIRTY_BLEND);
        emit.vp = NULL;   /* we changed key so need to refetch vp */
        emit.fp = NULL;
-       draw_impl(ctx, ctx->batch->binning, &emit);
+       draw_impl(ctx, ctx->batch->binning, &emit, index_offset);
 
        fd_context_all_clean(ctx);
 
index 950675f43ffc4af60e3ffa60cb7c8484d859d460..842a952719b38214658b8082d580d80e6a9b8062 100644 (file)
@@ -105,7 +105,7 @@ fd4_draw_emit(struct fd_batch *batch, struct fd_ringbuffer *ring,
                enum pc_di_primtype primtype,
                enum pc_di_vis_cull_mode vismode,
                const struct pipe_draw_info *info,
-                unsigned index_offset)
+               unsigned index_offset)
 {
        struct pipe_resource *idx_buffer = NULL;
        enum a4xx_index_size idx_type;
index 5baf1676f15a2bc0e84a451555739869c233a303..de210e456546d21316e56b7404a157824651be00 100644 (file)
@@ -81,7 +81,7 @@ fd5_draw_emit(struct fd_batch *batch, struct fd_ringbuffer *ring,
                enum pc_di_primtype primtype,
                enum pc_di_vis_cull_mode vismode,
                const struct pipe_draw_info *info,
-                unsigned index_offset)
+               unsigned index_offset)
 {
        struct pipe_resource *idx_buffer = NULL;
        enum a4xx_index_size idx_type;
index 1d86a49dd4509f6b9114964bc29f04916a0a8548..08cba77751061bcc2f5d2b6a79f40e0c41b53632 100644 (file)
@@ -91,11 +91,20 @@ fd_draw_vbo(struct pipe_context *pctx, const struct pipe_draw_info *info)
        }
 
        /* Upload a user index buffer. */
-       struct pipe_resource *indexbuf = info->has_user_indices ? NULL : info->index.resource;
-        unsigned index_offset = 0;
-       if (info->index_size && info->has_user_indices &&
-           !util_upload_index_buffer(pctx, info, &indexbuf, &index_offset)) {
-               return;
+       struct pipe_resource *indexbuf = NULL;
+       unsigned index_offset = 0;
+       struct pipe_draw_info new_info;
+       if (info->index_size) {
+               if (info->has_user_indices) {
+                       if (!util_upload_index_buffer(pctx, info, &indexbuf, &index_offset))
+                               return;
+                       new_info = *info;
+                       new_info.index.resource = indexbuf;
+                       new_info.has_user_indices = false;
+                       info = &new_info;
+               } else {
+                       indexbuf = info->index.resource;
+               }
        }
 
        if (ctx->in_blit) {
@@ -224,7 +233,8 @@ fd_draw_vbo(struct pipe_context *pctx, const struct pipe_draw_info *info)
                fd_context_all_dirty(ctx);
 
        fd_batch_check_size(batch);
-       if (info->index_size && indexbuf != info->index.resource)
+
+       if (info == &new_info)
                pipe_resource_reference(&indexbuf, NULL);
 }
 
index f2163bb10d1c564e6306c6bf26290c9369f2c0eb..b293f73b82ed4f4f89f037df3d7f5d084d97db9b 100644 (file)
@@ -115,7 +115,8 @@ static inline void
 fd_draw_emit(struct fd_batch *batch, struct fd_ringbuffer *ring,
                enum pc_di_primtype primtype,
                enum pc_di_vis_cull_mode vismode,
-               const struct pipe_draw_info *info)
+               const struct pipe_draw_info *info,
+               unsigned index_offset)
 {
        struct pipe_resource *idx_buffer = NULL;
        enum pc_di_index_size idx_type = INDEX_SIZE_IGN;
@@ -128,7 +129,7 @@ fd_draw_emit(struct fd_batch *batch, struct fd_ringbuffer *ring,
                idx_buffer = info->index.resource;
                idx_type = size2indextype(info->index_size);
                idx_size = info->index_size * info->count;
-               idx_offset = info->start * info->index_size;
+               idx_offset = index_offset + info->start * info->index_size;
                src_sel = DI_SRC_SEL_DMA;
        } else {
                idx_buffer = NULL;