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_TILE_CACHE_H
29 #define SP_TILE_CACHE_H
32 #include "pipe/p_compiler.h"
33 #include "sp_texture.h"
36 struct softpipe_tile_cache
;
40 * Cache tile size (width and height). This needs to be a power of two.
42 #define TILE_SIZE_LOG2 6
43 #define TILE_SIZE (1 << TILE_SIZE_LOG2)
46 #define TILE_ADDR_BITS (SP_MAX_TEXTURE_2D_LEVELS - 1 - TILE_SIZE_LOG2)
50 * Surface tile address as a union for fast compares.
54 unsigned x
:TILE_ADDR_BITS
; /* 16K / TILE_SIZE */
55 unsigned y
:TILE_ADDR_BITS
; /* 16K / TILE_SIZE */
63 struct softpipe_cached_tile
66 float color
[TILE_SIZE
][TILE_SIZE
][4];
67 uint color32
[TILE_SIZE
][TILE_SIZE
];
68 uint depth32
[TILE_SIZE
][TILE_SIZE
];
69 ushort depth16
[TILE_SIZE
][TILE_SIZE
];
70 ubyte stencil8
[TILE_SIZE
][TILE_SIZE
];
71 uint colorui128
[TILE_SIZE
][TILE_SIZE
][4];
72 int colori128
[TILE_SIZE
][TILE_SIZE
][4];
73 uint64_t depth64
[TILE_SIZE
][TILE_SIZE
];
78 #define NUM_ENTRIES 50
81 struct softpipe_tile_cache
83 struct pipe_context
*pipe
;
84 struct pipe_surface
*surface
; /**< the surface we're caching */
85 struct pipe_transfer
*transfer
;
88 union tile_address tile_addrs
[NUM_ENTRIES
];
89 struct softpipe_cached_tile
*entries
[NUM_ENTRIES
];
90 uint clear_flags
[(MAX_WIDTH
/ TILE_SIZE
) * (MAX_HEIGHT
/ TILE_SIZE
) / 32];
91 union pipe_color_union clear_color
; /**< for color bufs */
92 uint64_t clear_val
; /**< for z+stencil */
93 boolean depth_stencil
; /**< Is the surface a depth/stencil format? */
95 struct softpipe_cached_tile
*tile
; /**< scratch tile for clears */
97 union tile_address last_tile_addr
;
98 struct softpipe_cached_tile
*last_tile
; /**< most recently retrieved tile */
102 extern struct softpipe_tile_cache
*
103 sp_create_tile_cache( struct pipe_context
*pipe
);
106 sp_destroy_tile_cache(struct softpipe_tile_cache
*tc
);
109 sp_tile_cache_set_surface(struct softpipe_tile_cache
*tc
,
110 struct pipe_surface
*sps
);
112 extern struct pipe_surface
*
113 sp_tile_cache_get_surface(struct softpipe_tile_cache
*tc
);
116 sp_tile_cache_map_transfers(struct softpipe_tile_cache
*tc
);
119 sp_tile_cache_unmap_transfers(struct softpipe_tile_cache
*tc
);
122 sp_flush_tile_cache(struct softpipe_tile_cache
*tc
);
125 sp_tile_cache_clear(struct softpipe_tile_cache
*tc
,
126 const union pipe_color_union
*color
,
127 uint64_t clearValue
);
129 extern struct softpipe_cached_tile
*
130 sp_find_cached_tile(struct softpipe_tile_cache
*tc
,
131 union tile_address addr
);
134 static INLINE
union tile_address
135 tile_address( unsigned x
,
138 union tile_address addr
;
141 addr
.bits
.x
= x
/ TILE_SIZE
;
142 addr
.bits
.y
= y
/ TILE_SIZE
;
147 /* Quickly retrieve tile if it matches last lookup.
149 static INLINE
struct softpipe_cached_tile
*
150 sp_get_cached_tile(struct softpipe_tile_cache
*tc
,
153 union tile_address addr
= tile_address( x
, y
);
155 if (tc
->last_tile_addr
.value
== addr
.value
)
156 return tc
->last_tile
;
158 return sp_find_cached_tile( tc
, addr
);
164 #endif /* SP_TILE_CACHE_H */