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 |
4 | |
8 | |
5 | #ifdef __APPLE__ |
9 | #ifdef __APPLE__ |
6 | #include <OpenCL/opencl.h> |
10 | #include <OpenCL/opencl.h> |
7 | #else |
11 | #else |
8 | #include <CL/opencl.h> |
12 | #include <CL/opencl.h> |
… | |
… | |
31 | |
35 | |
32 | typedef SV *FUTURE; |
36 | typedef SV *FUTURE; |
33 | |
37 | |
34 | /*****************************************************************************/ |
38 | /*****************************************************************************/ |
35 | |
39 | |
|
|
40 | // name must include a leading underscore |
|
|
41 | // all of this horrors would be unneceesary if somebody wrote a proper OpenGL module |
|
|
42 | // for perl. doh. |
|
|
43 | static void * |
|
|
44 | glsym (const char *name) |
|
|
45 | { |
|
|
46 | void *fun = 0; |
|
|
47 | |
|
|
48 | #if defined I_DLFCN && defined RTLD_DEFAULT |
|
|
49 | fun = dlsym (RTLD_DEFAULT, name + 1); |
|
|
50 | if (!fun) fun = dlsym (RTLD_DEFAULT, name); |
|
|
51 | |
|
|
52 | if (!fun) |
|
|
53 | { |
|
|
54 | static void *libgl; |
|
|
55 | static const char *glso[] = { |
|
|
56 | "libGL.so.1", |
|
|
57 | "libGL.so.3", |
|
|
58 | "libGL.so.4.0", |
|
|
59 | "libGL.so", |
|
|
60 | "/usr/lib/libGL.so", |
|
|
61 | "/usr/X11R6/lib/libGL.1.dylib" |
|
|
62 | }; |
|
|
63 | int i; |
|
|
64 | |
|
|
65 | for (i = 0; !libgl && i < sizeof (glso) / sizeof (glso [0]); ++i) |
|
|
66 | { |
|
|
67 | libgl = dlopen (glso [i], RTLD_LAZY); |
|
|
68 | if (libgl) |
|
|
69 | break; |
|
|
70 | } |
|
|
71 | |
|
|
72 | if (libgl) |
|
|
73 | { |
|
|
74 | fun = dlsym (libgl, name + 1); |
|
|
75 | if (!fun) fun = dlsym (libgl, name); |
|
|
76 | } |
|
|
77 | } |
|
|
78 | #endif |
|
|
79 | |
|
|
80 | return fun; |
|
|
81 | } |
|
|
82 | |
|
|
83 | /*****************************************************************************/ |
|
|
84 | |
36 | /* up to two temporary buffers */ |
85 | /* up to two temporary buffers */ |
37 | static void * |
86 | static void * |
38 | tmpbuf (size_t size) |
87 | tmpbuf (size_t size) |
39 | { |
88 | { |
|
|
89 | enum { buffers = 3 }; |
40 | static int idx; |
90 | static int idx; |
41 | static void *buf [2]; |
91 | static void *buf [buffers]; |
42 | static size_t len [2]; |
92 | static size_t len [buffers]; |
43 | |
93 | |
44 | idx ^= 1; |
94 | idx = ++idx % buffers; |
45 | |
95 | |
46 | if (len [idx] < size) |
96 | if (len [idx] < size) |
47 | { |
97 | { |
48 | free (buf [idx]); |
98 | free (buf [idx]); |
49 | len [idx] = ((size + 31) & ~4095) + 4096 - 32; |
99 | len [idx] = ((size + 31) & ~4095) + 4096 - 32; |
… | |
… | |
127 | { |
177 | { |
128 | if (SvROK (sv) && sv_derived_from (sv, pkg)) |
178 | if (SvROK (sv) && sv_derived_from (sv, pkg)) |
129 | return (void *)SvIV (SvRV (sv)); |
179 | return (void *)SvIV (SvRV (sv)); |
130 | |
180 | |
131 | croak ("%s: %s is not of type %s", func, svname, pkg); |
181 | croak ("%s: %s is not of type %s", func, svname, pkg); |
|
|
182 | } |
|
|
183 | |
|
|
184 | /*****************************************************************************/ |
|
|
185 | |
|
|
186 | static cl_context_properties * |
|
|
187 | SvCONTEXTPROPERTIES (const char *func, const char *svname, SV *sv, cl_context_properties *extra, int extracount) |
|
|
188 | { |
|
|
189 | if (!sv || !SvOK (sv)) |
|
|
190 | if (extra) |
|
|
191 | sv = sv_2mortal (newRV_noinc ((SV *)newAV ())); // slow, but rarely used hopefully |
|
|
192 | else |
|
|
193 | return 0; |
|
|
194 | |
|
|
195 | if (SvROK (sv) && SvTYPE (SvRV (sv)) == SVt_PVAV) |
|
|
196 | { |
|
|
197 | AV *av = (AV *)SvRV (sv); |
|
|
198 | int i, len = av_len (av) + 1; |
|
|
199 | cl_context_properties *p = tmpbuf (sizeof (cl_context_properties) * (len + extracount + 1)); |
|
|
200 | cl_context_properties *l = p; |
|
|
201 | |
|
|
202 | if (len & 1) |
|
|
203 | croak ("%s: %s is not a property list (must be even number of elements)", func, svname); |
|
|
204 | |
|
|
205 | while (extracount--) |
|
|
206 | *l++ = *extra++; |
|
|
207 | |
|
|
208 | for (i = 0; i < len; i += 2) |
|
|
209 | { |
|
|
210 | cl_context_properties t = SvIV (*av_fetch (av, i , 0)); |
|
|
211 | SV *p_sv = *av_fetch (av, i + 1, 0); |
|
|
212 | cl_context_properties v = SvIV (p_sv); // code below can override |
|
|
213 | |
|
|
214 | switch (t) |
|
|
215 | { |
|
|
216 | case CL_GLX_DISPLAY_KHR: |
|
|
217 | if (!SvOK (p_sv)) |
|
|
218 | { |
|
|
219 | void *func = glsym ("_glXGetCurrentDisplay"); |
|
|
220 | if (func) |
|
|
221 | v = (cl_context_properties)((void *(*)(void))func)(); |
|
|
222 | } |
|
|
223 | break; |
|
|
224 | |
|
|
225 | case CL_GL_CONTEXT_KHR: |
|
|
226 | if (!SvOK (p_sv)) |
|
|
227 | { |
|
|
228 | void *func = glsym ("_glXGetCurrentContext"); |
|
|
229 | if (func) |
|
|
230 | v = (cl_context_properties)((void *(*)(void))func)(); |
|
|
231 | } |
|
|
232 | break; |
|
|
233 | |
|
|
234 | default: |
|
|
235 | /* unknown property, treat as int */ |
|
|
236 | break; |
|
|
237 | } |
|
|
238 | |
|
|
239 | *l++ = t; |
|
|
240 | *l++ = v; |
|
|
241 | } |
|
|
242 | |
|
|
243 | *l = 0; |
|
|
244 | |
|
|
245 | return p; |
|
|
246 | } |
|
|
247 | |
|
|
248 | croak ("%s: %s is not a property list (either undef or [type => value, ...])", func, svname); |
132 | } |
249 | } |
133 | |
250 | |
134 | /*****************************************************************************/ |
251 | /*****************************************************************************/ |
135 | |
252 | |
136 | static size_t |
253 | static size_t |
… | |
… | |
175 | |
292 | |
176 | PROTOTYPES: ENABLE |
293 | PROTOTYPES: ENABLE |
177 | |
294 | |
178 | BOOT: |
295 | BOOT: |
179 | { |
296 | { |
180 | HV *stash = gv_stashpv ("OpenCL", 1); |
297 | HV *stash = gv_stashpv ("OpenCL", 1); |
181 | static const ivstr *civ, const_iv[] = { |
298 | static const ivstr *civ, const_iv[] = { |
182 | { sizeof (cl_char ), "SIZEOF_CHAR" }, |
299 | { sizeof (cl_char ), "SIZEOF_CHAR" }, |
183 | { sizeof (cl_uchar ), "SIZEOF_UCHAR" }, |
300 | { sizeof (cl_uchar ), "SIZEOF_UCHAR" }, |
184 | { sizeof (cl_short ), "SIZEOF_SHORT" }, |
301 | { sizeof (cl_short ), "SIZEOF_SHORT" }, |
185 | { sizeof (cl_ushort), "SIZEOF_USHORT" }, |
302 | { sizeof (cl_ushort), "SIZEOF_USHORT" }, |
186 | { sizeof (cl_int ), "SIZEOF_INT" }, |
303 | { sizeof (cl_int ), "SIZEOF_INT" }, |
187 | { sizeof (cl_uint ), "SIZEOF_UINT" }, |
304 | { sizeof (cl_uint ), "SIZEOF_UINT" }, |
188 | { sizeof (cl_long ), "SIZEOF_LONG" }, |
305 | { sizeof (cl_long ), "SIZEOF_LONG" }, |
189 | { sizeof (cl_ulong ), "SIZEOF_ULONG" }, |
306 | { sizeof (cl_ulong ), "SIZEOF_ULONG" }, |
190 | { sizeof (cl_half ), "SIZEOF_HALF" }, |
307 | { sizeof (cl_half ), "SIZEOF_HALF" }, |
191 | { sizeof (cl_float ), "SIZEOF_FLOAT" }, |
308 | { sizeof (cl_float ), "SIZEOF_FLOAT" }, |
192 | { sizeof (cl_double), "SIZEOF_DOUBLE" }, |
309 | { sizeof (cl_double), "SIZEOF_DOUBLE" }, |
193 | #include "constiv.h" |
310 | #include "constiv.h" |
194 | }; |
311 | }; |
195 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--) |
312 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--) |
196 | newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv)); |
313 | newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv)); |
197 | } |
314 | } |
198 | |
315 | |
199 | cl_int |
316 | cl_int |
200 | errno () |
317 | errno () |
201 | CODE: |
318 | CODE: |
… | |
… | |
221 | EXTEND (SP, count); |
338 | EXTEND (SP, count); |
222 | for (i = 0; i < count; ++i) |
339 | for (i = 0; i < count; ++i) |
223 | PUSHs (NEW_MORTAL_OBJ ("OpenCL::Platform", list [i])); |
340 | PUSHs (NEW_MORTAL_OBJ ("OpenCL::Platform", list [i])); |
224 | |
341 | |
225 | void |
342 | void |
226 | context_from_type (FUTURE properties = 0, cl_device_type type = CL_DEVICE_TYPE_DEFAULT, FUTURE notify = 0) |
343 | context_from_type (cl_context_properties *properties = 0, cl_device_type type = CL_DEVICE_TYPE_DEFAULT, FUTURE notify = 0) |
227 | PPCODE: |
344 | PPCODE: |
228 | NEED_SUCCESS_ARG (cl_context ctx, CreateContextFromType, (0, type, 0, 0, &res)); |
345 | NEED_SUCCESS_ARG (cl_context ctx, CreateContextFromType, (properties, type, 0, 0, &res)); |
229 | XPUSH_NEW_OBJ ("OpenCL::Context", ctx); |
346 | XPUSH_NEW_OBJ ("OpenCL::Context", ctx); |
230 | |
347 | |
231 | void |
348 | void |
232 | context (FUTURE properties, FUTURE devices, FUTURE notify = 0) |
349 | context (cl_context_properties *properties = 0, FUTURE devices, FUTURE notify = 0) |
233 | PPCODE: |
350 | PPCODE: |
234 | /* der Gipfel der Kunst */ |
351 | /* der Gipfel der Kunst */ |
235 | |
352 | |
236 | void |
353 | void |
237 | wait_for_events (...) |
354 | wait_for_events (...) |
… | |
… | |
283 | EXTEND (SP, count); |
400 | EXTEND (SP, count); |
284 | for (i = 0; i < count; ++i) |
401 | for (i = 0; i < count; ++i) |
285 | PUSHs (sv_setref_pv (sv_newmortal (), "OpenCL::Device", list [i])); |
402 | PUSHs (sv_setref_pv (sv_newmortal (), "OpenCL::Device", list [i])); |
286 | |
403 | |
287 | void |
404 | void |
288 | context (OpenCL::Platform self, FUTURE properties, SV *devices, FUTURE notify = 0) |
405 | context (OpenCL::Platform self, cl_context_properties *properties = 0, SV *devices, FUTURE notify = 0) |
289 | PPCODE: |
406 | PPCODE: |
290 | if (!SvROK (devices) || SvTYPE (SvRV (devices)) != SVt_PVAV) |
407 | if (!SvROK (devices) || SvTYPE (SvRV (devices)) != SVt_PVAV) |
291 | croak ("OpenCL::Platform argument 'device' must be an arrayref with device objects, in call"); |
408 | croak ("OpenCL::Platform::context argument 'device' must be an arrayref with device objects, in call"); |
292 | |
409 | |
293 | AV *av = (AV *)SvRV (devices); |
410 | AV *av = (AV *)SvRV (devices); |
294 | cl_uint num_devices = av_len (av) + 1; |
411 | cl_uint num_devices = av_len (av) + 1; |
295 | cl_device_id *device_list = tmpbuf (sizeof (cl_device_id) * num_devices); |
412 | cl_device_id *device_list = tmpbuf (sizeof (cl_device_id) * num_devices); |
296 | int i; |
413 | int i; |
297 | |
414 | |
298 | for (i = num_devices; i--; ) |
415 | for (i = num_devices; i--; ) |
299 | device_list [i] = SvPTROBJ ("clCreateContext", "devices", *av_fetch (av, i, 0), "OpenCL::Device"); |
416 | device_list [i] = SvPTROBJ ("clCreateContext", "devices", *av_fetch (av, i, 0), "OpenCL::Device"); |
300 | |
417 | |
301 | NEED_SUCCESS_ARG (cl_context ctx, CreateContext, (0, num_devices, device_list, 0, 0, &res)); |
418 | NEED_SUCCESS_ARG (cl_context ctx, CreateContext, (properties, num_devices, device_list, 0, 0, &res)); |
302 | XPUSH_NEW_OBJ ("OpenCL::Context", ctx); |
419 | XPUSH_NEW_OBJ ("OpenCL::Context", ctx); |
303 | |
420 | |
304 | void |
421 | void |
305 | context_from_type (OpenCL::Platform self, FUTURE properties = 0, cl_device_type type = CL_DEVICE_TYPE_DEFAULT, FUTURE notify = 0) |
422 | context_from_type (OpenCL::Platform self, SV *properties = 0, cl_device_type type = CL_DEVICE_TYPE_DEFAULT, FUTURE notify = 0) |
306 | PPCODE: |
423 | PPCODE: |
307 | cl_context_properties props[] = { CL_CONTEXT_PLATFORM, (cl_context_properties)self, 0 }; |
424 | cl_context_properties extra[] = { CL_CONTEXT_PLATFORM, (cl_context_properties)self }; |
|
|
425 | cl_context_properties *props = SvCONTEXTPROPERTIES ("OpenCL::Platform::context_from_type", "properties", properties, extra, 2); |
308 | NEED_SUCCESS_ARG (cl_context ctx, CreateContextFromType, (props, type, 0, 0, &res)); |
426 | NEED_SUCCESS_ARG (cl_context ctx, CreateContextFromType, (props, type, 0, 0, &res)); |
309 | XPUSH_NEW_OBJ ("OpenCL::Context", ctx); |
427 | XPUSH_NEW_OBJ ("OpenCL::Context", ctx); |
310 | |
428 | |
311 | MODULE = OpenCL PACKAGE = OpenCL::Device |
429 | MODULE = OpenCL PACKAGE = OpenCL::Device |
312 | |
430 | |
… | |
… | |
565 | |
683 | |
566 | void |
684 | void |
567 | buffer (OpenCL::Context self, cl_mem_flags flags, size_t len) |
685 | buffer (OpenCL::Context self, cl_mem_flags flags, size_t len) |
568 | PPCODE: |
686 | PPCODE: |
569 | if (flags & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR)) |
687 | if (flags & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR)) |
570 | croak ("clCreateBuffer: cannot use/copy host ptr when no data is given, use $context->buffer_sv instead?"); |
688 | croak ("OpenCL::Context::buffer: cannot use/copy host ptr when no data is given, use $context->buffer_sv instead?"); |
571 | |
689 | |
572 | NEED_SUCCESS_ARG (cl_mem mem, CreateBuffer, (self, flags, len, 0, &res)); |
690 | NEED_SUCCESS_ARG (cl_mem mem, CreateBuffer, (self, flags, len, 0, &res)); |
573 | XPUSH_NEW_OBJ ("OpenCL::BufferObj", mem); |
691 | XPUSH_NEW_OBJ ("OpenCL::BufferObj", mem); |
574 | |
692 | |
575 | void |
693 | void |
576 | buffer_sv (OpenCL::Context self, cl_mem_flags flags, SV *data) |
694 | buffer_sv (OpenCL::Context self, cl_mem_flags flags, SV *data) |
577 | PPCODE: |
695 | PPCODE: |
578 | STRLEN len; |
696 | STRLEN len; |
579 | char *ptr = SvOK (data) ? SvPVbyte (data, len) : 0; |
697 | char *ptr = SvOK (data) ? SvPVbyte (data, len) : 0; |
580 | if (!(flags & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR))) |
698 | if (!(flags & (CL_MEM_USE_HOST_PTR | CL_MEM_COPY_HOST_PTR))) |
581 | croak ("clCreateBuffer: have to specify use or copy host ptr when buffer data is given, use $context->buffer instead?"); |
699 | croak ("OpenCL::Context::buffer_sv: you have to specify use or copy host ptr when buffer data is given, use $context->buffer instead?"); |
582 | NEED_SUCCESS_ARG (cl_mem mem, CreateBuffer, (self, flags, len, ptr, &res)); |
700 | NEED_SUCCESS_ARG (cl_mem mem, CreateBuffer, (self, flags, len, ptr, &res)); |
583 | XPUSH_NEW_OBJ ("OpenCL::BufferObj", mem); |
701 | XPUSH_NEW_OBJ ("OpenCL::BufferObj", mem); |
584 | |
702 | |
585 | void |
703 | void |
586 | 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) |
704 | 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) |
… | |
… | |
597 | STRLEN len; |
715 | STRLEN len; |
598 | char *ptr = SvOK (data) ? SvPVbyte (data, len) : 0; |
716 | char *ptr = SvOK (data) ? SvPVbyte (data, len) : 0; |
599 | const cl_image_format format = { channel_order, channel_type }; |
717 | const cl_image_format format = { channel_order, channel_type }; |
600 | NEED_SUCCESS_ARG (cl_mem mem, CreateImage3D, (self, flags, &format, width, height, depth, row_pitch, slice_pitch, ptr, &res)); |
718 | NEED_SUCCESS_ARG (cl_mem mem, CreateImage3D, (self, flags, &format, width, height, depth, row_pitch, slice_pitch, ptr, &res)); |
601 | XPUSH_NEW_OBJ ("OpenCL::Image3D", mem); |
719 | XPUSH_NEW_OBJ ("OpenCL::Image3D", mem); |
|
|
720 | |
|
|
721 | #if cl_apple_gl_sharing || cl_khr_gl_sharing |
|
|
722 | |
|
|
723 | void |
|
|
724 | gl_buffer (OpenCL::Context self, cl_mem_flags flags, cl_GLuint bufobj) |
|
|
725 | PPCODE: |
|
|
726 | NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLBuffer, (self, flags, bufobj, &res)); |
|
|
727 | XPUSH_NEW_OBJ ("OpenCL::BufferObj", mem); |
|
|
728 | |
|
|
729 | void |
|
|
730 | gl_texture2d (OpenCL::Context self, cl_mem_flags flags, cl_GLenum target, cl_GLint miplevel, cl_GLuint texture) |
|
|
731 | PPCODE: |
|
|
732 | NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLTexture2D, (self, flags, target, miplevel, texture, &res)); |
|
|
733 | XPUSH_NEW_OBJ ("OpenCL::Image2D", mem); |
|
|
734 | |
|
|
735 | void |
|
|
736 | gl_texture3d (OpenCL::Context self, cl_mem_flags flags, cl_GLenum target, cl_GLint miplevel, cl_GLuint texture) |
|
|
737 | PPCODE: |
|
|
738 | NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLTexture3D, (self, flags, target, miplevel, texture, &res)); |
|
|
739 | XPUSH_NEW_OBJ ("OpenCL::Image3D", mem); |
|
|
740 | |
|
|
741 | void |
|
|
742 | gl_renderbuffer (OpenCL::Context self, cl_mem_flags flags, cl_GLuint renderbuffer) |
|
|
743 | PPCODE: |
|
|
744 | NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLRenderbuffer, (self, flags, renderbuffer, &res)); |
|
|
745 | XPUSH_NEW_OBJ ("OpenCL::Image2D", mem); |
|
|
746 | |
|
|
747 | #endif |
602 | |
748 | |
603 | void |
749 | void |
604 | supported_image_formats (OpenCL::Context self, cl_mem_flags flags, cl_mem_object_type image_type) |
750 | supported_image_formats (OpenCL::Context self, cl_mem_flags flags, cl_mem_object_type image_type) |
605 | PPCODE: |
751 | PPCODE: |
606 | { |
752 | { |
… | |
… | |
958 | NEED_SUCCESS (EnqueueNDRangeKernel, (self, kernel, gws_len, gwo, gws, lws, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); |
1104 | NEED_SUCCESS (EnqueueNDRangeKernel, (self, kernel, gws_len, gwo, gws, lws, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); |
959 | |
1105 | |
960 | if (ev) |
1106 | if (ev) |
961 | XPUSH_NEW_OBJ ("OpenCL::Event", ev); |
1107 | XPUSH_NEW_OBJ ("OpenCL::Event", ev); |
962 | |
1108 | |
|
|
1109 | #if cl_apple_gl_sharing || cl_khr_gl_sharing |
|
|
1110 | |
|
|
1111 | void |
|
|
1112 | enqueue_acquire_gl_objects (OpenCL::Queue self, SV *objects, ...) |
|
|
1113 | ALIAS: |
|
|
1114 | enqueue_release_gl_objects = 1 |
|
|
1115 | CODE: |
|
|
1116 | if (!SvROK (objects) || SvTYPE (SvRV (objects)) != SVt_PVAV) |
|
|
1117 | croak ("OpenCL::Queue::enqueue_acquire/release_gl_objects argument 'objects' must be an arrayref with memory objects, in call"); |
|
|
1118 | |
|
|
1119 | cl_event ev = 0; |
|
|
1120 | EVENT_LIST (2, items - 2); |
|
|
1121 | AV *av = (AV *)SvRV (objects); |
|
|
1122 | cl_uint num_objects = av_len (av) + 1; |
|
|
1123 | cl_mem *object_list = tmpbuf (sizeof (cl_mem) * num_objects); |
|
|
1124 | int i; |
|
|
1125 | |
|
|
1126 | for (i = num_objects; i--; ) |
|
|
1127 | object_list [i] = SvPTROBJ ("OpenCL::Queue::enqueue_acquire/release_gl_objects", "objects", *av_fetch (av, i, 0), "OpenCL::Memory"); |
|
|
1128 | |
|
|
1129 | if (ix) |
|
|
1130 | NEED_SUCCESS (EnqueueReleaseGLObjects, (self, num_objects, object_list, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); |
|
|
1131 | else |
|
|
1132 | NEED_SUCCESS (EnqueueAcquireGLObjects, (self, num_objects, object_list, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); |
|
|
1133 | |
|
|
1134 | if (ev) |
|
|
1135 | XPUSH_NEW_OBJ ("OpenCL::Event", ev); |
|
|
1136 | |
|
|
1137 | #endif |
|
|
1138 | |
963 | void |
1139 | void |
964 | enqueue_marker (OpenCL::Queue self) |
1140 | enqueue_marker (OpenCL::Queue self) |
965 | PPCODE: |
1141 | PPCODE: |
966 | cl_event ev; |
1142 | cl_event ev; |
967 | NEED_SUCCESS (EnqueueMarker, (self, &ev)); |
1143 | NEED_SUCCESS (EnqueueMarker, (self, &ev)); |
… | |
… | |
1126 | NEED_SUCCESS (RetainMemObject, (value [i])); |
1302 | NEED_SUCCESS (RetainMemObject, (value [i])); |
1127 | PUSHs (NEW_MORTAL_OBJ ("OpenCL::Memory", value [i])); |
1303 | PUSHs (NEW_MORTAL_OBJ ("OpenCL::Memory", value [i])); |
1128 | } |
1304 | } |
1129 | |
1305 | |
1130 | #END:mem |
1306 | #END:mem |
|
|
1307 | |
|
|
1308 | #if cl_apple_gl_sharing || cl_khr_gl_sharing |
|
|
1309 | |
|
|
1310 | void |
|
|
1311 | gl_object_info (OpenCL::Memory self) |
|
|
1312 | PPCODE: |
|
|
1313 | cl_gl_object_type type; |
|
|
1314 | cl_GLuint name; |
|
|
1315 | NEED_SUCCESS (GetGLObjectInfo, (self, &type, &name)); |
|
|
1316 | EXTEND (SP, 2); |
|
|
1317 | PUSHs (sv_2mortal (newSVuv (type))); |
|
|
1318 | PUSHs (sv_2mortal (newSVuv (name))); |
|
|
1319 | |
|
|
1320 | #endif |
1131 | |
1321 | |
1132 | MODULE = OpenCL PACKAGE = OpenCL::BufferObj |
1322 | MODULE = OpenCL PACKAGE = OpenCL::BufferObj |
1133 | |
1323 | |
1134 | void |
1324 | void |
1135 | sub_buffer_region (OpenCL::BufferObj self, cl_mem_flags flags, size_t origin, size_t size) |
1325 | sub_buffer_region (OpenCL::BufferObj self, cl_mem_flags flags, size_t origin, size_t size) |
… | |
… | |
1166 | EXTEND (SP, 1); |
1356 | EXTEND (SP, 1); |
1167 | const int i = 0; |
1357 | const int i = 0; |
1168 | PUSHs (sv_2mortal (newSVuv (value [i]))); |
1358 | PUSHs (sv_2mortal (newSVuv (value [i]))); |
1169 | |
1359 | |
1170 | #END:image |
1360 | #END:image |
|
|
1361 | |
|
|
1362 | #if cl_apple_gl_sharing || cl_khr_gl_sharing |
|
|
1363 | |
|
|
1364 | #BEGIN:gl_texture |
|
|
1365 | |
|
|
1366 | void |
|
|
1367 | target (OpenCL::Image self) |
|
|
1368 | PPCODE: |
|
|
1369 | cl_GLenum value [1]; |
|
|
1370 | NEED_SUCCESS (GetGLTextureInfo, (self, CL_GL_TEXTURE_TARGET, sizeof (value), value, 0)); |
|
|
1371 | EXTEND (SP, 1); |
|
|
1372 | const int i = 0; |
|
|
1373 | PUSHs (sv_2mortal (newSVuv (value [i]))); |
|
|
1374 | |
|
|
1375 | void |
|
|
1376 | gl_mipmap_level (OpenCL::Image self) |
|
|
1377 | PPCODE: |
|
|
1378 | cl_GLint value [1]; |
|
|
1379 | NEED_SUCCESS (GetGLTextureInfo, (self, CL_GL_MIPMAP_LEVEL, sizeof (value), value, 0)); |
|
|
1380 | EXTEND (SP, 1); |
|
|
1381 | const int i = 0; |
|
|
1382 | PUSHs (sv_2mortal (newSViv (value [i]))); |
|
|
1383 | |
|
|
1384 | #END:gl_texture |
|
|
1385 | |
|
|
1386 | #endif |
1171 | |
1387 | |
1172 | MODULE = OpenCL PACKAGE = OpenCL::Sampler |
1388 | MODULE = OpenCL PACKAGE = OpenCL::Sampler |
1173 | |
1389 | |
1174 | void |
1390 | void |
1175 | DESTROY (OpenCL::Sampler self) |
1391 | DESTROY (OpenCL::Sampler self) |
… | |
… | |
1474 | set_sampler (OpenCL::Kernel self, cl_uint idx, OpenCL::Sampler value) |
1690 | set_sampler (OpenCL::Kernel self, cl_uint idx, OpenCL::Sampler value) |
1475 | CODE: |
1691 | CODE: |
1476 | clSetKernelArg (self, idx, sizeof (value), &value); |
1692 | clSetKernelArg (self, idx, sizeof (value), &value); |
1477 | |
1693 | |
1478 | void |
1694 | void |
|
|
1695 | set_local (OpenCL::Kernel self, cl_uint idx, size_t size) |
|
|
1696 | CODE: |
|
|
1697 | clSetKernelArg (self, idx, size, 0); |
|
|
1698 | |
|
|
1699 | void |
1479 | set_event (OpenCL::Kernel self, cl_uint idx, OpenCL::Event value) |
1700 | set_event (OpenCL::Kernel self, cl_uint idx, OpenCL::Event value) |
1480 | CODE: |
1701 | CODE: |
1481 | clSetKernelArg (self, idx, sizeof (value), &value); |
1702 | clSetKernelArg (self, idx, sizeof (value), &value); |
1482 | |
1703 | |
1483 | void |
1704 | void |