Mark Ingram
Mark Ingram

Reputation: 73625

Is there a performance penalty for creating Direct3D vertices with all semantic types?

In Direct3D, you can create any type of Vertex you like. You can have a simple Vertex with just positional information, or you could add colour info, texture info, etc etc. When creating your input layout, you define what parts of a Vertex you've implemented:

D3D10_INPUT_ELEMENT_DESC layout[] =
{
    { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 },
    { "COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D10_APPEND_ALIGNED_ELEMENT, D3D10_INPUT_PER_VERTEX_DATA, 0 },
};

My question is, should I define a vertex structure with all of the input types (position, colour, texture etc etc). Or should I create several vertex structures, each with different types of input.

The downsides to using multiple classes is that you have to create and maintain several classes, and it could be confusing knowing which type of vertex to use. What are the downsides of having 1 vertex structure?

Upvotes: 0

Views: 168

Answers (3)

Alexander Gessler
Alexander Gessler

Reputation: 46607

Don't do that, use specialized structures. Uploading vertex data to the GPU consumes a lot of your bandwidth and quickly becomes a bottleneck (given that the problem is trivial to solve -- wrap a Vertexbuffer in a custom class to handle the conversion to the most efficient input layout automatically).

It's also unpractical - Skinning, for example, needs a lot of per-vertex extra data. Do you really want every single vertex in your application to carry it as well, even though it is not needed at all?

I do, however, recommend to establish some kind of convention for the order in which the vertex components appear in the data structure. That'll help you at writing your shaders, because these are ultimatively coupled to vertex input layout.

Upvotes: 1

Mark Ingram
Mark Ingram

Reputation: 73625

I solved it by generating a chunk of memory on the heap and only filling it with the required elements. The code is available here:

http://code.google.com/p/woof/source/browse/trunk/Libraries/WOOF3D/Direct3D10Vertices.cpp?r=24

Upvotes: 0

n0rd
n0rd

Reputation: 12620

You will upload unused vertex data to the 3d accelerator, and it will eat some bandwidth. It shouldn't matter much unless you are doing some top notch video game (you'll almost certainly have a bottleneck somewhere else).

Upvotes: 1

Related Questions