i965/vec4: Init mlen for several send from GRF instructions.
[mesa.git] / src / mesa / drivers / dri / i965 / brw_cc.c
index 698af6db87c19bc087a796e7cf6d23d21f8eb4fa..02f5a3a76fb3e31a6f1ed4ccdea0eb9868cfa3a9 100644 (file)
@@ -1,8 +1,8 @@
 /*
  Copyright (C) Intel Corp.  2006.  All Rights Reserved.
- Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to
+ Intel funded Tungsten Graphics to
  develop this 3D driver.
+
  Permission is hereby granted, free of charge, to any person obtaining
  a copy of this software and associated documentation files (the
  "Software"), to deal in the Software without restriction, including
  distribute, sublicense, and/or sell copies of the Software, and to
  permit persons to whom the Software is furnished to do so, subject to
  the following conditions:
+
  The above copyright notice and this permission notice (including the
  next paragraph) shall be included in all copies or substantial
  portions of the Software.
+
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
  **********************************************************************/
  /*
   * Authors:
-  *   Keith Whitwell <keith@tungstengraphics.com>
+  *   Keith Whitwell <keithw@vmware.com>
   */
 
 
 static void
 brw_upload_cc_vp(struct brw_context *brw)
 {
-   struct gl_context *ctx = &brw->intel.ctx;
+   struct gl_context *ctx = &brw->ctx;
    struct brw_cc_viewport *ccv;
 
    ccv = brw_state_batch(brw, AUB_TRACE_CC_VP_STATE,
-                        sizeof(*ccv), 32, &brw->cc.vp_offset);
+                        sizeof(*ccv) * ctx->Const.MaxViewports, 32,
+                         &brw->cc.vp_offset);
 
    /* _NEW_TRANSFORM */
-   if (ctx->Transform.DepthClamp) {
-      /* _NEW_VIEWPORT */
-      ccv->min_depth = MIN2(ctx->Viewport.Near, ctx->Viewport.Far);
-      ccv->max_depth = MAX2(ctx->Viewport.Near, ctx->Viewport.Far);
-   } else {
-      ccv->min_depth = 0.0;
-      ccv->max_depth = 1.0;
+   for (unsigned i = 0; i < ctx->Const.MaxViewports; i++) {
+      if (ctx->Transform.DepthClamp) {
+         /* _NEW_VIEWPORT */
+         ccv[i].min_depth = MIN2(ctx->ViewportArray[i].Near,
+                                 ctx->ViewportArray[i].Far);
+         ccv[i].max_depth = MAX2(ctx->ViewportArray[i].Near,
+                                 ctx->ViewportArray[i].Far);
+      } else {
+         ccv[i].min_depth = 0.0;
+         ccv[i].max_depth = 1.0;
+      }
    }
 
-   brw->state.dirty.cache |= CACHE_NEW_CC_VP;
+   if (brw->gen >= 7) {
+      BEGIN_BATCH(2);
+      OUT_BATCH(_3DSTATE_VIEWPORT_STATE_POINTERS_CC << 16 | (2 - 2));
+      OUT_BATCH(brw->cc.vp_offset);
+      ADVANCE_BATCH();
+   } else {
+      brw->state.dirty.brw |= BRW_NEW_CC_VP;
+   }
 }
 
 const struct brw_tracked_state brw_cc_vp = {
    .dirty = {
-      .mesa = _NEW_VIEWPORT | _NEW_TRANSFORM,
+      .mesa = _NEW_TRANSFORM |
+              _NEW_VIEWPORT,
       .brw = BRW_NEW_BATCH,
-      .cache = 0
    },
    .emit = brw_upload_cc_vp
 };
