where does the vertex engine fit?

22
Where does the Vertex Engine fit? frame-buffer anti-aliasing texture blending setup rasterizer Transform & Lighting Traditional Graphics Pipeline

Upload: taite

Post on 11-Jan-2016

49 views

Category:

Documents


0 download

DESCRIPTION

Where does the Vertex Engine fit?. Transform & Lighting. Traditional Graphics Pipeline. setup rasterizer. texture blending. frame-buffer anti-aliasing. GeForce 3 Vertex Engine. Vertex Program. Transform & Lighting. setup rasterizer. texture blending. frame-buffer - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Where does the Vertex Engine fit?

Where does the Vertex Engine fit?

frame-bufferanti-aliasingframe-bufferanti-aliasing

textureblendingtexture

blending

setuprasterizer

setuprasterizer

Transform & LightingTransform & Lighting

Traditional Graphics Pipeline

Page 2: Where does the Vertex Engine fit?

frame-bufferanti-aliasingframe-bufferanti-aliasing

textureblendingtexture

blending

setuprasterizer

setuprasterizer

Transform & LightingTransform & Lighting

GeForce 3 Vertex Engine

VertexProgramVertex

Program

Page 3: Where does the Vertex Engine fit?

API Support

• Designed to fit into OpenGL and D3D API’s

• Program mode vs. Fixed function mode

• Load and bind program

• Simple to add to old D3D and OpenGL programs

Page 4: Where does the Vertex Engine fit?

Programming Model

• Enable vertex program – glEnable(GL_VERTEX_PROGRAM_NV);

• Create vertex program object

• Bind vertex program object

• Execute vertex program object

Page 5: Where does the Vertex Engine fit?

Create Vertex Program

•Programs (assembly) are defined Programs (assembly) are defined inline as inline as

character strings character strings static const GLubyte vpgm[] = “\!!VP1. 0\ DP4 o[HPOS].x, c[0], v[0]; \ DP4 o[HPOS].y, c[1], v[0]; \ DP4 o[HPOS].z, c[2], v[0]; \ DP4 o[HPOS].w, c[3], v[0]; \ MOV o[COL0],v[3]; \END";

Page 6: Where does the Vertex Engine fit?

Create Vertex Program (2)

• Load and bind vertex programs similar to texture objects glLoadProgramNV(GL_VERTEX_PROGRAM_NV,

7, strelen(programString), programString);

….

glBindProgramNV(GL_VERTEX_PROGRAM_NV, 7);

Page 7: Where does the Vertex Engine fit?

Invoke Vertex Program

• The vertex program is invoked when a vertex is given, i.e., when

glBegin(…)

glVertex3f(x,y,z)

glEnd()

Page 8: Where does the Vertex Engine fit?

Let’s look at a sample programstatic const GLubyte vpgm[] = “\!!VP1. 0\ DP4 o[HPOS].x, c[0], v[0]; \ DP4 o[HPOS].y, c[1], v[0]; \ DP4 o[HPOS].z, c[2], v[0]; \ DP4 o[HPOS].w, c[3], v[0]; \ MOV o[COL0],v[3]; \END";

O[HPOS] = M(c0,c1,c2,c3) * v - HPOS? O[COL0] = v[3] - COL0?

Calculate the clip space point position and Assign the vertex with v[3] for its diffuse color

Page 9: Where does the Vertex Engine fit?

Vertex Source

Vertex Program

Vertex Output

Program Constants

Temporary Registers

16x4 registers

128 instructions

96x4 registers

12x4 registers

15x4 registers

Programming ModelProgramming Model

V[0] …V[15] c[0]

…c[96]

R0 …R11

O[HPOS]O[COL0]O[COL1]O[FOGP]O[PSIZ]O[TEX0] …O[TEX7]

All quad floats

Page 10: Where does the Vertex Engine fit?

Input Vertex Attributes

• V[0] – V[15]• Aliased (tracked) with conventional per-vertex

