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

Handle libEGL, libGL and DRI #1

Open
probonopd opened this issue Nov 22, 2024 · 18 comments
Open

Handle libEGL, libGL and DRI #1

probonopd opened this issue Nov 22, 2024 · 18 comments

Comments

@probonopd
Copy link

probonopd commented Nov 22, 2024

Using userland-execve is a very interesting approach @VHSgunzo, very clever.

I tried to experiment with sharun a bit, but I am running into an issue:
Some applicatons, e.g., PrusaSlicer, require libGL and DRI for 3D graphics rendering.
It seems like this needs to be handled somehow.

https://github.com/probonopd/PrusaSlicer/blob/efe3df7c9a9a3bd8c2b7bdfa3ec6bb31bb67ab41/.github/workflows/build.yml#L111-L114

This approach is certainly not the way to do it but maybe it can give you a hint at where to look. It seems like libGL and DRI and its dependencies (graphics driver libraries) need to be bundled. Can you get it to work?

@Samueru-sama
Copy link

Samueru-sama commented Nov 22, 2024

LIBGL_DRIVERS_PATH was removed recently

Also I'm not sure if there is ever a need to copy the dri dir, instead you just need libGL* and the share/glvnd/egl_vendor.d directory, which sharun will automatically point __EGL_VENDOR_LIBRARY_DIRS to it.

This is all it took to have a working opengl with this desmume appimage for example, and similar for a working vulkan here.

I noticed xvfb-run isn't working on your script? I think I had this issue with an ubuntu runner as well.

@probonopd
Copy link
Author

xvfb-run runs for the first but not for the second binary - but then again, maybe I am doing it entirely wrong?

@probonopd
Copy link
Author

probonopd commented Nov 22, 2024

Also I'm not sure if there is ever a need to copy the dri dir, instead you just need libGL* and the share/glvnd/egl_vendor.d directory, which sharun will automatically point __EGL_VENDOR_LIBRARY_DIRS to it.

If I don't do this, then I get:

squashfs-root$ ./AppRun 2>&1

(prusa-slicer:1434): Gtk-CRITICAL **: 02:15:47.231: gtk_window_resize: assertion 'width > 0' failed
[2024-11-22 02:15:47.544278] [0x00007f9b6f50f7c0] [error]   UserAccount: Failed to read token - no datafile found.
libGL error: MESA-LOADER: failed to open swrast: /usr/lib/dri/swrast_dri.so: cannot open shared object file: No such file or directory (search paths /usr/lib/x86_64-linux-gnu/dri:\$${ORIGIN}/dri:/usr/lib/dri, suffix _dri)
libGL error: failed to load driver: swrast

(prusa-slicer:1434): Gdk-ERROR **: 02:15:47.626: The program 'prusa-slicer' received an X Window System error.
This probably reflects a bug in the program.
The error was 'BadValue (integer parameter out of range for operation)'.
  (Details: serial 894 error_code 2 request_code 148 (GLX) minor_code 3)
  (Note to programmers: normally, X errors are reported asynchronously;
   that is, you will receive the error a while after causing it.
   To debug your program, run it with the GDK_SYNCHRONIZE environment
   variable to change this behavior. You can then get a meaningful
   backtrace from your debugger if you break on the gdk_x_error() function.)
Trace/breakpoint trap (core dumped)

@Samueru-sama
Copy link

Interesting.

Looks like dri has to be copied here, I also tested the last artifact that has dri, I noticed that if I set LIBGL_DRIVERS_PATH to the AppDir dri I get this error instead:

libGL error: MESA-LOADER: failed to open radeonsi: libLLVM-15.so.1: cannot open shared object file

which is indeed missing from the AppDir.

Also with the removal of LIBGL_DRIVERS_PATH I'm not sure what would need to be done in the future.

@probonopd
Copy link
Author

probonopd commented Nov 22, 2024

