Cycles: Fix long compile time with MSVC.
[blender.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/opencl/kernel.cl
17         kernels/opencl/kernel_data_init.cl
18         kernels/opencl/kernel_queue_enqueue.cl
19         kernels/opencl/kernel_scene_intersect.cl
20         kernels/opencl/kernel_lamp_emission.cl
21         kernels/opencl/kernel_background_buffer_update.cl
22         kernels/opencl/kernel_shader_eval.cl
23         kernels/opencl/kernel_holdout_emission_blurring_pathtermination_ao.cl
24         kernels/opencl/kernel_direct_lighting.cl
25         kernels/opencl/kernel_shadow_blocked.cl
26         kernels/opencl/kernel_next_iteration_setup.cl
27         kernels/opencl/kernel_sum_all_radiance.cl
28         kernels/cuda/kernel.cu
29 )
30
31 set(SRC_HEADERS
32         kernel_accumulate.h
33         kernel_bake.h
34         kernel_camera.h
35         kernel_compat_cpu.h
36         kernel_compat_cuda.h
37         kernel_compat_opencl.h
38         kernel_debug.h
39         kernel_differential.h
40         kernel_emission.h
41         kernel_film.h
42         kernel_globals.h
43         kernel_jitter.h
44         kernel_light.h
45         kernel_math.h
46         kernel_montecarlo.h
47         kernel_passes.h
48         kernel_path.h
49         kernel_path_branched.h
50         kernel_path_common.h
51         kernel_path_state.h
52         kernel_path_surface.h
53         kernel_path_volume.h
54         kernel_projection.h
55         kernel_queues.h
56         kernel_random.h
57         kernel_shader.h
58         kernel_shadow.h
59         kernel_subsurface.h
60         kernel_textures.h
61         kernel_types.h
62         kernel_volume.h
63         kernel_work_stealing.h
64 )
65
66 set(SRC_KERNELS_CPU_HEADERS
67         kernel.h
68         kernels/cpu/kernel_cpu.h
69         kernels/cpu/kernel_cpu_impl.h
70         kernels/cpu/kernel_cpu_image.h
71 )
72
73 set(SRC_CLOSURE_HEADERS
74         closure/bsdf.h
75         closure/bsdf_ashikhmin_velvet.h
76         closure/bsdf_diffuse.h
77         closure/bsdf_diffuse_ramp.h
78         closure/bsdf_microfacet.h
79         closure/bsdf_oren_nayar.h
80         closure/bsdf_phong_ramp.h
81         closure/bsdf_reflection.h
82         closure/bsdf_refraction.h
83         closure/bsdf_toon.h
84         closure/bsdf_transparent.h
85         closure/bsdf_util.h
86         closure/bsdf_ashikhmin_shirley.h
87         closure/bsdf_hair.h
88         closure/bssrdf.h
89         closure/emissive.h
90         closure/volume.h
91 )
92
93 set(SRC_SVM_HEADERS
94         svm/svm.h
95         svm/svm_attribute.h
96         svm/svm_blackbody.h
97         svm/svm_camera.h
98         svm/svm_closure.h
99         svm/svm_convert.h
100         svm/svm_checker.h
101         svm/svm_brick.h
102         svm/svm_displace.h
103         svm/svm_fresnel.h
104         svm/svm_wireframe.h
105         svm/svm_wavelength.h
106         svm/svm_gamma.h
107         svm/svm_brightness.h
108         svm/svm_geometry.h
109         svm/svm_gradient.h
110         svm/svm_hsv.h
111         svm/svm_image.h
112         svm/svm_invert.h
113         svm/svm_light_path.h
114         svm/svm_magic.h
115         svm/svm_mapping.h
116         svm/svm_math.h
117         svm/svm_math_util.h
118         svm/svm_mix.h
119         svm/svm_musgrave.h
120         svm/svm_noise.h
121         svm/svm_noisetex.h
122         svm/svm_normal.h
123         svm/svm_ramp.h
124         svm/svm_sepcomb_hsv.h
125         svm/svm_sepcomb_vector.h
126         svm/svm_sky.h
127         svm/svm_tex_coord.h
128         svm/svm_texture.h
129         svm/svm_types.h
130         svm/svm_value.h
131         svm/svm_vector_transform.h
132         svm/svm_voronoi.h
133         svm/svm_voxel.h
134         svm/svm_wave.h
135 )
136
137 set(SRC_GEOM_HEADERS
138         geom/geom.h
139         geom/geom_attribute.h
140         geom/geom_bvh.h
141         geom/geom_bvh_shadow.h
142         geom/geom_bvh_subsurface.h
143         geom/geom_bvh_traversal.h
144         geom/geom_bvh_volume.h
145         geom/geom_bvh_volume_all.h
146         geom/geom_curve.h
147         geom/geom_motion_curve.h
148         geom/geom_motion_triangle.h
149         geom/geom_object.h
150         geom/geom_primitive.h
151         geom/geom_qbvh.h
152         geom/geom_qbvh_shadow.h
153         geom/geom_qbvh_subsurface.h
154         geom/geom_qbvh_traversal.h
155         geom/geom_qbvh_volume.h
156         geom/geom_qbvh_volume_all.h
157         geom/geom_triangle.h
158         geom/geom_triangle_intersect.h
159         geom/geom_volume.h
160 )
161
162 set(SRC_UTIL_HEADERS
163         ../util/util_atomic.h
164         ../util/util_color.h
165         ../util/util_half.h
166         ../util/util_math.h
167         ../util/util_math_fast.h
168         ../util/util_transform.h
169         ../util/util_texture.h
170         ../util/util_types.h
171 )
172
173 set(SRC_SPLIT_HEADERS
174         split/kernel_background_buffer_update.h
175         split/kernel_data_init.h
176         split/kernel_direct_lighting.h
177         split/kernel_holdout_emission_blurring_pathtermination_ao.h
178         split/kernel_lamp_emission.h
179         split/kernel_next_iteration_setup.h
180         split/kernel_scene_intersect.h
181         split/kernel_shader_eval.h
182         split/kernel_shadow_blocked.h
183         split/kernel_split_common.h
184         split/kernel_sum_all_radiance.h
185 )
186
187 # CUDA module
188
189 if(WITH_CYCLES_CUDA_BINARIES)
190         # 32 bit or 64 bit
191         if(CUDA_64_BIT_DEVICE_CODE)
192                 set(CUDA_BITS 64)
193         else()
194                 set(CUDA_BITS 32)
195         endif()
196
197         # CUDA version
198         execute_process(COMMAND ${CUDA_NVCC_EXECUTABLE} "--version" OUTPUT_VARIABLE NVCC_OUT)
199         string(REGEX REPLACE ".*release ([0-9]+)\\.([0-9]+).*" "\\1" CUDA_VERSION_MAJOR "${NVCC_OUT}")
200         string(REGEX REPLACE ".*release ([0-9]+)\\.([0-9]+).*" "\\2" CUDA_VERSION_MINOR "${NVCC_OUT}")
201         set(CUDA_VERSION "${CUDA_VERSION_MAJOR}${CUDA_VERSION_MINOR}")
202
203         # warn for other versions
204         if(CUDA_VERSION MATCHES "75")
205         else()
206                 message(WARNING
207                         "CUDA version ${CUDA_VERSION_MAJOR}.${CUDA_VERSION_MINOR} detected, "
208                         "build may succeed but only CUDA 7.5 is officially supported")
209         endif()
210
211         # build for each arch
212         set(cuda_sources kernels/cuda/kernel.cu ${SRC_HEADERS} ${SRC_SVM_HEADERS} ${SRC_GEOM_HEADERS} ${SRC_CLOSURE_HEADERS} ${SRC_UTIL_HEADERS})
213         set(cuda_cubins)
214
215         macro(CYCLES_CUDA_KERNEL_ADD arch experimental)
216                 if(${experimental})
217                         set(cuda_extra_flags "-D__KERNEL_EXPERIMENTAL__")
218                         set(cuda_cubin kernel_experimental_${arch}.cubin)
219                 else()
220                         set(cuda_extra_flags "")
221                         set(cuda_cubin kernel_${arch}.cubin)
222                 endif()
223
224                 if(WITH_CYCLES_DEBUG)
225                         set(cuda_debug_flags "-D__KERNEL_DEBUG__")
226                 else()
227                         set(cuda_debug_flags "")
228                 endif()
229
230                 set(cuda_version_flags "-D__KERNEL_CUDA_VERSION__=${CUDA_VERSION}")
231                 set(cuda_math_flags "--use_fast_math")
232
233                 add_custom_command(
234                         OUTPUT ${cuda_cubin}
235                         COMMAND ${CUDA_NVCC_EXECUTABLE}
236                                         -arch=${arch}
237                                         -m${CUDA_BITS}
238                                         --cubin ${CMAKE_CURRENT_SOURCE_DIR}/kernels/cuda/kernel.cu
239                                         -o ${CMAKE_CURRENT_BINARY_DIR}/${cuda_cubin}
240                                         --ptxas-options="-v"
241                                         ${cuda_arch_flags}
242                                         ${cuda_version_flags}
243                                         ${cuda_math_flags}
244                                         ${cuda_extra_flags}
245                                         ${cuda_debug_flags}
246                                         -I${CMAKE_CURRENT_SOURCE_DIR}/../util
247                                         -I${CMAKE_CURRENT_SOURCE_DIR}/svm
248                                         -DCCL_NAMESPACE_BEGIN=
249                                         -DCCL_NAMESPACE_END=
250                                         -DNVCC
251
252                         DEPENDS ${cuda_sources})
253
254                 delayed_install("${CMAKE_CURRENT_BINARY_DIR}" "${cuda_cubin}" ${CYCLES_INSTALL_PATH}/lib)
255                 list(APPEND cuda_cubins ${cuda_cubin})
256
257                 unset(cuda_extra_flags)
258                 unset(cuda_debug_flags)
259         endmacro()
260
261         foreach(arch ${CYCLES_CUDA_BINARIES_ARCH})
262                 # Compile regular kernel
263                 CYCLES_CUDA_KERNEL_ADD(${arch} FALSE)
264         endforeach()
265
266         add_custom_target(cycles_kernel_cuda ALL DEPENDS ${cuda_cubins})
267 endif()
268
269 # OSL module
270
271 if(WITH_CYCLES_OSL)
272         add_subdirectory(osl)
273         add_subdirectory(shaders)
274 endif()
275
276 # CPU module
277
278 include_directories(${INC})
279 include_directories(SYSTEM ${INC_SYS})
280
281 if(CXX_HAS_SSE)
282         list(APPEND SRC
283                 kernels/cpu/kernel_sse2.cpp
284                 kernels/cpu/kernel_sse3.cpp
285                 kernels/cpu/kernel_sse41.cpp
286         )
287
288         set_source_files_properties(kernels/cpu/kernel_sse2.cpp PROPERTIES COMPILE_FLAGS "${CYCLES_SSE2_KERNEL_FLAGS}")
289         set_source_files_properties(kernels/cpu/kernel_sse3.cpp PROPERTIES COMPILE_FLAGS "${CYCLES_SSE3_KERNEL_FLAGS}")
290         set_source_files_properties(kernels/cpu/kernel_sse41.cpp PROPERTIES COMPILE_FLAGS "${CYCLES_SSE41_KERNEL_FLAGS}")
291 endif()
292
293 if(CXX_HAS_AVX)
294         list(APPEND SRC
295                 kernels/cpu/kernel_avx.cpp
296         )
297         set_source_files_properties(kernels/cpu/kernel_avx.cpp PROPERTIES COMPILE_FLAGS "${CYCLES_AVX_KERNEL_FLAGS}")
298 endif()
299
300 if(CXX_HAS_AVX2)
301         list(APPEND SRC
302                 kernels/cpu/kernel_avx2.cpp
303         )
304         set_source_files_properties(kernels/cpu/kernel_avx2.cpp PROPERTIES COMPILE_FLAGS "${CYCLES_AVX2_KERNEL_FLAGS}")
305 endif()
306
307 add_library(cycles_kernel
308         ${SRC}
309         ${SRC_HEADERS}
310         ${SRC_KERNELS_CPU_HEADERS}
311         ${SRC_CLOSURE_HEADERS}
312         ${SRC_SVM_HEADERS}
313         ${SRC_GEOM_HEADERS}
314         ${SRC_SPLIT_HEADERS}
315 )
316
317 if(WITH_CYCLES_CUDA)
318         add_dependencies(cycles_kernel cycles_kernel_cuda)
319 endif()
320
321 # OpenCL kernel
322
323 #set(KERNEL_PREPROCESSED ${CMAKE_CURRENT_BINARY_DIR}/kernel_preprocessed.cl)
324 #add_custom_command(
325 #       OUTPUT ${KERNEL_PREPROCESSED}
326 #       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}
327 #       DEPENDS ${SRC_KERNEL} ${SRC_UTIL_HEADERS})
328 #add_custom_target(cycles_kernel_preprocess ALL DEPENDS ${KERNEL_PREPROCESSED})
329 #delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "${KERNEL_PREPROCESSED}" ${CYCLES_INSTALL_PATH}/kernel)
330
331 delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "kernels/opencl/kernel.cl" ${CYCLES_INSTALL_PATH}/kernel/kernels/opencl)
332 delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "kernels/opencl/kernel_data_init.cl" ${CYCLES_INSTALL_PATH}/kernel/kernels/opencl)
333 delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "kernels/opencl/kernel_queue_enqueue.cl" ${CYCLES_INSTALL_PATH}/kernel/kernels/opencl)
334 delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "kernels/opencl/kernel_scene_intersect.cl" ${CYCLES_INSTALL_PATH}/kernel/kernels/opencl)
335 delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "kernels/opencl/kernel_lamp_emission.cl" ${CYCLES_INSTALL_PATH}/kernel/kernels/opencl)
336 delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "kernels/opencl/kernel_background_buffer_update.cl" ${CYCLES_INSTALL_PATH}/kernel/kernels/opencl)
337 delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "kernels/opencl/kernel_shader_eval.cl" ${CYCLES_INSTALL_PATH}/kernel/kernels/opencl)
338 delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "kernels/opencl/kernel_holdout_emission_blurring_pathtermination_ao.cl" ${CYCLES_INSTALL_PATH}/kernel/kernels/opencl)
339 delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "kernels/opencl/kernel_direct_lighting.cl" ${CYCLES_INSTALL_PATH}/kernel/kernels/opencl)
340 delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "kernels/opencl/kernel_shadow_blocked.cl" ${CYCLES_INSTALL_PATH}/kernel/kernels/opencl)
341 delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "kernels/opencl/kernel_next_iteration_setup.cl" ${CYCLES_INSTALL_PATH}/kernel/kernels/opencl)
342 delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "kernels/opencl/kernel_sum_all_radiance.cl" ${CYCLES_INSTALL_PATH}/kernel/kernels/opencl)
343 delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "kernels/cuda/kernel.cu" ${CYCLES_INSTALL_PATH}/kernel/kernels/cuda)
344 delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "${SRC_HEADERS}" ${CYCLES_INSTALL_PATH}/kernel)
345 delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "${SRC_CLOSURE_HEADERS}" ${CYCLES_INSTALL_PATH}/kernel/closure)
346 delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "${SRC_SVM_HEADERS}" ${CYCLES_INSTALL_PATH}/kernel/svm)
347 delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "${SRC_GEOM_HEADERS}" ${CYCLES_INSTALL_PATH}/kernel/geom)
348 delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "${SRC_UTIL_HEADERS}" ${CYCLES_INSTALL_PATH}/kernel)
349 delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "${SRC_SPLIT_HEADERS}" ${CYCLES_INSTALL_PATH}/kernel/split)
350