render: add support for clearing render passes

introduces a new `wlr_render_pass_clear` function, allowing
render passes to be cleared with a solid color.
This commit is contained in:
YaoBing Xiao 2026-01-31 21:45:12 +08:00
parent 7cb4e30bfd
commit eeecb382cc
8 changed files with 120 additions and 8 deletions

View file

@ -943,13 +943,60 @@ static void render_pass_add_texture(struct wlr_render_pass *wlr_pass,
}
}
static void render_pass_clear(struct wlr_render_pass *wlr_pass,
const struct wlr_render_clear_options *options) {
struct wlr_vk_render_pass *pass = get_render_pass(wlr_pass);
VkCommandBuffer cb = pass->command_buffer->vk;
float linear_color[] = {
color_to_linear_premult(options->color.r, options->color.a),
color_to_linear_premult(options->color.g, options->color.a),
color_to_linear_premult(options->color.b, options->color.a),
options->color.a,
};
VkClearAttachment clear_att = {
.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
.colorAttachment = 0,
.clearValue.color.float32 = {
linear_color[0],
linear_color[1],
linear_color[2],
linear_color[3],
},
};
pixman_region32_t clip;
get_clip_region(pass, options->clip, &clip);
int clip_rects_len;
const pixman_box32_t *clip_rects = pixman_region32_rectangles(&clip, &clip_rects_len);
VkClearRect clear_rect = {
.layerCount = 1,
};
for (int i = 0; i < clip_rects_len; i++) {
convert_pixman_box_to_vk_rect(&clip_rects[i], &clear_rect.rect);
vkCmdClearAttachments(cb, 1, &clear_att, 1, &clear_rect);
struct wlr_box box = {
.x = clip_rects[i].x1,
.y = clip_rects[i].y1,
.width = clip_rects[i].x2 - clip_rects[i].x1,
.height = clip_rects[i].y2 - clip_rects[i].y1,
};
render_pass_mark_box_updated(pass, &box);
}
pixman_region32_fini(&clip);
}
static const struct wlr_render_pass_impl render_pass_impl = {
.submit = render_pass_submit,
.add_rect = render_pass_add_rect,
.add_texture = render_pass_add_texture,
.clear = render_pass_clear,
};
void vk_color_transform_destroy(struct wlr_addon *addon) {
struct wlr_vk_renderer *renderer = (struct wlr_vk_renderer *)addon->owner;
struct wlr_vk_color_transform *transform = wl_container_of(addon, transform, addon);