1 /**************************************************************************
3 * Copyright 2007 VMware, Inc.
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 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.
26 **************************************************************************/
32 #include "pipe/p_context.h"
33 #include "util/u_sampler.h"
35 #include "main/mtypes.h"
41 struct st_texture_image_transfer
{
42 struct pipe_transfer
*transfer
;
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. */
52 * Subclass of gl_texure_image.
54 struct st_texture_image
56 struct gl_texture_image base
;
58 /* If stImage->pt != NULL, image data is stored here.
59 * Else there is no image data.
61 struct pipe_resource
*pt
;
63 /* List of transfers, allocated on demand.
64 * transfer[layer] is a mapping for that layer.
66 struct st_texture_image_transfer
*transfer
;
67 unsigned num_transfers
;
69 /* For ETC images, keep track of the original data. This is necessary for
70 * mapping/unmapping, as well as image copies.
77 * Subclass of gl_texure_object.
79 struct st_texture_object
81 struct gl_texture_object base
; /* The "parent" object */
83 /* The texture must include at levels [0..lastLevel] once validated:
87 unsigned int validated_first_level
;
88 unsigned int validated_last_level
;
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.
93 struct pipe_resource
*pt
;
95 /* Number of views in sampler_views array */
96 GLuint num_sampler_views
;
98 /* Array of sampler views (one per context) attached to this texture
99 * object. Created lazily on first binding in context.
101 struct pipe_sampler_view
**sampler_views
;
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
107 GLboolean surface_based
;
109 /* If surface_based is true, this format should be used for all sampler
110 * views and surfaces instead of pt->format.
112 enum pipe_format surface_format
;
114 /* When non-zero, samplers should use this layer instead of the one
115 * specified by the GL state.
117 * This is used for VDPAU interop, where imported pipe_resources may be
118 * array textures (containing layers with different fields) even though the
119 * GL state describes one non-array texture per field.
123 /** The glsl version of the shader seen during the previous validation */
124 bool prev_glsl130_or_later
;
125 /** The value of the sampler's sRGBDecode state at the previous validation */
126 GLenum prev_sRGBDecode
;
129 * Set when the texture images of this texture object might not all be in
130 * the pipe_resource *pt above.
132 bool needs_validation
;
136 static inline struct st_texture_image
*
137 st_texture_image(struct gl_texture_image
*img
)
139 return (struct st_texture_image
*) img
;
142 static inline const struct st_texture_image
*
143 st_texture_image_const(const struct gl_texture_image
*img
)
145 return (const struct st_texture_image
*) img
;
148 static inline struct st_texture_object
*
149 st_texture_object(struct gl_texture_object
*obj
)
151 return (struct st_texture_object
*) obj
;
154 static inline const struct st_texture_object
*
155 st_texture_object_const(const struct gl_texture_object
*obj
)
157 return (const struct st_texture_object
*) obj
;
161 static inline struct pipe_resource
*
162 st_get_texobj_resource(struct gl_texture_object
*texObj
)
164 struct st_texture_object
*stObj
= st_texture_object(texObj
);
165 return stObj
? stObj
->pt
: NULL
;
169 static inline struct pipe_resource
*
170 st_get_stobj_resource(struct st_texture_object
*stObj
)
172 return stObj
? stObj
->pt
: NULL
;
176 static inline struct st_texture_object
*
177 st_get_texture_object(struct gl_context
*ctx
,
178 const struct gl_program
*prog
,
181 const GLuint texUnit
= prog
->SamplerUnits
[unit
];
182 struct gl_texture_object
*texObj
= ctx
->Texture
.Unit
[texUnit
]._Current
;
187 return st_texture_object(texObj
);
190 static inline enum pipe_format
191 st_get_view_format(struct st_texture_object
*stObj
)
194 return PIPE_FORMAT_NONE
;
195 return stObj
->surface_based
? stObj
->surface_format
: stObj
->pt
->format
;
199 extern struct pipe_resource
*
200 st_texture_create(struct st_context
*st
,
201 enum pipe_texture_target target
,
202 enum pipe_format format
,
213 st_gl_texture_dims_to_pipe_dims(GLenum texture
,
220 uint16_t *layersOut
);
222 /* Check if an image fits into an existing texture object.
225 st_texture_match_image(struct st_context
*st
,
226 const struct pipe_resource
*pt
,
227 const struct gl_texture_image
*image
);
229 /* Return a pointer to an image within a texture. Return image stride as
233 st_texture_image_map(struct st_context
*st
, struct st_texture_image
*stImage
,
234 enum pipe_transfer_usage usage
,
235 GLuint x
, GLuint y
, GLuint z
,
236 GLuint w
, GLuint h
, GLuint d
,
237 struct pipe_transfer
**transfer
);
240 st_texture_image_unmap(struct st_context
*st
,
241 struct st_texture_image
*stImage
, unsigned slice
);
244 /* Return pointers to each 2d slice within an image. Indexed by depth
247 extern const GLuint
*
248 st_texture_depth_offsets(struct pipe_resource
*pt
, GLuint level
);
250 /* Copy an image between two textures
253 st_texture_image_copy(struct pipe_context
*pipe
,
254 struct pipe_resource
*dst
, GLuint dstLevel
,
255 struct pipe_resource
*src
, GLuint srcLevel
,
259 extern struct pipe_resource
*
260 st_create_color_map_texture(struct gl_context
*ctx
);
263 st_destroy_bound_texture_handles(struct st_context
*st
);
266 st_destroy_bound_image_handles(struct st_context
*st
);
269 st_etc_fallback(struct st_context
*st
, struct gl_texture_image
*texImage
);
272 st_convert_image(const struct st_context
*st
, const struct gl_image_unit
*u
,
273 struct pipe_image_view
*img
);
276 st_convert_image_from_unit(const struct st_context
*st
,
277 struct pipe_image_view
*img
,
281 st_convert_sampler(const struct st_context
*st
,
282 const struct gl_texture_object
*texobj
,
283 const struct gl_sampler_object
*msamp
,
284 float tex_unit_lod_bias
,
285 struct pipe_sampler_state
*sampler
);
288 st_convert_sampler_from_unit(const struct st_context
*st
,
289 struct pipe_sampler_state
*sampler
,
293 st_update_single_texture(struct st_context
*st
,
294 struct pipe_sampler_view
**sampler_view
,
295 GLuint texUnit
, bool glsl130_or_later
);
298 st_make_bound_samplers_resident(struct st_context
*st
,
299 struct gl_program
*prog
);
302 st_make_bound_images_resident(struct st_context
*st
,
303 struct gl_program
*prog
);