[Mesa-dev] [v2 PATCH 10/16] glsl: Optimize clamp(x, 0.0, b), where b < 1.0 as min(saturate(x), b)
Abdiel Janulgue
abdiel.janulgue at linux.intel.com
Tue Jul 8 02:37:09 PDT 2014
On 07.07.2014 20:25, Matt Turner wrote:
> On Mon, Jul 7, 2014 at 6:57 AM, Abdiel Janulgue
> <abdiel.janulgue at linux.intel.com> wrote:
>> v2: - Output min(saturate(x),b) instead of saturate(min(x,b)) suggested by Ilia Mirkin
>> - Make sure we do component-wise comparison for vectors (Ian Romanick)
>>
>> Signed-off-by: Abdiel Janulgue <abdiel.janulgue at linux.intel.com>
>> ---
>> src/glsl/opt_algebraic.cpp | 10 ++++++++++
>> 1 file changed, 10 insertions(+)
>>
>> diff --git a/src/glsl/opt_algebraic.cpp b/src/glsl/opt_algebraic.cpp
>> index 2ad561c..bcda7a9 100644
>> --- a/src/glsl/opt_algebraic.cpp
>> +++ b/src/glsl/opt_algebraic.cpp
>> @@ -643,6 +643,16 @@ ir_algebraic_visitor::handle_expression(ir_expression *ir)
>> /* Found a min (max(x, 0), 1.0) */
>> if (outer_const->is_one() && inner_val_a->is_zero())
>> return saturate(inner_val_b);
>> +
>> + unsigned component = 0;
>> + for (int c = 0; c < outer_const->type->vector_elements; c++) {
>> + if (outer_const->get_float_component(c) < 1.0f)
>> + component++;
>> + }
>> + /* Found a min (max(x, 0.0) b), where b < 1.0 */
>
> Is this case the only thing it finds?
>
> Does it find max(min(x, b), 0.0)?
Unfortunately, you are right. The detection only works if the inner
constant is zero. I'll fix this in the next revision
>
>> + if ((component == outer_const->type->vector_elements) &&
>> + inner_val_b->is_zero())
>> + return expr(ir_binop_min, saturate(inner_val_a), outer_const);
>
> It seems like it would incorrectly recognize max(min(x, 0.0), b).
>
This one it would correctly recognize.
More information about the mesa-dev
mailing list