From 17c29268c94e7d222f87d58d9597c8d83883339e Mon Sep 17 00:00:00 2001 From: Kenny Levinsen Date: Thu, 23 Apr 2026 16:47:40 +0200 Subject: [PATCH] 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 --- include/util/rect_union.h | 2 +- render/vulkan/pass.c | 2 +- util/rect_union.c | 20 ++++++++++---------- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/include/util/rect_union.h b/include/util/rect_union.h index 2d74f94d5..c4b378888 100644 --- a/include/util/rect_union.h +++ b/include/util/rect_union.h @@ -58,7 +58,7 @@ void rect_union_finish(struct rect_union *r); * * 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 diff --git a/render/vulkan/pass.c b/render/vulkan/pass.c index fe1b37ff0..b250543ce 100644 --- a/render/vulkan/pass.c +++ b/render/vulkan/pass.c @@ -634,7 +634,7 @@ static void render_pass_mark_box_updated(struct wlr_vk_render_pass *pass, if (!pass->two_pass) { 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, diff --git a/util/rect_union.c b/util/rect_union.c index 8cd26d761..8d29798de 100644 --- a/util/rect_union.c +++ b/util/rect_union.c @@ -1,15 +1,15 @@ #include #include "util/rect_union.h" -static void box_union(pixman_box32_t *dst, pixman_box32_t box) { - dst->x1 = dst->x1 < box.x1 ? dst->x1 : box.x1; - dst->y1 = dst->y1 < box.y1 ? dst->y1 : box.y1; - dst->x2 = dst->x2 > box.x2 ? dst->x2 : box.x2; - dst->y2 = dst->y2 > box.y2 ? dst->y2 : box.y2; +static void box_union(pixman_box32_t *dst, const pixman_box32_t *box) { + dst->x1 = dst->x1 < box->x1 ? dst->x1 : box->x1; + dst->y1 = dst->y1 < box->y1 ? dst->y1 : box->y1; + dst->x2 = dst->x2 > box->x2 ? dst->x2 : box->x2; + dst->y2 = dst->y2 > box->y2 ? dst->y2 : box->y2; } -static bool box_empty_or_invalid(pixman_box32_t box) { - return box.x1 >= box.x2 || box.y1 >= box.y2; +static bool box_empty_or_invalid(const pixman_box32_t *box) { + return box->x1 >= box->x2 || box->y1 >= box->y2; } 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); } -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)) { return; } @@ -47,7 +47,7 @@ void rect_union_add(struct rect_union *ru, pixman_box32_t box) { if (!ru->alloc_failure) { pixman_box32_t *entry = wl_array_add(&ru->unsorted, sizeof(*entry)); if (entry) { - *entry = box; + *entry = *box; } else { handle_alloc_failure(ru); } @@ -81,7 +81,7 @@ const pixman_region32_t *rect_union_evaluate(struct rect_union *ru) { return &ru->region; bounding_box: 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); } else { pixman_region32_init_with_extents(&ru->region, &ru->bounding_box);