Groupe de Travail Introduction GPU/GLSL - PowerPoint PPT Presentation

About This Presentation
Title:

Groupe de Travail Introduction GPU/GLSL

Description:

Groupe de Travail Introduction GPU/GLSL S bastien Barbier Laboratoire Jean Kuntzmann/EVASION Grenoble sebastien.barbier_at_inrialpes.fr – PowerPoint PPT presentation

Number of Views:26
Avg rating:3.0/5.0
Slides: 50
Provided by: wwwevasi
Category:

less

Transcript and Presenter's Notes

Title: Groupe de Travail Introduction GPU/GLSL


1
Groupe de Travail Introduction GPU/GLSL
  • Sébastien Barbier
  • Laboratoire Jean Kuntzmann/EVASION
  • Grenoble
  • sebastien.barbier_at_inrialpes.fr

2
Plan
  • Historique
  • Fonctionnalités des cartes graphiques
  • GLSL
  • Communications CPU ? GPU
  • Rendu Off-Screen
  • GPGPU

3
Plan
  • Historique
  • Fonctionnalités des cartes graphiques
  • GLSL
  • Communications CPU ? GPU
  • Rendu Off-Screen
  • GPGPU

4
Motivations
  • Le CPU soccupe
  • Simulation physique, Intelligence Artificielle,
    Son, Réseau
  • Le GPU doit vérifier
  • Accès mémoire rapide
  • Nombreux accès vertices, normal, textures,
  • Une bonne bande passante
  • Go/s au meilleur cas
  • Une grande force de calcul
  • Flops Floating Point Operations ADD, MUL,
    SUB,
  • Illustration matrix-vector products
  • (16 MUL 12 ADD) x (vertices normals) x fps
  • (28 Flops) x (6.000.000) x 30 5GFlops

5
Motivations
  • Interactivité 15-60 fps
  • Haute Résolution

6
Pipeline Graphique
LOD selection Frustum Culling Portal
Culling
Application
Modelview/Projection tr. Clipping
Lighting Division by w Primitive
Assembly Viewport transform Backface culling
Geometry Processing
Scan Conversion Fragment Shading Color and
Texture interpol. Frame Buffer Ops Z-buffer,
Alpha Blending,
Rasterization
Output to Device
Output
7
Pipeline Graphique
LOD selection Frustum Culling Portal
Culling
Application
Programmable
Clipping Division by
w Viewport transform Backface culling
VERTEX SHADER
Geometry Processing
GEOMETRY SHADER
Scan Conversion
Rasterization
FRAGMENT SHADER
Output to Device
Output
8
Shaders
9
Plan
  • Historique
  • Fonctionnalités des cartes graphiques
  • GLSL
  • Communications CPU ? GPU
  • Rendu Off-Screen
  • GPGPU

10
Pipeline Graphique
11
Fonctionnalités des cartes graphiquesShaders
  • On agit au niveau local
  • Vertex shader un sommet à la fois
  • On ne connaît pas les sommets voisins

12
Fonctionnalités des cartes graphiquesShaders
  • On agit au niveau local
  • Geometry shader une primitive à la fois
  • On ne connait que les sommets de la primitive
    courante
  • On peut aussi connaître ses voisins

13
Fonctionnalités des cartes graphiquesShaders
  • On agit au niveau local
  • Pixel shader un pixel à la fois
  • On ne connaît pas les pixels voisins
  • Au mieux, variation dune valeur par rapport au
    pixel dà côté

14
Fonctionnalités des cartes graphiquesShaders
  • Ce quon peut faire
  • Au niveau des sommets
  • Des transformations/projections
  • Des calculs de coordonnées de textures
  • Des calculs dillumination, de couleurs

( x, y, z, w ) ( nx, ny, nz ) ( s, t, r, q ) ( r,
g, b, a )
15
Fonctionnalités des cartes graphiquesShaders
  • Ce quon peut faire
  • Au niveau des primitives
  • Ajouter/Supprimer des sommets
  • Modifier les primitives
  • Récupérer directement la géométrie sans
    tramage.

16
Fonctionnalités des cartes graphiquesShaders
  • Ce quon peut faire
  • Au niveau des pixels
  • La même chose quaux sommets, mais par pixel
  • Utiliser le contenu de textures dans des calculs
  • Changer la profondeur des pixels

17
Fonctionnalités des cartes graphiquesShaders
  • Ce quon ne peut pas (encore ?) faire
  • Modifier le tramage (rasterizer)
  • Modifier la composition (output merger)
  • Lire le buffer de dessin sur la fenêtre

18
Plan
  • Historique
  • Fonctionnalités des cartes graphiques
  • GLSL
  • Communications CPU ? GPU
  • Rendu Off-Screen
  • GPGPU

19
GLSLTypes de base
  • Flottants, entiers, booléens
  • float, bool, int, unsigned int
  • Vecteurs 2,3,4
  • b,u,ivec2,3,4
  • Matrices 2x2, 3x3, 4x4
  • mat2,3,4
  • Accesseurs de textures
  • sampler1,2,3D, samplerCube, samplerRect, (et
    plein dautres !!)
  • Structures
  • struct my_struct int index float value
  • Tableaux
  • int array5

20
GLSL Entrées
  • Built-in tous les états dOpenGL, passés par
    OpenGL
  • Position (glVertex3fv, )
  • Couleurs (glColor4f, )
  • Directions des lumières (glLighiv, )
  • Textures flottantes ou entières
    (glTexCoord123if, )
  • Matrices (glMatrixMode, )
  • Matériaux (glMateriali, )
  • Attribute passés par le programme OpenGL
  • Peuvent varier pour chaque sommet (couleurs,
    textures, normales, )
  • Uniform passés par le programme OpenGL
  • Ne varie pas entre glBegin/glEnd (matrices,
    textures, lumières, )
  • Varying échanges entre les différents shaders
  • In dentrées
  • Out de sortie
  • Constant constant au sein des shaders

21
GLSLEntrées built-in
  • Vertex/Geometry shader
  • Position gl_Vertex
  • Couleurs gl_Color, gl_SecondaryColor
  • Normale gl_Normal
  • Coordonnées de textures gl_MultiTexCoordn
  • Fragment shader
  • gl_FragCoord coordonnées du pixel dans la
    fenêtre
  • gl_Color couleur du pixel interpolée
  • gl_TexCoord coordonnées de textures
    interpolées
  • gl_FrontFacing face ou dos du triangle

22
GLSLSorties
  • Vertex/Geometry shader
  • gl_Position position du sommet en coordonnées
    homogènes (obligatoire)
  • gl_PointSize taille dun point en rendu par
    point
  • gl_FrontColor, gl_BackColor couleurs
  • gl_TexCoord coordonnées de textures
  • Fragment Shader
  • gl_FragColor couleur du pixel (obligatoire)
  • gl_FragData rendu offscreen (obligatoire)
  • gl_FragDepth profondeur du pixel

23
GLSLGénération
  • Geometry shader
  • EmitVertex()
  • EndPrimitive()
  • Types des primitives
  • Points, Lignes, Triangles
  • Lignes, Triangles avec Adjacences

3
2
4
1
5
3
0
1
2
3
2
0
1
2
3
4
1
5
6
24
GLSLFonctions built-in
  • Trigonométrie
  • sin, cos, tan, asin, acos, atan,
  • Exponentiation
  • exp, pow, log, exp2, log2, sqrt,
  • Arithmétiques
  • abs, sign, floor, ceil, fract, mod, min, max,
    clamp, mix, step,
  • Géométriques
  • length, distance, dot, cross, normalize, reflect,
    refract
  • Accès aux textures
  • texture1D, texture2D, texture3D, textureCube,
    shadow,
  • Manipulation de bits
  • ltlt , gtgt , ,
  • Et dautres

25
GLSLSwizzle
  • Convention de notations (vec4)
  • position x, y, z, w
  • couleur r, g, b, a
  • texture s, t, p, q
  • Permutation des variables
  • Toutes les combinaisons sont possibles
  • vec4 res
  • res.xyzw (par défaut)
  • res.xxxx, res.xyxy, res.xyzx, res.wzyx, res.xyww,
    etc
  • Changement de dimensions
  • vec4 start vec3 triple vec2 couple float
    alone
  • triple start.xyz
  • couple start.xy
  • alone start.x

26
GLSLPremier Programme
uniform vec4 Bidule vec4 UneFonction( vec4
Entree ) return Entree.zxyw void
main() vec4 pos gl_ModelViewProjectionMatrix
gl_Vertex gl_Position pos UneFonction(
Bidule )
Entrée
Fonction
Swizzle
Point dentrée
Entrées OpenGL
Variable locale
Multiplication matrice-vecteur
Sortie OpenGL
27
GLSLCompilation
  • Création Kernel
  • shader_id glCreateShaderObjectARB(type)
  • Type GL_VERTEX_SHADER_ARB, GL_FRAGMENT_SHADER_A
    RB, GL_GEOMETRY_SHADER_EXT
  • glShaderSourceARB(shader_id,1,const_shader_src,NU
    LL)
  • const_shader_src programme
  • Compilation
  • glCompileShaderARB(shader_id)
  • Debug
  • glGetProgramivARB(shader_id,GL_OBJECT_INFO_LOG_LEN
    GTH_ARB,info_log_length)
  • c_infolog new charinfo_log_length
  • glGetInfoLogARB(shader_id,info_log_length,nread,c
    _infolog)

28
GLSLCompilation
  • Création Programme
  • _program_shader glCreateProgramObjectARB()
  • Propriétés Geometry Kernel
  • glProgramParameteriEXT(_program_shader,
    GL_GEOMETRY_INPUT_TYPE_EXT, _input_device)
  • glProgramParameteriEXT(_program_shader,
    GL_GEOMETRY_OUTPUT_TYPE_EXT, _output_device)
  • glProgramParameteriEXT(_program_shader,
    GL_GEOMETRY_VERTICES_OUT_EXT, _nb_max_vertices)
  • Attacher
  • glAttachObjectARB(_program_shader,_vertex_shader)
  • glAttachObjectARB(_program_shader,
    _geometry_shader)
  • glAttachObjectARB(_program_shader,_fragment_shade
    r)
  • Lier
  • glLinkProgramARB(_program_shader)

29
GLSLUniforms/Attributes
glUseProgramObjectARB( Program
) glGetUniformLocationARB() glUniform1,2,3,4f
vARB() glUniformMatrix2,3,4fvARB() glGetAt
tribLocationARB() glVertexAttrib1,2,3,4fvARB(
) glUseProgramObjectARB(0)
Utilisation dun programme
Réglage dun uniform
Réglage dun attribute
Fin de programme
30
Plan
  • Historique
  • Fonctionnalités des cartes graphiques
  • GLSL
  • Communications CPU ? GPU
  • Rendu Off-Screen
  • GPGPU

31
GénéralitésTypes de Buffer
  • Mise à jour static, dynamic, stream
  • Static une et une seule fois pour lapplication
  • Dynamic modification multiples pour plusieurs
    rendus
  • Stream une modification, un rendu
  • Accès read, draw, copy
  • Read From GPU to CPU
  • Draw From CPU to GPU
  • Copy Both and From GPU to GPU
  • Création
  • glGenBuffersARB(1, _name)
  • glBindBufferARB(NATURE, _name)
  • glBufferDataARB(NATURE, size, ptr, TYPE)

32
Communications CPU ? GPU du CPU vers le GPU
  • Vertex et Index Buffer Objects (VBO)
  • Envoyer la géométrie via des tableaux
  • Position, Normal, Couleurs, Coordonnées de
    textures (GL_ARRAY_BUFFER_ARB)
  • Topologie (GL_ELEMENT_ARRAY_BUFFER_ARB)
  • Type STATICDYNAMICSTREAM_DRAW

33
Communications CPU ? GPUdu CPU vers le GPU
  • Pixel Buffer Object UNPACK (PBO)
  • Envoyer une texture au GPU GL_PIXEL_UNPACK_BUFFER_
    ARB
  • Activer le buffer
  • Remplir le buffer
  • Instancier la texture
  • Type STATICDYNAMICSTREAM_DRAW

34
Communications CPU ? GPUdu GPU vers le CPU
  • Pixel Buffer Object PACK (PBO)
  • Récupérer une texture du GPU GL_PIXEL_PACK_BUFFER_
    EXT
  • Activer le buffer
  • Lire la sortie glReadPixels
  • Mapping
  • Type STATICDYNAMICSTREAM_READ

35
Communications CPU ? GPUdu GPU vers le CPU/GPU
  • TRANSFORM FEEDBACK BUFFER OBJECT
  • Buffer déléments spécial GL_ARRAY_BUFFER_ARB
  • Spécifier
  • Les éléments à récupérer à la fin du VS ou du GS
  • Comment ? Un/Plusieurs buffers
  • Lors du rendu GL_TRANSFORM_FEEDBACK_BUFFER_NV
  • Activer ou Désactiver la Rasterisation
    glEnable(GL_RASTERIZER_DISCARD)
  • TYPE DYNAMICSTREAM_COPYREAD

36
Communications CPU ? GPU du CPU/GPU vers le GPU
  • Texture Buffer Objects (TBO)
  • Envoyer une texture accessible comme un tableau
  • Utilisation Réutiliser la sortie du pixel
    shader comme un buffer de géometrie
  • GL_TEXTURE_BUFFER_EXT
  • Type STATICDYNAMICSTREAM_DRAWCOPY
  • glTexBufferEXT association avec la texture

37
Communications CPU ? GPU du CPU vers le GPU
  • Bindable Uniform Buffer Objects (BUBO)
  • Envoyer des uniforms accessibles par TOUS les
    shaders
  • Minimiser lenvoi de constantes (et aussi la
    place mémoire)
  • GL_UNIFORM_BUFFER_EXT
  • Type STATIC_DRAW
  • glUniformBufferExt association mémoire buffer

38
Plan
  • Historique
  • Fonctionnalités des cartes graphiques
  • GLSL
  • Communications CPU ? GPU
  • Rendu Off-Screen
  • GPGPU

39
Rendu off-screen
  • FrameBuffer Objects (FBO)
  • Object GL_FRAMEBUFFER_EXT
  • Attacher
  • n textures GL_COLOR_ATTACHMENTn_EXT
  • z-buffer GL_DEPTH_ATTACHMENT_EXT
  • stencil-buffer GL_STENCIL_ATTACHMENT_EXT

40
Rendu off-screen
  • FrameBuffer Objects (FBO) Type de Textures
  • Flottantes rectangles gl_FragDatan
  • Entières rectangles varying out iuvec4 data
  • Tableau de textures 1D, 2D (layers)
  • glFramebufferTextureArrayExt(),TEXTURE_1D2D_ARR
    AY_EXT
  • gl_Layer

41
Rendu off-screen
  • FrameBuffer Objects (FBO)
  • Rendu
  • Activer le FrameBuffer
  • Activer le rendu dans les différentes textures
  • Dessiner
  • Terminer

42
Plan
  • Historique
  • Fonctionnalités des cartes graphiques
  • GLSL
  • Communications CPU ? GPU
  • Rendu Off-Screen
  • GPGPU

43
GPGPU
  • General-Purpose Computation Using Graphics
    Hardware
  • Un GPU un processeur SIMD
  • Une texture un tableau dentrée
  • Une image un tableau de sortie

44
GPGPU Applications
  • Rendu avancé
  • Illumination globale
  • Image-based rendering
  • Traitement du signal
  • Géométrie algorithmique
  • Algorithmes génétiques
  • A priori, tout ce qui peut se paralléliser

45
GPGPULimitations
  • Récupérer limage rendue lent
  • PCI Express
  • Opérateurs, fonctions, types assez limités
  • Un algorithme parallélisé nest pas forcément
    plus rapide que lalgorithme séquentiel

46
GPGPULangages
  • CUDA (NVIDIA)
  • CTM (ATI)
  • Shallows (Johan S. Seland Chercheur à SINTEF
    ICT - Norvège)
  • OpenCL (KRONOS, initié par APPLE)
  • Exploite les puissances combinées du CPU et du GPU

47
GPGPUCUDA
  • Compute Unified Device Architecture
  • Basé sur le langage C
  • Propose une mémoire partagée de 16 Ko pour les
    threads
  • Pensé pour simplifier les accès, les retours et
    la compilation des kernels pour les
    non-spécialistes dOpenGL.
  • Librairies fournies
  • FFT
  • BLAS Algèbre Linéaire

48
GPGPUExemple Cuda
  • cudaArray cu_array float gpu_array
  • float cpu_array new floatwidthheight
  • textureltfloat, 2, cudaReadModeElementTypegt tex
  • //Allocate array
  • cudaMalloc((void)gpu_array, widthheightsizeof
    (float))
  • // Bind the array to the texture
  • cudaBindTextureToArray(tex, cuArray)
  • // Run kernel
  • dim3 blockDim(16, 16)
  • dim3 gridDim(width / blockDim.x, height /
    blockDm.y)
  • kernel ltltltgridDim, blockDimgtgtgt(gpu_array,
    cu_array, width)
  • cudaUnbindTexture(tex)
  • //Copy GPU data to array
  • cudaMemcpy(cpu_array,gpu_array,widthheightsizeof
    (float),cudaMemcpyDeviceToHost)
  • //Free memory
  • cudaFree(gpu_array) delete cpu_array
  • __global__ void kernel(float odata, float
    idata, int width)

49
Références/Liens Utiles
  • La spec GLSL http//www.opengl.org/registry/doc
    /GLSLangSpec.Full.1.30.08.pdf
  • Cg http//developer.nvidia.com/p
    age/cg_main.html
  • Cuda http//www.nvidia.com/cuda
  • OpenCL http//www.kronos.org/opencl/
  • Libraries pour les extensions
  • GLUX (de Sylvain !) http//www-sop.inria.fr/reve
    s/Sylvain.Lefebvre/glux/
  • GLEW http//glew.sourceforge.
    net/
  • Un éditeur spécial shader (malheureusement pas à
    jour, mais bien pour débuter)
  • http//www.typhoonlabs.com/
  • Erreurs openGL/GLSL un débogueur simple,
    efficace, super utile, vite pris en main.
  • http//www.vis.uni-stuttgart.de/glsldevil/
  • Des tas dexemples (à tester, éplucher, torturer)
  • http//developer.nvidia.com/object/sdk_home.html
  • La référence GPGPU avec code, forums, tutoriaux
    http//www.gpgpu.org/
Write a Comment
User Comments (0)
About PowerShow.com