gallium: Add util_blend_factor_uses_dest helper
authorAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Tue, 18 Aug 2020 21:28:38 +0000 (17:28 -0400)
committerMarge Bot <eric+marge@anholt.net>
Mon, 24 Aug 2020 11:42:34 +0000 (11:42 +0000)
Drivers may be able to optimize cases where blending is enabled but the
destination colour is not used. This helps detect that case.

Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Reviewed-by: Eric Anholt <eric@anholt.net>
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6407>

src/gallium/auxiliary/util/u_blend.h

index d5f9050bc32458dc6aecd2c0e51eaecd7e96e00f..7fca2fab6d18594cdf4165cf168342f6a17fb3ca 100644 (file)
@@ -114,4 +114,22 @@ 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;
+   }
+}
+
 #endif /* U_BLEND_H */