… | |
… | |
11 | // this. This breaks 100% of the opencl 1.1 apps, for what reason? |
11 | // this. This breaks 100% of the opencl 1.1 apps, for what reason? |
12 | // after all, the functions are deprecated, not removed. |
12 | // after all, the functions are deprecated, not removed. |
13 | // in addition, you cannot test for this in any future-proof way. |
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 |
14 | // each time a new opencl version comes out, you need to make a new |
15 | // release. |
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 */ |
16 | #define CL_USE_DEPRECATED_OPENCL_1_2_APIS /* just guessing, you stupid idiots */ |
|
|
17 | |
|
|
18 | #ifndef PREFER_1_1 |
|
|
19 | #define PREFER_1_1 1 |
|
|
20 | #endif |
|
|
21 | |
|
|
22 | #if PREFER_1_1 |
|
|
23 | #define CL_USE_DEPRECATED_OPENCL_1_1_APIS |
|
|
24 | #endif |
18 | |
25 | |
19 | #ifdef __APPLE__ |
26 | #ifdef __APPLE__ |
20 | #include <OpenCL/opencl.h> |
27 | #include <OpenCL/opencl.h> |
21 | #else |
28 | #else |
22 | #include <CL/opencl.h> |
29 | #include <CL/opencl.h> |
23 | #endif |
30 | #endif |
24 | |
31 | |
25 | #if 0 // testing |
|
|
26 | #undef CL_USE_DEPRECATED_OPENCL_1_1_APIS |
|
|
27 | #undef CL_VERSION_1_2 |
32 | #ifndef CL_VERSION_1_2 |
|
|
33 | #undef PREFER_1_1 |
|
|
34 | #define PREFER_1_1 1 |
28 | #endif |
35 | #endif |
29 | |
36 | |
30 | typedef cl_platform_id OpenCL__Platform; |
37 | typedef cl_platform_id OpenCL__Platform; |
31 | typedef cl_device_id OpenCL__Device; |
38 | typedef cl_device_id OpenCL__Device; |
32 | typedef cl_context OpenCL__Context; |
39 | typedef cl_context OpenCL__Context; |
… | |
… | |
759 | } |
766 | } |
760 | XPUSH_NEW_OBJ (klass, mem); |
767 | XPUSH_NEW_OBJ (klass, mem); |
761 | |
768 | |
762 | #endif |
769 | #endif |
763 | |
770 | |
764 | #if !CL_VERSION_1_2 || defined CL_USE_DEPRECATED_OPENCL_1_1_APIS |
|
|
765 | |
|
|
766 | void |
771 | void |
767 | 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) |
772 | 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) |
768 | PPCODE: |
773 | PPCODE: |
769 | STRLEN len; |
774 | STRLEN len; |
770 | char *ptr = SvOK (data) ? SvPVbyte (data, len) : 0; |
775 | char *ptr = SvOK (data) ? SvPVbyte (data, len) : 0; |
771 | const cl_image_format format = { channel_order, channel_type }; |
776 | const cl_image_format format = { channel_order, channel_type }; |
772 | #if CL_VERSION_1_2 |
777 | #if PREFER_1_1 |
|
|
778 | NEED_SUCCESS_ARG (cl_mem mem, CreateImage2D, (self, flags, &format, width, height, row_pitch, ptr, &res)); |
|
|
779 | #else |
773 | const cl_image_desc desc = { CL_MEM_OBJECT_IMAGE2D, width, height, 0, 0, row_pitch, 0, 0, 0, 0 }; |
780 | const cl_image_desc desc = { CL_MEM_OBJECT_IMAGE2D, width, height, 0, 0, row_pitch, 0, 0, 0, 0 }; |
774 | NEED_SUCCESS_ARG (cl_mem mem, CreateImage, (self, flags, &format, &desc, ptr, &res)); |
781 | NEED_SUCCESS_ARG (cl_mem mem, CreateImage, (self, flags, &format, &desc, ptr, &res)); |
775 | #else |
|
|
776 | NEED_SUCCESS_ARG (cl_mem mem, CreateImage2D, (self, flags, &format, width, height, row_pitch, ptr, &res)); |
|
|
777 | #endif |
782 | #endif |
778 | XPUSH_NEW_OBJ ("OpenCL::Image2D", mem); |
783 | XPUSH_NEW_OBJ ("OpenCL::Image2D", mem); |
779 | |
784 | |
780 | void |
785 | void |
781 | image3d (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 depth, size_t row_pitch = 0, size_t slice_pitch = 0, SV *data = &PL_sv_undef) |
786 | image3d (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 depth, size_t row_pitch = 0, size_t slice_pitch = 0, SV *data = &PL_sv_undef) |
782 | PPCODE: |
787 | PPCODE: |
783 | STRLEN len; |
788 | STRLEN len; |
784 | char *ptr = SvOK (data) ? SvPVbyte (data, len) : 0; |
789 | char *ptr = SvOK (data) ? SvPVbyte (data, len) : 0; |
785 | const cl_image_format format = { channel_order, channel_type }; |
790 | const cl_image_format format = { channel_order, channel_type }; |
786 | #if CL_VERSION_1_2 |
791 | #if PREFER_1_1 |
|
|
792 | NEED_SUCCESS_ARG (cl_mem mem, CreateImage3D, (self, flags, &format, width, height, depth, row_pitch, slice_pitch, ptr, &res)); |
|
|
793 | #else |
787 | const cl_image_desc desc = { CL_MEM_OBJECT_IMAGE3D, width, height, depth, 0, row_pitch, slice_pitch, 0, 0, 0 }; |
794 | const cl_image_desc desc = { CL_MEM_OBJECT_IMAGE3D, width, height, depth, 0, row_pitch, slice_pitch, 0, 0, 0 }; |
788 | NEED_SUCCESS_ARG (cl_mem mem, CreateImage, (self, flags, &format, &desc, ptr, &res)); |
795 | NEED_SUCCESS_ARG (cl_mem mem, CreateImage, (self, flags, &format, &desc, ptr, &res)); |
789 | #else |
|
|
790 | NEED_SUCCESS_ARG (cl_mem mem, CreateImage3D, (self, flags, &format, width, height, depth, row_pitch, slice_pitch, ptr, &res)); |
|
|
791 | #endif |
796 | #endif |
792 | XPUSH_NEW_OBJ ("OpenCL::Image3D", mem); |
797 | XPUSH_NEW_OBJ ("OpenCL::Image3D", mem); |
793 | |
798 | |
794 | #endif |
|
|
795 | |
|
|
796 | #if cl_apple_gl_sharing || cl_khr_gl_sharing |
799 | #if cl_apple_gl_sharing || cl_khr_gl_sharing |
797 | |
800 | |
798 | void |
801 | void |
799 | gl_buffer (OpenCL::Context self, cl_mem_flags flags, cl_GLuint bufobj) |
802 | gl_buffer (OpenCL::Context self, cl_mem_flags flags, cl_GLuint bufobj) |
800 | PPCODE: |
803 | PPCODE: |
… | |
… | |
809 | |
812 | |
810 | #if CL_VERSION_1_2 |
813 | #if CL_VERSION_1_2 |
811 | |
814 | |
812 | void |
815 | void |
813 | gl_texture (OpenCL::Context self, cl_mem_flags flags, cl_GLenum target, cl_GLint miplevel, cl_GLuint texture) |
816 | gl_texture (OpenCL::Context self, cl_mem_flags flags, cl_GLenum target, cl_GLint miplevel, cl_GLuint texture) |
|
|
817 | ALIAS: |
814 | PPCODE: |
818 | PPCODE: |
|
|
819 | NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLTexture, (self, flags, target, miplevel, texture, &res)); |
|
|
820 | cl_gl_object_type type; |
|
|
821 | NEED_SUCCESS (GetGLObjectInfo, (mem, &type, 0)); // TODO: use target instead? |
815 | char *klass = "OpenCL::Memory"; |
822 | char *klass = "OpenCL::Memory"; |
816 | cl_gl_object_type type; |
|
|
817 | NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLTexture2D, (self, flags, target, miplevel, texture, &res)); |
|
|
818 | NEED_SUCCESS (GetGLObjectInfo, (mem, &type, 0)); |
|
|
819 | switch (type) |
823 | switch (type) |
820 | { |
824 | { |
821 | case CL_GL_OBJECT_TEXTURE_BUFFER: klass = "OpenCL::Image1DBuffer"; break; |
825 | case CL_GL_OBJECT_TEXTURE_BUFFER: klass = "OpenCL::Image1DBuffer"; break; |
822 | case CL_GL_OBJECT_TEXTURE1D: klass = "OpenCL::Image1D"; break; |
826 | case CL_GL_OBJECT_TEXTURE1D: klass = "OpenCL::Image1D"; break; |
823 | case CL_GL_OBJECT_TEXTURE1D_ARRAY: klass = "OpenCL::Image2DArray"; break; |
827 | case CL_GL_OBJECT_TEXTURE1D_ARRAY: klass = "OpenCL::Image2DArray"; break; |
… | |
… | |
827 | } |
831 | } |
828 | XPUSH_NEW_OBJ (klass, mem); |
832 | XPUSH_NEW_OBJ (klass, mem); |
829 | |
833 | |
830 | #endif |
834 | #endif |
831 | |
835 | |
832 | #if !CL_VERSION_1_2 || defined CL_USE_DEPRECATED_OPENCL_1_1_APIS |
|
|
833 | |
|
|
834 | void |
836 | void |
835 | gl_texture2d (OpenCL::Context self, cl_mem_flags flags, cl_GLenum target, cl_GLint miplevel, cl_GLuint texture) |
837 | gl_texture2d (OpenCL::Context self, cl_mem_flags flags, cl_GLenum target, cl_GLint miplevel, cl_GLuint texture) |
836 | PPCODE: |
838 | PPCODE: |
|
|
839 | #if PREFER_1_1 |
837 | NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLTexture2D, (self, flags, target, miplevel, texture, &res)); |
840 | NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLTexture2D, (self, flags, target, miplevel, texture, &res)); |
|
|
841 | #else |
|
|
842 | NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLTexture , (self, flags, target, miplevel, texture, &res)); |
|
|
843 | #endif |
838 | XPUSH_NEW_OBJ ("OpenCL::Image2D", mem); |
844 | XPUSH_NEW_OBJ ("OpenCL::Image2D", mem); |
839 | |
845 | |
840 | void |
846 | void |
841 | gl_texture3d (OpenCL::Context self, cl_mem_flags flags, cl_GLenum target, cl_GLint miplevel, cl_GLuint texture) |
847 | gl_texture3d (OpenCL::Context self, cl_mem_flags flags, cl_GLenum target, cl_GLint miplevel, cl_GLuint texture) |
842 | PPCODE: |
848 | PPCODE: |
|
|
849 | #if PREFER_1_1 |
843 | NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLTexture3D, (self, flags, target, miplevel, texture, &res)); |
850 | NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLTexture3D, (self, flags, target, miplevel, texture, &res)); |
|
|
851 | #else |
|
|
852 | NEED_SUCCESS_ARG (cl_mem mem, CreateFromGLTexture , (self, flags, target, miplevel, texture, &res)); |
|
|
853 | #endif |
844 | XPUSH_NEW_OBJ ("OpenCL::Image3D", mem); |
854 | XPUSH_NEW_OBJ ("OpenCL::Image3D", mem); |
845 | |
|
|
846 | #endif |
|
|
847 | |
855 | |
848 | #endif |
856 | #endif |
849 | |
857 | |
850 | void |
858 | void |
851 | supported_image_formats (OpenCL::Context self, cl_mem_flags flags, cl_mem_object_type image_type) |
859 | supported_image_formats (OpenCL::Context self, cl_mem_flags flags, cl_mem_object_type image_type) |
… | |
… | |
1250 | void |
1258 | void |
1251 | enqueue_marker (OpenCL::Queue self, ...) |
1259 | enqueue_marker (OpenCL::Queue self, ...) |
1252 | PPCODE: |
1260 | PPCODE: |
1253 | cl_event ev = 0; |
1261 | cl_event ev = 0; |
1254 | EVENT_LIST (1, items - 1); |
1262 | EVENT_LIST (1, items - 1); |
1255 | #if CL_VERSION_1_2 |
1263 | #if PREFER_1_1 |
1256 | NEED_SUCCESS (EnqueueMarkerWithWaitList, (self, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); |
|
|
1257 | #else |
|
|
1258 | if (event_list_count) |
1264 | if (event_list_count) |
1259 | croak ("OpenCL::Queue->enqueue_marker does not support a wait list in OpenCL 1.1 - upgrade to 1.2"); |
1265 | croak ("OpenCL::Queue->enqueue_marker does not support a wait list in OpenCL 1.1 - upgrade to 1.2"); |
1260 | NEED_SUCCESS (EnqueueMarker, (self, GIMME_V != G_VOID ? &ev : 0)); |
1266 | NEED_SUCCESS (EnqueueMarker, (self, GIMME_V != G_VOID ? &ev : 0)); |
|
|
1267 | #else |
|
|
1268 | NEED_SUCCESS (EnqueueMarkerWithWaitList, (self, event_list_count, event_list_ptr, GIMME_V != G_VOID ? &ev : 0)); |
1261 | #endif |
1269 | #endif |
1262 | if (ev) |
1270 | if (ev) |
1263 | XPUSH_NEW_OBJ ("OpenCL::Event", ev); |
1271 | XPUSH_NEW_OBJ ("OpenCL::Event", ev); |
1264 | |
1272 | |
1265 | void |
1273 | void |
1266 | enqueue_barrier (OpenCL::Queue self, ...) |
1274 | enqueue_barrier (OpenCL::Queue self, ...) |
1267 | PPCODE: |
1275 | PPCODE: |
1268 | cl_event ev = 0; |
1276 | cl_event ev = 0; |
1269 | EVENT_LIST (1, items - 1); |
1277 | EVENT_LIST (1, items - 1); |
1270 | #if CL_VERSION_1_2 |
1278 | #if PREFER_1_1 |
1271 | NEED_SUCCESS (EnqueueBarrierWithWaitList, (self, event_list_count, event_list_ptr, &ev)); |
|
|
1272 | #else |
|
|
1273 | if (event_list_count) |
1279 | if (event_list_count) |
1274 | croak ("OpenCL::Queue->enqueue_barrier does not support a wait list in OpenCL 1.1 - upgrade to 1.2"); |
1280 | croak ("OpenCL::Queue->enqueue_barrier does not support a wait list in OpenCL 1.1 - upgrade to 1.2"); |
1275 | if (GIMME_V != G_VOID) |
1281 | if (GIMME_V != G_VOID) |
1276 | croak ("OpenCL::Queue->enqueue_barrier does not return an event object in OpenCL 1.1 - upgrade to 1.2"); |
1282 | croak ("OpenCL::Queue->enqueue_barrier does not return an event object in OpenCL 1.1 - upgrade to 1.2"); |
1277 | NEED_SUCCESS (EnqueueBarrier, (self)); |
1283 | NEED_SUCCESS (EnqueueBarrier, (self)); |
|
|
1284 | #else |
|
|
1285 | NEED_SUCCESS (EnqueueBarrierWithWaitList, (self, event_list_count, event_list_ptr, &ev)); |
1278 | #endif |
1286 | #endif |
1279 | if (ev) |
1287 | if (ev) |
1280 | XPUSH_NEW_OBJ ("OpenCL::Event", ev); |
1288 | XPUSH_NEW_OBJ ("OpenCL::Event", ev); |
1281 | |
1289 | |
1282 | void |
1290 | void |