Hello, I am looking for help about the cl_khr_gl_sharing.
My C program use OpenCL to compute some maths and then display the result by sharing an openGL PBO between CL/GL. In most case, those results are displayed up to 60 fps to the user.
Everything seemed ok, my code works, but I noticed an usual CPU usage with clEnqueueAcquireGLObjects.
Actually even if I run a test program with clEnqueueAcquireGLObjects alone in a loop, i can observe the thing taking all my CPU.
What I dont understand is, why does clEnqueueAcquireGLObjects have so much things to do with the HOST ?
because everything should be computed on my GPU anyway. I thought clEnqueueAcquireGLObjects was just acting like a fence for the interop.
I tried others things like using a texture instead of a PBO, change nothing. and on both windows/linux
my setup use a NVIDIA GPU (GTX 1060), with up to date drivers. had no problem with anything with my hardware until now.
Maybe there is a problem with drivers ? or this is just me who doesnt understand how the cl_khr_gl_sharing should be used.
Here is a simpliflied sample of the relevent code in my app.
// this come after all glx/glew/x11/etc. initialisation
// the buffer is like this
glGenBuffers(1, &gLPBO);
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, gLPBO);
glBufferData(GL_PIXEL_UNPACK_BUFFER, size, NULL, GL_DYNAMIC_DRAW);
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
//this is how i create my context
cl_context_properties properties[] = {
CL_GL_CONTEXT_KHR, (cl_context_properties)glxctx,
CL_GLX_DISPLAY_KHR, (cl_context_properties)X11display,
// CL_CONTEXT_PLATFORM, (cl_context_properties)myPlat,
0
};
//and m command queue
clctx = clCreateContext(properties,1, &prefDevice, NULL, NULL, &err);
clque = clCreateCommandQueueWithProperties(clctx, prefDevice, 0, &err);
// the fonction to share a buffer between GL/CL
cLPBO = clCreateFromGLBuffer(clctx, CL_MEM_WRITE_ONLY, gLPBO, &err);
// a simple loop
while (1) {
this_thread::sleep_for(chrono::milliseconds(16));
err = clEnqueueAcquireGLObjects(clque, 1, &cLPBO, 0, 0, 0);
// err = clEnqueueNDRangeKernel(clque, mykernel, 1, NULL, globWorkSize, NULL, 0, NULL, NULL);
err = clEnqueueReleaseGLObjects(clque, 1, &cLPBO, 0, 0, 0);
// glBindBuffer(GL_PIXEL_UNPACK_BUFFER, gLPBO);
// glRasterPos2i(-1, -1);
// glDrawPixels(wndWidth, wndHeight, GL_RGBA, GL_UNSIGNED_BYTE, 0);
// glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
// glXSwapBuffers(X11display, X11window);
// glFinish();
}