SlideShare ist ein Scribd-Unternehmen logo
1 von 58
Downloaden Sie, um offline zu lesen
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… 
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 
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
What Frameworks are 
Hardware Accelerated? 
Core Animation 
GLKit 
SpriteKit 
SceneKit 
For more information on 2D drawing frameworks, 
go see “To drawRect, Or Not to drawRect” later 
today with Sam Davies.
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
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. Fragment shader performance has 
increased tremendously, so do as much work here 
as you can! 
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.
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
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.
WHAT HAPPENS WHEN YOU LOOK 
INTO THE HEART OF THE GPU 
BAD WOLF 
PROJECT 
DATE 12/05/14 CLIENT
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

Weitere ähnliche Inhalte

Was ist angesagt?

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 FoundationUnity Technologies
 
Cross platform computer vision optimization
Cross platform computer vision optimizationCross platform computer vision optimization
Cross platform computer vision optimizationYoss Cohen
 
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
 
Creating next-gen VR and MR experiences using Varjo VR-1 and XR-1 - Unite Cop...
Creating next-gen VR and MR experiences using Varjo VR-1 and XR-1 - Unite Cop...Creating next-gen VR and MR experiences using Varjo VR-1 and XR-1 - Unite Cop...
Creating next-gen VR and MR experiences using Varjo VR-1 and XR-1 - Unite Cop...Unity Technologies
 
Mobile development in 2020
Mobile development in 2020 Mobile development in 2020
Mobile development in 2020 Bogusz Jelinski
 
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 2019Unity Technologies
 
"OpenCV for Embedded: Lessons Learned," a Presentation from itseez
"OpenCV for Embedded: Lessons Learned," a Presentation from itseez"OpenCV for Embedded: Lessons Learned," a Presentation from itseez
"OpenCV for Embedded: Lessons Learned," a Presentation from itseezEdge AI and Vision Alliance
 
Introduction to Computing on GPU
Introduction to Computing on GPUIntroduction to Computing on GPU
Introduction to Computing on GPUIlya Kuzovkin
 
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 CataldiLuis Cataldi
 
Weekly #106: Deep Learning on Mobile
Weekly #106: Deep Learning on MobileWeekly #106: Deep Learning on Mobile
Weekly #106: Deep Learning on MobileBill Liu
 
OpenGLES - Graphics Programming in Android
OpenGLES - Graphics Programming in Android OpenGLES - Graphics Programming in Android
OpenGLES - Graphics Programming in Android Arvind Devaraj
 
Cloud Deep Learning Chips Training & Inference
Cloud Deep Learning Chips Training & InferenceCloud Deep Learning Chips Training & Inference
Cloud Deep Learning Chips Training & InferenceMr. Vengineer
 

Was ist angesagt? (14)

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
 
Cross platform computer vision optimization
Cross platform computer vision optimizationCross platform computer vision optimization
Cross platform computer vision optimization
 
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...
 
Creating next-gen VR and MR experiences using Varjo VR-1 and XR-1 - Unite Cop...
Creating next-gen VR and MR experiences using Varjo VR-1 and XR-1 - Unite Cop...Creating next-gen VR and MR experiences using Varjo VR-1 and XR-1 - Unite Cop...
Creating next-gen VR and MR experiences using Varjo VR-1 and XR-1 - Unite Cop...
 
Mobile development in 2020
Mobile development in 2020 Mobile development in 2020
Mobile development in 2020
 
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
 
The Rise of Mobility
The Rise of MobilityThe Rise of Mobility
The Rise of Mobility
 
"OpenCV for Embedded: Lessons Learned," a Presentation from itseez
"OpenCV for Embedded: Lessons Learned," a Presentation from itseez"OpenCV for Embedded: Lessons Learned," a Presentation from itseez
"OpenCV for Embedded: Lessons Learned," a Presentation from itseez
 
Introduction to Computing on GPU
Introduction to Computing on GPUIntroduction to Computing on GPU
Introduction to Computing on GPU
 
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
 
2014/07/17 Parallelize computer vision by GPGPU computing
2014/07/17 Parallelize computer vision by GPGPU computing2014/07/17 Parallelize computer vision by GPGPU computing
2014/07/17 Parallelize computer vision by GPGPU computing
 
Weekly #106: Deep Learning on Mobile
Weekly #106: Deep Learning on MobileWeekly #106: Deep Learning on Mobile
Weekly #106: Deep Learning on Mobile
 
OpenGLES - Graphics Programming in Android
OpenGLES - Graphics Programming in Android OpenGLES - Graphics Programming in Android
OpenGLES - Graphics Programming in Android
 
Cloud Deep Learning Chips Training & Inference
Cloud Deep Learning Chips Training & InferenceCloud Deep Learning Chips Training & Inference
Cloud Deep Learning Chips Training & Inference
 

Ähnlich wie GPU Programming: CocoaConf Atlanta

Gpu Programming With GPUImage and Metal
Gpu Programming With GPUImage and MetalGpu Programming With GPUImage and Metal
Gpu Programming With GPUImage and MetalJanie Clayton
 
Threading Successes 01 Intro
Threading Successes 01   IntroThreading Successes 01   Intro
Threading Successes 01 Introguest40fc7cd
 
VisionizeBeforeVisulaize_IEVC_Final
VisionizeBeforeVisulaize_IEVC_FinalVisionizeBeforeVisulaize_IEVC_Final
VisionizeBeforeVisulaize_IEVC_FinalMasatsugu HASHIMOTO
 
Writing 3D Applications Using ruby-processing
Writing 3D Applications Using ruby-processingWriting 3D Applications Using ruby-processing
Writing 3D Applications Using ruby-processingPreston Lee
 
Advanced Graphics Workshop - GFX2011
Advanced Graphics Workshop - GFX2011Advanced Graphics Workshop - GFX2011
Advanced Graphics Workshop - GFX2011Prabindh Sundareson
 
Java on the GPU: Where are we now?
Java on the GPU: Where are we now?Java on the GPU: Where are we now?
Java on the GPU: Where are we now?Dmitry Alexandrov
 
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 APPLICATIONScseij
 
Benchmark of common AI accelerators: NVIDIA GPU vs. Intel Movidius
Benchmark of common AI accelerators: NVIDIA GPU vs. Intel MovidiusBenchmark of common AI accelerators: NVIDIA GPU vs. Intel Movidius
Benchmark of common AI accelerators: NVIDIA GPU vs. Intel MovidiusbyteLAKE
 
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
 
OpenGL Based Testing Tool Architecture for Exascale Computing
OpenGL Based Testing Tool Architecture for Exascale ComputingOpenGL Based Testing Tool Architecture for Exascale Computing
OpenGL Based Testing Tool Architecture for Exascale ComputingCSCJournals
 
Metail Skin Colour Authoring Tool
Metail Skin Colour Authoring ToolMetail Skin Colour Authoring Tool
Metail Skin Colour Authoring ToolDavid Gavilan
 
Compute API –Past & Future
Compute API –Past & FutureCompute API –Past & Future
Compute API –Past & FutureOfer Rosenberg
 
Computer Graphics - Lecture 01 - 3D Programming I
Computer Graphics - Lecture 01 - 3D Programming IComputer Graphics - Lecture 01 - 3D Programming I
Computer Graphics - Lecture 01 - 3D Programming I💻 Anton Gerdelan
 
CS 354 Introduction
CS 354 IntroductionCS 354 Introduction
CS 354 IntroductionMark Kilgard
 
Seminar presentation on OpenGL
Seminar presentation on OpenGLSeminar presentation on OpenGL
Seminar presentation on OpenGLMegha V
 
Console to PC VR: Lessons Learned from the Unspoken
Console to PC VR: Lessons Learned from the UnspokenConsole to PC VR: Lessons Learned from the Unspoken
Console to PC VR: Lessons Learned from the UnspokenRobert Sprentall
 

Ähnlich wie GPU Programming: CocoaConf Atlanta (20)

Gpu Programming With GPUImage and Metal
Gpu Programming With GPUImage and MetalGpu Programming With GPUImage and Metal
Gpu Programming With GPUImage and Metal
 
Threading Successes 01 Intro
Threading Successes 01   IntroThreading Successes 01   Intro
Threading Successes 01 Intro
 
VisionizeBeforeVisulaize_IEVC_Final
VisionizeBeforeVisulaize_IEVC_FinalVisionizeBeforeVisulaize_IEVC_Final
VisionizeBeforeVisulaize_IEVC_Final
 
Writing 3D Applications Using ruby-processing
Writing 3D Applications Using ruby-processingWriting 3D Applications Using ruby-processing
Writing 3D Applications Using ruby-processing
 
Advanced Graphics Workshop - GFX2011
Advanced Graphics Workshop - GFX2011Advanced Graphics Workshop - GFX2011
Advanced Graphics Workshop - GFX2011
 
Cheap HPC
Cheap HPCCheap HPC
Cheap HPC
 
