Feature Level 9_3 compile issue

All replies

  • The "[branch]" and "[flatten]" attributes require Shader Model 3.0 or greater. "ps_2_x" provides a level of dynamic flow control based on predication and can perform looping based on runtime variables, but it's not the same level of expressiveness as you can find in Shader Model 3.0, 4.x, 5.x etc.

    Details on the Shader Model 2.x flow control are covered here.


    Wednesday, June 12, 2013 5:39 PM
  • Thanks Chuck.  But since "if_comp - ps" is listed as available for ps_2_x, doesn't that mean that regular if statements should be available in assembly, and therefore [branch] and [flatten] in HLSL (same as they are in vs_4_0_level_9_3)?
    Wednesday, June 12, 2013 6:07 PM
  • Actually, I think "[branch]" is valid in ps_2_x, but you can get that error when you exhaust the dynamic flow control depth. I guess the general comment is: simplify your pixel shader.
    Wednesday, June 12, 2013 6:10 PM
  • Well the shader is relatively simple, at least regarding if statements, and the output assembly from the compiler shows that no actual branching is taking place at all, which is why I was trying to add a [branch] attribute to just one outer if statement.
    Wednesday, June 12, 2013 6:16 PM
  • To recap, branching is supposed be valid for and work in ps_2_x.  However, if you take this simple code:

    float4 main (float4 inColor : TEXCOORD0) : SV_Target0
        float4 outColor = inColor;
        [branch] if (inColor.r >= 0.5f)
            outColor.b = 1.0f;
        return outColor;

    and compile it for ps_4_0_level_9_3, you get "error X3528: can't use flow control on this profile".

    Similarly, if you don't force a branch, but add enough arbitrary math instructions to get the compiler to use a branch when compiling for ps_3_0 or ps_4_0 like so:

    float4 main (float4 inColor : TEXCOORD0, float data : TEXCOORD1) : SV_Target0
        float4 outColor = inColor;
        if (inColor.r >= 0.5f)
            float t = fmod (inColor.r, 16.0f);
            float tfrac = frac (t);
            float tdec = t - tfrac;
            t = data / exp2 (tdec);
            t = (t - floor (t * 0.25f) * 4.0f);
            float upper = (t >= 2.0f) ? 1.0f : 0.0f; 
            t -= upper * 2.0f;
            float lower =  (t >= 1.0f) ? 1.0f : 0.0f; 
            t = lerp (lower, upper, tfrac);
            t *= 1.0f - sqrt (1.0f - t);
            t *= inColor.g * sqrt (1.0f / inColor.b);
            t = clamp (t, 0.1f, 0.9f);
            t = smoothstep (cos (inColor.g), sin (inColor.b), t);
            t *= tan (t) * sin (abs (t));
            t = floor (t * 0.25f);
            outColor.b = sqrt (t * data);
        return outColor;

    then you still do not get any branching from ps_2_x (compiling it for ps_4_0_level_9_3).

    So, how do I go about getting this bug acknowledged and fixed?

    Wednesday, June 19, 2013 9:33 PM
  • OK, so the MSDN docs are a bit misleading. The HLSL complier will never use dynamic branching in PS 2.x profiles.
    Thursday, June 20, 2013 7:27 PM