--- OpenCL/OpenCL.xs 2012/04/21 17:56:21 1.36 +++ OpenCL/OpenCL.xs 2012/04/21 19:48:58 1.39 @@ -6,12 +6,27 @@ #include #endif +// how stupid is that, the 1.2 header files define CL_VERSION_1_1, +// but then fail to define the api functions unless you ALSO define +// this. This breaks 100% of the opencl 1.1 apps, for what reason? +// after all, the functions are deprecated, not removed. +// in addition, you cannot test for this in any future-proof way. +// each time a new opencl version comes out, you need to make a new +// release. +#define CL_USE_DEPRECATED_OPENCL_1_1_APIS +#define CL_USE_DEPRECATED_OPENCL_1_2_APIS /* just guessing, you stupid idiots */ + #ifdef __APPLE__ #include #else #include #endif +#if 0 // testing +#undef CL_USE_DEPRECATED_OPENCL_1_1_APIS +#undef CL_VERSION_1_2 +#endif + typedef cl_platform_id OpenCL__Platform; typedef cl_device_id OpenCL__Device; typedef cl_context OpenCL__Context; @@ -91,7 +106,7 @@ static void *buf [buffers]; static size_t len [buffers]; - idx = ++idx % buffers; + idx = (idx + 1) % buffers; if (len [idx] < size) { @@ -326,7 +341,9 @@ cl_int errno () CODE: - errno = res; + RETVAL = res; + OUTPUT: + RETVAL const char * err2str (cl_int err) @@ -355,11 +372,15 @@ NEED_SUCCESS_ARG (cl_context ctx, CreateContextFromType, (properties, type, 0, 0, &res)); XPUSH_NEW_OBJ ("OpenCL::Context", ctx); +#if 0 + void context (cl_context_properties *properties = 0, FUTURE devices, FUTURE notify = 0) PPCODE: /* der Gipfel der Kunst */ +#endif + void wait_for_events (...) CODE: @@ -710,6 +731,8 @@ NEED_SUCCESS_ARG (cl_mem mem, CreateBuffer, (self, flags, len, ptr, &res)); XPUSH_NEW_OBJ ("OpenCL::BufferObj", mem); +#if !CL_VERSION_1_2 || defined CL_USE_DEPRECATED_OPENCL_1_1_APIS + void 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) PPCODE: @@ -728,6 +751,8 @@ NEED_SUCCESS_ARG (cl_mem mem, CreateImage3D, (self, flags, &format, width, height, depth, row_pitch, slice_pitch, ptr, &res)); XPUSH_NEW_OBJ ("OpenCL::Image3D", mem); +#endif + #if cl_apple_gl_sharing || cl_khr_gl_sharing void @@ -736,6 +761,8 @@ NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLBuffer, (self, flags, bufobj, &res)); XPUSH_NEW_OBJ ("OpenCL::BufferObj", mem); +#if !CL_VERSION_1_2 || defined CL_USE_DEPRECATED_OPENCL_1_1_APIS + void gl_texture2d (OpenCL::Context self, cl_mem_flags flags, cl_GLenum target, cl_GLint miplevel, cl_GLuint texture) PPCODE: @@ -748,6 +775,30 @@ NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLTexture3D, (self, flags, target, miplevel, texture, &res)); XPUSH_NEW_OBJ ("OpenCL::Image3D", mem); +#endif + +#if CL_VERSION_1_2 + +void +gl_texture (OpenCL::Context self, cl_mem_flags flags, cl_GLenum target, cl_GLint miplevel, cl_GLuint texture) + PPCODE: + char *klass = "OpenCL::Memory"; + cl_gl_object_type t; + NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLTexture2D, (self, flags, target, miplevel, texture, &res)); + NEED_SUCCESS (GetGLObjectInfo, (mem, &t, 0)); + switch (t) + { + case CL_GL_OBJECT_TEXTURE_BUFFER: klass = "OpenCL::Image1DBuffer"; break; + case CL_GL_OBJECT_TEXTURE1D: klass = "OpenCL::Image1D"; break; + case CL_GL_OBJECT_TEXTURE1D_ARRAY: klass = "OpenCL::Image2DArray"; break; + case CL_GL_OBJECT_TEXTURE2D: klass = "OpenCL::Image2D"; break; + case CL_GL_OBJECT_TEXTURE2D_ARRAY: klass = "OpenCL::Image2DArray"; break; + case CL_GL_OBJECT_TEXTURE3D: klass = "OpenCL::Image3D"; break; + } + XPUSH_NEW_OBJ (klass, mem); + +#endif + void gl_renderbuffer (OpenCL::Context self, cl_mem_flags flags, cl_GLuint renderbuffer) PPCODE: @@ -943,7 +994,7 @@ if (len < min_len) croak ("clEnqueueWriteImage: data string is shorter than what would be transferred"); - 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)); + 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)); if (ev) XPUSH_NEW_OBJ ("OpenCL::Event", ev); @@ -1008,7 +1059,7 @@ if (len < min_len) croak ("clEnqueueWriteImage: data string is shorter than what would be transferred"); - 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)); + 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)); if (ev) XPUSH_NEW_OBJ ("OpenCL::Event", ev); @@ -1100,7 +1151,7 @@ if (SvOK (local_work_size)) { - if (SvOK (local_work_size) && !SvROK (local_work_size) || SvTYPE (SvRV (local_work_size)) != SVt_PVAV) + if ((SvOK (local_work_size) && !SvROK (local_work_size)) || SvTYPE (SvRV (local_work_size)) != SVt_PVAV) croak ("clEnqueueNDRangeKernel: global_work_size must be undef or an array reference"); if (AvFILLp (SvRV (local_work_size)) + 1 != gws_len) @@ -1146,12 +1197,7 @@ #endif -void -enqueue_marker (OpenCL::Queue self) - PPCODE: - cl_event ev; - NEED_SUCCESS (EnqueueMarker, (self, &ev)); - XPUSH_NEW_OBJ ("OpenCL::Event", ev); +#if !CL_VERSION_1_2 || defined CL_USE_DEPRECATED_OPENCL_1_1_APIS void enqueue_wait_for_events (OpenCL::Queue self, ...) @@ -1159,10 +1205,39 @@ EVENT_LIST (1, items - 1); NEED_SUCCESS (EnqueueWaitForEvents, (self, event_list_count, event_list_ptr)); +#endif + void -enqueue_barrier (OpenCL::Queue self) - CODE: +enqueue_marker (OpenCL::Queue self, ...) + PPCODE: + cl_event ev = 0; + EVENT_LIST (1, items - 1); +#if CL_VERSION_1_2 + NEED_SUCCESS (EnqueueMarkerWithWaitList, (self, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); +#else + if (event_list_count) + croak ("OpenCL::Queue->enqueue_marker does not support a wait list in OpenCL 1.1 - upgrade to 1.2"); + NEED_SUCCESS (EnqueueMarker, (self, GIMME_V != G_VOID ? &ev : 0)); +#endif + if (ev) + XPUSH_NEW_OBJ ("OpenCL::Event", ev); + +void +enqueue_barrier (OpenCL::Queue self, ...) + PPCODE: + cl_event ev = 0; + EVENT_LIST (1, items - 1); +#if CL_VERSION_1_2 + NEED_SUCCESS (EnqueueBarrierWithWaitList, (self, event_list_count, event_list_ptr, &ev)); +#else + if (event_list_count) + croak ("OpenCL::Queue->enqueue_barrier does not support a wait list in OpenCL 1.1 - upgrade to 1.2"); + if (GIMME_V != G_VOID) + croak ("OpenCL::Queue->enqueue_barrier does not return an event object in OpenCL 1.1 - upgrade to 1.2"); NEED_SUCCESS (EnqueueBarrier, (self)); +#endif + if (ev) + XPUSH_NEW_OBJ ("OpenCL::Event", ev); void flush (OpenCL::Queue self) @@ -1542,7 +1617,7 @@ SvUPGRADE (sv, SVt_PV); SvPOK_only (sv); SvCUR_set (sv, sizes [i]); - ptrs [i] = SvPVX (sv); + ptrs [i] = (void *)SvPVX (sv); PUSHs (sv); }