Static constants and the HLSL compiler

Discussion in 'Programming/Html' started by Guy.J., May 11, 2014.

  1. Guy.J.

    Guy.J. Guest

    Messages:
    70
    Likes Received:
    0
    GPU:
    GTX 560
    I'd like to know whether the HLSL compiler is smart enough sort out conditions that depend on constants. Specifically, I want to know what it will do in these two made-up examples.

    1)
    Code:
    const static int myconstant = 3;
    float myvar = (myconstant == 3 || checksomething()) ? getsomething() : getsomethingelse();
    
    2)
    Code:
    const static int myconstant = 3;
    if (myconstant == 3 || checksomething())
    {
    float myvar = getsomething();
    }
    else
    {
    float myvar = getsomethingelse();
    }
    
    In both cases I'd want the compiler to end up with simply
    Code:
    float myvar = getsomething();
    Will it?
     

Share This Page