[SlimDX] strange error from Effect.FromFile (D3D9)

Started by
6 comments, last by Promit 15 years, 3 months ago
Hi, i've just started toying around with HLSL/shaders in SlimDX/Direct3D9, so please forgive me if i missed something totaly obvious. But i can't seem to even get the most basic shaders running. Thats how i try to create the effect:

fx = Effect.FromFile( GraphicsDevice, "Content\\Effects\\Test.fx", ShaderFlags.None );


this line always throws a Direct3D9Exception "E_FAIL: An undetermined error occurred (-2147467259)". GraphicsDevice is a valid Direct3D9.Device (i use it just above that line to create a VertexBuffer without any trouble), the file is there (opening and dumping to console works like expected) and the shader seems to be ok (compiles and runs in fx composer) and i tried different types/combinations of shader flags (i.e. ShaderFlag.Debug | ShaderFlags.PartialPrecision like in the water sample that comes with SlimDX). I'm using the November 2008 distribution of SlimDX, the samples work, even those that use effects like the water sample. I also tried the debug runtimes + unmanaged code debugging but that only gives the usual infos when the device is created. No extra details or actually nothing at all about that error. What am i missing here? Thanks. Edit: if that helps, here's the shader:

float4x4 ProjectionMatrix : PROJECTION;
float4x4 ViewMatrix : VIEW;
float4x4 WorldMatrix : WORLD;

float4 LightDirection;
float4 LightAmbient;
float4 LightColor;



struct VertexIn {
	float3 Position : POSITION;
	float3 Normal : NORMAL;
};

struct VertexOut {
	float4 Position : POSITION0;
	float3 Normal : TEXCOORD0;
	float3 LightDir : TEXCOORD1;
};


void VS_Main( VertexIn input, out VertexOut output ) {
	float4x4 WorldViewProjectionMatrix = mul( WorldMatrix, mul( ViewMatrix, ProjectionMatrix ) );
	float3 LightDir = normalize( LightDirection );
	
	output.Position = mul( float4( input.Position, 1 ), WorldViewProjectionMatrix );
	output.Normal = normalize( mul( input.Normal, WorldMatrix ) );
	output.LightDir = LightDir;
}

float4 PS_Main( float3 Normal : TEXCOORD0, float3 LightDir : TEXCOORD1 ) : COLOR0 {
	return LightAmbient + LightColor * saturate( dot( LightDir, Normal ) );
}


technique Test {
	pass P0 {
		VertexShader = compile vs_2_0 VS_Main();
		PixelShader = compile ps_2_0 PS_Main();
	}
}


but as i said: it compiles, runs and works in fx composer so shouldn't be the problem.
Advertisement
Enable the debug runtimes, use unmanaged debugging, and call the overload of FromFile that takes "out compilationError" to examine any messages from the compiler.

Post the results -- particularly of any additional messages printed to the output window.
Well, first of all thanks for the quick reply!
The Effect.FromFile overload that returns an error message did the trick. I was already using the debug runtimes and unmanaged code debugging, but that didn't give any error messages.
I fell kinda dumb but in the end the problem was, that i created the shaders as text files in Visual Studio which uses UTF-8 encoding by default. Converted it to ASCII and it worked. Well, [rolleyes].
Yeah, the dumb effect compiler barfs on Unicode, which is really annoying. We should try to get an exception thrown if we can detect that the file is Unicode.

As a side note, you don't necessarily need to use the overload that returns compiler errors if you don't want to. The exception that gets thrown on failure contains the compiler errors inside its Data property, so you can look at that in the debugger.
Mike Popoloski | Journal | SlimDX
Quote:Original post by Mike.Popoloski
We should try to get an exception thrown if we can detect that the file is Unicode.
You don't really want to go there. There's a Win32 API function that attempts to detect encoding, but it's not completely reliable.
SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.
Quote:
The exception that gets thrown on failure contains the compiler errors inside its Data property, so you can look at that in the debugger.

The Data property is the spawn of Satan and I, for one, will not condone its use!
While i also don't think that those methods should check the encoding of it's input, it would imho help a lot if the exception thrown when effect compiler fails to compile it's input would be a little bit more descriptive.
I'll admit it's unfortunate that D3DX returns E_FAIL in the first place, rather than using a D3D specific error code. Still, we usually try to avoid making too many changes to how DX looks to a C# user compared to a C++ one. I'll talk with the guys and see what they think.
SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.

This topic is closed to new replies.

Advertisement