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 LP_TEX_CACHE_H
29 #define LP_TEX_CACHE_H
32 #include "pipe/p_compiler.h"
35 struct llvmpipe_context
;
36 struct llvmpipe_tex_tile_cache
;
40 * Cache tile size (width and height). This needs to be a power of two.
42 #define TEX_TILE_SIZE 64
45 /* If we need to support > 4096, just expand this to be a 64 bit
46 * union, or consider tiling in Z as well.
48 union tex_tile_address
{
50 unsigned x
:6; /* 4096 / TEX_TILE_SIZE */
51 unsigned y
:6; /* 4096 / TEX_TILE_SIZE */
52 unsigned z
:12; /* 4096 -- z not tiled */
61 struct llvmpipe_cached_tex_tile
63 union tex_tile_address addr
;
64 uint8_t color
[TEX_TILE_SIZE
][TEX_TILE_SIZE
][4];
67 #define NUM_ENTRIES 50
71 #define MAX_TEX_WIDTH 2048
72 #define MAX_TEX_HEIGHT 2048
75 struct llvmpipe_tex_tile_cache
77 struct pipe_screen
*screen
;
78 struct pipe_surface
*surface
; /**< the surface we're caching */
79 struct pipe_transfer
*transfer
;
82 struct pipe_texture
*texture
; /**< if caching a texture */
85 struct llvmpipe_cached_tex_tile entries
[NUM_ENTRIES
];
87 struct pipe_transfer
*tex_trans
;
89 int tex_face
, tex_level
, tex_z
;
91 struct llvmpipe_cached_tex_tile
*last_tile
; /**< most recently retrieved tile */
95 extern struct llvmpipe_tex_tile_cache
*
96 lp_create_tex_tile_cache( struct pipe_screen
*screen
);
99 lp_destroy_tex_tile_cache(struct llvmpipe_tex_tile_cache
*tc
);
102 lp_tex_tile_cache_map_transfers(struct llvmpipe_tex_tile_cache
*tc
);
105 lp_tex_tile_cache_unmap_transfers(struct llvmpipe_tex_tile_cache
*tc
);
108 lp_tex_tile_cache_set_texture(struct llvmpipe_tex_tile_cache
*tc
,
109 struct pipe_texture
*texture
);
112 lp_tex_tile_cache_validate_texture(struct llvmpipe_tex_tile_cache
*tc
);
114 extern const struct llvmpipe_cached_tex_tile
*
115 lp_find_cached_tex_tile(struct llvmpipe_tex_tile_cache
*tc
,
116 union tex_tile_address addr
);
118 static INLINE
const union tex_tile_address
119 tex_tile_address( unsigned x
,
125 union tex_tile_address addr
;
128 addr
.bits
.x
= x
/ TEX_TILE_SIZE
;
129 addr
.bits
.y
= y
/ TEX_TILE_SIZE
;
131 addr
.bits
.face
= face
;
132 addr
.bits
.level
= level
;
137 /* Quickly retrieve tile if it matches last lookup.
139 static INLINE
const struct llvmpipe_cached_tex_tile
*
140 lp_get_cached_tex_tile(struct llvmpipe_tex_tile_cache
*tc
,
141 union tex_tile_address addr
)
143 if (tc
->last_tile
->addr
.value
== addr
.value
)
144 return tc
->last_tile
;
146 return lp_find_cached_tex_tile( tc
, addr
);
150 #endif /* LP_TEX_CACHE_H */