Upgrade to Pro — share decks privately, control downloads, hide ads and more …

[Refael Ozeri, Yonatan Levin] GPU. The journey ...

[Refael Ozeri, Yonatan Levin] GPU. The journey from code to pixel

Presentation from GDG DevFest Ukraine 2018 - the biggest community-driven Google tech conference in the CEE.

Learn more at: https://devfest.gdg.org.ua

__

In this session we will talk about our GPU, did you ever asked yourself what happens behind the scenes when we see a text view? or how does our code turn into pixels?

Google Developers Group Lviv

October 12, 2018
Tweet

More Decks by Google Developers Group Lviv

Other Decks in Programming

Transcript

  1. How is motion perceived? 12fps Flip Book 24fps Movies Fluid

    Motion 60fps + No Difference 60fps Smooth Motion
  2. How is motion perceived? So.. 60 fps is our target.

    A new frame is displayed every _____ milliseconds
  3. How is motion perceived? So.. 60 fps is our target.

    A new frame is displayed every 16.666.. milliseconds
  4. DisplayList A sequence of graphics commands needed to be executed

    to render a specific view These commands are a mixture of statements that can be directly mapped to OpenGL commands
  5. OpenGL OpenGL is a cross-language, cross-platform API for rendering 2D

    and 3D vector graphics. The API is typically used to interact with a GPU, to achieve hardware-accelerated rendering.
  6. Execute CPU new View() GPU Polygons Textures DisplayList CPU new

    View() GPU Polygons Textures DisplayList Frame Buffer
  7. input UI Thread animations measure layout draw sync Render Thread

    sync execute get buffer issue swap buffer Graphics get buffer get buffer See more @ I/O 2018 - Drawn out lecture - https://youtu.be/zdQRIYOST64
  8. Tools→ Layout Inspector • Display complete view hierarchy • Access

    to all the views’ properties • Get performance stats Layout Inspector
  9. Fixing Overdraw There are 2 common reasons for overdraw: -

    Redundant backgrounds / Redundant transparency - Wasteful onDraw - Things that aren’t visible at all gets drawn (not using quickReject) - Things that will be overdrawn gets drawn (not using clipRect) Colt McAnlis: https://youtu.be/vkTn3Ule4Ps
  10. QuickReject A method to tell if something can be not

    drawn at all. Call quickReject to see if you can skip drawing of things that will be off screen. REF: https://developer.android.com/reference/android/graphics/Canvas.html
  11. ClipRect ClipRect is a way to avoid OverDraw, By keeping

    your GPU from drawing pixels that you know that will be obscured by other stuff, you refrain from overdraw.
  12. GPU Profiling • A graph per visible app • A

    bar per frame • Render time corresponds height • 16 millis benchmark (green) • Crossing = skipping frame https://developer.android.com/studio/profile/dev-options-rendering.html
  13. VSync/Misc Input Animation Measure/ Layout Draw Sync & Upload Command

    Issue Swap Buffers So many colors.. What do they mean?
  14. Vsync / Misc Time Misc = (vsync timestamp) - (timestamp

    when received) → work on the UI thread between two consecutive frames • Choreographer log : “Missed vsync by XX ms skipping XX frames” High? move work off UI Thread VSync/ Misc Input Animation Measure/ Layout Draw Sync & Upload Command Issue Swap Buffers
  15. Ever seen this? 06-29 23:11:17.796: I/Choreographer(691): Skipped 647 frames! The

    application may be doing too much work on its main thread.
  16. Input Handling App code inside an input event callback. High?

    optimize/offload processing input VSync/ Misc Input Animation Measure/ Layout Draw Sync & Upload Command Issue Swap Buffers
  17. Animation Evaluate all running animators Often : object animator, view

    property animator, and transitions High?(2milis+) check custom animators / unintended work VSync/ Misc Input Animation Measure/ Layout Draw Sync & Upload Command Issue Swap Buffers
  18. Measure / Layout Executing layout and measure callbacks for needed

    view. More on that in a few slides :) VSync/ Misc Input Animation Measure/ Layout Draw Sync & Upload Command Issue Swap Buffers
  19. Draw update (/creates) all display lists + cache. High? •

    complex onDraw() logic • many views invalidated VSync/ Misc Input Animation Measure/ Layout Draw Sync & Upload Command Issue Swap Buffers
  20. Sync & Upload Upload bitmap to the GPU. High? •

    Too many images • Too big of an image VSync/ Misc Input Animation Measure/ Layout Draw Sync & Upload Command Issue Swap Buffers
  21. Command Issue Execution: Android's 2D renderer issuing commands to OpenGL

    to draw and redraw all display lists High? • Complex view (custom?) • Many views redrawing: ◦ Invalidation ◦ animation VSync/ Misc Input Animation Measure/ Layout Draw Sync & Upload Command Issue Swap Buffers
  22. Swap Buffers CPU done rendering and wait for GPU ack.

    High? A lot of GPU work VSync/ Misc Input Animation Measure/ Layout Draw Sync & Upload Command Issue Swap Buffers
  23. - Why 60 fps - The stages of creating a

    frame - Tools that helps you find out what wrong with your app What did we talk about today?