cudaGraphicsGLRegisterBuffer与cudaGraphicsGLRegisterImage的对比
来源:互联网 发布:种植牙的利与弊 知乎 编辑:程序博客网 时间:2024/05/17 19:59
cudaGraphicsGLRegisterBuffer是把opengl缓冲区对象同cuda绑定
使用cudaGraphicsResourceGetMappedPointer
获得的指针类型void**
获取的void**指针可以直接传入核函数中来进行修改
// imgId运行时将在CUDA和OpenGL间共享,通过把imgId注册为一个图形资源cudaGraphicsGLRegisterBuffer(&resource, imgId, cudaGraphicsMapFlagsNone);// 映射该共享资源checkCudaErrors( cudaGraphicsMapResources(1, &resource, NULL) ); // 请求一个指向映射资源的指针uchar4* devPtr;size_t size;checkCudaErrors( cudaGraphicsResourceGetMappedPointer((void**)&devPtr, &size, resource) );
cudaGraphicsGLRegisterImage是把opengl纹理对象同cuda绑定
使用cudaGraphicsSubResourceGetMappedArray获取cuda指向资源的指针
获得的指针类型cudaArray*
cudaArray*必须通过绑定到surface reference来进行修改
checkCudaErrors( cudaGraphicsGLRegisterImage(&resource, imgId, GL_TEXTURE_2D, cudaGraphicsRegisterFlagsSurfaceLoadStore)); checkCudaErrors( cudaGraphicsMapResources(1, &resource, NULL) ); cudaArray* devArray;checkCudaErrors( cudaGraphicsSubResourceGetMappedArray(&devArray, resource, 0, 0));
surface<void, cudaSurfaceType2D> surfRef;checkCudaErrors( cudaBindSurfaceToArray(surfRef, d_output) );
// 在核函数中的访问uchar4 data;data.x = d_lut[nMax];data.y = d_lut[nMax];data.z = d_lut[nMax];data.w = 255;surf2Dwrite(data, surfRef, x*4, y);最后一点要注意:根据CUDA_C_Progamming_Guide,Surface Memory need compute capability 2.0,而一般VC默认配置的是1.0,所有在使用surface编译时一般会出现错误:
fatal : Parsing error near '.surf': syntax error
这时候修改Properties-->CUDA Runtime API-->GPU-->GPR Architecture1 to sm_20 但sm_20明显和sm_10有区别,我修改完后编译通过,但在运行时,会出现cudaErrorInvalidTexture等运行时错误
- cudaGraphicsGLRegisterBuffer与cudaGraphicsGLRegisterImage的对比
- cudaGLUnregisterBufferObject和cudaGraphicsGLRegisterBuffer错误
- include()与require()的对比
- 指针与数组的对比
- 指针与数组的对比
- 指针与数组的对比
- Struts2与Struts1的对比
- SQL与ORACLE的对比
- SQL与ORACLE的对比
- Struts2与Struts1的对比
- Xml与html的对比
- Struts2与Struts1的对比
- 指针与数组的对比
- python与c++的对比
- Struts2与Struts1的对比
- Struts2与Struts1的对比
- Struts2与Struts1的对比
- Struts2与Struts1的对比
- DataGeridView添加行号
- 【OpenStack】OpenStack keystone的理解 2
- sql 2008 安装失败 mof语法错误 处理
- c++ primer 4 中10.6节算法改正
- DataGridViewRow 改变奇数行颜色
- cudaGraphicsGLRegisterBuffer与cudaGraphicsGLRegisterImage的对比
- 用C++写一个键盘函数控制函数
- 《C语言深度剖析》笔记之关键字篇
- DataGridView列排序
- MFC 选择路径
- 轻松掌握WebService技术后台—Soap图解法
- 基础知识1
- 2010VS连接2008sql数据库
- 四个程序员的一天