aboutsummaryrefslogtreecommitdiffstats
path: root/main/mesa/APKBUILD
blob: ca4e3b70f95efc2f763b3a86c68040aa807374c4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=mesa
pkgver=23.1.9
pkgrel=1
pkgdesc="Mesa DRI OpenGL library"
url="https://www.mesa3d.org"
arch="all"
license="MIT AND SGI-B-2.0 AND BSL-1.0"
subpackages="
	$pkgname-dbg
	$pkgname-dev
	$pkgname-dri-gallium:_gallium
	$pkgname-va-gallium:_va
	$pkgname-vdpau-gallium:_vdpau
	$pkgname-glapi
	$pkgname-egl
	$pkgname-gl
	$pkgname-gles
	$pkgname-xatracker
	$pkgname-osmesa
	$pkgname-gbm
	$pkgname-vulkan-ati:_vulkan
	$pkgname-vulkan-swrast:_vulkan
	$pkgname-vulkan-layers:_vulkan_layers
	$pkgname-libd3dadapter9
	"
_llvmver=17
depends_dev="
	libdrm-dev
	libxext-dev
	libxdamage-dev
	libxcb-dev
	libxshmfence-dev
	"
makedepends="
	$depends_dev
	bison
	eudev-dev
	expat-dev
	findutils
	flex
	gettext
	elfutils-dev
	glslang-dev
	libtool
	libxfixes-dev
	libva-dev
	libvdpau-dev
	libx11-dev
	libxml2-dev
	libxrandr-dev
	libxxf86vm-dev
	llvm$_llvmver-dev
	meson
	py3-mako
	python3
	vulkan-loader-dev
	wayland-dev
	wayland-protocols
	xorgproto
	zlib-dev
	zstd-dev
	"
source="
	https://mesa.freedesktop.org/archive/mesa-${pkgver/_/-}.tar.xz
	0001-freedreno-Enable-A506.patch
	0002-freedreno-Add-Adreno-643.patch
	no-unlink-megadrivers.patch
	llvm17.patch
	"
replaces="mesa-dricore"
options="!check" # we skip tests intentionally
builddir="$srcdir/mesa-${pkgver/_/-}"

_dri_driverdir=/usr/lib/xorg/modules/dri
_gallium_drivers="r300,r600,radeonsi,nouveau,swrast,virgl,zink"
_vulkan_drivers="amd,swrast"
_vulkan_layers="device-select,overlay"

# extra gallium per arch
case "$CARCH" in
x86*)
	_gallium_drivers="$_gallium_drivers,svga,i915,iris,crocus"
	;;
armhf|armv7|aarch64)
	_gallium_drivers="$_gallium_drivers,vc4,v3d,freedreno,kmsro,lima,panfrost,etnaviv,tegra"
	;;
esac

# extra vulkan per arch
case "$CARCH" in
x86*)
	_vulkan_drivers="$_vulkan_drivers,intel,intel_hasvk"
	_vulkan_layers="$_vulkan_layers,intel-nullhw"
	subpackages="
		$subpackages
		$pkgname-vulkan-intel:_vulkan
		"
	;;
aarch64)
	_vulkan_drivers="$_vulkan_drivers,broadcom,freedreno,panfrost"
	subpackages="
		$subpackages
		$pkgname-vulkan-broadcom:_vulkan
		$pkgname-vulkan-freedreno:_vulkan
		$pkgname-vulkan-panfrost:_vulkan
		"
	;;
esac

case "$CARCH" in
x86)
	# lto fails on x86 only
	# mostly:
	# https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/21371
	# https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/21180
	_lto=false
	;;
*)
	# ~5% smaller
	_lto=true
	;;
esac

case "$CARCH" in
aarch64|x86_64)
	_rusticl=true
	makedepends="
		$makedepends
		clang$_llvmver-dev
		libclc-dev~$_llvmver
		rust
		rust-bindgen
		spirv-llvm-translator-dev
		"
	subpackages="
		$subpackages
		$pkgname-rusticl
		"
	;;
*)
	_rusticl=false
	;;
esac

