Presentation is loading. Please wait.

Presentation is loading. Please wait.

Arquitetura de GPU´s. a. Arquitetura de Hardware.

Similar presentations


Presentation on theme: "Arquitetura de GPU´s. a. Arquitetura de Hardware."— Presentation transcript:

1 Arquitetura de GPU´s

2 a. Arquitetura de Hardware

3 Interface CPU - GPU CPU Interface GPU - Video Engine de Geometria Engines de Rasterização Front Buffer Back Buffers Z Buffer Stencil Buffer Texture Buffer MemóriaMemória devídeodevídeo Processador(es) Back Buffer Front Buffer Arquitetura de GPUs

4

5

6 b. Programação de GPUs

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

8 Tipos de Variáveis - int, float, bool, struct, in, out, string - vetores: float2, float3, float4 Float4 cor; Vermelho = cor[0]; Vermelho = cor.r; Vermelho = cor.x; Float2 parte = cor.xy; (swizzling) Float2 parte = {cor[0], cor[1]};

9 Matrizes -floatLxC: float3x4, float4x4... -Matrix Matriz2; -Floar4x4 matriz1; -Float b = matriz1.m11; -Float c = matriz1[0][1];

10 Funções Intrínsecas Abs (a), acos(x), all(x) [todos os componentes são não zero], any(x), asin(x), atan(x), atan2(y,x), ceil(x), clamp(x, min, max), clip(x), cos(x), cosh(x), cross(a, b), D3DCOLORtoUBYTE4(x), ddx(x), ddy(x), degree(x), determinant(m), distance(a,b), dot(a, b), exp(x), exp2(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), log10(x), log2(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), sin(x), sincos(x, out s, out c), sinh(x), smoothstep(min, max, x), value sqrt(value a), step(a, x), tan(x), tanh(x), tex1D(s, t), tex1D(s, t, ddx, ddy), tex1Dbias(s, t), tex1Dgrad(s, t, ddx, ddy), tex1Dlod(s, t), tex1Dproj(s, t), tex2D(s, t), tex2D(s, t, ddx, ddy), tex2Dbias(s, t), tex2Dgrad(s, t, ddx, ddy), tex2Dlod(s, t), tex2Dproj(s, t), tex3D(s, t), tex3D(s, t, ddx, ddy), tex3Dbias(s, t), tex3Dgrad(s, t, ddx, ddy), tex3Dlod(s, t), tex3Dproj(s, t), texCUBE(s, t), texCUBE(s, t, ddx, ddy), texCUBEbias(s, t), texCUBEgrad(s, t, ddx, ddy), texCUBElod(s, t), texCUBEproj(s, t), transpose(m)

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

12 c. Vertex Programming

13 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 c. Vertex Programming

14 Struct input Vertex Struct VertexInput { float4 Position : POSITION0; float3 Normal : NORMAL; float4 TextureCoor : TEXCOORD0; } BINORMAL[n] BLENDINDICES[n] BLENDWEIGHT [n] COLOR[n] NORMAL[n] POSITION[n] PSIZE[n] TANGENT[n] TESSFACTOR[n] TEXCOORD[n]

15 Struct output Vertex Struct VertexOutput { float4 Position : POSITION0; float4 TextureCoor : TEXCOORD0; } COLOR[n] FOG POSITION PSIZE TEXCOORD[n]

16 Struct VertexInput { float4 Position : POSITION; float2 TexCoord : TEXCOORD0; } Struct VertexOutput { floar4 Position : POSITION; float2 TexCoord : TEXCOORD0; } c. Vertex Programming

17 VertexOutPut AulaVerterxShader (VertexInput input) { VertexOutput output; WorldViewProjection = mul (mul(World, View), Projection); output.Position = mul(input.Position, WorldViewProjection); output.TexCoord = input.TexCoord; return (output); } c. Vertex Programming

18 d. Pixel Programming

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

20 Struct input Pixel Struct PixelInput { float4 Color : COLOR0; } COLOR[n] TEXCOORD[n] VFACE VPOS

21 Struct output Pixel Struct PixelOutput { float4 Position : POSITION0; float Depth : DEPTH; } COLOR[n] DEPTH[n]

22 Struct PixelInput { float2 TexCoord : TEXCOORD0; } d. Pixel Programming

23 Float4 pixelShader (PixelInput input) : COLOR { return (tex2D (TextureSampler, input.TexCoord) * AmbientColor); } d. Pixel Programming

