nir/vtn: SPIR-V bit count opcodes (core and extension) dest size mismatches nir
[mesa.git] / src / compiler / spirv / vtn_alu.c
index e92a48f24a63962b5cc86e828f483ffe7ec9ad37..b403a25e51b20659bc22b13fc61f32a73355427e 100644 (file)
@@ -257,7 +257,6 @@ vtn_nir_alu_op_for_spirv_opcode(struct vtn_builder *b,
    case SpvOpBitFieldSExtract:      return nir_op_ibitfield_extract;
    case SpvOpBitFieldUExtract:      return nir_op_ubitfield_extract;
    case SpvOpBitReverse:            return nir_op_bitfield_reverse;
-   case SpvOpBitCount:              return nir_op_bit_count;
 
    case SpvOpUCountLeadingZerosINTEL: return nir_op_uclz;
    /* SpvOpUCountTrailingZerosINTEL is handled elsewhere. */
@@ -282,8 +281,8 @@ vtn_nir_alu_op_for_spirv_opcode(struct vtn_builder *b,
    case SpvOpFUnordEqual:                          return nir_op_feq;
    case SpvOpINotEqual:                            return nir_op_ine;
    case SpvOpLessOrGreater:                        /* Deprecated, use OrdNotEqual */
-   case SpvOpFOrdNotEqual:                         return nir_op_fne;
-   case SpvOpFUnordNotEqual:                       return nir_op_fne;
+   case SpvOpFOrdNotEqual:                         return nir_op_fneu;
+   case SpvOpFUnordNotEqual:                       return nir_op_fneu;
    case SpvOpULessThan:                            return nir_op_ult;
    case SpvOpSLessThan:                            return nir_op_ilt;
    case SpvOpFOrdLessThan:                         return nir_op_flt;
@@ -513,7 +512,7 @@ vtn_handle_alu(struct vtn_builder *b, SpvOp opcode,
       break;
 
    case SpvOpIsNan:
-      dest->def = nir_fne(&b->nb, src[0], src[0]);
+      dest->def = nir_fneu(&b->nb, src[0], src[0]);
       break;
 
    case SpvOpOrdered:
@@ -522,8 +521,8 @@ vtn_handle_alu(struct vtn_builder *b, SpvOp opcode,
       break;
 
    case SpvOpUnordered:
-      dest->def = nir_ior(&b->nb, nir_fne(&b->nb, src[0], src[0]),
-                                  nir_fne(&b->nb, src[1], src[1]));
+      dest->def = nir_ior(&b->nb, nir_fneu(&b->nb, src[0], src[0]),
+                                  nir_fneu(&b->nb, src[1], src[1]));
       break;
 
    case SpvOpIsInf: {
@@ -554,8 +553,8 @@ vtn_handle_alu(struct vtn_builder *b, SpvOp opcode,
          nir_ior(&b->nb,
                  nir_build_alu(&b->nb, op, src[0], src[1], NULL, NULL),
                  nir_ior(&b->nb,
-                         nir_fne(&b->nb, src[0], src[0]),
-                         nir_fne(&b->nb, src[1], src[1])));
+                         nir_fneu(&b->nb, src[0], src[0]),
+                         nir_fneu(&b->nb, src[1], src[1])));
       break;
    }
 
@@ -640,6 +639,14 @@ vtn_handle_alu(struct vtn_builder *b, SpvOp opcode,
                                nir_imm_int(&b->nb, 32u));
       break;
 
+   case SpvOpBitCount: {
+      /* bit_count always returns int32, but the SPIR-V opcode just says the return
+       * value needs to be big enough to store the number of bits.
+       */
+      dest->def = nir_u2u(&b->nb, nir_bit_count(&b->nb, src[0]), glsl_get_bit_size(dest_type));
+      break;
+   }
+
    default: {
       bool swap;
       unsigned src_bit_size = glsl_get_bit_size(vtn_src[0]->type);