Programmable GPUs Outline

Similar documents
OpenGL Programmable Shaders

OpenGL Rendering Pipeline and Programmable Shaders

OpenGL Rendering Pipeline and Programmable Shaders

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

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

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

Supplement to Lecture 22

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

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

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

Programmable Graphics Hardware

Programmable Graphics Hardware

12.2 Programmable Graphics Hardware

The Application Stage. The Game Loop, Resource Management and Renderer Design

Shaders. Slide credit to Prof. Zwicker

Introduction to Shaders.

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

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

Lecture 13: OpenGL Shading Language (GLSL)

Spring 2009 Prof. Hyesoon Kim

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

Lecture 2. Shaders, GLSL and GPGPU

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

Programming shaders & GPUs Christian Miller CS Fall 2011

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

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

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

GPU Programming EE Final Examination

Could you make the XNA functions yourself?

Spring 2011 Prof. Hyesoon Kim

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

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

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

Next-Generation Graphics on Larrabee. Tim Foley Intel Corp

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

Real-Time Rendering (Echtzeitgraphik) Michael Wimmer

The Graphics Pipeline

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

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

Introduction to Shaders for Visualization. The Basic Computer Graphics Pipeline

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

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

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

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

Lecture 09: Shaders (Part 1)

Shaders CSCI 4229/5229 Computer Graphics Fall 2017

CHAPTER 1 Graphics Systems and Models 3

CS451Real-time Rendering Pipeline

Shaders CSCI 4239/5239 Advanced Computer Graphics Spring 2014

GPU Memory Model. Adapted from:

Shading Languages. Ari Silvennoinen Apri 12, 2004

EE 4702 GPU Programming

Real-Time Graphics Architecture

Graphics Processing Unit Architecture (GPU Arch)

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

GPU Programming EE Final Examination

Sung-Eui Yoon ( 윤성의 )

GPU Programming EE Final Examination

Shading Language Update

Blis: Better Language for Image Stuff Project Proposal Programming Languages and Translators, Spring 2017

The GPGPU Programming Model

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

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

Rendering Objects. Need to transform all geometry then

Computer Graphics Coursework 1

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

API Background. Prof. George Wolberg Dept. of Computer Science City College of New York

Shader Series Primer: Fundamentals of the Programmable Pipeline in XNA Game Studio Express

2.11 Particle Systems

GeForce4. John Montrym Henry Moreton

Programming Graphics Hardware

CS770/870 Spring 2017 Open GL Shader Language GLSL

CS770/870 Spring 2017 Open GL Shader Language GLSL

Mali Demos: Behind the Pixels. Stacy Smith

Comp 410/510 Computer Graphics Spring Programming with OpenGL Part 2: First Program

Ciril Bohak. - INTRODUCTION TO WEBGL

CS 4620 Program 3: Pipeline

Dave Shreiner, ARM March 2009

GPU Programming EE Final Examination

Cg 2.0. Mark Kilgard

EDAF80 Introduction to Computer Graphics. Seminar 3. Shaders. Michael Doggett. Slides by Carl Johan Gribel,

Lecture 9(B): GPUs & GPGPU

GPU Memory Model Overview

PowerVR Hardware. Architecture Overview for Developers

CS 432 Interactive Computer Graphics

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 #5: Rasterization. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2015

CS 130 Final. Fall 2015

Chapter 1 Introduction

OPENGL AND GLSL. Computer Graphics

Graphics Hardware. Instructor Stephen J. Guy

Sign up for crits! Announcments

GPU Programming EE Midterm Examination

CS8803SC Software and Hardware Cooperative Computing GPGPU. Prof. Hyesoon Kim School of Computer Science Georgia Institute of Technology

WebGL and GLSL Basics. CS559 Fall 2015 Lecture 10 October 6, 2015

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

OPENGL RENDERING PIPELINE

CS770/870 Fall 2015 Advanced GLSL

CS230 : Computer Graphics Lecture 4. Tamar Shinar Computer Science & Engineering UC Riverside

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

Transcription:

papi 1 Outline References Programmable Units Languages Programmable GPUs Outline papi 1 OpenGL Shading Language papi 1 EE 7700-1 Lecture Transparency. Formatted 11:30, 25 March 2009 from set-prog-api. papi 1

