D3D10 and Input Layouts

Started by
4 comments, last by jffortin 15 years, 10 months ago
Hi, I'm currently updating/refactoring some engine code for D3D10 and I can't find a good way to encapsulate the input layouts. It's the fact that they link the vertex declarations and the effect passes in some way that makes it hard. First pass was to make this works. But recreating the input layout object for each passes, each vertex buffers on each frame is really not the best idea. How have you done this? Whose responsibility to manage these structures? Is there any examples that are worth looking at? Objects can share the same input element descriptors (a.k.a vertex declaration in D3D9) but might be rendered with different shaders, which means different passes and might need different input layout objects. Also each passes could be used to render objects using different descriptors so the passes might need to mange more than one input layout object. I was thinking about creating a structure to manage this in the D3D10 render device because it's the only class that will know about all the different objects at the API level. But this doesn't sound like a "clean" solution to me. JFF
Advertisement
CreateInputLayout maps between the input elements and the shader input. Other shaders that have the same input structure don't need a separate input layout. It's also okay if the shader has inputs which are the start of the full structure (i.e., same semantics and order, but some are missing at the end).

So if, for example, all shaders using a certain vertex structure have the same input structure in your HLSL file, then you can just use a single input layout and keep it with the "vertex declaration" object.
From Direct3D 10 FAQ:

I need a shader signature in order to create an Input Layout, but I load my meshes and create layouts before creating shaders. What do I do?


One solution is to switch the order and load shaders before loading meshes. However, this is much easier said than done. You always can create the Input Layouts on demand when needed by the application. You will have to keep a version of the shader signature around. You should create a hash based off of the shader and buffer layout, and only create the Input Layout if one that matches does not exist already.

Quote:Original post by XVincentX
From Direct3D 10 FAQ:

I need a shader signature in order to create an Input Layout, but I load my meshes and create layouts before creating shaders. What do I do?

One solution is to switch the order and load shaders before loading meshes. However, this is much easier said than done. You always can create the Input Layouts on demand when needed by the application. You will have to keep a version of the shader signature around. You should create a hash based off of the shader and buffer layout, and only create the Input Layout if one that matches does not exist already.


I guess I somehow forgot about FAQs when looking for solutions...


Quote:Original post by ET3D
So if, for example, all shaders using a certain vertex structure have the same input structure in your HLSL file, then you can just use a single input layout and keep it with the "vertex declaration" object.


My next try after reading the two posts would be to have a std::map or similar in the vertex declaration class I have. This would map shader layouts and input layouts so I could make a quick query to the map to retrieve the information I need when rendering.

This solution sounds good and doesn't add a new responsibility to the render device class (which was my main concern with what I was doing).

Thanks for the help so far! If anybody still has something to add to this I'm still interested in more ideas.

JFF
If you want to preserve space and not keep all the shaders in the memory, keep only the input signatures. The Input layout only needs the VS's anyway. Use D3D10GetInputSignatureBlob().
Every time you implement a singleton, God kills a kitten. Please, think of the kittens!
Quote:Original post by darkelf2k5
If you want to preserve space and not keep all the shaders in the memory, keep only the input signatures. The Input layout only needs the VS's anyway. Use D3D10GetInputSignatureBlob().


Well I'll be registering only the signatures that I need for the shaders I'll be rendering with so I guess (if I understand correctly) I won't save anything. I just get the signature from the effect pass descriptor like this:

    ID3D10EffectPass* pass = technique->GetPassByIndex(_index);    pass->GetDesc(&passDescriptor);


JFF

This topic is closed to new replies.

Advertisement