如何优化 VBO/IBO 以最大化 GPU 缓存使用
How to Optimizing a VBO/IBO to maximize GPU cache usage
我在 CUDA 上使用 Marching Cubes 算法 运行 从体积数据生成网格。
我尝试过保存网格并以 3 种方式渲染它。
- 将一组粗略的三角形保存为连续的顶点数据数组。
如果第一次通过,我估计大小,创建一个 OpenGL VBO,
将其映射到CUDA并按照以下格式将顶点数据写入其中
V0x, V0y, V0z, N0x, N0y, N0z, V1x, V1y, V1z, N1x, N1y, N1z, ...
并使用glDrawArrays()
绘制它。
Redundant Vertices in VBO, Redundant Vertices per Cube, No Indices.
- 从步骤 1 中获取网格,使用
thrust::sort()
和 thrust::unique()
删除冗余顶点,使用 thrust::lower_bound()
计算索引。将结果保存到映射到 CUDA 的 OpenGL VBO/IBO。
使用 glDrawElements()
. 绘制模型
No Redundant Vertices in VBO, Generated Indices.
- 为每个立方体生成一个唯一的顶点列表,将它们连同它们在 IBO 中形成三角形的索引一起存储在 VBO 中。使用
glDrawElements()
. 渲染
Redundant Vertices in VBO, Unique Vertices per Cube, Generated Indices per Cube
现在,我在相同 ISO 值下针对相同数据集获得的 FPS 是
Method 1 : 92 FPS, 30,647,016 Verts, 0 Indices
Method 2 : 122 FPS, 6,578,066 Verts, 30,647,016 Indices
Method 3 : 140 FPS, 20,349,880 Verts, 30,647,016 Indices
尽管方法 2 产生的顶点数量最少,但 FPS 很低。我相信这是因为索引的顺序可以最大限度地减少 GPU 缓存的使用。方法 3 的索引顺序获得更高的 GPU 缓存使用率,因此 FPS 更高。
如何modify/amend方法2产生更高的FPS?
有两件事可以提供帮助:
- 尝试通过大致按照绘制顺序放置顶点来优化数据缓存的使用
- 正在尝试优化 post transform cache usage (there is an algorithm to do that here,可能可以在网上找到实现)
我在 CUDA 上使用 Marching Cubes 算法 运行 从体积数据生成网格。
我尝试过保存网格并以 3 种方式渲染它。
- 将一组粗略的三角形保存为连续的顶点数据数组。 如果第一次通过,我估计大小,创建一个 OpenGL VBO, 将其映射到CUDA并按照以下格式将顶点数据写入其中
V0x, V0y, V0z, N0x, N0y, N0z, V1x, V1y, V1z, N1x, N1y, N1z, ...
并使用glDrawArrays()
绘制它。
Redundant Vertices in VBO, Redundant Vertices per Cube, No Indices.
- 从步骤 1 中获取网格,使用
thrust::sort()
和thrust::unique()
删除冗余顶点,使用thrust::lower_bound()
计算索引。将结果保存到映射到 CUDA 的 OpenGL VBO/IBO。 使用glDrawElements()
. 绘制模型
No Redundant Vertices in VBO, Generated Indices.
- 为每个立方体生成一个唯一的顶点列表,将它们连同它们在 IBO 中形成三角形的索引一起存储在 VBO 中。使用
glDrawElements()
. 渲染
Redundant Vertices in VBO, Unique Vertices per Cube, Generated Indices per Cube
现在,我在相同 ISO 值下针对相同数据集获得的 FPS 是
Method 1 : 92 FPS, 30,647,016 Verts, 0 Indices
Method 2 : 122 FPS, 6,578,066 Verts, 30,647,016 Indices
Method 3 : 140 FPS, 20,349,880 Verts, 30,647,016 Indices
尽管方法 2 产生的顶点数量最少,但 FPS 很低。我相信这是因为索引的顺序可以最大限度地减少 GPU 缓存的使用。方法 3 的索引顺序获得更高的 GPU 缓存使用率,因此 FPS 更高。
如何modify/amend方法2产生更高的FPS?
有两件事可以提供帮助:
- 尝试通过大致按照绘制顺序放置顶点来优化数据缓存的使用
- 正在尝试优化 post transform cache usage (there is an algorithm to do that here,可能可以在网上找到实现)