department of computer science [email protected]...
TRANSCRIPT
RenderingCPSC 591/691: Fall 2016
GPU-Programming
Allan [email protected]
Department of Computer ScienceUniversity of Calgary
October 19th, 2016
Outline
● History of 3D Graphics● GPU vs CPU● OpenGL● GLSL
○ Storing data○ Shader communication○ Variables and data types
● Examples
History of 3D Graphics
● Battlezone (1980)[Image from Creative Commons]
History of 3D Graphics
● Battlezone (1980)● 3D Monster Maze (1981) [Image from Creative Commons]
History of 3D Graphics
● Battlezone (1980)● 3D Monster Maze (1981)● Wolfenstein 3D (1992)
[Image from Wolfenstein 3D's Steam store page]
History of 3D Graphics
● Battlezone (1980)● 3D Monster Maze (1981)● Wolfenstein 3D (1992)● Super Mario Kart (1992)
[Image from Creative Commons]
History of 3D Graphics
● Battlezone (1980)● 3D Monster Maze (1981)● Wolfenstein 3D (1992)● Super Mario Kart (1992)● Doom (1993)
[Image from Doom's Steam store page]
History of 3D Graphics
● Battlezone (1980)● 3D Monster Maze (1981)● Wolfenstein 3D (1992)● Super Mario Kart (1992)● Doom (1993)● Quake (1996)
[Image from Quake's Steam store page]
History of 3D Graphics
● Battlezone (1980)● 3D Monster Maze (1981)● Wolfenstein 3D (1992)● Super Mario Kart (1992)● Doom (1993)● Quake (1996)● …● Assassin's Creed (2013)
History of 3D Graphics [Image from Assassin's Creed® Rogue by Ubisoft]
Outline
● History of 3D Graphics● GPU vs CPU● OpenGL● GLSL
○ Storing data○ Shader communication○ Variables and data types
● Examples
GPU vs CPU[http://www.tomshardware.com/forum/356253-33-tasks]
GPU vs CPU
[Image from Creative Commons]
Streaming Multiprocessor (SM)
Memory Hierarchy
[Images from Nvidia]
Each SM has its own: Control units, registers, execution pipelines, cachesCUDA Core = SP (Streaming processor)
GPU architecture [Images from Nvidia]
Outline
● History of 3D Graphics● GPU vs CPU● OpenGL● GLSL
○ Storing data○ Shader communication○ Variables and data types
● Examples
An Evolving Standard
● The standard has seen over 20 years of evolution
Over time, some extensionsbecome part of the standard.
Fixed Function Pipeline
[Image from Flipcode archives]
Fixed Function Pipeline: OpenGL 1
[Image from 3DGEP]
Programmable Pipeline: OpenGL 2
[Image from 3DGEP]
Programmable Pipeline: OpenGL 3
[Image from 3DGEP]
Programmable Pipeline: OpenGL 3
[Image from 3DGEP]
Programmable Pipeline: OpenGL 4
[Image from 3DGEP]
Opengl 4
● Vertex Shader ○ Processing of each individual vertex
● Tessellation Control○ The amount of tessellation
● Tessellation Evaluation ○ Compute interpolations
● Geometry Shader○ Emit different primitives
● Fragment Shader○ Operations per pixel
[Superbible OpenGL]
Shading Languages
● Assembly● Cg● HLSL● GLSL● OpenCL● CUDA● Vulkan
Outline
● History of 3D Graphics● GPU vs CPU● OpenGL● GLSL
○ Storing data○ Shader communication○ Variables and data types
● Examples
Opengl Shader Language (GLSL)
● Basic concepts
○ C-like language
○ Execution is inherently parallel
○ No pointers
○ Vector operators
○ Built-in support for many mathematical functions
○ For efficiency, avoid branches and loops
GLSL - Storing data
● Attributes
○ Vertex Array Object (VAO) and Vertex Buffer Object (VBO)
○ Data that changes per vertex
■ Position, normals, texture coordinates, etc.
○ 4-tuples: (x, y, z, w)
○ Think homogeneous coordinates
● Uniforms
○ Data that stays the same for all vertices
○ Can be scalar, vector or matrix types
GLSL - Storing data
● Texture data
○ Data to be applied as a texture
■ not necessarily - Texture Buffer Objects
○ Support for 2D and 3D floating point textures
GLSL - Shader communication
● Outs
○ Output from the shaders, used to pass data from one stage to the next
○ Client does not have access
○ Variables IN and OUT
Opengl Shader Language (GLSL)● Variable and data types
Opengl Shader Language (GLSL)● Variable and data types
Per pixel lighting
[Image from cgchannel]
Vertex Shader
Fragment Shader
Texture Mapping
[Image from Blender documentation]
Normal Mapping
[Image from Independent Developer]
Framebuffer
● Support to several attachments ○ Color attachment ○ Depth attachment
Framebuffer
● Support to several attachments ○ Color attachment ○ Depth attachment
render target
Framebuffer● Render to texture
First pass Second pass
Render to texture
● Create framebuffer● Create the attachments ● Bind ● Unbind
Render to texture
● Create framebuffer● Create the attachments ● Bind ● Unbind
Applications
Render to texture
● Create framebuffer● Create the attachments ● Bind ● Unbind
Applications
● Deferred Shading● Ambient Occlusion● Shadow Mapping
Render to texture
● Create framebuffer● Create the attachments ● Bind ● Unbind
Applications
● Deferred Shading● Ambient Occlusion● Shadow Mapping
Let's run this example!