summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian <brian.paul@tungstengraphics.com>2007-10-21 18:06:35 -0600
committerBrian <brian.paul@tungstengraphics.com>2007-10-21 18:06:35 -0600
commitb3204c2aff3f3d442ada04f241f352155a3af205 (patch)
tree3d793eda42903eec2d7cae2cb0cf16577fbaf6ef
parentc2322333b8d1732f4c6d4b71ff5ee2ea772d3cb5 (diff)
Start implementing cache routines for textures.
First step to consolidating surface/texture caching...
-rw-r--r--src/mesa/pipe/softpipe/sp_tile_cache.c61
-rw-r--r--src/mesa/pipe/softpipe/sp_tile_cache.h11
2 files changed, 71 insertions, 1 deletions
diff --git a/src/mesa/pipe/softpipe/sp_tile_cache.c b/src/mesa/pipe/softpipe/sp_tile_cache.c
index 74bd4a3d11c..d88bce46190 100644
--- a/src/mesa/pipe/softpipe/sp_tile_cache.c
+++ b/src/mesa/pipe/softpipe/sp_tile_cache.c
@@ -49,6 +49,7 @@
struct softpipe_tile_cache
{
struct softpipe_surface *surface; /**< the surface we're caching */
+ struct pipe_mipmap_tree *texture; /**< if caching a texture */
struct softpipe_cached_tile entries[NUM_ENTRIES];
uint clear_flags[(MAX_WIDTH / TILE_SIZE) * (MAX_HEIGHT / TILE_SIZE) / 32];
};
@@ -124,6 +125,12 @@ sp_tile_cache_set_surface(struct softpipe_tile_cache *tc,
}
+void
+sp_tile_cache_set_texture(struct softpipe_tile_cache *tc,
+ struct pipe_mipmap_tree *texture)
+{
+ tc->texture = texture;
+}
void
@@ -249,6 +256,60 @@ sp_get_cached_tile(struct softpipe_tile_cache *tc, int x, int y)
}
+/**
+ * Given the texture face, level, zslice, x and y values, compute
+ * the cache entry position/index where we'd hope to find the
+ * cached texture tile.
+ * This is basically a direct-map cache.
+ * XXX There's probably lots of ways in which we can improve this.
+ */
+static uint
+tex_cache_pos(int x, int y, int z, int face, int level)
+{
+ uint entry = x + y * 2 + z * 4 + face + level;
+ return entry % NUM_ENTRIES;
+}
+
+
+/**
+ * Similar to sp_get_cached_tile() but for textures.
+ * Tiles are read-only and indexed with more params.
+ */
+struct softpipe_cached_tile *
+sp_get_cached_tile_tex(struct softpipe_tile_cache *tc, int x, int y, int z,
+ int face, int level)
+{
+ struct pipe_context *pipe; /* XXX need this */
+
+ /* tile pos in framebuffer: */
+ const int tile_x = x & ~(TILE_SIZE - 1);
+ const int tile_y = y & ~(TILE_SIZE - 1);
+
+ /* cache pos/entry: */
+ const int pos = tex_cache_pos(x / TILE_SIZE, y / TILE_SIZE,
+ z, face, level);
+ struct softpipe_cached_tile *tile = tc->entries + pos;
+
+ if (tile_x != tile->x ||
+ tile_y != tile->y ||
+ z != tile->z ||
+ face != tile->face ||
+ level != tile->level) {
+ struct pipe_surface *ps
+ = pipe->get_tex_surface(pipe, tc->texture, face, level, z);
+
+ ps->get_tile(ps,
+ tile_x, tile_y, TILE_SIZE, TILE_SIZE,
+ (float *) tile->data.color);
+
+ pipe_surface_reference(&ps, NULL);
+ }
+
+ return tile;
+}
+
+
+
void
sp_clear_tile_cache(struct softpipe_tile_cache *tc, unsigned clearval)
{
diff --git a/src/mesa/pipe/softpipe/sp_tile_cache.h b/src/mesa/pipe/softpipe/sp_tile_cache.h
index 80bcac6904d..9879b1821ce 100644
--- a/src/mesa/pipe/softpipe/sp_tile_cache.h
+++ b/src/mesa/pipe/softpipe/sp_tile_cache.h
@@ -45,7 +45,8 @@ struct softpipe_tile_cache;
struct softpipe_cached_tile
{
- int x, y; /** pos of tile in window coords */
+ int x, y; /**< pos of tile in window coords */
+ int z, face, level; /**< Extra texture indexes */
union {
float color[TILE_SIZE][TILE_SIZE][4];
uint depth32[TILE_SIZE][TILE_SIZE];
@@ -66,6 +67,10 @@ sp_tile_cache_set_surface(struct softpipe_tile_cache *tc,
struct softpipe_surface *sps);
extern void
+sp_tile_cache_set_texture(struct softpipe_tile_cache *tc,
+ struct pipe_mipmap_tree *texture);
+
+extern void
sp_flush_tile_cache(struct softpipe_tile_cache *tc);
extern void
@@ -74,6 +79,10 @@ sp_clear_tile_cache(struct softpipe_tile_cache *tc, unsigned clearval);
extern struct softpipe_cached_tile *
sp_get_cached_tile(struct softpipe_tile_cache *tc, int x, int y);
+extern struct softpipe_cached_tile *
+sp_get_cached_tile_tex(struct softpipe_tile_cache *tc, int x, int y, int z,
+ int face, int level);
+
#endif /* SP_TILE_CACHE_H */