410 likes | 651 Views
GPU Programming. Lecture 2 Comp 175: Computer Graphics April 22, 2014. Interfacing with the GPU. Modern OpenGL Mobile/Web Programming Direct3D Compute Languages Stream, OpenCL , CUDA Future. Modern OpenGL. OpenGL 2.0 and beyond. Client/Server Architecture. Think of like a network
E N D
GPU Programming Lecture 2 Comp 175: Computer Graphics April 22, 2014 Michael Shah
Interfacing with the GPU • Modern OpenGL • Mobile/Web Programming • Direct3D • Compute Languages • Stream, OpenCL, CUDA • Future Michael Shah
Modern OpenGL OpenGL 2.0 and beyond Michael Shah
Client/Server Architecture • Think of like a network • Client = the CPU • Server = the GPU • The less they talk, the better • Less waiting for memory to transfer • Bandwith is almost always the bottleneck • Send data over once, and have it ready to go Michael Shah
Optimizations Available • Vertex Array • Display Lists • Vertex Buffer Objects • Pixel Buffers • Frame Buffer Objects Michael Shah
Immediate Mode • Every ‘gl’ command is being sent to the GPU every iteration. • Very inefficient • Think of it like having an interpreter versus a compiler for C++ Michael Shah
Vertex Array • No more glBegin/glEnd • Store Vertices, indices, normals, colors, texture coordinates in an array • Minimizes OpenGL calls on Client (CPU) • Data still being passed from Client to Server every frame • A little better because it’s all at once • Stylistically, much cleaner code as well Michael Shah
Display List • Compiled geometry • Send it to the Server(GPU) once, and it is stored in memory on Server • Geometry cannot be updated, without deleting display list. someGeometryDisplayList= glGenLists(1); glNewList(someGeometryDisplayList,GL_COMPILE); drawShape(); glEndList(); Michael Shah
Vertex Buffer Object (VBO) • Improves upon Vertex Array • We can store data on the Server (GPU) • Just like display lists! • We get a pointer into the Server (GPU) so that we can update it! • As good as display lists! • Because we have a pointer to the data, multiple clients can access data. • Multiple instances of a program can access data Michael Shah
Buffer ObjectPattern Step 1: • glGenBuffer // Allocate some memory • glBindBuffer // Populate memory • glBufferData // copy data over to GPU Step 2: • glEnable // Enable drawing of Buffer Object • glDrawElements // draw the data Michael Shah
Pixel Buffer Object (PBO) • Same as Vertex Buffer Object • But--We are storing pixel data • Pixels can be stored to make up textures • Static • Dynamic • Streaming • Not directlytied to texture Michael Shah
PBO Use Case Michael Shah
FramebufferObject (FBO) • Two Use Cases • Render Buffer – Controlled by Windows System • This is what we see (Deferred Render Example) • Texture Images • Used for rendering textures to geometry • Can be static, dynamic, or streaming data just like with VBO. • Used to give us cool animations, or simply play videos on shapes. • Video Example Michael Shah
Mobile/Web Graphics OpenGL ES and WebGL Michael Shah
OpenGL ES[1] • OpenGL ES 1.X • Fixed Function pipeline (OpenGL 1.5) on mobile platforms • OpenGL ES 2.X • Programmable Pipeline only • OpenGL ES 3.X • Many more features, texture compression the big one! Michael Shah [1] http://www.khronos.org/opengles/
OpenGL ES versus OpenGL • ES – Stands for embedded systems • Simpler API (Meaning, less functions implemented) • No geometry shader support for OpenGL ES 2.0 (or 3.0) • 2.0 version supports the GLSL 1.2 version we are using • Which again means no fixed-function pipeline Michael Shah
WebGL • Javascript API – currently in version 2.0 • Identical to OpenGL ES • Runs in your browser • Programmable Pipeline only • No fixed-function pipeline available Michael Shah
What Does it Look Like • WebGL Samples • http://webglplayground.net/ Michael Shah
Direct3D (D3D) Microsoft’s Graphics API Michael Shah
Microsoft’s Equivalent Graphics API • Very similar graphics API, but for Microsoft Platforms only • X-Box, PC, Zune, Surface, Windows Phone • Has High Level Shading Language(HLSL) similar to GLSL Michael Shah
Which is Better? • Learn both • (Or the one your company is interviewing you for) • Use D3D for Microsoft platforms Michael Shah
Managed Languages • For managed languages (Visual Basic, C#, other .net languages) • XNA Software Development Kit for Microsoft platforms) – Use for X-Box 360 programming Michael Shah
GPGPU (General Purpose GPU) Languages CUDA OpenCL Compute Michael Shah
CUDA Created by nVidia • Terminology • Device – GPU • Host – CPU • Kernel – Function that runs on device(GPU) • Gives us access to 100s or 1000s of processors on GPU • We write code in a kernel (think of like a shader) • One kernel executers at a time • Then 100s or 1000s of threads are spawned to compute result. • We can pre-compile the kernel! (But we must do so for each architecture we want to support) Michael Shah
What GPU Looks like • Each Kernel gets a grid which has blocks • Each block has threads that share memory Michael Shah
Example CUDA (Host) Michael Shah
Example CUDA Kernel (Executed on Device) Michael Shah
CUDA + OpenGL • Shared memory for all the buffer objects • So it’s still fast! It all lives on the Device (GPU) • Special CUDA Calls to register buffers • cuGLRegisterBufferObject(GLuintbufferobj ); • Simulations/programs where graphics are tied to data should use CUDA • e.g. Volume Rendering Michael Shah
A Graphics Example [1] Michael Shah
OpenCL • Performs same job as CUDA • Speed-wise • OpenCL and CUDA give you same benefits • OpenCL offers better portability • CUDA generally more tied to nVidia Michael Shah
Compute • Microsoft’s version of CUDA or OpenCL • Programs written called “compute shaders” Michael Shah
When to Use each? • Compute with DirectX suite • OpenCL with OpenGL and browser applications (webCL exists now!) • CUDA if only designing for one platform • CUDA is the most mature platform Michael Shah
Future What to do in the next 1.5 weeks “Great Scott!” – Dr. Emmett Brown Michael Shah
Where to Go • Finish your final project • Think about graphics applied to non-graphics applications • Check out the state of the art and build lots of little demoes Michael Shah
Stuff to Check Out • Unity3D Michael Shah
Stuff to Check Out • Unreal Engine (State of the Art) Michael Shah
Renderman • Pixar’s tools • If you liked Ray tracer, you will want to take a look Michael Shah
Next 15 minutes and Next Class • Project Updates in 1 minute • Next 15 minutes • Course evaluation (link) • Next Class • Mini in-class lab • Most likely VBO’s Michael Shah
Supporting Slides In class questions come up Michael Shah
Ambient Occlusion Map Michael Shah