Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.
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.

share|improve this question
    
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. –  jacker Jun 28 '13 at 0:16
add comment

1 Answer

up vote 3 down vote accepted

"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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.