Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

This tutorial (msdn) gives a description of a vertex layout.

This is an example of a input layout:

D3D11_INPUT_ELEMENT_DESC layout[] =
{
    { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },  
};
UINT numElements = ARRAYSIZE(layout);

It seems to me that it would be easier to bypass this and simply consider data sent to the vertex shader/pixel shader as a block of floats and allow the vertex or pixel shader to interpret it as it wants.

My question is this:

  • What is the purpose of a vertex layout?
  • Is a vertex layout optional in Direct3D 11?
share|improve this question

2 Answers 2

up vote 4 down vote accepted

The example reasons why a vertex layout is needed:

We now have a structure that represents our vertex. That takes care of storing vertex information in system memory in our application. However, when we feed the GPU the vertex buffer containing our vertices, we are just feeding it a chunk of memory. The GPU must also know about the vertex layout in order to extract correct attributes out from the buffer. To accomplish this requires the use of an input layout.

Take into account that the vertex shader is just a step in the rendering pipeline, so is the responsibility of the GPU to issue the correct data as parameters in the shader. Yes, you could just define a "data size" and receive an array with that size in the shader and then process it, but that would require more code in the shader, and also could disallow GPU internal optimizations.

I haven't work with DX11, but in OpenGl, DX9 and other graphical APIs, you must define some kind of vertex layout

share|improve this answer

'A block of floats' wouldn't quite work, as

1) GPUs generally deal with vectors, usually 4-element vectors - and a vertex declaration defines how the floats are grouped into vectors (3-element position, 2-element UV set, etc)

2) Non-float data formats can be used, such as a 32-bit RGBA (which gets expanded into a vector of floats). The GPU needs to know about this

share|improve this answer
    
+1 for point no.2. –  Groky Aug 30 '11 at 20:30

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.