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

opengl: provide swrast as fallback when no GL drivers are found #62177

Closed
wants to merge 1 commit into from

Conversation

matthewbauer
Copy link
Member

When no libGL drivers are found, we will fall back to “libGLX_mesa.so”
which corresponds to the mesa “swrast” driver. This uses some X11 apis
for rendering, and is suitable for many use cases of . This is still
not as good as having the hardware drivers. Adding libGLX_mesa.so to
the closures ends up adding about 1MB, which is signifcant but still
acceptable.

Fixes #62032
Fixes #62169
Fixes #9415

/cc @ambrop72 @edahlgren

Motivation for this change
Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nix-review --run "nix-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Assured whether relevant documentation is up to date
  • Fits CONTRIBUTING.md.

@ambrop72
Copy link
Contributor

ambrop72 commented May 28, 2019

Why did you remove addOpenGLRunpath from libglvnd? Looks like an accident to me.

@edahlgren
Copy link

Sorry, quick high-level question. I just realized, will this only work for non-NixOS Linux users without extra setup, due to the X11 nature of libGLX_mesa.so? Maybe I'm missing something, but I didn't see any documentation telling macOS users to install XQuartz when they install nix.

@matthewbauer
Copy link
Member Author

Why did you remove addOpenGLRunpath from libglvnd? Looks like an accident to me.

Sorry i should have commented on that. But leaving it here leads to an infinite recursion because libglvnd -> addOpenGLRunpath -> mesa -> libglvnd. I am pretty sure it is unnecessary because it does not link against libGL or libEGL at all. It is the library used to detect which driver vendor you will need.

Sorry, quick high-level question. I just realized, will this only work for non-NixOS Linux users without extra setup, due to the X11 nature of libGLX_mesa.so? Maybe I'm missing something, but I didn't see any documentation telling macOS users to install XQuartz when they install nix.

Yeah swrast utilizes the xlib API to do rendering (see 1.4 What's the difference between "Stand-Alone" Mesa and the DRI drivers for a better explanation). This will only work on X11 systems. AFAICT you can't use swrast with XQuartz at all. This really isn't a problem on macOS because we can provide OpenGL.framework which contains Apple's proprietary libGL driver. Luckily, it supports all Apple hardware, and we don't have to mess with libglvnd at all. This will all become a huge problem though if apple ever decides to remove opengl support from macOS! I don't think even Apple would do that though.

When no libGL drivers are found, we will fall back to “libGLX_mesa.so”
which corresponds to the mesa “swrast” driver. This uses some X11 apis
for rendering, and is suitable for many use cases of . This is still
not as good as having the hardware drivers. Adding libGLX_mesa.so to
the closures ends up adding about 1MB, which is signifcant but still
acceptable.

Fixes NixOS#62032
Fixes NixOS#62169
Fixes NixOS#9415
@ambrop72
Copy link
Contributor

Why did you remove addOpenGLRunpath from libglvnd? Looks like an accident to me.

Sorry i should have commented on that. But leaving it here leads to an infinite recursion because libglvnd -> addOpenGLRunpath -> mesa -> libglvnd. I am pretty sure it is unnecessary because it does not link against libGL or libEGL at all. It is the library used to detect which driver vendor you will need.

libglvnd provides a generic libGL/libEGL that programs should link to and use. It is a dispatch library which figures out the <vendor>, dlopens libGLX_<vendor>/libEGL_<vendor> and forwards calls to it. Possible vendor libraries are mesa_drivers (libGLX_mesa, ...) and nvidia-x11 (libGLX_nvidia, ...).

libglvnd needs to have /run/opengl-driver/lib in RUNPATH so that the vendor libraries are found by dlopen even in the absence of LD_LIBRARY_PATH. This was the whole point of #60985 and removing it would re-introduce #22760. The purpose of the RUNPATH is not to find libGL/libEGL but to find the vendor libraries.

@ambrop72
Copy link
Contributor

My guess is that mesa needs some headers from libglvnd to build but does not link to any library. This can be solved by making a libglvnd-headers package and using that instead, and checking that there are no references left to it.

@matthewbauer
Copy link
Member Author

My guess is that mesa needs some headers from libglvnd to build but does not link to any library. This can be solved by making a libglvnd-headers package and using that instead, and checking that there are no references left to it.

Ok that sounds good! I will look into it now.

Otherwise does this seems like an okay thing to do? Things like nixGL would still be useful if you need the real drivers, but the fallback should be okay for at least some use cases.

@abbradar
Copy link
Member

I like a fallback in principle but we need to address the problem of people misunderstanding how their software works. Specifically: someone starts a graphics-heavy application from Nix on a non-NixOS system. It starts but is slow for some reason. As I feel people don't expect that to happen because wrong drivers were chosen; instead they think it's a problem with their current drivers or their video card is slow or something and will lose time debugging.

This can be solved if a debug message of some sort is displayed (e.g. "Falling back to software rendering; if you are on non-NixOS you need nixGL to run applications with hardware rendering."); maybe a patch to libglvnd?

@baloo
Copy link
Member

baloo commented Jul 6, 2019

I tried building glxinfo from this branch on debian, and I get the following result:

cycle detected in the references of '/nix/store/lwg87blivdmh3sfkgb3703hwxjbdgl0r-mesa-noglu-18.3.4-drivers' from '/nix/store/ns68h0xiakx3gaanxr5163y6j3nqm09y-mesa-noglu-18.3.4-swrast'
cannot build derivation '/nix/store/f79znzzhv1xb5vkb5pka4mykpz2zwzk5-libGL-1.0.0.drv': 1 dependencies couldn't be built
error: build of '/nix/store/f79znzzhv1xb5vkb5pka4mykpz2zwzk5-libGL-1.0.0.drv' failed

being somewhat a newbie on nix, I am missing something? (building with nix-shell $NIXPKGS -A glxinfo with the branch checkout in NIXPKGS)

@FRidh FRidh added this to New in Staging Oct 24, 2019
@FRidh FRidh moved this from New to WIP in Staging Oct 24, 2019
@spacekitteh
Copy link
Contributor

Any movement on this?

@stale
Copy link

stale bot commented Aug 10, 2020

Hello, I'm a bot and I thank you in the name of the community for your contributions.

Nixpkgs is a busy repository, and unfortunately sometimes PRs get left behind for too long. Nevertheless, we'd like to help committers reach the PRs that are still important. This PR has had no activity for 180 days, and so I marked it as stale, but you can rest assured it will never be closed by a non-human.

If this is still important to you and you'd like to remove the stale label, we ask that you leave a comment. Your comment can be as simple as "still important to me". But there's a bit more you can do:

If you received an approval by an unprivileged maintainer and you are just waiting for a merge, you can @ mention someone with merge permissions and ask them to help. You might be able to find someone relevant by using Git blame on the relevant files, or via GitHub's web interface. You can see if someone's a member of the nixpkgs-committers team, by hovering with the mouse over their username on the web interface, or by searching them directly on the list.

If your PR wasn't reviewed at all, it might help to find someone who's perhaps a user of the package or module you are changing, or alternatively, ask once more for a review by the maintainer of the package/module this is about. If you don't know any, you can use Git blame on the relevant files, or GitHub's web interface to find someone who touched the relevant files in the past.

If your PR has had reviews and nevertheless got stale, make sure you've responded to all of the reviewer's requests / questions. Usually when PR authors show responsibility and dedication, reviewers (privileged or not) show dedication as well. If you've pushed a change, it's possible the reviewer wasn't notified about your push via email, so you can always officially request them for a review, or just @ mention them and say you've addressed their comments.

Lastly, you can always ask for help at our Discourse Forum, or more specifically, at this thread or at #nixos' IRC channel.

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Aug 10, 2020
@spacekitteh
Copy link
Contributor

still important to me

@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Aug 11, 2020
@bobismijnnaam
Copy link
Contributor

I would also like to use something like this for non-performance critical drawing (such as drawing graphs in mcrl2). I also ran into the cycle error that @baloo encountered.

@stale
Copy link

stale bot commented Apr 7, 2021

I marked this as stale due to inactivity. → More info

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Apr 7, 2021
@spacekitteh
Copy link
Contributor

not stale :(

@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Apr 7, 2021
@stale
Copy link

stale bot commented Oct 12, 2021

I marked this as stale due to inactivity. → More info

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Oct 12, 2021
@spacekitteh
Copy link
Contributor

sigh

@SuperSandro2000
Copy link
Member

not stale :(

Stale is to describe that in over a year nothing happened in this PR which is correct.

@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Nov 15, 2021
@SuperSandro2000 SuperSandro2000 added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Nov 15, 2021
@AleksanderGondek
Copy link
Contributor

Why did you remove addOpenGLRunpath from libglvnd? Looks like an accident to me.

Sorry i should have commented on that. But leaving it here leads to an infinite recursion because libglvnd -> addOpenGLRunpath -> mesa -> libglvnd. I am pretty sure it is unnecessary because it does not link against libGL or libEGL at all. It is the library used to detect which driver vendor you will need.

libglvnd provides a generic libGL/libEGL that programs should link to and use. It is a dispatch library which figures out the <vendor>, dlopens libGLX_<vendor>/libEGL_<vendor> and forwards calls to it. Possible vendor libraries are mesa_drivers (libGLX_mesa, ...) and nvidia-x11 (libGLX_nvidia, ...).

libglvnd needs to have /run/opengl-driver/lib in RUNPATH so that the vendor libraries are found by dlopen even in the absence of LD_LIBRARY_PATH. This was the whole point of #60985 and removing it would re-introduce #22760. The purpose of the RUNPATH is not to find libGL/libEGL but to find the vendor libraries.

Thank you!

@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Dec 6, 2021
@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jun 12, 2022
@K900
Copy link
Contributor

K900 commented Apr 3, 2023

No longer relevant as Mesa will automatically fall back to software drivers now.

@K900 K900 closed this Apr 3, 2023
Staging automation moved this from WIP to Done Apr 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Staging
  
Done