From: Marek Olšák Date: Wed, 15 Nov 2017 21:10:43 +0000 (+0100) Subject: mesa: decrease the array size of ctx->Texture.FixedFuncUnit to 8 X-Git-Tag: upstream/18.1.0~1741 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=78043a75f6c05c470da97d1f18615821d69177c0;p=platform%2Fupstream%2Fmesa.git 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 --- diff --git a/src/mesa/main/enable.c b/src/mesa/main/enable.c index 4c5f9dc..f23673a 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 562fb17..3a4fdb5 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 9018ce9..22fc8da 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 2b05630..f9f50a3 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 cf3f7e5..c0b73b1 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]; }