From: Elie Tournier <tournier.e...@gmail.com> [airlied: update to handle min(dvec, double) case.
Signed-off-by: Elie Tournier <elie.tourn...@collabora.com> --- src/compiler/glsl/ir_optimization.h | 1 + src/compiler/glsl/lower_instructions.cpp | 33 ++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/src/compiler/glsl/ir_optimization.h b/src/compiler/glsl/ir_optimization.h index 3c99ae0..f9b688a 100644 --- a/src/compiler/glsl/ir_optimization.h +++ b/src/compiler/glsl/ir_optimization.h @@ -54,6 +54,7 @@ #define DDIV_TO_MUL_RCP 0x100000 #define DIV_TO_MUL_RCP (FDIV_TO_MUL_RCP | DDIV_TO_MUL_RCP) #define SQRT_TO_ABS_SQRT 0x200000 +#define DMIN_DMAX_TO_LESS 0x400000 /* Opertaions for lower_64bit_integer_instructions() */ #define MUL64 (1U << 0) diff --git a/src/compiler/glsl/lower_instructions.cpp b/src/compiler/glsl/lower_instructions.cpp index 91f71b3..8c3d623 100644 --- a/src/compiler/glsl/lower_instructions.cpp +++ b/src/compiler/glsl/lower_instructions.cpp @@ -43,6 +43,7 @@ * - BORROW_TO_ARITH * - SAT_TO_CLAMP * - DOPS_TO_DFRAC + * - DMIN_DMAX_TO_LESS * * SUB_TO_ADD_NEG: * --------------- @@ -115,6 +116,12 @@ * DOPS_TO_DFRAC: * -------------- * Converts double trunc, ceil, floor, round to fract + * + * DMIN_DMAX_TO_LESS: + * ---------------- + * Converts double min, max into less. + * min(x,y) = less(x,y) ? x, y; + * max(x,y) = less(x,y) ? y, x; */ #include "c99_math.h" @@ -169,6 +176,7 @@ private: void find_msb_to_float_cast(ir_expression *ir); void imul_high_to_mul(ir_expression *ir); void sqrt_to_abs_sqrt(ir_expression *ir); + void dmin_to_less(ir_expression *ir); ir_expression *_carry(operand a, operand b); }; @@ -1666,6 +1674,25 @@ lower_instructions_visitor::sqrt_to_abs_sqrt(ir_expression *ir) this->progress = true; } +void +lower_instructions_visitor::dmin_to_less(ir_expression *ir) +{ + const unsigned vec_elem = ir->type->vector_elements; + ir_rvalue *x_clone = ir->operands[0]->clone(ir, NULL); + ir_rvalue *y_clone = ir->operands[1]->clone(ir, NULL); + ir->operation = ir_triop_csel; + ir->init_num_operands(); + if (ir->operands[1]->type->vector_elements == 1 && vec_elem > 1) { + ir->operands[0] = less(ir->operands[0], swizzle(ir->operands[1], SWIZZLE_XXXX, vec_elem)); + ir->operands[2] = swizzle(y_clone, SWIZZLE_XXXX, vec_elem); + } else { + ir->operands[0] = less(ir->operands[0], ir->operands[1]); + ir->operands[2] = y_clone; + } + ir->operands[1] = x_clone; + this->progress = true; +} + ir_visitor_status lower_instructions_visitor::visit_leave(ir_expression *ir) { @@ -1809,6 +1836,12 @@ lower_instructions_visitor::visit_leave(ir_expression *ir) sqrt_to_abs_sqrt(ir); break; + case ir_binop_min: + if (lowering(DMIN_DMAX_TO_LESS) && + ir->type->is_double()) + dmin_to_less(ir); + break; + default: return visit_continue; } -- 2.9.5 _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev