Docstoc

ModernGraphicsHardware02vp

Document Sample
ModernGraphicsHardware02vp Powered By Docstoc
					Modern Graphics Hardware
         2002
    Vertex Programs
      Joe Michael Kniss
               Overview

•   Pipeline overview
•   VP/FP overview
•   Vertex Programs – Me
•   Fragment Programs – Aaron
•   Discussion
      Modern Graphics Hardware
 Primitive
construction
                 Tessellation

Transform &      Transform to homogeneous eye space,
  Lighting       light, texgen, deform…
Triangle setup   View volume clip, view surface coordinates
Rasterization    Generate fragments, interpolate color & texcoords

 Fragment        Access textures, & compute final color
 processing

    Tests        Stencil, alpha, scissor, depth ….

  Blending       Anti-Aliasing   Add, mult, interpolate, max…
      Modern Graphics Hardware
 Primitive                   Primitive    03?
construction                Programs?

Transform &                   Vertex
  Lighting
                 00        Programs 2.0
                             Programs
                                          01
                                          02

Triangle setup   99

Rasterization

 Fragment        Pre--98    Fragment
                            Combiners
 processing                 Programs

    Tests

  Blending        Anti-Aliasing
                 Higher order surfaces
Higher order                           • PN Triangles (ATI)
  surface
                                       •Bezier patches (NVIDIA)
Transform &                  Vertex
  Lighting                  Programs

Triangle setup

Rasterization

 Fragment                   Fragment
 processing                 Programs

    Tests

  Blending         Anti-Aliasing
                 Vertex Programs
Higher order
  surface                                16 input
                                         vectors
Transform &                Vertex
  Lighting                Programs   256 static
                                      vectors 12 temp
Triangle setup
                                      Loops vectors
Rasterization
                                         22 output
 Fragment                 Fragment
 processing               Programs
                                          vectors
                                        Post T&L
    Tests
                                          cache
  Blending       Anti-Aliasing
         Vertex Programs

• 3-5 flavors
  – nv vertex programs 1.0 & 2.0
  – ati vertex program (EXT)
  – ARB vertex program 1.0 ( & 2.0 ???)
• nv 1.0 + ati ext  ARB 1.0
• Next gen == ARB 2.0 ????
• Closely matches Direct3D
            Vertex Programs
• First generation (nv1.0, ati ext, ARB1.0)
  – 128 instructions                16 input
  – 96 constants                    vectors
  – 12 temps                    96 static
                                vectors 12 temp
  – No loops
                                          vectors

                                    15 output
                                     vectors
                                   Post T&L
                                     cache
               Vertex Programs
• First gen. inputs
Generic
Attribute   Conventional Attribute     Conventional Attribute Command
---------   ------------------------   ------------------------------
     0      vertex position            Vertex
     1      vertex weights 0-3         WeightARB, VertexWeightEXT
     2      normal                     Normal
     3      primary color              Color
     4      secondary color            SecondaryColorEXT
     5      fog coordinate             FogCoordEXT
     6      -                          -
     7      -                          -
     8      texture coordinate set 0   MultiTexCoord(TEXTURE0, ...)
     9      texture coordinate set 1   MultiTexCoord(TEXTURE1, ...)
    10      texture coordinate set 2   MultiTexCoord(TEXTURE2, ...)
    11      texture coordinate set 3   MultiTexCoord(TEXTURE3, ...)
    12      texture coordinate set 4   MultiTexCoord(TEXTURE4, ...)
    13      texture coordinate set 5   MultiTexCoord(TEXTURE5, ...)
    14      texture coordinate set 6   MultiTexCoord(TEXTURE6, ...)
    15      texture coordinate set 7   MultiTexCoord(TEXTURE7, ...)
   8+n      texture coordinate set n   MultiTexCoord(TEXTURE0+n, ...)
             Vertex Programs
• First gen. inputs
  Conventional Attribute Binding   Generic Attribute Binding
  ------------------------------   -------------------------
  vertex.position                  vertex.attrib[0]
  vertex.weight                    vertex.attrib[1]
  vertex.weight[0]                 vertex.attrib[1]
  vertex.normal                    vertex.attrib[2]
  vertex.color                     vertex.attrib[3]
  vertex.color.primary             vertex.attrib[3]
  vertex.color.secondary           vertex.attrib[4]
  vertex.fogcoord                  vertex.attrib[5]
  vertex.texcoord                  vertex.attrib[8]
  vertex.texcoord[0]               vertex.attrib[8]
  vertex.texcoord[1]               vertex.attrib[9]
  vertex.texcoord[2]               vertex.attrib[10]
  vertex.texcoord[3]               vertex.attrib[11]
  vertex.texcoord[4]               vertex.attrib[12]
  vertex.texcoord[5]               vertex.attrib[13]
  vertex.texcoord[6]               vertex.attrib[14]
  vertex.texcoord[7]               vertex.attrib[15]
  vertex.texcoord[n]               vertex.attrib[8+n]


     ARB 1.0 notation (inputs == Read only)
                Vertex Programs
• First gen instruction set
  Instruction   Inputs   Output   Description
  -----------   ------   ------   --------------------------------
  ABS           v        v        absolute value
  ADD           v,v      v        add
  ARL           v        a        address register load
  DP3           v,v      ssss     3-component dot product
  DP4           v,v      ssss     4-component dot product
  DPH           v,v      ssss     homogeneous dot product
  DST           v,v      v        distance vector
  EX2           s        ssss     exponential base 2
  EXP           s        v        exponential base 2 (approximate)
  FLR           v        v        floor
  FRC           v        v        fraction
  LG2           s        ssss     logarithm base 2
  LIT           v        v        compute light coefficients
  LOG           s        v        logarithm base 2 (approximate)
  MAD           v,v,v    v        multiply and add
  MAX           v,v      v        maximum
  MIN           v,v      v        minimum
  MOV           v        v        move
  MUL           v,v      v        multiply
  POW           s,s      ssss     exponentiate
  RCP           s        ssss     reciprocal
  RSQ           s        ssss     reciprocal square root
  SGE           v,v      v        set on greater than or equal
  SLT           v,v      v        set on less than
  SUB           v,v      v        subtract
  SWZ           v        v        extended swizzle
  XPD           v,v      v        cross product
          Vertex Programs

• First gen instruction set
  – Wow! That’s a lot of instructions
  – Why: SIMD processor
  – Single clock execution
  – Taken from ARB spec, not all instructions
    available on all platforms
               Vertex Programs
• First gen. outputs
 Binding                         Components   Description
 -----------------------------   ----------   ----------------------------
 result.position                 (x,y,z,w)    position in clip coordinates
 result.color                    (r,g,b,a)    front-facing primary color
 result.color.primary            (r,g,b,a)    front-facing primary color
 result.color.secondary          (r,g,b,a)    front-facing secondary color
 result.color.front              (r,g,b,a)    front-facing primary color
 result.color.front.primary      (r,g,b,a)    front-facing primary color
 result.color.front.secondary    (r,g,b,a)    front-facing secondary color
 result.color.back               (r,g,b,a)    back-facing primary color
 result.color.back.primary       (r,g,b,a)    back-facing primary color
 result.color.back.secondary     (r,g,b,a)    back-facing secondary color
 result.fogcoord                 (f,*,*,*)    fog coordinate
 result.pointsize                (s,*,*,*)    point size
 result.texcoord                 (s,t,r,q)    texture coordinate, unit 0
 result.texcoord[n]              (s,t,r,q)    texture coordinate, unit n




      ARB 1.0 notation (outputs == Write only??)
         Vertex Programs

• What’s special about the ARB 1.0 spec?
  – Unifies coding for multiple platforms
    (That’s their job!)
  – Access to “tracked” OGL state
    (Materials, Matrices,…)
  – Unifies vertex programs and next gen
    fragment programs
         Vertex Programs

• ARB 1.0 continued
  – Position invariant vertex programs
    • Use the fixed function pipe to transform vertices
    • You still do the lighting
    • Same transformation even if vertex program
      enabled
    • Option set in VP text file
    • KEY for multi-pass algorithms!!!
         Vertex Programs

• ARB 1.0 continued…
  – Vender specific “enhancements”
  – Access special functionality of chip
  – Use “OPTION BLAH” at top of program text
          Vertex Programs

• Other ARB 1.0 features
  – Constant scoping, env, state, local
    • Determines life time & update behavior
  – Temporary aliasing (tmp1 = tmp2)
  – Automatic constant management, let
    driver deal with constant numbering!
                 Vertex Programs
 • ARB 1.0 example
!!ARBvp1.0
# comment here ;)
ATTRIB pos = vertex.position; #alias long names
ATTRIB norm = vertex.normal;
PARAM mv[4] = { state.matrix.modelview }; #alias
PARAM mvit[4] = { state.matrix.modelview.invtrans };
TEMP   tnorm; # temp for the transformed normal
DP4 result.position.x mv[0] pos; # vertex to clip space
DP4 result.position.y mv[1] pos;
DP4 result.position.z mv[2] pos;
DP4 result.position.w mv[3] pos;
DP3 tnorm.x mvit[0] norm; # tranform the normal
DP3 tnorm.y mvit[1] norm; #    for lighting (later)
DP3 tnorm.z mvit[2] norm;
…
                 Vertex Programs
 • Same example in Cg:
struct appin : application2vertex
{
         float4 pos     : POSITION;
         float4 Norm    : NORMAL;
};
struct vertout : vertex2fragment
{
         float4 HPos    : POSITION;
         float4 PCol    : COLOR0;
};

vertout main(appin IN)
{
     vertout out;
     out.Hpos = mul(glstate.matrix.mvp, IN.pos);
     // note cast to float3 for the normal!!!!
     float3 tnorm =
         mul(glstate.matrix.invtrans.modelview[0],(float3)IN.norm);
     …
     return out;
}
           Vertex Programs
• Next generation (nv2.0, ati ?, ARB2.0?)
  – 256 instructions              16 input
  – 256 constants                 vectors
  – 12 temps ?                256 static
                               vectors 12 temp
  – Loops
                               Loops vectors
  – Subroutines
  – Conditional branching         22 output
                                   vectors
  – 4 address registers
                                  Post T&L
  – 6 clips & 8 textures            cache
          Vertex Programs
• Next gen vertex programs
  – True conditional branching, looping and
    subroutine calls
  – Conditional write masks
  – Enhanced instruction set
    (frac, floor, sin, cos, ex2, lg2, pow, lerp)
  – More everything vs. NV2X
      • instructions (from 128 to 256)
      • constants (from 96 to 256)
      • address registers (from 1 to 4)
      • texture coordinate sets (from 4 to 8)
      • clip planes (from 0 to 6)
         Vertex Programs

• ARB vp2.0 not ratified yet
  – Have to use vendor specifics till then
  – Who knows when???
  – Still follows Direct3D, no problem??
  – Need uniformity for programmers sake
           Questions?




… now on to Fragment Programs

				
DOCUMENT INFO
Shared By:
Categories:
Tags:
Stats:
views:3
posted:12/10/2011
language:German
pages:23