Jump to content

  • Log In with Google      Sign In   
  • Create Account


How to handle input layouts in DX11?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 jbb   Members   -  Reputation: 328

Like
0Likes
Like

Posted 12 March 2012 - 03:43 AM

How do people handle input layouts elegantly in directx11?

Simplifying things a little, I have an Effect class which is responsible for how to draw something, and amongst other things holds the vertex shader to use. I also have a Element class which holds the geometry to draw amongst other things (vertex buffer, index buffer etc).

The problem is that only my Element class knows about the format of the vertex buffers if uses so it's really the only object that can create and set the input layout, However in order to do this it needs to know which vertex shader is being used for that draw call, and in fact needs to create a different input layout for each shader that can be used to draw it, as well as to know at run time which shader is being used so it can select which input layout is the appropriate one.

I can make my Element object cache the ID3D11InputLayout in a map indexed on vertex structure type, and vertex shader type, and share that map between all of the elements rather than create the input layout each time it's asked to draw something (which I suspect would be horribly inefficient anyway...) but that just seems inelegant and mixes together the responsibilities for the Effect and the Element far too much.

So how do people handle selecting which input layout to use, creating the ID3D11InputLayout objects, and so on? Is there something I'm missing, or is my overall design flawed and could be altered?

Thanks for any suggestions :)

Sponsor:

#2 Hodgman   Moderators   -  Reputation: 29400

Like
0Likes
Like

Posted 12 March 2012 - 04:56 AM

Before issuing a draw-call, I look at the currently bound Element's vertex description and the currently bound Effect's vertex description (to use your terminology) and then use a 2D look-up-table to fetch the appropriate input layout to use.

#3 jbb   Members   -  Reputation: 328

Like
0Likes
Like

Posted 12 March 2012 - 05:00 AM

Before issuing a draw-call, I look at the currently bound Element's vertex description and the currently bound Effect's vertex description (to use your terminology) and then use a 2D look-up-table to fetch the appropriate input layout to use.

(I don't like my terminology for Element, I plan to change that to something more descriptive!)
Thanks,
Do you calculate all the possible combinations in advance, or generate and cache them when needed?
I was trying to avoid my drawing code having to know anything about the geometry that it was asking the element to draw, but I guess it's unavoidable because of the coupling between the two things

#4 MJP   Moderators   -  Reputation: 10871

Like
0Likes
Like

Posted 12 March 2012 - 01:08 PM

I generate the input layouts at load time, since I know what shaders are used for a given vertex buffer. If you don't know that in advance, then you have to do it at the time of the draw call.

#5 Jason Z   Crossbones+   -  Reputation: 4905

Like
0Likes
Like

Posted 12 March 2012 - 06:15 PM

I am of the school of thought that the geometry has to be specified in advance with the effect and the type of draw call. In that case, I generate the layout once for each effect that a geometry object will be used with, and then just cache it for later on. This means you have to intentionally ensure that the geometry can be used with a particular effect before using it, but you need to do that anyways - for example, you can't use an effect that needs tangents and bitangents if your geometry doesn't have them.

So you could use a preprocess to generate the layouts that you will need and store them in a script, or just load them up as you need them (this is what Hieroglyph 3 does).




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS