Skip to content

Make glamor egl more flexible#2167

Merged
metux merged 5 commits intoX11Libre:masterfrom
stefan11111:glamor-egl-prelims
Apr 17, 2026
Merged

Make glamor egl more flexible#2167
metux merged 5 commits intoX11Libre:masterfrom
stefan11111:glamor-egl-prelims

Conversation

@stefan11111
Copy link
Copy Markdown
Contributor

No description provided.

@stefan11111
Copy link
Copy Markdown
Contributor Author

@metux @cepelinas9000 ping

Comment thread glamor/glamor_egl.c
if (glamor_egl->fd >= 0) {
glamor_egl->gbm = gbm_create_device(glamor_egl->fd);
if (!glamor_egl->gbm) {
glamor_egl->gbm = gbm_create_device_by_name(glamor_egl->fd, "dumb");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm a bit confused. Isn't that a separate issue / feature that should be a separate commit ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

split into a separate commit

Comment thread glamor/glamor_egl.c
static void
glamor_filter_modifiers(uint32_t *num_modifiers, uint64_t **modifiers,
EGLBoolean *external_only)
EGLBoolean *external_only, int linear_only)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Not sure, but looks like a separate topic (-> separate commit ?) to me.
Can you please give some bits documentation on what that's actually doing ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Split into a separate commit.

This filters all modifiers except DRM_FORMAT_MOD_{LINEAR,INVALID}, when using the dumb gbm backend.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

IOW: when using dumb gbm, it's restricting to linear framebuffer only ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes.
We still have to read the modifier list, because the linear modifier may not be in the list at all, or it may be external_only, which means we cannot use it.

If the linear modifier cannot be used, we disable glamor's dri3 implementation when we check for at least a supported (format, modifier) pair and find none.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ok. maybe we should have some little docs on that.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This the current commit message:

https://github.com/stefan11111/dumb_gbm is a gbm backend
that only uses dumb buffers.

As such, it is very portable, allowing libgbm to be used
on devices where a proper gbm backend with tiled buffer support
isn't available.

What should I add to it?

Also, my earlier response was perhaps a bit incomplete.

With dumb gbm, all buffers created are linear, so they can be thought of as linear framebuffers.

However, it's not like traditional unaccelerated fbdev, with a single front framebuffer where everything is drawn.

With dumb gbm, glamor draws into the (linear) front buffer using gl, and X clients can also draw into the (linear) buffers they get from the X server through DRI3 with gl.

Comment thread glamor/glamor_egl.h
Comment thread glamor/glamor_egl.c
Comment thread glamor/glamor_egl.c
Comment thread glamor/glamor_egl.c
If we still have an egl context when `closeScreen` is called,
we destroy it here and set it to `EGL_NO_CONTEXT`

Signed-off-by: stefan11111 <stefan11111@shitposting.expert>
@metux
Copy link
Copy Markdown
Contributor

metux commented Apr 15, 2026

This github review & commenting functionality is quite crap ... totally mixes up context :(
Maybe we should only 1-commit-PRs ... :o grmpf

Just reviewed directly via git ... only one little nitpick:
The commit "glamor/glamor_egl.c: extend glamor_egl_make_current" could deserve a bit better description on what/why it's actually doing. Anything else looks good to me.

The change is mostly cosmetic, bringing this in line
with Xephyr's `egl_make_current`.

We'll see if we need to do anything fancier if/when
we decide to add EGLStream support

Signed-off-by: stefan11111 <stefan11111@shitposting.expert>
glamor_egl's glvnd vendor option used to only work with libraries.
Now, it will work with driver names too (e.g. intel/iris vs mesa).

This code doesn't do much currently, it will be used by
subsequent commits.

Signed-off-by: stefan11111 <stefan11111@shitposting.expert>
Before this, the generic glamor egl code from xf86 only worked
with a dri fd.
However, this is only needed for glamor_egl's dri3 support.

Glamor supports having no DRI3 support at all, even if the
X server / xf86 ddx driver doesn't implement DRI3 itself.

When using glamor's DRI3 implementation, we create a
gbm bo for each pixmap we want to export using DRI3.
From that bo, we create an `EGLImageKHR`.
From this `EGLImageKHR`, we create a texture using
`glEGLImageTargetTexture2DOES` and set this newly
created texture as the pixmap's texture, for glamor
to render into.

When not using DRI3, glamor allocates all textures itself, using
`glTexImage2D` in `_glamor_create_tex` from `glamor/glamor_fbo.c`.

As-is, the generic glamor_egl code doesn't work without a dri fd,
because it only tries to get an `EGLDisplay` on the GBM platform.

This commit only make glamor handle the case if no fd (-1) is passed
to it. It will currently error out cleanly at runtime if this
actually happens.

Subsequent commits will add support for more egl platforms
and drop existing extension requirements, enabling support
for more hardware.

Signed-off-by: stefan11111 <stefan11111@shitposting.expert>
https://github.com/stefan11111/dumb_gbm is a gbm backend
that only uses dumb buffers.

As such, it is very portable, allowing libgbm to be used
on devices where a proper gbm backend with tiled buffer support
isn't available.

Signed-off-by: stefan11111 <stefan11111@shitposting.expert>
@stefan11111
Copy link
Copy Markdown
Contributor Author

This github review & commenting functionality is quite crap ... totally mixes up context :( Maybe we should only 1-commit-PRs ... :o grmpf

Just reviewed directly via git ... only one little nitpick: The commit "glamor/glamor_egl.c: extend glamor_egl_make_current" could deserve a bit better description on what/why it's actually doing. Anything else looks good to me.

Done.
Added some more description to the other commits too.

@stefan11111
Copy link
Copy Markdown
Contributor Author

@cepelinas9000 Any concerns on your side?

@cepelinas9000
Copy link
Copy Markdown
Contributor

applying on master, i getting small leak:


Indirect leak of 4128 byte(s) in 43 object(s) allocated from:
    #0 0x7ffff792220b in realloc /usr/src/debug/sys-devel/gcc-15.2.1_p20251122/gcc-15-20251122/libsanitizer/asan/asan_malloc_linux.cpp:81
    #1 0x7bfff285a188 in glamor_filter_modifiers ../glamor/glamor_egl.c:897
    #2 0x7bfff285aacc in glamor_get_modifiers_internal ../glamor/glamor_egl.c:949
    #3 0x7bfff285ac39 in glamor_get_modifiers ../glamor/glamor_egl.c:970
    #4 0x5555572a8080 in cache_formats_and_modifiers ../dri3/dri3_screen.c:198
    #5 0x5555572a877d in dri3_get_supported_modifiers ../dri3/dri3_screen.c:236
    #6 0x55555729e364 in proc_dri3_get_supported_modifiers ../dri3/dri3_request.c:399
    #7 0x5555572a5818 in proc_dri3_dispatch ../dri3/dri3_request.c:680
    #8 0x555556a03e93 in Dispatch ../dix/dispatch.c:566
    #9 0x555556a70b15 in dix_main ../dix/main.c:288
    #10 0x55555760b25a in main ../dix/stubmain.c:34
    #11 0x7ffff6c4d3fa  (/usr/lib64/libc.so.6+0x273fa)
    #12 0x7fffffffdb38  ([stack]+0x28b38)

This was when i ran glxgears something 40 times. Or this leak fix should be seperate pr?

@stefan11111
Copy link
Copy Markdown
Contributor Author

This leak is not related to this patch.
It's dri3 allocating a cache of formats and modifiers, so that it doesn't have to
call into egl every time an X client requests it.
It's not really a leak, the X server never looses track of the cache,
it just doesn't free it at closeScreen time.

This patch should fix it: #2198

Copy link
Copy Markdown
Contributor

@cepelinas9000 cepelinas9000 left a comment

Choose a reason for hiding this comment

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

LGTM

@metux metux merged commit 8ba3f3a into X11Libre:master Apr 17, 2026
@stefan11111 stefan11111 deleted the glamor-egl-prelims branch April 18, 2026 23:54
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.

3 participants