Repository navigation
Implemented optional EGL based GL/CL interop - #22704
kallaballa wants to merge 21 commits into
Conversation
|
OpenCV may use GLX for several purposes:
|
But why would you use GLX if you already have EGL (e.g. for android CL/GL interop). Could you please explain a use case where having EGL & GLX provides a benefit? Because all of those things (and more... e.g. offscreen rendering) can be done with EGL. |
|
Let's say, historical reason. Some code was contributed long time ago and not developed actively. I'm not against of EGL, but prefer safe way - not destroy existing features. |
|
I see now what you mean. There is another place where GLX is used: opencv/modules/core/src/gl_core_3_1.cpp Line 131 in 778fadd Anyway, I understand your point but on the other hand I wouldn't mind also replacing the CV_GL_GET_PROC_ADDRESS implementation and be done with GLX. :) |
|
Anyway... even if you don't want to replace GLX completely, this pull request still makes sense. Replacing GLX with EGL for OpenGL interop brings many advantages, like:
|
I understand now. and will implement it like that. |
|
Done de6bb16 |
|
I improved the implementation by defining a proper OCV_OPTION |
|
I thought about it and maybe it would be a good idea to infer which window-system API (GLX or EGL) to use by probing |
|
I tried both branches on my Ubuntu 18.04 host. Both implementations work, but final executable has significantly different dependencies. I do not think that dependency from both libEGL and libGLX is good idea. |
|
Also not all Linux systems provide EGL support. Please check |
Alright!
I understand your intuition in this (I had the same) but since i really want this feature i went to find evidence. ;) First i tried to find examples of libraries on my system linking to both find /usr/lib64/ -maxdepth 1 -name "*.so" | while read lib; do
deps="$(sudo ldd "$lib" 2>/dev/null | tr -d '\n')";
echo "$deps" | grep -q -E "libGLX.so.*libEGL.so|libEGL.so.*libGLX.so";
if [ $? -eq 0 ]; then
echo "$lib";
fi;
doneAnd i found the following files: So at least somebody is actively linking EGL and GLX at the same time. But what struck my eye quickly is that it's mostly GTK stack.... So i went to search in their repo and found this: https://gitlab.gnome.org/GNOME/gtk/-/merge_requests/3540 They are basically using GLX as a fallback to EGL. |
|
Half a year later firefox did the same: https://mozillagfx.wordpress.com/2021/10/30/switching-the-linux-graphics-stack-from-glx-to-egl/ Btw. I just realized I left |
|
Thanks a lot for the research! Could you check if the GTK stack does lazy linkage with EGL and GLX? |
|
I am on it :) |
|
I have following statement from a GTK developer: "EGL has issues with properly reporting the RGBA VIsual, which is why GTK defaults to GLX. You can often just force the RGBA Visual and it'll work, but GTK isn't doing that yet (Firefox and Chrome switched recently I think, maybe it got fixed or there's a an official way, didn't investigate yet) About the exact circumstances of linking i still have to investigate and I am also going to branch out to the Firefox community and see if they have advice. |
|
Statement from a Firefox dev: "Hi! So unfortunately Mesas X11 EGL implementation still has some open issues (e.g. https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9989 ....) which is why GTK4 still falls back to GLX. Generally GTK4 and OBS-Studio might be simpler examples than FF." |
There is no check for GLX in place either (as far as i can see). Can't hurt to add that too? |
Done 735a0f2
Done 49f64dd |
|
I have this in use on a couple of Linux systems (OpenSuSe, Debian, Ubuntu) mostly Intel iGPU systems but also one with Nvidia GPU. Intel requires EGL while Nvidia requires GLX. On the NVidia system the Intel iGPU is available as well and works - so i can switch between them with the same binary due to the GLX fallback mechanism. |
|
Tested using an Intel A770 and Mesa 24.3.1 as well |
|
Resolved merge conflict. testing. |
|
Tested. Still works as expected. |
d243a30 to
3b3f415
Compare
| if(WITH_WIN32UI OR (HAVE_QT AND QT_QTOPENGL_FOUND) OR HAVE_GTK3 OR (HAVE_GTK AND NOT HAVE_GTK3 AND HAVE_GTKGLEXT)) | ||
| find_package (OpenGL QUIET) | ||
| if(OpenGL_EGL_FOUND) | ||
| set(HAVE_EGL TRUE AND OPENCV_ENABLE_EGL) |
There was a problem hiding this comment.
CMake's set doesn't support complex boolean values.
| # if defined(OPENCV_ENABLE_EGL) | ||
| # include <EGL/egl.h> | ||
| # endif | ||
| # if defined(OPENCV_ENABLE_GLX) |
There was a problem hiding this comment.
Where are these vars defined?
| if(OPENCV_LIBVA_LINK) | ||
| ocv_append_source_file_compile_definitions("${CMAKE_CURRENT_LIST_DIR}/src/va_intel.cpp" "OPENCV_LIBVA_LINK=1") | ||
| endif() | ||
| if(OPENCV_ENABLE_EGL_INTEROP) |
There was a problem hiding this comment.
Where do we define this flag?
|
i fixed the issues |
There was a problem hiding this comment.
Status: 🔴 Red
Verdict: Refactor before merge.
Preserve default Linux GLX interoperability and make EGL detection usable headlessly; the current option defaults can leave neither interop path enabled.
Please address this in the current PR and add focused regression coverage where applicable.
The pertaining issue: #22703
Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
Patch to opencv_extra has the same branch name.