From c7bdbef5042dadfe032dfb5d80f9b90bec830371 Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Thu, 4 Feb 2016 12:04:04 +0300 Subject: [PATCH] ocl: fix OpenGL sharing detection (6052) Apple OpenCL framework hasn't OpenGL sharing extension --- .../opencl/runtime/autogenerated/opencl_gl.hpp | 4 ++++ .../runtime/autogenerated/opencl_gl_wrappers.hpp | 4 ++++ .../runtime/autogenerated/opencl_gl_impl.hpp | 4 ++++ .../core/src/opencl/runtime/generator/common.py | 4 ++-- .../core/src/opencl/runtime/generator/generate.sh | 0 .../runtime/generator/template/opencl_gl.hpp.in | 4 ++++ .../generator/template/opencl_gl_impl.hpp.in | 4 ++++ .../generator/template/opencl_gl_wrappers.hpp.in | 4 ++++ modules/core/src/opencl/runtime/opencl_core.cpp | 4 ++++ modules/core/src/opengl.cpp | 15 +++++++++++++++ 10 files changed, 45 insertions(+), 2 deletions(-) mode change 100644 => 100755 modules/core/src/opencl/runtime/generator/generate.sh diff --git a/modules/core/include/opencv2/core/opencl/runtime/autogenerated/opencl_gl.hpp b/modules/core/include/opencv2/core/opencl/runtime/autogenerated/opencl_gl.hpp index 64a7fedba..1ad4a6acc 100644 --- a/modules/core/include/opencv2/core/opencl/runtime/autogenerated/opencl_gl.hpp +++ b/modules/core/include/opencv2/core/opencl/runtime/autogenerated/opencl_gl.hpp @@ -41,6 +41,8 @@ #undef clGetGLTextureInfo #define clGetGLTextureInfo clGetGLTextureInfo_pfn +#ifdef cl_khr_gl_sharing + // generated by parser_cl.py extern CL_RUNTIME_EXPORT cl_mem (CL_API_CALL*clCreateFromGLBuffer)(cl_context, cl_mem_flags, cl_GLuint, int*); extern CL_RUNTIME_EXPORT cl_mem (CL_API_CALL*clCreateFromGLRenderbuffer)(cl_context, cl_mem_flags, cl_GLuint, cl_int*); @@ -52,3 +54,5 @@ extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clEnqueueReleaseGLObjects)(cl_comma extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clGetGLContextInfoKHR)(const cl_context_properties*, cl_gl_context_info, size_t, void*, size_t*); extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clGetGLObjectInfo)(cl_mem, cl_gl_object_type*, cl_GLuint*); extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clGetGLTextureInfo)(cl_mem, cl_gl_texture_info, size_t, void*, size_t*); + +#endif // cl_khr_gl_sharing diff --git a/modules/core/include/opencv2/core/opencl/runtime/autogenerated/opencl_gl_wrappers.hpp b/modules/core/include/opencv2/core/opencl/runtime/autogenerated/opencl_gl_wrappers.hpp index 105867f47..8338ac681 100644 --- a/modules/core/include/opencv2/core/opencl/runtime/autogenerated/opencl_gl_wrappers.hpp +++ b/modules/core/include/opencv2/core/opencl/runtime/autogenerated/opencl_gl_wrappers.hpp @@ -5,6 +5,8 @@ #error "Invalid usage" #endif +#ifdef cl_khr_gl_sharing + // generated by parser_cl.py #undef clCreateFromGLBuffer #define clCreateFromGLBuffer clCreateFromGLBuffer_fn @@ -36,3 +38,5 @@ inline cl_int clGetGLObjectInfo(cl_mem p0, cl_gl_object_type* p1, cl_GLuint* p2) #undef clGetGLTextureInfo #define clGetGLTextureInfo clGetGLTextureInfo_fn inline cl_int clGetGLTextureInfo(cl_mem p0, cl_gl_texture_info p1, size_t p2, void* p3, size_t* p4) { return clGetGLTextureInfo_pfn(p0, p1, p2, p3, p4); } + +#endif // cl_khr_gl_sharing diff --git a/modules/core/src/opencl/runtime/autogenerated/opencl_gl_impl.hpp b/modules/core/src/opencl/runtime/autogenerated/opencl_gl_impl.hpp index 6d9718050..5b371330c 100644 --- a/modules/core/src/opencl/runtime/autogenerated/opencl_gl_impl.hpp +++ b/modules/core/src/opencl/runtime/autogenerated/opencl_gl_impl.hpp @@ -139,6 +139,8 @@ struct opencl_gl_fn14 } // anonymous namespace +#ifdef cl_khr_gl_sharing + // generated by parser_cl.py cl_mem (CL_API_CALL*clCreateFromGLBuffer)(cl_context, cl_mem_flags, cl_GLuint, int*) = opencl_gl_fn4::switch_fn; @@ -196,3 +198,5 @@ static const struct DynamicFnEntry* opencl_gl_fn_list[] = { }; // number of enabled functions: 10 + +#endif // cl_khr_gl_sharing diff --git a/modules/core/src/opencl/runtime/generator/common.py b/modules/core/src/opencl/runtime/generator/common.py index 80c545295..5f81e8ee5 100644 --- a/modules/core/src/opencl/runtime/generator/common.py +++ b/modules/core/src/opencl/runtime/generator/common.py @@ -254,6 +254,6 @@ def ProcessTemplate(inputFile, ctx, noteLine='//\n// AUTOGENERATED, DO NOT EDIT\ assert line[-1] == '@' name = line[1:-1] assert ctx.has_key(name), name - line = ctx[name] - print line, + line = ctx[name] + ('\n' if len(ctx[name]) > 0 and ctx[name][-1] != '\n' else '') + sys.stdout.write(line) f.close() diff --git a/modules/core/src/opencl/runtime/generator/generate.sh b/modules/core/src/opencl/runtime/generator/generate.sh old mode 100644 new mode 100755 diff --git a/modules/core/src/opencl/runtime/generator/template/opencl_gl.hpp.in b/modules/core/src/opencl/runtime/generator/template/opencl_gl.hpp.in index 4bed42331..13a33c715 100644 --- a/modules/core/src/opencl/runtime/generator/template/opencl_gl.hpp.in +++ b/modules/core/src/opencl/runtime/generator/template/opencl_gl.hpp.in @@ -8,4 +8,8 @@ @CL_REMAP_DYNAMIC@ +#ifdef cl_khr_gl_sharing + @CL_FN_DECLARATIONS@ + +#endif // cl_khr_gl_sharing diff --git a/modules/core/src/opencl/runtime/generator/template/opencl_gl_impl.hpp.in b/modules/core/src/opencl/runtime/generator/template/opencl_gl_impl.hpp.in index 14586017a..cba1278a3 100644 --- a/modules/core/src/opencl/runtime/generator/template/opencl_gl_impl.hpp.in +++ b/modules/core/src/opencl/runtime/generator/template/opencl_gl_impl.hpp.in @@ -4,8 +4,12 @@ namespace { @CL_FN_SWITCH@ } // anonymous namespace +#ifdef cl_khr_gl_sharing + @CL_FN_ENTRY_DEFINITIONS@ @CL_FN_ENTRY_LIST@ @CL_NUMBER_OF_ENABLED_FUNCTIONS@ + +#endif // cl_khr_gl_sharing diff --git a/modules/core/src/opencl/runtime/generator/template/opencl_gl_wrappers.hpp.in b/modules/core/src/opencl/runtime/generator/template/opencl_gl_wrappers.hpp.in index 0aeefb4f4..fc0317914 100644 --- a/modules/core/src/opencl/runtime/generator/template/opencl_gl_wrappers.hpp.in +++ b/modules/core/src/opencl/runtime/generator/template/opencl_gl_wrappers.hpp.in @@ -2,4 +2,8 @@ #error "Invalid usage" #endif +#ifdef cl_khr_gl_sharing + @CL_FN_INLINE_WRAPPERS@ + +#endif // cl_khr_gl_sharing diff --git a/modules/core/src/opencl/runtime/opencl_core.cpp b/modules/core/src/opencl/runtime/opencl_core.cpp index 0ab338112..405a5936a 100644 --- a/modules/core/src/opencl/runtime/opencl_core.cpp +++ b/modules/core/src/opencl/runtime/opencl_core.cpp @@ -286,6 +286,8 @@ static void* opencl_check_fn(int ID) #include "opencv2/core/opencl/runtime/opencl_gl.hpp" +#ifdef cl_khr_gl_sharing + static void* opencl_gl_check_fn(int ID); #include "autogenerated/opencl_gl_impl.hpp" @@ -306,6 +308,8 @@ static void* opencl_gl_check_fn(int ID) return func; } +#endif // cl_khr_gl_sharing + #endif // HAVE_OPENGL #endif diff --git a/modules/core/src/opengl.cpp b/modules/core/src/opengl.cpp index 3bbc0f8e9..f3d106fd2 100644 --- a/modules/core/src/opengl.cpp +++ b/modules/core/src/opengl.cpp @@ -1580,6 +1580,11 @@ void cv::ogl::render(const ogl::Arrays& arr, InputArray indices, int mode, Scala #ifdef HAVE_OPENCL # include "opencv2/core/opencl/runtime/opencl_gl.hpp" +# ifdef cl_khr_gl_sharing +# define HAVE_OPENCL_OPENGL_SHARING +# else +# define NO_OPENCL_SHARING_ERROR CV_ErrorNoReturn(cv::Error::StsBadFunc, "OpenCV was build without OpenCL/OpenGL sharing support") +# endif #else // HAVE_OPENCL # define NO_OPENCL_SUPPORT_ERROR CV_ErrorNoReturn(cv::Error::StsBadFunc, "OpenCV was build without OpenCL support") #endif // HAVE_OPENCL @@ -1602,6 +1607,8 @@ Context& initializeContextFromGL() NO_OPENGL_SUPPORT_ERROR; #elif !defined(HAVE_OPENCL) NO_OPENCL_SUPPORT_ERROR; +#elif !defined(HAVE_OPENCL_OPENGL_SHARING) + NO_OPENCL_SHARING_ERROR; #else cl_uint numPlatforms; cl_int status = clGetPlatformIDs(0, NULL, &numPlatforms); @@ -1701,6 +1708,8 @@ void convertToGLTexture2D(InputArray src, Texture2D& texture) NO_OPENGL_SUPPORT_ERROR; #elif !defined(HAVE_OPENCL) NO_OPENCL_SUPPORT_ERROR; +#elif !defined(HAVE_OPENCL_OPENGL_SHARING) + NO_OPENCL_SHARING_ERROR; #else Size srcSize = src.size(); CV_Assert(srcSize.width == (int)texture.cols() && srcSize.height == (int)texture.rows()); @@ -1753,6 +1762,8 @@ void convertFromGLTexture2D(const Texture2D& texture, OutputArray dst) NO_OPENGL_SUPPORT_ERROR; #elif !defined(HAVE_OPENCL) NO_OPENCL_SUPPORT_ERROR; +#elif !defined(HAVE_OPENCL_OPENGL_SHARING) + NO_OPENCL_SHARING_ERROR; #else // check texture format const int dtype = CV_8UC4; @@ -1812,6 +1823,8 @@ UMat mapGLBuffer(const Buffer& buffer, int accessFlags) NO_OPENGL_SUPPORT_ERROR; #elif !defined(HAVE_OPENCL) NO_OPENCL_SUPPORT_ERROR; +#elif !defined(HAVE_OPENCL_OPENGL_SHARING) + NO_OPENCL_SHARING_ERROR; #else using namespace cv::ocl; Context& ctx = Context::getDefault(); @@ -1862,6 +1875,8 @@ void unmapGLBuffer(UMat& u) NO_OPENGL_SUPPORT_ERROR; #elif !defined(HAVE_OPENCL) NO_OPENCL_SUPPORT_ERROR; +#elif !defined(HAVE_OPENCL_OPENGL_SHARING) + NO_OPENCL_SHARING_ERROR; #else using namespace cv::ocl; cl_command_queue clQueue = (cl_command_queue)Queue::getDefault().ptr();