glDrawElements() terrible lag, glDrawArrays fine?

Started by
17 comments, last by Conoktra 12 years, 9 months ago
in your case using a index array should be slower then just using the vertex array, cause the little speedup by the indices is very small to the performance overhead produced by the additional data upload.

Did u try using Buffer Objects ?

the performance shouldn't drop to 1fps of course, but this could perhaps fix some hidden bugs
Advertisement
The performance problem is due to the fact that you are not using vertex buffer objects (VBOs). Without VBOs, the driver has to copy all of your vertex data into the command buffer when you call glDrawArrays() or glDrawElements() before those functions can return. In today's multithreaded drivers, that can get very expensive, especially because putting all that data in the command buffer can cause a lot of flushes to happen, which cause the driver threads to have to synchronize with each other. The performance is worse with glDrawElements() because the driver is actually de-indexing your vertex data.

For any kind of reasonable performance, you absolutely must put the vertex data and index data in VBOs. Then, the glDrawArrays() and glDrawElements() functions can return immediately, no data has to be copied by the driver, and no thread synchronization has to occur in the driver.
Interesting, and it definitely makes sense. I was hoping to avoid VBO's for the fact that as the terrain mesh is modified I have to constantly re-upload the data anyway (at least this way I don't have to constantly re-upload index data =D). I will give it a try and report back.

Thanks for everyone's help thus far :).

The performance problem is due to the fact that you are not using vertex buffer objects (VBOs). Without VBOs, the driver has to copy all of your vertex data into the command buffer when you call glDrawArrays() or glDrawElements() before those functions can return. In today's multithreaded drivers, that can get very expensive, especially because putting all that data in the command buffer can cause a lot of flushes to happen, which cause the driver threads to have to synchronize with each other. The performance is worse with glDrawElements() because the driver is actually de-indexing your vertex data.

For any kind of reasonable performance, you absolutely must put the vertex data and index data in VBOs. Then, the glDrawArrays() and glDrawElements() functions can return immediately, no data has to be copied by the driver, and no thread synchronization has to occur in the driver.


I don't think that's quite true. There are plenty of practical real-world examples that don't use VBOs but which can still get reasonable performance despite that (even on today's multithreaded hardware), and - in fact - if you're using a dynamic VBO that you must refill every time you draw from it, then client-side arrays are most likely going to be the fast path anyway. Plus, while glDrawElements certainly has some additional overhead, it's nowhere near that much. A drop to 1 FPS is certainly not symptomatic of not using VBOs. (Interesting to note that if you do use VBOs but don't have a good understanding of how the hardware and CPU/GPU synchronisation works then you will lose performance with them when compared to client-side arrays, typically from multiple GPU-stalls per frame.)

There's something else wrong here. I wonder what would happen if the OP split his drawing into two batches of 8k quads each.

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

That's why I gave him that link. It just draws 2 triangles and his performance is even worst.
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
Ive been thinking perhaps it is a problem with GLEW or the actual radeon driver :(.
I had sometimes the same thoughts, but only in very rare cases it is a problem of the driver.

Just test your program on different machines(send it to friends for example) and see if they have the same problem.

[quote name='Eric Lengyel' timestamp='1309300638' post='4828857']
The performance problem is due to the fact that you are not using vertex buffer objects (VBOs). Without VBOs, the driver has to copy all of your vertex data into the command buffer when you call glDrawArrays() or glDrawElements() before those functions can return. In today's multithreaded drivers, that can get very expensive, especially because putting all that data in the command buffer can cause a lot of flushes to happen, which cause the driver threads to have to synchronize with each other. The performance is worse with glDrawElements() because the driver is actually de-indexing your vertex data.

For any kind of reasonable performance, you absolutely must put the vertex data and index data in VBOs. Then, the glDrawArrays() and glDrawElements() functions can return immediately, no data has to be copied by the driver, and no thread synchronization has to occur in the driver.


I don't think that's quite true. There are plenty of practical real-world examples that don't use VBOs but which can still get reasonable performance despite that (even on today's multithreaded hardware), and - in fact - if you're using a dynamic VBO that you must refill every time you draw from it, then client-side arrays are most likely going to be the fast path anyway. Plus, while glDrawElements certainly has some additional overhead, it's nowhere near that much. A drop to 1 FPS is certainly not symptomatic of not using VBOs. (Interesting to note that if you do use VBOs but don't have a good understanding of how the hardware and CPU/GPU synchronisation works then you will lose performance with them when compared to client-side arrays, typically from multiple GPU-stalls per frame.)

There's something else wrong here. I wonder what would happen if the OP split his drawing into two batches of 8k quads each.
[/quote]

I didn't see the mention of 1 fps in the first post before. Yeah, there is something else going on. However, everything I said is valid. I don't mean that not using VBOs will perform terribly, but you should always be able to beat client-side arrays by using VBOs, even for dynamic vertex data that changes every frame. Client-side arrays are never faster unless you're talking about a very small number of vertices. In either case (dynamic VBO or client-side arrays), the driver has to copy the vertex data to an internal buffer, and the hardware has to read that data through a DMA. The difference is that by using a VBO, you don't risk filling up the command buffer and causing a flush that could stall the CPU, and you don't pay for the CPU copy if the vertex data doesn't change. And don't forget that the driver has to de-index the vertex data if you use client-side arrays with glDrawElements(). There's no way that's ever going to be faster than using VBOs.
Alright, so I finally got home and tested the same code on a GeForce GTX 460, and it gets about 500 FPS--which is even more baffling. I am leaning more and more towards a driver bug.

This topic is closed to new replies.

Advertisement