opengl - 顶点缓冲区的双缓冲与三重缓冲

标签 opengl graphics

许多图形编程资源似乎都建议使用三重缓冲数据以避免 GPU 上的同步。以下是几个例子:

OpenGL Insights - Asynchronous Buffer Transfers

Apple's Best Practices (Triple Buffering)

还有 another source says that :

GPU and CPU runs asynchronously... but there is also another factor: the driver. It may happen (and on desktop driver implementations it happens quite often) that the driver also runs asynchronously. To solve this, even more complicated synchronization scenario, you might consider triple buffering:

  • one buffer for cpu
  • one for the driver
  • one for gpu

This way there should be no stalls in the pipeline, but you need to sacrifice a bit more memory for your data.

--

第三个缓冲区实际上是为驱动程序准备的吗?第三个缓冲区试图解决驱动程序上的什么同步问题?感觉我们可以只用两个缓冲区来避免所有同步。

最佳答案

三重或双缓冲问题是在持久映射缓冲区的上下文中。我还没有使用持久映射的缓冲区,但我已经阅读了来自 Nvidia (How Modern OpenGL Can Radically Reduce Driver Overhead) 的演示文稿,其中讨论了这个主题并解释了它是如何工作的。只有在每帧流式传输新数据时,才需要三重缓冲避免停顿:

  • You are responsible for not stomping on data in flight.
  • Why 3x?
    • 1x: What the GPU is using right now.
    • 2x: What the driver is holding, getting ready for the GPU to use.
    • 3x: What you are writing to.
  • 3x should ~ guarantee enough buffer room*…
  • Use fences to ensure that rendering is complete before you begin to write new data.

Efficient Buffer Management [McDonald 2012]上述演示文稿中引用的内容还提供了有关正确缓冲区管理的更深入信息。

另请参阅概述 efficient buffer update algorithm 的 OpenGL wiki。 .

只要您保护缓冲区内存区域不被栅栏覆盖,您甚至可以使用单个缓冲顶点缓冲区。但是,这会降低性能,因为您将失去异步内存传输的好处。写入操作将等待之前的渲染操作完成,从而序列化更新和绘制阶段。

同样,所有这些双重和三重缓冲仅与 流式传输 改变每一帧的顶点数据相关。

关于opengl - 顶点缓冲区的双缓冲与三重缓冲,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47563995/

相关文章:

c++ - 使用 lodePng 和 OpenGL 显示 png 图像

c++ - 在 OpengL 中多次重复图像

vb.net - 是否可以使用标准控件生成动画过渡?

c++ - 网格三角测量 : Seperate vs Nested loop Complexity

image - Rust 图形库

c++ - OpenGL 截掉部分屏幕

opengl - Mac - OpenGL - 找不到发光

c - C Opengl 过剩中的错误 'glutTimerfunc'

opengl - 如何插入顶点法线?

java - 如何递归画线