Your SlideShare is downloading. ×
Android High performance in GPU using opengles and renderscript
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Saving this for later?

Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime - even offline.

Text the download link to your phone

Standard text messaging rates apply

Android High performance in GPU using opengles and renderscript

6,173
views

Published on

Published in: Technology

0 Comments
7 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
6,173
On Slideshare
0
From Embeds
0
Number of Embeds
7
Actions
Shares
0
Downloads
60
Comments
0
Likes
7
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. High Performance Graphics and Compute OpenGLES and RenderScript Arvind Devaraj Limitless Arvind Devaraj
  • 2. slideshare.net/darvind/ Limitless Arvind Devaraj
  • 3. Agenda ● Introduction : Graphics terms ● Graphics on GPU ● OpenGL Android Graphics ● Graphics Pipeline ● Shaders ● High Performance Compute on GPU ● RenderScript Limitless Arvind Devaraj
  • 4. CPU versus GPU ● CPU – good at executing sequential code – ● Handles branches well – Same code, multiple data GPU – Limitless Parallelism (ideal for image rendering) Arvind Devaraj
  • 5. Graphics Terms ● ● ● OpenGLES : Graphics API for doing 3D operations on GPU / CPU Primitives : lines, point, triangles Texture : make the image realistic by adding bitmap Limitless Arvind Devaraj
  • 6. Graphics on GPU Wireframe of model Polygonated Limitless Arvind Devaraj
  • 7. Graphics Pipeline Vertex Pixel operations Vertex Transformation Rasterize the triangle to pixels Limitless Arvind Devaraj
  • 8. OpenGL Driver Converts API call to commands – glDraw() Commands executed in GPU / CPU Implementation of the Graphics Pipeline Limitless Arvind Devaraj
  • 9. OpenGLES Android Graphics ● Graphics Library for 3D Limitless Arvind Devaraj
  • 10. Android Graphics Classes GLSurfaceView GLSurfaceView.Renderer ➢ View - connects SurfaceView to OpenGLES library ➢ Renderer - responsible for rendering a frame Limitless Arvind Devaraj
  • 11. GLSurfaceView          GLSurfaceView view = new GLSurfaceView(this);     view.setRenderer(new SquareRenderer()); Limitless Arvind Devaraj
  • 12. GLSurfaceView.Renderer public class SquareRenderer implements GLSurfaceView.Renderer {     public void onSurfaceCreated(GL10 unused, EGLConfig config) {             Code when surface is created     }     public void onDrawFrame(GL10 unused) { draw() - Code for drawing the frame ( Square )     }     public void onSurfaceChanged(GL10 unused, int width, int height)   {         When surface is changed (rotated etc)     } } Limitless Arvind Devaraj
  • 13. GLSurfaceView.Renderer ● The renderer is responsible for making OpenGL calls to render a frame. – onDrawFrame() responsible for drawing the current frame – OnSurfaceChanged() called when surface size changes – OnSurfaceCreated() called when surface is created Limitless Arvind Devaraj
  • 14. Drawing a Square draw() {   float coords[] = { ....     }; vertex 'buffer' created with the coords glVertexPointer(buffer) : } glDrawArrays(TRIANGLE_STRIP ...); , Limitless Arvind Devaraj
  • 15. Drawing a Square draw() {   float squareCoords[] = { ....     }; ByteBuffer vbb = ....   squareVB = vbb.asFloatBuffer();    squareVB.put(squareCoords);  gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer); } gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP 0, vertices.length / 3); , Full code: https://github.com/arvind-devaraj/androidopengles/blob/master/3_SquareRenderer/src/com/example/graphics1/Square.java Limitless Arvind Devaraj
  • 16. Drawing a Square draw() {   float squareCoords[] = { ....     }; ByteBuffer vbb = ....   squareVB = vbb.asFloatBuffer();    squareVB.put(squareCoords);  gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer); } gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP 0, vertices.length / 3); , Full code: https://github.com/arvind-devaraj/androidopengles/blob/master/3_SquareRenderer/src/com/example/graphics1/Square.java Limitless Arvind Devaraj
  • 17. OpenGL Rendering Pipeline Limitless Arvind Devaraj
  • 18. Shaders ● Shaders are programs that execute on the GPU ● Shader programs operate on – Each vertex – Each pixel Limitless Arvind Devaraj
  • 19. Shader Programs • Vertex Shader – operates on each vertex • Fragment Shader – operates on each pixel • Shaders are compiled and linked ( like any program ) • Executable is sent to the GPU Limitless Arvind Devaraj
  • 20. Limitless Arvind Devaraj
  • 21. Vertex Shader attribute vec4 vertexPosition; void main(){      gl_Position = vertexPosition * 2;   } Fragment Shader precision mediump float; void main(){     gl_FragColor = ( color.r + color.g + color.b ) / 3; } Limitless Arvind Devaraj
  • 22. Program running on GPU/CPU Limitless Arvind Devaraj
  • 23. CPU – GPU communication Limitless Arvind Devaraj
  • 24. GPU for General Programs ● Graphics is accelerated by the GPU ● Can GPU accelerate other programs ? – ● e.g. Matrix multiply, encryption OpenCL, CUDA, Renderscript are API – used for general purpose GPU Limitless Arvind Devaraj
  • 25. RenderScript ● A high level API to access GPU ● Provides high performance Compute ● Provides uniform API across multiple SoC ● Alternative is NDK (but NDK is platform specific) Limitless Arvind Devaraj
  • 26. RenderScript – Use cases ● What functions can be accelerated – Graphics – Image Processing – Encryption – Signal processing – Mathematical functions Limitless Arvind Devaraj
  • 27. RenderScript - Flow Limitless Arvind Devaraj
  • 28. RenderScript – CPU side Class Hello extends Activity { Allocation input, output; Allocation is how you get data to RS, so that it is processed by kernel Create a script (kernel) that specifies the function Run script for each element in allocation } Limitless Arvind Devaraj
  • 29. RenderScript – CPU side Class Hello extends Activity { Allocation input; Allocation output; RenderScript rs = new RenderScript() ScriptC_func script = new ScriptC_func(...) } script.forEach_root(input, output) Allocation is how you get data to RS, so that it is processed by kernel Limitless Arvind Devaraj
  • 30. Renderscript Java interaction Limitless Arvind Devaraj
  • 31. RenderScript – GPU side func.rs void root (char *in , char *out) { *out = *in * 2 } Renderscript code is compiled to device independent Bitcode Bitcode is dynamically interpreted by runtime for specifi GPU Limitless Arvind Devaraj
  • 32. RenderScript ● ● Advantages : Compared to NDK, provides an easy device agnostic way to accelerate performance on GPU Disadvantages : C99 standard, debugging is restricted Limitless Arvind Devaraj
  • 33. Renderscipt - Summary ● Renderscript is an API to access GPU ● Used for High Performance ● High Performance Compute / Graphics ● Compute, Math , FFT, convolution, Signal processing ● Support Graphics – but not a replacement for OpenGL ● Works on all GPUs ( if supported by SoC ) otherwise on CPU Limitless Arvind Devaraj
  • 34. Renderscript potential Limitless arvind.iisc@gmail.com arvinddevaraj github, linkedin,twitter Limitless Arvind Devaraj