LLVM-less Mesa PKGBUILDs for Arch and its stepchildren

The place to discuss Linux and Unix Operating Systems
Forum rules
Behave
Post Reply
User avatar
Grogan
Your Host
Posts: 2049
Joined: Sat Aug 21, 2021 10:04 am
Location: Ontario, Canada

LLVM-less Mesa PKGBUILDs for Arch and its stepchildren

Post by Grogan »

There's a significant change with respect to doing this, a Mesa built without LLVM now needs the softpipe driver for software rendering.

I build my Mesa without linking against LLVM libraries, using ACO for OpenGL shaders as well as Vulkan now. I have long hated that LLVM back end and the dependency on LLVM that breaks Mesa. I actually use LLVM toolchains, so I upgrade it.

This will prevent anything that needs LLVM from building. If enabled (implicitly or explicitly) it will fail to configure.

Code: Select all

-D llvm=disabled
Anyway, it used to be possible to still build the swrast driver for software rendering without LLVM, but it seems they have removed that legacy path and swrast now requires llvmpipe, and turns it on if selected.

Starting with the branching to Mesa 24.3.0, they have now moved that legacy functionality to softpipe for indirect opengl instead of building the old swrast driver.

Mesa 24.2 (not yet released, but it's -rc1) and prior:

Code: Select all

 -D gallium-drivers=radeonsi,zink,swrast
Mesa 24.3 (current git main):

Code: Select all

 -D gallium-drivers=radeonsi,zink,softpipe
For Vulkan, I only build the amd driver. I don't care about any other bollocks. I'll never be having anything else. There isn't any use for software rendered vulkan (lavapipe) on my system and as far as I'm concerned I don't have an Intel graphics adapter (I do, but it's all but disabled in BIOS such that only some ioports show up when probing)

Code: Select all

-D vulkan-drivers=amd
The only reason I even care about opengl software rendering is for use with the xorg-server-xfvb (virtual framebuffer, headless) for profiling Firefox. It's program execution being profiled, not graphics rendering (and 800 FPS is way outside of reality anyway, which is about what I get for such tests). Also, some applications will just use software rendering on purpose for light usage, so it's necessary to have. I mean I don't particularly care about its performance.

It will complain, and fall back to softpipe but performance isn't a problem for the piddly things that will ever be software rendered on my system.

Code: Select all

[grogan@nicetry ~]$ LIBGL_ALWAYS_SOFTWARE=true xvfb-run -s "-screen 0 1920x1080x24" glxgears
MESA-LOADER: failed to open swrast: driver not built!)
4299 frames in 5.0 seconds = 859.756 FPS
4399 frames in 5.0 seconds = 879.651 FPS
4319 frames in 5.0 seconds = 863.778 FPS
4315 frames in 5.0 seconds = 862.830 FPS
4283 frames in 5.0 seconds = 856.558 FPS
Software rendering displaying the frames (normal running X server) isn't much worse for that piddly test either:

Code: Select all

[grogan@nicetry ~]$ LIBGL_ALWAYS_SOFTWARE=true glxgears
MESA-LOADER: failed to open swrast: driver not built!)
4067 frames in 5.0 seconds = 813.199 FPS
4083 frames in 5.0 seconds = 816.545 FPS
4155 frames in 5.0 seconds = 830.945 FPS
4124 frames in 5.0 seconds = 824.587 FPS
4133 frames in 5.0 seconds = 826.440 FPS
Zink is 75 shit tonnes better than software rendering

Code: Select all

[grogan@nicetry ~]$ MESA_LOADER_DRIVER_OVERRIDE=zink glxgears
Running synchronized to the vertical refresh.  The framerate should be
approximately the same as the monitor refresh rate.
106637 frames in 5.0 seconds = 21327.400 FPS
106664 frames in 5.0 seconds = 21332.650 FPS
106435 frames in 5.0 seconds = 21286.834 FPS
106757 frames in 5.0 seconds = 21351.330 FPS
106603 frames in 5.0 seconds = 21320.430 FPS
106961 frames in 5.0 seconds = 21392.055 FPS
104684 frames in 5.0 seconds = 20936.678 FPS
(and no, evidently zink is not honouring sync to vblank)

Normal, hardware rendered opengl for comparison:

Code: Select all

[grogan@nicetry ~]$ vblank_mode=0 glxgears
MESA-LOADER: failed to open radeonsi: driver not built!)
ATTENTION: default value of option vblank_mode overridden by environment.
216722 frames in 5.0 seconds = 43344.289 FPS
219615 frames in 5.0 seconds = 43922.816 FPS
219245 frames in 5.0 seconds = 43848.930 FPS
219911 frames in 5.0 seconds = 43982.008 FPS
219520 frames in 5.0 seconds = 43903.875 FPS
But look at that bollocks, that's certainly not true about radeonsi (gallium driver) or I wouldn't be here. I wonder if that's a symptom of not compiling against LLVM. I wouldn't ordinarily have cause to run glxgears to test MY opengl, just to troubleshoot those other things. I'm going to recompile my x servers and stuff after last night's plumbing, and I guess I'll take over mesa-utils too. I was just using the distro package for that because they are just demo/test utilities, most of the time unused.

