Sign in to follow this  
maya18222

Questions regarding shaders

Recommended Posts

maya18222    194
Whats the idea behind the approach they took for the programmer to create InputLayouts? From the documentation, it is simply used to check that the vertex type to be used matches that of the vertex shader signature. Where from my experimentation :- - Input layouts must match the vertex shader referenced signature exactly upon their creation (Device->CreateInputLayout()) - When rendering, its ok to bind an input layout, that has more elements than the vertex shader that is about to be called. ie, its ok to set an input layout that has pos,colour, and normal, to a vertex shader that is only exspecting pos and colour. As long as they are in the same order, and of the same size, as specified in the input layout. - When rendering, it is NOT ok to bind an input layout, that has *less* elements than the vertex shader that is about to be called. ie, its not ok to set an input layout that has pos,colour, to a vertex shader that is exspecting pos, colour and normal. But why cant we just do this without having to reference some shader? The documentation says that they can be reused between shaders as long as the signature is the same. So why cant we just define the layout simply with a signature? and not having to reference some pass in a shader. Surely the layout information should be kept with the vertex buffer. I recently came across the device functions, VSSetShader() and PSSetShader(), along with the setSampler, setResource and setConstantBuffs functions. Is this just the code that a D3DEffect wraps? Do these still require an input layout to be set? When calling ID3D10Buffer::Map() for some buffer, is this the same as ID3D10EffectVariable::set() for some effect handle ? When setting shader constants, using PSSetConstantBuffers(), it asks for a slot. Is this the order the constant appears in, in the shader? so if I have 3 constant buffers, one after the after. The first is slot 0 and the last slot 2? Same question with textures and samplers. So my shader would look something like ?:-
cbuffer buff1 // Slot0
{
	// Need to declare data types and name
	// so we can use it in the shader
	float4x4 gWorld;
	float4x4 gView; 
	float4x4 gProjection;
};

cbuffer buff2 // Slot1
{
// some data
}

cbuffer buff3 // Slot2
{
// some data
}

// Just need to declare name to be referenced in shader
Texture2D gTex1;      // Slot 0
Texture2D gTex2;      // Slot 1
TextureCube gTexCude; // Slot 2

// Just need to declare name to be referenced in shader
SamplerState gSam1; // Slot 0
SamplerState gSam2; // Slot 1
SamplerState gSam3; // Slot 2


Share this post


Link to post
Share on other sites
Washu    7829
Take a look at your input elements. Now, notice what each parameter does. How would Direct3D10 be able to anticipate the actual values of those parameters just based on the binary blob it receives from the buffer? Or how about if you have many buffers bound, how would it know which parts are in what buffers?

This is what the input layout object does: it takes a mapping of N data streams (and their associated element descriptors) and maps them to the input signature of the shader.

Share this post


Link to post
Share on other sites
maya18222    194
Im not arguing that the input layout isnt required. Im wondering why we have to create it with a reference to a shader vertex shader. Whilst the check can be convenient, I dont see why its strictly necessary.

Share this post


Link to post
Share on other sites
Washu    7829
Quote:
Original post by maya18222
Im not arguing that the input layout isnt required. Im wondering why we have to create it with a reference to a shader vertex shader. Whilst the check can be convenient, I dont see why its strictly necessary.

Because the layout of the parameters to your shader is not fixed EITHER.
struct VS_IN {
float4 pos : POSITION;
float3 normal : NORMAL;
float2 texCoord : TEXCOORD;
};

and
struct VS_IN {
float3 normal : NORMAL;
float4 pos : POSITION;
float2 texCoord : TEXCOORD;
};

will produce different signatures, and omitting one of those parameters certainly would. As such, in order for it to create a mapping from your input elements to the shader's expected layout, it needs to know the shader's input signature.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this