Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Load the shader as normal. Using the shader blob that was used to create the shader,
- // We can create a ID3D11ShaderReflection object that can be used to automatically build
- // the input layout.
- // Reflect the parameters from the shader.
- // Inspired by: http://members.gamedev.net/JasonZ/Heiroglyph/D3D11ShaderReflection.pdf
- Microsoft::WRL::ComPtr<ID3D11ShaderReflection> pReflector;
- hr = D3DReflect( m_pShaderBlob->GetBufferPointer(), m_pShaderBlob->GetBufferSize(), IID_ID3D11ShaderReflection, &pReflector );
- if ( FAILED( hr ) )
- {
- ReportError( "Failed to reflect shader." );
- return false;
- }
- // Query input parameters and build the input layout
- D3D11_SHADER_DESC shaderDescription;
- hr = pReflector->GetDesc( &shaderDescription );
- if ( FAILED( hr ) )
- {
- ReportError( "Failed to get shader description from shader reflector." );
- return false;
- }
- m_InputSemantics.clear();
- UINT numInputParameters = shaderDescription.InputParameters;
- std::vector<D3D11_INPUT_ELEMENT_DESC> inputElements;
- for ( UINT i = 0; i < numInputParameters; ++i )
- {
- D3D11_INPUT_ELEMENT_DESC inputElement;
- D3D11_SIGNATURE_PARAMETER_DESC parameterSignature;
- pReflector->GetInputParameterDesc( i, ¶meterSignature );
- inputElement.SemanticName = parameterSignature.SemanticName;
- inputElement.SemanticIndex = parameterSignature.SemanticIndex;
- inputElement.InputSlot = i; // TODO: If using interleaved arrays, then the input slot should be 0. If using packed arrays, the input slot will vary.
- inputElement.AlignedByteOffset = D3D11_APPEND_ALIGNED_ELEMENT;
- inputElement.InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA; // TODO: Figure out how to deal with per-instance data? .. Don't. Just use structured buffers to store per-instance data and use the SV_InstanceID as an index in the structured buffer.
- inputElement.InstanceDataStepRate = 0;
- inputElement.Format = GetDXGIFormat( parameterSignature );
- assert( inputElement.Format != DXGI_FORMAT_UNKNOWN );
- inputElements.push_back( inputElement );
- m_InputSemantics.insert( SemanticMap::value_type( BufferBinding( inputElement.SemanticName, inputElement.SemanticIndex ), i ) );
- }
- if ( inputElements.size() > 0 )
- {
- hr = m_pDevice->CreateInputLayout( inputElements.data(), (UINT)inputElements.size(), m_pShaderBlob->GetBufferPointer(), m_pShaderBlob->GetBufferSize(), &m_pInputLayout );
- if ( FAILED( hr ) )
- {
- ReportError( "Failed to create input layout." );
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement