Cycles: Code cleanup, spaces around keywords
[blender-staging.git] / intern / cycles / kernel / 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 #include "kernel_compat_cpu.h"
20 #include "kernel.h"
21 #include "kernel_math.h"
22 #include "kernel_types.h"
23 #include "kernel_globals.h"
24 #include "kernel_film.h"
25 #include "kernel_path.h"
26 #include "kernel_bake.h"
27
28 CCL_NAMESPACE_BEGIN
29
30 /* Memory Copy */
31
32 void kernel_const_copy(KernelGlobals *kg, const char *name, void *host, size_t size)
33 {
34         if(strcmp(name, "__data") == 0)
35                 memcpy(&kg->__data, host, size);
36         else
37                 assert(0);
38 }
39
40 void kernel_tex_copy(KernelGlobals *kg, const char *name, device_ptr mem, size_t width, size_t height, size_t depth, InterpolationType interpolation)
41 {
42         if(0) {
43         }
44
45 #define KERNEL_TEX(type, ttype, tname) \
46         else if(strcmp(name, #tname) == 0) { \
47                 kg->tname.data = (type*)mem; \
48                 kg->tname.width = width; \
49         }
50 #define KERNEL_IMAGE_TEX(type, ttype, tname)
51 #include "kernel_textures.h"
52
53         else if(strstr(name, "__tex_image_float")) {
54                 texture_image_float4 *tex = NULL;
55                 int id = atoi(name + strlen("__tex_image_float_"));
56                 int array_index = id;
57
58                 if(array_index >= 0 && array_index < MAX_FLOAT_IMAGES) {
59                         tex = &kg->texture_float_images[array_index];
60                 }
61
62                 if(tex) {
63                         tex->data = (float4*)mem;
64                         tex->dimensions_set(width, height, depth);
65                         tex->interpolation = interpolation;
66                 }
67         }
68         else if(strstr(name, "__tex_image")) {
69                 texture_image_uchar4 *tex = NULL;
70                 int id = atoi(name + strlen("__tex_image_"));
71                 int array_index = id - MAX_FLOAT_IMAGES;
72
73                 if(array_index >= 0 && array_index < MAX_BYTE_IMAGES) {
74                         tex = &kg->texture_byte_images[array_index];
75                 }
76
77                 if(tex) {
78                         tex->data = (uchar4*)mem;
79                         tex->dimensions_set(width, height, depth);
80                         tex->interpolation = interpolation;
81                 }
82         }
83         else
84                 assert(0);
85 }
86
87 /* On x86-64, we can assume SSE2, so avoid the extra kernel and compile this one with SSE2 intrinsics */
88 #if defined(__x86_64__) || defined(_M_X64)
89 #define __KERNEL_SSE2__
90 #endif
91
92 /* quiet unused define warnings */
93 #if defined(__KERNEL_SSE2__)
94         /* do nothing */
95 #endif
96
97 /* Path Tracing */
98
99 void kernel_cpu_path_trace(KernelGlobals *kg, float *buffer, unsigned int *rng_state, int sample, int x, int y, int offset, int stride)
100 {
101 #ifdef __BRANCHED_PATH__
102         if(kernel_data.integrator.branched)
103                 kernel_branched_path_trace(kg, buffer, rng_state, sample, x, y, offset, stride);
104         else
105 #endif
106                 kernel_path_trace(kg, buffer, rng_state, sample, x, y, offset, stride);
107 }
108
109 /* Film */
110
111 void kernel_cpu_convert_to_byte(KernelGlobals *kg, uchar4 *rgba, float *buffer, float sample_scale, int x, int y, int offset, int stride)
112 {
113         kernel_film_convert_to_byte(kg, rgba, buffer, sample_scale, x, y, offset, stride);
114 }
115
116 void kernel_cpu_convert_to_half_float(KernelGlobals *kg, uchar4 *rgba, float *buffer, float sample_scale, int x, int y, int offset, int stride)
117 {
118         kernel_film_convert_to_half_float(kg, rgba, buffer, sample_scale, x, y, offset, stride);
119 }
120
121 /* Shader Evaluation */
122
123 void kernel_cpu_shader(KernelGlobals *kg, uint4 *input, float4 *output, int type, int i, int offset, int sample)
124 {
125         if(type >= SHADER_EVAL_BAKE)
126                 kernel_bake_evaluate(kg, input, output, (ShaderEvalType)type, i, offset, sample);
127         else
128                 kernel_shader_evaluate(kg, input, output, (ShaderEvalType)type, i, sample);
129 }
130
131 CCL_NAMESPACE_END
132