Programmable Graphics Hardware

Similar documents
Introduction to Shaders.

Shader Programs. Lecture 30 Subsections 2.8.2, Robb T. Koether. Hampden-Sydney College. Wed, Nov 16, 2011

X. GPU Programming. Jacobs University Visualization and Computer Graphics Lab : Advanced Graphics - Chapter X 1

Shaders. Slide credit to Prof. Zwicker

Supplement to Lecture 22

12.2 Programmable Graphics Hardware

Programmable GPUs. Real Time Graphics 11/13/2013. Nalu 2004 (NVIDIA Corporation) GeForce 6. Virtua Fighter 1995 (SEGA Corporation) NV1

Programmable Graphics Hardware

Real - Time Rendering. Graphics pipeline. Michal Červeňanský Juraj Starinský

Today. Rendering - III. Outline. Texturing: The 10,000m View. Texture Coordinates. Specifying Texture Coordinates in GL

Programming with OpenGL Part 3: Shaders. Ed Angel Professor of Emeritus of Computer Science University of New Mexico

The Graphics Pipeline and OpenGL III: OpenGL Shading Language (GLSL 1.10)!

OpenGL Programmable Shaders

CS GPU and GPGPU Programming Lecture 7: Shading and Compute APIs 1. Markus Hadwiger, KAUST

Programming shaders & GPUs Christian Miller CS Fall 2011

Information Coding / Computer Graphics, ISY, LiTH GLSL. OpenGL Shading Language. Language with syntax similar to C

Programming Graphics Hardware

GPU Memory Model. Adapted from:

The Transition from RenderMan to the OpenGL Shading Language (GLSL)

GLSL Introduction. Fu-Chung Huang. Thanks for materials from many other people

Introduction to the OpenGL Shading Language

Graphics Processing Unit Architecture (GPU Arch)

printf Debugging Examples

Graphics Hardware. Graphics Processing Unit (GPU) is a Subsidiary hardware. With massively multi-threaded many-core. Dedicated to 2D and 3D graphics

Grafica Computazionale: Lezione 30. Grafica Computazionale. Hiding complexity... ;) Introduction to OpenGL. lezione30 Introduction to OpenGL

GLSL 1: Basics. J.Tumblin-Modified SLIDES from:

Shaders CSCI 4239/5239 Advanced Computer Graphics Spring 2014

Graphics Hardware. Computer Graphics COMP 770 (236) Spring Instructor: Brandon Lloyd 2/26/07 1

Shader Programming 1. Examples. Vertex displacement mapping. Daniel Wesslén 1. Post-processing, animated procedural textures

Copyright Khronos Group, Page Graphic Remedy. All Rights Reserved

Sung-Eui Yoon ( 윤성의 )

Graphics Programming. Computer Graphics, VT 2016 Lecture 2, Chapter 2. Fredrik Nysjö Centre for Image analysis Uppsala University

CSE 167: Introduction to Computer Graphics Lecture #13: GLSL. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2015

Information Coding / Computer Graphics, ISY, LiTH GLSL. OpenGL Shading Language. Language with syntax similar to C

CSE 167: Lecture #8: GLSL. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2012

Real - Time Rendering. Pipeline optimization. Michal Červeňanský Juraj Starinský

COMP371 COMPUTER GRAPHICS

Cg 2.0. Mark Kilgard

Shader Programming. Daniel Wesslén, Stefan Seipel, Examples

Real-Time Rendering (Echtzeitgraphik) Michael Wimmer

SHADER PROGRAMMING. Based on Jian Huang s lecture on Shader Programming

Programmable GPUs Outline

Graphics Hardware. Instructor Stephen J. Guy

The Graphics Pipeline and OpenGL III: OpenGL Shading Language (GLSL 1.10)!

Lecture 5 Vertex and Fragment Shaders-1. CITS3003 Graphics & Animation

Lecture 2. Shaders, GLSL and GPGPU

GLSL Introduction. Fu-Chung Huang. Thanks for materials from many other people

Shaders CSCI 4229/5229 Computer Graphics Fall 2017

Sign up for crits! Announcments

Shading Languages. Ari Silvennoinen Apri 12, 2004

Introduction to Shaders for Visualization. The Basic Computer Graphics Pipeline

Technical Game Development II. Reference: Rost, OpenGL Shading Language, 2nd Ed., AW, 2006 The Orange Book Also take CS 4731 Computer Graphics

Advanced Graphics. The Shader knows. Alex Benton, University of Cambridge Supported in part by Google UK, Ltd

An Overview GLUT GLSL GLEW

Some advantages come from the limited environment! No classes. Stranight ans simple code. Remarkably. Avoids most of the bad things with C/C++.

Computergrafik. Matthias Zwicker. Herbst 2010

CMPS160 Shader-based OpenGL Programming. All slides originally from Prabath Gunawardane, et al. unless noted otherwise

CS4621/5621 Fall Computer Graphics Practicum Intro to OpenGL/GLSL

Programming with OpenGL Shaders I. Adapted From: Ed Angel Professor of Emeritus of Computer Science University of New Mexico

C P S C 314 S H A D E R S, O P E N G L, & J S RENDERING PIPELINE. Mikhail Bessmeltsev

Why modern versions of OpenGL should be used Some useful API commands and extensions

Programming Graphics Hardware

Dave Shreiner, ARM March 2009

Evolution of GPUs Chris Seitz

Levy: Constraint Texture Mapping, SIGGRAPH, CS 148, Summer 2012 Introduction to Computer Graphics and Imaging Justin Solomon

The Basic Computer Graphics Pipeline, OpenGL-style. Introduction to the OpenGL Shading Language (GLSL)

Technical Game Development II. Reference: Rost, OpenGL Shading Language, 2nd Ed., AW, 2006 The Orange Book Also take CS 4731 Computer Graphics

Working with Metal Overview

Shaders. Introduction. OpenGL Grows via Extensions. OpenGL Extensions. OpenGL 2.0 Added Shaders. Shaders Enable Many New Effects

Introduction to the OpenGL Shading Language (GLSL)

The GPGPU Programming Model

CS GPU and GPGPU Programming Lecture 2: Introduction; GPU Architecture 1. Markus Hadwiger, KAUST

CS770/870 Spring 2017 Open GL Shader Language GLSL

CS770/870 Spring 2017 Open GL Shader Language GLSL

OpenGL SUPERBIBLE. Fifth Edition. Comprehensive Tutorial and Reference. Richard S. Wright, Jr. Nicholas Haemel Graham Sellers Benjamin Lipchak

Rendering Objects. Need to transform all geometry then

Next-Generation Graphics on Larrabee. Tim Foley Intel Corp

CSE 167: Introduction to Computer Graphics Lecture #7: GLSL. Jürgen P. Schulze, Ph.D. University of California, San Diego Spring Quarter 2016

General Purpose computation on GPUs. Liangjun Zhang 2/23/2005

General Purpose Computation (CAD/CAM/CAE) on the GPU (a.k.a. Topics in Manufacturing)

Pipeline Operations. CS 4620 Lecture Steve Marschner. Cornell CS4620 Spring 2018 Lecture 11

1.2.3 The Graphics Hardware Pipeline

The Problem: Difficult To Use. Motivation: The Potential of GPGPU CGC & FXC. GPGPU Languages

Best practices for effective OpenGL programming. Dan Omachi OpenGL Development Engineer

Introduction to OpenGL

CS427 Multicore Architecture and Parallel Computing

Programmable GPUS. Last Time? Reading for Today. Homework 4. Planar Shadows Projective Texture Shadows Shadow Maps Shadow Volumes

Real-time Graphics 9. GPGPU

Computer Graphics Coursework 1

Tutorial on GPU Programming #2. Joong-Youn Lee Supercomputing Center, KISTI

CMSC427 Advanced shading getting global illumination by local methods. Credit: slides Prof. Zwicker

Accelerating Realism with the (NVIDIA Scene Graph)

Programming with OpenGL Shaders I. Adapted From: Ed Angel Professor of Emeritus of Computer Science University of New Mexico

OpenGL Status - November 2013 G-Truc Creation

GPGPU. Peter Laurens 1st-year PhD Student, NSC

Automatic Tuning Matrix Multiplication Performance on Graphics Hardware

Could you make the XNA functions yourself?

Lecture 09: Shaders (Part 1)

Shaders (some slides taken from David M. course)

Rasterization Overview

Transcription:

Programmable Graphics Hardware

Outline 2/ 49 A brief Introduction into Programmable Graphics Hardware Hardware Graphics Pipeline Shading Languages Tools GPGPU Resources

Hardware Graphics Pipeline 3/ 49 Hardware Graphics Pipeline From vertices to pixels... and what you can do in between.

Hardware Graphics Pipeline 4/ 49 Hardware Graphics Pipeline GPU Video Memory CPU Vertex Processor Raster Unit Fragment Processor Render Target Screen

Hardware Graphics Pipeline 5/ 49 Hardware Graphics Pipeline GPU Video Memory CPU Vertex Processor Raster Unit Fragment Processor Render Target Screen

Hardware Graphics Pipeline 6/ 49 Hardware Graphics Pipeline GPU Video Memory CPU Vertex Processor Raster Unit Fragment Processor Render Target Screen

Hardware Graphics Pipeline 7/ 49 Hardware Graphics Pipeline GPU Video Memory CPU Vertex Processor Raster Unit Fragment Processor Render Target Screen

Hardware Graphics Pipeline 8/ 49 Hardware Graphics Pipeline GPU Video Memory CPU Vertex Processor Raster Unit Fragment Processor Render Target Screen

Hardware Graphics Pipeline 9/ 49 Hardware Graphics Pipeline GPU Video Memory CPU Vertex Processor Raster Unit Fragment Processor Render Target Screen

Hardware Graphics Pipeline 10 / 49 General Properties Strictly sequential processing (pipeline ) Active vertex / fragment shader program is executed for each vertex / fragment Floating-point pipeline - No native support for integer / boolean data types GPU primitive - Vertex Shader: Vertex - Fragment Shader: Fragment Shader programs often called kernels

Hardware Graphics Pipeline 11 / 49 Fine-Grain Parallelism Each graphics primitive is considered as independent The program flow for each GPU primitive is considered as (almost) identical Multiple GPU primitives are processed in parallel Scheduling cannot be controlled by the user No simultaneous read / write of a buffer Multi-GPU solutions extend to high-level parallelism with explicit control for the user

Uniform Parameters 12 / 49 Uniform Parameters Infrequently changing Available in every stage of the pipeline Built-in or user-defined Examples: - Model-View-Projection matrix - Textures - Parameters of shading model

Varying Parameters 13 / 49 Varying Parameter Change for every GPU primitive Availability depends on the stage in the graphics pipeline Interpolation in the rasterization unit Built-in or user-specified Examples: - Vertex position - Vertex color - Fragment color

Vertex Processor 14 / 49 Vertex Processor Up to 8 parallel units MIMD architecture* - Units execute same program but operate independent Texture fetch possible* - High latency - Only 2D textures - Displacement Mapping Instruction slots: 512 * Nvidia NV4X architecture

Vertex Processor 15 / 49 Vertex Processor Position (Object Space) 0 Position (mult. with MVP) Color 1 Color...... Generic N Generic Uniform Variables MVP, Texture Matrix, Textures, User-defined,...

Vertex Processor 16 / 49 Functionality Vertex transformation Normal, texture coordinate transformation Lighting Point size computation Vertex position generation Texture coordinate generation Detail generation Skinning

Vertex Processor 17 / 49 Functionality Feedback loop 1. Render-to-Texture 2. Copy to PBO 3. Use PBO as VBO

Rasterization Unit 18 / 49 Rasterization Unit Perspective division Primitive assembly Clipping Interpolation of all varying parameters Rasterization. Early-Z culling (hierarchical and / or per fragment)