papi 2 OpenGL OpenGL Shading Language References papi 2 John Kessenich, The OpenGL Shading Language, OpenGL Language Version 1.20, Document Revision 8, September 2006. OpenGL Commands for Shader Language Control Mark Segal, Kurt Akeley, The OpenGL Graphics System: A Specification (Version 2.1), OpenGL, July 2006. papi 2 EE 7700-1 Lecture Transparency. Formatted 11:30, 25 March 2009 from set-prog-api. papi 2

papi 3 Programmable Units papi 3 Programmable Unit: Part of the pipeline that can be programmed (as defined by some API). Choice of what is and isn t programmable constrained by: Need to allow for parallel (multithreaded, SIMD, MIMD) execution. Simple memory access. OpenGL Programmable Units Vertex Processor: Transform vertex and texture coordinates, compute lighting. Geometry Processor: Using a transformed primitive and its neighbors generates new primitives. For example, replace one triangle with many triangles to more closely match a curved surface. (Not in OpenGL 2.1, defined in extensions.) Fragment Processor: Using interpolated coordinates, read filtered texels and combine with colors. papi 3 EE 7700-1 Lecture Transparency. Formatted 11:30, 25 March 2009 from set-prog-api. papi 3

papi 4 Languages papi 4 Shader: A programmable part of a GPU. Name is now misleading but is still in common use. Shader Language: An language for programming shaders. Shader Assembly Language: An assembly-like language for programming GPUs. High-Level Shader Language: A high-level language for programming GPUs. papi 4 EE 7700-1 Lecture Transparency. Formatted 11:30, 25 March 2009 from set-prog-api. papi 4

papi 5 Shader Assembly Language Shader Assembly Language papi 5 At one time, only way to program. Unlike a true assembly language...... no instruction encoding defined...... no promise of a one-to-one correspondence with machine instructions. Translated into machine instructions (or micro-instructions) by API implementation. Many APIs not picky about matching assembly language to target. Currently might be used for tuning code from high-level shader language. Separate languages defined for vertex, geometry, and fragment processors. Early languages closely match underlying hardware, so more useful for performance tuning. Defined as OpenGL extensions. papi 5 EE 7700-1 Lecture Transparency. Formatted 11:30, 25 March 2009 from set-prog-api. papi 5

papi 6 Shader Assembly Languages papi 6 First-Generation Languages NV vertex program (For vertex processor) Close match to GEForce 3 hardware. No branches or memory (texture or otherwise) access. NV fragment program (2003) (For fragment processor) Arbitrary texel access. (Can ignore or modify provided texture coords.) Instructions for texture access and interpolation. No branching. papi 6 EE 7700-1 Lecture Transparency. Formatted 11:30, 25 March 2009 from set-prog-api. papi 6

papi 7 Shader Assembly Languages papi 7 Second-Generation Languages NV vertex program2, NV vertex program3. NV fragment program2, Later Languages Full support for integer operations, branching. NV gpu program4: Instructions common to each kind of shader. NV vertex program4. NV geometry program4. NV fragment program4. papi 7 EE 7700-1 Lecture Transparency. Formatted 11:30, 25 March 2009 from set-prog-api. papi 7

papi 8 High-Level Shader Languages papi 8 High-Level Shader Languages OpenGL Shader Language OpenGL standard. Syntax very similar to C. Language designed for vertex and fragment shaders. Current version is 1.3. Cg Originated with ATI, adopted in Direct3D. Syntax very similar to C. Language designed for stream programs...... geometry, vertex, and fragment programs can be in stream form. papi 8 EE 7700-1 Lecture Transparency. Formatted 11:30, 25 March 2009 from set-prog-api. papi 8

papi 9 OpenGL Shader Language (OGSL) papi 9 OpenGL Shader Language Important Features C-like CPP-like preprocessor directives. Library of useful functions. papi 9 EE 7700-1 Lecture Transparency. Formatted 11:30, 25 March 2009 from set-prog-api. papi 9

papi 10 Data Types OGSL Data Types papi 10 OpenGL Shading Language 1.30 Section 4.1 Scalar types: bool, int, float Vectors of bool, int, float. Element access: xyzw, rgba, stpq. E.g., var.xy, var.r Matrices of float. Structures papi 10 EE 7700-1 Lecture Transparency. Formatted 11:30, 25 March 2009 from set-prog-api. papi 10

papi 11 Integer Signed and unsigned. Thirty-two bits. OGSL Data Types papi 11 Earlier versions had lower precision and lacked bitwise operations.) papi 11 EE 7700-1 Lecture Transparency. Formatted 11:30, 25 March 2009 from set-prog-api. papi 11

papi 12 Float IEEE 754 Single Format OGSL Data Types papi 12 Calculations may be to less than IEEE 754 precision. papi 12 EE 7700-1 Lecture Transparency. Formatted 11:30, 25 March 2009 from set-prog-api. papi 12

papi 13 Example OGSL Data Types papi 13 vec4 vertex_e = gl_modelviewmatrix * o_point; vec3 norm_e = gl_normalmatrix * gl_normal; vec4 light_pos = gl_lightsource[1].position; float phase_light = dot(norm_e, normalize(light_pos - vertex_e).xyz); float phase_user = dot(norm_e, -vertex_e.xyz); float phase = sign(phase_light) == sign(phase_user)? abs(phase_light) : 0.0; papi 13 EE 7700-1 Lecture Transparency. Formatted 11:30, 25 March 2009 from set-prog-api. papi 13

papi 14 Variable Types OGSL Data Types papi 14 Uniforms: Read-only by shader. Changed by client, change is time consuming. Implemented as shader constants. Attributes: Read-only by vertex shader, not available to fragment shader. Changed by client, change is fast. Varying: Written by vertex shader, interpolated for fragment shader where read-only. Sampler: Read-only by vertex and fragment shader. Value is a filtered texel. papi 14 EE 7700-1 Lecture Transparency. Formatted 11:30, 25 March 2009 from set-prog-api. papi 14

papi 15 Storage Qualifiers const attribute Read only. OGSL Data Types papi 15 Not allowed in fragment shaders. uniform Read only. varying Written by vertex shader. Interpolated for fragment shader. Read only for fragment shaders. papi 15 EE 7700-1 Lecture Transparency. Formatted 11:30, 25 March 2009 from set-prog-api. papi 15

papi 16 papi 16 Storage Qualifier Example uniform vec3 gravity_force; uniform float gs_constant; uniform vec2 ball_size; attribute float step_last_time; attribute vec4 position_left, position_right, position_above, position_below; attribute vec3 ball_speed; varying vec4 out_position; varying vec3 out_velocity; papi 16 EE 7700-1 Lecture Transparency. Formatted 11:30, 25 March 2009 from set-prog-api. papi 16

papi 17 Function Parameters OGSL Functions papi 17 OpenGL Shading Language 1.30 Section 4.4 Call by value. Parameter Qualifiers: in (default) out inout papi 17 EE 7700-1 Lecture Transparency. Formatted 11:30, 25 March 2009 from set-prog-api. papi 17

papi 18 Built In Variables OGSL Functions papi 18 OpenGL Shading Language 1.30 Section 7 Pre-defined uniform, attribute, and varying variables. papi 18 EE 7700-1 Lecture Transparency. Formatted 11:30, 25 March 2009 from set-prog-api. papi 18

papi 19 Built In Functions OGSL Functions papi 19 See OpenGL Shading Language 1.30 Section 8 papi 19 EE 7700-1 Lecture Transparency. Formatted 11:30, 25 March 2009 from set-prog-api. papi 19

papi 20 Code Use Overview OGSL Use papi 20 Suppose something (tube) needs special lighting. Shader language code in light.cc. All steps below done by code using OpenGL. Initialize step: Load, compile, and link light.cc. During render, when ready for tube: Install light.cc. As needed, write uniform values. At this point all vertices handled by light.cc. When done with tube install another shader or switch to fixed func. papi 20 EE 7700-1 Lecture Transparency. Formatted 11:30, 25 March 2009 from set-prog-api. papi 20

papi 21 See OpenGL 2.1 Section 2.15 Initialize Program OGSL Use papi 21 Create Shader Object sobject = glcreateshader(gl VERTEX SHADER) Provide Source Code to Shader Object glshadersource(sobject,1,&shader text lines,null); Compile Shader Object glcompileshader(sobject); Attach and Link glattachshader(pobject,sobject); gllinkprogram(pobject); Use gluseprogram(pobject); papi 21 EE 7700-1 Lecture Transparency. Formatted 11:30, 25 March 2009 from set-prog-api. papi 21

papi 22 OGSL Use papi 22 Obtaining and Using Variable References At run time variables identified by number. At Initialization get location (index) of attributes and uniforms: vsal pinnacle = glgetattriblocation(pobject,name); sun ball size = glgetuniformlocation(pobject,name); During Render (Infrequently) Change Uniform Value (Using location) gluniform2f(sun ball size,ball size,ball size sq); During Render (Per Vertex Okay) Change Attribute Value (Using location) glvertexattrib4f(vsal pinnacle,pinnacle.x,pinnacle.y,pinnacle.z,radius); Done before each glvertex. Same options as vertex, such as client and buffer object arrays. papi 22 EE 7700-1 Lecture Transparency. Formatted 11:30, 25 March 2009 from set-prog-api. papi 22

papi 23 Vertex Shader Examples OGSL Vertex Shader Examples papi 23 Minor variation on lighting. Compute geometry of bump and circle. Physics papi 23 EE 7700-1 Lecture Transparency. Formatted 11:30, 25 March 2009 from set-prog-api. papi 23

papi 24 OGSL Vertex Shader Example papi 24 Example: Variation on Lighting Program: cube4.cc (gpu acceleration off) Shader Code: cube4 vshader.cc::vs main lighting() Why: Tweak lighting. Notes: Shader computes transformation, lighting, and texture coordinates. Program switches between vs main lighting and fixed func. papi 24 EE 7700-1 Lecture Transparency. Formatted 11:30, 25 March 2009 from set-prog-api. papi 24

papi 25 OGSL Vertex Shader Example papi 25 Example: Compute Geometry Program: cube4.cc (gpu acceleration on) Why: Less work for CPU. Shader Code: cube4 vshader.cc::vs main circle() and vs main bump() Notes: Not a geometry shader. Program switches between vs main circle, vs main bump and fixed func. papi 25 EE 7700-1 Lecture Transparency. Formatted 11:30, 25 March 2009 from set-prog-api. papi 25

papi 26 Example: Physics Program: cube5.cc OGSL Vertex Shader Example papi 26 What: Shader time-steps lattice of masses. Why: Less work for CPU. papi 26 EE 7700-1 Lecture Transparency. Formatted 11:30, 25 March 2009 from set-prog-api. papi 26

papi 27 Sample Program cube4.cc Displays a rotating cube. Sample Program cube4.cc papi 27 Cube faces have textures: syllabus, pic of EE building, etc. Ball bouncing around cube. Low-speed impact: color circle. High-speed impact: bump. Vertex Shader Uses Lighting tweak. Circle painting. Bump painting. papi 27 EE 7700-1 Lecture Transparency. Formatted 11:30, 25 March 2009 from set-prog-api. papi 27

papi 28 Data Representations Cube: Sample Program cube4.cc papi 28 Admittedly messy part of code. Cube position: transformation matrix in pcube. Textures: pcube Face Info (6-element array). History of ball contact: pcontact List (6-element array). Ball: position, speed, size. papi 28 EE 7700-1 Lecture Transparency. Formatted 11:30, 25 March 2009 from set-prog-api. papi 28

papi 29 Physics Sample Program cube4.cc papi 29 At each time step...... move cube to new position...... move ball to new position. To move cube: update rotation matrix using time and spin rate. To move ball: Find next intercept of ball trajectory with cube face. If intercept after end of time step, done. Record intercept position and ball velocity. Recompute ball trajectory and repeat. papi 29 EE 7700-1 Lecture Transparency. Formatted 11:30, 25 March 2009 from set-prog-api. papi 29

papi 30 Graphics Sample Program cube4.cc papi 30 Trivial Case: no translucency and ball doesn t leave marks: Render cube faces and ball. Middle Case: no translucency but ball does leave marks: Stencil holes at collision points. Render face using stencil to leave hole positions unchanged. Render bumps. Render ball. Code as Written: translucency and ball leaves marks: Sort faces so that face never under one already rendered. Render bumps before face if bump behind face. papi 30 EE 7700-1 Lecture Transparency. Formatted 11:30, 25 March 2009 from set-prog-api. papi 30

papi 31 Code Organization Sample Program cube4.cc papi 31 Initialization: Set idle callback. Idle Callback: Wait for beginning of display refresh (or 30ms)...... request redisplay. Redisplay: Advance physics (time step), then render frame. papi 31 EE 7700-1 Lecture Transparency. Formatted 11:30, 25 March 2009 from set-prog-api. papi 31

papi 32 Use of Vertex Shaders Sample Program cube4.cc papi 32 Lighting (vs lighting). Used for cube faces (except marks). Circle (vs circle). Used for stenciling and drawing circles. Bump (vs bump). Used for drawing bump. papi 32 EE 7700-1 Lecture Transparency. Formatted 11:30, 25 March 2009 from set-prog-api. papi 32