   DirectX11 and VertexBuffer-VertexShader decoupling
  Hi,Our engine separates the concepts of vertex buffers and vertex shaders.Currently, when a model is loaded, its buffer is read and a vertex declaration is automatically created.Then, when it is about to be rendered, it is set together with the vertex shader associated with it.This is a problem when trying to write a single shader that works with many objects. In DX11, you cannot bind a vertex shader that doesn't use all of the inputs it receives (am I wrong? is there a way to bypass this?).So, if I have a simple shader (for debugging purposes, for example) and I try to render an object that has additional properties (bone indices/weights for example) that the shader doesn't use, I won't be able to bind them together and render.Is it possible to work around this issue without writing additional shaders? Perhaps create a vertex declaration with holes or something similar?Thanks!   
Quote:Original post by nomanCurrently, when a model is loaded, its buffer is read and a vertex declaration is automatically created.Model should use vertex declaration of shader it is rendered with.You can change current declaration on device and render model with another shader but you have to make sure you bind to device all streams that shader uses and set correct declaration that matches the definition of shader input (it is input structure of vertex function in your shader).Vertex declaration defines length,type,usage, offset in stream and stream index of every element.You bind streams to indexes to have actual data.Generaly, you should load all art explicit model data, and use them in manner of current rendering effect.;  I'll post my question in the form of an example :I have a shader that only uses the position and normal attributes. (Lets call it ShaderA)I have a shader that uses the position,uv and normal. (Lets call it shaderB)I have a model that contains all 3 elements in this order : Position,UV,Normal (Lets call it ModelA)ModelA normally renders with ShaderB.Assuming I want to render my model with ShaderA, DX11 will not let me bind the vertex declaration created for ShaderA with ModelA because the layouts don't match. (Incorrect vertex size etc)How do I get ModelA to render with ShaderA? Can a vertex declaration contain 'holes'?   ;Quote:Original post by nomanCan a vertex declaration contain 'holes'?I don't see why not. Just make sure the offsets in the vertex declaration are correct.Anyway, there's an easy way to find out: try it! :)   ;Quote:Original post by nomanAssuming I want to render my model with ShaderA, DX11 will not let me bind the vertex declaration created for ShaderA with ModelA because the layouts don't match. (Incorrect vertex size etc)Make a matching vertex declaration for shader A. You need to know layout of every stream. If every element is in separate streams you have easy sitation.If not dx, seems to know the layout of every stream and warns you, get this info and make a matching vertex declaration.In vertex shader for every element:-Set correct usage and dimension, dimension is always floatOn CPU in declaration:for every element in vertex set:amount of dimensions, datatype of dimension, stream index, offset in bytes in stream  Example:normal,position,uv is in 1 stream:You find out the order of usages in stream and use offset parameter to point.You know dimension type and amount of dimensions and stream index .normal,position,uv is in 3 streams:Offset is always 0 you need to know indexes of streams and their usage.;  Hey Noman!Sure you can!What I do in my rendering framework is to have the vertex shaders that are interested in rendering a given geometry (collection of vertexbuffer(s), indexbuffer and vertexdeclaration) to register with the geometry vertexdeclaration and internally keep the created inputlayouts for the actual rendering. However that was not the question - Just wanted to make to crystal clear before moving on.Say you have given vertexdeclaration with position, normal and texcoord in a single stream (a single vertexbuffer), and you want to render it with two shaders each with different input stream requirements. Shader A needs (position, normal) and Shader B needs (position, texcoord). Then you'll need to create a ID3D11InputLayout for each of the vertexdeclaration / shaders pairs and then use the correct one when setting up the rendering. As long as the vertex streams you're binding contains the data needed by the shader you can create an InputLayout and use the stream without any problems.I hope this answers the question and if you need further information you can read in the DirectX graphical docs under "Direct3D 9 to Direct3D 10 Considerations (Direct3D 10)"   ;  Thanks elurahu! Thats what I was looking for (that was my direction, I just wanted to know if it was legal to have declarations with holes in them).I assume its possible to investigate a loaded shader to find out which parameter it needs (if not, sucks to be me) - I guess I'll do that create appropriate declarations (my vertex buffers do have their element order attached to each of them)   