Cycles: Calculate size of split state buffer kernel side
[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/cpu/kernel_split.cpp
17         kernels/opencl/kernel.cl
18         kernels/opencl/kernel_state_buffer_size.cl
19         kernels/opencl/kernel_data_init.cl
20         kernels/opencl/kernel_path_init.cl
21         kernels/opencl/kernel_queue_enqueue.cl
22         kernels/opencl/kernel_scene_intersect.cl
23         kernels/opencl/kernel_lamp_emission.cl
24         kernels/opencl/kernel_background_buffer_update.cl
25         kernels/opencl/kernel_shader_eval.cl
26         kernels/opencl/kernel_holdout_emission_blurring_pathtermination_ao.cl
27         kernels/opencl/kernel_direct_lighting.cl
28         kernels/opencl/kernel_shadow_blocked.cl
29         kernels/opencl/kernel_next_iteration_setup.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 )
213
214 # CUDA module
215
216 if(WITH_CYCLES_CUDA_BINARIES)
217         # 32 bit or 64 bit
218         if(CUDA_64_BIT_DEVICE_CODE)
219                 set(CUDA_BITS 64)
220         else()
221                 set(CUDA_BITS 32)
222         endif()
223
224         # CUDA version
225         execute_process(COMMAND ${CUDA_NVCC_EXECUTABLE} "--version" OUTPUT_VARIABLE NVCC_OUT)
226         string(REGEX REPLACE ".*release ([0-9]+)\\.([0-9]+).*" "\\1" CUDA_VERSION_MAJOR "${NVCC_OUT}")
227         string(REGEX REPLACE ".*release ([0-9]+)\\.([0-9]+).*" "\\2" CUDA_VERSION_MINOR "${NVCC_OUT}")
228         set(CUDA_VERSION "${CUDA_VERSION_MAJOR}${CUDA_VERSION_MINOR}")
229
230         # warn for other versions
231         if(CUDA_VERSION MATCHES "80")
232         else()
233                 message(WARNING
234                         "CUDA version ${CUDA_VERSION_MAJOR}.${CUDA_VERSION_MINOR} detected, "
235                         "build may succeed but only CUDA 8.0 is officially supported")
236         endif()
237
238         # build for each arch
239         set(cuda_sources kernels/cuda/kernel.cu kernels/cuda/kernel_split.cu
240                 ${SRC_HEADERS}
241                 ${SRC_KERNELS_CUDA_HEADERS}
242                 ${SRC_BVH_HEADERS}
243                 ${SRC_SVM_HEADERS}
244                 ${SRC_GEOM_HEADERS}
245                 ${SRC_CLOSURE_HEADERS}
246                 ${SRC_UTIL_HEADERS}
247         )
248         set(cuda_cubins)
249
250         macro(CYCLES_CUDA_KERNEL_ADD arch split experimental)
251                 if(${split})
252                         set(cuda_extra_flags "-D__SPLIT__")
253                         set(cuda_cubin kernel_split)
254                 else()
255                         set(cuda_extra_flags "")
256                         set(cuda_cubin kernel)
257                 endif()
258
259                 if(${experimental})
260                         set(cuda_extra_flags ${cuda_extra_flags} -D__KERNEL_EXPERIMENTAL__)
261                         set(cuda_cubin ${cuda_cubin}_experimental)
262                 endif()
263
264                 set(cuda_cubin ${cuda_cubin}_${arch}.cubin)
265
266                 if(WITH_CYCLES_DEBUG)
267                         set(cuda_debug_flags "-D__KERNEL_DEBUG__")
268                 else()
269                         set(cuda_debug_flags "")
270                 endif()
271
272                 set(cuda_nvcc_command ${CUDA_NVCC_EXECUTABLE})
273                 set(cuda_nvcc_version ${CUDA_VERSION})
274
275                 set(cuda_version_flags "-D__KERNEL_CUDA_VERSION__=${cuda_nvcc_version}")
276                 set(cuda_math_flags "--use_fast_math")
277
278                 if(split)
279                         set(cuda_kernel_src "/kernels/cuda/kernel_split.cu")
280                 else()
281                         set(cuda_kernel_src "/kernels/cuda/kernel.cu")
282                 endif()
283
284                 add_custom_command(
285                         OUTPUT ${cuda_cubin}
286                         COMMAND ${cuda_nvcc_command}
287                                         -arch=${arch}
288                                         ${CUDA_NVCC_FLAGS}
289                                         -m${CUDA_BITS}
290                                         --cubin ${CMAKE_CURRENT_SOURCE_DIR}${cuda_kernel_src}
291                                         -o ${CMAKE_CURRENT_BINARY_DIR}/${cuda_cubin}
292                                         --ptxas-options="-v"
293                                         ${cuda_arch_flags}
294                                         ${cuda_version_flags}
295                                         ${cuda_math_flags}
296                                         ${cuda_extra_flags}
297                                         ${cuda_debug_flags}
298                                         -I${CMAKE_CURRENT_SOURCE_DIR}/../util
299                                         -I${CMAKE_CURRENT_SOURCE_DIR}/svm
300                                         -DCCL_NAMESPACE_BEGIN=
301                                         -DCCL_NAMESPACE_END=
302                                         -DNVCC
303                         DEPENDS ${cuda_sources})
304
305                 delayed_install("${CMAKE_CURRENT_BINARY_DIR}" "${cuda_cubin}" ${CYCLES_INSTALL_PATH}/lib)
306                 list(APPEND cuda_cubins ${cuda_cubin})
307
308                 unset(cuda_extra_flags)
309                 unset(cuda_debug_flags)
310
311                 unset(cuda_nvcc_command)
312                 unset(cuda_nvcc_version)
313         endmacro()
314
315         foreach(arch ${CYCLES_CUDA_BINARIES_ARCH})
316                 # Compile regular kernel
317                 CYCLES_CUDA_KERNEL_ADD(${arch} FALSE FALSE)
318
319                 if(WITH_CYCLES_CUDA_SPLIT_KERNEL_BINARIES)
320                         # Compile split kernel
321                         CYCLES_CUDA_KERNEL_ADD(${arch} TRUE FALSE)
322                 endif()
323         endforeach()
324
325         add_custom_target(cycles_kernel_cuda ALL DEPENDS ${cuda_cubins})
326 endif()
327
328 # OSL module
329
330 if(WITH_CYCLES_OSL)
331         add_subdirectory(osl)
332         add_subdirectory(shaders)
333 endif()
334
335 # CPU module
336
337 include_directories(${INC})
338 include_directories(SYSTEM ${INC_SYS})
339
340 if(CXX_HAS_SSE)
341         list(APPEND SRC
342                 kernels/cpu/kernel_sse2.cpp
343                 kernels/cpu/kernel_sse3.cpp
344                 kernels/cpu/kernel_sse41.cpp
345                 kernels/cpu/kernel_split_sse2.cpp
346                 kernels/cpu/kernel_split_sse3.cpp
347                 kernels/cpu/kernel_split_sse41.cpp
348         )
349
350         set_source_files_properties(kernels/cpu/kernel_sse2.cpp PROPERTIES COMPILE_FLAGS "${CYCLES_SSE2_KERNEL_FLAGS}")
351         set_source_files_properties(kernels/cpu/kernel_sse3.cpp PROPERTIES COMPILE_FLAGS "${CYCLES_SSE3_KERNEL_FLAGS}")
352         set_source_files_properties(kernels/cpu/kernel_sse41.cpp PROPERTIES COMPILE_FLAGS "${CYCLES_SSE41_KERNEL_FLAGS}")
353         set_source_files_properties(kernels/cpu/kernel_split_sse2.cpp PROPERTIES COMPILE_FLAGS "${CYCLES_SSE2_KERNEL_FLAGS}")
354         set_source_files_properties(kernels/cpu/kernel_split_sse3.cpp PROPERTIES COMPILE_FLAGS "${CYCLES_SSE3_KERNEL_FLAGS}")
355         set_source_files_properties(kernels/cpu/kernel_split_sse41.cpp PROPERTIES COMPILE_FLAGS "${CYCLES_SSE41_KERNEL_FLAGS}")
356 endif()
357
358 if(CXX_HAS_AVX)
359         list(APPEND SRC
360                 kernels/cpu/kernel_avx.cpp
361                 kernels/cpu/kernel_split_avx.cpp
362         )
363         set_source_files_properties(kernels/cpu/kernel_avx.cpp PROPERTIES COMPILE_FLAGS "${CYCLES_AVX_KERNEL_FLAGS}")
364         set_source_files_properties(kernels/cpu/kernel_split_avx.cpp PROPERTIES COMPILE_FLAGS "${CYCLES_AVX_KERNEL_FLAGS}")
365 endif()
366
367 if(CXX_HAS_AVX2)
368         list(APPEND SRC
369                 kernels/cpu/kernel_avx2.cpp
370                 kernels/cpu/kernel_split_avx2.cpp
371         )
372         set_source_files_properties(kernels/cpu/kernel_avx2.cpp PROPERTIES COMPILE_FLAGS "${CYCLES_AVX2_KERNEL_FLAGS}")
373         set_source_files_properties(kernels/cpu/kernel_split_avx2.cpp PROPERTIES COMPILE_FLAGS "${CYCLES_AVX2_KERNEL_FLAGS}")
374 endif()
375
376 add_library(cycles_kernel
377         ${SRC}
378         ${SRC_HEADERS}
379         ${SRC_KERNELS_CPU_HEADERS}
380         ${SRC_KERNELS_CUDA_HEADERS}
381         ${SRC_BVH_HEADERS}
382         ${SRC_CLOSURE_HEADERS}
383         ${SRC_SVM_HEADERS}
384         ${SRC_GEOM_HEADERS}
385         ${SRC_SPLIT_HEADERS}
386 )
387
388 if(WITH_CYCLES_CUDA)
389         add_dependencies(cycles_kernel cycles_kernel_cuda)
390 endif()
391
392 # OpenCL kernel
393
394 #set(KERNEL_PREPROCESSED ${CMAKE_CURRENT_BINARY_DIR}/kernel_preprocessed.cl)
395 #add_custom_command(
396 #       OUTPUT ${KERNEL_PREPROCESSED}
397 #       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}
398 #       DEPENDS ${SRC_KERNEL} ${SRC_UTIL_HEADERS})
399 #add_custom_target(cycles_kernel_preprocess ALL DEPENDS ${KERNEL_PREPROCESSED})
400 #delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "${KERNEL_PREPROCESSED}" ${CYCLES_INSTALL_PATH}/kernel)
401
402 delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "kernels/opencl/kernel.cl" ${CYCLES_INSTALL_PATH}/kernel/kernels/opencl)
403 delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "kernels/opencl/kernel_state_buffer_size.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/cuda/kernel.cu" ${CYCLES_INSTALL_PATH}/kernel/kernels/cuda)
416 delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "kernels/cuda/kernel_split.cu" ${CYCLES_INSTALL_PATH}/kernel/kernels/cuda)
417 delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "${SRC_HEADERS}" ${CYCLES_INSTALL_PATH}/kernel)
418 delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "${SRC_KERNELS_CUDA_HEADERS}" ${CYCLES_INSTALL_PATH}/kernel/kernels/cuda)
419 delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "${SRC_BVH_HEADERS}" ${CYCLES_INSTALL_PATH}/kernel/bvh)
420 delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "${SRC_CLOSURE_HEADERS}" ${CYCLES_INSTALL_PATH}/kernel/closure)
421 delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "${SRC_SVM_HEADERS}" ${CYCLES_INSTALL_PATH}/kernel/svm)
422 delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "${SRC_GEOM_HEADERS}" ${CYCLES_INSTALL_PATH}/kernel/geom)
423 delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "${SRC_UTIL_HEADERS}" ${CYCLES_INSTALL_PATH}/kernel)
424 delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "${SRC_SPLIT_HEADERS}" ${CYCLES_INSTALL_PATH}/kernel/split)
425