Fragment Processor 19 / 49 Fragment Processor Up to 48 parallel units Quad of pixels are processed together Very deep pipelines to hide texture fetch latency Effectively SIMD architecture - All occurring program paths have to be computed for for all fragments in a batch (4 x pipeline depth) - Incurs very high penalty for incoherent branching Instruction slots: 1024-4096

Fragment Processor 20 / 49 Fragment Processor Screen space position Color... Generic 0 1 N Color Depth Uniform Variables Textures, Textures, MVP, User-defined,...

Fragment Processor 21 / 49 Functionality Very high floating-point computing power Fragment position fixed Computing / altering the depth value possible Texture lookups - Samplers = textures - Dependent texture lookups - 1D, 2D and 3D textures - Explicit mipmap level addressing

Fragment Processor 22 / 49 Functionality (cont d) Result can be up to - 16 full precision floating point values - 32 half precision floating point values - 64 8-bit unsigned char values Feedback loop: Render-to-Texture 1. Render to offscreen target with texture as attachment 2. Use texture as data source in the next render pass

Framebuffer 23 / 49 Framebuffer Can be onscreen or offscreen buffer Can have up to four Color buffers (MRTs) Can have depth / stencil / accumulation buffer Onscreen render target: Provided by Windowing System - Visual determines properties Offscreen render target: Framebuffer object (FBO) - Attachments determine properties Various parameters can be set by the client API - glblendequation(),...

Hardware Graphics Pipeline 24 / 49 Hardware Graphics Pipeline GPU Video Memory CPU Vertex Processor Raster Unit Fragment Processor Render Target Screen

Modern Graphics Processors 25 / 49 High-Level Shading Languages From smooth shaded, textured fragments... to physical accurate BRDF on graphics hardware.

Mental Model Software Layers 26 / 49 Application brook lib SH lib Cg lib GLSL Compiler OpenGL Driver Intermediate Assembler Low Level Graphics Driver Graphics Hardware

Shading Languages 27 / 49 General Considerations Based on C/C++ Additions to support graphics Several limitations compared to C/C++ Languages GLSL: OpenGL Shading Language - Part of OpenGL 2.0 - Developed by 3DLabs, maintained by ARB forum

Shading Languages 28 / 49 Languages (cont d) Cg: C for Graphics - Developed and maintained by Nvidia - Graphics API independent - Proprietary - Can be used with ATI cards when compiling to ASM HLSL: High-Level Shading Languages - Developed and maintained by Microsoft - Shading Language for DirectX

Extensions for Graphics 29 / 49 Extensions for Graphics OpenGL state is available via built-in uniform variables - Availability depends on stage of the pipeline - gl_modelviewmatrix - gl_lightpos[n] - gl_clipplane[n] Parameters of GPU primitive are available via built-in varying variables - Availability depends on stage of the pipeline - gl_position - gl_frontcolor

Extensions for Graphics 30 / 49 Extensions for Graphics Data types for textures - sampler1d, sampler2d, samplerrect, sampler3d - texture1d(), texture2d(),... - texture2dshadow(), texture2dshadow() - Special lookup for shadow mapping - Perspective correct depth value comparison is performed automatically, - sampler1d( name, tex_coord.st, mipmap_level) - Mipmap level can be specified explicitly

Extensions for Graphics 31 / 49 Extensions for Graphics Additional type qualifiers - attribute (generic vertex attribute, varying type) - uniform - varying Built-in data types for vectors and (square-)matrices - vec2, vec3, vec4, ivec2, ivec3, bvec2, bvec3,... - mat2, mat3, mat4

Extensions for Graphics 32 / 49 Extensions for Graphics Build-in functions for frequently needed functionality - operator*( mat, mat), operator*( mat, vec), operator+( mat, mat) - dot(), cross(), normalize(), length() Token discard to abort any further processing of a fragment Special functions for boolean operations on vectors - any(), all()

Restrictions 33 / 49 Restrictions (compared to C/C++) No double, unsigned int,... data types No strings and character data types No dynamic memory allocation and no pointers - Array indexing has to be compile time constant No enums and unions No classes - No templates No bit-wise operations

