From 2692fa1b61058946151d045fa3b0b1e67fd48a9a Mon Sep 17 00:00:00 2001 From: Boris Brezillon Date: Mon, 18 Sep 2023 11:48:25 +0200 Subject: [PATCH 56/64] panfrost: Move vertex_count calculation out of panfrost_direct_draw() --- src/gallium/drivers/panfrost/pan_cmdstream.c | 94 +++++++++++--------- 1 file changed, 54 insertions(+), 40 deletions(-) diff --git a/src/gallium/drivers/panfrost/pan_cmdstream.c b/src/gallium/drivers/panfrost/pan_cmdstream.c index 519f44ef7a1..af9d9a65f43 100644 --- a/src/gallium/drivers/panfrost/pan_cmdstream.c +++ b/src/gallium/drivers/panfrost/pan_cmdstream.c @@ -4001,6 +4001,57 @@ panfrost_launch_grid(struct pipe_context *pipe, panfrost_flush_all_batches(ctx, "Launch grid post-barrier"); } +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, + mali_ptr *indices, bool idvs) +{ + struct panfrost_context *ctx = batch->ctx; + unsigned vertex_count = ctx->vertex_count; + unsigned min_index = 0, max_index = 0; + + *indices = 0; + if (info->index_size && PAN_ARCH >= 9) { + *indices = panfrost_get_index_buffer(batch, info, draw); + + /* Use index count to estimate vertex count */ + if (!PAN_USE_CSF) + panfrost_increase_vertex_count(batch, draw->count); + } else if (info->index_size) { + *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; + + if (!PAN_USE_CSF) + panfrost_increase_vertex_count(batch, vertex_count); + } + + if (!PAN_USE_CSF && 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; +} + /* * Entrypoint for draws on JM/CSF Mali. Depending on generation, this requires * emitting jobs for indirect drawing, transform feedback, vertex shading, and @@ -4057,46 +4108,9 @@ panfrost_direct_draw(struct panfrost_batch *batch, #endif } - unsigned vertex_count = ctx->vertex_count; - - unsigned min_index = 0, max_index = 0; - mali_ptr indices = 0; - - if (info->index_size && PAN_ARCH >= 9) { - indices = panfrost_get_index_buffer(batch, info, draw); - - /* Use index count to estimate vertex count */ - if (!PAN_USE_CSF) - panfrost_increase_vertex_count(batch, draw->count); - } else if (info->index_size) { - 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; - - if (!PAN_USE_CSF) - panfrost_increase_vertex_count(batch, vertex_count); - } - - if (!PAN_USE_CSF && 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; + mali_ptr indices; + UNUSED unsigned vertex_count = + panfrost_draw_get_vertex_count(batch, info, draw, &indices, idvs); panfrost_statistics_record(ctx, info, draw); -- 2.42.0