[Mesa-dev] [PATCH 3/3] glsl/nir: glsl_to_nir fixes for native_integers=false
Jonathan Marek
jonathan at marek.ca
Mon Nov 12 18:15:43 UTC 2018
Two parts:
1. for intructions that have a BOOL source, insert b2f to so that the
backend can identify the source as a BOOL and perform the conversion from
NIR_TRUE/NIR_FALSE
2. add missing type conversions (out_type is always GLSL_TYPE_FLOAT, so we
are missing some conversion instructions): float to int (ftrunc), and f2b
(which represents the operation that is the opposite of a fnot).
Signed-off-by: Jonathan Marek <jonathan at marek.ca>
---
src/compiler/glsl/glsl_to_nir.cpp | 23 ++++++++++++++++++++++-
1 file changed, 22 insertions(+), 1 deletion(-)
diff --git a/src/compiler/glsl/glsl_to_nir.cpp b/src/compiler/glsl/glsl_to_nir.cpp
index 0479f8fcfe..565bf588f5 100644
--- a/src/compiler/glsl/glsl_to_nir.cpp
+++ b/src/compiler/glsl/glsl_to_nir.cpp
@@ -1465,9 +1465,13 @@ nir_visitor::visit(ir_expression *ir)
}
nir_ssa_def *srcs[4];
- for (unsigned i = 0; i < ir->num_operands; i++)
+ for (unsigned i = 0; i < ir->num_operands; i++) {
srcs[i] = evaluate_rvalue(ir->operands[i]);
+ if (ir->operands[i]->type->base_type == GLSL_TYPE_BOOL)
+ srcs[i] = nir_b2f(&b, srcs[i]);
+ }
+
glsl_base_type types[4];
for (unsigned i = 0; i < ir->num_operands; i++)
if (supports_ints)
@@ -1552,6 +1556,23 @@ nir_visitor::visit(ir_expression *ir)
case ir_unop_u2i:
case ir_unop_i642u64:
case ir_unop_u642i64: {
+ if (!supports_ints) {
+ switch (ir->operation) {
+ case ir_unop_f2i:
+ case ir_unop_f2u:
+ result = nir_ftrunc(&b, srcs[0]);
+ break;
+ case ir_unop_f2b:
+ case ir_unop_i2b:
+ result = nir_f2b(&b, srcs[0]);
+ break;
+ default:
+ result = nir_fmov(&b, srcs[0]);
+ break;
+ }
+ 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