util/rect_union: Limit rect_union_add to 1024 rects

If a very large number of clip rects are accumulated in rect_union_add,
rect_union_evaluate can end up being disproportionately expensive, and
as an extreme numbers of clip rects are not beneficial for drawing, this
is without any benefit.

Limit the number of rects to 1024 in rect_union_add, switching over to
bounding box mode instead when the limit is exceeded. This leads to a
small 70% reduction in CPU time in the Vulkan renderer on the
stacked/clip200/1024 benchmarks.

Signed-off-by: Kenny Levinsen <kl@kl.wtf>
This commit is contained in:
Kenny Levinsen 2026-04-23 17:15:28 +02:00 committed by Félix Poisot
parent 17c29268c9
commit 57441ded02
2 changed files with 19 additions and 9 deletions

View file

@ -63,8 +63,10 @@ void rect_union_add(struct rect_union *r, const pixman_box32_t *box);
/**
* Compute an exact cover of the rectangles added so far, and return
* a pointer to a pixman_region32_t giving that cover. The pointer will
* remain valid until the next time *r is modified. If there was an allocation
* failure, this function may return a single-rectangle bounding box instead.
* remain valid until the next time *r is modified.
*
* An internal complexity limit is enforced by rect_union. If exceeded, this
* function will instead return a single-rectangle bounding box.
*
* This may be called multiple times and interleaved with rect_union_add().
*