HTML5 Game Development frameworks overview
HTML5 Game Development frameworks overviewHTML5 Game Development frameworks overview
HTML5 Game Development frameworks overview
 
Java on the GPU: Where are we now?
Java on the GPU: Where are we now?Java on the GPU: Where are we now?
Java on the GPU: Where are we now?
 
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
 
Benchmark of common AI accelerators: NVIDIA GPU vs. Intel Movidius
Benchmark of common AI accelerators: NVIDIA GPU vs. Intel MovidiusBenchmark of common AI accelerators: NVIDIA GPU vs. Intel Movidius
Benchmark of common AI accelerators: NVIDIA GPU vs. Intel Movidius
 
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)
 
OpenGL Based Testing Tool Architecture for Exascale Computing
OpenGL Based Testing Tool Architecture for Exascale ComputingOpenGL Based Testing Tool Architecture for Exascale Computing
OpenGL Based Testing Tool Architecture for Exascale Computing
 
Computer graphics workbook
Computer graphics workbookComputer graphics workbook
Computer graphics workbook
 
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
 
Computer Graphics - Lecture 01 - 3D Programming I
Computer Graphics - Lecture 01 - 3D Programming IComputer Graphics - Lecture 01 - 3D Programming I
Computer Graphics - Lecture 01 - 3D Programming I
 
CS 354 Introduction
CS 354 IntroductionCS 354 Introduction
CS 354 Introduction
 
Seminar presentation on OpenGL
Seminar presentation on OpenGLSeminar presentation on OpenGL
Seminar presentation on OpenGL
 
GPU Programming with Java
GPU Programming with JavaGPU Programming with Java
GPU Programming with Java
 
Console to PC VR: Lessons Learned from the Unspoken
Console to PC VR: Lessons Learned from the UnspokenConsole to PC VR: Lessons Learned from the Unspoken
Console to PC VR: Lessons Learned from the Unspoken
 

Mehr von 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 AestheticJanie Clayton
 
3D Math Primer: CocoaConf Chicago
3D Math Primer: CocoaConf Chicago3D Math Primer: CocoaConf Chicago
3D Math Primer: CocoaConf ChicagoJanie Clayton
 
3D Math Primer: CocoaConf Atlanta
3D Math Primer: CocoaConf Atlanta3D Math Primer: CocoaConf Atlanta
3D Math Primer: CocoaConf AtlantaJanie Clayton
 
3D Math Without Presenter Notes
3D Math Without Presenter Notes3D Math Without Presenter Notes
3D Math Without Presenter NotesJanie 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 PrimerJanie Clayton
 

Mehr von 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
 

Kürzlich hochgeladen

GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGSujit Pal
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
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...Miguel Araújo
 
[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.pdfhans926745
 
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...Igalia
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
The Evolution of Money: Digital Transformation and CBDCs in Central Banking
The Evolution of Money: Digital Transformation and CBDCs in Central BankingThe Evolution of Money: Digital Transformation and CBDCs in Central Banking
The Evolution of Money: Digital Transformation and CBDCs in Central BankingSelcen Ozturkcan
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 

Kürzlich hochgeladen (20)

GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAG
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
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...
 
[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
 
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...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
The Evolution of Money: Digital Transformation and CBDCs in Central Banking
The Evolution of Money: Digital Transformation and CBDCs in Central BankingThe Evolution of Money: Digital Transformation and CBDCs in Central Banking
The Evolution of Money: Digital Transformation and CBDCs in Central Banking
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 

GPU Programming: CocoaConf Atlanta

  • 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… Everything you see and use comes down to shaders.
  • 9. GRAPHICS ON IOS DEVICES
  • 10. There are many levels of abstraction for graphics on iOS. Some frameworks are more abstracted than others.
  • 11. UIKit Sprite Kit Core Animation/Graphics OpenGL ES/GLKit
  • 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. What Frameworks are Hardware Accelerated? Core Animation GLKit SpriteKit SceneKit For more information on 2D drawing frameworks, go see “To drawRect, Or Not to drawRect” later today with Sam Davies.
  • 28. 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.
  • 29. 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!!
  • 31. 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. 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.
  • 35. Fragment Shaders Fragment Shaders determine what pixels receive which color. Fragment shader performance has increased tremendously, so do as much work here as you can! 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.
  • 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. 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.
  • 46. 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.
  • 47. ZEN GARDEN DEMO EPIC GAMES
  • 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. WHAT HAPPENS WHEN YOU LOOK INTO THE HEART OF THE GPU BAD WOLF PROJECT DATE 12/05/14 CLIENT
  • 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.