[Mesa-dev] [PATCH 48/59] nir: Enable 64-bit integer support for almost all unary and binary operations
Ian Romanick
idr at freedesktop.org
Wed Oct 26 00:59:54 UTC 2016
From: Ian Romanick <ian.d.romanick at 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.
Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
---
src/compiler/glsl/glsl_to_nir.cpp | 40 +++++++++++++++++++++++++++++----------
1 file changed, 30 insertions(+), 10 deletions(-)
diff --git a/src/compiler/glsl/glsl_to_nir.cpp b/src/compiler/glsl/glsl_to_nir.cpp
index b1c8ec6..41c2493 100644
--- a/src/compiler/glsl/glsl_to_nir.cpp
+++ b/src/compiler/glsl/glsl_to_nir.cpp
@@ -1663,7 +1663,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 (out_type == GLSL_TYPE_INT || out_type == GLSL_TYPE_INT64)
result = nir_idiv(&b, srcs[0], srcs[1]);
else
result = nir_udiv(&b, srcs[0], srcs[1]);
@@ -1675,7 +1675,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 (out_type == GLSL_TYPE_INT || out_type == GLSL_TYPE_INT64)
result = nir_imin(&b, srcs[0], srcs[1]);
else
result = nir_umin(&b, srcs[0], srcs[1]);
@@ -1683,7 +1683,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 (out_type == GLSL_TYPE_INT || out_type == GLSL_TYPE_INT64)
result = nir_imax(&b, srcs[0], srcs[1]);
else
result = nir_umax(&b, srcs[0], srcs[1]);
@@ -1704,10 +1704,30 @@ nir_visitor::visit(ir_expression *ir)
result = supports_ints ? nir_ixor(&b, srcs[0], srcs[1])
: nir_fxor(&b, srcs[0], srcs[1]);
break;
- case ir_binop_lshift: result = nir_ishl(&b, srcs[0], srcs[1]); break;
+ case ir_binop_lshift:
+ if (out_type == GLSL_TYPE_UINT || out_type == GLSL_TYPE_INT) {
+ result = nir_ishl(&b, srcs[0], srcs[1]);
+ } else {
+ result = nir_ishl(&b, srcs[0], nir_u2u64(&b, 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]);
+ switch (out_type) {
+ case GLSL_TYPE_UINT:
+ result = nir_ushr(&b, srcs[0], srcs[1]);
+ break;
+ case GLSL_TYPE_INT:
+ result = nir_ishr(&b, srcs[0], srcs[1]);
+ break;
+ case GLSL_TYPE_UINT64:
+ result = nir_ushr(&b, srcs[0], nir_u2u64(&b, srcs[1]));
+ break;
+ case GLSL_TYPE_INT64:
+ result = nir_ishr(&b, srcs[0], nir_u2u64(&b, srcs[1]));
+ break;
+ default:
+ unreachable("invalid ir_binop_rshift result type");
+ }
break;
case ir_binop_imul_high:
result = (out_type == GLSL_TYPE_INT) ? nir_imul_high(&b, srcs[0], srcs[1])
@@ -1719,7 +1739,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 (types[0] == GLSL_TYPE_INT || types[0] == GLSL_TYPE_INT64)
result = nir_ilt(&b, srcs[0], srcs[1]);
else
result = nir_ult(&b, srcs[0], srcs[1]);
@@ -1731,7 +1751,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 (types[0] == GLSL_TYPE_INT || types[0] == GLSL_TYPE_INT64)
result = nir_ilt(&b, srcs[1], srcs[0]);
else
result = nir_ult(&b, srcs[1], srcs[0]);
@@ -1743,7 +1763,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 (types[0] == GLSL_TYPE_INT || types[0] == GLSL_TYPE_INT64)
result = nir_ige(&b, srcs[1], srcs[0]);
else
result = nir_uge(&b, srcs[1], srcs[0]);
@@ -1755,7 +1775,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 (types[0] == GLSL_TYPE_INT || types[0] == GLSL_TYPE_INT64)
result = nir_ige(&b, srcs[0], srcs[1]);
else
result = nir_uge(&b, srcs[0], srcs[1]);
--
2.5.5
More information about the mesa-dev
mailing list