Restrictions 34 / 49 Restrictions (compared to C/C++) No stack for registers - No context switches - No real function calls No switch statement, goto statement and labels Branching and looping available but instructions significantly more expensive than on a CPU processor

Example: Vertex Shader 35 / 49 Example: Vertex Shader uniform float diffuse; // vertex shader entry point void main() { // compute eye space position of vertex vec3 es_pos = gl_modelviewmatrix * gl_vertex; // apply normal transformation vec3 n = gl_normalmatrix * gl_normal; // compute light vector vec3 light_vec = gl_lightsource[0].position - es_pos;

Example: Vertex Shader 36 / 49 Example: Vertex Shader // vectors have to be normalized light_vec = normalize( light_vec); n = normalize( n); // compute diffuse color contribution gl_frontcolor = max(dot(light_vec, n), 0.0) * diffuse; } // apply texture transformation gl_texcoord[0] = gl_texturematrix[0] * gl_multitexcoord0;

Example: Fragment Shader 37 / 49 Example: Fragment Shader // define texture uniform sampler2d texture; // fragment shader program entry point void main() { // lookup texel float4 ctexel = texture2d( texture, gl_texcoord[0].st); } // modulate fragment color and texel gl_fragcolor = ctexel * 0.5 + gl_color * 0.5;

Modern Graphics Processors 38 / 49 GLSL + Built-in uniforms + No separate libraries required + Extensions + Good portability (compared to Cg) No compiler flags (in the standard) No includes (in the standard) No control over intermediate assembler

Modern Graphics Processors 39 / 49 Cg + Structs with member functions + Interface structs (Compile time polymorphism) + Command line flags + Faster evolution Setting up default unfiorms tedious and error prone Proprietary (but can be used on ATI / 3DLabs cards)

Modern Graphics Processors 40 / 49 Miscellaneous Compiler still (very) buggy - Look at the assembler to verify correctness Test shader with offline compiler - cgc compiler from Nvidia (-oglsl for GLSL) - GLSLvalidate from 3DLabs Debug properly - Setup debugging environment before start coding

Shading Languages 41 / 49 Other Languages for GPU Programming Motivation: Simplify GPU programming Abstract programming models (e.g. stream processor) Integration of shader programming into client side program code Hardware independent - Graphics API / Shading Language implementation have slight differences between vendors - Compilation for CPU (helpful for debugging) or other parallel architecture with similar capabilities possible

Shading Languages 42 / 49 Other Languages for GPU Programming Brook - Developed at the graphics lab in Stanford - GPU as stream processor - Mainly for GPGPU applications SH - Developed at the graphics lab in Waterloo - Graphical and general purpose computations - Shader can be created at runtime using C/C++ language features (metaprogramming)

Tools 43 / 49 Tools The things which come after printf debugging...

Debugging / Profiling 44 / 49 Debugging / Profiling No direct debugging possible - No breakpoints - No stepping through a program GPU Printf Debugger: Readback framebuffer content and analyze - Writing content to an image often helpful - Floating point render targets if precision matters, e.g. FBO with float texture as color attachment

Debugging / Profiling 45 / 49 Debugging / Profiling (cont d) GDebugger - OpenGL debugger - OpenGL state can be queried and compared / saved - Allows on-the-fly modification and re-compilation shader programs - Textures can be queried via an integrated image viewer - GUI integration for performance counter from 3DLabs and Nvidia, ATI will follow soon

Debugging / Profiling 46 / 49 Debugging / Profiling (cont d) GPUBench - Developed at the graphics lab in Stanford - Benchmark for GPUs with focus on features which are important for GPGPU - Provides brief summary over GPU capabilities Profiling libraries - Available from 3DLabs and Nvidia - Can be integrated into application - For many purposes integration into GDebugger sufficient

Debugging / Profiling 47 / 49 Shader Creation Tools Avoid overhead to write a full OpenGL / DirectX application just to write a shader Provide easy-to-use interface to change shader parameter, set lighting, load textures,... Nvidia: FXComposer 3DLabs / ATI: RenderMonkey Typhoon Labs: Shader Designer (Win / Linux)

What s coming next? 48 / 49 What s coming next? Geometry shader - Located after vertex processor in the existing pipeline - Primitive information available - Can generate geometry on the fly Unified shader processor units - In hardware, no distinction between vertex, geometry and fragment shader - Enables arbitrary feedback loops Support for integer in hardware

Questions 49 / 49 Questions?

Modern Graphics Processors Resources - OpenGL Shading Language (2nd Edition), Randi J. Rost, The first chapters gives an introduction into the GPU graphics pipeline. The next chapters provide information about the OpenGL Shading Language, in particular on how the client side API works, how to write a first shader and then different shaders are explained and its implementation is discussed. - The Cg Tutorial: The Definitive Guide to Programmable Real-Time Graphics, R. Fernando, M, J. Kilgard, Similar to the OpenGL Shading Language book by Randi Rost (see above) but it uses Cg as shading language. - www.gpgpu.org, Homepage on General Purpose Programming on GPUs, Has many material and links related to GPUs in general ans GPGPU. The FAQ (http://www.gpgpu.org/wiki/faq) provides a profound resource for writing shaders. - GPU Gems 2 : Programming Techniques for High-Performance Graphics and General-Purpose Computation, M. Pharr, R.Fernando, Six chapters discuss general programming models and techniques for GPUs as well as a concrete architecture. The remaining book is a collection of technical reports on advanced graphics and general purpose algorithms which use the GPU. - Programming Graphics Hardware, R. Fernando, M. Harris, M. Wloka and C. Zeller, Tutorial Notes, Eurographics 2004, August 2004, Evolution of GPUs, its working principles and recent trends. - Reality Engine graphics, K. Akeley, SIGGRAPH 1993, July 1993, Good explaination of the graphics pipeline (as implemented on SGI workstation) and the functionality of the different stages. The architecture discussed differs slightly from current GPUs but most discussions are still valid.

Modern Graphics Processors Resources (cont d) - http://www.cs.unc.edu/events/conferences/gp2/, GPGPU conference, the proceedings (can be found under program) provide an overview over applications possible on the GPU. - http://developer.3dlabs.com/opengl2/index.htm, 3DLabs developer support homepages, - http://developer.3dlabs.com/downloads/index.htm, Code examples and helpful tools, e.g. offline parser for GLSL - http://developer.3dlabs.com/documents/index.htm#presentations, Randi Rost s presentation GLSL Overview gives a concise overview about GLSL, its API and some examples (parts of this slides are based on his presentation) - http://developer.3dlabs.com/documents/glsl manpage_index.htm, GLSL API man pages online - http://developer.nvidia.com/page/home.html, Nvidia s developer support website - http://developer.nvidia.com/object/gpu_programming_guide.html, Many useful tips on how to write fast GPU applications - http://developer.nvidia.com/page/event_calendar.html, Presentation slides from various conferences including Siggraph and Eurographics. Helpful as an introduction for topics covered, often with good examples. - http://download.developer.nvidia.com/developer/sdk/individual_samples/samples.html, Many code examples, each covers a specific feature, similar to the OpenGL redbook examples, programs use either Cg or GLSL, Source code for Windows available, partially also for Linux - http://developer.nvidia.com/page/tools.html, Various tools for developer, including Cg libraries, FXComposer, Nvidia photoshop plugin, tool to generate normal maps, profiling tools,... - ftp://download.nvidia.com/developer/cg/cg_1.4/docs/cg_usermanual_1-4.pdf, The How to get started for Cg, containing explanation of the client and server side functionality and program examples.

Modern Graphics Processors Resources (cont d) - http://ww.ati.com/developer/, ATI s developer support website with code examples, demos, presentations, technical reports - http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=47, Tutorial how to write a simple vertex shader and the corresponding client side code - www.libsh.org, SH metaprogramming language - http://graphics.stanford.edu/projects/brookgpu/, BrookGPU language - http://graphics.stanford.edu/projects/gpubench/, GPU benchmark, check also the results section