+ struct gl_context *ctx = &brw->intel.ctx;
+ struct gen6_blend_state *blend;
+ int b;
+ int nr_draw_buffers = ctx->DrawBuffer->_NumColorDrawBuffers;
+ int size;
+
+ /* We need at least one BLEND_STATE written, because we might do
+ * thread dispatch even if _NumColorDrawBuffers is 0 (for example
+ * for computed depth or alpha test), which will do an FB write
+ * with render target 0, which will reference BLEND_STATE[0] for
+ * alpha test enable.
+ */
+ if (nr_draw_buffers == 0 && ctx->Color.AlphaEnabled)
+ nr_draw_buffers = 1;
+
+ size = sizeof(*blend) * nr_draw_buffers;
+ blend = brw_state_batch(brw, size, 64, &brw->cc.blend_state_offset);
+
+ memset(blend, 0, size);
+
+ for (b = 0; b < nr_draw_buffers; b++) {
+ /* _NEW_COLOR */
+ if (ctx->Color._LogicOpEnabled) {
+ struct gl_renderbuffer *rb = ctx->DrawBuffer->_ColorDrawBuffers[b];
+ /* _NEW_BUFFERS */
+ /* Floating point RTs should have no effect from LogicOp,
+ * except for disabling of blending
+ */
+ if (_mesa_get_format_datatype(rb->Format) != GL_FLOAT) {
+ blend[b].blend1.logic_op_enable = 1;
+ blend[b].blend1.logic_op_func =
+ intel_translate_logic_op(ctx->Color.LogicOp);
+ }
+ } else if (ctx->Color.BlendEnabled & (1 << b)) {
+ GLenum eqRGB = ctx->Color.Blend[0].EquationRGB;
+ GLenum eqA = ctx->Color.Blend[0].EquationA;
+ GLenum srcRGB = ctx->Color.Blend[0].SrcRGB;
+ GLenum dstRGB = ctx->Color.Blend[0].DstRGB;
+ GLenum srcA = ctx->Color.Blend[0].SrcA;
+ GLenum dstA = ctx->Color.Blend[0].DstA;
+
+ if (eqRGB == GL_MIN || eqRGB == GL_MAX) {
+ srcRGB = dstRGB = GL_ONE;
+ }
+
+ if (eqA == GL_MIN || eqA == GL_MAX) {
+ srcA = dstA = GL_ONE;
+ }
+
+ blend[b].blend0.dest_blend_factor = brw_translate_blend_factor(dstRGB);
+ blend[b].blend0.source_blend_factor = brw_translate_blend_factor(srcRGB);
+ blend[b].blend0.blend_func = brw_translate_blend_equation(eqRGB);
+
+ blend[b].blend0.ia_dest_blend_factor = brw_translate_blend_factor(dstA);
+ blend[b].blend0.ia_source_blend_factor = brw_translate_blend_factor(srcA);
+ blend[b].blend0.ia_blend_func = brw_translate_blend_equation(eqA);
+
+ blend[b].blend0.blend_enable = 1;
+ blend[b].blend0.ia_blend_enable = (srcA != srcRGB ||
+ dstA != dstRGB ||
+ eqA != eqRGB);
+ }