Also with the removal of LIBGL_DRIVERS_PATH I'm not sure what would need to be done in the future.

Found out so far that the string

MESA-LOADER: failed to open %s: %s (search paths %s, suffix %s)
/usr/lib/x86_64-linux-gnu/dri:\$${ORIGIN}/dri:/usr/lib/dri

appears in ./shared/lib/libgbm.so.1.0.0 which has to do with the Mesa3D project.

\$${ORIGIN} also appears in the unpatched /usr/lib/x86_64-linux-gnu/libgbm.so.1.0.0. But what is it supposed to resolve to?

@Samueru-sama
Copy link

Samueru-sama commented Nov 22, 2024

Btw I noticed another thing, the webkit2gtk-4.0 dir contains binaries.

Those binaries have to be wrapped around with sharun, otherwise they will try to use the host dynamic linker when ran.

Something like this would need to be done for those binaries

@probonopd
Copy link
Author

probonopd commented Nov 22, 2024

webkit2gtk-4.0

#2 :-)

@Samueru-sama
Copy link

Samueru-sama commented Nov 22, 2024

This appimage works on my PC.

However it does not work on ubuntu, I get this error:

(prusa-slicer:8225): GLib-GObject-CRITICAL **: 00:48:51.285: g_object_unref: assertion 'G_IS_OBJECT (object)' failed
[2024-11-22 00:48:51.375700] [0x0000715d5cf547c0] [error]   UserAccount: Failed to read token - no datafile found.
**
Gtk:ERROR:../../../../gtk/gtkiconhelper.c:494:ensure_surface_for_gicon: assertion failed (error == NULL): Failed to load /usr/local/share/icons/Papirus-Dark/16x16/actions/image-missing.svg: Unable to load image-loading module: /usr/lib/x86_64-linux-gnu/gdk-pixbuf-2.0/2.10.0/loaders/libpixbufloader-svg.so: /run/host/tmp/samuel/Volatile/squashfs-root/shared/lib/libm.so.6: version `GLIBC_2.38' not found (required by /lib/x86_64-linux-gnu/librsvg-2.so.2) (gdk-pixbuf-error-quark, 5)
Bail out! Gtk:ERROR:../../../../gtk/gtkiconhelper.c:494:ensure_surface_for_gicon: assertion failed (error == NULL): Failed to load /usr/local/share/icons/Papirus-Dark/16x16/actions/image-missing.svg: Unable to load image-loading module: /usr/lib/x86_64-linux-gnu/gdk-pixbuf-2.0/2.10.0/loaders/libpixbufloader-svg.so: /run/host/tmp/samuel/Volatile/squashfs-root/shared/lib/libm.so.6: version `GLIBC_2.38' not found (required by /lib/x86_64-linux-gnu/librsvg-2.so.2) (gdk-pixbuf-error-quark, 5)
zsh: IOT instruction  ./AppRun

This is likely because gdk wasn't deployed, which is odd, I noticed that the app crashes when I continue a confirmation dialog that pops up when launching, very likely the strace mode doesn't catch these libs since they are loaded after the confrimation dialog is closed.

Try deploying gdk manually anyway, add something like this:

# DEPLOY GDK
echo "Deploying gdk..."
GDK_PATH="$(find /usr/lib -type d -regex ".*/gdk-pixbuf-2.0" -print -quit)"
cp -rv "$GDK_PATH" ./shared/lib
echo "Deploying gdk deps..."
find ./shared/lib/gdk-pixbuf-2.0 -type f -name '*.so*' -exec ldd {} \; \
	| awk -F"[> ]" '{print $4}' | xargs -I {} cp -vn {} ./shared/lib
find ./shared/lib -type f -regex '.*gdk.*loaders.cache' \
	-exec sed -i 's|/.*lib.*/gdk-pixbuf.*/.*/loaders/||g' {} \;

The ideal solution though is finding a way to bypass the confirmation dialog about SSL certificates when launching the app in the CI, that way we would get the missing libs.

@probonopd
Copy link
Author

Thanks @Samueru-sama. Do you know why rpath is getting patched, I thought patching rpath was no longer necessary thanks to userland-execve?

@Samueru-sama
Copy link

Thanks @Samueru-sama. Do you know why rpath is getting patched, I thought patching rpath was no longer necessary thanks to userland-execve?

It isn't needed, but lib4bin has the -r flag which will patch the rpath of the libraries, I do this because sometimes the libraries from the host have hardcoded fullpaths in the rpath and this can cause issues, for example the obs-studio plugins had /usr/lib rpaths.

The ideal solution would be checking all the libs and remove the rpaths from the ones that have it previously set, no idea if @VHSgunzo wants to implement this feature in lib4bin either.

I forked your fork of pureslicer and I'm testing some things, will likely continue tomorrow since it is late here now.

@Samueru-sama
Copy link

@probonopd just checked your last build and it works on ubuntu latest now, and I had to set LIBGL_DRIVERS_PATH to make it work on 20.04.

Note that you can add extra env variables by creating a .env file next to sharun and add something like LIBGL_DRIVERS_PATH=${SHARUN_DIR}/shared/lib/dri

@probonopd
Copy link
Author

probonopd commented Nov 22, 2024

Getting somewhere. #2 still needs to be tamed somehow. See there.

@VHSgunzo
Copy link
Owner

Using userland-execve is a very interesting approach @VHSgunzo, very clever.

Hi! Thanks! I have not yet looked at the problem that is being discussed here

@Samueru-sama
Copy link

Most of the issues here were solved already, the only thing is that LIBGL_DRIVERS_PATH needed to declared here.

What's left is the other issue with webkitgtk.

@probonopd
Copy link
Author

probonopd commented Nov 23, 2024

When I run my build made on Ubuntu on a Ubuntu target system, it seems to work. However, on a Fedora Linux 38 (KDE Plasma) target system, then I get

libEGL fatal: DRI driver not from this Mesa build ('23.2.1-1ubuntu3.1~22.04.2' vs '23.0.1')

So there is more to libGL and DRI than meets the eye...

libEGL_mesa.so.0 and its dependencies also need to be deployed, as I have done in this build.

https://github.com/probonopd/PrusaSlicer/blob/1211b28bd7bb7d715b67d6c964ce067e003b0a01/.github/workflows/build.yml

@probonopd probonopd changed the title Handle libGL and DRI Handle libEGL, libGL and DRI Nov 23, 2024
@probonopd
Copy link
Author

So, for my personal test case I found solutions for all of the above. But it is a lot of manual work, Is it in the scope of this project to provide automation for this? Thanks.

@Samueru-sama
Copy link

Samueru-sama commented Nov 26, 2024

So, for my personal test case I found solutions for all of the above. But it is a lot of manual work, Is it in the scope of this project to provide automation for this? Thanks.

Not sure, sharun already sets a lot of env variables.

I recently made an AppImage of Cromite (Chromium fork) with sharun and also needed to deploy lib/dri however I didn't need to set LIBGL_DRIVERS_PATH, this is likely because I'm using the new mesa that doesn't need it (Now it looks for the dri libs like any other regular shared library). So I'm not sure if this should be added to sharun given it is deprecated.

@probonopd
Copy link
Author

probonopd commented Nov 26, 2024

I recently made an AppImage of Cromite (Chromium fork) with sharun and also needed to deploy lib/dri however I didn't need to set LIBGL_DRIVERS_PATH, this is likely because I'm using the new mesa that doesn't need it (Now it looks for the dri libs like any other regular shared library).

Great to know @Samueru-sama. Thanks!

So I'm not sure if this should be added to sharun given it is deprecated.

If it is no longer needed with the new versions, then no, we wouldn't imho need to set LIBGL_DRIVERS_PATH.

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

No branches or pull requests

3 participants