dlist: use an union instead of allocating a 1-sized array

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11493>
This commit is contained in:
Pierre-Eric Pelloux-Prayer 2021-06-15 15:43:57 +02:00 committed by Marge Bot
parent 33fe403ccd
commit b328d8e9bc
4 changed files with 24 additions and 17 deletions

View File

@ -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);

View File

@ -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;

View File

@ -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) {

View File

@ -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;
}