Cycles: Split path initialization into own kernel
[blender-staging.git] / intern / cycles / kernel / CMakeLists.txt
1 remove_extra_strict_flags()
2
3 set(INC
4         .
5         ../util
6         osl
7         svm
8 )
9
10 set(INC_SYS
11
12 )
13
14 set(SRC
15         kernels/cpu/kernel.cpp
16         kernels/cpu/kernel_split.cpp
17         kernels/opencl/kernel.cl
18         kernels/opencl/kernel_data_init.cl
19         kernels/opencl/kernel_path_init.cl
20         kernels/opencl/kernel_queue_enqueue.cl
21         kernels/opencl/kernel_scene_intersect.cl
22         kernels/opencl/kernel_lamp_emission.cl
23         kernels/opencl/kernel_background_buffer_update.cl
24         kernels/opencl/kernel_shader_eval.cl
25         kernels/opencl/kernel_holdout_emission_blurring_pathtermination_ao.cl
26         kernels/opencl/kernel_direct_lighting.cl
27         kernels/opencl/kernel_shadow_blocked.cl
28         kernels/opencl/kernel_next_iteration_setup.cl
29         kernels/opencl/kernel_sum_all_radiance.cl
30         kernels/cuda/kernel.cu
31         kernels/cuda/kernel_split.cu
32 )
33
34 set(SRC_BVH_HEADERS
35         bvh/bvh.h
36         bvh/bvh_nodes.h
37         bvh/bvh_shadow_all.h
38         bvh/bvh_subsurface.h
39         bvh/bvh_traversal.h
40         bvh/bvh_types.h
41         bvh/bvh_volume.h
42         bvh/bvh_volume_all.h
43         bvh/qbvh_nodes.h
44         bvh/qbvh_shadow_all.h
45         bvh/qbvh_subsurface.h
46         bvh/qbvh_traversal.h
47         bvh/qbvh_volume.h
48         bvh/qbvh_volume_all.h
49 )
50
51 set(SRC_HEADERS
52         kernel_accumulate.h
53         kernel_bake.h
54         kernel_camera.h
55         kernel_compat_cpu.h
56         kernel_compat_cuda.h
57         kernel_compat_opencl.h
58         kernel_debug.h
59         kernel_differential.h
60         kernel_emission.h
61         kernel_film.h
62         kernel_globals.h
63         kernel_image_opencl.h
64         kernel_jitter.h
65         kernel_light.h
66         kernel_math.h
67         kernel_montecarlo.h
68         kernel_passes.h
69         kernel_path.h
70         kernel_path_branched.h
71         kernel_path_common.h
72         kernel_path_state.h
73         kernel_path_surface.h
74         kernel_path_volume.h
75         kernel_projection.h
76         kernel_queues.h
77         kernel_random.h
78         kernel_shader.h
79         kernel_shadow.h
80         kernel_subsurface.h
81         kernel_textures.h
82         kernel_types.h
83         kernel_volume.h
84         kernel_work_stealing.h
85 )
86
87 set(SRC_KERNELS_CPU_HEADERS
88         kernel.h
89         kernels/cpu/kernel_cpu.h
90         kernels/cpu/kernel_cpu_impl.h
91         kernels/cpu/kernel_cpu_image.h
92 )
93
94 set(SRC_KERNELS_CUDA_HEADERS
95         kernels/cuda/kernel_config.h
96 )
97
98 set(SRC_CLOSURE_HEADERS
99         closure/alloc.h
100         closure/bsdf.h
101         closure/bsdf_ashikhmin_velvet.h
102         closure/bsdf_diffuse.h
103         closure/bsdf_diffuse_ramp.h
104         closure/bsdf_microfacet.h
105         closure/bsdf_microfacet_multi.h
106         closure/bsdf_microfacet_multi_impl.h
107         closure/bsdf_oren_nayar.h
108         closure/bsdf_phong_ramp.h
109         closure/bsdf_reflection.h
110         closure/bsdf_refraction.h
111         closure/bsdf_toon.h
112         closure/bsdf_transparent.h
113         closure/bsdf_util.h
114         closure/bsdf_ashikhmin_shirley.h
115         closure/bsdf_hair.h
116         closure/bssrdf.h
117         closure/emissive.h
118         closure/volume.h
119 )
120
121 set(SRC_SVM_HEADERS
122         svm/svm.h
123         svm/svm_attribute.h
124         svm/svm_blackbody.h
125         svm/svm_bump.h
126         svm/svm_camera.h
127         svm/svm_closure.h
128         svm/svm_convert.h
129         svm/svm_checker.h
130         svm/svm_color_util.h
131         svm/svm_brick.h
132         svm/svm_displace.h
133         svm/svm_fresnel.h
134         svm/svm_wireframe.h
135         svm/svm_wavelength.h
136         svm/svm_gamma.h
137         svm/svm_brightness.h
138         svm/svm_geometry.h
139         svm/svm_gradient.h
140         svm/svm_hsv.h
141         svm/svm_image.h
142         svm/svm_invert.h
143         svm/svm_light_path.h
144         svm/svm_magic.h
145         svm/svm_mapping.h
146         svm/svm_math.h
147         svm/svm_math_util.h
148         svm/svm_mix.h
149         svm/svm_musgrave.h
150         svm/svm_noise.h
151         svm/svm_noisetex.h
152         svm/svm_normal.h
153         svm/svm_ramp.h
154         svm/svm_ramp_util.h
155         svm/svm_sepcomb_hsv.h
156         svm/svm_sepcomb_vector.h
157         svm/svm_sky.h
158         svm/svm_tex_coord.h
159         svm/svm_texture.h
160         svm/svm_types.h
161         svm/svm_value.h
162         svm/svm_vector_transform.h
163         svm/svm_voronoi.h
164         svm/svm_voxel.h
165         svm/svm_wave.h
166 )
167
168 set(SRC_GEOM_HEADERS
169         geom/geom.h
170         geom/geom_attribute.h
171         geom/geom_curve.h
172         geom/geom_motion_curve.h
173         geom/geom_motion_triangle.h
174         geom/geom_motion_triangle_intersect.h
175         geom/geom_motion_triangle_shader.h
176         geom/geom_object.h
177         geom/geom_patch.h
178         geom/geom_primitive.h
179         geom/geom_subd_triangle.h
180         geom/geom_triangle.h
181         geom/geom_triangle_intersect.h
182         geom/geom_volume.h
183 )
184
185 set(SRC_UTIL_HEADERS
186         ../util/util_atomic.h
187         ../util/util_color.h
188         ../util/util_half.h
189         ../util/util_hash.h
190         ../util/util_math.h
191         ../util/util_math_fast.h
192         ../util/util_static_assert.h
193         ../util/util_transform.h
194         ../util/util_texture.h
195         ../util/util_types.h
196 )
197
198 set(SRC_SPLIT_HEADERS
199         split/kernel_background_buffer_update.h
200         split/kernel_data_init.h
201         split/kernel_direct_lighting.h
202         split/kernel_holdout_emission_blurring_pathtermination_ao.h
203         split/kernel_lamp_emission.h
204         split/kernel_next_iteration_setup.h
205         split/kernel_path_init.h
206         split/kernel_queue_enqueue.h
207         split/kernel_scene_intersect.h
208         split/kernel_shader_eval.h
209         split/kernel_shadow_blocked.h
210         split/kernel_split_common.h
211         split/kernel_split_data.h
212         split/kernel_sum_all_radiance.h
213 )
214
215 # CUDA module
216
217 if(WITH_CYCLES_CUDA_BINARIES)
218         # 32 bit or 64 bit
219         if(CUDA_64_BIT_DEVICE_CODE)
220                 set(CUDA_BITS 64)
221         else()
222                 set(CUDA_BITS 32)
223         endif()
224
225         # CUDA version
226         execute_process(COMMAND ${CUDA_NVCC_EXECUTABLE} "--version" OUTPUT_VARIABLE NVCC_OUT)
227         string(REGEX REPLACE ".*release ([0-9]+)\\.([0-9]+).*" "\\1" CUDA_VERSION_MAJOR "${NVCC_OUT}")
228         string(REGEX REPLACE ".*release ([0-9]+)\\.([0-9]+).*" "\\2" CUDA_VERSION_MINOR "${NVCC_OUT}")
229         set(CUDA_VERSION "${CUDA_VERSION_MAJOR}${CUDA_VERSION_MINOR}")
230
231         # warn for other versions
232         if(CUDA_VERSION MATCHES "80")
233         else()
234                 message(WARNING
235                         "CUDA version ${CUDA_VERSION_MAJOR}.${CUDA_VERSION_MINOR} detected, "
236                         "build may succeed but only CUDA 8.0 is officially supported")
237         endif()
238
239         # build for each arch
240         set(cuda_sources kernels/cuda/kernel.cu kernels/cuda/kernel_split.cu
241                 ${SRC_HEADERS}
242                 ${SRC_KERNELS_CUDA_HEADERS}
243                 ${SRC_BVH_HEADERS}
244                 ${SRC_SVM_HEADERS}
245                 ${SRC_GEOM_HEADERS}
246                 ${SRC_CLOSURE_HEADERS}
247                 ${SRC_UTIL_HEADERS}
248         )
249         set(cuda_cubins)
250
251         macro(CYCLES_CUDA_KERNEL_ADD arch split experimental)
252                 if(${split})
253                         set(cuda_extra_flags "-D__SPLIT__")
254                         set(cuda_cubin kernel_split)
255                 else()
256                         set(cuda_extra_flags "")
257                         set(cuda_cubin kernel)
258                 endif()
259
260                 if(${experimental})
261                         set(cuda_extra_flags ${cuda_extra_flags} -D__KERNEL_EXPERIMENTAL__)
262                         set(cuda_cubin ${cuda_cubin}_experimental)
263                 endif()
264
265                 set(cuda_cubin ${cuda_cubin}_${arch}.cubin)
266
267                 if(WITH_CYCLES_DEBUG)
268                         set(cuda_debug_flags "-D__KERNEL_DEBUG__")
269                 else()
270                         set(cuda_debug_flags "")
271                 endif()
272
273                 set(cuda_nvcc_command ${CUDA_NVCC_EXECUTABLE})
274                 set(cuda_nvcc_version ${CUDA_VERSION})
275
276                 set(cuda_version_flags "-D__KERNEL_CUDA_VERSION__=${cuda_nvcc_version}")
277                 set(cuda_math_flags "--use_fast_math")
278
279                 if(split)
280                         set(cuda_kernel_src "/kernels/cuda/kernel_split.cu")
281                 else()
282                         set(cuda_kernel_src "/kernels/cuda/kernel.cu")
283                 endif()
284
285                 add_custom_command(
286                         OUTPUT ${cuda_cubin}
287                         COMMAND ${cuda_nvcc_command}
288                                         -arch=${arch}
289                                         ${CUDA_NVCC_FLAGS}
290                                         -m${CUDA_BITS}
291                                         --cubin ${CMAKE_CURRENT_SOURCE_DIR}${cuda_kernel_src}
292                                         -o ${CMAKE_CURRENT_BINARY_DIR}/${cuda_cubin}
293                                         --ptxas-options="-v"
294                                         ${cuda_arch_flags}
295                                         ${cuda_version_flags}
296                                         ${cuda_math_flags}
297                                         ${cuda_extra_flags}
298                                         ${cuda_debug_flags}
299                                         -I${CMAKE_CURRENT_SOURCE_DIR}/../util
300                                         -I${CMAKE_CURRENT_SOURCE_DIR}/svm
301                                         -DCCL_NAMESPACE_BEGIN=
302                                         -DCCL_NAMESPACE_END=
303                                         -DNVCC
304                         DEPENDS ${cuda_sources})
305
306                 delayed_install("${CMAKE_CURRENT_BINARY_DIR}" "${cuda_cubin}" ${CYCLES_INSTALL_PATH}/lib)
307                 list(APPEND cuda_cubins ${cuda_cubin})
308
309                 unset(cuda_extra_flags)
310                 unset(cuda_debug_flags)
311
312                 unset(cuda_nvcc_command)
313                 unset(cuda_nvcc_version)
314         endmacro()
315
316         foreach(arch ${CYCLES_CUDA_BINARIES_ARCH})
317                 # Compile regular kernel
318                 CYCLES_CUDA_KERNEL_ADD(${arch} FALSE FALSE)
319
320                 if(WITH_CYCLES_CUDA_SPLIT_KERNEL_BINARIES)
321                         # Compile split kernel
322                         CYCLES_CUDA_KERNEL_ADD(${arch} TRUE FALSE)
323                 endif()
324         endforeach()
325
326         add_custom_target(cycles_kernel_cuda ALL DEPENDS ${cuda_cubins})
327 endif()
328
329 # OSL module
330
331 if(WITH_CYCLES_OSL)
332         add_subdirectory(osl)
333         add_subdirectory(shaders)
334 endif()
335
336 # CPU module
337
338 include_directories(${INC})
339 include_directories(SYSTEM ${INC_SYS})
340
341 if(CXX_HAS_SSE)
342         list(APPEND SRC
343                 kernels/cpu/kernel_sse2.cpp
344                 kernels/cpu/kernel_sse3.cpp
345                 kernels/cpu/kernel_sse41.cpp
346                 kernels/cpu/kernel_split_sse2.cpp
347                 kernels/cpu/kernel_split_sse3.cpp
348                 kernels/cpu/kernel_split_sse41.cpp
349         )
350
351         set_source_files_properties(kernels/cpu/kernel_sse2.cpp PROPERTIES COMPILE_FLAGS "${CYCLES_SSE2_KERNEL_FLAGS}")
352         set_source_files_properties(kernels/cpu/kernel_sse3.cpp PROPERTIES COMPILE_FLAGS "${CYCLES_SSE3_KERNEL_FLAGS}")
353         set_source_files_properties(kernels/cpu/kernel_sse41.cpp PROPERTIES COMPILE_FLAGS "${CYCLES_SSE41_KERNEL_FLAGS}")
354         set_source_files_properties(kernels/cpu/kernel_split_sse2.cpp PROPERTIES COMPILE_FLAGS "${CYCLES_SSE2_KERNEL_FLAGS}")
355         set_source_files_properties(kernels/cpu/kernel_split_sse3.cpp PROPERTIES COMPILE_FLAGS "${CYCLES_SSE3_KERNEL_FLAGS}")
356         set_source_files_properties(kernels/cpu/kernel_split_sse41.cpp PROPERTIES COMPILE_FLAGS "${CYCLES_SSE41_KERNEL_FLAGS}")
357 endif()
358
359 if(CXX_HAS_AVX)
360         list(APPEND SRC
361                 kernels/cpu/kernel_avx.cpp
362                 kernels/cpu/kernel_split_avx.cpp
363         )
364         set_source_files_properties(kernels/cpu/kernel_avx.cpp PROPERTIES COMPILE_FLAGS "${CYCLES_AVX_KERNEL_FLAGS}")
365         set_source_files_properties(kernels/cpu/kernel_split_avx.cpp PROPERTIES COMPILE_FLAGS "${CYCLES_AVX_KERNEL_FLAGS}")
366 endif()
367
368 if(CXX_HAS_AVX2)
369         list(APPEND SRC
370                 kernels/cpu/kernel_avx2.cpp
371                 kernels/cpu/kernel_split_avx2.cpp
372         )
373         set_source_files_properties(kernels/cpu/kernel_avx2.cpp PROPERTIES COMPILE_FLAGS "${CYCLES_AVX2_KERNEL_FLAGS}")
374         set_source_files_properties(kernels/cpu/kernel_split_avx2.cpp PROPERTIES COMPILE_FLAGS "${CYCLES_AVX2_KERNEL_FLAGS}")
375 endif()
376
377 add_library(cycles_kernel
378         ${SRC}
379         ${SRC_HEADERS}
380         ${SRC_KERNELS_CPU_HEADERS}
381         ${SRC_KERNELS_CUDA_HEADERS}
382         ${SRC_BVH_HEADERS}
383         ${SRC_CLOSURE_HEADERS}
384         ${SRC_SVM_HEADERS}
385         ${SRC_GEOM_HEADERS}
386         ${SRC_SPLIT_HEADERS}
387 )
388
389 if(WITH_CYCLES_CUDA)
390         add_dependencies(cycles_kernel cycles_kernel_cuda)
391 endif()
392
393 # OpenCL kernel
394
395 #set(KERNEL_PREPROCESSED ${CMAKE_CURRENT_BINARY_DIR}/kernel_preprocessed.cl)
396 #add_custom_command(
397 #       OUTPUT ${KERNEL_PREPROCESSED}
398 #       COMMAND gcc -x c++ -E ${CMAKE_CURRENT_SOURCE_DIR}/kernel.cl -I ${CMAKE_CURRENT_SOURCE_DIR}/../util/ -DCCL_NAMESPACE_BEGIN= -DCCL_NAMESPACE_END= -o ${KERNEL_PREPROCESSED}
399 #       DEPENDS ${SRC_KERNEL} ${SRC_UTIL_HEADERS})
400 #add_custom_target(cycles_kernel_preprocess ALL DEPENDS ${KERNEL_PREPROCESSED})
401 #delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "${KERNEL_PREPROCESSED}" ${CYCLES_INSTALL_PATH}/kernel)
402
403 delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "kernels/opencl/kernel.cl" ${CYCLES_INSTALL_PATH}/kernel/kernels/opencl)
404 delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "kernels/opencl/kernel_data_init.cl" ${CYCLES_INSTALL_PATH}/kernel/kernels/opencl)
405 delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "kernels/opencl/kernel_path_init.cl" ${CYCLES_INSTALL_PATH}/kernel/kernels/opencl)
406 delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "kernels/opencl/kernel_queue_enqueue.cl" ${CYCLES_INSTALL_PATH}/kernel/kernels/opencl)
407 delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "kernels/opencl/kernel_scene_intersect.cl" ${CYCLES_INSTALL_PATH}/kernel/kernels/opencl)
408 delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "kernels/opencl/kernel_lamp_emission.cl" ${CYCLES_INSTALL_PATH}/kernel/kernels/opencl)
409 delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "kernels/opencl/kernel_background_buffer_update.cl" ${CYCLES_INSTALL_PATH}/kernel/kernels/opencl)
410 delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "kernels/opencl/kernel_shader_eval.cl" ${CYCLES_INSTALL_PATH}/kernel/kernels/opencl)
411 delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "kernels/opencl/kernel_holdout_emission_blurring_pathtermination_ao.cl" ${CYCLES_INSTALL_PATH}/kernel/kernels/opencl)
412 delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "kernels/opencl/kernel_direct_lighting.cl" ${CYCLES_INSTALL_PATH}/kernel/kernels/opencl)
413 delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "kernels/opencl/kernel_shadow_blocked.cl" ${CYCLES_INSTALL_PATH}/kernel/kernels/opencl)
414 delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "kernels/opencl/kernel_next_iteration_setup.cl" ${CYCLES_INSTALL_PATH}/kernel/kernels/opencl)
415 delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "kernels/opencl/kernel_sum_all_radiance.cl" ${CYCLES_INSTALL_PATH}/kernel/kernels/opencl)
416 delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "kernels/cuda/kernel.cu" ${CYCLES_INSTALL_PATH}/kernel/kernels/cuda)
417 delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "kernels/cuda/kernel_split.cu" ${CYCLES_INSTALL_PATH}/kernel/kernels/cuda)
418 delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "${SRC_HEADERS}" ${CYCLES_INSTALL_PATH}/kernel)
419 delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "${SRC_KERNELS_CUDA_HEADERS}" ${CYCLES_INSTALL_PATH}/kernel/kernels/cuda)
420 delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "${SRC_BVH_HEADERS}" ${CYCLES_INSTALL_PATH}/kernel/bvh)
421 delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "${SRC_CLOSURE_HEADERS}" ${CYCLES_INSTALL_PATH}/kernel/closure)
422 delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "${SRC_SVM_HEADERS}" ${CYCLES_INSTALL_PATH}/kernel/svm)
423 delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "${SRC_GEOM_HEADERS}" ${CYCLES_INSTALL_PATH}/kernel/geom)
424 delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "${SRC_UTIL_HEADERS}" ${CYCLES_INSTALL_PATH}/kernel)
425 delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "${SRC_SPLIT_HEADERS}" ${CYCLES_INSTALL_PATH}/kernel/split)
426