1 |
commit: 240b8b5737d5451ad70466ccc16e49630c295863 |
2 |
Author: Bernd Waibel <waebbl-gentoo <AT> posteo <DOT> net> |
3 |
AuthorDate: Sat Sep 17 09:06:21 2022 +0000 |
4 |
Commit: Ionen Wolkens <ionen <AT> gentoo <DOT> org> |
5 |
CommitDate: Sun Sep 25 12:22:38 2022 +0000 |
6 |
URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=240b8b57 |
7 |
|
8 |
media-gfx/blender: add optix support |
9 |
|
10 |
Add compile and runtime support for the NVIDIA OptiX library. |
11 |
|
12 |
Signed-off-by: Bernd Waibel <waebbl-gentoo <AT> posteo.net> |
13 |
Closes: https://bugs.gentoo.org/741564 |
14 |
Signed-off-by: Ionen Wolkens <ionen <AT> gentoo.org> |
15 |
|
16 |
media-gfx/blender/blender-3.2.2.ebuild | 15 ++- |
17 |
...option-to-specify-OptiX-runtime-root-dire.patch | 108 +++++++++++++++++++++ |
18 |
...-wrong-Cycles-OptiX-runtime-compilation-i.patch | 23 +++++ |
19 |
media-gfx/blender/metadata.xml | 3 + |
20 |
4 files changed, 148 insertions(+), 1 deletion(-) |
21 |
|
22 |
diff --git a/media-gfx/blender/blender-3.2.2.ebuild b/media-gfx/blender/blender-3.2.2.ebuild |
23 |
index b8269d9b77fb..4442e89a027e 100644 |
24 |
--- a/media-gfx/blender/blender-3.2.2.ebuild |
25 |
+++ b/media-gfx/blender/blender-3.2.2.ebuild |
26 |
@@ -28,7 +28,8 @@ IUSE="+bullet +dds +fluid +openexr +tbb \ |
27 |
alembic collada +color-management cuda +cycles \ |
28 |
debug doc +embree +ffmpeg +fftw +gmp headless jack jemalloc jpeg2k \ |
29 |
man +nanovdb ndof nls openal +oidn +openimageio +openmp +opensubdiv \ |
30 |
- +openvdb +osl +pdf +potrace +pugixml pulseaudio sdl +sndfile test +tiff valgrind" |
31 |
+ +openvdb optix +osl +pdf +potrace +pugixml pulseaudio sdl +sndfile \ |
32 |
+ test +tiff valgrind" |
33 |
RESTRICT="!test? ( test )" |
34 |
|
35 |
REQUIRED_USE="${PYTHON_REQUIRED_USE} |
36 |
@@ -37,6 +38,7 @@ REQUIRED_USE="${PYTHON_REQUIRED_USE} |
37 |
cycles? ( openexr tiff openimageio ) |
38 |
fluid? ( tbb ) |
39 |
openvdb? ( tbb ) |
40 |
+ optix? ( cuda ) |
41 |
osl? ( cycles ) |
42 |
test? ( color-management )" |
43 |
|
44 |
@@ -93,6 +95,7 @@ RDEPEND="${PYTHON_DEPS} |
45 |
>=media-gfx/openvdb-9.0.0:=[nanovdb?] |
46 |
dev-libs/c-blosc:= |
47 |
) |
48 |
+ optix? ( <dev-libs/optix-7.5.0 ) |
49 |
osl? ( >=media-libs/osl-1.11.16.0-r3:= ) |
50 |
pdf? ( media-libs/libharu ) |
51 |
potrace? ( media-gfx/potrace ) |
52 |
@@ -126,6 +129,8 @@ BDEPEND=" |
53 |
PATCHES=( |
54 |
"${FILESDIR}"/${PN}-3.2.2-support-building-with-musl-libc.patch |
55 |
"${FILESDIR}"/${PN}-3.2.2-musl-glibc-prereq.patch |
56 |
+ "${FILESDIR}"/${PN}-3.2.2-Cycles-add-option-to-specify-OptiX-runtime-root-dire.patch |
57 |
+ "${FILESDIR}"/${PN}-3.2.2-Fix-T100845-wrong-Cycles-OptiX-runtime-compilation-i.patch |
58 |
) |
59 |
|
60 |
blender_check_requirements() { |
61 |
@@ -222,6 +227,7 @@ src_configure() { |
62 |
-DWITH_CXX_GUARDEDALLOC=$(usex debug) |
63 |
-DWITH_CYCLES=$(usex cycles) |
64 |
-DWITH_CYCLES_DEVICE_CUDA=$(usex cuda TRUE FALSE) |
65 |
+ -DWITH_CYCLES_DEVICE_OPTIX=$(usex optix) |
66 |
-DWITH_CYCLES_EMBREE=$(usex embree) |
67 |
-DWITH_CYCLES_OSL=$(usex osl) |
68 |
-DWITH_CYCLES_STANDALONE=OFF |
69 |
@@ -269,6 +275,13 @@ src_configure() { |
70 |
-DWITH_XR_OPENXR=OFF |
71 |
) |
72 |
|
73 |
+ if use optix; then |
74 |
+ mycmakeargs+=( |
75 |
+ -DCYCLES_RUNTIME_OPTIX_ROOT_DIR="${EPREFIX}"/opt/optix |
76 |
+ -DOPTIX_ROOT_DIR="${EPREFIX}"/opt/optix |
77 |
+ ) |
78 |
+ fi |
79 |
+ |
80 |
append-flags $(usex debug '-DDEBUG' '-DNDEBUG') |
81 |
|
82 |
if tc-is-gcc ; then |
83 |
|
84 |
diff --git a/media-gfx/blender/files/blender-3.2.2-Cycles-add-option-to-specify-OptiX-runtime-root-dire.patch b/media-gfx/blender/files/blender-3.2.2-Cycles-add-option-to-specify-OptiX-runtime-root-dire.patch |
85 |
new file mode 100644 |
86 |
index 000000000000..2a7b33cf8ac4 |
87 |
--- /dev/null |
88 |
+++ b/media-gfx/blender/files/blender-3.2.2-Cycles-add-option-to-specify-OptiX-runtime-root-dire.patch |
89 |
@@ -0,0 +1,108 @@ |
90 |
+From https://developer.blender.org/rB74caf773619bbf6a0f95c598b66261a6bef392ee |
91 |
+From: Brecht Van Lommel <brecht@×××××××.org> |
92 |
+Date: Mon, 29 Aug 2022 19:12:15 +0200 |
93 |
+Subject: [PATCH 001/539] Cycles: add option to specify OptiX runtime root |
94 |
+ directory |
95 |
+ |
96 |
+This allows individual users or Linux distributions to specify a directory |
97 |
+Cycles will automatically look for the OptiX include folder, to compile kernels |
98 |
+at runtime. |
99 |
+ |
100 |
+It is still possible to override this with the OPTIX_ROOT_DIR environment |
101 |
+variable at runtime. |
102 |
+ |
103 |
+Based on patch by Sebastian Parborg. |
104 |
+ |
105 |
+Ref D15792 |
106 |
+--- a/CMakeLists.txt |
107 |
++++ b/CMakeLists.txt |
108 |
+@@ -435,10 +435,16 @@ if(NOT APPLE) |
109 |
+ option(WITH_CYCLES_CUBIN_COMPILER "Build cubins with nvrtc based compiler instead of nvcc" OFF) |
110 |
+ option(WITH_CYCLES_CUDA_BUILD_SERIAL "Build cubins one after another (useful on machines with limited RAM)" OFF) |
111 |
+ option(WITH_CUDA_DYNLOAD "Dynamically load CUDA libraries at runtime (for developers, makes cuda-gdb work)" ON) |
112 |
++ |
113 |
++ set(OPTIX_ROOT_DIR "" CACHE PATH "Path to the OptiX SDK root directory, for building Cycles OptiX kernels.") |
114 |
++ set(CYCLES_RUNTIME_OPTIX_ROOT_DIR "" CACHE PATH "Path to the OptiX SDK root directory. When set, this path will be used at runtime to compile OptiX kernels.") |
115 |
++ |
116 |
+ mark_as_advanced(CYCLES_CUDA_BINARIES_ARCH) |
117 |
+ mark_as_advanced(WITH_CYCLES_CUBIN_COMPILER) |
118 |
+ mark_as_advanced(WITH_CYCLES_CUDA_BUILD_SERIAL) |
119 |
+ mark_as_advanced(WITH_CUDA_DYNLOAD) |
120 |
++ mark_as_advanced(OPTIX_ROOT_DIR) |
121 |
++ mark_as_advanced(CYCLES_RUNTIME_OPTIX_ROOT_DIR) |
122 |
+ endif() |
123 |
+ |
124 |
+ # AMD HIP |
125 |
+--- a/intern/cycles/device/CMakeLists.txt |
126 |
++++ b/intern/cycles/device/CMakeLists.txt |
127 |
+@@ -19,6 +19,8 @@ if(WITH_CYCLES_DEVICE_OPTIX OR WITH_CYCLES_DEVICE_CUDA) |
128 |
+ ) |
129 |
+ add_definitions(-DCYCLES_CUDA_NVCC_EXECUTABLE="${CUDA_NVCC_EXECUTABLE}") |
130 |
+ endif() |
131 |
++ |
132 |
++ add_definitions(-DCYCLES_RUNTIME_OPTIX_ROOT_DIR="${CYCLES_RUNTIME_OPTIX_ROOT_DIR}") |
133 |
+ endif() |
134 |
+ |
135 |
+ if(WITH_CYCLES_DEVICE_HIP AND WITH_HIP_DYNLOAD) |
136 |
+--- a/intern/cycles/device/optix/device_impl.cpp |
137 |
++++ b/intern/cycles/device/optix/device_impl.cpp |
138 |
+@@ -342,15 +342,29 @@ BVHLayoutMask OptiXDevice::get_bvh_layout_mask() const |
139 |
+ return BVH_LAYOUT_OPTIX; |
140 |
+ } |
141 |
+ |
142 |
++static string get_optix_include_dir() |
143 |
++{ |
144 |
++ const char *env_dir = getenv("OPTIX_ROOT_DIR"); |
145 |
++ const char *default_dir = CYCLES_RUNTIME_OPTIX_ROOT_DIR; |
146 |
++ |
147 |
++ if (env_dir && env_dir[0]) { |
148 |
++ const string env_include_dir = path_join(env_dir, "include"); |
149 |
++ return env_include_dir; |
150 |
++ } |
151 |
++ else if (default_dir[0]) { |
152 |
++ const string default_include_dir = path_join(default_dir, "include"); |
153 |
++ return default_include_dir; |
154 |
++ } |
155 |
++ |
156 |
++ return string(); |
157 |
++} |
158 |
++ |
159 |
+ string OptiXDevice::compile_kernel_get_common_cflags(const uint kernel_features) |
160 |
+ { |
161 |
+ string common_cflags = CUDADevice::compile_kernel_get_common_cflags(kernel_features); |
162 |
+ |
163 |
+ /* Add OptiX SDK include directory to include paths. */ |
164 |
+- const char *optix_sdk_path = getenv("OPTIX_ROOT_DIR"); |
165 |
+- if (optix_sdk_path) { |
166 |
+- common_cflags += string_printf(" -I\"%s/include\"", optix_sdk_path); |
167 |
+- } |
168 |
++ common_cflags += string_printf(" -I\"%s/include\"", get_optix_include_dir().c_str()); |
169 |
+ |
170 |
+ /* Specialization for shader raytracing. */ |
171 |
+ if (kernel_features & KERNEL_FEATURE_NODE_RAYTRACE) { |
172 |
+@@ -460,10 +474,19 @@ bool OptiXDevice::load_kernels(const uint kernel_features) |
173 |
+ "lib/kernel_optix_shader_raytrace.ptx" : |
174 |
+ "lib/kernel_optix.ptx"); |
175 |
+ if (use_adaptive_compilation() || path_file_size(ptx_filename) == -1) { |
176 |
+- if (!getenv("OPTIX_ROOT_DIR")) { |
177 |
++ std::string optix_include_dir = get_optix_include_dir(); |
178 |
++ if (optix_include_dir.empty()) { |
179 |
+ set_error( |
180 |
+- "Missing OPTIX_ROOT_DIR environment variable (which must be set with the path to " |
181 |
+- "the Optix SDK to be able to compile Optix kernels on demand)."); |
182 |
++ "Unable to compile OptiX kernels at runtime. Set OPTIX_ROOT_DIR environment variable " |
183 |
++ "to a directory containing the OptiX SDK."); |
184 |
++ return false; |
185 |
++ } |
186 |
++ else if (!path_is_directory(optix_include_dir)) { |
187 |
++ set_error(string_printf( |
188 |
++ "OptiX headers not found at %s, unable to compile OptiX kernels at runtime. Install " |
189 |
++ "OptiX SDK in the specified location, or set OPTIX_ROOT_DIR environment variable to a " |
190 |
++ "directory containing the OptiX SDK.", |
191 |
++ optix_include_dir.c_str())); |
192 |
+ return false; |
193 |
+ } |
194 |
+ ptx_filename = compile_kernel( |
195 |
+-- |
196 |
+2.37.3 |
197 |
+ |
198 |
|
199 |
diff --git a/media-gfx/blender/files/blender-3.2.2-Fix-T100845-wrong-Cycles-OptiX-runtime-compilation-i.patch b/media-gfx/blender/files/blender-3.2.2-Fix-T100845-wrong-Cycles-OptiX-runtime-compilation-i.patch |
200 |
new file mode 100644 |
201 |
index 000000000000..921b648ca388 |
202 |
--- /dev/null |
203 |
+++ b/media-gfx/blender/files/blender-3.2.2-Fix-T100845-wrong-Cycles-OptiX-runtime-compilation-i.patch |
204 |
@@ -0,0 +1,23 @@ |
205 |
+From https://developer.blender.org/rB74477149dddfddeca71be6770d520f870c0b5bc9 |
206 |
+From: Josh Whelchel <soundofjw> |
207 |
+Date: Tue, 6 Sep 2022 15:39:39 +0200 |
208 |
+Subject: [PATCH 663/965] Fix T100845: wrong Cycles OptiX runtime compilation |
209 |
+ include path |
210 |
+ |
211 |
+Causing OptiX kernel build errors on Arch Linux. |
212 |
+ |
213 |
+Differential Revision: https://developer.blender.org/D15891 |
214 |
+--- a/intern/cycles/device/optix/device_impl.cpp |
215 |
++++ b/intern/cycles/device/optix/device_impl.cpp |
216 |
+@@ -364,7 +364,7 @@ string OptiXDevice::compile_kernel_get_common_cflags(const uint kernel_features) |
217 |
+ string common_cflags = CUDADevice::compile_kernel_get_common_cflags(kernel_features); |
218 |
+ |
219 |
+ /* Add OptiX SDK include directory to include paths. */ |
220 |
+- common_cflags += string_printf(" -I\"%s/include\"", get_optix_include_dir().c_str()); |
221 |
++ common_cflags += string_printf(" -I\"%s\"", get_optix_include_dir().c_str()); |
222 |
+ |
223 |
+ /* Specialization for shader raytracing. */ |
224 |
+ if (kernel_features & KERNEL_FEATURE_NODE_RAYTRACE) { |
225 |
+-- |
226 |
+2.37.3 |
227 |
+ |
228 |
|
229 |
diff --git a/media-gfx/blender/metadata.xml b/media-gfx/blender/metadata.xml |
230 |
index a6093fd9c1b6..41cc89220a5f 100644 |
231 |
--- a/media-gfx/blender/metadata.xml |
232 |
+++ b/media-gfx/blender/metadata.xml |
233 |
@@ -67,6 +67,9 @@ |
234 |
<flag name="openvdb"> |
235 |
Enable openvdb for volumetric processing, like the voxel remesher. Also enables volumetric GPU preview rendering for Nvidia cards. |
236 |
</flag> |
237 |
+ <flag name="optix"> |
238 |
+ Add support for NVIDIA's OptiX Raytracing Engine. |
239 |
+ </flag> |
240 |
<flag name="osl"> |
241 |
Add support for OpenShadingLanguage scripting. |
242 |
</flag> |