Jump to content

  • Log In with Google      Sign In   
  • Create Account

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


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
5 replies to this topic

#1 Joakim1234   Members   -  Reputation: 111

Like
0Likes
Like

Posted 27 July 2012 - 01:24 PM

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)

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))

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.

Edited by Joakim1234, 27 July 2012 - 07:21 PM.


Sponsor:

#2 L. Spiro   Crossbones+   -  Reputation: 14258

Like
0Likes
Like

Posted 27 July 2012 - 01:31 PM

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
It is amazing how often people try to be unique, and yet they are always trying to make others be like them. - L. Spiro 2011
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
I went to my local Subway once to find some guy yelling at the staff. When someone finally came to take my order and asked, “May I help you?”, I replied, “Yeah, I’ll have one asshole to go.”
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums

#3 Joakim1234   Members   -  Reputation: 111

Like
0Likes
Like

Posted 27 July 2012 - 01:46 PM

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++?

#4 SamiHuutoniemi   Members   -  Reputation: 259

Like
0Likes
Like

Posted 27 July 2012 - 02:18 PM

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!

Edited by SamiHuutoniemi, 27 July 2012 - 02:26 PM.


#5 MJP   Moderators   -  Reputation: 11753

Like
0Likes
Like

Posted 27 July 2012 - 03:08 PM

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

#6 mgoss   Members   -  Reputation: 225

Like
0Likes
Like

Posted 27 July 2012 - 03:39 PM

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


:D must upgrade.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS