30
Navendu Jain Programmable Hardware #2 Focus Current Programming Languages

Focus Current Programming Languagespl887.pairlitesite.com/.../presentations/Feb13-programmable-hardwar… · Graphics hardware approach Hybrid vertex/pixel shading Triangle Vertices

  • Upload
    others

  • View
    10

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Focus Current Programming Languagespl887.pairlitesite.com/.../presentations/Feb13-programmable-hardwar… · Graphics hardware approach Hybrid vertex/pixel shading Triangle Vertices

Navendu Jain

Programmable Hardware #2

Focus

Current Programming Languages

Page 2: Focus Current Programming Languagespl887.pairlitesite.com/.../presentations/Feb13-programmable-hardwar… · Graphics hardware approach Hybrid vertex/pixel shading Triangle Vertices

OutlineIntroduction

Cg

Shading and Lighting

Shading Languages

Related Issues and Discussion

Page 3: Focus Current Programming Languagespl887.pairlitesite.com/.../presentations/Feb13-programmable-hardwar… · Graphics hardware approach Hybrid vertex/pixel shading Triangle Vertices

OutlineIntroduction

Cg

Shading and Lighting

Shading Languages

Related Issues and Discussion

Page 4: Focus Current Programming Languagespl887.pairlitesite.com/.../presentations/Feb13-programmable-hardwar… · Graphics hardware approach Hybrid vertex/pixel shading Triangle Vertices

Evolution of the GPUSpecialized and highly parallelized design

"Big Iron" to "Single Chip“

Moore’s Law cubed

More Realistic and More Interactive

Programmability

Page 5: Focus Current Programming Languagespl887.pairlitesite.com/.../presentations/Feb13-programmable-hardwar… · Graphics hardware approach Hybrid vertex/pixel shading Triangle Vertices

GPU Model

Page 6: Focus Current Programming Languagespl887.pairlitesite.com/.../presentations/Feb13-programmable-hardwar… · Graphics hardware approach Hybrid vertex/pixel shading Triangle Vertices

GPU Programming Model

Programmable Vertex

Processor

Programmable Fragment Processor

Page 7: Focus Current Programming Languagespl887.pairlitesite.com/.../presentations/Feb13-programmable-hardwar… · Graphics hardware approach Hybrid vertex/pixel shading Triangle Vertices

ImpactResult

New H/w features, many APIs

Assembly Coding

Demand for more flexibility, control

SolutionRaise the level of abstraction

Programmability

Give me the power – Developer!!

Page 8: Focus Current Programming Languagespl887.pairlitesite.com/.../presentations/Feb13-programmable-hardwar… · Graphics hardware approach Hybrid vertex/pixel shading Triangle Vertices

Introduction

Cg

Shading and Lighting

Shading Languages

Related Issues and Discussion

Page 9: Focus Current Programming Languagespl887.pairlitesite.com/.../presentations/Feb13-programmable-hardwar… · Graphics hardware approach Hybrid vertex/pixel shading Triangle Vertices

Cg“C for graphics” ; developed by NVIDIA

Ease of Programming (tweak & run)

Virtualizes the hardware

Library of Shaders

Run-time compilation - optimization

Portable Programs

Page 10: Focus Current Programming Languagespl887.pairlitesite.com/.../presentations/Feb13-programmable-hardwar… · Graphics hardware approach Hybrid vertex/pixel shading Triangle Vertices

Language Profiles

GPUs don’t support the same capabilities

Profile defines a subset of the language supported on a particular hardware

Examples:Vertex Shaders

CG_PROFILE_VS_2_X, CG_PROFILE_ARBVP1Fragment Shaders

CG_PROFILE_PS_2_X, CG_PROFILE_ARBFP1

Page 11: Focus Current Programming Languagespl887.pairlitesite.com/.../presentations/Feb13-programmable-hardwar… · Graphics hardware approach Hybrid vertex/pixel shading Triangle Vertices

Programs

Operate on streams of data

