Merge remote branch 'upstream/gallium-0.1' into nouveau-gallium-0.1
[mesa.git] / src / gallium / drivers / softpipe / sp_tile_cache.c
index dde3fabc81ed7dd9f46dca00066b5c9f958186f4..edafd93d8b88add9e5017366aa6ec96332318eaf 100644 (file)
@@ -39,7 +39,7 @@
 #include "sp_surface.h"
 #include "sp_tile_cache.h"
 
-#define NUM_ENTRIES 30
+#define NUM_ENTRIES 32
 
 
 /** XXX move these */
@@ -156,6 +156,7 @@ sp_tile_cache_set_surface(struct softpipe_tile_cache *tc,
    if (tc->surface_map) {
       /*assert(tc->surface != ps);*/
       pipe_surface_unmap(tc->surface);
+      tc->surface_map = NULL;
    }
 
    pipe_surface_reference(&tc->surface, ps);
@@ -212,14 +213,15 @@ sp_tile_cache_unmap_surfaces(struct softpipe_tile_cache *tc)
  * Specify the texture to cache.
  */
 void
-sp_tile_cache_set_texture(struct softpipe_tile_cache *tc,
+sp_tile_cache_set_texture(struct pipe_context *pipe,
+                          struct softpipe_tile_cache *tc,
                           struct pipe_texture *texture)
 {
    uint i;
 
    assert(!tc->surface);
 
-   tc->texture = texture;
+   pipe_texture_reference(&tc->texture, texture);
 
    if (tc->tex_surf_map) {
       pipe_surface_unmap(tc->tex_surf);
@@ -358,30 +360,37 @@ sp_flush_tile_cache(struct softpipe_context *softpipe,
    struct pipe_surface *ps = tc->surface;
    int inuse = 0, pos;
 
-   if (!ps || !ps->buffer)
-      return;
-
-   for (pos = 0; pos < NUM_ENTRIES; pos++) {
-      struct softpipe_cached_tile *tile = tc->entries + pos;
-      if (tile->x >= 0) {
-         if (tc->depth_stencil) {
-            pipe_put_tile_raw(pipe, ps,
-                           tile->x, tile->y, TILE_SIZE, TILE_SIZE,
-                           tile->data.depth32, 0/*STRIDE*/);
-         }
-         else {
-            pipe_put_tile_rgba(pipe, ps,
-                               tile->x, tile->y, TILE_SIZE, TILE_SIZE,
-                               (float *) tile->data.color);
+   if (ps && ps->buffer) {
+      /* caching a drawing surface */
+      for (pos = 0; pos < NUM_ENTRIES; pos++) {
+         struct softpipe_cached_tile *tile = tc->entries + pos;
+         if (tile->x >= 0) {
+            if (tc->depth_stencil) {
+               pipe_put_tile_raw(pipe, ps,
+                              tile->x, tile->y, TILE_SIZE, TILE_SIZE,
+                              tile->data.depth32, 0/*STRIDE*/);
+            }
+            else {
+               pipe_put_tile_rgba(pipe, ps,
+                                  tile->x, tile->y, TILE_SIZE, TILE_SIZE,
+                                  (float *) tile->data.color);
+            }
+            tile->x = tile->y = -1;  /* mark as empty */
+            inuse++;
          }
-         tile->x = tile->y = -1;  /* mark as empty */
-         inuse++;
       }
-   }
 
 #if TILE_CLEAR_OPTIMIZATION
-   sp_tile_cache_flush_clear(&softpipe->pipe, tc);
+      sp_tile_cache_flush_clear(&softpipe->pipe, tc);
 #endif
+   }
+   else if (tc->texture) {
+      /* caching a texture, mark all entries as embpy */
+      for (pos = 0; pos < NUM_ENTRIES; pos++) {
+         tc->entries[pos].x = -1;
+      }
+      tc->tex_face = -1;
+   }
 
 #if 0
    debug_printf("flushed tiles in use: %d\n", inuse);
@@ -481,6 +490,7 @@ sp_get_cached_tile_tex(struct pipe_context *pipe,
                        struct softpipe_tile_cache *tc, int x, int y, int z,
                        int face, int level)
 {
+   struct pipe_screen *screen = pipe->screen;
    /* tile pos in framebuffer: */
    const int tile_x = x & ~(TILE_SIZE - 1);
    const int tile_y = y & ~(TILE_SIZE - 1);
@@ -506,7 +516,7 @@ sp_get_cached_tile_tex(struct pipe_context *pipe,
         if (tc->tex_surf_map)
             pipe_surface_unmap(tc->tex_surf);
 
-         tc->tex_surf = pipe->get_tex_surface(pipe, tc->texture, face, level, z);
+         tc->tex_surf = screen->get_tex_surface(screen, tc->texture, face, level, z);
          tc->tex_surf_map = pipe_surface_map(tc->tex_surf);
 
          tc->tex_face = face;