Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Script to build latest development Mesa for maximum gaming performance on Orange Pi 5 Max
- # Optimized for Panfrost with Panthor kernel support, Wayland, X11, and full Vulkan via PanVK
- # Installs to /usr, which may overwrite system Mesa—backup your existing /usr/lib/aarch64-linux-gnu/libGL* files first!
- # Assumes Debian Bookworm or similar; ensure your kernel has Panthor module enabled (modprobe panthor)
- # Exit on any error
- set -e
- # Define variables
- MESADIR="$HOME/Downloads/mesa"
- BUILDDIR="$MESADIR/builddir"
- INSTALL_PREFIX="/usr/local"
- MESA_VERSION="main (development branch)" # Always uses the dev branch for latest features
- CFLAGS="-march=armv8-a -mtune=cortex-a76 -O3 -pipe -flto=$(nproc) -funroll-loops -fomit-frame-pointer -fno-plt"
- CXXFLAGS="$CFLAGS"
- # Check if Panthor kernel module is available
- if ! lsmod | grep -q panthor; then
- echo "Warning: Panthor kernel module not loaded/detected. Ensure your kernel (6.9+) supports it for Mali-G610 GPUs."
- echo "You may need to modprobe panthor or upgrade your kernel. Continuing anyway..."
- fi
- # Install dependencies
- echo "Installing dependencies..."
- sudo apt update
- sudo apt-get build-dep mesa -y # Pulls all Mesa build deps including LLVM, libdrm, etc.
- sudo apt install -y meson cmake ninja-build pkgconf build-essential gcc g++ libdrm-dev libx11-dev libxext-dev libxrandr-dev libxfixes-dev libwayland-dev libegl-dev libgles2-mesa-dev python3-mako flex bison lm-sensors nvtop glslang-tools
- sudo apt --no-install-recommends install -t trixie-backports meson ninja-build -y
- # Build and install SPIRV-Tools for latest Vulkan support
- echo "Building and installing latest SPIRV-Tools..."
- if [ ! -d "SPIRV-Tools" ]; then
- git clone https://github.com/KhronosGroup/SPIRV-Tools.git
- fi
- cd SPIRV-Tools
- git pull
- git submodule update --init
- cd external
- if [ ! -d "spirv-headers" ]; then
- git clone https://github.com/KhronosGroup/SPIRV-Headers.git spirv-headers
- fi
- cd ..
- mkdir -p build
- cd build
- cmake .. -G Ninja -DCMAKE_BUILD_TYPE=Release
- ninja
- sudo ninja install
- cd ../..
- # Clone or update Mesa source
- echo "Setting up Mesa source..."
- if [ ! -d "$MESADIR" ]; then
- echo "Cloning Mesa repository..."
- mkdir -p ~/Downloads
- cd ~/Downloads
- git clone https://gitlab.freedesktop.org/mesa/mesa.git
- cd "$MESADIR"
- else
- echo "Updating existing Mesa repository..."
- cd "$MESADIR"
- git checkout main
- git pull
- fi
- # No specific version checkout—staying on main for dev branch
- # Set compiler flags
- echo "Setting performance-optimized compiler flags..."
- export CFLAGS="$CFLAGS"
- export CXXFLAGS="$CXXFLAGS"
- # Configure Mesa with Meson
- echo "Configuring Mesa with Meson..."
- if [ -d "$BUILDDIR" ]; then
- echo "Cleaning existing build directory..."
- rm -rf "$BUILDDIR"
- fi
- mkdir -p "$BUILDDIR"
- cd "$MESADIR"
- meson setup builddir \
- -Dprefix="$INSTALL_PREFIX" \
- -Dgallium-drivers=panfrost \
- -Dvulkan-drivers=panfrost \
- -Dplatforms=wayland,x11 \
- -Dbuildtype=release \
- -Dgles1=disabled \
- -Dgles2=enabled \
- -Dllvm=enabled \
- -Db_ndebug=true \
- -Db_lto=true \
- -Db_lto_threads=$(nproc) \
- -Dc_args="$CFLAGS" \
- -Dcpp_args="$CXXFLAGS"
- # Compile Mesa
- echo "Compiling Mesa..."
- ninja -C builddir -j$(nproc)
- # Install Mesa
- echo "Installing Mesa to $INSTALL_PREFIX..."
- echo "Warning: This will overwrite system Mesa libraries in /usr. Ensure you've backed up if needed."
- sudo ninja -C builddir install
- # Completion message with runtime tips
- echo "Mesa build and installation complete!"
- echo "Development Mesa ($MESA_VERSION) installed to $INSTALL_PREFIX. Note: This may have overwritten your system Mesa—test carefully."
- echo "Test with: glxgears (X11), es2gears_wayland (Wayland), or vkcube (Vulkan)"
- echo "Compiler flags used: $CFLAGS"
- echo "For maximum game performance, run:"
- echo " PAN_MESA_DEBUG=perf,gofaster,no_crc MESA_GLSL_CACHE_DISABLE=0 ./your_game"
- echo "Set MESA_GLSL_CACHE_DIR=/path/to/fast/storage for faster shader caching."
- echo "Monitor temperatures with 'sensors' to avoid thermal throttling."
- echo "If Vulkan issues arise, ensure SPIRV-Tools and glslang are properly installed and your kernel uses Panthor."
Advertisement
Add Comment
Please, Sign In to add comment