SlideShare a Scribd company logo
1 of 52
Download to read offline
GPU PROGRAMMING WITH
GPUIMAGE AND METAL
JANIE CLAYTON-HASZ
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
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.
Shader Basics
Shaders are the programs that determine what
gets displayed on your screen.

Shaders determine shapes, colors, textures,
lighting…

Everything you see and use comes down to
shaders.
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
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
What the Heck is “State”??
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.
What the Heck is “State”??
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.
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
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
Two Flavors of GLSL
Shaders
Vertex

Fragment
Vertex Shaders
Vertex Shaders
The Vertex Shader would record the vertices of the
star (which would be broken down into a series of
triangles)

The Vertex Shader would also specify that the area
between the vertices is yellow. If there was a
texture instead of a color, the shader would keep
track of the texture coordinates.
Fragment Shaders
Fragment Shaders
Fragment Shaders determine what pixels receive
which color.

If you look carefully at the star, there are areas
outside the star that are yellow and areas inside
that are white.

If there is a gradient, the Fragment Shader will
calculate what specific color each individual pixel
will be.
Inputs and Outputs
Uniforms

Attributes

Varyings
Uniforms
Values that don’t change during rendering

Read-Only

Available in both Vertex and Fragment Shaders
Attributes
Vertex Shader only

Input values that change with every vertex, like
their position, color, and texture coordinates
Varyings
Used to pass data between the Vertex and the
Fragment Shaders

Read-only in the Fragment Shader

Read-Write in the Vertex Shader

Varyings are the variables that determine the pixel
color for the Fragment Shader
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…
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.
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.
ZEN GARDEN DEMO
EPIC GAMES
Secret Sauce
Okay, so one of the big, obscure black boxes in
this scheme is the promise of deep software/
hardware integration. One thing I have not had
the chance to study in depth is kernel
programming and chip architecture. Knowing
the idiosyncrasies of the chips and only having
to support one type allows for more targeted
processes.
IS THERE ANY POINT IN LEARNING
OPENGL ES ANYMORE?
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).
!
It isn’t like they would
just throw out an older technology that works
perfectly well and replace it with something
that barely works, right??
Well crap.
Think Different.
The End

More Related Content

What's hot

Orthogonality: A Strategy for Reusable Code
Orthogonality: A Strategy for Reusable CodeOrthogonality: A Strategy for Reusable Code
Orthogonality: A Strategy for Reusable Code
rsebbe
 
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
Arvind Devaraj
 
Threading Successes 01 Intro
Threading Successes 01   IntroThreading Successes 01   Intro
Threading Successes 01 Intro
guest40fc7cd
 
Android open gl2_droidcon_2014
Android open gl2_droidcon_2014Android open gl2_droidcon_2014
Android open gl2_droidcon_2014
Droidcon Berlin
 

What's hot (16)

Gl efficiency
Gl efficiencyGl efficiency
Gl efficiency
 
XR graphics in Unity: delivering the best AR/VR experiences – Unite Copenhage...
XR graphics in Unity: delivering the best AR/VR experiences – Unite Copenhage...XR graphics in Unity: delivering the best AR/VR experiences – Unite Copenhage...
XR graphics in Unity: delivering the best AR/VR experiences – Unite Copenhage...
 
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
 
How the Universal Render Pipeline unlocks games for you - Unite Copenhagen 2019
How the Universal Render Pipeline unlocks games for you - Unite Copenhagen 2019How the Universal Render Pipeline unlocks games for you - Unite Copenhagen 2019
How the Universal Render Pipeline unlocks games for you - Unite Copenhagen 2019
 
DDD loves Actor Model and Actor Model loves Elixir
DDD loves Actor Model and Actor Model loves ElixirDDD loves Actor Model and Actor Model loves Elixir
DDD loves Actor Model and Actor Model loves Elixir
 
FGS 2011: Making A Game With Molehill: Zombie Tycoon
FGS 2011: Making A Game With Molehill: Zombie TycoonFGS 2011: Making A Game With Molehill: Zombie Tycoon
FGS 2011: Making A Game With Molehill: Zombie Tycoon
 
GPU accelerated path rendering fastforward
GPU accelerated path rendering fastforwardGPU accelerated path rendering fastforward
GPU accelerated path rendering fastforward
 
【Unite 2017 Tokyo】スクリプタブル・レンダーパイプラインのカスタマイズと拡張
【Unite 2017 Tokyo】スクリプタブル・レンダーパイプラインのカスタマイズと拡張【Unite 2017 Tokyo】スクリプタブル・レンダーパイプラインのカスタマイズと拡張
【Unite 2017 Tokyo】スクリプタブル・レンダーパイプラインのカスタマイズと拡張
 
Orthogonality: A Strategy for Reusable Code
Orthogonality: A Strategy for Reusable CodeOrthogonality: A Strategy for Reusable Code
Orthogonality: A Strategy for Reusable Code
 
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
 
Unite Berlin 2018 - Book of the Dead Optimizing Performance for High End Cons...
Unite Berlin 2018 - Book of the Dead Optimizing Performance for High End Cons...Unite Berlin 2018 - Book of the Dead Optimizing Performance for High End Cons...
Unite Berlin 2018 - Book of the Dead Optimizing Performance for High End Cons...
 
Seminar presentation on OpenGL
Seminar presentation on OpenGLSeminar presentation on OpenGL
Seminar presentation on OpenGL
 
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
 
TensorFlow Lite for mobile & IoT
TensorFlow Lite for mobile & IoT   TensorFlow Lite for mobile & IoT
TensorFlow Lite for mobile & IoT
 
Threading Successes 01 Intro
Threading Successes 01   IntroThreading Successes 01   Intro
Threading Successes 01 Intro
 
Android open gl2_droidcon_2014
Android open gl2_droidcon_2014Android open gl2_droidcon_2014
Android open gl2_droidcon_2014
 

Similar to Gpu Programming With GPUImage and Metal

Presentation
PresentationPresentation
Presentation
butest
 
Minko - Flash Conference #5
Minko - Flash Conference #5Minko - Flash Conference #5
Minko - Flash Conference #5
Minko3D
 
13th kandroid OpenGL and EGL
13th kandroid OpenGL and EGL13th kandroid OpenGL and EGL
13th kandroid OpenGL and EGL
Jungsoo Nam
 

Similar to Gpu Programming With GPUImage and Metal (20)

Advanced Graphics Workshop - GFX2011
Advanced Graphics Workshop - GFX2011Advanced Graphics Workshop - GFX2011
Advanced Graphics Workshop - GFX2011
 
GFX Part 1 - Introduction to GPU HW and OpenGL ES specifications
GFX Part 1 - Introduction to GPU HW and OpenGL ES specificationsGFX Part 1 - Introduction to GPU HW and OpenGL ES specifications
GFX Part 1 - Introduction to GPU HW and OpenGL ES specifications
 
Presentation
PresentationPresentation
Presentation
 
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)
 
Domain driven design ch1
Domain driven design ch1Domain driven design ch1
Domain driven design ch1
 
What is OpenGL ?
What is OpenGL ?What is OpenGL ?
What is OpenGL ?
 
Пиксельные шейдеры для Web-разработчиков. Программируем GPU / Денис Радин (Li...
Пиксельные шейдеры для Web-разработчиков. Программируем GPU / Денис Радин (Li...Пиксельные шейдеры для Web-разработчиков. Программируем GPU / Денис Радин (Li...
Пиксельные шейдеры для Web-разработчиков. Программируем GPU / Денис Радин (Li...
 
CS 354 Programmable Shading
CS 354 Programmable ShadingCS 354 Programmable Shading
CS 354 Programmable Shading
 
The nitty gritty of game development
The nitty gritty of game developmentThe nitty gritty of game development
The nitty gritty of game development
 
Android native gl
Android native glAndroid native gl
Android native gl
 
Minko - Flash Conference #5
Minko - Flash Conference #5Minko - Flash Conference #5
Minko - Flash Conference #5
 
Metail Skin Colour Authoring Tool
Metail Skin Colour Authoring ToolMetail Skin Colour Authoring Tool
Metail Skin Colour Authoring Tool
 
Compute API –Past & Future
Compute API –Past & FutureCompute API –Past & Future
Compute API –Past & Future
 
Sig13 ce future_gfx
Sig13 ce future_gfxSig13 ce future_gfx
Sig13 ce future_gfx
 
Angel
AngelAngel
Angel
 
Gpu presentation
Gpu presentationGpu presentation
Gpu presentation
 
13th kandroid OpenGL and EGL
13th kandroid OpenGL and EGL13th kandroid OpenGL and EGL
13th kandroid OpenGL and EGL
 
Cheap HPC
Cheap HPCCheap HPC
Cheap HPC
 
The Rendering Pipeline - Challenges & Next Steps
The Rendering Pipeline - Challenges & Next StepsThe Rendering Pipeline - Challenges & Next Steps
The Rendering Pipeline - Challenges & Next Steps
 
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
 

More from 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

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 

Recently uploaded (20)

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 

Gpu Programming With GPUImage and Metal

  • 1. GPU PROGRAMMING WITH GPUIMAGE AND METAL JANIE CLAYTON-HASZ
  • 2. 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
  • 3. 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.
  • 4. But I Have Concurrency! Concurrency is about dealing with a lot of things at once. Parallelism is about doing lots of things at once.
  • 5. Shader Basics Shaders are the programs that determine what gets displayed on your screen. Shaders determine shapes, colors, textures, lighting… Everything you see and use comes down to shaders.
  • 6. GRAPHICS ON IOS DEVICES
  • 7. There are many levels of abstraction for graphics on iOS. ! Some frameworks are more abstracted than others.
  • 9. A BRIEF HISTORY OF TIME, UH, OPENGL…
  • 10. OpenGL Origins First released in 1992 Was an attempt to formalize a 3D graphic specification across platforms
  • 11. 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)
  • 12.
  • 13. 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
  • 14. We don’t need a dozen turtles that all do the same thing
  • 15. 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
  • 16. CPU VS GPU PROGRAMMING
  • 17. 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
  • 18. What the Heck is “State”?? 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.
  • 19. What the Heck is “State”?? 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.
  • 20.
  • 21. Fixed Function Pipeline Present in OpenGL ES 1.1 Shaders were hard-coded into OpenGL Easier to use, but were very limited
  • 22. 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
  • 24. 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
  • 25. Two Flavors of GLSL Shaders Vertex Fragment
  • 27. Vertex Shaders The Vertex Shader would record the vertices of the star (which would be broken down into a series of triangles) The Vertex Shader would also specify that the area between the vertices is yellow. If there was a texture instead of a color, the shader would keep track of the texture coordinates.
  • 29. Fragment Shaders Fragment Shaders determine what pixels receive which color. If you look carefully at the star, there are areas outside the star that are yellow and areas inside that are white. If there is a gradient, the Fragment Shader will calculate what specific color each individual pixel will be.
  • 31. Uniforms Values that don’t change during rendering Read-Only Available in both Vertex and Fragment Shaders
  • 32. Attributes Vertex Shader only Input values that change with every vertex, like their position, color, and texture coordinates
  • 33. Varyings Used to pass data between the Vertex and the Fragment Shaders Read-only in the Fragment Shader Read-Write in the Vertex Shader Varyings are the variables that determine the pixel color for the Fragment Shader
  • 35. 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.
  • 36. 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.
  • 37. Demo
  • 38. METAL: THE NEW KID IN TOWN
  • 39. 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
  • 40. What Specifically are the CPU Expensive Tasks? Compiling Shaders Validating State Start Work on the GPU
  • 41. 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.
  • 42. 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…
  • 43. 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.
  • 44. 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. Secret Sauce Okay, so one of the big, obscure black boxes in this scheme is the promise of deep software/ hardware integration. One thing I have not had the chance to study in depth is kernel programming and chip architecture. Knowing the idiosyncrasies of the chips and only having to support one type allows for more targeted processes.
  • 47. IS THERE ANY POINT IN LEARNING OPENGL ES ANYMORE?
  • 48. 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). ! It isn’t like they would just throw out an older technology that works perfectly well and replace it with something that barely works, right??
  • 49.