mercredi 22 février 2017

DirectX 11 Vertex Shader Reflection

I'm trying to write some DirectX code that takes a compiled shader and uses reflection to automatically generate input layouts for vertex shaders. I have a simple vertex shader which is designed to take advantage of instancing, this is the input it accepts:

struct VertexIn
{
    // Per-vertex data
    float3 pos      : POSITION;
    float4 color    : COLOR;

    // Per-instance data
    matrix worldMatrix : WORLDMATRIX;
};

And my layout if I were to write it by hand would be:

// Per-vertex data
{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
{ "COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0 },
// Per-instance data.
{ "WORLDMATRIX", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 1, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_INSTANCE_DATA, 1 },
{ "WORLDMATRIX", 1, DXGI_FORMAT_R32G32B32A32_FLOAT, 1, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_INSTANCE_DATA, 1 },
{ "WORLDMATRIX", 2, DXGI_FORMAT_R32G32B32A32_FLOAT, 1, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_INSTANCE_DATA, 1 },
{ "WORLDMATRIX", 3, DXGI_FORMAT_R32G32B32A32_FLOAT, 1, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_INSTANCE_DATA, 1 }

When I reflect the compiled shader I get the correct number of input parameters, but when I try to read the input descriptions through D3D11_SIGNATURE_PARAMTER_DESC, I can't find the details that I need to fill the D3D11_INPUT_ELEMENT_DESC members InputSlot, InputSlotClass and InstanceDataStepRate? Am I looking in the wrong description for this information or is getting instancing details not possible through reflection?

If this isn't possible then I'm guessing the only other alternative I have is to pass the expected vertex input layout and check all parameters





Aucun commentaire:

Enregistrer un commentaire