summaryrefslogtreecommitdiff
blob: e450385f5016bf52657a7027c29cf94139eb830b (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
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
# Copyright 1999-2024 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

EAPI=8

PYTHON_COMPAT=( python3_{10..12} )

# Check this on updates
LLVM_COMPAT=( {15..15} )

inherit cmake flag-o-matic llvm-r1 toolchain-funcs python-single-r1

DESCRIPTION="Advanced shading language for production GI renderers"
HOMEPAGE="https://www.imageworks.com/technology/opensource https://github.com/AcademySoftwareFoundation/OpenShadingLanguage"

if [[ ${PV} = *9999* ]] ; then
	inherit git-r3
	EGIT_REPO_URI="https://github.com/AcademySoftwareFoundation/OpenShadingLanguage.git"
else
	# If a development release, please don't keyword!
	SRC_URI="https://github.com/AcademySoftwareFoundation/OpenShadingLanguage/archive/v${PV}.tar.gz -> ${P}.tar.gz"
	KEYWORDS="~amd64 ~arm ~arm64 ~ppc64"
	S="${WORKDIR}/OpenShadingLanguage-${PV}"
fi

LICENSE="BSD"
SLOT="0/$(ver_cut 1-3)"

X86_CPU_FEATURES=(
	sse2:sse2 sse3:sse3 ssse3:ssse3 sse4_1:sse4.1 sse4_2:sse4.2
	avx:avx avx2:avx2 avx512f:avx512f f16c:f16c
)
CPU_FEATURES=( "${X86_CPU_FEATURES[@]/#/cpu_flags_x86_}" )

IUSE="debug doc gui libcxx nofma partio qt6 test ${CPU_FEATURES[*]%:*} python"
RESTRICT="!test? ( test )"
REQUIRED_USE="${PYTHON_REQUIRED_USE}"

RDEPEND="
	dev-libs/boost:=
	dev-libs/pugixml
	>=media-libs/openexr-3:0=
	>=media-libs/openimageio-2.4:=
	$(llvm_gen_dep '
		sys-devel/clang:${LLVM_SLOT}
		sys-devel/llvm:${LLVM_SLOT}
	')
	sys-libs/zlib:=
	python? (
		${PYTHON_DEPS}
		$(python_gen_cond_dep '
			dev-python/pybind11[${PYTHON_USEDEP}]
			media-libs/openimageio[python,${PYTHON_SINGLE_USEDEP}]
		')
	)
	partio? ( media-libs/partio )
	gui? (
		!qt6? (
			dev-qt/qtcore:5
			dev-qt/qtgui:5
			dev-qt/qtwidgets:5
			dev-qt/qtopengl:5
		)
		qt6? (
			dev-qt/qtbase:6[gui,widgets,opengl]
		)
	)
"

DEPEND="${RDEPEND}"
BDEPEND="
	sys-devel/bison
	sys-devel/flex
	virtual/pkgconfig
"

pkg_setup() {
	llvm-r1_pkg_setup

	use python && python-single-r1_pkg_setup
}

src_prepare() {
	sed -e "/^install.*llvm_macros.cmake.*cmake/d" -i CMakeLists.txt || die

	cmake_src_prepare
}

src_configure() {
	# -Werror=lto-type-mismatch
	# https://bugs.gentoo.org/875836
	# https://github.com/AcademySoftwareFoundation/OpenShadingLanguage/issues/1810
	filter-lto

	# pick the highest we support
	local mysimd=()
	if use cpu_flags_x86_avx512f; then
		mysimd+=( avx512f )
	elif use cpu_flags_x86_avx2 ; then
		mysimd+=( avx2 )
		if use cpu_flags_x86_f16c ; then
			mysimd+=( f16c )
		fi
	elif use cpu_flags_x86_avx ; then
		mysimd+=( avx )
	elif use cpu_flags_x86_sse4_2 ; then
		mysimd+=( sse4.2 )
	elif use cpu_flags_x86_sse4_1 ; then
		mysimd+=( sse4.1 )
	elif use cpu_flags_x86_ssse3 ; then
		mysimd+=( ssse3 )
	elif use cpu_flags_x86_sse3 ; then
		mysimd+=( sse3 )
	elif use cpu_flags_x86_sse2 ; then
		mysimd+=( sse2 )
	fi

	local mybatched=()
	if use cpu_flags_x86_avx512f || use cpu_flags_x86_avx2 ; then
		if use cpu_flags_x86_avx512f ; then
			if use nofma; then
				mybatched+=(
					"b8_AVX512_noFMA"
					"b16_AVX512_noFMA"
				)
			else
				mybatched+=(
					"b8_AVX512"
					"b16_AVX512"
				)
			fi
		fi
		if use cpu_flags_x86_avx2 ; then
			if use nofma; then
				mybatched+=(
					"b8_AVX2_noFMA"
				)
			else
				mybatched+=(
					"b8_AVX2"
				)
			fi
		fi
	elif use cpu_flags_x86_avx ; then
		mybatched+=(
			"b8_AVX"
		)
	fi

	# If no CPU SIMDs were used, completely disable them
	[[ -z "${mysimd[*]}" ]] && mysimd=("0")
	[[ -z "${mybatched[*]}" ]] && mybatched=("0")

	# This is currently needed on arm64 to get the NEON SIMD wrapper to compile the code successfully
	# Even if there are no SIMD features selected, it seems like the code will turn on NEON support if it is available.
	use arm64 && append-flags -flax-vector-conversions

	local gcc
	gcc="$(tc-getCC)"

	local mycmakeargs=(
		-DCMAKE_POLICY_DEFAULT_CMP0146="OLD" # BUG FindCUDA
		-DCMAKE_POLICY_DEFAULT_CMP0148="OLD" # BUG FindPythonInterp

		# std::tuple_size_v is c++17
		-DCMAKE_CXX_STANDARD="17"

		-DCMAKE_INSTALL_DOCDIR="share/doc/${PF}"
		-DINSTALL_DOCS="$(usex doc)"
		-DUSE_CCACHE="no"
		-DLLVM_STATIC="no"
		-DOSL_BUILD_TESTS="$(usex test)"
		-DSTOP_ON_WARNING="no"
		-DUSE_PARTIO="$(usex partio)"
		-DUSE_PYTHON="$(usex python)"
		-DUSE_SIMD="$(IFS=","; echo "${mysimd[*]}")"
		-DUSE_BATCHED="$(IFS=","; echo "${mybatched[*]}")"
		-DUSE_LIBCPLUSPLUS="$(usex libcxx)"
		-DUSE_OPTIX="no"

		-DOpenImageIO_ROOT="${EPREFIX}/usr"
	)

	if use debug; then
		mycmakeargs+=(
			-DVEC_REPORT="yes"
		)
	fi

	if use gui; then
		mycmakeargs+=( -DUSE_QT="yes" )
		if ! use qt6; then
			mycmakeargs+=( -DCMAKE_DISABLE_FIND_PACKAGE_Qt6="yes" )
		fi
	else
		mycmakeargs+=( -DUSE_QT="no" )
	fi

	if use partio; then
		mycmakeargs+=(
			-Dpartio_ROOT="${EPREFIX}/usr"
		)
	fi

	if use python; then
		mycmakeargs+=(
			"-DPYTHON_VERSION=${EPYTHON#python}"
			"-DPYTHON_SITE_DIR=$(python_get_sitedir)"
		)
	fi

	cmake_src_configure
}

src_test() {
	# A bunch of tests only work when installed.
	# So install them into the temp directory now.
	DESTDIR="${T}" cmake_build install

	ln -s "${CMAKE_USE_DIR}/src/cmake/" "${BUILD_DIR}/src/cmake" || die

	CMAKE_SKIP_TESTS=(
		"broken"
		"^render"

		# outright fail
		"^color$"
		"^color.opt$"
		"^color.batched$"
		"^color.batched.opt$"
		"^matrix.batched.opt$"
		"^spline-reg.regress.batched.opt$"
		"^transform-reg.regress.batched.opt$"
	)

	# These only fail inside sandbox
	if [[ "${OSL_OPTIONAL_TESTS}" != "true" ]]; then
		CMAKE_SKIP_TESTS+=(
			# TODO: investigate failures
			# SIGABRT similar to https://github.com/AcademySoftwareFoundation/OpenShadingLanguage/issues/1363
			"^andor-reg.regress.batched.opt$"
			"^arithmetic-reg.regress.batched.opt$"
			"^array-assign-reg.regress.batched.opt$"
			"^array-length-reg.regress.batched$"
			"^closure.batched$"
			"^closure.batched.opt$"
			"^closure-parameters.batched$"
			"^closure-parameters.batched.opt$"
			"^debug-uninit$"
			"^debug-uninit.opt$"
			"^debug-uninit.batched$"
			"^debug-uninit.batched.opt$"
			"^derivs$"
			"^derivs.opt$"
			"^derivs.batched$"
			"^derivs.batched.opt$"
			"^filterwidth-reg.regress.batched.opt$"
			"^geomath.opt$"
			"^geomath.batched$"
			"^geomath.batched.opt$"
			"^getattribute-camera.batched$"
			"^getattribute-camera.batched.opt$"
			"^getattribute-shader.batched.opt$"
			"^gettextureinfo.batched$"
			"^gettextureinfo-reg.regress.batched.opt$"
			"^hyperb.opt$"
			"^hyperb.batched.opt$"
			"^ieee_fp-reg.regress.batched.opt$"
			"^initlist.batched$"
			"^initlist.batched.opt$"
			"^isconnected.batched$"
			"^linearstep.batched$"
			"^linearstep.batched.opt$"
			"^loop.batched$"
			"^loop.batched.opt$"
			"^matrix$"
			"^matrix.opt$"
			"^matrix.batched$"
			"^matrix-compref-reg.regress.batched.opt$"
			"^message-no-closure.batched$"
			"^message-no-closure.batched.opt$"
			"^message-reg.regress.batched.opt$"
			"^miscmath$"
			"^miscmath.opt$"
			"^miscmath.batched$"
			"^miscmath.batched.opt$"
			"^noise.batched$"
			"^noise-cell.batched$"
			"^noise-gabor.batched$"
			"^noise-gabor.batched.opt$"
			"^noise-gabor-reg.regress.batched.opt$"
			"^noise-generic.batched$"
			"^noise-generic.batched.opt$"
			"^noise-perlin.batched$"
			"^noise-perlin.batched.opt$"
			"^noise-simplex.batched$"
			"^noise-simplex.batched.opt$"
			"^noise-reg.regress.batched.opt$"
			"^pnoise.batched$"
			"^pnoise-cell.batched$"
			"^pnoise-gabor.batched$"
			"^pnoise-gabor.batched.opt$"
			"^pnoise-generic.batched$"
			"^pnoise-generic.batched.opt$"
			"^pnoise-perlin.batched$"
			"^pnoise-perlin.batched.opt$"
			"^pnoise-reg.regress.batched.opt$"
			"^opt-warnings.batched$"
			"^opt-warnings.batched.opt$"
			"^regex-reg.regress.batched.opt$"
			"^select.batched$"
			"^select.batched.opt$"
			"^shaderglobals.batched$"
			"^shaderglobals.batched.opt$"
			"^smoothstep-reg.regress.batched.opt$"
			"^spline.batched$"
			"^spline.batched.opt$"
			"^splineinverse-ident.batched$"
			"^splineinverse-ident.batched.opt$"
			"^spline-derivbug.batched$"
			"^spline-derivbug.batched.opt$"
			"^split-reg.regress.batched.opt$"
			"^string.batched$"
			"^string.batched.opt$"
			"^string-reg.regress.batched.opt$"
			"^struct.batched$"
			"^struct-array-mixture.batched$"
			"^struct-array-mixture.batched.opt$"
			"^texture-environment-opts-reg.regress.batched.opt$"
			"^texture-opts-reg.regress.batched.opt$"
			"^texture-wrap.batched$"
			"^texture-wrap.batched.opt$"
			"^transcendental-reg.regress.batched.opt$"
			"^transform$"
			"^transform.opt$"
			"^transform.batched$"
			"^transform.batched.opt$"
			"^transformc$"
			"^transformc.opt$"
			"^transformc.batched$"
			"^transformc.batched.opt$"
			"^trig$"
			"^trig.opt$"
			"^trig.batched$"
			"^trig.batched.opt$"
			"^trig-reg.regress.batched.opt$"
			"^vecctr.batched$"
			"^vecctr.batched.opt$"
			"^vector-reg.regress.batched.opt$"
			"^xml-reg.regress.batched.opt$"
			"^gettextureinfo-udim.batched$"
			"^gettextureinfo-udim.batched.opt$"
			"^gettextureinfo-udim-reg.regress.batched.opt$"
			"^pointcloud.batched$"
			"^pointcloud.batched.opt$"
		)
	fi

	myctestargs=(
		# src/build-scripts/ci-test.bash
		'--force-new-ctest-process'
	)

	local -x DEBUG CXXFLAGS LD_LIBRARY_PATH DIR OSL_DIR OSL_SOURCE_DIR PYTHONPATH
	DEBUG=1 # doubles the floating point tolerance
	CXXFLAGS="-I${T}/usr/include"
	LD_LIBRARY_PATH="${T}/usr/$(get_libdir)"
	OSL_DIR="${T}/usr/$(get_libdir)/cmake/OSL"
	OSL_SOURCE_DIR="${S}"

	if use python; then
		PYTHONPATH="${BUILD_DIR}/lib/python/site-packages"
	fi

	cmake_src_test

	CMAKE_SKIP_TESTS=(
		"^render-background$"
		"^render-bumptest$"
		"^render-mx-furnace-sheen$"
		"^render-mx-burley-diffuse$"
		"^render-mx-conductor$"
		"^render-mx-generalized-schlick-glass$"
		"^render-microfacet$"
		"^render-oren-nayar$"
		"^render-veachmis$"
		"^render-ward$"
		"^render-raytypes.opt$"
	)

	myctestargs=(
		# src/build-scripts/ci-test.bash
		'--force-new-ctest-process'
		--repeat until-pass:10
		-R "^render"
	)

	cmake_src_test
}