SlideShare a Scribd company logo
GPU PROGRAMMING WITH
GPUIMAGE AND METAL
JANIE CLAYTON
About Me
Janie Clayton

Co-Author of “iOS 8 SDK
Development”

Software engineer at
SonoPlot

@redqueencoder

http://redqueencoder.com
What is a GPU?
A Graphics Processing Unit (GPU) is a small super
computer that does one thing really really well. That
one thing is processing floating point math in parallel.

There are several applications for being able to do
really fast floating point math: Graphics processing,
bioinformatics, molecular dynamics, etc…

Most people are going to primarily focus on graphics
processing, as we will today. For GPGPU
programming, go see Jeff Biggus speak about
OpenCL!
What is Parallel Computing
The default processes in a project is serialized
computing. One instruction is processed at a time
and then the CPU moves on to the next one.

Parallel computing is the process of allowing
multiple instructions to be carried out at once.

Can be done on different threads, cores, and even
at the bit level.
But I Have Concurrency!
Concurrency is about dealing with a lot of things
at once.

Parallelism is about doing lots of things at once.
SERIES CIRCUIT
LESS EFFICIENT
PARALLEL CIRCUIT
MORE EFFICIENT
Shader Basics
Shaders are the programs that determine
what gets displayed on your screen.

Shaders determine shapes, colors,
textures, lighting…
GRAPHICS ON IOS DEVICES
There are many levels of abstraction
for graphics on iOS.
Some frameworks are more
abstracted than others.
UIKit
Sprite Kit
Core Animation/Graphics
OpenGL ES/GLKit
A BRIEF HISTORY OF TIME,
UH, OPENGL…
OpenGL Origins
First released in 1992

Was an attempt to formalize a 3D graphic
specification across platforms

John Carmack was instrumental for the adoption
of OpenGL as a cross-platform 3D graphic
specification.
Problems with OpenGL
Was created back when GPUs were not very
powerful and existed on external graphics cards
that could be swapped out

The computer system architecture was vastly
different when OpenGL was created. Things that
were not very efficient then, like the GPU, are vastly
more efficient now.

Nothing is ever deprecated (Don’t ask Java
programmers what that means, they don’t know)
Creation of OpenGL ES
ES: Embedded Systems

Wanted to strip out all of the dead code from
OpenGL

Was specifically tailored to work on less powerful
devices like mobile phones
We don’t need a dozen turtles that all do the same thing
OpenGL ES Specifics
Streamlined version of OpenGL

Everything you can do in OpenGL ES can directly
be ported to OpenGL

Basically an optimized version of OpenGL
CPU VS GPU PROGRAMMING
CPU Expensive Tasks
Sending hardware commands to the GPU
(Changing State Vectors)

Confirming that API usage is valid

Compiling the shaders

Interaction between the state and the shaders
How does the CPU Send
tasks to the GPU?
Try to envision a client-server process. Instead of
your program sending an instruction over the
network to a server and getting data back, you are
sending instructions from your CPU to your GPU
to be executed. Since you are sending instructions
away from your client to be done elsewhere, you
want to minimize this as much as possible.
How does the CPU Send
tasks to the GPU?
For example, in most Twitter client applications the
client batches 20 or more Tweets in one call. This
allows the application to feed tweets to the user
without them having to wait for the network to
deliver each and every tweet individually.
What Actually Sends
Commands to the GPU?
glGenBuffers(): Creates the buffer

glBindBuffers(): Tells OpenGL to use this buffer.

glBufferData(): Allocate this much continuous memory

glVertexAttribPointer(): What kind of data do we have?

glDrawArrays(): Render the data in the buffer

glDeleteBuffer(): We don’t need the buffer anymore,
get rid of it.
Fixed Function Pipeline
Present in OpenGL ES 1.1

Shaders were hard-coded into OpenGL

Easier to use, but were very limited
Programmable Pipeline
Introduced in OpenGL ES 2.0

Shaders are now the responsibility of the
programmer

Harder to do, but provides far more flexibility and
options for effects
OpenGL ES 1.1 vs 2.0
1.1 2.0
http://www.sunsetlakesoftware.com/molecules
What Frameworks are
Hardware Accelerated?
Core Animation 

GLKit

SpriteKit

SceneKit
What About Core
Graphics/Quartz?
Core Graphics/Quartz is NOT performed on the
GPU. It is performed on the CPU.

Core Graphics is off on its own. UIKit is written on
top of Core Animation, which is written on top of
the GPU.

Core Graphics utilizes offscreen drawing. Anything
using offscreen drawing is not hardware
accelerated.
Offscreen Drawing
Core Graphics (anything starting with “CG”)

Every “drawRect()” method

Anything using Core Text

CALayers using masks and shadows

CALayers with “shouldRasterize” set to YES
Do not animate anything using offscreen drawing!
It is horribly inefficient!!
GLSL SHADER BUILDING
GLSL
OpenGL Shading Language (GLSL)

Introduced in OpenGL 2.0 in 2004

C-like language for building shaders, which are
small, efficient programs to run on the GPU

Includes some specific data types and methods
for processing geometry and graphics math that
are not included in C
GLSL
Two shader components: Vertex and Fragment

Both are necessary to create a completed shader
program

Vertex shaders deal with how geometry is handled
on the screen

Fragment shaders calculate what each individual
pixel will look like
Vertex Shaders
Fragment Shaders
GPU IMAGE
Creating GPUImage
GPUImage dates back to iOS 5.

Unlike Core Image (at the time), GPUImage utilized
shaders more efficiently to make image processing
faster. Core Image has been improved over the
years and they are now comparable.
Why is GPUImage so
Efficient?
OpenGL ES tasks must be performed on one
thread

Many people utilize locks to manage the thread or,
God forbid, only use the main thread. <shudder>

NSLock is expensive to the CPU

GPUImage utilizes a serial dispatch queue through
GCD to manage anything that touches the GPU to
keep everything happy and thread safe.
Demo
METAL: THE NEW KID IN
TOWN
What does Metal Promise?
Deep hardware integration between Apple chips
and Apple frameworks

General Purpose GPU programming (GPGPU)

Precompiled Shaders

up to 10 times more draw calls per frame

Being able to perform draw calls on multiple
threads
What Specifically are the
CPU Expensive Tasks?
Compiling Shaders

Validating State

Start Work on the GPU
Life Before Metal
All three of these expensive tasks were done on
each and every single draw call.

All of these tasks don’t have to be done thousands
of times a frame. Many can be done once, as long
as the program knows that it does not have to
continually check them.
Life After Metal
Compiling Shaders: Now done when the
applications builds

Validating State: Now done when the content
loads

Start Work on the GPU: Still happens on each
draw call. We can’t win them all…
Where Does Metal Help
You?
Metal helps you when you have a lot of objects
that need to work independently of one another.

Certain tasks, like image processing, do not
involve a lot of objects, so you aren’t going to gain
much with Metal.
Why is This Important?
Before Metal, you would have to balance CPU time
with GPU time. Tasks were so expensive that the
GPU would usually not be used to capacity.

Now that the CPU tasks are less expensive, you can
take that time to generate more AI and do more
programming logic.

Also, when people were generating art assets, they
had to make convoluted versions of assets to work
around OpenGL ES limitations. Now the same
assets can be used in all places. Not everything is
about code.
ZEN GARDEN DEMO
EPIC GAMES
SO, WHAT DO I THINK
ABOUT METAL?
Why Metal is Scary
You have to control EVERYTHING!!!

You have to have a deep understanding of how
the computer works that I have not seen
demonstrated by a large number of people.

Metal assumes you know more than the computer
does, which in my experience is usually a bad
move.
BAD WOLF
PROJECT
DATE CLIENT
3/27/15
WHAT HAPPENS WHEN YOU LOOK
INTO THE HEART OF THE GPU
Why Metal is Exciting
Metal, along with Swift, signals a shift to figuring
out how to do more parallel programming.

I believe Metal is not going anywhere. It will take a
while for people to learn how to fully utilize it, but I
believe it has the potential to be a game changer.

Metal, like Swift, is still partly baked. It gives early
adopters an opportunity to master something
extraordinary.
IS THERE ANY POINT IN LEARNING
OPENGL ES ANYMORE?
“Easy things should be easy.

Hard things should be possible.”
–Larry Wall
Yes, absolutely. Metal’s API is very similar to OpenGL ES.
It will take a while for everyone to transition over
to devices with A7 chips.
Apple will continue to support its developers who
work with OpenGL ES, especially since the
Mac uses OpenGL and won’t be able to use Metal (yet).
Also, Metal is new. It usually takes Apple a few
years to work the kinks out of their new frameworks.
Also, with Metal’s incredibly steep learning curve,
very few people could work with it now.
Take Aways
Whether you learn GLSL or Metal Shading Language,
the value comes from the algorithms. The languages
are not complicated and are similar. If you don’t know
how the math on a shader works, knowing the language
won’t really help you.

There are lots of books on GPU programming out there
explaining how to create effects, not to mention the
shaders included in GPUImage. You will need to
understand the math, but there are great resources
online out there for this stuff.

Be tenacious. This takes a lot of time to master. It is
worth it. Be patient.
Think Different.
The End
• http://www.objc.io/issue-21/gpu-accelerated-image-
processing.html
• https://developer.apple.com/videos/wwdc/2011/#414
• https://developer.apple.com/videos/wwdc/2014/#603
• http://www.sunsetlakesoftware.com/2011/05/08/
enhancing-molecules-using-opengl-es-20
Links

More Related Content

What's hot

Need For Speed
Need For SpeedNeed For Speed
Need For Speed
Noj
 
Need for speed
Need for speedNeed for speed
Need for speed
Hari Bol
 
Need for Speed - Comparison of Current Web Technologies
Need for Speed - Comparison of Current Web TechnologiesNeed for Speed - Comparison of Current Web Technologies
Need for Speed - Comparison of Current Web Technologies
guest1d9d29
 
Rendering Techniques for Augmented Reality and a Look Ahead at AR Foundation
Rendering Techniques for Augmented Reality and a Look Ahead at AR FoundationRendering Techniques for Augmented Reality and a Look Ahead at AR Foundation
Rendering Techniques for Augmented Reality and a Look Ahead at AR Foundation
Unity Technologies
 
Developing and optimizing a procedural game: The Elder Scrolls Blades- Unite ...
Developing and optimizing a procedural game: The Elder Scrolls Blades- Unite ...Developing and optimizing a procedural game: The Elder Scrolls Blades- Unite ...
Developing and optimizing a procedural game: The Elder Scrolls Blades- Unite ...
Unity Technologies
 
【Unite 2018 Tokyo】スクリプタブルレンダーパイプライン入門
【Unite 2018 Tokyo】スクリプタブルレンダーパイプライン入門【Unite 2018 Tokyo】スクリプタブルレンダーパイプライン入門
【Unite 2018 Tokyo】スクリプタブルレンダーパイプライン入門
Unity Technologies Japan K.K.
 
AGDK tutorial step by step
AGDK tutorial step by stepAGDK tutorial step by step
AGDK tutorial step by step
Jungsoo Nam
 
Cross platform computer vision optimization
Cross platform computer vision optimizationCross platform computer vision optimization
Cross platform computer vision optimization
Yoss Cohen
 
What's ahead for film and animation with Unity 2020 - Unite Copenhagen 2019
What's ahead for film and animation with Unity 2020 - Unite Copenhagen 2019What's ahead for film and animation with Unity 2020 - Unite Copenhagen 2019
What's ahead for film and animation with Unity 2020 - Unite Copenhagen 2019
Unity Technologies
 
【Unite 2017 Tokyo】スクリプタブル・レンダーパイプラインのカスタマイズと拡張
【Unite 2017 Tokyo】スクリプタブル・レンダーパイプラインのカスタマイズと拡張【Unite 2017 Tokyo】スクリプタブル・レンダーパイプラインのカスタマイズと拡張
【Unite 2017 Tokyo】スクリプタブル・レンダーパイプラインのカスタマイズと拡張
Unite2017Tokyo
 
GPU accelerated path rendering fastforward
GPU accelerated path rendering fastforwardGPU accelerated path rendering fastforward
GPU accelerated path rendering fastforward
Mark Kilgard
 
Improve the performance of your Unity project using Graphics Performance Anal...
Improve the performance of your Unity project using Graphics Performance Anal...Improve the performance of your Unity project using Graphics Performance Anal...
Improve the performance of your Unity project using Graphics Performance Anal...
Unity Technologies
 
Making High Quality Interactive VR with Unreal Engine Luis Cataldi
Making High Quality Interactive VR with Unreal Engine Luis CataldiMaking High Quality Interactive VR with Unreal Engine Luis Cataldi
Making High Quality Interactive VR with Unreal Engine Luis Cataldi
Luis Cataldi
 
Android High performance in GPU using opengles and renderscript
Android High performance in GPU using opengles and renderscriptAndroid High performance in GPU using opengles and renderscript
Android High performance in GPU using opengles and renderscriptArvind Devaraj
 
Anomaly Detection with Azure and .net
Anomaly Detection with Azure and .netAnomaly Detection with Azure and .net
Anomaly Detection with Azure and .net
Marco Parenzan
 
Discover the technology behind "The Heretic" – Unite Copenhagen 2019
Discover the technology behind "The Heretic" – Unite Copenhagen 2019Discover the technology behind "The Heretic" – Unite Copenhagen 2019
Discover the technology behind "The Heretic" – Unite Copenhagen 2019
Unity Technologies
 

What's hot (17)

Need For Speed
Need For SpeedNeed For Speed
Need For Speed
 
Need for speed
Need for speedNeed for speed
Need for speed
 
Need for Speed - Comparison of Current Web Technologies
Need for Speed - Comparison of Current Web TechnologiesNeed for Speed - Comparison of Current Web Technologies
Need for Speed - Comparison of Current Web Technologies
 
Rendering Techniques for Augmented Reality and a Look Ahead at AR Foundation
Rendering Techniques for Augmented Reality and a Look Ahead at AR FoundationRendering Techniques for Augmented Reality and a Look Ahead at AR Foundation
Rendering Techniques for Augmented Reality and a Look Ahead at AR Foundation
 
Developing and optimizing a procedural game: The Elder Scrolls Blades- Unite ...
Developing and optimizing a procedural game: The Elder Scrolls Blades- Unite ...Developing and optimizing a procedural game: The Elder Scrolls Blades- Unite ...
Developing and optimizing a procedural game: The Elder Scrolls Blades- Unite ...
 
【Unite 2018 Tokyo】スクリプタブルレンダーパイプライン入門
【Unite 2018 Tokyo】スクリプタブルレンダーパイプライン入門【Unite 2018 Tokyo】スクリプタブルレンダーパイプライン入門
【Unite 2018 Tokyo】スクリプタブルレンダーパイプライン入門
 
AGDK tutorial step by step
AGDK tutorial step by stepAGDK tutorial step by step
AGDK tutorial step by step
 
Cross platform computer vision optimization
Cross platform computer vision optimizationCross platform computer vision optimization
Cross platform computer vision optimization
 
What's ahead for film and animation with Unity 2020 - Unite Copenhagen 2019
What's ahead for film and animation with Unity 2020 - Unite Copenhagen 2019What's ahead for film and animation with Unity 2020 - Unite Copenhagen 2019
What's ahead for film and animation with Unity 2020 - Unite Copenhagen 2019
 
Gl efficiency
Gl efficiencyGl efficiency
Gl efficiency
 
【Unite 2017 Tokyo】スクリプタブル・レンダーパイプラインのカスタマイズと拡張
【Unite 2017 Tokyo】スクリプタブル・レンダーパイプラインのカスタマイズと拡張【Unite 2017 Tokyo】スクリプタブル・レンダーパイプラインのカスタマイズと拡張
【Unite 2017 Tokyo】スクリプタブル・レンダーパイプラインのカスタマイズと拡張
 
GPU accelerated path rendering fastforward
GPU accelerated path rendering fastforwardGPU accelerated path rendering fastforward
GPU accelerated path rendering fastforward
 
Improve the performance of your Unity project using Graphics Performance Anal...
Improve the performance of your Unity project using Graphics Performance Anal...Improve the performance of your Unity project using Graphics Performance Anal...
Improve the performance of your Unity project using Graphics Performance Anal...
 
Making High Quality Interactive VR with Unreal Engine Luis Cataldi
Making High Quality Interactive VR with Unreal Engine Luis CataldiMaking High Quality Interactive VR with Unreal Engine Luis Cataldi
Making High Quality Interactive VR with Unreal Engine Luis Cataldi
 
Android High performance in GPU using opengles and renderscript
Android High performance in GPU using opengles and renderscriptAndroid High performance in GPU using opengles and renderscript
Android High performance in GPU using opengles and renderscript
 
Anomaly Detection with Azure and .net
Anomaly Detection with Azure and .netAnomaly Detection with Azure and .net
Anomaly Detection with Azure and .net
 
Discover the technology behind "The Heretic" – Unite Copenhagen 2019
Discover the technology behind "The Heretic" – Unite Copenhagen 2019Discover the technology behind "The Heretic" – Unite Copenhagen 2019
Discover the technology behind "The Heretic" – Unite Copenhagen 2019
 

Viewers also liked

iOS intro to 3D graphics with Metal
iOS intro to 3D graphics with MetaliOS intro to 3D graphics with Metal
iOS intro to 3D graphics with Metal
Sigmapoint
 
iOS & Android Dev in C# & Visual Studio using Xamarin
iOS & Android Dev in C# & Visual Studio using XamariniOS & Android Dev in C# & Visual Studio using Xamarin
iOS & Android Dev in C# & Visual Studio using Xamarin
Nish Anil
 
Lecture 07 swift
Lecture 07 swiftLecture 07 swift
Lecture 07 swift
Maksym Davydov
 
Building Your First Android App with Xamarin
Building Your First Android App with XamarinBuilding Your First Android App with Xamarin
Building Your First Android App with Xamarin
Xamarin
 
Building Mobile Cross-Platform Apps for iOS, Android & Windows in C# with Xam...
Building Mobile Cross-Platform Apps foriOS, Android & Windows in C# with Xam...Building Mobile Cross-Platform Apps foriOS, Android & Windows in C# with Xam...
Building Mobile Cross-Platform Apps for iOS, Android & Windows in C# with Xam...
Nick Landry
 
Build Features, Not Apps
Build Features, Not AppsBuild Features, Not Apps
Build Features, Not Apps
Natasha Murashev
 

Viewers also liked (6)

iOS intro to 3D graphics with Metal
iOS intro to 3D graphics with MetaliOS intro to 3D graphics with Metal
iOS intro to 3D graphics with Metal
 
iOS & Android Dev in C# & Visual Studio using Xamarin
iOS & Android Dev in C# & Visual Studio using XamariniOS & Android Dev in C# & Visual Studio using Xamarin
iOS & Android Dev in C# & Visual Studio using Xamarin
 
Lecture 07 swift
Lecture 07 swiftLecture 07 swift
Lecture 07 swift
 
Building Your First Android App with Xamarin
Building Your First Android App with XamarinBuilding Your First Android App with Xamarin
Building Your First Android App with Xamarin
 
Building Mobile Cross-Platform Apps for iOS, Android & Windows in C# with Xam...
Building Mobile Cross-Platform Apps foriOS, Android & Windows in C# with Xam...Building Mobile Cross-Platform Apps foriOS, Android & Windows in C# with Xam...
Building Mobile Cross-Platform Apps for iOS, Android & Windows in C# with Xam...
 
Build Features, Not Apps
Build Features, Not AppsBuild Features, Not Apps
Build Features, Not Apps
 

Similar to GPU Programming: Chicago CocoaConf 2015

Threading Successes 01 Intro
Threading Successes 01   IntroThreading Successes 01   Intro
Threading Successes 01 Introguest40fc7cd
 
Seminar presentation on OpenGL
Seminar presentation on OpenGLSeminar presentation on OpenGL
Seminar presentation on OpenGL
Megha V
 
Advanced Graphics Workshop - GFX2011
Advanced Graphics Workshop - GFX2011Advanced Graphics Workshop - GFX2011
Advanced Graphics Workshop - GFX2011
Prabindh Sundareson
 
Writing 3D Applications Using ruby-processing
Writing 3D Applications Using ruby-processingWriting 3D Applications Using ruby-processing
Writing 3D Applications Using ruby-processingPreston Lee
 
Cheap HPC
Cheap HPCCheap HPC
Cheap HPC
Alex Moore
 
Pixel shaders based UI components + writing your first pixel shader
Pixel shaders based UI components + writing your first pixel shaderPixel shaders based UI components + writing your first pixel shader
Pixel shaders based UI components + writing your first pixel shader
Denis Radin
 
Пиксельные шейдеры для Web-разработчиков. Программируем GPU / Денис Радин (Li...
Пиксельные шейдеры для Web-разработчиков. Программируем GPU / Денис Радин (Li...Пиксельные шейдеры для Web-разработчиков. Программируем GPU / Денис Радин (Li...
Пиксельные шейдеры для Web-разработчиков. Программируем GPU / Денис Радин (Li...
Ontico
 
Metail Skin Colour Authoring Tool
Metail Skin Colour Authoring ToolMetail Skin Colour Authoring Tool
Metail Skin Colour Authoring Tool
David Gavilan
 
OpenGL ES EGL Spec&APIs
OpenGL ES EGL Spec&APIsOpenGL ES EGL Spec&APIs
OpenGL ES EGL Spec&APIs
Jungsoo Nam
 
Android open gl2_droidcon_2014
Android open gl2_droidcon_2014Android open gl2_droidcon_2014
Android open gl2_droidcon_2014Droidcon Berlin
 
Parallel Futures of a Game Engine (v2.0)
Parallel Futures of a Game Engine (v2.0)Parallel Futures of a Game Engine (v2.0)
Parallel Futures of a Game Engine (v2.0)
Johan Andersson
 
VisionizeBeforeVisulaize_IEVC_Final
VisionizeBeforeVisulaize_IEVC_FinalVisionizeBeforeVisulaize_IEVC_Final
VisionizeBeforeVisulaize_IEVC_FinalMasatsugu HASHIMOTO
 
3D on the Web in 2011
3D on the Web in 20113D on the Web in 2011
3D on the Web in 2011Chad Austin
 
Power of WebGL (FSTO 2014)
Power of WebGL (FSTO 2014)Power of WebGL (FSTO 2014)
Power of WebGL (FSTO 2014)
Verold
 
Computer graphics workbook
Computer graphics workbookComputer graphics workbook
Computer graphics workbook
Muhammadalizardari
 
Domain driven design ch1
Domain driven design ch1Domain driven design ch1
Domain driven design ch1
HyeonSeok Choi
 
Presentation
PresentationPresentation
Presentationbutest
 
A SURVEY ON GPU SYSTEM CONSIDERING ITS PERFORMANCE ON DIFFERENT APPLICATIONS
A SURVEY ON GPU SYSTEM CONSIDERING ITS PERFORMANCE ON DIFFERENT APPLICATIONSA SURVEY ON GPU SYSTEM CONSIDERING ITS PERFORMANCE ON DIFFERENT APPLICATIONS
A SURVEY ON GPU SYSTEM CONSIDERING ITS PERFORMANCE ON DIFFERENT APPLICATIONS
cseij
 
01 first
01 first01 first
01 firstscythus
 

Similar to GPU Programming: Chicago CocoaConf 2015 (20)

Threading Successes 01 Intro
Threading Successes 01   IntroThreading Successes 01   Intro
Threading Successes 01 Intro
 
Seminar presentation on OpenGL
Seminar presentation on OpenGLSeminar presentation on OpenGL
Seminar presentation on OpenGL
 
Advanced Graphics Workshop - GFX2011
Advanced Graphics Workshop - GFX2011Advanced Graphics Workshop - GFX2011
Advanced Graphics Workshop - GFX2011
 
Writing 3D Applications Using ruby-processing
Writing 3D Applications Using ruby-processingWriting 3D Applications Using ruby-processing
Writing 3D Applications Using ruby-processing
 
Cheap HPC
Cheap HPCCheap HPC
Cheap HPC
 
Pixel shaders based UI components + writing your first pixel shader
Pixel shaders based UI components + writing your first pixel shaderPixel shaders based UI components + writing your first pixel shader
Pixel shaders based UI components + writing your first pixel shader
 
Пиксельные шейдеры для Web-разработчиков. Программируем GPU / Денис Радин (Li...
Пиксельные шейдеры для Web-разработчиков. Программируем GPU / Денис Радин (Li...Пиксельные шейдеры для Web-разработчиков. Программируем GPU / Денис Радин (Li...
Пиксельные шейдеры для Web-разработчиков. Программируем GPU / Денис Радин (Li...
 
Metail Skin Colour Authoring Tool
Metail Skin Colour Authoring ToolMetail Skin Colour Authoring Tool
Metail Skin Colour Authoring Tool
 
OpenGL ES EGL Spec&APIs
OpenGL ES EGL Spec&APIsOpenGL ES EGL Spec&APIs
OpenGL ES EGL Spec&APIs
 
Android open gl2_droidcon_2014
Android open gl2_droidcon_2014Android open gl2_droidcon_2014
Android open gl2_droidcon_2014
 
CG mini project
CG mini projectCG mini project
CG mini project
 
Parallel Futures of a Game Engine (v2.0)
Parallel Futures of a Game Engine (v2.0)Parallel Futures of a Game Engine (v2.0)
Parallel Futures of a Game Engine (v2.0)
 
VisionizeBeforeVisulaize_IEVC_Final
VisionizeBeforeVisulaize_IEVC_FinalVisionizeBeforeVisulaize_IEVC_Final
VisionizeBeforeVisulaize_IEVC_Final
 
3D on the Web in 2011
3D on the Web in 20113D on the Web in 2011
3D on the Web in 2011
 
Power of WebGL (FSTO 2014)
Power of WebGL (FSTO 2014)Power of WebGL (FSTO 2014)
Power of WebGL (FSTO 2014)
 
Computer graphics workbook
Computer graphics workbookComputer graphics workbook
Computer graphics workbook
 
Domain driven design ch1
Domain driven design ch1Domain driven design ch1
Domain driven design ch1
 
Presentation
PresentationPresentation
Presentation
 
A SURVEY ON GPU SYSTEM CONSIDERING ITS PERFORMANCE ON DIFFERENT APPLICATIONS
A SURVEY ON GPU SYSTEM CONSIDERING ITS PERFORMANCE ON DIFFERENT APPLICATIONSA SURVEY ON GPU SYSTEM CONSIDERING ITS PERFORMANCE ON DIFFERENT APPLICATIONS
A SURVEY ON GPU SYSTEM CONSIDERING ITS PERFORMANCE ON DIFFERENT APPLICATIONS
 
01 first
01 first01 first
01 first
 

More from Janie Clayton

Robots in Swift
Robots in SwiftRobots in Swift
Robots in Swift
Janie Clayton
 
Beyond White: Embracing the iOS Design Aesthetic
Beyond White: Embracing the iOS Design AestheticBeyond White: Embracing the iOS Design Aesthetic
Beyond White: Embracing the iOS Design Aesthetic
Janie Clayton
 
Thinking In Swift
Thinking In SwiftThinking In Swift
Thinking In Swift
Janie Clayton
 
3D Math Primer: CocoaConf Chicago
3D Math Primer: CocoaConf Chicago3D Math Primer: CocoaConf Chicago
3D Math Primer: CocoaConf Chicago
Janie Clayton
 
3D Math Primer: CocoaConf Atlanta
3D Math Primer: CocoaConf Atlanta3D Math Primer: CocoaConf Atlanta
3D Math Primer: CocoaConf Atlanta
Janie Clayton
 
3D Math Without Presenter Notes
3D Math Without Presenter Notes3D Math Without Presenter Notes
3D Math Without Presenter Notes
Janie Clayton
 
The Day You Finally Use Algebra: A 3D Math Primer
The Day You Finally Use Algebra: A 3D Math PrimerThe Day You Finally Use Algebra: A 3D Math Primer
The Day You Finally Use Algebra: A 3D Math Primer
Janie Clayton
 
Bug Hunting Safari
Bug Hunting SafariBug Hunting Safari
Bug Hunting Safari
Janie Clayton
 

More from Janie Clayton (8)

Robots in Swift
Robots in SwiftRobots in Swift
Robots in Swift
 
Beyond White: Embracing the iOS Design Aesthetic
Beyond White: Embracing the iOS Design AestheticBeyond White: Embracing the iOS Design Aesthetic
Beyond White: Embracing the iOS Design Aesthetic
 
Thinking In Swift
Thinking In SwiftThinking In Swift
Thinking In Swift
 
3D Math Primer: CocoaConf Chicago
3D Math Primer: CocoaConf Chicago3D Math Primer: CocoaConf Chicago
3D Math Primer: CocoaConf Chicago
 
3D Math Primer: CocoaConf Atlanta
3D Math Primer: CocoaConf Atlanta3D Math Primer: CocoaConf Atlanta
3D Math Primer: CocoaConf Atlanta
 
3D Math Without Presenter Notes
3D Math Without Presenter Notes3D Math Without Presenter Notes
3D Math Without Presenter Notes
 
The Day You Finally Use Algebra: A 3D Math Primer
The Day You Finally Use Algebra: A 3D Math PrimerThe Day You Finally Use Algebra: A 3D Math Primer
The Day You Finally Use Algebra: A 3D Math Primer
 
Bug Hunting Safari
Bug Hunting SafariBug Hunting Safari
Bug Hunting Safari
 

Recently uploaded

Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
rickgrimesss22
 
Top 7 Unique WhatsApp API Benefits | Saudi Arabia
Top 7 Unique WhatsApp API Benefits | Saudi ArabiaTop 7 Unique WhatsApp API Benefits | Saudi Arabia
Top 7 Unique WhatsApp API Benefits | Saudi Arabia
Yara Milbes
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
Shane Coughlan
 
APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)
Boni García
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
Fermin Galan
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
XfilesPro
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
Donna Lenk
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Globus
 
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI AppAI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
Google
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
Google
 
Pro Unity Game Development with C-sharp Book
Pro Unity Game Development with C-sharp BookPro Unity Game Development with C-sharp Book
Pro Unity Game Development with C-sharp Book
abdulrafaychaudhry
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Globus
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
Globus
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
Georgi Kodinov
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
Globus
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
abdulrafaychaudhry
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
Aftab Hussain
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
Matt Welsh
 

Recently uploaded (20)

Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
 
Top 7 Unique WhatsApp API Benefits | Saudi Arabia
Top 7 Unique WhatsApp API Benefits | Saudi ArabiaTop 7 Unique WhatsApp API Benefits | Saudi Arabia
Top 7 Unique WhatsApp API Benefits | Saudi Arabia
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
 
APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
 
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI AppAI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
 
Pro Unity Game Development with C-sharp Book
Pro Unity Game Development with C-sharp BookPro Unity Game Development with C-sharp Book
Pro Unity Game Development with C-sharp Book
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
 

GPU Programming: Chicago CocoaConf 2015

  • 1. GPU PROGRAMMING WITH GPUIMAGE AND METAL JANIE CLAYTON
  • 2. About Me Janie Clayton Co-Author of “iOS 8 SDK Development” Software engineer at SonoPlot @redqueencoder http://redqueencoder.com
  • 3. What is a GPU? A Graphics Processing Unit (GPU) is a small super computer that does one thing really really well. That one thing is processing floating point math in parallel. There are several applications for being able to do really fast floating point math: Graphics processing, bioinformatics, molecular dynamics, etc… Most people are going to primarily focus on graphics processing, as we will today. For GPGPU programming, go see Jeff Biggus speak about OpenCL!
  • 4. What is Parallel Computing The default processes in a project is serialized computing. One instruction is processed at a time and then the CPU moves on to the next one. Parallel computing is the process of allowing multiple instructions to be carried out at once. Can be done on different threads, cores, and even at the bit level.
  • 5. But I Have Concurrency! Concurrency is about dealing with a lot of things at once. Parallelism is about doing lots of things at once.
  • 8. Shader Basics Shaders are the programs that determine what gets displayed on your screen. Shaders determine shapes, colors, textures, lighting…
  • 9. GRAPHICS ON IOS DEVICES
  • 10. There are many levels of abstraction for graphics on iOS. Some frameworks are more abstracted than others.
  • 12. A BRIEF HISTORY OF TIME, UH, OPENGL…
  • 13. OpenGL Origins First released in 1992 Was an attempt to formalize a 3D graphic specification across platforms John Carmack was instrumental for the adoption of OpenGL as a cross-platform 3D graphic specification.
  • 14. Problems with OpenGL Was created back when GPUs were not very powerful and existed on external graphics cards that could be swapped out The computer system architecture was vastly different when OpenGL was created. Things that were not very efficient then, like the GPU, are vastly more efficient now. Nothing is ever deprecated (Don’t ask Java programmers what that means, they don’t know)
  • 15.
  • 16. Creation of OpenGL ES ES: Embedded Systems Wanted to strip out all of the dead code from OpenGL Was specifically tailored to work on less powerful devices like mobile phones
  • 17. We don’t need a dozen turtles that all do the same thing
  • 18. OpenGL ES Specifics Streamlined version of OpenGL Everything you can do in OpenGL ES can directly be ported to OpenGL Basically an optimized version of OpenGL
  • 19. CPU VS GPU PROGRAMMING
  • 20. CPU Expensive Tasks Sending hardware commands to the GPU (Changing State Vectors) Confirming that API usage is valid Compiling the shaders Interaction between the state and the shaders
  • 21. How does the CPU Send tasks to the GPU? Try to envision a client-server process. Instead of your program sending an instruction over the network to a server and getting data back, you are sending instructions from your CPU to your GPU to be executed. Since you are sending instructions away from your client to be done elsewhere, you want to minimize this as much as possible.
  • 22. How does the CPU Send tasks to the GPU? For example, in most Twitter client applications the client batches 20 or more Tweets in one call. This allows the application to feed tweets to the user without them having to wait for the network to deliver each and every tweet individually.
  • 23. What Actually Sends Commands to the GPU? glGenBuffers(): Creates the buffer glBindBuffers(): Tells OpenGL to use this buffer. glBufferData(): Allocate this much continuous memory glVertexAttribPointer(): What kind of data do we have? glDrawArrays(): Render the data in the buffer glDeleteBuffer(): We don’t need the buffer anymore, get rid of it.
  • 24.
  • 25. Fixed Function Pipeline Present in OpenGL ES 1.1 Shaders were hard-coded into OpenGL Easier to use, but were very limited
  • 26. Programmable Pipeline Introduced in OpenGL ES 2.0 Shaders are now the responsibility of the programmer Harder to do, but provides far more flexibility and options for effects
  • 27. OpenGL ES 1.1 vs 2.0 1.1 2.0 http://www.sunsetlakesoftware.com/molecules
  • 28. What Frameworks are Hardware Accelerated? Core Animation GLKit SpriteKit SceneKit
  • 29. What About Core Graphics/Quartz? Core Graphics/Quartz is NOT performed on the GPU. It is performed on the CPU. Core Graphics is off on its own. UIKit is written on top of Core Animation, which is written on top of the GPU. Core Graphics utilizes offscreen drawing. Anything using offscreen drawing is not hardware accelerated.
  • 30. Offscreen Drawing Core Graphics (anything starting with “CG”) Every “drawRect()” method Anything using Core Text CALayers using masks and shadows CALayers with “shouldRasterize” set to YES Do not animate anything using offscreen drawing! It is horribly inefficient!!
  • 32. GLSL OpenGL Shading Language (GLSL) Introduced in OpenGL 2.0 in 2004 C-like language for building shaders, which are small, efficient programs to run on the GPU Includes some specific data types and methods for processing geometry and graphics math that are not included in C
  • 33. GLSL Two shader components: Vertex and Fragment Both are necessary to create a completed shader program Vertex shaders deal with how geometry is handled on the screen Fragment shaders calculate what each individual pixel will look like
  • 37. Creating GPUImage GPUImage dates back to iOS 5. Unlike Core Image (at the time), GPUImage utilized shaders more efficiently to make image processing faster. Core Image has been improved over the years and they are now comparable.
  • 38. Why is GPUImage so Efficient? OpenGL ES tasks must be performed on one thread Many people utilize locks to manage the thread or, God forbid, only use the main thread. <shudder> NSLock is expensive to the CPU GPUImage utilizes a serial dispatch queue through GCD to manage anything that touches the GPU to keep everything happy and thread safe.
  • 39. Demo
  • 40. METAL: THE NEW KID IN TOWN
  • 41. What does Metal Promise? Deep hardware integration between Apple chips and Apple frameworks General Purpose GPU programming (GPGPU) Precompiled Shaders up to 10 times more draw calls per frame Being able to perform draw calls on multiple threads
  • 42. What Specifically are the CPU Expensive Tasks? Compiling Shaders Validating State Start Work on the GPU
  • 43. Life Before Metal All three of these expensive tasks were done on each and every single draw call. All of these tasks don’t have to be done thousands of times a frame. Many can be done once, as long as the program knows that it does not have to continually check them.
  • 44. Life After Metal Compiling Shaders: Now done when the applications builds Validating State: Now done when the content loads Start Work on the GPU: Still happens on each draw call. We can’t win them all…
  • 45. Where Does Metal Help You? Metal helps you when you have a lot of objects that need to work independently of one another. Certain tasks, like image processing, do not involve a lot of objects, so you aren’t going to gain much with Metal.
  • 46. Why is This Important? Before Metal, you would have to balance CPU time with GPU time. Tasks were so expensive that the GPU would usually not be used to capacity. Now that the CPU tasks are less expensive, you can take that time to generate more AI and do more programming logic. Also, when people were generating art assets, they had to make convoluted versions of assets to work around OpenGL ES limitations. Now the same assets can be used in all places. Not everything is about code.
  • 48. SO, WHAT DO I THINK ABOUT METAL?
  • 49. Why Metal is Scary You have to control EVERYTHING!!! You have to have a deep understanding of how the computer works that I have not seen demonstrated by a large number of people. Metal assumes you know more than the computer does, which in my experience is usually a bad move.
  • 50. BAD WOLF PROJECT DATE CLIENT 3/27/15 WHAT HAPPENS WHEN YOU LOOK INTO THE HEART OF THE GPU
  • 51. Why Metal is Exciting Metal, along with Swift, signals a shift to figuring out how to do more parallel programming. I believe Metal is not going anywhere. It will take a while for people to learn how to fully utilize it, but I believe it has the potential to be a game changer. Metal, like Swift, is still partly baked. It gives early adopters an opportunity to master something extraordinary.
  • 52. IS THERE ANY POINT IN LEARNING OPENGL ES ANYMORE?
  • 53. “Easy things should be easy. Hard things should be possible.” –Larry Wall
  • 54. Yes, absolutely. Metal’s API is very similar to OpenGL ES. It will take a while for everyone to transition over to devices with A7 chips. Apple will continue to support its developers who work with OpenGL ES, especially since the Mac uses OpenGL and won’t be able to use Metal (yet). Also, Metal is new. It usually takes Apple a few years to work the kinks out of their new frameworks. Also, with Metal’s incredibly steep learning curve, very few people could work with it now.
  • 55. Take Aways Whether you learn GLSL or Metal Shading Language, the value comes from the algorithms. The languages are not complicated and are similar. If you don’t know how the math on a shader works, knowing the language won’t really help you. There are lots of books on GPU programming out there explaining how to create effects, not to mention the shaders included in GPUImage. You will need to understand the math, but there are great resources online out there for this stuff. Be tenacious. This takes a lot of time to master. It is worth it. Be patient.
  • 56.
  • 59. • http://www.objc.io/issue-21/gpu-accelerated-image- processing.html • https://developer.apple.com/videos/wwdc/2011/#414 • https://developer.apple.com/videos/wwdc/2014/#603 • http://www.sunsetlakesoftware.com/2011/05/08/ enhancing-molecules-using-opengl-es-20 Links