Best possible score with more planes than layers

When calculating the best possible score (used to stop early when we're
found an allocation we can't beat), take into account the number of
remaining layers.  If we have more planes than layers then the best
possible score might be limited by the number of layers, not the number
of planes.

Before this patch, `bench -p 15 -l 5` does 340390 atomic test commits
After this patch, `bench -p 15 -l 5` does 15 atomic test commits
This commit is contained in:
David Turner 2023-12-20 13:50:37 +00:00
parent 98ef9e52d4
commit 4cd2c4defd

38
alloc.c
View file

@ -442,6 +442,38 @@ count_remaining_compatible_planes(struct liftoff_output *output,
return remaining; return remaining;
} }
static int
calculate_best_possible_score(struct liftoff_output *output, struct alloc_result *result,
struct alloc_step *step)
{
struct liftoff_layer *layer;
int remaining_planes, remaining_layers, remaining_allocs;
remaining_planes = count_remaining_compatible_planes(output, step);
/* Count number of remaining scoring layers */
remaining_layers = 0;
liftoff_list_for_each(layer, &output->layers, link) {
/* Allocated layers are already included in current score */
if (is_layer_allocated(step, layer)) {
continue;
}
/* Invisible layers won't be allocated */
if (!layer_is_visible(layer)) {
continue;
}
/* Composition layer isn't included in the score */
if (layer == output->composition_layer) {
continue;
}
remaining_layers++;
}
remaining_allocs = remaining_layers < remaining_planes
? remaining_layers : remaining_planes;
return step->score + remaining_allocs;
}
static int static int
output_choose_layers(struct liftoff_output *output, struct alloc_result *result, output_choose_layers(struct liftoff_output *output, struct alloc_result *result,
struct alloc_step *step) struct alloc_step *step)
@ -450,7 +482,7 @@ output_choose_layers(struct liftoff_output *output, struct alloc_result *result,
struct liftoff_plane *plane; struct liftoff_plane *plane;
struct liftoff_layer *layer; struct liftoff_layer *layer;
int cursor, ret; int cursor, ret;
int remaining_planes; int best_possible_score;
struct alloc_step next_step = {0}; struct alloc_step next_step = {0};
device = output->device; device = output->device;
@ -471,8 +503,8 @@ output_choose_layers(struct liftoff_output *output, struct alloc_result *result,
plane = liftoff_container_of(step->plane_link, plane, link); plane = liftoff_container_of(step->plane_link, plane, link);
remaining_planes = count_remaining_compatible_planes(output, step); best_possible_score = calculate_best_possible_score(output, result, step);
if (result->best_score >= step->score + remaining_planes) { if (result->best_score >= best_possible_score) {
/* Even if we find a layer for all remaining planes, we won't /* Even if we find a layer for all remaining planes, we won't
* find a better allocation. Give up. */ * find a better allocation. Give up. */
return 0; return 0;