Shit though... there's stuff I didn't even know we had in there now. glxgears ported to Vulkan :lol:

mesa-utils package binaries (Arch Linux)

Code: Select all

usr/bin/eglgears_wayland
usr/bin/eglgears_x11
usr/bin/eglinfo
usr/bin/eglkms
usr/bin/egltri_wayland
usr/bin/egltri_x11
usr/bin/es2_info
usr/bin/es2gears_wayland
usr/bin/es2gears_x11
usr/bin/es2tri
usr/bin/glxgears
usr/bin/glxinfo
usr/bin/peglgears
usr/bin/vkgears
usr/bin/xeglgears
usr/bin/xeglthreads
User avatar
Grogan
Your Host
Posts: 2049
Joined: Sat Aug 21, 2021 10:04 am
Location: Ontario, Canada

Re: Change to swrast for LLVM-less Mesa

Post by Grogan »

I realized that I don't actually have LLVM-less Mesa PKGBUILDs here yet, it was the old forum.

Note that these are only for amdgpu. If you need to use any other drivers, you can't build Mesa like this. If you have a built in Intel GPU you want to use along with your AMD card, you can't build Mesa like this. Moreover, if you want to use opencl/libclc support in Mesa you can't build Mesa like this. These things need LLVM. Personally I only want this, and I only use Mesa for graphics (desktop, video, games etc.)

This also turns on the forbidden video codecs that most distros (not Arch!) disables. Even Manjaro disables those nowadays.

Let's start by displaying the mesa-git PKGBUILD. The lib32 is similar but even simpler. I will be providing a tarball to download near the end of this post.

Code: Select all

# Maintainer: Lone_Wolf <lonewolf at xs4all dot nl>
# Contributor: Armin K. <krejzi at email dot com>
# Contributor: Kristian Klausen <klausenbusk@hotmail.com>
# Contributor: Egon Ashrafinia <e.ashrafinia@gmail.com>
# Contributor: Tavian Barnes <tavianator@gmail.com>
# Contributor: Jan de Groot <jgc@archlinux.org>
# Contributor: Andreas Radke <andyrtr@archlinux.org>
# Contributor: Thomas Dziedzic < gostrc at gmail >
# Contributor: Antti "Tera" Oja <antti.bofh@gmail.com>
# Contributor: Diego Jose <diegoxter1006@gmail.com>

# Grogan: I have not removed any credits from the original file from AUR
# that I started with, but have modified this extensively over the years.
# http://www.mikeserv.com/support/

pkgname=mesa-git
pkgdesc="an open-source implementation of the OpenGL specification, git version"
pkgver=24.3.0_devel.192319.dc6e6d7a2be
pkgrel=1
arch=('x86_64')
makedepends=('git' 'python-mako' 'xorgproto'
              'libxml2' 'libx11'  'libvdpau' 'libva' 'elfutils' 'libxrandr'
              'vulkan-icd-loader' 'libgcrypt'  'wayland' 'wayland-protocols' 'meson' 'ninja')
depends=('libdrm' 'libxxf86vm' 'libxdamage' 'libxshmfence' 'libelf' 'xcb-util-keysyms'
                 'libunwind' 'libglvnd' 'wayland' 'lm_sensors' 'glslang')
optdepends=('opengl-man-pages: for the OpenGL API man pages')
options=('!debug')
provides=('mesa' 'vulkan-radeon' 'vulkan-mesa-layers' 'libva-mesa-driver' 'mesa-vdpau' 'vulkan-driver' 'mesa-libgl' 'opengl-driver')
conflicts=('mesa' 'opencl-mesa' 'vulkan-intel' 'vulkan-radeon' 'vulkan-mesa-layers' 'libva-mesa-driver' 'mesa-vdpau' 'vulkan-swrast' 'mesa-libgl')
url="https://www.mesa3d.org"
license=('custom')
source=('git+https://gitlab.freedesktop.org/mesa/mesa.git' 'LICENSE')
md5sums=('SKIP' 'SKIP')
sha512sums=('SKIP' 'SKIP')

# NOTE: The read and echo method may not always have the desired result for pkgver() depending on the tree
# One of the following cut commands will work for the case where the other git version gymnastics don't.
# Uncomment the desired line, according to the desired version string delimited by "."
# (and if so, comment out both the read and echo lines below it)
# At the time of writing it is once again fine the way it is for both main and tag checkouts

