cudaGLUnregisterBufferObject和cudaGraphicsGLRegisterBuffer错误

来源:互联网 发布:大学生开淘宝店可行性 编辑:程序博客网 时间:2024/05/02 17:39

无论是使用旧版本的cudaGLUnregisterBufferObject ,还是新版本的cudaGraphicsGLRegisterBuffer,当传入的buffer大小为0,VBO对应的指针为NULL时,cudaGLUnregisterBufferObject (cudaGraphicsGLRegisterBuffer)会返回错误cudaErrorMemoryAllocation,后面对应的cudaGLUnregisterBufferObject(cudaGraphicsUnregisterResource)会返回cudaErrorInvalidResourceHandle。

 

因此当VBO映射到cuda时不要传入空的VBO(NULL指针,0个元素),其实程序中真的有这种情况一般也不会影响运行的,前提是你得用下面的形式:

cudaGraphicsGLRegisterBuffer(&cuda_posvbo_resource, m_uId,   cudaGraphicsMapFlagsWriteDiscard);

这时返回的错误不用理睬的,可知照常运行出结果。

如果用了下面更安全的调用形式

cutilSafeCall(cudaGraphicsGLRegisterBuffer(&cuda_posvbo_resource, m_uId,  cudaGraphicsMapFlagsWriteDiscard));

程序就会在该句直接退出,因为cutilSafeCall会处理返回的错误而终止程序。

原创粉丝点击