From: Pierre-Eric Pelloux-Prayer Date: Tue, 15 Jun 2021 13:43:57 +0000 (+0200) Subject: dlist: use an union instead of allocating a 1-sized array X-Git-Tag: upstream/21.2.3~680 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b328d8e9bc9900a0372d7c3307f18ad11d708af9;p=platform%2Fupstream%2Fmesa.git dlist: use an union instead of allocating a 1-sized array Reviewed-by: Marek Olšák Part-of: --- diff --git a/src/mesa/main/dlist.c b/src/mesa/main/dlist.c index d86fcbb..b43b383 100644 --- a/src/mesa/main/dlist.c +++ b/src/mesa/main/dlist.c @@ -800,8 +800,10 @@ vbo_destroy_vertex_list(struct gl_context *ctx, struct vbo_save_vertex_list *nod free(node->prim_store); } - free(node->merged.mode); - free(node->merged.start_count); + if (node->merged.mode) { + free(node->merged.mode); + free(node->merged.start_counts); + } _mesa_reference_buffer_object(ctx, &node->merged.ib.obj, NULL); free(node->current_data); diff --git a/src/mesa/vbo/vbo_save.h b/src/mesa/vbo/vbo_save.h index 0a0eaeb..ca592a3 100644 --- a/src/mesa/vbo/vbo_save.h +++ b/src/mesa/vbo/vbo_save.h @@ -72,7 +72,10 @@ struct vbo_save_vertex_list { struct _mesa_index_buffer ib; struct pipe_draw_info info; unsigned char *mode; - struct pipe_draw_start_count_bias *start_count; + union { + struct pipe_draw_start_count_bias *start_counts; + struct pipe_draw_start_count_bias start_count; + }; unsigned num_draws; } merged; diff --git a/src/mesa/vbo/vbo_save_api.c b/src/mesa/vbo/vbo_save_api.c index e69f543..ed8d529 100644 --- a/src/mesa/vbo/vbo_save_api.c +++ b/src/mesa/vbo/vbo_save_api.c @@ -809,20 +809,21 @@ compile_vertex_list(struct gl_context *ctx) node->merged.info.index_size = 4; node->merged.info.instance_count = 1; node->merged.info.index.gl_bo = node->merged.ib.obj; - node->merged.start_count = malloc(merged_prim_count * sizeof(struct pipe_draw_start_count_bias)); if (merged_prim_count == 1) { node->merged.info.mode = merged_prims[0].mode; + node->merged.start_count.start = merged_prims[0].start; + node->merged.start_count.count = merged_prims[0].count; + node->merged.start_count.index_bias = 0; node->merged.mode = NULL; } else { node->merged.mode = malloc(merged_prim_count * sizeof(unsigned char)); - } - - for (unsigned i = 0; i < merged_prim_count; i++) { - node->merged.start_count[i].start = merged_prims[i].start; - node->merged.start_count[i].count = merged_prims[i].count; - node->merged.start_count[i].index_bias = 0; - if (merged_prim_count > 1) + node->merged.start_counts = malloc(merged_prim_count * sizeof(struct pipe_draw_start_count_bias)); + for (unsigned i = 0; i < merged_prim_count; i++) { + node->merged.start_counts[i].start = merged_prims[i].start; + node->merged.start_counts[i].count = merged_prims[i].count; + node->merged.start_counts[i].index_bias = 0; node->merged.mode[i] = merged_prims[i].mode; + } } node->merged.num_draws = merged_prim_count; if (node->merged.num_draws > 1) { diff --git a/src/mesa/vbo/vbo_save_draw.c b/src/mesa/vbo/vbo_save_draw.c index 330a3a8..104b0bf 100644 --- a/src/mesa/vbo/vbo_save_draw.c +++ b/src/mesa/vbo/vbo_save_draw.c @@ -232,14 +232,15 @@ vbo_save_playback_vertex_list(struct gl_context *ctx, void *data) info->vertices_per_patch = ctx->TessCtrlProgram.patch_vertices; void *gl_bo = info->index.gl_bo; if (node->merged.mode) { + assert(node->merged.mode); ctx->Driver.DrawGalliumMultiMode(ctx, info, 0, - node->merged.start_count, - node->merged.mode, - node->merged.num_draws); + node->merged.start_counts, + node->merged.mode, + node->merged.num_draws); } else if (node->merged.num_draws) { - ctx->Driver.DrawGallium(ctx, info, 0, - node->merged.start_count, - node->merged.num_draws); + /* If node->merged.mode is NULL then num_draws is 0 or 1 */ + assert (node->merged.num_draws == 1); + ctx->Driver.DrawGallium(ctx, info, 0, &node->merged.start_count, 1); } info->index.gl_bo = gl_bo; }