Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cache GLX fbconfigs #1190

Merged
merged 4 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

* Allow `corner-radius-rules` to override `corner-radius = 0`. Previously setting corner radius to 0 globally disables rounded corners. (#1170)

## Notable changes

* Marginally improve performance when resizing/opening/closing windows. (#1190)

# v11.2 (2024-Feb-13)

## Build changes
Expand Down
73 changes: 51 additions & 22 deletions src/backend/gl/glx.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <uthash.h>
#include <xcb/composite.h>
#include <xcb/xcb.h>

Expand Down Expand Up @@ -44,6 +45,13 @@
struct gl_data gl;
xcb_window_t target_win;
GLXContext ctx;
struct glx_fbconfig_cache *cached_fbconfigs;
};

struct glx_fbconfig_cache {
UT_hash_handle hh;
struct xvisual_info visual_info;
struct glx_fbconfig_info info;
};

#define glXGetFBConfigAttribChecked(a, b, attr, c) \
Expand All @@ -54,9 +62,12 @@
} \
} while (0)

struct glx_fbconfig_info *glx_find_fbconfig(struct x_connection *c, struct xvisual_info m) {
log_debug("Looking for FBConfig for RGBA%d%d%d%d, depth %d", m.red_size,
m.blue_size, m.green_size, m.alpha_size, m.visual_depth);
bool glx_find_fbconfig(struct x_connection *c, struct xvisual_info m,

Check warning on line 65 in src/backend/gl/glx.c

View check run for this annotation

Codecov / codecov/patch

src/backend/gl/glx.c#L65

Added line #L65 was not covered by tests
struct glx_fbconfig_info *info) {
log_debug("Looking for FBConfig for RGBA%d%d%d%d, depth: %d, visual id: %#x", m.red_size,

Check warning on line 67 in src/backend/gl/glx.c

View check run for this annotation

Codecov / codecov/patch

src/backend/gl/glx.c#L67

Added line #L67 was not covered by tests
m.blue_size, m.green_size, m.alpha_size, m.visual_depth, m.visual);

info->cfg = NULL;

Check warning on line 70 in src/backend/gl/glx.c

View check run for this annotation

Codecov / codecov/patch

src/backend/gl/glx.c#L70

Added line #L70 was not covered by tests

int ncfg;
// clang-format off
Expand Down Expand Up @@ -143,16 +154,13 @@
min_cost = depthbuf + stencil + bufsize * (doublebuf + 1);
}
free(cfg);
if (!found) {
return NULL;
if (found) {
info->cfg = ret;
info->texture_tgts = texture_tgts;
info->texture_fmt = texture_fmt;
info->y_inverted = y_inverted;

Check warning on line 161 in src/backend/gl/glx.c

View check run for this annotation

Codecov / codecov/patch

src/backend/gl/glx.c#L157-L161

Added lines #L157 - L161 were not covered by tests
}

auto info = cmalloc(struct glx_fbconfig_info);
info->cfg = ret;
info->texture_tgts = texture_tgts;
info->texture_fmt = texture_fmt;
info->y_inverted = y_inverted;
return info;
return found;

Check warning on line 163 in src/backend/gl/glx.c

View check run for this annotation

Codecov / codecov/patch

src/backend/gl/glx.c#L163

Added line #L163 was not covered by tests
}

/**
Expand Down Expand Up @@ -197,6 +205,12 @@
gd->ctx = 0;
}

struct glx_fbconfig_cache *cached_fbconfig = NULL, *tmp = NULL;
HASH_ITER(hh, gd->cached_fbconfigs, cached_fbconfig, tmp) {
HASH_DEL(gd->cached_fbconfigs, cached_fbconfig);
free(cached_fbconfig);

Check warning on line 211 in src/backend/gl/glx.c

View check run for this annotation

Codecov / codecov/patch

src/backend/gl/glx.c#L210-L211

Added lines #L210 - L211 were not covered by tests
}

free(gd);
}

Expand Down Expand Up @@ -367,6 +381,7 @@
static void *
glx_bind_pixmap(backend_t *base, xcb_pixmap_t pixmap, struct xvisual_info fmt, bool owned) {
struct _glx_pixmap *glxpixmap = NULL;
auto gd = (struct _glx_data *)base;

Check warning on line 384 in src/backend/gl/glx.c

View check run for this annotation

Codecov / codecov/patch

src/backend/gl/glx.c#L384

Added line #L384 was not covered by tests
// Retrieve pixmap parameters, if they aren't provided
if (fmt.visual_depth > OPENGL_MAX_DEPTH) {
log_error("Requested depth %d higher than max possible depth %d.",
Expand Down Expand Up @@ -394,38 +409,52 @@
wd->inner = (struct backend_image_inner_base *)inner;
free(r);

auto fbcfg = glx_find_fbconfig(base->c, fmt);
if (!fbcfg) {
log_error("Couldn't find FBConfig with requested visual %x", fmt.visual);
goto err;
struct glx_fbconfig_cache *cached_fbconfig = NULL;
HASH_FIND(hh, gd->cached_fbconfigs, &fmt, sizeof(fmt), cached_fbconfig);
if (!cached_fbconfig) {

Check warning on line 414 in src/backend/gl/glx.c

View check run for this annotation

Codecov / codecov/patch

src/backend/gl/glx.c#L412-L414

Added lines #L412 - L414 were not covered by tests
struct glx_fbconfig_info fbconfig;
if (!glx_find_fbconfig(base->c, fmt, &fbconfig)) {
log_error("Couldn't find FBConfig with requested visual %#x",

Check warning on line 417 in src/backend/gl/glx.c

View check run for this annotation

Codecov / codecov/patch

src/backend/gl/glx.c#L416-L417

Added lines #L416 - L417 were not covered by tests
fmt.visual);
goto err;

Check warning on line 419 in src/backend/gl/glx.c

View check run for this annotation

Codecov / codecov/patch

src/backend/gl/glx.c#L419

Added line #L419 was not covered by tests
}
cached_fbconfig = cmalloc(struct glx_fbconfig_cache);
cached_fbconfig->visual_info = fmt;
cached_fbconfig->info = fbconfig;
HASH_ADD(hh, gd->cached_fbconfigs, visual_info, sizeof(fmt), cached_fbconfig);

Check warning on line 424 in src/backend/gl/glx.c

View check run for this annotation

Codecov / codecov/patch

src/backend/gl/glx.c#L421-L424

Added lines #L421 - L424 were not covered by tests
} else {
log_debug("Found cached FBConfig for RGBA%d%d%d%d, depth: %d, visual id: "

Check warning on line 426 in src/backend/gl/glx.c

View check run for this annotation

Codecov / codecov/patch

src/backend/gl/glx.c#L426

Added line #L426 was not covered by tests
"%#x",
fmt.red_size, fmt.blue_size, fmt.green_size, fmt.alpha_size,
fmt.visual_depth, fmt.visual);
}
struct glx_fbconfig_info *fbconfig = &cached_fbconfig->info;

Check warning on line 431 in src/backend/gl/glx.c

View check run for this annotation

Codecov / codecov/patch

src/backend/gl/glx.c#L431

Added line #L431 was not covered by tests

// Choose a suitable texture target for our pixmap.
// Refer to GLX_EXT_texture_om_pixmap spec to see what are the mean
// of the bits in texture_tgts
if (!(fbcfg->texture_tgts & GLX_TEXTURE_2D_BIT_EXT)) {
if (!(fbconfig->texture_tgts & GLX_TEXTURE_2D_BIT_EXT)) {

Check warning on line 436 in src/backend/gl/glx.c

View check run for this annotation

Codecov / codecov/patch

src/backend/gl/glx.c#L436

Added line #L436 was not covered by tests
log_error("Cannot bind pixmap to GL_TEXTURE_2D, giving up");
goto err;
}

log_debug("depth %d, rgba %d", fmt.visual_depth,
(fbcfg->texture_fmt == GLX_TEXTURE_FORMAT_RGBA_EXT));
(fbconfig->texture_fmt == GLX_TEXTURE_FORMAT_RGBA_EXT));

GLint attrs[] = {
GLX_TEXTURE_FORMAT_EXT,
fbcfg->texture_fmt,
fbconfig->texture_fmt,

Check warning on line 446 in src/backend/gl/glx.c

View check run for this annotation

Codecov / codecov/patch

src/backend/gl/glx.c#L446

Added line #L446 was not covered by tests
GLX_TEXTURE_TARGET_EXT,
GLX_TEXTURE_2D_EXT,
0,
};

inner->y_inverted = fbcfg->y_inverted;
inner->y_inverted = fbconfig->y_inverted;

Check warning on line 452 in src/backend/gl/glx.c

View check run for this annotation

Codecov / codecov/patch

src/backend/gl/glx.c#L452

Added line #L452 was not covered by tests

glxpixmap = cmalloc(struct _glx_pixmap);
glxpixmap->pixmap = pixmap;
glxpixmap->glpixmap = glXCreatePixmap(base->c->dpy, fbcfg->cfg, pixmap, attrs);
glxpixmap->glpixmap = glXCreatePixmap(base->c->dpy, fbconfig->cfg, pixmap, attrs);

Check warning on line 456 in src/backend/gl/glx.c

View check run for this annotation

Codecov / codecov/patch

src/backend/gl/glx.c#L456

Added line #L456 was not covered by tests
glxpixmap->owned = owned;
free(fbcfg);

if (!glxpixmap->glpixmap) {
log_error("Failed to create glpixmap for pixmap %#010x", pixmap);
Expand Down
17 changes: 2 additions & 15 deletions src/backend/gl/glx.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,8 @@ struct glx_fbconfig_info {
int y_inverted;
};

/// The search criteria for glx_find_fbconfig
struct glx_fbconfig_criteria {
/// Bit width of the red component
int red_size;
/// Bit width of the green component
int green_size;
/// Bit width of the blue component
int blue_size;
/// Bit width of the alpha component
int alpha_size;
/// The depth of X visual
int visual_depth;
};

struct glx_fbconfig_info *glx_find_fbconfig(struct x_connection *, struct xvisual_info);
bool glx_find_fbconfig(struct x_connection *c, struct xvisual_info m,
struct glx_fbconfig_info *info);

struct glxext_info {
bool initialized;
Expand Down
2 changes: 1 addition & 1 deletion src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ typedef struct session {
/// Custom GLX program used for painting window.
// XXX should be in struct glx_session
glx_prog_main_t glx_prog_win;
struct glx_fbconfig_info *argb_fbconfig;
struct glx_fbconfig_info argb_fbconfig;
#endif
/// Sync fence to sync draw operations
xcb_sync_fence_t sync_fence;
Expand Down
2 changes: 1 addition & 1 deletion src/opengl.c
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@

free(ps->psglx);
ps->psglx = NULL;
ps->argb_fbconfig = NULL;
ps->argb_fbconfig = (struct glx_fbconfig_info){0};

Check warning on line 282 in src/opengl.c

View check run for this annotation

Codecov / codecov/patch

src/opengl.c#L282

Added line #L282 was not covered by tests
}

/**
Expand Down
5 changes: 1 addition & 4 deletions src/opengl.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,7 @@ static inline void free_texture(session_t *ps, glx_texture_t **pptex) {
*/
static inline void free_paint_glx(session_t *ps, paint_t *ppaint) {
free_texture(ps, &ppaint->ptex);
#ifdef CONFIG_OPENGL
free(ppaint->fbcfg);
#endif
ppaint->fbcfg = NULL;
ppaint->fbcfg = (struct glx_fbconfig_info){0};
}

/**
Expand Down
5 changes: 0 additions & 5 deletions src/picom.c
Original file line number Diff line number Diff line change
Expand Up @@ -2640,11 +2640,6 @@ static void session_destroy(session_t *ps) {
unredirect(ps);
}

#ifdef CONFIG_OPENGL
free(ps->argb_fbconfig);
ps->argb_fbconfig = NULL;
#endif

file_watch_destroy(ps->loop, ps->file_watch_handle);
ps->file_watch_handle = NULL;

Expand Down
29 changes: 15 additions & 14 deletions src/render.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,20 @@
struct glx_fbconfig_info *fbcfg;
if (!visual) {
assert(depth == 32);
if (!ps->argb_fbconfig) {
ps->argb_fbconfig = glx_find_fbconfig(
&ps->c, (struct xvisual_info){.red_size = 8,
.green_size = 8,
.blue_size = 8,
.alpha_size = 8,
.visual_depth = 32});
if (!ps->argb_fbconfig.cfg) {
glx_find_fbconfig(&ps->c,
(struct xvisual_info){.red_size = 8,

Check warning on line 60 in src/render.c

View check run for this annotation

Codecov / codecov/patch

src/render.c#L58-L60

Added lines #L58 - L60 were not covered by tests
.green_size = 8,
.blue_size = 8,
.alpha_size = 8,
.visual_depth = 32},
&ps->argb_fbconfig);
}
if (!ps->argb_fbconfig) {
if (!ps->argb_fbconfig.cfg) {

Check warning on line 67 in src/render.c

View check run for this annotation

Codecov / codecov/patch

src/render.c#L67

Added line #L67 was not covered by tests
log_error("Failed to find appropriate FBConfig for 32 bit depth");
return false;
}
fbcfg = ps->argb_fbconfig;
fbcfg = &ps->argb_fbconfig;

Check warning on line 71 in src/render.c

View check run for this annotation

Codecov / codecov/patch

src/render.c#L71

Added line #L71 was not covered by tests
} else {
auto m = x_get_visual_info(&ps->c, visual);
if (m.visual_depth < 0) {
Expand All @@ -79,14 +80,14 @@
return false;
}

if (!ppaint->fbcfg) {
ppaint->fbcfg = glx_find_fbconfig(&ps->c, m);
if (!ppaint->fbcfg.cfg) {
glx_find_fbconfig(&ps->c, m, &ppaint->fbcfg);

Check warning on line 84 in src/render.c

View check run for this annotation

Codecov / codecov/patch

src/render.c#L83-L84

Added lines #L83 - L84 were not covered by tests
}
if (!ppaint->fbcfg) {
if (!ppaint->fbcfg.cfg) {

Check warning on line 86 in src/render.c

View check run for this annotation

Codecov / codecov/patch

src/render.c#L86

Added line #L86 was not covered by tests
log_error("Failed to find appropriate FBConfig for X pixmap");
return false;
}
fbcfg = ppaint->fbcfg;
fbcfg = &ppaint->fbcfg;

Check warning on line 90 in src/render.c

View check run for this annotation

Codecov / codecov/patch

src/render.c#L90

Added line #L90 was not covered by tests
}

if (force || !glx_tex_bound(ppaint->ptex, ppaint->pixmap)) {
Expand Down Expand Up @@ -1528,7 +1529,7 @@
free_root_tile(ps);

#ifdef CONFIG_OPENGL
free(ps->root_tile_paint.fbcfg);
ps->root_tile_paint.fbcfg = (struct glx_fbconfig_info){0};

Check warning on line 1532 in src/render.c

View check run for this annotation

Codecov / codecov/patch

src/render.c#L1532

Added line #L1532 was not covered by tests
if (bkend_use_glx(ps)) {
glx_destroy(ps);
}
Expand Down
2 changes: 1 addition & 1 deletion src/render.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ typedef struct paint {
xcb_render_picture_t pict;
glx_texture_t *ptex;
#ifdef CONFIG_OPENGL
struct glx_fbconfig_info *fbcfg;
struct glx_fbconfig_info fbcfg;
#endif
} paint_t;

Expand Down