broadcom/vc5: Fix CLIF dumping of lists that aren't capped by a HALT.
[mesa.git] / src / mesa / state_tracker / st_texture.h
1 /**************************************************************************
2 *
3 * Copyright 2007 VMware, Inc.
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 VMWARE 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 ST_TEXTURE_H
29 #define ST_TEXTURE_H
30
31
32 #include "pipe/p_context.h"
33 #include "util/u_sampler.h"
34
35 #include "main/mtypes.h"
36
37
38 struct pipe_resource;
39
40
41 struct st_texture_image_transfer {
42 struct pipe_transfer *transfer;
43
44 /* For ETC fallback. */
45 GLubyte *temp_data; /**< Temporary ETC texture storage. */
46 unsigned temp_stride; /**< Stride of the ETC texture storage. */
47 GLubyte *map; /**< Saved map pointer of the uncompressed transfer. */
48 };
49
50
51 /**
52 * Subclass of gl_texure_image.
53 */
54 struct st_texture_image
55 {
56 struct gl_texture_image base;
57
58 /* If stImage->pt != NULL, image data is stored here.
59 * Else there is no image data.
60 */
61 struct pipe_resource *pt;
62
63 /* List of transfers, allocated on demand.
64 * transfer[layer] is a mapping for that layer.
65 */
66 struct st_texture_image_transfer *transfer;
67 unsigned num_transfers;
68
69 /* For ETC images, keep track of the original data. This is necessary for
70 * mapping/unmapping, as well as image copies.
71 */
72 GLubyte *etc_data;
73 };
74
75
76 /**
77 * Subclass of gl_texure_object.
78 */
79 struct st_texture_object
80 {
81 struct gl_texture_object base; /* The "parent" object */
82
83 /* The texture must include at levels [0..lastLevel] once validated:
84 */
85 GLuint lastLevel;
86
87 unsigned int validated_first_level;
88 unsigned int validated_last_level;
89
90 /* On validation any active images held in main memory or in other
91 * textures will be copied to this texture and the old storage freed.
92 */
93 struct pipe_resource *pt;
94
95 /* Number of views in sampler_views array */
96 GLuint num_sampler_views;
97
98 /* Array of sampler views (one per context) attached to this texture
99 * object. Created lazily on first binding in context.
100 */
101 struct pipe_sampler_view **sampler_views;
102
103 /* True if this texture comes from the window system. Such a texture
104 * cannot be reallocated and the format can only be changed with a sampler
105 * view or a surface.
106 */
107 GLboolean surface_based;
108
109 /* If surface_based is true, this format should be used for all sampler
110 * views and surfaces instead of pt->format.
111 */
112 enum pipe_format surface_format;
113
114 /* When non-zero, samplers should use this level instead of the level
115 * range specified by the GL state.
116 *
117 * This is used for EGL images, which may correspond to a single level out
118 * of an imported pipe_resources with multiple mip levels.
119 */
120 uint level_override;
121
122 /* When non-zero, samplers should use this layer instead of the one
123 * specified by the GL state.
124 *
125 * This is used for EGL images and VDPAU interop, where imported
126 * pipe_resources may be cube, 3D, or array textures (containing layers
127 * with different fields in the case of VDPAU) even though the GL state
128 * describes one non-array texture per field.
129 */
130 uint layer_override;
131
132 /** The glsl version of the shader seen during the previous validation */
133 bool prev_glsl130_or_later;
134 /** The value of the sampler's sRGBDecode state at the previous validation */
135 GLenum prev_sRGBDecode;
136
137 /**
138 * Set when the texture images of this texture object might not all be in
139 * the pipe_resource *pt above.
140 */
141 bool needs_validation;
142 };
143
144
145 static inline struct st_texture_image *
146 st_texture_image(struct gl_texture_image *img)
147 {
148 return (struct st_texture_image *) img;
149 }
150
151 static inline const struct st_texture_image *
152 st_texture_image_const(const struct gl_texture_image *img)
153 {
154 return (const struct st_texture_image *) img;
155 }
156
157 static inline struct st_texture_object *
158 st_texture_object(struct gl_texture_object *obj)
159 {
160 return (struct st_texture_object *) obj;
161 }
162
163 static inline const struct st_texture_object *
164 st_texture_object_const(const struct gl_texture_object *obj)
165 {
166 return (const struct st_texture_object *) obj;
167 }
168
169
170 static inline struct pipe_resource *
171 st_get_texobj_resource(struct gl_texture_object *texObj)
172 {
173 struct st_texture_object *stObj = st_texture_object(texObj);
174 return stObj ? stObj->pt : NULL;
175 }
176
177
178 static inline struct pipe_resource *
179 st_get_stobj_resource(struct st_texture_object *stObj)
180 {
181 return stObj ? stObj->pt : NULL;
182 }
183
184
185 static inline struct st_texture_object *
186 st_get_texture_object(struct gl_context *ctx,
187 const struct gl_program *prog,
188 unsigned unit)
189 {
190 const GLuint texUnit = prog->SamplerUnits[unit];
191 struct gl_texture_object *texObj = ctx->Texture.Unit[texUnit]._Current;
192
193 if (!texObj)
194 return NULL;
195
196 return st_texture_object(texObj);
197 }
198
199 static inline enum pipe_format
200 st_get_view_format(struct st_texture_object *stObj)
201 {
202 if (!stObj)
203 return PIPE_FORMAT_NONE;
204 return stObj->surface_based ? stObj->surface_format : stObj->pt->format;
205 }
206
207
208 extern struct pipe_resource *
209 st_texture_create(struct st_context *st,
210 enum pipe_texture_target target,
211 enum pipe_format format,
212 GLuint last_level,
213 GLuint width0,
214 GLuint height0,
215 GLuint depth0,
216 GLuint layers,
217 GLuint nr_samples,
218 GLuint tex_usage );
219
220
221 extern void
222 st_gl_texture_dims_to_pipe_dims(GLenum texture,
223 unsigned widthIn,
224 uint16_t heightIn,
225 uint16_t depthIn,
226 unsigned *widthOut,
227 uint16_t *heightOut,
228 uint16_t *depthOut,
229 uint16_t *layersOut);
230
231 /* Check if an image fits into an existing texture object.
232 */
233 extern GLboolean
234 st_texture_match_image(struct st_context *st,
235 const struct pipe_resource *pt,
236 const struct gl_texture_image *image);
237
238 /* Return a pointer to an image within a texture. Return image stride as
239 * well.
240 */
241 extern GLubyte *
242 st_texture_image_map(struct st_context *st, struct st_texture_image *stImage,
243 enum pipe_transfer_usage usage,
244 GLuint x, GLuint y, GLuint z,
245 GLuint w, GLuint h, GLuint d,
246 struct pipe_transfer **transfer);
247
248 extern void
249 st_texture_image_unmap(struct st_context *st,
250 struct st_texture_image *stImage, unsigned slice);
251
252
253 /* Return pointers to each 2d slice within an image. Indexed by depth
254 * value.
255 */
256 extern const GLuint *
257 st_texture_depth_offsets(struct pipe_resource *pt, GLuint level);
258
259 /* Copy an image between two textures
260 */
261 extern void
262 st_texture_image_copy(struct pipe_context *pipe,
263 struct pipe_resource *dst, GLuint dstLevel,
264 struct pipe_resource *src, GLuint srcLevel,
265 GLuint face);
266
267
268 extern struct pipe_resource *
269 st_create_color_map_texture(struct gl_context *ctx);
270
271 void
272 st_destroy_bound_texture_handles(struct st_context *st);
273
274 void
275 st_destroy_bound_image_handles(struct st_context *st);
276
277 bool
278 st_etc_fallback(struct st_context *st, struct gl_texture_image *texImage);
279
280 void
281 st_convert_image(const struct st_context *st, const struct gl_image_unit *u,
282 struct pipe_image_view *img);
283
284 void
285 st_convert_image_from_unit(const struct st_context *st,
286 struct pipe_image_view *img,
287 GLuint imgUnit);
288
289 void
290 st_convert_sampler(const struct st_context *st,
291 const struct gl_texture_object *texobj,
292 const struct gl_sampler_object *msamp,
293 float tex_unit_lod_bias,
294 struct pipe_sampler_state *sampler);
295
296 void
297 st_convert_sampler_from_unit(const struct st_context *st,
298 struct pipe_sampler_state *sampler,
299 GLuint texUnit);
300
301 void
302 st_update_single_texture(struct st_context *st,
303 struct pipe_sampler_view **sampler_view,
304 GLuint texUnit, bool glsl130_or_later);
305
306 void
307 st_make_bound_samplers_resident(struct st_context *st,
308 struct gl_program *prog);
309
310 void
311 st_make_bound_images_resident(struct st_context *st,
312 struct gl_program *prog);
313
314 #endif