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 * Container for one context's validated sampler view.
54 struct st_sampler_view
{
55 struct pipe_sampler_view
*view
;
57 /** The glsl version of the shader seen during validation */
58 bool glsl130_or_later
;
59 /** The value of the sampler's sRGBDecode state during validation */
65 * Subclass of gl_texure_image.
67 struct st_texture_image
69 struct gl_texture_image base
;
71 /* If stImage->pt != NULL, image data is stored here.
72 * Else there is no image data.
74 struct pipe_resource
*pt
;
76 /* List of transfers, allocated on demand.
77 * transfer[layer] is a mapping for that layer.
79 struct st_texture_image_transfer
*transfer
;
80 unsigned num_transfers
;
82 /* For ETC images, keep track of the original data. This is necessary for
83 * mapping/unmapping, as well as image copies.
90 * Subclass of gl_texure_object.
92 struct st_texture_object
94 struct gl_texture_object base
; /* The "parent" object */
96 /* The texture must include at levels [0..lastLevel] once validated:
100 unsigned int validated_first_level
;
101 unsigned int validated_last_level
;
103 /* On validation any active images held in main memory or in other
104 * textures will be copied to this texture and the old storage freed.
106 struct pipe_resource
*pt
;
108 /* Number of views in sampler_views array */
109 GLuint num_sampler_views
;
111 /* Array of sampler views (one per context) attached to this texture
112 * object. Created lazily on first binding in context.
114 struct st_sampler_view
*sampler_views
;
116 /* True if this texture comes from the window system. Such a texture
117 * cannot be reallocated and the format can only be changed with a sampler
120 GLboolean surface_based
;
122 /* If surface_based is true, this format should be used for all sampler
123 * views and surfaces instead of pt->format.
125 enum pipe_format surface_format
;
127 /* When non-zero, samplers should use this level instead of the level
128 * range specified by the GL state.
130 * This is used for EGL images, which may correspond to a single level out
131 * of an imported pipe_resources with multiple mip levels.
135 /* When non-zero, samplers should use this layer instead of the one
136 * specified by the GL state.
138 * This is used for EGL images and VDPAU interop, where imported
139 * pipe_resources may be cube, 3D, or array textures (containing layers
140 * with different fields in the case of VDPAU) even though the GL state
141 * describes one non-array texture per field.
146 * Set when the texture images of this texture object might not all be in
147 * the pipe_resource *pt above.
149 bool needs_validation
;
153 static inline struct st_texture_image
*
154 st_texture_image(struct gl_texture_image
*img
)
156 return (struct st_texture_image
*) img
;
159 static inline const struct st_texture_image
*
160 st_texture_image_const(const struct gl_texture_image
*img
)
162 return (const struct st_texture_image
*) img
;
165 static inline struct st_texture_object
*
166 st_texture_object(struct gl_texture_object
*obj
)
168 return (struct st_texture_object
*) obj
;
171 static inline const struct st_texture_object
*
172 st_texture_object_const(const struct gl_texture_object
*obj
)
174 return (const struct st_texture_object
*) obj
;
178 static inline struct pipe_resource
*
179 st_get_texobj_resource(struct gl_texture_object
*texObj
)
181 struct st_texture_object
*stObj
= st_texture_object(texObj
);
182 return stObj
? stObj
->pt
: NULL
;
186 static inline struct pipe_resource
*
187 st_get_stobj_resource(struct st_texture_object
*stObj
)
189 return stObj
? stObj
->pt
: NULL
;
193 static inline struct st_texture_object
*
194 st_get_texture_object(struct gl_context
*ctx
,
195 const struct gl_program
*prog
,
198 const GLuint texUnit
= prog
->SamplerUnits
[unit
];
199 struct gl_texture_object
*texObj
= ctx
->Texture
.Unit
[texUnit
]._Current
;
204 return st_texture_object(texObj
);
207 static inline enum pipe_format
208 st_get_view_format(struct st_texture_object
*stObj
)
211 return PIPE_FORMAT_NONE
;
212 return stObj
->surface_based
? stObj
->surface_format
: stObj
->pt
->format
;
216 extern struct pipe_resource
*
217 st_texture_create(struct st_context
*st
,
218 enum pipe_texture_target target
,
219 enum pipe_format format
,
230 st_gl_texture_dims_to_pipe_dims(GLenum texture
,
237 uint16_t *layersOut
);
239 /* Check if an image fits into an existing texture object.
242 st_texture_match_image(struct st_context
*st
,
243 const struct pipe_resource
*pt
,
244 const struct gl_texture_image
*image
);
246 /* Return a pointer to an image within a texture. Return image stride as
250 st_texture_image_map(struct st_context
*st
, struct st_texture_image
*stImage
,
251 enum pipe_transfer_usage usage
,
252 GLuint x
, GLuint y
, GLuint z
,
253 GLuint w
, GLuint h
, GLuint d
,
254 struct pipe_transfer
**transfer
);
257 st_texture_image_unmap(struct st_context
*st
,
258 struct st_texture_image
*stImage
, unsigned slice
);
261 /* Return pointers to each 2d slice within an image. Indexed by depth
264 extern const GLuint
*
265 st_texture_depth_offsets(struct pipe_resource
*pt
, GLuint level
);
267 /* Copy an image between two textures
270 st_texture_image_copy(struct pipe_context
*pipe
,
271 struct pipe_resource
*dst
, GLuint dstLevel
,
272 struct pipe_resource
*src
, GLuint srcLevel
,
276 extern struct pipe_resource
*
277 st_create_color_map_texture(struct gl_context
*ctx
);
280 st_destroy_bound_texture_handles(struct st_context
*st
);
283 st_destroy_bound_image_handles(struct st_context
*st
);
286 st_etc_fallback(struct st_context
*st
, struct gl_texture_image
*texImage
);
289 st_convert_image(const struct st_context
*st
, const struct gl_image_unit
*u
,
290 struct pipe_image_view
*img
);
293 st_convert_image_from_unit(const struct st_context
*st
,
294 struct pipe_image_view
*img
,
298 st_convert_sampler(const struct st_context
*st
,
299 const struct gl_texture_object
*texobj
,
300 const struct gl_sampler_object
*msamp
,
301 float tex_unit_lod_bias
,
302 struct pipe_sampler_state
*sampler
);
305 st_convert_sampler_from_unit(const struct st_context
*st
,
306 struct pipe_sampler_state
*sampler
,
310 st_update_single_texture(struct st_context
*st
,
311 struct pipe_sampler_view
**sampler_view
,
312 GLuint texUnit
, bool glsl130_or_later
);
315 st_make_bound_samplers_resident(struct st_context
*st
,
316 struct gl_program
*prog
);
319 st_make_bound_images_resident(struct st_context
*st
,
320 struct gl_program
*prog
);