xref: /aosp_15_r20/external/mesa3d/src/mesa/main/texobj.h (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /**
2  * \file texobj.h
3  * Texture object management.
4  */
5 
6 /*
7  * Mesa 3-D graphics library
8  *
9  * Copyright (C) 1999-2006  Brian Paul   All Rights Reserved.
10  *
11  * Permission is hereby granted, free of charge, to any person obtaining a
12  * copy of this software and associated documentation files (the "Software"),
13  * to deal in the Software without restriction, including without limitation
14  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15  * and/or sell copies of the Software, and to permit persons to whom the
16  * Software is furnished to do so, subject to the following conditions:
17  *
18  * The above copyright notice and this permission notice shall be included
19  * in all copies or substantial portions of the Software.
20  *
21  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
24  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
25  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
26  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27  * OTHER DEALINGS IN THE SOFTWARE.
28  */
29 
30 
31 #ifndef TEXTOBJ_H
32 #define TEXTOBJ_H
33 
34 
35 #include "util/glheader.h"
36 #include "samplerobj.h"
37 #include "teximage.h"
38 
39 
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43 
44 
45 /**
46  * \name Internal functions
47  */
48 /*@{*/
49 
50 extern struct gl_texture_object *
51 _mesa_lookup_texture(struct gl_context *ctx, GLuint id);
52 
53 extern struct gl_texture_object *
54 _mesa_lookup_texture_err(struct gl_context *ctx, GLuint id, const char* func);
55 
56 extern struct gl_texture_object *
57 _mesa_lookup_texture_locked(struct gl_context *ctx, GLuint id);
58 
59 extern struct gl_texture_object *
60 _mesa_get_current_tex_object(struct gl_context *ctx, GLenum target);
61 
62 extern struct gl_texture_object *
63 _mesa_get_texobj_by_target_and_texunit(struct gl_context *ctx, GLenum target,
64                                        GLuint texunit,
65                                        bool allowProxyTargets,
66                                        const char* caller);
67 
68 extern struct gl_texture_object *
69 _mesa_new_texture_object( struct gl_context *ctx, GLuint name, GLenum target );
70 
71 extern int
72 _mesa_tex_target_to_index(const struct gl_context *ctx, GLenum target);
73 
74 extern void
75 _mesa_delete_texture_object( struct gl_context *ctx,
76                              struct gl_texture_object *obj );
77 
78 extern void
79 _mesa_clear_texture_object(struct gl_context *ctx,
80                            struct gl_texture_object *obj,
81                            struct gl_texture_image *retainTexImage);
82 
83 extern void
84 _mesa_reference_texobj_(struct gl_texture_object **ptr,
85                         struct gl_texture_object *tex);
86 
87 static inline void
_mesa_reference_texobj(struct gl_texture_object ** ptr,struct gl_texture_object * tex)88 _mesa_reference_texobj(struct gl_texture_object **ptr,
89                        struct gl_texture_object *tex)
90 {
91    if (*ptr != tex)
92       _mesa_reference_texobj_(ptr, tex);
93 }
94 
95 /**
96  * Lock a texture for updating.  See also _mesa_lock_context_textures().
97  */
98 static inline void
_mesa_lock_texture(struct gl_context * ctx,struct gl_texture_object * texObj)99 _mesa_lock_texture(struct gl_context *ctx, struct gl_texture_object *texObj)
100 {
101    if (!ctx->TexturesLocked)
102       simple_mtx_lock(&ctx->Shared->TexMutex);
103    ctx->Shared->TextureStateStamp++;
104    (void) texObj;
105 }
106 
107 static inline void
_mesa_unlock_texture(struct gl_context * ctx,struct gl_texture_object * texObj)108 _mesa_unlock_texture(struct gl_context *ctx, struct gl_texture_object *texObj)
109 {
110    (void) texObj;
111    if (!ctx->TexturesLocked)
112       simple_mtx_unlock(&ctx->Shared->TexMutex);
113 }
114 
115 
116 /** Is the texture "complete" with respect to the given sampler state? */
117 static inline GLboolean
_mesa_is_texture_complete(const struct gl_texture_object * texObj,const struct gl_sampler_object * sampler,bool linear_as_nearest_for_int_tex)118 _mesa_is_texture_complete(const struct gl_texture_object *texObj,
119                           const struct gl_sampler_object *sampler,
120                           bool linear_as_nearest_for_int_tex)
121 {
122    struct gl_texture_image *img = _mesa_base_tex_image(texObj);
123    bool isMultisample = img && img->NumSamples >= 2;
124 
125    /*
126     * According to ARB_stencil_texturing, NEAREST_MIPMAP_NEAREST would
127     * be forbidden, however it is allowed per GL 4.5 rules, allow it
128     * even without GL 4.5 since it was a spec mistake.
129     */
130    /* Section 8.17 (texture completeness) of the OpenGL 4.6 core profile spec:
131     *
132     *  "The texture is not multisample; either the magnification filter is not
133     *  NEAREST, or the minification filter is neither NEAREST nor NEAREST_-
134     *  MIPMAP_NEAREST; and any of
135     *  – The internal format of the texture is integer.
136     *  – The internal format is STENCIL_INDEX.
137     *  – The internal format is DEPTH_STENCIL, and the value of DEPTH_-
138     *    STENCIL_TEXTURE_MODE for the texture is STENCIL_INDEX.""
139     */
140    /* GL_EXT_texture_filter_minmax further modifies this to explain it does
141     * not apply to MIN/MAX reduction, only WEIGHTED_AVERAGE (i.e. default)
142     */
143    if (!isMultisample &&
144        (texObj->_IsIntegerFormat ||
145         (texObj->StencilSampling &&
146          img->_BaseFormat == GL_DEPTH_STENCIL)) &&
147        sampler->Attrib.ReductionMode == GL_WEIGHTED_AVERAGE_EXT &&
148        (sampler->Attrib.MagFilter != GL_NEAREST ||
149         (sampler->Attrib.MinFilter != GL_NEAREST &&
150          sampler->Attrib.MinFilter != GL_NEAREST_MIPMAP_NEAREST))) {
151       /* If the format is integer, only nearest filtering is allowed,
152        * but some applications (eg: Grid Autosport) uses the default
153        * filtering values.
154        */
155       if (texObj->_IsIntegerFormat &&
156           linear_as_nearest_for_int_tex) {
157          /* Skip return */
158       } else {
159          return GL_FALSE;
160       }
161    }
162 
163    /* Section 8.17 (texture completeness) of the OpenGL 4.6 core profile spec:
164     *
165     *  "The minification filter requires a mipmap (is neither NEAREST nor LINEAR),
166     *  the texture is not multisample, and the texture is not mipmap complete.""
167     */
168    if (!isMultisample &&_mesa_is_mipmap_filter(sampler))
169       return texObj->_MipmapComplete;
170    else
171       return texObj->_BaseComplete;
172 }
173 
174 
175 extern void
176 _mesa_test_texobj_completeness( const struct gl_context *ctx,
177                                 struct gl_texture_object *obj );
178 
179 extern GLboolean
180 _mesa_cube_level_complete(const struct gl_texture_object *texObj,
181                           const GLint level);
182 
183 extern GLboolean
184 _mesa_cube_complete(const struct gl_texture_object *texObj);
185 
186 extern void
187 _mesa_dirty_texobj(struct gl_context *ctx, struct gl_texture_object *texObj);
188 
189 extern struct gl_texture_object *
190 _mesa_get_fallback_texture(struct gl_context *ctx, gl_texture_index tex, bool is_depth);
191 
192 extern GLuint
193 _mesa_total_texture_memory(struct gl_context *ctx);
194 
195 extern GLenum
196 _mesa_texture_base_format(const struct gl_texture_object *texObj);
197 
198 extern void
199 _mesa_unlock_context_textures( struct gl_context *ctx );
200 
201 extern void
202 _mesa_lock_context_textures( struct gl_context *ctx );
203 
204 extern struct gl_texture_object *
205 _mesa_lookup_or_create_texture(struct gl_context *ctx, GLenum target,
206                                GLuint texName, bool no_error, bool is_ext_dsa,
207                                const char *name);
208 void
209 _mesa_update_texture_object_swizzle(struct gl_context *ctx,
210                                     struct gl_texture_object *texObj);
211 /*@}*/
212 
213 #ifdef __cplusplus
214 }
215 #endif
216 
217 
218 #endif
219