24 Exemplo no XNA – Arquivo Ambiente.fx float4 AmbientColor : COLOR0; float4x4 WorldViewProjection : WORLDVIEWPROJECTION; texture Texture; sampler TextureSampler = sampler_state { texture = ; magfilter = LINEAR; minfilter = LINEAR; mipfilter = LINEAR; };

25 Exemplo no XNA – Arquivo Ambiente.fx struct VertexInput { float4 Position : POSITION; float2 TexCoord : TEXCOORD0; }; struct VertexOutput { float4 Position : POSITION; float2 TexCoord : TEXCOORD0; }; VertexOutput vertexShader (VertexInput input) { VertexOutput output; WorldViewProjection = mul (mul (World, View), Projection); output.Position = mul(input.Position, WorldViewProjection); output.TexCoord = input.TexCoord; return (output); }

26 Exemplo no XNA – Arquivo Ambiente.fx struct PixelInput { float2 TexCoord : TEXCOORD0; }; float4 pixelShader (PixelInput input) : COLOR { //return (tex2D (TextureSampler, input.TexCoord)* AmbientColor); return (1.0f, 1.0f, 1.0f, 0.0f); } technique Default { pass P0 { VertexShader = compile vs_1_1 vertexShader(); PixelShader = compile ps_1_1 pixelShader (); }

27 Exemplo no XNA – Projeto.net amespace Load3DObject { /// /// This is the main type for your game /// public class Game1 : Microsoft.Xna.Framework.Game { private GraphicsDeviceManager graphics; private ContentManager content; private Matrix world; private Model model; private FPS fps; private FirstPersonCamera camera; private InputHandler input; private Texture2D greyAsteroid; private Texture2D originalAsteroid; Effect shader;

28 Exemplo no XNA – Projeto.net public Game1() { graphics = new GraphicsDeviceManager(this); content = new ContentManager(Services); input = new InputHandler(this); Components.Add(input); camera = new FirstPersonCamera(this); Components.Add(camera); }

29 Exemplo no XNA – Projeto.net protected override void Initialize() { base.Initialize(); shader.Parameters["AmbientColor"].SetValue(0.8f); }

30 Exemplo no XNA – Projeto.net protected override void LoadGraphicsContent(bool loadAllContent) { if (loadAllContent) { model = content.Load greyAsteroid = content.Load originalAsteroid = content.Load shader = content.Load } protected override void UnloadGraphicsContent(bool unloadAllContent) { if (unloadAllContent == true) { content.Unload(); }

31 Exemplo no XNA – Projeto.net protected override void Update(GameTime gameTime) { if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) this.Exit(); base.Update(gameTime); }

32 Exemplo no XNA – Projeto.net protected override void Draw(GameTime gameTime) { graphics.GraphicsDevice.Clear(Color.CornflowerBlue); // TODO: Add your drawing code here world = Matrix.CreateRotationY( MathHelper.ToRadians(270.0f * (float)gameTime.TotalGameTime.TotalSeconds)) * Matrix.CreateTranslation(new Vector3(0, 0, -4000)); DrawModel(ref model, ref world, greyAsteroid); world = Matrix.CreateRotationY( MathHelper.ToRadians(45.0f * (float)gameTime.TotalGameTime.TotalSeconds)) * Matrix.CreateRotationZ( MathHelper.ToRadians(45.0f * (float)gameTime.TotalGameTime.TotalSeconds)) * Matrix.CreateTranslation(new Vector3(0, 0, 4000)); DrawModel(ref model, ref world, originalAsteroid); base.Draw(gameTime); }

33 Exemplo no XNA – Projeto.net private void DrawModel(ref Model m, ref Matrix world, Texture2D texture) { Matrix[] transforms = new Matrix[m.Bones.Count]; m.CopyAbsoluteBoneTransformsTo(transforms); foreach (ModelMesh mesh in m.Meshes) { foreach (ModelMeshPart mp in mesh.MeshParts) { if (texture != null) shader.Parameters["Texture"].SetValue(texture); shader.Parameters["Projection"].SetValue(camera.Projection); shader.Parameters["View"].SetValue(camera.View); shader.Parameters["World"].SetValue(world * mesh.ParentBone.Transform); mp.Effect = shader; mesh.Draw(); }

34 e. General Pourpose GPUs


Download ppt "Arquitetura de GPU´s. a. Arquitetura de Hardware."

Similar presentations


Ads by Google