Cycles: Add an option to build single kernel only which fits current CPU
[blender.git] / intern / cycles / kernel / kernels / cpu / kernel.cpp
1 /*
2  * Copyright 2011-2013 Blender Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 /* CPU kernel entry points */
18
19 /* On x86-64, we can assume SSE2, so avoid the extra kernel and compile this
20  * one with SSE2 intrinsics.
21  */
22 #if defined(__x86_64__) || defined(_M_X64)
23 #  define __KERNEL_SSE2__
24 #endif
25
26 /* When building kernel for native machine detect kernel features from the flags
27  * set by compiler.
28  */
29 #ifdef WITH_KERNEL_NATIVE
30 #  ifdef __SSE2__
31 #    ifndef __KERNEL_SSE2__
32 #      define __KERNEL_SSE2__
33 #    endif
34 #  endif
35 #  ifdef __SSE3__
36 #    define __KERNEL_SSE3__
37 #  endif
38 #  ifdef __SSSE3__
39 #    define __KERNEL_SSSE3__
40 #  endif
41 #  ifdef __SSE4_1__
42 #    define __KERNEL_SSE41__
43 #  endif
44 #  ifdef __AVX__
45 #    define __KERNEL_AVX__
46 #  endif
47 #  ifdef __AVX2__
48 #    define __KERNEL_AVX2__
49 #  endif
50 #endif
51
52 /* quiet unused define warnings */
53 #if defined(__KERNEL_SSE2__)
54     /* do nothing */
55 #endif
56
57 #include "kernel.h"
58 #define KERNEL_ARCH cpu
59 #include "kernel_cpu_impl.h"
60
61 CCL_NAMESPACE_BEGIN
62
63 /* Memory Copy */
64
65 void kernel_const_copy(KernelGlobals *kg, const char *name, void *host, size_t size)
66 {
67         if(strcmp(name, "__data") == 0)
68                 memcpy(&kg->__data, host, size);
69         else
70                 assert(0);
71 }
72
73 void kernel_tex_copy(KernelGlobals *kg,
74                      const char *name,
75                      device_ptr mem,
76                      size_t width,
77                      size_t height,
78                      size_t depth,
79                      InterpolationType interpolation,
80                      ExtensionType extension)
81 {
82         if(0) {
83         }
84
85 #define KERNEL_TEX(type, ttype, tname) \
86         else if(strcmp(name, #tname) == 0) { \
87                 kg->tname.data = (type*)mem; \
88                 kg->tname.width = width; \
89         }
90 #define KERNEL_IMAGE_TEX(type, ttype, tname)
91 #include "kernel_textures.h"
92
93         else if(strstr(name, "__tex_image_float")) {
94                 texture_image_float4 *tex = NULL;
95                 int id = atoi(name + strlen("__tex_image_float_"));
96                 int array_index = id;
97
98                 if(array_index >= 0 && array_index < MAX_FLOAT_IMAGES) {
99                         tex = &kg->texture_float_images[array_index];
100                 }
101
102                 if(tex) {
103                         tex->data = (float4*)mem;
104                         tex->dimensions_set(width, height, depth);
105                         tex->interpolation = interpolation;
106                         tex->extension = extension;
107                 }
108         }
109         else if(strstr(name, "__tex_image")) {
110                 texture_image_uchar4 *tex = NULL;
111                 int id = atoi(name + strlen("__tex_image_"));
112                 int array_index = id - MAX_FLOAT_IMAGES;
113
114                 if(array_index >= 0 && array_index < MAX_BYTE_IMAGES) {
115                         tex = &kg->texture_byte_images[array_index];
116                 }
117
118                 if(tex) {
119                         tex->data = (uchar4*)mem;
120                         tex->dimensions_set(width, height, depth);
121                         tex->interpolation = interpolation;
122                         tex->extension = extension;
123                 }
124         }
125         else
126                 assert(0);
127 }
128
129 CCL_NAMESPACE_END