News for hackers. Stuff that matters.
Re:Android Performance Case Study by kevingadd on Sunday December 02, 2012 @11:23AM (#4861588)
The OP is slightly overstating the impact of overdraw as a general thing. While in this particular case it is likely that the overdraw is the cause of poor performance in this application, it's not always going to be the cause.

Overdraw primarily eats up memory bandwidth. Bandwidth isn't the only resource you have to worry about on a GPU (though on a mobile, it's certainly important). Equally important can be the time spent running pixel and/or vertex shaders when actually drawing onscreen elements - it's quite easy for a poorly written pixel shader to add multiple milliseconds to the time taken to render one fullscreen image on an embedded device.

Unfortunately none of the steps he takes in this article, until the OpenGL ES Trace near the end, appear to give you any of the information you'd need to figure out whether overdraw is actually your problem. Maybe it's a safe bet that for most Android apps, overdraw is the issue, because they're using Skia and thus don't have access to use custom shaders?

On the other hand, that Hierarchy Viewer feature in the debug tools looks really great. I wish more SDKs offered features that nice.

Re:Android Performance Case Study by RomainGuy on Sunday December 02, 2012 @12:37PM (#4861833)
You are right but apps are not in control of the shaders, at least not directly. It is possible to make the View system use complicated shaders but it's rare and I've never seen this be the cause of performance issues (except when we had bugs in our shaders generation code.)

Most UI elements are drawn with a quad and trivial shaders (a couple of multiplications in the vertex shader, a texture lookup and modulate in the fragment shader.)

In my years of working on Android I have learned that poor framerate is most of the time (not always) a combination of blocking the UI thread for too long and drawing too much.

I should have made this clearer but a lot of overdraw above 2x will likely be one of the causes of performance issue. Not all devices will behave the same of course but it's a reasonable average (devices with more bandwidth tend to have higher screen resolutions.)

What's important to remember however is that overdraw often indicates other problems. This typically the application uses more views than it needs. This impacts performance in other ways: higher memory consumption, larger tree that takes longer to manager and traverse, longer startup times, more work for the renderer (sorting display lists, managing OpenGL state, etc.)

Re:Android Performance Case Study by randallu on Sunday December 02, 2012 @12:23PM (#4861797)
Not really, all of the shaders come from the Android View System and are pretty simple (could probably have been done with the fixed function pipeline).

In general, you're right, you can "shade too hard" (consuming too many GPU cycles) and/or "shade too much" (consuming too much memory bandwidth); In my experience on mobile "shading too much" is more common and easier to do (especially in the era of 2560x1600 displays...). Maybe because the framebuffer and textures are on system memory and not GDDR5/whatever like on a desktop.

Re:Android Performance Case Study by corysama on Sunday December 02, 2012 @05:24PM (#4862807)
In the case of pixels hidden behind views that do not use blending, overdraw only eats a very small amount of memory bandwidth checking the depth/stencil buffer for each covered pixel. This check is highly optimized in the hardware to reject whole blocks of pixels while reading only a few bits. (Android UI does use the depth/stencil buffer, right???) However, I don't think that's what the article is talking about. "You can see that the transparent pixels of the bitmaps count against your overdraw."

In the case of visible views that do use blending, overdraw multiplies the time spent running shader computation right along side multiplying the full memory bandwidth consumption of the shader (much more than just checking the depth/stencil buffer). It's true that it's totally possible to write slow shaders that chug with only 1x overdraw. But, at 3x overdraw it will be 3x as bad because you are running the whole function 3x per pixel.

Re:Android Performance Case Study by RomainGuy on Sunday December 02, 2012 @06:20PM (#4863025)
Android does not use the depth buffer. The UI toolkit draws back to front. We are thinking about ways to improve this but most apps draw blended primitives back to front. An optimization I want to get in is to resort the render tree to batch commands by type and state. A side effect of this will be the ability to cull invisible primitives.

The stencil is not used at the moment (well... that's actually how overdraw debugging is implemented) because the hardware renderer only support rectangular clipping regions and thus relies on the scissor instead. Given how the original 2D API was designed, using the stencil buffer for clipping could eat up quite a bit of bandwidth or require a rather complex implementation.

It is planned to start using the stencil buffer to support non-rectangular clipping regions but this will have a cost.

Remember that the GPU rendering pipeline was written for an API that was never designed to run on the GPU and some obvious optimizations applied to traditional rendering engines do not necessarily apply.

Re:Android Performance Case Study by corysama on Sunday December 02, 2012 @07:00PM (#4863185)
That's actually what I expected, but I couldn't find any reference. So, I defaulted to the optimistic, but probably wrong stance hoping that someone would correct me. Thanks!

This means that, at least on traditional forward rendering GPUs (Nvidia, Adreno), overdraw is full cost even for pixels covered by opaque views. Do the PowerVR chips still get effectively-zero opaque overdraw from their tile-based-deferred-rendering approach?

Meanwhile, I'm not totally clear how hidden surface removal works on Mali chips. They use TBDR, but still recommend drawing front-to-back to avoid overdraw http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc....