ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/OpenCL/OpenCL.xs
(Generate patch)

Comparing OpenCL/OpenCL.xs (file contents):
Revision 1.29 by root, Thu Apr 19 13:51:36 2012 UTC vs.
Revision 1.40 by root, Sat Apr 21 19:49:40 2012 UTC

1#include "EXTERN.h" 1#include "EXTERN.h"
2#include "perl.h" 2#include "perl.h"
3#include "XSUB.h" 3#include "XSUB.h"
4
5#ifdef I_DLFCN
6 #include <dlfcn.h>
7#endif
8
9// how stupid is that, the 1.2 header files define CL_VERSION_1_1,
10// but then fail to define the api functions unless you ALSO define
11// this. This breaks 100% of the opencl 1.1 apps, for what reason?
12// after all, the functions are deprecated, not removed.
13// in addition, you cannot test for this in any future-proof way.
14// each time a new opencl version comes out, you need to make a new
15// release.
16#define CL_USE_DEPRECATED_OPENCL_1_1_APIS
17#define CL_USE_DEPRECATED_OPENCL_1_2_APIS /* just guessing, you stupid idiots */
4 18
5#ifdef __APPLE__ 19#ifdef __APPLE__
6 #include <OpenCL/opencl.h> 20 #include <OpenCL/opencl.h>
7#else 21#else
8 #include <CL/opencl.h> 22 #include <CL/opencl.h>
23#endif
24
25#if 0 // testing
26#undef CL_USE_DEPRECATED_OPENCL_1_1_APIS
27#undef CL_VERSION_1_2
9#endif 28#endif
10 29
11typedef cl_platform_id OpenCL__Platform; 30typedef cl_platform_id OpenCL__Platform;
12typedef cl_device_id OpenCL__Device; 31typedef cl_device_id OpenCL__Device;
13typedef cl_context OpenCL__Context; 32typedef cl_context OpenCL__Context;
31 50
32typedef SV *FUTURE; 51typedef SV *FUTURE;
33 52
34/*****************************************************************************/ 53/*****************************************************************************/
35 54
55// name must include a leading underscore
56// all of this horrors would be unneceesary if somebody wrote a proper OpenGL module
57// for perl. doh.
58static void *
59glsym (const char *name)
60{
61 void *fun = 0;
62
63 #if defined I_DLFCN && defined RTLD_DEFAULT
64 fun = dlsym (RTLD_DEFAULT, name + 1);
65 if (!fun) fun = dlsym (RTLD_DEFAULT, name);
66
67 if (!fun)
68 {
69 static void *libgl;
70 static const char *glso[] = {
71 "libGL.so.1",
72 "libGL.so.3",
73 "libGL.so.4.0",
74 "libGL.so",
75 "/usr/lib/libGL.so",
76 "/usr/X11R6/lib/libGL.1.dylib"
77 };
78 int i;
79
80 for (i = 0; !libgl && i < sizeof (glso) / sizeof (glso [0]); ++i)
81 {
82 libgl = dlopen (glso [i], RTLD_LAZY);
83 if (libgl)
84 break;
85 }
86
87 if (libgl)
88 {
89 fun = dlsym (libgl, name + 1);
90 if (!fun) fun = dlsym (libgl, name);
91 }
92 }
93 #endif
94
95 return fun;
96}
97
98/*****************************************************************************/
99
36/* up to two temporary buffers */ 100/* up to two temporary buffers */
37static void * 101static void *
38tmpbuf (size_t size) 102tmpbuf (size_t size)
39{ 103{
40 enum { buffers = 3 }; 104 enum { buffers = 3 };
41 static int idx; 105 static int idx;
42 static void *buf [buffers]; 106 static void *buf [buffers];
43 static size_t len [buffers]; 107 static size_t len [buffers];
44 108
45 idx = ++idx % buffers; 109 idx = (idx + 1) % buffers;
46 110
47 if (len [idx] < size) 111 if (len [idx] < size)
48 { 112 {
49 free (buf [idx]); 113 free (buf [idx]);
50 len [idx] = ((size + 31) & ~4095) + 4096 - 32; 114 len [idx] = ((size + 31) & ~4095) + 4096 - 32;
158 222
159 for (i = 0; i < len; i += 2) 223 for (i = 0; i < len; i += 2)
160 { 224 {
161 cl_context_properties t = SvIV (*av_fetch (av, i , 0)); 225 cl_context_properties t = SvIV (*av_fetch (av, i , 0));
162 SV *p_sv = *av_fetch (av, i + 1, 0); 226 SV *p_sv = *av_fetch (av, i + 1, 0);
163 cl_context_properties v; 227 cl_context_properties v = SvIV (p_sv); // code below can override
164 228
165 switch (t) 229 switch (t)
166 { 230 {
231 case CL_GLX_DISPLAY_KHR:
232 if (!SvOK (p_sv))
233 {
234 void *func = glsym ("_glXGetCurrentDisplay");
235 if (func)
236 v = (cl_context_properties)((void *(*)(void))func)();
237 }
238 break;
239
240 case CL_GL_CONTEXT_KHR:
241 if (!SvOK (p_sv))
242 {
243 void *func = glsym ("_glXGetCurrentContext");
244 if (func)
245 v = (cl_context_properties)((void *(*)(void))func)();
246 }
247 break;
248
167 default: 249 default:
168 /* unknown property, treat as int */ 250 /* unknown property, treat as int */
169 v = SvIV (p_sv);
170 break; 251 break;
171 } 252 }
172 253
173 *l++ = t; 254 *l++ = t;
174 *l++ = v; 255 *l++ = v;
191 clGetImageInfo (img, CL_IMAGE_ROW_PITCH, sizeof (res), &res, 0); 272 clGetImageInfo (img, CL_IMAGE_ROW_PITCH, sizeof (res), &res, 0);
192 return res; 273 return res;
193} 274}
194 275
195static cl_event * 276static cl_event *
196event_list (SV **items, int count) 277event_list (SV **items, cl_uint *rcount)
197{ 278{
279 cl_uint count = *rcount;
280
198 if (!count) 281 if (!count)
199 return 0; 282 return 0;
200 283
201 cl_event *list = tmpbuf (sizeof (cl_event) * count); 284 cl_event *list = tmpbuf (sizeof (cl_event) * count);
285 int i = 0;
202 286
203 while (count--) 287 do
288 {
289 --count;
290 if (SvOK (items [count]))
204 list [count] = SvPTROBJ ("clEnqueue", "wait_events", items [count], "OpenCL::Event"); 291 list [i++] = SvPTROBJ ("clEnqueue", "wait_events", items [count], "OpenCL::Event");
292 }
293 while (count);
205 294
295 *rcount = i;
296
206 return list; 297 return i ? list : 0;
207} 298}
208 299
209#define EVENT_LIST(items,count) \ 300#define EVENT_LIST(items,count) \
210 cl_uint event_list_count = (count); \ 301 cl_uint event_list_count = (count); \
211 cl_event *event_list_ptr = event_list (&ST (items), event_list_count) 302 cl_event *event_list_ptr = event_list (&ST (items), &event_list_count)
212 303
213#define INFO(class) \ 304#define INFO(class) \
214{ \ 305{ \
215 size_t size; \ 306 size_t size; \
216 NEED_SUCCESS (Get ## class ## Info, (self, name, 0, 0, &size)); \ 307 NEED_SUCCESS (Get ## class ## Info, (self, name, 0, 0, &size)); \
248} 339}
249 340
250cl_int 341cl_int
251errno () 342errno ()
252 CODE: 343 CODE:
253 errno = res; 344 RETVAL = res;
345 OUTPUT:
346 RETVAL
254 347
255const char * 348const char *
256err2str (cl_int err) 349err2str (cl_int err)
257 350
258const char * 351const char *
277context_from_type (cl_context_properties *properties = 0, cl_device_type type = CL_DEVICE_TYPE_DEFAULT, FUTURE notify = 0) 370context_from_type (cl_context_properties *properties = 0, cl_device_type type = CL_DEVICE_TYPE_DEFAULT, FUTURE notify = 0)
278 PPCODE: 371 PPCODE:
279 NEED_SUCCESS_ARG (cl_context ctx, CreateContextFromType, (properties, type, 0, 0, &res)); 372 NEED_SUCCESS_ARG (cl_context ctx, CreateContextFromType, (properties, type, 0, 0, &res));
280 XPUSH_NEW_OBJ ("OpenCL::Context", ctx); 373 XPUSH_NEW_OBJ ("OpenCL::Context", ctx);
281 374
375#if 0
376
282void 377void
283context (cl_context_properties *properties = 0, FUTURE devices, FUTURE notify = 0) 378context (cl_context_properties *properties = 0, FUTURE devices, FUTURE notify = 0)
284 PPCODE: 379 PPCODE:
285 /* der Gipfel der Kunst */ 380 /* der Gipfel der Kunst */
381
382#endif
286 383
287void 384void
288wait_for_events (...) 385wait_for_events (...)
289 CODE: 386 CODE:
290 EVENT_LIST (0, items); 387 EVENT_LIST (0, items);
632 if (!(flags & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR))) 729 if (!(flags & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR)))
633 croak ("OpenCL::Context::buffer_sv: you have to specify use or copy host ptr when buffer data is given, use $context->buffer instead?"); 730 croak ("OpenCL::Context::buffer_sv: you have to specify use or copy host ptr when buffer data is given, use $context->buffer instead?");
634 NEED_SUCCESS_ARG (cl_mem mem, CreateBuffer, (self, flags, len, ptr, &res)); 731 NEED_SUCCESS_ARG (cl_mem mem, CreateBuffer, (self, flags, len, ptr, &res));
635 XPUSH_NEW_OBJ ("OpenCL::BufferObj", mem); 732 XPUSH_NEW_OBJ ("OpenCL::BufferObj", mem);
636 733
734#if !CL_VERSION_1_2 || defined CL_USE_DEPRECATED_OPENCL_1_1_APIS
735
637void 736void
638image2d (OpenCL::Context self, cl_mem_flags flags, cl_channel_order channel_order, cl_channel_type channel_type, size_t width, size_t height, size_t row_pitch = 0, SV *data = &PL_sv_undef) 737image2d (OpenCL::Context self, cl_mem_flags flags, cl_channel_order channel_order, cl_channel_type channel_type, size_t width, size_t height, size_t row_pitch = 0, SV *data = &PL_sv_undef)
639 PPCODE: 738 PPCODE:
640 STRLEN len; 739 STRLEN len;
641 char *ptr = SvOK (data) ? SvPVbyte (data, len) : 0; 740 char *ptr = SvOK (data) ? SvPVbyte (data, len) : 0;
650 char *ptr = SvOK (data) ? SvPVbyte (data, len) : 0; 749 char *ptr = SvOK (data) ? SvPVbyte (data, len) : 0;
651 const cl_image_format format = { channel_order, channel_type }; 750 const cl_image_format format = { channel_order, channel_type };
652 NEED_SUCCESS_ARG (cl_mem mem, CreateImage3D, (self, flags, &format, width, height, depth, row_pitch, slice_pitch, ptr, &res)); 751 NEED_SUCCESS_ARG (cl_mem mem, CreateImage3D, (self, flags, &format, width, height, depth, row_pitch, slice_pitch, ptr, &res));
653 XPUSH_NEW_OBJ ("OpenCL::Image3D", mem); 752 XPUSH_NEW_OBJ ("OpenCL::Image3D", mem);
654 753
754#endif
755
655#if cl_apple_gl_sharing || cl_khr_gl_sharing 756#if cl_apple_gl_sharing || cl_khr_gl_sharing
656 757
657void 758void
658gl_buffer (OpenCL::Context self, cl_mem_flags flags, cl_GLuint bufobj) 759gl_buffer (OpenCL::Context self, cl_mem_flags flags, cl_GLuint bufobj)
659 PPCODE: 760 PPCODE:
660 NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLBuffer, (self, flags, bufobj, &res)); 761 NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLBuffer, (self, flags, bufobj, &res));
661 XPUSH_NEW_OBJ ("OpenCL::BufferObj", mem); 762 XPUSH_NEW_OBJ ("OpenCL::BufferObj", mem);
662 763
663void 764void
765gl_renderbuffer (OpenCL::Context self, cl_mem_flags flags, cl_GLuint renderbuffer)
766 PPCODE:
767 NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLRenderbuffer, (self, flags, renderbuffer, &res));
768 XPUSH_NEW_OBJ ("OpenCL::Image2D", mem);
769
770#if CL_VERSION_1_2
771
772void
773gl_texture (OpenCL::Context self, cl_mem_flags flags, cl_GLenum target, cl_GLint miplevel, cl_GLuint texture)
774 PPCODE:
775 char *klass = "OpenCL::Memory";
776 cl_gl_object_type t;
777 NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLTexture2D, (self, flags, target, miplevel, texture, &res));
778 NEED_SUCCESS (GetGLObjectInfo, (mem, &t, 0));
779 switch (t)
780 {
781 case CL_GL_OBJECT_TEXTURE_BUFFER: klass = "OpenCL::Image1DBuffer"; break;
782 case CL_GL_OBJECT_TEXTURE1D: klass = "OpenCL::Image1D"; break;
783 case CL_GL_OBJECT_TEXTURE1D_ARRAY: klass = "OpenCL::Image2DArray"; break;
784 case CL_GL_OBJECT_TEXTURE2D: klass = "OpenCL::Image2D"; break;
785 case CL_GL_OBJECT_TEXTURE2D_ARRAY: klass = "OpenCL::Image2DArray"; break;
786 case CL_GL_OBJECT_TEXTURE3D: klass = "OpenCL::Image3D"; break;
787 }
788 XPUSH_NEW_OBJ (klass, mem);
789
790#endif
791
792#if !CL_VERSION_1_2 || defined CL_USE_DEPRECATED_OPENCL_1_1_APIS
793
794void
664gl_texture2d (OpenCL::Context self, cl_mem_flags flags, cl_GLenum target, cl_GLint miplevel, cl_GLuint texture) 795gl_texture2d (OpenCL::Context self, cl_mem_flags flags, cl_GLenum target, cl_GLint miplevel, cl_GLuint texture)
665 PPCODE: 796 PPCODE:
666 NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLTexture2D, (self, flags, target, miplevel, texture, &res)); 797 NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLTexture2D, (self, flags, target, miplevel, texture, &res));
667 XPUSH_NEW_OBJ ("OpenCL::Image2D", mem); 798 XPUSH_NEW_OBJ ("OpenCL::Image2D", mem);
668 799
670gl_texture3d (OpenCL::Context self, cl_mem_flags flags, cl_GLenum target, cl_GLint miplevel, cl_GLuint texture) 801gl_texture3d (OpenCL::Context self, cl_mem_flags flags, cl_GLenum target, cl_GLint miplevel, cl_GLuint texture)
671 PPCODE: 802 PPCODE:
672 NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLTexture3D, (self, flags, target, miplevel, texture, &res)); 803 NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLTexture3D, (self, flags, target, miplevel, texture, &res));
673 XPUSH_NEW_OBJ ("OpenCL::Image3D", mem); 804 XPUSH_NEW_OBJ ("OpenCL::Image3D", mem);
674 805
675void 806#endif
676gl_renderbuffer (OpenCL::Context self, cl_mem_flags flags, cl_GLuint renderbuffer)
677 PPCODE:
678 NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLRenderbuffer, (self, flags, renderbuffer, &res));
679 XPUSH_NEW_OBJ ("OpenCL::Image2D", mem);
680 807
681#endif 808#endif
682 809
683void 810void
684supported_image_formats (OpenCL::Context self, cl_mem_flags flags, cl_mem_object_type image_type) 811supported_image_formats (OpenCL::Context self, cl_mem_flags flags, cl_mem_object_type image_type)
789 cl_event ev = 0; 916 cl_event ev = 0;
790 STRLEN len; 917 STRLEN len;
791 char *ptr = SvPVbyte (data, len); 918 char *ptr = SvPVbyte (data, len);
792 EVENT_LIST (5, items - 5); 919 EVENT_LIST (5, items - 5);
793 920
794 NEED_SUCCESS (EnqueueReadBuffer, (self, mem, blocking, offset, len, ptr, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); 921 NEED_SUCCESS (EnqueueWriteBuffer, (self, mem, blocking, offset, len, ptr, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
795 922
796 if (ev) 923 if (ev)
797 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 924 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
798 925
799void 926void
865 size_t min_len = host_row_pitch * host_slice_pitch * region [2]; 992 size_t min_len = host_row_pitch * host_slice_pitch * region [2];
866 993
867 if (len < min_len) 994 if (len < min_len)
868 croak ("clEnqueueWriteImage: data string is shorter than what would be transferred"); 995 croak ("clEnqueueWriteImage: data string is shorter than what would be transferred");
869 996
870 NEED_SUCCESS (EnqueueWriteBufferRect, (self, buf, blocking, buf_origin, host_origin, region, buf_row_pitch, buf_slice_pitch, host_row_pitch, host_slice_pitch, SvPVX (data), event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); 997 NEED_SUCCESS (EnqueueWriteBufferRect, (self, buf, blocking, buf_origin, host_origin, region, buf_row_pitch, buf_slice_pitch, host_row_pitch, host_slice_pitch, ptr, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
871 998
872 if (ev) 999 if (ev)
873 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 1000 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
874 1001
875void 1002void
930 size_t min_len = slice_pitch ? slice_pitch * depth : row_pitch * height; 1057 size_t min_len = slice_pitch ? slice_pitch * depth : row_pitch * height;
931 1058
932 if (len < min_len) 1059 if (len < min_len)
933 croak ("clEnqueueWriteImage: data string is shorter than what would be transferred"); 1060 croak ("clEnqueueWriteImage: data string is shorter than what would be transferred");
934 1061
935 NEED_SUCCESS (EnqueueWriteImage, (self, dst, blocking, dst_origin, region, row_pitch, slice_pitch, SvPVX (data), event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); 1062 NEED_SUCCESS (EnqueueWriteImage, (self, dst, blocking, dst_origin, region, row_pitch, slice_pitch, ptr, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
936 1063
937 if (ev) 1064 if (ev)
938 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 1065 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
939 1066
940void 1067void
1022 gwo [i] = SvIV (AvARRAY (SvRV (global_work_offset))[i]); 1149 gwo [i] = SvIV (AvARRAY (SvRV (global_work_offset))[i]);
1023 } 1150 }
1024 1151
1025 if (SvOK (local_work_size)) 1152 if (SvOK (local_work_size))
1026 { 1153 {
1027 if (SvOK (local_work_size) && !SvROK (local_work_size) || SvTYPE (SvRV (local_work_size)) != SVt_PVAV) 1154 if ((SvOK (local_work_size) && !SvROK (local_work_size)) || SvTYPE (SvRV (local_work_size)) != SVt_PVAV)
1028 croak ("clEnqueueNDRangeKernel: global_work_size must be undef or an array reference"); 1155 croak ("clEnqueueNDRangeKernel: global_work_size must be undef or an array reference");
1029 1156
1030 if (AvFILLp (SvRV (local_work_size)) + 1 != gws_len) 1157 if (AvFILLp (SvRV (local_work_size)) + 1 != gws_len)
1031 croak ("clEnqueueNDRangeKernel: local_work_local must be undef or an array of same size as global_work_size"); 1158 croak ("clEnqueueNDRangeKernel: local_work_local must be undef or an array of same size as global_work_size");
1032 1159
1044 1171
1045void 1172void
1046enqueue_acquire_gl_objects (OpenCL::Queue self, SV *objects, ...) 1173enqueue_acquire_gl_objects (OpenCL::Queue self, SV *objects, ...)
1047 ALIAS: 1174 ALIAS:
1048 enqueue_release_gl_objects = 1 1175 enqueue_release_gl_objects = 1
1049 CODE: 1176 PPCODE:
1050 if (!SvROK (objects) || SvTYPE (SvRV (objects)) != SVt_PVAV) 1177 if (!SvROK (objects) || SvTYPE (SvRV (objects)) != SVt_PVAV)
1051 croak ("OpenCL::Queue::enqueue_acquire/release_gl_objects argument 'objects' must be an arrayref with memory objects, in call"); 1178 croak ("OpenCL::Queue::enqueue_acquire/release_gl_objects argument 'objects' must be an arrayref with memory objects, in call");
1052 1179
1053 cl_event ev = 0; 1180 cl_event ev = 0;
1054 EVENT_LIST (2, items - 2); 1181 EVENT_LIST (2, items - 2);
1068 if (ev) 1195 if (ev)
1069 XPUSH_NEW_OBJ ("OpenCL::Event", ev); 1196 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
1070 1197
1071#endif 1198#endif
1072 1199
1073void 1200#if !CL_VERSION_1_2 || defined CL_USE_DEPRECATED_OPENCL_1_1_APIS
1074enqueue_marker (OpenCL::Queue self)
1075 PPCODE:
1076 cl_event ev;
1077 NEED_SUCCESS (EnqueueMarker, (self, &ev));
1078 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
1079 1201
1080void 1202void
1081enqueue_wait_for_events (OpenCL::Queue self, ...) 1203enqueue_wait_for_events (OpenCL::Queue self, ...)
1082 CODE: 1204 CODE:
1083 EVENT_LIST (1, items - 1); 1205 EVENT_LIST (1, items - 1);
1084 NEED_SUCCESS (EnqueueWaitForEvents, (self, event_list_count, event_list_ptr)); 1206 NEED_SUCCESS (EnqueueWaitForEvents, (self, event_list_count, event_list_ptr));
1085 1207
1208#endif
1209
1086void 1210void
1211enqueue_marker (OpenCL::Queue self, ...)
1212 PPCODE:
1213 cl_event ev = 0;
1214 EVENT_LIST (1, items - 1);
1215#if CL_VERSION_1_2
1216 NEED_SUCCESS (EnqueueMarkerWithWaitList, (self, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0));
1217#else
1218 if (event_list_count)
1219 croak ("OpenCL::Queue->enqueue_marker does not support a wait list in OpenCL 1.1 - upgrade to 1.2");
1220 NEED_SUCCESS (EnqueueMarker, (self, GIMME_V != G_VOID ? &ev : 0));
1221#endif
1222 if (ev)
1223 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
1224
1225void
1087enqueue_barrier (OpenCL::Queue self) 1226enqueue_barrier (OpenCL::Queue self, ...)
1088 CODE: 1227 PPCODE:
1228 cl_event ev = 0;
1229 EVENT_LIST (1, items - 1);
1230#if CL_VERSION_1_2
1231 NEED_SUCCESS (EnqueueBarrierWithWaitList, (self, event_list_count, event_list_ptr, &ev));
1232#else
1233 if (event_list_count)
1234 croak ("OpenCL::Queue->enqueue_barrier does not support a wait list in OpenCL 1.1 - upgrade to 1.2");
1235 if (GIMME_V != G_VOID)
1236 croak ("OpenCL::Queue->enqueue_barrier does not return an event object in OpenCL 1.1 - upgrade to 1.2");
1089 NEED_SUCCESS (EnqueueBarrier, (self)); 1237 NEED_SUCCESS (EnqueueBarrier, (self));
1238#endif
1239 if (ev)
1240 XPUSH_NEW_OBJ ("OpenCL::Event", ev);
1090 1241
1091void 1242void
1092flush (OpenCL::Queue self) 1243flush (OpenCL::Queue self)
1093 CODE: 1244 CODE:
1094 NEED_SUCCESS (Flush, (self)); 1245 NEED_SUCCESS (Flush, (self));
1244void 1395void
1245gl_object_info (OpenCL::Memory self) 1396gl_object_info (OpenCL::Memory self)
1246 PPCODE: 1397 PPCODE:
1247 cl_gl_object_type type; 1398 cl_gl_object_type type;
1248 cl_GLuint name; 1399 cl_GLuint name;
1249 NEED_SUCCESS (clGetGLObjectInfo, (self, &type, &name)); 1400 NEED_SUCCESS (GetGLObjectInfo, (self, &type, &name));
1250 EXTEND (SP, 2); 1401 EXTEND (SP, 2);
1251 PUSHs (sv_2mortal (newSVuv (type))); 1402 PUSHs (sv_2mortal (newSVuv (type)));
1252 PUSHs (sv_2mortal (newSVuv (name))); 1403 PUSHs (sv_2mortal (newSVuv (name)));
1253 1404
1254#endif 1405#endif
1299 1450
1300void 1451void
1301target (OpenCL::Image self) 1452target (OpenCL::Image self)
1302 PPCODE: 1453 PPCODE:
1303 cl_GLenum value [1]; 1454 cl_GLenum value [1];
1304 NEED_SUCCESS (GetGlTextureInfo, (self, CL_GL_TEXTURE_TARGET, sizeof (value), value, 0)); 1455 NEED_SUCCESS (GetGLTextureInfo, (self, CL_GL_TEXTURE_TARGET, sizeof (value), value, 0));
1305 EXTEND (SP, 1); 1456 EXTEND (SP, 1);
1306 const int i = 0; 1457 const int i = 0;
1307 PUSHs (sv_2mortal (newSVuv (value [i]))); 1458 PUSHs (sv_2mortal (newSVuv (value [i])));
1308 1459
1309void 1460void
1310gl_mipmap_level (OpenCL::Image self) 1461gl_mipmap_level (OpenCL::Image self)
1311 PPCODE: 1462 PPCODE:
1312 cl_GLint value [1]; 1463 cl_GLint value [1];
1313 NEED_SUCCESS (GetGlTextureInfo, (self, CL_GL_MIPMAP_LEVEL, sizeof (value), value, 0)); 1464 NEED_SUCCESS (GetGLTextureInfo, (self, CL_GL_MIPMAP_LEVEL, sizeof (value), value, 0));
1314 EXTEND (SP, 1); 1465 EXTEND (SP, 1);
1315 const int i = 0; 1466 const int i = 0;
1316 PUSHs (sv_2mortal (newSViv (value [i]))); 1467 PUSHs (sv_2mortal (newSViv (value [i])));
1317 1468
1318#END:gl_texture 1469#END:gl_texture
1464 { 1615 {
1465 SV *sv = sv_2mortal (newSV (sizes [i])); 1616 SV *sv = sv_2mortal (newSV (sizes [i]));
1466 SvUPGRADE (sv, SVt_PV); 1617 SvUPGRADE (sv, SVt_PV);
1467 SvPOK_only (sv); 1618 SvPOK_only (sv);
1468 SvCUR_set (sv, sizes [i]); 1619 SvCUR_set (sv, sizes [i]);
1469 ptrs [i] = SvPVX (sv); 1620 ptrs [i] = (void *)SvPVX (sv);
1470 PUSHs (sv); 1621 PUSHs (sv);
1471 } 1622 }
1472 1623
1473 NEED_SUCCESS (GetProgramInfo, (self, CL_PROGRAM_BINARIES , sizeof (*ptrs ) * n, ptrs , &size)); 1624 NEED_SUCCESS (GetProgramInfo, (self, CL_PROGRAM_BINARIES , sizeof (*ptrs ) * n, ptrs , &size));
1474 if (size != sizeof (*ptrs) * n) XSRETURN_EMPTY; 1625 if (size != sizeof (*ptrs) * n) XSRETURN_EMPTY;
1624set_sampler (OpenCL::Kernel self, cl_uint idx, OpenCL::Sampler value) 1775set_sampler (OpenCL::Kernel self, cl_uint idx, OpenCL::Sampler value)
1625 CODE: 1776 CODE:
1626 clSetKernelArg (self, idx, sizeof (value), &value); 1777 clSetKernelArg (self, idx, sizeof (value), &value);
1627 1778
1628void 1779void
1780set_local (OpenCL::Kernel self, cl_uint idx, size_t size)
1781 CODE:
1782 clSetKernelArg (self, idx, size, 0);
1783
1784void
1629set_event (OpenCL::Kernel self, cl_uint idx, OpenCL::Event value) 1785set_event (OpenCL::Kernel self, cl_uint idx, OpenCL::Event value)
1630 CODE: 1786 CODE:
1631 clSetKernelArg (self, idx, sizeof (value), &value); 1787 clSetKernelArg (self, idx, sizeof (value), &value);
1632 1788
1633void 1789void

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines