opengl: Use glxgallium Mesa when VirtualGL is not appropriate
This commit is contained in:
@@ -3,7 +3,9 @@
|
||||
# Add a setup hook to the mesa_noglu package that automatically adds
|
||||
# a libvglfaker.so dependency to executables that depend on libGL.so.
|
||||
|
||||
{ super, lib, buildEnv, makeSetupHook, file, bash, xorg }:
|
||||
{ super, stdenv, buildEnv, substituteAll, bash
|
||||
, autoreconfHook, pkgconfig, python2
|
||||
, xorg, llvmPackages, expat, mesa_glxgallium, mesa_noglu, libglvnd }:
|
||||
|
||||
let
|
||||
autoVirtualGLHook =
|
||||
@@ -15,28 +17,105 @@ let
|
||||
|
||||
libGL = super.libGL;
|
||||
libGLU = super.libGLU.override { inherit libGL; };
|
||||
libGLU_combined = (buildEnv {
|
||||
libGLU_combined = buildEnv {
|
||||
name = "libGLU-combined";
|
||||
paths = [ libGL libGLU ];
|
||||
extraOutputsToInstall = [ "dev" ];
|
||||
});
|
||||
};
|
||||
|
||||
virtualglLib = (super.virtualglLib.override { inherit libGLU_combined fltk; });
|
||||
fltk = super.fltk.override { inherit libGLU_combined freeglut; };
|
||||
freeglut = super.freeglut.override { inherit libGL libGLU; };
|
||||
in
|
||||
makeSetupHook {
|
||||
name = "insert-virtualgl";
|
||||
deps = [ file virtualglLib ];
|
||||
substitutions = { inherit virtualglLib bash; inherit (xorg) libXext; };
|
||||
} ./insert-virtualgl.sh;
|
||||
substituteAll {
|
||||
src = ./insert-virtualgl.sh;
|
||||
bash = "${bash}/bin/bash";
|
||||
virtualglLib = "${virtualglLib}/lib/libvglfaker.so";
|
||||
};
|
||||
|
||||
in {
|
||||
libGL = super.libGL.overrideAttrs ( attrs: {
|
||||
# Done as a non-standard build command, so have to add it in this way
|
||||
|
||||
buildCommand = attrs.buildCommand + ''
|
||||
echo '${autoVirtualGLHook}' >> $dev/nix-support/propagated-build-inputs
|
||||
# Mesa build for glxgallium software rendering (works with all X11 forwarding)
|
||||
|
||||
mesa_glxgallium = stdenv.mkDerivation rec {
|
||||
version = super.mesa_noglu.version;
|
||||
name = "mesa-glxgallium-${version}";
|
||||
src = super.mesa_noglu.src;
|
||||
|
||||
outputs = [ "out" "dev" ];
|
||||
|
||||
configureFlags = [
|
||||
"--with-gallium-drivers=swrast"
|
||||
"--with-platforms=x11" # surfaceless would make sense, but egl requires dri
|
||||
"--disable-dri"
|
||||
"--enable-glx=gallium-xlib" # gallium-xlib requires no dri
|
||||
"--enable-gallium-osmesa"
|
||||
"--enable-llvm"
|
||||
"--disable-egl" # egl requries dri for some reason
|
||||
"--disable-gbm" # gbm requires dri for some reason
|
||||
"--enable-llvm-shared-libs"
|
||||
"--disable-opencl"
|
||||
];
|
||||
|
||||
nativeBuildInputs = [
|
||||
autoreconfHook pkgconfig
|
||||
python2
|
||||
];
|
||||
propagatedBuildInputs = [ ];
|
||||
buildInputs = [
|
||||
llvmPackages.llvm
|
||||
xorg.xorgproto xorg.libX11 xorg.libXext xorg.libxcb
|
||||
expat
|
||||
];
|
||||
|
||||
enableParallelBuilding = true;
|
||||
|
||||
meta = with stdenv.lib; {
|
||||
description = "An open source implementation of OpenGL";
|
||||
homepage = https://www.mesa3d.org/;
|
||||
license = licenses.mit; # X11 variant, in most files
|
||||
platforms = platforms.linux;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
# Duplicate mesa_noglu.stub with mesa_glxgallium stuffed in as the libGL source
|
||||
|
||||
libGL = stdenv.mkDerivation {
|
||||
name = "libGL-${libglvnd.version}";
|
||||
outputs = [ "out" "dev" ];
|
||||
|
||||
nativeBuildInputs = [ xorg.lndir ];
|
||||
|
||||
# Use stub libraries from mesa_glxgallium and libglvnd and headers from lib_noglu
|
||||
buildCommand = ''
|
||||
mkdir -p $out/lib
|
||||
lndir -silent ${mesa_glxgallium.out}/lib $out/lib
|
||||
lndir -silent ${libglvnd.out}/lib $out/lib
|
||||
|
||||
mkdir -p $dev/{,lib/pkgconfig,nix-support}
|
||||
echo "$out" > $dev/nix-support/propagated-build-inputs
|
||||
echo ${autoVirtualGLHook} >> $dev/nix-support/propagated-build-inputs
|
||||
ln -s ${mesa_noglu.dev}/include $dev/include
|
||||
|
||||
genPkgConfig() {
|
||||
local location="$1"
|
||||
local name="$2"
|
||||
local lib="$3"
|
||||
|
||||
cat <<EOF >$dev/lib/pkgconfig/$name.pc
|
||||
Name: $name
|
||||
Description: $lib library
|
||||
Version: ${mesa_noglu.version}
|
||||
Libs: -L$location/lib -l$lib
|
||||
Cflags: -I${mesa_noglu.dev}/include
|
||||
EOF
|
||||
}
|
||||
|
||||
genPkgConfig ${mesa_glxgallium.out} gl GL
|
||||
genPkgConfig ${libglvnd.out} egl EGL
|
||||
genPkgConfig ${libglvnd.out} glesv1_cm GLESv1_CM
|
||||
genPkgConfig ${libglvnd.out} glesv2 GLESv2
|
||||
'';
|
||||
} );
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user