build() {
	# use -g1 to generate less debug info:
	# 485 MiB -> ~80 MiB
	export CFLAGS="$CFLAGS -O2 -g1"
	export CXXFLAGS="$CXXFLAGS -O2 -g1"
	export CPPFLAGS="$CPPFLAGS -O2 -g1"

	case "$CARCH" in
	armhf|armv7)
		# gnu2 tlsdesc is broken in binutils
		export CFLAGS="$CFLAGS -mtls-dialect=gnu"
		export CXXFLAGS="$CXXFLAGS -mtls-dialect=gnu"
		;;
	esac

	PATH="$PATH:/usr/lib/llvm$_llvmver/bin" \
	abuild-meson \
		-Db_ndebug=true \
		-Db_lto=$_lto \
		-Dbackend_max_links=2 \
		-Ddri-drivers-path=$_dri_driverdir \
		-Dgallium-drivers=$_gallium_drivers \
		-Dvulkan-drivers=$_vulkan_drivers \
		-Dvulkan-layers=$_vulkan_layers \
		-Dplatforms=x11,wayland \
		-Dllvm=enabled \
		-Dshared-llvm=enabled \
		-Dshared-glapi=enabled \
		-Dgbm=enabled \
		-Dglx=dri \
		-Dopengl=true \
		-Dosmesa=true \
		-Dgles1=enabled \
		-Dgles2=enabled \
		-Degl=enabled \
		-Dgallium-extra-hud=true \
		-Dgallium-nine=true \
		-Dgallium-rusticl=$_rusticl \
		-Dgallium-va=enabled \
		-Dgallium-vdpau=enabled \
		-Dgallium-xa=enabled \
		-Drust_std=2021 \
		-Dvideo-codecs=h264dec,h264enc,h265dec,h265enc \
		. output

	# Print config
	meson configure --no-pager output

	# parallel build workaround
	if [ "$CARCH" = "aarch64" ]; then
		local build_first="
		src/broadcom/cle/v3d_packet_v33_pack.h
		src/broadcom/cle/v3d_packet_v41_pack.h
		"
	fi
	ninja -C output \
		src/compiler/nir/nir_intrinsics.h \
		src/util/format/u_format_pack.h \
		$build_first

	meson compile -C output src/compiler/nir/nir_opcodes.h src/compiler/nir/nir_intrinsics_indices.h src/git_sha1.h
	meson compile -C output
}

package() {
	DESTDIR="$pkgdir" meson install --no-rebuild -C output
}

egl() {
	pkgdesc="Mesa libEGL runtime libraries"
	depends="mesa=$pkgver-r$pkgrel"

	amove usr/lib/libEGL.so*
}

gl() {
	pkgdesc="Mesa libGL runtime libraries"
	depends="mesa=$pkgver-r$pkgrel"

	amove usr/lib/libGL.so*
}

glapi() {
	pkgdesc="Mesa shared glapi"
	replaces="$pkgname-gles=$pkgver-r$pkgrel"

	amove usr/lib/libglapi.so.*
}

gles() {
	pkgdesc="Mesa libGLESv2 runtime libraries"
	depends="mesa=$pkgver-r$pkgrel"

	amove usr/lib/libGLES*.so*
}

xatracker() {
	pkgdesc="Mesa XA state tracker for vmware"
	depends="mesa=$pkgver-r$pkgrel"

	amove usr/lib/libxatracker*.so.*
}

osmesa() {
	pkgdesc="Mesa offscreen rendering libraries"
	depends="mesa=$pkgver-r$pkgrel"

	amove usr/lib/libOSMesa.so.*
}

gbm() {
	pkgdesc="Mesa gbm library"
	depends="mesa=$pkgver-r$pkgrel"

	amove usr/lib/libgbm.so.*
}

libd3dadapter9() {
	pkgdesc="Mesa directx9 adapter"
	depends="mesa=$pkgver-r$pkgrel"

	amove usr/lib/d3d/d3dadapter9.so*
}

rusticl() {
	pkgdesc="Mesa OpenCL driver"
	depends="mesa=$pkgver-r$pkgrel clang$_llvmver-headers libclc~$_llvmver"

	amove usr/lib/libRusticlOpenCL.so.*
	amove etc/OpenCL/vendors/
}

