35 # define CYCLES_DISABLE_DRIVER_WORKAROUNDS
38 # ifndef CYCLES_DISABLE_DRIVER_WORKAROUNDS
40 # undef clEnqueueNDRangeKernel
41 # define clEnqueueNDRangeKernel(a, b, c, d, e, f, g, h, i) \
42 CLEW_GET_FUN(__clewEnqueueNDRangeKernel)(a, b, c, d, e, f, g, h, i); \
45 # undef clEnqueueWriteBuffer
46 # define clEnqueueWriteBuffer(a, b, c, d, e, f, g, h, i) \
47 CLEW_GET_FUN(__clewEnqueueWriteBuffer)(a, b, c, d, e, f, g, h, i); \
50 # undef clEnqueueReadBuffer
51 # define clEnqueueReadBuffer(a, b, c, d, e, f, g, h, i) \
52 CLEW_GET_FUN(__clewEnqueueReadBuffer)(a, b, c, d, e, f, g, h, i); \
56 # define CL_MEM_PTR(p) ((cl_mem)(uintptr_t)(p))
58 struct OpenCLPlatformDevice {
59 OpenCLPlatformDevice(cl_platform_id platform_id,
60 const string &platform_name,
61 cl_device_id device_id,
62 cl_device_type device_type,
63 const string &device_name,
64 const string &hardware_id,
65 const string &device_extensions)
66 : platform_id(platform_id),
67 platform_name(platform_name),
69 device_type(device_type),
70 device_name(device_name),
71 hardware_id(hardware_id),
72 device_extensions(device_extensions)
75 cl_platform_id platform_id;
77 cl_device_id device_id;
78 cl_device_type device_type;
81 string device_extensions;
87 static cl_device_type device_type();
88 static bool use_debug();
89 static bool device_supported(
const string &platform_name,
const cl_device_id device_id);
90 static bool platform_version_check(cl_platform_id platform,
string *
error =
NULL);
91 static bool device_version_check(cl_device_id device,
string *
error =
NULL);
92 static bool get_device_version(cl_device_id device,
96 static string get_hardware_id(
const string &platform_name, cl_device_id device_id);
102 static bool get_num_platforms(cl_uint *num_platforms, cl_int *
error =
NULL);
103 static cl_uint get_num_platforms();
108 static bool get_platform_name(cl_platform_id platform_id,
string *platform_name);
109 static string get_platform_name(cl_platform_id platform_id);
111 static bool get_num_platform_devices(cl_platform_id platform_id,
112 cl_device_type device_type,
113 cl_uint *num_devices,
115 static cl_uint get_num_platform_devices(cl_platform_id platform_id, cl_device_type device_type);
117 static bool get_platform_devices(cl_platform_id platform_id,
118 cl_device_type device_type,
122 cl_device_type device_type);
125 static bool get_device_name(cl_device_id device_id,
string *device_name, cl_int *
error =
NULL);
127 static string get_device_name(cl_device_id device_id);
129 static bool get_device_extensions(cl_device_id device_id,
130 string *device_extensions,
133 static string get_device_extensions(cl_device_id device_id);
135 static bool get_device_type(cl_device_id device_id,
136 cl_device_type *device_type,
138 static cl_device_type get_device_type(cl_device_id device_id);
140 static bool get_driver_version(cl_device_id device_id,
145 static int mem_sub_ptr_alignment(cl_device_id device_id);
152 static string get_readable_device_name(cl_device_id device_id);
159 struct ProgramEntry {
161 ProgramEntry(
const ProgramEntry &rhs);
168 Slot(
const Slot &rhs);
173 typedef map<ustring, ProgramEntry> EntryMap;
178 typedef pair<cl_platform_id, cl_device_id> PlatformDevicePair;
181 typedef map<PlatformDevicePair, Slot> CacheMap;
191 static OpenCLCache &global_instance();
195 OCL_DEV_BASE_PROGRAM,
196 OCL_DEV_MEGAKERNEL_PROGRAM,
202 static cl_context get_context(cl_platform_id platform,
206 static cl_program get_program(cl_platform_id platform,
212 static void store_context(cl_platform_id platform,
217 static void store_program(cl_platform_id platform,
223 static string get_kernel_md5();
226 # define opencl_device_assert(device, stmt) \
230 if (err != CL_SUCCESS) { \
231 string message = string_printf( \
232 "OpenCL error: %s in %s (%s:%d)", clewErrorString(err), #stmt, __FILE__, __LINE__); \
233 if ((device)->error_message() == "") { \
234 (device)->set_error(message); \
236 fprintf(stderr, "%s\n", message.c_str()); \
241 # define opencl_assert(stmt) \
245 if (err != CL_SUCCESS) { \
246 string message = string_printf( \
247 "OpenCL error: %s in %s (%s:%d)", clewErrorString(err), #stmt, __FILE__, __LINE__); \
248 if (error_msg == "") { \
249 error_msg = message; \
251 fprintf(stderr, "%s\n", message.c_str()); \
256 class OpenCLDevice :
public Device {
261 TaskPool load_required_kernel_task_pool;
264 std::atomic<int> load_kernel_num_compiling;
266 cl_context cxContext;
267 cl_command_queue cqCommandQueue;
268 cl_platform_id cpPlatform;
269 cl_device_id cdDevice;
273 class OpenCLProgram {
275 OpenCLProgram() : loaded(false), needs_compiling(true),
program(
NULL), device(
NULL)
278 OpenCLProgram(OpenCLDevice *device,
279 const string &program_name,
280 const string &kernel_name,
281 const string &kernel_build_options,
282 bool use_stdout =
true);
285 void add_kernel(ustring name);
292 void create_kernels();
294 bool is_loaded()
const
298 const string &get_log()
const
308 bool wait_for_availability();
316 bool build_kernel(
const string *debug_src);
322 bool compile_separate(
const string &clbin);
324 bool compile_kernel(
const string *debug_src);
326 bool load_binary(
const string &clbin,
const string *debug_src =
NULL);
327 bool save_binary(
const string &clbin);
329 void add_log(
const string &msg,
bool is_debug);
330 void add_error(
const string &msg);
333 bool needs_compiling;
336 OpenCLDevice *device;
341 string kernel_file, kernel_build_options, device_md5;
344 string log, error_msg;
345 string compile_output;
347 map<ustring, cl_kernel> kernels;
351 class OpenCLSplitPrograms {
353 OpenCLDevice *device;
354 OpenCLProgram program_split;
355 OpenCLProgram program_lamp_emission;
356 OpenCLProgram program_do_volume;
357 OpenCLProgram program_indirect_background;
358 OpenCLProgram program_shader_eval;
359 OpenCLProgram program_holdout_emission_blurring_pathtermination_ao;
360 OpenCLProgram program_subsurface_scatter;
361 OpenCLProgram program_direct_lighting;
362 OpenCLProgram program_shadow_blocked_ao;
363 OpenCLProgram program_shadow_blocked_dl;
365 OpenCLSplitPrograms(OpenCLDevice *device);
366 ~OpenCLSplitPrograms();
376 OpenCLProgram base_program;
377 OpenCLProgram bake_program;
378 OpenCLProgram displace_program;
379 OpenCLProgram background_program;
380 OpenCLProgram denoising_program;
382 OpenCLSplitPrograms kernel_programs;
384 typedef map<string, device_vector<uchar> *> ConstMemMap;
385 typedef map<string, device_ptr> MemMap;
387 ConstMemMap const_mem_map;
390 bool device_initialized;
391 string platform_name;
394 bool opencl_error(cl_int
err);
395 void opencl_error(
const string &message);
396 void opencl_assert_err(cl_int
err,
const char *where);
401 static void CL_CALLBACK context_notify_callback(
const char *err_info,
406 bool opencl_version_check();
407 OpenCLSplitPrograms *get_split_programs();
409 string device_md5_hash(
string kernel_custom_build_options =
"");
417 const string get_opencl_program_name(
const string &kernel_name);
419 const string get_opencl_program_filename(
const string &kernel_name);
421 const string &opencl_program_name);
431 int mem_sub_ptr_alignment();
433 void const_copy_to(
const char *name,
void *host,
size_t size);
439 size_t global_size_round_up(
int group_size,
int global_size);
440 void enqueue_kernel(cl_kernel kernel,
443 bool x_workgroups =
false,
444 size_t max_workgroup_size = -1);
445 void set_kernel_arg_mem(cl_kernel kernel, cl_uint *narg,
const char *name);
446 void set_kernel_arg_buffers(cl_kernel kernel, cl_uint *narg);
467 thread_run(task_copy);
488 virtual bool show_samples()
const
494 string kernel_build_options(
const string *debug_src =
NULL);
498 bool denoising_non_local_means(
device_ptr image_ptr,
504 bool denoising_accumulate(
device_ptr color_ptr,
510 bool denoising_combine_halves(
device_ptr a_ptr,
517 bool denoising_divide_shadow(
device_ptr a_ptr,
523 bool denoising_get_feature(
int mean_offset,
529 bool denoising_write_feature(
int to_offset,
533 bool denoising_detect_outliers(
device_ptr image_ptr,
542 class ArgumentWrapper {
544 ArgumentWrapper() :
size(0), pointer(
NULL)
549 :
size(sizeof(void *)), pointer((void *)(&argument.device_pointer))
555 :
size(sizeof(void *)), pointer((void *)(&argument.device_pointer))
561 :
size(sizeof(void *)), pointer((void *)(&argument.device_pointer))
564 template<
typename T> ArgumentWrapper(
T &argument) :
size(sizeof(argument)), pointer(&argument)
568 ArgumentWrapper(
int argument) :
size(sizeof(int)), int_value(argument), pointer(&int_value)
572 ArgumentWrapper(
float argument)
573 :
size(sizeof(
float)), float_value(argument), pointer(&float_value)
586 int kernel_set_args(cl_kernel kernel,
587 int start_argument_index,
588 const ArgumentWrapper &arg1 = ArgumentWrapper(),
589 const ArgumentWrapper &arg2 = ArgumentWrapper(),
590 const ArgumentWrapper &arg3 = ArgumentWrapper(),
591 const ArgumentWrapper &arg4 = ArgumentWrapper(),
592 const ArgumentWrapper &arg5 = ArgumentWrapper(),
593 const ArgumentWrapper &arg6 = ArgumentWrapper(),
594 const ArgumentWrapper &arg7 = ArgumentWrapper(),
595 const ArgumentWrapper &arg8 = ArgumentWrapper(),
596 const ArgumentWrapper &arg9 = ArgumentWrapper(),
597 const ArgumentWrapper &arg10 = ArgumentWrapper(),
598 const ArgumentWrapper &arg11 = ArgumentWrapper(),
599 const ArgumentWrapper &arg12 = ArgumentWrapper(),
600 const ArgumentWrapper &arg13 = ArgumentWrapper(),
601 const ArgumentWrapper &arg14 = ArgumentWrapper(),
602 const ArgumentWrapper &arg15 = ArgumentWrapper(),
603 const ArgumentWrapper &arg16 = ArgumentWrapper(),
604 const ArgumentWrapper &arg17 = ArgumentWrapper(),
605 const ArgumentWrapper &arg18 = ArgumentWrapper(),
606 const ArgumentWrapper &arg19 = ArgumentWrapper(),
607 const ArgumentWrapper &arg20 = ArgumentWrapper(),
608 const ArgumentWrapper &arg21 = ArgumentWrapper(),
609 const ArgumentWrapper &arg22 = ArgumentWrapper(),
610 const ArgumentWrapper &arg23 = ArgumentWrapper(),
611 const ArgumentWrapper &arg24 = ArgumentWrapper(),
612 const ArgumentWrapper &arg25 = ArgumentWrapper(),
613 const ArgumentWrapper &arg26 = ArgumentWrapper(),
614 const ArgumentWrapper &arg27 = ArgumentWrapper(),
615 const ArgumentWrapper &arg28 = ArgumentWrapper(),
616 const ArgumentWrapper &arg29 = ArgumentWrapper(),
617 const ArgumentWrapper &arg30 = ArgumentWrapper(),
618 const ArgumentWrapper &arg31 = ArgumentWrapper(),
619 const ArgumentWrapper &arg32 = ArgumentWrapper(),
620 const ArgumentWrapper &arg33 = ArgumentWrapper());
622 void release_kernel_safe(cl_kernel kernel);
623 void release_mem_object_safe(cl_mem mem);
624 void release_program_safe(cl_program
program);
639 typedef map<string, device_memory *> TexturesMap;
642 bool textures_need_update;
645 void flush_texture_buffers();
647 friend class OpenCLSplitKernel;
648 friend class OpenCLSplitKernelFunction;
typedef float(TangentPoint)[2]
_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 const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble w _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat w _GL_VOID_RET _GL_VOID GLint GLint GLint w _GL_VOID_RET _GL_VOID GLshort GLshort GLshort w _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble y2 _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat y2 _GL_VOID_RET _GL_VOID GLint GLint GLint y2 _GL_VOID_RET _GL_VOID GLshort GLshort GLshort y2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLuint *buffer _GL_VOID_RET _GL_VOID GLdouble t _GL_VOID_RET _GL_VOID GLfloat t _GL_VOID_RET _GL_VOID GLint t _GL_VOID_RET _GL_VOID GLshort t _GL_VOID_RET _GL_VOID GLdouble GLdouble r _GL_VOID_RET _GL_VOID GLfloat GLfloat r _GL_VOID_RET _GL_VOID GLint GLint r _GL_VOID_RET _GL_VOID GLshort GLshort r _GL_VOID_RET _GL_VOID GLdouble GLdouble r
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint * textures
_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
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
#define CCL_NAMESPACE_END
void KERNEL_FUNCTION_FULL_NAME() shader(KernelGlobals *kg, uint4 *input, float4 *output, int type, int filter, int i, int offset, int sample)
__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
static void error(const char *str)
int load(istream &in, Vec3r &v)
INLINE Rall1d< T, V, S > log(const Rall1d< T, V, S > &arg)
static void sample(SocketReader *reader, int x, int y, float color[4])
struct blender::compositor::@172::@174 task
static int bake(const BakeAPIRender *bkr, Object *ob_low, const ListBase *selected_objects, ReportList *reports)
struct SELECTID_Context context
void push(TaskRunFunction &&task)
#define static_assert_align(st, align)
std::unique_lock< std::mutex > thread_scoped_lock
CCL_NAMESPACE_BEGIN typedef std::mutex thread_mutex