glsl/builtin: Add alternate versions of atan using new ops
authorNeil Roberts <nroberts@igalia.com>
Fri, 11 Oct 2019 16:06:34 +0000 (18:06 +0200)
committerNeil Roberts <nroberts@igalia.com>
Sat, 12 Oct 2019 07:43:18 +0000 (09:43 +0200)
Adds alternate versions of the atan builtin functions that use
ir_unop_atan and ir_binop_atan2 instead of inlining to the IR
implementation of the function. These alternatives are selected if the
IR is going to be consumed by NIR. In that case the IR ops will be
translated to the appropriate NIR op.

Reviewed-by: Kristian H. Kristensen <hoegsberg@google.com>
src/compiler/glsl/builtin_functions.cpp

index 67ed936478ff14d48ccd04a789d9e7e6a07c0ee1..d7473ee4922560ea47aa425f1580dae14c255178 100644 (file)
@@ -826,6 +826,18 @@ demote_to_helper_invocation(const _mesa_glsl_parse_state *state)
    return state->EXT_demote_to_helper_invocation_enable;
 }
 
+static bool
+is_nir(const _mesa_glsl_parse_state *state)
+{
+   return state->ctx->Const.ShaderCompilerOptions[state->stage].NirOptions;
+}
+
+static bool
+is_not_nir(const _mesa_glsl_parse_state *state)
+{
+   return !is_nir(state);
+}
+
 /** @} */
 
 /******************************************************************************/
@@ -956,6 +968,8 @@ private:
    B1(acos)
    B1(atan2)
    B1(atan)
+   B1(atan2_op)
+   B1(atan_op)
    B1(sinh)
    B1(cosh)
    B1(tanh)
@@ -1729,6 +1743,14 @@ builtin_builder::create_builtins()
                 _atan2(glsl_type::vec2_type),
                 _atan2(glsl_type::vec3_type),
                 _atan2(glsl_type::vec4_type),
+                _atan_op(glsl_type::float_type),
+                _atan_op(glsl_type::vec2_type),
+                _atan_op(glsl_type::vec3_type),
+                _atan_op(glsl_type::vec4_type),
+                _atan2_op(glsl_type::float_type),
+                _atan2_op(glsl_type::vec2_type),
+                _atan2_op(glsl_type::vec3_type),
+                _atan2_op(glsl_type::vec4_type),
                 NULL);
 
    F(sinh)
@@ -4728,7 +4750,7 @@ builtin_builder::_atan2(const glsl_type *type)
    const unsigned n = type->vector_elements;
    ir_variable *y = in_var(type, "y");
    ir_variable *x = in_var(type, "x");
-   MAKE_SIG(type, always_available, 2, y, x);
+   MAKE_SIG(type, is_not_nir, 2, y, x);
 
    /* If we're on the left half-plane rotate the coordinates π/2 clock-wise
     * for the y=0 discontinuity to end up aligned with the vertical
@@ -4865,7 +4887,7 @@ ir_function_signature *
 builtin_builder::_atan(const glsl_type *type)
 {
    ir_variable *y_over_x = in_var(type, "y_over_x");
-   MAKE_SIG(type, always_available, 1, y_over_x);
+   MAKE_SIG(type, is_not_nir, 1, y_over_x);
 
    ir_variable *tmp = body.make_temp(type, "tmp");
    do_atan(body, type, tmp, y_over_x);
@@ -4968,6 +4990,7 @@ UNOP(exp,         ir_unop_exp,  always_available)
 UNOP(log,         ir_unop_log,  always_available)
 UNOP(exp2,        ir_unop_exp2, always_available)
 UNOP(log2,        ir_unop_log2, always_available)
+UNOP(atan_op,     ir_unop_atan, is_nir)
 UNOPA(sqrt,        ir_unop_sqrt)
 UNOPA(inversesqrt, ir_unop_rsq)
 
@@ -5167,6 +5190,12 @@ builtin_builder::_isinf(builtin_available_predicate avail, const glsl_type *type
    return sig;
 }
 
+ir_function_signature *
+builtin_builder::_atan2_op(const glsl_type *x_type)
+{
+   return binop(is_nir, ir_binop_atan2, x_type, x_type, x_type);
+}
+
 ir_function_signature *
 builtin_builder::_floatBitsToInt(const glsl_type *type)
 {