Merge remote branch 'origin/7.8'
[mesa.git] / src / gallium / drivers / llvmpipe / lp_texture.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 LP_TEXTURE_H
29 #define LP_TEXTURE_H
30
31
32 #include "pipe/p_state.h"
33 #include "util/u_debug.h"
34
35
36 #define LP_MAX_TEXTURE_2D_LEVELS 12 /* 2K x 2K for now */
37 #define LP_MAX_TEXTURE_3D_LEVELS 10 /* 512 x 512 x 512 for now */
38
39 #define LP_MAX_TEXTURE_LEVELS LP_MAX_TEXTURE_2D_LEVELS
40
41
42 enum lp_texture_usage
43 {
44 LP_TEX_USAGE_READ = 100,
45 LP_TEX_USAGE_READ_WRITE,
46 LP_TEX_USAGE_WRITE_ALL
47 };
48
49
50 /** Per-tile layout mode */
51 enum lp_texture_layout
52 {
53 LP_TEX_LAYOUT_NONE = 0, /**< no layout for the tile data yet */
54 LP_TEX_LAYOUT_TILED, /**< the tile data is in tiled layout */
55 LP_TEX_LAYOUT_LINEAR, /**< the tile data is in linear layout */
56 LP_TEX_LAYOUT_BOTH /**< the tile data is in both modes */
57 };
58
59
60 struct pipe_context;
61 struct pipe_screen;
62 struct llvmpipe_context;
63
64 struct sw_displaytarget;
65
66
67 /**
68 * We keep one or two copies of the texture image data: one in a simple
69 * linear layout (for texture sampling) and another in a tiled layout (for
70 * render targets). We keep track of whether each image tile is linear
71 * or tiled on a per-tile basis.
72 */
73
74
75 /** A 1D/2D/3D image, one mipmap level */
76 struct llvmpipe_texture_image
77 {
78 void *data;
79 };
80
81
82 /**
83 * llvmpipe subclass of pipe_resource. A texture, drawing surface,
84 * vertex buffer, const buffer, etc.
85 * Textures are stored differently than othere types of objects such as
86 * vertex buffers and const buffers.
87 * The former are tiled and have per-tile layout flags.
88 * The later are simple malloc'd blocks of memory.
89 */
90 struct llvmpipe_resource
91 {
92 struct pipe_resource base;
93
94 /** Row stride in bytes */
95 unsigned row_stride[LP_MAX_TEXTURE_LEVELS];
96 /** Image stride (for cube maps or 3D textures) in bytes */
97 unsigned img_stride[LP_MAX_TEXTURE_LEVELS];
98 unsigned tiles_per_row[LP_MAX_TEXTURE_LEVELS];
99 unsigned tiles_per_image[LP_MAX_TEXTURE_LEVELS];
100 /** Number of 3D slices or cube faces per level */
101 unsigned num_slices_faces[LP_MAX_TEXTURE_LEVELS];
102
103 /**
104 * Display target, for textures with the PIPE_BIND_DISPLAY_TARGET
105 * usage.
106 */
107 struct sw_displaytarget *dt;
108
109 /**
110 * Malloc'ed data for regular textures, or a mapping to dt above.
111 */
112 struct llvmpipe_texture_image tiled[LP_MAX_TEXTURE_LEVELS];
113 struct llvmpipe_texture_image linear[LP_MAX_TEXTURE_LEVELS];
114
115 /**
116 * Data for non-texture resources.
117 */
118 void *data;
119
120 /** array [level][face or slice][tile_y][tile_x] of layout values) */
121 enum lp_texture_layout *layout[LP_MAX_TEXTURE_LEVELS];
122
123 boolean userBuffer; /** Is this a user-space buffer? */
124 unsigned timestamp;
125
126 unsigned id; /**< temporary, for debugging */
127 };
128
129
130 struct llvmpipe_transfer
131 {
132 struct pipe_transfer base;
133
134 unsigned long offset;
135 };
136
137
138 /** cast wrappers */
139 static INLINE struct llvmpipe_resource *
140 llvmpipe_resource(struct pipe_resource *pt)
141 {
142 return (struct llvmpipe_resource *) pt;
143 }
144
145
146 static INLINE const struct llvmpipe_resource *
147 llvmpipe_resource_const(const struct pipe_resource *pt)
148 {
149 return (const struct llvmpipe_resource *) pt;
150 }
151
152
153 static INLINE struct llvmpipe_transfer *
154 llvmpipe_transfer(struct pipe_transfer *pt)
155 {
156 return (struct llvmpipe_transfer *) pt;
157 }
158
159
160 void llvmpipe_init_screen_resource_funcs(struct pipe_screen *screen);
161 void llvmpipe_init_context_resource_funcs(struct pipe_context *pipe);
162
163 static INLINE unsigned
164 llvmpipe_resource_stride(struct pipe_resource *resource,
165 unsigned level)
166 {
167 struct llvmpipe_resource *lpr = llvmpipe_resource(resource);
168 assert(level < LP_MAX_TEXTURE_2D_LEVELS);
169 return lpr->row_stride[level];
170 }
171
172
173 void *
174 llvmpipe_resource_map(struct pipe_resource *resource,
175 unsigned face_slice,
176 unsigned level,
177 unsigned zslice,
178 enum lp_texture_usage tex_usage,
179 enum lp_texture_layout layout);
180
181 void
182 llvmpipe_resource_unmap(struct pipe_resource *resource,
183 unsigned face_slice,
184 unsigned level,
185 unsigned zslice);
186
187
188 void *
189 llvmpipe_resource_data(struct pipe_resource *resource);
190
191
192 ubyte *
193 llvmpipe_get_texture_image_address(struct llvmpipe_resource *lpr,
194 unsigned face_slice, unsigned level,
195 enum lp_texture_layout layout);
196
197 void *
198 llvmpipe_get_texture_image(struct llvmpipe_resource *resource,
199 unsigned face_slice, unsigned level,
200 enum lp_texture_usage usage,
201 enum lp_texture_layout layout);
202
203 void *
204 llvmpipe_get_texture_image_all(struct llvmpipe_resource *lpr,
205 unsigned level,
206 enum lp_texture_usage usage,
207 enum lp_texture_layout layout);
208
209 ubyte *
210 llvmpipe_get_texture_tile_linear(struct llvmpipe_resource *lpr,
211 unsigned face_slice, unsigned level,
212 enum lp_texture_usage usage,
213 unsigned x, unsigned y);
214
215 ubyte *
216 llvmpipe_get_texture_tile(struct llvmpipe_resource *lpr,
217 unsigned face_slice, unsigned level,
218 enum lp_texture_usage usage,
219 unsigned x, unsigned y);
220
221
222
223 extern void
224 llvmpipe_init_screen_texture_funcs(struct pipe_screen *screen);
225
226 extern void
227 llvmpipe_init_context_texture_funcs(struct pipe_context *pipe);
228
229 #endif /* LP_TEXTURE_H */