From 172d4bccd29c71f21ed1d5fec524cd7bb9608cad Mon Sep 17 00:00:00 2001 From: Boris Brezillon Date: Wed, 15 Nov 2023 14:39:43 +0100 Subject: [PATCH] panfrost: Factor out the vertex count logic Makes panfrost_direct_draw() shorter and thus easier to read. Signed-off-by: Boris Brezillon Reviewed-by: Erik Faye-Lund Part-of: --- src/gallium/drivers/panfrost/pan_cmdstream.c | 87 +++++++++++--------- 1 file changed, 50 insertions(+), 37 deletions(-) diff --git a/src/gallium/drivers/panfrost/pan_cmdstream.c b/src/gallium/drivers/panfrost/pan_cmdstream.c index cecc3d27978..8f8bb3148c0 100644 --- a/src/gallium/drivers/panfrost/pan_cmdstream.c +++ b/src/gallium/drivers/panfrost/pan_cmdstream.c @@ -3576,6 +3576,54 @@ panfrost_update_point_sprite_shader(struct panfrost_context *ctx, } } +static unsigned +panfrost_draw_get_vertex_count(struct panfrost_batch *batch, + const struct pipe_draw_info *info, + const struct pipe_draw_start_count_bias *draw, + bool idvs) +{ + struct panfrost_context *ctx = batch->ctx; + unsigned vertex_count = ctx->vertex_count; + unsigned min_index = 0, max_index = 0; + + batch->indices = 0; + if (info->index_size && PAN_ARCH >= 9) { + batch->indices = panfrost_get_index_buffer(batch, info, draw); + + /* Use index count to estimate vertex count */ + panfrost_increase_vertex_count(batch, draw->count); + } else if (info->index_size) { + batch->indices = panfrost_get_index_buffer_bounded( + batch, info, draw, &min_index, &max_index); + + /* Use the corresponding values */ + vertex_count = max_index - min_index + 1; + ctx->offset_start = min_index + draw->index_bias; + panfrost_increase_vertex_count(batch, vertex_count); + } else { + ctx->offset_start = draw->start; + panfrost_increase_vertex_count(batch, vertex_count); + } + + if (info->instance_count > 1) { + unsigned count = vertex_count; + + /* Index-Driven Vertex Shading requires different instances to + * have different cache lines for position results. Each vertex + * position is 16 bytes and the Mali cache line is 64 bytes, so + * the instance count must be aligned to 4 vertices. + */ + if (idvs) + count = ALIGN_POT(count, 4); + + ctx->padded_count = panfrost_padded_vertex_count(count); + } else { + ctx->padded_count = vertex_count; + } + + return vertex_count; +} + static void panfrost_direct_draw(struct panfrost_batch *batch, const struct pipe_draw_info *info, unsigned drawid_offset, @@ -3617,43 +3665,8 @@ panfrost_direct_draw(struct panfrost_batch *batch, tiler = pan_pool_alloc_desc(&batch->pool.base, TILER_JOB); } - unsigned vertex_count = ctx->vertex_count; - - unsigned min_index = 0, max_index = 0; - - batch->indices = 0; - if (info->index_size && PAN_ARCH >= 9) { - batch->indices = panfrost_get_index_buffer(batch, info, draw); - - /* Use index count to estimate vertex count */ - panfrost_increase_vertex_count(batch, draw->count); - } else if (info->index_size) { - batch->indices = panfrost_get_index_buffer_bounded( - batch, info, draw, &min_index, &max_index); - - /* Use the corresponding values */ - vertex_count = max_index - min_index + 1; - ctx->offset_start = min_index + draw->index_bias; - panfrost_increase_vertex_count(batch, vertex_count); - } else { - ctx->offset_start = draw->start; - panfrost_increase_vertex_count(batch, vertex_count); - } - - if (info->instance_count > 1) { - unsigned count = vertex_count; - - /* Index-Driven Vertex Shading requires different instances to - * have different cache lines for position results. Each vertex - * position is 16 bytes and the Mali cache line is 64 bytes, so - * the instance count must be aligned to 4 vertices. - */ - if (idvs) - count = ALIGN_POT(count, 4); - - ctx->padded_count = panfrost_padded_vertex_count(count); - } else - ctx->padded_count = vertex_count; + UNUSED unsigned vertex_count = + panfrost_draw_get_vertex_count(batch, info, draw, idvs); panfrost_statistics_record(ctx, info, draw);