/**
 * Get a tile from the cache.
 * \param x, y  position of tile, in pixels
 */
struct softpipe_cached_tile *
sp_find_cached_tile(struct softpipe_tile_cache *tc, 
                    union tile_address addr )
{
   struct pipe_transfer *pt = tc->transfer;
   
   /* cache pos/entry: */
   const int pos = CACHE_POS(addr.bits.x,
                             addr.bits.y);
   struct softpipe_cached_tile *tile = tc->entries + pos;

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

      assert(pt->resource);
      if (tile->addr.bits.invalid == 0) {
         /* put dirty tile back in framebuffer */
         if (tc->depth_stencil) {
            pipe_put_tile_raw(tc->pipe, pt,
                              tile->addr.bits.x * TILE_SIZE,
                              tile->addr.bits.y * TILE_SIZE,
                              TILE_SIZE, TILE_SIZE,
                              tile->data.depth32, 0/*STRIDE*/);
         }
         else {
            pipe_put_tile_rgba(tc->pipe, pt,
                               tile->addr.bits.x * TILE_SIZE,
                               tile->addr.bits.y * TILE_SIZE,
                               TILE_SIZE, TILE_SIZE,
                               (float *) tile->data.color);
         }
      }

      tile->addr = addr;

      if (is_clear_flag_set(tc->clear_flags, addr)) {
         /* don't get tile from framebuffer, just clear it */
         if (tc->depth_stencil) {
            clear_tile(tile, pt->resource->format, tc->clear_val);
         }
         else {
            clear_tile_rgba(tile, pt->resource->format, tc->clear_color);
         }
         clear_clear_flag(tc->clear_flags, addr);
      }
      else {
         /* get new tile data from transfer */
         if (tc->depth_stencil) {
            pipe_get_tile_raw(tc->pipe, pt,
                              tile->addr.bits.x * TILE_SIZE, 
                              tile->addr.bits.y * TILE_SIZE, 
                              TILE_SIZE, TILE_SIZE,
                              tile->data.depth32, 0/*STRIDE*/);
         }
         else {
            pipe_get_tile_rgba(tc->pipe, pt,
                               tile->addr.bits.x * TILE_SIZE, 
                               tile->addr.bits.y * TILE_SIZE,
                               TILE_SIZE, TILE_SIZE,
                               (float *) tile->data.color);
         }
      }
   }

   tc->last_tile = tile;
   return tile;
}
Example #2
0
/**
 * Get a tile from the cache.
 * \param x, y  position of tile, in pixels
 */
struct softpipe_cached_tile *
sp_find_cached_tile(struct softpipe_tile_cache *tc,
                    union tile_address addr )
{
    struct pipe_transfer *pt = tc->transfer;
    /* cache pos/entry: */
    const int pos = CACHE_POS(addr.bits.x,
                              addr.bits.y);
    struct softpipe_cached_tile *tile = tc->entries[pos];

    if (!tile) {
        tile = sp_alloc_tile(tc);
        tc->entries[pos] = tile;
    }

    if (addr.value != tc->tile_addrs[pos].value) {

        assert(pt->resource);
        if (tc->tile_addrs[pos].bits.invalid == 0) {
            /* put dirty tile back in framebuffer */
            if (tc->depth_stencil) {
                pipe_put_tile_raw(tc->pipe, pt,
                                  tc->tile_addrs[pos].bits.x * TILE_SIZE,
                                  tc->tile_addrs[pos].bits.y * TILE_SIZE,
                                  TILE_SIZE, TILE_SIZE,
                                  tile->data.depth32, 0/*STRIDE*/);
            }
            else {
                if (util_format_is_pure_uint(tc->surface->format)) {
                    pipe_put_tile_ui_format(tc->pipe, pt,
                                            tc->tile_addrs[pos].bits.x * TILE_SIZE,
                                            tc->tile_addrs[pos].bits.y * TILE_SIZE,
                                            TILE_SIZE, TILE_SIZE,
                                            tc->surface->format,
                                            (unsigned *) tile->data.colorui128);
                } else if (util_format_is_pure_sint(tc->surface->format)) {
                    pipe_put_tile_i_format(tc->pipe, pt,
                                           tc->tile_addrs[pos].bits.x * TILE_SIZE,
                                           tc->tile_addrs[pos].bits.y * TILE_SIZE,
                                           TILE_SIZE, TILE_SIZE,
                                           tc->surface->format,
                                           (int *) tile->data.colori128);
                } else {
                    pipe_put_tile_rgba_format(tc->pipe, pt,
                                              tc->tile_addrs[pos].bits.x * TILE_SIZE,
                                              tc->tile_addrs[pos].bits.y * TILE_SIZE,
                                              TILE_SIZE, TILE_SIZE,
                                              tc->surface->format,
                                              (float *) tile->data.color);
                }
            }
        }

        tc->tile_addrs[pos] = addr;

        if (is_clear_flag_set(tc->clear_flags, addr)) {
            /* don't get tile from framebuffer, just clear it */
            if (tc->depth_stencil) {
                clear_tile(tile, pt->resource->format, tc->clear_val);
            }
            else {
                clear_tile_rgba(tile, pt->resource->format, &tc->clear_color);
            }
            clear_clear_flag(tc->clear_flags, addr);
        }
        else {
            /* get new tile data from transfer */
            if (tc->depth_stencil) {
                pipe_get_tile_raw(tc->pipe, pt,
                                  tc->tile_addrs[pos].bits.x * TILE_SIZE,
                                  tc->tile_addrs[pos].bits.y * TILE_SIZE,
                                  TILE_SIZE, TILE_SIZE,
                                  tile->data.depth32, 0/*STRIDE*/);
            }
            else {
                if (util_format_is_pure_uint(tc->surface->format)) {
                    pipe_get_tile_ui_format(tc->pipe, pt,
                                            tc->tile_addrs[pos].bits.x * TILE_SIZE,
                                            tc->tile_addrs[pos].bits.y * TILE_SIZE,
                                            TILE_SIZE, TILE_SIZE,
                                            tc->surface->format,
                                            (unsigned *) tile->data.colorui128);
                } else if (util_format_is_pure_sint(tc->surface->format)) {
                    pipe_get_tile_i_format(tc->pipe, pt,
                                           tc->tile_addrs[pos].bits.x * TILE_SIZE,
                                           tc->tile_addrs[pos].bits.y * TILE_SIZE,
                                           TILE_SIZE, TILE_SIZE,
                                           tc->surface->format,
                                           (int *) tile->data.colori128);
                } else {
                    pipe_get_tile_rgba_format(tc->pipe, pt,
                                              tc->tile_addrs[pos].bits.x * TILE_SIZE,
                                              tc->tile_addrs[pos].bits.y * TILE_SIZE,
                                              TILE_SIZE, TILE_SIZE,
                                              tc->surface->format,
                                              (float *) tile->data.color);
                }
            }
        }
    }

    tc->last_tile = tile;
    tc->last_tile_addr = addr;
    return tile;
}