Shader signature question

Started by
4 comments, last by DividedByZero 6 years, 9 months ago

Hi Guys,

Just wondering if you could assist me with some basic theory here.

Why is it that CreateInputLayout() requires both the input description and shader input signature.

Quote

D3D11_INPUT_ELEMENT_DESC inputDescP[] = { "POSITION", 0 ,DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 };
        
const BYTE signature_fvf_xy[] = { // removed for sake of post size };

ID3D11InputLayout* inputLayoutXY;

int result = test->CreateInputLayout(inputDescP, 1, signature_fvf_xy, sizeof(signature_fvf_xy), &inputLayoutXY);

Seems like a redundant operation.

If the input signature is allready defined by the coder, then why is the input signature of the shader needed as well (if it has to be the same anyway)?

As far as I can tell, there is no way to successfully create an input layout with the input description alone. Why the requirement of doubling up on the same information?

Thanks in advance :)

Advertisement

(Sorry guys. Browser wont allow me to format the post correctly. No matter how I edit this thing, I can't separate the last paragraphs out of the code. Tried Chrome and IE)

The shader signature defines a structure that will be consumed by the vertex shader code. The input description defines a structure that exists across a set of buffers in memory. The IA stage is a translater that reads one format from memory and rearranges it into the format expected by the VS code. 

You can't translate from one format to another unless you know what both the formats are.

Validation.

Because different states can be specified in isolation from each other, part of an API's job is to validate the current combination of states in order to ensure that it's OK to draw with them.

Traditionally this could only be done at run time because older API's had no way of knowing what the final combination of states used for a draw call would be until the draw call is made.

Direct3D 10 moved a lot of validation from run time to object creation time, and Direct3D 11 continued with this. One place you see it is in the use of immutable state objects, gathering groups of related states used at different parts of the pipeline together. Another place you see it is in the tight coupling of input layouts with vertex shaders.

Think back to Direct3D 9 and try to imagine how vertex declarations might work. What happens if the vertex declaration provides an input that the vertex shader doesn't consume? What happens if the vertex shader consumes an input that the declaration doesn't provide? How are format conversions worked out? There are rules for all of these things, but because the API doesn't have a way to know which combination of declaration and shader will be used together it can't work things out until run time, typically when you make a draw call.

Under Direct3D 10+ because they're linked at creation time the validation can also be done at creation time, meaning that this step can be skipped at run time and run time gets faster.

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

Great explanation guys. Thank you for clearing this up for me. :)

This topic is closed to new replies.

Advertisement