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> |
… | |
… | |
31 | |
45 | |
32 | typedef SV *FUTURE; |
46 | typedef SV *FUTURE; |
33 | |
47 | |
34 | /*****************************************************************************/ |
48 | /*****************************************************************************/ |
35 | |
49 | |
|
|
50 | // name must include a leading underscore |
|
|
51 | // all of this horrors would be unneceesary if somebody wrote a proper OpenGL module |
|
|
52 | // for perl. doh. |
|
|
53 | static void * |
|
|
54 | glsym (const char *name) |
|
|
55 | { |
|
|
56 | void *fun = 0; |
|
|
57 | |
|
|
58 | #if defined I_DLFCN && defined RTLD_DEFAULT |
|
|
59 | fun = dlsym (RTLD_DEFAULT, name + 1); |
|
|
60 | if (!fun) fun = dlsym (RTLD_DEFAULT, name); |
|
|
61 | |
|
|
62 | if (!fun) |
|
|
63 | { |
|
|
64 | static void *libgl; |
|
|
65 | static const char *glso[] = { |
|
|
66 | "libGL.so.1", |
|
|
67 | "libGL.so.3", |
|
|
68 | "libGL.so.4.0", |
|
|
69 | "libGL.so", |
|
|
70 | "/usr/lib/libGL.so", |
|
|
71 | "/usr/X11R6/lib/libGL.1.dylib" |
|
|
72 | }; |
|
|
73 | int i; |
|
|
74 | |
|
|
75 | for (i = 0; !libgl && i < sizeof (glso) / sizeof (glso [0]); ++i) |
|
|
76 | { |
|
|
77 | libgl = dlopen (glso [i], RTLD_LAZY); |
|
|
78 | if (libgl) |
|
|
79 | break; |
|
|
80 | } |
|
|
81 | |
|
|
82 | if (libgl) |
|
|
83 | { |
|
|
84 | fun = dlsym (libgl, name + 1); |
|
|
85 | if (!fun) fun = dlsym (libgl, name); |
|
|
86 | } |
|
|
87 | } |
|
|
88 | #endif |
|
|
89 | |
|
|
90 | return fun; |
|
|
91 | } |
|
|
92 | |
|
|
93 | /*****************************************************************************/ |
|
|
94 | |
36 | /* up to two temporary buffers */ |
95 | /* up to two temporary buffers */ |
37 | static void * |
96 | static void * |
38 | tmpbuf (size_t size) |
97 | tmpbuf (size_t size) |
39 | { |
98 | { |
40 | enum { buffers = 3 }; |
99 | enum { buffers = 3 }; |
41 | static int idx; |
100 | static int idx; |
42 | static void *buf [buffers]; |
101 | static void *buf [buffers]; |
43 | static size_t len [buffers]; |
102 | static size_t len [buffers]; |
44 | |
103 | |
45 | idx = ++idx % buffers; |
104 | idx = (idx + 1) % buffers; |
46 | |
105 | |
47 | if (len [idx] < size) |
106 | if (len [idx] < size) |
48 | { |
107 | { |
49 | free (buf [idx]); |
108 | free (buf [idx]); |
50 | len [idx] = ((size + 31) & ~4095) + 4096 - 32; |
109 | len [idx] = ((size + 31) & ~4095) + 4096 - 32; |
… | |
… | |
144 | return 0; |
203 | return 0; |
145 | |
204 | |
146 | if (SvROK (sv) && SvTYPE (SvRV (sv)) == SVt_PVAV) |
205 | if (SvROK (sv) && SvTYPE (SvRV (sv)) == SVt_PVAV) |
147 | { |
206 | { |
148 | AV *av = (AV *)SvRV (sv); |
207 | AV *av = (AV *)SvRV (sv); |
149 | int i, len = av_len (av); |
208 | int i, len = av_len (av) + 1; |
150 | cl_context_properties *p = tmpbuf (sizeof (cl_context_properties) * (len + extracount + 1)); |
209 | cl_context_properties *p = tmpbuf (sizeof (cl_context_properties) * (len + extracount + 1)); |
151 | cl_context_properties *l = p; |
210 | cl_context_properties *l = p; |
152 | |
211 | |
153 | if (len & 1) |
212 | if (len & 1) |
154 | croak ("%s: %s is not a property list (must be even number of elements)", func, svname); |
213 | croak ("%s: %s is not a property list (must be even number of elements)", func, svname); |
… | |
… | |
156 | while (extracount--) |
215 | while (extracount--) |
157 | *l++ = *extra++; |
216 | *l++ = *extra++; |
158 | |
217 | |
159 | for (i = 0; i < len; i += 2) |
218 | for (i = 0; i < len; i += 2) |
160 | { |
219 | { |
161 | cl_context_properties t = SvIV (*av_fetch (av, i, 0)); |
220 | cl_context_properties t = SvIV (*av_fetch (av, i , 0)); |
162 | cl_context_properties v; |
221 | SV *p_sv = *av_fetch (av, i + 1, 0); |
|
|
222 | cl_context_properties v = SvIV (p_sv); // code below can override |
163 | |
223 | |
164 | switch (t) |
224 | switch (t) |
165 | { |
225 | { |
|
|
226 | case CL_GLX_DISPLAY_KHR: |
|
|
227 | if (!SvOK (p_sv)) |
|
|
228 | { |
|
|
229 | void *func = glsym ("_glXGetCurrentDisplay"); |
|
|
230 | if (func) |
|
|
231 | v = (cl_context_properties)((void *(*)(void))func)(); |
|
|
232 | } |
|
|
233 | break; |
|
|
234 | |
|
|
235 | case CL_GL_CONTEXT_KHR: |
|
|
236 | if (!SvOK (p_sv)) |
|
|
237 | { |
|
|
238 | void *func = glsym ("_glXGetCurrentContext"); |
|
|
239 | if (func) |
|
|
240 | v = (cl_context_properties)((void *(*)(void))func)(); |
|
|
241 | } |
|
|
242 | break; |
|
|
243 | |
166 | default: |
244 | default: |
167 | /* unknown property, treat as int */ |
245 | /* unknown property, treat as int */ |
168 | v = SvIV (*av_fetch (av, i, 0)); |
|
|
169 | break; |
246 | break; |
170 | } |
247 | } |
171 | |
248 | |
172 | *l++ = t; |
249 | *l++ = t; |
173 | *l++ = v; |
250 | *l++ = v; |
… | |
… | |
190 | clGetImageInfo (img, CL_IMAGE_ROW_PITCH, sizeof (res), &res, 0); |
267 | clGetImageInfo (img, CL_IMAGE_ROW_PITCH, sizeof (res), &res, 0); |
191 | return res; |
268 | return res; |
192 | } |
269 | } |
193 | |
270 | |
194 | static cl_event * |
271 | static cl_event * |
195 | event_list (SV **items, int count) |
272 | event_list (SV **items, cl_uint *rcount) |
196 | { |
273 | { |
|
|
274 | cl_uint count = *rcount; |
|
|
275 | |
197 | if (!count) |
276 | if (!count) |
198 | return 0; |
277 | return 0; |
199 | |
278 | |
200 | cl_event *list = tmpbuf (sizeof (cl_event) * count); |
279 | cl_event *list = tmpbuf (sizeof (cl_event) * count); |
|
|
280 | int i = 0; |
201 | |
281 | |
202 | while (count--) |
282 | do |
|
|
283 | { |
|
|
284 | --count; |
|
|
285 | if (SvOK (items [count])) |
203 | list [count] = SvPTROBJ ("clEnqueue", "wait_events", items [count], "OpenCL::Event"); |
286 | list [i++] = SvPTROBJ ("clEnqueue", "wait_events", items [count], "OpenCL::Event"); |
|
|
287 | } |
|
|
288 | while (count); |
204 | |
289 | |
|
|
290 | *rcount = i; |
|
|
291 | |
205 | return list; |
292 | return i ? list : 0; |
206 | } |
293 | } |
207 | |
294 | |
208 | #define EVENT_LIST(items,count) \ |
295 | #define EVENT_LIST(items,count) \ |
209 | cl_uint event_list_count = (count); \ |
296 | cl_uint event_list_count = (count); \ |
210 | cl_event *event_list_ptr = event_list (&ST (items), event_list_count) |
297 | cl_event *event_list_ptr = event_list (&ST (items), &event_list_count) |
211 | |
298 | |
212 | #define INFO(class) \ |
299 | #define INFO(class) \ |
213 | { \ |
300 | { \ |
214 | size_t size; \ |
301 | size_t size; \ |
215 | NEED_SUCCESS (Get ## class ## Info, (self, name, 0, 0, &size)); \ |
302 | NEED_SUCCESS (Get ## class ## Info, (self, name, 0, 0, &size)); \ |
… | |
… | |
247 | } |
334 | } |
248 | |
335 | |
249 | cl_int |
336 | cl_int |
250 | errno () |
337 | errno () |
251 | CODE: |
338 | CODE: |
252 | errno = res; |
339 | RETVAL = res; |
|
|
340 | OUTPUT: |
|
|
341 | RETVAL |
253 | |
342 | |
254 | const char * |
343 | const char * |
255 | err2str (cl_int err) |
344 | err2str (cl_int err) |
256 | |
345 | |
257 | const char * |
346 | const char * |
… | |
… | |
276 | context_from_type (cl_context_properties *properties = 0, cl_device_type type = CL_DEVICE_TYPE_DEFAULT, FUTURE notify = 0) |
365 | context_from_type (cl_context_properties *properties = 0, cl_device_type type = CL_DEVICE_TYPE_DEFAULT, FUTURE notify = 0) |
277 | PPCODE: |
366 | PPCODE: |
278 | NEED_SUCCESS_ARG (cl_context ctx, CreateContextFromType, (properties, type, 0, 0, &res)); |
367 | NEED_SUCCESS_ARG (cl_context ctx, CreateContextFromType, (properties, type, 0, 0, &res)); |
279 | XPUSH_NEW_OBJ ("OpenCL::Context", ctx); |
368 | XPUSH_NEW_OBJ ("OpenCL::Context", ctx); |
280 | |
369 | |
|
|
370 | #if 0 |
|
|
371 | |
281 | void |
372 | void |
282 | context (cl_context_properties *properties = 0, FUTURE devices, FUTURE notify = 0) |
373 | context (cl_context_properties *properties = 0, FUTURE devices, FUTURE notify = 0) |
283 | PPCODE: |
374 | PPCODE: |
284 | /* der Gipfel der Kunst */ |
375 | /* der Gipfel der Kunst */ |
|
|
376 | |
|
|
377 | #endif |
285 | |
378 | |
286 | void |
379 | void |
287 | wait_for_events (...) |
380 | wait_for_events (...) |
288 | CODE: |
381 | CODE: |
289 | EVENT_LIST (0, items); |
382 | EVENT_LIST (0, items); |
… | |
… | |
631 | if (!(flags & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR))) |
724 | if (!(flags & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR))) |
632 | croak ("OpenCL::Context::buffer_sv: you have to specify use or copy host ptr when buffer data is given, use $context->buffer instead?"); |
725 | croak ("OpenCL::Context::buffer_sv: you have to specify use or copy host ptr when buffer data is given, use $context->buffer instead?"); |
633 | NEED_SUCCESS_ARG (cl_mem mem, CreateBuffer, (self, flags, len, ptr, &res)); |
726 | NEED_SUCCESS_ARG (cl_mem mem, CreateBuffer, (self, flags, len, ptr, &res)); |
634 | XPUSH_NEW_OBJ ("OpenCL::BufferObj", mem); |
727 | XPUSH_NEW_OBJ ("OpenCL::BufferObj", mem); |
635 | |
728 | |
|
|
729 | #if !defined CL_VERSION_1_2 || defined CL_USE_DEPRECATED_OPENCL_1_1_APIS |
|
|
730 | |
636 | void |
731 | void |
637 | image2d (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) |
732 | image2d (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) |
638 | PPCODE: |
733 | PPCODE: |
639 | STRLEN len; |
734 | STRLEN len; |
640 | char *ptr = SvOK (data) ? SvPVbyte (data, len) : 0; |
735 | char *ptr = SvOK (data) ? SvPVbyte (data, len) : 0; |
… | |
… | |
649 | char *ptr = SvOK (data) ? SvPVbyte (data, len) : 0; |
744 | char *ptr = SvOK (data) ? SvPVbyte (data, len) : 0; |
650 | const cl_image_format format = { channel_order, channel_type }; |
745 | const cl_image_format format = { channel_order, channel_type }; |
651 | NEED_SUCCESS_ARG (cl_mem mem, CreateImage3D, (self, flags, &format, width, height, depth, row_pitch, slice_pitch, ptr, &res)); |
746 | NEED_SUCCESS_ARG (cl_mem mem, CreateImage3D, (self, flags, &format, width, height, depth, row_pitch, slice_pitch, ptr, &res)); |
652 | XPUSH_NEW_OBJ ("OpenCL::Image3D", mem); |
747 | XPUSH_NEW_OBJ ("OpenCL::Image3D", mem); |
653 | |
748 | |
|
|
749 | #endif |
|
|
750 | |
654 | #if cl_apple_gl_sharing || cl_khr_gl_sharing |
751 | #if cl_apple_gl_sharing || cl_khr_gl_sharing |
655 | |
752 | |
656 | void |
753 | void |
657 | gl_buffer (OpenCL::Context self, cl_mem_flags flags, cl_GLuint bufobj) |
754 | gl_buffer (OpenCL::Context self, cl_mem_flags flags, cl_GLuint bufobj) |
658 | PPCODE: |
755 | PPCODE: |
659 | NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLBuffer, (self, flags, bufobj, &res)); |
756 | NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLBuffer, (self, flags, bufobj, &res)); |
660 | XPUSH_NEW_OBJ ("OpenCL::BufferObj", mem); |
757 | XPUSH_NEW_OBJ ("OpenCL::BufferObj", mem); |
661 | |
758 | |
|
|
759 | #if !defined CL_VERSION_1_2 || defined CL_USE_DEPRECATED_OPENCL_1_1_APIS |
|
|
760 | |
662 | void |
761 | void |
663 | gl_texture2d (OpenCL::Context self, cl_mem_flags flags, cl_GLenum target, cl_GLint miplevel, cl_GLuint texture) |
762 | gl_texture2d (OpenCL::Context self, cl_mem_flags flags, cl_GLenum target, cl_GLint miplevel, cl_GLuint texture) |
664 | PPCODE: |
763 | PPCODE: |
665 | NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLTexture2D, (self, flags, target, miplevel, texture, &res)); |
764 | NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLTexture2D, (self, flags, target, miplevel, texture, &res)); |
666 | XPUSH_NEW_OBJ ("OpenCL::Image2D", mem); |
765 | XPUSH_NEW_OBJ ("OpenCL::Image2D", mem); |
… | |
… | |
668 | void |
767 | void |
669 | gl_texture3d (OpenCL::Context self, cl_mem_flags flags, cl_GLenum target, cl_GLint miplevel, cl_GLuint texture) |
768 | gl_texture3d (OpenCL::Context self, cl_mem_flags flags, cl_GLenum target, cl_GLint miplevel, cl_GLuint texture) |
670 | PPCODE: |
769 | PPCODE: |
671 | NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLTexture3D, (self, flags, target, miplevel, texture, &res)); |
770 | NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLTexture3D, (self, flags, target, miplevel, texture, &res)); |
672 | XPUSH_NEW_OBJ ("OpenCL::Image3D", mem); |
771 | XPUSH_NEW_OBJ ("OpenCL::Image3D", mem); |
|
|
772 | |
|
|
773 | #endif |
673 | |
774 | |
674 | void |
775 | void |
675 | gl_renderbuffer (OpenCL::Context self, cl_mem_flags flags, cl_GLuint renderbuffer) |
776 | gl_renderbuffer (OpenCL::Context self, cl_mem_flags flags, cl_GLuint renderbuffer) |
676 | PPCODE: |
777 | PPCODE: |
677 | NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLRenderbuffer, (self, flags, renderbuffer, &res)); |
778 | NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLRenderbuffer, (self, flags, renderbuffer, &res)); |
… | |
… | |
788 | cl_event ev = 0; |
889 | cl_event ev = 0; |
789 | STRLEN len; |
890 | STRLEN len; |
790 | char *ptr = SvPVbyte (data, len); |
891 | char *ptr = SvPVbyte (data, len); |
791 | EVENT_LIST (5, items - 5); |
892 | EVENT_LIST (5, items - 5); |
792 | |
893 | |
793 | NEED_SUCCESS (EnqueueReadBuffer, (self, mem, blocking, offset, len, ptr, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); |
894 | NEED_SUCCESS (EnqueueWriteBuffer, (self, mem, blocking, offset, len, ptr, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); |
794 | |
895 | |
795 | if (ev) |
896 | if (ev) |
796 | XPUSH_NEW_OBJ ("OpenCL::Event", ev); |
897 | XPUSH_NEW_OBJ ("OpenCL::Event", ev); |
797 | |
898 | |
798 | void |
899 | void |
… | |
… | |
864 | size_t min_len = host_row_pitch * host_slice_pitch * region [2]; |
965 | size_t min_len = host_row_pitch * host_slice_pitch * region [2]; |
865 | |
966 | |
866 | if (len < min_len) |
967 | if (len < min_len) |
867 | croak ("clEnqueueWriteImage: data string is shorter than what would be transferred"); |
968 | croak ("clEnqueueWriteImage: data string is shorter than what would be transferred"); |
868 | |
969 | |
869 | 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)); |
970 | 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)); |
870 | |
971 | |
871 | if (ev) |
972 | if (ev) |
872 | XPUSH_NEW_OBJ ("OpenCL::Event", ev); |
973 | XPUSH_NEW_OBJ ("OpenCL::Event", ev); |
873 | |
974 | |
874 | void |
975 | void |
… | |
… | |
929 | size_t min_len = slice_pitch ? slice_pitch * depth : row_pitch * height; |
1030 | size_t min_len = slice_pitch ? slice_pitch * depth : row_pitch * height; |
930 | |
1031 | |
931 | if (len < min_len) |
1032 | if (len < min_len) |
932 | croak ("clEnqueueWriteImage: data string is shorter than what would be transferred"); |
1033 | croak ("clEnqueueWriteImage: data string is shorter than what would be transferred"); |
933 | |
1034 | |
934 | 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)); |
1035 | 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)); |
935 | |
1036 | |
936 | if (ev) |
1037 | if (ev) |
937 | XPUSH_NEW_OBJ ("OpenCL::Event", ev); |
1038 | XPUSH_NEW_OBJ ("OpenCL::Event", ev); |
938 | |
1039 | |
939 | void |
1040 | void |
… | |
… | |
1021 | gwo [i] = SvIV (AvARRAY (SvRV (global_work_offset))[i]); |
1122 | gwo [i] = SvIV (AvARRAY (SvRV (global_work_offset))[i]); |
1022 | } |
1123 | } |
1023 | |
1124 | |
1024 | if (SvOK (local_work_size)) |
1125 | if (SvOK (local_work_size)) |
1025 | { |
1126 | { |
1026 | if (SvOK (local_work_size) && !SvROK (local_work_size) || SvTYPE (SvRV (local_work_size)) != SVt_PVAV) |
1127 | if ((SvOK (local_work_size) && !SvROK (local_work_size)) || SvTYPE (SvRV (local_work_size)) != SVt_PVAV) |
1027 | croak ("clEnqueueNDRangeKernel: global_work_size must be undef or an array reference"); |
1128 | croak ("clEnqueueNDRangeKernel: global_work_size must be undef or an array reference"); |
1028 | |
1129 | |
1029 | if (AvFILLp (SvRV (local_work_size)) + 1 != gws_len) |
1130 | if (AvFILLp (SvRV (local_work_size)) + 1 != gws_len) |
1030 | croak ("clEnqueueNDRangeKernel: local_work_local must be undef or an array of same size as global_work_size"); |
1131 | croak ("clEnqueueNDRangeKernel: local_work_local must be undef or an array of same size as global_work_size"); |
1031 | |
1132 | |
… | |
… | |
1043 | |
1144 | |
1044 | void |
1145 | void |
1045 | enqueue_acquire_gl_objects (OpenCL::Queue self, SV *objects, ...) |
1146 | enqueue_acquire_gl_objects (OpenCL::Queue self, SV *objects, ...) |
1046 | ALIAS: |
1147 | ALIAS: |
1047 | enqueue_release_gl_objects = 1 |
1148 | enqueue_release_gl_objects = 1 |
1048 | CODE: |
1149 | PPCODE: |
1049 | if (!SvROK (objects) || SvTYPE (SvRV (objects)) != SVt_PVAV) |
1150 | if (!SvROK (objects) || SvTYPE (SvRV (objects)) != SVt_PVAV) |
1050 | croak ("OpenCL::Queue::enqueue_acquire/release_gl_objects argument 'objects' must be an arrayref with memory objects, in call"); |
1151 | croak ("OpenCL::Queue::enqueue_acquire/release_gl_objects argument 'objects' must be an arrayref with memory objects, in call"); |
1051 | |
1152 | |
1052 | cl_event ev = 0; |
1153 | cl_event ev = 0; |
1053 | EVENT_LIST (2, items - 2); |
1154 | EVENT_LIST (2, items - 2); |
… | |
… | |
1067 | if (ev) |
1168 | if (ev) |
1068 | XPUSH_NEW_OBJ ("OpenCL::Event", ev); |
1169 | XPUSH_NEW_OBJ ("OpenCL::Event", ev); |
1069 | |
1170 | |
1070 | #endif |
1171 | #endif |
1071 | |
1172 | |
|
|
1173 | #if !defined CL_VERSION_1_2 || defined CL_USE_DEPRECATED_OPENCL_1_1_APIS |
|
|
1174 | |
1072 | void |
1175 | void |
1073 | enqueue_marker (OpenCL::Queue self) |
1176 | enqueue_marker (OpenCL::Queue self) |
1074 | PPCODE: |
1177 | PPCODE: |
1075 | cl_event ev; |
1178 | cl_event ev; |
1076 | NEED_SUCCESS (EnqueueMarker, (self, &ev)); |
1179 | NEED_SUCCESS (EnqueueMarker, (self, &ev)); |
… | |
… | |
1084 | |
1187 | |
1085 | void |
1188 | void |
1086 | enqueue_barrier (OpenCL::Queue self) |
1189 | enqueue_barrier (OpenCL::Queue self) |
1087 | CODE: |
1190 | CODE: |
1088 | NEED_SUCCESS (EnqueueBarrier, (self)); |
1191 | NEED_SUCCESS (EnqueueBarrier, (self)); |
|
|
1192 | |
|
|
1193 | #endif |
1089 | |
1194 | |
1090 | void |
1195 | void |
1091 | flush (OpenCL::Queue self) |
1196 | flush (OpenCL::Queue self) |
1092 | CODE: |
1197 | CODE: |
1093 | NEED_SUCCESS (Flush, (self)); |
1198 | NEED_SUCCESS (Flush, (self)); |
… | |
… | |
1243 | void |
1348 | void |
1244 | gl_object_info (OpenCL::Memory self) |
1349 | gl_object_info (OpenCL::Memory self) |
1245 | PPCODE: |
1350 | PPCODE: |
1246 | cl_gl_object_type type; |
1351 | cl_gl_object_type type; |
1247 | cl_GLuint name; |
1352 | cl_GLuint name; |
1248 | NEED_SUCCESS (clGetGLObjectInfo, (self, &type, &name)); |
1353 | NEED_SUCCESS (GetGLObjectInfo, (self, &type, &name)); |
1249 | EXTEND (SP, 2); |
1354 | EXTEND (SP, 2); |
1250 | PUSHs (sv_2mortal (newSVuv (type))); |
1355 | PUSHs (sv_2mortal (newSVuv (type))); |
1251 | PUSHs (sv_2mortal (newSVuv (name))); |
1356 | PUSHs (sv_2mortal (newSVuv (name))); |
1252 | |
1357 | |
1253 | #endif |
1358 | #endif |
… | |
… | |
1298 | |
1403 | |
1299 | void |
1404 | void |
1300 | target (OpenCL::Image self) |
1405 | target (OpenCL::Image self) |
1301 | PPCODE: |
1406 | PPCODE: |
1302 | cl_GLenum value [1]; |
1407 | cl_GLenum value [1]; |
1303 | NEED_SUCCESS (GetGlTextureInfo, (self, CL_GL_TEXTURE_TARGET, sizeof (value), value, 0)); |
1408 | NEED_SUCCESS (GetGLTextureInfo, (self, CL_GL_TEXTURE_TARGET, sizeof (value), value, 0)); |
1304 | EXTEND (SP, 1); |
1409 | EXTEND (SP, 1); |
1305 | const int i = 0; |
1410 | const int i = 0; |
1306 | PUSHs (sv_2mortal (newSVuv (value [i]))); |
1411 | PUSHs (sv_2mortal (newSVuv (value [i]))); |
1307 | |
1412 | |
1308 | void |
1413 | void |
1309 | gl_mipmap_level (OpenCL::Image self) |
1414 | gl_mipmap_level (OpenCL::Image self) |
1310 | PPCODE: |
1415 | PPCODE: |
1311 | cl_GLint value [1]; |
1416 | cl_GLint value [1]; |
1312 | NEED_SUCCESS (GetGlTextureInfo, (self, CL_GL_MIPMAP_LEVEL, sizeof (value), value, 0)); |
1417 | NEED_SUCCESS (GetGLTextureInfo, (self, CL_GL_MIPMAP_LEVEL, sizeof (value), value, 0)); |
1313 | EXTEND (SP, 1); |
1418 | EXTEND (SP, 1); |
1314 | const int i = 0; |
1419 | const int i = 0; |
1315 | PUSHs (sv_2mortal (newSViv (value [i]))); |
1420 | PUSHs (sv_2mortal (newSViv (value [i]))); |
1316 | |
1421 | |
1317 | #END:gl_texture |
1422 | #END:gl_texture |
… | |
… | |
1463 | { |
1568 | { |
1464 | SV *sv = sv_2mortal (newSV (sizes [i])); |
1569 | SV *sv = sv_2mortal (newSV (sizes [i])); |
1465 | SvUPGRADE (sv, SVt_PV); |
1570 | SvUPGRADE (sv, SVt_PV); |
1466 | SvPOK_only (sv); |
1571 | SvPOK_only (sv); |
1467 | SvCUR_set (sv, sizes [i]); |
1572 | SvCUR_set (sv, sizes [i]); |
1468 | ptrs [i] = SvPVX (sv); |
1573 | ptrs [i] = (void *)SvPVX (sv); |
1469 | PUSHs (sv); |
1574 | PUSHs (sv); |
1470 | } |
1575 | } |
1471 | |
1576 | |
1472 | NEED_SUCCESS (GetProgramInfo, (self, CL_PROGRAM_BINARIES , sizeof (*ptrs ) * n, ptrs , &size)); |
1577 | NEED_SUCCESS (GetProgramInfo, (self, CL_PROGRAM_BINARIES , sizeof (*ptrs ) * n, ptrs , &size)); |
1473 | if (size != sizeof (*ptrs) * n) XSRETURN_EMPTY; |
1578 | if (size != sizeof (*ptrs) * n) XSRETURN_EMPTY; |
… | |
… | |
1623 | set_sampler (OpenCL::Kernel self, cl_uint idx, OpenCL::Sampler value) |
1728 | set_sampler (OpenCL::Kernel self, cl_uint idx, OpenCL::Sampler value) |
1624 | CODE: |
1729 | CODE: |
1625 | clSetKernelArg (self, idx, sizeof (value), &value); |
1730 | clSetKernelArg (self, idx, sizeof (value), &value); |
1626 | |
1731 | |
1627 | void |
1732 | void |
|
|
1733 | set_local (OpenCL::Kernel self, cl_uint idx, size_t size) |
|
|
1734 | CODE: |
|
|
1735 | clSetKernelArg (self, idx, size, 0); |
|
|
1736 | |
|
|
1737 | void |
1628 | set_event (OpenCL::Kernel self, cl_uint idx, OpenCL::Event value) |
1738 | set_event (OpenCL::Kernel self, cl_uint idx, OpenCL::Event value) |
1629 | CODE: |
1739 | CODE: |
1630 | clSetKernelArg (self, idx, sizeof (value), &value); |
1740 | clSetKernelArg (self, idx, sizeof (value), &value); |
1631 | |
1741 | |
1632 | void |
1742 | void |