Parte 2 Arquitetura de GPUs referncia GPU Gems

  • Slides: 48
Download presentation
Parte 2 - Arquitetura de GPU´s referência GPU Gems: Programming Techniques, Tips, and Tricks

Parte 2 - Arquitetura de GPU´s referência GPU Gems: Programming Techniques, Tips, and Tricks for Real-Time Graphics Randima Fernando referência GPU Gems 2 : Programming Techniques for High. Performance Graphics and General-Purpose Computation Matt Pharr, Randima Fernando

a. Arquitetura de Hardware

a. Arquitetura de Hardware

Arquitetura de GPUs Processador(es) Engine de Geometria CPU Interface CPU - GPU Engines de

Arquitetura de GPUs Processador(es) Engine de Geometria CPU Interface CPU - GPU Engines de Rasterização Front Buffer Back Buffers Z Buffer Stencil Buffer Texture Buffer Interface Front Buffer GPU - Video M e m ó r i a d e v í d e o

Arquitetura de GPUs

Arquitetura de GPUs

Arquitetura de GPUs

Arquitetura de GPUs

b. Programação de GPUs

b. Programação de GPUs

Programação de GPUs - Linguagens: Cg, HLSL, Open. GL Shader Language - Ambientes de

Programação de GPUs - Linguagens: Cg, HLSL, Open. GL Shader Language - Ambientes de Desenvolvimento NVídia FX Composer ATI Rendermonkey

Tipos de Variáveis - int, float, bool, struct, in, out, string - vetores: float

Tipos de Variáveis - int, float, bool, struct, in, out, string - vetores: float 2, float 3, float 4 Float 4 cor; Vermelho = cor[0]; Vermelho = cor. r; Vermelho = cor. x; Float 2 parte = cor. xy; (swizzling) Float 2 parte = {cor[0], cor[1]};

Matrizes -float. Lx. C: float 3 x 4, float 4 x 4. . .

Matrizes -float. Lx. C: float 3 x 4, float 4 x 4. . . -Matrix <float, 4, 4> Matriz 2; -Floar 4 x 4 matriz 1; -Float b = matriz 1. m 11; -Float c = matriz 1[0][1];

Funções Intrínsecas Abs (a), acos(x), all(x) [todos os componentes são não zero], any(x), asin(x),

Funções Intrínsecas Abs (a), acos(x), all(x) [todos os componentes são não zero], any(x), asin(x), atan 2(y, x), ceil(x), clamp(x, min, max), clip(x), cosh(x), cross(a, b), D 3 DCOLORto. UBYTE 4(x), ddx(x), ddy(x), degree(x), determinant(m), distance(a, b), dot(a, b), exp(x), exp 2(value a), faceforward(n, i, ng), floor(x), fmod(a, b), frac(x), frexp(x, out exp), fwidth(x), isfinite(x), isinf(x), isnan(x), idexp(x, exp), length(v), lerp(a, b, s), lit(n. l, n. h, m), log(x), log 10(x), log 2(x), max(a, b), min(a, b), modf(x, out ip), mul (a, B), noise(x), normalize(v), pow(x, y), radians(x), reflect(i, n), refract(i, n, R), round(x), rsqrt(x), saturate(x), sign(x), sincos(x, out s, out c), sinh(x), smoothstep(min, max, x), value sqrt(value a), step(a, x), tan(x), tanh(x), tex 1 D(s, t, ddx, ddy), tex 1 Dbias(s, t), tex 1 Dgrad(s, t, ddx, ddy), tex 1 Dlod(s, t), tex 1 Dproj(s, t), tex 2 D(s, t, ddx, ddy), tex 2 Dbias(s, t), tex 2 Dgrad(s, t, ddx, ddy), tex 2 Dlod(s, t), tex 2 Dproj(s, t), tex 3 D(s, t, ddx, ddy), tex 3 Dbias(s, t), tex 3 Dgrad(s, t, ddx, ddy), tex 3 Dlod(s, t), tex 3 Dproj(s, t), tex. CUBE(s, t, ddx, ddy), tex. CUBEbias(s, t), tex. CUBEgrad(s, t, ddx, ddy), tex. CUBElod(s, t), tex. CUBEproj(s, t), transpose(m)

Loops e Condicionais If, While, do, for. . .

Loops e Condicionais If, While, do, for. . .

c. Vertex Programming

c. Vertex Programming

c. Vertex Programming Operações nesta etapa: - Transformação da posição do vértice - Geração

c. Vertex Programming Operações nesta etapa: - Transformação da posição do vértice - Geração de coordenadas de textura para a posição do vértice - Iluminação sobre o vértice - Operações para determinar o material a ser aplicado ao vértice Efeitos: - Geração de texturas procedurais - Efeitos de iluminação per-vertex - Animação procedural em vértices - Displacement mapping

Struct input Vertex Struct Vertex. Input { float 4 Position : POSITION 0; float

Struct input Vertex Struct Vertex. Input { float 4 Position : POSITION 0; float 3 Normal : NORMAL; float 4 Texture. Coor : TEXCOORD 0; } BINORMAL[n] BLENDINDICES[n] BLENDWEIGHT [n] COLOR[n] NORMAL[n] POSITION[n] PSIZE[n] TANGENT[n] TESSFACTOR[n] TEXCOORD[n]

Struct output Vertex Struct Vertex. Output { float 4 Position : POSITION 0; float

Struct output Vertex Struct Vertex. Output { float 4 Position : POSITION 0; float 4 Texture. Coor : TEXCOORD 0; } COLOR[n] FOG POSITION PSIZE TEXCOORD[n]

c. Vertex Programming Struct Vertex. Input { float 4 Position : POSITION; float 2

c. Vertex Programming Struct Vertex. Input { float 4 Position : POSITION; float 2 Tex. Coord : TEXCOORD 0; } Struct Vertex. Output { floar 4 Position : POSITION; float 2 Tex. Coord : TEXCOORD 0; }

c. Vertex Programming Vertex. Out. Put Aula. Verterx. Shader (Vertex. Input input) { Vertex.

c. Vertex Programming Vertex. Out. Put Aula. Verterx. Shader (Vertex. Input input) { Vertex. Output output; World. View. Projection = mul (mul(World, View), Projection); output. Position = mul(input. Position, World. View. Projection); output. Tex. Coord = input. Tex. Coord; return (output); }

d. Pixel Programming

d. Pixel Programming

d. Pixel Programming Operações nesta etapa: - Computar a cor de um fragmento -

d. Pixel Programming Operações nesta etapa: - Computar a cor de um fragmento - Alterar iluminação “per-pixel” - gl_Frag. Coord

Struct input Pixel Struct Pixel. Input { float 4 Color : COLOR 0; }

Struct input Pixel Struct Pixel. Input { float 4 Color : COLOR 0; } COLOR[n] TEXCOORD[n] VFACE VPOS

Struct output Pixel Struct Pixel. Output { float 4 Position : POSITION 0; float

Struct output Pixel Struct Pixel. Output { float 4 Position : POSITION 0; float Depth : DEPTH; } COLOR[n] DEPTH[n]

d. Pixel Programming Struct Pixel. Input { float 2 Tex. Coord : TEXCOORD 0;

d. Pixel Programming Struct Pixel. Input { float 2 Tex. Coord : TEXCOORD 0; }

d. Pixel Programming Float 4 pixel. Shader (Pixel. Input input) : COLOR { return

d. Pixel Programming Float 4 pixel. Shader (Pixel. Input input) : COLOR { return (tex 2 D (Texture. Sampler, input. Tex. Coord) * Ambient. Color); }

Exemplo no XNA – Arquivo Ambiente. fx float 4 Ambient. Color : COLOR 0;

Exemplo no XNA – Arquivo Ambiente. fx float 4 Ambient. Color : COLOR 0; float 4 x 4 World. View. Projection : WORLDVIEWPROJECTION; texture Texture; sampler Texture. Sampler = sampler_state { texture = <Texture>; magfilter = LINEAR; minfilter = LINEAR; mipfilter = LINEAR; };

Exemplo no XNA – Arquivo Ambiente. fx struct Vertex. Input { float 4 Position

Exemplo no XNA – Arquivo Ambiente. fx struct Vertex. Input { float 4 Position : POSITION; float 2 Tex. Coord : TEXCOORD 0; }; struct Vertex. Output { float 4 Position : POSITION; float 2 Tex. Coord : TEXCOORD 0; }; Vertex. Output vertex. Shader (Vertex. Input input) { Vertex. Output output; World. View. Projection = mul (World, View), Projection); output. Position = mul(input. Position, World. View. Projection); output. Tex. Coord = input. Tex. Coord; return (output); }

Exemplo no XNA – Arquivo Ambiente. fx struct Pixel. Input { float 2 Tex.

Exemplo no XNA – Arquivo Ambiente. fx struct Pixel. Input { float 2 Tex. Coord : TEXCOORD 0; }; float 4 pixel. Shader (Pixel. Input input) : COLOR { //return (tex 2 D (Texture. Sampler, input. Tex. Coord)* Ambient. Color); return (1. 0 f, 0. 0 f); } technique Default { pass P 0 { Vertex. Shader = compile vs_1_1 vertex. Shader(); Pixel. Shader = compile ps_1_1 pixel. Shader (); } }

Exemplo no XNA – Projeto. net amespace Load 3 DObject { /// <summary> ///

Exemplo no XNA – Projeto. net amespace Load 3 DObject { /// <summary> /// This is the main type for your game /// </summary> public class Game 1 : Microsoft. Xna. Framework. Game { private Graphics. Device. Manager graphics; private Content. Manager content; private Matrix world; private Model model; private FPS fps; private First. Person. Camera camera; private Input. Handler input; private Texture 2 D grey. Asteroid; private Texture 2 D original. Asteroid; Effect shader;

Exemplo no XNA – Projeto. net public Game 1() { graphics = new Graphics.

Exemplo no XNA – Projeto. net public Game 1() { graphics = new Graphics. Device. Manager(this); content = new Content. Manager(Services); input = new Input. Handler(this); Components. Add(input); camera = new First. Person. Camera(this); Components. Add(camera); }

Exemplo no XNA – Projeto. net protected override void Initialize() { base. Initialize(); shader.

Exemplo no XNA – Projeto. net protected override void Initialize() { base. Initialize(); shader. Parameters["Ambient. Color"]. Set. Value(0. 8 f); }

Exemplo no XNA – Projeto. net protected override void Load. Graphics. Content(bool load. All.

Exemplo no XNA – Projeto. net protected override void Load. Graphics. Content(bool load. All. Content) { if (load. All. Content) { model = content. Load<Model>(@"ContentModelsasteroid 1"); grey. Asteroid = content. Load<Texture 2 D>(@"ContentTexturesasteroid 1 -grey"); original. Asteroid = content. Load<Texture 2 D>(@"ContentTexturesasteroid 1"); shader = content. Load<Effect>(@"Contenteffectsambiente"); } } protected override void Unload. Graphics. Content(bool unload. All. Content) { if (unload. All. Content == true) { content. Unload(); } }

Exemplo no XNA – Projeto. net protected override void Update(Game. Time game. Time) {

Exemplo no XNA – Projeto. net protected override void Update(Game. Time game. Time) { if (Game. Pad. Get. State(Player. Index. One). Buttons. Back == Button. State. Pressed) this. Exit(); base. Update(game. Time); }

Exemplo no XNA – Projeto. net protected override void Draw(Game. Time game. Time) {

Exemplo no XNA – Projeto. net protected override void Draw(Game. Time game. Time) { graphics. Graphics. Device. Clear(Color. Cornflower. Blue); // TODO: Add your drawing code here world = Matrix. Create. Rotation. Y( Math. Helper. To. Radians(270. 0 f * (float)game. Time. Total. Game. Time. Total. Seconds)) * Matrix. Create. Translation(new Vector 3(0, 0, -4000)); Draw. Model(ref model, ref world, grey. Asteroid); world = Matrix. Create. Rotation. Y( Math. Helper. To. Radians(45. 0 f * (float)game. Time. Total. Game. Time. Total. Seconds)) * Matrix. Create. Rotation. Z( Math. Helper. To. Radians(45. 0 f * (float)game. Time. Total. Game. Time. Total. Seconds)) * Matrix. Create. Translation(new Vector 3(0, 0, 4000)); Draw. Model(ref model, ref world, original. Asteroid); base. Draw(game. Time); }

Exemplo no XNA – Projeto. net private void Draw. Model(ref Model m, ref Matrix

Exemplo no XNA – Projeto. net private void Draw. Model(ref Model m, ref Matrix world, Texture 2 D texture) { Matrix[] transforms = new Matrix[m. Bones. Count]; m. Copy. Absolute. Bone. Transforms. To(transforms); foreach (Model. Mesh mesh in m. Meshes) { foreach (Model. Mesh. Part mp in mesh. Mesh. Parts) { if (texture != null) shader. Parameters["Texture"]. Set. Value(texture); shader. Parameters["Projection"]. Set. Value(camera. Projection); shader. Parameters["View"]. Set. Value(camera. View); shader. Parameters["World"]. Set. Value(world * mesh. Parent. Bone. Transform); mp. Effect = shader; mesh. Draw(); } } }

e. General Pourpose GPUs

e. General Pourpose GPUs

Requisitos dos Motores Encapsulamento Integração Independência de Plataforma Otimização em Hardware Gerenciamento de Projeto

Requisitos dos Motores Encapsulamento Integração Independência de Plataforma Otimização em Hardware Gerenciamento de Projeto

Arquitetura Níveis de Abstração: SDK Ferramental

Arquitetura Níveis de Abstração: SDK Ferramental

Arquitetura SDK referência 3 D Game Engine Architecture : Engineering Real-Time Applications with Wild

Arquitetura SDK referência 3 D Game Engine Architecture : Engineering Real-Time Applications with Wild Magic David H. Eberly

Arquitetura SDK

Arquitetura SDK

Biblioteca Matemática referência Operações de Vetores Operações de Matrizes Operações de Quaternions Operações de

Biblioteca Matemática referência Operações de Vetores Operações de Matrizes Operações de Quaternions Operações de Interceção Biblioteca baseada em GPUs Essential Mathematics for Games and Interactive Applications : A Programmer's Guide James M. Van Verth, Lars M. Bishop

Biblioteca de Rendering referência Abstração de APIs Implementação do Pipeline Leitor de shaders Tricks

Biblioteca de Rendering referência Abstração de APIs Implementação do Pipeline Leitor de shaders Tricks of the 3 D Game Programming Gurus-Advanced 3 D Graphics and Rasterization André La. Mothe

Biblioteca de Física

Biblioteca de Física

Biblioteca de Rede referência Programming Multiplayer Games Andrew Mulholland

Biblioteca de Rede referência Programming Multiplayer Games Andrew Mulholland

Biblioteca de Recursos referência www. gametutorials. com Standard Codecs: Image Compression to Advanced Video

Biblioteca de Recursos referência www. gametutorials. com Standard Codecs: Image Compression to Advanced Video Coding M. Ghanbari

Parser de Scripts Mapeamento com atributos dos objetos dinâmicos de um cenário Mapeamento com

Parser de Scripts Mapeamento com atributos dos objetos dinâmicos de um cenário Mapeamento com algumas funções do SDK

Arquitetura Ferramental referência 3 D Game Programming All in One Kenneth C Finney

Arquitetura Ferramental referência 3 D Game Programming All in One Kenneth C Finney

Arquitetura Ferramental

Arquitetura Ferramental

Arquitetura Ferramental SDK Script editors Conversores / Exportadores Engine Core Front End Level Editors

Arquitetura Ferramental SDK Script editors Conversores / Exportadores Engine Core Front End Level Editors EXEMPLO Builders

Arquitetura Ferramental

Arquitetura Ferramental