1

I recently began incorporating OpenCL into my OpenGL application that renders a basic particle system, the basic interoperation–without events–between the two works fine. However, having tried to use the clCreateEventFromGLsyncKHR function in order to improve performance instead of having to call glFinish and clFinish, I am unable to get the running program as the program complains with the following error:

error LNK2019: unresolved external symbol _clCreateEventFromGLsyncKHR

I have tried to use both of the provided functions used to obtain extension-function pointers (clGetExtensionFunctionAddressForPlatform, clGetExtensionFunctionAddress) but for reasons I cant fathom, I am not able to get it to work.

Sample code:

#include <CL/cl_gl_ext.h>

typedef cl_event (*PFNCLCREATEEVENTFROMGLSYNCKHR) (cl_context context, cl_GLsync sync, cl_int *errcode_ret);

PFNCLCREATEEVENTFROMGLSYNCKHR clCreateEventFromGLsyncKHR = (PFNCLCREATEEVENTFROMGLSYNCKHR)clGetExtensionFunctionAddressForPlatform(opencl::target::inst()->platform(), "clCreateEventFromGLsyncKHR");

GLsync sync = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);

cl_event gl_event = clCreateEventFromGLsyncKHR(opencl::contexts["GL_CL_context"]->_get(), sync, NULL );

Would anyone kindly assist me in understanding as to where it is I am going wrong?

For those interested:

Name:                        GeForce GT 740M
Vendor:                  NVIDIA Corporation
Device OpenCL C version:             OpenCL C 1.1 
Driver version:              327.23
Profile:                     FULL_PROFILE
Version:                     OpenCL 1.1 CUDA
Extensions:                  cl_khr_byte_addressable_store cl_khr_icd cl_khr_gl_sharing cl_nv_d3d9_sharing cl_nv_d3d10_sharing cl_khr_d3d10_sharing cl_nv_d3d11_sharing cl_nv_compiler_options 
cl_nv_device_attribute_query cl_nv_pragma_unroll  cl_khr_global_int32_base_atomics cl_khr_global_int32_extended_atomics 
cl_khr_local_int32_base_atomics cl_khr_local_int32_extended_atomics cl_khr_fp64 

Update The above code still does not work if I use a device that supports the cl_khr_gl_event extension

1 Answers1

0

Your device does not support cl_khr_gl_event extension. That extension is needed to use the clCreateEventFromGLsyncKHR method. As stated here. Typically all the methods that are part of an extension end/start have KHR/NV/AMD in their name.

Another problem with your code, is that you have not enabled the extension anyway, with you have to do by defining the following:

#include <CL/cl_gl_ext.h>
DarkZeros
  • 8,235
  • 1
  • 26
  • 36
  • Apollogies that that was not included in the sample code but is in the actual code itself. Interesting point, I have two GPUs one without the extension as you have highlighted and another that does. However the same occurs if I use the device with the extension. Could my problem now be the way in which the above code has been written? – user1087765 Nov 19 '13 at 23:04
  • It may be the library you are linking does not have the method. Are you linking with nVIDIA? Do you have another library to link with? – DarkZeros Nov 19 '13 at 23:38
  • After messing around with it (using the same code) it is now giving me the following error: Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention. – user1087765 Nov 20 '13 at 00:02
  • For crash safety, you should check if you're getting a non-NULL result from clGetExtensionFunctionAddressForPlatform. – Dithermaster Nov 20 '13 at 01:49
  • From the spec: "A return value of NULL indicates that the specified function does not exist for the implementation or platform is not a valid platform. A non-NULL return value for clGetExtensionFunctionAddressForPlatform does not guarantee that an extension function is actually supported by the platform. The application must also make a corresponding query using clGetPlatformInfo (platform, CL_PLATFORM_EXTENSIONS, ... ) or clGetDeviceInfo (device,CL_DEVICE_EXTENSIONS, ... ) to determine if an extension is supported by the OpenCL implementation." – Dithermaster Nov 20 '13 at 01:49