glsl/nir: Use i2b instead of ine for fixing UBO/SSBO Booleans
authorJason Ekstrand <jason.ekstrand@intel.com>
Thu, 18 Oct 2018 22:55:49 +0000 (17:55 -0500)
committerJason Ekstrand <jason.ekstrand@intel.com>
Fri, 26 Oct 2018 16:45:29 +0000 (11:45 -0500)
They do the same thing in the end but i2b is a bit simpler.  Also, let's
clean up the mess of code for SSBO handling with one line of builder.

Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
Reviewed-by: Eric Anholt <eric@anholt.net>
src/compiler/glsl/glsl_to_nir.cpp

index dc6ffa3599dd38bda6cfad20e61fb3ce00c9ae1a..0479f8fcfe4f4d7e2ba09fa833b55b01039a0c18 100644 (file)
@@ -833,7 +833,7 @@ nir_visitor::visit(ir_call *ir)
       }
 
       nir_intrinsic_instr *instr = nir_intrinsic_instr_create(shader, op);
-      nir_dest *dest = &instr->dest;
+      nir_ssa_def *ret = &instr->dest.ssa;
 
       switch (op) {
       case nir_intrinsic_atomic_counter_read_deref:
@@ -1037,22 +1037,8 @@ nir_visitor::visit(ir_call *ir)
           * consider a true boolean to be ~0. Fix this up with a != 0
           * comparison.
           */
-         if (type->is_boolean()) {
-            nir_alu_instr *load_ssbo_compare =
-               nir_alu_instr_create(shader, nir_op_ine);
-            load_ssbo_compare->src[0].src.is_ssa = true;
-            load_ssbo_compare->src[0].src.ssa = &instr->dest.ssa;
-            load_ssbo_compare->src[1].src =
-               nir_src_for_ssa(nir_imm_int(&b, 0));
-            for (unsigned i = 0; i < type->vector_elements; i++)
-               load_ssbo_compare->src[1].swizzle[i] = 0;
-            nir_ssa_dest_init(&load_ssbo_compare->instr,
-                              &load_ssbo_compare->dest.dest,
-                              type->vector_elements, bit_size, NULL);
-            load_ssbo_compare->dest.write_mask = (1 << type->vector_elements) - 1;
-            nir_builder_instr_insert(&b, &load_ssbo_compare->instr);
-            dest = &load_ssbo_compare->dest.dest;
-         }
+         if (type->is_boolean())
+            ret = nir_i2b(&b, &instr->dest.ssa);
          break;
       }
       case nir_intrinsic_ssbo_atomic_add:
@@ -1243,7 +1229,7 @@ nir_visitor::visit(ir_call *ir)
       }
 
       if (ir->return_deref)
-         nir_store_deref(&b, evaluate_deref(ir->return_deref), &dest->ssa, ~0);
+         nir_store_deref(&b, evaluate_deref(ir->return_deref), ret, ~0);
 
       return;
    }
@@ -1403,7 +1389,7 @@ nir_visitor::visit(ir_expression *ir)
        */
 
       if (ir->type->is_boolean())
-         this->result = nir_ine(&b, &load->dest.ssa, nir_imm_int(&b, 0));
+         this->result = nir_i2b(&b, &load->dest.ssa);
 
       return;
    }