Download
gpu programming n.
Skip this Video
Loading SlideShow in 5 Seconds..
GPU Programming PowerPoint Presentation
Download Presentation
GPU Programming

GPU Programming

201 Vues Download Presentation
Télécharger la présentation

GPU Programming

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. GPU Programming Lecture 2 Comp 175: Computer Graphics April 22, 2014 Michael Shah

  2. Interfacing with the GPU • Modern OpenGL • Mobile/Web Programming • Direct3D • Compute Languages • Stream, OpenCL, CUDA • Future Michael Shah

  3. Modern OpenGL OpenGL 2.0 and beyond Michael Shah

  4. 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

  5. Optimizations Available • Vertex Array • Display Lists • Vertex Buffer Objects • Pixel Buffers • Frame Buffer Objects Michael Shah

  6. 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

  7. 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

  8. 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

  9. 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

  10. 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

  11. 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

  12. PBO Use Case Michael Shah

  13. 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

  14. Mobile/Web Graphics OpenGL ES and WebGL Michael Shah

  15. 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/

  16. 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

  17. 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

  18. What Does it Look Like • WebGL Samples • http://webglplayground.net/ Michael Shah

  19. Direct3D (D3D) Microsoft’s Graphics API Michael Shah

  20. 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

  21. Which is Better? • Learn both • (Or the one your company is interviewing you for) • Use D3D for Microsoft platforms Michael Shah

  22. 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

  23. GPGPU (General Purpose GPU) Languages CUDA OpenCL Compute Michael Shah

  24. 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

  25. What GPU Looks like • Each Kernel gets a grid which has blocks • Each block has threads that share memory Michael Shah

  26. Example CUDA (Host) Michael Shah

  27. Example CUDA Kernel (Executed on Device) Michael Shah

  28. 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

  29. A Graphics Example [1] Michael Shah

  30. 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

  31. Compute • Microsoft’s version of CUDA or OpenCL • Programs written called “compute shaders” Michael Shah

  32. 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

  33. Future What to do in the next 1.5 weeks “Great Scott!” – Dr. Emmett Brown Michael Shah

  34. 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

  35. Stuff to Check Out • Unity3D Michael Shah

  36. Stuff to Check Out • Unreal Engine (State of the Art) Michael Shah

  37. Renderman • Pixar’s tools • If you liked Ray tracer, you will want to take a look Michael Shah

  38. 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

  39. Supporting Slides In class questions come up Michael Shah

  40. Ambient Occlusion Map Michael Shah