简体   繁体   English

测量渲染时间OpenGL ES 2.0

[英]Measure Render Time OpenGL ES 2.0

I want to measure render performance on various Android devices using OpenGL ES 2.0. 我想使用OpenGL ES 2.0评估各种Android设备上的渲染性能。 I do this by drawing a (textured) quad the size of the screen and drawing it N times. 我通过绘制(带纹理的)四边形屏幕大小并绘制N次来做到这一点。 The basic idea looks like this: 基本思想如下:

start = System.currentTimeMillis();
for (int i = 0; i < N; ++i) {
  GLES20.glDrawArrays(GLES20.GL_TRIANGLE_FAN, 0, v_n);
}
GLES20.glFinish();
time = System.currentTimeMillis()-start;

In reality I store the values and measure the average over a certain amount of render passes, but that is not the problem. 实际上,我存储这些值并在一定数量的渲染过程中测量平均值,但这不是问题。 This approach appeared to go well with my device (Samsung Galaxy SIII) and the HTC Legend. 这种方法似乎与我的设备(三星Galaxy SIII)和HTC Legend配合得很好。 However, the Samsung Galaxy S seems to ignore the glFinish() resulting in a pretty intense (but false) render speed. 但是,三星Galaxy S似乎忽略了glFinish()导致了相当高的渲染速度(但错误)。 I have read before that some devices don't really listen to glFinish() , but if not like this, how can I measure the render speed? 在此之前,我已经读过一些设备并没有真正听过glFinish() ,但是如果不是这样,我该如何测量渲染速度?

I have also tried the other way I have seen all over the internet (mainly in the context of measuring FPS): 我还尝试了另一种遍及互联网的方式(主要是在测量FPS的情况下):

@Override
public void onDrawFrame(GL10 unused) {
  time =  System.currentTimeMillis()-start;
  //store time somewhere
  start = System.currentTimeMillis();
  ...
  //rendering here
  ...
}

Here you measure the time at the beginning of the next call to onDrawFrame(..) with the idea that it would not be called unless the previous rendering has completed. 在这里,您测量下一次调用onDrawFrame(..)时的开始时间,除非您之前的渲染完成,否则将不会调用它。 But this results in the same problem. 但这导致了同样的问题。

Is there another way? 还有另一种方法吗? Or should I just avoid these devices for performance measurements? 还是我应该避免使用这些设备进行性能测量?

Measuring GPU performance can be tricky. 测量GPU性能可能很棘手。 There are a number of things you have to consider, such as how a graphics driver will interpret a glFlush/glFinish and how VSync will effect results. 您需要考虑很多事情,例如图形驱动程序如何解释glFlush / glFinish以及VSync如何影响结果。

Calling glFinish() per-frame will never give a true representation of performance on GPUs that defer work - such as PowerVR - as the architecture relies on processing multiple frames in parallel to achieve optimal performance. 每帧调用glFinish()永远不会真正表示延迟工作的GPU(例如PowerVR)的性能,因为该体系结构需要并行处理多个帧才能获得最佳性能。 On devices where the glFinish() call is honoured (ie the CPU thread blocks until the GPU render is complete), your test will cause the render to be serialized which will incur a significant performance hit. 在执行glFinish()调用的设备上(即,CPU线程阻塞,直到GPU渲染完成为止),您的测试将导致渲染序列化,这将导致性能严重下降。 Also, blocking the CPU thread until GPU work completes will introduce another large overhead. 同样,阻塞CPU线程直到GPU工作完成会带来另一大开销。

When Vsync is enabled, you'll also be measuring time the GPU is waiting for the flip to occur. 启用Vsync后,您还将测量GPU等待翻转发生的时间。 If possible, you should disable Vsync when running performance tests like this or render offscreen (ie to FBOs) so you can avoid the vsync limit. 如果可能的话,您应在运行此类性能测试时禁用Vsync或在屏幕外渲染(即渲染到FBO),以便避免vsync限制。 Alternatively you can use GPU profiling tools, such as Imagination's PVRTune , to obtain accurate timing information for the GPU time spent processing your render. 另外,您可以使用Imagination的PVRTune之类的GPU分析工具来获取有关GPU处理渲染所花费时间的准确时序信息。

The "Micro-benchmark your render on PowerVR Series5, Series5XT and Series6 GPUs" post on the Imagination blog explains best practices for writing performance tests like this. Imagination博客上的“在PowerVR Series5,Series5XT和Series6 GPU上微渲染渲染基准”一文介绍了编写此类性能测试的最佳做法。

You can also use apps like GameBench that work on any android device and will measure the FPS. 您还可以使用像GameBench这样的应用程序,这些应用程序可以在任何Android设备上运行,并且可以测量FPS。 It also retrieves GPU Usage for devices that use Adreno and IMG GPUs. 它还会为使用Adreno和IMG GPU的设备检索GPU使用情况。 The app also collects screenshots so you can understand what was happening when frame rate drops. 该应用程序还会收集屏幕截图,以便您了解帧频下降时发生的情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM