我可以将数据写入cl :: BufferGL变量(在GPU上)并用它来绘制,但在读回主机时我得到了错误的值。我从AMD SDK中运行了几个例子,包括GL_CL interop,一切正常。我可以读写cl :: Buffer,即从主机复制到设备并从设备复制到主机。
源代码托管在link。
要创建cl :: Buffer,我在下面执行以下步骤(按顺序,并在获取cl_gl上下文后):
该程序使用以下方式编写:
编辑:我创建了一个代码块来重现错误
// Terminates OpenCL commands
cl_int status = 0;
status = clFinish( (cq)() );
if ( status != CL_SUCCESS ) { printf("File: %s:%d\n", __FILE__, __LINE__); }
// Create Vertex buffer object
GLint number = 5;
GLuint buffer;
CHk_ERR( glGenBuffers( 1, &buffer ));
CHk_ERR( glBindBuffer( GL_ARRAY_BUFFER, buffer ) );
// initialize buffer object
GLsizeiptr size = static_cast<GLsizeiptr>(sizeof(number));
const GLvoid * data = static_cast<const GLvoid *>(&number);
CHk_ERR( glBufferData( GL_ARRAY_BUFFER, size, data, GL_DYNAMIC_DRAW) );
CHk_ERR( glBindBuffer(GL_ARRAY_BUFFER, 0) );
glFinish();
if ( glGetError() != GL_NO_ERROR ) { printf("File: %s:%d\n", __FILE__, __LINE__); }
// create OpenCL buffer from GL VBO
cl_mem mem = clCreateFromGLBuffer( (context)(), CL_MEM_READ_WRITE, buffer, &status );
if ( status != CL_SUCCESS ) { printf("File: %s:%d\n", __FILE__, __LINE__); }
// Acquire OpenCL memory objects that have been created from OpenGL objects
if ( clEnqueueAcquireGLObjects( (cq)(), 1, &(mem), 0, NULL, NULL ) != CL_SUCCESS ){
std::cout << "ERROR!";
}
// Read buffer
GLint value;
cq.enqueueReadBuffer( mem, CL_TRUE, 0, size, &value );
std::cout << "Value: " << value << std::endl;
任何帮助表示赞赏!!