   alternative hardware instancing technique
  Hello,I'm coming from the GL world, and I'm trying to implement hardware geometry instancing in a way that will be compatible for both my GL renderer and my DirectX renderer.In GL, you call a different draw function (DrawElementsInstanced) to enable instancing.  This function provides vertex shaders with a constant value (gl_InstanceID) that is unique to each instance of the object being drawn.  This handy value can be used to fetch per-instance data from textures or vertex buffers.  It can also be used to synthesize per-instance data, which seems like an under-rated usage.  Is there any equivalent in Dirext X (9/10/11) ?Alternatively, OpenGL also provides, what looks to be helpful for compatibility with Direct X instancing, a 'vertex attribute divisor'.  This feature seems to parallel the instancing support in DirectX 9.0c a la:d3d9Device->SetStreamSourceFreq(0, num_copies | D3DSTREAMSOURCE_INDEXEDDATA );I don't have experience with this form of instancing because it seems much less flexible as you need to build and bind an extra vertex buffer for rendering, instead of using textures or other buffers/arrays.  The vertex shader is provided with the per-instance data as vertex attributes.  There is no unique ID available to fetch per-instance data from other buffers, or to synthesize per-instance data.To summarize, DirectX 9.0c provides the per-instance data only via vertex attributes.  Do later versions of Direct X (10/11) provide a unique constant which would allow per-instance data to be stored in buffers?   
  You always have to add that unique constant as a FLOAT1 TEXCOORD to your vertex declaration and then fill it in for every vertex.For example, if I have an 8-vertex cube mesh that I want to instance 20 times, and the mesh declaration is Position, Normal and U,V (for example), then you do the following:1. Add a FLOAT1 TEXCOORD to the existing Pos, Normal, Texcoord vertex decl.2. Create a large vertex buffer with space for 8 * 20 vertices.3. Replicate the Pos, Normal and U,V 20 times throughout the larger VB.4. Place 8 0's in the first 8 vertices "InstanceIndex" FLOAT1. Place 8 1's in the second 8 vertices "InstanceIndex" FLOAT2, etc, etc.5. In the Vertex Shader take this per-vertex instance index and use it to index into an array of shader constants (perhaps float4s) and derive enough to create a S,R,T matrix for this vertex of this instance.D3DVERTEXELEMENT9 VertexMeshInstanceElements[] ={{ 0, 0,D3DDECLTYPE_FLOAT3,D3DDECLMETHOD_DEFAULT,  D3DDECLUSAGE_POSITION,  0 },{ 0, 3 * 4, D3DDECLTYPE_FLOAT3,D3DDECLMETHOD_DEFAULT,  D3DDECLUSAGE_NORMAL,    0 },{ 0, 6 * 4, D3DDECLTYPE_FLOAT2,D3DDECLMETHOD_DEFAULT,  D3DDECLUSAGE_TEXCOORD,  0 },{ 0, 8 * 4, D3DDECLTYPE_FLOAT1,D3DDECLMETHOD_DEFAULT,  D3DDECLUSAGE_TEXCOORD,  1 }, // This is the per-instance index which is per-vertexD3DDECL_END()};HR(g_d3dDevice->CreateVertexDeclaration(VertexMeshInstanceElements, &VertexMeshInstance::Decl));;  There's SV_InstanceID in DX10. See http://msdn.microsoft.com/en-us/library/bb509647%28VS.85%29.aspxFor DX9 I think you could just fill a second vertex stream with instance IDs, and use that.   ;  There is a very close parallel between version of opengl (and extensions) and directx versions.  So yes, directx has similar mechanisms for all of the things you described, however they are restricted to different dx releases just as they are not available across all releases of opengl.DX9 requires vertex buffer packing of instance attributes and other tricks in order to tease instancing out of the system.DX10+ provides direct support for instancing with API functions such as DrawInstanced(), DrawIndexInstanced() and then in the shader there are system values available such as SV_InstanceId.   The repeat rate of various instance data can also be specified on a per input stream level.   