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

VirtualBox nixos guest missing 3D acceleration #18457

Closed
viric opened this issue Sep 9, 2016 · 22 comments · Fixed by #60985
Closed

VirtualBox nixos guest missing 3D acceleration #18457

viric opened this issue Sep 9, 2016 · 22 comments · Fixed by #60985

Comments

@viric
Copy link
Member

viric commented Sep 9, 2016

In NixOS 16.03 I enable VirtualBox guest additions (virtualization.virtualbox.guest.enable = true) and I properly get Direct Rendering in X.org but it still uses the swrast GL code. In VirtualBox I do enable "3D acceleration" but I guess there should be some userlib in the guest that makes GL go through the vm for the acceleration.

Does anybody know how to get this 3d acceleration?

Thank you.

@domenkozar
Copy link
Member

Did you check if guest additions are correctly installed and enabled?

@viric
Copy link
Member Author

viric commented Oct 11, 2016

Sure, they are installed. I also made the guest nixos module put virtualbox_dri.so to /run/opengl-driver/lib/dri, but that did not help.

My X log only says:

vboxvideo: kernel driver found, not loading.
modeset(0): using drv /dev/dri/card0
...
AIGLX: Screen 0 is not DRI2 compatible
AIGLX: reverting to software rendering

I tried with 'modeset' in cmdline too, no difference.

@viric
Copy link
Member Author

viric commented Oct 11, 2016

Ok, I have a dirty patch that makes it work. Basically, libGL.so.1 should point to VBoxOGL.so, instead of the mesa one. Then, acceleration works.

But in my machine, Optimus (Intel+NVidia), I fail to make the acceleration go through NVidia and I only get the Intel acceleration. Like this poor guy: http://superuser.com/questions/779070/use-nvidia-gpu-from-virtualbox (but it is another topic).

We should think how to add a nixos option that makes the libGL.so.1 override in opengl-drivers/lib

@viric
Copy link
Member Author

viric commented Oct 11, 2016

btw, here is the source from where I got the idea of the symlink: https://bugs.archlinux.org/task/49752

@husnoo
Copy link

husnoo commented Dec 22, 2016

I was able to get it to work using the link you provided:

LD_PRELOAD=/nix/store/jbyg9nzcg405qw8byjg5p35fnhkknivz-system-path/lib/VBoxOGL.so glxinfo | grep -i render

Any ideas how to make this the default using my configuration.nix?

thanks!

@rehno-lindeque
Copy link
Contributor

I think that #9415 may be somewhat related.

@rehno-lindeque
Copy link
Contributor

Also #1608 and #5051

@lovek323
Copy link
Member

I'm having the same issue. I can get good output from glxinfo in a similar way to @husnoo, but I am not sure where to go from here.

@rehno-lindeque
Copy link
Contributor

I'd been meaning to submit a PR for this, but unfortunately I'm no longer on VirtualBox.

Last time I tried it this expression in my config worked more or less:

{ pkgs
, config
, ...
}:

let
  makePackage = p: p.buildEnv {
    name = "mesa+vbox+txc-${p.mesa_drivers.version}";
    paths =
      let version = "5.1.12";
          virtualboxGuestAdditions = p.linuxPackages.virtualboxGuestAdditions.overrideDerivation (oldAttrs: {
              /* src = p.fetchurl { */
              /*   url = "http://download.virtualbox.org/virtualbox/${version}/VBoxGuestAdditions_${version}.iso"; */
              /*   sha256 = "08a3vycj7yw6ihb3myi9yhag1ivpwdl9m5c33viw66lpmdf2d80k"; */
              /* }; */
              buildCommand = lib.traceShowVal oldAttrs.buildCommand +
                ''
                  ln -s $out/lib/VBoxOGL.so $out/lib/libGL.so
                  ln -s $out/lib/VBoxOGL.so $out/lib/libGL.so.1
                  ln -s $out/lib/VBoxOGL.so $out/lib/libGL.so.1.2.0
                  # TODO: in the next version add EGL? 
                  # patchelf --set-rpath ${lib.makeLibraryPath (with p; with p.xorg; [ "$out" dbus libXcomposite libXdamage libXext libXfixes ])} lib/VBoxEGL.so
                  # cp -v lib/VBoxEGL.so $out/lib
                  # ln -s $out/lib/VBoxEGL.so $out/lib/libEGL.so
                  # ln -s $out/lib/VBoxEGL.so $out/lib/libEGL.so.1
                  # ln -s $out/lib/VBoxEGL.so $out/lib/libEGL.so.1.2.0
                '';
            });
      in
        [ virtualboxGuestAdditions # for the DRI driver
          # p.mesa_drivers
          # p.mesa_drivers.out # mainly for libGL # (TODO: replace?)
          (if config.hardware.opengl.s3tcSupport then p.libtxc_dxtn else p.libtxc_dxtn_s2tc)
        ];
  };
in
{
  hardware = {
    opengl = {
      /* FIXME: See https://github.com/NixOS/nixpkgs/issues/5051#issuecomment-64393958 */
      package = makePackage pkgs;
      /* extraPackages = [pkgs.linuxPackages.virtualboxGuestAdditions]; */
    };
  };
}

I hope it'll be helpful for someone that wants to submit a proper PR.

@cgo
Copy link

cgo commented Mar 26, 2017

@rehno-lindeque, I am relatively new to nixos, just trying to get it to do what I want for the second time (tried a while ago). When I simply paste your configuration snippet from above in my configuration.nix,
and call nixos-rebuild, it complains that the variable lib is undefined.
Any hint what I am doing wrong? Thanks!

@vcunat
Copy link
Member

vcunat commented Mar 27, 2017

@cgo: typically one adds lib to the parameter list at the start, but it's also accessible e.g. as pkgs.stdenv.lib.

@vcunat
Copy link
Member

vcunat commented Mar 27, 2017

BTW, setting videoDrivers = [ "virtualbox" ]; on the guest nixos config is supposed to do all this automatically. Now I see this setting is even done by virtualisation.virtualbox.guest.x11 = true; If this doesn't work, it's a bug somewhere in the implementation. (I've never tested this myself.)

@rehno-lindeque
Copy link
Contributor

rehno-lindeque commented Mar 28, 2017

BTW, setting videoDrivers = [ "virtualbox" ]; on the guest nixos config is supposed to do all this automatically.

@vcunat @cgo To clarify, the expression above makes use of virtualbox's VBoxOGL.so for hardware acceleration. Without this you get software-only rendering for 3D graphics. Never-the-less I wouldn't recommend this ugly hack unless you specifically need it or want to submit a PR.

@nek0
Copy link
Contributor

nek0 commented Aug 25, 2018

any movement on this?

@flokli
Copy link
Contributor

flokli commented May 20, 2019

This should get fixed by #60985.

@ambrop72
Copy link
Contributor

This should get fixed by #60985.

I don't think so. The problem is that the 3D support in VirtualBox additions relies on programs loading VBoxOGL.so in place of libGL.so, it (presumably) doesn't play with libglvnd. The current additions package doesn't provide the symlinks from libGL.so to VBoxOGL.so which supposedly fix this issue. Actually, #60985 will make it a bit harder to get this working once LD_LIBRARY_PATH no longer contains /run/opengl-driver/lib (one could still set it manually though).

But since the Linux 3D support on VirtualBox has a questionable support status and is known to have issues, I would be reluctant to make it enabled automatically even if we support it.

@flokli
Copy link
Contributor

flokli commented May 20, 2019

If virtualbox would support libglvnd, this would have fixed it in a nice way.

But unfortunately you're right. Seems adding libglvnd and/or fixing some of the unstable 3d guest support is very much down on Oracles priority list: https://www.virtualbox.org/pipermail/vbox-dev/2017-June/014561.html

We should probably add some documentation on how to load VBoxOGL.so manually, but seems using 3d acceleration from a Linux guest currently isn't really advisable…

@zarelit
Copy link
Member

zarelit commented May 23, 2019

@flokli @ambrop72 In the last two comments it looked like the #60985 would NOT solve the issue, does this mean that it has been fixed or that this has been closed accidentally?

flokli added a commit to flokli/nixpkgs that referenced this issue May 23, 2019
It seems to be broken upstream too, and fixing it is far down the
priority list:
https://www.virtualbox.org/pipermail/vbox-dev/2017-June/014561.html
Additionally, 3d support seems to rely on VBoxOGL.so being symlinked
from libGL.so (which we can't), and Oracle doesn't plan on supporting
libglvnd either. (NixOS#18457)
@flokli
Copy link
Contributor

flokli commented May 23, 2019

@zarelit as explained in the mail linked in my comment, 3d guest support is pretty much broken in virtualbox upstream too, and fixing that is far down on Oracle's priority list:

In fact, as soon as I get round to it I will disable 3D support for
Fedora guests altogether, as it is not reliable.

On top of that, it's probably not really possible to run it in NixOS either, due to it not supporting libglvnd.

I guess this would need to be fixed upstream first.

I opened #61944 which changes virtualboxGuestAdditions to not install VBoxOGL.so, with a comment on why.

@zarelit
Copy link
Member

zarelit commented May 23, 2019

@flokli thank you for the clarification on for your work on this!

@husnoo
Copy link

husnoo commented May 23, 2019

just to clarify, there's a working solution for this, but we're not going to make it easy for ideological reasons? did I understand this right?

@flokli
Copy link
Contributor

flokli commented May 23, 2019

@husnoo The reasons are mostly technical, given even upstream considers their driver to be unstable and are thinking loudly about disabling it entirely.

This could be made "easy" by passing in the VBoxOGL driver (together with the required libGL.so symlinks) through hardware.opengl.extraPackages, behind a virtualisation.virtualbox.guest.enableHardwareAcceleration option. I'd be reluctant to unconditionally enable it on virtualisation.virtualbox.guest.enable together with the other additions, given its unstable nature (we could flip the default if/when things improve).

I was just assuming there wasn't too much need in supporting that, given nobody stepped up with a PR after a possible solution was sketched in March 2017.

I'd be happy to review a PR adding this option, though ;-)

peti pushed a commit that referenced this issue May 27, 2019
It seems to be broken upstream too, and fixing it is far down the
priority list:
https://www.virtualbox.org/pipermail/vbox-dev/2017-June/014561.html
Additionally, 3d support seems to rely on VBoxOGL.so being symlinked
from libGL.so (which we can't), and Oracle doesn't plan on supporting
libglvnd either. (#18457)
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 a pull request may close this issue.