Merge branch 'master' of ssh://git.freedesktop.org/git/mesa/mesa into r600_state_predict
[mesa.git] / src / mesa / drivers / dri / i965 / brw_wm_surface_state.c
index 53ce39cfe236ea4a14d9f08a4d56af2efe211ba3..096f74394eb6db3365eb5d939f7b60d1895886e6 100644 (file)
@@ -505,7 +505,7 @@ const struct brw_tracked_state brw_wm_constant_surface = {
 static void
 brw_update_renderbuffer_surface(struct brw_context *brw,
                                struct gl_renderbuffer *rb,
-                               unsigned int unit, GLboolean cached)
+                               unsigned int unit)
 {
    GLcontext *ctx = &brw->intel.ctx;
    dri_bo *region_bo = NULL;
@@ -565,13 +565,11 @@ brw_update_renderbuffer_surface(struct brw_context *brw,
                      ctx->Color.BlendEnabled);
 
    dri_bo_unreference(brw->wm.surf_bo[unit]);
-   brw->wm.surf_bo[unit] = NULL;
-   if (cached) 
-       brw->wm.surf_bo[unit] = brw_search_cache(&brw->surface_cache,
-                                                BRW_SS_SURFACE,
-                                                &key, sizeof(key),
-                                                &region_bo, 1,
-                                                NULL);
+   brw->wm.surf_bo[unit] = brw_search_cache(&brw->surface_cache,
+                                           BRW_SS_SURFACE,
+                                           &key, sizeof(key),
+                                           &region_bo, 1,
+                                           NULL);
 
    if (brw->wm.surf_bo[unit] == NULL) {
       struct brw_surface_state surf;
@@ -580,7 +578,27 @@ brw_update_renderbuffer_surface(struct brw_context *brw,
 
       surf.ss0.surface_format = key.surface_format;
       surf.ss0.surface_type = key.surface_type;
-      surf.ss1.base_addr =  key.draw_offset;
+      if (key.tiling == I915_TILING_NONE) {
+        surf.ss1.base_addr = key.draw_offset;
+      } else {
+        uint32_t tile_offset = key.draw_offset % 4096;
+
+        surf.ss1.base_addr = key.draw_offset - tile_offset;
+
+        assert(BRW_IS_G4X(brw) || tile_offset == 0);
+        if (BRW_IS_G4X(brw)) {
+           if (key.tiling == I915_TILING_X) {
+              /* Note that the low bits of these fields are missing, so
+               * there's the possibility of getting in trouble.
+               */
+              surf.ss5.x_offset = (tile_offset % 512) / key.cpp / 4;
+              surf.ss5.y_offset = tile_offset / 512 / 2;
+           } else {
+              surf.ss5.x_offset = (tile_offset % 128) / key.cpp / 4;
+              surf.ss5.y_offset = tile_offset / 128 / 2;
+           }
+        }
+      }
       if (region_bo != NULL)
         surf.ss1.base_addr += region_bo->offset; /* reloc */
 
@@ -611,7 +629,7 @@ brw_update_renderbuffer_surface(struct brw_context *brw,
         drm_intel_bo_emit_reloc(brw->wm.surf_bo[unit],
                                 offsetof(struct brw_surface_state, ss1),
                                 region_bo,
-                                key.draw_offset,
+                                surf.ss1.base_addr,
                                 I915_GEM_DOMAIN_RENDER,
                                 I915_GEM_DOMAIN_RENDER);
       }
@@ -682,11 +700,10 @@ static void prepare_wm_surfaces(struct brw_context *brw )
       for (i = 0; i < ctx->DrawBuffer->_NumColorDrawBuffers; i++) {
          brw_update_renderbuffer_surface(brw,
                                         ctx->DrawBuffer->_ColorDrawBuffers[i],
-                                        i,
-                                        GL_FALSE);
+                                        i);
       }
    } else {
-      brw_update_renderbuffer_surface(brw, NULL, 0, GL_TRUE);
+      brw_update_renderbuffer_surface(brw, NULL, 0);
    }
 
    old_nr_surfaces = brw->wm.nr_surfaces;
@@ -730,8 +747,7 @@ const struct brw_tracked_state brw_wm_surfaces = {
    .dirty = {
       .mesa = (_NEW_COLOR |
                _NEW_TEXTURE |
-               _NEW_BUFFERS |
-               _NEW_PROGRAM),
+               _NEW_BUFFERS),
       .brw = (BRW_NEW_CONTEXT |
              BRW_NEW_WM_SURFACES),
       .cache = 0