Graphics Hardware - PowerPoint PPT Presentation

1 / 53
About This Presentation
Title:

Graphics Hardware

Description:

Replaced ISA as standard peripheral bus in early 90s ... abs, sign, floor, ceil, fract, mod, min, max, clamp. Built-in functions. Interpolations ... – PowerPoint PPT presentation

Number of Views:24
Avg rating:3.0/5.0
Slides: 54
Provided by: keitho4
Category:

less

Transcript and Presenter's Notes

Title: Graphics Hardware


1
Graphics Hardware
  • Keith OConor

4ba6, March 1st 2006
2
Outline
  • Graphics Card buses
  • OpenGL extensions
  • Graphics Hardware pipeline
  • GPU programmability
  • The OpenGL shading language

3
Graphics adapters
  • Buses for graphics adapters
  • PCI
  • AGP
  • PCI Express

4
PCI
  • Peripheral Component Interconnect
  • Replaced ISA as standard peripheral bus in early
    90s
  • Designed as a general bus, not necessarily for
    graphics
  • 33.33 MHz clock
  • Peak transfer rate 133MB/s
  • Shared between every PCI device
  • Network card, sound card, etc


5
AGP
  • Accelerated Graphics Port
  • Imroved bandwidth, dedicated bus
  • AGP aperture allows system memory to be mapped
    as AGP memory
  • 66 Mhz clock, variants
  • 1x 266MB/s
  • 2x 533MB/s
  • 4x 1066MB/s
  • 8x 2GB/s

6
PCI Express
  • PCIe, not to be confused with PCI-X
  • 1x 250MB/s
  • 2x 500MB/s
  • 4x 1GB/s
  • 16x 4GB/s
  • Current standard for graphics cards
  • 32x 8GB/s
  • Can split bandwidth between read and write
  • vs AGPs read OR write
  • Scalable Link Interface (SLI) possible


7
OpenGL ARB
  • Architecture Review Board
  • Comprised of representatives from
  • 3DLabs, Apple, ATI, Dell, IBM, Intel, nVIDIA,
    SGI, Sun
  • Microsoft resigned in March 2003
  • Decides on all core OpenGL features API specs
  • Meets once every three months

8
OpenGL extensions
  • Allow hardware vendors to rapidly expose new
    features
  • Reviewed promoted by the ARB
  • Hierarchy, specified by extension prefix
  • NV_, ATI_, etc
  • EXT_
  • ARB_
  • core
  • Eg. Multitexturing
  • SGIS_multitexture
  • ARB_multitexture
  • Core multitexturing

9
Programmable Graphics Hardware
  • Major growth in graphics hardware power
  • (Moores Law)³
  • Progression from Fixed Function Pipeline to
    Programmable Pipeline
  • Allows for programmability at essential stages of
    the graphics pipeline
  • Vertex stage
  • Fragment stage

10
Basic graphics hardware pipeline
Vertex Stage
Vertex
Fragment Stage
Camera Model Transformations, Lighting etc
Pixel!
Position, Color, Normal Tex Coords,
Texture Addressing, Colour Combining etc
Triangle Setup
Pixel Tests
Textures
11
OpenGL programmability
  • Texture Shaders
  • Register Combiners
  • Assembly programs
  • ARB_vertex_program
  • ARB_fragment_program
  • Messy!
  • GL Shading Language (GLSL)

12
ARB_vertex_program
transform the positions DP4 out.x, in,
mvp0 DP4 out.y, in, mvp1 DP4 out.z, in,
mvp2 DP4 out.w, in, mvp3 transform the
position to eye-space DP4 tmp.x, in, mv0 DP4
tmp.y, in, mv1 DP4 tmp.z, in, mv2 DP4
tmp.w, in, mv3 view direction MOV vDir,
-tmp transfrom the normal to eye-space DP3
oNrm.x, mv0, nrm DP3 oNrm.y, mv1, nrm DP3
oNrm.z, mv2, nrm output the light vector MOV
lVec, light output the texcoords MOV oTex,
tex END
  • !!ARBvp1.0
  • Phong shading example
  • Declarations
  • ATTRIB in vertex.position
  • ATTRIB nrm vertex.normal
  • ATTRIB tex vertex.texcoord0
  • PARAM mvp4 state.matrix.mvp
  • PARAM mv4 state.matrix.modelview
  • PARAM light 0.57735, 0.57735, 0.57735, 0.0
  • PARAM const 0.0, 0.0, 0.0, 0.2
  • OUTPUT out result.position
  • OUTPUT oTex result.texcoord0
  • OUTPUT oNrm result.texcoord1
  • OUTPUT lVec result.texcoord2
  • OUTPUT vDir result.texcoord3

13
ARB_fragment_program
normalize the view direction DP3 view.a, vDir,
vDir RSQ view.a, view.a MUL view.rgb, vDir,
view.a compute half angle vector ADD spec.rgb,
view, lVec DP3 spec.a, spec, spec RSQ spec.a,
spec.a MUL spec.rgb, spec, spec.a compute
specular intensisty DP3_SAT spec.a, spec,
tmp LG2 spec.a, spec.a MUL spec.a, spec.a,
const.w EX2 spec.a, spec.a compute diffuse
illum DP3_SAT dif, tmp, lVec ADD_SAT dif.rgb,
dif, const sum MAD_SAT dif.rgb, color, dif,
spec.a MOV dif.a, color.a MOV out, dif END
  • !!ARBfp1.0
  • Phong shading example
  • Declarations
  • TEMP tmp
  • TEMP dif
  • TEMP spec
  • TEMP view
  • ATTRIB tex fragment.texcoord0
  • ATTRIB nrm fragment.texcoord1
  • ATTRIB lVec fragment.texcoord2
  • ATTRIB vDir fragment.texcoord3
  • PARAM color 0.2, 0.3, 1.0, 1.0
  • PARAM const 0.2, 0.2, 0.2, 32.0
  • OUTPUT out result.color

14
GLSL Who? When? Why?!
  • ARB GL2 workgroup
  • For inclusion in next major OpenGL revision
  • OpenGL 2.0
  • February 27, 2003
  • OpenGL Shading Language draft released
  • Advances in hardware
  • Just not feasible before now
  • Specific operations in specific order fast
    hardware

15
Fixed Function Vertex Processor
Vertex (object)
Vertex (clip)
TransformMVP,MV,MV-T
Normal
Vertex (eye)
ColorSecondaryColor
FrontBackColor
0,1
Lighting
FrontBackSecondaryColor
0,1
Texgen
TextureMatrixn
TexCoordn
TexCoordn
EdgeFlag
EdgeFlag
16
GL2 Vertex Processor
Attribute0
Position
Texture
Uniform
Attribute1
ClipVertex
Attribute2
PointSize
VertexShader

Varying0
Attributen
Varying1
Varying2

Temporaries
Varyingn
EdgeFlag
EdgeFlag
17
Fixed Function Fragment Processor
Color
SecondaryColor
Texn
TEn
Sum
Fog
Color
TexCoordn
0,1
z (ze,f )
Depth
Depth
Coord
Coord
FrontFacing
FrontFacing
18
GL2 Fragment Processor
Varying0
Uniform
Texture
Varying1
Varying2
FragmentShader

FragColor
Varyingn
FragDepth
FragDepth
Temporaries
FragCoord
FragCoord
FrontFacing
FrontFacing
19
In General
  • Vertex processes bypassed
  • Vertex Transformation
  • Normal Transformation, Normalization
  • Lighting
  • Texture Coordinate Generation and Transformation
  • Fragment processes bypassed
  • Texture accesses application
  • Fog

20
Many possibilities
  • Arbitrary vertex transformation

21
Many possibilities
  • Customizable lighting equations
  • Not the fixed Blinn-Phong lighting Gouraud
    shading of standard OpenGL

22
Many possibilities
  • Customizable lighting equations
  • Not the fixed Blinn-Phong lighting Gouraud
    shading of standard OpenGL

23
Many possibilities
  • Customizable lighting equations
  • Not the fixed Blinn-Phong lighting Gouraud
    shading of standard OpenGL

24
Many possibilities
25
Many possibilities
26
Many possibilities
27
Many possibilities
28
Example Vertex Shader
  • varying vec4 diffuseColor
  • varying vec3 fragNormal
  • varying vec3 lightVector
  • uniform vec3 eyeSpaceLightVector
  • void main()
  • vec3 eyeSpaceVertex vec3(gl_ModelViewMatrix
    gl_Vertex)
  • lightVector vec3(normalize(eyeSpaceLightVector
    - eyeSpaceVertex))
  • fragNormal normalize(gl_NormalMatrix
    gl_Normal)
  • diffuseColor gl_Color
  • gl_Position gl_ModelViewProjectionMatrix
    gl_Vertex

29
Example Fragment Shader
  • varying vec4 diffuseColor
  • varying vec3 lightVector
  • varying vec3 fragNormal
  • void main()
  • float perFragmentLightingmax(dot(lightVector,fra
    gNormal),0.0)
  • gl_FragColor diffuseColor lightingFactor

30
Types
  • void
  • float vec2 vec3 vec4
  • mat2 mat3 mat4
  • int ivec2 ivec3 ivec4
  • bool bvec2 bvec3 bvec4
  • samplernD, samplerCube, samplerShadownD

31
Types
  • Structs
  • Arrays
  • One dimensional
  • Constant size (ie float array4)
  • Reserved types
  • half hvec2 hvec3 hvec4
  • fixed fvec2 fvec3 fvec4
  • double dvec2 dvec3 dvec4

32
Type qualifiers
  • attribute
  • Changes per-vertex
  • eg. position, normal etc.
  • uniform
  • Does not change between vertices of a batch
  • eg light position, texture unit, other constants
  • varying
  • Passed from VS to FS, interpolated
  • eg texture coordinates, vertex color

33
Built-in variables
  • Attributes uniforms
  • For ease of programming
  • OpenGL state mapped to variables
  • Some special variables are required to be written
    to, others are optional

34
Special built-ins
  • Vertex shader
  • vec4 gl_Position // must be written
  • vec4 gl_ClipPosition // may be written
  • float gl_PointSize // may be written
  • Fragment shader
  • float gl_FragColor // may be written
  • float gl_FragDepth // may be read/written
  • vec4 gl_FragCoord // may be read
  • bool gl_FrontFacing // may be read

35
Attributes
  • Built-in
  • attribute vec4 gl_Vertex
  • attribute vec3 gl_Normal
  • attribute vec4 gl_Color
  • attribute vec4 gl_SecondaryColor
  • attribute vec4 gl_MultiTexCoordn
  • attribute float gl_FogCoord
  • User-defined
  • attribute vec3 myTangent
  • attribute vec3 myBinormal
  • Etc

36
Built-in Uniforms
  • uniform mat4 gl_ModelViewMatrix
  • uniform mat4 gl_ProjectionMatrix
  • uniform mat4 gl_ModelViewProjectionMatrix
  • uniform mat3 gl_NormalMatrix
  • uniform mat4 gl_TextureMatrixn
  • struct gl_MaterialParameters
  • vec4 emission
  • vec4 ambient
  • vec4 diffuse
  • vec4 specular
  • float shininess
  • uniform gl_MaterialParameters gl_FrontMaterial
  • uniform gl_MaterialParameters gl_BackMaterial

37
Built-in Uniforms
  • struct gl_LightSourceParameters
  • vec4 ambient
  • vec4 diffuse
  • vec4 specular
  • vec4 position
  • vec4 halfVector
  • vec3 spotDirection
  • float spotExponent
  • float spotCutoff
  • float spotCosCutoff
  • float constantAttenuation
  • float linearAttenuation
  • float quadraticAttenuation
  • Uniform gl_LightSourceParameters
    gl_LightSourcegl_MaxLights

38
Built-in Varyings
  • varying vec4 gl_FrontColor // vertex
  • varying vec4 gl_BackColor // vertex
  • varying vec4 gl_FrontSecColor // vertex
  • varying vec4 gl_BackSecColor // vertex
  • varying vec4 gl_Color // fragment
  • varying vec4 gl_SecondaryColor // fragment
  • varying vec4 gl_TexCoord // both
  • varying float gl_FogFragCoord // both

39
Built-in functions
  • Angles Trigonometry
  • radians, degrees, sin, cos, tan, asin, acos, atan
  • Exponentials
  • pow, exp2, log2, sqrt, inversesqrt
  • Common
  • abs, sign, floor, ceil, fract, mod, min, max,
    clamp

40
Built-in functions
  • Interpolations
  • mix(x,y,a) x( 1.0-a) ya)
  • step(edge,x) x lt edge ? 0.0 1.0
  • smoothstep(edge0,edge1,x)
  • t (x-edge0)/(edge1-edge0)
  • t clamp( t, 0.0, 1.0)
  • return tt(3.0-2.0t)

41
Built-in functions
  • Geometric
  • length, distance, cross, dot, normalize,
    faceForward, reflect
  • Matrix
  • matrixCompMult
  • Vector relational
  • lessThan, lessThanEqual, greaterThan,
    greaterThanEqual, equal, notEqual, notEqual, any,
    all

42
Built-in functions
  • Texture
  • texture1D, texture2D, texture3D, textureCube
  • texture1DProj, texture2DProj, texture3DProj,
    textureCubeProj
  • shadow1D, shadow2D, shadow1DProj, shadow2Dproj
  • Vertex
  • ftransform

43
Windows API
  • Available now through 4 extensions
  • GL_ARB_shader_objects, GL_ARB_shading_language_100
    , GL_ARB_vertex_shader, GL_ARB_fragment_shader
  • Core in OpenGL 2.0
  • With very minor modifications

44
Basic method
  • 2 basic object types
  • Shader object
  • Program object
  • Create Vertex Fragment Shader Objects
  • Compile both
  • Create program object attach shaders
  • Link program
  • Use program

45
Creating objects
  • GLhandleARB glCreateProgramObjectARB()
  • GLhandleARB glCreateShaderObjectARB(GL_VERTEX_SHAD
    ER_ARB)
  • GLhandleARB glCreateShaderObjectARB(GL_FRAGMENT_SH
    ADER_ARB)

46
Compiling
  • void glShaderSourceARB(GLhandleARB shader,
    GLsizei nstrings, const GLcharARB strings,
    const GLint lengths)
  • //if lengthsNULL, assumed to be null-terminated
  • void glCompileShaderARB(GLhandleARB shader)

47
Attaching Linking
  • void glAttachObjectARB(GLhandleARB program,
    GLhandleARB shader)
  • //twice, once for vertex shader once for
    fragment shader
  • void glLinkProgramARB(GLhandleARB program)
  • //program now ready to use
  • void glUseProgramObjectARB(GLhandleARB program)
  • //switches on shader, bypasses FFP
  • //if program0, shaders turned off, returns to
    FFP

48
In short
  • GLhandleARB programObject
  • GLhandleARB vertexShaderObject
  • GLhandleARB fragmentShaderObject
  • unsigned char vertexShaderSource
    readShaderFile(vertexShaderFilename)
  • unsigned char fragmentShaderSource
    readShaderFile(fragmentShaderFilename)
  • programObjectglCreateProgramObjectARB()
  • vertexShaderObjectglCreateShaderObjectARB(GL_VERT
    EX_SHADER_ARB)
  • fragmentShaderObjectglCreateShaderObjectARB(GL_FR
    AGMENT_SHADER_ARB)
  • glShaderSourceARB(vertexShaderObject,1,(const
    char)vertexShaderSource,NULL)
  • glShaderSourceARB(fragmentShaderObject,1,(const
    char)fragmentShaderSource,NULL)
  • glCompileShaderARB(vertexShaderObject)
  • glCompileShaderARB(fragmentShaderObject)
  • glAttachObjectARB(programObject,
    vertexShaderObject)
  • glAttachObjectARB(programObject,
    fragmentShaderObject)

49
In short
  • glUseProgramObjectARB(programObject)
  • // enables shaders attached to programObject
  • doRendering()
  • glUseProgramObjectARB(0)
  • // return to fixed function pipeline

50
Loading Uniforms
  • void glUniform1234fiARB(GLint
    location,)
  • Location obtained with
  • GLint glGetUniformLocationARB(GLhandleARB
    program, const GLcharARB name)
  • Shader must be enabled with glUseProgramObjectARB(
    ) before uniforms can be loaded

51
Loading Attributes
  • void glVertexAttrib1234sfdARB(GLint
    index,)
  • Index obtained with
  • GLint glGetAttribLocationARB(GLhandleARB
    program, const GLcharARB name)
  • Alternate method
  • void glBindAttribLocationARB(GLhandleARB program,
    GLuint index, const GLcharARB name)
  • Program must be linked after binding attrib
    locations

52
Loading Textures
  • Bind textures to different units as usual
  • glActiveTexture(GL_TEXTURE0)
  • glBindTexture(GL_TEXTURE_2D,myFirstTexture)
  • glActiveTexture(GL_TEXTURE1)
  • glBindTexture(GL_TEXTURE_2D,mySecondTexture)
  • Then load corresponding sampler with texture unit
    that texture is bound to
  • glUniform1iARB(glGetUniformLocationARB(
    programObject,myFirstSampler),0)
  • glUniform1iARB(glGetUniformLocationARB(
    programObject,mySecondSampler),1)

53
Other functions
  • Clean-up
  • void glDetachObjectARB(GLhandleARB container,
    GLhandleARB attached)
  • void glDeleteObjectARB(GLhandleARB object)
  • Info Log
  • void glGetInfoLogARB(GLhandleARB object,
    GLsizei maxLength, GLsizei length, GLcharARB
    infoLog)
  • Returns compile linking information, errors
Write a Comment
User Comments (0)
About PowerShow.com