gallium: Add util_blend_uses_dest helper
[mesa.git] / src / gallium / auxiliary / util / u_blend.h
index ed3f7589345d4ce949c4d145480b728df22f7e04..7fccdb26d3168c21fdb64e4ec0cd10ed29ca4aa1 100644 (file)
@@ -82,12 +82,12 @@ util_blend_factor_to_shader(enum pipe_blendfactor factor)
          return BLEND_FACTOR_CONSTANT_ALPHA;
 
       case PIPE_BLENDFACTOR_SRC1_COLOR:
-      case PIPE_BLENDFACTOR_SRC1_ALPHA:
       case PIPE_BLENDFACTOR_INV_SRC1_COLOR:
+         return BLEND_FACTOR_SRC1_COLOR;
+
       case PIPE_BLENDFACTOR_INV_SRC1_ALPHA:
-         /* unimplemented */
-         assert(0);
-         return BLEND_FACTOR_ZERO;
+      case PIPE_BLENDFACTOR_SRC1_ALPHA:
+         return BLEND_FACTOR_SRC1_ALPHA;
 
       default:
          unreachable("Invalid factor");
@@ -114,4 +114,32 @@ util_blend_factor_is_inverted(enum pipe_blendfactor factor)
    }
 }
 
+/* To determine if the destination needs to be read while blending */
+
+static inline bool
+util_blend_factor_uses_dest(enum pipe_blendfactor factor, bool alpha)
+{
+   switch (factor) {
+      case PIPE_BLENDFACTOR_DST_ALPHA:
+      case PIPE_BLENDFACTOR_DST_COLOR:
+      case PIPE_BLENDFACTOR_INV_DST_ALPHA:
+      case PIPE_BLENDFACTOR_INV_DST_COLOR:
+         return true;
+      case PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE:
+         return !alpha;
+      default:
+         return false;
+   }
+}
+
+static inline bool
+util_blend_uses_dest(struct pipe_rt_blend_state rt)
+{
+   return rt.blend_enable &&
+      (util_blend_factor_uses_dest(rt.rgb_src_factor, false) ||
+       util_blend_factor_uses_dest(rt.alpha_src_factor, true) ||
+       rt.rgb_dst_factor != PIPE_BLENDFACTOR_ZERO ||
+       rt.alpha_dst_factor != PIPE_BLENDFACTOR_ZERO);
+}
+
 #endif /* U_BLEND_H */