1
\$\begingroup\$
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.

\$\endgroup\$
3
  • \$\begingroup\$ 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? \$\endgroup\$ Commented Jun 28, 2013 at 0:11
  • \$\begingroup\$ 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" ? \$\endgroup\$ Commented Jun 28, 2013 at 0:11
  • \$\begingroup\$ @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. \$\endgroup\$
    – Levi H
    Commented Jun 28, 2013 at 0:16

1 Answer 1

3
\$\begingroup\$

"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
    {
        SetVertexShader( CompileShader( vs_4_0_level_9_3, RenderSceneVS( 1, true, true ) ) );
        SetGeometryShader( NULL );
        SetPixelShader( CompileShader( ps_4_0_level_9_3, RenderScenePS( true ) ) );
    }
}

That extra "_level_9_3" at the end specifies that you're making use of the 10level9 functionality. You can see what each feature level supports here.

Unfortunately, there is no feature level that corresponds to SM 3.0 hardware. Your options are to stick with SM 2.x support in feature level 9_3 or to jump up to full D3D10-era SM 4.0.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .