Cycles: Make all #include statements relative to cycles source directory
[blender.git] / intern / cycles / kernel / kernels / opencl / kernel.cl
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 /* OpenCL kernel entry points - unfinished */
18
19 #include "kernel/kernel_compat_opencl.h"
20 #include "kernel/kernel_math.h"
21 #include "kernel/kernel_types.h"
22 #include "kernel/kernel_globals.h"
23 #include "kernel/kernel_image_opencl.h"
24
25 #include "kernel/kernel_film.h"
26
27 #if defined(__COMPILE_ONLY_MEGAKERNEL__) || !defined(__NO_BAKING__)
28 #  include "kernel/kernel_path.h"
29 #  include "kernel/kernel_path_branched.h"
30 #else  /* __COMPILE_ONLY_MEGAKERNEL__ */
31 /* Include only actually used headers for the case
32  * when path tracing kernels are not needed.
33  */
34 #  include "kernel/kernel_random.h"
35 #  include "kernel/kernel_differential.h"
36 #  include "kernel/kernel_montecarlo.h"
37 #  include "kernel/kernel_projection.h"
38 #  include "kernel/geom/geom.h"
39 #  include "kernel/bvh/bvh.h"
40
41 #  include "kernel/kernel_accumulate.h"
42 #  include "kernel/kernel_camera.h"
43 #  include "kernel/kernel_shader.h"
44 #endif  /* defined(__COMPILE_ONLY_MEGAKERNEL__) || !defined(__NO_BAKING__) */
45
46 #include "kernel/kernel_bake.h"
47
48 #ifdef __COMPILE_ONLY_MEGAKERNEL__
49
50 __kernel void kernel_ocl_path_trace(
51         ccl_constant KernelData *data,
52         ccl_global float *buffer,
53         ccl_global uint *rng_state,
54
55 #define KERNEL_TEX(type, ttype, name) \
56         ccl_global type *name,
57 #include "kernel/kernel_textures.h"
58
59         int sample,
60         int sx, int sy, int sw, int sh, int offset, int stride)
61 {
62         KernelGlobals kglobals, *kg = &kglobals;
63
64         kg->data = data;
65
66 #define KERNEL_TEX(type, ttype, name) \
67         kg->name = name;
68 #include "kernel/kernel_textures.h"
69
70         int x = sx + ccl_global_id(0);
71         int y = sy + ccl_global_id(1);
72
73         if(x < sx + sw && y < sy + sh)
74                 kernel_path_trace(kg, buffer, rng_state, sample, x, y, offset, stride);
75 }
76
77 #else  /* __COMPILE_ONLY_MEGAKERNEL__ */
78
79 __kernel void kernel_ocl_shader(
80         ccl_constant KernelData *data,
81         ccl_global uint4 *input,
82         ccl_global float4 *output,
83         ccl_global float *output_luma,
84
85 #define KERNEL_TEX(type, ttype, name) \
86         ccl_global type *name,
87 #include "kernel/kernel_textures.h"
88
89         int type, int sx, int sw, int offset, int sample)
90 {
91         KernelGlobals kglobals, *kg = &kglobals;
92
93         kg->data = data;
94
95 #define KERNEL_TEX(type, ttype, name) \
96         kg->name = name;
97 #include "kernel/kernel_textures.h"
98
99         int x = sx + ccl_global_id(0);
100
101         if(x < sx + sw) {
102                 kernel_shader_evaluate(kg,
103                                        input,
104                                        output,
105                                        output_luma,
106                                        (ShaderEvalType)type,
107                                        x,
108                                        sample);
109         }
110 }
111
112 __kernel void kernel_ocl_bake(
113         ccl_constant KernelData *data,
114         ccl_global uint4 *input,
115         ccl_global float4 *output,
116
117 #define KERNEL_TEX(type, ttype, name) \
118         ccl_global type *name,
119 #include "kernel/kernel_textures.h"
120
121         int type, int filter, int sx, int sw, int offset, int sample)
122 {
123         KernelGlobals kglobals, *kg = &kglobals;
124
125         kg->data = data;
126
127 #define KERNEL_TEX(type, ttype, name) \
128         kg->name = name;
129 #include "kernel/kernel_textures.h"
130
131         int x = sx + ccl_global_id(0);
132
133         if(x < sx + sw) {
134 #ifdef __NO_BAKING__
135                 output[x] = make_float4(0.0f, 0.0f, 0.0f, 0.0f);
136 #else
137                 kernel_bake_evaluate(kg, input, output, (ShaderEvalType)type, filter, x, offset, sample);
138 #endif
139         }
140 }
141
142 __kernel void kernel_ocl_convert_to_byte(
143         ccl_constant KernelData *data,
144         ccl_global uchar4 *rgba,
145         ccl_global float *buffer,
146
147 #define KERNEL_TEX(type, ttype, name) \
148         ccl_global type *name,
149 #include "kernel/kernel_textures.h"
150
151         float sample_scale,
152         int sx, int sy, int sw, int sh, int offset, int stride)
153 {
154         KernelGlobals kglobals, *kg = &kglobals;
155
156         kg->data = data;
157
158 #define KERNEL_TEX(type, ttype, name) \
159         kg->name = name;
160 #include "kernel/kernel_textures.h"
161
162         int x = sx + ccl_global_id(0);
163         int y = sy + ccl_global_id(1);
164
165         if(x < sx + sw && y < sy + sh)
166                 kernel_film_convert_to_byte(kg, rgba, buffer, sample_scale, x, y, offset, stride);
167 }
168
169 __kernel void kernel_ocl_convert_to_half_float(
170         ccl_constant KernelData *data,
171         ccl_global uchar4 *rgba,
172         ccl_global float *buffer,
173
174 #define KERNEL_TEX(type, ttype, name) \
175         ccl_global type *name,
176 #include "kernel/kernel_textures.h"
177
178         float sample_scale,
179         int sx, int sy, int sw, int sh, int offset, int stride)
180 {
181         KernelGlobals kglobals, *kg = &kglobals;
182
183         kg->data = data;
184
185 #define KERNEL_TEX(type, ttype, name) \
186         kg->name = name;
187 #include "kernel/kernel_textures.h"
188
189         int x = sx + ccl_global_id(0);
190         int y = sy + ccl_global_id(1);
191
192         if(x < sx + sw && y < sy + sh)
193                 kernel_film_convert_to_half_float(kg, rgba, buffer, sample_scale, x, y, offset, stride);
194 }
195
196 __kernel void kernel_ocl_zero_buffer(ccl_global float4 *buffer, ulong size, ulong offset)
197 {
198         size_t i = ccl_global_id(0) + ccl_global_id(1) * ccl_global_size(0);
199
200         if(i < size / sizeof(float4)) {
201                 buffer[i+offset/sizeof(float4)] = make_float4(0.0f, 0.0f, 0.0f, 0.0f);
202         }
203         else if(i == size / sizeof(float4)) {
204                 ccl_global uchar *b = (ccl_global uchar*)&buffer[i+offset/sizeof(float4)];
205
206                 for(i = 0; i < size % sizeof(float4); i++) {
207                         *(b++) = 0;
208                 }
209         }
210 }
211
212 #endif  /* __COMPILE_ONLY_MEGAKERNEL__ */