Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#include <Windows.h>
#include <d3d11.h>
#include <D3DCompiler.h>
bool GetCompiledShaderCode(ID3DBlob **pBlob, const char *pszShaderStr, const char *pszShaderTarget)
{
ID3DBlob *pErrorMsgs = NULL;
if (!SUCCEEDED(D3DCompile(
pszShaderStr,
strlen(pszShaderStr),
NULL,
NULL,
NULL,
"your_entry_point_function_here",
pszShaderTarget,
D3DCOMPILE_DEBUG | D3DCOMPILE_SKIP_OPTIMIZATION,
0,
pBlob,
&pErrorMsgs)))
{
CHAR *pErrorBuffer = new CHAR[pErrorMsgs->GetBufferSize() + 1];
memcpy(pErrorBuffer, pErrorMsgs->GetBufferPointer(), pErrorMsgs->GetBufferSize());
pErrorBuffer[pErrorMsgs->GetBufferSize()] = '\0';
printf("\nError[target = %s]: \n\t%s", pszShaderTarget, pErrorBuffer);
delete[] pErrorBuffer;
pErrorMsgs->Release();
return false;
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment