Skip to content

blur: rendering time improvements#151

Closed
the-eater wants to merge 7 commits intowlrfx:mainfrom
the-eater:blur-performance
Closed

blur: rendering time improvements#151
the-eater wants to merge 7 commits intowlrfx:mainfrom
the-eater:blur-performance

Conversation

@the-eater
Copy link
Copy Markdown
Member

Adds a few more API breaks but also should allow to get some performance time back by allowing sources to define the opaque region, allowing us to render, Less

most of it was recommended by @ErikReider, and it seems to work well

Comment thread tinywl/tinywl.c Outdated
Comment thread types/scene/wlr_scene.c Outdated
@WillPower3309
Copy link
Copy Markdown
Member

WillPower3309 commented Nov 11, 2025

I think we already get this for free somewhere with https://github.com/wlrfx/scenefx/blob/main/types/scene/wlr_scene.c#L297, let me double check the rendering loop in wlr_scene.c

@the-eater the-eater requested a review from ErikReider November 18, 2025 22:11
@the-eater the-eater force-pushed the blur-performance branch 2 times, most recently from 3d8b3bd to 91a8fcd Compare November 18, 2025 22:53
@DreamMaoMao
Copy link
Copy Markdown
Contributor

DreamMaoMao commented Nov 19, 2025

The lag caused by blur has disappeared in the latest commit

@the-eater the-eater mentioned this pull request Nov 19, 2025
3 tasks
@WillPower3309 WillPower3309 linked an issue Jan 1, 2026 that may be closed by this pull request
3 tasks
Comment on lines +192 to +196
struct linked_node mask_source;
// store which node is stored with `mask_source`
// So we don't call `wlr_container_of` with the wrong type
enum wlr_scene_node_type mask_node_type;
enum blur_mask_type mask_type;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be wrapped in struct {...} WLR_PRIVATE;

bool link_tex_program(struct tex_shader *shader, GLint client_version, enum fx_tex_shader_source source) {
GLchar frag_src_part[2048];
GLchar frag_src[4096];
bool link_tex_program(struct tex_shader *shader, GLint client_version, enum fx_tex_shader_source source, bool has_clip) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Maybe shorten the line with a line break? (also make sure that you're using tabs as stated in the .editorconfig file 😄)

Comment thread types/scene/wlr_scene.c
blur->corners = CORNER_LOCATION_NONE;
blur->should_only_blur_bottom_layer = false;
blur->transparency_mask_source = linked_node_init();;
blur->mask_source = linked_node_init();;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably initialize mask_type as well, and what's with the ;;?

Comment thread types/scene/wlr_scene.c
}

void wlr_scene_blur_set_mask_source(struct wlr_scene_blur *blur,
struct wlr_scene_node *source, enum blur_mask_type mask_type) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Use tabs as specified in the .editorconfig

/**
* Set the transparency mask source for the blur, only rendering blur where the
* Mask source is actually rendering (e.g. skip transparent spaces)
* Set the mask source for the blur, reducing rendering area based on mask type
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should document that only scene_buffers and rects are supported

Comment thread types/scene/wlr_scene.c
}
}

void wlr_scene_blur_set_mask_source(struct wlr_scene_blur *blur,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd split this up into two functions, one for setting mask_source and one for setting the mask type. Would really simplify the logic here :)

Something like this:

void wlr_scene_blur_set_mask_source(struct wlr_scene_blur *blur,
		struct wlr_scene_node *source) {

	struct linked_node *linked_node = get_blur_linked_node_for_node(source);
	if (source && !linked_node) {
		wlr_log(WLR_ERROR, "Masking blur is only supported for "
				" wlr_scene_buffer and wlr_scene_rect sources. Keeping old source");
		return;
	}

	// Already linked
	if (linked_node && linked_nodes_are_linked(&blur->mask_source, linked_node)) {
		return;
	}

	linked_node_destroy(&blur->mask_source);
	if (linked_node != NULL) {
		linked_node_destroy(linked_node);

		blur->mask_node_type = source->type;
		linked_node_init_link(&blur->mask_source, linked_node);
	}

	scene_node_update(&blur->node, NULL);
}

void wlr_scene_blur_set_mask_type(struct wlr_scene_blur *blur,
		enum blur_mask_type mask_type) {
	if (blur->mask_type == mask_type) {
		return;
	}
	blur->mask_type = mask_type;

	// Only update when the mask type is NONE, or when there's a mask
	// source present
	if (mask_type == BLUR_MASK_NONE
			|| linked_nodes_get_sibling(&blur->mask_source)) {
		scene_node_update(&blur->node, NULL);
	}
}

Comment on lines +172 to +178
enum blur_mask_type {
BLUR_MASK_NONE = 0,
BLUR_MASK_IGNORE_TRANSPARENCY = 1,
BLUR_MASK_OPAQUE_REGION = 2,
BLUR_MASK_ALL = INT_MAX,
};

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: tabs

Comment thread types/scene/wlr_scene.c
if (pixman_region32_empty(&blur_render_area)) {
pixman_region32_fini(&opaque_region);
pixman_region32_fini(&blur_render_area);
break;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic should also only be handled in the scene_node_opaque_region function to make our lives easier :)

@ErikReider
Copy link
Copy Markdown
Member

ErikReider commented Jan 19, 2026

The lag caused by blur has disappeared in the latest commit

Is this still the case with the lastest changes in main? Trying to reproduce, but can't see any performance difference in Tracy

Edit: Nvm. I managed to reproduce this by setting this env variable AMD_CU_MASK=0x3 (reduces the number of used AMD GPU CUs) and limited my GPU to 500MHz

image image

Edit 2: Here's with all the calls to corner_alpha removed:

image

@WillPower3309
Copy link
Copy Markdown
Member

Thanks for the work here! I think #170 applies the fix here, which will probably itself be replaced by #178

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

blur: issue master issue

4 participants