Skip to content

Instantly share code, notes, and snippets.

@shmerl
Last active August 28, 2024 00:56
Show Gist options
  • Save shmerl/611b5b1670eb5963d0d99a4512ed8674 to your computer and use it in GitHub Desktop.
Save shmerl/611b5b1670eb5963d0d99a4512ed8674 to your computer and use it in GitHub Desktop.
For launching programs with custom Mesa
#!/bin/bash
# Assumes Mesa libraries are installed in:
# /opt/${mesa}/<arch_dir>
# or in
# ${mesa_path}/<arch_dir>
# For explicit control of the run
mesa_run=${mesa_run:-true}
if ! $mesa_run; then
"$@" &
disown -h %+
exit 0
fi
mesa=${mesa:-"mesa-main"}
mesa_arch=${mesa_arch:-"x86_64"}
# $mesa variable is a shortcut, setting /opt/$mesa for $mesa_path
# But explicitly set $mesa_path takes priority.
if [[ "${mesa+isset}" ]] && ! [[ "${mesa_path+isset}" ]]; then
mesa_path="/opt/${mesa}"
fi
if [[ "$mesa_arch" == "x86_64" ]]; then
vulkan_icd=radeon_icd.x86_64.json
elif [[ "$mesa_arch" == "x86" ]]; then
vulkan_icd=radeon_icd.i686.json
else
echo "Invalid Mesa arch ${mesa_arch} specified!"
exit 1
fi
export LD_LIBRARY_PATH="${mesa_path}/${mesa_arch}:${LD_LIBRARY_PATH}"
export LIBGL_DRIVERS_PATH="${mesa_path}/${mesa_arch}"
export EGL_DRIVERS_PATH="${mesa_path}/${mesa_arch}"
export LIBVA_DRIVERS_PATH="${mesa_path}/${mesa_arch}"
export VK_DRIVER_FILES="${mesa_path}/share/vulkan/icd.d/${vulkan_icd}"
export VK_ADD_LAYER_PATH="${mesa_path}/share/vulkan/explicit_layer.d:${mesa_path}/share/vulkan/implicit_layer.d:${VK_ADD_LAYER_PATH}"
echo "Mesa env:"
echo "LD_LIBRARY_PATH=${LD_LIBRARY_PATH}"
echo "LIBGL_DRIVERS_PATH=${LIBGL_DRIVERS_PATH}"
echo "EGL_DRIVERS_PATH=${EGL_DRIVERS_PATH}"
echo "LIBVA_DRIVERS_PATH=${LIBVA_DRIVERS_PATH}"
echo "VK_DRIVER_FILES=${VK_DRIVER_FILES}"
echo "VK_ADD_LAYER_PATH=${VK_ADD_LAYER_PATH}"
echo "VK_INSTANCE_LAYERS=${VK_INSTANCE_LAYERS}"
echo "==========================================="
"$@" &
disown -h %+
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment