OpenGL Vertex Programming and Vertex Programm Assembler - PowerPoint PPT Presentation

1 / 32
About This Presentation
Title:

OpenGL Vertex Programming and Vertex Programm Assembler

Description:

... Programming offers programmable T&L unit. User-defined. Vertex. Processing. frame-buffer. anti-aliasing. texture. blending. setup. rasterizer. transform & lighting ... – PowerPoint PPT presentation

Number of Views:52
Avg rating:3.0/5.0
Slides: 33
Provided by: imsTuw
Category:

less

Transcript and Presenter's Notes

Title: OpenGL Vertex Programming and Vertex Programm Assembler


1
OpenGL Vertex Programming and Vertex Programm
Assembler
  • Reinhard Steiner

2
Overview
  • What is Vertex Programming?
  • Program Specification and Parameters
  • Vertex Program Register Set
  • Vertex Programming Assembly Language

3
What is Vertex Programming?
  • Traditional Graphics Pipeline

transform lighting
setup rasterizer
texture blending
Each unit has specific function (possibly with
modes of operation)
frame-buffer anti-aliasing
4
What is Vertex Programming?
  • Vertex Programming offers programmable TL unit

User-defined Vertex Processing
transform lighting
setup rasterizer
texture blending
Gives the programmer total control of vertex
processing.
frame-buffer anti-aliasing
5
What is Vertex Programming?
  • Complete control of transform and lighting HW
  • Complex vertex operations accelerated in HW
  • Custom texture coordinate generation
  • Custom texture matrix operations
  • Custom vertex computations of your choice
  • Offloading vertex computations frees up CPU
  • More physics and simulation possible!

6
What is Vertex Programming?
  • Custom cartoon-style lighting

7
What is Vertex Programming?
Dynamic displacements of surfaces by objects
8
What is Vertex Programming?
  • Vertex Program
  • Assembly language interface to TL unit
  • GPU instruction set to perform all vertex math
  • Reads an untransformed, unlit vertex
  • Creates a transformed vertex
  • Optionally creates
  • Lights a vertex
  • Creates texture coordinates
  • Creates fog coordinates
  • Creates point sizes

9
What is Vertex Programming?
  • Vertex Program
  • Does not create or delete vertices
  • 1 vertex in and 1 vertex out
  • No topological information provided
  • No edge, face, nor neighboring vertex info
  • Dynamically loadable
  • Exposed through NV_vertex_program extension
  • 4 Component Vector Math

10
What is Vertex Programming?
Vertex Program
transform lighting
setup rasterizer
glEnable( GL_VERTEX_PROGRAM_NV )
texture blending
Switch from standard TL mode to Vertex Program
mode
frame-buffer anti-aliasing
11
Vertex ProgrammingConceptual Overview
Vertex Attributes
Vertex Program
Vertex Output
12
Vertex ProgrammingConceptual Overview
Sixteen 4-component vector floating point
registers
Vertex Attributes
Position, colors, normal
User-defined vertex parameters
16x4 registers
densities, velocities, weights, etc.
Vertex Program
Vertex Output
13
Vertex ProgrammingConceptual Overview
Vertex Attributes
16x4 registers
Up to 128 program instructions (SIMD)
Vertex Program
(i.e. add, multiply, etc.)
Read vertex attribute registers
Write vertex output registers
128 instructions
Vertex Output
14
Vertex ProgrammingConceptual Overview
Vertex Attributes
Program Parameters
16x4 registers
Modifiable only outside of glBegin/glEnd pair
Read-only
Vertex Program
96x4 registers
Temporary Registers
128 instructions
Read/Write-able
12x4 registers
Vertex Output
15
Vertex ProgrammingConceptual Overview
Vertex Attributes
Program Parameters
16x4 registers
Vertex Program
96x4 registers
Temporary Registers
128 instructions
12x4 registers
Vertex Output
Fifteen 4-component floating vectors
Homogeneous clip space position
15x4 registers
Primary, secondary colors
Fog coord, point size, texture coords.
16
Vertex Program Specification
  • Programs are arrays of GLubytes (strings)
  • Created/managed similar to texture objects
  • glGenProgramsNV( sizei n, uint ids )
  • glLoadProgramNV( enum target, uint id, sizei
    len, const ubyte program )
  • glBindProgramNV( enum target, uint id )

