Skip to content

Instantly share code, notes, and snippets.

@croberts81
Forked from baryluk/mesa-build.py
Created October 24, 2021 03:05
Show Gist options
  • Save croberts81/da4da68d0cf709e54baaa53b0775ca5f to your computer and use it in GitHub Desktop.
Save croberts81/da4da68d0cf709e54baaa53b0775ca5f to your computer and use it in GitHub Desktop.
Mesa and libdrm git, amdgpu build 64-bit and 32-bit for Debian testing and unstable, and possibly Ubuntu, Mint, PopOS, etc. No root required.
#!/bin/bash
# A simple script to build 64-bit and 32-bit libdrm, Mesa and vkpipeline-db
# on amd64 Debian testing, Debian unstable, and possibly some Ubuntu
# with some tweaks.
#
# libdrm is build too, because version right now in Debian sid and experimental
# is too old for current mesa git repo. Also it is nice to build debug
# versions of libdrm when troubleshooting some crashes and bugs.
#
# A situation with LLVM on Ubuntu was (is?) not perfect, so you are on your own.
#
# If you do not want to or can not use it, modify the script to install and use
# other LLVM and update LLVMVERSION variable below.
#
# It is too complex to handle fully automatically and be future proof. So just
# edit the script accordingly.
#
# By default only drivers for AMD, Intel and software rendering will be built.
# That will build radeon driver, radv (with ACO and LLVM), llvmpipe, swr,
# lavapipe, and zink, with few other minor things.
#
# No Nvidia drivers will be compiled. This is to speed up compilation
# a bit. Modify MESA_COMMON_OPTS to change that.
#
# OpenCL support with clover will be built for 64-bit, but you should know
# the OpenCL support in Mesa still has some bugs, so be aware.
# Valgrind extra support will be built for 64-bit only too.
# Otherwise rest (Mesa, OpenGL, Vulkan, Mesa overlay layer, Mesa device selection
# layer, gallium-nine, zink, lavapipe, vkpipeline-db), will be built for both
# 64-bit and 32-bit versions.
#
# No OpenGL ES (GLES), or EGL will be built. It is simply to save a bit of time
# compiling Mesa. You can enable it in MESA_COMMON_OPTS below.
#
# Similarlly a Wayland support is untested, and probably not enabled.
# Modify MESA_COMMON_OPTS if needed.
#
# Check variable BUILDDEBUG below to enable also debug builds, which can build
# together with optimized builds.
#
# The build will be performed in ~/mesa-git directory for you.
#
# The source tree will live in ~/mesa-git
# Built libraries and binaries will be in ~/mesa-git/builddir/build-{amd64,i386}-{dbg,opt}/
# Libraries and binaries will be installed into ~/mesa-git/installdir/build-{amd64,i386}-{dbg,opt}/
#
# After compilation is done, the script will perform a small test with glxinfo,
# vulkaninfo and vkcube for 2 seconds.
#
#
# After compilation is done, use '. ~/enable-new-mesa-opt.source'
# (without quotes) in your terminal to enable it.
# You can add it to your ~/.profile or ~/.bashrc file too.
#
# You need to use this '. ~/enable-new-mesa-opt.source' before any other
# OpenGL / Vulkan app is started from the same terminal. It is not enough to
# simply do '. ~/enable-new-mesa-opt.source' in a terminal, and the launch
# steam or some game via desktop shorcut, or other terminal. The changes are
# local to the terminal / shell you used it to. You can use it in many terminals
# as you wish.
#
# Note that `enable-new-mesa-opt.source` will also automatically enable ACO if
# available and enable Vulkan Mesa overlay, Gallium HUD, and DXVK HUD.
# Feel free to modify this script below (line ~280 and ~328) to not do that.
# Or source the `disable-new-mesa-hud.source` script to undo the HUD stuff.
#
# This script will not install libraries system wide, so it is safe to use in
# parallel with your distro libraries. And even have applications using one
# or another, or some using optimized libraries and some using debug libraries.
#
# To get rid of it simply run:
#
# rm -rf ~/mesa-git ~/libdrm-git ~/vkpipeline-db ~/enable-new-mesa-*.source ~/disable-new-mesa-hud.source ~/mesa-{opt,dbg} ~/zink-{opt,dbg}
#
# If you want to use this Mesa's OpenGL / Vulkan for your desktop manager, like
# Gnome Shell, you are on your own, but it can be probably done some way by
# putting needed variables in /etc/environment. Maybe...
# Or tweak INSTALLDIR variable. But few more variables (`-Dprefix` for example)
# will be needed to be changed. See https://www.mesa3d.org/meson.html for details.
#
# Rerunning this script will cleanup builddir and installdirs from scratch,
# so it will take some time.
# If you want a bit faster updates, you can do "git pull", then go into proper
# build subdirectory and recompile, i.e. using:
# cd ~/mesa-git/builddir/build-amd64-opt/ && ninja && ninja install
#
# Copyright: Witold Baryluk <[email protected]>, 2019, 2020, 2021
# License: MIT style license
# Stop execution on first error, and don't continue.
set -e
if [ "x${DEBUG}" = "x1" ]; then
set -x
fi
export LC_ALL=C.UTF-8
# Show less output, but also do fully automatic apt-get setup not needing any confirmations.
QUIET="${QUIET:-0}"
if [ $(whoami) = "root" ]; then
echo "Do not run this script under root or using sudo!" >&2
exit 1
fi
if [ "x${QUIET}" = "x1" ]; then
echo
fi
cd "${HOME}"
BUILDDIR="${PWD}/mesa-git/builddir"
# Aka prefix, but we put each build into separate subprefix.
# So in total there will be 4 subprefixes (64-bit optimized, 32-bit optimized,
# 64-bit debug, 32-bit debug)
INSTALLDIR="${PWD}/mesa-git/installdir"
# Build optimized (-march=native -O2) binaries. If not, only separate debug
# build is built.
BUILDOPT="${BUILDOPT:-1}"
# Use heavy optimizations (-march=native -O3 -free-vectorize -flto -g0) in
# optimized build. This will take about twice as long to compile, might
# expose extra bugs in Mesa or GCC, and will make debugging a bit harder.
# I personally didn't notice any significant performance improvements,
# but in theory they are slightly faster.
HEAVYOPT="${HEAVYOPT:-0}"
# Build separate debug builds with -O1 -ggdb and Mesa debugging code (extra
# runtime checks and asserts) present. You can have both BUILDOPT and
# BUILDDEBUG enabled, and two versions of Mesa will be built, and you can
# switch between them per-app quickly. It is not recommended to use it in
# general unless you find an issue in some apps, crashes, or glitches.
# It is safe to enable building debug builds, even if you are only going to
# use optimized built. They are completly independent.
BUILDDEBUG="${BUILDDEBUG:-0}"
# Build Clover / OpenCL / OpenCL-SpirV support for 64-bit. This flag is ignored
# for 32-bit builds at the moment.
BUILDOPENCL="${BUILDOPENCL:-1}"
BUILD64="${BUILD64:-1}"
BUILD32="${BUILD32:-1}"
DRIVERS="amd,intel,zink,virgl,software"
GIT_REPO_MESA="${GIT_REPO:-https://gitlab.freedesktop.org/mesa/mesa.git}" # TODO(baryluk): Remove this usage of env variable as default.
GIT_BRANCH_MESA="${GIT_BRANCH}" # TODO(baryluk): Remove this usage of env variable as default.
GIT_DEPTH="${GIT_DEPTH:-1}"
# GIT_REPO_MESA=https://gitlab.freedesktop.org/zmike/mesa.git; GIT_BRANCH_MESA=zink-wip; GIT_DEPTH=1000
# GIT_REPO_MESA=https://gitlab.freedesktop.org/Venemo/mesa.git; GIT_BRANCH_MESA=aco-navi
GIT_REPO_LIBDRM="https://gitlab.freedesktop.org/mesa/drm.git"
GIT_BRANCH_LIBDRM="master"
USE_SYSTEM_LIBDRM=0 # Set to "1" to use system libdrm-dev.
usage () {
echo "$0 usage:"
echo "--help Show this message and exit"
echo "--quiet Run in quiet and automated mode. Default: ${QUIET}"
echo "--debug=[0|1] Run in debug mode. Default: ${DEBUG}"
echo "--git-repo-mesa=URL If sourcedir doesn't exist, clone the repo with URL. Default: ${GIT_REPO_MESA}"
echo "--git-branch-mesa=B For --git-repo which branch to checkout. Default: ${GIT_BRANCH_MESA}"
echo "--git-repo-libdrm=URL If sourcedir doesn't exist, clone the repo with URL. Default: ${GIT_REPO_LIBDRM}"
echo "--git-branch-libdrm=B For --git-repo which branch to checkout. Default: ${GIT_BRANCH_LIBDRM}"
echo "--git-depth=N For --git-repo-mesa and --git-repo-libdrm what --depth=N to use. Default: ${GIT_DEPTH}"
#echo "--git-full-depth=N For the clone, use full clone, instead of using --depth=1000. Default: no."
echo "--git-repo=URL Deprecated alias for --git-repo-mesa"
echo "--git-branch=B Deprecated alias for --git-branch-mesa"
#echo "--no-clean Don't remove builddir and installdir at the start. Default: no (full clean)."
#echo "--sourcedir=D Where to put mesa sources. Default: ~/mesa-git"
#echo "--builddir=D Base for the build location. Default: ${BUILDDIR}"
#echo "--installdir=D Base for the install location. Default: ${INSTALLDIR}"
echo "--build64=[0|1] Build 64-bit version. Default: ${BUILD64}"
echo "--build32=[0|1] Build 32-bit version. Default: ${BUILD32}"
echo "--buildopt=[0|1] Build optimized (-O2 -march=native + debug code disabled) version. Default: ${BUILDOPT}"
echo "--builddebug=[0|1] Build debug (-O1 -ggdb -g3 + asserts / checks enabled) version. Default: ${BUILDDEBUG}"
echo "--heavyopt=[0|1] Use additionally -O3 -march=native -flto -g -mf16c -mfpmath=sse ... et al for --buildopt. Default: ${HEAVYOPT}"
echo "--buildopencl=[0|1] Include OpenCL support (Clover). Default: ${BUILDOPENCL}"
#echo "--buildextras=[0|1] Build extras (i.e. fossilize, shader-db). Default: 1"
echo "--drivers=LIST Drivers to include. Default: ${DRIVERS}"
#echo "--endchecks=[0|1] Perform post-install tests / sanity checks. Default: 1"
#echo "--uninstall Cleanup everything, sourcedir, builddir, installdir, and generated files, and exit. (Remember to pass --*dir options first, if needed). Default: no"
echo
echo "It is valid to have both --buildopt and --builddbg enabled at the same time."
echo "It will build two separate builds in own directories"
echo
exit 0
}
#[ $# -eq 0 ] && usage
opts=$(env --unset=GETOPT_COMPATIBLE getopt --name "$0" --options "" --longoptions "help,quiet,debug:,git-repo-mesa:,git-branch-mesa:,git-repo-libdrm:,git-branch-libdrm:,git-repo:,git-branch:,git-depth:,sourcedir:,builddir:,installdir:,build32:,build64:,builddebug:,buildopt:,heavyopt:,buildopencl:,buildextras:,drivers:" -- "$@")
eval set -- "${opts}"
while [[ $# -gt 0 ]]; do
case "$1" in
--help)
usage
exit 0
;;
--quiet)
QUIET=1
;;
--debug)
shift
DEBUG="$1"
;;
--git-repo-mesa)
shift
GIT_REPO_MESA="$1"
;;
--git-branch-mesa)
shift
GIT_BRANCH_MESA="$1"
;;
--git-repo-libdrm)
shift
GIT_REPO_LIBDRM="$1"
;;
--git-branch-libdrm)
shift
GIT_BRANCH_LIBDRM="$1"
;;
--git-repo)
shift
GIT_REPO_MESA="$1"
echo "DeprecationWarning: Use --git-repo-mesa instead of --git-repo" >&2
;;
--git-branch)
shift
GIT_BRANCH_MESA="$1"
echo "DeprecationWarning: Use --git-branch-mesa instead of --git-branch" >&2
;;
--git-depth)
shift
GIT_DEPTH="$1"
;;
--build64)
shift
BUILD64="$1"
;;
--build32)
shift
BUILD32="$1"
;;
--buildopt)
shift
BUILDOPT="$1"
;;
--builddebug)
shift
BUILDDEBUG="$1"
;;
--heavyopt)
shift
HEAVYOPT="$1"
;;
--buildopencl)
shift
BUILDOPENCL="$1"
;;
--drivers)
shift
DRIVERS="$1"
;;
--)
break
;;
*)
echo "$0: Unknown option $1" >&2
echo
usage
exit 1
;;
esac
shift
done
# If needed enabled / disable debug mode.
if [ "x${DEBUG}" = "x1" ]; then
set -x
else
set +x
fi
if [ "$BUILDOPT" != 1 ] && [ "$BUILDDEBUG" != 1 ]; then
echo "$0: At least one of the --buildopt and --builddbg is required" 2>&1
exit 1
fi
if [ "$BUILD32" != 1 ] && [ "$BUILD64" != 1 ]; then
echo "$0: At least one of the --build32 and --build64 is required" 2>&1
exit 1
fi
echo "Checking multiarch support ..."
echo
if [ "x$(dpkg --print-foreign-architectures | egrep ^i386)" != "xi386" ]; then
echo "No multiarch enabled. Please run (as root) below command and retry:"
echo "dpkg --add-architecture i386 && apt-get update"
exit 2
fi
if [ "x${QUIET}" = "x1" ]; then
APT_INSTALL=("apt-get" "install" "--option" "APT::Get::HideAutoRemove=1" "--option" "quiet::NoProgress=1" "-qq" "--assume-yes" "--no-remove" "--no-install-recommends" "--option" "Dpkg::Use-Pty=0")
else
APT_INSTALL=("apt-get" "install" "--option" "APT::Get::HideAutoRemove=1" "--option" "quiet::NoProgress=1" "--no-install-recommends")
fi
echo
echo "Checking base dependency versions on amd64 and i386 ..."
echo
sudo "${APT_INSTALL[@]}" libc6-dev:amd64 libc6-dev:i386
# Sometimes some packages might reach only one architecture first, and it might
# be really hard to coinstall some package on both amd64 and i386, when they are
# out of sync. Check they are in sync first.
# Note: This can be done nicer using dctrl-tools package, but it is not
# installed by default or needed.
if [ "$(dpkg -s linux-libc-dev:amd64 | grep ^Version:)" != "$(dpkg -s linux-libc-dev:i386 | grep ^Version:)" ]; then
echo "linux-libc-dev:amd64 and linux-libc-dev:i386 do have different versions!"
echo "Please fix first and then retry."
exit 2
fi
if [ "$(dpkg -s libc6-dev:amd64 | grep ^Version:)" != "$(dpkg -s libc6-dev:i386 | grep ^Version:)" ]; then
echo "libc6-dev:amd64 and libc6-dev:i386 do have different versions!"
echo "Please fix first and then retry."
exit 2
fi
DIST_VERSION="$(lsb_release -is)_$(lsb_release -sr)"
LLVMVERSION=11
GCCVERSION=10
# Directly in Debian testing (bullseye, future Debian 11) LLVMVERSION=9 is available.
# But for Debian testing I recommend using LLVMVERSION=10 with experimental repo
# enabled. See above.
LLVMREPO=( )
case "$DIST_VERSION" in
Debian_9*) LLVMVERSION=7 ; GCCVERSION=6 ;; # Stretch
Debian_10*) LLVMVERSION=8 ; GCCVERSION=8 ;; # Buster backports.
Debian_11*) LLVMVERSION=11 ; GCCVERSION=10 ;; # Bullseye
Debian_testing) LLVMVERSION=11 ; GCCVERSION=10 ;;
Debian_unstable) LLVMVERSION=11 ; GCCVERSION=10 ;;
Ubuntu_16.04) LLVMVERSION=5.0 ; GCCVERSION=5 ;; # Good luck with that.
Ubuntu_18.04) LLVMVERSION=6.0 ; GCCVERSION=8 ;; # or with that.
Ubuntu_18.10) LLVMVERSION=7 ; GCCVERSION=8 ;;
Ubuntu_19.04) LLVMVERSION=8 ; GCCVERSION=9 ;;
Ubuntu_19.10) LLVMVERSION=9 ; GCCVERSION=9 ;;
Ubuntu_20.04) LLVMVERSION=10 ; GCCVERSION=10 ;;
Ubuntu_20.10) LLVMVERSION=11 ; GCCVERSION=10 ;;
Ubuntu_21.04) LLVMVERSION=11 ; GCCVERSION=10 ;;
*) echo "Warning: Distribution '$DIST_VERSION' is not supported by this script"
LLVMVERSION=10
GCCVERSION=9
esac
# Main Mesa dependencies which we will install both on amd64 and i386
#
# wayland-protocols is :all, and dpkg will install no issues.
# But bison, flex, pkg-config, glslang-tools we only want amd64 for build.
#
# We keep the order in the list same as Meson configure output.
MAINDEPS=(
linux-libc-dev # Probably will be pulled by gcc & co.
# linux-libc-dev is not libc-dev. It has Linux kernel headers,
# for use by userspace, 'uapi'.
libvdpau-dev
libvulkan-dev
# glslang-tools # We only want to install amd64 binary version.
libxvmc-dev
libxv-dev
# libomxil-bellagio-dev # Optional. Can't coinstall on amd64 and i386 at the moment.
libva-dev
zlib1g-dev
libzstd-dev
libexpat1-dev
# libdrm-dev # We build our own by default now.
# LLVM stuff
libelf-dev
libglvnd-dev
# libglvnd-core-dev
# bison # We only want to install amd64 binary version.
# flex # We only want to install amd64 binary version.
libunwind-dev
# pkg-config stuff # We install it separately, because it is a bit more complex.
# libwayland-bin # For wayland-scanner. Technically dependency of libwayland-dev
# We only want to install amd64 binary version.
wayland-protocols
libwayland-dev
libwayland-egl-backend-dev
libx11-dev
libxext-dev
libxfixes-dev
libxcb-glx0-dev
libxcb-shm0-dev
libxcb1-dev
libx11-xcb-dev
libxcb-dri2-0-dev
libxcb-dri3-dev
libxcb-present-dev
libxcb-sync-dev
libxshmfence-dev
x11proto-dev # For glproto and dri2proto. Technically dependency of other libx* packages.
libxxf86vm-dev
libxcb-xfixes0-dev
libxcb-randr0-dev
libxrandr-dev
# libxdamage-dev # I do not see it Meson output, and I do not think is needed. Debian Build-Depends has it.
libxcb-sync-dev # I don't see it Meson output, but it is in Debian Build-Depends.
libsensors-dev
# libdrm dependencies from Debian.
#
# minus some that can be 64-bit,
# minus valgrind, minus quilt (debian specific patching) and xsltproc (docs).
# meson, quilt, xsltproc
libx11-dev
# pkg-config
# xutils-dev # X Window System utility programs for development # We can use 64-bit version for 32-bit.
libudev-dev
libpciaccess-dev
# python3-docutils
# valgrind
)
if [ "${USE_SYSTEM_LIBDRM}" = "1" ]; then
MAINDEPS+=("libdrm-dev")
fi
MAINDEPS64=()
MAINDEPS32=()
for d in "${MAINDEPS[@]}"; do
MAINDEPS64+=("$d:amd64")
MAINDEPS32+=("$d:i386")
done
# For OpenCL support, one might need libclc-dev and libclang-XYZ-dev, to add a parser
# and some passes from LLVM. (See https://libclc.llvm.org for details). This is AFAIK
# for Clover subproject in Mesa, which is disabled, but might go forward, especially
# for Novoue driver, and possibly in the future as a SPIR-V target, which is then
# consumed by LLVM or by ACO, via NIR again.
OPENCL_DEPS=()
if [ "x${BUILDOPENCL}" = "x1" ]; then
OPENCL_DEPS=("libclang-${LLVMVERSION}-dev:amd64" "libclang-cpp${LLVMVERSION}-dev" "libclc-dev")
fi
echo
if [ "${USE_SYSTEM_LIBDRM}" != "1" ]; then
echo "Ensuring dependencies for Mesa (and libdrm) build are installed ..."
else
echo "Ensuring dependencies for Mesa build are installed ..."
fi
echo
# Note: We need glslangValidator to compile trivial GLSL code into SPV for Vulkan Mesa overlay.
# Compilers and cross compilers. Will automatically install binutils (for ar, strip, etc.).
sudo "${APT_INSTALL[@]}" \
git \
"gcc-${GCCVERSION}" "g++-${GCCVERSION}" \
"gcc-${GCCVERSION}-i686-linux-gnu" "g++-${GCCVERSION}-i686-linux-gnu" \
pkg-config \
meson ninja-build \
cmake \
gettext \
python3 python3-setuptools \
python3-distutils python3-mako \
valgrind \
bison flex \
dpkg-dev \
wayland-protocols \
libwayland-bin \
glslang-tools \
"${OPENCL_DEPS[@]}" \
"${MAINDEPS64[@]}" "${MAINDEPS32[@]}" \
libomxil-bellagio-dev:amd64 \
xutils-dev:amd64
# dpkg-dev is needed by multi-arch-aware pkg-config when cross-compiling
# cmake is neede for building vkpipeline-db
# libomxil-bellagio-dev can't coinstall on amd64 and i386 at the moment.
# Install directx-headers-dev for amd64 only for now.
# xutils-dev is for libdrm, but these are build utilities, only need amd64 version.
# Allow installation of directx-headers-dev:amd64 to fail.
# It is not in testing (bullseye), only in unstable (sid) for now (2021-07-24).
sudo "${APT_INSTALL[@]}" "directx-headers-dev:amd64" || echo "Warning: Can not install directx-headers-dev:amd64. Consider switching to Debian unstable / Debian bookworm to get it."
if [ "${USE_SYSTEM_LIBDRM}" != "1" ]; then
:
# TODO(baryluk): Separate dependencies for libdrm. I.e. xutils-dev:amd64, and libpciaccess-dev, libudev-dev.
fi
echo
echo
echo "Attempting to install llvm${LLVMVERSION} ... If it fails, please read the source code how to add proper repos..."
echo
echo
sudo "${APT_INSTALL[@]}" "${LLVMREPO[@]}" "libllvm${LLVMVERSION}" "libllvm${LLVMVERSION}:amd64" "libllvm${LLVMVERSION}:i386" "llvm-${LLVMVERSION}-dev" "libllvm${LLVMVERSION}:i386" "llvm-${LLVMVERSION}-dev" # "llvm-${LLVMVERSION}:i386"
sudo "${APT_INSTALL[@]}" "libllvm${LLVMVERSION}-dbgsym:amd64" "libllvm${LLVMVERSION}-dbgsym:i386" || echo "Warning: Can't install debug symbols. Enable them: https://wiki.debian.org/HowToGetABacktrace"
# No need to install pkg-config:i386, it would conflict with pkg-config:amd64.
# Debian's pkg-config will automatically create symlinks to all supported
# archs to proper wrapper that sets proper paths.
# A 32-bit version of pkg-config, that actually is a wrapper, that knows how to
# filter various libraries and multiple versions of them.
# removes pkg-config:amd64, but kind of fine for a moment. We still can use the
# properly prefixed versions all the time!
if [ "${USE_SYSTEM_LIBDRM}" != "1" ]; then
echo
echo "Checking libdrm git repo ..."
echo
SOURCEDIR_LIBDRM="${HOME}/libdrm-git"
if ! [ -d "${SOURCEDIR_LIBDRM}" ]; then
if [ "x${GIT_DEPTH}" != "x" ]; then
GIT_DEPTH_ARG="--depth=${GIT_DEPTH}"
fi
if [ "x${GIT_BRANCH_LIBDRM}" != "x" ]; then
GIT_BRANCH_ARG="--branch=${GIT_BRANCH_LIBDRM} --single-branch"
else
GIT_BRANCH_ARG=""
fi
git clone ${GIT_DEPTH_ARG} ${GIT_BRANCH_ARG} "${GIT_REPO_LIBDRM}" "${SOURCEDIR_LIBDRM}"
if [ "x${GIT_BRANCH_LIBDRM}" != "x" ]; then
git -C "${SOURCEDIR_LIBDRM}" checkout "${GIT_BRANCH_LIBDRM}"
fi
else
echo "libdrm-git repo already present. To update, run \"cd '${SOURCEDIR_LIBDRM}' && git pull\" manually."
fi
echo
fi
echo
echo "Checking mesa git repo ..."
echo
SOURCEDIR_MESA="${HOME}/mesa-git"
if ! [ -d "${SOURCEDIR_MESA}" ]; then
if [ "x${GIT_DEPTH}" != "x" ]; then
GIT_DEPTH_ARG="--depth=${GIT_DEPTH}"
fi
if [ "x${GIT_BRANCH_MESA}" != "x" ]; then
GIT_BRANCH_ARG="--branch=${GIT_BRANCH_MESA} --single-branch"
else
GIT_BRANCH_ARG=""
fi
git clone ${GIT_DEPTH_ARG} ${GIT_BRANCH_ARG} "${GIT_REPO_MESA}" "${HOME}/mesa-git"
if [ "x${GIT_BRANCH_MESA}" != "x" ]; then
git -C "${SOURCEDIR_MESA}" checkout "${GIT_BRANCH_MESA}"
fi
else
echo "mesa-git repo already present. To update, run \"cd '${SOURCEDIR_MESA}' && git pull\" manually."
fi
echo
cd "${SOURCEDIR_MESA}"
# These are roots of the build and install.
# Actuall build and install will happen in various
# subdirectories, for mesa, libdrm, 32-bit & 64-bit, opt & dbg.
echo
echo "Cleaning previous build directory ${BUILDDIR}"
rm -rf "${BUILDDIR}"
echo
echo "Cleaning previous install directory ${INSTALLDIR}"
rm -rf "${INSTALLDIR}"
echo
#OPENCL_SUPPORT=("-Dgallium-opencl=icd" "-Dopencl-spirv=true")
# For "-Dopencl-spirv=true". Also in Debian this version is based on LLVM8 at
# the moment.
#sudo "${APT_INSTALL[@]}" libllvmspirvlib-dev
# Required for parsing OpenCL when gallium-opencl is enabled.
# The clang-cpp component can be skipped, but helps with some stuff apparently.
sudo "${APT_INSTALL[@]}" "libclang-${LLVMVERSION}-dev" "libclang-cpp${LLVMVERSION}-dev:amd64"
MESA_COMMON_OPTS=("-Dplatforms=x11,wayland"
"-Ddri-drivers=[]"
"-Ddri3=enabled"
"-Dgallium-extra-hud=true"
"-Dvulkan-drivers=['amd','intel','swrast']" # RADV + ANV + lavapipe
"-Dshader-cache=enabled"
"-Dvulkan-layers=device-select,overlay"
"-Dopengl=true"
"-Dgles1=disabled"
"-Dgles2=disabled"
"-Degl=disabled"
"-Dllvm=enabled"
"-Dlmsensors=enabled"
"-Dtools=glsl,nir"
"-Dopencl-spirv=true"
"-Dgallium-vdpau=enabled"
"-Dgallium-xvmc=enabled"
"-Dgallium-va=enabled"
"-Dglvnd=true"
"-Dgbm=enabled"
#"-Dglx=gallium-xlib"
"-Dlibunwind=enabled"
"-Dosmesa=true"
"-Dgallium-nine=true")
# Interesingly enough, "-Dopencl-spirv=true" compiles even without
# libllvmspirvlib-dev installed.
if false; then # Compile SWR or not?
MESA_COMMON_OPTS+=("-Dgallium-drivers=['radeonsi','r600','zink','virgl','swrast','swr']" "-Dswr-arches=['avx','avx2','knl','skx']")
# "-Dosmesa=gallium"
else
MESA_COMMON_OPTS+=("-Dgallium-drivers=['radeonsi','r600','zink','virgl','swrast']" "-Dswr-arches=[]")
fi
# At the moment it is not possible to install valgrind i386 and amd64 at the
# same time in Debian, as it is using monolithic package.
# See https://bugs.debian.org/941160 for details
MESA_COMMON_OPTS_64=("-Dvalgrind=enabled")
MESA_COMMON_OPTS_32=("-Dvalgrind=disabled")
# libdrm also supports valigrind, so also disable it on 32-bit. But support
# of this flag might be removed in the future due to issues:
# https://gitlab.freedesktop.org/mesa/drm/-/issues/63
# Also the value names are different.
LIBDRM_COMMON_OPTS_64=("-Dvalgrind=true")
LIBDRM_COMMON_OPTS_32=("-Dvalgrind=false")
if [ "x${BUILDOPENCL}" = "x1" ]; then
# Compile Clover/OpenCL only for 64-bit. 32-bit would require installing
# "libclang1-${LLVMVERSION}:i386", but it removes the
# "libclang1-${LLVMVERSION}:amd64" and header files!
# See https://bugs.debian.org/941755 for details.
MESA_COMMON_OPTS_64+=("-Dgallium-opencl=icd" "-Dopencl-spirv=false")
fi
# Common opts for 32-bit and 64-bit, for libdrm and Mesa.
# Ones with _OPT suffix are for optimized build, ones with _DBG suffix are for debug build.
COMMON_OPTS_OPT=("--buildtype=plain")
COMMON_OPTS_OPT+=("-Db_ndebug=true")
# If you really care about library size and maybe improve performance by 0.1%,
# enable stripping. We already are compiling with -g0, so stripping will save
# very little, and make stack traces or use in gdb / valgrind way harder.
# COMMON_OPTS_OPT+=("--strip")
#
# We explicitly pass -mfpmath=sse, otherwise when compiling 32-bit version,
# it will use x87 / non-see for almost everything, which is slower, and
# can't be vectorized, even when using -march=native -msse2, etc.
# With -mfpmath=sse, it will use sse and sse2 almost everywhere, modulo
# few places where the calling conventions (i.e. to glibc) requires passing
# stuff on x87 stack / registers.
if [ "x${HEAVYOPT}" = "x1" ]; then
COMPILERFLAGS_OPT="-pipe -march=native -O3 -mfpmath=sse -ftree-vectorize -flto -flto=$(nproc --ignore=2) -g0 -fno-semantic-interposition"
COMMON_OPTS_OPT+=("-Dc_args=${COMPILERFLAGS_OPT}" "-Dcpp_args=-std=c++17 ${COMPILERFLAGS_OPT}")
else
COMPILERFLAGS_OPT="-pipe -march=native -O2 -mfpmath=sse"
COMMON_OPTS_OPT+=("-Dc_args=${COMPILERFLAGS_OPT}" "-Dcpp_args=-std=c++17 ${COMPILERFLAGS_OPT}")
fi
# For i387, one can also use -mpc64, to set the 387 in "reduced precision" mode (32 or 64 bit).
# It could be faster than full 80-bit, but that is anecdotal.
COMMON_OPTS_DBG=("--buildtype=debug")
COMMON_OPTS_DBG+=("-Db_ndebug=false")
#COMMON_OPTS_DBG+=("-Db_sanitize=thread")
COMPILERFLAGS_DBG="-pipe -march=native -O1 -mfpmath=sse -ggdb -g3 -gz"
# Note: This is working when doing 'meson configure', but I am not 100% sure
# this is correct when passing everything just to initial 'meson'.
# From testing it appears to be working.
COMMON_OPTS_DBG+=("-Dc_args=${COMPILERFLAGS_DBG}" "-Dcpp_args=-std=c++17 ${COMPILERFLAGS_DBG}")
# "-Db_sanitize=thread"
# Build tests.
# MESA_COMMON_OPTS+=("-Dbuild-tests=true")
#-Ddri-drivers=r100,r200,swrast # Note that dri swrast, is different than gallium
# swrast. It is older rasterizer. the softpipe, llvmpipe are newer ones.
# swr (openswr) it the most newest one, high performance LLVM JIT rasterizer,
# but it might be still referenced in logs as swrast!
# TODO(baryluk): Add option to build with clang, and with thread / address
# sanitizers.
# Even if we do not build 32-bit version, prepare the cross-file anyway.
# This simplifies a bit of scripting.
# Also by BUILDDBG we could theoretically build optimized libdrm, and
# debug mesa, but that is kind of pointless, often you want debug in drm
# too, and it will perform well anyway one way or another.
cat > "${SOURCEDIR_MESA}/llvm.ini" <<EOF
[binaries]
c = '/usr/bin/x86_64-linux-gnu-gcc-${GCCVERSION}'
cpp = '/usr/bin/x86_64-linux-gnu-g++-${GCCVERSION}'
llvm-config = '/usr/bin/llvm-config-${LLVMVERSION}'
strip = '/usr/bin/x86_64-linux-gnu-strip'
EOF
cat > "${SOURCEDIR_MESA}/meson-cross-i386.ini" <<EOF
[binaries]
c = '/usr/bin/i686-linux-gnu-gcc-${GCCVERSION}'
cpp = '/usr/bin/i686-linux-gnu-g++-${GCCVERSION}'
ar = '/usr/bin/i686-linux-gnu-gcc-ar-${GCCVERSION}'
strip = '/usr/bin/i686-linux-gnu-strip'
pkgconfig = '/usr/bin/i686-linux-gnu-pkg-config'
; We are cheating here. We are using 64-bit llvm-config. But we stars align
; it should work (same compiler and linker flags will be used).
llvm-config = '/usr/bin/llvm-config-${LLVMVERSION}'
; llvm-config = '/usr/lib/llvm-${LLVMVERSION}/bin/llvm-config'
[properties]
c_args = ['-m32']
c_link_args = ['-m32']
cpp_args = ['-m32']
cpp_link_args = ['-m32']
[host_machine]
system = 'linux'
cpu_family = 'x86'
cpu = 'i686'
endian = 'little'
EOF
common_build() {
local BUILD_TYPE="$1"; shift # opt / dbg
local ARCHITECTURE="$1"; shift # amd64 / i386
echo
if [ "${USE_SYSTEM_LIBDRM}" != "1" ]; then
echo "Configuring and building ${ARCHITECTURE} ${BUILD_TYPE} libdrm and Mesa ..."
else
echo "Configuring and building ${ARCHITECTURE} ${BUILD_TYPE} Mesa ..."
fi
echo
if [ "${BUILD_TYPE}" = "opt" ]; then
local COMMON_OPTS_BUILD_TYPE_SPECIFIC=("${COMMON_OPTS_OPT[@]}")
elif [ "${BUILD_TYPE}" = "dbg" ]; then
local COMMON_OPTS_BUILD_TYPE_SPECIFIC=("${COMMON_OPTS_DBG[@]}")
else
echo "Unknown BUILD_TYPE passed to common_build: ${BUILD_TYPE}" >&2
exit 1
fi
if [ "${ARCHITECTURE}" = "amd64" ]; then
local CC="gcc-${GCCVERSION}"
local CXX="gcc-${GCCVERSION}"
local PKG_CONFIG_ARCH="x86_64"
# We use the same cross file for libdrm and mesa. But we keep it in Mesa directory only for convinience.
local CROSS_FILE="${SOURCEDIR_MESA}/llvm.ini"
local COMMON_OPTS_ARCH_SPECIFIC=("${COMMON_OPTS_64[@]}")
local MESA_COMMON_OPTS_ARCH_SPECIFIC=("${MESA_COMMON_OPTS_64[@]}")
local LIBDRM_COMMON_OPTS_ARCH_SPECIFIC=("${LIBDRM_COMMON_OPTS_64[@]}")
elif [ "${ARCHITECTURE}" = "i386" ]; then
local CC="i686-linux-gnu-gcc-${GCCVERSION}"
local CXX="i686-linux-gnu-gcc-${GCCVERSION}"
local PKG_CONFIG_ARCH="i686"
local CROSS_FILE="${SOURCEDIR_MESA}/meson-cross-i386.ini" # ditto.
local COMMON_OPTS_ARCH_SPECIFIC=("${COMMON_OPTS_32[@]}")
local MESA_COMMON_OPTS_ARCH_SPECIFIC=("${MESA_COMMON_OPTS_32[@]}")
local LIBDRM_COMMON_OPTS_ARCH_SPECIFIC=("${LIBDRM_COMMON_OPTS_32[@]}")
else
echo "Unknown ARCHITECTURE passed to common_build: ${ARCHITECTURE}" >&2
exit 1
fi
# So happens that libdrm and mesa both use meson and ninja, and we should be
# able to use same options and techiniques for both.
# We just separate the some mesa-specific meson options into MESA_COMMON_OPTS
# now.
# We set same --prefix for both libdrm and mesa, that makes it easier later
# to use pkgconfig, and setup LD_LIBRARY_PATH in general.
local PREFIX="${INSTALLDIR}/build-${ARCHITECTURE}-${BUILD_TYPE}/install" # No slash at the end.
if [ "${USE_SYSTEM_LIBDRM}" != "1" ]; then
echo
echo "libdrm: Configuring and building ${ARCHITECTURE} ${BUILD_TYPE} build ..."
echo
cd "${SOURCEDIR_LIBDRM}"
local BUILDDIR_LIBDRM="${BUILDDIR}/build-${ARCHITECTURE}-${BUILD_TYPE}/libdrm"
# At the moment we do not have LIBDRM_COMMON_OPTS (i.e. to select libdrm features or drivers to build).
# libdrm even with everything enabled build so fast, that there is really no point to exclude things (like vmwgfx API or Nouveau API).
CC="${CC}" \
CXX="${CXX}" \
PKG_CONFIG="${PKG_CONFIG_ARCH}-linux-gnu-pkg-config" \
meson "${BUILDDIR_LIBDRM}/" \
--prefix="${PREFIX}" \
--cross-file="${CROSS_FILE}" \
"${COMMON_OPTS[@]}" "${COMMON_OPTS_ARCH_SPECIFIC[@]}" "${COMMON_OPTS_BUILD_TYPE_SPECIFIC[@]}" "${LIBDRM_COMMON_OPTS_ARCH_SPECIFIC[@]}"
# meson configure "${BUILDDIR_LIBDRM}/" "${COMMON_OPTS[@]}" "${COMMON_OPTS_ARCH_SPECIFIC[@]}" "${COMMON_OPTS_BUILD_TYPE_SPECIFIC[@]}" "${LIBDRM_COMMON_OPTS_ARCH_SPECIFIC[@]}"
ninja -C "${BUILDDIR_LIBDRM}/"
ninja -C "${BUILDDIR_LIBDRM}/" install
# Now libdrm is installed, we need to tell PKG_CONFIG to also look for the
# extra .pc files in the installed directory.
# Note: This only prepends extra paths. Default paths will still be searched after it.
# We do not use 'export' and pass it as env variable to meson instead
# (probably not needed to pass it to ninja).
local PKG_CONFIG_PATH="${PREFIX}/lib/pkgconfig"
else
local PKG_CONFIG_PATH=""
fi
echo
echo "mesa: Configuring and building ${ARCHITECTURE} ${BUILD_TYPE} build ..."
echo
cd "${SOURCEDIR_MESA}"
local BUILDDIR_MESA="${BUILDDIR}/build-${ARCHITECTURE}-${BUILD_TYPE}/mesa"
CC="${CC}" \
CXX="${CXX}" \
PKG_CONFIG_PATH="${PKG_CONFIG_PATH}" \
PKG_CONFIG="${PKG_CONFIG_ARCH}-linux-gnu-pkg-config" \
meson "${BUILDDIR_MESA}/" \
--prefix="${PREFIX}" \
--cross-file="${CROSS_FILE}" \
"${COMMON_OPTS[@]}" "${MESA_COMMON_OPTS[@]}" "${COMMON_OPTS_ARCH_SPECIFIC[@]}" "${COMMON_OPTS_BUILD_TYPE_SPECIFIC[@]}" "${MESA_COMMON_OPTS_ARCH_SPECIFIC[@]}"
# meson configure "${BUILDDIR_MESA}/" "${COMMON_OPTS[@]}" "${MESA_COMMON_OPTS[@]}" "${COMMON_OPTS_ARCH_SPECIFIC[@]}" "${COMMON_OPTS_BUILD_TYPE_SPECIFIC[@]}" "${MESA_COMMON_OPTS_ARCH_SPECIFIC[@]}"
ninja -C "${BUILDDIR_MESA}/"
ninja -C "${BUILDDIR_MESA}/" install
}
if [ "x${BUILD64}" = "x1" ]; then
if [ "x${BUILDOPT}" = "x1" ]; then
common_build opt amd64
fi
if [ "x${BUILDDEBUG}" = "x1" ]; then
common_build dbg amd64
fi
fi
if [ "x${BUILD32}" = "x1" ]; then
echo
echo "Configuring and building 32-bit Mesa ..."
echo
# ar is symlink to x86_64-linux-gnu-ar
# gcc-ar is symlink to gcc-ar-10, and it is symlink to x86_64-linux-gnu-gcc-ar-10
if [ "x${BUILDOPT}" = "x1" ]; then
common_build opt i386
fi
if [ "x${BUILDDEBUG}" = "x1" ]; then
common_build dbg i386
fi
fi
echo
echo "Checking vkpipeline-db repo ..."
echo
if ! [ -d "${HOME}/vkpipeline-db" ]; then
cd "${HOME}" && git clone https://gitlab.freedesktop.org/mesa/vkpipeline-db.git "${HOME}/vkpipeline-db"
fi
if [ "x${BUILD64}" = "x1" ]; then
(
echo
echo "Configuring and building 64-bit vkpipeline-db ..."
echo
cd "${HOME}/vkpipeline-db"
mkdir build-amd64 || true
cd build-amd64
cmake ..
make "-j$(nproc)"
)
fi
if [ "x${BUILD32}" = "x1" ]; then
(
echo
echo "Configuring and building 32-bit vkpipeline-db ..."
echo
# We need to install i386 version of headers for pkg-config files.
cd "${HOME}/vkpipeline-db"
mkdir build-i386 || true
cd build-i386
# I am not sure if the PKG_CONFIG{,_EXECUTABLE} works here or not. It works even
# when mistyped. So I guess it picks up the 64-bit CCFLAGS and LDFLAGS, but
# because they are the same as 32-bit ones it just works, and gcc knows how to
# search for includes in standard locations.
CC="i686-linux-gnu-gcc-${GCCVERSION}" \
CXX="i686-linux-gnu-g++-${GCCVERSION}" \
PKG_CONFIG="i686-linux-gnu-pkg-config" \
PKG_CONFIG_EXECUTABLE="i686-linux-gnu-pkg-config" \
cmake ..
make "-j$(nproc)"
)
fi
echo
echo "Generating source files with environmental variable overrides ..."
echo
# TODO(baryluk): Make paths only include 64-bit or/and 32-bit paths, depending on BUILD64 and BUILD32 variables.
if [ "x${BUILDOPT}" != "x" ]; then
cat > "${HOME}/enable-new-mesa-opt.source" <<EOF
#!/bin/sh
# Do not execute this file in your shell, instead "source" it using:
# . ~/enable-new-mesa-opt.source
# or
# source ~/enable-new-mesa-opt.source
#
# This will have effects only once in the current shell. It will not apply to
# other shells, terminals, users, whole desktop, other running programs, or once
# you close this shell, logout, reboot, etc. It is temporary.
#
# If you want you get remove eventually. It will be regenerated every time you
# run "mesa-build.sh" script to build new Mesa.
echo "Warning: Will remove existing LD_LIBRARY_PATH." >&2
export LD_LIBRARY_PATH="${INSTALLDIR}/build-amd64-opt/install/lib:${INSTALLDIR}/build-i386-opt/install/lib:${INSTALLDIR}/build-amd64-opt/install/lib/vdpau:${INSTALLDIR}/build-i386-opt/install/lib/vdpau"
export LIBGL_DRIVERS_PATH="${INSTALLDIR}/build-amd64-opt/install/lib/dri:${INSTALLDIR}/build-i386-opt/install/lib/dri"
export VK_LAYER_PATH="${INSTALLDIR}/build-amd64-opt/install/share/vulkan/explicit_layer.d:${INSTALLDIR}/build-i386-opt/install/share/vulkan/explicit_layer.d:/usr/share/vulkan/explicit_layer.d"
export VK_ICD_FILENAMES="${INSTALLDIR}/build-amd64-opt/install/share/vulkan/icd.d/radeon_icd.x86_64.json:${INSTALLDIR}/build-i386-opt/install/share/vulkan/icd.d/radeon_icd.i686.json:${INSTALLDIR}/build-amd64-opt/install/share/vulkan/icd.d/lvp_icd.x86_64.json:${INSTALLDIR}/build-i386-opt/install/share/vulkan/icd.d/lvp_icd.i686.json"
export OCL_ICD_VENDORS="${INSTALLDIR}/build-amd64-opt/install/etc/OpenCL/vendors/mesa.icd:${INSTALLDIR}/build-i386-opt/install/etc/OpenCL/vendors/mesa.icd"
export VK_INSTANCE_LAYERS=VK_LAYER_MESA_overlay
# To enable frametime outputs uncommend next line. It requires modified Mesa.
#export VK_LAYER_MESA_OVERLAY_CONFIG=output_relative_time,fps,frame,frame_timing,gpu_timing,pipeline_graphics,graph_y_zero,output_csv=0,output_per_frame=1,output_flush=0,position=top-right,width=300,output_file=/tmp/mesa_overlay_%T_%p.txt
# This uses some extra modified features, but they will only produce warnings in
# normal Mesa.
# export VK_LAYER_MESA_OVERLAY_CONFIG=output_relative_time,fps,frame,frame_timing,gpu_timing,pipeline_graphics,graph_y_zero,output_csv=0,output_per_frame=1,output_flush=0,position=top-right,width=300
export VK_LAYER_MESA_OVERLAY_CONFIG=fps,frame,frame_timing,gpu_timing,pipeline_graphics,position=top-right,width=300
export GALLIUM_HUD=fps
export DXVK_HUD=full
# If one wishes to use exported dev files, one can use /home/user/mesa/build-i386/install/lib/pkgconfig
# And possible /home/user/mesa/build-i386/install/include , for some state trackers, vulkan_intel.h,
# GL, GLEX, KHR headers.
CAPTURE_DIR="\${HOME}/vkpipeline-db-capture"
# Create directory for pipeline capture files.
if ! [ -d "\${CAPTURE_DIR}" ]; then
mkdir "\${CAPTURE_DIR}"
fi
export LD_LIBRARY_PATH="\${LD_LIBRARY_PATH}:\${HOME}/vkpipeline-db/build-amd64:\${HOME}/vkpipeline-db/build-i386"
export VK_LAYER_PATH="\${VK_LAYER_PATH}:\${HOME}/vkpipeline-db"
# To enable vkpipeline-db layer uncommend next line.
#export VK_INSTANCE_LAYERS="\${VK_INSTANCE_LAYERS}:VK_LAYER_vkpipeline_db"
# Set up the pipeline capture directory.
export VKPIPELINE_DB_CAPTURE_PATH="\${CAPTURE_DIR}"
EOF
cat > "${HOME}/mesa-opt" <<EOF
#!/bin/sh
# We keep the existing LD_LIBRARY_PATH and VK_LAYER_PATH, and not erase it unconditionally.
# This is beacuse user might have other libs and layers installed, and want to use them.
# Also, a steam often will provide its own very verbose LD_LIBRARY_PATH to own runtime libraries,
# and they might be required for games to work properly.
export LD_LIBRARY_PATH="${INSTALLDIR}/build-amd64-opt/install/lib:${INSTALLDIR}/build-i386-opt/install/lib:${INSTALLDIR}/build-amd64-opt/install/lib/vdpau:${INSTALLDIR}/build-i386-opt/install/lib/vdpau:\${LD_LIBRARY_PATH}"
export LIBGL_DRIVERS_PATH="${INSTALLDIR}/build-amd64-opt/install/lib/dri:${INSTALLDIR}/build-i386-opt/install/lib/dri"
export VK_LAYER_PATH="${INSTALLDIR}/build-amd64-opt/install/share/vulkan/explicit_layer.d:${INSTALLDIR}/build-i386-opt/install/share/vulkan/explicit_layer.d:/usr/share/vulkan/explicit_layer.d:\${VK_LAYER_PATH}"
export VK_ICD_FILENAMES="${INSTALLDIR}/build-amd64-opt/install/share/vulkan/icd.d/radeon_icd.x86_64.json:${INSTALLDIR}/build-i386-opt/install/share/vulkan/icd.d/radeon_icd.i686.json:${INSTALLDIR}/build-amd64-opt/install/share/vulkan/icd.d/lvp_icd.x86_64.json:${INSTALLDIR}/build-i386-opt/install/share/vulkan/icd.d/lvp_icd.i686.json"
export OCL_ICD_VENDORS="${INSTALLDIR}/build-amd64-opt/install/etc/OpenCL/vendors/mesa.icd:${INSTALLDIR}/build-i386-opt/install/etc/OpenCL/vendors/mesa.icd"
export LD_LIBRARY_PATH="\${LD_LIBRARY_PATH}:\${HOME}/vkpipeline-db/build-amd64:\${HOME}/vkpipeline-db/build-i386"
export VK_LAYER_PATH="\${VK_LAYER_PATH}:\${HOME}/vkpipeline-db"
# TODO(baryluk): If the path has no "/", maybe use 'env'?
exec "\$@"
EOF
chmod +x "${HOME}/mesa-opt"
# A handy wrapper to run with zink.
cat > "${HOME}/zink-opt" <<EOF
#!/bin/sh
exec env MESA_LOADER_DRIVER_OVERRIDE=zink "\${HOME}/mesa-opt" "\$@"
EOF
chmod +x "${HOME}/zink-opt"
fi
if [ "x${BUILDDEBUG}" = "x1" ]; then
cat > "${HOME}/enable-new-mesa-dbg.source" <<EOF
#!/bin/sh
# Do not execute this file in your shell, instead "source" it using:
# . ~/enable-new-mesa-dbg.source
# or
# source ~/enable-new-mesa-dbg.source
#
# This will have effects only once in the current shell. It will not apply to
# other shells, terminals, users, whole desktop, other running programs, or once
# you close this shell, logout, reboot, etc. It is temporary.
#
# If you want you get remove eventually. It will be regenerated every time you
# run "mesa-build.sh" script to build new Mesa.
echo "Warning: Will remove existing LD_LIBRARY_PATH." >&2
export LD_LIBRARY_PATH="${INSTALLDIR}/build-amd64-dbg/install/lib:${INSTALLDIR}/build-i386-dbg/install/lib:${INSTALLDIR}/build-amd64-dbg/install/lib/vdpau:${INSTALLDIR}/build-i386-dbg/install/lib/vdpau"
export LIBGL_DRIVERS_PATH="${INSTALLDIR}/build-amd64-dbg/install/lib/dri:${INSTALLDIR}/build-i386-dbg/install/lib/dri"
export VK_LAYER_PATH="${INSTALLDIR}/build-amd64-dbg/install/share/vulkan/explicit_layer.d:${INSTALLDIR}/build-i386-dbg/install/share/vulkan/explicit_layer.d:/usr/share/vulkan/explicit_layer.d"
export VK_ICD_FILENAMES="${INSTALLDIR}/build-amd64-dbg/install/share/vulkan/icd.d/radeon_icd.x86_64.json:${INSTALLDIR}/build-i386-dbg/install/share/vulkan/icd.d/radeon_icd.i686.json:${INSTALLDIR}/build-amd64-dbg/install/share/vulkan/icd.d/lvp_icd.x86_64.json:${INSTALLDIR}/build-i386-dbg/install/share/vulkan/icd.d/lvp_icd.i686.json"
export OCL_ICD_VENDORS="${INSTALLDIR}/build-amd64-dbg/install/etc/OpenCL/vendors/mesa.icd:${INSTALLDIR}/build-i386-dbg/install/etc/OpenCL/vendors/mesa.icd"
export VK_INSTANCE_LAYERS=VK_LAYER_MESA_overlay
# To enable frametime outputs uncommend next line. It requires modified Mesa.
#export VK_LAYER_MESA_OVERLAY_CONFIG=output_relative_time,fps,frame,frame_timing,gpu_timing,pipeline_graphics,graph_y_zero,output_csv=0,output_per_frame=1,output_flush=0,position=top-right,width=300,output_file=/tmp/mesa_overlay_%T_%p.txt
# This uses some extra modified features, but they will only produce warnings in
# normal Mesa.
#export VK_LAYER_MESA_OVERLAY_CONFIG=output_relative_time,fps,frame,frame_timing,gpu_timing,pipeline_graphics,graph_y_zero,output_csv=0,output_per_frame=1,output_flush=0,position=top-right,width=300
export VK_LAYER_MESA_OVERLAY_CONFIG=fps,frame,frame_timing,gpu_timing,pipeline_graphics,position=top-right,width=300
export GALLIUM_HUD=fps
export DXVK_HUD=full
# If one wishes to use exported dev files, one can use /home/user/mesa/build-i386/install/lib/pkgconfig
# And possible /home/user/mesa/build-i386/install/include , for some state trackers, vulkan_intel.h,
# GL, GLEX, KHR headers.
CAPTURE_DIR="\${HOME}/vkpipeline-db-capture"
# Create directory for pipeline capture files.
if ! [ -d "\${CAPTURE_DIR}" ]; then
mkdir "\${CAPTURE_DIR}"
fi
export LD_LIBRARY_PATH="\${LD_LIBRARY_PATH}:\${HOME}/vkpipeline-db/build-amd64:\${HOME}/vkpipeline-db/build-i386"
export VK_LAYER_PATH="\${VK_LAYER_PATH}:\${HOME}/vkpipeline-db"
# To enable vkpipeline-db layer uncommend next line.
#export VK_INSTANCE_LAYERS="\${VK_INSTANCE_LAYERS}:VK_LAYER_vkpipeline_db"
# Set up the pipeline capture directory.
export VKPIPELINE_DB_CAPTURE_PATH="\${CAPTURE_DIR}"
EOF
cat > "${HOME}/mesa-dbg" <<EOF
#!/bin/sh
# We keep the existing LD_LIBRARY_PATH and VK_LAYER_PATH, and not erase it unconditionally.
# This is beacuse user might have other libs and layers installed, and want to use them.
# Also, a steam often will provide its own very verbose LD_LIBRARY_PATH to own runtime libraries,
# and they might be required for games to work properly.
export LD_LIBRARY_PATH="${INSTALLDIR}/build-amd64-dbg/install/lib:${INSTALLDIR}/build-i386-dbg/install/lib:${INSTALLDIR}/build-amd64-dbg/install/lib/vdpau:${INSTALLDIR}/build-i386-dbg/install/lib/vdpau:\${LD_LIBRARY_PATH}"
export LIBGL_DRIVERS_PATH="${INSTALLDIR}/build-amd64-dbg/install/lib/dri:${INSTALLDIR}/build-i386-dbg/install/lib/dri"
export VK_LAYER_PATH="${INSTALLDIR}/build-amd64-dbg/install/share/vulkan/explicit_layer.d:${INSTALLDIR}/build-i386-dbg/install/share/vulkan/explicit_layer.d:/usr/share/vulkan/explicit_layer.d:\${VK_LAYER_PATH}"
export VK_ICD_FILENAMES="${INSTALLDIR}/build-amd64-dbg/install/share/vulkan/icd.d/radeon_icd.x86_64.json:${INSTALLDIR}/build-i386-dbg/install/share/vulkan/icd.d/radeon_icd.i686.json:${INSTALLDIR}/build-amd64-dbg/install/share/vulkan/icd.d/lvp_icd.x86_64.json:${INSTALLDIR}/build-i386-dbg/install/share/vulkan/icd.d/lvp_icd.i686.json"
export OCL_ICD_VENDORS="${INSTALLDIR}/build-amd64-dbg/install/etc/OpenCL/vendors/mesa.icd:${INSTALLDIR}/build-i386-dbg/install/etc/OpenCL/vendors/mesa.icd"
export LD_LIBRARY_PATH="\${LD_LIBRARY_PATH}:\${HOME}/vkpipeline-db/build-amd64:\${HOME}/vkpipeline-db/build-i386"
export VK_LAYER_PATH="\${VK_LAYER_PATH}:\${HOME}/vkpipeline-db"
# TODO(baryluk): If the path has no "/", maybe use 'env'?
exec "\$@"
EOF
chmod +x "${HOME}/mesa-dbg"
# A handy wrapper to run with zink.
cat > "${HOME}/zink-dbg" <<EOF
#!/bin/sh
exec env MESA_LOADER_DRIVER_OVERRIDE=zink "\${HOME}/mesa-dbg" "\$@"
EOF
chmod +x "${HOME}/zink-dbg"
fi
cat > "${HOME}/disable-new-mesa-hud.source" <<EOF
#!/bin/sh
unset DXVK_HUD
unset GALLIUM_HUD
unset VK_LAYER_MESA_OVERLAY_CONFIG
unset VK_INSTANCE_LAYERS
EOF
if [ "x${DISPLAY}" != "x" ]; then
echo
echo "Testing installation ..."
echo
if [ "x${BUILDOPT}" = "x1" ]; then
. "${HOME}/enable-new-mesa-opt.source"
elif [ "x${BUILDDEBUG}" = "x1" ]; then
. "${HOME}/enable-new-mesa-dbg.source"
else
echo "No BUILDOPT or BUILDDEBUG enabled." >&2
exit 1
fi
if ! glxinfo >/dev/null; then
echo
echo "glxinfo failed! Bad installation of DRI, gallium or other component." >&2
echo
# exit 2 # See https://gitlab.freedesktop.org/mesa/mesa/-/issues/4236 and https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96817#c17 for details.
fi
glxinfo | grep 'OpenGL renderer string' || true
vulkaninfo 2>&1 | grep 'GPU id' | head --lines=2 || true
RADV_DEBUG=llvm vulkaninfo 2>&1 | grep 'GPU id' | head --lines=2 || true
if ! VK_INSTANCE_LAYERS=VK_LAYER_MESA_overlay vkcube --c 120; then
echo
echo "vkcube failed! Bad installation of vulkan drivers or Mesa overlay layer." >&2
echo
# exit 2
fi
#export VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation
else # if [ "x${DISPLAY}" != "x" ]
echo
echo "Skipping testing because we are running headless (no X server running?)"
echo
fi
# Testing SSE, AVX support:
# $ objdump -d "${INSTALLDIR}/install-amd64-opt/install/lib/libvulkan_radeon.so" | grep %ymm | wc -l
# 12225
# $ objdump -d "${INSTALLDIR}/install-amd64-opt/install/lib/libvulkan_radeon.so" | grep %xmm | wc -l
# 41859
# $ objdump -d "${INSTALLDIR}/install-amd64-opt/install/lib/libvulkan_radeon.so" | grep %ymm | grep %xmm | wc -l
# 966
# $
# Good.
# $ objdump -d "${INSTALLDIR}/install-i386-opt/install/lib/libvulkan_radeon.so" | grep %xmm | wc -l
# 0
# $
# BAD.
#cd $HOME && git clone git://anongit.freedesktop.org/mesa/rbug-gui rbug-gui
#sudo "${APT_INSTALL[@]}" libgtkgl2.0-dev libgtkglext1-dev
#sudo apt-get clean
echo
echo "Build complete and passed basic tests!"
echo "Execute one of the following shell commands to enable proper Mesa"
echo "library paths and variables in the current shell:"
if [ "x${BUILDOPT}" = "x1" ]; then
echo
echo ". \"${HOME}/enable-new-mesa-opt.source\" # Optimized Mesa build"
fi
if [ "x${BUILDDEBUG}" = "x1" ]; then
echo
echo ". \"${HOME}/enable-new-mesa-dbg.source\" # Debug Mesa build"
fi
echo
echo
echo "To disable GALLIUM_HUD , DXVK_HUD and MESA_OVERLAY execute (AFTER above):"
echo ". \"${HOME}/disable-new-mesa-hud.source\""
echo
echo
echo "Alternative run your application with one of these wrapper scripts:"
echo
if [ "x${BUILDOPT}" = "x1" ]; then
echo "${HOME}/mesa-opt"
echo "${HOME}/zink-opt"
fi
if [ "x${BUILDDEBUG}" = "x1" ]; then
echo "${HOME}/mesa-dbg"
echo "${HOME}/zink-dbg"
fi
echo
echo
echo "All generated scripts use absolute paths, so you can move / relocate them as you wish (i.e. into your PATH, like ~/bin, or ~/.local/bin). Or safely remove."
echo
echo
echo "Bye!"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment