# How can I compile SM 3.0 effects in D3D11 in SlimDX?

var bytecode = ShaderBytecode.CompileFromFile("shaders\\testShader.fx", "fx_5_0", ShaderFlags.None, SlimDX.D3DCompiler.EffectFlags.None, null, null, out str);
var effect = new SlimDX.Direct3D11.Effect(gpu.Device, bytecode);


This works fine but if I try to use another shader model like 4.0 or 3.0 it throws an error on the new effect creation:

E_FAIL: An undetermined error occurred (-2147467259)


How do I compile older shaders? And I've read about device context but I can't find any information on how to use them to maintain DX9 compatibility.

• So you're saying "fx_4_0" or "fx_3_0" doesn't work? Does it work if in the effect file you specify vs_3_0 / ps_3_0 in the compile-expressions in the techniques? – Nathan Reed Jun 28 '13 at 0:11
• Please expand. The error is from SlimDX.Direct3D11.Effect? What is the error output of CompileFromFile (the last arg there, I think). What profiles does your fx file use? What exact shader profile string are you putting in place of "fx_5_0" ? – Sean Middleditch Jun 28 '13 at 0:11
• @SeanMiddleditch there is no error output, str is just "", the new Effect instance causes the error. I've tried using fx_4_0 and fx_3_0. NathanReed yeah I made sure to change the vertex and pixel declarations. – Levi H Jun 28 '13 at 0:16

"fx_5_0" refers to the effect file version, not the shader profile. Basically it's just telling the HLSL / effect compiler which version of syntax to allow.

You actually control which shader profiles are used when you use the CompileShader function inside your techniques in the effect, like so:

technique11 RenderSceneWithTexture1Light
{
pass P0
{