Cg: A system for programming graphics hardware in a C-like language

Similar documents
Tutorial on GPU Programming. Joong-Youn Lee Supercomputing Center, KISTI

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

Comparing Reyes and OpenGL on a Stream Architecture

GpuPy: Accelerating NumPy With a GPU

Shading Languages for Graphics Hardware

Shaders. Slide credit to Prof. Zwicker

Hardware Shading: State-of-the-Art and Future Challenges

frame buffer depth buffer stencil buffer

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

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

A Real-Time Procedural Shading System for Programmable Graphics Hardware

The F-Buffer: A Rasterization-Order FIFO Buffer for Multi-Pass Rendering. Bill Mark and Kekoa Proudfoot. Stanford University

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

Graphics Hardware, Graphics APIs, and Computation on GPUs. Mark Segal

CS195V Week 9. GPU Architecture and Other Shading Languages

Basics of GPU-Based Programming

Shading Languages Tim Foley

Shaders (some slides taken from David M. course)

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

OpenGL Programmable Shaders

Complex Multipass Shading On Programmable Graphics Hardware

Sung-Eui Yoon ( 윤성의 )

Shaders CSCI 4239/5239 Advanced Computer Graphics Spring 2014

Real-Time Graphics Architecture

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

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

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

Shaders CSCI 4229/5229 Computer Graphics Fall 2017

PyFX: A framework for programming real-time effects

Graphics Hardware. Instructor Stephen J. Guy

SGI OpenGL Shader. Marc Olano SGI

Lecture 2. Shaders, GLSL and GPGPU

Programmable Graphics Hardware

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

Cg 2.0. Mark Kilgard

Introduction to Shaders.

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

Understanding Shaders and WebGL. Chris Dalton & Olli Etuaho

12.2 Programmable Graphics Hardware

CS GPU and GPGPU Programming Lecture 3: GPU Architecture 2. Markus Hadwiger, KAUST

DirectX Programming #4. Kang, Seongtae Computer Graphics, 2009 Spring

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

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

Programmable GPUs Outline

CIS 536/636 Introduction to Computer Graphics. Kansas State University. CIS 536/636 Introduction to Computer Graphics

Could you make the XNA functions yourself?

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

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

Dynamic Code Generation for Realtime Shaders

What s New with GPGPU?

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

Parallelizing Graphics Pipeline Execution (+ Basics of Characterizing a Rendering Workload)

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

GPU Programmable Graphics Pipeline

Real-Time Graphics Architecture

CS427 Multicore Architecture and Parallel Computing

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

Teaching Cg. This presentation introduces Cg ( C for graphics ) and explains why it would be useful when teaching a computer graphics course.

Cg Toolkit. Cg 1.3 Release Notes. December 2004

Consumer graphics cards for fast image processing based on the Pixel Shader 3.0 standard

Introduction. Chapter What Is Cg?

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

Programmable Graphics Hardware

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

printf Debugging Examples

GeForce 8 Features for OpenGL

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

Pat Hanrahan. Modern Graphics Pipeline. How Powerful are GPUs? Application. Command. Geometry. Rasterization. Fragment. Display.

Mobile Graphics Ecosystem. Tom Olson OpenGL ES working group chair

Parallelizing Graphics Pipeline Execution (+ Basics of Characterizing a Rendering Workload)

Shading Languages. Ari Silvennoinen Apri 12, 2004

Dave Shreiner, ARM March 2009

Programming Graphics Hardware

Shader Programming CgFX, OpenGL 2.0. Michael Haller 2003

Programming shaders & GPUs Christian Miller CS Fall 2011

CS GPU and GPGPU Programming Lecture 3: GPU Architecture 2. Markus Hadwiger, KAUST

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

Lecture 13: OpenGL Shading Language (GLSL)

Getting Started with Cg. Release 1.2 February 2004

Graphics Processing Unit With Graphics API. Darshana Mistry. Computer Engineering Department, Gandhinagar Institute Of Technology Gandhinagar, India

ECE 574 Cluster Computing Lecture 16

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

Experiences with gpu Computing

MXwendler Fragment Shader Development Reference Version 1.0

Sign up for crits! Announcments

Introduction to Programmable GPUs CPSC 314. Real Time Graphics

Threading Hardware in G80

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

GPU Memory Model. Adapted from:

1.2.3 The Graphics Hardware Pipeline

20 Years of OpenGL. Kurt Akeley. Copyright Khronos Group, Page 1

Introduction to Programmable GPUs CPSC 314. Introduction to GPU Programming CS314 Gordon Wetzstein, 09/03/09

GPU Memory Model Overview

Next Generation OpenGL Neil Trevett Khronos President NVIDIA VP Mobile Copyright Khronos Group Page 1

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

Intro to GPU Programming (OpenGL Shading Language) Cliff Lindsay Ph.D. Student CS WPI

Prospects for a more robust, simpler and more efficient shader cross-compilation pipeline in Unity with SPIR-V

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

Cornell University CS 569: Interactive Computer Graphics. Introduction. Lecture 1. [John C. Stone, UIUC] NASA. University of Calgary

Parallel Programming for Graphics

Transcription:

Cg: A system for programming graphics hardware in a C-like language William R. Mark University of Texas at Austin R. Steven Glanville NVIDIA Kurt Akeley NVIDIA and Stanford University Mark Kilgard NVIDIA

GPUs are now programmable Vertex Processor Triangle Assembly & Rasterization Fragment Processor Framebuffer Operations Framebuffer Texture Decompression & Filtering Textures MOV R4.y, R2.y; ADD R4.x, -R4.y, C[3].w; MAD R3.xy, R2, R3.xyww, C[2].z; ADD R3.xy, R3.xyww, C11.z; TEX H5, R3, TEX2, 2D; TEX H6, R3, TEX2, 2D;

Programmable units in GPUs are stream processors kernel state Input stream I1 I2 In Stream Processor Output stream O1 O2 On The programmable unit executes a computational kernel for each input element Streams consist of ordered elements

Example: Vertex processor Vertex Array V1 V2 Vn uniform values Vertex Processor Transformed Vertexes V1 V2 Vn Fragment processor can do more: It can read from texture memory

Previous work Earlier programmable graphics HW Ikonas [England 86] Pixar FLAP [Levinthal 87] UNC PixelFlow [Olano 98] Multipass SIMD: SGI ISL [Peercy00] RenderMan [Hanrahan90] Stanford RTSL [Proudfoot01]

Design goals Easier programming of GPUs Ease of adoption Portability HW, API, OS Complete support for HW capabilities Performance - similar to assembly Minimal interference with application data Longevity -- useful for future hardware Support for non-shading computations Non-goal: Backward compatibility

The design process Concentrate on: Overall system architecture System interfaces: Cg language and APIs What principles guided the design? Why did we make the choices we did? What alternatives did we consider?

Major Design Decisions

Modular or monolithic architecture? Cg system is modular Provides access to assembly-level interfaces GLSL made different choices Compile off-line, or at run time Cg OpenGL runtime OpenGL API GPU Application Cg Direct3D runtime Direct3D API Cg common runtime (compiler) The Cg system manages Cg programs AND the flow of data on which they operate

Specialize for shading? RenderMan language is domain-specific Domain-specific types (e.g. color ) Domain-specific constructs (e.g. illuminance ) Imposes a particular model on the user C is general purpose A HW oriented language Avoids assumptions about problem domain Cg follows C s philosophy language follows syntax and philosophy of C Targets GPU HW performance transparency Some exceptions we were not dogmatic

Cg language example void simpletransform(float4 objectposition : POSITION, float4 color : COLOR, float4 decalcoord : TEXCOORD0, out float4 clipposition : POSITION, out float4 Color : COLOR, out float4 odecalcoord : TEXCOORD0, uniform float brightness, uniform float4x4 modelviewprojection) { clipposition = mul(modelviewprojection, objectposition); ocolor = brightness * color; odecalcoord = decalcoord; }

