From b9c371ba09c1e330ebdc5627956b8e2152fed56b Mon Sep 17 00:00:00 2001 From: OPNA2608 Date: Wed, 29 Oct 2025 23:27:39 +0100 Subject: [PATCH 1/2] mesa: Only build OpenCL stuff on platforms where it works MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Somewhere in OpenCL-related code (SPIRV-LLVM-Translator at minimum), things go wrong when running `mesa_clc` for OpenCL-using drivers on big-endian: Invalid extended instruction import ‘nepOs.LC’ Based on upstream issues and blog posts, the issue is likely in at least SPIRV-LLVM-Translator, so this one will have BE added to its badPlatforms in the future. When SPIRV-LLVM-Translator is unavailable, don't bother with any OpenCL stuff. --- pkgs/development/libraries/mesa/default.nix | 61 +++++++++++++++------ 1 file changed, 45 insertions(+), 16 deletions(-) diff --git a/pkgs/development/libraries/mesa/default.nix b/pkgs/development/libraries/mesa/default.nix index d65868fa97ea0..fa91c6f38baf4 100644 --- a/pkgs/development/libraries/mesa/default.nix +++ b/pkgs/development/libraries/mesa/default.nix @@ -54,18 +54,15 @@ # We enable as many drivers as possible here, to build cross tools # and support emulation use cases (emulated x86_64 on aarch64, etc) galliumDrivers ? [ - "asahi" # Apple AGX "crocus" # Intel legacy "d3d12" # WSL emulated GPU (aka Dozen) "ethosu" # ARM Ethos NPU "etnaviv" # Vivante GPU designs (mostly NXP/Marvell SoCs) "freedreno" # Qualcomm Adreno (all Qualcomm SoCs) "i915" # Intel extra legacy - "iris" # new Intel (Broadwell+) "lima" # ARM Mali 4xx "llvmpipe" # software renderer "nouveau" # Nvidia - "panfrost" # ARM Mali Midgard and up (T/G series) "r300" # very old AMD "r600" # less old AMD "radeonsi" # new AMD (GCN+) @@ -77,20 +74,29 @@ "vc4" # Broadcom VC4 (Raspberry Pi 0-3) "virgl" # QEMU virtualized GPU (aka VirGL) "zink" # generic OpenGL over Vulkan, experimental + ] + # See platformOpenCLWorks + ++ lib.optionals (lib.meta.availableOn stdenv.hostPlatform spirv-llvm-translator) [ + "asahi" # Apple AGX + "iris" # new Intel (Broadwell+) + "panfrost" # ARM Mali Midgard and up (T/G series) ], vulkanDrivers ? [ "amd" # AMD (aka RADV) - "asahi" # Apple AGX "broadcom" # Broadcom VC5 (Raspberry Pi 4, aka V3D) "freedreno" # Qualcomm Adreno (all Qualcomm SoCs) "gfxstream" # Android virtualized GPU - "imagination" # PowerVR Rogue (currently N/A) "intel_hasvk" # Intel Haswell/Broadwell, "legacy" Vulkan driver (https://www.phoronix.com/news/Intel-HasVK-Drop-Dead-Code) - "intel" # new Intel (aka ANV) "microsoft-experimental" # WSL virtualized GPU (aka DZN/Dozen) + "swrast" # software renderer (aka Lavapipe) + ] + # See platformOpenCLWorks + ++ lib.optionals (lib.meta.availableOn stdenv.hostPlatform spirv-llvm-translator) [ + "asahi" # Apple AGX + "imagination" # PowerVR Rogue (currently N/A) + "intel" # new Intel (aka ANV) "nouveau" # Nouveau (aka NVK) "panfrost" # ARM Mali Midgard and up (T/G series) - "swrast" # software renderer (aka Lavapipe) ] ++ lib.optionals @@ -142,6 +148,9 @@ let needNativeCLC = !stdenv.buildPlatform.canExecute stdenv.hostPlatform; + # See spirv-llvm-translator.meta.badPlatforms for details + platformOpenCLWorks = lib.meta.availableOn stdenv.hostPlatform spirv-llvm-translator; + common = import ./common.nix { inherit lib fetchFromGitLab; }; in stdenv.mkDerivation { @@ -169,9 +178,6 @@ stdenv.mkDerivation { outputs = [ "out" - # OpenCL drivers pull in ~1G of extra LLVM stuff, so don't install them - # if the user didn't explicitly ask for it - "opencl" # the Dozen drivers depend on libspirv2dxil, but link it statically, and # libspirv2dxil itself is pretty chonky, so relocate it to its own output in # case anything wants to use it at some point @@ -185,6 +191,11 @@ stdenv.mkDerivation { # - for a cross build (needNativeCLC = true), we provide mesa with `*-clc` # binaries, so it skips building & installing any new CLC files. "cross_tools" + ] + ++ lib.optionals platformOpenCLWorks [ + # OpenCL drivers pull in ~1G of extra LLVM stuff, so don't install them + # if the user didn't explicitly ask for it + "opencl" ]; # Keep build-ids so drivers can use them for caching, etc. @@ -228,7 +239,7 @@ stdenv.mkDerivation { (lib.mesonOption "clang-libdir" "${lib.getLib llvmPackages.clang-unwrapped}/lib") # Rusticl, new OpenCL frontend - (lib.mesonBool "gallium-rusticl" true) + (lib.mesonBool "gallium-rusticl" platformOpenCLWorks) (lib.mesonOption "gallium-rusticl-enable-drivers" "auto") # Enable more sensors in gallium-hud @@ -249,11 +260,14 @@ stdenv.mkDerivation { (lib.mesonOption "video-codecs" "all") ] ++ lib.optionals (!needNativeCLC) [ - # Build and install extra tools for cross - (lib.mesonOption "tools" "asahi,panfrost") (lib.mesonBool "install-mesa-clc" true) (lib.mesonBool "install-precomp-compiler" true) ] + # These need OpenCL / libclc support + ++ lib.optionals (!needNativeCLC && platformOpenCLWorks) [ + # Build and install extra tools for cross + (lib.mesonOption "tools" "asahi,panfrost") + ] ++ lib.optionals needNativeCLC [ (lib.mesonOption "mesa-clc" "system") (lib.mesonOption "precomp-compiler" "system") @@ -282,11 +296,9 @@ stdenv.mkDerivation { libxxf86vm llvmPackages.clang llvmPackages.clang-unwrapped - llvmPackages.libclc llvmPackages.libllvm lm_sensors python3Packages.python # for shebang - spirv-llvm-translator udev vulkan-loader wayland @@ -297,6 +309,10 @@ stdenv.mkDerivation { ] ++ lib.optionals withValgrind [ valgrind-light + ] + ++ lib.optionals platformOpenCLWorks [ + llvmPackages.libclc + spirv-llvm-translator ]; depsBuildBuild = [ @@ -348,10 +364,14 @@ stdenv.mkDerivation { moveToOutput bin/pco_clc $cross_tools moveToOutput bin/vtn_bindgen2 $cross_tools + '' + + lib.optionalString platformOpenCLWorks '' moveToOutput "lib/lib*OpenCL*" $opencl # Construct our own .icd file that contains an absolute path. mkdir -p $opencl/etc/OpenCL/vendors/ echo $opencl/lib/libRusticlOpenCL.so > $opencl/etc/OpenCL/vendors/rusticl.icd + '' + + '' moveToOutput bin/spirv2dxil $spirv2dxil moveToOutput "lib/libspirv_to_dxil*" $spirv2dxil @@ -386,7 +406,16 @@ stdenv.mkDerivation { jdupes --hard-links --link-soft --recurse "$out" # add RPATH here so Zink can find libvulkan.so - patchelf --add-rpath ${vulkan-loader}/lib $out/lib/libgallium*.so $opencl/lib/libRusticlOpenCL.so + patchelf --add-rpath ${vulkan-loader}/lib ${ + lib.strings.concatStringsSep " " ( + [ + "$out/lib/libgallium*.so" + ] + ++ lib.optionals platformOpenCLWorks [ + "$opencl/lib/libRusticlOpenCL.so" + ] + ) + } ''; passthru = { From 04011e45571e1732c9a430e3f84510e9872dd124 Mon Sep 17 00:00:00 2001 From: OPNA2608 Date: Mon, 16 Feb 2026 04:54:13 +0100 Subject: [PATCH 2/2] spirv-llvm-translator: Add BE to badPlatforms See comments for details. --- pkgs/by-name/sp/spirv-llvm-translator/package.nix | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkgs/by-name/sp/spirv-llvm-translator/package.nix b/pkgs/by-name/sp/spirv-llvm-translator/package.nix index ce8f31de261d1..d142ade9ca57d 100644 --- a/pkgs/by-name/sp/spirv-llvm-translator/package.nix +++ b/pkgs/by-name/sp/spirv-llvm-translator/package.nix @@ -111,6 +111,10 @@ stdenv.mkDerivation { mainProgram = "llvm-spirv"; license = lib.licenses.ncsa; platforms = lib.platforms.unix; + # Issues with endianness handling outside of LE, in this + SPIRV-Tools + glslang + # https://github.com/KhronosGroup/SPIRV-Tools/issues/5595 + # https://github.com/KhronosGroup/SPIRV-LLVM-Translator/issues/2397 + badPlatforms = lib.platforms.bigEndian; maintainers = with lib.maintainers; [ gloaming ]; broken = !(versions ? ${llvmMajor}); };