High Performance
Graphics and Compute
OpenGLES and RenderScript

Arvind Devaraj
Agenda
●

Introduction : Graphics terms

●

Graphics on GPU

●

OpenGL Android Graphics

●

Graphics Pipeline

●

Shaders
...
Graphics Terms
●

●

●

OpenGLES : Graphics API for doing 3D operations on GPU /
CPU
Primitives : lines, point, triangles
...
CPU versus GPU
●

CPU
–

good at executing sequential code

–

●

Handles branches well

–

Same code, multiple data

GPU
...
Graphics on GPU
Graphics Pipeline
OpenGLES Android Graphics
●

Graphics Library for 3D
Android Graphics Classes
GLSurfaceView
GLSurfaceView.Renderer

View

➢

- connects SurfaceView to OpenGLES library

Render...
GLSurfaceView
    

    GLSurfaceView view = new GLSurfaceView(this);

    view.setRenderer(new SquareRenderer());
GLSurfaceView.Renderer

●

The renderer is responsible for making OpenGL calls to
render a frame.
–

onDrawFrame() respons...
GLSurfaceView.Renderer
public class SquareRenderer implements GLSurfaceView.Renderer {
    public void onSurfaceCreated(GL...
Drawing a Square
draw() {
 

float coords[] = { ....     };
vertex 'buffer' created with the coords
glVertexPointer(buffer...
Drawing a Square
draw() {
 

float squareCoords[] = { ....     };
ByteBuffer vbb = ....
  squareVB = vbb.asFloatBuffer(); ...
OpenGL Rendering Pipeline
Shaders
●

Shaders are programs that execute on the GPU

●

Shader programs operate on
–

Each vertex

–

Each pixel
Shader Programs
• Vertex Shader – operates on each vertex
• Fragment Shader – operates on each pixel
• Shaders are compile...
Vertex Shader
attribute vec4 vertexPosition;
void main(){
     gl_Position = vertexPosition;
 

}

Fragment Shader
precisi...
CPU – GPU communication
GPU for General Programs
●

Graphics is accelerated by the GPU

●

Can GPU accelerate other programs ?
–

●

e.g. Matrix m...
RenderScript
●

A high level API to access GPU

●

Provides high performance Compute

●

Provides uniform API across multi...
RenderScript – Use cases
●

What functions can be accelerated
–

Graphics

–

Image Processing

–

Encryption

–

Signal p...
RenderScript - Flow
RenderScript – CPU side
Class Hello extends Activity {
Allocation input;
Allocation output;
RenderScript rs = new RenderSc...
RenderScript – GPU side
Hello.rs
void root (char *in , char *out) {
*out = *in * 2
}
RenderScript
●

●

Advantages : Compared to NDK, provides an easy device
agnostic way to accelerate performance on GPU
Dis...
Renderscipt - Summary
●

Renderscript is an API to access GPU

●

Used for High Performance

●

High Performance Compute /...
High performance graphics and computation - OpenGL ES and RenderScript
High performance graphics and computation - OpenGL ES and RenderScript
Upcoming SlideShare
Loading in …5
×

High performance graphics and computation - OpenGL ES and RenderScript

1,642 views

Published on

Arvind Devraj's overview of OpenGL and RenderScript

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,642
On SlideShare
0
From Embeds
0
Number of Embeds
86
Actions
Shares
0
Downloads
14
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

High performance graphics and computation - OpenGL ES and RenderScript

  1. 1. High Performance Graphics and Compute OpenGLES and RenderScript Arvind Devaraj
  2. 2. Agenda ● Introduction : Graphics terms ● Graphics on GPU ● OpenGL Android Graphics ● Graphics Pipeline ● Shaders ● High Performance Compute on GPU ● RenderScript
  3. 3. Graphics Terms ● ● ● OpenGLES : Graphics API for doing 3D operations on GPU / CPU Primitives : lines, point, triangles Texture : make the image realistic by adding bitmap
  4. 4. CPU versus GPU ● CPU – good at executing sequential code – ● Handles branches well – Same code, multiple data GPU – Parallelism (ideal for image rendering)
  5. 5. Graphics on GPU
  6. 6. Graphics Pipeline
  7. 7. OpenGLES Android Graphics ● Graphics Library for 3D
  8. 8. Android Graphics Classes GLSurfaceView GLSurfaceView.Renderer View ➢ - connects SurfaceView to OpenGLES library Renderer - responsible for making OpenGL calls to render a frame ➢
  9. 9. GLSurfaceView          GLSurfaceView view = new GLSurfaceView(this);     view.setRenderer(new SquareRenderer());
  10. 10. 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
  11. 11. 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) { Code for drawing the frame ( Square )     }     public void onSurfaceChanged(GL10 unused, int width, int height)   {         When surface is changed (rotated etc)     } }
  12. 12. Drawing a Square draw() {   float coords[] = { ....     }; vertex 'buffer' created with the coords glVertexPointer(buffer) : } glDrawArrays(TRIANGLE_STRIP ...); ,
  13. 13. 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
  14. 14. OpenGL Rendering Pipeline
  15. 15. Shaders ● Shaders are programs that execute on the GPU ● Shader programs operate on – Each vertex – Each pixel
  16. 16. 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
  17. 17. Vertex Shader attribute vec4 vertexPosition; void main(){      gl_Position = vertexPosition;   } Fragment Shader precision mediump float; void main(){     gl_FragColor = vec4(0.5, 0.5, 0.5, 1.0); }
  18. 18. CPU – GPU communication
  19. 19. 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
  20. 20. 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)
  21. 21. RenderScript – Use cases ● What functions can be accelerated – Graphics – Image Processing – Encryption – Signal processing – Mathematical functions
  22. 22. RenderScript - Flow
  23. 23. 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)
  24. 24. RenderScript – GPU side Hello.rs void root (char *in , char *out) { *out = *in * 2 }
  25. 25. RenderScript ● ● Advantages : Compared to NDK, provides an easy device agnostic way to accelerate performance on GPU Disadvantages : C99 standard, debugging is restricted
  26. 26. 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 ● ●

×