Possible causes for ''D3DX11CompileFromFile'' to return E_FAIL?[RESOLVED]

Started by
4 comments, last by mgoss 11 years, 8 months ago
When I call
D3DX11CompileFromFile(pixelShaderPath, NULL, NULL, "SpritePixelShader", "vs_5_0", D3D10_SHADER_ENABLE_STRICTNESS, 0, NULL, &pixelShaderBuffer, NULL, NULL);
I get the error message:

Unexpected error encountered
Error Code: E_FAIL(0x80004005)
Calling: D3DX11CompileFromFile(pixelShaderPath, NULL, NULL, "SpritePixelShader", "vs_5_0", D3D10_SHADER_ENABLE_STRICTNESS, 0, NULL, &pixelShaderBuffer, NULL, NULL)
[/quote]
The D3DX11CompileFromFile(vertexShaderPath, NULL, NULL, "SpriteVertexShader", "vs_5_0", D3D10_SHADER_ENABLE_STRICTNESS, 0, NULL, &vertexShaderBuffer, NULL, NULL) function doesn't cause an error,but on the next 2 lines where I call CreateVertexShader and CreatePixelShader, CreateVertexShader does cause an error:

Unexpected error encountered
Error Code: E_INVALIDARG(0x80070057)
Calling: CreateVertexShader(vertexShaderBuffer->GetBufferPointer(), vertexShaderBuffer->GetBufferSize(), NULL, &vertexShader))
[/quote]
Which brings me to believe,that D3DX11CompileFromFile(vertexShaderPath, NULL, NULL, "SpriteVertexShader", "vs_5_0", D3D10_SHADER_ENABLE_STRICTNESS, 0, NULL, &vertexShaderBuffer, NULL, NULL) also didn't work out very well.All the pointers are initialized properly before calling these functions,so that can't be it:
vertexShader = 0;
pixelShader = 0;
vertexShaderBuffer = 0;
pixelShaderBuffer = 0;

And it can't be from not finding the SpriteEffect.vs and SpriteEffect.ps files,they're right next to the source files,I also copied them in the debug folder to be next to the .exe just in case.Could the problem be invalid code in the shader files themselves?They're just a simple instanced geometry/bump map effect:
cbuffer MatrixBuffer
{
matrix worldMatrix;
matrix viewMatrix;
matrix projectionMatrix;
};
struct VertexInputType
{
float4 position : POSITION;
float2 tex : TEXCOORD0;
float3 normal : NORMAL;
float3 tangent : TANGENT;
float3 binormal : BINORMAL;
float3 instancePosition : TEXCOORD1;
};
struct PixelInputType
{
float4 position : SV_POSITION;
float2 tex : TEXCOORD0;
float3 normal : NORMAL;
float3 tangent : TANGENT;
float3 binormal : BINORMAL;
};
PixelInputType SpriteVertexShader(VertexInputType input)
{
PixelInputType output;

input.position.w = 1.0f;
input.position.x += input.instancePosition.x;
input.position.y += input.instancePosition.y;
input.position.z += input.instancePosition.z;
output.position = mul(input.position, worldMatrix);
output.position = mul(output.position, viewMatrix);
output.position = mul(output.position, projectionMatrix);

output.tex = input.tex;
output.normal = mul(input.normal, (float3x3)worldMatrix);
output.normal = normalize(output.normal);
output.tangent = mul(input.tangent, (float3x3)worldMatrix);
output.tangent = normalize(output.tangent);
output.binormal = mul(input.binormal, (float3x3)worldMatrix);
output.binormal = normalize(output.binormal);

return output;
}


Texture2D shaderTexture;


SamplerState SampleType;
struct PixelInputType
{
float4 position : SV_POSITION;
float2 tex : TEXCOORD0;
float3 normal : NORMAL;
float3 tangent : TANGENT;
float3 binormal : BINORMAL;
};
float4 SpritePixelShader(PixelInputType input) : SV_TARGET
{
float4 textureColor;
float4 bumpMap;
float3 bumpNormal;
float3 lightDir;
float lightIntensity;
float4 color;
textureColor = shaderTextures[0].Sample(SampleType, input.tex);

bumpMap = shaderTextures[1].Sample(SampleType, input.tex);
bumpMap = (bumpMap * 2.0f) - 1.0f;

bumpNormal = input.normal + bumpMap.x * input.tangent + bumpMap.y * input.binormal;

bumpNormal = normalize(bumpNormal);
lightDir = -lightDirection;
lightIntensity = saturate(dot(bumpNormal, lightDir));
color = saturate(diffuseColor * lightIntensity);
color = color * textureColor;

return color;
}
I don't have syntax highlighting for HLSL,so it's possible that I missed something stupid.Any help would be appreciated.
Advertisement
The second-to-last parameter, to which you have passed NULL, is called “ppErrorMsgs”.
It is not a coincidence that it also happens to be able to give you the actual error messages generated during compile time.

You should use it.


L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid


The second-to-last parameter, to which you have passed NULL, is called “ppErrorMsgs”.
It is not a coincidence that it also happens to be able to give you the actual error messages generated during compile time.

You should use it.


L. Spiro

The second-to-last parameter, to which you have passed NULL, is called “ppErrorMsgs”.
It is not a coincidence that it also happens to be able to give you the actual error messages generated during compile time.

You should use it.


L. Spiro


Ah,thank you,it seems there were a lot of missing variables from the SpriteEffect.ps file.Is there a program in existence that checks and highlights HLSL code like Visual Studio with Intellisense highlights C++?
NShader does exactly what you are looking for.

Also you can compile your shader in visual studio instead of at runtime, and you'll get error messages in the output window, just like you compile your c++-files. Here is a short guide on how to set that up. Makes debugging HLSL so much easier!
Also, the newest version of Visual Studio includes HLSL syntax highlighting by default.

Also, the newest version of Visual Studio includes HLSL syntax highlighting by default.


:D must upgrade.

This topic is closed to new replies.

Advertisement