32 , spirv-llvm-translator
43 , enablePatentEncumberedCodecs ? true
44 , withValgrind ? lib.meta.availableOn stdenv.hostPlatform valgrind-light
47 "d3d12" # WSL emulated GPU (aka Dozen)
48 "iris" # new Intel (Broadwell+)
49 "llvmpipe" # software renderer
53 "radeonsi" # new AMD (GCN+)
54 "softpipe" # older software renderer
55 "svga" # VMWare virtualized GPU
56 "virgl" # QEMU virtualized GPU (aka VirGL)
57 "zink" # generic OpenGL over Vulkan, experimental
58 ] ++ lib.optionals (stdenv.hostPlatform.isAarch64 || stdenv.hostPlatform.isAarch32) [
59 "etnaviv" # Vivante GPU designs (mostly NXP/Marvell SoCs)
60 "freedreno" # Qualcomm Adreno (all Qualcomm SoCs)
62 "panfrost" # ARM Mali Midgard and up (T/G series)
63 "vc4" # Broadcom VC4 (Raspberry Pi 0-3)
64 ] ++ lib.optionals stdenv.hostPlatform.isAarch64 [
65 "tegra" # Nvidia Tegra SoCs
66 "v3d" # Broadcom VC5 (Raspberry Pi 4)
67 ] ++ lib.optionals stdenv.hostPlatform.isx86 [
68 "crocus" # Intel legacy, x86 only
69 "i915" # Intel extra legacy, x86 only
72 "amd" # AMD (aka RADV)
73 "intel" # new Intel (aka ANV)
74 "microsoft-experimental" # WSL virtualized GPU (aka DZN/Dozen)
75 "nouveau" # Nouveau (aka NVK)
76 "swrast" # software renderer (aka Lavapipe)
77 ] ++ lib.optionals (stdenv.hostPlatform.isAarch -> lib.versionAtLeast stdenv.hostPlatform.parsed.cpu.version "6") [
78 # QEMU virtualized GPU (aka VirGL)
79 # Requires ATOMIC_INT_LOCK_FREE == 2.
81 ] ++ lib.optionals stdenv.hostPlatform.isAarch64 [
82 "broadcom" # Broadcom VC5 (Raspberry Pi 4, aka V3D)
83 "freedreno" # Qualcomm Adreno (all Qualcomm SoCs)
84 "imagination-experimental" # PowerVR Rogue (currently N/A)
85 "panfrost" # ARM Mali Midgard and up (T/G series)
86 ] ++ lib.optionals stdenv.hostPlatform.isx86 [
87 "intel_hasvk" # Intel Haswell/Broadwell, "legacy" Vulkan driver (https://www.phoronix.com/news/Intel-HasVK-Drop-Dead-Code)
89 , eglPlatforms ? [ "x11" "wayland" ]
104 hash = "sha256-+J1h7New5MEclUBvwDQtTYJCHKKqAEOeQkuKy+g0vEc=";
107 pname = "proc-macro2";
109 hash = "sha256-9fYAlWRGVIwPp8OKX7Id84Kjt8OoN2cANJ/D9ZOUUZE=";
114 hash = "sha256-VWRCZJO0/DJbNu0/V9TLaqlwMot65YjInWT9VWg57DY=";
119 hash = "sha256-nGLBbxR0DFBpsXMngXdegTm/o13FBS6QsM7TwxHXbgQ=";
122 pname = "unicode-ident";
124 hash = "sha256-KX8NqYYw6+rGsoR9mdZx8eT1HIPEUUyxErdk2H/Rlj8=";
128 copyRustDep = dep: ''
129 cp -R --no-preserve=mode,ownership ${fetchCrate dep} subprojects/${dep.pname}-${dep.version}
130 cp -R subprojects/packagefiles/${dep.pname}/* subprojects/${dep.pname}-${dep.version}/
133 copyRustDeps = lib.concatStringsSep "\n" (builtins.map copyRustDep rustDeps);
135 needNativeCLC = !stdenv.buildPlatform.canExecute stdenv.hostPlatform;
137 common = import ./common.nix { inherit lib fetchFromGitLab; };
138 in stdenv.mkDerivation {
139 inherit (common) pname version src meta;
148 # The drirc.d directory cannot be installed to $drivers as that would cause a cyclic dependency:
149 substituteInPlace src/util/xmlconfig.c --replace \
150 'DATADIR "/drirc.d"' '"${placeholder "out"}/share/drirc.d"'
151 substituteInPlace src/util/meson.build --replace \
152 "get_option('datadir')" "'${placeholder "out"}/share'"
153 substituteInPlace src/amd/vulkan/meson.build --replace \
154 "get_option('datadir')" "'${placeholder "out"}/share'"
160 "out" "dev" "drivers" "driversdev" "opencl" "teflon" "osmesa"
161 # the Dozen drivers depend on libspirv2dxil, but link it statically, and
162 # libspirv2dxil itself is pretty chonky, so relocate it to its own output in
163 # case anything wants to use it at some point
167 # Keep build-ids so drivers can use them for caching, etc.
168 # Also some drivers segfault without this.
169 separateDebugInfo = true;
171 # Needed to discover llvm-config for cross
173 PATH=${lib.getDev llvmPackages.libllvm}/bin:$PATH
178 "--datadir=${placeholder "drivers"}/share"
181 (lib.mesonOption "platforms" (lib.concatStringsSep "," eglPlatforms))
182 (lib.mesonOption "gallium-drivers" (lib.concatStringsSep "," galliumDrivers))
183 (lib.mesonOption "vulkan-drivers" (lib.concatStringsSep "," vulkanDrivers))
184 (lib.mesonOption "vulkan-layers" (builtins.concatStringsSep "," vulkanLayers))
186 # Make sure we know where to find all the drivers
187 (lib.mesonOption "dri-drivers-path" "${placeholder "drivers"}/lib/dri")
188 (lib.mesonOption "vdpau-libs-path" "${placeholder "drivers"}/lib/vdpau")
189 (lib.mesonOption "omx-libs-path" "${placeholder "drivers"}/lib/bellagio")
190 (lib.mesonOption "va-libs-path" "${placeholder "drivers"}/lib/dri")
191 (lib.mesonOption "d3d-drivers-path" "${placeholder "drivers"}/lib/d3d")
193 # Set search paths for non-Mesa drivers (e.g. Nvidia)
194 (lib.mesonOption "dri-search-path" "${libglvnd.driverLink}/lib/dri")
195 (lib.mesonOption "gbm-backends-path" "${libglvnd.driverLink}/lib/gbm:${placeholder "out"}/lib/gbm")
197 # Enable glvnd for dynamic libGL dispatch
198 (lib.mesonEnable "glvnd" true)
200 (lib.mesonBool "gallium-nine" true) # Direct3D in Wine
201 (lib.mesonBool "osmesa" true) # used by wine
202 (lib.mesonBool "teflon" true) # TensorFlow frontend
204 # Enable Intel RT stuff when available
205 (lib.mesonBool "install-intel-clc" true)
206 (lib.mesonEnable "intel-rt" stdenv.hostPlatform.isx86_64)
207 (lib.mesonOption "clang-libdir" "${lib.getLib llvmPackages.clang-unwrapped}/lib")
209 # Clover, old OpenCL frontend
210 (lib.mesonOption "gallium-opencl" "icd")
211 (lib.mesonBool "opencl-spirv" true)
213 # Rusticl, new OpenCL frontend
214 (lib.mesonBool "gallium-rusticl" true)
216 # meson auto_features enables this, but we do not want it
217 (lib.mesonEnable "android-libbacktrace" false)
218 (lib.mesonEnable "microsoft-clc" false) # Only relevant on Windows (OpenCL 1.2 API on top of D3D12)
219 (lib.mesonEnable "valgrind" withValgrind)
220 ] ++ lib.optionals enablePatentEncumberedCodecs [
221 (lib.mesonOption "video-codecs" "all")
222 ] ++ lib.optionals needNativeCLC [
223 (lib.mesonOption "intel-clc" "system")
228 buildInputs = with xorg; [
246 llvmPackages.clang-unwrapped
250 python3Packages.python # for shebang
251 spirv-llvm-translator
259 ] ++ lib.optionals withValgrind [
265 buildPackages.stdenv.cc
268 nativeBuildInputs = [
276 python3Packages.python
277 python3Packages.packaging
278 python3Packages.pycparser
281 python3Packages.pyyaml
283 # Use bin output from glslang to not propagate the dev output at
284 # the build time with the host glslang.
289 rustPlatform.bindgenHook
291 ] ++ lib.optionals needNativeCLC [
292 # `or null` to not break eval with `attribute missing` on darwin to linux cross
293 (buildPackages.mesa.driversdev or null)
296 disallowedRequisites = lib.optionals needNativeCLC [
297 (buildPackages.mesa.driversdev or null)
300 propagatedBuildInputs = [ libdrm ];
305 # Move driver-related bits to $drivers
306 moveToOutput "lib/lib*_mesa*" $drivers
307 moveToOutput "lib/libpowervr_rogue*" $drivers
308 moveToOutput "lib/libxatracker*" $drivers
309 moveToOutput "lib/libvulkan_*" $drivers
311 # Update search path used by glvnd (it's pointing to $out but drivers are in $drivers)
312 for js in $drivers/share/glvnd/egl_vendor.d/*.json; do
313 substituteInPlace "$js" --replace-fail '"libEGL_' '"'"$drivers/lib/libEGL_"
316 # And same for Vulkan
317 for js in $drivers/share/vulkan/icd.d/*.json; do
318 substituteInPlace "$js" --replace-fail "$out" "$drivers"
321 # Move Vulkan layers to $drivers and update manifests
322 moveToOutput "lib/libVkLayer*" $drivers
323 for js in $drivers/share/vulkan/{im,ex}plicit_layer.d/*.json; do
324 substituteInPlace "$js" --replace '"libVkLayer_' '"'"$drivers/lib/libVkLayer_"
327 # Construct our own .icd files that contain absolute paths.
328 mkdir -p $opencl/etc/OpenCL/vendors/
329 echo $opencl/lib/libMesaOpenCL.so > $opencl/etc/OpenCL/vendors/mesa.icd
330 echo $opencl/lib/libRusticlOpenCL.so > $opencl/etc/OpenCL/vendors/rusticl.icd
332 moveToOutput bin/intel_clc $driversdev
333 moveToOutput lib/gallium-pipe $opencl
334 moveToOutput "lib/lib*OpenCL*" $opencl
335 moveToOutput "lib/libOSMesa*" $osmesa
336 moveToOutput bin/spirv2dxil $spirv2dxil
337 moveToOutput "lib/libspirv_to_dxil*" $spirv2dxil
338 moveToOutput lib/libteflon.so $teflon
342 # set the default search path for DRI drivers; used e.g. by X server
343 for pc in lib/pkgconfig/{dri,d3d}.pc; do
344 [ -f "$dev/$pc" ] && substituteInPlace "$dev/$pc" --replace "$drivers" "${libglvnd.driverLink}"
347 # remove pkgconfig files for GL/EGL; they are provided by libGL.
348 rm -f $dev/lib/pkgconfig/{gl,egl}.pc
350 # Move development files for libraries in $drivers to $driversdev
351 mkdir -p $driversdev/include
352 mv $dev/include/xa_* $dev/include/d3d* -t $driversdev/include || true
353 mkdir -p $driversdev/lib/pkgconfig
354 for pc in lib/pkgconfig/{xatracker,d3d}.pc; do
355 if [ -f "$dev/$pc" ]; then
356 substituteInPlace "$dev/$pc" --replace $out $drivers
357 mv $dev/$pc $driversdev/$pc
361 # Don't depend on build python
362 patchShebangs --host --update $out/bin/*
364 # NAR doesn't support hard links, so convert them to symlinks to save space.
365 jdupes --hard-links --link-soft --recurse "$drivers"
367 # add RPATH so the drivers can find the moved libgallium and libdricore9
368 # moved here to avoid problems with stripping patchelfed files
369 for lib in $drivers/lib/*.so* $drivers/lib/*/*.so*; do
370 if [[ ! -L "$lib" ]]; then
371 patchelf --set-rpath "$(patchelf --print-rpath $lib):$drivers/lib" "$lib"
375 # add RPATH here so Zink can find libvulkan.so
376 patchelf --add-rpath ${vulkan-loader}/lib $out/lib/libgallium*.so
379 env.NIX_CFLAGS_COMPILE = toString ([
381 "-DPIPE_SEARCH_DIR=\"${placeholder "opencl"}/lib/gallium-pipe\""
385 inherit (libglvnd) driverLink;
386 inherit llvmPackages;
388 tests.devDoesNotDependOnLLVM = stdenv.mkDerivation {
389 name = "mesa-dev-does-not-depend-on-llvm";
391 echo ${mesa.dev} >>$out
393 disallowedRequisites = [ llvmPackages.llvm mesa.drivers ];
396 llvmpipeHook = makeSetupHook {
397 name = "llvmpipe-hook";
398 substitutions.drivers = mesa.drivers;
399 } ./llvmpipe-hook.sh;