【发布时间】:2014-05-17 06:39:05
【问题描述】:
这是我的秒表课
public class Benchmark {
static long starttime;
static ArrayList<Long> timeList = new ArrayList<Long>();
public static void start() {
glFinish();
starttime = System.nanoTime();
}
public static void stop() {
glFinish();
timeList.add(System.nanoTime() - starttime);
if(timeList.size() > 10) {
Long total = (long) 0 ;
for(Long time : timeList) {
total += time;
}
System.out.println(((float)total / timeList.size())/1000000 );
timeList.clear();
}
}
这是简单的基准测试
Benchmark.start();
glBindVertexArray(vao);
Benchmark.stop();
我正在读取 1ms 的值,这怎么可能?我的秒表坏了吗?我注意到如果我注释掉一些绘图调用,那么它会读取 0.2ms 的较低值,这很奇怪,因为它不应该影响这一点。
绑定真的这么贵还是有什么问题?
【问题讨论】:
-
为什么绘图调用不会影响这个?如果你不使用
glFinish()那么绘图调用不会影响这一点,但你会;) -
我对 openGL 代码比你的手表更感兴趣。不过,你为什么要使用 glFinish()。您使用的是旧版 openGL 吗?
-
实际上,唯一的原因是它需要你超过纳秒(这里谈论现代硬件)是因为你正在使用
glFinish() -
@CoffeeandCode 不一定,验证可能会有可衡量的开销。尽管顶点数组通常是最便宜/最简单的验证资源。不过,你有一个很好的观点......所测量的大部分时间是
glFinish (...)的结果。 -
@AndonM.Coleman 我只是假设驱动程序很好 :L 但
glFinish调用实际上会非常昂贵(当然不是实际调用本身,只是副作用),因为它在返回之前等待任何帧缓冲区/连接/状态更改完成。这意味着任何绘图调用或缓冲区绑定。
标签: opengl graphics shader lwjgl