r300g: only check for an empty shader if there are no compile errors
[mesa.git] / src / gallium / drivers / softpipe / sp_tex_tile_cache.c
index b9635bee78bb7e6e238c7afb88b376472f045f79..eb74f14a7bef52597c822e7e73ecd8884f1e0f70 100644 (file)
    
 
 struct softpipe_tex_tile_cache *
-sp_create_tex_tile_cache( struct pipe_screen *screen )
+sp_create_tex_tile_cache( struct pipe_context *pipe )
 {
    struct softpipe_tex_tile_cache *tc;
    uint pos;
 
    tc = CALLOC_STRUCT( softpipe_tex_tile_cache );
    if (tc) {
-      tc->screen = screen;
+      tc->pipe = pipe;
       for (pos = 0; pos < NUM_ENTRIES; pos++) {
          tc->entries[pos].addr.bits.invalid = 1;
       }
@@ -63,22 +63,21 @@ sp_create_tex_tile_cache( struct pipe_screen *screen )
 void
 sp_destroy_tex_tile_cache(struct softpipe_tex_tile_cache *tc)
 {
-   struct pipe_screen *screen;
-   uint pos;
+   if (tc) {
+      uint pos;
 
-   for (pos = 0; pos < NUM_ENTRIES; pos++) {
-      /*assert(tc->entries[pos].x < 0);*/
-   }
-   if (tc->transfer) {
-      screen = tc->transfer->texture->screen;
-      screen->tex_transfer_destroy(tc->transfer);
-   }
-   if (tc->tex_trans) {
-      screen = tc->tex_trans->texture->screen;
-      screen->tex_transfer_destroy(tc->tex_trans);
-   }
+      for (pos = 0; pos < NUM_ENTRIES; pos++) {
+         /*assert(tc->entries[pos].x < 0);*/
+      }
+      if (tc->transfer) {
+         tc->pipe->transfer_destroy(tc->pipe, tc->transfer);
+      }
+      if (tc->tex_trans) {
+         tc->pipe->transfer_destroy(tc->pipe, tc->tex_trans);
+      }
 
-   FREE( tc );
+      FREE( tc );
+   }
 }
 
 
@@ -88,7 +87,7 @@ void
 sp_tex_tile_cache_map_transfers(struct softpipe_tex_tile_cache *tc)
 {
    if (tc->tex_trans && !tc->tex_trans_map)
-      tc->tex_trans_map = tc->screen->transfer_map(tc->screen, tc->tex_trans);
+      tc->tex_trans_map = tc->pipe->transfer_map(tc->pipe, tc->tex_trans);
 }
 
 
@@ -96,7 +95,7 @@ void
 sp_tex_tile_cache_unmap_transfers(struct softpipe_tex_tile_cache *tc)
 {
    if (tc->tex_trans_map) {
-      tc->screen->transfer_unmap(tc->screen, tc->tex_trans);
+      tc->pipe->transfer_unmap(tc->pipe, tc->tex_trans);
       tc->tex_trans_map = NULL;
    }
 }
@@ -118,6 +117,20 @@ sp_tex_tile_cache_validate_texture(struct softpipe_tex_tile_cache *tc)
    }
 }
 
+static boolean
+sp_tex_tile_is_compat_view(struct softpipe_tex_tile_cache *tc,
+                           struct pipe_sampler_view *view)
+{
+   if (!view)
+      return FALSE;
+   return (tc->texture == view->texture &&
+           tc->format == view->format &&
+           tc->swizzle_r == view->swizzle_r &&
+           tc->swizzle_g == view->swizzle_g &&
+           tc->swizzle_b == view->swizzle_b &&
+           tc->swizzle_a == view->swizzle_a);
+}
+
 /**
  * Specify the sampler view to cache.
  */
@@ -125,23 +138,21 @@ void
 sp_tex_tile_cache_set_sampler_view(struct softpipe_tex_tile_cache *tc,
                                    struct pipe_sampler_view *view)
 {
-   struct pipe_texture *texture = view ? view->texture : NULL;
+   struct pipe_resource *texture = view ? view->texture : NULL;
    uint i;
 
    assert(!tc->transfer);
 
-   if (tc->texture != texture) {
-      pipe_texture_reference(&tc->texture, texture);
+   if (!sp_tex_tile_is_compat_view(tc, view)) {
+      pipe_resource_reference(&tc->texture, texture);
 
       if (tc->tex_trans) {
-         struct pipe_screen *screen = tc->tex_trans->texture->screen;
-         
          if (tc->tex_trans_map) {
-            screen->transfer_unmap(screen, tc->tex_trans);
+            tc->pipe->transfer_unmap(tc->pipe, tc->tex_trans);
             tc->tex_trans_map = NULL;
          }
 
-         screen->tex_transfer_destroy(tc->tex_trans);
+         tc->pipe->transfer_destroy(tc->pipe, tc->tex_trans);
          tc->tex_trans = NULL;
       }
 
@@ -150,6 +161,7 @@ sp_tex_tile_cache_set_sampler_view(struct softpipe_tex_tile_cache *tc,
          tc->swizzle_g = view->swizzle_g;
          tc->swizzle_b = view->swizzle_b;
          tc->swizzle_a = view->swizzle_a;
+         tc->format = view->format;
       }
 
       /* mark as entries as invalid/empty */
@@ -212,7 +224,6 @@ const struct softpipe_tex_cached_tile *
 sp_find_cached_tile_tex(struct softpipe_tex_tile_cache *tc, 
                         union tex_tile_address addr )
 {
-   struct pipe_screen *screen = tc->screen;
    struct softpipe_tex_cached_tile *tile;
    
    tile = tc->entries + tex_cache_pos( addr );
@@ -240,24 +251,25 @@ sp_find_cached_tile_tex(struct softpipe_tex_tile_cache *tc,
 
          if (tc->tex_trans) {
             if (tc->tex_trans_map) {
-               tc->screen->transfer_unmap(tc->screen, tc->tex_trans);
+               tc->pipe->transfer_unmap(tc->pipe, tc->tex_trans);
                tc->tex_trans_map = NULL;
             }
 
-            screen->tex_transfer_destroy(tc->tex_trans);
+            tc->pipe->transfer_destroy(tc->pipe, tc->tex_trans);
             tc->tex_trans = NULL;
          }
 
          tc->tex_trans = 
-            screen->get_tex_transfer(screen, tc->texture, 
-                                     addr.bits.face, 
-                                     addr.bits.level, 
-                                     addr.bits.z, 
-                                     PIPE_TRANSFER_READ, 0, 0,
-                                     u_minify(tc->texture->width0, addr.bits.level),
-                                     u_minify(tc->texture->height0, addr.bits.level));
+            pipe_get_transfer(tc->pipe, tc->texture, 
+                             addr.bits.face, 
+                             addr.bits.level, 
+                             addr.bits.z, 
+                             PIPE_TRANSFER_READ | PIPE_TRANSFER_UNSYNCHRONIZED,
+                             0, 0,
+                             u_minify(tc->texture->width0, addr.bits.level),
+                             u_minify(tc->texture->height0, addr.bits.level));
          
-         tc->tex_trans_map = screen->transfer_map(screen, tc->tex_trans);
+         tc->tex_trans_map = tc->pipe->transfer_map(tc->pipe, tc->tex_trans);
 
          tc->tex_face = addr.bits.face;
          tc->tex_level = addr.bits.level;
@@ -265,7 +277,8 @@ sp_find_cached_tile_tex(struct softpipe_tex_tile_cache *tc,
       }
 
       /* get tile from the transfer (view into texture) */
-      pipe_get_tile_swizzle(tc->tex_trans,
+      pipe_get_tile_swizzle(tc->pipe,
+                           tc->tex_trans,
                             addr.bits.x * TILE_SIZE, 
                             addr.bits.y * TILE_SIZE,
                             TILE_SIZE,
@@ -274,6 +287,7 @@ sp_find_cached_tile_tex(struct softpipe_tex_tile_cache *tc,
                             tc->swizzle_g,
                             tc->swizzle_b,
                             tc->swizzle_a,
+                            tc->format,
                             (float *) tile->data.color);
       tile->addr = addr;
    }