mesa: don't update tnl spaces on irrelevant _NEW_POINT/TEXTURE_STATE changes
authorMarek Olšák <marek.olsak@amd.com>
Wed, 3 Feb 2021 19:02:39 +0000 (14:02 -0500)
committerMarge Bot <eric+marge@anholt.net>
Fri, 26 Feb 2021 23:38:02 +0000 (23:38 +0000)
Reviewed-by: Zoltán Böszörményi <zboszor@gmail.com>
Acked-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8850>

src/mesa/main/light.c
src/mesa/main/light.h
src/mesa/main/mtypes.h
src/mesa/main/points.c
src/mesa/main/state.c
src/mesa/main/texstate.c

index 8317173..bb513f7 100644 (file)
@@ -949,14 +949,17 @@ _mesa_GetMaterialiv( GLenum face, GLenum pname, GLint *params )
  * Also, precompute some lighting values such as the products of light
  * source and material ambient, diffuse and specular coefficients.
  */
-void
+GLbitfield
 _mesa_update_lighting( struct gl_context *ctx )
 {
    GLbitfield flags = 0;
+   bool old_need_eye_coords = ctx->Light._NeedEyeCoords;
    ctx->Light._NeedEyeCoords = GL_FALSE;
 
-   if (!ctx->Light.Enabled)
-      return;
+   if (!ctx->Light.Enabled) {
+      return old_need_eye_coords != ctx->Light._NeedEyeCoords ?
+                                       _NEW_TNL_SPACES : 0;
+   }
 
    GLbitfield mask = ctx->Light._EnabledLights;
    while (mask) {
@@ -979,6 +982,9 @@ _mesa_update_lighting( struct gl_context *ctx )
     */
    if (ctx->Light._NeedVertices)
       ctx->Light._NeedEyeCoords = GL_TRUE;
+
+   return old_need_eye_coords != ctx->Light._NeedEyeCoords ?
+                                    _NEW_TNL_SPACES : 0;
 }
 
 void
@@ -1184,7 +1190,7 @@ void
 _mesa_allow_light_in_model( struct gl_context *ctx, GLboolean flag )
 {
    ctx->_ForceEyeCoords = !flag;
-   ctx->NewState |= _NEW_POINT; /* for _mesa_update_tnl_spaces */
+   ctx->NewState |= _NEW_TNL_SPACES;
 }
 
 
index 973f7d4..855389e 100644 (file)
@@ -91,7 +91,7 @@ extern GLuint _mesa_material_bitmask( struct gl_context *ctx,
                                       GLuint legal,
                                       const char * );
 
-extern void _mesa_update_lighting( struct gl_context *ctx );
+extern GLbitfield _mesa_update_lighting( struct gl_context *ctx );
 extern void _mesa_update_light_materials(struct gl_context *ctx);
 extern bool _mesa_update_tnl_spaces( struct gl_context *ctx, GLuint new_state );
 
index 5f62ffc..ecdf2d0 100644 (file)
@@ -4631,7 +4631,7 @@ struct gl_matrix_stack
 #define _NEW_TEXTURE_MATRIX    (1u << 2)   /**< gl_context::TextureMatrix */
 #define _NEW_COLOR             (1u << 3)   /**< gl_context::Color */
 #define _NEW_DEPTH             (1u << 4)   /**< gl_context::Depth */
-/* gap */
+#define _NEW_TNL_SPACES        (1u << 5)  /**< _mesa_update_tnl_spaces */
 #define _NEW_FOG               (1u << 6)   /**< gl_context::Fog */
 #define _NEW_HINT              (1u << 7)   /**< gl_context::Hint */
 #define _NEW_LIGHT_CONSTANTS   (1u << 8)   /**< gl_context::Light */
index 1b0be65..c336d88 100644 (file)
@@ -130,7 +130,8 @@ _mesa_PointParameterfv( GLenum pname, const GLfloat *params)
       case GL_DISTANCE_ATTENUATION_EXT:
          if (TEST_EQ_3V(ctx->Point.Params, params))
             return;
-         FLUSH_VERTICES(ctx, _NEW_POINT | _NEW_FF_VERT_PROGRAM, GL_POINT_BIT);
+         FLUSH_VERTICES(ctx, _NEW_POINT | _NEW_FF_VERT_PROGRAM |
+                        _NEW_TNL_SPACES, GL_POINT_BIT);
          COPY_3V(ctx->Point.Params, params);
          ctx->Point._Attenuated = (ctx->Point.Params[0] != 1.0F ||
                                    ctx->Point.Params[1] != 0.0F ||
index 9a77ef3..e184338 100644 (file)
@@ -463,7 +463,7 @@ _mesa_update_state_locked( struct gl_context *ctx )
          new_state |= _mesa_update_texture_state(ctx);
 
       if (new_state & _NEW_LIGHT_CONSTANTS)
-         _mesa_update_lighting(ctx);
+         new_state |= _mesa_update_lighting(ctx);
 
       /* ctx->_NeedEyeCoords is determined here.
        *
@@ -474,8 +474,8 @@ _mesa_update_state_locked( struct gl_context *ctx )
        * If the lighting space hasn't changed, may still need to recompute
        * light positions & normal transforms for other reasons.
        */
-      if (new_state & (_NEW_LIGHT_CONSTANTS | _NEW_TEXTURE_STATE |
-                       _NEW_POINT | _NEW_MODELVIEW)) {
+      if (new_state & (_NEW_TNL_SPACES | _NEW_LIGHT_CONSTANTS |
+                       _NEW_MODELVIEW)) {
          if (_mesa_update_tnl_spaces(ctx, new_state))
             new_state |= _NEW_FF_VERT_PROGRAM;
       }
index 1e8baea..cbdfb18 100644 (file)
@@ -903,6 +903,7 @@ _mesa_update_texture_state(struct gl_context *ctx)
    /* TODO: only set this if there are actual changes */
    ctx->NewState |= _NEW_TEXTURE_OBJECT | _NEW_TEXTURE_STATE;
 
+   GLbitfield old_genflags = ctx->Texture._GenFlags;
    GLbitfield old_enabled_coord_units = ctx->Texture._EnabledCoordUnits;
    GLbitfield old_texgen_enabled = ctx->Texture._TexGenEnabled;
    GLbitfield old_texmat_enabled = ctx->Texture._TexMatEnabled;
@@ -954,6 +955,9 @@ _mesa_update_texture_state(struct gl_context *ctx)
       new_state |= _NEW_FF_VERT_PROGRAM | _NEW_FF_FRAG_PROGRAM;
    }
 
+   if (old_genflags != ctx->Texture._GenFlags)
+      new_state |= _NEW_TNL_SPACES;
+
    return new_state;
 }