Almost verbatim copy of what I posted here:
https://forums.gentoo.org/viewtopic-t-1176307.html
libgbm is a generic buffer allocation library from mesa.
It is used for allocating gpu memory, drawing into it, mapping it, and
sending it to the gpu for drawing.
It can be found at:
https://gitlab.freedesktop.org/mesa/mesa/-/tree/main/src/gbm
The library consists of 2 parts.
One is the loader, located at
https://gitlab.freedesktop.org/mesa/mesa/-/tree/main/src/gbm/main ,
which is the frontend with which consumers of the library interact with.
The other is the backend. Mesa maintains the dri backend, located at
https://gitlab.freedesktop.org/mesa/mesa/-/tree/main/src/gbm/backends/dri
.
The backend implements the buffer allocation, and a hook for the
frontend to call and load the functions from the backend.
There were talks about splitting libgbm from mesa, due to the fact that
the loader doesn't really need anything from mesa,
and building it takes a couple of seconds at best, compared to mesa,
which can take over 10 minutes to build.
See
https://bugs.gentoo.org/940168 and the links posted there for more
context.
Most notably, the nvidia gpus don't use the in-tree dri gbm backend, so
all they really need from mesa is the tiny libgbm loader.
recently, someone split the loader from mesa:
https://github.com/glfs-book/libgbm
This means that recent nvidia cards, those supported by the 5xx drivers,
can use that instead of mesa and save a lot of compilation time.
However, there are cards that do have a gbm driver that supports tiled
buffers.
These cards do not work with the in-tree dri gbm backend, and they do
not work with the nvidia gbm backend either.
I have an open mr for supporting these cards with the dri gbm backend:
https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/38646
However, even with that patch, these cards would require mesa to be
compiled, which is a lot of code that they can't use.
Because of things like this people are either using the drm dumb buffer
api directly,
or rolling their own wrappers:
https://gitlab.freedesktop.org/xorg/xserver/-/blob/master/hw/xfree86/drivers/modesetting/dumb_bo.c
Today, I wrote this:
https://github.com/stefan11111/dumb_gbm
This is a libgbm backend that does not depend on mesa and that uses dumb
buffers only.
There is no egl support with this, so this is not a mesa replacement on
cards that support more than dumb buffers.
However, on cards that only support dumb buffers, in combination with a
libgbm loader, this makes it so that mesa is no longer needed on these
cards.
The dumb gbm backend works on cards that support more than just dumb
buffers too, so if anyone wants to test it, they can.
To use this backend instead, the GBM_BACKEND="dumb" envvar must be
present.
Here is some test code creates a gbm device, a gbm buffer, and exports
it as a dmabuf:
Code:
> #include <fcntl.h>
> #include <unistd.h>
> #include <stdio.h>
> #include <stdlib.h>
>
> #include <gbm.h>
>
> int main()
> {
> char data[0x10] = "";
>
> int drm_fd = open("/dev/dri/card0", O_RDWR);
> struct gbm_device *device = gbm_create_device(drm_fd);
>
> printf("device: %p\n", device);
>
> int width = 32;
> int height = 32;
>
> struct gbm_bo *bo = gbm_bo_create(device, width, height,
> GBM_FORMAT_ARGB8888,
> GBM_BO_USE_CURSOR);
>
> height = gbm_bo_get_height(bo);
> width = gbm_bo_get_width(bo);
>
> printf("height: %d width: %d \n", height, width);
>
> int ret = gbm_bo_write(bo, data, sizeof(data));
>
> printf("%d \n", ret);
>
> int prime_fd = gbm_bo_get_fd(bo);
> printf("PRIME fd: %d\n", prime_fd);
> close(prime_fd);
>
> gbm_bo_destroy(bo);
> gbm_device_destroy(device);
> close(drm_fd);
> }
It's compiled and executed like this:
Code:
> $ gcc cursor.c -o cursor -lgbm
> $ GBM_BACKEND=dumb ./cursor
> device: 0x557c9a06b480
> height: 32 width: 32
> 0
> PRIME fd: 4
I have tested this setup with librewolf and Xlibre too, both with the
nvidia backend, and the dumb backend.
For anyone who wants to try this, I have ebuilds here:
https://github.com/stefan11111/stefan_overlay/tree/main/media-libs/dumb-gbm
https://github.com/stefan11111/stefan_overlay/tree/main/media-libs/libgbm
If someone wants to try removing mesa and using libgbm instead, they
will want to install a header from mesa,
as discussed here:
http://forums.gentoo.org/viewtopic-t-1167405.html
The repo with just the header is here:
https://github.com/stefan11111/dri_interface.h
An ebuild for installing it is here:
https://github.com/stefan11111/stefan_overlay/blob/main/x11-base/xorg-dri-interface/xorg-dri-interface-1.0.ebuild
If there is anything on the system that explicitly requires mesa, it
will have to be added to package.provided, or a dummy ebuild that pulls
libgbm instead will have to be used.
If anyone wants to test using Xlibre with this they will have to use
this patch:
https://github.com/X11Libre/xserver/pull/1396
Received on Sat Dec 13 2025 - 20:13:49 CET