# If you would like to build a release tag instead of main, uncomment and edit the "git checkout" line within the pkgver() function below.

pkgver() {
   cd mesa
   #git describe --long | sed 's/\([^-]*-g\)/r\1/;s/-/./g' | cut -d "." -f "2 3 4"
   #git describe --long | sed 's/\([^-]*-g\)/r\1/;s/-/./g' | cut -d "." -f "2 3 4 5"
   #git describe --long | sed 's/\([^-]*-g\)/r\1/;s/-/./g' | cut -d "." -f "1 2 4"

# git checkout tags/mesa-24.1.4

   read -r _ver <VERSION
   echo ${_ver/-/_}.$(git rev-list --count HEAD).$(git rev-parse --short HEAD)
   if [  -d _build ]; then
        rm -rf _build
    fi
}

# Placeholder patch line in prepare() function in case you want to add a patch.
# Don't forget to add it to the source array and add another 'SKIP' for checkums

prepare() {
#    patch -Np1 -i "$srcdir"/some.patch
    echo "Done Preparing"
}

## -D gallium-opencl=icd \ is disabled and libclc removed from depends ###

## Get rid of bollocks build flags from makepkg. We want performance, not hardening and debugging/profiling. A release build will use -O3
## If you want to add -march for your CPU type, simply uncomment and edit the additional provided lines.

build () {
    unset CFLAGS
    unset CXXFLAGS
    unset LDFLAGS
    # export CFLAGS="-march=x86-64"
    # export CXXFLAGS="-march=x86-64"
    meson setup mesa _build \
       -D buildtype=release \
       -D b_ndebug=true \
       -D b_lto=true \
       --wrap-mode=nofallback \
       -D prefix=/usr \
       -D sysconfdir=/etc \
       -D platforms=x11,wayland \
       -D gallium-drivers=radeonsi,zink,softpipe \
       -D vulkan-drivers=amd \
       -D vulkan-layers=device-select,overlay \
       -D dri3=enabled \
       -D egl=enabled \
       -D gallium-extra-hud=true \
       -D gallium-nine=false \
       -D gallium-omx=disabled \
       -D gallium-va=enabled \
       -D gallium-vdpau=enabled \
       -D gbm=enabled \
       -D gles1=disabled \
       -D gles2=enabled \
       -D glvnd=true \
       -D glx=dri \
       -D libunwind=disabled \
       -D llvm=disabled \
       -D lmsensors=enabled \
       -D osmesa=true \
       -D shared-glapi=enabled \
       -D gallium-opencl=disabled \
       -D valgrind=disabled \
       -D zstd=enabled \
       -D microsoft-clc=disabled \
       -D video-codecs=vc1dec,h264dec,h264enc,h265dec,h265enc
       
    # meson configure _build
    ninja -C _build
}

package() {
  DESTDIR="$pkgdir" ninja $NINJAFLAGS -C _build install

  # indirect rendering
  ln -s /usr/lib/libGLX_mesa.so.0 ${pkgdir}/usr/lib/libGLX_indirect.so.0

  install -Dt "$pkgdir"/usr/share/licenses/$pkgname "$srcdir"/LICENSE
}
Read comments, I put in a few convenient lines to uncomment if you want something different.

Also included in the tarball are two little scripts. If you use ./mesabuild to build both mesa-git and lib32-mesa-git it will copy over the cloned source to the lib32 directory so you don't have to clone it twice. It's pretty large and the gitlab git server can be a bit slow at times, so you'll want this.

Code: Select all

#! /bin/sh
cd mesa-git
makepkg
cp -a mesa ../lib32-mesa-git
cd ../lib32-mesa-git
makepkg
Nothing to it, just simple commands. The PKGBUILDs will nuke the _build directory so that doesn't cause any problems in this specific case.

Whenever you do anything to Mesa, your shader cache is invalid. I also included a script for cleaning that out, both the main mesa shader cache directory in the home dir, but also throughout all Steam's wine prefixes

Code: Select all

#! /bin/bash

### Clean out ~/.cache/mesa_shader_cache(_sf) and radv_builtin shaders
### Clean out the mesa_shader_cache(_sf) directories from Steam's compatdata
### Note that the fossilize cache (MESA_DISK_CACHE_SINGLE_FILE=1) isn't used by default,
### so we cover the mesa_shader_cache_sf case with a wildcard

# System specific path, you may need to edit below if the following doesn't lead
# to the real path correctly

cd "$HOME"/.steam/root/steamapps/compatdata || exit 1
COMPATDATA=$(pwd -P)

find "$COMPATDATA" -name 'mesa_shader_cache*' -exec du -sh '{}' \;
find "$HOME"/.cache -name 'mesa_shader_cache*' -exec du -sh '{}' \;

echo "Look at all the CRUD that is accumulating..."

while true; do
read -p "Do you wish to clean it out? (y/n) " yn
case $yn in 
	[yY] ) echo Nuking...;
		break;;
	[nN] ) echo Aborting...;
		exit 0;;
	* ) echo "Enter y or n, silly!";;
esac
done

find "$COMPATDATA" -name 'mesa_shader_cache*' -exec rm -rvf '{}' \;
rm -vf "$HOME"/.cache/radv_builtin_shaders32
rm -vf "$HOME"/.cache/radv_builtin_shaders64
rm -rvf "$HOME"/.cache/mesa_shader_cache*
Alright, here are the PKGBUILDs. The file, nonllvmPKGBUILDs-july232024.tar.gz will unpack to "nonllvmPKGBUILDs" and you should be able simply run ./mesabuild from there after looking over your PKGBUILDs to see if you want to change anything (e.g. add CPU opts).

PKGBUILDs for mesa-git and lib32-mesa-git
http://www.mikeserv.org/files/nonllvmPK ... 024.tar.gz

MD5SUM:
http://www.mikeserv.org/files/nonllvmPK ... 024.md5sum

How to install the built packages? Put them in a directory and...

Code: Select all

pacman -U lib32-mesa-git-24.3.0_devel.192319.dc6e6d7a2be-1-x86_64.pkg.tar.zst mesa-git-24.3.0_devel.192319.dc6e6d7a2be-1-x86_64.pkg.tar.zst
(or use a wildcard like "pacman -U *.pkg.tar.zst" if they are the only ones in the dir etc.)

If you have your Arch distro's Mesa packages installed, the conflicts= line in the package will prompt for their removal. This includes things that aren't provided by this build, but will be broken with this Mesa build.
User avatar
Grogan
Your Host
Posts: 2049
Joined: Sat Aug 21, 2021 10:04 am
Location: Ontario, Canada

Re: LLVM-less Mesa PKGBUILDs for Arch and its stepchildren

Post by Grogan »

It looks like that softpipe change is going to be in Mesa 24.2 as well now... I just pulled 24.2.0-rc2 and it took softpipe (would have failed on meson setup if they hadn't made that change)

-D gallium-drivers=radeonsi,zink,softpipe
User avatar
Grogan
Your Host
Posts: 2049
Joined: Sat Aug 21, 2021 10:04 am
Location: Ontario, Canada

Re: LLVM-less Mesa PKGBUILDs for Arch and its stepchildren

Post by Grogan »

Today, I checked out mesa main (current 24.3.0-devel git) and found that they have changed some options again. For starters:

Code: Select all

-D glvnd=enabled \
glvnd=true has been hard deprecated now. It needs to be -D glvnd=enabled. I got hit by that because I hadn't changed mine yet (that one has been accepting both I think) :lol:

This has been deprecated:

Code: Select all

-D dri3=enabled \
(note that the \ is to escape line breaks for readability... all but the last gets one. If you forget one when using that in a file, that'll be a line break and that's it for your command)

is no longer valid for the current tree. Remove that setting (remove the line from the meson setup in the build () function in the PKGBUILD.

As near as I can figure at this time, from the meson_options.txt file (currently "meson configure" to list options in the tree is broken), it IS going to be DRI3 by default, and if you need DRI2 for older drivers, it's behind a legacy-x11 setting. (default =none)

This should probably be enabled.

Code: Select all

-D legacy-x11=dri2 \
That is how that will work, according to this:

Code: Select all

option(
  'legacy-x11',
  type : 'array',
  value : ['none'],
  description : 'Build legacy X11 support features.',
  choices : [
    'none', 'dri2'
  ],
I'm not going to enable that. I'm using amdgpu with the generic modesetting driver in X11, not xf86-video-amdgpu.

I'll update these PKGBUILDs later, after this shit settles down. We can't just go converting all the "true" to "enabled" until they have made those changes for those options.

This is only for current git main (24.3.0-devel), if checking out a stable tag or anything else, don't do this yet.

Another thing I'm going to be changing in the PKGBUILDs soon is the video-codecs option. I'm not sure when they added this, but I think now we'd rather use:

Code: Select all

-D video-codecs=all \
Choices are 'all', 'all_free', 'vc1dec', 'h264dec', 'h264enc', 'h265dec', 'h265enc', 'av1dec', 'av1enc', 'vp9dec'

If we say all, then when they add new ones like vp9dec, we'll get them (assuming they don't fail our builds lol)
User avatar
Grogan
Your Host
Posts: 2049
Joined: Sat Aug 21, 2021 10:04 am
Location: Ontario, Canada

Re: LLVM-less Mesa PKGBUILDs for Arch and its stepchildren

Post by Grogan »

-D gallium-omx

Seems to be deprecated now... not just renamed. (no omx or bellagio setting present in meson_options.txt at all)

Remove from settings.
Post Reply