简体   繁体   中英

Opengl and opencl can use only 1 kernel in a single shared context

(Solved)

There was a problem in installing of one of these:

{OpenTK, JIT(C#), Wrong dependencies, wrong DLL, GPU drivers, me}

Now same thing works without a problem in Java+jocl+lwjgl.

In a simple opencl-opengl interop program, a kernel uses GL-buffers(vertices, colors,..) and a CL-buffer(time in milliseconds and filter data) to alter the vertices of a mesh. It works when there is only one kernel in for the shared context.

Question: Why can't I add GL-buffers anymore when I use two cl-kernels instead of one? Second kernel is built as separate program from separate strings(C99 codes)

OpenCL's buffers are created in the C++ code:

 //raises System.AccessViolationException at C# if there are more than 1 kernel
 glBuf1=cl::BufferGL(ctx,CL_MEM_READ_WRITE,glBufName,0); // exception is exactly here

 //no error even with multiple kernels
 buf1=cl::Buffer(ctx,CL_MEM_READ_WRITE,sizeof(cl_float) * 1);//single time variable
 buf2=cl::Buffer(ctx,CL_MEM_READ_WRITE,sizeof(cl_float) * bufferN*3);// some filter data
 buf3=cl::Buffer(ctx,CL_MEM_READ_WRITE,sizeof(cl_float) * bufferN*3);// some filter data

OpenGL's buffers are created in C# code:

 GL.GenBuffers(1,&name); // and name is passed to opencl wrapper as glBufName.

Is there a rule like "each kernel must be in a separate context and each context must have different buffers than other contexts if the contexts are to be shared between opengl and opencl" ?

Edit: 64bit target buid, windows7-64bit, OpenTK as opengl part, opencl 1.2 C++ wrapper from Khronos' site as opencl part.

Edit: Multiple kernels for pure open-cl computing works without a problem. When there GL buffer included, it bugs. Only single opencl kernel and opengl can cooperate for my windows7-64 bit + HD7870 WHQL 13.4 + opentk + opencl 1.2 c++ wrapper.

It sounds more like you are having a synchronization issue here. And the addition of kernels is bringing it to the surface. As soon as you start sharing resources heavily, you need to make sure your OpenGL and OpenCL contexts aren't using them at the same time.

At the simplest level, glFinish (...) may help. Otherwise you will have to use more sophisticated (and less portable) OpenCL/OpenGL synchronization techniques like fences.

What error message to you get when it doesn't work?

There isn't a rule requiring that each kernel must be in a separate context. You should be able to have multiple kernels in a single cl_program and multiple programs in a context.

What hardware are you using eg Nvidia or AMD GPUs?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM