17ee590424c974cb10882e9c4664a6024595fc9deEric Anholt/*
27ee590424c974cb10882e9c4664a6024595fc9deEric Anholt * Copyright © 2009 Intel Corporation
37ee590424c974cb10882e9c4664a6024595fc9deEric Anholt *
47ee590424c974cb10882e9c4664a6024595fc9deEric Anholt * Permission is hereby granted, free of charge, to any person obtaining a
57ee590424c974cb10882e9c4664a6024595fc9deEric Anholt * copy of this software and associated documentation files (the "Software"),
67ee590424c974cb10882e9c4664a6024595fc9deEric Anholt * to deal in the Software without restriction, including without limitation
77ee590424c974cb10882e9c4664a6024595fc9deEric Anholt * the rights to use, copy, modify, merge, publish, distribute, sublicense,
87ee590424c974cb10882e9c4664a6024595fc9deEric Anholt * and/or sell copies of the Software, and to permit persons to whom the
97ee590424c974cb10882e9c4664a6024595fc9deEric Anholt * Software is furnished to do so, subject to the following conditions:
107ee590424c974cb10882e9c4664a6024595fc9deEric Anholt *
117ee590424c974cb10882e9c4664a6024595fc9deEric Anholt * The above copyright notice and this permission notice (including the next
127ee590424c974cb10882e9c4664a6024595fc9deEric Anholt * paragraph) shall be included in all copies or substantial portions of the
137ee590424c974cb10882e9c4664a6024595fc9deEric Anholt * Software.
147ee590424c974cb10882e9c4664a6024595fc9deEric Anholt *
157ee590424c974cb10882e9c4664a6024595fc9deEric Anholt * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
167ee590424c974cb10882e9c4664a6024595fc9deEric Anholt * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
177ee590424c974cb10882e9c4664a6024595fc9deEric Anholt * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
187ee590424c974cb10882e9c4664a6024595fc9deEric Anholt * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
197ee590424c974cb10882e9c4664a6024595fc9deEric Anholt * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
207ee590424c974cb10882e9c4664a6024595fc9deEric Anholt * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
217ee590424c974cb10882e9c4664a6024595fc9deEric Anholt * IN THE SOFTWARE.
227ee590424c974cb10882e9c4664a6024595fc9deEric Anholt *
237ee590424c974cb10882e9c4664a6024595fc9deEric Anholt * Authors:
247ee590424c974cb10882e9c4664a6024595fc9deEric Anholt *    Eric Anholt <eric@anholt.net>
257ee590424c974cb10882e9c4664a6024595fc9deEric Anholt *
267ee590424c974cb10882e9c4664a6024595fc9deEric Anholt */
277ee590424c974cb10882e9c4664a6024595fc9deEric Anholt
287ee590424c974cb10882e9c4664a6024595fc9deEric Anholt#include "brw_context.h"
297ee590424c974cb10882e9c4664a6024595fc9deEric Anholt#include "brw_state.h"
307ee590424c974cb10882e9c4664a6024595fc9deEric Anholt#include "brw_defines.h"
317ee590424c974cb10882e9c4664a6024595fc9deEric Anholt#include "brw_util.h"
327ee590424c974cb10882e9c4664a6024595fc9deEric Anholt#include "intel_batchbuffer.h"
33cb099c2ecfe3cf8d8ff21c3031e3c2d43efd0e69Brian Paul#include "main/macros.h"
347ee590424c974cb10882e9c4664a6024595fc9deEric Anholt
357ee590424c974cb10882e9c4664a6024595fc9deEric Anholtstatic void
36f84f3322b44e9828dcbee4791909025369c96f74Eric Anholtgen6_upload_blend_state(struct brw_context *brw)
377ee590424c974cb10882e9c4664a6024595fc9deEric Anholt{
38cd5cd85a43dc43f62274be72d3252503dfc88babAnuj Phogat   bool is_buffer_zero_integer_format = false;
39f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg   struct gl_context *ctx = &brw->intel.ctx;
4035e8fe5c99b285f348cb8a1bba2931f120f7c0a1Eric Anholt   struct gen6_blend_state *blend;
414b4dc778b6289891d18ad62efdea86b060f07061Eric Anholt   int b;
4235e8fe5c99b285f348cb8a1bba2931f120f7c0a1Eric Anholt   int nr_draw_buffers = ctx->DrawBuffer->_NumColorDrawBuffers;
43367020d87ce8c27aeb58b3887fbd29d216fdc151Eric Anholt   int size;
447ee590424c974cb10882e9c4664a6024595fc9deEric Anholt
45367020d87ce8c27aeb58b3887fbd29d216fdc151Eric Anholt   /* We need at least one BLEND_STATE written, because we might do
46367020d87ce8c27aeb58b3887fbd29d216fdc151Eric Anholt    * thread dispatch even if _NumColorDrawBuffers is 0 (for example
47367020d87ce8c27aeb58b3887fbd29d216fdc151Eric Anholt    * for computed depth or alpha test), which will do an FB write
48367020d87ce8c27aeb58b3887fbd29d216fdc151Eric Anholt    * with render target 0, which will reference BLEND_STATE[0] for
49367020d87ce8c27aeb58b3887fbd29d216fdc151Eric Anholt    * alpha test enable.
50367020d87ce8c27aeb58b3887fbd29d216fdc151Eric Anholt    */
51367020d87ce8c27aeb58b3887fbd29d216fdc151Eric Anholt   if (nr_draw_buffers == 0 && ctx->Color.AlphaEnabled)
52367020d87ce8c27aeb58b3887fbd29d216fdc151Eric Anholt      nr_draw_buffers = 1;
53367020d87ce8c27aeb58b3887fbd29d216fdc151Eric Anholt
54367020d87ce8c27aeb58b3887fbd29d216fdc151Eric Anholt   size = sizeof(*blend) * nr_draw_buffers;
55d375df220fae47f38944c4832bcbd5f5d568884cEric Anholt   blend = brw_state_batch(brw, AUB_TRACE_BLEND_STATE,
56d375df220fae47f38944c4832bcbd5f5d568884cEric Anholt			   size, 64, &brw->cc.blend_state_offset);
577ee590424c974cb10882e9c4664a6024595fc9deEric Anholt
5835e8fe5c99b285f348cb8a1bba2931f120f7c0a1Eric Anholt   memset(blend, 0, size);
5935e8fe5c99b285f348cb8a1bba2931f120f7c0a1Eric Anholt
6035e8fe5c99b285f348cb8a1bba2931f120f7c0a1Eric Anholt   for (b = 0; b < nr_draw_buffers; b++) {
6104b4880d7c9a5882100ca6a19d42a8c012b174f6Eric Anholt      /* _NEW_BUFFERS */
6204b4880d7c9a5882100ca6a19d42a8c012b174f6Eric Anholt      struct gl_renderbuffer *rb = ctx->DrawBuffer->_ColorDrawBuffers[b];
6304b4880d7c9a5882100ca6a19d42a8c012b174f6Eric Anholt      GLenum rb_type;
6404b4880d7c9a5882100ca6a19d42a8c012b174f6Eric Anholt      bool integer;
6504b4880d7c9a5882100ca6a19d42a8c012b174f6Eric Anholt
6604b4880d7c9a5882100ca6a19d42a8c012b174f6Eric Anholt      if (rb)
6704b4880d7c9a5882100ca6a19d42a8c012b174f6Eric Anholt	 rb_type = _mesa_get_format_datatype(rb->Format);
6804b4880d7c9a5882100ca6a19d42a8c012b174f6Eric Anholt      else
6904b4880d7c9a5882100ca6a19d42a8c012b174f6Eric Anholt	 rb_type = GL_UNSIGNED_NORMALIZED;
7004b4880d7c9a5882100ca6a19d42a8c012b174f6Eric Anholt
7104b4880d7c9a5882100ca6a19d42a8c012b174f6Eric Anholt      /* Used for implementing the following bit of GL_EXT_texture_integer:
7204b4880d7c9a5882100ca6a19d42a8c012b174f6Eric Anholt       *     "Per-fragment operations that require floating-point color
7304b4880d7c9a5882100ca6a19d42a8c012b174f6Eric Anholt       *      components, including multisample alpha operations, alpha test,
7404b4880d7c9a5882100ca6a19d42a8c012b174f6Eric Anholt       *      blending, and dithering, have no effect when the corresponding
7504b4880d7c9a5882100ca6a19d42a8c012b174f6Eric Anholt       *      colors are written to an integer color buffer."
7604b4880d7c9a5882100ca6a19d42a8c012b174f6Eric Anholt      */
7704b4880d7c9a5882100ca6a19d42a8c012b174f6Eric Anholt      integer = (rb_type == GL_INT || rb_type == GL_UNSIGNED_INT);
7804b4880d7c9a5882100ca6a19d42a8c012b174f6Eric Anholt
79cd5cd85a43dc43f62274be72d3252503dfc88babAnuj Phogat      if(b == 0 && integer)
80cd5cd85a43dc43f62274be72d3252503dfc88babAnuj Phogat         is_buffer_zero_integer_format = true;
81cd5cd85a43dc43f62274be72d3252503dfc88babAnuj Phogat
8235e8fe5c99b285f348cb8a1bba2931f120f7c0a1Eric Anholt      /* _NEW_COLOR */
832836aab2031d5b6926923fbc70f867ec638301bdIan Romanick      if (ctx->Color.ColorLogicOpEnabled) {
846a02679f0120f095d2678eec4532e27e9627b26dEric Anholt	 /* Floating point RTs should have no effect from LogicOp,
85f6e82cd2a18b0edebe3e4102fc93b552e708935aEric Anholt	  * except for disabling of blending.
86f6e82cd2a18b0edebe3e4102fc93b552e708935aEric Anholt	  *
87f6e82cd2a18b0edebe3e4102fc93b552e708935aEric Anholt	  * From the Sandy Bridge PRM, Vol 2 Par 1, Section 8.1.11, "Logic Ops",
88f6e82cd2a18b0edebe3e4102fc93b552e708935aEric Anholt	  *
89f6e82cd2a18b0edebe3e4102fc93b552e708935aEric Anholt	  *     "Logic Ops are only supported on *_UNORM surfaces (excluding
90f6e82cd2a18b0edebe3e4102fc93b552e708935aEric Anholt	  *      _SRGB variants), otherwise Logic Ops must be DISABLED."
916a02679f0120f095d2678eec4532e27e9627b26dEric Anholt	  */
92f6e82cd2a18b0edebe3e4102fc93b552e708935aEric Anholt	 if (rb_type == GL_UNSIGNED_NORMALIZED) {
936a02679f0120f095d2678eec4532e27e9627b26dEric Anholt	    blend[b].blend1.logic_op_enable = 1;
946a02679f0120f095d2678eec4532e27e9627b26dEric Anholt	    blend[b].blend1.logic_op_func =
956a02679f0120f095d2678eec4532e27e9627b26dEric Anholt	       intel_translate_logic_op(ctx->Color.LogicOp);
966a02679f0120f095d2678eec4532e27e9627b26dEric Anholt	 }
9704b4880d7c9a5882100ca6a19d42a8c012b174f6Eric Anholt      } else if (ctx->Color.BlendEnabled & (1 << b) && !integer) {
98b7932e183c15a224adc4b04835f82f3c867a4a24Eric Anholt	 GLenum eqRGB = ctx->Color.Blend[b].EquationRGB;
99b7932e183c15a224adc4b04835f82f3c867a4a24Eric Anholt	 GLenum eqA = ctx->Color.Blend[b].EquationA;
100b7932e183c15a224adc4b04835f82f3c867a4a24Eric Anholt	 GLenum srcRGB = ctx->Color.Blend[b].SrcRGB;
101b7932e183c15a224adc4b04835f82f3c867a4a24Eric Anholt	 GLenum dstRGB = ctx->Color.Blend[b].DstRGB;
102b7932e183c15a224adc4b04835f82f3c867a4a24Eric Anholt	 GLenum srcA = ctx->Color.Blend[b].SrcA;
103b7932e183c15a224adc4b04835f82f3c867a4a24Eric Anholt	 GLenum dstA = ctx->Color.Blend[b].DstA;
1044b4dc778b6289891d18ad62efdea86b060f07061Eric Anholt
1054b4dc778b6289891d18ad62efdea86b060f07061Eric Anholt	 if (eqRGB == GL_MIN || eqRGB == GL_MAX) {
1064b4dc778b6289891d18ad62efdea86b060f07061Eric Anholt	    srcRGB = dstRGB = GL_ONE;
1074b4dc778b6289891d18ad62efdea86b060f07061Eric Anholt	 }
1084b4dc778b6289891d18ad62efdea86b060f07061Eric Anholt
1094b4dc778b6289891d18ad62efdea86b060f07061Eric Anholt	 if (eqA == GL_MIN || eqA == GL_MAX) {
1104b4dc778b6289891d18ad62efdea86b060f07061Eric Anholt	    srcA = dstA = GL_ONE;
1114b4dc778b6289891d18ad62efdea86b060f07061Eric Anholt	 }
1124b4dc778b6289891d18ad62efdea86b060f07061Eric Anholt
1134b4dc778b6289891d18ad62efdea86b060f07061Eric Anholt	 blend[b].blend0.dest_blend_factor = brw_translate_blend_factor(dstRGB);
1144b4dc778b6289891d18ad62efdea86b060f07061Eric Anholt	 blend[b].blend0.source_blend_factor = brw_translate_blend_factor(srcRGB);
1154b4dc778b6289891d18ad62efdea86b060f07061Eric Anholt	 blend[b].blend0.blend_func = brw_translate_blend_equation(eqRGB);
1164b4dc778b6289891d18ad62efdea86b060f07061Eric Anholt
1174b4dc778b6289891d18ad62efdea86b060f07061Eric Anholt	 blend[b].blend0.ia_dest_blend_factor = brw_translate_blend_factor(dstA);
1184b4dc778b6289891d18ad62efdea86b060f07061Eric Anholt	 blend[b].blend0.ia_source_blend_factor = brw_translate_blend_factor(srcA);
1194b4dc778b6289891d18ad62efdea86b060f07061Eric Anholt	 blend[b].blend0.ia_blend_func = brw_translate_blend_equation(eqA);
1204b4dc778b6289891d18ad62efdea86b060f07061Eric Anholt
1214b4dc778b6289891d18ad62efdea86b060f07061Eric Anholt	 blend[b].blend0.blend_enable = 1;
1224b4dc778b6289891d18ad62efdea86b060f07061Eric Anholt	 blend[b].blend0.ia_blend_enable = (srcA != srcRGB ||
1234b4dc778b6289891d18ad62efdea86b060f07061Eric Anholt					 dstA != dstRGB ||
1244b4dc778b6289891d18ad62efdea86b060f07061Eric Anholt					 eqA != eqRGB);
1257ee590424c974cb10882e9c4664a6024595fc9deEric Anholt      }
1267ee590424c974cb10882e9c4664a6024595fc9deEric Anholt
12714ae70f79328fb92886e4ebb5c950b35bcc3b5f5Eric Anholt      /* See section 8.1.6 "Pre-Blend Color Clamping" of the
12814ae70f79328fb92886e4ebb5c950b35bcc3b5f5Eric Anholt       * SandyBridge PRM Volume 2 Part 1 for HW requirements.
12914ae70f79328fb92886e4ebb5c950b35bcc3b5f5Eric Anholt       *
13014ae70f79328fb92886e4ebb5c950b35bcc3b5f5Eric Anholt       * We do our ARB_color_buffer_float CLAMP_FRAGMENT_COLOR
13114ae70f79328fb92886e4ebb5c950b35bcc3b5f5Eric Anholt       * clamping in the fragment shader.  For its clamping of
13214ae70f79328fb92886e4ebb5c950b35bcc3b5f5Eric Anholt       * blending, the spec says:
13314ae70f79328fb92886e4ebb5c950b35bcc3b5f5Eric Anholt       *
13414ae70f79328fb92886e4ebb5c950b35bcc3b5f5Eric Anholt       *     "RESOLVED: For fixed-point color buffers, the inputs and
13514ae70f79328fb92886e4ebb5c950b35bcc3b5f5Eric Anholt       *      the result of the blending equation are clamped.  For
13614ae70f79328fb92886e4ebb5c950b35bcc3b5f5Eric Anholt       *      floating-point color buffers, no clamping occurs."
13714ae70f79328fb92886e4ebb5c950b35bcc3b5f5Eric Anholt       *
13814ae70f79328fb92886e4ebb5c950b35bcc3b5f5Eric Anholt       * So, generally, we want clamping to the render target's range.
13914ae70f79328fb92886e4ebb5c950b35bcc3b5f5Eric Anholt       * And, good news, the hardware tables for both pre- and
14014ae70f79328fb92886e4ebb5c950b35bcc3b5f5Eric Anholt       * post-blend color clamping are either ignored, or any are
14114ae70f79328fb92886e4ebb5c950b35bcc3b5f5Eric Anholt       * allowed, or clamping is required but RT range clamping is a
14214ae70f79328fb92886e4ebb5c950b35bcc3b5f5Eric Anholt       * valid option.
14314ae70f79328fb92886e4ebb5c950b35bcc3b5f5Eric Anholt       */
14414ae70f79328fb92886e4ebb5c950b35bcc3b5f5Eric Anholt      blend[b].blend1.pre_blend_clamp_enable = 1;
14514ae70f79328fb92886e4ebb5c950b35bcc3b5f5Eric Anholt      blend[b].blend1.post_blend_clamp_enable = 1;
14614ae70f79328fb92886e4ebb5c950b35bcc3b5f5Eric Anholt      blend[b].blend1.clamp_range = BRW_RENDERTARGET_CLAMPRANGE_FORMAT;
14735e8fe5c99b285f348cb8a1bba2931f120f7c0a1Eric Anholt
14835e8fe5c99b285f348cb8a1bba2931f120f7c0a1Eric Anholt      /* _NEW_COLOR */
14904b4880d7c9a5882100ca6a19d42a8c012b174f6Eric Anholt      if (ctx->Color.AlphaEnabled && !integer) {
1504b4dc778b6289891d18ad62efdea86b060f07061Eric Anholt	 blend[b].blend1.alpha_test_enable = 1;
15135e8fe5c99b285f348cb8a1bba2931f120f7c0a1Eric Anholt	 blend[b].blend1.alpha_test_func =
15235e8fe5c99b285f348cb8a1bba2931f120f7c0a1Eric Anholt	    intel_translate_compare_func(ctx->Color.AlphaFunc);
1537ee590424c974cb10882e9c4664a6024595fc9deEric Anholt
1544b4dc778b6289891d18ad62efdea86b060f07061Eric Anholt      }
1557ee590424c974cb10882e9c4664a6024595fc9deEric Anholt
15635e8fe5c99b285f348cb8a1bba2931f120f7c0a1Eric Anholt      /* _NEW_COLOR */
15704b4880d7c9a5882100ca6a19d42a8c012b174f6Eric Anholt      if (ctx->Color.DitherFlag && !integer) {
1584b4dc778b6289891d18ad62efdea86b060f07061Eric Anholt	 blend[b].blend1.dither_enable = 1;
1594b4dc778b6289891d18ad62efdea86b060f07061Eric Anholt	 blend[b].blend1.y_dither_offset = 0;
1604b4dc778b6289891d18ad62efdea86b060f07061Eric Anholt	 blend[b].blend1.x_dither_offset = 0;
1614b4dc778b6289891d18ad62efdea86b060f07061Eric Anholt      }
1627ee590424c974cb10882e9c4664a6024595fc9deEric Anholt
16335e8fe5c99b285f348cb8a1bba2931f120f7c0a1Eric Anholt      blend[b].blend1.write_disable_r = !ctx->Color.ColorMask[b][0];
16435e8fe5c99b285f348cb8a1bba2931f120f7c0a1Eric Anholt      blend[b].blend1.write_disable_g = !ctx->Color.ColorMask[b][1];
16535e8fe5c99b285f348cb8a1bba2931f120f7c0a1Eric Anholt      blend[b].blend1.write_disable_b = !ctx->Color.ColorMask[b][2];
16635e8fe5c99b285f348cb8a1bba2931f120f7c0a1Eric Anholt      blend[b].blend1.write_disable_a = !ctx->Color.ColorMask[b][3];
167bc53e14d98de11593788d302c0bb198e3a2097a4Paul Berry
168cd5cd85a43dc43f62274be72d3252503dfc88babAnuj Phogat      /* OpenGL specification 3.3 (page 196), section 4.1.3 says:
169cd5cd85a43dc43f62274be72d3252503dfc88babAnuj Phogat       * "If drawbuffer zero is not NONE and the buffer it references has an
170cd5cd85a43dc43f62274be72d3252503dfc88babAnuj Phogat       * integer format, the SAMPLE_ALPHA_TO_COVERAGE and SAMPLE_ALPHA_TO_ONE
171cd5cd85a43dc43f62274be72d3252503dfc88babAnuj Phogat       * operations are skipped."
172cd5cd85a43dc43f62274be72d3252503dfc88babAnuj Phogat       */
173cd5cd85a43dc43f62274be72d3252503dfc88babAnuj Phogat      if(!is_buffer_zero_integer_format) {
174cd5cd85a43dc43f62274be72d3252503dfc88babAnuj Phogat         /* _NEW_MULTISAMPLE */
175cd5cd85a43dc43f62274be72d3252503dfc88babAnuj Phogat         blend[b].blend1.alpha_to_coverage =
176cd5cd85a43dc43f62274be72d3252503dfc88babAnuj Phogat            ctx->Multisample._Enabled && ctx->Multisample.SampleAlphaToCoverage;
177c566267f5c3b480c1a805790c45fc13ab52c98e2Anuj Phogat
178c566267f5c3b480c1a805790c45fc13ab52c98e2Anuj Phogat	/* From SandyBridge PRM, volume 2 Part 1, section 8.2.3, BLEND_STATE:
179c566267f5c3b480c1a805790c45fc13ab52c98e2Anuj Phogat	 * DWord 1, Bit 30 (AlphaToOne Enable):
180c566267f5c3b480c1a805790c45fc13ab52c98e2Anuj Phogat	 * "If Dual Source Blending is enabled, this bit must be disabled"
181c566267f5c3b480c1a805790c45fc13ab52c98e2Anuj Phogat	 */
182c566267f5c3b480c1a805790c45fc13ab52c98e2Anuj Phogat	 if (ctx->Color.Blend[b]._UsesDualSrc)
183c566267f5c3b480c1a805790c45fc13ab52c98e2Anuj Phogat            blend[b].blend1.alpha_to_one = false;
184c566267f5c3b480c1a805790c45fc13ab52c98e2Anuj Phogat	 else
185c566267f5c3b480c1a805790c45fc13ab52c98e2Anuj Phogat	    blend[b].blend1.alpha_to_one =
186c566267f5c3b480c1a805790c45fc13ab52c98e2Anuj Phogat	       ctx->Multisample._Enabled && ctx->Multisample.SampleAlphaToOne;
187c566267f5c3b480c1a805790c45fc13ab52c98e2Anuj Phogat
188cd5cd85a43dc43f62274be72d3252503dfc88babAnuj Phogat         blend[b].blend1.alpha_to_coverage_dither = (brw->intel.gen >= 7);
189cd5cd85a43dc43f62274be72d3252503dfc88babAnuj Phogat      }
190cd5cd85a43dc43f62274be72d3252503dfc88babAnuj Phogat      else {
191cd5cd85a43dc43f62274be72d3252503dfc88babAnuj Phogat         blend[b].blend1.alpha_to_coverage = false;
192cd5cd85a43dc43f62274be72d3252503dfc88babAnuj Phogat         blend[b].blend1.alpha_to_one = false;
193cd5cd85a43dc43f62274be72d3252503dfc88babAnuj Phogat      }
1947ee590424c974cb10882e9c4664a6024595fc9deEric Anholt   }
1957ee590424c974cb10882e9c4664a6024595fc9deEric Anholt
19635e8fe5c99b285f348cb8a1bba2931f120f7c0a1Eric Anholt   brw->state.dirty.cache |= CACHE_NEW_BLEND_STATE;
1977ee590424c974cb10882e9c4664a6024595fc9deEric Anholt}
1987ee590424c974cb10882e9c4664a6024595fc9deEric Anholt
1997ee590424c974cb10882e9c4664a6024595fc9deEric Anholtconst struct brw_tracked_state gen6_blend_state = {
2007ee590424c974cb10882e9c4664a6024595fc9deEric Anholt   .dirty = {
2016a02679f0120f095d2678eec4532e27e9627b26dEric Anholt      .mesa = (_NEW_COLOR |
202bc53e14d98de11593788d302c0bb198e3a2097a4Paul Berry               _NEW_BUFFERS |
203bc53e14d98de11593788d302c0bb198e3a2097a4Paul Berry               _NEW_MULTISAMPLE),
20435e8fe5c99b285f348cb8a1bba2931f120f7c0a1Eric Anholt      .brw = BRW_NEW_BATCH,
2057ee590424c974cb10882e9c4664a6024595fc9deEric Anholt      .cache = 0,
2067ee590424c974cb10882e9c4664a6024595fc9deEric Anholt   },
207f84f3322b44e9828dcbee4791909025369c96f74Eric Anholt   .emit = gen6_upload_blend_state,
2087ee590424c974cb10882e9c4664a6024595fc9deEric Anholt};
2097ee590424c974cb10882e9c4664a6024595fc9deEric Anholt
2107ee590424c974cb10882e9c4664a6024595fc9deEric Anholtstatic void
211f84f3322b44e9828dcbee4791909025369c96f74Eric Anholtgen6_upload_color_calc_state(struct brw_context *brw)
2127ee590424c974cb10882e9c4664a6024595fc9deEric Anholt{
213f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg   struct gl_context *ctx = &brw->intel.ctx;
2142ee1fd2e8f023853b60c242ce7f83a595c0f65ffEric Anholt   struct gen6_color_calc_state *cc;
2157ee590424c974cb10882e9c4664a6024595fc9deEric Anholt
216d375df220fae47f38944c4832bcbd5f5d568884cEric Anholt   cc = brw_state_batch(brw, AUB_TRACE_CC_STATE,
217d375df220fae47f38944c4832bcbd5f5d568884cEric Anholt			sizeof(*cc), 64, &brw->cc.state_offset);
2182ee1fd2e8f023853b60c242ce7f83a595c0f65ffEric Anholt   memset(cc, 0, sizeof(*cc));
2197ee590424c974cb10882e9c4664a6024595fc9deEric Anholt
2207ee590424c974cb10882e9c4664a6024595fc9deEric Anholt   /* _NEW_COLOR */
2212ee1fd2e8f023853b60c242ce7f83a595c0f65ffEric Anholt   cc->cc0.alpha_test_format = BRW_ALPHATEST_FORMAT_UNORM8;
2222ee1fd2e8f023853b60c242ce7f83a595c0f65ffEric Anholt   UNCLAMPED_FLOAT_TO_UBYTE(cc->cc1.alpha_ref_fi.ui, ctx->Color.AlphaRef);
2237ee590424c974cb10882e9c4664a6024595fc9deEric Anholt
2242ee1fd2e8f023853b60c242ce7f83a595c0f65ffEric Anholt   /* _NEW_STENCIL */
2252ee1fd2e8f023853b60c242ce7f83a595c0f65ffEric Anholt   cc->cc0.stencil_ref = ctx->Stencil.Ref[0];
2262ee1fd2e8f023853b60c242ce7f83a595c0f65ffEric Anholt   cc->cc0.bf_stencil_ref = ctx->Stencil.Ref[ctx->Stencil._BackFace];
2277ee590424c974cb10882e9c4664a6024595fc9deEric Anholt
2282ee1fd2e8f023853b60c242ce7f83a595c0f65ffEric Anholt   /* _NEW_COLOR */
2292ee1fd2e8f023853b60c242ce7f83a595c0f65ffEric Anholt   cc->constant_r = ctx->Color.BlendColorUnclamped[0];
2302ee1fd2e8f023853b60c242ce7f83a595c0f65ffEric Anholt   cc->constant_g = ctx->Color.BlendColorUnclamped[1];
2312ee1fd2e8f023853b60c242ce7f83a595c0f65ffEric Anholt   cc->constant_b = ctx->Color.BlendColorUnclamped[2];
2322ee1fd2e8f023853b60c242ce7f83a595c0f65ffEric Anholt   cc->constant_a = ctx->Color.BlendColorUnclamped[3];
2337ee590424c974cb10882e9c4664a6024595fc9deEric Anholt
2342ee1fd2e8f023853b60c242ce7f83a595c0f65ffEric Anholt   brw->state.dirty.cache |= CACHE_NEW_COLOR_CALC_STATE;
2357ee590424c974cb10882e9c4664a6024595fc9deEric Anholt}
2367ee590424c974cb10882e9c4664a6024595fc9deEric Anholt
2377ee590424c974cb10882e9c4664a6024595fc9deEric Anholtconst struct brw_tracked_state gen6_color_calc_state = {
2387ee590424c974cb10882e9c4664a6024595fc9deEric Anholt   .dirty = {
2399d45c7d1ce0c4ab7c981ddd15b296b2117437fa4Eric Anholt      .mesa = _NEW_COLOR | _NEW_STENCIL,
2402ee1fd2e8f023853b60c242ce7f83a595c0f65ffEric Anholt      .brw = BRW_NEW_BATCH,
2417ee590424c974cb10882e9c4664a6024595fc9deEric Anholt      .cache = 0,
2427ee590424c974cb10882e9c4664a6024595fc9deEric Anholt   },
243f84f3322b44e9828dcbee4791909025369c96f74Eric Anholt   .emit = gen6_upload_color_calc_state,
2447ee590424c974cb10882e9c4664a6024595fc9deEric Anholt};
2457ee590424c974cb10882e9c4664a6024595fc9deEric Anholt
2467ee590424c974cb10882e9c4664a6024595fc9deEric Anholtstatic void upload_cc_state_pointers(struct brw_context *brw)
2477ee590424c974cb10882e9c4664a6024595fc9deEric Anholt{
2487ee590424c974cb10882e9c4664a6024595fc9deEric Anholt   struct intel_context *intel = &brw->intel;
2497ee590424c974cb10882e9c4664a6024595fc9deEric Anholt
2507ee590424c974cb10882e9c4664a6024595fc9deEric Anholt   BEGIN_BATCH(4);
251e31defc825ee94f1d1092e277954abad7097c552Kenneth Graunke   OUT_BATCH(_3DSTATE_CC_STATE_POINTERS << 16 | (4 - 2));
252a82a43e8d99e1715dd11c9c091b5ab734079b6a6Eric Anholt   OUT_BATCH(brw->cc.blend_state_offset | 1);
253a82a43e8d99e1715dd11c9c091b5ab734079b6a6Eric Anholt   OUT_BATCH(brw->cc.depth_stencil_state_offset | 1);
254a82a43e8d99e1715dd11c9c091b5ab734079b6a6Eric Anholt   OUT_BATCH(brw->cc.state_offset | 1);
2557ee590424c974cb10882e9c4664a6024595fc9deEric Anholt   ADVANCE_BATCH();
2567ee590424c974cb10882e9c4664a6024595fc9deEric Anholt}
2577ee590424c974cb10882e9c4664a6024595fc9deEric Anholt
2587ee590424c974cb10882e9c4664a6024595fc9deEric Anholtconst struct brw_tracked_state gen6_cc_state_pointers = {
2597ee590424c974cb10882e9c4664a6024595fc9deEric Anholt   .dirty = {
2607ee590424c974cb10882e9c4664a6024595fc9deEric Anholt      .mesa = 0,
261a09c5c2e3053c48a33134cf28229105bfef52e6fEric Anholt      .brw = (BRW_NEW_BATCH |
262a09c5c2e3053c48a33134cf28229105bfef52e6fEric Anholt	      BRW_NEW_STATE_BASE_ADDRESS),
2637ee590424c974cb10882e9c4664a6024595fc9deEric Anholt      .cache = (CACHE_NEW_BLEND_STATE |
2647ee590424c974cb10882e9c4664a6024595fc9deEric Anholt		CACHE_NEW_COLOR_CALC_STATE |
2657ee590424c974cb10882e9c4664a6024595fc9deEric Anholt		CACHE_NEW_DEPTH_STENCIL_STATE)
2667ee590424c974cb10882e9c4664a6024595fc9deEric Anholt   },
2677ee590424c974cb10882e9c4664a6024595fc9deEric Anholt   .emit = upload_cc_state_pointers,
2687ee590424c974cb10882e9c4664a6024595fc9deEric Anholt};
269