I am doing an N Body particle project and have some questions about cl_mem_flags.
I assume cl_mem_flags are only used for optimisation?
Otherwise why would I not use CL_MEM_READ_WRITE all the time.
I assume this flag is not relevant to clEnqueueWriteBuffer, clEnqueueReadBuffer and clEnqueueCopyBuffer
i.e. you can copy to/write to a CL_MEM_READ_ONLY buffer and copy from/read from a CL_MEM_WRITE_ONLY buffer.
Is it possible to change the flags between kernel calls.
For example a kernel might take data from current Positions (CL_MEM_READ_ONLY) and write out new values to new Positions (CL_MEM_WRITE_ONLY).
Rather than clEnqueueCopyBuffer to copy new Positions to current Positions is it possible to switch the cl_mem_flags on these two and then switch the arguments around using clSetKernelArg
As it happens… I’m using a GL Vertex Buffer Object so the Positions can be directly rendered from graphics card memory.
Could I create two cl_mem objects for two vbo’s each with different cl_mem_flags?
i.e.
PositionsARead = clCreateFromGLBuffer(this->context, CL_MEM_READ_ONLY, vbo[0], &status);
PositionsAWrite = clCreateFromGLBuffer(this->context, CL_MEM_WRITE_ONLY, vbo[0], &status);
PositionsBRead = clCreateFromGLBuffer(this->context, CL_MEM_READ_ONLY, vbo[1], &status);
PositionsBWrite = clCreateFromGLBuffer(this->context, CL_MEM_WRITE_ONLY, vbo[1], &status);
And then alternate between
- kernel to read from PositionsARead and write to PositionsBWrite
- kernel to read from PositionsBRead and write to PositionsAWrite
My end goal is to have a one thread iterating OpenCL kernel calls (current to new,new to current) and have a timer event in another thread request that the OpenCL kernel also write a copy to a vbo buffer for display.
One last question is their any restrictions between the glBufferData GL flags and the cm_mem_flags
i.e. specifiying GL_STATIC_DRAW on a vbo and then creating a CL_MEM_WRITE_ONLY cl buffer to it doesn’t seem wise.