attributes (Table 3)• Use glVertexAttribNV() to explicitly assign values • Can also specify a scalar value to the vertex

attribute array - glVertexAttributesNV() • Can change values inside or outside

glBegin()/glEnd() pair

Page 11: Where does the Vertex Engine fit?

Program Constants

• Can only change values outside glBegin()/glEnd() pair • No automatic aliasing • Can be used to track OpenGl matrices (modelview,

projection, texture, etc.)• Example:

glTrackMatrix(GL_VERTEX_PROGRAM_NV, 0,

GL_MODELVIEW_PROJECTION_NV, GL_IDENTIGY_NV)

• Track 4 contiguous program constants starting with c[0]

Page 12: Where does the Vertex Engine fit?

Program Constants (cont’d)

DP4 o[HPOS].x, c[0], v[OPOS]

DP4 o[HPOS].y, c[1], v[OPOS]

DP4 o[HPOS].z, c[2], v[OPOS]

DP4 o[HPOS].w, c[3], v[OPOS]

What does it do?

Page 13: Where does the Vertex Engine fit?

Program Constants (cont’d)

glTrackMatrixNV(GL_VERTEX_PROGRAM_NV, 4, GL_MODEL_VIEW, GL_INVERSE_TRANPOSE_NV)

DP3 R0.x, C[4], V[NRML]

DP3 R0.y, C[5[, V[NRML]

DP3 R0.z, C[6], V[NRML]

What doe it do?

Page 14: Where does the Vertex Engine fit?

Hardware Block Diagram

Vertex Attribute Buffer (VAB)

Vector FP Core

Vertex In

Vertex Out

Page 15: Where does the Vertex Engine fit?

Data Path

FPU Core

NegateSwizzle

NegateSwizzle

NegateSwizzle

X Y Z WX Y Z W X Y Z W

Write Mask

X Y Z W

Page 16: Where does the Vertex Engine fit?

Instruction Set: The ops• 17 instructions total

• MOV, MUL, ADD, MAD, DST

• DP3, DP4

• MIN, MAX, SLT, SGE

• RCP, RSQ, LOG, EXP, LIT

• ARL

Page 17: Where does the Vertex Engine fit?

Instruction Set: The Core Features

• Immediate access to sources

• Swizzle/negate on all sources

• Write mask on all destinations

• DP3,DP4 most common graphics ops

• Cross product is MUL+MAD with swizzling

• LIT instruction implements phonglighting

Page 18: Where does the Vertex Engine fit?

Dot Product Instruction

• DP3 R0.x, R1, R2 -

R0.x = R1.x * R2.x + R1.y * R1.y + R1.z * R2.z

• DP4 R0.x, R1, R2 -

4-component dot product

Page 19: Where does the Vertex Engine fit?

MUL instruction

• MUL R1, R0, R2 (component-wise mult.)R1.x = R0.x * R2.x

R1.y = R0.y * R2.y

R1.z = R0.z * R2.z

R1.w = R0.w * R2.w

Page 20: Where does the Vertex Engine fit?

MAD instruction

• MAD R1, R2, R3, R4

R1 = R2 * R3 + R4

*: component wise multiplication

Example:

• MAD R1, R0.yzxw, R2.zxyw, -R1

What does it do?

Page 21: Where does the Vertex Engine fit?

Cross Product Coding Example

# Cross product R2 = R0 x R1# Cross product R2 = R0 x R1

MUL R2, R0.zxyw, R1.yzxw;MUL R2, R0.zxyw, R1.yzxw;MAD R2, R0.yzxw, R1.zxyw, -R2;MAD R2, R0.yzxw, R1.zxyw, -R2;

Page 22: Where does the Vertex Engine fit?

Lighting instruction

• LIT R1, R0 (Phong light model)Input: R0 = (diffuse, specular, ??, shiness)

Output R1 = (1, diffuse, specular^shininess, 1)

Usually followed by

• DP3 o[COL0], C[21], R1 (assuming using c[21])

where C[xx] = (ka, kd, ks, ??)