17
Vertex ProgrammingParameter Specification
  • Two types
  • Per-Vertex
  • Per-Begin/End block
  • Vertex Attributes
  • Program Parameters

18
Vertex ProgrammingPer-Vertex Parameters
  • Up to 16x4 per-vertex attributes
  • (Position, Color, Texture Coords., )
  • Values specified with new commands
  • glVertexAttrib4fNV( index, )
  • glVertexAttribs4fvNV( index, )

19
Vertex ProgrammingProgram Parameters
  • Up to 96x4 per-block parameters
  • Store parameters such as matrices, lighting
    params, and constants required by vertex
    programs.
  • Values specified with new commands
  • glProgramParameter4fNV( GL_VERTEX_PROGRAM_NV,
    index, x, y, z, w )
  • glProgramParameter4fvNV( GL_VERTEX_PROGRAM_NV,
    index, n, params )

20
Vertex ProgrammingProgram Parameters
  • Values also modifiable by Vertex State Programs
  • Vertex State Programs are a special kind of
    vertex program
  • NOT invoked by glVertex
  • Explicitly executed, only outside of a
    glBegin/glEnd pair.
  • Used to modify program parameters.
  • Uses same instructions/register set but can read
    AND write c0, , c95.

21
Vertex Program Register Access
Vertex Attribute Registers
Program Parameter Registers
v0 v1 v15
r
Vertex Program
r
c0 c1 c95
Temporary Registers
r/w
w
R0 R1 R10 R11
Vertex Result Registers
oHPOS oCOL0
22
Vertex State ProgramRegister Access
Vertex Attribute Registers
Program Parameter Registers
v0 v1 v15
r
(v0 only)
Vertex Program
r/w
VSPs used to modify program parameter state.
c0 c1 c95
Temporary Registers
r/w
R0 R1 R10 R11
Vertex Result Registers
oHPOS oCOL0
23
Vertex ProgrammingAssembly Language
  • SIMD instruction set
  • Four operations simultaneously
  • 17 instructions
  • Operate on scalar or 4-vector input
  • Result in a vector or replicated scalar output

24
Vertex ProgrammingAssembly Language
  • Instruction Format
  • Opcode dst, -s0 ,-s1 ,-s2 comment

Instruction name
Destination Register
Source0 Register
Source1 Register
Source2 Register
Example MOV r1, r2
25
Vertex ProgrammingAssembly Language
There are 17 instructions in total
  • ARL
  • MOV
  • MUL
  • ADD
  • MAD
  • RCP
  • RSQ
  • DP3
  • DP4
  • DST
  • MIN
  • MAX
  • SLT
  • SGE
  • EXP
  • LOG
  • LIT

26
Vertex ProgrammingAssembly Language
  • Example
  • MOV R1, -R2.yzzx

before
after
27
The Instruction Set
  • No branching, no early exit supported
  • Deterministic Speed for each Vertex
  • Endless Loop on Graphic Hardware

28
Example Programs
3-Component Normalize R1 (nx,ny,nz)
R0.xyz normalize(R1) R0.w nxnx nyny
nznz R0.w 1/sqrt(nxnx nyny nznz)
R0.xyz R1.xyz / sqrt(nxnx nyny
nznz) DP3 R0.w, R1, R1 RSQ R0.w, R0.w MUL
R0.xyz, R1, R0.w
29
Performance
  • Programs managed similar to texture objects
  • Switching between small number of programs is
    fast!
  • Switching between large number of programs is
    slower.

30
Performance
  • Use vertex programming when required
  • Use conventional OpenGL TnL mode when not
  • There is no penalty for switching in and out of
    vertex program mode.
  • Vertex Program execution time
  • proportional to length of program
  • shorter programs ? faster execution

31
Vertex Programs Summary
  • Increased programmability
  • Customizable engine for transform, lighting,
    texture coordinate generation, and more.
  • Offloads CPU tasks to GPU yielding higher
    performance.

32
HW Shader Problems
  • No Standard available
  • Different APIs from nVidia and ATI
  • Solution
  • Shading Languages
  • OpenGL 2.0
Write a Comment
User Comments (0)
About PowerShow.com