| 155 | } |
| 156 | |
| 157 | ALResult Tr2VertexLayoutAL::SetLayout( const TrinityALImpl::Tr2ShaderAL* vertexShader, Tr2RenderContextAL& renderContext ) const |
| 158 | { |
| 159 | if( !renderContext.m_secondaryDevice11 || !vertexShader || m_definition.empty() ) |
| 160 | { |
| 161 | return E_FAIL; |
| 162 | } |
| 163 | auto found = m_layout.find( vertexShader->m_pipelineInputHash ); |
| 164 | if( found != m_layout.end() ) |
| 165 | { |
| 166 | renderContext.m_context->IASetInputLayout( found->second ); |
| 167 | return S_OK; |
| 168 | } |
| 169 | |
| 170 | Tr2ShaderBytecodeAL bytecode; |
| 171 | CR_RETURN_HR( vertexShader->GetBytecode( bytecode ) ); |
| 172 | |
| 173 | const auto& definition = vertexShader->m_signature; |
| 174 | auto patchedDefinition = m_definition; |
| 175 | for( auto it = definition.pipelineInputs.begin(); it != definition.pipelineInputs.end(); ++it ) |
| 176 | { |
| 177 | if( !FindInputElement( m_definition, *it ) ) |
| 178 | { |
| 179 | D3D11_INPUT_ELEMENT_DESC fakeElement; |
| 180 | fakeElement.AlignedByteOffset = 0; |
| 181 | switch( it->type ) |
| 182 | { |
| 183 | case Tr2ShaderPipelineInputAL::INT: |
| 184 | fakeElement.Format = DXGI_FORMAT_R8G8B8A8_SINT; |
| 185 | break; |
| 186 | case Tr2ShaderPipelineInputAL::UINT: |
| 187 | fakeElement.Format = DXGI_FORMAT_R8G8B8A8_UINT; |
| 188 | break; |
| 189 | default: |
| 190 | fakeElement.Format = DXGI_FORMAT_R32G32B32A32_FLOAT; |
| 191 | } |
| 192 | fakeElement.InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA; |
| 193 | fakeElement.InstanceDataStepRate = 0; |
| 194 | fakeElement.SemanticIndex = it->usageIndex; |
| 195 | fakeElement.SemanticName = semanticNames[it->usage]; |
| 196 | if( it->usedMask == 0 ) |
| 197 | { |
| 198 | fakeElement.InputSlot = 4; |
| 199 | } |
| 200 | else |
| 201 | { |
| 202 | fakeElement.InputSlot = 4; |
| 203 | } |
| 204 | patchedDefinition.push_back( fakeElement ); |
| 205 | } |
| 206 | } |
| 207 | |
| 208 | CComPtr<ID3D11InputLayout> layout; |
| 209 | long result = renderContext.m_secondaryDevice11->CreateInputLayout( |
| 210 | patchedDefinition.data(), |
| 211 | (uint32_t)patchedDefinition.size(), |
| 212 | bytecode.bytecode, |
| 213 | bytecode.size, |
| 214 | &layout ); |
no test coverage detected