panfrost: Convert to PIPE_BLEND enums internally
authorAlyssa Rosenzweig <alyssa@rosenzweig.io>
Tue, 11 Jul 2023 12:42:36 +0000 (08:42 -0400)
committerMarge Bot <emma+marge@anholt.net>
Thu, 13 Jul 2023 21:03:32 +0000 (21:03 +0000)
This removes all the users of the compiler enums, and is a lot more natural now
that nir_lower_blend speaks PIPE_BLEND enums.

Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Reviewed-by: Italo Nicola <italonicola@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24076>

src/gallium/drivers/panfrost/pan_cmdstream.c
src/panfrost/lib/pan_blend.c
src/panfrost/lib/pan_blend.h
src/panfrost/lib/tests/test-blend.c
src/panfrost/vulkan/panvk_vX_pipeline.c
src/panfrost/vulkan/panvk_vX_shader.c

index 0f88792..89ec578 100644 (file)
@@ -4201,24 +4201,12 @@ panfrost_create_blend_state(struct pipe_context *pipe,
       equation.blend_enable = pipe.blend_enable;
 
       if (pipe.blend_enable) {
-         equation.rgb_func = util_blend_func_to_shader(pipe.rgb_func);
-         equation.rgb_src_factor =
-            util_blend_factor_to_shader(pipe.rgb_src_factor);
-         equation.rgb_invert_src_factor =
-            util_blend_factor_is_inverted(pipe.rgb_src_factor);
-         equation.rgb_dst_factor =
-            util_blend_factor_to_shader(pipe.rgb_dst_factor);
-         equation.rgb_invert_dst_factor =
-            util_blend_factor_is_inverted(pipe.rgb_dst_factor);
-         equation.alpha_func = util_blend_func_to_shader(pipe.alpha_func);
-         equation.alpha_src_factor =
-            util_blend_factor_to_shader(pipe.alpha_src_factor);
-         equation.alpha_invert_src_factor =
-            util_blend_factor_is_inverted(pipe.alpha_src_factor);
-         equation.alpha_dst_factor =
-            util_blend_factor_to_shader(pipe.alpha_dst_factor);
-         equation.alpha_invert_dst_factor =
-            util_blend_factor_is_inverted(pipe.alpha_dst_factor);
+         equation.rgb_func = pipe.rgb_func;
+         equation.rgb_src_factor = pipe.rgb_src_factor;
+         equation.rgb_dst_factor = pipe.rgb_dst_factor;
+         equation.alpha_func = pipe.alpha_func;
+         equation.alpha_src_factor = pipe.alpha_src_factor;
+         equation.alpha_dst_factor = pipe.alpha_dst_factor;
       }
 
       /* Determine some common properties */
index 782c7e1..de9e65e 100644 (file)
 #include "util/format/u_format.h"
 #include "pan_texture.h"
 
-static inline enum pipe_blend_func
-to_pipe_blend_func(enum blend_func func)
-{
-   switch (func) {
-   case BLEND_FUNC_ADD:
-      return PIPE_BLEND_ADD;
-   case BLEND_FUNC_SUBTRACT:
-      return PIPE_BLEND_SUBTRACT;
-   case BLEND_FUNC_REVERSE_SUBTRACT:
-      return PIPE_BLEND_REVERSE_SUBTRACT;
-   case BLEND_FUNC_MIN:
-      return PIPE_BLEND_MIN;
-   case BLEND_FUNC_MAX:
-      return PIPE_BLEND_MAX;
-   }
-
-   unreachable("invalid");
-}
-
-static inline enum pipe_blendfactor
-to_pipe_blendfactor_uninverted(enum blend_factor factor)
-{
-   switch (factor) {
-   case BLEND_FACTOR_SRC_COLOR:
-      return PIPE_BLENDFACTOR_SRC_COLOR;
-   case BLEND_FACTOR_SRC1_COLOR:
-      return PIPE_BLENDFACTOR_SRC1_COLOR;
-   case BLEND_FACTOR_DST_COLOR:
-      return PIPE_BLENDFACTOR_DST_COLOR;
-   case BLEND_FACTOR_SRC_ALPHA:
-      return PIPE_BLENDFACTOR_SRC_ALPHA;
-   case BLEND_FACTOR_SRC1_ALPHA:
-      return PIPE_BLENDFACTOR_SRC1_ALPHA;
-   case BLEND_FACTOR_DST_ALPHA:
-      return PIPE_BLENDFACTOR_DST_ALPHA;
-   case BLEND_FACTOR_CONSTANT_COLOR:
-      return PIPE_BLENDFACTOR_CONST_COLOR;
-   case BLEND_FACTOR_CONSTANT_ALPHA:
-      return PIPE_BLENDFACTOR_CONST_ALPHA;
-   case BLEND_FACTOR_SRC_ALPHA_SATURATE:
-      return PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE;
-   default:
-      unreachable("Invalid");
-   }
-}
-
-static inline enum pipe_blendfactor
-to_pipe_blendfactor(enum blend_factor factor, bool inverted)
-{
-   /* Flipped so handle special */
-   if (factor == BLEND_FACTOR_ZERO)
-      return inverted ? PIPE_BLENDFACTOR_ONE : PIPE_BLENDFACTOR_ZERO;
-
-   enum pipe_blendfactor pipe = to_pipe_blendfactor_uninverted(factor);
-
-   if (inverted)
-      pipe |= PIPE_BLENDFACTOR_INVERT_BIT;
-
-   return pipe;
-}
-
 #ifndef PAN_ARCH
 
 /* Fixed function blending */
 
 static bool
-factor_is_supported(enum blend_factor factor)
+factor_is_supported(enum pipe_blendfactor factor)
 {
-   return factor != BLEND_FACTOR_SRC_ALPHA_SATURATE &&
-          factor != BLEND_FACTOR_SRC1_COLOR &&
-          factor != BLEND_FACTOR_SRC1_ALPHA;
+   factor = util_blendfactor_without_invert(factor);
+
+   return factor != PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE &&
+          factor != PIPE_BLENDFACTOR_SRC1_COLOR &&
+          factor != PIPE_BLENDFACTOR_SRC1_ALPHA;
 }
 
 /* OpenGL allows encoding (src*dest + dest*src) which is incompatiblle with
@@ -116,50 +57,50 @@ factor_is_supported(enum blend_factor factor)
  * + dest * (2*src) wih the new source_2 value of C. Detect this case. */
 
 static bool
-is_2srcdest(enum blend_func blend_func, enum blend_factor src_factor,
-            bool invert_src, enum blend_factor dest_factor, bool invert_dest,
-            bool is_alpha)
+is_2srcdest(enum pipe_blend_func blend_func, enum pipe_blendfactor src_factor,
+            enum pipe_blendfactor dest_factor, bool is_alpha)
 {
-   return (blend_func == BLEND_FUNC_ADD) &&
-          ((src_factor == BLEND_FACTOR_DST_COLOR) ||
-           ((src_factor == BLEND_FACTOR_DST_ALPHA) && is_alpha)) &&
-          ((dest_factor == BLEND_FACTOR_SRC_COLOR) ||
-           ((dest_factor == BLEND_FACTOR_SRC_ALPHA) && is_alpha)) &&
-          !invert_src && !invert_dest;
+   return (blend_func == PIPE_BLEND_ADD) &&
+          ((src_factor == PIPE_BLENDFACTOR_DST_COLOR) ||
+           ((src_factor == PIPE_BLENDFACTOR_DST_ALPHA) && is_alpha)) &&
+          ((dest_factor == PIPE_BLENDFACTOR_SRC_COLOR) ||
+           ((dest_factor == PIPE_BLENDFACTOR_SRC_ALPHA) && is_alpha));
 }
 
 static bool
-can_fixed_function_equation(enum blend_func blend_func,
-                            enum blend_factor src_factor, bool invert_src,
-                            enum blend_factor dest_factor, bool invert_dest,
-                            bool is_alpha, bool supports_2src)
+can_fixed_function_equation(enum pipe_blend_func blend_func,
+                            enum pipe_blendfactor src_factor,
+                            enum pipe_blendfactor dest_factor, bool is_alpha,
+                            bool supports_2src)
 {
-   if (is_2srcdest(blend_func, src_factor, invert_src, dest_factor, invert_dest,
-                   is_alpha)) {
-
+   if (is_2srcdest(blend_func, src_factor, dest_factor, is_alpha))
       return supports_2src;
-   }
 
-   if (blend_func != BLEND_FUNC_ADD && blend_func != BLEND_FUNC_SUBTRACT &&
-       blend_func != BLEND_FUNC_REVERSE_SUBTRACT)
+   if (blend_func != PIPE_BLEND_ADD && blend_func != PIPE_BLEND_SUBTRACT &&
+       blend_func != PIPE_BLEND_REVERSE_SUBTRACT)
       return false;
 
    if (!factor_is_supported(src_factor) || !factor_is_supported(dest_factor))
       return false;
 
-   if (src_factor != dest_factor && src_factor != BLEND_FACTOR_ZERO &&
-       dest_factor != BLEND_FACTOR_ZERO)
-      return false;
+   /* Fixed function requires src/dest factors to match (up to invert) or be
+    * zero/one.
+    */
+   enum pipe_blendfactor src = util_blendfactor_without_invert(src_factor);
+   enum pipe_blendfactor dest = util_blendfactor_without_invert(dest_factor);
 
-   return true;
+   return (src == dest) || (src == PIPE_BLENDFACTOR_ONE) ||
+          (dest == PIPE_BLENDFACTOR_ONE);
 }
 
 static unsigned
-blend_factor_constant_mask(enum blend_factor factor)
+blend_factor_constant_mask(enum pipe_blendfactor factor)
 {
-   if (factor == BLEND_FACTOR_CONSTANT_COLOR)
+   factor = util_blendfactor_without_invert(factor);
+
+   if (factor == PIPE_BLENDFACTOR_CONST_COLOR)
       return 0b0111; /* RGB */
-   else if (factor == BLEND_FACTOR_CONSTANT_ALPHA)
+   else if (factor == PIPE_BLENDFACTOR_CONST_ALPHA)
       return 0b1000; /* A */
    else
       return 0b0000; /* - */
@@ -199,35 +140,34 @@ pan_blend_can_fixed_function(const struct pan_blend_equation equation,
    return !equation.blend_enable ||
           (can_fixed_function_equation(
               equation.rgb_func, equation.rgb_src_factor,
-              equation.rgb_invert_src_factor, equation.rgb_dst_factor,
-              equation.rgb_invert_dst_factor, false, supports_2src) &&
+              equation.rgb_dst_factor, false, supports_2src) &&
            can_fixed_function_equation(
               equation.alpha_func, equation.alpha_src_factor,
-              equation.alpha_invert_src_factor, equation.alpha_dst_factor,
-              equation.alpha_invert_dst_factor, true, supports_2src));
+              equation.alpha_dst_factor, true, supports_2src));
 }
 
 static enum mali_blend_operand_c
-to_c_factor(enum blend_factor factor)
+to_c_factor(enum pipe_blendfactor factor)
 {
-   switch (factor) {
-   case BLEND_FACTOR_ZERO:
+   switch (util_blendfactor_without_invert(factor)) {
+   case PIPE_BLENDFACTOR_ONE:
+      /* Extra invert to flip back in caller */
       return MALI_BLEND_OPERAND_C_ZERO;
 
-   case BLEND_FACTOR_SRC_ALPHA:
+   case PIPE_BLENDFACTOR_SRC_ALPHA:
       return MALI_BLEND_OPERAND_C_SRC_ALPHA;
 
-   case BLEND_FACTOR_DST_ALPHA:
+   case PIPE_BLENDFACTOR_DST_ALPHA:
       return MALI_BLEND_OPERAND_C_DEST_ALPHA;
 
-   case BLEND_FACTOR_SRC_COLOR:
+   case PIPE_BLENDFACTOR_SRC_COLOR:
       return MALI_BLEND_OPERAND_C_SRC;
 
-   case BLEND_FACTOR_DST_COLOR:
+   case PIPE_BLENDFACTOR_DST_COLOR:
       return MALI_BLEND_OPERAND_C_DEST;
 
-   case BLEND_FACTOR_CONSTANT_COLOR:
-   case BLEND_FACTOR_CONSTANT_ALPHA:
+   case PIPE_BLENDFACTOR_CONST_COLOR:
+   case PIPE_BLENDFACTOR_CONST_ALPHA:
       return MALI_BLEND_OPERAND_C_CONSTANT;
 
    default:
@@ -236,87 +176,98 @@ to_c_factor(enum blend_factor factor)
 }
 
 static void
-to_panfrost_function(enum blend_func blend_func, enum blend_factor src_factor,
-                     bool invert_src, enum blend_factor dest_factor,
-                     bool invert_dest, bool is_alpha,
+to_panfrost_function(enum pipe_blend_func blend_func,
+                     enum pipe_blendfactor src_factor,
+                     enum pipe_blendfactor dest_factor, bool is_alpha,
                      struct MALI_BLEND_FUNCTION *function)
 {
-   assert(can_fixed_function_equation(blend_func, src_factor, invert_src,
-                                      dest_factor, invert_dest, is_alpha,
-                                      true));
+   assert(can_fixed_function_equation(blend_func, src_factor, dest_factor,
+                                      is_alpha, true));
+
+   /* We handle ZERO/ONE specially since it's the hardware has 0 and can invert
+    * to 1 but Gallium has 0 as the uninverted version.
+    */
+   bool src_inverted =
+      util_blendfactor_is_inverted(src_factor) ^
+      (util_blendfactor_without_invert(src_factor) == PIPE_BLENDFACTOR_ONE);
+
+   bool dest_inverted =
+      util_blendfactor_is_inverted(dest_factor) ^
+      (util_blendfactor_without_invert(dest_factor) == PIPE_BLENDFACTOR_ONE);
 
-   if (src_factor == BLEND_FACTOR_ZERO && !invert_src) {
+   if (src_factor == PIPE_BLENDFACTOR_ZERO) {
       function->a = MALI_BLEND_OPERAND_A_ZERO;
       function->b = MALI_BLEND_OPERAND_B_DEST;
-      if (blend_func == BLEND_FUNC_SUBTRACT)
+      if (blend_func == PIPE_BLEND_SUBTRACT)
          function->negate_b = true;
-      function->invert_c = invert_dest;
+      function->invert_c = dest_inverted;
       function->c = to_c_factor(dest_factor);
-   } else if (src_factor == BLEND_FACTOR_ZERO && invert_src) {
+   } else if (src_factor == PIPE_BLENDFACTOR_ONE) {
       function->a = MALI_BLEND_OPERAND_A_SRC;
       function->b = MALI_BLEND_OPERAND_B_DEST;
-      if (blend_func == BLEND_FUNC_SUBTRACT)
+      if (blend_func == PIPE_BLEND_SUBTRACT)
          function->negate_b = true;
-      else if (blend_func == BLEND_FUNC_REVERSE_SUBTRACT)
+      else if (blend_func == PIPE_BLEND_REVERSE_SUBTRACT)
          function->negate_a = true;
-      function->invert_c = invert_dest;
+      function->invert_c = dest_inverted;
       function->c = to_c_factor(dest_factor);
-   } else if (dest_factor == BLEND_FACTOR_ZERO && !invert_dest) {
+   } else if (dest_factor == PIPE_BLENDFACTOR_ZERO) {
       function->a = MALI_BLEND_OPERAND_A_ZERO;
       function->b = MALI_BLEND_OPERAND_B_SRC;
-      if (blend_func == BLEND_FUNC_REVERSE_SUBTRACT)
+      if (blend_func == PIPE_BLEND_REVERSE_SUBTRACT)
          function->negate_b = true;
-      function->invert_c = invert_src;
+      function->invert_c = src_inverted;
       function->c = to_c_factor(src_factor);
-   } else if (dest_factor == BLEND_FACTOR_ZERO && invert_dest) {
+   } else if (dest_factor == PIPE_BLENDFACTOR_ONE) {
       function->a = MALI_BLEND_OPERAND_A_DEST;
       function->b = MALI_BLEND_OPERAND_B_SRC;
-      if (blend_func == BLEND_FUNC_SUBTRACT)
+      if (blend_func == PIPE_BLEND_SUBTRACT)
          function->negate_a = true;
-      else if (blend_func == BLEND_FUNC_REVERSE_SUBTRACT)
+      else if (blend_func == PIPE_BLEND_REVERSE_SUBTRACT)
          function->negate_b = true;
-      function->invert_c = invert_src;
+      function->invert_c = src_inverted;
       function->c = to_c_factor(src_factor);
-   } else if (src_factor == dest_factor && invert_src == invert_dest) {
+   } else if (src_factor == dest_factor) {
       function->a = MALI_BLEND_OPERAND_A_ZERO;
-      function->invert_c = invert_src;
+      function->invert_c = src_inverted;
       function->c = to_c_factor(src_factor);
 
       switch (blend_func) {
-      case BLEND_FUNC_ADD:
+      case PIPE_BLEND_ADD:
          function->b = MALI_BLEND_OPERAND_B_SRC_PLUS_DEST;
          break;
-      case BLEND_FUNC_REVERSE_SUBTRACT:
+      case PIPE_BLEND_REVERSE_SUBTRACT:
          function->negate_b = true;
          FALLTHROUGH;
-      case BLEND_FUNC_SUBTRACT:
+      case PIPE_BLEND_SUBTRACT:
          function->b = MALI_BLEND_OPERAND_B_SRC_MINUS_DEST;
          break;
       default:
          unreachable("Invalid blend function");
       }
-   } else if (is_2srcdest(blend_func, src_factor, invert_src, dest_factor,
-                          invert_dest, is_alpha)) {
+   } else if (is_2srcdest(blend_func, src_factor, dest_factor, is_alpha)) {
       /* src*dest + dest*src = 2*src*dest = 0 + dest*(2*src) */
       function->a = MALI_BLEND_OPERAND_A_ZERO;
       function->b = MALI_BLEND_OPERAND_B_DEST;
       function->c = MALI_BLEND_OPERAND_C_SRC_X_2;
    } else {
-      assert(src_factor == dest_factor && invert_src != invert_dest);
+      assert(util_blendfactor_without_invert(src_factor) ==
+                util_blendfactor_without_invert(dest_factor) &&
+             src_inverted != dest_inverted);
 
       function->a = MALI_BLEND_OPERAND_A_DEST;
-      function->invert_c = invert_src;
+      function->invert_c = src_inverted;
       function->c = to_c_factor(src_factor);
 
       switch (blend_func) {
-      case BLEND_FUNC_ADD:
+      case PIPE_BLEND_ADD:
          function->b = MALI_BLEND_OPERAND_B_SRC_MINUS_DEST;
          break;
-      case BLEND_FUNC_REVERSE_SUBTRACT:
+      case PIPE_BLEND_REVERSE_SUBTRACT:
          function->b = MALI_BLEND_OPERAND_B_SRC_PLUS_DEST;
          function->negate_b = true;
          break;
-      case BLEND_FUNC_SUBTRACT:
+      case PIPE_BLEND_SUBTRACT:
          function->b = MALI_BLEND_OPERAND_B_SRC_PLUS_DEST;
          function->negate_a = true;
          break;
@@ -339,32 +290,42 @@ pan_blend_is_opaque(const struct pan_blend_equation equation)
       return true;
 
    /* Also detect open-coded opaque blending */
-   return equation.rgb_src_factor == BLEND_FACTOR_ZERO &&
-          equation.rgb_invert_src_factor &&
-          equation.rgb_dst_factor == BLEND_FACTOR_ZERO &&
-          !equation.rgb_invert_dst_factor &&
-          (equation.rgb_func == BLEND_FUNC_ADD ||
-           equation.rgb_func == BLEND_FUNC_SUBTRACT) &&
-          equation.alpha_src_factor == BLEND_FACTOR_ZERO &&
-          equation.alpha_invert_src_factor &&
-          equation.alpha_dst_factor == BLEND_FACTOR_ZERO &&
-          !equation.alpha_invert_dst_factor &&
-          (equation.alpha_func == BLEND_FUNC_ADD ||
-           equation.alpha_func == BLEND_FUNC_SUBTRACT);
-}
-
-/* Check if (factor, invert) represents a constant value of val, assuming
- * src_alpha is the given constant.
+   return equation.rgb_src_factor == PIPE_BLENDFACTOR_ONE &&
+          equation.rgb_dst_factor == PIPE_BLENDFACTOR_ZERO &&
+          (equation.rgb_func == PIPE_BLEND_ADD ||
+           equation.rgb_func == PIPE_BLEND_SUBTRACT) &&
+          equation.alpha_src_factor == PIPE_BLENDFACTOR_ONE &&
+          equation.alpha_dst_factor == PIPE_BLENDFACTOR_ZERO &&
+          (equation.alpha_func == PIPE_BLEND_ADD ||
+           equation.alpha_func == PIPE_BLEND_SUBTRACT);
+}
+
+/* Check if a factor represents a constant value of val, assuming src_alpha is
+ * the given constant.
  */
 
 static inline bool
-is_factor_01(unsigned factor, bool invert, unsigned val, unsigned srca)
+is_factor_01(enum pipe_blendfactor factor, unsigned val, unsigned srca)
 {
    assert(val == 0 || val == 1);
    assert(srca == 0 || srca == 1);
 
-   return ((invert ^ !val) && factor == BLEND_FACTOR_ZERO) ||
-          ((invert ^ srca ^ !val) && factor == BLEND_FACTOR_SRC_ALPHA);
+   switch (factor) {
+   case PIPE_BLENDFACTOR_ZERO:
+      return (val == 0);
+
+   case PIPE_BLENDFACTOR_ONE:
+      return (val == 1);
+
+   case PIPE_BLENDFACTOR_SRC_ALPHA:
+      return (val == srca);
+
+   case PIPE_BLENDFACTOR_INV_SRC_ALPHA:
+      return (val == (1 - srca));
+
+   default:
+      return false;
+   }
 }
 
 /* Returns if src alpha = 0 implies the blended colour equals the destination
@@ -387,20 +348,20 @@ is_factor_01(unsigned factor, bool invert, unsigned val, unsigned srca)
 bool
 pan_blend_alpha_zero_nop(const struct pan_blend_equation eq)
 {
-   if (eq.rgb_func != BLEND_FUNC_ADD &&
-       eq.rgb_func != BLEND_FUNC_REVERSE_SUBTRACT)
+   if (eq.rgb_func != PIPE_BLEND_ADD &&
+       eq.rgb_func != PIPE_BLEND_REVERSE_SUBTRACT)
       return false;
 
    if (eq.color_mask & 0x8) {
-      if (!is_factor_01(eq.alpha_dst_factor, eq.alpha_invert_dst_factor, 1, 0))
+      if (!is_factor_01(eq.alpha_dst_factor, 1, 0))
          return false;
    }
 
    if (eq.color_mask & 0x7) {
-      if (!is_factor_01(eq.rgb_dst_factor, eq.rgb_invert_dst_factor, 1, 0))
+      if (!is_factor_01(eq.rgb_dst_factor, 1, 0))
          return false;
 
-      if (!is_factor_01(eq.rgb_src_factor, eq.rgb_invert_src_factor, 0, 0))
+      if (!is_factor_01(eq.rgb_src_factor, 0, 0))
          return false;
    }
 
@@ -425,24 +386,26 @@ pan_blend_alpha_zero_nop(const struct pan_blend_equation eq)
 bool
 pan_blend_alpha_one_store(const struct pan_blend_equation eq)
 {
-   if (eq.rgb_func != BLEND_FUNC_ADD && eq.rgb_func != BLEND_FUNC_SUBTRACT)
+   if (eq.rgb_func != PIPE_BLEND_ADD && eq.rgb_func != PIPE_BLEND_SUBTRACT)
       return false;
 
    if (eq.color_mask != 0xf)
       return false;
 
-   return is_factor_01(eq.rgb_src_factor, eq.rgb_invert_src_factor, 1, 1) &&
-          is_factor_01(eq.alpha_src_factor, eq.alpha_invert_src_factor, 1, 1) &&
-          is_factor_01(eq.rgb_dst_factor, eq.rgb_invert_dst_factor, 0, 1) &&
-          is_factor_01(eq.alpha_dst_factor, eq.alpha_invert_dst_factor, 0, 1);
+   return is_factor_01(eq.rgb_src_factor, 1, 1) &&
+          is_factor_01(eq.alpha_src_factor, 1, 1) &&
+          is_factor_01(eq.rgb_dst_factor, 0, 1) &&
+          is_factor_01(eq.alpha_dst_factor, 0, 1);
 }
 
 static bool
-is_dest_factor(enum blend_factor factor, bool alpha)
+is_dest_factor(enum pipe_blendfactor factor, bool alpha)
 {
-   return factor == BLEND_FACTOR_DST_ALPHA ||
-          factor == BLEND_FACTOR_DST_COLOR ||
-          (factor == BLEND_FACTOR_SRC_ALPHA_SATURATE && !alpha);
+   factor = util_blendfactor_without_invert(factor);
+
+   return factor == PIPE_BLENDFACTOR_DST_ALPHA ||
+          factor == PIPE_BLENDFACTOR_DST_COLOR ||
+          (factor == PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE && !alpha);
 }
 
 /* Determines if a blend equation reads back the destination. This can occur by
@@ -452,13 +415,16 @@ is_dest_factor(enum blend_factor factor, bool alpha)
 bool
 pan_blend_reads_dest(const struct pan_blend_equation equation)
 {
-   return (equation.color_mask && equation.color_mask != 0xF) ||
-          is_dest_factor(equation.rgb_src_factor, false) ||
+   if (equation.color_mask && equation.color_mask != 0xF)
+      return true;
+
+   if (!equation.blend_enable)
+      return false;
+
+   return is_dest_factor(equation.rgb_src_factor, false) ||
           is_dest_factor(equation.alpha_src_factor, true) ||
-          equation.rgb_dst_factor != BLEND_FACTOR_ZERO ||
-          equation.rgb_invert_dst_factor ||
-          equation.alpha_dst_factor != BLEND_FACTOR_ZERO ||
-          equation.alpha_invert_dst_factor;
+          equation.rgb_dst_factor != PIPE_BLENDFACTOR_ZERO ||
+          equation.alpha_dst_factor != PIPE_BLENDFACTOR_ZERO;
 }
 
 /* Create the descriptor for a fixed blend mode given the corresponding API
@@ -482,13 +448,10 @@ pan_blend_to_fixed_function_equation(const struct pan_blend_equation equation,
 
    /* Compile the fixed-function blend */
    to_panfrost_function(equation.rgb_func, equation.rgb_src_factor,
-                        equation.rgb_invert_src_factor, equation.rgb_dst_factor,
-                        equation.rgb_invert_dst_factor, false, &out->rgb);
-
+                        equation.rgb_dst_factor, false, &out->rgb);
    to_panfrost_function(equation.alpha_func, equation.alpha_src_factor,
-                        equation.alpha_invert_src_factor,
-                        equation.alpha_dst_factor,
-                        equation.alpha_invert_dst_factor, true, &out->alpha);
+                        equation.alpha_dst_factor, true, &out->alpha);
+
    out->color_mask = equation.color_mask;
 }
 
@@ -583,8 +546,8 @@ get_equation_str(const struct pan_blend_rt_state *rt_state, char *str,
       "add", "sub", "reverse_sub", "min", "max",
    };
    const char *factors[] = {
-      "zero",       "src_color", "src1_color",  "dst_color",   "src_alpha",
-      "src1_alpha", "dst_alpha", "const_color", "const_alpha", "src_alpha_sat",
+      "one",           "src_color",   "src_alpha",   "dst_alpha",  "dst_color",
+      "src_alpha_sat", "const_color", "const_alpha", "src1_color", "src1_alpha",
    };
    int ret;
 
@@ -600,19 +563,21 @@ get_equation_str(const struct pan_blend_rt_state *rt_state, char *str,
 
    if (rt_state->equation.color_mask & 7) {
       assert(rt_state->equation.rgb_func < ARRAY_SIZE(funcs));
-      assert(rt_state->equation.rgb_src_factor < ARRAY_SIZE(factors));
-      assert(rt_state->equation.rgb_dst_factor < ARRAY_SIZE(factors));
-      ret =
-         snprintf(str, len, "%s%s%s(func=%s,src_factor=%s%s,dst_factor=%s%s)%s",
-                  (rt_state->equation.color_mask & 1) ? "R" : "",
-                  (rt_state->equation.color_mask & 2) ? "G" : "",
-                  (rt_state->equation.color_mask & 4) ? "B" : "",
-                  funcs[rt_state->equation.rgb_func],
-                  rt_state->equation.rgb_invert_src_factor ? "-" : "",
-                  factors[rt_state->equation.rgb_src_factor],
-                  rt_state->equation.rgb_invert_dst_factor ? "-" : "",
-                  factors[rt_state->equation.rgb_dst_factor],
-                  rt_state->equation.color_mask & 8 ? ";" : "");
+      ret = snprintf(
+         str, len, "%s%s%s(func=%s,src_factor=%s%s,dst_factor=%s%s)%s",
+         (rt_state->equation.color_mask & 1) ? "R" : "",
+         (rt_state->equation.color_mask & 2) ? "G" : "",
+         (rt_state->equation.color_mask & 4) ? "B" : "",
+         funcs[rt_state->equation.rgb_func],
+         util_blendfactor_is_inverted(rt_state->equation.rgb_src_factor) ? "-"
+                                                                         : "",
+         factors[util_blendfactor_without_invert(
+            rt_state->equation.rgb_src_factor)],
+         util_blendfactor_is_inverted(rt_state->equation.rgb_dst_factor) ? "-"
+                                                                         : "",
+         factors[util_blendfactor_without_invert(
+            rt_state->equation.rgb_dst_factor)],
+         rt_state->equation.color_mask & 8 ? ";" : "");
       assert(ret > 0);
       str += ret;
       len -= ret;
@@ -620,14 +585,17 @@ get_equation_str(const struct pan_blend_rt_state *rt_state, char *str,
 
    if (rt_state->equation.color_mask & 8) {
       assert(rt_state->equation.alpha_func < ARRAY_SIZE(funcs));
-      assert(rt_state->equation.alpha_src_factor < ARRAY_SIZE(factors));
-      assert(rt_state->equation.alpha_dst_factor < ARRAY_SIZE(factors));
-      ret = snprintf(str, len, "A(func=%s,src_factor=%s%s,dst_factor=%s%s)",
-                     funcs[rt_state->equation.alpha_func],
-                     rt_state->equation.alpha_invert_src_factor ? "-" : "",
-                     factors[rt_state->equation.alpha_src_factor],
-                     rt_state->equation.alpha_invert_dst_factor ? "-" : "",
-                     factors[rt_state->equation.alpha_dst_factor]);
+      ret = snprintf(
+         str, len, "A(func=%s,src_factor=%s%s,dst_factor=%s%s)",
+         funcs[rt_state->equation.alpha_func],
+         util_blendfactor_is_inverted(rt_state->equation.alpha_src_factor) ? "-"
+                                                                           : "",
+         factors[util_blendfactor_without_invert(
+            rt_state->equation.alpha_src_factor)],
+         util_blendfactor_is_inverted(rt_state->equation.alpha_dst_factor) ? "-"
+                                                                           : "",
+         factors[util_blendfactor_without_invert(
+            rt_state->equation.alpha_dst_factor)]);
       assert(ret > 0);
       str += ret;
       len -= ret;
@@ -707,21 +675,12 @@ GENX(pan_blend_create_shader)(const struct panfrost_device *dev,
       options.rt[rt].rgb = replace;
       options.rt[rt].alpha = replace;
    } else {
-      options.rt[rt].rgb.func = to_pipe_blend_func(rt_state->equation.rgb_func);
-      options.rt[rt].rgb.src_factor =
-         to_pipe_blendfactor(rt_state->equation.rgb_src_factor,
-                             rt_state->equation.rgb_invert_src_factor);
-      options.rt[rt].rgb.dst_factor =
-         to_pipe_blendfactor(rt_state->equation.rgb_dst_factor,
-                             rt_state->equation.rgb_invert_dst_factor);
-      options.rt[rt].alpha.func =
-         to_pipe_blend_func(rt_state->equation.alpha_func);
-      options.rt[rt].alpha.src_factor =
-         to_pipe_blendfactor(rt_state->equation.alpha_src_factor,
-                             rt_state->equation.alpha_invert_src_factor);
-      options.rt[rt].alpha.dst_factor =
-         to_pipe_blendfactor(rt_state->equation.alpha_dst_factor,
-                             rt_state->equation.alpha_invert_dst_factor);
+      options.rt[rt].rgb.func = rt_state->equation.rgb_func;
+      options.rt[rt].rgb.src_factor = rt_state->equation.rgb_src_factor;
+      options.rt[rt].rgb.dst_factor = rt_state->equation.rgb_dst_factor;
+      options.rt[rt].alpha.func = rt_state->equation.alpha_func;
+      options.rt[rt].alpha.src_factor = rt_state->equation.alpha_src_factor;
+      options.rt[rt].alpha.dst_factor = rt_state->equation.alpha_dst_factor;
    }
 
    nir_ssa_def *pixel = nir_load_barycentric_pixel(&b, 32, .interp_mode = 1);
index 914b9a1..82f8fa2 100644 (file)
@@ -28,7 +28,7 @@
 #include "genxml/gen_macros.h"
 
 #include "compiler/nir/nir.h"
-#include "compiler/shader_enums.h"
+#include "util/blend.h"
 #include "util/format/u_format.h"
 #include "util/u_dynarray.h"
 
@@ -38,18 +38,15 @@ struct MALI_BLEND_EQUATION;
 struct panfrost_device;
 
 struct pan_blend_equation {
-   unsigned blend_enable              : 1;
-   enum blend_func rgb_func           : 3;
-   unsigned rgb_invert_src_factor     : 1;
-   enum blend_factor rgb_src_factor   : 4;
-   unsigned rgb_invert_dst_factor     : 1;
-   enum blend_factor rgb_dst_factor   : 4;
-   enum blend_func alpha_func         : 3;
-   unsigned alpha_invert_src_factor   : 1;
-   enum blend_factor alpha_src_factor : 4;
-   unsigned alpha_invert_dst_factor   : 1;
-   enum blend_factor alpha_dst_factor : 4;
-   unsigned color_mask                : 4;
+   unsigned blend_enable                  : 1;
+   enum pipe_blend_func rgb_func          : 3;
+   enum pipe_blendfactor rgb_src_factor   : 5;
+   enum pipe_blendfactor rgb_dst_factor   : 5;
+   enum pipe_blend_func alpha_func        : 3;
+   enum pipe_blendfactor alpha_src_factor : 5;
+   enum pipe_blendfactor alpha_dst_factor : 5;
+   unsigned color_mask                    : 4;
+   unsigned padding                       : 1;
 };
 
 struct pan_blend_rt_state {
index 2ba301e..11bbfdd 100644 (file)
@@ -62,10 +62,9 @@ static const struct test blend_tests[] = {
          .blend_enable = true,
          .color_mask = 0xF,
 
-         RGBA(func, BLEND_FUNC_ADD),
-         RGBA(src_factor, BLEND_FACTOR_SRC_ALPHA),
-         RGBA(dst_factor, BLEND_FACTOR_SRC_ALPHA),
-         RGBA(invert_dst_factor, true),
+         RGBA(func, PIPE_BLEND_ADD),
+         RGBA(src_factor, PIPE_BLENDFACTOR_SRC_ALPHA),
+         RGBA(dst_factor, PIPE_BLENDFACTOR_INV_SRC_ALPHA),
       },
       .constant_mask = 0x0,
       .reads_dest = true,
@@ -81,11 +80,9 @@ static const struct test blend_tests[] = {
          .blend_enable = true,
          .color_mask = 0xF,
 
-         RGBA(func, BLEND_FUNC_ADD),
-         RGBA(src_factor, BLEND_FACTOR_ZERO),
-         RGBA(dst_factor, BLEND_FACTOR_ZERO),
-         RGBA(invert_src_factor, true),
-         RGBA(invert_dst_factor, true),
+         RGBA(func, PIPE_BLEND_ADD),
+         RGBA(src_factor, PIPE_BLENDFACTOR_ONE),
+         RGBA(dst_factor, PIPE_BLENDFACTOR_ONE),
       },
       .constant_mask = 0x0,
       .reads_dest = true,
@@ -101,10 +98,9 @@ static const struct test blend_tests[] = {
          .blend_enable = true,
          .color_mask = 0xF,
 
-         RGBA(func, BLEND_FUNC_ADD),
-         RGBA(src_factor, BLEND_FACTOR_SRC_ALPHA),
-         RGBA(dst_factor, BLEND_FACTOR_ZERO),
-         RGBA(invert_dst_factor, true),
+         RGBA(func, PIPE_BLEND_ADD),
+         RGBA(src_factor, PIPE_BLENDFACTOR_SRC_ALPHA),
+         RGBA(dst_factor, PIPE_BLENDFACTOR_ONE),
       },
       .constant_mask = 0x0,
       .reads_dest = true,
@@ -120,11 +116,9 @@ static const struct test blend_tests[] = {
          .blend_enable = true,
          .color_mask = 0xF,
 
-         RGBA(func, BLEND_FUNC_SUBTRACT),
-         RGBA(src_factor, BLEND_FACTOR_ZERO),
-         RGBA(dst_factor, BLEND_FACTOR_ZERO),
-         RGBA(invert_src_factor, true),
-         RGBA(invert_dst_factor, true),
+         RGBA(func, PIPE_BLEND_SUBTRACT),
+         RGBA(src_factor, PIPE_BLENDFACTOR_ONE),
+         RGBA(dst_factor, PIPE_BLENDFACTOR_ONE),
       },
       .constant_mask = 0x0,
       .reads_dest = true,
@@ -140,10 +134,9 @@ static const struct test blend_tests[] = {
          .blend_enable = true,
          .color_mask = 0xF,
 
-         RGBA(func, BLEND_FUNC_SUBTRACT),
-         RGBA(src_factor, BLEND_FACTOR_SRC_ALPHA),
-         RGBA(dst_factor, BLEND_FACTOR_ZERO),
-         RGBA(invert_dst_factor, true),
+         RGBA(func, PIPE_BLEND_SUBTRACT),
+         RGBA(src_factor, PIPE_BLENDFACTOR_SRC_ALPHA),
+         RGBA(dst_factor, PIPE_BLENDFACTOR_ONE),
       },
       .constant_mask = 0x0,
       .reads_dest = true,
@@ -159,9 +152,9 @@ static const struct test blend_tests[] = {
          .blend_enable = true,
          .color_mask = 0xF,
 
-         RGBA(func, BLEND_FUNC_ADD),
-         RGBA(src_factor, BLEND_FACTOR_ZERO),
-         RGBA(dst_factor, BLEND_FACTOR_SRC_COLOR),
+         RGBA(func, PIPE_BLEND_ADD),
+         RGBA(src_factor, PIPE_BLENDFACTOR_ZERO),
+         RGBA(dst_factor, PIPE_BLENDFACTOR_SRC_COLOR),
       },
       .constant_mask = 0x0,
       .reads_dest = true,
@@ -191,9 +184,9 @@ static const struct test blend_tests[] = {
          .blend_enable = true,
          .color_mask = 0xA,
 
-         RGBA(func, BLEND_FUNC_ADD),
-         RGBA(src_factor, BLEND_FACTOR_ZERO),
-         RGBA(dst_factor, BLEND_FACTOR_SRC_COLOR),
+         RGBA(func, PIPE_BLEND_ADD),
+         RGBA(src_factor, PIPE_BLENDFACTOR_ZERO),
+         RGBA(dst_factor, PIPE_BLENDFACTOR_SRC_COLOR),
       },
       .constant_mask = 0x0,
       .reads_dest = true,
@@ -209,9 +202,9 @@ static const struct test blend_tests[] = {
          .blend_enable = true,
          .color_mask = 0xF,
 
-         RGBA(func, BLEND_FUNC_ADD),
-         RGBA(src_factor, BLEND_FACTOR_DST_COLOR),
-         RGBA(dst_factor, BLEND_FACTOR_SRC_COLOR),
+         RGBA(func, PIPE_BLEND_ADD),
+         RGBA(src_factor, PIPE_BLENDFACTOR_DST_COLOR),
+         RGBA(dst_factor, PIPE_BLENDFACTOR_SRC_COLOR),
       },
       .constant_mask = 0x0,
       .reads_dest = true,
@@ -227,14 +220,13 @@ static const struct test blend_tests[] = {
          .blend_enable = true,
          .color_mask = 0xC,
 
-         .rgb_func = BLEND_FUNC_ADD,
-         .rgb_src_factor = BLEND_FACTOR_ZERO,
-         .rgb_invert_src_factor = true,
-         .rgb_dst_factor= BLEND_FACTOR_ZERO,
+         .rgb_func = PIPE_BLEND_ADD,
+         .rgb_src_factor = PIPE_BLENDFACTOR_ONE,
+         .rgb_dst_factor= PIPE_BLENDFACTOR_ZERO,
 
-         .alpha_func = BLEND_FUNC_ADD,
-         .alpha_src_factor = BLEND_FACTOR_DST_COLOR,
-         .alpha_dst_factor= BLEND_FACTOR_SRC_COLOR,
+         .alpha_func = PIPE_BLEND_ADD,
+         .alpha_src_factor = PIPE_BLENDFACTOR_DST_COLOR,
+         .alpha_dst_factor= PIPE_BLENDFACTOR_SRC_COLOR,
       },
       .constant_mask = 0x0,
       .reads_dest = true,
@@ -250,14 +242,13 @@ static const struct test blend_tests[] = {
          .blend_enable = true,
          .color_mask = 0xC,
 
-         .rgb_func = BLEND_FUNC_ADD,
-         .rgb_src_factor = BLEND_FACTOR_ZERO,
-         .rgb_invert_src_factor = true,
-         .rgb_dst_factor= BLEND_FACTOR_ZERO,
+         .rgb_func = PIPE_BLEND_ADD,
+         .rgb_src_factor = PIPE_BLENDFACTOR_ONE,
+         .rgb_dst_factor = PIPE_BLENDFACTOR_ZERO,
 
-         .alpha_func = BLEND_FUNC_ADD,
-         .alpha_src_factor = BLEND_FACTOR_DST_ALPHA,
-         .alpha_dst_factor= BLEND_FACTOR_SRC_COLOR,
+         .alpha_func = PIPE_BLEND_ADD,
+         .alpha_src_factor = PIPE_BLENDFACTOR_DST_ALPHA,
+         .alpha_dst_factor= PIPE_BLENDFACTOR_SRC_COLOR,
       },
       .constant_mask = 0x0,
       .reads_dest = true,
@@ -273,14 +264,13 @@ static const struct test blend_tests[] = {
          .blend_enable = true,
          .color_mask = 0xC,
 
-         .rgb_func = BLEND_FUNC_ADD,
-         .rgb_src_factor = BLEND_FACTOR_ZERO,
-         .rgb_invert_src_factor = true,
-         .rgb_dst_factor= BLEND_FACTOR_ZERO,
+         .rgb_func = PIPE_BLEND_ADD,
+         .rgb_src_factor = PIPE_BLENDFACTOR_ONE,
+         .rgb_dst_factor = PIPE_BLENDFACTOR_ZERO,
 
-         .alpha_func = BLEND_FUNC_ADD,
-         .alpha_src_factor = BLEND_FACTOR_DST_ALPHA,
-         .alpha_dst_factor= BLEND_FACTOR_SRC_ALPHA,
+         .alpha_func = PIPE_BLEND_ADD,
+         .alpha_src_factor = PIPE_BLENDFACTOR_DST_ALPHA,
+         .alpha_dst_factor= PIPE_BLENDFACTOR_SRC_ALPHA,
       },
       .constant_mask = 0x0,
       .reads_dest = true,
index 2ab35bb..0459c53 100644 (file)
 #include "nir/nir.h"
 #include "nir/nir_builder.h"
 #include "spirv/nir_spirv.h"
+#include "util/blend.h"
 #include "util/mesa-sha1.h"
 #include "util/u_atomic.h"
 #include "util/u_debug.h"
+#include "vk_blend.h"
 #include "vk_format.h"
 #include "vk_util.h"
 
@@ -391,126 +393,6 @@ panvk_pipeline_builder_parse_input_assembly(
       builder->create_info.gfx->pInputAssemblyState->topology);
 }
 
-static enum pipe_logicop
-translate_logicop(VkLogicOp in)
-{
-   switch (in) {
-   case VK_LOGIC_OP_CLEAR:
-      return PIPE_LOGICOP_CLEAR;
-   case VK_LOGIC_OP_AND:
-      return PIPE_LOGICOP_AND;
-   case VK_LOGIC_OP_AND_REVERSE:
-      return PIPE_LOGICOP_AND_REVERSE;
-   case VK_LOGIC_OP_COPY:
-      return PIPE_LOGICOP_COPY;
-   case VK_LOGIC_OP_AND_INVERTED:
-      return PIPE_LOGICOP_AND_INVERTED;
-   case VK_LOGIC_OP_NO_OP:
-      return PIPE_LOGICOP_NOOP;
-   case VK_LOGIC_OP_XOR:
-      return PIPE_LOGICOP_XOR;
-   case VK_LOGIC_OP_OR:
-      return PIPE_LOGICOP_OR;
-   case VK_LOGIC_OP_NOR:
-      return PIPE_LOGICOP_NOR;
-   case VK_LOGIC_OP_EQUIVALENT:
-      return PIPE_LOGICOP_EQUIV;
-   case VK_LOGIC_OP_INVERT:
-      return PIPE_LOGICOP_INVERT;
-   case VK_LOGIC_OP_OR_REVERSE:
-      return PIPE_LOGICOP_OR_REVERSE;
-   case VK_LOGIC_OP_COPY_INVERTED:
-      return PIPE_LOGICOP_COPY_INVERTED;
-   case VK_LOGIC_OP_OR_INVERTED:
-      return PIPE_LOGICOP_OR_INVERTED;
-   case VK_LOGIC_OP_NAND:
-      return PIPE_LOGICOP_NAND;
-   case VK_LOGIC_OP_SET:
-      return PIPE_LOGICOP_SET;
-   default:
-      unreachable("Invalid logicop");
-   }
-}
-
-static enum blend_func
-translate_blend_op(VkBlendOp in)
-{
-   switch (in) {
-   case VK_BLEND_OP_ADD:
-      return BLEND_FUNC_ADD;
-   case VK_BLEND_OP_SUBTRACT:
-      return BLEND_FUNC_SUBTRACT;
-   case VK_BLEND_OP_REVERSE_SUBTRACT:
-      return BLEND_FUNC_REVERSE_SUBTRACT;
-   case VK_BLEND_OP_MIN:
-      return BLEND_FUNC_MIN;
-   case VK_BLEND_OP_MAX:
-      return BLEND_FUNC_MAX;
-   default:
-      unreachable("Invalid blend op");
-   }
-}
-
-static enum blend_factor
-translate_blend_factor(VkBlendFactor in, bool dest_has_alpha)
-{
-   switch (in) {
-   case VK_BLEND_FACTOR_ZERO:
-   case VK_BLEND_FACTOR_ONE:
-      return BLEND_FACTOR_ZERO;
-   case VK_BLEND_FACTOR_SRC_COLOR:
-   case VK_BLEND_FACTOR_ONE_MINUS_SRC_COLOR:
-      return BLEND_FACTOR_SRC_COLOR;
-   case VK_BLEND_FACTOR_DST_COLOR:
-   case VK_BLEND_FACTOR_ONE_MINUS_DST_COLOR:
-      return BLEND_FACTOR_DST_COLOR;
-   case VK_BLEND_FACTOR_SRC_ALPHA:
-   case VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA:
-      return BLEND_FACTOR_SRC_ALPHA;
-   case VK_BLEND_FACTOR_DST_ALPHA:
-   case VK_BLEND_FACTOR_ONE_MINUS_DST_ALPHA:
-      return dest_has_alpha ? BLEND_FACTOR_DST_ALPHA : BLEND_FACTOR_ZERO;
-   case VK_BLEND_FACTOR_CONSTANT_COLOR:
-   case VK_BLEND_FACTOR_ONE_MINUS_CONSTANT_COLOR:
-      return BLEND_FACTOR_CONSTANT_COLOR;
-   case VK_BLEND_FACTOR_CONSTANT_ALPHA:
-   case VK_BLEND_FACTOR_ONE_MINUS_CONSTANT_ALPHA:
-      return BLEND_FACTOR_CONSTANT_ALPHA;
-   case VK_BLEND_FACTOR_SRC1_COLOR:
-   case VK_BLEND_FACTOR_ONE_MINUS_SRC1_COLOR:
-      return BLEND_FACTOR_SRC1_COLOR;
-   case VK_BLEND_FACTOR_SRC1_ALPHA:
-   case VK_BLEND_FACTOR_ONE_MINUS_SRC1_ALPHA:
-      return BLEND_FACTOR_SRC1_ALPHA;
-   case VK_BLEND_FACTOR_SRC_ALPHA_SATURATE:
-      return BLEND_FACTOR_SRC_ALPHA_SATURATE;
-   default:
-      unreachable("Invalid blend factor");
-   }
-}
-
-static bool
-inverted_blend_factor(VkBlendFactor in, bool dest_has_alpha)
-{
-   switch (in) {
-   case VK_BLEND_FACTOR_ONE:
-   case VK_BLEND_FACTOR_ONE_MINUS_SRC_COLOR:
-   case VK_BLEND_FACTOR_ONE_MINUS_DST_COLOR:
-   case VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA:
-   case VK_BLEND_FACTOR_ONE_MINUS_CONSTANT_COLOR:
-   case VK_BLEND_FACTOR_ONE_MINUS_CONSTANT_ALPHA:
-   case VK_BLEND_FACTOR_ONE_MINUS_SRC1_COLOR:
-   case VK_BLEND_FACTOR_ONE_MINUS_SRC1_ALPHA:
-      return true;
-   case VK_BLEND_FACTOR_ONE_MINUS_DST_ALPHA:
-      return dest_has_alpha ? true : false;
-   case VK_BLEND_FACTOR_DST_ALPHA:
-      return !dest_has_alpha ? true : false;
-   default:
-      return false;
-   }
-}
-
 bool
 panvk_per_arch(blend_needs_lowering)(const struct panfrost_device *dev,
                                      const struct pan_blend_state *state,
@@ -548,7 +430,7 @@ panvk_pipeline_builder_parse_color_blend(struct panvk_pipeline_builder *builder,
    pipeline->blend.state.logicop_enable =
       builder->create_info.gfx->pColorBlendState->logicOpEnable;
    pipeline->blend.state.logicop_func =
-      translate_logicop(builder->create_info.gfx->pColorBlendState->logicOp);
+      vk_logic_op_to_pipe(builder->create_info.gfx->pColorBlendState->logicOp);
    pipeline->blend.state.rt_count =
       util_last_bit(builder->active_color_attachments);
    memcpy(pipeline->blend.state.constants,
@@ -568,24 +450,28 @@ panvk_pipeline_builder_parse_color_blend(struct panvk_pipeline_builder *builder,
          builder->create_info.gfx->pMultisampleState->rasterizationSamples;
       out->equation.blend_enable = in->blendEnable;
       out->equation.color_mask = in->colorWriteMask;
-      out->equation.rgb_func = translate_blend_op(in->colorBlendOp);
+      out->equation.rgb_func = vk_blend_op_to_pipe(in->colorBlendOp);
       out->equation.rgb_src_factor =
-         translate_blend_factor(in->srcColorBlendFactor, dest_has_alpha);
-      out->equation.rgb_invert_src_factor =
-         inverted_blend_factor(in->srcColorBlendFactor, dest_has_alpha);
+         vk_blend_factor_to_pipe(in->srcColorBlendFactor);
       out->equation.rgb_dst_factor =
-         translate_blend_factor(in->dstColorBlendFactor, dest_has_alpha);
-      out->equation.rgb_invert_dst_factor =
-         inverted_blend_factor(in->dstColorBlendFactor, dest_has_alpha);
-      out->equation.alpha_func = translate_blend_op(in->alphaBlendOp);
+         vk_blend_factor_to_pipe(in->dstColorBlendFactor);
+      out->equation.alpha_func = vk_blend_op_to_pipe(in->alphaBlendOp);
       out->equation.alpha_src_factor =
-         translate_blend_factor(in->srcAlphaBlendFactor, dest_has_alpha);
-      out->equation.alpha_invert_src_factor =
-         inverted_blend_factor(in->srcAlphaBlendFactor, dest_has_alpha);
+         vk_blend_factor_to_pipe(in->srcAlphaBlendFactor);
       out->equation.alpha_dst_factor =
-         translate_blend_factor(in->dstAlphaBlendFactor, dest_has_alpha);
-      out->equation.alpha_invert_dst_factor =
-         inverted_blend_factor(in->dstAlphaBlendFactor, dest_has_alpha);
+         vk_blend_factor_to_pipe(in->dstAlphaBlendFactor);
+
+      if (!dest_has_alpha) {
+         out->equation.rgb_src_factor =
+            util_blend_dst_alpha_to_one(out->equation.rgb_src_factor);
+         out->equation.rgb_dst_factor =
+            util_blend_dst_alpha_to_one(out->equation.rgb_dst_factor);
+
+         out->equation.alpha_src_factor =
+            util_blend_dst_alpha_to_one(out->equation.alpha_src_factor);
+         out->equation.alpha_dst_factor =
+            util_blend_dst_alpha_to_one(out->equation.alpha_dst_factor);
+      }
 
       pipeline->blend.reads_dest |= pan_blend_reads_dest(out->equation);
 
index e889799..0fdfd6d 100644 (file)
@@ -120,67 +120,6 @@ panvk_lower_sysvals(nir_builder *b, nir_instr *instr, void *data)
    return true;
 }
 
-static inline enum pipe_blend_func
-to_pipe_blend_func(enum blend_func func)
-{
-   switch (func) {
-   case BLEND_FUNC_ADD:
-      return PIPE_BLEND_ADD;
-   case BLEND_FUNC_SUBTRACT:
-      return PIPE_BLEND_SUBTRACT;
-   case BLEND_FUNC_REVERSE_SUBTRACT:
-      return PIPE_BLEND_REVERSE_SUBTRACT;
-   case BLEND_FUNC_MIN:
-      return PIPE_BLEND_MIN;
-   case BLEND_FUNC_MAX:
-      return PIPE_BLEND_MAX;
-   }
-
-   unreachable("invalid");
-}
-
-static inline enum pipe_blendfactor
-to_pipe_blendfactor_uninverted(enum blend_factor factor)
-{
-   switch (factor) {
-   case BLEND_FACTOR_SRC_COLOR:
-      return PIPE_BLENDFACTOR_SRC_COLOR;
-   case BLEND_FACTOR_SRC1_COLOR:
-      return PIPE_BLENDFACTOR_SRC1_COLOR;
-   case BLEND_FACTOR_DST_COLOR:
-      return PIPE_BLENDFACTOR_DST_COLOR;
-   case BLEND_FACTOR_SRC_ALPHA:
-      return PIPE_BLENDFACTOR_SRC_ALPHA;
-   case BLEND_FACTOR_SRC1_ALPHA:
-      return PIPE_BLENDFACTOR_SRC1_ALPHA;
-   case BLEND_FACTOR_DST_ALPHA:
-      return PIPE_BLENDFACTOR_DST_ALPHA;
-   case BLEND_FACTOR_CONSTANT_COLOR:
-      return PIPE_BLENDFACTOR_CONST_COLOR;
-   case BLEND_FACTOR_CONSTANT_ALPHA:
-      return PIPE_BLENDFACTOR_CONST_ALPHA;
-   case BLEND_FACTOR_SRC_ALPHA_SATURATE:
-      return PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE;
-   default:
-      unreachable("Invalid");
-   }
-}
-
-static inline enum pipe_blendfactor
-to_pipe_blendfactor(enum blend_factor factor, bool inverted)
-{
-   /* Flipped so handle special */
-   if (factor == BLEND_FACTOR_ZERO)
-      return inverted ? PIPE_BLENDFACTOR_ONE : PIPE_BLENDFACTOR_ZERO;
-
-   enum pipe_blendfactor pipe = to_pipe_blendfactor_uninverted(factor);
-
-   if (inverted)
-      pipe |= PIPE_BLENDFACTOR_INVERT_BIT;
-
-   return pipe;
-}
-
 static void
 panvk_lower_blend(struct panfrost_device *pdev, nir_shader *nir,
                   struct panfrost_compile_inputs *inputs,
@@ -214,36 +153,22 @@ panvk_lower_blend(struct panfrost_device *pdev, nir_shader *nir,
          options.rt[rt].rgb = replace;
          options.rt[rt].alpha = replace;
       } else {
-         options.rt[rt].rgb.func =
-            to_pipe_blend_func(rt_state->equation.rgb_func);
-         options.rt[rt].rgb.src_factor =
-            to_pipe_blendfactor(rt_state->equation.rgb_src_factor,
-                                rt_state->equation.rgb_invert_src_factor);
-         options.rt[rt].rgb.dst_factor =
-            to_pipe_blendfactor(rt_state->equation.rgb_dst_factor,
-                                rt_state->equation.rgb_invert_dst_factor);
-         options.rt[rt].alpha.func =
-            to_pipe_blend_func(rt_state->equation.alpha_func);
-         options.rt[rt].alpha.src_factor =
-            to_pipe_blendfactor(rt_state->equation.alpha_src_factor,
-                                rt_state->equation.alpha_invert_src_factor);
-         options.rt[rt].alpha.dst_factor =
-            to_pipe_blendfactor(rt_state->equation.alpha_dst_factor,
-                                rt_state->equation.alpha_invert_dst_factor);
+         options.rt[rt].rgb.func = rt_state->equation.rgb_func;
+         options.rt[rt].rgb.src_factor = rt_state->equation.rgb_src_factor;
+         options.rt[rt].rgb.dst_factor = rt_state->equation.rgb_dst_factor;
+         options.rt[rt].alpha.func = rt_state->equation.alpha_func;
+         options.rt[rt].alpha.src_factor = rt_state->equation.alpha_src_factor;
+         options.rt[rt].alpha.dst_factor = rt_state->equation.alpha_dst_factor;
       }
 
       /* Update the equation to force a color replacement */
       rt_state->equation.color_mask = 0xf;
-      rt_state->equation.rgb_func = BLEND_FUNC_ADD;
-      rt_state->equation.rgb_src_factor = BLEND_FACTOR_ZERO;
-      rt_state->equation.rgb_invert_src_factor = true;
-      rt_state->equation.rgb_dst_factor = BLEND_FACTOR_ZERO;
-      rt_state->equation.rgb_invert_dst_factor = false;
-      rt_state->equation.alpha_func = BLEND_FUNC_ADD;
-      rt_state->equation.alpha_src_factor = BLEND_FACTOR_ZERO;
-      rt_state->equation.alpha_invert_src_factor = true;
-      rt_state->equation.alpha_dst_factor = BLEND_FACTOR_ZERO;
-      rt_state->equation.alpha_invert_dst_factor = false;
+      rt_state->equation.rgb_func = PIPE_BLEND_ADD;
+      rt_state->equation.rgb_src_factor = PIPE_BLENDFACTOR_ONE;
+      rt_state->equation.rgb_dst_factor = PIPE_BLENDFACTOR_ZERO;
+      rt_state->equation.alpha_func = PIPE_BLEND_ADD;
+      rt_state->equation.alpha_src_factor = PIPE_BLENDFACTOR_ONE;
+      rt_state->equation.alpha_dst_factor = PIPE_BLENDFACTOR_ZERO;
       lower_blend = true;
    }