CPU - GPU transfer time

Started by
8 comments, last by x86asm 18 years, 4 months ago
Hi, I'm trying to make a simple benchmark application in which I can measure the time needed to transfer data to and from the GPU. In my benchmark application I use the following code to send the data:
timer.startTimer();
glTexSubImage2D(GL_TEXTURE_RECTANGLE_ARB,0,0,0,texSize,texSize,
		GL_RGBA,GL_FLOAT,data);
timer.stopTimer();
For reading the data back I use:
timer.startTimer();
glReadPixels(0, 0, texSize, texSize,GL_RGBA,GL_FLOAT,result);
timer.stopTimer();
I've placed this code in a loop which iterates 10 times, so that I can calculate an average after the loop. Now, the strange part is that during the first loop sending and receiving takes much much longer than during the remaining loops. I'm wondering what causes this. Has it something to do with caching maybe? If so, how can I prevent this so I can measure the real transfer times. I hope someone can clear this up for me. Thanks in advance.
Advertisement
Quote:
timer.startTimer();
glTexSubImage2D(GL_TEXTURE_RECTANGLE_ARB,0,0,0,texSize,texSize,
GL_RGBA,GL_FLOAT,data);
timer.stopTimer();


You're not measuring anything very useful this way. You think you're measuring how long GL takes to execute glTexSubImage2D, but remember that GL is not running on the CPU. It runs in parallel with your program, in GPU. glTexSubImage2D() just "tells" OpenGL to put that command in the pipeline, then immediately returns without actually having to wait until the command is executed. This is the correct way to time:

glFinish();//Wait until all previous OpenGL operations are finished, so that we don't include them in the timing.timer.startTimer();glTexSubImage2D(...);glFinish();//Wait until glTexSubImage2D() is completed.timer.stopTimer();
Yeah, I knew about that, I've also implemented my benchmark with glFinish() before, but then I read somewhere that glGetTexImage() and glReadPixels() forces an implicit glFinish(), so I removed them again.
my 2 cents... A call to glFlush() may not be useful too ?
- Iliak -
[ ArcEngine: An open source .Net gaming framework ]
[ Dungeon Eye: An open source remake of Eye of the Beholder II ]
using common sense, glTexImage2d HAS to do a glFinish. why? because the data pointer could be delete[]-ed right after it's called! although it's possible that the drivers buffers it by copying the data to a buffer somewhere on the local ram, but I doubt it'd do that. could somebody enlighten us all here?
glTexImage2d causes the driver to take a copy of the data, as to if that data ends up in VRAM or in system ram doesnt matter to the application.

There is no reason for ANY commands to be issued to the GPU when the function is called, the function could just cause the data to be copied to system ram and associated with the correct texture data. The upload doesnt have to occur until a later time.
But what if it *does* matter to the application? Do you have any recommendation for timing actual transfers (Pre OpenGL 1.2)?
not using texture objects might well be enuff to simulate it, upload and bind the texture right away.

Althogh there are still no garrentees, its upto the driver what happens.
If you have an nVidia card with the GL_NV_fence extension, then you can precisely check the amount of time a specific OpenGL call takes. I use it in my own stuff for timing GPU performance as well as CPU performance.

See the extension under "Can fences be used as a form of performance monitoring?" for some sample code too.
I think you have to call glFlush(). That is the only way I got reasonable results from timing texture uploads.
"I'm a rockstar, baby, baby , baby" -Bizarre

This topic is closed to new replies.

Advertisement