• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "util/simple_mtx.h"
35 
36 #include "main/mtypes.h"
37 
38 
39 struct pipe_resource;
40 
41 
42 struct st_texture_image_transfer
43 {
44    struct pipe_transfer *transfer;
45 
46    /* For compressed texture fallback. */
47    GLubyte *temp_data; /**< Temporary compressed texture storage. */
48    unsigned temp_stride; /**< Stride of the compressed texture storage. */
49    GLubyte *map; /**< Saved map pointer of the uncompressed transfer. */
50 };
51 
52 
53 /**
54  * Container for one context's validated sampler view.
55  */
56 struct st_sampler_view
57 {
58    struct pipe_sampler_view *view;
59 
60    /** The context which created this view */
61    struct st_context *st;
62 
63    /** The glsl version of the shader seen during validation */
64    bool glsl130_or_later;
65    /** Derived from the sampler's sRGBDecode state during validation */
66    bool srgb_skip_decode;
67 
68    /* This mechanism allows passing sampler view references to the driver
69     * without using atomics to increase the reference count.
70     *
71     * This private refcount can be decremented without atomics but only one
72     * context (st above) can use this counter (so that it's only used by
73     * 1 thread).
74     *
75     * This number is atomically added to view->reference.count at
76     * initialization. If it's never used, the same number is atomically
77     * subtracted from view->reference.count before destruction. If this
78     * number is decremented, we can pass one reference to the driver without
79     * touching reference.count with atomics. At destruction we only subtract
80     * the number of references we have not returned. This can possibly turn
81     * a million atomic increments into 1 add and 1 subtract atomic op over
82     * the whole lifetime of an app.
83     */
84    int private_refcount;
85 };
86 
87 
88 /**
89  * Container for per-context sampler views of a texture.
90  */
91 struct st_sampler_views
92 {
93    struct st_sampler_views *next;
94    uint32_t max;
95    uint32_t count;
96    struct st_sampler_view views[0];
97 };
98 
99 struct st_compressed_data
100 {
101    struct pipe_reference reference;
102    GLubyte *ptr;
103 };
104 
105 static inline const struct gl_texture_image *
st_texture_image_const(const struct gl_texture_image * img)106 st_texture_image_const(const struct gl_texture_image *img)
107 {
108    return (const struct gl_texture_image *) img;
109 }
110 
111 static inline const struct gl_texture_object *
st_texture_object_const(const struct gl_texture_object * obj)112 st_texture_object_const(const struct gl_texture_object *obj)
113 {
114    return (const struct gl_texture_object *) obj;
115 }
116 
117 
118 static inline struct pipe_resource *
st_get_texobj_resource(struct gl_texture_object * texObj)119 st_get_texobj_resource(struct gl_texture_object *texObj)
120 {
121    return texObj ? texObj->pt : NULL;
122 }
123 
124 
125 static inline struct pipe_resource *
st_get_stobj_resource(struct gl_texture_object * stObj)126 st_get_stobj_resource(struct gl_texture_object *stObj)
127 {
128    return stObj ? stObj->pt : NULL;
129 }
130 
131 
132 static inline struct gl_texture_object *
st_get_texture_object(struct gl_context * ctx,const struct gl_program * prog,unsigned unit)133 st_get_texture_object(struct gl_context *ctx,
134                       const struct gl_program *prog,
135                       unsigned unit)
136 {
137    const GLuint texUnit = prog->SamplerUnits[unit];
138    return ctx->Texture.Unit[texUnit]._Current;
139 }
140 
141 static inline enum pipe_format
st_get_view_format(struct gl_texture_object * stObj)142 st_get_view_format(struct gl_texture_object *stObj)
143 {
144    if (!stObj)
145       return PIPE_FORMAT_NONE;
146    return stObj->surface_based ? stObj->surface_format : stObj->pt->format;
147 }
148 
149 
150 extern struct pipe_resource *
151 st_texture_create(struct st_context *st,
152                   enum pipe_texture_target target,
153                   enum pipe_format format,
154                   GLuint last_level,
155                   GLuint width0,
156                   GLuint height0,
157                   GLuint depth0,
158                   GLuint layers,
159                   GLuint nr_samples,
160                   GLuint tex_usage,
161                   bool sparse);
162 
163 
164 extern void
165 st_gl_texture_dims_to_pipe_dims(GLenum texture,
166                                 unsigned widthIn,
167                                 uint16_t heightIn,
168                                 uint16_t depthIn,
169                                 unsigned *widthOut,
170                                 uint16_t *heightOut,
171                                 uint16_t *depthOut,
172                                 uint16_t *layersOut);
173 
174 /* Check if an image fits into an existing texture object.
175  */
176 extern GLboolean
177 st_texture_match_image(struct st_context *st,
178                        const struct pipe_resource *pt,
179                        const struct gl_texture_image *image);
180 
181 /* Return a pointer to an image within a texture.  Return image stride as
182  * well.
183  */
184 extern GLubyte *
185 st_texture_image_map(struct st_context *st, struct gl_texture_image *stImage,
186                      enum pipe_map_flags usage,
187                      GLuint x, GLuint y, GLuint z,
188                      GLuint w, GLuint h, GLuint d,
189                      struct pipe_transfer **transfer);
190 
191 extern void
192 st_texture_image_unmap(struct st_context *st,
193                        struct gl_texture_image *stImage, unsigned slice);
194 
195 
196 /* Return pointers to each 2d slice within an image.  Indexed by depth
197  * value.
198  */
199 extern const GLuint *
200 st_texture_depth_offsets(struct pipe_resource *pt, GLuint level);
201 
202 /* Copy an image between two textures
203  */
204 extern void
205 st_texture_image_copy(struct pipe_context *pipe,
206                       struct pipe_resource *dst, GLuint dstLevel,
207                       struct pipe_resource *src, GLuint srcLevel,
208                       GLuint face);
209 
210 
211 extern struct pipe_resource *
212 st_create_color_map_texture(struct gl_context *ctx);
213 
214 void
215 st_destroy_bound_texture_handles(struct st_context *st);
216 
217 void
218 st_destroy_bound_image_handles(struct st_context *st);
219 
220 bool
221 st_astc_format_fallback(const struct st_context *st, mesa_format format);
222 
223 bool
224 st_compressed_format_fallback(struct st_context *st, mesa_format format);
225 
226 void
227 st_convert_image(const struct st_context *st, const struct gl_image_unit *u,
228                  struct pipe_image_view *img, unsigned shader_access);
229 
230 void
231 st_convert_image_from_unit(const struct st_context *st,
232                            struct pipe_image_view *img,
233                            GLuint imgUnit,
234                            unsigned shader_access);
235 
236 void
237 st_convert_sampler(const struct st_context *st,
238                    const struct gl_texture_object *texobj,
239                    const struct gl_sampler_object *msamp,
240                    float tex_unit_lod_bias,
241                    struct pipe_sampler_state *sampler,
242                    bool seamless_cube_map);
243 
244 void
245 st_convert_sampler_from_unit(const struct st_context *st,
246                              struct pipe_sampler_state *sampler,
247                              GLuint texUnit);
248 
249 struct pipe_sampler_view *
250 st_update_single_texture(struct st_context *st,
251                          GLuint texUnit, bool glsl130_or_later,
252                          bool ignore_srgb_decode, bool get_reference);
253 
254 unsigned
255 st_get_sampler_views(struct st_context *st,
256                      enum pipe_shader_type shader_stage,
257                      const struct gl_program *prog,
258                      struct pipe_sampler_view **sampler_views);
259 
260 void
261 st_make_bound_samplers_resident(struct st_context *st,
262                                 struct gl_program *prog);
263 
264 void
265 st_make_bound_images_resident(struct st_context *st,
266                               struct gl_program *prog);
267 
268 #endif
269