[c++,dx11], compiler shader from Memory
category: code [glöplog]
Heej,
i try to compile a vertex shader on runtime. But it is not working. How to fix it??
Thanks for helping :-)
i try to compile a vertex shader on runtime. But it is not working. How to fix it??
Code:
char *VERTEXSHADER = R"(
cbuffer PerApplication : register(b0)
{
matrix projectionMatrix;
}
cbuffer PerFrame : register(b1)
{
matrix viewMatrix;
}
cbuffer PerObject : register(b2)
{
matrix worldMatrix;
}
struct AppData
{
float3 position : POSITION;
float3 color : COLOR;
};
struct VertexShaderOutput
{
float4 color : COLOR;
float4 position : SV_POSITION;
};
VertexShaderOutput SimpleVertexShader(AppData IN)
{
VertexShaderOutput OUT;
matrix mvp = mul(projectionMatrix, mul(viewMatrix, worldMatrix));
OUT.position = mul(mvp, float4(IN.position, 1.0f));
OUT.color = float4(IN.color, 1.0f);
return OUT;
}
)";
// Load the compiled vertex shader.
ID3DBlob* vertexShaderBlob=NULL;
ID3DBlob* vertexShaderBlobError=NULL;
hr= D3DCompile(
&VERTEXSHADER, //in LPCVOID pSrcData,
sizeof(VERTEXSHADER), //in SIZE_T SrcDataSize,
NULL, //in_opt LPCSTR pSourceName,
NULL, //in_opt const D3D_SHADER_MACRO pDefines,
NULL, //in_opt ID3DInclude pInclude,
"SimpleVertexShader", //in LPCSTR pEntrypoint,
"vs_5_0", //in LPCSTR pTarget,
D3DCOMPILE_OPTIMIZATION_LEVEL3 ,//in UINT Flags1,
NULL, //in UINT Flags2,
&vertexShaderBlob, //out ID3DBlob ppCode,
&vertexShaderBlobError //out_opt ID3DBlob ppErrorMsgs
);
if (FAILED(hr)) return false;
Thanks for helping :-)
Very cursory look but if VERTEXSHADER is char*, shouldnt you pass that instead of &VERTEXSHADER as a first parameter?
I tryed everything , VERTEXSHADER or &VERTEXSHADER , no difference
Are there messages in vertexShaderBlobError?
Yes,
- __vfptr D3DCompiler_47.dll!0x5a4d0a94 (Symbole für zusätzliche Informationen laden) {D3DCompiler_47.dll!0x5a74d811, ...} void * *
- __vfptr D3DCompiler_47.dll!0x5a4d0a94 (Symbole für zusätzliche Informationen laden) {D3DCompiler_47.dll!0x5a74d811, ...} void * *
- 0x006b5c38 <Keine Informationen verfügbar. Für D3DCompiler_47.dll wurden keine Symbole geladen> ID3D10Blob *
- __vfptr D3DCompiler_47.dll!0x5a4d0a94 (Symbole für zusätzliche Informationen laden) {D3DCompiler_47.dll!0x5a74d811, ...} void * *
- __vfptr D3DCompiler_47.dll!0x5a4d0a94 (Symbole für zusätzliche Informationen laden) {D3DCompiler_47.dll!0x5a74d811, ...} void * *
- 0x006b5c38 <Keine Informationen verfügbar. Für D3DCompiler_47.dll wurden keine Symbole geladen> ID3D10Blob *
I have no clue about D3D but I assume D3DCompile expects the length of the source and not sizeof(char*).
YES, thats it.. :-) Now it is compiling without Errors... :-)