i965: Enable L3 caching of buffer surfaces.
[mesa.git] / src / mesa / drivers / dri / i965 / brw_urb.c
index 7673dd36eb90b5e44e6216fbdfb081e8b4b82323..e76db6af976f9246431ef9188d19285a9756e293 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>
   */
-        
+
 
 
 #include "intel_batchbuffer.h"
@@ -97,7 +97,7 @@ static const struct {
 };
 
 
-static GLboolean check_urb_layout( struct brw_context *brw )
+static bool check_urb_layout(struct brw_context *brw)
 {
    brw->urb.vs_start = 0;
    brw->urb.gs_start = brw->urb.nr_vs_entries * brw->urb.vsize;
@@ -105,7 +105,8 @@ static GLboolean check_urb_layout( struct brw_context *brw )
    brw->urb.sf_start = brw->urb.clip_start + brw->urb.nr_clip_entries * brw->urb.vsize;
    brw->urb.cs_start = brw->urb.sf_start + brw->urb.nr_sf_entries * brw->urb.sfsize;
 
-   return brw->urb.cs_start + brw->urb.nr_cs_entries * brw->urb.csize <= URB_SIZES(brw);
+   return brw->urb.cs_start + brw->urb.nr_cs_entries *
+      brw->urb.csize <= brw->urb.size;
 }
 
 /* Most minimal update, forces re-emit of URB fence packet after GS
@@ -114,7 +115,7 @@ static GLboolean check_urb_layout( struct brw_context *brw )
 static void recalculate_urb_fence( struct brw_context *brw )
 {
    GLuint csize = brw->curbe.total_size;
-   GLuint vsize = brw->vs.prog_data->urb_entry_size;
+   GLuint vsize = brw->vs.prog_data->base.urb_entry_size;
    GLuint sfsize = brw->sf.prog_data->urb_entry_size;
 
    if (csize < limits[CS].min_entry_size)
@@ -132,7 +133,7 @@ static void recalculate_urb_fence( struct brw_context *brw )
        (brw->urb.constrained && (brw->urb.vsize > vsize ||
                                 brw->urb.sfsize > sfsize ||
                                 brw->urb.csize > csize))) {
-      
+
 
       brw->urb.csize = csize;
       brw->urb.sfsize = sfsize;
@@ -143,7 +144,29 @@ static void recalculate_urb_fence( struct brw_context *brw )
       brw->urb.nr_clip_entries = limits[CLP].preferred_nr_entries;
       brw->urb.nr_sf_entries = limits[SF].preferred_nr_entries;        
       brw->urb.nr_cs_entries = limits[CS].preferred_nr_entries;        
-      
+
+      brw->urb.constrained = 0;
+
+      if (brw->gen == 5) {
+         brw->urb.nr_vs_entries = 128;
+         brw->urb.nr_sf_entries = 48;
+         if (check_urb_layout(brw)) {
+            goto done;
+         } else {
+            brw->urb.constrained = 1;
+            brw->urb.nr_vs_entries = limits[VS].preferred_nr_entries;
+            brw->urb.nr_sf_entries = limits[SF].preferred_nr_entries;
+         }
+      } else if (brw->is_g4x) {
+        brw->urb.nr_vs_entries = 64;
+        if (check_urb_layout(brw)) {
+           goto done;
+        } else {
+           brw->urb.constrained = 1;
+           brw->urb.nr_vs_entries = limits[VS].preferred_nr_entries;
+        }
+      }
+
       if (!check_urb_layout(brw)) {
         brw->urb.nr_vs_entries = limits[VS].min_nr_entries;    
         brw->urb.nr_gs_entries = limits[GS].min_nr_entries;    
@@ -156,31 +179,31 @@ static void recalculate_urb_fence( struct brw_context *brw )
          * escaping constrained mode and getting back to normal performance.
          */
         brw->urb.constrained = 1;
-        
+       
         if (!check_urb_layout(brw)) {
            /* This is impossible, given the maximal sizes of urb
             * entries and the values for minimum nr of entries
             * provided above.
             */
-           _mesa_printf("couldn't calculate URB layout!\n");
+           fprintf(stderr, "couldn't calculate URB layout!\n");
            exit(1);
         }
-        
-        if (INTEL_DEBUG & (DEBUG_URB|DEBUG_FALLBACKS))
-           _mesa_printf("URB CONSTRAINED\n");
+       
+        if (unlikely(INTEL_DEBUG & (DEBUG_URB|DEBUG_PERF)))
+           fprintf(stderr, "URB CONSTRAINED\n");
       }
-      else 
-        brw->urb.constrained = 0;
-
-      if (INTEL_DEBUG & DEBUG_URB)
-        _mesa_printf("URB fence: %d ..VS.. %d ..GS.. %d ..CLP.. %d ..SF.. %d ..CS.. %d\n",
-                     brw->urb.vs_start,
-                     brw->urb.gs_start,
-                     brw->urb.clip_start,
-                     brw->urb.sf_start,
-                     brw->urb.cs_start, 
-                     URB_SIZES(brw));
-      
+
+done:
+      if (unlikely(INTEL_DEBUG & DEBUG_URB))
+        fprintf(stderr,
+                 "URB fence: %d ..VS.. %d ..GS.. %d ..CLP.. %d ..SF.. %d ..CS.. %d\n",
+                 brw->urb.vs_start,
+                 brw->urb.gs_start,
+                 brw->urb.clip_start,
+                 brw->urb.sf_start,
+                 brw->urb.cs_start,
+                 brw->urb.size);
+
       brw->state.dirty.brw |= BRW_NEW_URB_FENCE;
    }
 }
@@ -189,11 +212,11 @@ static void recalculate_urb_fence( struct brw_context *brw )
 const struct brw_tracked_state brw_recalculate_urb_fence = {
    .dirty = {
       .mesa = 0,
-      .brw = BRW_NEW_CURBE_OFFSETS,
-      .cache = (CACHE_NEW_VS_PROG |
-               CACHE_NEW_SF_PROG)
+      .brw = BRW_NEW_CURBE_OFFSETS |
+             BRW_NEW_SF_PROG_DATA |
+             BRW_NEW_VS_PROG_DATA,
    },
-   .prepare = recalculate_urb_fence
+   .emit = recalculate_urb_fence
 };
 
 
@@ -220,10 +243,18 @@ void brw_upload_urb_fence(struct brw_context *brw)
     * There are 256/384 urb reg pairs in total.
     */
    uf.bits0.vs_fence  = brw->urb.gs_start;
-   uf.bits0.gs_fence  = brw->urb.clip_start; 
-   uf.bits0.clp_fence = brw->urb.sf_start; 
-   uf.bits1.sf_fence  = brw->urb.cs_start; 
-   uf.bits1.cs_fence  = URB_SIZES(brw);
+   uf.bits0.gs_fence  = brw->urb.clip_start;
+   uf.bits0.clp_fence = brw->urb.sf_start;
+   uf.bits1.sf_fence  = brw->urb.cs_start;
+   uf.bits1.cs_fence  = brw->urb.size;
+
+   /* erratum: URB_FENCE must not cross a 64byte cacheline */
+   if ((brw->batch.used & 15) > 12) {
+      int pad = 16 - (brw->batch.used & 15);
+      do
+        brw->batch.map[brw->batch.used++] = MI_NOOP;
+      while (--pad);
+   }
 
    BRW_BATCH_STRUCT(brw, &uf);
 }