Mesa (master): mesa: decrease the array size of ctx->Texture.FixedFuncUnit to 8

Marek Olšák mareko at kemper.freedesktop.org
Tue Feb 13 00:17:36 UTC 2018


Module: Mesa
Branch: master
Commit: 78043a75f6c05c470da97d1f18615821d69177c0
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=78043a75f6c05c470da97d1f18615821d69177c0

Author: Marek Olšák <marek.olsak at amd.com>
Date:   Wed Nov 15 22:10:43 2017 +0100

mesa: decrease the array size of ctx->Texture.FixedFuncUnit to 8

GL allows doing glTexEnv on 192 texture units, while in reality,
only MaxTextureCoordUnits units are used by fixed-func shaders.

There is a piglit patch that adjusts piglits/texunits to check only
MaxTextureCoordUnits units.

Reviewed-by: Brian Paul <brianp at vmware.com>

---

 src/mesa/main/enable.c   |  5 +++++
 src/mesa/main/mtypes.h   |  2 +-
 src/mesa/main/texenv.c   | 27 +++++++++++++++++++++++++++
 src/mesa/main/texstate.c |  2 +-
 src/mesa/main/texstate.h |  3 +++
 5 files changed, 37 insertions(+), 2 deletions(-)

diff --git a/src/mesa/main/enable.c b/src/mesa/main/enable.c
index 4c5f9dce5e..f23673a6cd 100644
--- a/src/mesa/main/enable.c
+++ b/src/mesa/main/enable.c
@@ -209,6 +209,8 @@ enable_texture(struct gl_context *ctx, GLboolean state, GLbitfield texBit)
 {
    struct gl_fixedfunc_texture_unit *texUnit =
       _mesa_get_current_fixedfunc_tex_unit(ctx);
+   if (!texUnit)
+      return GL_FALSE;
 
    const GLbitfield newenabled = state
       ? (texUnit->Enabled | texBit) : (texUnit->Enabled & ~texBit);
@@ -1293,6 +1295,9 @@ is_texture_enabled(struct gl_context *ctx, GLbitfield bit)
    const struct gl_fixedfunc_texture_unit *const texUnit =
       _mesa_get_current_fixedfunc_tex_unit(ctx);
 
+   if (!texUnit)
+      return GL_FALSE;
+
    return (texUnit->Enabled & bit) ? GL_TRUE : GL_FALSE;
 }
 
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index 562fb17c10..3a4fdb57c1 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -1370,7 +1370,7 @@ struct gl_texture_attrib
    GLint NumCurrentTexUsed;
 
    struct gl_texture_unit Unit[MAX_COMBINED_TEXTURE_IMAGE_UNITS];
-   struct gl_fixedfunc_texture_unit FixedFuncUnit[MAX_COMBINED_TEXTURE_IMAGE_UNITS];
+   struct gl_fixedfunc_texture_unit FixedFuncUnit[MAX_TEXTURE_COORD_UNITS];
 };
 
 
diff --git a/src/mesa/main/texenv.c b/src/mesa/main/texenv.c
index 9018ce9bc4..22fc8da1ca 100644
--- a/src/mesa/main/texenv.c
+++ b/src/mesa/main/texenv.c
@@ -400,6 +400,15 @@ _mesa_TexEnvfv( GLenum target, GLenum pname, const GLfloat *param )
       struct gl_fixedfunc_texture_unit *texUnit =
          _mesa_get_current_fixedfunc_tex_unit(ctx);
 
+      /* The GL spec says that we should report an error if the unit is greater
+       * than GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, but in practice, only
+       * fixed-function units are usable. This is probably a spec bug.
+       * Ignore glTexEnv(GL_TEXTURE_ENV) calls for non-fixed-func units,
+       * because we don't want to process calls that have no effect.
+       */
+      if (!texUnit)
+         return;
+
       switch (pname) {
       case GL_TEXTURE_ENV_MODE:
          set_env_mode(ctx, texUnit, (GLenum) iparam0);
@@ -649,6 +658,15 @@ _mesa_GetTexEnvfv( GLenum target, GLenum pname, GLfloat *params )
       struct gl_fixedfunc_texture_unit *texUnit =
          _mesa_get_current_fixedfunc_tex_unit(ctx);
 
+      /* The GL spec says that we should report an error if the unit is greater
+       * than GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, but in practice, only
+       * fixed-function units are usable. This is probably a spec bug.
+       * Ignore calls for non-fixed-func units, because we don't process
+       * glTexEnv for them either.
+       */
+      if (!texUnit)
+         return;
+
       if (pname == GL_TEXTURE_ENV_COLOR) {
          if(ctx->NewState & (_NEW_BUFFERS | _NEW_FRAG_CLAMP))
             _mesa_update_state(ctx);
@@ -717,6 +735,15 @@ _mesa_GetTexEnviv( GLenum target, GLenum pname, GLint *params )
       struct gl_fixedfunc_texture_unit *texUnit =
          _mesa_get_current_fixedfunc_tex_unit(ctx);
 
+      /* The GL spec says that we should report an error if the unit is greater
+       * than GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, but in practice, only
+       * fixed-function units are usable. This is probably a spec bug.
+       * Ignore calls for non-fixed-func units, because we don't process
+       * glTexEnv for them either.
+       */
+      if (!texUnit)
+         return;
+
       if (pname == GL_TEXTURE_ENV_COLOR) {
          params[0] = FLOAT_TO_INT( texUnit->EnvColor[0] );
          params[1] = FLOAT_TO_INT( texUnit->EnvColor[1] );
diff --git a/src/mesa/main/texstate.c b/src/mesa/main/texstate.c
index 2b05630e61..f9f50a3005 100644
--- a/src/mesa/main/texstate.c
+++ b/src/mesa/main/texstate.c
@@ -103,7 +103,7 @@ _mesa_copy_texture_state( const struct gl_context *src, struct gl_context *dst )
       }
    }
 
-   for (u = 0; u < src->Const.MaxCombinedTextureImageUnits; u++) {
+   for (u = 0; u < src->Const.MaxTextureCoordUnits; u++) {
       dst->Texture.FixedFuncUnit[u].Enabled = src->Texture.FixedFuncUnit[u].Enabled;
       dst->Texture.FixedFuncUnit[u].EnvMode = src->Texture.FixedFuncUnit[u].EnvMode;
       COPY_4V(dst->Texture.FixedFuncUnit[u].EnvColor, src->Texture.FixedFuncUnit[u].EnvColor);
diff --git a/src/mesa/main/texstate.h b/src/mesa/main/texstate.h
index cf3f7e5a21..c0b73b14e8 100644
--- a/src/mesa/main/texstate.h
+++ b/src/mesa/main/texstate.h
@@ -65,6 +65,9 @@ _mesa_get_current_fixedfunc_tex_unit(struct gl_context *ctx)
 {
    unsigned unit = ctx->Texture.CurrentUnit;
 
+   if (unit >= ARRAY_SIZE(ctx->Texture.FixedFuncUnit))
+      return NULL;
+
    return &ctx->Texture.FixedFuncUnit[unit];
 }
 




More information about the mesa-commit mailing list