Huge increase in CPU usage in OpenGL ES on Android after 10 seconds

I have a fairly simple OpenGL ES app running on Android - it just loads a texture atlas and then loads the tiles at the given positions

Based on this tutorial: http://androidblog.reindustries.com/a-real-open-gl-es-2-0-2d-tutorial-part-1/

After about 10 seconds of rendering, the CPU will increase significantly (as shown in the picture) and the time taken to increase each frame from about 1ms to about 14ms (works on my Nexus 5)

CPU Usage Graph

I have counted everything in the method onDrawFrame

and this is completely a mistakeGLES20.glDrawElements

My whole render method is like this:

GLES20.glUseProgram(ShaderTools.sp_Image);

GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);

int mPositionHandle = GLES20.glGetAttribLocation(ShaderTools.sp_Image, "vPosition");
GLES20.glVertexAttribPointer(mPositionHandle, 3, GLES20.GL_FLOAT, false, 0, vertexBuffer);
GLES20.glEnableVertexAttribArray(mPositionHandle);

int mTexCoordLoc = GLES20.glGetAttribLocation(ShaderTools.sp_Image, "a_texCoord");
GLES20.glVertexAttribPointer(mTexCoordLoc, 2, GLES20.GL_FLOAT, false, 0, uvBuffer);
GLES20.glEnableVertexAttribArray(mTexCoordLoc);

int mtrxhandle = GLES20.glGetUniformLocation(ShaderTools.sp_Image, "uMVPMatrix");
GLES20.glUniformMatrix4fv(mtrxhandle, 1, false, mtrxProjectionAndView, 0);

int mSamplerLoc = GLES20.glGetUniformLocation(ShaderTools.sp_Image, "s_texture");

GLES20.glUniform1i(mSamplerLoc, 0);

GLES20.glDrawElements(GLES20.GL_TRIANGLES, indices.length, GLES20.GL_UNSIGNED_SHORT, drawListBuffer);

GLES20.glDisableVertexAttribArray(mPositionHandle);
GLES20.glDisableVertexAttribArray(mTexCoordLoc);

      

If anyone can shed some light on what might be causing this and how to fix it, I would be very grateful :-)

+3


source to share


2 answers


The Nexus5 is based on the Qualcomm chipset and has an Adreno 330 GPU.

Qualcomm chipsets have been known to quickly shut down GPU frequency if your application is quite graphics intensive / has no / fps limiter at (huge) native resolution (therefore not using a hardware scanner ).

So, what is probably going on is that the GPU frequency gets throttle and then you see a high CPU load which represents "CPU waiting for GPU" at the end of the frame.

It's also possible the CPU gets throttled, but in my experience this tends to happen on Samsung phones due to DVFS , not much on Nexus ...



The good news is that there is actually a tool to monitor the current CPUs and GPU frequencies on Qualcomm devices called Trepn Profiler , and you can use it on non-loaded devices.

So, you have to install this tool, configure it to display the GPU clock and cpu00 clock as an overlay, then run the application and you can see in real time how the GPU and / or CPU decays over time.

Additional note: Throttling will happen faster when the phone is charging.

+1


source


A possible explanation is that mobile devices throttle their processor power to conserve battery. The device may detect that you are using a very small processor in order to reduce the power of your processor to conserve battery. I don't remember ever seeing this phenomenon myself, but I know it exists, not sure if this is the case here.



Edit: Perhaps you can measure if your battery usage is negatively correlated with your CPU usage in this case.

+1


source







All Articles