[Mesa-dev] [PATCH] i965/blorp: Fix hw blending coefficients
Topi Pohjolainen
topi.pohjolainen at intel.com
Mon Feb 3 11:42:16 CET 2014
Previously the color components where evaluated using formula
(src_color * src_color + 1.0 dst_color) and alpha in turn using
(1.0 * src_alpha + 0.0 * dst_alpha). The intention is to keep
source color components unmodified and force alpha channel to
fixed value of one regardless of source or destination.
If one modifies piglit test gl-3.2-layered-rendering-blit to
use color components values other than zero or one, this change
will kick in on IVB. No regressions on IVB.
CC: Ian Romanick <ian.d.romanick at intel.com>
CC: Kenneth Graunke <kenneth at whitecape.org>
CC: Martin Steigerwald <martin at lichtvoll.de>
CC: Eric Anholt <eric at anholt.net>
CC: mesa-stable at lists.freedesktop.org
Signed-off-by: Topi Pohjolainen <topi.pohjolainen at intel.com>
---
src/mesa/drivers/dri/i965/gen6_blorp.cpp | 22 ++++++++++++++++++++--
1 file changed, 20 insertions(+), 2 deletions(-)
diff --git a/src/mesa/drivers/dri/i965/gen6_blorp.cpp b/src/mesa/drivers/dri/i965/gen6_blorp.cpp
index 90b9fbb..281ea5c 100644
--- a/src/mesa/drivers/dri/i965/gen6_blorp.cpp
+++ b/src/mesa/drivers/dri/i965/gen6_blorp.cpp
@@ -262,15 +262,27 @@ gen6_blorp_emit_blend_state(struct brw_context *brw,
if (params->src.mt &&
_mesa_get_format_bits(params->dst.mt->format, GL_ALPHA_BITS) > 0 &&
_mesa_get_format_bits(params->src.mt->format, GL_ALPHA_BITS) == 0) {
+ /* The blending function cannot be set for the alpha channel alone. It
+ * is an addition to the basic color blending and hence both need to
+ * be enabled explicitly.
+ */
blend->blend0.blend_enable = 1;
blend->blend0.ia_blend_enable = 1;
blend->blend0.blend_func = BRW_BLENDFUNCTION_ADD;
blend->blend0.ia_blend_func = BRW_BLENDFUNCTION_ADD;
- blend->blend0.source_blend_factor = BRW_BLENDFACTOR_SRC_COLOR;
+ /* Only alpha channel needs adjusting whereas the color components are
+ * to be evaluated regardless of the existing destination value. This
+ * can be achieved using formula: 1.0 * src_color + 0.0 * dst_color.
+ */
+ blend->blend0.source_blend_factor = BRW_BLENDFACTOR_ONE;
blend->blend0.dest_blend_factor = BRW_BLENDFACTOR_ZERO;
- blend->blend0.ia_source_blend_factor = BRW_BLENDFACTOR_ONE;
+ /* Forces alpha to fixed value of one by ignoring source value explicitly
+ * by replacing it with the constant one. The existing destination value
+ * in turn is ignored by using multiplier of zero: 1.0 + 0.0 * dst_color.
+ */
+ blend->blend0.ia_source_blend_factor = BRW_BLENDFACTOR_CONST_ALPHA;
blend->blend0.ia_dest_blend_factor = BRW_BLENDFACTOR_ZERO;
}
@@ -291,6 +303,12 @@ gen6_blorp_emit_cc_state(struct brw_context *brw,
&cc_state_offset);
memset(cc, 0, sizeof(*cc));
+ /* When using hw color blending for forcing alpha channel to one independent
+ * of the source, the blender is told to refer to the constant table here
+ * for the fixed value.
+ */
+ cc->constant_a = 1.0;
+
return cc_state_offset;
}
--
1.8.3.1
More information about the mesa-dev
mailing list