【发布时间】:2013-11-21 12:07:56
【问题描述】:
我正在一个单独的线程中以 60FPS (16ms) 的速度运行渲染器。
以下代码会产生随机卡顿...
long testTime = System.nanoTime();
GL20.glUniformMatrix4(
GL20.glGetUniformLocation(getProgram(), "projectionMatrix"),
false,
matrix4fBuffer // holds projection matrix
);
testTime = System.nanoTime() - testTime;
if (testTime > 1000000) {
System.out.println("DELAY " + (testTime / 1000000) ); // 22-30ms
}
GL20.glUniformMatrix4 随机调用大约需要 22-30 毫秒(每 10 秒、30 秒、45 秒……),这会导致随机减速(卡顿)。通常需要 0 毫秒(几纳秒)。
我正在测试仅渲染一个对象(使用可编程管道 - 着色器,OpenGL >= 3.3)。
这个例子的其他部分:
getProgram() // simply returns integer
// This is called before GL20.GLUniformMatrix4
FloatBuffer matrix4fBuffer = BufferUtils.createFloatBuffer(16);
projectionMatrix.store(matrix4fBuffer);
matrix4fBuffer.flip();
知道这里发生了什么吗?
编辑: 我忘了提到我在单独的线程中运行渲染和更新。我想可能是 跟线程调度有关吗?
编辑: 好的,我也在单线程环境中对此进行了测试,但问题仍然存在......我还发现对 glUnuformMatrix4 的其他调用不会导致问题,例如:
long testTime = System.nanoTime();
state.model.store(buffer);
buffer.flip();
GL20.glUniformMatrix4(
GL20.glGetUniformLocation(shader.getProgram(), "modelMatrix"),
false,
buffer
);
testTime = System.nanoTime() - testTime;
if (testTime > 16000000) {
System.out.println("DELAY MODEL" + (testTime / 1000000) );
}
【问题讨论】:
-
请使用
-verbose:gc命令行参数验证是否没有进行完全停止的GC暂停。 -
我测试了它,没有 GC 干扰的记录......如果我增加 FPS,我什至会得到更多的延迟(在 120FPS 我得到 260ms 的延迟)......
标签: java performance lwjgl opengl-3