panfrost: Fix BI_BLEND packing
[mesa.git] / src / panfrost / bifrost / bifrost_compile.c
index 23e451f0761d8c26c436f8682cbbc80b49e3566d..42abe567ee744a7b844382069b2c7cbe123d2e78 100644 (file)
@@ -147,16 +147,16 @@ bi_emit_frag_out(bi_context *ctx, nir_intrinsic_instr *instr)
                 .type = BI_BLEND,
                 .blend_location = nir_intrinsic_base(instr),
                 .src = {
+                        bir_src_index(&instr->src[0]),
                         BIR_INDEX_REGISTER | 60 /* Can this be arbitrary? */,
-                        bir_src_index(&instr->src[0])
                 },
                 .src_types = {
-                        nir_type_uint32,
                         nir_type_float32,
+                        nir_type_uint32
                 },
                 .swizzle = {
-                        { 0 },
-                        { 0, 1, 2, 3 }
+                        { 0, 1, 2, 3 },
+                        { 0 }
                 },
                 .dest = BIR_INDEX_REGISTER | 48 /* Looks like magic */,
                 .dest_type = nir_type_uint32,
@@ -320,6 +320,9 @@ emit_load_const(bi_context *ctx, nir_load_const_instr *instr)
                 .src = {
                         BIR_INDEX_CONSTANT
                 },
+                .src_types = {
+                        instr->def.bit_size | nir_type_uint,
+                },
                 .constant = {
                         .u64 = nir_const_value_as_uint(instr->value[0], instr->def.bit_size)
                 }
@@ -379,6 +382,10 @@ bi_class_for_nir_alu(nir_op op)
         case nir_op_u2f16:
         case nir_op_u2f32:
         case nir_op_u2f64:
+        case nir_op_f2f16:
+        case nir_op_f2f32:
+        case nir_op_f2f64:
+        case nir_op_f2fmp:
                 return BI_CONVERT;
 
         case nir_op_vec2:
@@ -409,10 +416,14 @@ bi_class_for_nir_alu(nir_op op)
         case nir_op_mov:
                 return BI_MOV;
 
+        case nir_op_fround_even:
+        case nir_op_fceil:
+        case nir_op_ffloor:
+        case nir_op_ftrunc:
+                return BI_ROUND;
+
         case nir_op_frcp:
         case nir_op_frsq:
-        case nir_op_fsin:
-        case nir_op_fcos:
                 return BI_SPECIAL;
 
         default:
@@ -507,7 +518,7 @@ bi_fuse_csel_cond(bi_instruction *csel, nir_alu_src cond,
         /* We found one, let's fuse it in */
         csel->csel_cond = bcond;
         bi_copy_src(csel, alu, 0, 0, constants_left, constant_shift);
-        bi_copy_src(csel, alu, 1, 3, constants_left, constant_shift);
+        bi_copy_src(csel, alu, 1, 1, constants_left, constant_shift);
 }
 
 static void
@@ -550,18 +561,28 @@ emit_alu(bi_context *ctx, nir_alu_instr *instr)
         unsigned constants_left = (64 / dest_bits);
         unsigned constant_shift = 0;
 
+        if (alu.type == BI_COMBINE)
+                constants_left = 0;
+
         /* Copy sources */
 
         unsigned num_inputs = nir_op_infos[instr->op].num_inputs;
         assert(num_inputs <= ARRAY_SIZE(alu.src));
 
-        for (unsigned i = 0; i < num_inputs; ++i)
-                bi_copy_src(&alu, instr, i, i, &constants_left, &constant_shift);
+        for (unsigned i = 0; i < num_inputs; ++i) {
+                unsigned f = 0;
+
+                if (i && alu.type == BI_CSEL)
+                        f++;
+
+                bi_copy_src(&alu, instr, i, i + f, &constants_left, &constant_shift);
+        }
 
         /* Op-specific fixup */
         switch (instr->op) {
         case nir_op_fmul:
                 alu.src[2] = BIR_INDEX_ZERO; /* FMA */
+                alu.src_types[2] = alu.src_types[1];
                 break;
         case nir_op_fsat:
                 alu.outmod = BIFROST_SAT; /* FMOV */
@@ -586,12 +607,6 @@ emit_alu(bi_context *ctx, nir_alu_instr *instr)
         case nir_op_frsq:
                 alu.op.special = BI_SPECIAL_FRSQ;
                 break;
-        case nir_op_fsin:
-                alu.op.special = BI_SPECIAL_FSIN;
-                break;
-        case nir_op_fcos:
-                alu.op.special = BI_SPECIAL_FCOS;
-                break;
         BI_CASE_CMP(nir_op_flt)
         BI_CASE_CMP(nir_op_ilt)
         BI_CASE_CMP(nir_op_fge)
@@ -602,6 +617,22 @@ emit_alu(bi_context *ctx, nir_alu_instr *instr)
         BI_CASE_CMP(nir_op_ine)
                 alu.op.compare = bi_cond_for_nir(instr->op, false);
                 break;
+        case nir_op_fround_even:
+                alu.op.round = BI_ROUND_MODE;
+                alu.roundmode = BIFROST_RTE;
+                break;
+        case nir_op_fceil:
+                alu.op.round = BI_ROUND_MODE;
+                alu.roundmode = BIFROST_RTP;
+                break;
+        case nir_op_ffloor:
+                alu.op.round = BI_ROUND_MODE;
+                alu.roundmode = BIFROST_RTN;
+                break;
+        case nir_op_ftrunc:
+                alu.op.round = BI_ROUND_MODE;
+                alu.roundmode = BIFROST_RTZ;
+                break;
         default:
                 break;
         }
@@ -609,8 +640,8 @@ emit_alu(bi_context *ctx, nir_alu_instr *instr)
         if (alu.type == BI_CSEL) {
                 /* Default to csel3 */
                 alu.csel_cond = BI_COND_NE;
-                alu.src[3] = BIR_INDEX_ZERO;
-                alu.src_types[3] = alu.src_types[0];
+                alu.src[1] = BIR_INDEX_ZERO;
+                alu.src_types[1] = alu.src_types[0];
 
                 bi_fuse_csel_cond(&alu, instr->src[0],
                                 &constants_left, &constant_shift);