19f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt/*
29f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt Copyright (C) Intel Corp.  2006.  All Rights Reserved.
39f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to
49f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt develop this 3D driver.
59f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
69f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt Permission is hereby granted, free of charge, to any person obtaining
79f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt a copy of this software and associated documentation files (the
89f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt "Software"), to deal in the Software without restriction, including
99f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt without limitation the rights to use, copy, modify, merge, publish,
109f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt distribute, sublicense, and/or sell copies of the Software, and to
119f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt permit persons to whom the Software is furnished to do so, subject to
129f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt the following conditions:
139f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
149f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt The above copyright notice and this permission notice (including the
159f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt next paragraph) shall be included in all copies or substantial
169f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt portions of the Software.
179f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
189f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
199f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
209f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
219f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
229f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
239f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
249f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
259f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
269f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt **********************************************************************/
279f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt /*
289f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt  * Authors:
299f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt  *   Keith Whitwell <keith@tungstengraphics.com>
309f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt  */
319f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
329f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
339f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt#include "brw_context.h"
349f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt#include "brw_state.h"
359f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt#include "brw_defines.h"
369f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt#include "brw_util.h"
37ecadb51bbcb972a79f3ed79e65a7986b9396e757Brian Paul#include "main/macros.h"
383f55683927278e57f3ef8a151d15f4cffdc060dcChris Wilson#include "intel_batchbuffer.h"
399f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
40d67c08319fda7d0f2df98d60b64c8cc2f3e06c44Eric Anholtstatic void
417a874d04a8410a2b778b29ba85797eaf45d96c84Eric Anholtbrw_upload_cc_vp(struct brw_context *brw)
429f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt{
43f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg   struct gl_context *ctx = &brw->intel.ctx;
44d67c08319fda7d0f2df98d60b64c8cc2f3e06c44Eric Anholt   struct brw_cc_viewport *ccv;
459f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
46d375df220fae47f38944c4832bcbd5f5d568884cEric Anholt   ccv = brw_state_batch(brw, AUB_TRACE_CC_VP_STATE,
47d375df220fae47f38944c4832bcbd5f5d568884cEric Anholt			 sizeof(*ccv), 32, &brw->cc.vp_offset);
489f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
49a56a732c6991f47d63f5ccbb27a45467541c43f8Kenneth Graunke   /* _NEW_TRANSFORM */
5092e7c6a2581b5f612a84587500399bb00318c6f0Eric Anholt   if (ctx->Transform.DepthClamp) {
5192e7c6a2581b5f612a84587500399bb00318c6f0Eric Anholt      /* _NEW_VIEWPORT */
52d67c08319fda7d0f2df98d60b64c8cc2f3e06c44Eric Anholt      ccv->min_depth = MIN2(ctx->Viewport.Near, ctx->Viewport.Far);
53d67c08319fda7d0f2df98d60b64c8cc2f3e06c44Eric Anholt      ccv->max_depth = MAX2(ctx->Viewport.Near, ctx->Viewport.Far);
5492e7c6a2581b5f612a84587500399bb00318c6f0Eric Anholt   } else {
55d67c08319fda7d0f2df98d60b64c8cc2f3e06c44Eric Anholt      ccv->min_depth = 0.0;
56d67c08319fda7d0f2df98d60b64c8cc2f3e06c44Eric Anholt      ccv->max_depth = 1.0;
5792e7c6a2581b5f612a84587500399bb00318c6f0Eric Anholt   }
589f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
59d67c08319fda7d0f2df98d60b64c8cc2f3e06c44Eric Anholt   brw->state.dirty.cache |= CACHE_NEW_CC_VP;
609f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt}
619f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
62d67c08319fda7d0f2df98d60b64c8cc2f3e06c44Eric Anholtconst struct brw_tracked_state brw_cc_vp = {
63d67c08319fda7d0f2df98d60b64c8cc2f3e06c44Eric Anholt   .dirty = {
64d67c08319fda7d0f2df98d60b64c8cc2f3e06c44Eric Anholt      .mesa = _NEW_VIEWPORT | _NEW_TRANSFORM,
65d67c08319fda7d0f2df98d60b64c8cc2f3e06c44Eric Anholt      .brw = BRW_NEW_BATCH,
66d67c08319fda7d0f2df98d60b64c8cc2f3e06c44Eric Anholt      .cache = 0
67d67c08319fda7d0f2df98d60b64c8cc2f3e06c44Eric Anholt   },
687a874d04a8410a2b778b29ba85797eaf45d96c84Eric Anholt   .emit = brw_upload_cc_vp
69d67c08319fda7d0f2df98d60b64c8cc2f3e06c44Eric Anholt};
70d67c08319fda7d0f2df98d60b64c8cc2f3e06c44Eric Anholt
71eadd9b8e16e3b1ad35fec54f780a0f94ac43988fIan Romanick/**
72eadd9b8e16e3b1ad35fec54f780a0f94ac43988fIan Romanick * Modify blend function to force destination alpha to 1.0
73eadd9b8e16e3b1ad35fec54f780a0f94ac43988fIan Romanick *
74eadd9b8e16e3b1ad35fec54f780a0f94ac43988fIan Romanick * If \c function specifies a blend function that uses destination alpha,
75eadd9b8e16e3b1ad35fec54f780a0f94ac43988fIan Romanick * replace it with a function that hard-wires destination alpha to 1.0.  This
76eadd9b8e16e3b1ad35fec54f780a0f94ac43988fIan Romanick * is used when rendering to xRGB targets.
77eadd9b8e16e3b1ad35fec54f780a0f94ac43988fIan Romanick */
78eadd9b8e16e3b1ad35fec54f780a0f94ac43988fIan Romanickstatic GLenum
79eadd9b8e16e3b1ad35fec54f780a0f94ac43988fIan Romanickfix_xRGB_alpha(GLenum function)
80eadd9b8e16e3b1ad35fec54f780a0f94ac43988fIan Romanick{
81eadd9b8e16e3b1ad35fec54f780a0f94ac43988fIan Romanick   switch (function) {
82eadd9b8e16e3b1ad35fec54f780a0f94ac43988fIan Romanick   case GL_DST_ALPHA:
83eadd9b8e16e3b1ad35fec54f780a0f94ac43988fIan Romanick      return GL_ONE;
84eadd9b8e16e3b1ad35fec54f780a0f94ac43988fIan Romanick
85eadd9b8e16e3b1ad35fec54f780a0f94ac43988fIan Romanick   case GL_ONE_MINUS_DST_ALPHA:
86eadd9b8e16e3b1ad35fec54f780a0f94ac43988fIan Romanick   case GL_SRC_ALPHA_SATURATE:
87eadd9b8e16e3b1ad35fec54f780a0f94ac43988fIan Romanick      return GL_ZERO;
88eadd9b8e16e3b1ad35fec54f780a0f94ac43988fIan Romanick   }
89eadd9b8e16e3b1ad35fec54f780a0f94ac43988fIan Romanick
90eadd9b8e16e3b1ad35fec54f780a0f94ac43988fIan Romanick   return function;
91eadd9b8e16e3b1ad35fec54f780a0f94ac43988fIan Romanick}
92eadd9b8e16e3b1ad35fec54f780a0f94ac43988fIan Romanick
93b35811e1b38e8fd454f369aefc0b3b3c50ecb8bcEric Anholt/**
94b35811e1b38e8fd454f369aefc0b3b3c50ecb8bcEric Anholt * Creates the state cache entry for the given CC unit key.
95b35811e1b38e8fd454f369aefc0b3b3c50ecb8bcEric Anholt */
967ad26b0030f6b14e6ec069eafdec6faf75e8007cEric Anholtstatic void upload_cc_unit(struct brw_context *brw)
979f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt{
984a0bc4716db7bbcbcd65c0f993704733f47d41f7Eric Anholt   struct intel_context *intel = &brw->intel;
99f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg   struct gl_context *ctx = &brw->intel.ctx;
100df156549e7ce284f0cf887eec1bad9aa1392ebbfChris Wilson   struct brw_cc_unit_state *cc;
101b35811e1b38e8fd454f369aefc0b3b3c50ecb8bcEric Anholt
102d375df220fae47f38944c4832bcbd5f5d568884cEric Anholt   cc = brw_state_batch(brw, AUB_TRACE_CC_STATE,
103d375df220fae47f38944c4832bcbd5f5d568884cEric Anholt			sizeof(*cc), 64, &brw->cc.state_offset);
104df156549e7ce284f0cf887eec1bad9aa1392ebbfChris Wilson   memset(cc, 0, sizeof(*cc));
1059f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
1069f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   /* _NEW_STENCIL */
1077ad26b0030f6b14e6ec069eafdec6faf75e8007cEric Anholt   if (ctx->Stencil._Enabled) {
1087ad26b0030f6b14e6ec069eafdec6faf75e8007cEric Anholt      const unsigned back = ctx->Stencil._BackFace;
1097ad26b0030f6b14e6ec069eafdec6faf75e8007cEric Anholt
110df156549e7ce284f0cf887eec1bad9aa1392ebbfChris Wilson      cc->cc0.stencil_enable = 1;
111df156549e7ce284f0cf887eec1bad9aa1392ebbfChris Wilson      cc->cc0.stencil_func =
1127ad26b0030f6b14e6ec069eafdec6faf75e8007cEric Anholt	 intel_translate_compare_func(ctx->Stencil.Function[0]);
113df156549e7ce284f0cf887eec1bad9aa1392ebbfChris Wilson      cc->cc0.stencil_fail_op =
1147ad26b0030f6b14e6ec069eafdec6faf75e8007cEric Anholt	 intel_translate_stencil_op(ctx->Stencil.FailFunc[0]);
115df156549e7ce284f0cf887eec1bad9aa1392ebbfChris Wilson      cc->cc0.stencil_pass_depth_fail_op =
1167ad26b0030f6b14e6ec069eafdec6faf75e8007cEric Anholt	 intel_translate_stencil_op(ctx->Stencil.ZFailFunc[0]);
117df156549e7ce284f0cf887eec1bad9aa1392ebbfChris Wilson      cc->cc0.stencil_pass_depth_pass_op =
1187ad26b0030f6b14e6ec069eafdec6faf75e8007cEric Anholt	 intel_translate_stencil_op(ctx->Stencil.ZPassFunc[0]);
119df156549e7ce284f0cf887eec1bad9aa1392ebbfChris Wilson      cc->cc1.stencil_ref = ctx->Stencil.Ref[0];
120df156549e7ce284f0cf887eec1bad9aa1392ebbfChris Wilson      cc->cc1.stencil_write_mask = ctx->Stencil.WriteMask[0];
121df156549e7ce284f0cf887eec1bad9aa1392ebbfChris Wilson      cc->cc1.stencil_test_mask = ctx->Stencil.ValueMask[0];
122b35811e1b38e8fd454f369aefc0b3b3c50ecb8bcEric Anholt
1237ad26b0030f6b14e6ec069eafdec6faf75e8007cEric Anholt      if (ctx->Stencil._TestTwoSide) {
124df156549e7ce284f0cf887eec1bad9aa1392ebbfChris Wilson	 cc->cc0.bf_stencil_enable = 1;
125df156549e7ce284f0cf887eec1bad9aa1392ebbfChris Wilson	 cc->cc0.bf_stencil_func =
1267ad26b0030f6b14e6ec069eafdec6faf75e8007cEric Anholt	    intel_translate_compare_func(ctx->Stencil.Function[back]);
127df156549e7ce284f0cf887eec1bad9aa1392ebbfChris Wilson	 cc->cc0.bf_stencil_fail_op =
1287ad26b0030f6b14e6ec069eafdec6faf75e8007cEric Anholt	    intel_translate_stencil_op(ctx->Stencil.FailFunc[back]);
129df156549e7ce284f0cf887eec1bad9aa1392ebbfChris Wilson	 cc->cc0.bf_stencil_pass_depth_fail_op =
1307ad26b0030f6b14e6ec069eafdec6faf75e8007cEric Anholt	    intel_translate_stencil_op(ctx->Stencil.ZFailFunc[back]);
131df156549e7ce284f0cf887eec1bad9aa1392ebbfChris Wilson	 cc->cc0.bf_stencil_pass_depth_pass_op =
1327ad26b0030f6b14e6ec069eafdec6faf75e8007cEric Anholt	    intel_translate_stencil_op(ctx->Stencil.ZPassFunc[back]);
133df156549e7ce284f0cf887eec1bad9aa1392ebbfChris Wilson	 cc->cc1.bf_stencil_ref = ctx->Stencil.Ref[back];
134df156549e7ce284f0cf887eec1bad9aa1392ebbfChris Wilson	 cc->cc2.bf_stencil_write_mask = ctx->Stencil.WriteMask[back];
135df156549e7ce284f0cf887eec1bad9aa1392ebbfChris Wilson	 cc->cc2.bf_stencil_test_mask = ctx->Stencil.ValueMask[back];
1369f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      }
1379f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
1389f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      /* Not really sure about this:
1399f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt       */
1407ad26b0030f6b14e6ec069eafdec6faf75e8007cEric Anholt      if (ctx->Stencil.WriteMask[0] ||
1417ad26b0030f6b14e6ec069eafdec6faf75e8007cEric Anholt	  (ctx->Stencil._TestTwoSide && ctx->Stencil.WriteMask[back]))
142df156549e7ce284f0cf887eec1bad9aa1392ebbfChris Wilson	 cc->cc0.stencil_write_enable = 1;
1439f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   }
1449f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
1459f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   /* _NEW_COLOR */
1462836aab2031d5b6926923fbc70f867ec638301bdIan Romanick   if (ctx->Color.ColorLogicOpEnabled && ctx->Color.LogicOp != GL_COPY) {
147df156549e7ce284f0cf887eec1bad9aa1392ebbfChris Wilson      cc->cc2.logicop_enable = 1;
148df156549e7ce284f0cf887eec1bad9aa1392ebbfChris Wilson      cc->cc5.logicop_func = intel_translate_logic_op(ctx->Color.LogicOp);
1497ad26b0030f6b14e6ec069eafdec6faf75e8007cEric Anholt   } else if (ctx->Color.BlendEnabled) {
15074713e2d293f9e796a4053a5a99ee5cb7df5c740Brian Paul      GLenum eqRGB = ctx->Color.Blend[0].EquationRGB;
15174713e2d293f9e796a4053a5a99ee5cb7df5c740Brian Paul      GLenum eqA = ctx->Color.Blend[0].EquationA;
15274713e2d293f9e796a4053a5a99ee5cb7df5c740Brian Paul      GLenum srcRGB = ctx->Color.Blend[0].SrcRGB;
15374713e2d293f9e796a4053a5a99ee5cb7df5c740Brian Paul      GLenum dstRGB = ctx->Color.Blend[0].DstRGB;
15474713e2d293f9e796a4053a5a99ee5cb7df5c740Brian Paul      GLenum srcA = ctx->Color.Blend[0].SrcA;
15574713e2d293f9e796a4053a5a99ee5cb7df5c740Brian Paul      GLenum dstA = ctx->Color.Blend[0].DstA;
1567ad26b0030f6b14e6ec069eafdec6faf75e8007cEric Anholt
1577ad26b0030f6b14e6ec069eafdec6faf75e8007cEric Anholt      /* If the renderbuffer is XRGB, we have to frob the blend function to
1587ad26b0030f6b14e6ec069eafdec6faf75e8007cEric Anholt       * force the destination alpha to 1.0.  This means replacing GL_DST_ALPHA
1597ad26b0030f6b14e6ec069eafdec6faf75e8007cEric Anholt       * with GL_ONE and GL_ONE_MINUS_DST_ALPHA with GL_ZERO.
1607ad26b0030f6b14e6ec069eafdec6faf75e8007cEric Anholt       */
1617ad26b0030f6b14e6ec069eafdec6faf75e8007cEric Anholt      if (ctx->DrawBuffer->Visual.alphaBits == 0) {
1627ad26b0030f6b14e6ec069eafdec6faf75e8007cEric Anholt	 srcRGB = fix_xRGB_alpha(srcRGB);
1637ad26b0030f6b14e6ec069eafdec6faf75e8007cEric Anholt	 srcA   = fix_xRGB_alpha(srcA);
1647ad26b0030f6b14e6ec069eafdec6faf75e8007cEric Anholt	 dstRGB = fix_xRGB_alpha(dstRGB);
1657ad26b0030f6b14e6ec069eafdec6faf75e8007cEric Anholt	 dstA   = fix_xRGB_alpha(dstA);
1667ad26b0030f6b14e6ec069eafdec6faf75e8007cEric Anholt      }
1679f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
1689f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      if (eqRGB == GL_MIN || eqRGB == GL_MAX) {
1699f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	 srcRGB = dstRGB = GL_ONE;
1709f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      }
1719f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
1729f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      if (eqA == GL_MIN || eqA == GL_MAX) {
1739f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	 srcA = dstA = GL_ONE;
1749f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      }
1759f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
176df156549e7ce284f0cf887eec1bad9aa1392ebbfChris Wilson      cc->cc6.dest_blend_factor = brw_translate_blend_factor(dstRGB);
177df156549e7ce284f0cf887eec1bad9aa1392ebbfChris Wilson      cc->cc6.src_blend_factor = brw_translate_blend_factor(srcRGB);
178df156549e7ce284f0cf887eec1bad9aa1392ebbfChris Wilson      cc->cc6.blend_function = brw_translate_blend_equation(eqRGB);
1799f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
180df156549e7ce284f0cf887eec1bad9aa1392ebbfChris Wilson      cc->cc5.ia_dest_blend_factor = brw_translate_blend_factor(dstA);
181df156549e7ce284f0cf887eec1bad9aa1392ebbfChris Wilson      cc->cc5.ia_src_blend_factor = brw_translate_blend_factor(srcA);
182df156549e7ce284f0cf887eec1bad9aa1392ebbfChris Wilson      cc->cc5.ia_blend_function = brw_translate_blend_equation(eqA);
1839f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
184df156549e7ce284f0cf887eec1bad9aa1392ebbfChris Wilson      cc->cc3.blend_enable = 1;
185df156549e7ce284f0cf887eec1bad9aa1392ebbfChris Wilson      cc->cc3.ia_blend_enable = (srcA != srcRGB ||
186b35811e1b38e8fd454f369aefc0b3b3c50ecb8bcEric Anholt				dstA != dstRGB ||
1879f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt				eqA != eqRGB);
1889f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   }
1899f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
1907ad26b0030f6b14e6ec069eafdec6faf75e8007cEric Anholt   if (ctx->Color.AlphaEnabled) {
191df156549e7ce284f0cf887eec1bad9aa1392ebbfChris Wilson      cc->cc3.alpha_test = 1;
192df156549e7ce284f0cf887eec1bad9aa1392ebbfChris Wilson      cc->cc3.alpha_test_func =
1937ad26b0030f6b14e6ec069eafdec6faf75e8007cEric Anholt	 intel_translate_compare_func(ctx->Color.AlphaFunc);
194df156549e7ce284f0cf887eec1bad9aa1392ebbfChris Wilson      cc->cc3.alpha_test_format = BRW_ALPHATEST_FORMAT_UNORM8;
195b35811e1b38e8fd454f369aefc0b3b3c50ecb8bcEric Anholt
196df156549e7ce284f0cf887eec1bad9aa1392ebbfChris Wilson      UNCLAMPED_FLOAT_TO_UBYTE(cc->cc7.alpha_ref.ub[0], ctx->Color.AlphaRef);
1979f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   }
1989f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
1997ad26b0030f6b14e6ec069eafdec6faf75e8007cEric Anholt   if (ctx->Color.DitherFlag) {
200df156549e7ce284f0cf887eec1bad9aa1392ebbfChris Wilson      cc->cc5.dither_enable = 1;
201df156549e7ce284f0cf887eec1bad9aa1392ebbfChris Wilson      cc->cc6.y_dither_offset = 0;
202df156549e7ce284f0cf887eec1bad9aa1392ebbfChris Wilson      cc->cc6.x_dither_offset = 0;
2039f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   }
2049f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
2059f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   /* _NEW_DEPTH */
2067ad26b0030f6b14e6ec069eafdec6faf75e8007cEric Anholt   if (ctx->Depth.Test) {
207df156549e7ce284f0cf887eec1bad9aa1392ebbfChris Wilson      cc->cc2.depth_test = 1;
208df156549e7ce284f0cf887eec1bad9aa1392ebbfChris Wilson      cc->cc2.depth_test_function =
2097ad26b0030f6b14e6ec069eafdec6faf75e8007cEric Anholt	 intel_translate_compare_func(ctx->Depth.Func);
210df156549e7ce284f0cf887eec1bad9aa1392ebbfChris Wilson      cc->cc2.depth_write_enable = ctx->Depth.Mask;
2119f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   }
212b35811e1b38e8fd454f369aefc0b3b3c50ecb8bcEric Anholt
213bb1540835056cdea5db6f55b19c0c87358f14cd1Eric Anholt   if (intel->stats_wm || unlikely(INTEL_DEBUG & DEBUG_STATS))
214df156549e7ce284f0cf887eec1bad9aa1392ebbfChris Wilson      cc->cc5.statistics_enable = 1;
2154a0bc4716db7bbcbcd65c0f993704733f47d41f7Eric Anholt
2169f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   /* CACHE_NEW_CC_VP */
217d67c08319fda7d0f2df98d60b64c8cc2f3e06c44Eric Anholt   cc->cc4.cc_viewport_state_offset = (intel->batch.bo->offset +
218d67c08319fda7d0f2df98d60b64c8cc2f3e06c44Eric Anholt				       brw->cc.vp_offset) >> 5; /* reloc */
219b35811e1b38e8fd454f369aefc0b3b3c50ecb8bcEric Anholt
2207ad26b0030f6b14e6ec069eafdec6faf75e8007cEric Anholt   brw->state.dirty.cache |= CACHE_NEW_CC_UNIT;
2218abffada70fcd62e3c2dcbcdc6d00d258805326bEric Anholt
2228abffada70fcd62e3c2dcbcdc6d00d258805326bEric Anholt   /* Emit CC viewport relocation */
2238d68a90e225d831a395ba788e425cb717eec1f9aChris Wilson   drm_intel_bo_emit_reloc(brw->intel.batch.bo,
224df156549e7ce284f0cf887eec1bad9aa1392ebbfChris Wilson			   (brw->cc.state_offset +
225df156549e7ce284f0cf887eec1bad9aa1392ebbfChris Wilson			    offsetof(struct brw_cc_unit_state, cc4)),
226d67c08319fda7d0f2df98d60b64c8cc2f3e06c44Eric Anholt			   intel->batch.bo, brw->cc.vp_offset,
227df3c1a563f3d76b07ab82c7b230b0030452f36ffEric Anholt			   I915_GEM_DOMAIN_INSTRUCTION, 0);
22838bad7677e57d629eeffd4ef39a7fc254db12735Eric Anholt}
22938bad7677e57d629eeffd4ef39a7fc254db12735Eric Anholt
2309f344b3e7d6e23674dd4747faec253f103563b36Eric Anholtconst struct brw_tracked_state brw_cc_unit = {
2319f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   .dirty = {
2329f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      .mesa = _NEW_STENCIL | _NEW_COLOR | _NEW_DEPTH,
2337ad26b0030f6b14e6ec069eafdec6faf75e8007cEric Anholt      .brw = BRW_NEW_BATCH,
2349f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      .cache = CACHE_NEW_CC_VP
2359f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   },
2367ad26b0030f6b14e6ec069eafdec6faf75e8007cEric Anholt   .emit = upload_cc_unit,
2379f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt};
2387720bfffa3fd537789b5ded30ecc23afa21dc410Eric Anholt
2397720bfffa3fd537789b5ded30ecc23afa21dc410Eric Anholtstatic void upload_blend_constant_color(struct brw_context *brw)
2407720bfffa3fd537789b5ded30ecc23afa21dc410Eric Anholt{
241aac120977d1ead319141d48d65c9bba626ec03b8Chris Wilson   struct intel_context *intel = &brw->intel;
242aac120977d1ead319141d48d65c9bba626ec03b8Chris Wilson   struct gl_context *ctx = &intel->ctx;
243aac120977d1ead319141d48d65c9bba626ec03b8Chris Wilson
244aac120977d1ead319141d48d65c9bba626ec03b8Chris Wilson   BEGIN_BATCH(5);
245aac120977d1ead319141d48d65c9bba626ec03b8Chris Wilson   OUT_BATCH(_3DSTATE_BLEND_CONSTANT_COLOR << 16 | (5-2));
246d22e2ebe35ef9d33ec5f7a67f903f36bcd9fbc91Eric Anholt   OUT_BATCH_F(ctx->Color.BlendColorUnclamped[0]);
247d22e2ebe35ef9d33ec5f7a67f903f36bcd9fbc91Eric Anholt   OUT_BATCH_F(ctx->Color.BlendColorUnclamped[1]);
248d22e2ebe35ef9d33ec5f7a67f903f36bcd9fbc91Eric Anholt   OUT_BATCH_F(ctx->Color.BlendColorUnclamped[2]);
249d22e2ebe35ef9d33ec5f7a67f903f36bcd9fbc91Eric Anholt   OUT_BATCH_F(ctx->Color.BlendColorUnclamped[3]);
250aac120977d1ead319141d48d65c9bba626ec03b8Chris Wilson   CACHED_BATCH();
2517720bfffa3fd537789b5ded30ecc23afa21dc410Eric Anholt}
2527720bfffa3fd537789b5ded30ecc23afa21dc410Eric Anholt
2537720bfffa3fd537789b5ded30ecc23afa21dc410Eric Anholtconst struct brw_tracked_state brw_blend_constant_color = {
2547720bfffa3fd537789b5ded30ecc23afa21dc410Eric Anholt   .dirty = {
2557720bfffa3fd537789b5ded30ecc23afa21dc410Eric Anholt      .mesa = _NEW_COLOR,
2567720bfffa3fd537789b5ded30ecc23afa21dc410Eric Anholt      .brw = BRW_NEW_CONTEXT,
2577720bfffa3fd537789b5ded30ecc23afa21dc410Eric Anholt      .cache = 0
2587720bfffa3fd537789b5ded30ecc23afa21dc410Eric Anholt   },
2597720bfffa3fd537789b5ded30ecc23afa21dc410Eric Anholt   .emit = upload_blend_constant_color
2607720bfffa3fd537789b5ded30ecc23afa21dc410Eric Anholt};
261