Hello,
VS output problem
I finally found my error !
By default, when initializing a D3D12_INPUT_ELEMENT_DESC structue with SharpDX, it set the input classification as D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA.
In my native renderer, I was initializing my input element with D3D12_INPUT_CLASSIFICATION_PER_INSTANCE_DATA. So, my vertices ID were entering the VS in a wrong order...
I don't know what is exactly input classification but it was my issue
The "per-instance" classification comes into play when you're drawing multiple instances of something, and you want per-instance data to come from a vertex buffer. The classic setup is two vertex buffers: the first one has all of your "normal" mesh vertex data, with PER_VERTEX_DATA classification for all attributes. Then the other one contains a per-instance unique transform with PER_INSTANCE_DATA. Conceptually you can think of it working like there's an invisible prologue to your vertex shader that pulls the data from your buffers using either the vertex index (PER_VERTEX_DATA) or the instance index (PER_INSTANCE_DATA):
// This is a normal, simple vertex shader
struct VSInput
{
float3 VtxPosition : VTXPOS; // PER_VERTEX_DATA
float3 InstancePosition : INSTPOS; // PER_INSTANCE_DATA
};
float4 VSMain(in VSInput input) : SV_Position
{
float3 vtxPos = input.VtxPosition;
vtxPos += input.InstancePosition;
return mul(float4(vtxPos, 1.0f), ViewProjectionMatrix);
}
// ======================================================================================================
// Imagine that this hidden VS "prologue" runs first for every instance of the vertex shader:
Buffer<float3> VtxPositionBuffer;
Buffer<float3> InstancePosBuffer;
float4 VSPrologue(in uint vertexIndex : SV_VertexID,
in uint instanceIndex : SV_InstanceID) : SV_Position
{
VSInput vsInput;
// PER_VERTEX_DATA means index into the buffer using the vertex index, typically from an index buffer
vsInput.VtxPosition = VtxPositionBuffer[vertexIndex];
// PER_INSTANCE_DATA means index into the buffer using instance index
vsInput.InstancePosition = InstancePosBuffer[instanceIndex];
return VSMain(vsInput);
}