[Mesa-dev] [PATCH 13/20] mesa: reduce the size of gl_texture_object

Marek Olšák maraeo at gmail.com
Tue Nov 21 18:01:55 UTC 2017


From: Marek Olšák <marek.olsak at amd.com>

We are technically incorrect by not allowing the full range of non-sensical
values. Like BaseLevel = 10000. Do we really care about that though?

gl_texture_object: 1032 -> 984 bytes.
---
 src/mesa/main/mtypes.h   | 48 ++++++++++++++++++++++++------------------------
 src/mesa/main/texparam.c |  7 ++++---
 2 files changed, 28 insertions(+), 27 deletions(-)

diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index f3e9839..d0bb3ee 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -975,109 +975,109 @@ typedef enum
 
 
 /**
  * Sampler object state.  These objects are new with GL_ARB_sampler_objects
  * and OpenGL 3.3.  Legacy texture objects also contain a sampler object.
  */
 struct gl_sampler_object
 {
    simple_mtx_t Mutex;
    GLuint Name;
-   GLint RefCount;
    GLchar *Label;               /**< GL_KHR_debug */
+   GLint RefCount;
 
    GLenum16 WrapS;		/**< S-axis texture image wrap mode */
    GLenum16 WrapT;		/**< T-axis texture image wrap mode */
    GLenum16 WrapR;		/**< R-axis texture image wrap mode */
    GLenum16 MinFilter;		/**< minification filter */
    GLenum16 MagFilter;		/**< magnification filter */
+   GLenum16 sRGBDecode;         /**< GL_DECODE_EXT or GL_SKIP_DECODE_EXT */
    union gl_color_union BorderColor;  /**< Interpreted according to texture format */
    GLfloat MinLod;		/**< min lambda, OpenGL 1.2 */
    GLfloat MaxLod;		/**< max lambda, OpenGL 1.2 */
    GLfloat LodBias;		/**< OpenGL 1.4 */
    GLfloat MaxAnisotropy;	/**< GL_EXT_texture_filter_anisotropic */
    GLenum16 CompareMode;	/**< GL_ARB_shadow */
    GLenum16 CompareFunc;	/**< GL_ARB_shadow */
-   GLenum16 sRGBDecode;         /**< GL_DECODE_EXT or GL_SKIP_DECODE_EXT */
    GLboolean CubeMapSeamless;   /**< GL_AMD_seamless_cubemap_per_texture */
 
    /** GL_ARB_bindless_texture */
    bool HandleAllocated;
    struct util_dynarray Handles;
 };
 
 
 /**
  * Texture object state.  Contains the array of mipmap images, border color,
  * wrap modes, filter modes, and shadow/texcompare state.
  */
 struct gl_texture_object
 {
    simple_mtx_t Mutex;      /**< for thread safety */
    GLint RefCount;             /**< reference count */
    GLuint Name;                /**< the user-visible texture object ID */
-   GLchar *Label;               /**< GL_KHR_debug */
    GLenum16 Target;            /**< GL_TEXTURE_1D, GL_TEXTURE_2D, etc. */
-   gl_texture_index TargetIndex; /**< The gl_texture_unit::CurrentTex index.
-                                      Only valid when Target is valid. */
+   GLenum16 DepthMode;         /**< GL_ARB_depth_texture */
+   GLchar *Label;              /**< GL_KHR_debug */
 
    struct gl_sampler_object Sampler;
 
-   GLenum16 DepthMode;         /**< GL_ARB_depth_texture */
-
+   gl_texture_index TargetIndex; /**< The gl_texture_unit::CurrentTex index.
+                                      Only valid when Target is valid. */
    GLfloat Priority;           /**< in [0,1] */
-   GLint BaseLevel;            /**< min mipmap level, OpenGL 1.2 */
-   GLint MaxLevel;             /**< max mipmap level, OpenGL 1.2 */
-   GLint ImmutableLevels;      /**< ES 3.0 / ARB_texture_view */
-   GLint _MaxLevel;            /**< actual max mipmap level (q in the spec) */
+   GLshort MaxLevel;           /**< max mipmap level (max=1000), OpenGL 1.2 */
+   GLbyte BaseLevel;           /**< min mipmap level, OpenGL 1.2 */
+   GLbyte _MaxLevel;           /**< actual max mipmap level (q in the spec) */
    GLfloat _MaxLambda;         /**< = _MaxLevel - BaseLevel (q - p in spec) */
    GLint CropRect[4];          /**< GL_OES_draw_texture */
    GLenum16 Swizzle[4];        /**< GL_EXT_texture_swizzle */
-   GLuint _Swizzle;            /**< same as Swizzle, but SWIZZLE_* format */
+   GLushort _Swizzle;          /**< same as Swizzle, but SWIZZLE_* format */
+   GLbyte ImmutableLevels;     /**< ES 3.0 / ARB_texture_view */
    GLboolean GenerateMipmap;   /**< GL_SGIS_generate_mipmap */
    GLboolean _BaseComplete;    /**< Is the base texture level valid? */
    GLboolean _MipmapComplete;  /**< Is the whole mipmap valid? */
    GLboolean _IsIntegerFormat; /**< Does the texture store integer values? */
    GLboolean _RenderToTexture; /**< Any rendering to this texture? */
    GLboolean Purgeable;        /**< Is the buffer purgeable under memory
                                     pressure? */
    GLboolean Immutable;        /**< GL_ARB_texture_storage */
    GLboolean _IsFloat;         /**< GL_OES_float_texture */
    GLboolean _IsHalfFloat;     /**< GL_OES_half_float_texture */
    bool StencilSampling;       /**< Should we sample stencil instead of depth? */
    bool HandleAllocated;       /**< GL_ARB_bindless_texture */
 
-   GLuint MinLevel;            /**< GL_ARB_texture_view */
-   GLuint MinLayer;            /**< GL_ARB_texture_view */
-   GLuint NumLevels;           /**< GL_ARB_texture_view */
-   GLuint NumLayers;           /**< GL_ARB_texture_view */
+   /** GL_OES_EGL_image_external */
+   GLubyte RequiredTextureImageUnits;
+
+   GLubyte MinLevel;            /**< GL_ARB_texture_view */
+   GLubyte NumLevels;           /**< GL_ARB_texture_view */
+   GLushort MinLayer;            /**< GL_ARB_texture_view */
+   GLushort NumLayers;           /**< GL_ARB_texture_view */
 
    /** GL_EXT_memory_object */
    GLenum16 TextureTiling;
 
-   /** Actual texture images, indexed by [cube face] and [mipmap level] */
-   struct gl_texture_image *Image[MAX_FACES][MAX_TEXTURE_LEVELS];
+   /** GL_ARB_shader_image_load_store */
+   GLenum16 ImageFormatCompatibilityType;
 
    /** GL_ARB_texture_buffer_object */
-   struct gl_buffer_object *BufferObject;
    GLenum16 BufferObjectFormat;
    /** Equivalent Mesa format for BufferObjectFormat. */
    mesa_format _BufferObjectFormat;
+   struct gl_buffer_object *BufferObject;
+
    /** GL_ARB_texture_buffer_range */
    GLintptr BufferOffset;
    GLsizeiptr BufferSize; /**< if this is -1, use BufferObject->Size instead */
 
-   /** GL_OES_EGL_image_external */
-   GLint RequiredTextureImageUnits;
-
-   /** GL_ARB_shader_image_load_store */
-   GLenum16 ImageFormatCompatibilityType;
+   /** Actual texture images, indexed by [cube face] and [mipmap level] */
+   struct gl_texture_image *Image[MAX_FACES][MAX_TEXTURE_LEVELS];
 
    /** GL_ARB_bindless_texture */
    struct util_dynarray SamplerHandles;
    struct util_dynarray ImageHandles;
 };
 
 
 /** Up to four combiner sources are possible with GL_NV_texture_env_combine4 */
 #define MAX_COMBINER_TERMS 4
 