# Move links referencing the same file to the subpackage.
# Usage: _mv_links <base directory> <example>
# where <example> is one of the libraries covered by the megadriver.
# The example is used to find other links that point to the same file.
_mv_links() {
	install -d "$subpkgdir"/$1
	find -L "$pkgdir"/$1 -samefile "$pkgdir"/$1/$2 -print0 \
		| xargs -0 -I{} mv {} "$subpkgdir"/$1/
}

_mv_vulkan() {
	local i
	for i in "$@"; do
		amove usr/lib/libvulkan_$i*.so
		amove usr/share/vulkan/icd.d/${i}_*.*
	done
}

# Mesa uses "megadrivers" where multiple drivers are linked into one shared
# library. This library is then hard-linked to separate files (one for each driver).
# Each subpackage contains one megadriver so that all the hard-links are preserved.

_gallium() {
	pkgdesc="Mesa gallium DRI drivers"
	depends="mesa=$pkgver-r$pkgrel"

	# libgallium_dri.so
	_mv_links $_dri_driverdir swrast_dri.so
}

_va() {
	local n=${subpkgname##*-va-}
	pkgdesc="Mesa $n VAAPI drivers"
	depends="mesa=$pkgver-r$pkgrel libva"

	case $n in
	gallium)
		# libgallium_drv_video.so
		_mv_links /usr/lib/dri radeonsi_drv_video.so ;;
	esac
}

_vdpau() {
	local n=${subpkgname##*-vdpau-}
	pkgdesc="Mesa $n VDPAU drivers"
	depends="mesa=$pkgver-r$pkgrel libvdpau"

	case $n in
	gallium)
		# libvdpau_gallium.so.1.0.0
		_mv_links /usr/lib/vdpau libvdpau_radeonsi.so.1.0.0 ;;
	esac
}

_vulkan() {
	local n=${subpkgname##*-vulkan-}
	pkgdesc="Mesa Vulkan API driver for $n"
	depends="mesa=$pkgver-r$pkgrel"

	case $n in
	ati)
		_mv_vulkan radeon ;;
	intel)
		_mv_vulkan intel ;;
	broadcom)
		_mv_vulkan broadcom ;;
	freedreno)
		_mv_vulkan freedreno ;;
	panfrost)
		_mv_vulkan panfrost ;;
	swrast)
		_mv_vulkan lvp ;;
	esac
}

_vulkan_layers() {
	pkgdesc="collection of vulkan layers from mesa"
	depends="python3"

	# Remove this after the release of the next stable (3.14)
	# it originally was claed layer as it only packaged the
	# overlay one but now it also packages device-select and
	# intel-nullhw (on x86*)
	provides="$pkgname-vulkan-layer=$pkgver-r$pkgrel"
	replaces="$pkgname-vulkan-layer=$pkgver-r$pkgrel"

	amove usr/share/vulkan/explicit_layer.d
	amove usr/share/vulkan/implicit_layer.d
	amove usr/lib/libVkLayer_*.so
	amove usr/bin/mesa-overlay-control.py
}

sha512sums="
83f57c530ccc14e9debbc292f71214343f506bdf35bad235cdd3c380d769eb30658bdf93a70b79d7ce08e75615b892023e4245aed1237cd285d2f045cdbf9241  mesa-23.1.9.tar.xz
a2fbc1d6d65f500e784d8ff0d5108b466e2628ebc003fdb403f89115d08d6622f561cf8624fe3b848109ffd08250befb6460ce29438caa7f911d7fac63e6febb  0001-freedreno-Enable-A506.patch
37296fe4903a369d3bc00833e271df0ec522a01a52d6adb6afc32eb0fafecb78a39728aaa657669e33df7ec5d3ee56f76a902a4ddc4a7d4df3e9dff6aaf02e08  0002-freedreno-Add-Adreno-643.patch
e3d39d61b14188cd5a22e19e8c065650995f85943e6c42ec5775db5b76a9ebe8913253a8b9ac32056ac13a2c357cd951f867ecb39976c52f7d014dcc1a2d87dc  no-unlink-megadrivers.patch
2026e88c245da00c5170e7ce658c783427569787805e024fbea333d24da399e46ca0d4403e222e8138911c7f76216852c9214a800e3a84cac1993379abb5a621  llvm17.patch
"