[Mesa-dev] [PATCH 02/16] glsl/nir: ftrunc for native_integers=false float to int cast

Jonathan Marek jonathan at marek.ca
Wed Dec 19 16:39:51 UTC 2018


out_type is always GLSL_TYPE_FLOAT, so we don't get the ftrunc otherwise

Signed-off-by: Jonathan Marek <jonathan at marek.ca>
---
 src/compiler/glsl/glsl_to_nir.cpp | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/src/compiler/glsl/glsl_to_nir.cpp b/src/compiler/glsl/glsl_to_nir.cpp
index c8a7f3bd6c..d88289f682 100644
--- a/src/compiler/glsl/glsl_to_nir.cpp
+++ b/src/compiler/glsl/glsl_to_nir.cpp
@@ -1578,6 +1578,13 @@ nir_visitor::visit(ir_expression *ir)
    case ir_unop_u2i:
    case ir_unop_i642u64:
    case ir_unop_u642i64: {
+      if (!supports_ints) {
+         if (ir->operation == ir_unop_f2i || ir->operation == ir_unop_f2u) {
+            result = nir_ftrunc(&b, srcs[0]);
+            break;
+         }
+      }
+
       nir_alu_type src_type = nir_get_nir_type_for_glsl_base_type(types[0]);
       nir_alu_type dst_type = nir_get_nir_type_for_glsl_base_type(out_type);
       result = nir_build_alu(&b, nir_type_conversion_op(src_type, dst_type,
-- 
2.17.1



More information about the mesa-dev mailing list