util/rect_union: Take pixman_box32_t by pointer

rect_union_add takes a pixman_box32_t by value, and passes it along by
value to internal helpers. render_pass_mark_box_updated which is the
only caller receives the pixman_box32_t by reference, so just plumb it
through that way.

Results in a 13% improvement in CPU time when using the Vulkan renderer
on the stacked/clip200/1024 benchmarks on my machine.

Signed-off-by: Kenny Levinsen <kl@kl.wtf>
This commit is contained in:
Kenny Levinsen 2026-04-23 16:47:40 +02:00 committed by Félix Poisot
parent 8abe53d1d2
commit 17c29268c9
3 changed files with 12 additions and 12 deletions

View file

@ -58,7 +58,7 @@ void rect_union_finish(struct rect_union *r);
* *
* Amortized time: O(1) * Amortized time: O(1)
*/ */
void rect_union_add(struct rect_union *r, pixman_box32_t box); 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 * Compute an exact cover of the rectangles added so far, and return

View file

@ -634,7 +634,7 @@ static void render_pass_mark_box_updated(struct wlr_vk_render_pass *pass,
if (!pass->two_pass) { if (!pass->two_pass) {
return; return;
} }
rect_union_add(&pass->updated_region, *box); rect_union_add(&pass->updated_region, box);
} }
static void render_pass_add_rect(struct wlr_render_pass *wlr_pass, static void render_pass_add_rect(struct wlr_render_pass *wlr_pass,

View file

@ -1,15 +1,15 @@
#include <limits.h> #include <limits.h>
#include "util/rect_union.h" #include "util/rect_union.h"
static void box_union(pixman_box32_t *dst, pixman_box32_t box) { static void box_union(pixman_box32_t *dst, const pixman_box32_t *box) {
dst->x1 = dst->x1 < box.x1 ? dst->x1 : box.x1; dst->x1 = dst->x1 < box->x1 ? dst->x1 : box->x1;
dst->y1 = dst->y1 < box.y1 ? dst->y1 : box.y1; dst->y1 = dst->y1 < box->y1 ? dst->y1 : box->y1;
dst->x2 = dst->x2 > box.x2 ? dst->x2 : box.x2; dst->x2 = dst->x2 > box->x2 ? dst->x2 : box->x2;
dst->y2 = dst->y2 > box.y2 ? dst->y2 : box.y2; dst->y2 = dst->y2 > box->y2 ? dst->y2 : box->y2;
} }
static bool box_empty_or_invalid(pixman_box32_t box) { static bool box_empty_or_invalid(const pixman_box32_t *box) {
return box.x1 >= box.x2 || box.y1 >= box.y2; return box->x1 >= box->x2 || box->y1 >= box->y2;
} }
void rect_union_init(struct rect_union *ru) { void rect_union_init(struct rect_union *ru) {
@ -37,7 +37,7 @@ static void handle_alloc_failure(struct rect_union *ru) {
wl_array_init(&ru->unsorted); wl_array_init(&ru->unsorted);
} }
void rect_union_add(struct rect_union *ru, pixman_box32_t box) { void rect_union_add(struct rect_union *ru, const pixman_box32_t *box) {
if (box_empty_or_invalid(box)) { if (box_empty_or_invalid(box)) {
return; return;
} }
@ -47,7 +47,7 @@ void rect_union_add(struct rect_union *ru, pixman_box32_t box) {
if (!ru->alloc_failure) { if (!ru->alloc_failure) {
pixman_box32_t *entry = wl_array_add(&ru->unsorted, sizeof(*entry)); pixman_box32_t *entry = wl_array_add(&ru->unsorted, sizeof(*entry));
if (entry) { if (entry) {
*entry = box; *entry = *box;
} else { } else {
handle_alloc_failure(ru); handle_alloc_failure(ru);
} }
@ -81,7 +81,7 @@ const pixman_region32_t *rect_union_evaluate(struct rect_union *ru) {
return &ru->region; return &ru->region;
bounding_box: bounding_box:
pixman_region32_fini(&ru->region); pixman_region32_fini(&ru->region);
if (box_empty_or_invalid(ru->bounding_box)) { if (box_empty_or_invalid(&ru->bounding_box)) {
pixman_region32_init(&ru->region); pixman_region32_init(&ru->region);
} else { } else {
pixman_region32_init_with_extents(&ru->region, &ru->bounding_box); pixman_region32_init_with_extents(&ru->region, &ru->bounding_box);