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