Skip to content
  • Brian Paul's avatar
    gallium: add SQRT shader opcode · d276a40e
    Brian Paul authored
    The glsl-to-tgsi translater will emit SQRT to implement GLSL's sqrt()
    and distance() functions if the PIPE_SHADER_CAP_TGSI_SQRT_SUPPORTED
    query says it's supported by the driver.
    
    Otherwise, sqrt(x) is implemented with x*rsq(x).  The problem with
    this is sqrt(0) must be handled specially because rsq(0) might be
    Inf/NaN/undefined (and then 0*rsq(0) is Inf/Nan/undefined).  In the
    glsl-to-tgsi code we use an extra CMP to check if x is zero and then
    replace the result of x*rsq(x) with zero.
    
    In the end, this makes sqrt() generate much more reasonable code for
    drivers that can do square roots.
    
    Note that many of piglit's generated shader tests use the GLSL
    distance() function.
    d276a40e