184aaecc9017fe4e2cecbbeab94fd6dda320c10d
[blender.git] / intern / cycles / kernel / CMakeLists.txt
1
2 set(INC
3         .
4         ../util
5         osl
6         svm
7 )
8
9 set(INC_SYS
10
11 )
12
13 set(SRC
14         kernel.cpp
15         kernel_sse2.cpp
16         kernel_sse3.cpp
17         kernel.cl
18         kernel.cu
19 )
20
21 set(SRC_HEADERS
22         kernel.h
23         kernel_accumulate.h
24         kernel_bvh.h
25         kernel_bvh_traversal.h
26         kernel_camera.h
27         kernel_compat_cpu.h
28         kernel_compat_cuda.h
29         kernel_compat_opencl.h
30         kernel_curve.h
31         kernel_differential.h
32         kernel_displace.h
33         kernel_emission.h
34         kernel_film.h
35         kernel_globals.h
36         kernel_jitter.h
37         kernel_light.h
38         kernel_math.h
39         kernel_montecarlo.h
40         kernel_object.h
41         kernel_passes.h
42         kernel_path.h
43         kernel_primitive.h
44         kernel_projection.h
45         kernel_random.h
46         kernel_shader.h
47         kernel_subsurface.h
48         kernel_textures.h
49         kernel_triangle.h
50         kernel_types.h
51 )
52
53 set(SRC_CLOSURE_HEADERS
54         closure/bsdf.h
55         closure/bsdf_ashikhmin_velvet.h
56         closure/bsdf_diffuse.h
57         closure/bsdf_diffuse_ramp.h
58         closure/bsdf_microfacet.h
59         closure/bsdf_oren_nayar.h
60         closure/bsdf_phong_ramp.h
61         closure/bsdf_reflection.h
62         closure/bsdf_refraction.h
63         closure/bsdf_toon.h
64         closure/bsdf_transparent.h
65         closure/bsdf_util.h
66         closure/bsdf_ward.h
67         closure/bsdf_westin.h
68         closure/bssrdf.h
69         closure/emissive.h
70         closure/volume.h
71 )
72 set(SRC_SVM_HEADERS
73         svm/svm.h
74         svm/svm_attribute.h
75         svm/svm_blackbody.h
76         svm/svm_camera.h
77         svm/svm_closure.h
78         svm/svm_convert.h
79         svm/svm_checker.h
80         svm/svm_brick.h
81         svm/svm_displace.h
82         svm/svm_fresnel.h
83         svm/svm_wireframe.h
84         svm/svm_wavelength.h
85         svm/svm_gamma.h
86         svm/svm_brightness.h
87         svm/svm_geometry.h
88         svm/svm_gradient.h
89         svm/svm_hsv.h
90         svm/svm_image.h
91         svm/svm_invert.h
92         svm/svm_light_path.h
93         svm/svm_magic.h
94         svm/svm_mapping.h
95         svm/svm_math.h
96         svm/svm_mix.h
97         svm/svm_musgrave.h
98         svm/svm_noise.h
99         svm/svm_noisetex.h
100         svm/svm_normal.h
101         svm/svm_ramp.h
102         svm/svm_sepcomb_rgb.h
103         svm/svm_sky.h
104         svm/svm_tex_coord.h
105         svm/svm_texture.h
106         svm/svm_types.h
107         svm/svm_value.h
108         svm/svm_vector_transform.h
109         svm/svm_voronoi.h
110         svm/svm_wave.h
111 )
112
113 set(SRC_UTIL_HEADERS
114         ../util/util_color.h
115         ../util/util_math.h
116         ../util/util_transform.h
117         ../util/util_types.h
118 )
119 # CUDA module
120
121 if(WITH_CYCLES_CUDA_BINARIES)
122         # 32 bit or 64 bit
123         if("${CMAKE_SIZEOF_VOID_P}" EQUAL "8")
124                 set(CUDA_BITS 64)
125         else()
126                 set(CUDA_BITS 32)
127         endif()
128
129         # CUDA version
130         execute_process (COMMAND ${CUDA_NVCC_EXECUTABLE} "--version" OUTPUT_VARIABLE NVCC_OUT)
131         string(REGEX REPLACE ".*release ([0-9]+)\\.([0-9]+).*" "\\1" CUDA_VERSION_MAJOR ${NVCC_OUT})
132         string(REGEX REPLACE ".*release ([0-9]+)\\.([0-9]+).*" "\\2" CUDA_VERSION_MINOR ${NVCC_OUT})
133         set(CUDA_VERSION "${CUDA_VERSION_MAJOR}${CUDA_VERSION_MINOR}")
134
135         # warn for other versions
136         if(CUDA_VERSION MATCHES "50")
137         else()
138                 message(WARNING "CUDA version ${CUDA_VERSION_MAJOR}.${CUDA_VERSION_MINOR} detected, build may succeed but only CUDA 5.0 is officially supported")
139         endif()
140
141         # build for each arch
142         set(cuda_sources kernel.cu ${SRC_HEADERS} ${SRC_SVM_HEADERS} ${SRC_CLOSURE_HEADERS} ${SRC_UTIL_HEADERS})
143         set(cuda_cubins)
144
145         foreach(arch ${CYCLES_CUDA_BINARIES_ARCH})
146                 set(cuda_cubin kernel_${arch}.cubin)
147
148                 set(cuda_version_flags "-D__KERNEL_CUDA_VERSION__=${CUDA_VERSION}")
149
150                 # build flags depending on CUDA version and arch
151                 if(CUDA_VERSION LESS 50)
152                         # CUDA 4.x
153                         if(${arch} MATCHES "sm_1[0-9]")
154                                 # sm_1x
155                                 set(cuda_arch_flags "--maxrregcount=24 --opencc-options -OPT:Olimit=0")
156                         elseif(${arch} MATCHES "sm_2[0-9]")
157                                 # sm_2x
158                                 set(cuda_arch_flags "--maxrregcount=24")
159                         else()
160                                 # sm_3x
161                                 set(cuda_arch_flags "--maxrregcount=32")
162                         endif()
163
164                         set(cuda_math_flags "")
165                 else()
166                         # CUDA 5.x
167                         if(${arch} MATCHES "sm_1[0-9]")
168                                 # sm_1x
169                                 set(cuda_arch_flags "--maxrregcount=24 --opencc-options -OPT:Olimit=0")
170                         elseif(${arch} MATCHES "sm_2[0-9]")
171                                 # sm_2x
172                                 set(cuda_arch_flags "--maxrregcount=32")
173                         else()
174                                 # sm_3x
175                                 set(cuda_arch_flags "--maxrregcount=32")
176                         endif()
177
178                         set(cuda_math_flags "--use_fast_math")
179                 endif()
180                 
181                 if(CUDA_VERSION LESS 50 AND ${arch} MATCHES "sm_35")
182                         message(WARNING "Can't build kernel for CUDA sm_35 architecture, skipping")
183                 else()
184                         add_custom_command(
185                                 OUTPUT ${cuda_cubin}
186                                 COMMAND ${CUDA_NVCC_EXECUTABLE} -arch=${arch} -m${CUDA_BITS} --cubin ${CMAKE_CURRENT_SOURCE_DIR}/kernel.cu -o ${CMAKE_CURRENT_BINARY_DIR}/${cuda_cubin} --ptxas-options="-v" ${cuda_arch_flags} ${cuda_version_flags} ${cuda_math_flags} -I${CMAKE_CURRENT_SOURCE_DIR}/../util -I${CMAKE_CURRENT_SOURCE_DIR}/svm -DCCL_NAMESPACE_BEGIN= -DCCL_NAMESPACE_END= -DNVCC
187                                 DEPENDS ${cuda_sources})
188
189                         delayed_install("${CMAKE_CURRENT_BINARY_DIR}" "${cuda_cubin}" ${CYCLES_INSTALL_PATH}/lib)
190                         list(APPEND cuda_cubins ${cuda_cubin})
191                 endif()
192         endforeach()
193
194         add_custom_target(cycles_kernel_cuda ALL DEPENDS ${cuda_cubins})
195 endif()
196
197 # OSL module
198
199 if(WITH_CYCLES_OSL)
200         add_subdirectory(osl)
201         add_subdirectory(shaders)
202 endif()
203
204 # CPU module
205
206 include_directories(${INC})
207 include_directories(SYSTEM ${INC_SYS})
208
209 add_library(cycles_kernel ${SRC} ${SRC_HEADERS} ${SRC_CLOSURE_HEADERS} ${SRC_SVM_HEADERS})
210
211 if(WITH_CYCLES_OPTIMIZED_KERNEL)
212         set_source_files_properties(kernel_sse2.cpp PROPERTIES COMPILE_FLAGS "${CYCLES_SSE2_KERNEL_FLAGS}")
213         set_source_files_properties(kernel_sse3.cpp PROPERTIES COMPILE_FLAGS "${CYCLES_SSE3_KERNEL_FLAGS}")
214 endif()
215
216 if(WITH_CYCLES_CUDA)
217         add_dependencies(cycles_kernel cycles_kernel_cuda)
218 endif()
219
220 # OpenCL kernel
221
222 #set(KERNEL_PREPROCESSED ${CMAKE_CURRENT_BINARY_DIR}/kernel_preprocessed.cl)
223 #add_custom_command(
224 #       OUTPUT ${KERNEL_PREPROCESSED}
225 #       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}
226 #       DEPENDS ${SRC_KERNEL} ${SRC_UTIL_HEADERS})
227 #add_custom_target(cycles_kernel_preprocess ALL DEPENDS ${KERNEL_PREPROCESSED})
228 #delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "${KERNEL_PREPROCESSED}" ${CYCLES_INSTALL_PATH}/kernel)
229
230 delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "kernel.cl" ${CYCLES_INSTALL_PATH}/kernel)
231 delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "kernel.cu" ${CYCLES_INSTALL_PATH}/kernel)
232 delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "${SRC_HEADERS}" ${CYCLES_INSTALL_PATH}/kernel)
233 delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "${SRC_CLOSURE_HEADERS}" ${CYCLES_INSTALL_PATH}/kernel/closure)
234 delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "${SRC_SVM_HEADERS}" ${CYCLES_INSTALL_PATH}/kernel/svm)
235 delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "${SRC_UTIL_HEADERS}" ${CYCLES_INSTALL_PATH}/kernel)
236