643eefcdc6c9f030eab42b05c67382758a735cf4
[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 one with SSE2 intrinsics */
20 #if defined(__x86_64__) || defined(_M_X64)
21 #  define __KERNEL_SSE2__
22 #endif
23
24 /* quiet unused define warnings */
25 #if defined(__KERNEL_SSE2__)
26     /* do nothing */
27 #endif
28
29 #include "kernel.h"
30 #define KERNEL_ARCH cpu
31 #include "kernel_cpu_impl.h"
32
33 CCL_NAMESPACE_BEGIN
34
35 /* Memory Copy */
36
37 void kernel_const_copy(KernelGlobals *kg, const char *name, void *host, size_t size)
38 {
39         if(strcmp(name, "__data") == 0)
40                 memcpy(&kg->__data, host, size);
41         else
42                 assert(0);
43 }
44
45 void kernel_tex_copy(KernelGlobals *kg,
46                      const char *name,
47                      device_ptr mem,
48                      size_t width,
49                      size_t height,
50                      size_t depth,
51                      InterpolationType interpolation,
52                      ExtensionType extension)
53 {
54         if(0) {
55         }
56
57 #define KERNEL_TEX(type, ttype, tname) \
58         else if(strcmp(name, #tname) == 0) { \
59                 kg->tname.data = (type*)mem; \
60                 kg->tname.width = width; \
61         }
62 #define KERNEL_IMAGE_TEX(type, ttype, tname)
63 #include "kernel_textures.h"
64
65         else if(strstr(name, "__tex_image_float")) {
66                 texture_image_float4 *tex = NULL;
67                 int id = atoi(name + strlen("__tex_image_float_"));
68                 int array_index = id;
69
70                 if(array_index >= 0 && array_index < MAX_FLOAT_IMAGES) {
71                         tex = &kg->texture_float_images[array_index];
72                 }
73
74                 if(tex) {
75                         tex->data = (float4*)mem;
76                         tex->dimensions_set(width, height, depth);
77                         tex->interpolation = interpolation;
78                         tex->extension = extension;
79                 }
80         }
81         else if(strstr(name, "__tex_image")) {
82                 texture_image_uchar4 *tex = NULL;
83                 int id = atoi(name + strlen("__tex_image_"));
84                 int array_index = id - MAX_FLOAT_IMAGES;
85
86                 if(array_index >= 0 && array_index < MAX_BYTE_IMAGES) {
87                         tex = &kg->texture_byte_images[array_index];
88                 }
89
90                 if(tex) {
91                         tex->data = (uchar4*)mem;
92                         tex->dimensions_set(width, height, depth);
93                         tex->interpolation = interpolation;
94                         tex->extension = extension;
95                 }
96         }
97         else
98                 assert(0);
99 }
100
101 CCL_NAMESPACE_END