Hi, I'm trying to create my input layout with shader reflection, but there's something weird happening because in the thaditional form this is my output:
Here's the code:
D3D11_INPUT_ELEMENT_DESC layout[] =
{
{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
{ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 }
};
UINT numElements = ARRAYSIZE(layout);
hr = m_ptrd3dDevice->CreateInputLayout(layout, numElements, m_ptrVSBlob->GetBufferPointer(),
m_ptrVSBlob->GetBufferSize(), &m_ptrInputLayout);
m_ptrVSBlob->Release();
if (FAILED(hr))
return hr;
And when I create the input layout with shader reflection, this is my output:
Here's the code:
// Reflect shader info
ID3D11ShaderReflection* pVertexShaderReflection = nullptr;
if (FAILED(D3DReflect(m_ptrVSBlob->GetBufferPointer(),
m_ptrVSBlob->GetBufferSize(), IID_ID3D11ShaderReflection,
(void**)&pVertexShaderReflection)))
{
return S_FALSE;
}
// Get shader info
D3D11_SHADER_DESC shaderDesc;
pVertexShaderReflection->GetDesc(&shaderDesc);
// Read input layout description from shader info
std::vector<D3D11_INPUT_ELEMENT_DESC> inputLayoutDesc;
for (UINT i = 0; i < shaderDesc.InputParameters; i++)
{
D3D11_SIGNATURE_PARAMETER_DESC paramDesc;
pVertexShaderReflection->GetInputParameterDesc(i, ¶mDesc);
// Fill out input element desc
D3D11_INPUT_ELEMENT_DESC elementDesc;
elementDesc.SemanticName = paramDesc.SemanticName;
elementDesc.SemanticIndex = paramDesc.SemanticIndex;
elementDesc.InputSlot = 0;
elementDesc.AlignedByteOffset = D3D11_APPEND_ALIGNED_ELEMENT;
elementDesc.InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
elementDesc.InstanceDataStepRate = 0;
// determine DXGI format
if (paramDesc.Mask == 1)
{
if (paramDesc.ComponentType == D3D_REGISTER_COMPONENT_UINT32)
elementDesc.Format = DXGI_FORMAT_R32_UINT;
else if (paramDesc.ComponentType == D3D_REGISTER_COMPONENT_SINT32)
elementDesc.Format = DXGI_FORMAT_R32_SINT;
else if (paramDesc.ComponentType == D3D_REGISTER_COMPONENT_FLOAT32)
elementDesc.Format = DXGI_FORMAT_R32_FLOAT;
}
else if (paramDesc.Mask <= 3)
{
if (paramDesc.ComponentType == D3D_REGISTER_COMPONENT_UINT32)
elementDesc.Format = DXGI_FORMAT_R32G32_UINT;
else if (paramDesc.ComponentType == D3D_REGISTER_COMPONENT_SINT32)
elementDesc.Format = DXGI_FORMAT_R32G32_SINT;
else if (paramDesc.ComponentType == D3D_REGISTER_COMPONENT_FLOAT32)
elementDesc.Format = DXGI_FORMAT_R32G32_FLOAT;
}
else if (paramDesc.Mask <= 7)
{
if (paramDesc.ComponentType == D3D_REGISTER_COMPONENT_UINT32)
elementDesc.Format = DXGI_FORMAT_R32G32B32_UINT;
else if (paramDesc.ComponentType == D3D_REGISTER_COMPONENT_SINT32)
elementDesc.Format = DXGI_FORMAT_R32G32B32_SINT;
else if (paramDesc.ComponentType == D3D_REGISTER_COMPONENT_FLOAT32)
elementDesc.Format = DXGI_FORMAT_R32G32B32_FLOAT;
}
else if (paramDesc.Mask <= 15)
{
if (paramDesc.ComponentType == D3D_REGISTER_COMPONENT_UINT32)
elementDesc.Format = DXGI_FORMAT_R32G32B32A32_UINT;
else if (paramDesc.ComponentType == D3D_REGISTER_COMPONENT_SINT32)
elementDesc.Format = DXGI_FORMAT_R32G32B32A32_SINT;
else if (paramDesc.ComponentType == D3D_REGISTER_COMPONENT_FLOAT32)
elementDesc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
}
// Save element desc
inputLayoutDesc.push_back(elementDesc);
}
// Try to create Input Layout
hr = m_ptrd3dDevice->CreateInputLayout(&inputLayoutDesc[0],
inputLayoutDesc.size(), m_ptrVSBlob->GetBufferPointer(),
m_ptrVSBlob->GetBufferSize(), &m_ptrInputLayout);
//Free allocation shader reflection memory
pVertexShaderReflection->Release();
pVertexShaderReflection = nullptr;
if (FAILED(hr))
return hr;