在CUDA中修改OpenGL FBO纹理附件 [英] Modifying OpenGL FBO texture attachment in CUDA

查看:160
本文介绍了在CUDA中修改OpenGL FBO纹理附件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下场景:



我有自定义FBO与纹理作为颜色附件。我呈现我的东西到FBO。下一步我需要共享这个纹理与CUDA,然后运行它一些后处理内核。后,纹理应该绑定回一个全屏幕的四边形,并呈现为默认帧缓冲区。
我阅读了几个OpenGL / CUDA互操作教程



首先,我看到他们通常做的是从GL纹理X中读取数据,在CUDA中处理它,然后使用PBO填充纹理Y与结果数据。



我注意到的另一件事(如果我错了,演示使用PBO默认绑定,这意味着第一遍渲染结果存储到它?我真的不确定它,因为所有这些演示使用固定的OpenGL,我看到没有地方PBO绑定,当初始几何通过渲染。



回到我的情况:
我的最后一个问题是 - 我可以直接操作CUDA中的OpenGL纹理而不使用PBO,这样我可以在CUDA内核中修改它?
如果不是,那么是否意味着我必须将FBO纹理打包到PBO中,然后才能传递到CUDA阶段?



UPDATE:



从帧缓冲区填充PBO通常使用glReadPixels ),这意味着它被下载到CPU。这是我想要防止的。 - 这是错误的假设。所以基于事实我可以填充PBO与像素从纹理是以下的方式去? :
用纹理数据填充PBO。



将其映射到CUDA缓冲区资源。





使用更新的纹理OpenGL。

解决方案

这里是一个处理CUDA中的OpenGL Texture,然后立即在OpenGL中使用它的例子,开销:



https://github.com/ nvpro-samples / gl_cuda_interop_pingpong_st


I have the following scenario:

I have custom FBO with texture as color attachment.I render my stuff into that FBO.Next step I need to share that texture with CUDA and then run on it some post-processing kernel.Afterwards the texture should be bound back to a full screen quad and rendered to default Frame Buffer. I have read several OpenGL / CUDA interop tutorials and some of the steps of doing this are not completely clear to me.

First ,what I see they usually do is to read data from GL texture X ,process it in CUDA ,and then using PBO fill texture Y with resulting data.

Another thing I noticed (correct me if I am wrong) is that the OpenGL in those demos use PBO bound by default and that means that the first pass rendering results are stored into it? I am really unsure about it as all those demos use fixed OpenGL and I see no place where PBO is bound when the initial geometry pass is rendered.

So back to my case: My final question is-can I operate directly on OpenGL texture in CUDA without using PBO so that I can modify it in CUDA kernel? If no , then does it mean I have to pack FBO texture into PBO before passing it to CUDA stage?

UPDATE:

Filling PBO from Frame buffer is usually done using glReadPixels(), which means it is downloaded to CPU.That is something I want to prevent. - THAT WAS WRONG ASSUMPTION. So based on the fact I can fill PBO with pixels from texture is the following way to go? : Fill PBO with data from texture.

Map it to CUDA buffer resource.

Do changes to the data with a kernel.

Update target texture from modified PBO.

Use the updated texture in OpenGL .

解决方案

Here is an example of processing an "OpenGL Texture" in CUDA and then immediately using it in OpenGL with no additional overhead:

https://github.com/nvpro-samples/gl_cuda_interop_pingpong_st

这篇关于在CUDA中修改OpenGL FBO纹理附件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