diff --git a/src/mesa/main/texparam.c b/src/mesa/main/texparam.c
index 4a0f61e..4922277 100644
--- a/src/mesa/main/texparam.c
+++ b/src/mesa/main/texparam.c
@@ -23,20 +23,21 @@
  * OTHER DEALINGS IN THE SOFTWARE.
  */
 
 /**
  * \file texparam.c
  *
  * glTexParameter-related functions
  */
 
 #include <stdbool.h>
+#include <limits.h>
 #include "main/glheader.h"
 #include "main/blend.h"
 #include "main/context.h"
 #include "main/enums.h"
 #include "main/formats.h"
 #include "main/glformats.h"
 #include "main/macros.h"
 #include "main/mtypes.h"
 #include "main/state.h"
 #include "main/texcompress.h"
@@ -201,21 +202,21 @@ comp_to_swizzle(GLenum comp)
       return SWIZZLE_ZERO;
    case GL_ONE:
       return SWIZZLE_ONE;
    default:
       return -1;
    }
 }
 
 
 static void
-set_swizzle_component(GLuint *swizzle, GLuint comp, GLuint swz)
+set_swizzle_component(GLushort *swizzle, GLuint comp, GLuint swz)
 {
    assert(comp < 4);
    assert(swz <= SWIZZLE_NIL);
    {
       GLuint mask = 0x7 << (3 * comp);
       GLuint s = (*swizzle & ~mask) | (swz << (3 * comp));
       *swizzle = s;
    }
 }
 
@@ -402,21 +403,21 @@ set_tex_parameteri(struct gl_context *ctx,
          _mesa_error(ctx, GL_INVALID_VALUE,
                      "glTex%sParameter(param=%d)", suffix, params[0]);
          return GL_FALSE;
       }
       incomplete(ctx, texObj);
 
       /** See note about ARB_texture_storage below */
       if (texObj->Immutable)
          texObj->BaseLevel = MIN2(texObj->ImmutableLevels - 1, params[0]);
       else
-         texObj->BaseLevel = params[0];
+         texObj->BaseLevel = MIN2(params[0], CHAR_MAX);
 
       return GL_TRUE;
 
    case GL_TEXTURE_MAX_LEVEL:
       if (texObj->MaxLevel == params[0])
          return GL_FALSE;
 
       if (params[0] < 0 ||
           (texObj->Target == GL_TEXTURE_RECTANGLE_ARB && params[0] > 0)) {
          _mesa_error(ctx, GL_INVALID_VALUE,
@@ -429,21 +430,21 @@ set_tex_parameteri(struct gl_context *ctx,
       /** From ARB_texture_storage:
        * However, if TEXTURE_IMMUTABLE_FORMAT is TRUE, then level_base is
        * clamped to the range [0, <levels> - 1] and level_max is then clamped to
        * the range [level_base, <levels> - 1], where <levels> is the parameter
        * passed the call to TexStorage* for the texture object.
        */
       if (texObj->Immutable)
           texObj->MaxLevel = CLAMP(params[0], texObj->BaseLevel,
                                    texObj->ImmutableLevels - 1);
       else
-         texObj->MaxLevel = params[0];
+         texObj->MaxLevel = MIN2(params[0], SHRT_MAX);
 
       return GL_TRUE;
 
    case GL_GENERATE_MIPMAP_SGIS:
       if (ctx->API != API_OPENGL_COMPAT && ctx->API != API_OPENGLES)
          goto invalid_pname;
 
       if (params[0] && texObj->Target == GL_TEXTURE_EXTERNAL_OES)
          goto invalid_param;
       if (texObj->GenerateMipmap != params[0]) {
-- 
2.7.4



More information about the mesa-dev mailing list