@@ -92,12 +104,11 @@ brw_fix_xRGB_alpha(GLenum function)
 }
 
 /**
- * Creates the state cache entry for the given CC unit key.
+ * Creates a CC unit packet from the current blend state.
  */
 static void upload_cc_unit(struct brw_context *brw)
 {
-   struct intel_context *intel = &brw->intel;
-   struct gl_context *ctx = &brw->intel.ctx;
+   struct gl_context *ctx = &brw->ctx;
    struct brw_cc_unit_state *cc;
 
    cc = brw_state_batch(brw, AUB_TRACE_CC_STATE,
@@ -188,7 +199,8 @@ static void upload_cc_unit(struct brw_context *brw)
                                eqA != eqRGB);
    }
 
-   if (ctx->Color.AlphaEnabled) {
+   /* _NEW_BUFFERS */
+   if (ctx->Color.AlphaEnabled && ctx->DrawBuffer->_NumColorDrawBuffers <= 1) {
       cc->cc3.alpha_test = 1;
       cc->cc3.alpha_test_func =
         intel_translate_compare_func(ctx->Color.AlphaFunc);
@@ -211,36 +223,39 @@ static void upload_cc_unit(struct brw_context *brw)
       cc->cc2.depth_write_enable = ctx->Depth.Mask;
    }
 
-   if (intel->stats_wm || unlikely(INTEL_DEBUG & DEBUG_STATS))
+   if (brw->stats_wm || unlikely(INTEL_DEBUG & DEBUG_STATS))
       cc->cc5.statistics_enable = 1;
 
-   /* CACHE_NEW_CC_VP */
-   cc->cc4.cc_viewport_state_offset = (intel->batch.bo->offset +
+   /* BRW_NEW_CC_VP */
+   cc->cc4.cc_viewport_state_offset = (brw->batch.bo->offset64 +
                                       brw->cc.vp_offset) >> 5; /* reloc */
 
-   brw->state.dirty.cache |= CACHE_NEW_CC_UNIT;
+   brw->state.dirty.brw |= BRW_NEW_GEN4_UNIT_STATE;
 
    /* Emit CC viewport relocation */
-   drm_intel_bo_emit_reloc(brw->intel.batch.bo,
+   drm_intel_bo_emit_reloc(brw->batch.bo,
                           (brw->cc.state_offset +
                            offsetof(struct brw_cc_unit_state, cc4)),
-                          intel->batch.bo, brw->cc.vp_offset,
+                          brw->batch.bo, brw->cc.vp_offset,
                           I915_GEM_DOMAIN_INSTRUCTION, 0);
 }
 
 const struct brw_tracked_state brw_cc_unit = {
    .dirty = {
-      .mesa = _NEW_STENCIL | _NEW_COLOR | _NEW_DEPTH | _NEW_BUFFERS,
-      .brw = BRW_NEW_BATCH | BRW_NEW_STATS_WM,
-      .cache = CACHE_NEW_CC_VP
+      .mesa = _NEW_BUFFERS |
+              _NEW_COLOR |
+              _NEW_DEPTH |
+              _NEW_STENCIL,
+      .brw = BRW_NEW_BATCH |
+             BRW_NEW_CC_VP |
+             BRW_NEW_STATS_WM,
    },
    .emit = upload_cc_unit,
 };
 
 static void upload_blend_constant_color(struct brw_context *brw)
 {
-   struct intel_context *intel = &brw->intel;
-   struct gl_context *ctx = &intel->ctx;
+   struct gl_context *ctx = &brw->ctx;
 
    BEGIN_BATCH(5);
    OUT_BATCH(_3DSTATE_BLEND_CONSTANT_COLOR << 16 | (5-2));
@@ -248,14 +263,13 @@ static void upload_blend_constant_color(struct brw_context *brw)
    OUT_BATCH_F(ctx->Color.BlendColorUnclamped[1]);
    OUT_BATCH_F(ctx->Color.BlendColorUnclamped[2]);
    OUT_BATCH_F(ctx->Color.BlendColorUnclamped[3]);
-   CACHED_BATCH();
+   ADVANCE_BATCH();
 }
 
 const struct brw_tracked_state brw_blend_constant_color = {
    .dirty = {
       .mesa = _NEW_COLOR,
       .brw = BRW_NEW_CONTEXT,
-      .cache = 0
    },
    .emit = upload_blend_constant_color
 };