Skip to content
This repository has been archived by the owner on Nov 1, 2021. It is now read-only.

Commit

Permalink
backend/drm: stop initializing renderer for parent backend
Browse files Browse the repository at this point in the history
Unless we're dealing with a multi-GPU setup and the backend being
initialized is secondary, we don't need a renderer not an allocator.
Stop initializing these.
  • Loading branch information
emersion committed Jul 12, 2021
1 parent 8e8f48e commit fc05b76
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 26 deletions.
19 changes: 15 additions & 4 deletions backend/drm/backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,13 @@ static void backend_destroy(struct wlr_backend *backend) {
wl_list_remove(&drm->dev_change.link);
wl_list_remove(&drm->dev_remove.link);

gbm_device_destroy(drm->gbm);

if (drm->parent) {
finish_drm_renderer(&drm->mgpu_renderer);
}

finish_drm_resources(drm);
finish_drm_renderer(&drm->renderer);

free(drm->name);
wlr_session_close_file(drm->session, drm->dev);
Expand Down Expand Up @@ -221,8 +226,9 @@ struct wlr_backend *wlr_drm_backend_create(struct wl_display *display,
goto error_event;
}

if (!init_drm_renderer(drm, &drm->renderer)) {
wlr_log(WLR_ERROR, "Failed to initialize renderer");
drm->gbm = gbm_create_device(drm->fd);
if (!drm->gbm) {
wlr_log(WLR_ERROR, "Failed to create GBM device");
goto error_event;
}

Expand All @@ -233,9 +239,14 @@ struct wlr_backend *wlr_drm_backend_create(struct wl_display *display,
}

if (drm->parent) {
if (!init_drm_renderer(drm, &drm->mgpu_renderer)) {
wlr_log(WLR_ERROR, "Failed to initialize renderer");
goto error_event;
}

// We'll perform a multi-GPU copy for all submitted buffers, we need
// to be able to texture from them
struct wlr_renderer *renderer = drm->renderer.wlr_rend;
struct wlr_renderer *renderer = drm->mgpu_renderer.wlr_rend;
const struct wlr_drm_format_set *texture_formats =
wlr_renderer_get_dmabuf_texture_formats(renderer);
if (texture_formats == NULL) {
Expand Down
8 changes: 4 additions & 4 deletions backend/drm/drm.c
Original file line number Diff line number Diff line change
Expand Up @@ -644,14 +644,14 @@ static bool drm_connector_init_renderer(struct wlr_drm_connector *conn,
int height = mode.vdisplay;

struct wlr_drm_format *format =
drm_plane_pick_render_format(plane, &drm->renderer);
drm_plane_pick_render_format(plane, &drm->mgpu_renderer);
if (format == NULL) {
wlr_log(WLR_ERROR, "Failed to pick primary plane format");
return false;
}

// TODO: fallback to modifier-less buffer allocation
bool ok = init_drm_surface(&plane->mgpu_surf, &drm->renderer,
bool ok = init_drm_surface(&plane->mgpu_surf, &drm->mgpu_renderer,
width, height, format);
free(format);
if (!ok) {
Expand Down Expand Up @@ -846,13 +846,13 @@ static bool drm_connector_set_cursor(struct wlr_output *output,
struct wlr_buffer *local_buf;
if (drm->parent) {
struct wlr_drm_format *format =
drm_plane_pick_render_format(plane, &drm->renderer);
drm_plane_pick_render_format(plane, &drm->mgpu_renderer);
if (format == NULL) {
wlr_log(WLR_ERROR, "Failed to pick cursor plane format");
return false;
}

bool ok = init_drm_surface(&plane->mgpu_surf, &drm->renderer,
bool ok = init_drm_surface(&plane->mgpu_surf, &drm->mgpu_renderer,
buffer->width, buffer->height, format);
free(format);
if (!ok) {
Expand Down
20 changes: 4 additions & 16 deletions backend/drm/renderer.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,21 @@ bool init_drm_renderer(struct wlr_drm_backend *drm,
struct wlr_drm_renderer *renderer) {
renderer->backend = drm;

renderer->gbm = gbm_create_device(drm->fd);
if (!renderer->gbm) {
wlr_log(WLR_ERROR, "Failed to create GBM device");
return false;
}

renderer->wlr_rend = renderer_autocreate_with_drm_fd(drm->fd);
if (!renderer->wlr_rend) {
wlr_log(WLR_ERROR, "Failed to create renderer");
goto error_gbm;
return false;
}

renderer->allocator = allocator_autocreate_with_drm_fd(&drm->backend,
renderer->wlr_rend, drm->fd);
if (renderer->allocator == NULL) {
wlr_log(WLR_ERROR, "Failed to create allocator");
goto error_wlr_rend;
wlr_renderer_destroy(renderer->wlr_rend);
return false;
}

return true;

error_wlr_rend:
wlr_renderer_destroy(renderer->wlr_rend);
error_gbm:
gbm_device_destroy(renderer->gbm);
return false;
}

void finish_drm_renderer(struct wlr_drm_renderer *renderer) {
Expand All @@ -59,7 +48,6 @@ void finish_drm_renderer(struct wlr_drm_renderer *renderer) {

wlr_allocator_destroy(renderer->allocator);
wlr_renderer_destroy(renderer->wlr_rend);
gbm_device_destroy(renderer->gbm);
}

bool init_drm_surface(struct wlr_drm_surface *surf,
Expand Down Expand Up @@ -288,7 +276,7 @@ static struct wlr_drm_fb *drm_fb_create(struct wlr_drm_backend *drm,
}
}

fb->bo = get_bo_for_dmabuf(drm->renderer.gbm, &attribs);
fb->bo = get_bo_for_dmabuf(drm->gbm, &attribs);
if (!fb->bo) {
wlr_log(WLR_DEBUG, "Failed to import DMA-BUF in GBM");
goto error_get_dmabuf;
Expand Down
5 changes: 4 additions & 1 deletion include/backend/drm/drm.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ struct wlr_drm_backend {
int fd;
char *name;
struct wlr_device *dev;
struct gbm_device *gbm;

size_t num_crtcs;
struct wlr_drm_crtc *crtcs;
Expand All @@ -79,7 +80,9 @@ struct wlr_drm_backend {
struct wl_list fbs; // wlr_drm_fb.link
struct wl_list outputs;

struct wlr_drm_renderer renderer;
/* Only initialized on multi-GPU setups */
struct wlr_drm_renderer mgpu_renderer;

struct wlr_session *session;

uint64_t cursor_width, cursor_height;
Expand Down
1 change: 0 additions & 1 deletion include/backend/drm/renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ struct wlr_buffer;

struct wlr_drm_renderer {
struct wlr_drm_backend *backend;
struct gbm_device *gbm;

struct wlr_renderer *wlr_rend;
struct wlr_allocator *allocator;
Expand Down

0 comments on commit fc05b76

Please sign in to comment.