gpt4 book ai didi

Opengl深度缓冲区到cuda

转载 作者:行者123 更新时间:2023-12-01 03:38:32 25 4
gpt4 key购买 nike

我是 Opengl 的新程序员,
我的目标是将深度缓冲区检索到 FBO 中,以便能够在不使用 glReadpixels 的情况下传输到 cuda。

这是我已经完成的:

void make_Fbo()
{

glGenFramebuffers(1, &fbo);
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
glFramebufferRenderbuffer(GL_FRAMEBUFFER,
GL_DEPTH_ATTACHMENT,
GL_RENDERBUFFER,
fbo);
check_gl_error("make_fbo");
}


void make_render_buffer()
{
glGenRenderbuffers(1, &rb);
glBindRenderbuffer(GL_RENDERBUFFER, rb);
glRenderbufferStorage(GL_RENDERBUFFER,
GL_DEPTH_COMPONENT,
win.width,
win.height);
check_gl_error("make render_buffer");
}

此代码使用正确的深度值创建我的 FBO。

现在出现了一个新问题,根据文章“使用不规则z-buffer on cuda的快速三角形光栅化”
无法从 Cuda 访问附加到 FBO 的深度缓冲区。

这是文章的引述:

Textures or render buffers can be attached onto the depth attachment point of FBOs to accommodate the depth values. However, as far as we have tested, they cannot be accessed by CUDA kernels. [...] we managed to use the color attachment points on the FBO. Apparently in this case we have to write a simple shader program to dump the depth values onto the color channels of the frame buffer. According to the GLSL specification [KBR06], the special variable gl_FragCoord



这些陈述仍然正确吗?
你建议我将深度缓冲区转储到颜色 channel 吗?
到纹理?

最佳答案

好吧,是的,不是的。问题是当它们绑定(bind)到 FBO 时,您无法访问 CUDA 中的资源。

据我了解,cudaGraphicsGLRegisterImage()您启用 cuda 访问任何类型的图像数据。因此,如果您使用作为渲染目标且未绑定(bind)到 FBO 的深度缓冲区,则可以使用它。

这是 cuda API 信息:

https://docs.nvidia.com/cuda/cuda-runtime-api/group__CUDART__OPENGL.html#group__CUDART__OPENGL_1g80d12187ae7590807c7676697d9fe03d

在这篇文章中,他们解释说你应该循环或双缓冲深度缓冲区,或者在 CUDA 中使用数据之前复制数据(但你或多或少地放弃了互操作的整个想法)。

http://codekea.com/xLj7d1ya5gD6/modifying-opengl-fbo-texture-attachment-in-cuda.html

关于Opengl深度缓冲区到cuda,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32611002/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com