OpenGL:在帧中回收帧缓冲会损害性能吗?

OpenGL: Will recycling a Framebuffer in a frame hurt performance?

本文关键字:性能 OpenGL 缓冲      更新时间:2023-10-16

缓冲区不经常在片段着色器中被绘制和采样之间切换,这对 GPU 性能很重要吗? 我也许可以通过在单个帧中回收帧缓冲来节省视频内存,但我担心当 FBO 写入不相互依赖时,它可能会削弱 GPU 可能进行的一些并行优化,或者只是在其他方面成本高昂。

背景:

在我的渲染器中,我分配当前帧中我需要的所有帧缓冲区,如果可能的话,重用前一帧,并以这种方式使用它们:

FBO_0, FBO_1, FBO_n are allocated (FBO_n is the final output)
FBO_0 bind      ]_____________________ 
FBO_0 drawn to  ]                     
FBO_n bind                             
FBO_0 color used as a texture          Could the GPU be doing these two tasks
FBO_n drawn to with this texture       in parallel thanks to them using seperate FBO? 
                                       /
FBO_1 bind      ]_____________________/
FBO_1 drawn to  ]
FBO_n bind
FBO_1 color used as a texture
FBO_n drawn to with this texture
但是,在这种情况下

,可以回收FBO_0以充当FBO_1,从而减少我需要的整体视频内存。 这在实践中有点复杂,需要大量的重构,所以我正在研究这是否会对性能有负面影响并且值得做。

如果您只使用FBO_0和FBO_n就可以了,例如:

FBO_0 bind
FBO_0 drawn data1
FBO_n bind
FBO_0 color used as a texture
FBO_n drawn to with this texture
FBO_0 bind      
FBO_0 drawn data2
FBO_n bind
FBO_0 color used as a texture
FBO_n drawn to with this texture

通常,如果写入对象,稍后发出的任何命令都将看到新值。

少数例外可以在这个维基中找到:

https://www.khronos.org/opengl/wiki/Memory_Model

但最快的方法,很大程度上取决于OpenGL的实现。

在您的示例中,由于第一次"FBO_n绘制"取决于FBO_0绘制的完成,因此实现可能会并行开始FBO_1绘制。但是你没有这个保证。