panfrost: Estimate vertex count for hier mask

In the next commit, we will refine our algorithm to select hierarchy masks based
on the vertex count. In preparation, augment the driver to track rough estimates
of the vertex count so we have a "geometry complexity" input for the heuristic.

Signed-off-by: Alyssa Rosenzweig <alyssa@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19482>
This commit is contained in:
Alyssa Rosenzweig 2023-03-15 21:35:29 -04:00 committed by Marge Bot
parent cabed30111
commit 1887b26845
4 changed files with 34 additions and 7 deletions

View file

@ -3519,6 +3519,21 @@ panfrost_launch_xfb(struct panfrost_batch *batch,
batch->push_uniforms[PIPE_SHADER_VERTEX] = saved_push;
}
/*
* Increase the vertex count on the batch using a saturating add, and hope the
* compiler can use the machine instruction here...
*/
static inline void
panfrost_increase_vertex_count(struct panfrost_batch *batch, uint32_t increment)
{
uint32_t sum = batch->tiler_ctx.vertex_count + increment;
if (sum >= batch->tiler_ctx.vertex_count)
batch->tiler_ctx.vertex_count = sum;
else
batch->tiler_ctx.vertex_count = UINT32_MAX;
}
static void
panfrost_direct_draw(struct panfrost_batch *batch,
const struct pipe_draw_info *info, unsigned drawid_offset,
@ -3578,6 +3593,9 @@ panfrost_direct_draw(struct panfrost_batch *batch,
if (info->index_size && PAN_ARCH >= 9) {
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) {
indices = panfrost_get_index_buffer_bounded(batch, info, draw, &min_index,
&max_index);
@ -3585,8 +3603,10 @@ panfrost_direct_draw(struct panfrost_batch *batch,
/* 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) {
@ -4476,7 +4496,8 @@ batch_get_polygon_list(struct panfrost_batch *batch)
if (!batch->tiler_ctx.midgard.polygon_list) {
bool has_draws = batch->scoreboard.first_tiler != NULL;
unsigned size = panfrost_tiler_get_polygon_list_size(
dev, batch->key.width, batch->key.height, has_draws);
dev, batch->key.width, batch->key.height,
batch->tiler_ctx.vertex_count);
/* Create the BO as invisible if we can. If there are no draws,
* we need to write the polygon list manually because there's

View file

@ -624,8 +624,8 @@ pan_emit_midgard_tiler(const struct panfrost_device *dev,
cfg.heap_start = tiler_ctx->midgard.polygon_list->ptr.gpu;
cfg.heap_end = tiler_ctx->midgard.polygon_list->ptr.gpu;
} else {
cfg.hierarchy_mask =
panfrost_choose_hierarchy_mask(fb->width, fb->height, 1, hierarchy);
cfg.hierarchy_mask = panfrost_choose_hierarchy_mask(
fb->width, fb->height, tiler_ctx->vertex_count, hierarchy);
header_size = panfrost_tiler_header_size(
fb->width, fb->height, cfg.hierarchy_mask, hierarchy);
cfg.polygon_list_size = panfrost_tiler_full_size(

View file

@ -69,6 +69,12 @@ struct pan_fb_zs_attachment {
};
struct pan_tiler_context {
/* Sum of vertex counts (for non-indexed draws), index counts (for
* indexed draws on Valhall as a best effort), or ~0 if any indirect
* draws are used. Helps tune hierarchy masks.
*/
uint32_t vertex_count;
union {
mali_ptr bifrost;
struct {

View file

@ -50,14 +50,14 @@ unsigned panfrost_choose_hierarchy_mask(unsigned width, unsigned height,
static inline unsigned
panfrost_tiler_get_polygon_list_size(const struct panfrost_device *dev,
unsigned fb_width, unsigned fb_height,
bool has_draws)
unsigned vertex_count)
{
if (!has_draws)
if (!vertex_count)
return MALI_MIDGARD_TILER_MINIMUM_HEADER_SIZE + 4;
bool hierarchy = !dev->model->quirks.no_hierarchical_tiling;
unsigned hierarchy_mask =
panfrost_choose_hierarchy_mask(fb_width, fb_height, 1, hierarchy);
unsigned hierarchy_mask = panfrost_choose_hierarchy_mask(
fb_width, fb_height, vertex_count, hierarchy);
return panfrost_tiler_full_size(fb_width, fb_height, hierarchy_mask,
hierarchy) +