[Mesa-dev] [PATCH 03/50] glsl: Add "built-in" function to do sign(fp64) (v2)

Roland Scheidegger sroland at vmware.com
Wed Mar 14 03:02:36 UTC 2018


Am 14.03.2018 um 02:05 schrieb Dave Airlie:
> On 14 March 2018 at 10:46, Roland Scheidegger <sroland at vmware.com> wrote:
>> Am 13.03.2018 um 05:24 schrieb Dave Airlie:
>>> From: Elie Tournier <tournier.elie at gmail.com>
>>>
>>> v2: use mix.
>>>
>>> Signed-off-by: Elie Tournier <elie.tournier at collabora.com>
>>> ---
>>>  src/compiler/glsl/builtin_float64.h     | 28 ++++++++++++++++++++++++++++
>>>  src/compiler/glsl/builtin_functions.cpp |  4 ++++
>>>  src/compiler/glsl/builtin_functions.h   |  3 +++
>>>  src/compiler/glsl/float64.glsl          |  9 +++++++++
>>>  src/compiler/glsl/glcpp/glcpp-parse.y   |  1 +
>>>  5 files changed, 45 insertions(+)
>>>
>>> diff --git a/src/compiler/glsl/builtin_float64.h b/src/compiler/glsl/builtin_float64.h
>>> index 2898fc9..8546048 100644
>>> --- a/src/compiler/glsl/builtin_float64.h
>>> +++ b/src/compiler/glsl/builtin_float64.h
>>> @@ -68,3 +68,31 @@ fneg64(void *mem_ctx, builtin_available_predicate avail)
>>>     sig->replace_parameters(&sig_parameters);
>>>     return sig;
>>>  }
>>> +ir_function_signature *
>>> +fsign64(void *mem_ctx, builtin_available_predicate avail)
>>> +{
>>> +   ir_function_signature *const sig =
>>> +      new(mem_ctx) ir_function_signature(glsl_type::uvec2_type, avail);
>>> +   ir_factory body(&sig->body, mem_ctx);
>>> +   sig->is_defined = true;
>>> +
>>> +   exec_list sig_parameters;
>>> +
>>> +   ir_variable *const r001D = new(mem_ctx) ir_variable(glsl_type::uvec2_type, "a", ir_var_function_in);
>>> +   sig_parameters.push_tail(r001D);
>>> +   ir_variable *const r001E = new(mem_ctx) ir_variable(glsl_type::uvec2_type, "retval", ir_var_auto);
>>> +   body.emit(r001E);
>>> +   body.emit(assign(r001E, body.constant(0u), 0x01));
>>> +
>>> +   ir_expression *const r001F = lshift(swizzle_y(r001D), body.constant(int(1)));
>>> +   ir_expression *const r0020 = bit_or(r001F, swizzle_x(r001D));
>>> +   ir_expression *const r0021 = equal(r0020, body.constant(0u));
>>> +   ir_expression *const r0022 = bit_and(swizzle_y(r001D), body.constant(2147483648u));
>>> +   ir_expression *const r0023 = bit_or(r0022, body.constant(1072693248u));
>>> +   body.emit(assign(r001E, expr(ir_triop_csel, r0021, body.constant(0u), r0023), 0x02));
>>> +
>>> +   body.emit(ret(r001E));
>>> +
>>> +   sig->replace_parameters(&sig_parameters);
>>> +   return sig;
>>> +}
>>> diff --git a/src/compiler/glsl/builtin_functions.cpp b/src/compiler/glsl/builtin_functions.cpp
>>> index 9d88a31..17aa868 100644
>>> --- a/src/compiler/glsl/builtin_functions.cpp
>>> +++ b/src/compiler/glsl/builtin_functions.cpp
>>> @@ -3350,6 +3350,10 @@ builtin_builder::create_builtins()
>>>                  generate_ir::fneg64(mem_ctx, integer_functions_supported),
>>>                  NULL);
>>>
>>> +   add_function("__builtin_fsign64",
>>> +                generate_ir::fsign64(mem_ctx, integer_functions_supported),
>>> +                NULL);
>>> +
>>>  #undef F
>>>  #undef FI
>>>  #undef FIUD_VEC
>>> diff --git a/src/compiler/glsl/builtin_functions.h b/src/compiler/glsl/builtin_functions.h
>>> index adec424..7954373 100644
>>> --- a/src/compiler/glsl/builtin_functions.h
>>> +++ b/src/compiler/glsl/builtin_functions.h
>>> @@ -73,6 +73,9 @@ fabs64(void *mem_ctx, builtin_available_predicate avail);
>>>  ir_function_signature *
>>>  fneg64(void *mem_ctx, builtin_available_predicate avail);
>>>
>>> +ir_function_signature *
>>> +fsign64(void *mem_ctx, builtin_available_predicate avail);
>>> +
>>>  }
>>>
>>>  #endif /* BULITIN_FUNCTIONS_H */
>>> diff --git a/src/compiler/glsl/float64.glsl b/src/compiler/glsl/float64.glsl
>>> index fedf8b7..f8eb1f3 100644
>>> --- a/src/compiler/glsl/float64.glsl
>>> +++ b/src/compiler/glsl/float64.glsl
>>> @@ -51,3 +51,12 @@ fneg64(uvec2 a)
>>>     a.y = mix(t, a.y, is_nan(a));
>>>     return a;
>>>  }
>>> +
>>
>> I think a function comment indicating what this returns would be quite
>> useful here(I had to look quite a long time at it to realize it returns
>> -1.0/1.0/0.0 depending on sign).
> 
> https://urldefense.proofpoint.com/v2/url?u=https-3A__www.khronos.org_registry_OpenGL-2DRefpages_gl4_html_sign.xhtml&d=DwIBaQ&c=uilaK90D4TOVoH58JNXRgQ&r=_QIjpv-UJ77xEQY8fIYoQtr5qv8wKrPJc7v7_-CYAb0&m=Kns1o3xPVFZHOhv63qzz5Cn5wzC5m_iNjS_DTEbzrQc&s=aPXd-t5FNI5Yn81XRndV6DRubU9vz3psCz2hmAJMmRo&e=
> 
>
Yes, but you should still do a function comment. You do it for the other
functions as well, after all.

Roland



More information about the mesa-dev mailing list