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

Wrapping MESA in OpenGL #10701

Open
ocaisa opened this issue May 27, 2020 · 4 comments
Open

Wrapping MESA in OpenGL #10701

ocaisa opened this issue May 27, 2020 · 4 comments

Comments

@ocaisa
Copy link
Member

ocaisa commented May 27, 2020

At JSC, we are moving away from MESA to providing an OpenGL that "does the right thing". Just so people get an idea what is going on, see the easyconfig below (also requires some patches).

easyblock = 'Bundle'

name = 'OpenGL'
version = '2019a'

homepage = 'http://www.opengl.org/'
description = """
Open Graphics Library (OpenGL) is a cross-language, cross-platform application programming interface (API) for rendering
2D and 3D vector graphics. Mesa is an open-source implementation of the OpenGL specification - a system for rendering
interactive 3D graphics. NVIDIA supports OpenGL and a complete set of OpenGL extensions, designed to give a maximum
performance on NVIDIA GPUs.

This is a GL vendor neutral dispatch (GLVND) installation with Mesa and NVIDIA in the same lib-directory. Mesa or NVIDIA
OpenGL is set individually for each XScreen.
"""

toolchain = {'name': 'GCCcore', 'version': '8.3.0'}

# The %(pyver)s does not work since the template resolution is not working when using build dependencies and minimal
# toolchains. See: https://github.com/easybuilders/easybuild-framework/issues/3300
local_pyver = '3.6.8'

builddependencies = [
    ('Python', local_pyver),
    ('binutils', '2.32'),
    ('flex', '2.6.4'),
    ('Bison', '3.3.2'),
    ('Autotools', '20180311'),
    ('pkg-config', '0.29.2'),
    ('expat', '2.2.6'),
    ('libxml2', '2.9.9', '-Python-%s' % local_pyver),
    ('Meson', '0.50.0', '-Python-%s' % local_pyver),
    ('Ninja', '1.9.0'),
    ('CMake', '3.14.0'),
]

dependencies = [
    ('zlib', '1.2.11'),
    ('nettle', '3.4'),
    ('libdrm', '2.4.97'),
    ('LLVM', '8.0.0'),
    ('X11', '20190311'),
    ('libunwind', '1.3.1'),
    ('nvidia', 'driver', '', SYSTEM),
]

default_easyblock = 'ConfigureMake'

default_component_specs = {
    'sources': [SOURCE_TAR_GZ],
    'start_dir': '%(name)s-%(version)s',
}

local_pkg_config = ('export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:%(installdir)s/lib/pkgconfig && '
                    'export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:%(installdir)s/lib64/pkgconfig && ')

components = [
    # A vendor neutral dispatch layer
    ('libglvnd', '1.2.0', {
        'source_urls': [
            'https://github.com/NVIDIA/libglvnd/archive/'
        ],
        'sources': ['v%(version)s.tar.gz'],
        'checksums': ['37981bd3320261f14140b8aef6e2e6c08c7e75b6a98dcea034670017f3f1312a'],
        'preconfigopts': './autogen.sh && '
    }),
    # Mesa for software rendering, not hardware rendering.
    ('Mesa', '19.2.1', {
        # We build:
        # - llvmpipe: the high-performance Gallium LLVM driver (only possible with glx=gallium-xlib)
        # - swr: Intel's OpenSWR
        'easyblock': 'MesonNinja',
        'source_urls': [
            'https://mesa.freedesktop.org/archive/',
            'https://mesa.freedesktop.org/archive/%(version)s',
            'ftp://ftp.freedesktop.org/pub/mesa/%(version)s',
            'ftp://ftp.freedesktop.org/pub/mesa/older-versions/%(version_major)s.x/%(version)s',
            'ftp://ftp.freedesktop.org/pub/mesa/older-versions/%(version_major)s.x',
        ],
        'sources': [SOURCELOWER_TAR_XZ],
        'checksums': [
            '4cc53ca1a8d12c6ff0e5ea44a5213c05c88447ab50d7e28bb350cd29199f01e9',
            '8997808ec140990141669d7ad7a536bba541aadbde85fdc1ec9cf849a945caa9',
            'f448455984b6234ef99ac348f9f641ec650eccfe659232ead0292c99441b9840',
        ],
        'start_dir': '%(namelower)s-%(version)s',
        'separate_build_dir': True,
        'patches': [
            'Mesa-19.2.1-match-swrast-loosely.patch',
            'Mesa-19.2.1-meson-avoid-march.patch',
        ],
        'preconfigopts': local_pkg_config,
        'configopts': (' -D libdir=%(installdir)s/lib'
                       ' -D gbm=true'
                       ' -D glx=auto'
                       ' -D osmesa=gallium'
                       ' -D llvm=true'
                       ' -D shared-llvm=true'
                       ' -D dri-drivers=""'
                       ' -D gallium-drivers="swr,swrast"'
                       ' -D swr-arches=avx,avx2,skx,knl'
                       ' -D vulkan-drivers=""'
                       ' -D platforms=x11,drm,surfaceless'
                       ' -D glvnd=true'
                       ' -D libunwind=true'
                       ' -D egl=true'
                       ' -D gles1=true -Dgles2=true'
                       ' -D shared-glapi=true'
                       ' -D gallium-omx=disabled'
                       ' -D buildtype=release'),
    }),
    # OpenGL Extension Wrangler Library - determines which OpenGL extensions are supported at run-time
    # This is just GLEW for GLX (which requires DISPLAY to be set) and not GLEW for EGL as GLEW selects GLX/EGL at
    # compile-time and not run-time (https://github.com/nigels-com/glew/issues/172#issuecomment-357400019)
    # Compile+Load GLEW-EGL on top to enable GLEW for EGL
    ('glew', '2.2.0', {
        'source_urls': [
            'https://sourceforge.net/projects/glew/files/glew/snapshots/',
        ],
        'sources': [
            'glew-20200115.tgz',
        ],
        'checksums': [
            '314219ba1db50d49b99705e8eb00e83b230ee7e2135289a00b5b570e4a4db43a',
        ],
        'skipsteps': ['configure'],
        'buildopts': ('GLEW_PREFIX=%(installdir)s GLEW_DEST=%(installdir)s LIBDIR=%(installdir)s/lib '
                      'LDFLAGS.EXTRA="-L${EBROOTX11}/lib/ -lX11" LDFLAGS.GL="-L%(installdir)s/lib -lGL"'),
        'installopts': 'GLEW_PREFIX=%(installdir)s GLEW_DEST=%(installdir)s LIBDIR=%(installdir)s/lib ',
        'install_cmd': 'make install.all ',
    }),
    # OpenGL Utility Library - offers higher level GL-graphics functions
    ('glu', '9.0.1', {
        'source_urls': [
            'ftp://ftp.freedesktop.org/pub/mesa/glu/'
        ],
        'sources': [
            'glu-%(version)s.tar.gz'
        ],
        'checksums': [
            'f6f484cfcd51e489afe88031afdea1e173aa652697e4c19ddbcb8260579a10f7',
        ],
    }),
    ('demos', '95c1a57cfdd1ef2852c828cba4659a72575c5c5d', {
        'source_urls': [
            'https://gitlab.freedesktop.org/mesa/demos/-/archive/%(version)s/',
        ],
        'sources': [SOURCELOWER_TAR_GZ],
        'checksums': [
            '7738beca8f6f6981ba04c8a22fde24d69d6b2aaab1758ac695c9475bf704249c',
        ],
        'preconfigopts': ('./autogen.sh && ' +
                          local_pkg_config +
                          'GLEW_CFLAGS="-I%(installdir)s/include/" GLEW_LIBS="-L%(installdir)s/lib/ -lGLEW -lGL" '
                          'EGL_CFLAGS="-I%(installdir)s/include/" EGL_LIBS="-L%(installdir)s/lib/ -lEGL" '),
        'configopts': '--disable-osmesa ',
    }),
]

postinstallcmds = [
    'cd %(installdir)s/lib && ln -sf libGL.so.1.7.0 libGL.so.1',
    'rm %(installdir)s/lib/*.la',
    'cd %(installdir)s/lib && ln -sf ${EBROOTNVIDIA}/lib64/libEGL_nvidia.so.0 .',
    'cd %(installdir)s/lib && ln -sf ${EBROOTNVIDIA}/lib64/libGLX_nvidia.so.0 .',
    'cd %(installdir)s/lib && ln -sf libGLX_mesa.so.0 libGLX_indirect.so.0',
    'cd %(installdir)s/lib && ln -sf ${EBROOTNVIDIA}/lib64/libGLESv1_CM_nvidia.so.1 .',
    'cd %(installdir)s/lib && ln -sf ${EBROOTNVIDIA}/lib64/libGLESv2_nvidia.so.2 .',
    # EGL vendor ICDs
    'echo "{"                                               >  %(installdir)s/share/glvnd/egl_vendor.d/10_nvidia.json',
    'echo "  \"file_format_version\" : \"1.0.0\","          >> %(installdir)s/share/glvnd/egl_vendor.d/10_nvidia.json',
    'echo "  \"ICD\" : {"                                   >> %(installdir)s/share/glvnd/egl_vendor.d/10_nvidia.json',
    'echo "      \"library_path\" : \"libEGL_nvidia.so.0\"" >> %(installdir)s/share/glvnd/egl_vendor.d/10_nvidia.json',
    'echo "  }"                                             >> %(installdir)s/share/glvnd/egl_vendor.d/10_nvidia.json',
    'echo "}"                                               >> %(installdir)s/share/glvnd/egl_vendor.d/10_nvidia.json',
    'echo "{"                                               >  %(installdir)s/share/glvnd/egl_vendor.d/50_mesa.json',
    'echo "  \"file_format_version\" : \"1.0.0\","          >> %(installdir)s/share/glvnd/egl_vendor.d/50_mesa.json',
    'echo "  \"ICD\" : {"                                   >> %(installdir)s/share/glvnd/egl_vendor.d/50_mesa.json',
    'echo "      \"library_path\" : \"libEGL_mesa.so.0\""   >> %(installdir)s/share/glvnd/egl_vendor.d/50_mesa.json',
    'echo "  }"                                             >> %(installdir)s/share/glvnd/egl_vendor.d/50_mesa.json',
    'echo "}"                                             >> %(installdir)s/share/glvnd/egl_vendor.d/50_mesa.json',
    # correct pkg-config of GLEW
    'sed -i "/^libdir=/c\libdir=\${exec_prefix}\/lib" %(installdir)s/lib/pkgconfig/glew.pc',
    'sed -i "/^prefix=/c\prefix=%(installdir)s"       %(installdir)s/lib/pkgconfig/glew.pc',
]

modextravars = {
    '__EGL_VENDOR_LIBRARY_FILENAMES': ('%(installdir)s/share/glvnd/egl_vendor.d/10_nvidia.json:'
                                       '%(installdir)s/share/glvnd/egl_vendor.d/50_mesa.json'),
    'EGL_PLATFORM': 'surfaceless',
    'EGL_DRIVER': 'swr',
    'EGL_LOG_LEVEL': 'fatal',
    'GALLIUM_DRIVER': 'swr',
    'KNOB_MAX_WORKER_THREADS': '65535',
}

modluafooter = '''
add_property("arch","gpu")

conflict("Mesa")
conflict("libGLU")
'''

sanity_check_paths = {
    'files': [
        'lib/libEGL_mesa.%s' % SHLIB_EXT, 'lib/libOSMesa.%s' % SHLIB_EXT,
        'include/GL/glext.h', 'include/GL/gl_mangle.h', 'include/GL/glx.h',
        'include/GL/osmesa.h', 'include/GL/gl.h', 'include/GL/glxext.h',
        'include/GL/glx_mangle.h', 'include/GLES/gl.h', 'include/GLES2/gl2.h', 'include/GLES3/gl3.h',
        'lib/libOpenGL.%s' % SHLIB_EXT,
        'lib/libGLEW.a', 'lib/libGLEW.%s' % SHLIB_EXT,
        'bin/glewinfo', 'bin/visualinfo',
        'include/GL/glew.h', 'include/GL/glxew.h', 'include/GL/wglew.h',
    ],
    'dirs': []
}

moduleclass = 'vis'
@ocaisa
Copy link
Member Author

ocaisa commented May 27, 2020

This is here as an FYI, it needs to be turned into an easyblock.

@ocaisa
Copy link
Member Author

ocaisa commented May 27, 2020

This is being developed by @jhgoebbert but I know that people in the maintainer list are interested in this

@paulmelis
Copy link
Contributor

This is really nice! A much better approach than using Mesa as a dep in every package that uses OpenGL. However, it seems to be based on the idea of having a separate package/module for the NVIDIA driver binaries (I see EBROOTNVIDIA) instead of using the driver installer?

@paulmelis
Copy link
Contributor

But how would an easyblock version of the above work?

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

2 participants