From: Ian Romanick <ian.d.roman...@intel.com> The shift operations are a little weird. NIR expects both operands to have the same size, but the shift count operand is always 32-bits in GLSL. Upconvert to make the rest of NIR happy, and we'll assume the driver back-end will do something sensible.
v2: Don't up-convert the shift count parameter if shift instructions. Suggested by Connor. Add type_is_singed() function. This will make adding 8- and 16-bit types easier. Signed-off-by: Ian Romanick <ian.d.roman...@intel.com> Cc: Connor Abbott <cwabbo...@gmail.com> Cc: Jason Ekstrand <ja...@jlekstrand.net> --- src/compiler/glsl/glsl_to_nir.cpp | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/compiler/glsl/glsl_to_nir.cpp b/src/compiler/glsl/glsl_to_nir.cpp index b1c8ec6..bbe4ae6 100644 --- a/src/compiler/glsl/glsl_to_nir.cpp +++ b/src/compiler/glsl/glsl_to_nir.cpp @@ -1316,6 +1316,12 @@ type_is_float(glsl_base_type type) return type == GLSL_TYPE_FLOAT || type == GLSL_TYPE_DOUBLE; } +static bool +type_is_signed(glsl_base_type type) +{ + return type == GLSL_TYPE_INT || type == GLSL_TYPE_INT64; +} + void nir_visitor::visit(ir_expression *ir) { @@ -1663,7 +1669,7 @@ nir_visitor::visit(ir_expression *ir) case ir_binop_div: if (type_is_float(out_type)) result = nir_fdiv(&b, srcs[0], srcs[1]); - else if (out_type == GLSL_TYPE_INT) + else if (type_is_signed(out_type)) result = nir_idiv(&b, srcs[0], srcs[1]); else result = nir_udiv(&b, srcs[0], srcs[1]); @@ -1675,7 +1681,7 @@ nir_visitor::visit(ir_expression *ir) case ir_binop_min: if (type_is_float(out_type)) result = nir_fmin(&b, srcs[0], srcs[1]); - else if (out_type == GLSL_TYPE_INT) + else if (type_is_signed(out_type)) result = nir_imin(&b, srcs[0], srcs[1]); else result = nir_umin(&b, srcs[0], srcs[1]); @@ -1683,7 +1689,7 @@ nir_visitor::visit(ir_expression *ir) case ir_binop_max: if (type_is_float(out_type)) result = nir_fmax(&b, srcs[0], srcs[1]); - else if (out_type == GLSL_TYPE_INT) + else if (type_is_signed(out_type)) result = nir_imax(&b, srcs[0], srcs[1]); else result = nir_umax(&b, srcs[0], srcs[1]); @@ -1706,8 +1712,8 @@ nir_visitor::visit(ir_expression *ir) break; case ir_binop_lshift: result = nir_ishl(&b, srcs[0], srcs[1]); break; case ir_binop_rshift: - result = (out_type == GLSL_TYPE_INT) ? nir_ishr(&b, srcs[0], srcs[1]) - : nir_ushr(&b, srcs[0], srcs[1]); + result = (type_is_signed(out_type)) ? nir_ishr(&b, srcs[0], srcs[1]) + : nir_ushr(&b, srcs[0], srcs[1]); break; case ir_binop_imul_high: result = (out_type == GLSL_TYPE_INT) ? nir_imul_high(&b, srcs[0], srcs[1]) @@ -1719,7 +1725,7 @@ nir_visitor::visit(ir_expression *ir) if (supports_ints) { if (type_is_float(types[0])) result = nir_flt(&b, srcs[0], srcs[1]); - else if (types[0] == GLSL_TYPE_INT) + else if (type_is_signed(types[0])) result = nir_ilt(&b, srcs[0], srcs[1]); else result = nir_ult(&b, srcs[0], srcs[1]); @@ -1731,7 +1737,7 @@ nir_visitor::visit(ir_expression *ir) if (supports_ints) { if (type_is_float(types[0])) result = nir_flt(&b, srcs[1], srcs[0]); - else if (types[0] == GLSL_TYPE_INT) + else if (type_is_signed(types[0])) result = nir_ilt(&b, srcs[1], srcs[0]); else result = nir_ult(&b, srcs[1], srcs[0]); @@ -1743,7 +1749,7 @@ nir_visitor::visit(ir_expression *ir) if (supports_ints) { if (type_is_float(types[0])) result = nir_fge(&b, srcs[1], srcs[0]); - else if (types[0] == GLSL_TYPE_INT) + else if (type_is_signed(types[0])) result = nir_ige(&b, srcs[1], srcs[0]); else result = nir_uge(&b, srcs[1], srcs[0]); @@ -1755,7 +1761,7 @@ nir_visitor::visit(ir_expression *ir) if (supports_ints) { if (type_is_float(types[0])) result = nir_fge(&b, srcs[0], srcs[1]); - else if (types[0] == GLSL_TYPE_INT) + else if (type_is_signed(types[0])) result = nir_ige(&b, srcs[0], srcs[1]); else result = nir_uge(&b, srcs[0], srcs[1]); -- 2.5.5 _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev