The Cg Runtime Cyril Zeller. Cg Pipeline Graphics programs are written in Cg...... and compiled to...... low-level assembly code... Cg Runtime API...

Slides:



Advertisements
Similar presentations
Teaching Cg. Real-Time Graphics Has Come a Long Way Virtua Fighter (SEGA Corporation) NV1 50K triangles/sec 1M pixel ops/sec 1995 Dead or Alive 3 (Tecmo.
Advertisements

MVisio: a multi-device 2D/3D graphic engine for PDAs, PCs and CAVEs Achille Peternier, Ph. D. Student VRLab, EPFL, Switzerland 3D Mental Vision.
Debugging Tools Tim Purcell NVIDIA. Programming Soap Box Successful programming systems require at least three ‘tools’ Successful programming systems.
COMPUTER GRAPHICS CS 482 – FALL 2014 NOVEMBER 10, 2014 GRAPHICS HARDWARE GRAPHICS PROCESSING UNITS PARALLELISM.
Lecture 38: Chapter 7: Multiprocessors Today’s topic –Vector processors –GPUs –An example 1.
Fast rendering of 2D applications with text and images Combines the power of DirectX and the convenience of.NET Adopted by most triple-A titles.
© David Kirk/NVIDIA and Wen-mei W. Hwu, ECE408, University of Illinois, Urbana-Champaign 1 Programming Massively Parallel Processors Chapter.
Status – Week 291 Victor Moya. Tracing 3D applications Three layers or levels for tracing: Three layers or levels for tracing: 3D Appl API Driver GPU.
Atila OGL library “T&L emulated via Vertex Shaders”
Cg: C for Graphics Jon Moon Based on slides by Eugene Lee.
The programmable pipeline Lecture 10 Slide Courtesy to Dr. Suresh Venkatasubramanian.
LAB #1: Computer Graphics Framework IGX is a set of programs which allow you to write graphics programs in C/C++ from plain text files. Benefits: 1. You.
Cg Overview Cg is the High Level language from NVIDIA for programming GPUs, developed in close collaboration with Microsoft Cg is 100% compatible with.
Computer Science – Game DesignUC Santa Cruz Adapted from Jim Whitehead’s slides Shaders Feb 18, 2011 Creative Commons Attribution 3.0 (Except copyrighted.
OPTIMIZING AND DEBUGGING GRAPHICS APPLICATIONS WITH AMD'S GPU PERFSTUDIO 2.5 GPG Developer Tools Gordon Selley Peter Lohrmann GDC 2011.
You can use 3D graphics to enhance and differentiate your Metro style app.
Cg Kevin Bjorke GDC NVIDIA CONFIDENTIAL A Whole New World with Cg Graphics Program Written in Cg “C” for Graphics Compiled & Optimized Low Level,
Cg – C for Graphics Eric Vidal CS 280. History General graphics processing languages – Renderman shading language (1988) Assembly languages for graphics.
Antigone Engine Kevin Kassing – Period
CHAPTER 4 Window Creation and Control © 2008 Cengage Learning EMEA.
G3D Design Goals C++ library of code common to every 3D project Write once, compile everywhere Safe and fast Prototype a game in one week Maximize flexibility.
Real-time Graphical Shader Programming with Cg (HLSL)
차세대 그래픽 개발 환경.NET & DirectX 강성재 Community Specialist Microsoft Corporation.
Geometric Objects and Transformations. Coordinate systems rial.html.
Graphics Graphics Korea University cgvr.korea.ac.kr 1 Using Vertex Shader in DirectX 8.1 강 신 진
GPU Shading and Rendering Shading Technology 8:30 Introduction (:30–Olano) 9:00 Direct3D 10 (:45–Blythe) Languages, Systems and Demos 10:30 RapidMind.
Computer Graphics Tz-Huan Huang National Taiwan University.
The Graphics Rendering Pipeline 3D SCENE Collection of 3D primitives IMAGE Array of pixels Primitives: Basic geometric structures (points, lines, triangles,
Real-Time Shading Using Programmable Graphics Hardware Introduction, Setup and Examples Wan-Chun Ma National Taiwan University.
Incell Phonium Processor Design Specifications Dale Mansholt Aaron Drake Jonathan Scruggs Travis Svehla Incell Phonium Processor.
The programmable pipeline Lecture 3.
CSE 690: GPGPU Lecture 6: Cg Tutorial Klaus Mueller Computer Science, Stony Brook University.
CS 4363/6353 OPENGL BACKGROUND. WHY IS THIS CLASS SO HARD TO TEACH? (I’LL STOP WHINING SOON) Hardware (GPUs) double in processing power ever 6 months!
CS 480/680 Intro Dr. Frederick C Harris, Jr. Fall 2014.
NVIDIA CONFIDENTIAL Hardware Shading for Artists.
CS662 Computer Graphics Game Technologies Jim X. Chen, Ph.D. Computer Science Department George Mason University.
3D Programming and DirectX API. Content Mathematics Mathematics Prepare to Write a 3D program Prepare to Write a 3D program Program Structure Program.
Introduction to OpenGL  OpenGL is a graphics API  Software library  Layer between programmer and graphics hardware (and software)  OpenGL can fit in.
David Luebke 1 11/24/2015 Programmable Graphics Hardware.
Survey of Program Compilation and Execution Bangor High School Ali Shareef 2/28/06.
Havok FX Physics on NVIDIA GPUs. Copyright © NVIDIA Corporation 2004 What is Effects Physics? Physics-based effects on a massive scale 10,000s of objects.
Computer Graphics 3 Lecture 6: Other Hardware-Based Extensions Benjamin Mora 1 University of Wales Swansea Dr. Benjamin Mora.
David Luebke 1 1/25/2016 Programmable Graphics Hardware.
© David Kirk/NVIDIA and Wen-mei W. Hwu, ECE408, University of Illinois, Urbana-Champaign 1 Programming Massively Parallel Processors Lecture.
Ray Tracing using Programmable Graphics Hardware
Mesh Skinning Sébastien Dominé. Agenda Introduction to Mesh Skinning 2 matrix skinning 4 matrix skinning with lighting Complex skinning for character.
Advanced D3D10 Shader Authoring Presentation/Presenter Title Slide.
CgFX Sébastien Dominé, NVIDIA. Overview What is CgFX? CgFX runtime Production pipeline with CgFX CgFX Tools set Demo.
An Introduction to the Cg Shading Language Marco Leon Brandeis University Computer Science Department.
Graphics Programming. Graphics Functions We can think of the graphics system as a black box whose inputs are function calls from an application program;
COMP 175 | COMPUTER GRAPHICS Remco Chang1/XX13 – GLSL Lecture 13: OpenGL Shading Language (GLSL) COMP 175: Computer Graphics April 12, 2016.
Chapter 6 Testing and running a solution. Errors X Three types Syntax Logic Run-time.
How to use a Pixel Shader CMT3317. Pixel shaders There is NO requirement to use a pixel shader for the coursework though you can if you want to You should.
COMPUTER GRAPHICS CHAPTER 38 CS 482 – Fall 2017 GRAPHICS HARDWARE
Antigone Engine.
Build /24/2018 © 2014 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks.
Introduction to OpenGL
Chapter 6 GPU, Shaders, and Shading Languages
Certifying graphics experiences on Windows 8
Introduction to Programmable Hardware
Graphics Processing Unit
Where does the Vertex Engine fit?
Computer Graphics Practical Lesson 10
Debugging Tools Tim Purcell NVIDIA.
Computer Graphics Introduction to Shaders
CIS 441/541: Introduction to Computer Graphics Lecture 15: shaders
Introduction to OpenGL
OpenGL Background CS 4722.
OpenGL-Rendering Pipeline
CIS 6930: Chip Multiprocessor: GPU Architecture and Programming
Presentation transcript:

The Cg Runtime Cyril Zeller

Cg Pipeline Graphics programs are written in Cg and compiled to low-level assembly code... Cg Runtime API... that runs on any GPU compatible with DirectX or OpenGL

At initialization: Load assembly or binary program For every frame: Load program parameters to hardware registers Set rendering state Load geometry Render … DP3 r0.x, f[TEX0], f[TEX0]; RSQ r0.x, r0.x; MUL r0, r0.x, f[TEX0]; DP3 r1.x, f[TEX1], f[TEX1]; RSQ r1.x, r1.x; MUL r1, r1.x, f[TEX1]; DP3 r0, r0, r1; MAX r0.x, r0.x, 1.0; MUL r0, r0.x, DIFFUSE; TEX r1, f[TEX1], 0, 2D; MUL r0, r0, r1; … Compiling Offline // // Diffuse lighting // float d = dot(normalize(frag.N), normalize(frag.L)); if (d < 0) d = 0; c = d*tex2D(t, frag.uv)*diffuse; … Cg program source code Shader program assembly code At Development TimeAt Runtime Shader program binary code Cg Compiler Shader Compiler (nvasm.exe, psa.exe)

Compiling at Runtime At Development TimeAt Runtime // // Diffuse lighting // float d = dot(normalize(frag.N), normalize(frag.L)); if (d < 0) d = 0; c = d*tex2D(t, frag.uv)*diffuse; … Cg program source code At initialization: Compile and load Cg program For every frame: Load program parameters with the Cg Runtime API Set rendering state Load geometry Render

Pros and Cons of Runtime Compilation Pros: Future compatibility: The application does not need to change to benefit from future compilers (future optimizations, future hardware) Easy parameter management Cons: Loading takes more time because of compilation Cannot tweak the result of the compilation

Cg Runtime Architecture Core Cg Runtime: cgCreateProgram Direct3D Cg Runtime: cgD3D9LoadProgram OpenGL Cg Runtime: cgGLLoadProgram

Core Cg Runtime Does not make any 3D API call Allows you to: Create a context: cgCreateContext() Compile a program for a given profile (vs_2_0, vs_2_x, ps_2_0, ps_2_x, arbvp1, arbvp1, vs_1_1, ps_1_1, fp20, etc...) : cgCreateProgram(), cgGetProgramString(), etc... Manage program parameters: Iterate through the parameters: cgGetFirstParameter(), cgGetNextParameter(), etc... Get parameter information: type, semantic, register,... Handle errors: cgGetError(), cgSetErrorCallback(), etc...

Direct3D Cg Runtime: Minimal Interface Does not make any Direct3D call Allows you to translate the information obtained through the Core Runtime to Direct3D data structures, so that you can: Create a Direct3D vertex declaration from the Cg program: cgD3D9GetVertexDeclaration() Validate a Direct3D vertex declaration against the Cg program: cgD3D9ValidateVertexDeclaration() and create a Direct3D vertex or pixel shader from the Cg program

Direct3D Cg Runtime: Expanded Interface Makes the necessary Direct3D calls for you Allows you to: Pass the Direct3D device: cgD3D9SetDevice() Load a program into Direct3D: cgD3D9LoadProgram() Tell Direct3D to render with it: cgD3D9BindProgram() Set parameter values: cgD3D9SetUniform(), cgD3D9SetUniformArray(), cgD3D9SetTexture(), etc... Output debug information by using the Cg Runtime debug DLL

OpenGL Cg Runtime Makes the necessary OpenGL calls for you Allows you to: Load a program into OpenGL: cgGLLoadProgram() Enable a profile: cgGLEnableProfile() Tell OpenGL to render with it: cgGLBindProgram() Set parameter values: cgGLSetParameter{1234}{fd}{v}(), cgGLSetParameterArray{1234}{fd}(), cgGLSetTextureParameter(), etc...

Learning the Runtime The documentation is in: Windows: C:\Program Files\NVIDIA Corporation\Cg\docs Linux: /usr/share/doc/Cg It includes: A Using the Cg Runtime Library chapter from the Cg User’s Manual Manual pages for every function Source code examples are in: Windows: C:\Program Files\NVIDIA Corporation\Cg\examples Linux: /usr/local/Cg/examples They include self-contained Direct3D and OpenGL examples

Questions, comments, feedback? Cyril Zeller, For Cg support Go to developer.nvidia.com/Cg Go to