Program Inputs and OutputsVarying (per-vertex, per-fragment values)Uniform (transformation matrix)

FeaturesIn-built Vector & Matrix supportNo support for pointersModifiable function params by value-resultSwizzle float3(a, b, c).zyx yields float3(c, b, a)

Page 12: Focus Current Programming Languagespl887.pairlitesite.com/.../presentations/Feb13-programmable-hardwar… · Graphics hardware approach Hybrid vertex/pixel shading Triangle Vertices

Cg runtime library

Page 13: Focus Current Programming Languagespl887.pairlitesite.com/.../presentations/Feb13-programmable-hardwar… · Graphics hardware approach Hybrid vertex/pixel shading Triangle Vertices

Introduction

Cg

Shading and Lighting

Shading Languages

Related Issues and Discussion

Page 14: Focus Current Programming Languagespl887.pairlitesite.com/.../presentations/Feb13-programmable-hardwar… · Graphics hardware approach Hybrid vertex/pixel shading Triangle Vertices

Background : Shading and Lighting

Shadingcolor, texture, optical, anistropic properties, illumination environment

AspectsSurface reflectance

Ambient, Diffuse, Specular, wavelength, polarization

Light source distributionPoint light sources, Geometric PrimitivesIntensity = f(x, y, z, λ, D)

Page 15: Focus Current Programming Languagespl887.pairlitesite.com/.../presentations/Feb13-programmable-hardwar… · Graphics hardware approach Hybrid vertex/pixel shading Triangle Vertices

Models of Shading

Inherently local processes

Global Illumination process

Kajiya's rendering equationGeneral Illumination Process

Local/ Global are independent aspects

i(x,x') = v(x,x') [l(x,x') + r(x,x',x'') i(x',x'') dx'‘ ]

Page 16: Focus Current Programming Languagespl887.pairlitesite.com/.../presentations/Feb13-programmable-hardwar… · Graphics hardware approach Hybrid vertex/pixel shading Triangle Vertices

Types of Shaders

Light Source l(x,x')Color, intensity emitted from a point

Surface Reflectance r(x,x',x'')Integral of bidirectional reflectance with incoming light

Volume or Atmosphere v(x,x')Scattering Effects

Other intersections handled by the Renderer

Page 17: Focus Current Programming Languagespl887.pairlitesite.com/.../presentations/Feb13-programmable-hardwar… · Graphics hardware approach Hybrid vertex/pixel shading Triangle Vertices

Introduction

Cg

Shading and Lighting

Shading Languages

Related Issues and Discussion

Page 18: Focus Current Programming Languagespl887.pairlitesite.com/.../presentations/Feb13-programmable-hardwar… · Graphics hardware approach Hybrid vertex/pixel shading Triangle Vertices

Shading LanguagesProgramming shading computations

Extend shading and lighting formulae, types of material and light sources

Offline Hanrahan’s, RenderMan

Real-Time Stanford Shading Language, NVIDIA’s Cg

Page 19: Focus Current Programming Languagespl887.pairlitesite.com/.../presentations/Feb13-programmable-hardwar… · Graphics hardware approach Hybrid vertex/pixel shading Triangle Vertices

DifferencesReal-Time Shading

Interactive appsLighting and Shader Anti-aliasing harderPerformance criticalFrame Rate (FPS)Execute on GPURendering cost per frame is bounded

Offline Shading

Fixed ViewpointFine Tuning

Non real-time

Execute on CPUDiffer by orders of magnitude

Page 20: Focus Current Programming Languagespl887.pairlitesite.com/.../presentations/Feb13-programmable-hardwar… · Graphics hardware approach Hybrid vertex/pixel shading Triangle Vertices

Shading approachesObject Space (at vertices)

REYES (Pixar’s PRMan)Change position (displacement map, procedural)

Dice ShaderProgram

Sample

3D Space

GeometricPrimitives

curved surfaces

Grids ofmicropolygans

in 3D

Shaded grids of micropolygans

in 3D Points In screen

space

Screen Space

Screen Space (at pixels)

Page 21: Focus Current Programming Languagespl887.pairlitesite.com/.../presentations/Feb13-programmable-hardwar… · Graphics hardware approach Hybrid vertex/pixel shading Triangle Vertices

Graphics hardware approachHybrid vertex/pixel shading

Triangle Vertices Fragment Shading

Can only change screen space depth

Vertex Shader

Program

Sample(rasterize)

FragmentShader

Program

3D Space

GeometricPrimitivesTriangular Polygons

Triangles In screen

space

Samples in screen space (fragments) Points

In screen space

Screen Space

Page 22: Focus Current Programming Languagespl887.pairlitesite.com/.../presentations/Feb13-programmable-hardwar… · Graphics hardware approach Hybrid vertex/pixel shading Triangle Vertices

Pros and ConsObject Space

Computations per polygonInexpensive motion-blur, depth of field effectsAnti-aliasing complex Geometric Normal

Hybrid Model

Computations per pixelExpensiveSimple derivative computationsOnly shading normal

Page 23: Focus Current Programming Languagespl887.pairlitesite.com/.../presentations/Feb13-programmable-hardwar… · Graphics hardware approach Hybrid vertex/pixel shading Triangle Vertices

Introduction

Cg

Shading and Lighting

Shading Languages

Related Issues and Discussion

Page 24: Focus Current Programming Languagespl887.pairlitesite.com/.../presentations/Feb13-programmable-hardwar… · Graphics hardware approach Hybrid vertex/pixel shading Triangle Vertices

Related Issues

Parallelism“Single” vertex modelMemory accessMultiple rendering passes

Computation modelSPMD (vertex) SIMD (fragment)

Page 25: Focus Current Programming Languagespl887.pairlitesite.com/.../presentations/Feb13-programmable-hardwar… · Graphics hardware approach Hybrid vertex/pixel shading Triangle Vertices

Related Issues (contd.)

Data Types (Low, High Precision)

Memory/Register resource limits

Host-to-GPU Bandwidth

Page 26: Focus Current Programming Languagespl887.pairlitesite.com/.../presentations/Feb13-programmable-hardwar… · Graphics hardware approach Hybrid vertex/pixel shading Triangle Vertices

Discussion

Surface and Light ShadersSeparabilityZ-buffer – surface rendererExpressibility powerUser’s flexibilityBinding Model

Early-binding (expensive)Late-binding (optimize)

Page 27: Focus Current Programming Languagespl887.pairlitesite.com/.../presentations/Feb13-programmable-hardwar… · Graphics hardware approach Hybrid vertex/pixel shading Triangle Vertices

Discussion (contd.)

Sharing ComputationsFP executed more than vertex programs

Move computation from FP to VPWhen : Result is

constant over all fragmentsLinear across a triangleNearly linear across a triangle

Move from VP to CPU (uniform params)

Page 28: Focus Current Programming Languagespl887.pairlitesite.com/.../presentations/Feb13-programmable-hardwar… · Graphics hardware approach Hybrid vertex/pixel shading Triangle Vertices

Discussion (contd.)

Optimizations Vector operations, swizzleLibrary of shadersLow precision data typesMinimize if/then/elseH/W – S/W approach

Page 29: Focus Current Programming Languagespl887.pairlitesite.com/.../presentations/Feb13-programmable-hardwar… · Graphics hardware approach Hybrid vertex/pixel shading Triangle Vertices

Thanks

Page 30: Focus Current Programming Languagespl887.pairlitesite.com/.../presentations/Feb13-programmable-hardwar… · Graphics hardware approach Hybrid vertex/pixel shading Triangle Vertices

References

"Real-Time Programmable Shading", excerpt from "Texturing and Modeling: A Procedural Approach", Ebert et al, pp. 97-121.

Cg toolkit user's manual", NVIDIA

Language for Shading and Lighting Calculations“ Hanrahan and Lawson, SIGGRAPH 90