My shader creation code looks like this.
std::shared_ptr<IRenderUtility::IVertexShader> D3D11RenderUtility::CreateVertexShader(IShader::INIT_DESC & desc) const
{
HRESULT result;
ID3D10Blob * errorMessage;
ID3D10Blob * vertexShaderBuffer;
ID3D11VertexShader * vertShader;
D3D11VertexShader::INIT_DESC vertShaderDesc;
char errorMsg[255];
result = D3DX11CompileFromFileA(desc.fileName.c_str(), NULL, NULL, desc.entryPoint.c_str(), "vs_5_0", D3D10_SHADER_ENABLE_STRICTNESS, 0, NULL, &vertexShaderBuffer, &errorMessage, NULL);
if(FAILED(result))
{
if(errorMessage)
{
OutputErrorBlob(errorMessage, desc.fileName.c_str());
}
sprintf_s(errorMsg, "D3D11_Renderer | D3D11RenderUtility::CreateVertexShader \n\tfailed to compile shader file %s %i", desc.fileName, __LINE__);
throw std::exception(errorMsg);
}
result = m_Device->CreateVertexShader(vertexShaderBuffer->GetBufferPointer(), vertexShaderBuffer->GetBufferSize(), NULL, &vertShader);
if(FAILED(result))
{
sprintf_s(errorMsg, "D3D11_Renderer | D3D11RenderUtility::CreateVertexShader \n\tfailed to create the vertex shader %i", __LINE__);
throw std::exception(errorMsg);
}
vertexShaderBuffer->Release();
vertexShaderBuffer = 0;
vertShaderDesc.shader = vertShader;
return std::shared_ptr<IVertexShader>(new D3D11VertexShader(vertShaderDesc));
}
IRenderUtility, D3D11RenderUtility, IVertexShader, D3D11VertexShader, and IShader are my stuff. My question only pertains to the Shader creation code. At a later point, after the shader is made, i would like to create an input layout, but without the blob to get a pointer to the compiled shader, i cannot. Is there any way to obtain a pointer to the compiled shader from ID3D11VertexShader after it is created, or should i keep the blob around, storing it in my VertexShader object? How big is it?
GetBufferSize(). I wouldn't expect the shader bytecode to be more than a few KB - maybe into the tens of KB for a big, complex shader - so keeping the bytecode around shouldn't be an issue. \$\endgroup\$