[SlimDX] Same shader compiles under DX10, but not DX9

Started by
7 comments, last by Meai 14 years, 1 month ago
Hi, SlimDX is really great once you understand how everything is done. Now I ran into a rather strange problem though, maybe you have seen it before and can help. The only thing I changed from the dx10 version in the shader code, was to change the profile from vs_4_0 to vs_2_0 and the same with the pixelshader. I get this error:

An unhandled exception of type 'SlimDX.CompilationException' occurred in SlimDX.dll

Additional information: ID3DXEffectCompiler: There were no techniques
ID3DXEffectCompiler: Compilation failed
This is how I load it: (I opened the "test.fx" file in notepad++ and it's described as ANSI. Just to make sure that there are no unneeded whitespaces, I trimmed the file of all spaces, blanks or anything else with TextFX. You see the final code below.

device.SetTexture(0, texture);
Effect effect = 
  Effect.FromFile(device, "test.fx", ShaderFlags.None);


float4x4 WorldViewProj : WorldViewProjection;
Texture2D text;
SamplerState linearSampler
{
	Filter = MIN_MAG_MIP_LINEAR;
	AddressU = Wrap;
	AddressV = Wrap;
};
struct VS_IN
{
	float4 pos : POSITION;
	float2 tex : TEXCOORD;
};
struct PS_IN
{
	float4 pos : SV_POSITION;
	float2 tex : TEXCOORD;
};
PS_IN VS( VS_IN input )
{
	PS_IN output = (PS_IN)0;
	
	output.pos = input.pos;
	output.tex = input.tex;				
	return output;
}
float4 PS( PS_IN input ) : SV_Target
{
	return text.Sample(linearSampler,input.tex);
}
technique10 test
{
	pass P0
	{
		SetGeometryShader( 0 );
		SetVertexShader( CompileShader(vs_2_0, VS() ) );
		SetPixelShader( CompileShader(ps_2_0, PS() ) );
	}
}


I really don't know what's causing this, I hope I didn't fall into the UTF-8 trap despite my precautions. I did not create the .fx file in Visual Studio, because of the known problems.
Advertisement
As the error sais, there are no techniques for DX9. You have to change the line
technique10 test

to
technique test


and maybe the SetGeometryShader(0) will be the next problem ^^
You Sir, are a genius :D
I was wondering why I needed that strange technique10 name in Directx10! Or maybe I don't, I'll have to try it out ..but really: thanks! These kind of errors take a lot of time. (or rather: took a lot of time)
Yeah, seems like DirectX10 just isn't as strict.

Do you happen to know how DirectX wants its vertex and UV coordinates?
My UV coordinates are plain 0/0, 0/1, 1/0, 1/1.
I just try to render a quad...I'm sure it's another tiny error again. With RHW coordinates, the same shader works just fine. I have to supply coordinates in the range of -1/1(topleft) to 1/-1(bottomright) with 0/0 in the middle of the screen right?

Right now this produces a quad with a hugely magnified texture on it.

struct Vertex{  public Vector4 Position;  public Vector2 Texture;}var vertices = new VertexBuffer(device, 4 * 24, Usage.WriteOnly,VertexFormat.Position | VertexFormat.Texture1, Pool.Managed);Effect effect = Effect.FromString(device, shaderCode, ShaderFlags.None);var effectHandle =effect.GetParameter(null, "DiffuseMap");effect.SetTexture((SlimDX.Direct3D9.EffectHandle)effectHandle,texture);device.SetStreamSource(0, vertices, 0, 24);device.VertexFormat = VertexFormat.Position | VertexFormat.Texture1;// with RHW and pixel coordinates it worked!device.BeginScene();var technique = effect.GetTechnique(0);effect.Technique = technique;effect.Begin();effect.BeginPass(0);						device.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2);effect.EndPass();effect.End();


// vertices with the uv coordinates for untransformed coordinates
                new Vertex() { Texture = new Vector2(0,0), 			Position = new Vector4(-1.0f, -1.0f, 1.0f, 0.0f) },                new Vertex() { Texture = new Vector2(0,1), 			Position = new Vector4(-1.0f, 1.0f, 1.0f, 0.0f) },                new Vertex() { Texture = new Vector2(1,0), 			Position = new Vector4(1.0f, -1.0f, 1.0f, 0.0f) },                new Vertex() { Texture = new Vector2(1,1), 			Position = new Vector4(1.0f, 1.0f, 1.0f, 0.0f) },
Use a VertexDeclaration (similar to an InputLayout in DirectX 10) when you're working with shaders, rather than VertexFormats.
Do you mean instead of vertex formats? How would I be able to create a device without a vertex format? And why is it even there, if I don't need it. I dont quite understand the difference between the VertexFormat and VertexDeclaration :(
Anyhow, I tried both: with/without vertexformat declared. (VertexFormat.None was declared in the device creation)
My texture is still hugely magnified, it didn't seem to change anything :/

Here's my vertex declaration:

SlimDX.Direct3D9.VertexElement[] elements = new[]{	new SlimDX.Direct3D9.VertexElement	(		0,		0,		DeclarationType.Float4,		DeclarationMethod.Default,		DeclarationUsage.Position,		0	),	new SlimDX.Direct3D9.VertexElement	(		0,		16,		DeclarationType.Float2,		DeclarationMethod.Default,		DeclarationUsage.TextureCoordinate,		0	),	SlimDX.Direct3D9.VertexElement.VertexDeclarationEnd,};
You don't want your vertex shader to output a w component of 0 for your position, it will screw up interpolation (since the texture coordinates will be divided by w during interpolatino). Try outputting a 1 instead.

Also the "VertexFormat" stuff is actually FVF codes, which is a leftover from the days of the fixed-function pipeline. They still work in D3D9, but vertex declarations are much more explicit and flexible.
Unfortunately a "1" for w doesnt change anything about the output. Any more ideas?

This is how my supposed flower texture looks like, whole screen:

http://img193.imageshack.us/img193/727/flowerpicture.png

its not a flower anymore :/

[Edited by - Meai on March 15, 2010 12:53:38 PM]
could someone maybe direct me to a tutorial with working code that does not use pretransformed vertices? That would be awesome, I just can't find anything. It's getting really annoying, DirectX10 works like a charm meanwhile.

edit: good thing I read this post twice:
http://www.gamedev.net/community/forums/topic.asp?topic_id=487981

Solution at the end worked: PositionW is needed in the vertex declaration.

[Edited by - Meai on March 16, 2010 5:51:32 AM]

This topic is closed to new replies.

Advertisement