Guest User

Untitled

a guest
Mar 24th, 2026
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.17 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Script to build latest development Mesa for maximum gaming performance on Orange Pi 5 Max
  4. # Optimized for Panfrost with Panthor kernel support, Wayland, X11, and full Vulkan via PanVK
  5. # Installs to /usr, which may overwrite system Mesa—backup your existing /usr/lib/aarch64-linux-gnu/libGL* files first!
  6. # Assumes Debian Bookworm or similar; ensure your kernel has Panthor module enabled (modprobe panthor)
  7.  
  8. # Exit on any error
  9. set -e
  10.  
  11. # Define variables
  12. MESADIR="$HOME/Downloads/mesa"
  13. BUILDDIR="$MESADIR/builddir"
  14. INSTALL_PREFIX="/usr/local"
  15. MESA_VERSION="main (development branch)" # Always uses the dev branch for latest features
  16. CFLAGS="-march=armv8-a -mtune=cortex-a76 -O3 -pipe -flto=$(nproc) -funroll-loops -fomit-frame-pointer -fno-plt"
  17. CXXFLAGS="$CFLAGS"
  18.  
  19. # Check if Panthor kernel module is available
  20. if ! lsmod | grep -q panthor; then
  21. echo "Warning: Panthor kernel module not loaded/detected. Ensure your kernel (6.9+) supports it for Mali-G610 GPUs."
  22. echo "You may need to modprobe panthor or upgrade your kernel. Continuing anyway..."
  23. fi
  24.  
  25. # Install dependencies
  26. echo "Installing dependencies..."
  27. sudo apt update
  28. sudo apt-get build-dep mesa -y # Pulls all Mesa build deps including LLVM, libdrm, etc.
  29. 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
  30. sudo apt --no-install-recommends install -t trixie-backports meson ninja-build -y
  31.  
  32. # Build and install SPIRV-Tools for latest Vulkan support
  33. echo "Building and installing latest SPIRV-Tools..."
  34. if [ ! -d "SPIRV-Tools" ]; then
  35. git clone https://github.com/KhronosGroup/SPIRV-Tools.git
  36. fi
  37. cd SPIRV-Tools
  38. git pull
  39. git submodule update --init
  40. cd external
  41. if [ ! -d "spirv-headers" ]; then
  42. git clone https://github.com/KhronosGroup/SPIRV-Headers.git spirv-headers
  43. fi
  44. cd ..
  45. mkdir -p build
  46. cd build
  47. cmake .. -G Ninja -DCMAKE_BUILD_TYPE=Release
  48. ninja
  49. sudo ninja install
  50. cd ../..
  51.  
  52. # Clone or update Mesa source
  53. echo "Setting up Mesa source..."
  54. if [ ! -d "$MESADIR" ]; then
  55. echo "Cloning Mesa repository..."
  56. mkdir -p ~/Downloads
  57. cd ~/Downloads
  58. git clone https://gitlab.freedesktop.org/mesa/mesa.git
  59. cd "$MESADIR"
  60. else
  61. echo "Updating existing Mesa repository..."
  62. cd "$MESADIR"
  63. git checkout main
  64. git pull
  65. fi
  66.  
  67. # No specific version checkout—staying on main for dev branch
  68.  
  69. # Set compiler flags
  70. echo "Setting performance-optimized compiler flags..."
  71. export CFLAGS="$CFLAGS"
  72. export CXXFLAGS="$CXXFLAGS"
  73.  
  74. # Configure Mesa with Meson
  75. echo "Configuring Mesa with Meson..."
  76. if [ -d "$BUILDDIR" ]; then
  77. echo "Cleaning existing build directory..."
  78. rm -rf "$BUILDDIR"
  79. fi
  80. mkdir -p "$BUILDDIR"
  81. cd "$MESADIR"
  82. meson setup builddir \
  83. -Dprefix="$INSTALL_PREFIX" \
  84. -Dgallium-drivers=panfrost \
  85. -Dvulkan-drivers=panfrost \
  86. -Dplatforms=wayland,x11 \
  87. -Dbuildtype=release \
  88. -Dgles1=disabled \
  89. -Dgles2=enabled \
  90. -Dllvm=enabled \
  91. -Db_ndebug=true \
  92. -Db_lto=true \
  93. -Db_lto_threads=$(nproc) \
  94. -Dc_args="$CFLAGS" \
  95. -Dcpp_args="$CXXFLAGS"
  96.  
  97. # Compile Mesa
  98. echo "Compiling Mesa..."
  99. ninja -C builddir -j$(nproc)
  100.  
  101. # Install Mesa
  102. echo "Installing Mesa to $INSTALL_PREFIX..."
  103. echo "Warning: This will overwrite system Mesa libraries in /usr. Ensure you've backed up if needed."
  104. sudo ninja -C builddir install
  105.  
  106. # Completion message with runtime tips
  107. echo "Mesa build and installation complete!"
  108. echo "Development Mesa ($MESA_VERSION) installed to $INSTALL_PREFIX. Note: This may have overwritten your system Mesa—test carefully."
  109. echo "Test with: glxgears (X11), es2gears_wayland (Wayland), or vkcube (Vulkan)"
  110. echo "Compiler flags used: $CFLAGS"
  111. echo "For maximum game performance, run:"
  112. echo " PAN_MESA_DEBUG=perf,gofaster,no_crc MESA_GLSL_CACHE_DISABLE=0 ./your_game"
  113. echo "Set MESA_GLSL_CACHE_DIR=/path/to/fast/storage for faster shader caching."
  114. echo "Monitor temperatures with 'sensors' to avoid thermal throttling."
  115. echo "If Vulkan issues arise, ensure SPIRV-Tools and glslang are properly installed and your kernel uses Panthor."
  116.  
Advertisement
Add Comment
Please, Sign In to add comment