我是否需要将 glMapRange 与缓冲区孤立一起使用以避免停顿?
Do I need to use glMapRange with buffer orphaning to avoid stalls?
有人告诉我,缓冲区孤立(即调用 glBufferData()
和 NULL
作为最终参数)允许我们避免在 GPU 尝试读取缓冲区对象时发生的停顿 CPU 正在尝试写入。
我不清楚的是我们是否可以使用这种方法 而无需 glMapBuffer*()
,或者 glMapBuffer*()
是否是孤儿化想法的组成部分和避免失速?我问这纯粹是为了避免对现有代码库进行不必要的更改,尽管我知道 glMapBuffer*()
比在长 运行.
中重复 glBufferData()
本质上是更好的选择
(请针对 OpenGL ES 2.0 做出具体回答,除非答案是跨 GL 版本的通用答案。)
答案在 official location:
The first way is to call glBufferData with a NULL pointer, and the
exact same size and usage hints it had before. This allows the
implementation to simply reallocate storage for that buffer object
under-the-hood. Since allocating storage is (likely) faster than the
implicit synchronization, you gain significant performance advantages
over synchronization. And since you passed NULL, if there wasn't a
need for synchronization to begin with, this can be reduced to a
no-op. The old storage will still be used by the OpenGL commands that
have been sent previously. If you continue to use the same size
over-and-over, it is likely that the GL driver will not be doing any
allocation at all, but will just be pulling an old free block off the
unused buffer queue and use it (though of course this isn't
guaranteed), so it is likely to be very efficient.
You can do the same thing when using glMapBufferRange with the
GL_MAP_INVALIDATE_BUFFER_BIT. You can also use
glInvalidateBufferData, where available.
所以我想可以安全地假设孤立只需要 glBufferData()
个调用。
有人告诉我,缓冲区孤立(即调用 glBufferData()
和 NULL
作为最终参数)允许我们避免在 GPU 尝试读取缓冲区对象时发生的停顿 CPU 正在尝试写入。
我不清楚的是我们是否可以使用这种方法 而无需 glMapBuffer*()
,或者 glMapBuffer*()
是否是孤儿化想法的组成部分和避免失速?我问这纯粹是为了避免对现有代码库进行不必要的更改,尽管我知道 glMapBuffer*()
比在长 运行.
glBufferData()
本质上是更好的选择
(请针对 OpenGL ES 2.0 做出具体回答,除非答案是跨 GL 版本的通用答案。)
答案在 official location:
The first way is to call glBufferData with a NULL pointer, and the exact same size and usage hints it had before. This allows the implementation to simply reallocate storage for that buffer object under-the-hood. Since allocating storage is (likely) faster than the implicit synchronization, you gain significant performance advantages over synchronization. And since you passed NULL, if there wasn't a need for synchronization to begin with, this can be reduced to a no-op. The old storage will still be used by the OpenGL commands that have been sent previously. If you continue to use the same size over-and-over, it is likely that the GL driver will not be doing any allocation at all, but will just be pulling an old free block off the unused buffer queue and use it (though of course this isn't guaranteed), so it is likely to be very efficient.
You can do the same thing when using glMapBufferRange with the GL_MAP_INVALIDATE_BUFFER_BIT. You can also use glInvalidateBufferData, where available.
所以我想可以安全地假设孤立只需要 glBufferData()
个调用。