跑步之间有区别吗?
glFinish()
并运行
glFenceSync(...) glClientWaitSync(...)
大超时?
我正在尝试做的事情:我运行一个OpenGL命令管道,我想要计算每个命令需要多长时间.如果没有上述任何命令,一切都将被流水线化/缓冲,并且看起来最后一个命令占用了所有处理时间.
timer start Run Opengl part 1 sync / glFinish timer measure Run Opengl part 2 sync / glFinish timer measure ...
所以我试图弄清楚如何最好地测量各个部件的"速度",而不会影响整个运行时间.
您提到的所有选项都会影响应用程序的性能,因为它们会使管道停滞不前.在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
参数,其也被链接的文章中描述.