运行
之间有区别吗?glFinish()
并正在运行
glFenceSync(...)
glClientWaitSync(...)
超时?
我尝试做的事情:我运行一系列OpenGL命令,我想知道每个命令需要多长时间。如果没有上述任何命令,一切都将被流水线化/缓冲,看起来最后一个命令占用了所有处理时间。
timer start
Run Opengl part 1
sync / glFinish
timer measure
Run Opengl part 2
sync / glFinish
timer measure
...
所以我想弄清楚如何最好地衡量"速度"各部分的影响不会影响整体运行时间。
答案 0 :(得分:6)
您提到的所有选项都会影响应用程序的性能,因为它们会使管道停滞不前。在OpenGL中测量时序的现代方法是使用Timer Queries:告诉OpenGL它应该在GPU上执行查询时保存时间戳,因此不需要GPU和CPU之间的同步。例如,代码可能如下所示:
GLuint64 startTime, stopTime;
unsigned int queryID[2];
// generate two queries
glGenQueries(2, queryID);
...
// issue the first query
// Records the time only after all previous
// commands have been completed
glQueryCounter(queryID[0], GL_TIMESTAMP);
// call a sequence of OpenGL commands
...
// issue the second query
// records the time when the sequence of OpenGL
// commands has been fully executed
glQueryCounter(queryID[1], GL_TIMESTAMP);
...
// get query results
// (automatically blocks until results are available)
glGetQueryObjectui64v(queryID[0], GL_QUERY_RESULT, &startTime);
glGetQueryObjectui64v(queryID[1], GL_QUERY_RESULT, &stopTime);
printf("Time spent on the GPU: %f ms\n", (stopTime - startTime) / 1000000.0);
(代码取自Lighthouse3d.com)。
另一种选择是将glBeginQuery
与GL_TIME_ELAPSED
参数一起使用,这也在链接文章中有所描述。