softpipe: fix swizzling of texture border color
[mesa.git] / src / gallium / drivers / softpipe / sp_tex_tile_cache.h
1 /**************************************************************************
2 *
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
5 *
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:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
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.
25 *
26 **************************************************************************/
27
28 #ifndef SP_TEX_TILE_CACHE_H
29 #define SP_TEX_TILE_CACHE_H
30
31
32 #include "pipe/p_compiler.h"
33
34
35 struct softpipe_context;
36 struct softpipe_tex_tile_cache;
37
38
39 /**
40 * Cache tile size (width and height). This needs to be a power of two.
41 */
42 #define TILE_SIZE 64
43
44
45 /* If we need to support > 4096, just expand this to be a 64 bit
46 * union, or consider tiling in Z as well.
47 */
48 union tex_tile_address {
49 struct {
50 unsigned x:6; /* 4096 / TILE_SIZE */
51 unsigned y:6; /* 4096 / TILE_SIZE */
52 unsigned z:12; /* 4096 -- z not tiled */
53 unsigned face:3;
54 unsigned level:4;
55 unsigned invalid:1;
56 } bits;
57 unsigned value;
58 };
59
60
61 struct softpipe_tex_cached_tile
62 {
63 union tex_tile_address addr;
64 union {
65 float color[TILE_SIZE][TILE_SIZE][4];
66 } data;
67 };
68
69 #define NUM_ENTRIES 50
70
71 struct softpipe_tex_tile_cache
72 {
73 struct pipe_context *pipe;
74 struct pipe_transfer *transfer;
75 void *transfer_map;
76
77 struct pipe_resource *texture; /**< if caching a texture */
78 unsigned timestamp;
79
80 struct softpipe_tex_cached_tile entries[NUM_ENTRIES];
81
82 struct pipe_transfer *tex_trans;
83 void *tex_trans_map;
84 int tex_face, tex_level, tex_z;
85
86 unsigned swizzle_r;
87 unsigned swizzle_g;
88 unsigned swizzle_b;
89 unsigned swizzle_a;
90 unsigned format;
91
92 struct softpipe_tex_cached_tile *last_tile; /**< most recently retrieved tile */
93
94 float swz_border_color[4]; /**< swizzled border color */
95 };
96
97
98 extern struct softpipe_tex_tile_cache *
99 sp_create_tex_tile_cache( struct pipe_context *pipe );
100
101 extern void
102 sp_destroy_tex_tile_cache(struct softpipe_tex_tile_cache *tc);
103
104
105 extern void
106 sp_tex_tile_cache_map_transfers(struct softpipe_tex_tile_cache *tc);
107
108 extern void
109 sp_tex_tile_cache_unmap_transfers(struct softpipe_tex_tile_cache *tc);
110
111 extern void
112 sp_tex_tile_cache_set_sampler_view(struct softpipe_tex_tile_cache *tc,
113 struct pipe_sampler_view *view);
114
115 void
116 sp_tex_tile_cache_validate_texture(struct softpipe_tex_tile_cache *tc);
117
118 extern void
119 sp_flush_tex_tile_cache(struct softpipe_tex_tile_cache *tc);
120
121
122
123 extern const struct softpipe_tex_cached_tile *
124 sp_find_cached_tile_tex(struct softpipe_tex_tile_cache *tc,
125 union tex_tile_address addr );
126
127 static INLINE union tex_tile_address
128 tex_tile_address( unsigned x,
129 unsigned y,
130 unsigned z,
131 unsigned face,
132 unsigned level )
133 {
134 union tex_tile_address addr;
135
136 addr.value = 0;
137 addr.bits.x = x / TILE_SIZE;
138 addr.bits.y = y / TILE_SIZE;
139 addr.bits.z = z;
140 addr.bits.face = face;
141 addr.bits.level = level;
142
143 return addr;
144 }
145
146 /* Quickly retrieve tile if it matches last lookup.
147 */
148 static INLINE const struct softpipe_tex_cached_tile *
149 sp_get_cached_tile_tex(struct softpipe_tex_tile_cache *tc,
150 union tex_tile_address addr )
151 {
152 if (tc->last_tile->addr.value == addr.value)
153 return tc->last_tile;
154
155 return sp_find_cached_tile_tex( tc, addr );
156 }
157
158
159 const float *
160 sp_tex_tile_cache_border_color(struct softpipe_tex_tile_cache *tc,
161 const float border_color[4]);
162
163
164 #endif /* SP_TEX_TILE_CACHE_H */
165