Forums - Timer Trouble

2 posts / 0 new
Last post
Timer Trouble
nicholas.howe
Join Date: 21 Jul 16
Posts: 16
Posted: Thu, 2016-09-01 13:28
I am having trouble getting reliable results from timer queries in OpenGL ES 3.1 on my Samsung Galaxy S7 Edge SM-G935A with GearVR.
 
According to the EXT_disjoint_timer_query spec, times returned from queries are in nanoseconds.  I have a simple Unity test scene that draws a few boxes.  Timing on my PC indicates the boxes render in about 40 microseconds, which sounds reasonable to me.  On my phone, the boxes render in about 4 microseconds, according to my timer code.  This seems suspicious, because I generally expect my PC to be more powerful than my phone.
 
The Snapdragon Profiler indicates the scene might be rendering in ~5 milliseconds, assuming the scene is rendering at 16.67 ms/frame and its GPU% Utilization metric of ~30% can be used to determine how much of that time is spent rendering, and my app is the only one doing significant GPU work.
 
That made me wonder if the queries are returning times in microseconds rather than nanoseconds.  To try to determine if that is the case, I wrote the following code.
 
// ...
 
namespace
{
   GLint64 nextGpuTime = 0;
   std::uint64_t nextCpuTime = 0;
   std::uint64_t gpuTimeElapsed = 0;
   std::uint64_t cpuTimeElapsed = 0;
}
 
// ...
 
   GLint64 lastGpuTime = nextGpuTime;
   glGetInteger64vEXT(GL_TIMESTAMP_EXT, &nextGpuTime);
   if (lastGpuTime)
      gpuTimeElapsed += std::uint64_t(nextGpuTime - lastGpuTime);
 
   timespec now;
   clock_gettime(CLOCK_MONOTONIC, &now);
   std::uint64_t lastCpuTime = nextCpuTime;
   nextCpuTime = now.tv_sec;
   nextCpuTime *= 1000000000;
   nextCpuTime += now.tv_nsec;
   if (lastCpuTime)
      cpuTimeElapsed += nextCpuTime - lastCpuTime;
 
   __android_log_print(ANDROID_LOG_INFO, "Profiler", "GPU:CPU timer ratio %f.", double(gpuTimeElapsed) / cpuTimeElapsed);
 
The spec says something precise about what getting the timestamp like this does in relation to all prior commands reaching the GL server.  Here, I hope it reasonably instantly returns the current time according to the GPU.  Then I compare it to the CPU time.  All the times are supposed to be in nanoseconds.  I invoke this code after every query.  After doing so, the behavior of the timer queries changes.  They start providing results that seem much more likely: ~3 ms to render the boxes.  I found that if I have the Snapdragon Profiler attached to the phone, the GPU:CPU timer ratio is 1.  If I don't, it is generally around 0.6, and my queries indicate the scene renders in ~2 ms.  I wondered if the profiler disables throttling, and if throttling causes the queries to report timings incorrectly.
 
I get similar results using either a time-elapsed query or a pair of timestamp counter queries.
 
Any idea why I get such strange results?
Is there some reason why I should have to read the timestamp on the CPU after beginning and ending each GPU time-elapsed query in order to get accurate timings?
Is there some reason why the timers' ratio should not be 1?
Are the timings affected by throttling?
 
I tried modifying the 03_DrawTriangle tutorial from the AdrenoSDK and get similar results.  The timings are very different if I read the GL timestamp.  However, here attaching the profiler doesn't make a difference to the timer ratios, which is around 0.4 GPU:CPU.
 
  • Up0
  • Down0
mhfeldma Moderator
Join Date: 29 Nov 12
Posts: 310
Posted: Tue, 2016-09-06 07:16

There are some issues with the EXT_disjoint_timer query timestamp behavior that we are planning to address.  For now, you should try just begin and end query to get the timings. 

Also we're not aware of any impact the Snapdragon Profiler might have on throttling the hardware.  If you can put together a simple test app, we can take a closer look

  • Up0
  • Down0
or Register

Opinions expressed in the content posted here are the personal opinions of the original authors, and do not necessarily reflect those of Qualcomm Incorporated or its subsidiaries (“Qualcomm”). The content is provided for informational purposes only and is not meant to be an endorsement or representation by Qualcomm or any other party. This site may also provide links or references to non-Qualcomm sites and resources. Qualcomm makes no representations, warranties, or other commitments whatsoever about any non-Qualcomm sites or third-party resources that may be referenced, accessible from, or linked to this site.