One program or two? Vertex Processor Triangle Assembly & Rasterization Fragment Processor Framebuffer Operations Framebuffer Texture Decompression & Filtering Textures void vprog(float4 objp : POSITION, float4 color : COLOR, Vertex program void fprog(float4 t0 : TEXCOORD0, float4 t1 : TEXCOORD1, Fragment program

How should stream HW be exposed in the language? How should stream inputs be accessed? Global variables? Parameters to main()? our choice How should stream outputs be written? Global variables? Output parameters from main()? our choice Should we distinguish between stream inputs and kernel state? e.g. vertex position vs. modelview matrix HW makes a distinction; so we expose it State parameters marked with keyword: uniform

How should system support different levels of HW? NV20 R200 R300 NV30 NV40 R400 NV50? HW capabilities change each generation Data types Support for branch instructions, We expect this problem to persist Future GPUs will have new features Mandate exactly one feature set? Must strand older HW or limit newer HW

Two options for handling HW differences Emulate missing features? Too slow on GPU Too slow on CPU, especially for fragment HW Expose differences to programmer? We chose this option Differences exposed via subsetting A profile is a named subset Cg supports function overloading by profile

Two detailed design decisions

How to specify a returnable function parameter? C uses pointers But no pointers on current GPUs void foobar(float *y) { *y = 2*x; C++ uses pass-by-reference: float &y Preferred implementation still uses pointers Cg uses pass-by-value-result Implementation doesn t need pointers void foobar(out float y) { y = 2*x;. By using new syntax, we preserve C and C++ syntax for the future

General mechanism for surface/light separability SURFACE 1 SURFACE 2 LIGHT 1 LIGHT 3 LIGHT 2 Convenient to put surface and light code in different modules Decouples surface selection from light selection Proven usefulness: Classic OpenGL; RenderMan; etc. We lost it for a while! RenderMan uses a specialized mechanism Cg uses a general-purpose mechanism More flexible Follows C-like philosophy

Light/surface example First: Declare an interface // Declare interface to lights interface Light { float3 direction(float3 from); float4 illuminate(float3 p, out float3 lv); }; Mechanism adapted from Java, C#

Second: Declare a light that implements interface // Declare object type for point lights struct PointLight : Light { float3 pos, color; float3 direction(float3 p) { return pos - p; } float3 illuminate(float3 p, out float3 lv) { lv = normalize(direction(p)); return color; } }; Declare an object that implements the interface

Third: Define surface that calls interface // Main program (surface shader) float4 main(appin IN, out float4 COUT, uniform Light lights[ ]) {... for (int i=0; i < lights.length; i++) { // for each light Cl = lights[i].illuminate(in.pos, L); // get dir/color color += Cl * Plastic(texcolor, L, Nn, In, 30); // apply } COUT = color; } Call object(s) via the interface type

Cg is closely related to other recent languages Microsoft HLSL Largely compatible with Cg NVIDIA and Microsoft collaborated OpenGL ARB shading language All three languages are similar Overlapping development Extensive cross-pollination of ideas Designers mostly agreed on right approach Systems are different

Summary Cg system: A system for programming GPUs Cg language: Extends and restricts C as needed for GPU s Expresses stream kernels HW oriented language Designed to age well By reintroducing missing C features

Acknowledgements Language co-designers at Microsoft: Craig Peeper and Loren McQuade Interface functionality: Craig Kolb, Matt Pharr Initial language direction: Cass Everitt Standard library: Chris Wynn Design and implementation team: Geoff Berry, Mike Bunnell, Chris Dodd, Wes Hunt, Jayant Kolhe, Rev Lebaredian, Nathan Paymer, Matt Pharr, Doug Rogers Director: Nick Triantos Many others at NVIDIA and Microsoft Code and experience from Stanford RTSL: Kekoa Proudfoot, Pat Hanrahan, and others

Demo and Questions