Blender  V2.93
kernel_cpu_impl.h
Go to the documentation of this file.
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 /* Templated common implementation part of all CPU kernels.
18  *
19  * The idea is that particular .cpp files sets needed optimization flags and
20  * simply includes this file without worry of copying actual implementation over.
21  */
22 
23 // clang-format off
25 
26 #ifndef KERNEL_STUB
27 # ifndef __SPLIT_KERNEL__
28 # include "kernel/kernel_math.h"
29 # include "kernel/kernel_types.h"
30 
32 # include "kernel/kernel_globals.h"
33 
34 # include "kernel/kernel_color.h"
36 # include "kernel/kernel_film.h"
37 # include "kernel/kernel_path.h"
39 # include "kernel/kernel_bake.h"
40 # else
42 
66 # endif /* __SPLIT_KERNEL__ */
67 #else
68 # define STUB_ASSERT(arch, name) \
69  assert(!(#name " kernel stub for architecture " #arch " was called!"))
70 
71 # ifdef __SPLIT_KERNEL__
73 # endif /* __SPLIT_KERNEL__ */
74 #endif /* KERNEL_STUB */
75 // clang-format on
76 
78 
79 #ifndef __SPLIT_KERNEL__
80 
81 /* Path Tracing */
82 
84  KernelGlobals *kg, float *buffer, int sample, int x, int y, int offset, int stride)
85 {
86 # ifdef KERNEL_STUB
87  STUB_ASSERT(KERNEL_ARCH, path_trace);
88 # else
89 # ifdef __BRANCHED_PATH__
90  if (kernel_data.integrator.branched) {
91  kernel_branched_path_trace(kg, buffer, sample, x, y, offset, stride);
92  }
93  else
94 # endif
95  {
96  kernel_path_trace(kg, buffer, sample, x, y, offset, stride);
97  }
98 # endif /* KERNEL_STUB */
99 }
100 
101 /* Film */
102 
104  uchar4 *rgba,
105  float *buffer,
106  float sample_scale,
107  int x,
108  int y,
109  int offset,
110  int stride)
111 {
112 # ifdef KERNEL_STUB
113  STUB_ASSERT(KERNEL_ARCH, convert_to_byte);
114 # else
115  kernel_film_convert_to_byte(kg, rgba, buffer, sample_scale, x, y, offset, stride);
116 # endif /* KERNEL_STUB */
117 }
118 
120  uchar4 *rgba,
121  float *buffer,
122  float sample_scale,
123  int x,
124  int y,
125  int offset,
126  int stride)
127 {
128 # ifdef KERNEL_STUB
129  STUB_ASSERT(KERNEL_ARCH, convert_to_half_float);
130 # else
131  kernel_film_convert_to_half_float(kg, rgba, buffer, sample_scale, x, y, offset, stride);
132 # endif /* KERNEL_STUB */
133 }
134 
135 /* Bake */
136 
138  KernelGlobals *kg, float *buffer, int sample, int x, int y, int offset, int stride)
139 {
140 # ifdef KERNEL_STUB
141  STUB_ASSERT(KERNEL_ARCH, bake);
142 # else
143 # ifdef __BAKING__
144  kernel_bake_evaluate(kg, buffer, sample, x, y, offset, stride);
145 # endif
146 # endif /* KERNEL_STUB */
147 }
148 
149 /* Shader Evaluate */
150 
151 void KERNEL_FUNCTION_FULL_NAME(shader)(KernelGlobals *kg,
152  uint4 *input,
153  float4 *output,
154  int type,
155  int filter,
156  int i,
157  int offset,
158  int sample)
159 {
160 # ifdef KERNEL_STUB
161  STUB_ASSERT(KERNEL_ARCH, shader);
162 # else
163  if (type == SHADER_EVAL_DISPLACE) {
164  kernel_displace_evaluate(kg, input, output, i);
165  }
166  else {
168  }
169 # endif /* KERNEL_STUB */
170 }
171 
172 #else /* __SPLIT_KERNEL__ */
173 
174 /* Split Kernel Path Tracing */
175 
176 # ifdef KERNEL_STUB
177 # define DEFINE_SPLIT_KERNEL_FUNCTION(name) \
178  void KERNEL_FUNCTION_FULL_NAME(name)(KernelGlobals * kg, KernelData * /*data*/) \
179  { \
180  STUB_ASSERT(KERNEL_ARCH, name); \
181  }
182 
183 # define DEFINE_SPLIT_KERNEL_FUNCTION_LOCALS(name, type) \
184  void KERNEL_FUNCTION_FULL_NAME(name)(KernelGlobals * kg, KernelData * /*data*/) \
185  { \
186  STUB_ASSERT(KERNEL_ARCH, name); \
187  }
188 # else
189 # define DEFINE_SPLIT_KERNEL_FUNCTION(name) \
190  void KERNEL_FUNCTION_FULL_NAME(name)(KernelGlobals * kg, KernelData * /*data*/) \
191  { \
192  kernel_##name(kg); \
193  }
194 
195 # define DEFINE_SPLIT_KERNEL_FUNCTION_LOCALS(name, type) \
196  void KERNEL_FUNCTION_FULL_NAME(name)(KernelGlobals * kg, KernelData * /*data*/) \
197  { \
198  ccl_local type locals; \
199  kernel_##name(kg, &locals); \
200  }
201 # endif /* KERNEL_STUB */
202 
203 DEFINE_SPLIT_KERNEL_FUNCTION(path_init)
204 DEFINE_SPLIT_KERNEL_FUNCTION(scene_intersect)
205 DEFINE_SPLIT_KERNEL_FUNCTION(lamp_emission)
206 DEFINE_SPLIT_KERNEL_FUNCTION(do_volume)
207 DEFINE_SPLIT_KERNEL_FUNCTION_LOCALS(queue_enqueue, QueueEnqueueLocals)
208 DEFINE_SPLIT_KERNEL_FUNCTION(indirect_background)
209 DEFINE_SPLIT_KERNEL_FUNCTION_LOCALS(shader_setup, uint)
210 DEFINE_SPLIT_KERNEL_FUNCTION_LOCALS(shader_sort, ShaderSortLocals)
211 DEFINE_SPLIT_KERNEL_FUNCTION(shader_eval)
212 DEFINE_SPLIT_KERNEL_FUNCTION_LOCALS(holdout_emission_blurring_pathtermination_ao,
214 DEFINE_SPLIT_KERNEL_FUNCTION(subsurface_scatter)
215 DEFINE_SPLIT_KERNEL_FUNCTION_LOCALS(direct_lighting, uint)
216 DEFINE_SPLIT_KERNEL_FUNCTION(shadow_blocked_ao)
217 DEFINE_SPLIT_KERNEL_FUNCTION(shadow_blocked_dl)
218 DEFINE_SPLIT_KERNEL_FUNCTION_LOCALS(enqueue_inactive, uint)
219 DEFINE_SPLIT_KERNEL_FUNCTION_LOCALS(next_iteration_setup, uint)
220 DEFINE_SPLIT_KERNEL_FUNCTION(indirect_subsurface)
221 DEFINE_SPLIT_KERNEL_FUNCTION_LOCALS(buffer_update, uint)
222 DEFINE_SPLIT_KERNEL_FUNCTION(adaptive_stopping)
223 DEFINE_SPLIT_KERNEL_FUNCTION(adaptive_filter_x)
224 DEFINE_SPLIT_KERNEL_FUNCTION(adaptive_filter_y)
225 DEFINE_SPLIT_KERNEL_FUNCTION(adaptive_adjust_samples)
226 #endif /* __SPLIT_KERNEL__ */
227 
228 #undef KERNEL_STUB
229 #undef STUB_ASSERT
230 #undef KERNEL_ARCH
231 
unsigned int uint
Definition: BLI_sys_types.h:83
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint y
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei stride
#define output
#define KERNEL_FUNCTION_FULL_NAME(name)
Definition: filter.h:30
#define KERNEL_ARCH
Definition: filter.h:47
DO_INLINE void filter(lfVector *V, fmatrix3x3 *S)
ccl_device_intersect bool scene_intersect(KernelGlobals *kg, const Ray *ray, const uint visibility, Intersection *isect)
ccl_device void kernel_background_evaluate(KernelGlobals *kg, ccl_global uint4 *input, ccl_global float4 *output, int i)
Definition: kernel_bake.h:475
CCL_NAMESPACE_BEGIN ccl_device void kernel_displace_evaluate(KernelGlobals *kg, ccl_global uint4 *input, ccl_global float4 *output, int i)
Definition: kernel_bake.h:447
#define kernel_data
#define CCL_NAMESPACE_END
void KERNEL_FUNCTION_FULL_NAME() convert_to_half_float(KernelGlobals *kg, uchar4 *rgba, float *buffer, float sample_scale, int x, int y, int offset, int stride)
void KERNEL_FUNCTION_FULL_NAME() convert_to_byte(KernelGlobals *kg, uchar4 *rgba, float *buffer, float sample_scale, int x, int y, int offset, int stride)
CCL_NAMESPACE_BEGIN void KERNEL_FUNCTION_FULL_NAME() path_trace(KernelGlobals *kg, float *buffer, int sample, int x, int y, int offset, int stride)
void KERNEL_FUNCTION_FULL_NAME() bake(KernelGlobals *kg, float *buffer, int sample, int x, int y, int offset, int stride)
void KERNEL_FUNCTION_FULL_NAME() shader(KernelGlobals *kg, uint4 *input, float4 *output, int type, int filter, int i, int offset, int sample)
ccl_device_noinline_cpu float3 indirect_background(KernelGlobals *kg, ShaderData *emission_sd, ccl_addr_space PathState *state, ccl_global float *buffer, ccl_addr_space Ray *ray)
ccl_device void kernel_film_convert_to_byte(KernelGlobals *kg, ccl_global uchar4 *rgba, ccl_global float *buffer, float sample_scale, int x, int y, int offset, int stride)
Definition: kernel_film.h:90
ccl_device void kernel_film_convert_to_half_float(KernelGlobals *kg, ccl_global uchar4 *rgba, ccl_global float *buffer, float sample_scale, int x, int y, int offset, int stride)
Definition: kernel_film.h:113
ccl_device void kernel_path_trace(KernelGlobals *kg, ccl_global float *buffer, int sample, int x, int y, int offset, int stride)
Definition: kernel_path.h:643
__kernel void ccl_constant KernelData ccl_global void ccl_global char ccl_global int ccl_global char ccl_global unsigned int ccl_global float * buffer
@ SHADER_EVAL_DISPLACE
Definition: kernel_types.h:197
static void sample(SocketReader *reader, int x, int y, float color[4])
void path_init(const string &path, const string &user_path)
Definition: util_path.cpp:338