modules/ryan-packages/gl.scm
4d22f5accf574b0ca0bc17775b8810a54ec08098
· 11.0 KB · 224 lines
raw
| 1 | (define-module (ryan-packages gl) |
| 2 | #:use-module ((guix licenses) #:prefix license:) |
| 3 | #:use-module (guix packages) |
| 4 | #:use-module (guix gexp) |
| 5 | #:use-module (guix utils) |
| 6 | #:use-module (ice-9 match) |
| 7 | #:use-module (gnu packages) |
| 8 | #:use-module (gnu packages gl)) |
| 9 | |
| 10 | (define-public mesa-libglvnd |
| 11 | (package |
| 12 | (inherit mesa) |
| 13 | (inputs (modify-inputs (package-inputs mesa) (prepend libglvnd))) |
| 14 | (arguments |
| 15 | (list |
| 16 | #:configure-flags |
| 17 | #~(list |
| 18 | #$@(cond |
| 19 | ((or (target-aarch64?) (target-arm32?)) |
| 20 | '("-Dgallium-drivers=etnaviv,freedreno,kmsro,lima,nouveau,\ |
| 21 | panfrost,r300,r600,svga,swrast,tegra,v3d,vc4,virgl,zink")) |
| 22 | ((or (target-ppc64le?) (target-ppc32?) (target-riscv64?)) |
| 23 | '("-Dgallium-drivers=nouveau,r300,r600,radeonsi,svga,swrast,virgl,zink")) |
| 24 | (else |
| 25 | '("-Dgallium-drivers=crocus,iris,nouveau,r300,r600,radeonsi,\ |
| 26 | svga,swrast,virgl,zink"))) |
| 27 | ;; Enable various optional features. TODO: opencl requires libclc, |
| 28 | ;; omx requires libomxil-bellagio |
| 29 | "-Dplatforms=x11,wayland" |
| 30 | "-Dglx=dri" ;Thread Local Storage, improves performance |
| 31 | ;; "-Dopencl=true" |
| 32 | ;; "-Domx=true" |
| 33 | "-Dosmesa=true" |
| 34 | "-Dgallium-xa=enabled" |
| 35 | |
| 36 | ;; features required by wayland |
| 37 | "-Dgles2=enabled" |
| 38 | "-Dgbm=enabled" |
| 39 | "-Dshared-glapi=enabled" |
| 40 | "-Dglvnd=true" |
| 41 | |
| 42 | ;; Explicitly enable Vulkan on some architectures. |
| 43 | #$@(cond |
| 44 | ((or (target-x86-32?) (target-x86-64?)) |
| 45 | '("-Dvulkan-drivers=intel,intel_hasvk,amd,swrast")) |
| 46 | ((or (target-ppc64le?) (target-ppc32?)) |
| 47 | '("-Dvulkan-drivers=amd,swrast")) |
| 48 | ((target-aarch64?) |
| 49 | '("-Dvulkan-drivers=freedreno,amd,broadcom,swrast")) |
| 50 | ((target-riscv64?) |
| 51 | '("-Dvulkan-drivers=amd,swrast")) |
| 52 | (else |
| 53 | '("-Dvulkan-drivers=auto"))) |
| 54 | |
| 55 | ;; Enable the Vulkan overlay layer on all architectures. |
| 56 | "-Dvulkan-layers=device-select,overlay" |
| 57 | |
| 58 | ;; Enable all the codecs that were built by default as part of the |
| 59 | ;; 21.3.x releases to avoid functionality regressions. |
| 60 | "-Dvideo-codecs=all" |
| 61 | |
| 62 | ;; Enable ZSTD compression for shader cache. |
| 63 | "-Dzstd=enabled" |
| 64 | |
| 65 | ;; Also enable the tests. |
| 66 | "-Dbuild-tests=true" |
| 67 | |
| 68 | "-Dllvm=enabled") ; default is x86/x86_64 only |
| 69 | |
| 70 | ;; XXX: 'debugoptimized' causes LTO link failures on some drivers. The |
| 71 | ;; documentation recommends using 'release' for performance anyway. |
| 72 | #:build-type "release" |
| 73 | |
| 74 | #:modules '((ice-9 match) |
| 75 | (srfi srfi-1) |
| 76 | (guix build utils) |
| 77 | (guix build meson-build-system)) |
| 78 | #:phases |
| 79 | #~(modify-phases %standard-phases |
| 80 | #$@(if (%current-target-system) |
| 81 | #~((add-after 'unpack 'fix-cross-compiling |
| 82 | (lambda* (#:key native-inputs #:allow-other-keys) |
| 83 | ;; When cross compiling, we use cmake to find llvm, not |
| 84 | ;; llvm-config, because llvm-config cannot be executed |
| 85 | ;; see https://github.com/llvm/llvm-project/issues/58984 |
| 86 | (substitute* "meson.build" |
| 87 | (("method : host_machine\\.system.*") |
| 88 | "method : 'cmake',\n")) |
| 89 | (setenv "CMAKE" |
| 90 | (search-input-file |
| 91 | native-inputs "/bin/cmake"))))) |
| 92 | #~()) |
| 93 | (add-after 'unpack 'disable-failing-test |
| 94 | (lambda _ |
| 95 | ;; Disable the intel vulkan (anv_state_pool) tests, as they may |
| 96 | ;; fail in a nondeterministic fashion (see: |
| 97 | ;; https://gitlab.freedesktop.org/mesa/mesa/-/issues/5446). |
| 98 | (substitute* "src/intel/vulkan/meson.build" |
| 99 | (("if with_tests") |
| 100 | "if false")) |
| 101 | #$@(match (%current-system) |
| 102 | ("riscv64-linux" |
| 103 | ;; According to the test logs the llvm JIT is not designed |
| 104 | ;; for this architecture and the llvmpipe tests all segfault. |
| 105 | ;; The same is true for mesa:gallium / osmesa-render. |
| 106 | `((substitute* '("src/gallium/drivers/llvmpipe/meson.build" |
| 107 | "src/gallium/targets/osmesa/meson.build") |
| 108 | (("if with_tests") "if false")))) |
| 109 | ("powerpc64le-linux" |
| 110 | ;; Disable some of the llvmpipe tests. |
| 111 | `((substitute* "src/gallium/drivers/llvmpipe/lp_test_arit.c" |
| 112 | (("0\\.5, ") "")))) |
| 113 | ("powerpc-linux" |
| 114 | ;; There are some tests which fail specifically on powerpc. |
| 115 | `((substitute* '(;; LLVM ERROR: Relocation type not implemented yet! |
| 116 | "src/gallium/drivers/llvmpipe/meson.build" |
| 117 | "src/gallium/targets/osmesa/meson.build") |
| 118 | (("if with_tests") "if not with_tests")) |
| 119 | ;; This is probably a big-endian test failure. |
| 120 | (substitute* "src/amd/common/meson.build" |
| 121 | (("and not with_platform_windows") |
| 122 | "and with_platform_windows")))) |
| 123 | ("i686-linux" |
| 124 | ;; This test is known to fail on i686 (see: |
| 125 | ;; https://gitlab.freedesktop.org/mesa/mesa/-/issues/4091). |
| 126 | `((substitute* "src/util/meson.build" |
| 127 | ((".*'tests/u_debug_stack_test.cpp',.*") "")))) |
| 128 | ("armhf-linux" |
| 129 | ;; Disable some of the llvmpipe tests. |
| 130 | `((substitute* "src/gallium/drivers/llvmpipe/meson.build" |
| 131 | (("'lp_test_arit', ") "")))) |
| 132 | (_ |
| 133 | '((display "No tests to disable on this architecture.\n")))))) |
| 134 | (add-before 'configure 'fix-dlopen-libnames |
| 135 | (lambda* (#:key inputs #:allow-other-keys) |
| 136 | (let ((out #$output)) |
| 137 | ;; Remain agnostic to .so.X.Y.Z versions while doing |
| 138 | ;; the substitutions so we're future-safe. |
| 139 | (substitute* "src/glx/meson.build" |
| 140 | (("-DGL_LIB_NAME=\"lib@0@\\.so\\.@1@\"") |
| 141 | (string-append "-DGL_LIB_NAME=\"" out |
| 142 | "/lib/lib@0@.so.@1@\""))) |
| 143 | (substitute* "src/gbm/backends/dri/gbm_dri.c" |
| 144 | (("\"libglapi\\.so") |
| 145 | (string-append "\"" out "/lib/libglapi.so"))) |
| 146 | (substitute* "src/gbm/main/backend.c" |
| 147 | ;; No need to patch the gbm_gallium_drm.so reference; |
| 148 | ;; it's never installed since Mesa removed its |
| 149 | ;; egl_gallium support. |
| 150 | (("\"gbm_dri\\.so") |
| 151 | (string-append "\"" out "/lib/dri/gbm_dri.so"))) |
| 152 | (substitute* "src/gallium/drivers/zink/zink_screen.c" |
| 153 | (("util_dl_open\\(VK_LIBNAME\\)") |
| 154 | (format #f "util_dl_open(\"~a\")" |
| 155 | (search-input-file inputs |
| 156 | "lib/libvulkan.so.1"))))))) |
| 157 | (add-after 'install 'split-outputs |
| 158 | (lambda _ |
| 159 | (let ((out #$output) |
| 160 | (bin #$output:bin)) |
| 161 | ;; Not all architectures have the Vulkan overlay control script. |
| 162 | (mkdir-p (string-append out "/bin")) |
| 163 | (call-with-output-file (string-append out "/bin/.empty") |
| 164 | (const #t)) |
| 165 | (copy-recursively (string-append out "/bin") |
| 166 | (string-append bin "/bin")) |
| 167 | (delete-file-recursively (string-append out "/bin"))))) |
| 168 | (add-after 'install 'symlinks-instead-of-hard-links |
| 169 | (lambda _ |
| 170 | ;; All the drivers and gallium targets create hard links upon |
| 171 | ;; installation (search for "hardlink each megadriver instance" |
| 172 | ;; in the makefiles). This is no good for us since we'd produce |
| 173 | ;; nars that contain several copies of these files. Thus, turn |
| 174 | ;; them into symlinks, which saves ~124 MiB. |
| 175 | (let* ((out #$output) |
| 176 | (lib (string-append out "/lib")) |
| 177 | (files (find-files lib |
| 178 | (lambda (file stat) |
| 179 | (and (string-contains file ".so") |
| 180 | (eq? 'regular |
| 181 | (stat:type stat)))))) |
| 182 | (inodes (map (compose stat:ino stat) files))) |
| 183 | (for-each (lambda (inode) |
| 184 | (match (filter-map (match-lambda |
| 185 | ((file ino) |
| 186 | (and (= ino inode) file))) |
| 187 | (zip files inodes)) |
| 188 | ((_) |
| 189 | #f) |
| 190 | ((reference others ..1) |
| 191 | (format #t "creating ~a symlinks to '~a'~%" |
| 192 | (length others) reference) |
| 193 | (for-each delete-file others) |
| 194 | (for-each (lambda (file) |
| 195 | (if (string=? (dirname file) |
| 196 | (dirname reference)) |
| 197 | (symlink (basename reference) |
| 198 | file) |
| 199 | (symlink reference file))) |
| 200 | others)))) |
| 201 | (delete-duplicates inodes))))) |
| 202 | (add-after 'install 'set-layer-path-in-manifests |
| 203 | (lambda _ |
| 204 | (let* ((out #$output) |
| 205 | (implicit-path (string-append |
| 206 | out |
| 207 | "/share/vulkan/implicit_layer.d/")) |
| 208 | (explicit-path (string-append |
| 209 | out |
| 210 | "/share/vulkan/explicit_layer.d/")) |
| 211 | (fix-layer-path |
| 212 | (lambda (layer-name) |
| 213 | (let* ((explicit (string-append explicit-path layer-name ".json")) |
| 214 | (implicit (string-append implicit-path layer-name ".json")) |
| 215 | (manifest (if (file-exists? explicit) |
| 216 | explicit |
| 217 | implicit))) |
| 218 | (substitute* manifest |
| 219 | (((string-append "\"lib" layer-name ".so\"")) |
| 220 | (string-append "\"" out "/lib/lib" layer-name ".so\""))))))) |
| 221 | (for-each fix-layer-path '("VkLayer_MESA_device_select" |
| 222 | "VkLayer_MESA_overlay")))))))))) |
| 223 | |
| 224 | mesa-libglvnd |