1 /**************************************************************************
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
28 #ifndef SP_TEX_TILE_CACHE_H
29 #define SP_TEX_TILE_CACHE_H
32 #include "pipe/p_compiler.h"
33 #include "sp_limits.h"
36 struct softpipe_context
;
37 struct softpipe_tex_tile_cache
;
41 * Cache tile size (width and height). This needs to be a power of two.
43 #define TILE_SIZE_LOG2 6
44 #define TILE_SIZE (1 << TILE_SIZE_LOG2)
47 #define TEX_ADDR_BITS (SP_MAX_TEXTURE_2D_LEVELS - 1 - TILE_SIZE_LOG2)
48 #define TEX_Z_BITS (SP_MAX_TEXTURE_2D_LEVELS - 1)
51 * Texture tile address as a union for fast compares.
53 union tex_tile_address
{
55 unsigned x
:TEX_ADDR_BITS
; /* 16K / TILE_SIZE */
56 unsigned y
:TEX_ADDR_BITS
; /* 16K / TILE_SIZE */
57 unsigned z
:TEX_Z_BITS
; /* 16K -- z not tiled */
66 struct softpipe_tex_cached_tile
68 union tex_tile_address addr
;
70 float color
[TILE_SIZE
][TILE_SIZE
][4];
71 unsigned int colorui
[TILE_SIZE
][TILE_SIZE
][4];
72 int colori
[TILE_SIZE
][TILE_SIZE
][4];
78 struct softpipe_tex_tile_cache
80 struct pipe_context
*pipe
;
81 struct pipe_transfer
*transfer
;
84 struct pipe_resource
*texture
; /**< if caching a texture */
87 struct softpipe_tex_cached_tile entries
[NUM_ENTRIES
];
89 struct pipe_transfer
*tex_trans
;
91 int tex_face
, tex_level
, tex_z
;
97 enum pipe_format format
;
99 struct softpipe_tex_cached_tile
*last_tile
; /**< most recently retrieved tile */
103 extern struct softpipe_tex_tile_cache
*
104 sp_create_tex_tile_cache( struct pipe_context
*pipe
);
107 sp_destroy_tex_tile_cache(struct softpipe_tex_tile_cache
*tc
);
110 sp_tex_tile_cache_set_sampler_view(struct softpipe_tex_tile_cache
*tc
,
111 struct pipe_sampler_view
*view
);
114 sp_tex_tile_cache_validate_texture(struct softpipe_tex_tile_cache
*tc
);
117 sp_flush_tex_tile_cache(struct softpipe_tex_tile_cache
*tc
);
121 extern const struct softpipe_tex_cached_tile
*
122 sp_find_cached_tile_tex(struct softpipe_tex_tile_cache
*tc
,
123 union tex_tile_address addr
);
125 static INLINE
union tex_tile_address
126 tex_tile_address( unsigned x
,
132 union tex_tile_address addr
;
135 addr
.bits
.x
= x
/ TILE_SIZE
;
136 addr
.bits
.y
= y
/ TILE_SIZE
;
138 addr
.bits
.face
= face
;
139 addr
.bits
.level
= level
;
144 /* Quickly retrieve tile if it matches last lookup.
146 static INLINE
const struct softpipe_tex_cached_tile
*
147 sp_get_cached_tile_tex(struct softpipe_tex_tile_cache
*tc
,
148 union tex_tile_address addr
)
150 if (tc
->last_tile
->addr
.value
== addr
.value
)
151 return tc
->last_tile
;
153 return sp_find_cached_tile_tex( tc
, addr
);
157 #endif /* SP_TEX_TILE_CACHE_H */