Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Performance of uploading mat4 attributes (VBO) versus mat4 uniforms (UBO)

Tags:

opengl

glsl

If I'm doing instanced rendering and need to send one mat4 per instance to the vertex shader, which approach is likely to be faster for large numbers of instances?

  1. Using an instanced mat4 attribute (glVertexAttribDivisor) and sending the mat4s into the VBO each frame (glBufferData)
  2. Using an array of mat4 uniforms in a uniform block, updating the array every frame using a uniform buffer object and accessing the appropriate mat4 using gl_InstanceID as the array index
like image 441
user1349637 Avatar asked Jul 29 '14 18:07

user1349637


1 Answers

Based on comments/answers from robinjam, GuyRT and Brett Hale I did some testing. The test rendered 40000 instances of the same mesh (a triangle) updating each instance's model matrix every frame. My GPU is a GeForce GTX 460 SE.

Here are my results:

  • mat4 uniforms (updated via glUniformMatrix4fv) with 254 instances per draw call (limited due to uniform limits) = 160 fps

  • mat4 uniforms in a block (updated via a UBO) with 254 instances per draw call (limited due to uniform limits) = 260 fps

  • mat4 attributes (updated via a VBO) with 40000 instances per draw call = 287 fps

like image 97
user1349637 Avatar answered Nov 10 '22 01:11

user1349637