HRESULT FMaterial::CreateInputLayoutDescFromVertexShaderSignature(ID3D11ShaderReflection* VertexShaderReflection, ID3DBlob* VertexShaderBlob, ID3D11Device* Device) { // Get shader info D3D11_SHADER_DESC ShaderDescription; VertexShaderReflection->GetDesc(&ShaderDescription); // Read input layout description from shader info TVector<D3D11_INPUT_ELEMENT_DESC> InputLayoutDesc; for (size_t i = 0; i < ShaderDescription.InputParameters; i++) { D3D11_SIGNATURE_PARAMETER_DESC ParamDescription; VertexShaderReflection->GetInputParameterDesc(i, &ParamDescription); // fill out input element desc D3D11_INPUT_ELEMENT_DESC ElementDesc; ElementDesc.SemanticName = ParamDescription.SemanticName; ElementDesc.SemanticIndex = ParamDescription.SemanticIndex; ElementDesc.InputSlot = 0; ElementDesc.AlignedByteOffset = D3D11_APPEND_ALIGNED_ELEMENT; ElementDesc.InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA; ElementDesc.InstanceDataStepRate = 0; // determine DXGI format if (ParamDescription.Mask == 1) { if (ParamDescription.ComponentType == D3D_REGISTER_COMPONENT_UINT32) ElementDesc.Format = DXGI_FORMAT_R32_UINT; else if (ParamDescription.ComponentType == D3D_REGISTER_COMPONENT_SINT32) ElementDesc.Format = DXGI_FORMAT_R32_SINT; else if (ParamDescription.ComponentType == D3D_REGISTER_COMPONENT_FLOAT32) ElementDesc.Format = DXGI_FORMAT_R32_FLOAT; } else if (ParamDescription.Mask <= 3) { if (ParamDescription.ComponentType == D3D_REGISTER_COMPONENT_UINT32) ElementDesc.Format = DXGI_FORMAT_R32G32_UINT; else if (ParamDescription.ComponentType == D3D_REGISTER_COMPONENT_SINT32) ElementDesc.Format = DXGI_FORMAT_R32G32_SINT; else if (ParamDescription.ComponentType == D3D_REGISTER_COMPONENT_FLOAT32) ElementDesc.Format = DXGI_FORMAT_R32G32_FLOAT; } else if (ParamDescription.Mask <= 7) { if (ParamDescription.ComponentType == D3D_REGISTER_COMPONENT_UINT32) ElementDesc.Format = DXGI_FORMAT_R32G32B32_UINT; else if (ParamDescription.ComponentType == D3D_REGISTER_COMPONENT_SINT32) ElementDesc.Format = DXGI_FORMAT_R32G32B32_SINT; else if (ParamDescription.ComponentType == D3D_REGISTER_COMPONENT_FLOAT32) ElementDesc.Format = DXGI_FORMAT_R32G32B32_FLOAT; } else if (ParamDescription.Mask <= 15) { if (ParamDescription.ComponentType == D3D_REGISTER_COMPONENT_UINT32) ElementDesc.Format = DXGI_FORMAT_R32G32B32A32_UINT; else if (ParamDescription.ComponentType == D3D_REGISTER_COMPONENT_SINT32) ElementDesc.Format = DXGI_FORMAT_R32G32B32A32_SINT; else if (ParamDescription.ComponentType == D3D_REGISTER_COMPONENT_FLOAT32) ElementDesc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT; } if (strcmp(ParamDescription.SemanticName, "COLOR") == 0) { // Special case: colour is actually a r8b8g8a8_unorm. ElementDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; } //save element desc InputLayoutDesc.Add(ElementDesc); } // Special case here: // If we're using SV_VertexID only then we don't actually need an input layout. if (InputLayoutDesc.Size() == 1 && strcmp(InputLayoutDesc[0].SemanticName, "SV_VertexID") != -1) { return S_OK; } // Try to create Input Layout HRESULT hr = Device->CreateInputLayout(&InputLayoutDesc[0], InputLayoutDesc.Size(), VertexShaderBlob->GetBufferPointer(), VertexShaderBlob->GetBufferSize(), &InputLayout); return hr; }