very simple texture cache implementation
authorBrian <brian@i915.localnet.net>
Wed, 8 Aug 2007 18:02:52 +0000 (12:02 -0600)
committerBrian <brian@i915.localnet.net>
Wed, 8 Aug 2007 18:04:08 +0000 (12:04 -0600)
src/mesa/pipe/softpipe/sp_tex_sample.c
src/mesa/pipe/tgsi/core/tgsi_exec.h

index 1d274d50384aaa40dab91ec15feaf01620474bfd..7f8bf0d99c64ff86b5bb2ff35c2aa430d1f92aec 100644 (file)
@@ -471,12 +471,34 @@ sp_get_sample_2d(struct tgsi_sampler *sampler,
    switch (sampler->state->min_filter) {
    case PIPE_TEX_FILTER_NEAREST:
       {
-         GLint x, y;
+         GLint x, y, cx, cy;         
+         const GLfloat *src;
          x = nearest_texcoord(sampler->state->wrap_s, strq[0],
                               sampler->texture->width0);
          y = nearest_texcoord(sampler->state->wrap_t, strq[1],
                               sampler->texture->height0);
-         ps->get_tile(ps, x, y, 1, 1, rgba);
+
+         cx = x / SAMPLER_CACHE_SIZE;
+         cy = y / SAMPLER_CACHE_SIZE;
+         if (cx != sampler->cache_x || cy != sampler->cache_y) {
+            /* cache miss, replace cache with new tile */
+            sampler->cache_x = cx;
+            sampler->cache_y = cy;
+            ps->get_tile(ps,
+                         cx * SAMPLER_CACHE_SIZE,
+                         cy * SAMPLER_CACHE_SIZE,
+                         SAMPLER_CACHE_SIZE, SAMPLER_CACHE_SIZE,
+                         (GLfloat *) sampler->cache);
+            /*printf("cache miss (%d, %d)\n", x, y);*/
+         }
+         else {
+            /*printf("cache hit (%d, %d)\n", x, y);*/
+         }
+
+         cx = x % SAMPLER_CACHE_SIZE;
+         cy = y % SAMPLER_CACHE_SIZE;
+         src = sampler->cache[cy][cx];
+         COPY_4V(rgba, src);
       }
       break;
    case PIPE_TEX_FILTER_LINEAR:
index 2ad4b965bd3863c41094df266c55533e462f4c3e..fb11eec777686f23f1237eb0d38e4800598f45ca 100644 (file)
@@ -21,6 +21,8 @@ struct tgsi_exec_vector
    union tgsi_exec_channel xyzw[4];
 };
 
+#define SAMPLER_CACHE_SIZE 8
+
 struct tgsi_sampler
 {
    const struct pipe_sampler_state *state;
@@ -28,6 +30,9 @@ struct tgsi_sampler
    void (*get_sample)(struct tgsi_sampler *sampler,
                       const GLfloat strq[4], GLfloat lambda, GLfloat rgba[4]);
    void *pipe; /*XXX temporary*/
+
+   GLint cache_x, cache_y;
+   GLfloat cache[SAMPLER_CACHE_SIZE][SAMPLER_CACHE_SIZE][4];
 };
 
 struct tgsi_exec_labels