/**
 * Similar to sp_get_cached_tile() but for textures.
 * Tiles are read-only and indexed with more params.
 */
const struct softpipe_tex_cached_tile *
sp_find_cached_tile_tex(struct softpipe_tex_tile_cache *tc, 
                        union tex_tile_address addr )
{
   struct softpipe_tex_cached_tile *tile;
   
   tile = tc->entries + tex_cache_pos( addr );

   if (addr.value != tile->addr.value) {

      /* cache miss.  Most misses are because we've invaldiated the
       * texture cache previously -- most commonly on binding a new
       * texture.  Currently we effectively flush the cache on texture
       * bind.
       */
#if 0
      _debug_printf("miss at %u:  x=%d y=%d z=%d face=%d level=%d\n"
                    "   tile %u:  x=%d y=%d z=%d face=%d level=%d\n",
                    pos, x/TILE_SIZE, y/TILE_SIZE, z, face, level,
                    pos, tile->addr.bits.x, tile->addr.bits.y, tile->z, tile->face, tile->level);
#endif

      /* check if we need to get a new transfer */
      if (!tc->tex_trans ||
          tc->tex_face != addr.bits.face ||
          tc->tex_level != addr.bits.level ||
          tc->tex_z != addr.bits.z) {
         /* get new transfer (view into texture) */

         if (tc->tex_trans) {
            if (tc->tex_trans_map) {
               tc->pipe->transfer_unmap(tc->pipe, tc->tex_trans);
               tc->tex_trans_map = NULL;
            }

            tc->pipe->transfer_destroy(tc->pipe, tc->tex_trans);
            tc->tex_trans = NULL;
         }

         tc->tex_trans = 
            pipe_get_transfer(tc->pipe, tc->texture,
                              addr.bits.level,
                              addr.bits.face + 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 = tc->pipe->transfer_map(tc->pipe, tc->tex_trans);

         tc->tex_face = addr.bits.face;
         tc->tex_level = addr.bits.level;
         tc->tex_z = addr.bits.z;
      }

      /* get tile from the transfer (view into texture) */
      pipe_get_tile_swizzle(tc->pipe,
			    tc->tex_trans,
                            addr.bits.x * TILE_SIZE, 
                            addr.bits.y * TILE_SIZE,
                            TILE_SIZE,
                            TILE_SIZE,
                            tc->swizzle_r,
                            tc->swizzle_g,
                            tc->swizzle_b,
                            tc->swizzle_a,
                            tc->format,
                            (float *) tile->data.color);
      tile->addr = addr;
   }

   tc->last_tile = tile;
   return tile;
}
Example #2
0
/**
 * Similar to sp_get_cached_tile() but for textures.
 * Tiles are read-only and indexed with more params.
 */
const struct softpipe_tex_cached_tile *
sp_find_cached_tile_tex(struct softpipe_tex_tile_cache *tc, 
                        union tex_tile_address addr )
{
   struct softpipe_tex_cached_tile *tile;
   boolean zs = util_format_is_depth_or_stencil(tc->format);

   tile = tc->entries + tex_cache_pos( addr );

   if (addr.value != tile->addr.value) {

      /* cache miss.  Most misses are because we've invaldiated the
       * texture cache previously -- most commonly on binding a new
       * texture.  Currently we effectively flush the cache on texture
       * bind.
       */
#if 0
      _debug_printf("miss at %u:  x=%d y=%d z=%d face=%d level=%d\n"
                    "   tile %u:  x=%d y=%d z=%d face=%d level=%d\n",
                    pos, x/TILE_SIZE, y/TILE_SIZE, z, face, level,
                    pos, tile->addr.bits.x, tile->addr.bits.y, tile->z, tile->face, tile->level);
#endif

      /* check if we need to get a new transfer */
      if (!tc->tex_trans ||
          tc->tex_face != addr.bits.face ||
          tc->tex_level != addr.bits.level ||
          tc->tex_z != addr.bits.z) {
         /* get new transfer (view into texture) */
         unsigned width, height, layer;

         if (tc->tex_trans) {
            if (tc->tex_trans_map) {
               tc->pipe->transfer_unmap(tc->pipe, tc->tex_trans);
               tc->tex_trans_map = NULL;
            }

            tc->pipe->transfer_destroy(tc->pipe, tc->tex_trans);
            tc->tex_trans = NULL;
         }

         width = u_minify(tc->texture->width0, addr.bits.level);
         if (tc->texture->target == PIPE_TEXTURE_1D_ARRAY) {
            height = tc->texture->array_size;
            layer = 0;
         }
         else {
            height = u_minify(tc->texture->height0, addr.bits.level);
            layer = addr.bits.face + addr.bits.z;
         }

         tc->tex_trans = 
            pipe_get_transfer(tc->pipe, tc->texture,
                              addr.bits.level,
                              layer,
                              PIPE_TRANSFER_READ | PIPE_TRANSFER_UNSYNCHRONIZED,
                              0, 0, width, height);

         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;
         tc->tex_z = addr.bits.z;
      }

      /* Get tile from the transfer (view into texture), explicitly passing
       * the image format.
       */
      if (!zs && util_format_is_pure_uint(tc->format)) {
         pipe_get_tile_ui_format(tc->pipe,
                                 tc->tex_trans,
                                 addr.bits.x * TILE_SIZE,
                                 addr.bits.y * TILE_SIZE,
                                 TILE_SIZE,
                                 TILE_SIZE,
                                 tc->format,
                                 (unsigned *) tile->data.colorui);
      } else if (!zs && util_format_is_pure_sint(tc->format)) {
         pipe_get_tile_i_format(tc->pipe,
                                tc->tex_trans,
                                addr.bits.x * TILE_SIZE,
                                addr.bits.y * TILE_SIZE,
                                TILE_SIZE,
                                 TILE_SIZE,
                                tc->format,
                                (int *) tile->data.colori);
      } else {
         pipe_get_tile_rgba_format(tc->pipe,
                                   tc->tex_trans,
                                   addr.bits.x * TILE_SIZE,
                                   addr.bits.y * TILE_SIZE,
                                   TILE_SIZE,
                                   TILE_SIZE,
                                   tc->format,
                                   (float *) tile->data.color);
      }
      tile->addr = addr;
   }

   tc->last_tile = tile;
   return tile;
}